@tobyt/expo-pdf-markup 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/android/.editorconfig +2 -0
  4. package/android/build.gradle +30 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationHitTester.kt +76 -0
  7. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationModel.kt +27 -0
  8. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationRenderer.kt +138 -0
  9. package/android/src/main/java/dev/terhoeven/expopdfmarkup/AnnotationSerializer.kt +152 -0
  10. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ContinuousPdfView.kt +539 -0
  11. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +81 -0
  12. package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +147 -0
  13. package/build/ExpoPdfMarkup.types.d.ts +96 -0
  14. package/build/ExpoPdfMarkup.types.d.ts.map +1 -0
  15. package/build/ExpoPdfMarkup.types.js +2 -0
  16. package/build/ExpoPdfMarkup.types.js.map +1 -0
  17. package/build/ExpoPdfMarkupModule.d.ts +2 -0
  18. package/build/ExpoPdfMarkupModule.d.ts.map +1 -0
  19. package/build/ExpoPdfMarkupModule.js +4 -0
  20. package/build/ExpoPdfMarkupModule.js.map +1 -0
  21. package/build/ExpoPdfMarkupModule.web.d.ts +2 -0
  22. package/build/ExpoPdfMarkupModule.web.d.ts.map +1 -0
  23. package/build/ExpoPdfMarkupModule.web.js +4 -0
  24. package/build/ExpoPdfMarkupModule.web.js.map +1 -0
  25. package/build/ExpoPdfMarkupView.d.ts +4 -0
  26. package/build/ExpoPdfMarkupView.d.ts.map +1 -0
  27. package/build/ExpoPdfMarkupView.js +7 -0
  28. package/build/ExpoPdfMarkupView.js.map +1 -0
  29. package/build/ExpoPdfMarkupView.web.d.ts +4 -0
  30. package/build/ExpoPdfMarkupView.web.d.ts.map +1 -0
  31. package/build/ExpoPdfMarkupView.web.js +8 -0
  32. package/build/ExpoPdfMarkupView.web.js.map +1 -0
  33. package/build/index.d.ts +3 -0
  34. package/build/index.d.ts.map +1 -0
  35. package/build/index.js +3 -0
  36. package/build/index.js.map +1 -0
  37. package/expo-module.config.json +9 -0
  38. package/ios/AnnotationModels.swift +73 -0
  39. package/ios/AnnotationSerializer.swift +252 -0
  40. package/ios/ExpoPdfMarkup.podspec +28 -0
  41. package/ios/ExpoPdfMarkupModule.swift +39 -0
  42. package/ios/ExpoPdfMarkupView.swift +541 -0
  43. package/package.json +67 -0
  44. package/src/ExpoPdfMarkup.types.ts +80 -0
  45. package/src/ExpoPdfMarkupModule.ts +2 -0
  46. package/src/ExpoPdfMarkupModule.web.ts +2 -0
  47. package/src/ExpoPdfMarkupView.tsx +10 -0
  48. package/src/ExpoPdfMarkupView.web.tsx +12 -0
  49. package/src/index.ts +2 -0
