@tobyt/expo-pdf-markup 1.2.0 → 2.0.0-next.20261121193029

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 (57) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +76 -0
  3. package/android/build.gradle +3 -0
  4. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationModel.kt +12 -0
  5. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationSerializer.kt +92 -15
  6. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationsChangeEmitter.kt +31 -0
  7. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +4 -0
  8. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +10 -13
  9. package/build/ExpoPdfMarkup.types.d.ts +31 -1
  10. package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
  11. package/build/ExpoPdfMarkup.types.js.map +1 -1
  12. package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
  13. package/build/ExpoPdfMarkupView.web.js +33 -27
  14. package/build/ExpoPdfMarkupView.web.js.map +1 -1
  15. package/build/index.d.ts +1 -0
  16. package/build/index.d.ts.map +1 -1
  17. package/build/index.js +1 -0
  18. package/build/index.js.map +1 -1
  19. package/build/parseAnnotations.d.ts +11 -0
  20. package/build/parseAnnotations.d.ts.map +1 -0
  21. package/build/parseAnnotations.js +49 -0
  22. package/build/parseAnnotations.js.map +1 -0
  23. package/build/web/annotationUtils.d.ts +12 -3
  24. package/build/web/annotationUtils.d.ts.map +1 -1
  25. package/build/web/annotationUtils.js +57 -12
  26. package/build/web/annotationUtils.js.map +1 -1
  27. package/docs/annotation-coordinates.md +45 -0
  28. package/docs/annotation-validation.md +117 -0
  29. package/fixtures/annotations-v1-array.json +124 -0
  30. package/fixtures/annotations-v1.json +130 -0
  31. package/fixtures/ink-cleanup-expected-array.json +95 -0
  32. package/fixtures/ink-cleanup-expected-object.json +95 -0
  33. package/fixtures/ink-cleanup-input.json +99 -0
  34. package/ios/AnnotationModels.swift +188 -30
  35. package/ios/AnnotationSerializer.swift +103 -14
  36. package/ios/ExpoPdfMarkupModule.swift +4 -0
  37. package/ios/ExpoPdfMarkupView+Ink.swift +13 -28
  38. package/ios/ExpoPdfMarkupView+Markup.swift +151 -0
  39. package/ios/ExpoPdfMarkupView+Move.swift +17 -6
  40. package/ios/ExpoPdfMarkupView.swift +38 -84
  41. package/ios/StampPDFAnnotation.swift +21 -3
  42. package/ios/Tests/AnnotationCoordinateTests.swift +424 -0
  43. package/ios/Tests/AnnotationSerializerTests.swift +201 -2
  44. package/ios/Tests/AreaMarkupTests.swift +279 -0
  45. package/ios/Tests/BookModeTests.swift +11 -7
  46. package/ios/Tests/ExpoPdfMarkupViewTests.swift +151 -0
  47. package/ios/Tests/RotatedAnnotationRenderingTests.swift +411 -0
  48. package/package.json +40 -25
  49. package/src/ExpoPdfMarkup.types.ts +33 -1
  50. package/src/ExpoPdfMarkupView.web.tsx +33 -22
  51. package/src/index.ts +1 -0
  52. package/src/parseAnnotations.ts +52 -0
  53. package/src/web/annotationUtils.ts +70 -11
  54. package/docs/agents/domain.md +0 -51
  55. package/docs/agents/issue-tracker.md +0 -46
  56. package/docs/agents/triage-labels.md +0 -15
  57. package/tsconfig.test.json +0 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 08d6547: Fix iOS annotation placement, moving and erasing on cropped or rotated PDFs, including stamps in thumbnails and text after reopening.
8
+
9
+ iOS annotation coordinates and `onTextInputRequested.point` now use the visible page, with `(0, 0)` at its bottom-left after rotation. Some annotations saved by older iOS versions may move; existing data is not automatically migrated. Back up saved annotations before upgrading.
10
+
11
+ Rebuild your native iOS app to apply these fixes.
12
+
13
+ - c9f8824: On iOS, drag a rectangle to highlight or underline any page, including scans. This replaces text-selection highlighting and underlining; marks no longer snap to text lines.
14
+
15
+ Switch `annotationMode` to `"none"` to scroll, zoom or turn pages by touch. Programmatic page changes and book-mode keyboard controls still work while marking.
16
+
17
+ Rebuild your native iOS app to use this behaviour.
18
+
3
19
  ## 1.2.0
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -136,6 +136,19 @@ annotation while the text tool is active.
136
136
 
