@tobyt/expo-pdf-markup 1.0.1 → 1.1.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationGeometry.kt +2 -2
  3. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationHitTester.kt +1 -1
  4. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationModel.kt +2 -1
  5. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationRenderer.kt +36 -0
  6. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationSerializer.kt +3 -1
  7. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ContinuousPdfView.kt +34 -0
  8. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +8 -0
  9. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +8 -0
  10. package/build/ExpoPdfMarkup.types.d.ts +27 -2
  11. package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
  12. package/build/ExpoPdfMarkup.types.js.map +1 -1
  13. package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
  14. package/build/ExpoPdfMarkupView.web.js +34 -5
  15. package/build/ExpoPdfMarkupView.web.js.map +1 -1
  16. package/build/web/annotationUtils.d.ts.map +1 -1
  17. package/build/web/annotationUtils.js +14 -0
  18. package/build/web/annotationUtils.js.map +1 -1
  19. package/ios/AnnotationModels.swift +1 -0
  20. package/ios/AnnotationSerializer.swift +20 -0
  21. package/ios/ExpoPdfMarkupModule.swift +8 -0
  22. package/ios/ExpoPdfMarkupView+Move.swift +1 -1
  23. package/ios/ExpoPdfMarkupView.swift +6 -0
  24. package/ios/StampPDFAnnotation.swift +100 -0
  25. package/ios/Tests/AnnotationSerializerTests.swift +63 -0
  26. package/ios/Tests/StampPDFAnnotationTests.swift +128 -0
  27. package/package.json +3 -3
  28. package/src/ExpoPdfMarkup.types.ts +34 -1
  29. package/src/ExpoPdfMarkupView.web.tsx +40 -2
  30. package/src/web/annotationUtils.ts +13 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 24c58b8: Add `stamp` annotations for placing consumer-defined text glyphs (e.g. emoji) onto a PDF. New `StampAnnotation` type, `'stamp'` annotation mode, and `stampText`/`stampSize` props let apps arm a stamp (from their own picker UI) and tap to place it; stamps support move and eraser like other bounds-based annotations. A new `StampDefinition` type is exported as a convenience shape for organizing a custom stamp set. Image-backed stamps were intentionally left out — a stored local file path can go stale (app reinstall, cache eviction) and silently break previously-placed stamps, so this stays text-only for now.
8
+
9
+ ### Patch Changes
10
+
11
+ - 850b4f9: Routine dependency maintenance: upgrade to the latest Expo SDK 55 patch release. Bumps `expo` (55.0.5 → 55.0.26) and `react-native` (0.83.2 → 0.83.6) in the module, and `expo`, `expo-asset`, `expo-font`, `react-native`, `react`, `react-dom` to their SDK 55.0.26-compatible versions in the example app. No runtime behavior changes.
12
+ - 95b8c0d: Routine dependency maintenance: patch/minor bumps for transitive and dev dependencies (`@babel/plugin-transform-modules-systemjs`, `@xmldom/xmldom`, `lodash`, `node-forge`, `flatted`, `picomatch`, `yaml`, `brace-expansion`, `shell-quote`, `markdown-it`, `linkify-it`, `form-data`, `hasown`, `ws`), example app `react`/`react-dom`/`@types/react`, and CI Actions (`checkout`, `setup-node`, `upload-pages-artifact`, `deploy-pages`). No runtime behavior changes.
13
+
3
14
  ## 1.0.1
4
15
 
5
16
  ### Patch Changes
@@ -4,7 +4,7 @@ object AnnotationGeometry {
4
4
 
5
5
  fun outlineBounds(annotation: AnnotationModel): AnnotationBounds? = when (annotation.type) {
6
6
  "ink" -> outlineBoundsForInk(annotation)
7
- "highlight", "underline", "freeText", "text" -> annotation.bounds
7
+ "highlight", "underline", "freeText", "text", "stamp" -> annotation.bounds
8
8
  else -> null
9
9
  }
10
10
 
@@ -39,7 +39,7 @@ object AnnotationGeometry {
39
39
  }
40
40
  )
41
41
 
