@onekeyfe/react-native-image-crop-picker 6.7.0-alpha.418 → 6.7.0-alpha.422
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 +12 -3
- 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 +6 -2
- 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
|
@@ -7,7 +7,9 @@ Picking never asks for photo library permission:
|
|
|
7
7
|
- **iOS** picks with `PHPickerViewController`, which runs out of process. `react-native-image-crop-picker` requested full photo library access first. Once a user denied it, iOS never showed the prompt again and every later `openPicker` call failed silently (OK-48227). The crop gestures come from a vendored TOCropViewController 3.2.0 `TOCropView`, with the OK-51551 rotation fix that upstream still lacks.
|
|
8
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
9
|
|
|
10
|
-
|
|
10
|
+
- **Web** (browsers, Electron and browser extensions) picks with an `<input type="file">` and crops with a DOM cropper, with no Nitro or native code. Bundlers select it through the `browser` export condition (`lib/module/index.web.js`).
|
|
11
|
+
|
|
12
|
+
All platforms show the same cropper screen, drawn by this package rather than by TOCropViewController, uCrop or a web cropper library. See [Cropper screen](#cropper-screen).
|
|
11
13
|
|
|
12
14
|
The behavioral contract and pending acceptance cases are in [docs/SPEC.md](docs/SPEC.md).
|
|
13
15
|
|
|
@@ -76,6 +78,12 @@ The cropper is a full-screen page with the same layout and metrics on iOS and An
|
|
|
76
78
|
- The crop area. The crop box keeps 20 pt from every edge, and the image outside it shows the page background at 70% opacity. The rule-of-thirds grid shows while the image is moved, unless `showCropGuidelines` is `false`.
|
|
77
79
|
- A footer with two capsule buttons, `cropperCancelText` and `cropperChooseText`, 50 pt tall with 10 pt between them. The confirm button shows a spinner while the image is saved.
|
|
78
80
|
|
|
81
|
+
On the web the same screen is full screen on windows narrower than 640 px or shorter than 560 px, and a centered 560 × 760 px panel (smaller when the window is) otherwise. The header, crop area, toolbar and footer are a flex column, so the buttons always stay inside the panel. The web screen adds, for mouse and keyboard users:
|
|
82
|
+
|
|
83
|
+
- A toolbar under the crop area: zoom out, a zoom slider, zoom in, and reset.
|
|
84
|
+
- Wheel to zoom around the pointer (trackpad pinch included), double click to zoom in 2× or back out, and two-finger pinch on touch screens.
|
|
85
|
+
- Keyboard: arrow keys move the image (Shift for larger steps), `+` / `-` zoom, `R` rotates, Enter confirms and Escape cancels. Focus stays inside the cropper and returns to the previous element when it closes.
|
|
86
|
+
|
|
79
87
|
`cropperAppearance` sets its colors and fonts. The optional font-family fields
|
|
80
88
|
below require the app to provide these Roobert faces and own the applicable
|
|
81
89
|
font license; this package contains no font files. Omit the fields to use
|
|
@@ -106,7 +114,7 @@ await ImageCropPicker.openPicker({
|
|
|
106
114
|
| `iconColor` | The rotate button. |
|
|
107
115
|
| `cancelButtonColor`, `cancelButtonPressedColor`, `cancelButtonTextColor` | The cancel button. |
|
|
108
116
|
| `confirmButtonColor`, `confirmButtonPressedColor`, `confirmButtonTextColor` | The confirm button. |
|
|
109
|
-
| `titleFontFamily`, `buttonFontFamily` | Fonts bundled with the app. iOS looks them up with `UIFont(name:)`, Android with React Native's `ReactFontManager`. |
|
|
117
|
+
| `titleFontFamily`, `buttonFontFamily` | Fonts bundled with the app. iOS looks them up with `UIFont(name:)`, Android with React Native's `ReactFontManager`. On the web they are CSS font families, drawn at weight 600 and 500. |
|
|
110
118
|
| `scale` | Multiplies every size, for apps that scale their UI. |
|
|
111
119
|
|
|
112
120
|
Colors are CSS hex strings: `#RGB`, `#RRGGBB` or `#RRGGBBAA`. Anything left out falls back to OneKey's light or dark palette.
|
|
@@ -117,8 +125,9 @@ Colors are CSS hex strings: `#RGB`, `#RRGGBB` or `#RRGGBBAA`. Anything left out
|
|
|
117
125
|
- `compressImageMaxWidth`, `compressImageMaxHeight` and `compressImageQuality` apply after cropping. The default quality is 0.8 on iOS and 1 on Android, as in `react-native-image-crop-picker`.
|
|
118
126
|
- Photos are decoded at most 4096 px on the long side, which keeps very large photos from exhausting memory. `cropRect` is reported in the original image's coordinates on iOS.
|
|
119
127
|
- Results are written to `<tmp>/react-native-image-crop-picker/` on iOS and `<cache>/react-native-image-crop-picker/` on Android. `clean()` empties that directory.
|
|
128
|
+
- On the web, results are JPEG blobs: `path` is a `blob:` URL, and `clean()` / `cleanSingle()` revoke the URLs this package created. The default quality is 0.8, as on iOS. `cropRect` is in the coordinates of the image as the browser decodes it (EXIF orientation applied), rotated with the crop. With `preserveOriginal`, `mime` comes from the file's leading bytes rather than `File.type`, and a file in an unrecognized format rejects `E_NO_IMAGE_DATA_FOUND`. `http(s)` images for `openCropper` must allow CORS, or the crop cannot be read back and rejects `E_CANNOT_SAVE_IMAGE`. `freeStyleCropEnabled` is not implemented on the web; the crop box keeps the `width` / `height` ratio. With `cropperCircleOverlay` the crop box is 1:1 with no frame or grid on every platform, whatever the image or target ratio.
|
|
120
129
|
- Only one picker or cropper can be open at a time. A second call rejects with `E_PICKER_IN_PROGRESS`.
|
|
121
|
-
- On iOS, cancelling the cropper that `openPicker` opened returns to the photo picker. On Android it rejects with `E_PICKER_CANCELLED
|
|
130
|
+
- On iOS, cancelling the cropper that `openPicker` opened returns to the photo picker. On Android and the web it rejects with `E_PICKER_CANCELLED`, as does dismissing the web file chooser.
|
|
122
131
|
- On Android the cropper keeps the calling activity's requested orientation, so a portrait-only app gets a portrait-only cropper.
|
|
123
132
|
|
|
124
133
|
## Not supported
|
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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AC,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,EACXC,YAAY,EACZC,eAAe,EACfC,WAAW,EACXC,SAAS,EACTC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,EACpBC,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sD,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":[]}
|