@tobyt/expo-pdf-markup 1.1.4 → 2.0.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.
- package/CHANGELOG.md +22 -0
- package/README.md +18 -0
- package/android/build.gradle +3 -0
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/BookPager.kt +66 -0
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/BookTurnPolicy.kt +117 -0
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ContinuousPdfView.kt +370 -57
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +4 -0
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +96 -5
- package/build/ExpoPdfMarkup.types.d.ts +19 -1
- package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
- package/build/ExpoPdfMarkup.types.js.map +1 -1
- package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
- package/build/ExpoPdfMarkupView.web.js +396 -65
- package/build/ExpoPdfMarkupView.web.js.map +1 -1
- package/build/web/bookMode.d.ts +77 -0
- package/build/web/bookMode.d.ts.map +1 -0
- package/build/web/bookMode.js +169 -0
- package/build/web/bookMode.js.map +1 -0
- package/build/web/layout.d.ts +8 -0
- package/build/web/layout.d.ts.map +1 -0
- package/build/web/layout.js +22 -0
- package/build/web/layout.js.map +1 -0
- package/build/web/types.d.ts +2 -0
- package/build/web/types.d.ts.map +1 -1
- package/build/web/types.js.map +1 -1
- package/docs/agents/domain.md +51 -0
- package/docs/agents/issue-tracker.md +46 -0
- package/docs/agents/triage-labels.md +15 -0
- package/docs/annotation-coordinates.md +45 -0
- package/docs/annotation-validation.md +117 -0
- package/fixtures/annotations-v1.json +130 -0
- package/ios/AnnotationModels.swift +29 -30
- package/ios/AnnotationSerializer.swift +99 -12
- package/ios/ExpoPdfMarkupModule.swift +4 -0
- package/ios/ExpoPdfMarkupView+Book.swift +455 -0
- package/ios/ExpoPdfMarkupView+Ink.swift +13 -28
- package/ios/ExpoPdfMarkupView+Markup.swift +151 -0
- package/ios/ExpoPdfMarkupView+Move.swift +17 -6
- package/ios/ExpoPdfMarkupView.swift +76 -84
- package/ios/StampPDFAnnotation.swift +21 -3
- package/ios/Tests/AnnotationCoordinateTests.swift +337 -0
- package/ios/Tests/AnnotationSerializerTests.swift +43 -1
- package/ios/Tests/AreaMarkupTests.swift +279 -0
- package/ios/Tests/BookModeTests.swift +534 -0
- package/ios/Tests/ExpoPdfMarkupViewTests.swift +29 -0
- package/ios/Tests/RotatedAnnotationRenderingTests.swift +411 -0
- package/ios/Tests/book-sample.pdf +207 -0
- package/ios/Tests/single-page.pdf +52 -0
- package/package.json +3 -2
- package/src/ExpoPdfMarkup.types.ts +20 -1
- package/src/ExpoPdfMarkupView.web.tsx +471 -70
- package/src/web/bookMode.ts +186 -0
- package/src/web/layout.ts +30 -0
- package/src/web/types.ts +3 -0
- package/tsconfig.test.json +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
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
|
+
|
|
19
|
+
## 1.2.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 055cf02: Add book mode. `ExpoPdfMarkupView` takes a new `displayMode` prop, `'continuous'` (the default) or `'book'`. Book mode shows one page at a time, fitted to the view, and turns pages sideways with a slide animation: swipe horizontally, tap the outer quarter of the view on either side, or press the arrow or Page Up / Page Down keys, which is what Bluetooth page-turner pedals send. Pinch to zoom still works, and while the page is zoomed in a swipe pans instead of turning. Markup tools keep working in book mode and take priority over swipes and taps, while hardware keys still turn the page. `page` and `onPageChanged` behave the same in both modes, and changing `displayMode` or rotating keeps the current page. Leaving `displayMode` out keeps today's continuous behaviour. The library adds no user-facing text: page indicators and announcements are up to your app. Book mode needs a new native build.
|
|
24
|
+
|
|
3
25
|
## 1.1.4
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -160,3 +160,21 @@ npx expo start
|
|
|
160
160
|
## License
|
|
161
161
|
|
|
162
162
|
MIT
|
|
163
|
+
|
|
164
|
+
### Annotation coordinates and compatibility
|
|
165
|
+
|
|
166
|
+
Annotations use zero-origin visible-page coordinates, in PDF points with y increasing upward.
|
|
167
|
+
See [the coordinate contract and upgrade guidance](docs/annotation-coordinates.md) for cropped
|
|
168
|
+
and rotated pages, v1 compatibility limits, and native rebuild requirements.
|
|
169
|
+
|
|
170
|
+
### Highlighting and underlining on iOS
|
|
171
|
+
|
|
172
|
+
With `annotationMode="highlight"` or `"underline"`, drag one finger to mark a rectangular area on
|
|
173
|
+
any page, including scanned PDFs. Highlights cover the rectangle; underlines follow its lower
|
|
174
|
+
edge. The tools use area selection on text-bearing pages too, without snapping to text lines.
|
|
175
|
+
|
|
176
|
+
The active tool captures touch input so marking does not scroll the page. Set
|
|
177
|
+
`annotationMode="none"` to scroll, pinch to zoom, or turn pages by touch, then reselect the tool.
|
|
178
|
+
The `page` prop and book-mode hardware keys remain available while marking; navigating cancels
|
|
179
|
+
an unfinished drag. Cancelling a gesture or switching tools also discards the unfinished area.
|
|
180
|
+
These Swift changes require a native iOS rebuild; a JavaScript-only update cannot install them.
|
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package dev.terhoeven.expopdfmarkup
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which page book mode shows, and how a turn moves between pages. Pure Kotlin
|
|
5
|
+
* so the turn rules can be tested in the JVM; the view animates whatever
|
|
6
|
+
* [turn] returns and calls [finishSlide] when the slide has landed.
|
|
7
|
+
*/
|
|
8
|
+
class BookPager(private val onPageChanged: (page: Int) -> Unit) {
|
|
9
|
+
sealed interface Turn {
|
|
10
|
+
data class Slide(val from: Int, val to: Int, val direction: BookTurnPolicy.Direction) : Turn
|
|
11
|
+
|
|
12
|
+
/** No page that way: nudge towards [direction] and spring back. Nothing wraps round. */
|
|
13
|
+
data class Bounce(val direction: BookTurnPolicy.Direction) : Turn
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var pageCount = 0
|
|
17
|
+
private set
|
|
18
|
+
var currentPage = 0
|
|
19
|
+
private set
|
|
20
|
+
|
|
21
|
+
private var inFlight: Turn.Slide? = null
|
|
22
|
+
|
|
23
|
+
/** True while a slide has started but not landed. */
|
|
24
|
+
val isSliding: Boolean get() = inFlight != null
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets the document and page without reporting a change, clamping [page]
|
|
28
|
+
* into the document. Used on load, mode switch, rotation and resize.
|
|
29
|
+
*/
|
|
30
|
+
fun reset(pageCount: Int, page: Int) {
|
|
31
|
+
inFlight = null
|
|
32
|
+
this.pageCount = maxOf(0, pageCount)
|
|
33
|
+
currentPage = page.coerceIn(0, maxOf(0, this.pageCount - 1))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Starts a turn. A slide already in flight lands first, so rapid turns
|
|
38
|
+
* each count and each report once. Returns [Turn.Bounce] at either end.
|
|
39
|
+
*/
|
|
40
|
+
fun turn(direction: BookTurnPolicy.Direction): Turn {
|
|
41
|
+
finishSlide()
|
|
42
|
+
val target = currentPage + direction.delta
|
|
43
|
+
if (target !in 0 until pageCount) return Turn.Bounce(direction)
|
|
44
|
+
val slide = Turn.Slide(currentPage, target, direction)
|
|
45
|
+
inFlight = slide
|
|
46
|
+
return slide
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Shows [page] straight away (the `page` prop), cancelling any slide. */
|
|
50
|
+
fun jumpTo(page: Int): Boolean {
|
|
51
|
+
if (page !in 0 until pageCount) return false
|
|
52
|
+
inFlight = null
|
|
53
|
+
if (page == currentPage) return false
|
|
54
|
+
currentPage = page
|
|
55
|
+
onPageChanged(page)
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Lands the slide in flight, if any, and reports the new page. */
|
|
60
|
+
fun finishSlide() {
|
|
61
|
+
val slide = inFlight ?: return
|
|
62
|
+
inFlight = null
|
|
63
|
+
currentPage = slide.to
|
|
64
|
+
onPageChanged(currentPage)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
package dev.terhoeven.expopdfmarkup
|
|
2
|
+
|
|
3
|
+
import android.view.KeyEvent
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Turn decisions for book mode. Every caller is book mode only, so nothing
|
|
7
|
+
* here takes the display mode.
|
|
8
|
+
*/
|
|
9
|
+
object BookTurnPolicy {
|
|
10
|
+
/** Scales within this of fit (1.0) count as "at fit", absorbing pinch rounding. */
|
|
11
|
+
private const val FIT_TOLERANCE = 0.01f
|
|
12
|
+
|
|
13
|
+
private const val EDGE_ZONE_FRACTION = 0.25f
|
|
14
|
+
private const val MIN_EDGE_ZONE_DP = 44f
|
|
15
|
+
|
|
16
|
+
/** Share of the view's width a slow swipe has to travel to turn the page. */
|
|
17
|
+
private const val SWIPE_TURN_FRACTION = 0.25f
|
|
18
|
+
|
|
19
|
+
enum class SwipeAction { TURN, PAN }
|
|
20
|
+
|
|
21
|
+
/** Direction of a page turn. [delta] is the change in page index. */
|
|
22
|
+
enum class Direction(val delta: Int) { NEXT(1), PREVIOUS(-1) }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Width of each edge tap zone: the outer quarter of the view, at least
|
|
26
|
+
* 44 dp, but never more than half the view so the zones can't overlap.
|
|
27
|
+
*/
|
|
28
|
+
fun edgeZoneWidth(viewWidth: Float, density: Float): Float =
|
|
29
|
+
maxOf(viewWidth * EDGE_ZONE_FRACTION, MIN_EDGE_ZONE_DP * density)
|
|
30
|
+
.coerceAtMost(viewWidth / 2f)
|
|
31
|
+
|
|
32
|
+
/** The turn an edge tap at [x] asks for, or null for no turn. */
|
|
33
|
+
fun edgeTapTurnFor(
|
|
34
|
+
annotationMode: String,
|
|
35
|
+
scale: Float,
|
|
36
|
+
x: Float,
|
|
37
|
+
viewWidth: Float,
|
|
38
|
+
density: Float
|
|
39
|
+
): Direction? {
|
|
40
|
+
if (!touchCanTurn(annotationMode, scale) || viewWidth <= 0f) return null
|
|
41
|
+
val zone = edgeZoneWidth(viewWidth, density)
|
|
42
|
+
return when {
|
|
43
|
+
x < zone -> Direction.PREVIOUS
|
|
44
|
+
x > viewWidth - zone -> Direction.NEXT
|
|
45
|
+
else -> null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether a double-tap at [x] zooms. Where an edge tap would turn, the
|
|
51
|
+
* first tap of the pair has already turned the page, so the second is
|
|
52
|
+
* swallowed: a double-tap zooms only in the middle region, or anywhere
|
|
53
|
+
* while edge taps can't turn (zoomed in or with a markup tool active).
|
|
54
|
+
*/
|
|
55
|
+
fun doubleTapZooms(
|
|
56
|
+
annotationMode: String,
|
|
57
|
+
scale: Float,
|
|
58
|
+
x: Float,
|
|
59
|
+
viewWidth: Float,
|
|
60
|
+
density: Float
|
|
61
|
+
): Boolean = edgeTapTurnFor(annotationMode, scale, x, viewWidth, density) == null
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Swipes and edge taps turn the page only with no markup tool active,
|
|
65
|
+
* while the page is not zoomed in beyond fit (scale 1).
|
|
66
|
+
*/
|
|
67
|
+
fun touchCanTurn(annotationMode: String, scale: Float): Boolean =
|
|
68
|
+
annotationMode == "none" && scale <= 1f + FIT_TOLERANCE
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The turn a released horizontal swipe asks for, or null to settle back.
|
|
72
|
+
* [dragX] is the finger's total horizontal travel (negative = leftwards).
|
|
73
|
+
* Leftwards always means next, whatever the layout direction. A fast
|
|
74
|
+
* fling turns in its own direction unless it flicks back against the
|
|
75
|
+
* drag; a slow release turns once the drag passes a quarter of the view.
|
|
76
|
+
*/
|
|
77
|
+
fun swipeReleaseTurnFor(
|
|
78
|
+
dragX: Float,
|
|
79
|
+
velocityX: Float,
|
|
80
|
+
viewWidth: Float,
|
|
81
|
+
flingVelocity: Float
|
|
82
|
+
): Direction? {
|
|
83
|
+
val fromDrag = when {
|
|
84
|
+
dragX <= -viewWidth * SWIPE_TURN_FRACTION -> Direction.NEXT
|
|
85
|
+
dragX >= viewWidth * SWIPE_TURN_FRACTION -> Direction.PREVIOUS
|
|
86
|
+
else -> null
|
|
87
|
+
}
|
|
88
|
+
if (kotlin.math.abs(velocityX) < flingVelocity) return fromDrag
|
|
89
|
+
val fromFling = if (velocityX < 0f) Direction.NEXT else Direction.PREVIOUS
|
|
90
|
+
val dragOpposes = (fromFling == Direction.NEXT && dragX > 0f) ||
|
|
91
|
+
(fromFling == Direction.PREVIOUS && dragX < 0f)
|
|
92
|
+
return if (dragOpposes) null else fromFling
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The turn a hardware key (keyboard or page-turner pedal) asks for, or
|
|
97
|
+
* null to leave the key alone. Right, Down and Page Down go forward; Left,
|
|
98
|
+
* Up and Page Up go back; Space isn't mapped. Keys turn whatever the zoom
|
|
99
|
+
* or markup mode, but never while a text input has focus, and never with
|
|
100
|
+
* a modifier held.
|
|
101
|
+
*/
|
|
102
|
+
fun keyTurnFor(keyCode: Int, textInputHasFocus: Boolean, hasModifiers: Boolean): Direction? {
|
|
103
|
+
if (textInputHasFocus || hasModifiers) return null
|
|
104
|
+
return when (keyCode) {
|
|
105
|
+
KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_PAGE_DOWN ->
|
|
106
|
+
Direction.NEXT
|
|
107
|
+
|
|
108
|
+
KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_PAGE_UP ->
|
|
109
|
+
Direction.PREVIOUS
|
|
110
|
+
|
|
111
|
+
else -> null
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fun swipeActionFor(annotationMode: String, scale: Float): SwipeAction =
|
|
116
|
+
if (touchCanTurn(annotationMode, scale)) SwipeAction.TURN else SwipeAction.PAN
|
|
117
|
+
}
|