@tobyt/expo-pdf-markup 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix gap at top of first page on iOS by changing pageBreakMargins to apply all margin to the bottom
8
+
9
+ ## 0.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix freeText annotation colour round-trip by storing the original hex string as a custom PDF annotation key, preventing loss when PDFKit's fontColor returns nil outside a document context
14
+
3
15
  ## 0.2.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@tobyt/expo-pdf-markup.svg)](https://www.npmjs.com/package/@tobyt/expo-pdf-markup)
4
+ [![npm downloads](https://img.shields.io/npm/dw/@tobyt/expo-pdf-markup.svg)](https://www.npmjs.com/package/@tobyt/expo-pdf-markup)
5
+ [![license](https://img.shields.io/npm/l/@tobyt/expo-pdf-markup.svg)](https://github.com/tobyt42/expo-pdf-markup/blob/main/LICENSE)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)
7
+
3
8
  An Expo module for displaying and annotating PDFs, with support for iOS, Android, and Web.
4
9
 
5
10
  > **Status:** Early development — actively being tested. Web support is planned and will be added soon.
@@ -8,9 +13,9 @@ An Expo module for displaying and annotating PDFs, with support for iOS, Android
8
13
 
9
14
  | Platform | PDF rendering | Annotations |
10
15
  | -------- | ------------- | ----------- |
11
- | iOS | ✅ | ✅ |
12
- | Android | ✅ | ✅ |
13
- | Web | 🔜 | 🔜 |
16
+ | iOS | ✅ | ✅ |
17
+ | Android | ✅ | ✅ |
18
+ | Web | 🔜 | 🔜 |
14
19
 
15
20
  ## Installation
16
21
 
@@ -49,6 +54,14 @@ cd example
49
54
  npx expo start
50
55
  ```
51
56
 
57
+ ## Core Team ✨
58
+
59
+ <table>
60
+ <tr>
61
+ <td align="center"><a href="https://github.com/tobyt42"><img src="https://avatars.githubusercontent.com/u/1678364?v=4" width="100px;" alt=""/><br /><sub><b>Toby Terhoeven</b></sub></a><br /></td>
62
+ </tr>
63
+ </table>
64
+
52
65
  ## License
53
66
 
54
67
  MIT
@@ -60,13 +60,19 @@ enum AnnotationSerializer {
60
60
  return nil
61
61
  }
62
62
 
63
- // freeText annotations store the visible colour in fontColor;
64
- // annotation.color is .clear (background).
63
+ // Prefer the stored hex colour (set by this module) to avoid lossy UIColor round-trips.
64
+ // freeText annotations otherwise use fontColor; other types use annotation.color.
65
65
  let isFreeText = type == "text" || type == "freeText"
66
- let effectiveColor = isFreeText
67
- ? (annotation.fontColor ?? annotation.color ?? .black)
68
- : (annotation.color ?? .red)
69
- let colorHex = hexFromColor(effectiveColor)
66
+ let storedHex = annotation.value(forAnnotationKey: PDFAnnotationKey(rawValue: "_color")) as? String
67
+ let colorHex: String
68
+ if let storedHex {
69
+ colorHex = storedHex
70
+ } else {
71
+ let effectiveColor = isFreeText
72
+ ? (annotation.fontColor ?? annotation.color ?? .black)
73
+ : (annotation.color ?? .red)
74
+ colorHex = hexFromColor(effectiveColor)
75
+ }
70
76
  var model = AnnotationModel(
71
77
  id: id,
72
78
  type: type,
@@ -107,10 +113,13 @@ enum AnnotationSerializer {
107
113
  annotation.value(forAnnotationKey: PDFAnnotationKey(rawValue: ownershipKey)) as? Bool == true
108
114
  }
109
115
 
110
- static func tagAsModuleManaged(_ annotation: PDFAnnotation, id: String, createdAt: Double) {
116
+ static func tagAsModuleManaged(_ annotation: PDFAnnotation, id: String, createdAt: Double, colorHex: String? = nil) {
111
117
  annotation.setValue(true, forAnnotationKey: PDFAnnotationKey(rawValue: ownershipKey))
112
118
  annotation.setValue(id, forAnnotationKey: PDFAnnotationKey(rawValue: "_id"))
113
119
  annotation.setValue(createdAt, forAnnotationKey: PDFAnnotationKey(rawValue: "_createdAt"))
120
+ if let colorHex {
121
+ annotation.setValue(colorHex, forAnnotationKey: PDFAnnotationKey(rawValue: "_color"))
122
+ }
114
123
  }
115
124
 
116
125
  // MARK: - Color helpers
@@ -203,7 +212,7 @@ enum AnnotationSerializer {
203
212
  }
204
213
 
205
214
  let createdAt = model.createdAt ?? Date().timeIntervalSince1970
206
- tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt)
215
+ tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt, colorHex: model.color)
207
216
  return annotation
208
217
  }
209
218
 
@@ -218,7 +227,7 @@ enum AnnotationSerializer {
218
227
  annotation.color = color.withAlphaComponent(alpha)
219
228
 
220
229
  let createdAt = model.createdAt ?? Date().timeIntervalSince1970
221
- tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt)
230
+ tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt, colorHex: model.color)
222
231
  return annotation
223
232
  }
224
233
 
@@ -232,7 +241,7 @@ enum AnnotationSerializer {
232
241
  annotation.contents = model.contents ?? ""
233
242
 
234
243
  let createdAt = model.createdAt ?? Date().timeIntervalSince1970
235
- tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt)
244
+ tagAsModuleManaged(annotation, id: model.id, createdAt: createdAt, colorHex: model.color)
236
245
  return annotation
237
246
  }
238
247
 
@@ -30,7 +30,7 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
30
30
  pdfView.autoScales = true
31
31
  pdfView.displayMode = .singlePageContinuous
32
32
  pdfView.displayDirection = .vertical
33
- pdfView.pageBreakMargins = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)
33
+ pdfView.pageBreakMargins = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0)
34
34
  pdfView.backgroundColor = UIColor(white: 0.92, alpha: 1)
35
35
 
36
36
  addSubview(pdfView)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tobyt/expo-pdf-markup",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "An Expo module for displaying and annotating PDFs",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",