@tobyt/expo-pdf-markup 2.0.0 → 2.1.0-next.20261121214724

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 (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +58 -0
  3. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationModel.kt +12 -0
  4. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationSerializer.kt +92 -15
  5. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationsChangeEmitter.kt +31 -0
  6. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +4 -0
  7. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +10 -13
  8. package/build/ExpoPdfMarkup.types.d.ts +24 -0
  9. package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
  10. package/build/ExpoPdfMarkup.types.js.map +1 -1
  11. package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
  12. package/build/ExpoPdfMarkupView.web.js +5 -5
  13. package/build/ExpoPdfMarkupView.web.js.map +1 -1
  14. package/build/index.d.ts +1 -0
  15. package/build/index.d.ts.map +1 -1
  16. package/build/index.js +1 -0
  17. package/build/index.js.map +1 -1
  18. package/build/parseAnnotations.d.ts +11 -0
  19. package/build/parseAnnotations.d.ts.map +1 -0
  20. package/build/parseAnnotations.js +49 -0
  21. package/build/parseAnnotations.js.map +1 -0
  22. package/build/web/annotationUtils.d.ts +12 -3
  23. package/build/web/annotationUtils.d.ts.map +1 -1
  24. package/build/web/annotationUtils.js +57 -12
  25. package/build/web/annotationUtils.js.map +1 -1
  26. package/fixtures/annotations-v1-array.json +124 -0
  27. package/fixtures/ink-cleanup-expected-array.json +95 -0
  28. package/fixtures/ink-cleanup-expected-object.json +95 -0
  29. package/fixtures/ink-cleanup-input.json +99 -0
  30. package/ios/AnnotationModels.swift +159 -0
  31. package/ios/AnnotationSerializer.swift +4 -2
  32. package/ios/ExpoPdfMarkupModule.swift +4 -0
  33. package/ios/ExpoPdfMarkupView.swift +8 -2
  34. package/package.json +40 -25
  35. package/src/ExpoPdfMarkup.types.ts +26 -0
  36. package/src/ExpoPdfMarkupView.web.tsx +5 -4
  37. package/src/index.ts +1 -0
  38. package/src/parseAnnotations.ts +52 -0
  39. package/src/web/annotationUtils.ts +70 -11
  40. package/docs/agents/domain.md +0 -51
  41. package/docs/agents/issue-tracker.md +0 -46
  42. package/docs/agents/triage-labels.md +0 -15
  43. package/ios/Tests/AnnotationCoordinateTests.swift +0 -337
  44. package/ios/Tests/AnnotationModelTests.swift +0 -178
  45. package/ios/Tests/AnnotationSerializerTests.swift +0 -329
  46. package/ios/Tests/AreaMarkupTests.swift +0 -279
  47. package/ios/Tests/BookModeTests.swift +0 -534
  48. package/ios/Tests/ExpoPdfMarkupViewTests.swift +0 -196
  49. package/ios/Tests/RotatedAnnotationRenderingTests.swift +0 -411
  50. package/ios/Tests/StampPDFAnnotationTests.swift +0 -128
  51. package/ios/Tests/book-sample.pdf +0 -207
  52. package/ios/Tests/single-page.pdf +0 -52
  53. package/ios/Tests/test.pdf +0 -0
  54. package/tsconfig.test.json +0 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9ea74e1: Smaller, more portable ink in annotation sets, on iOS, Android and web.
8
+
9
+ - **Reading:** every platform now reads ink points in object form (`{"x": …, "y": …}`), array form (`[x, y]`) or a mix of both within one ink stroke. A malformed ink point, or an ink stroke that isn't an array, is skipped and the rest of the annotation set still loads (previously iOS and Android could reject the whole set, and web could draw `NaN`).
10
+ - **Writing:** ink coordinates are now rounded to the nearest 0.1 pt (at most one decimal digit, whole numbers without `.0`) and consecutive duplicate ink points within an ink stroke are dropped; a stroke that collapses to a single point is kept as two identical points so it still draws as a dot. This clean-up happens only when an annotation set is written, identically on every platform: ink points keep full precision while drawing and moving, and bounds and all other fields are written exactly as before. Ink points are still written in object form by default, but the coordinate values written will differ slightly from earlier releases. Loading an annotation set writes nothing and doesn't fire `onAnnotationsChanged`.
11
+ - **New `inkPointFormat` prop:** `'object'` (the default) or `'array'`, which makes ink-heavy annotation sets noticeably smaller; `version` stays at 1. Changing the prop doesn't write anything or fire `onAnnotationsChanged`; it applies from the next edit, when any annotation set loaded in either form is written in the chosen form. Only choose `'array'` once every version of your app that might read the annotation set includes this release or a later one, because earlier releases can't read array form.
12
+ - **New exports:** a platform-neutral `parseAnnotations(json)` helper, which reads either form and always returns ink points in object form (throwing on JSON that can't be parsed or has no `annotations` array), and the `AnnotationPointArray` and `InkPointFormat` types. `AnnotationPoint` and `InkAnnotation` are unchanged.
13
+
14
+ ### Patch Changes
15
+
16
+ - bcb86ff: Tested with Expo SDK 58 and React Native 0.88.
17
+
3
18
  ## 2.0.0
4
19
 
5
20
  ### Major 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
@@ -167,6 +180,51 @@ Annotations use zero-origin visible-page coordinates, in PDF points with y incre
167
180
  See [the coordinate contract and upgrade guidance](docs/annotation-coordinates.md) for cropped
168
181
  and rotated pages, v1 compatibility limits, and native rebuild requirements.
169
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
+
170
228
  ### Highlighting and underlining on iOS
171
229
 
172
230
  With `annotationMode="highlight"` or `"underline"`, drag one finger to mark a rectangular area on
@@ -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?) {
@@ -4,6 +4,18 @@ export type AnnotationPoint = {
4
4
  x: number;
5
5
  y: number;
6
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';
7
19
  /** Visible-page rectangle; x/y locate its bottom-left corner. See docs/annotation-coordinates.md. */
8
20
  export type AnnotationBounds = {
9
21
  x: number;
@@ -108,6 +120,18 @@ export type ExpoPdfMarkupViewProps = {
108
120
  backgroundColor?: string;
109
121
  /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */
110
122
  annotations?: string;
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;
111
135
  /**
112
136
  * Active annotation tool. Defaults to `'none'` (view-only).
113
137
  * On iOS, highlight/underline use a one-finger area drag on scanned and text-bearing pages.
@@ -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,mGAAmG;AACnG,MAAM,MAAM,eAAe,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,qGAAqG;AACrG,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,MAA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9B,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\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/** 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 * 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
+ {"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;AA+ZD,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)
@@ -356,7 +356,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
356
356
  /** Duration of the book mode slide, in ms. */
357
357
  const TURN_DURATION_MS = 250;
358
358
  export default function ExpoPdfMarkupView(props) {
359
- 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;
360
360
  const isBook = displayMode === 'book';
361
361
  const scrollContainerRef = React.useRef(null);
362
362
  const [containerSize, setContainerSize] = React.useState({ width: 0, height: 0 });
@@ -407,12 +407,12 @@ export default function ExpoPdfMarkupView(props) {
407
407
  const applyAnnotations = React.useCallback((updater) => {
408
408
  setAnnotations((prev) => {
409
409
  const next = updater(prev);
410
- const json = serializeAnnotations({ version: 1, annotations: next });
410
+ const json = serializeAnnotations({ version: 1, annotations: next }, { inkPointFormat });
411
411
  lastAnnotationsJsonRef.current = json;
412
412
  onAnnotationsChanged?.({ nativeEvent: { annotations: json } });
413
413
  return next;
414
414
  });
415
- }, [onAnnotationsChanged]);
415
+ }, [onAnnotationsChanged, inkPointFormat]);
416
416
  // ResizeObserver → containerSize
417
417
  React.useEffect(() => {
418
418
  const el = scrollContainerRef.current;
@@ -574,7 +574,7 @@ export default function ExpoPdfMarkupView(props) {
574
574
  if (annotationsProp === lastAnnotationsJsonRef.current)
575
575
  return;
576
576
  lastAnnotationsJsonRef.current = annotationsProp;
577
- const parsed = parseAnnotations(annotationsProp);
577
+ const parsed = parseAnnotationsOrEmpty(annotationsProp);
578
578
  setAnnotations(parsed.annotations);
579
579
  }, [annotationsProp]);
580
580
  // -------------------------------------------------------------------------