@onekeyfe/react-native-image-crop-picker 6.7.0-5 → 6.7.0-51
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/README.md +109 -101
- package/lib/module/index.js +2 -14
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +203 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/module/shared.js +19 -0
- package/lib/module/shared.js.map +1 -0
- package/lib/module/web/CropperView.js +570 -0
- package/lib/module/web/CropperView.js.map +1 -0
- package/lib/module/web/geometry.js +189 -0
- package/lib/module/web/geometry.js.map +1 -0
- package/lib/module/web/imageFormat.js +60 -0
- package/lib/module/web/imageFormat.js.map +1 -0
- package/lib/module/web/imageIO.js +153 -0
- package/lib/module/web/imageIO.js.map +1 -0
- package/lib/module/web/theme.js +98 -0
- package/lib/module/web/theme.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -17
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +18 -0
- package/lib/typescript/src/index.web.d.ts.map +1 -0
- package/lib/typescript/src/shared.d.ts +18 -0
- package/lib/typescript/src/shared.d.ts.map +1 -0
- package/lib/typescript/src/web/CropperView.d.ts +16 -0
- package/lib/typescript/src/web/CropperView.d.ts.map +1 -0
- package/lib/typescript/src/web/geometry.d.ts +53 -0
- package/lib/typescript/src/web/geometry.d.ts.map +1 -0
- package/lib/typescript/src/web/imageFormat.d.ts +3 -0
- package/lib/typescript/src/web/imageFormat.d.ts.map +1 -0
- package/lib/typescript/src/web/imageIO.d.ts +15 -0
- package/lib/typescript/src/web/imageIO.d.ts.map +1 -0
- package/lib/typescript/src/web/theme.d.ts +37 -0
- package/lib/typescript/src/web/theme.d.ts.map +1 -0
- package/package.json +13 -8
- package/src/index.tsx +16 -49
- package/src/index.web.tsx +288 -0
- package/src/shared.ts +51 -0
- package/src/web/CropperView.ts +725 -0
- package/src/web/geometry.ts +285 -0
- package/src/web/imageFormat.ts +63 -0
- package/src/web/imageIO.ts +178 -0
- package/src/web/theme.ts +130 -0
package/README.md
CHANGED
|
@@ -1,40 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Single photo picker and cropper for OneKey, built on [Nitro Modules](https://nitro.margelo.com/). It replaces `react-native-image-crop-picker` and keeps the part of its API that OneKey uses: `openPicker`, `openCropper`, `clean`, `cleanSingle`, and the `E_*` error codes.
|
|
4
|
-
|
|
5
|
-
Picking never asks for photo library permission:
|
|
1
|
+
<div align="center">
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
- **Android** picks with the system Photo Picker (`ActivityResultContracts.PickVisualMedia`, which falls back to `ACTION_OPEN_DOCUMENT` on devices without it). The crop gestures come from uCrop `2.2.11-native`'s `UCropView`. Activity results go through the activity's `ActivityResultRegistry`, so no `ActivityEventListener` is needed.
|
|
9
|
-
|
|
10
|
-
Both platforms show the same cropper screen, drawn by this package rather than by TOCropViewController or uCrop. See [Cropper screen](#cropper-screen).
|
|
3
|
+
# @onekeyfe/react-native-image-crop-picker
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
**Pick one photo and crop it with one API on iOS, Android and the web — without photo-library permission.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-image-crop-picker)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
A single-photo picker and cropper for OneKey, replacing the parts of
|
|
17
|
+
`react-native-image-crop-picker` that OneKey uses: `openPicker`, `openCropper`,
|
|
18
|
+
`clean`, `cleanSingle` and the `E_*` error codes. iOS picks with
|
|
19
|
+
`PHPickerViewController`, Android with the system Photo Picker, and the browser
|
|
20
|
+
with a file input, so no platform asks for photo-library permission. The cropper
|
|
21
|
+
is a screen drawn by this package, identical on iOS and Android, with a DOM
|
|
22
|
+
equivalent on the web. Photo saving and its authorization belong to
|
|
23
|
+
`@onekeyfe/react-native-photo-library`; this package exposes no save API.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **No photo-library prompt** — picking grants access only to the selected
|
|
28
|
+
item, so a denied library permission can no longer break the picker.
|
|
29
|
+
- **One shared cropper** — the same header, crop box, dimmed background,
|
|
30
|
+
rotate control and footer on iOS and Android; the same layout on the web with
|
|
31
|
+
zoom and keyboard input for mouse users.
|
|
32
|
+
- **Optional cropping or original bytes** — `cropping: true` returns a JPEG at
|
|
33
|
+
the requested size; `preserveOriginal: true` copies the selected
|
|
34
|
+
representation untouched when cropping is off.
|
|
35
|
+
- **Explicit cleanup** — results live in the module's temporary directory until
|
|
36
|
+
the caller runs `clean()` or `cleanSingle()`.
|
|
37
|
+
- **Typed failures** — every rejection is an `ImageCropPickerError` with a
|
|
38
|
+
stable `E_*` code.
|
|
13
39
|
|
|
14
|
-
##
|
|
40
|
+
## Installation
|
|
15
41
|
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
// Read the selected file before cleaning it.
|
|
19
|
-
await ImageCropPicker.cleanSingle(image.path);
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @onekeyfe/react-native-image-crop-picker react-native-nitro-modules
|
|
20
44
|
```
|
|
21
45
|
|
|
22
|
-
|
|
23
|
-
Compression options are ignored unless cropping is enabled. Originals are limited
|
|
24
|
-
to 64 MiB. Saving and its authorization are provided by the separate
|
|
25
|
-
`@onekeyfe/react-native-photo-library`; this picker exposes neither saving nor
|
|
26
|
-
photo-library permission APIs.
|
|
27
|
-
|
|
28
|
-
## Installation
|
|
46
|
+
Install the native peer packages this package links as well:
|
|
29
47
|
|
|
30
48
|
```sh
|
|
31
|
-
yarn add @onekeyfe/react-native-
|
|
49
|
+
yarn add @onekeyfe/react-native-native-logger
|
|
32
50
|
```
|
|
33
51
|
|
|
34
|
-
To keep existing `react-native-image-crop-picker` imports working, install it
|
|
52
|
+
To keep existing `react-native-image-crop-picker` imports working, install it
|
|
53
|
+
under an npm alias: `react-native-image-crop-picker@npm:@onekeyfe/react-native-image-crop-picker`.
|
|
54
|
+
Install the application's iOS pods and rebuild the native binary; the web entry
|
|
55
|
+
needs no native code.
|
|
35
56
|
|
|
36
|
-
- **iOS**: do not also install the `TOCropViewController` pod. This package
|
|
37
|
-
|
|
57
|
+
- **iOS**: do not also install the `TOCropViewController` pod. This package
|
|
58
|
+
compiles its own copy and duplicate classes clash at link time.
|
|
59
|
+
- **Android**: uCrop is published only to JitPack, so add
|
|
60
|
+
`maven { url "https://www.jitpack.io" }` to the app's `allprojects.repositories`.
|
|
38
61
|
|
|
39
62
|
## Usage
|
|
40
63
|
|
|
@@ -51,7 +74,7 @@ try {
|
|
|
51
74
|
includeBase64: true,
|
|
52
75
|
compressImageQuality: 0.8,
|
|
53
76
|
});
|
|
54
|
-
// image.path is a file:// URI
|
|
77
|
+
// image.path is a file:// URI (blob: URL on the web).
|
|
55
78
|
} catch (error) {
|
|
56
79
|
if (error instanceof ImageCropPickerError && error.code === 'E_PICKER_CANCELLED') {
|
|
57
80
|
return;
|
|
@@ -66,80 +89,65 @@ const cropped = await ImageCropPicker.openCropper({
|
|
|
66
89
|
});
|
|
67
90
|
```
|
|
68
91
|
|
|
69
|
-
`openCropper` accepts `file://` URIs, absolute paths, `http(s)://` URLs,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
Multiple selection, video, the camera and `includeExif` are not implemented. `mediaType`, `forceJpg` and `sortOrder` are accepted for source compatibility and ignored.
|
|
127
|
-
|
|
128
|
-
## Error codes
|
|
129
|
-
|
|
130
|
-
| Code | Meaning |
|
|
131
|
-
| --- | --- |
|
|
132
|
-
| `E_PICKER_CANCELLED` | The user closed the picker or the cropper. |
|
|
133
|
-
| `E_PICKER_IN_PROGRESS` | Another picker or cropper is still open. |
|
|
134
|
-
| `E_ACTIVITY_DOES_NOT_EXIST` | Android: no current activity. |
|
|
135
|
-
| `E_FAILED_TO_SHOW_PICKER` | The picker or cropper could not be presented. |
|
|
136
|
-
| `E_NO_IMAGE_DATA_FOUND` | The selected item could not be read as an image. |
|
|
137
|
-
| `E_CROPPER_IMAGE_NOT_FOUND` | `openCropper` could not load `path`. |
|
|
138
|
-
| `E_CANNOT_SAVE_IMAGE` | The result could not be written. |
|
|
139
|
-
| `E_LOW_MEMORY_ERROR` | Android: out of memory while processing. |
|
|
140
|
-
| `E_ERROR_WHILE_CLEANING_FILES` | `clean` or `cleanSingle` failed. |
|
|
141
|
-
| `E_UNKNOWN` | Any other native error. |
|
|
92
|
+
`openCropper` accepts `file://` URIs, absolute paths, `http(s)://` URLs,
|
|
93
|
+
`data:` URIs and, on Android, `content://` URIs. Read or save a result before
|
|
94
|
+
cleaning it; only one picker or cropper can be open per app.
|
|
95
|
+
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
| Method | Result | Platforms | Description |
|
|
99
|
+
| --- | --- | :-: | --- |
|
|
100
|
+
| `openPicker(options?)` | `Promise<Image>` | iOS, Android, Web | Picks one photo, optionally connected to the cropper. |
|
|
101
|
+
| `openCropper({ path, ...options })` | `Promise<Image>` | iOS, Android, Web | Crops an existing image and returns a JPEG. |
|
|
102
|
+
| `clean()` | `Promise<void>` | iOS, Android, Web | Deletes every file this module wrote. |
|
|
103
|
+
| `cleanSingle(path)` | `Promise<void>` | iOS, Android, Web | Deletes one file returned by this module. |
|
|
104
|
+
| `ImageCropPickerError` | `Error` subclass with `code` | iOS, Android, Web | Rejection type for all operations. |
|
|
105
|
+
| `Image` | `{ path, size, width, height, mime, data?, cropRect?, filename? }` | iOS, Android, Web | Pick/crop result; `data` is base64 without a `data:` prefix. |
|
|
106
|
+
|
|
107
|
+
Cropping uses `width`/`height` as both the target size and the aspect ratio;
|
|
108
|
+
`freeStyleCropEnabled` lets the box keep its own ratio and fit inside that size.
|
|
109
|
+
`compressImageMaxWidth`, `compressImageMaxHeight` and `compressImageQuality`
|
|
110
|
+
apply after cropping. `cropperAppearance`, `cropperToolbarTitle`,
|
|
111
|
+
`cropperChooseText`, `cropperCancelText`, `cropperRotateButtonsHidden` and
|
|
112
|
+
`showCropGuidelines` style the cropper. See
|
|
113
|
+
[`src/ReactNativeImageCropPicker.nitro.ts`](src/ReactNativeImageCropPicker.nitro.ts)
|
|
114
|
+
for every option and [`src/shared.ts`](src/shared.ts) for the full error-code list.
|
|
115
|
+
|
|
116
|
+
## Platform support
|
|
117
|
+
|
|
118
|
+
| Capability | iOS | Android | Web |
|
|
119
|
+
| --- | :-: | :-: | :-: |
|
|
120
|
+
| Pick one photo without library permission | ✅ PHPicker | ✅ Photo Picker | ✅ file input |
|
|
121
|
+
| Interactive cropper | ✅ | ✅ | ✅ DOM |
|
|
122
|
+
| `preserveOriginal` (byte-for-byte copy) | ✅ | ✅ | ✅ |
|
|
123
|
+
| Native Nitro module | ✅ | ✅ | — |
|
|
124
|
+
| `freeStyleCropEnabled` | ✅ | ✅ | — |
|
|
125
|
+
|
|
126
|
+
## Caveats
|
|
127
|
+
|
|
128
|
+
> [!NOTE]
|
|
129
|
+
> Cancelling the cropper that `openPicker` opened returns to the photo picker on
|
|
130
|
+
> iOS but rejects with `E_PICKER_CANCELLED` on Android and the web. A second
|
|
131
|
+
> picker or cropper while one is open rejects with `E_PICKER_IN_PROGRESS`.
|
|
132
|
+
|
|
133
|
+
> [!WARNING]
|
|
134
|
+
> On the web, `freeStyleCropEnabled` is not implemented, `path` is a `blob:` URL
|
|
135
|
+
> that `clean()` revokes, and `http(s)` sources for `openCropper` must allow CORS
|
|
136
|
+
> or the crop rejects with `E_CANNOT_SAVE_IMAGE`.
|
|
137
|
+
|
|
138
|
+
> [!IMPORTANT]
|
|
139
|
+
> A picker result proves access to that one item only — never photo-library
|
|
140
|
+
> authorization. Results are temporary files owned by the caller; do not clean a
|
|
141
|
+
> file while a scan or save still reads it.
|
|
142
|
+
|
|
143
|
+
## References
|
|
144
|
+
|
|
145
|
+
- [Package spec](docs/SPEC.md)
|
|
146
|
+
- [Native interface](src/ReactNativeImageCropPicker.nitro.ts)
|
|
147
|
+
- [Example page](../../example/react-native/pages/ImageCropPickerTestPage.tsx)
|
|
148
|
+
- [Changelog](../../CHANGELOG.md)
|
|
142
149
|
|
|
143
150
|
## License
|
|
144
151
|
|
|
145
|
-
MIT. The vendored TOCropViewController in
|
|
152
|
+
MIT. See [LICENSE](LICENSE). The vendored TOCropViewController in
|
|
153
|
+
`ios/TOCropViewController` is MIT licensed by Tim Oliver; see its `LICENSE`.
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
import { ERROR_CODES, ImageCropPickerError } from "./shared.js";
|
|
5
|
+
export { ImageCropPickerError } from "./shared.js";
|
|
4
6
|
// Created on first use so importing this module costs nothing at startup.
|
|
5
7
|
let hybridObject;
|
|
6
8
|
export function getReactNativeImageCropPicker() {
|
|
@@ -9,16 +11,6 @@ export function getReactNativeImageCropPicker() {
|
|
|
9
11
|
}
|
|
10
12
|
return hybridObject;
|
|
11
13
|
}
|
|
12
|
-
const ERROR_CODES = ['E_PICKER_CANCELLED', 'E_PICKER_IN_PROGRESS', 'E_ACTIVITY_DOES_NOT_EXIST', 'E_FAILED_TO_SHOW_PICKER', 'E_NO_IMAGE_DATA_FOUND', 'E_CROPPER_IMAGE_NOT_FOUND', 'E_CANNOT_SAVE_IMAGE', 'E_LOW_MEMORY_ERROR', 'E_ERROR_WHILE_CLEANING_FILES'];
|
|
13
|
-
// Rejections carry the same `code` values as react-native-image-crop-picker,
|
|
14
|
-
// e.g. `E_PICKER_CANCELLED` when the user dismisses the picker or cropper.
|
|
15
|
-
export class ImageCropPickerError extends Error {
|
|
16
|
-
constructor(code, message) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = 'ImageCropPickerError';
|
|
19
|
-
this.code = code;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
14
|
function isErrorCode(value) {
|
|
23
15
|
return ERROR_CODES.includes(value);
|
|
24
16
|
}
|
|
@@ -38,10 +30,6 @@ function toImageCropPickerError(error) {
|
|
|
38
30
|
}
|
|
39
31
|
return new ImageCropPickerError('E_UNKNOWN', message.split('\n')[0] ?? message);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
// Options accepted for source compatibility with react-native-image-crop-picker.
|
|
43
|
-
// Only single photos are supported; processed results are JPEG.
|
|
44
|
-
|
|
45
33
|
export async function openPicker(options = {}) {
|
|
46
34
|
try {
|
|
47
35
|
return await getReactNativeImageCropPicker().openPicker(options);
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","
|
|
1
|
+
{"version":3,"names":["NitroModules","ERROR_CODES","ImageCropPickerError","hybridObject","getReactNativeImageCropPicker","createHybridObject","isErrorCode","value","includes","NATIVE_ERROR_PATTERN","toImageCropPickerError","error","message","Error","String","match","exec","trim","split","openPicker","options","openCropper","path","clean","cleanSingle","ImageCropPicker"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAIzD,SACEC,WAAW,EACXC,oBAAoB,QAIf,aAAU;AAGjB,SAASA,oBAAoB,QAAQ,aAAU;AAQ/C;AACA,IAAIC,YAAwD;AAE5D,OAAO,SAASC,6BAA6BA,CAAA,EAAmC;EAC9E,IAAI,CAACD,YAAY,EAAE;IACjBA,YAAY,GACVH,YAAY,CAACK,kBAAkB,CAC7B,4BACF,CAAC;EACL;EACA,OAAOF,YAAY;AACrB;AAEA,SAASG,WAAWA,CAACC,KAAa,EAAyC;EACzE,OAAQN,WAAW,CAAuBO,QAAQ,CAACD,KAAK,CAAC;AAC3D;;AAEA;AACA;AACA;AACA,MAAME,oBAAoB,GAAG,qBAAqB;AAElD,SAASC,sBAAsBA,CAACC,KAAc,EAAwB;EACpE,IAAIA,KAAK,YAAYT,oBAAoB,EAAE;IACzC,OAAOS,KAAK;EACd;EACA,MAAMC,OAAO,GAAGD,KAAK,YAAYE,KAAK,GAAGF,KAAK,CAACC,OAAO,GAAGE,MAAM,CAACH,KAAK,CAAC;EACtE,MAAMI,KAAK,GAAGN,oBAAoB,CAACO,IAAI,CAACJ,OAAO,CAAC;EAChD,IAAIG,KAAK,GAAG,CAAC,CAAC,IAAIT,WAAW,CAACS,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIb,oBAAoB,CAACa,KAAK,CAAC,CAAC,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,EAAEE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;EACnE;EACA,OAAO,IAAIf,oBAAoB,CAC7B,WAAW,EACXU,OAAO,CAACM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAIN,OAC5B,CAAC;AACH;AAEA,OAAO,eAAeO,UAAUA,CAACC,OAAgB,GAAG,CAAC,CAAC,EAAkB;EACtE,IAAI;IACF,OAAO,MAAMhB,6BAA6B,CAAC,CAAC,CAACe,UAAU,CAACC,OAAO,CAAC;EAClE,CAAC,CAAC,OAAOT,KAAK,EAAE;IACd,MAAMD,sBAAsB,CAACC,KAAK,CAAC;EACrC;AACF;AAEA,OAAO,eAAeU,WAAWA,CAAC;EAChCC,IAAI;EACJ,GAAGF;AACW,CAAC,EAAkB;EACjC,IAAI;IACF,OAAO,MAAMhB,6BAA6B,CAAC,CAAC,CAACiB,WAAW,CAACC,IAAI,EAAEF,OAAO,CAAC;EACzE,CAAC,CAAC,OAAOT,KAAK,EAAE;IACd,MAAMD,sBAAsB,CAACC,KAAK,CAAC;EACrC;AACF;AAEA,OAAO,eAAeY,KAAKA,CAAA,EAAkB;EAC3C,IAAI;IACF,MAAMnB,6BAA6B,CAAC,CAAC,CAACmB,KAAK,CAAC,CAAC;EAC/C,CAAC,CAAC,OAAOZ,KAAK,EAAE;IACd,MAAMD,sBAAsB,CAACC,KAAK,CAAC;EACrC;AACF;AAEA,OAAO,eAAea,WAAWA,CAACF,IAAY,EAAiB;EAC7D,IAAI;IACF,MAAMlB,6BAA6B,CAAC,CAAC,CAACoB,WAAW,CAACF,IAAI,CAAC;EACzD,CAAC,CAAC,OAAOX,KAAK,EAAE;IACd,MAAMD,sBAAsB,CAACC,KAAK,CAAC;EACrC;AACF;AAEA,MAAMc,eAAe,GAAG;EACtBN,UAAU;EACVE,WAAW;EACXE,KAAK;EACLC;AACF,CAAC;AAED,eAAeC,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/// <reference lib="dom" />
|
|
4
|
+
import { ImageCropPickerError } from "./shared.js";
|
|
5
|
+
import { cropRectOf, outputSizeOf, shrinkToFit } from "./web/geometry.js";
|
|
6
|
+
import { MAX_INPUT_BYTES, RESULT_MIME, blobToBase64, createResultUrl, imageSizeOf, loadImage, normalizeQuality, readImageHeader, releaseAllResultUrls, releaseResultUrl, renderCrop, renderWhole } from "./web/imageIO.js";
|
|
7
|
+
import { presentCropper } from "./web/CropperView.js";
|
|
8
|
+
import { detectImageMime } from "./web/imageFormat.js";
|
|
9
|
+
export { ImageCropPickerError } from "./shared.js";
|
|
10
|
+
// Web entry: the same API and results as the native module. The picker is a
|
|
11
|
+
// file input, the cropper is drawn with the DOM (web/CropperView.ts), and
|
|
12
|
+
// result paths are blob: URLs that clean/cleanSingle revoke.
|
|
13
|
+
|
|
14
|
+
export function getReactNativeImageCropPicker() {
|
|
15
|
+
throw new ImageCropPickerError('E_UNKNOWN', 'The Nitro hybrid object is not available on the web');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// One picker or cropper at a time, like native.
|
|
19
|
+
let busy = false;
|
|
20
|
+
async function exclusive(task) {
|
|
21
|
+
if (busy) {
|
|
22
|
+
throw new ImageCropPickerError('E_PICKER_IN_PROGRESS', 'Another picker or cropper is still open');
|
|
23
|
+
}
|
|
24
|
+
busy = true;
|
|
25
|
+
try {
|
|
26
|
+
return await task();
|
|
27
|
+
} finally {
|
|
28
|
+
busy = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function assertDocument() {
|
|
32
|
+
if (typeof document === 'undefined' || !document.body) {
|
|
33
|
+
throw new ImageCropPickerError('E_FAILED_TO_SHOW_PICKER', 'No document to show the picker in');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function cancelledError() {
|
|
37
|
+
return new ImageCropPickerError('E_PICKER_CANCELLED', 'User cancelled image selection');
|
|
38
|
+
}
|
|
39
|
+
function targetSizeOf(options) {
|
|
40
|
+
const {
|
|
41
|
+
width,
|
|
42
|
+
height
|
|
43
|
+
} = options;
|
|
44
|
+
if (width && height && width > 0 && height > 0) {
|
|
45
|
+
return {
|
|
46
|
+
width,
|
|
47
|
+
height
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
function chooseFile() {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const input = document.createElement('input');
|
|
55
|
+
input.type = 'file';
|
|
56
|
+
input.accept = 'image/*';
|
|
57
|
+
input.style.display = 'none';
|
|
58
|
+
let settled = false;
|
|
59
|
+
const finish = file => {
|
|
60
|
+
if (settled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
settled = true;
|
|
64
|
+
window.removeEventListener('focus', onWindowFocus);
|
|
65
|
+
input.remove();
|
|
66
|
+
if (file) {
|
|
67
|
+
resolve(file);
|
|
68
|
+
} else {
|
|
69
|
+
reject(cancelledError());
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// Browsers without the input `cancel` event only report a dismissed
|
|
73
|
+
// chooser by giving focus back; `change` arrives first when a file was
|
|
74
|
+
// picked.
|
|
75
|
+
const onWindowFocus = () => {
|
|
76
|
+
setTimeout(() => finish(input.files?.[0]), 1000);
|
|
77
|
+
};
|
|
78
|
+
input.addEventListener('change', () => finish(input.files?.[0]));
|
|
79
|
+
input.addEventListener('cancel', () => finish(undefined));
|
|
80
|
+
if (!('oncancel' in input)) {
|
|
81
|
+
window.addEventListener('focus', onWindowFocus);
|
|
82
|
+
}
|
|
83
|
+
document.body.appendChild(input);
|
|
84
|
+
input.click();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function decodeFile(file) {
|
|
88
|
+
if (file.size > MAX_INPUT_BYTES) {
|
|
89
|
+
throw new ImageCropPickerError('E_NO_IMAGE_DATA_FOUND', 'The selected image is larger than 64 MiB');
|
|
90
|
+
}
|
|
91
|
+
const url = URL.createObjectURL(file);
|
|
92
|
+
try {
|
|
93
|
+
return await loadImage(url);
|
|
94
|
+
} catch {
|
|
95
|
+
URL.revokeObjectURL(url);
|
|
96
|
+
throw new ImageCropPickerError('E_NO_IMAGE_DATA_FOUND', 'The selected file is not a readable image');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// `mime` always describes the bytes in `blob`: RESULT_MIME for everything this
|
|
101
|
+
// module encodes, the sniffed format for a preserved original.
|
|
102
|
+
async function makeResult(blob, size, mime, options, extra) {
|
|
103
|
+
return {
|
|
104
|
+
path: createResultUrl(blob),
|
|
105
|
+
size: blob.size,
|
|
106
|
+
width: size.width,
|
|
107
|
+
height: size.height,
|
|
108
|
+
mime,
|
|
109
|
+
data: options.includeBase64 ? await blobToBase64(blob) : undefined,
|
|
110
|
+
...extra
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function crop(image, options, filename) {
|
|
114
|
+
const targetSize = targetSizeOf(options);
|
|
115
|
+
const quality = normalizeQuality(options.compressImageQuality);
|
|
116
|
+
return presentCropper({
|
|
117
|
+
image,
|
|
118
|
+
aspectRatio: targetSize ? targetSize.width / targetSize.height : undefined,
|
|
119
|
+
title: options.cropperToolbarTitle,
|
|
120
|
+
cancelText: options.cropperCancelText,
|
|
121
|
+
confirmText: options.cropperChooseText,
|
|
122
|
+
rotateButtonHidden: options.cropperRotateButtonsHidden,
|
|
123
|
+
showGuidelines: options.showCropGuidelines,
|
|
124
|
+
circular: options.cropperCircleOverlay,
|
|
125
|
+
appearance: options.cropperAppearance
|
|
126
|
+
}, async (state, box) => {
|
|
127
|
+
const cropRect = cropRectOf(state, imageSizeOf(image), box);
|
|
128
|
+
const output = outputSizeOf(cropRect, {
|
|
129
|
+
targetSize,
|
|
130
|
+
maxWidth: options.compressImageMaxWidth,
|
|
131
|
+
maxHeight: options.compressImageMaxHeight
|
|
132
|
+
});
|
|
133
|
+
const blob = await renderCrop(image, state, box, output, quality);
|
|
134
|
+
return makeResult(blob, output, RESULT_MIME, options, {
|
|
135
|
+
cropRect,
|
|
136
|
+
filename
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function pickWithoutCropping(file, image, options) {
|
|
141
|
+
const size = imageSizeOf(image);
|
|
142
|
+
if (options.preserveOriginal) {
|
|
143
|
+
// The selected file as is; compression options are ignored. Its type
|
|
144
|
+
// comes from its bytes: `File.type` is only a guess from the name and can
|
|
145
|
+
// be empty or wrong.
|
|
146
|
+
const mime = detectImageMime(await readImageHeader(file));
|
|
147
|
+
if (!mime) {
|
|
148
|
+
throw new ImageCropPickerError('E_NO_IMAGE_DATA_FOUND', 'The selected file is not a recognized image format');
|
|
149
|
+
}
|
|
150
|
+
return makeResult(file, size, mime, options, {
|
|
151
|
+
filename: file.name
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const output = shrinkToFit(outputSizeOf(size, {}), options.compressImageMaxWidth, options.compressImageMaxHeight);
|
|
155
|
+
const blob = await renderWhole(image, output, normalizeQuality(options.compressImageQuality));
|
|
156
|
+
return makeResult(blob, output, RESULT_MIME, options, {
|
|
157
|
+
filename: file.name
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
export function openPicker(options = {}) {
|
|
161
|
+
return exclusive(async () => {
|
|
162
|
+
assertDocument();
|
|
163
|
+
const file = await chooseFile();
|
|
164
|
+
const image = await decodeFile(file);
|
|
165
|
+
try {
|
|
166
|
+
return options.cropping ? await crop(image, options, file.name) : await pickWithoutCropping(file, image, options);
|
|
167
|
+
} finally {
|
|
168
|
+
URL.revokeObjectURL(image.src);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export function openCropper({
|
|
173
|
+
path,
|
|
174
|
+
...options
|
|
175
|
+
}) {
|
|
176
|
+
return exclusive(async () => {
|
|
177
|
+
assertDocument();
|
|
178
|
+
if (!path) {
|
|
179
|
+
throw new ImageCropPickerError('E_CROPPER_IMAGE_NOT_FOUND', 'No image path to crop');
|
|
180
|
+
}
|
|
181
|
+
let image;
|
|
182
|
+
try {
|
|
183
|
+
image = await loadImage(path);
|
|
184
|
+
} catch {
|
|
185
|
+
throw new ImageCropPickerError('E_CROPPER_IMAGE_NOT_FOUND', 'Cannot load the image to crop');
|
|
186
|
+
}
|
|
187
|
+
return crop(image, options, undefined);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
export async function clean() {
|
|
191
|
+
releaseAllResultUrls();
|
|
192
|
+
}
|
|
193
|
+
export async function cleanSingle(path) {
|
|
194
|
+
releaseResultUrl(path);
|
|
195
|
+
}
|
|
196
|
+
const ImageCropPicker = {
|
|
197
|
+
openPicker,
|
|
198
|
+
openCropper,
|
|
199
|
+
clean,
|
|
200
|
+
cleanSingle
|
|
201
|
+
};
|
|
202
|
+
export default ImageCropPicker;
|
|
203
|
+
//# sourceMappingURL=index.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ImageCropPickerError","cropRectOf","outputSizeOf","shrinkToFit","MAX_INPUT_BYTES","RESULT_MIME","blobToBase64","createResultUrl","imageSizeOf","loadImage","normalizeQuality","readImageHeader","releaseAllResultUrls","releaseResultUrl","renderCrop","renderWhole","presentCropper","detectImageMime","getReactNativeImageCropPicker","busy","exclusive","task","assertDocument","document","body","cancelledError","targetSizeOf","options","width","height","undefined","chooseFile","Promise","resolve","reject","input","createElement","type","accept","style","display","settled","finish","file","window","removeEventListener","onWindowFocus","remove","setTimeout","files","addEventListener","appendChild","click","decodeFile","size","url","URL","createObjectURL","revokeObjectURL","makeResult","blob","mime","extra","path","data","includeBase64","crop","image","filename","targetSize","quality","compressImageQuality","aspectRatio","title","cropperToolbarTitle","cancelText","cropperCancelText","confirmText","cropperChooseText","rotateButtonHidden","cropperRotateButtonsHidden","showGuidelines","showCropGuidelines","circular","cropperCircleOverlay","appearance","cropperAppearance","state","box","cropRect","output","maxWidth","compressImageMaxWidth","maxHeight","compressImageMaxHeight","pickWithoutCropping","preserveOriginal","name","openPicker","cropping","src","openCropper","clean","cleanSingle","ImageCropPicker"],"sourceRoot":"../../src","sources":["index.web.tsx"],"mappings":";;AAAA;AACA,SAASA,oBAAoB,QAAQ,aAAU;AAC/C,SAASC,UAAU,EAAEC,YAAY,EAAEC,WAAW,QAAQ,mBAAgB;AACtE,SACEC,eAAe,EACfC,WAAW,EAC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B,EAC3B,uBACF,CAAC;IACH;IACA,IAAImE,KAAuB;IAC3B,IAAI;MACFA,KAAK,GAAG,MAAM1D,SAAS,CAACsD,IAAI,CAAC;IAC/B,CAAC,CAAC,MAAM;MACN,MAAM,IAAI/D,oBAAoB,CAC5B,2BAA2B,EAC3B,+BACF,CAAC;IACH;IACA,OAAOkE,IAAI,CAACC,KAAK,EAAExC,OAAO,EAAEG,SAAS,CAAC;EACxC,CAAC,CAAC;AACJ;AAEA,OAAO,eAAewE,KAAKA,CAAA,EAAkB;EAC3C1F,oBAAoB,CAAC,CAAC;AACxB;AAEA,OAAO,eAAe2F,WAAWA,CAACxC,IAAY,EAAiB;EAC7DlD,gBAAgB,CAACkD,IAAI,CAAC;AACxB;AAEA,MAAMyC,eAAe,GAAG;EACtBN,UAAU;EACVG,WAAW;EACXC,KAAK;EACLC;AACF,CAAC;AAED,eAAeC,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Shared by the native and web entry points, so both reject with the same
|
|
4
|
+
// error class and accept the same options.
|
|
5
|
+
|
|
6
|
+
export const ERROR_CODES = ['E_PICKER_CANCELLED', 'E_PICKER_IN_PROGRESS', 'E_ACTIVITY_DOES_NOT_EXIST', 'E_FAILED_TO_SHOW_PICKER', 'E_NO_IMAGE_DATA_FOUND', 'E_CROPPER_IMAGE_NOT_FOUND', 'E_CANNOT_SAVE_IMAGE', 'E_LOW_MEMORY_ERROR', 'E_ERROR_WHILE_CLEANING_FILES'];
|
|
7
|
+
// Rejections carry the same `code` values as react-native-image-crop-picker,
|
|
8
|
+
// e.g. `E_PICKER_CANCELLED` when the user dismisses the picker or cropper.
|
|
9
|
+
export class ImageCropPickerError extends Error {
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'ImageCropPickerError';
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Options accepted for source compatibility with react-native-image-crop-picker.
|
|
18
|
+
// Only single photos are supported; processed results are JPEG.
|
|
19
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ERROR_CODES","ImageCropPickerError","Error","constructor","code","message","name"],"sourceRoot":"../../src","sources":["shared.ts"],"mappings":";;AAKA;AACA;;AAEA,OAAO,MAAMA,WAAW,GAAG,CACzB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,8BAA8B,CACtB;AAMV;AACA;AACA,OAAO,MAAMC,oBAAoB,SAASC,KAAK,CAAC;EAG9CC,WAAWA,CAACC,IAA8B,EAAEC,OAAe,EAAE;IAC3D,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,sBAAsB;IAClC,IAAI,CAACF,IAAI,GAAGA,IAAI;EAClB;AACF;;AAEA;AACA","ignoreList":[]}
|