@@ -0,0 +1,147 @@
1
+ package dev.terhoeven.expopdfmarkup
2
+
3
+ import android.app.AlertDialog
4
+ import android.content.Context
5
+ import android.graphics.pdf.PdfRenderer
6
+ import android.os.ParcelFileDescriptor
7
+ import android.widget.EditText
8
+ import expo.modules.kotlin.AppContext
9
+ import expo.modules.kotlin.viewevent.EventDispatcher
10
+ import expo.modules.kotlin.views.ExpoView
11
+ import java.io.File
12
+
13
+ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
14
+ private val pdfView = ContinuousPdfView(context).apply {
15
+ layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
16
+ }
17
+
18
+ private val onPageChanged by EventDispatcher()
19
+ private val onLoadComplete by EventDispatcher()
20
+ private val onError by EventDispatcher()
21
+ private val onAnnotationsChanged by EventDispatcher()
22
+
23
+ private var renderer: PdfRenderer? = null
24
+ private var fileDescriptor: ParcelFileDescriptor? = null
25
+ private var currentSource: String? = null
26
+ private var pendingAnnotationsJson: String? = null
27
+
28
+ init {
29
+ addView(pdfView)
30
+ pdfView.onPageChangeListener = { page, pageCount ->
31
+ onPageChanged(mapOf("page" to page, "pageCount" to pageCount))
32
+ }
33
+ pdfView.onAnnotationsChangedListener = {
34
+ emitAnnotationsChanged()
35
+ }
36
+ pdfView.onTextInputRequested = { page, point ->
37
+ showTextInputDialog(page, point)
38
+ }
39
+ }
40
+
41
+ fun loadPdf(source: String) {
42
+ if (source == currentSource) return
43
+ currentSource = source
44
+
45
+ try {
46
+ close()
47
+ val file = File(source)
48
+ if (!file.exists()) {
49
+ onError(mapOf("message" to "File not found: $source"))
50
+ return
51
+ }
52
+ val fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
53
+ fileDescriptor = fd
54
+ val r = PdfRenderer(fd)
55
+ renderer = r
56
+ onLoadComplete(mapOf("pageCount" to r.pageCount))
57
+ if (width > 0) {
58
+ pdfView.loadPages(r, width)
59
+ } else {
60
+ post { renderer?.let { pdfView.loadPages(it, width) } }
61
+ }
62
+ // Re-apply pending annotations after load
63
+ pendingAnnotationsJson?.let { loadAnnotations(it) }
64
+ } catch (e: Exception) {
65
+ onError(mapOf("message" to "Failed to load PDF: ${e.message}"))
66
+ }
67
+ }
68
+
69
+ fun goToPage(pageIndex: Int) {
70
+ pdfView.scrollToPage(pageIndex)
71
+ }
72
+
73
+ fun setPageBackgroundColor(color: Int?) {
74
+ pdfView.pageBackgroundColor = color ?: android.graphics.Color.rgb(235, 235, 235)
75
+ pdfView.setBackgroundColor(pdfView.pageBackgroundColor)
76
+ }
77
+
78
+ fun loadAnnotations(json: String?) {
79
+ pendingAnnotationsJson = json
80
+ if (json.isNullOrEmpty()) {
81
+ pdfView.annotations = emptyList()
82
+ return
83
+ }
84
+ val data = AnnotationSerializer.deserialize(json) ?: return
85
+ // Dedup by id — keep last occurrence
86
+ val seen = mutableSetOf<String>()
87
+ val deduped = data.annotations.reversed().filter { seen.add(it.id) }.reversed()
88
+ pdfView.annotations = deduped
89
+ }
90
+
91
+ fun setAnnotationMode(mode: String?) {
92
+ pdfView.annotationMode = mode ?: "none"
93
+ }
94
+
95
+ fun setAnnotationColor(color: String?) {
96
+ pdfView.annotationColor = color ?: "#000000"
97
+ }
98
+
99
+ fun setAnnotationLineWidth(width: Double?) {
100
+ pdfView.annotationLineWidth = width?.toFloat() ?: 2f
101
+ }
102
+
103
+ private fun emitAnnotationsChanged() {
104
+ val data = AnnotationsData(version = 1, annotations = pdfView.annotations)
105
+ val json = AnnotationSerializer.serialize(data)
106
+ pendingAnnotationsJson = json
107
+ onAnnotationsChanged(mapOf("annotations" to json))
108
+ }
109
+
110
+ private fun showTextInputDialog(page: Int, point: AnnotationPoint) {
111
+ val editText = EditText(context).apply {
112
+ hint = "Enter text"
113
+ setPadding(48, 32, 48, 32)
114
+ }
115
+ AlertDialog.Builder(context)
116
+ .setTitle("Add Text")
117
+ .setView(editText)
118
+ .setPositiveButton("Add") { _, _ ->
119
+ val text = editText.text.toString().trim()
120
+ if (text.isNotEmpty()) {
121
+ pdfView.addTextAnnotation(page, point, text)
122
+ }
123
+ }
124
+ .setNegativeButton("Cancel", null)
125
+ .show()
126
+ }
127
+
128
+ private fun close() {
129
+ pdfView.recycle()
130
+ renderer?.close()
131
+ renderer = null
132
+ fileDescriptor?.close()
133
+ fileDescriptor = null
134
+ }
135
+
136
+ override fun onDetachedFromWindow() {
137
+ super.onDetachedFromWindow()
138
+ close()
139
+ }
140
+
141
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
142
+ super.onSizeChanged(w, h, oldw, oldh)
143
+ if (w > 0 && w != oldw) {
144
+ renderer?.let { pdfView.loadPages(it, w) }
145
+ }
146
+ }
147
+ }
@@ -0,0 +1,96 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
2
+ export type AnnotationPoint = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export type AnnotationBounds = {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ export type InkAnnotation = {
13
+ id: string;
14
+ type: 'ink';
15
+ page: number;
16
+ color: string;
17
+ lineWidth: number;
18
+ paths: AnnotationPoint[][];
19
+ createdAt?: number;
20
+ };
21
+ export type HighlightAnnotation = {
22
+ id: string;
23
+ type: 'highlight';
24
+ page: number;
25
+ color: string;
26
+ alpha?: number;
27
+ bounds: AnnotationBounds;
28
+ createdAt?: number;
29
+ };
30
+ export type UnderlineAnnotation = {
31
+ id: string;
32
+ type: 'underline';
33
+ page: number;
34
+ color: string;
35
+ bounds: AnnotationBounds;
36
+ createdAt?: number;
37
+ };
38
+ export type TextAnnotation = {
39
+ id: string;
40
+ type: 'text' | 'freeText';
41
+ page: number;
42
+ color: string;
43
+ bounds: AnnotationBounds;
44
+ contents?: string;
45
+ fontSize?: number;
46
+ createdAt?: number;
47
+ };
48
+ export type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation;
49
+ export type AnnotationsData = {
50
+ version: 1;
51
+ annotations: Annotation[];
52
+ };
53
+ export type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser';
54
+ export type ExpoPdfMarkupViewProps = {
55
+ /** Local file path or remote URL of the PDF to display. */
56
+ source: string;
57
+ /** 0-based page number to display. Can be used to restore scroll position on orientation change. */
58
+ page?: number;
59
+ /** Background colour shown behind the PDF pages. */
60
+ backgroundColor?: string;
61
+ /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */
62
+ annotations?: string;
63
+ /** Active annotation tool. Defaults to `'none'` (view-only). */
64
+ annotationMode?: AnnotationMode;
65
+ /** Colour applied to new annotations, as a CSS colour string (e.g. `'#FF0000'`). */
66
+ annotationColor?: string;
67
+ /** Stroke width in points applied to new ink annotations. */
68
+ annotationLineWidth?: number;
69
+ /** Fired when the visible page changes. */
70
+ onPageChanged?: (event: {
71
+ nativeEvent: {
72
+ page: number;
73
+ pageCount: number;
74
+ };
75
+ }) => void;
76
+ /** Fired once the document has finished loading. */
77
+ onLoadComplete?: (event: {
78
+ nativeEvent: {
79
+ pageCount: number;
80
+ };
81
+ }) => void;
82
+ /** Fired when the document fails to load. */
83
+ onError?: (event: {
84
+ nativeEvent: {
85
+ message: string;
86
+ };
87
+ }) => void;
88
+ /** Fired after annotations are created or edited. `annotations` is a serialised {@link AnnotationsData} JSON string. */
89
+ onAnnotationsChanged?: (event: {
90
+ nativeEvent: {
91
+ annotations: string;
92
+ };
93
+ }) => void;
94
+ style?: StyleProp<ViewStyle>;
95
+ };
96
+ //# sourceMappingURL=ExpoPdfMarkup.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkup.types.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkup.types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExpoPdfMarkup.types.js.map
@@ -0,0 +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 createdAt?: number;\n};\n\nexport type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser';\n\nexport type ExpoPdfMarkupViewProps = {\n /** Local file path or remote URL of the PDF to display. */\n source: string;\n /** 0-based page number to display. Can be used to restore scroll position on orientation change. */\n page?: number;\n /** Background colour shown behind the PDF pages. */\n backgroundColor?: string;\n /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */\n annotations?: string;\n /** Active annotation tool. Defaults to `'none'` (view-only). */\n annotationMode?: AnnotationMode;\n /** Colour applied to new annotations, as a CSS colour string (e.g. `'#FF0000'`). */\n annotationColor?: string;\n /** Stroke width in points applied to new ink annotations. */\n annotationLineWidth?: number;\n /** Fired when the visible page changes. */\n onPageChanged?: (event: { nativeEvent: { page: number; pageCount: number } }) => 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 style?: StyleProp<ViewStyle>;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExpoPdfMarkupModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupModule.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupModule.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export {};
2
+ // Module file kept for potential future imperative API.
3
+ // Currently this is a view-only module — no native module functions needed.
4
+ //# sourceMappingURL=ExpoPdfMarkupModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupModule.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupModule.ts"],"names":[],"mappings":";AAAA,wDAAwD;AACxD,4EAA4E","sourcesContent":["// Module file kept for potential future imperative API.\n// Currently this is a view-only module — no native module functions needed.\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExpoPdfMarkupModule.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupModule.web.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupModule.web.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export {};
2
+ // Module file kept for potential future imperative API.
3
+ // Currently this is a view-only module — no native module functions needed.
4
+ //# sourceMappingURL=ExpoPdfMarkupModule.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupModule.web.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupModule.web.ts"],"names":[],"mappings":";AAAA,wDAAwD;AACxD,4EAA4E","sourcesContent":["// Module file kept for potential future imperative API.\n// Currently this is a view-only module — no native module functions needed.\n"]}
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';
3
+ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps): React.JSX.Element;
4
+ //# sourceMappingURL=ExpoPdfMarkupView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupView.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAI/D,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAEtE"}
@@ -0,0 +1,7 @@
1
+ import { requireNativeView } from 'expo';
2
+ import * as React from 'react';
3
+ const NativeView = requireNativeView('ExpoPdfMarkup');
4
+ export default function ExpoPdfMarkupView(props) {
5
+ return <NativeView {...props}/>;
6
+ }
7
+ //# sourceMappingURL=ExpoPdfMarkupView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupView.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,UAAU,GAAgD,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAEnG,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAA6B;IACrE,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeView } from 'expo';\nimport * as React from 'react';\n\nimport { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';\n\nconst NativeView: React.ComponentType<ExpoPdfMarkupViewProps> = requireNativeView('ExpoPdfMarkup');\n\nexport default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {\n return <NativeView {...props} />;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';
3
+ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps): React.JSX.Element;
4
+ //# sourceMappingURL=ExpoPdfMarkupView.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupView.web.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAMtE"}
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { Text, View } from 'react-native';
3
+ export default function ExpoPdfMarkupView(props) {
4
+ return (<View style={[{ flex: 1, alignItems: 'center', justifyContent: 'center' }, props.style]}>
5
+ <Text>PDF viewing is not yet supported on web.</Text>
6
+ </View>);
7
+ }
8
+ //# sourceMappingURL=ExpoPdfMarkupView.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoPdfMarkupView.web.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAA6B;IACrE,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CACtF;MAAA,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CACtD;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\nimport { Text, View } from 'react-native';\n\nimport { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';\n\nexport default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {\n return (\n <View style={[{ flex: 1, alignItems: 'center', justifyContent: 'center' }, props.style]}>\n <Text>PDF viewing is not yet supported on web.</Text>\n </View>\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { default as ExpoPdfMarkupView } from './ExpoPdfMarkupView';
2
+ export * from './ExpoPdfMarkup.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,cAAc,uBAAuB,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as ExpoPdfMarkupView } from './ExpoPdfMarkupView';
2
+ export * from './ExpoPdfMarkup.types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,cAAc,uBAAuB,CAAC","sourcesContent":["export { default as ExpoPdfMarkupView } from './ExpoPdfMarkupView';\nexport * from './ExpoPdfMarkup.types';\n"]}
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["apple", "android", "web"],
3
+ "apple": {
4
+ "modules": ["ExpoPdfMarkupModule"]
5
+ },
6
+ "android": {
7
+ "modules": ["dev.terhoeven.expopdfmarkup.ExpoPdfMarkupModule"]
8
+ }
9
+ }
@@ -0,0 +1,73 @@
1
+ import Foundation
2
+
3
+ struct AnnotationPoint: Codable, Equatable {
4
+ let x: CGFloat
5
+ let y: CGFloat
6
+ }
7
+
8
+ struct AnnotationBounds: Codable, Equatable {
9
+ let x: CGFloat
10
+ let y: CGFloat
11
+ let width: CGFloat
12
+ let height: CGFloat
13
+
14
+ var cgRect: CGRect {
15
+ CGRect(x: x, y: y, width: width, height: height)
16
+ }
17
+
18
+ init(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) {
19
+ self.x = x
20
+ self.y = y
21
+ self.width = width
22
+ self.height = height
23
+ }
24
+
25
+ init(_ rect: CGRect) {
26
+ x = rect.origin.x
27
+ y = rect.origin.y
28
+ width = rect.size.width
29
+ height = rect.size.height
30
+ }
31
+ }
32
+
33
+ struct AnnotationModel: Codable, Equatable {
34
+ let id: String
35
+ let type: String
36
+ let page: Int
37
+ let color: String
38
+ var lineWidth: CGFloat?
39
+ var alpha: CGFloat?
40
+ var paths: [[[String: CGFloat]]]?
41
+ var bounds: AnnotationBounds?
42
+ var contents: String?
43
+ var fontSize: CGFloat?
44
+ var createdAt: Double?
45
+
46
+ var decodedPaths: [[AnnotationPoint]] {
47
+ guard let paths else { return [] }
48
+ return paths.map { path in
49
+ path.compactMap { dict in
50
+ guard let x = dict["x"], let y = dict["y"] else { return nil }
51
+ return AnnotationPoint(x: x, y: y)
52
+ }
53
+ }
54
+ }
55
+
56
+ func encodedPaths(from points: [[AnnotationPoint]]) -> [[[String: CGFloat]]] {
57
+ points.map { path in
58
+ path.map { point in
59
+ ["x": point.x, "y": point.y]
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ struct AnnotationsData: Codable, Equatable {
66
+ let version: Int
67
+ let annotations: [AnnotationModel]
68
+
69
+ init(version: Int = 1, annotations: [AnnotationModel] = []) {
70
+ self.version = version
71
+ self.annotations = annotations
72
+ }
73
+ }