137
137
  This module uses the [Expo Modules API](https://docs.expo.dev/modules/overview/). The `example` directory contains a test app.
138
138
 
139
+ The library development environment and example use Expo SDK 58, React 19.3, and React Native
140
+ 0.88. Use Node.js 22.13+ or 24.3+ (even-numbered releases). Install dependencies with `npm ci`
141
+ in both the root and `example` directories.
142
+
143
+ Builds and type checks use TypeScript directly. ESLint uses the public Expo flat config,
144
+ and Jest uses `jest-expo` presets for iOS, Android, Web, and Node. Test types are checked
145
+ separately with `npm run typecheck:tests`, since Jest uses Babel to transform TypeScript.
146
+ React and React DOM are pinned together for the web tests.
147
+
148
+ `expo-doctor` in `example` reports duplicate copies of native dependencies from the separate
149
+ root and example installs, including the library's peer dependencies. Their versions match;
150
+ the native builds select the example's copies. Keep both installations aligned when upgrading.
151
+
139
152
  ```sh
140
153
  # Build the module
141
154
  npm run build
@@ -160,3 +173,66 @@ npx expo start
160
173
  ## License
161
174
 
162
175
  MIT
176
+
177
+ ### Annotation coordinates and compatibility
178
+
179
+ Annotations use zero-origin visible-page coordinates, in PDF points with y increasing upward.
180
+ See [the coordinate contract and upgrade guidance](docs/annotation-coordinates.md) for cropped
181
+ and rotated pages, v1 compatibility limits, and native rebuild requirements.
182
+
183
+ ### Reading annotation JSON
184
+
185
+ Ink points in an annotation set may be stored in object form (`{"x": 40, "y": 100}`) or array
186
+ form (`[40, 100]`), and one ink stroke may mix both. Use `parseAnnotations` to read raw
187
+ annotation JSON in your own code: it accepts either form and always returns ink points as
188
+ `{ x, y }` objects, so the `AnnotationPoint` and `InkAnnotation` types are unchanged.
189
+
190
+ ```tsx
191
+ import { parseAnnotations, type InkAnnotation } from '@tobyt/expo-pdf-markup';
192
+
193
+ const { annotations } = parseAnnotations(storedJson);
194
+ const inks = annotations.filter((a): a is InkAnnotation => a.type === 'ink');
195
+ ```
196
+
197
+ Malformed ink points are skipped. `parseAnnotations` throws if the JSON can't be parsed or has
198
+ no `annotations` array, so lost data isn't mistaken for an empty set. It doesn't round values.
199
+ `AnnotationPointArray` (`[number, number]`) types raw array-form ink points.
200
+
201
+ ### Writing ink points in array form (`inkPointFormat`)
202
+
203
+ Whenever an annotation set is written, each ink coordinate is rounded to 0.1 pt and consecutive
204
+ duplicate ink points are dropped. By default ink points are still written in object form, which
205
+ every release can read. Set `inkPointFormat="array"` to write them in the shorter array form
206
+ instead; the clean-up is the same, the output is identical on iOS, Android and web, and
207
+ `version` stays at 1.
208
+
209
+ ```tsx
210
+ <ExpoPdfMarkupView
211
+ source={pdfPath}
212
+ annotations={annotations}
213
+ inkPointFormat="array"
214
+ onAnnotationsChanged={({ nativeEvent }) => setAnnotations(nativeEvent.annotations)}
215
+ />
216
+ ```
217
+
218
+ **Rollout rule:** only choose `'array'` once every version of your app that might read the
219
+ annotation set includes the release of this library with the array-form readers. Earlier
220
+ releases can't read array form: iOS rejects the whole annotation set, Android throws and web
221
+ draws `NaN`. So ship a version of your app with this release first,
222
+ and switch to `'array'` once that is the oldest version still in use.
223
+
224
+ Changing `inkPointFormat` writes nothing and doesn't fire `onAnnotationsChanged`. It applies from
225
+ the next edit, when the whole annotation set is written in the chosen form, whichever form it was
226
+ loaded in. Loading an annotation set never rewrites it.
227
+
228
+ ### Highlighting and underlining on iOS
229
+
230
+ With `annotationMode="highlight"` or `"underline"`, drag one finger to mark a rectangular area on
231
+ any page, including scanned PDFs. Highlights cover the rectangle; underlines follow its lower
232
+ edge. The tools use area selection on text-bearing pages too, without snapping to text lines.
233
+
234
+ The active tool captures touch input so marking does not scroll the page. Set
235
+ `annotationMode="none"` to scroll, pinch to zoom, or turn pages by touch, then reselect the tool.
236
+ The `page` prop and book-mode hardware keys remain available while marking; navigating cancels
237
+ an unfinished drag. Cancelling a gesture or switching tools also discards the unfinished area.
238
+ These Swift changes require a native iOS rebuild; a JavaScript-only update cannot install them.
@@ -15,6 +15,9 @@ android {
15
15
  lintOptions {
16
16
  abortOnError false
17
17
  }
18
+ sourceSets {
19
+ test.resources.srcDir '../fixtures'
20
+ }
18
21
  }
19
22
 
20
23
  dependencies {
@@ -27,3 +27,15 @@ data class AnnotationsData(
27
27
  val version: Int = 1,
28
28
  val annotations: List<AnnotationModel> = emptyList()
29
29
  )
30
+
31
+ /** How ink points are written: object form `{"x": …, "y": …}` (default) or array form `[x, y]`. */
32
+ enum class InkPointFormat {
33
+ OBJECT,
34
+ ARRAY
35
+ ;
36
+
37
+ companion object {
38
+ /** Maps the `inkPointFormat` view prop; anything other than `"array"` is object form. */
39
+ fun fromProp(value: String?): InkPointFormat = if (value == "array") ARRAY else OBJECT
40
+ }
41
+ }
@@ -20,12 +20,15 @@ object AnnotationSerializer {
20
20
  }
21
21
  }
22
22
 
23
- fun serialize(data: AnnotationsData): String {
23
+ fun serialize(
24
+ data: AnnotationsData,
25
+ inkPointFormat: InkPointFormat = InkPointFormat.OBJECT
26
+ ): String {
24
27
  val obj = JSONObject()
25
28
  obj.put("version", data.version)
26
29
  val arr = JSONArray()
27
30
  for (annotation in data.annotations) {
28
- arr.put(annotationToJson(annotation))
31
+ arr.put(annotationToJson(annotation, inkPointFormat))
29
32
  }
30
33
  obj.put("annotations", arr)
31
34
  return obj.toString()
@@ -89,19 +92,35 @@ object AnnotationSerializer {
89
92
  arr ?: return null
90
93
  val paths = mutableListOf<List<AnnotationPoint>>()
91
94
  for (i in 0 until arr.length()) {
92
- val stroke = arr.getJSONArray(i)
95
+ // A stroke that isn't an array is malformed and skipped; the rest still loads.
96
+ val stroke = arr.optJSONArray(i) ?: continue
93
97
  val points = mutableListOf<AnnotationPoint>()
94
98
  for (j in 0 until stroke.length()) {
95
- val pt = stroke.getJSONObject(j)
96
- points.add(
97
- AnnotationPoint(pt.getDouble("x").toFloat(), pt.getDouble("y").toFloat())
98
- )
99
+ readInkPoint(stroke.opt(j))?.let { points.add(it) }
99
100
  }
100
101
  paths.add(points)
101
102
  }
102
103
  return paths
103
104
  }
104
105
 
106
+ /**
107
+ * Reads one ink point in object form (`{"x": …, "y": …}`) or array form (`[x, y]`).
108
+ * Anything else is malformed and returns null, so the caller skips just that point.
109
+ */
110
+ private fun readInkPoint(value: Any?): AnnotationPoint? {
111
+ val (x, y) = when (value) {
112
+ is JSONObject -> value.opt("x") to value.opt("y")
113
+ is JSONArray -> if (value.length() == 2) value.opt(0) to value.opt(1) else return null
114
+ else -> return null
115
+ }
116
+ val xd = finiteNumber(x) ?: return null
117
+ val yd = finiteNumber(y) ?: return null
118
+ return AnnotationPoint(xd.toFloat(), yd.toFloat())
119
+ }
120
+
121
+ private fun finiteNumber(value: Any?): Double? =
122
+ (value as? Number)?.toDouble()?.takeIf { it.isFinite() }
123
+
105
124
  private fun parseBounds(obj: JSONObject?): AnnotationBounds? {
106
125
  obj ?: return null
107
126
  return AnnotationBounds(
@@ -112,7 +131,10 @@ object AnnotationSerializer {
112
131
  )
113
132
  }
114
133
 
115
- private fun annotationToJson(model: AnnotationModel): JSONObject {
134
+ private fun annotationToJson(
135
+ model: AnnotationModel,
136
+ inkPointFormat: InkPointFormat
137
+ ): JSONObject {
116
138
  val obj = JSONObject()
117
139
  obj.put("id", model.id)
118
140
  obj.put("type", model.type)
@@ -122,10 +144,12 @@ object AnnotationSerializer {
122
144
  model.alpha?.let { obj.put("alpha", it.toDouble()) }
123
145
  // Ink annotations always carry `paths`, even when empty: the JS `Annotation` type
124
146
  // declares it non-optional, so omitting the key crashes consumers that dereference it.
147
+ // Only ink points are cleaned up and follow the ink point format; any other paths are
148
+ // written as they always were.
125
149
  if (model.type == "ink") {
126
- obj.put("paths", pathsToJson(model.paths ?: emptyList()))
150
+ obj.put("paths", inkPathsToJson(model.paths ?: emptyList(), inkPointFormat))
127
151
  } else {
128
- model.paths?.let { obj.put("paths", pathsToJson(it)) }
152
+ model.paths?.let { obj.put("paths", rawPathsToJson(it)) }
129
153
  }
130
154
  model.bounds?.let { obj.put("bounds", boundsToJson(it)) }
131
155
  model.contents?.let { obj.put("contents", it) }
@@ -136,21 +160,74 @@ object AnnotationSerializer {
136
160
  return obj
137
161
  }
138
162
 
139
- private fun pathsToJson(paths: List<List<AnnotationPoint>>): JSONArray {
163
+ /**
164
+ * Writes ink strokes cleaned up: every coordinate rounded to 0.1 pt, consecutive duplicate
165
+ * points (after rounding) dropped, and a stroke that collapses from 2+ points to one kept
166
+ * as two identical points so it still draws as a dot. In-memory points are untouched.
167
+ * Each point is written in object form (`{"x": …, "y": …}`) or array form (`[x, y]`).
168
+ */
169
+ private fun inkPathsToJson(
170
+ paths: List<List<AnnotationPoint>>,
171
+ inkPointFormat: InkPointFormat
172
+ ): JSONArray {
173
+ val writePoint: (Long, Long) -> Any = when (inkPointFormat) {
174
+ InkPointFormat.OBJECT -> { x, y ->
175
+ JSONObject().put("x", tenthsToJsonNumber(x)).put("y", tenthsToJsonNumber(y))
176
+ }
177
+
178
+ InkPointFormat.ARRAY -> { x, y ->
179
+ JSONArray().put(tenthsToJsonNumber(x)).put(tenthsToJsonNumber(y))
180
+ }
181
+ }
182
+ val arr = JSONArray()
183
+ for (stroke in paths) {
184
+ val strokeArr = JSONArray()
185
+ for ((x, y) in cleanUpStroke(stroke)) strokeArr.put(writePoint(x, y))
186
+ arr.put(strokeArr)
187
+ }
188
+ return arr
189
+ }
190
+
191
+ /** Writes paths of a non-ink annotation unchanged, each point in object form. */
192
+ private fun rawPathsToJson(paths: List<List<AnnotationPoint>>): JSONArray {
140
193
  val arr = JSONArray()
141
194
  for (stroke in paths) {
142
195
  val strokeArr = JSONArray()
143
196
  for (pt in stroke) {
144
- val ptObj = JSONObject()
145
- ptObj.put("x", pt.x.toDouble())
146
- ptObj.put("y", pt.y.toDouble())
147
- strokeArr.put(ptObj)
197
+ strokeArr.put(JSONObject().put("x", pt.x.toDouble()).put("y", pt.y.toDouble()))
148
198
  }
149
199
  arr.put(strokeArr)
150
200
  }
151
201
  return arr
152
202
  }
153
203
 
204
+ /** Rounds a stroke to whole tenths of a point and drops consecutive duplicates. */
205
+ private fun cleanUpStroke(stroke: List<AnnotationPoint>): List<Pair<Long, Long>> {
206
+ val kept = mutableListOf<Pair<Long, Long>>()
207
+ for (pt in stroke) {
208
+ val rounded = toTenths(pt.x) to toTenths(pt.y)
209
+ if (kept.lastOrNull() != rounded) kept.add(rounded)
210
+ }
211
+ if (stroke.size >= 2 && kept.size == 1) kept.add(kept[0])
212
+ return kept
213
+ }
214
+
215
+ /**
216
+ * Nearest whole number of tenths, rounding the Double product with ties away from zero.
217
+ * The Float is widened to Double first; `kotlin.math.round` is half-even, so it isn't used.
218
+ */
219
+ private fun toTenths(value: Float): Long {
220
+ val scaled = value.toDouble() * 10
221
+ return (Math.signum(scaled) * Math.round(Math.abs(scaled))).toLong()
222
+ }
223
+
224
+ /**
225
+ * Whole numbers go in as Long so they print without `.0` (and negative zero as `0`);
226
+ * anything else is n / 10.0, whose shortest decimal has a single digit after the point.
227
+ */
228
+ private fun tenthsToJsonNumber(tenths: Long): Number =
229
+ if (tenths % 10 == 0L) tenths / 10 else tenths / 10.0
230
+
154
231
  private fun boundsToJson(bounds: AnnotationBounds): JSONObject {
155
232
  val obj = JSONObject()
156
233
  obj.put("x", bounds.x.toDouble())
@@ -0,0 +1,31 @@
1
+ package dev.terhoeven.expopdfmarkup
2
+
3
+ /**
4
+ * Reads the view's annotation set when it is loaded, and writes it after an edit, handing the
5
+ * JSON to [emit] (the view's `onAnnotationsChanged`). Loading never emits.
6
+ */
7
+ class AnnotationsChangeEmitter(private val emit: (String) -> Unit) {
8
+ /** Applies from the next write; setting it writes nothing by itself. */
9
+ var inkPointFormat: InkPointFormat = InkPointFormat.OBJECT
10
+
11
+ fun annotationsChanged(annotations: List<AnnotationModel>) {
12
+ emit(
13
+ AnnotationSerializer.serialize(
14
+ AnnotationsData(version = 1, annotations = annotations),
15
+ inkPointFormat
16
+ )
17
+ )
18
+ }
19
+
20
+ /**
21
+ * Reads an annotation set given to the view, keeping the last annotation with each id.
22
+ * Returns an empty list for no set, or null when [json] can't be read (keep what is shown).
23
+ * Writes nothing.
24
+ */
25
+ fun annotationsLoaded(json: String?): List<AnnotationModel>? {
26
+ if (json.isNullOrEmpty()) return emptyList()
27
+ val data = AnnotationSerializer.deserialize(json) ?: return null
28
+ val seen = mutableSetOf<String>()
29
+ return data.annotations.reversed().filter { seen.add(it.id) }.reversed()
30
+ }
31
+ }
@@ -100,6 +100,10 @@ class ExpoPdfMarkupModule : Module() {
100
100
  view.useJsTextDialog = use ?: false
101
101
  }
102
102
 
103
+ Prop("inkPointFormat") { view: ExpoPdfMarkupView, format: String? ->
104
+ view.inkPointFormat = InkPointFormat.fromProp(format)
105
+ }
106
+
103
107
  Events(
104
108
  "onPageChanged",
105
109
  "onLoadComplete",
@@ -34,6 +34,14 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
34
34
  private var savedScrollState: ContinuousPdfView.ScrollState? = null
35
35
  var useJsTextDialog: Boolean = false
36
36
 
37
+ private val annotationsChangeEmitter = AnnotationsChangeEmitter { json ->
38
+ pendingAnnotationsJson = json
39
+ onAnnotationsChanged(mapOf("annotations" to json))
40
+ }
41
+
42
+ /** How ink points are written from the next edit on; changing it writes nothing. */
43
+ var inkPointFormat: InkPointFormat by annotationsChangeEmitter::inkPointFormat
44
+
37
45
  private var pendingTextPage: Int = -1
38
46
  private var pendingTextPoint: AnnotationPoint? = null
39
47
  private var pendingTextAnnotationId: String? = null
@@ -123,15 +131,7 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
123
131
 
124
132
  fun loadAnnotations(json: String?) {
125
133
  pendingAnnotationsJson = json
126
- if (json.isNullOrEmpty()) {
127
- pdfView.annotations = emptyList()
128
- return
129
- }
130
- val data = AnnotationSerializer.deserialize(json) ?: return
131
- // Dedup by id — keep last occurrence
132
- val seen = mutableSetOf<String>()
133
- val deduped = data.annotations.reversed().filter { seen.add(it.id) }.reversed()
134
- pdfView.annotations = deduped
134
+ annotationsChangeEmitter.annotationsLoaded(json)?.let { pdfView.annotations = it }
135
135
  }
136
136
 
137
137
  /** `"continuous"` (default) or `"book"`: one page at a time, turned sideways. */
@@ -226,10 +226,7 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
226
226
  }
227
227
 
228
228
  private fun emitAnnotationsChanged() {
229
- val data = AnnotationsData(version = 1, annotations = pdfView.annotations)
230
- val json = AnnotationSerializer.serialize(data)
231
- pendingAnnotationsJson = json
232
- onAnnotationsChanged(mapOf("annotations" to json))
229
+ annotationsChangeEmitter.annotationsChanged(pdfView.annotations)
233
230
  }
234
231
 
235
232
  fun provideTextInput(text: String?) {
@@ -1,8 +1,22 @@
1
1
  import type { StyleProp, ViewStyle } from 'react-native';
2
+ /** Zero-origin visible-page points after page rotation, in PDF points with y increasing upward. */
2
3
  export type AnnotationPoint = {
3
4
  x: number;
4
5
  y: number;
5
6
  };
7
+ /**
8
+ * An ink point in array form (`[x, y]`), as it may appear in raw annotation set JSON.
9
+ * Use `parseAnnotations` to read raw JSON; it always returns ink points as {@link AnnotationPoint}.
10
+ */
11
+ export type AnnotationPointArray = [number, number];
12
+ /**
13
+ * How ink points are written in annotation set JSON:
14
+ * - `'object'`: `{"x": 12.3, "y": 45.6}`, readable by every release of this library.
15
+ * - `'array'`: `[12.3, 45.6]`, shorter, but only readable by releases that include the
16
+ * array-form readers (see {@link ExpoPdfMarkupViewProps.inkPointFormat}).
17
+ */
18
+ export type InkPointFormat = 'object' | 'array';
19
+ /** Visible-page rectangle; x/y locate its bottom-left corner. See docs/annotation-coordinates.md. */
6
20
  export type AnnotationBounds = {
7
21
  x: number;
8
22
  y: number;
@@ -106,7 +120,23 @@ export type ExpoPdfMarkupViewProps = {
106
120
  backgroundColor?: string;
107
121
  /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */
108
122
  annotations?: string;
109
- /** Active annotation tool. Defaults to `'none'` (view-only). */
123
+ /**
124
+ * How ink points are written in the annotation set JSON passed to `onAnnotationsChanged`:
125
+ * `'object'` (`{"x": …, "y": …}`, the default) or `'array'` (`[x, y]`, smaller). Ink points are
126
+ * rounded to 0.1 pt and consecutive duplicates dropped in both forms, and `version` stays 1.
127
+ *
128
+ * Rollout rule: only choose `'array'` once every version of your app that might read the
129
+ * annotation set includes the release of this library with the array-form readers. Older
130
+ * releases can't read array form (iOS rejects the whole set, Android throws, web draws `NaN`).
131
+ *
132
+ * Changing this prop writes nothing by itself; it applies from the next edit.
133
+ */
134
+ inkPointFormat?: InkPointFormat;
135
+ /**
136
+ * Active annotation tool. Defaults to `'none'` (view-only).
137
+ * On iOS, highlight/underline use a one-finger area drag on scanned and text-bearing pages.
138
+ * Set `'none'` for touch navigation/zoom; `page` and book-mode hardware keys remain available.
139
+ */
110
140
  annotationMode?: AnnotationMode;
111
141
  /** Colour applied to new annotations, as a CSS colour string (e.g. `'#FF0000'`). */
112
142
  annotationColor?: string;
@@ -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,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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;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,MAAM,GAAG,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 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 | HighlightAnnotation | UnderlineAnnotation | TextAnnotation | StampAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode =\n 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'stamp' | 'eraser' | '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\n/**\n * How the document's pages are presented.\n * - `'continuous'`: every page stacked in one continuous vertical scroll.\n * - `'book'`: one page at a time, fitted to the view, turned sideways by swiping, tapping near\n * the left or right edge, or pressing the arrow or Page Up / Page Down keys.\n */\nexport type DisplayMode = 'continuous' | 'book';\n\nexport type ExpoPdfMarkupViewProps = {\n /** Absolute local file path of the PDF to display. */\n source: string;\n /**\n * How pages are presented: `'continuous'` vertical scroll, or `'book'` mode with one page at a\n * time. `page` and `onPageChanged` mean the same in both modes. Defaults to `'continuous'`.\n */\n displayMode?: DisplayMode;\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
+ {"version":3,"file":"ExpoPdfMarkup.types.js","sourceRoot":"","sources":["../src/ExpoPdfMarkup.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StyleProp, ViewStyle } from 'react-native';\n\n/** Zero-origin visible-page points after page rotation, in PDF points with y increasing upward. */\nexport type AnnotationPoint = { x: number; y: number };\n\n/**\n * An ink point in array form (`[x, y]`), as it may appear in raw annotation set JSON.\n * Use `parseAnnotations` to read raw JSON; it always returns ink points as {@link AnnotationPoint}.\n */\nexport type AnnotationPointArray = [number, number];\n\n/**\n * How ink points are written in annotation set JSON:\n * - `'object'`: `{\"x\": 12.3, \"y\": 45.6}`, readable by every release of this library.\n * - `'array'`: `[12.3, 45.6]`, shorter, but only readable by releases that include the\n * array-form readers (see {@link ExpoPdfMarkupViewProps.inkPointFormat}).\n */\nexport type InkPointFormat = 'object' | 'array';\n\n/** Visible-page rectangle; x/y locate its bottom-left corner. See docs/annotation-coordinates.md. */\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 | HighlightAnnotation | UnderlineAnnotation | TextAnnotation | StampAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode =\n 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'stamp' | 'eraser' | '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\n/**\n * How the document's pages are presented.\n * - `'continuous'`: every page stacked in one continuous vertical scroll.\n * - `'book'`: one page at a time, fitted to the view, turned sideways by swiping, tapping near\n * the left or right edge, or pressing the arrow or Page Up / Page Down keys.\n */\nexport type DisplayMode = 'continuous' | 'book';\n\nexport type ExpoPdfMarkupViewProps = {\n /** Absolute local file path of the PDF to display. */\n source: string;\n /**\n * How pages are presented: `'continuous'` vertical scroll, or `'book'` mode with one page at a\n * time. `page` and `onPageChanged` mean the same in both modes. Defaults to `'continuous'`.\n */\n displayMode?: DisplayMode;\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 /**\n * How ink points are written in the annotation set JSON passed to `onAnnotationsChanged`:\n * `'object'` (`{\"x\": …, \"y\": …}`, the default) or `'array'` (`[x, y]`, smaller). Ink points are\n * rounded to 0.1 pt and consecutive duplicates dropped in both forms, and `version` stays 1.\n *\n * Rollout rule: only choose `'array'` once every version of your app that might read the\n * annotation set includes the release of this library with the array-form readers. Older\n * releases can't read array form (iOS rejects the whole set, Android throws, web draws `NaN`).\n *\n * Changing this prop writes nothing by itself; it applies from the next edit.\n */\n inkPointFormat?: InkPointFormat;\n /**\n * Active annotation tool. Defaults to `'none'` (view-only).\n * On iOS, highlight/underline use a one-finger area drag on scanned and text-bearing pages.\n * Set `'none'` for touch navigation/zoom; `page` and book-mode hardware keys remain available.\n */\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;AAwC/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AASD,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAqZD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBA2sBtE"}
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;AAwC/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AASD,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AA+ZD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBA4sBtE"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import * as pdfjs from 'pdfjs-dist';
3
3
  import * as React from 'react';
4
- import { clampAnnotationTranslation, canvasRectToPdfBounds, canvasToPdf, drawAnnotationsOnCanvas, hitTestAnnotation, newAnnotationId, parseAnnotations, serializeAnnotations, translateAnnotation, } from './web/annotationUtils';
4
+ import { clampAnnotationTranslation, canvasRectToPdfBounds, canvasToPdf, drawAnnotationsOnCanvas, hitTestAnnotation, newAnnotationId, parseAnnotationsOrEmpty, serializeAnnotations, translateAnnotation, } from './web/annotationUtils';
5
5
  import { BOUNCE_PX, EDGE_RESISTANCE, TAP_SLOP_PX, isViewShown, ownsArrowKeys, keyTurnFor, canGestureTurn, classifySwipe, classifyTap, releaseVelocityX, resolveTurn, slideOffsetFor, } from './web/bookMode';
6
6
  import { computePageMetas } from './web/layout';
7
7
  // Configure pdfjs worker once at module level (consumers can override before mounting)
@@ -51,32 +51,38 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
51
51
  React.useEffect(() => {
52
52
  let cancelled = false;
53
53
  async function render() {
54
- if (!pdfCanvasRef.current)
55
- return;
56
- renderTaskRef.current?.cancel();
57
- renderTaskRef.current = null;
58
- const page = await doc.getPage(pageIndex + 1);
59
- if (cancelled) {
60
- page.cleanup();
61
- return;
62
- }
63
- pageRef.current = page;
64
54
  const canvas = pdfCanvasRef.current;
65
55
  if (!canvas)
66
56
  return;
67
- canvas.width = meta.canvasWidth;
68
- canvas.height = meta.canvasHeight;
69
- const ctx = canvas.getContext('2d');
70
- if (!ctx)
71
- return;
72
- const viewport = page.getViewport({ scale: meta.scale * dpr });
73
- const task = page.render({ canvas: null, canvasContext: ctx, viewport });
74
- renderTaskRef.current = task;
57
+ canvas.dataset.pdfRenderState = 'pending';
58
+ renderTaskRef.current?.cancel();
59
+ renderTaskRef.current = null;
75
60
  try {
61
+ const page = await doc.getPage(pageIndex + 1);
62
+ if (cancelled) {
63
+ page.cleanup();
64
+ return;
65
+ }
66
+ pageRef.current = page;
67
+ canvas.width = meta.canvasWidth;
68
+ canvas.height = meta.canvasHeight;
69
+ const ctx = canvas.getContext('2d');
70
+ if (!ctx) {
71
+ canvas.dataset.pdfRenderState = 'error';
72
+ return;
73
+ }
74
+ const viewport = page.getViewport({ scale: meta.scale * dpr });
75
+ const task = page.render({ canvas: null, canvasContext: ctx, viewport });
76
+ renderTaskRef.current = task;
76
77
  await task.promise;
78
+ if (!cancelled)
79
+ canvas.dataset.pdfRenderState = 'complete';
77
80
  }
78
- catch {
79
- // Render cancelled — ignore
81
+ catch (error) {
82
+ if (!cancelled) {
83
+ canvas.dataset.pdfRenderState = 'error';
84
+ console.error('PDF page rendering failed', error);
85
+ }
80
86
  }
81
87
  }
82
88
  render();
@@ -327,14 +333,14 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
327
333
  : annotationMode === 'stamp'
328
334
  ? 'copy'
329
335
  : 'crosshair';
330
- return (_jsxs("div", { ref: containerRef, "data-pdf-page": pageIndex, style: { position: 'relative', width: cssWidth, height: cssHeight, margin: '0 auto' }, children: [_jsx("canvas", { ref: pdfCanvasRef, style: {
336
+ return (_jsxs("div", { ref: containerRef, "data-pdf-page": pageIndex, style: { position: 'relative', width: cssWidth, height: cssHeight, margin: '0 auto' }, children: [_jsx("canvas", { ref: pdfCanvasRef, "data-pdf-layer": "pdf", "data-pdf-render-state": "pending", style: {
331
337
  position: 'absolute',
332
338
  top: 0,
333
339
  left: 0,
334
340
  width: cssWidth,
335
341
  height: cssHeight,
336
342
  pointerEvents: 'none',
337
- } }), _jsx("canvas", { ref: annotCanvasRef, style: {
343
+ } }), _jsx("canvas", { ref: annotCanvasRef, "data-pdf-layer": "annotations", style: {
338
344
  position: 'absolute',
339
345
  top: 0,
340
346
  left: 0,
@@ -350,7 +356,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
350
356
  /** Duration of the book mode slide, in ms. */
351
357
  const TURN_DURATION_MS = 250;
352
358
  export default function ExpoPdfMarkupView(props) {
353
- const { source, displayMode = 'continuous', page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, annotationFontFamily, stampText, stampSize = 48, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, onTextInputRequested, style, } = props;
359
+ const { source, displayMode = 'continuous', page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, inkPointFormat = 'object', annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, annotationFontFamily, stampText, stampSize = 48, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, onTextInputRequested, style, } = props;
354
360
  const isBook = displayMode === 'book';
355
361
  const scrollContainerRef = React.useRef(null);
356
362
  const [containerSize, setContainerSize] = React.useState({ width: 0, height: 0 });
@@ -401,12 +407,12 @@ export default function ExpoPdfMarkupView(props) {
401
407
  const applyAnnotations = React.useCallback((updater) => {
402
408
  setAnnotations((prev) => {
403
409
  const next = updater(prev);
404
- const json = serializeAnnotations({ version: 1, annotations: next });
410
+ const json = serializeAnnotations({ version: 1, annotations: next }, { inkPointFormat });
405
411
  lastAnnotationsJsonRef.current = json;
406
412
  onAnnotationsChanged?.({ nativeEvent: { annotations: json } });
407
413
  return next;
408
414
  });
409
- }, [onAnnotationsChanged]);
415
+ }, [onAnnotationsChanged, inkPointFormat]);
410
416
  // ResizeObserver → containerSize
411
417
  React.useEffect(() => {
412
418
  const el = scrollContainerRef.current;
@@ -568,7 +574,7 @@ export default function ExpoPdfMarkupView(props) {
568
574
  if (annotationsProp === lastAnnotationsJsonRef.current)
569
575
  return;
570
576
  lastAnnotationsJsonRef.current = annotationsProp;
571
- const parsed = parseAnnotations(annotationsProp);
577
+ const parsed = parseAnnotationsOrEmpty(annotationsProp);
572
578
  setAnnotations(parsed.annotations);
573
579
  }, [annotationsProp]);
574
580
  // -------------------------------------------------------------------------