@asaddevworld/image-crop 0.0.0-stage → 0.1.1
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/LICENSE +20 -0
- package/README.md +94 -2
- package/lib/module/ImageCropper.js +369 -0
- package/lib/module/ImageCropper.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/geometry.js +102 -0
- package/lib/module/utils/geometry.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ImageCropper.d.ts +3 -0
- package/lib/typescript/src/ImageCropper.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +40 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/utils/geometry.d.ts +27 -0
- package/lib/typescript/src/utils/geometry.d.ts.map +1 -0
- package/package.json +165 -4
- package/src/ImageCropper.tsx +482 -0
- package/src/index.tsx +14 -0
- package/src/types.ts +40 -0
- package/src/utils/geometry.ts +129 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ImageCropper } from './ImageCropper.js';
|
|
2
|
+
export { frameFor, coverScale, clampTranslation, frameInImage, snapRotation, } from './utils/geometry.js';
|
|
3
|
+
export type { CropResult, CropState, ImageCropperHandle, ImageCropperProps, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAC9C,OAAO,EACL,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,MAAM,qBAAkB,CAAC;AAC1B,YAAY,EACV,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,YAAS,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SkImage } from '@shopify/react-native-skia';
|
|
2
|
+
export interface CropState {
|
|
3
|
+
scale: number;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
/** Degrees. */
|
|
7
|
+
rotation: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CropResult {
|
|
10
|
+
image: SkImage;
|
|
11
|
+
base64: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ImageCropperProps {
|
|
16
|
+
image: SkImage;
|
|
17
|
+
/** Width / height. Undefined keeps the image ratio. */
|
|
18
|
+
aspect?: number;
|
|
19
|
+
/** Space around the frame, px. Default 24. */
|
|
20
|
+
frameInset?: number;
|
|
21
|
+
grid?: 'always' | 'gesture' | 'never';
|
|
22
|
+
onChange?: (state: CropState) => void;
|
|
23
|
+
minScaleFactor?: number;
|
|
24
|
+
maxScale?: number;
|
|
25
|
+
frameRadius?: number;
|
|
26
|
+
overlayColor?: string;
|
|
27
|
+
frameColor?: string;
|
|
28
|
+
style?: object;
|
|
29
|
+
accessibilityLabel?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ImageCropperHandle {
|
|
32
|
+
crop: (options?: {
|
|
33
|
+
width?: number;
|
|
34
|
+
height?: number;
|
|
35
|
+
}) => Promise<CropResult>;
|
|
36
|
+
rotate: (degrees: 90 | -90) => void;
|
|
37
|
+
reset: () => void;
|
|
38
|
+
getState: () => CropState;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAE1D,MAA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{
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
/** Frame rectangle centred in the viewport, sized by the aspect ratio. */
|
|
8
|
+
export declare function frameFor(viewW: number, viewH: number, aspect: number | undefined, inset: number, imageAspect: number): Rect;
|
|
9
|
+
/** Scale at which the (rotated) image fully covers the frame. */
|
|
10
|
+
export declare function coverScale(imageW: number, imageH: number, frame: Rect, rotation: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Clamp a translation so the scaled, 90-degree-rotated image still covers the frame.
|
|
13
|
+
* Translation is the offset of the image centre from the frame centre.
|
|
14
|
+
*/
|
|
15
|
+
export declare function clampTranslation(x: number, y: number, imageW: number, imageH: number, scale: number, frame: Rect, rotation: number): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function rubberBand(distance: number, dimension: number, coefficient?: number): number;
|
|
20
|
+
/** Snap to the nearest multiple of 90 when within `tolerance` degrees. */
|
|
21
|
+
export declare function snapRotation(degrees: number, tolerance?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* The frame rectangle in image pixel coordinates for a transform.
|
|
24
|
+
* Only 90-degree rotations map to an axis-aligned rectangle; free angles are rounded.
|
|
25
|
+
*/
|
|
26
|
+
export declare function frameInImage(imageW: number, imageH: number, scale: number, x: number, y: number, frame: Rect, rotation: number): Rect;
|
|
27
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/utils/geometry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAClB,IAAI,CAWN;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,MAAM,GACf;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAW1B;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,SAAO,GACjB,MAAM,CAMR;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,CAIpE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,MAAM,GACf,IAAI,CA+BN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,167 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asaddevworld/image-crop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Image cropper for React Native: pinch, pan and rotate with Reanimated, aspect presets, grid overlay, and Skia export at any size",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"rn-image-crop-source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace rn-image-crop-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"test": "jest"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"react-native",
|
|
44
|
+
"expo",
|
|
45
|
+
"image",
|
|
46
|
+
"crop",
|
|
47
|
+
"cropper",
|
|
48
|
+
"pinch",
|
|
49
|
+
"zoom",
|
|
50
|
+
"rotate",
|
|
51
|
+
"skia",
|
|
52
|
+
"reanimated",
|
|
53
|
+
"gesture-handler",
|
|
54
|
+
"ios",
|
|
55
|
+
"android"
|
|
56
|
+
],
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/asadDevWorld/rn-image-crop.git"
|
|
60
|
+
},
|
|
61
|
+
"author": "Asad Ali <sadali3690@gmail.com> (https://github.com/asadDevWorld)",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/asadDevWorld/rn-image-crop/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/asadDevWorld/rn-image-crop#readme",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"registry": "https://registry.npmjs.org/",
|
|
69
|
+
"access": "public"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@eslint/compat": "^2.1.1",
|
|
73
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
74
|
+
"@eslint/js": "^9.39.5",
|
|
75
|
+
"@jest/globals": "^29.7.0",
|
|
76
|
+
"@react-native/babel-preset": "0.88.1",
|
|
77
|
+
"@react-native/eslint-config": "0.88.1",
|
|
78
|
+
"@react-native/jest-preset": "0.88.1",
|
|
79
|
+
"@shopify/react-native-skia": "2.14.0",
|
|
80
|
+
"@testing-library/react-native": "^13.3.3",
|
|
81
|
+
"@types/react": "^19.2.0",
|
|
82
|
+
"del-cli": "^8.0.1",
|
|
83
|
+
"eslint": "^9.39.5",
|
|
84
|
+
"eslint-config-prettier": "^10.1.8",
|
|
85
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
86
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
87
|
+
"jest": "^29.7.0",
|
|
88
|
+
"prettier": "^3.9.10",
|
|
89
|
+
"react": "19.3.0",
|
|
90
|
+
"react-native": "0.88.1",
|
|
91
|
+
"react-native-builder-bob": "^0.44.1",
|
|
92
|
+
"react-native-gesture-handler": "~3.3.0",
|
|
93
|
+
"react-native-reanimated": "4.7.1",
|
|
94
|
+
"react-native-safe-area-context": "~5.10.1",
|
|
95
|
+
"react-native-worklets": "0.13.0",
|
|
96
|
+
"react-test-renderer": "19.3.0",
|
|
97
|
+
"turbo": "^2.11.10",
|
|
98
|
+
"typescript": "^6.0.3"
|
|
99
|
+
},
|
|
100
|
+
"peerDependencies": {
|
|
101
|
+
"@shopify/react-native-skia": ">=2.0.0",
|
|
102
|
+
"react": "*",
|
|
103
|
+
"react-native": "*",
|
|
104
|
+
"react-native-gesture-handler": ">=3.0.0",
|
|
105
|
+
"react-native-reanimated": ">=4.0.0",
|
|
106
|
+
"react-native-worklets": "*"
|
|
107
|
+
},
|
|
108
|
+
"workspaces": [
|
|
109
|
+
"example"
|
|
110
|
+
],
|
|
111
|
+
"packageManager": "yarn@4.18.1",
|
|
112
|
+
"react-native-builder-bob": {
|
|
113
|
+
"source": "src",
|
|
114
|
+
"output": "lib",
|
|
115
|
+
"targets": [
|
|
116
|
+
[
|
|
117
|
+
"module",
|
|
118
|
+
{
|
|
119
|
+
"esm": true
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
[
|
|
123
|
+
"typescript",
|
|
124
|
+
{
|
|
125
|
+
"project": "tsconfig.build.json"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
"prettier": {
|
|
131
|
+
"quoteProps": "consistent",
|
|
132
|
+
"singleQuote": true,
|
|
133
|
+
"tabWidth": 2,
|
|
134
|
+
"trailingComma": "es5",
|
|
135
|
+
"useTabs": false
|
|
136
|
+
},
|
|
137
|
+
"jest": {
|
|
138
|
+
"preset": "@react-native/jest-preset",
|
|
139
|
+
"testEnvironmentOptions": {
|
|
140
|
+
"customExportConditions": [
|
|
141
|
+
"require",
|
|
142
|
+
"react-native",
|
|
143
|
+
"rn-image-crop-source"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
"modulePathIgnorePatterns": [
|
|
147
|
+
"<rootDir>/example/node_modules",
|
|
148
|
+
"<rootDir>/lib/"
|
|
149
|
+
],
|
|
150
|
+
"setupFiles": [
|
|
151
|
+
"<rootDir>/jest.setup.js"
|
|
152
|
+
],
|
|
153
|
+
"resolver": "react-native-reanimated/jest/resolver",
|
|
154
|
+
"transformIgnorePatterns": [
|
|
155
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|react-native-reanimated|react-native-worklets|react-native-gesture-handler|react-native-safe-area-context|@shopify/react-native-skia)/)"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
"create-react-native-library": {
|
|
159
|
+
"type": "library",
|
|
160
|
+
"languages": "js",
|
|
161
|
+
"tools": [
|
|
162
|
+
"eslint",
|
|
163
|
+
"jest"
|
|
164
|
+
],
|
|
165
|
+
"version": "0.64.0"
|
|
166
|
+
}
|
|
167
|
+
}
|