42
- "highlight", "underline", "freeText", "text" -> {
42
+ "highlight", "underline", "freeText", "text", "stamp" -> {
43
43
  val bounds = annotation.bounds ?: return annotation
44
44
  annotation.copy(
45
45
  bounds =
@@ -20,7 +20,7 @@ object AnnotationHitTester {
20
20
  if (hitTestInk(point, annotation, tolerance)) return annotation
21
21
  }
22
22
 
23
- "highlight", "underline", "freeText", "text" -> {
23
+ "highlight", "underline", "freeText", "text", "stamp" -> {
24
24
  val bounds = annotation.bounds ?: continue
25
25
  if (bounds.contains(point)) return annotation
26
26
  }
@@ -19,7 +19,8 @@ data class AnnotationModel(
19
19
  val contents: String? = null,
20
20
  val fontSize: Float? = null,
21
21
  val fontFamily: String? = null,
22
- val createdAt: Double? = null
22
+ val createdAt: Double? = null,
23
+ val text: String? = null
23
24
  )
24
25
 
25
26
  data class AnnotationsData(
@@ -6,6 +6,7 @@ import android.graphics.Canvas
6
6
  import android.graphics.DashPathEffect
7
7
  import android.graphics.Paint
8
8
  import android.graphics.Path
9
+ import android.graphics.RectF
9
10
  import android.graphics.Typeface
10
11
 
11
12
  object AnnotationRenderer {
@@ -48,6 +49,14 @@ object AnnotationRenderer {
48
49
  pageHeight,
49
50
  context
50
51
  )
52
+
53
+ "stamp" -> drawStamp(
54
+ canvas,
55
+ annotation,
56
+ pageYOffset,
57
+ renderScale,
58
+ pageHeight
59
+ )
51
60
  }
52
61
  }
53
62
  }
@@ -172,6 +181,33 @@ object AnnotationRenderer {
172
181
  canvas.drawText(text, left, top + paint.textSize, paint)
173
182
  }
174
183
 
184
+ private fun drawStamp(
185
+ canvas: Canvas,
186
+ annotation: AnnotationModel,
187
+ pageYOffset: Float,
188
+ renderScale: Float,
189
+ pageHeight: Int
190
+ ) {
191
+ val bounds = annotation.bounds ?: return
192
+ val text = annotation.text ?: return
193
+ val left = bounds.x * renderScale
194
+ val top = (pageHeight - bounds.y - bounds.height) * renderScale + pageYOffset
195
+ val right = left + bounds.width * renderScale
196
+ val bottom = top + bounds.height * renderScale
197
+ val rect = RectF(left, top, right, bottom)
198
+
199
+ val paint = Paint().apply {
200
+ color = AnnotationSerializer.colorFromHex(annotation.color)
201
+ textSize = rect.height() * 0.7f
202
+ textAlign = Paint.Align.CENTER
203
+ isAntiAlias = true
204
+ }
205
+ // Paint has no built-in middle-baseline; offset by (ascent + descent) / 2 to
206
+ // vertically center the glyph within rect.
207
+ val baselineY = rect.centerY() - (paint.descent() + paint.ascent()) / 2f
208
+ canvas.drawText(text, rect.centerX(), baselineY, paint)
209
+ }
210
+
175
211
  /** Resolve a typeface the same way React Native text does when available, so
176
212
  * expo-font loaded families are measured and rendered consistently with the
177
213
  * rest of the app. */
@@ -77,7 +77,8 @@ object AnnotationSerializer {
77
77
  contents = if (obj.has("contents")) obj.getString("contents") else null,
78
78
  fontSize = optFloat(obj, "fontSize"),
79
79
  fontFamily = if (obj.has("fontFamily")) obj.getString("fontFamily") else null,
80
- createdAt = if (obj.has("createdAt")) obj.optDouble("createdAt") else null
80
+ createdAt = if (obj.has("createdAt")) obj.optDouble("createdAt") else null,
81
+ text = if (obj.has("text")) obj.getString("text") else null
81
82
  )
82
83
  }
83
84
 
@@ -125,6 +126,7 @@ object AnnotationSerializer {
125
126
  model.fontSize?.let { obj.put("fontSize", it.toDouble()) }
126
127
  model.fontFamily?.let { obj.put("fontFamily", it) }
127
128
  model.createdAt?.let { obj.put("createdAt", it) }
129
+ model.text?.let { obj.put("text", it) }
128
130
  return obj
129
131
  }
130
132
 
@@ -78,6 +78,8 @@ class ContinuousPdfView(context: Context) : View(context) {
78
78
  var annotationColor: String = "#000000"
79
79
  var annotationLineWidth: Float = 2f
80
80
  var annotationFontFamily: String? = null
81
+ var stampText: String? = null
82
+ var stampSize: Float = 48f
81
83
  var onAnnotationsChangedListener: (() -> Unit)? = null
82
84
 
83
85
  // Ink drawing state
@@ -290,6 +292,14 @@ class ContinuousPdfView(context: Context) : View(context) {
290
292
  return true
291
293
  }
292
294
 
295
+ "stamp" -> {
296
+ if (event.action == MotionEvent.ACTION_UP && event.pointerCount == 1) {
297
+ handleStampTap(event)
298
+ }
299
+ gestureDetector.onTouchEvent(event)
300
+ return true
301
+ }
302
+
293
303
  else -> {
294
304
  // "none" mode — normal scroll/zoom
295
305
  gestureDetector.onTouchEvent(event)
@@ -574,6 +584,30 @@ class ContinuousPdfView(context: Context) : View(context) {
574
584
  )
575
585
  }
576
586
 
587
+ // --- Stamp mode ---
588
+
589
+ private fun handleStampTap(event: MotionEvent) {
590
+ val text = stampText ?: return
591
+ val pdfTouch = screenToPdfPoint(event.x, event.y) ?: return
592
+ val half = stampSize / 2f
593
+ val annotation = AnnotationModel(
594
+ id = UUID.randomUUID().toString(),
595
+ type = "stamp",
596
+ page = pdfTouch.pageIndex,
597
+ color = annotationColor,
598
+ bounds = AnnotationBounds(
599
+ pdfTouch.point.x - half,
600
+ pdfTouch.point.y - half,
601
+ stampSize,
602
+ stampSize
603
+ ),
604
+ text = text,
605
+ createdAt = System.currentTimeMillis() / 1000.0
606
+ )
607
+ annotations = annotations + annotation
608
+ onAnnotationsChangedListener?.invoke()
609
+ }
610
+
577
611
  // --- Helpers ---
578
612
 
579
613
  private fun pageIndexAtContentY(contentY: Float): Int {
@@ -84,6 +84,14 @@ class ExpoPdfMarkupModule : Module() {
84
84
  view.setAnnotationFontFamily(font)
85
85
  }
86
86
 
87
+ Prop("stampText") { view: ExpoPdfMarkupView, value: String? ->
88
+ view.setStampText(value)
89
+ }
90
+
91
+ Prop("stampSize") { view: ExpoPdfMarkupView, value: Double? ->
92
+ view.setStampSize(value)
93
+ }
94
+
87
95
  Prop("useJsTextDialog") { view: ExpoPdfMarkupView, use: Boolean? ->
88
96
  view.useJsTextDialog = use ?: false
89
97
  }
@@ -135,6 +135,14 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
135
135
  pdfView.annotationFontFamily = font
136
136
  }
137
137
 
138
+ fun setStampText(value: String?) {
139
+ pdfView.stampText = value
140
+ }
141
+
142
+ fun setStampSize(value: Double?) {
143
+ pdfView.stampSize = value?.toFloat() ?: 48f
144
+ }
145
+
138
146
  private fun emitAnnotationsChanged() {
139
147
  val data = AnnotationsData(version = 1, annotations = pdfView.annotations)
140
148
  val json = AnnotationSerializer.serialize(data)
@@ -52,12 +52,33 @@ export type TextAnnotation = {
52
52
  fontFamily?: string;
53
53
  createdAt?: number;
54
54
  };
55
- export type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation;
55
+ export type StampAnnotation = {
56
+ id: string;
57
+ type: 'stamp';
58
+ page: number;
59
+ /** Colour applied to the text glyph, as a CSS colour string (e.g. `'#FF0000'`). Has no visible effect on full-colour emoji. */
60
+ color: string;
61
+ bounds: AnnotationBounds;
62
+ /** A glyph or short string to render (e.g. an emoji, or a plain character like `'f'`). */
63
+ text: string;
64
+ createdAt?: number;
65
+ };
66
+ export type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation | StampAnnotation;
56
67
  export type AnnotationsData = {
57
68
  version: 1;
58
69
  annotations: Annotation[];
59
70
  };
60
- export type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser' | 'move';
71
+ export type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'stamp' | 'eraser' | 'move';
72
+ /**
73
+ * Recommended shape for describing a consumer-defined stamp set (e.g. domain-specific glyphs).
74
+ * Purely a convenience type for organizing your own stamp picker UI — never sent to native;
75
+ * extract `text` to set as the `stampText` prop before placement.
76
+ */
77
+ export type StampDefinition = {
78
+ id: string;
79
+ label: string;
80
+ text: string;
81
+ };
61
82
  export type TextInputRequest = {
62
83
  mode: 'create' | 'edit';
63
84
  page: number;
@@ -86,6 +107,10 @@ export type ExpoPdfMarkupViewProps = {
86
107
  * - Web: CSS font family (`"Georgia, serif"`) or `undefined` for `sans-serif`
87
108
  */
88
109
  annotationFontFamily?: string;
110
+ /** Glyph or short string for the next stamp to place. Required for the `'stamp'` tool to place anything on tap. */
111
+ stampText?: string;
112
+ /** Side length, in PDF points, of the square bounding box for newly placed stamps. Defaults to 48. */
113
+ stampSize?: number;
89
114
  /** Fired when the visible page changes. */
90
115
  onPageChanged?: (event: {
91
116
  nativeEvent: {
@@ -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,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvF,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,eAAe,EAAE,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA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G,IAAI,CAAC,CAAC;IAC7E,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 /**\n * Font family for the text annotation. Platform-specific:\n * - iOS: PostScript name (`\"Georgia\"`, `\"Courier\"`) or `undefined` for system font (San Francisco)\n * - Android: family name (`\"serif\"`, `\"monospace\"`) or `undefined` for default sans-serif\n * - Web: CSS font family (`\"Georgia, serif\"`) or `undefined` for `sans-serif`\n */\n fontFamily?: string;\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 =\n | 'none'\n | 'ink'\n | 'highlight'\n | 'underline'\n | 'text'\n | 'eraser'\n | 'move';\n\nexport type TextInputRequest = {\n mode: 'create' | 'edit';\n page: number;\n point: AnnotationPoint;\n currentText?: string;\n};\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 /**\n * Default font family for new text annotations. Platform-specific:\n * - iOS: PostScript name (`\"Georgia\"`, `\"Courier\"`) or `undefined` for system font (San Francisco)\n * - Android: React Native / Expo font family name (`\"Montserrat-Regular\"`, `\"serif\"`) or `undefined` for default sans-serif\n * - Web: CSS font family (`\"Georgia, serif\"`) or `undefined` for `sans-serif`\n */\n annotationFontFamily?: string;\n /** Fired when the visible page changes. */\n onPageChanged?: (event: {\n nativeEvent: { page: number; pageCount: number; pageWidth: number; pageHeight: number };\n }) => void;\n /** Fired once the document has finished loading. */\n onLoadComplete?: (event: { nativeEvent: { pageCount: number } }) => void;\n /** Fired when the document fails to load. */\n onError?: (event: { nativeEvent: { message: string } }) => void;\n /** Fired after annotations are created or edited. `annotations` is a serialised {@link AnnotationsData} JSON string. */\n onAnnotationsChanged?: (event: { nativeEvent: { annotations: string } }) => void;\n /**\n * Optional async callback for the text annotation tool. When provided, this is called instead of\n * the native platform dialog (UIAlertController / AlertDialog) when the user taps to place a text\n * annotation. When editing an existing text annotation, `request.currentText` is populated and\n * `request.mode` is `'edit'`. Return the text string to create/update the annotation, or `null`\n * to cancel.\n */\n onTextInputRequested?: (request: TextInputRequest) => Promise<string | null>;\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 /**\n * Font family for the text annotation. Platform-specific:\n * - iOS: PostScript name (`\"Georgia\"`, `\"Courier\"`) or `undefined` for system font (San Francisco)\n * - Android: family name (`\"serif\"`, `\"monospace\"`) or `undefined` for default sans-serif\n * - Web: CSS font family (`\"Georgia, serif\"`) or `undefined` for `sans-serif`\n */\n fontFamily?: string;\n createdAt?: number;\n};\n\nexport type StampAnnotation = {\n id: string;\n type: 'stamp';\n page: number;\n /** Colour applied to the text glyph, as a CSS colour string (e.g. `'#FF0000'`). Has no visible effect on full-colour emoji. */\n color: string;\n bounds: AnnotationBounds;\n /** A glyph or short string to render (e.g. an emoji, or a plain character like `'f'`). */\n text: string;\n createdAt?: number;\n};\n\nexport type Annotation =\n | InkAnnotation\n | HighlightAnnotation\n | UnderlineAnnotation\n | TextAnnotation\n | StampAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode =\n | 'none'\n | 'ink'\n | 'highlight'\n | 'underline'\n | 'text'\n | 'stamp'\n | 'eraser'\n | 'move';\n\n/**\n * Recommended shape for describing a consumer-defined stamp set (e.g. domain-specific glyphs).\n * Purely a convenience type for organizing your own stamp picker UI — never sent to native;\n * extract `text` to set as the `stampText` prop before placement.\n */\nexport type StampDefinition = {\n id: string;\n label: string;\n text: string;\n};\n\nexport type TextInputRequest = {\n mode: 'create' | 'edit';\n page: number;\n point: AnnotationPoint;\n currentText?: string;\n};\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 /**\n * Default font family for new text annotations. Platform-specific:\n * - iOS: PostScript name (`\"Georgia\"`, `\"Courier\"`) or `undefined` for system font (San Francisco)\n * - Android: React Native / Expo font family name (`\"Montserrat-Regular\"`, `\"serif\"`) or `undefined` for default sans-serif\n * - Web: CSS font family (`\"Georgia, serif\"`) or `undefined` for `sans-serif`\n */\n annotationFontFamily?: string;\n /** Glyph or short string for the next stamp to place. Required for the `'stamp'` tool to place anything on tap. */\n stampText?: string;\n /** Side length, in PDF points, of the square bounding box for newly placed stamps. Defaults to 48. */\n stampSize?: number;\n /** Fired when the visible page changes. */\n onPageChanged?: (event: {\n nativeEvent: { page: number; pageCount: number; pageWidth: number; pageHeight: number };\n }) => void;\n /** Fired once the document has finished loading. */\n onLoadComplete?: (event: { nativeEvent: { pageCount: number } }) => void;\n /** Fired when the document fails to load. */\n onError?: (event: { nativeEvent: { message: string } }) => void;\n /** Fired after annotations are created or edited. `annotations` is a serialised {@link AnnotationsData} JSON string. */\n onAnnotationsChanged?: (event: { nativeEvent: { annotations: string } }) => void;\n /**\n * Optional async callback for the text annotation tool. When provided, this is called instead of\n * the native platform dialog (UIAlertController / AlertDialog) when the user taps to place a text\n * annotation. When editing an existing text annotation, `request.currentText` is populated and\n * `request.mode` is `'edit'`. Return the text string to create/update the annotation, or `null`\n * to cancel.\n */\n onTextInputRequested?: (request: TextInputRequest) => Promise<string | null>;\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,EAGV,sBAAsB,EAGvB,MAAM,uBAAuB,CAAC;AAuB/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AAkWD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAiWtE"}
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,EAGV,sBAAsB,EAGvB,MAAM,uBAAuB,CAAC;AAuB/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AAoYD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAqWtE"}
@@ -18,7 +18,7 @@ export function setPdfJsWorkerSrc(url) {
18
18
  // ---------------------------------------------------------------------------
19
19
  const MIN_ZOOM = 1;
20
20
  const MAX_ZOOM = 5;
21
- function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotationColor, annotationLineWidth, zoomLevel, onAnnotationAdded, onAnnotationRemoved, onAnnotationUpdated, onTextInputRequested, containerRef, }) {
21
+ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotationColor, annotationLineWidth, stampText, stampSize, zoomLevel, onAnnotationAdded, onAnnotationRemoved, onAnnotationUpdated, onTextInputRequested, containerRef, }) {
22
22
  const pdfCanvasRef = React.useRef(null);
23
23
  const annotCanvasRef = React.useRef(null);
24
24
  const pageRef = React.useRef(null);
@@ -194,7 +194,10 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
194
194
  }
195
195
  }
196
196
  function handlePointerUp(e) {
197
- if (!pointerDownRef.current && annotationMode !== 'text' && annotationMode !== 'eraser')
197
+ if (!pointerDownRef.current &&
198
+ annotationMode !== 'text' &&
199
+ annotationMode !== 'eraser' &&
200
+ annotationMode !== 'stamp')
198
201
  return;
199
202
  pointerDownRef.current = false;
200
203
  const pt = getCanvasPoint(e);
@@ -280,9 +283,35 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
280
283
  if (hit)
281
284
  onAnnotationRemoved(hit.id);
282
285
  }
286
+ else if (annotationMode === 'stamp') {
287
+ if (!stampText)
288
+ return;
289
+ const pdfPoint = canvasToPdf(pt.x, pt.y, scale, pdfHeight);
290
+ const half = stampSize / 2;
291
+ onAnnotationAdded({
292
+ id: newAnnotationId(),
293
+ type: 'stamp',
294
+ page: pageIndex,
295
+ color: annotationColor,
296
+ bounds: {
297
+ x: pdfPoint.x - half,
298
+ y: pdfPoint.y - half,
299
+ width: stampSize,
300
+ height: stampSize,
301
+ },
302
+ text: stampText,
303
+ createdAt: Date.now(),
304
+ });
305
+ }
283
306
  }
284
307
  const pointerEvents = annotationMode === 'none' ? 'none' : 'auto';
285
- const cursor = annotationMode === 'move' ? 'grab' : annotationMode === 'eraser' ? 'not-allowed' : 'crosshair';
308
+ const cursor = annotationMode === 'move'
309
+ ? 'grab'
310
+ : annotationMode === 'eraser'
311
+ ? 'not-allowed'
312
+ : annotationMode === 'stamp'
313
+ ? 'copy'
314
+ : 'crosshair';
286
315
  return (<div ref={containerRef} style={{ position: 'relative', width: cssWidth, height: cssHeight, margin: '0 auto' }}>
287
316
  <canvas ref={pdfCanvasRef} style={{
288
317
  position: 'absolute',
@@ -307,7 +336,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
307
336
  // Main component
308
337
  // ---------------------------------------------------------------------------
309
338
  export default function ExpoPdfMarkupView(props) {
310
- const { source, page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, annotationFontFamily, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, onTextInputRequested, style, } = props;
339
+ const { source, page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, annotationFontFamily, stampText, stampSize = 48, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, onTextInputRequested, style, } = props;
311
340
  const scrollContainerRef = React.useRef(null);
312
341
  const [containerWidth, setContainerWidth] = React.useState(0);
313
342
  const [doc, setDoc] = React.useState(null);
@@ -579,7 +608,7 @@ export default function ExpoPdfMarkupView(props) {
579
608
  <div style={{ zoom: zoomLevel }}>
580
609
  {doc &&
581
610
  pageMetas.map((meta, i) => (<React.Fragment key={i}>
582
- <PageView doc={doc} pageIndex={i} meta={meta} annotations={annotations} annotationMode={annotationMode} annotationColor={annotationColor} annotationLineWidth={annotationLineWidth} zoomLevel={zoomLevel} onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} onAnnotationUpdated={handleAnnotationUpdated} onTextInputRequested={handleTextInputRequested} containerRef={(el) => {
611
+ <PageView doc={doc} pageIndex={i} meta={meta} annotations={annotations} annotationMode={annotationMode} annotationColor={annotationColor} annotationLineWidth={annotationLineWidth} stampText={stampText} stampSize={stampSize} zoomLevel={zoomLevel} onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} onAnnotationUpdated={handleAnnotationUpdated} onTextInputRequested={handleTextInputRequested} containerRef={(el) => {
583
612
  pageContainerRefs.current[i] = el;
584
613
  }}/>
585
614
  {i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden/>}