@crafing/react-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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crafing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,617 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # `@crafing/react-image-crop`
2
+
3
+ Complete React integration guide for beginners.
4
+
5
+ This package gives you a React hook: **`useImageCrop`**.
6
+ It connects a `<canvas>` to an image cropper (pan, zoom, rotate, export) and keeps the transform in React state.
7
+
8
+ It does **not** draw buttons, sliders, or a layout. You build the UI. The hook is the **controller**.
9
+
10
+ ## Live demo
11
+
12
+ Try the free browser cropper (same engine this package wraps):
13
+
14
+ **[Image crop on Crafing](https://www.crafing.com/tools/crop-image)**
15
+
16
+ ---
17
+
18
+ ## Table of contents
19
+
20
+ 1. [What you get](#1-what-you-get)
21
+ 2. [Install](#2-install)
22
+ 3. [Important rules (read first)](#3-important-rules-read-first)
23
+ 4. [Minimal working app (copy-paste)](#4-minimal-working-app-copy-paste)
24
+ 5. [Step-by-step integration](#5-step-by-step-integration)
25
+ 6. [Load an image (first time)](#6-load-an-image-first-time)
26
+ 7. [Save transform to a database](#7-save-transform-to-a-database)
27
+ 8. [Restore a saved edit](#8-restore-a-saved-edit)
28
+ 9. [Zoom, rotate, reset, frame size](#9-zoom-rotate-reset-frame-size)
29
+ 10. [Export the cropped image](#10-export-the-cropped-image)
30
+ 11. [Optional: CSS / DOM preview](#11-optional-css--dom-preview)
31
+ 12. [Upload from a file input](#12-upload-from-a-file-input)
32
+ 13. [Full API reference](#13-full-api-reference)
33
+ 14. [Data format reference](#14-data-format-reference)
34
+ 15. [Common mistakes](#15-common-mistakes)
35
+
36
+ ---
37
+
38
+ ## 1. What you get
39
+
40
+ ```
41
+ Your React app
42
+ ├── Toolbar (zoom, rotate, save) ← you write
43
+ ├── <canvas> inside a frame div ← you write
44
+ └── useImageCrop() ← this package
45
+ ```
46
+
47
+ | Included | Not included |
48
+ |----------|--------------|
49
+ | `useImageCrop` hook | Crop UI chrome |
50
+ | Transform helpers (fractions ↔ pixels) | File upload widgets |
51
+ | Bind to your canvas via `canvasRef` | CSS themes |
52
+
53
+ ---
54
+
55
+ ## 2. Install
56
+
57
+ Packages ship from **`dist/`** (minified). Until npm publish, install from the **admin-hosted** build:
58
+
59
+ ```bash
60
+ # From a running / deployed admin (see /packages/index.json for exact filenames)
61
+ npm install https://<admin-host>/packages/crafing-react-image-crop-0.1.0.tgz
62
+
63
+ # Or from a crafing repo checkout (after: cd admin && npm run build:packages)
64
+ npm install ./admin/public/packages/react-image-crop
65
+ # Source for this package lives at repo-root packages/react-image-crop
66
+ ```
67
+
68
+ When published to npm later:
69
+
70
+ ```bash
71
+ npm install @crafing/react-image-crop
72
+ ```
73
+
74
+ Peer dependency: **React 18+**. Depends on `lego-image`.
75
+
76
+ ---
77
+
78
+ ## 3. Important rules (read first)
79
+
80
+ 1. **You must render a `<canvas>`** and attach `canvasRef` to it.
81
+ 2. **Do not set React `width` / `height` props on `<canvas>`.**
82
+ The cropper sets the bitmap size from `frameSize` / `setFrameSize`.
83
+ 3. Wrap the canvas in a box with fixed CSS size and `overflow: hidden` matching the frame.
84
+ 4. Call `setLego(...)` only after `ready === true` (canvas is bound).
85
+ 5. Save the **`transform` object from `onChange`**, not random pixel values, if you want perfect restore later.
86
+
87
+ ---
88
+
89
+ ## 4. Minimal working app (copy-paste)
90
+
91
+ Replace `src/App.jsx` with:
92
+
93
+ ```jsx
94
+ import { useEffect, useState } from "react";
95
+ import { useImageCrop } from "@crafing/react-image-crop";
96
+
97
+ const FRAME = { width: 600, height: 600 };
98
+
99
+ // Public sample image — replace with your URL
100
+ const DEMO_URL = "https://picsum.photos/1200/800";
101
+
102
+ export default function App() {
103
+ const [savedTransform, setSavedTransform] = useState(null);
104
+
105
+ const {
106
+ canvasRef,
107
+ ready,
108
+ loaded,
109
+ error,
110
+ transform,
111
+ setLego,
112
+ zoomIn,
113
+ zoomOut,
114
+ rotateLeft,
115
+ rotateRight,
116
+ resetImage,
117
+ getCanvasDataUrl,
118
+ } = useImageCrop({
119
+ onChange: (values) => {
120
+ // Called whenever the user pans / zooms / rotates
121
+ setSavedTransform(values);
122
+ },
123
+ });
124
+
125
+ // Load image once the canvas is ready
126
+ useEffect(() => {
127
+ if (!ready) return;
128
+
129
+ setLego({
130
+ imageUrl: DEMO_URL,
131
+ imageType: "image/jpeg",
132
+ frameSize: FRAME,
133
+ // no transform → default cover fit
134
+ }).catch((err) => {
135
+ console.error(err);
136
+ });
137
+ }, [ready, setLego]);
138
+
139
+ function downloadCrop() {
140
+ const dataUrl = getCanvasDataUrl();
141
+ if (!dataUrl) {
142
+ alert("Nothing to export yet");
143
+ return;
144
+ }
145
+ const a = document.createElement("a");
146
+ a.href = dataUrl;
147
+ a.download = "crop.png";
148
+ a.click();
149
+ }
150
+
151
+ return (
152
+ <div style={{ fontFamily: "system-ui", padding: 16, maxWidth: 720 }}>
153
+ <h1>Image crop demo</h1>
154
+
155
+ {error ? (
156
+ <p style={{ color: "crimson" }}>Error: {error}</p>
157
+ ) : null}
158
+
159
+ <p>
160
+ Status: {ready ? "ready" : "waiting for canvas"} ·{" "}
161
+ {loaded ? "image loaded" : "no image yet"}
162
+ </p>
163
+
164
+ {/* Frame box — size must match frameSize */}
165
+ <div
166
+ style={{
167
+ width: FRAME.width,
168
+ height: FRAME.height,
169
+ overflow: "hidden",
170
+ border: "1px solid #ccc",
171
+ background: "#111",
172
+ }}
173
+ >
174
+ <canvas ref={canvasRef} />
175
+ </div>
176
+
177
+ <div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginTop: 12 }}>
178
+ <button type="button" onClick={zoomIn} disabled={!loaded}>
179
+ Zoom in
180
+ </button>
181
+ <button type="button" onClick={zoomOut} disabled={!loaded}>
182
+ Zoom out
183
+ </button>
184
+ <button type="button" onClick={rotateLeft} disabled={!loaded}>
185
+ Rotate left
186
+ </button>
187
+ <button type="button" onClick={rotateRight} disabled={!loaded}>
188
+ Rotate right
189
+ </button>
190
+ <button type="button" onClick={resetImage} disabled={!loaded}>
191
+ Reset
192
+ </button>
193
+ <button type="button" onClick={downloadCrop} disabled={!loaded}>
194
+ Download crop
195
+ </button>
196
+ </div>
197
+
198
+ <h2>Current transform (save this)</h2>
199
+ <pre style={{ background: "#f4f4f5", padding: 12, overflow: "auto" }}>
200
+ {JSON.stringify(transform || savedTransform, null, 2)}
201
+ </pre>
202
+
203
+ <p style={{ color: "#666", fontSize: 14 }}>
204
+ Tip: hold <kbd>Ctrl</kbd> (or <kbd>Cmd</kbd>) and scroll on the canvas to zoom.
205
+ Drag on the canvas to pan.
206
+ </p>
207
+ </div>
208
+ );
209
+ }
210
+ ```
211
+
212
+ ### How to try it
213
+
214
+ 1. Install from admin public packages: `npm install ./admin/public/packages/react-image-crop` (or the `.tgz` URL from `/packages/index.json`)
215
+ 2. Paste the code into your React app.
216
+ 3. You should see an image inside a 600×600 box.
217
+ 4. Drag to pan, Ctrl+scroll to zoom, use the buttons.
218
+ 5. Click **Download crop** to get a flattened image file.
219
+
220
+ If that works, integration is correct.
221
+
222
+ ---
223
+
224
+ ## 5. Step-by-step integration
225
+
226
+ ### Step 1 — Import
227
+
228
+ ```jsx
229
+ import { useImageCrop } from "@crafing/react-image-crop";
230
+ ```
231
+
232
+ ### Step 2 — Call the hook
233
+
234
+ ```jsx
235
+ const {
236
+ canvasRef,
237
+ ready,
238
+ setLego,
239
+ zoomIn,
240
+ // ...
241
+ } = useImageCrop({
242
+ onChange: (transform) => {
243
+ // optional: autosave
244
+ },
245
+ });
246
+ ```
247
+
248
+ ### Step 3 — Put a canvas in the page
249
+
250
+ ```jsx
251
+ <div style={{ width: 600, height: 600, overflow: "hidden" }}>
252
+ <canvas ref={canvasRef} />
253
+ </div>
254
+ ```
255
+
256
+ ### Step 4 — When `ready` is true, load an image
257
+
258
+ ```jsx
259
+ useEffect(() => {
260
+ if (!ready) return;
261
+ setLego({
262
+ imageUrl: "https://example.com/photo.png",
263
+ imageType: "image/png",
264
+ frameSize: { width: 600, height: 600 },
265
+ });
266
+ }, [ready, setLego]);
267
+ ```
268
+
269
+ ### Step 5 — Add your buttons
270
+
271
+ ```jsx
272
+ <button type="button" onClick={zoomIn}>Zoom in</button>
273
+ ```
274
+
275
+ Done.
276
+
277
+ ---
278
+
279
+ ## 6. Load an image (first time)
280
+
281
+ Omit `transform` so the cropper applies **cover fit** (image fills the frame).
282
+
283
+ ```js
284
+ await setLego({
285
+ imageUrl: "https://cdn.example.com/user-photo.jpg",
286
+ imageType: "image/jpeg",
287
+ frameSize: { width: 600, height: 600 },
288
+ });
289
+ ```
290
+
291
+ `imageUrl` can be:
292
+
293
+ - `https://...` URL
294
+ - Blob URL (`URL.createObjectURL(file)`)
295
+ - Data URL (`data:image/png;base64,...`)
296
+
297
+ ---
298
+
299
+ ## 7. Save transform to a database
300
+
301
+ `onChange` gives you **fractions** relative to the frame. Store them as-is.
302
+
303
+ ```jsx
304
+ const [record, setRecord] = useState({
305
+ imageUrl: "",
306
+ imageType: "image/jpeg",
307
+ frameSize: { width: 600, height: 600 },
308
+ transform: null,
309
+ });
310
+
311
+ const { setLego, ready } = useImageCrop({
312
+ onChange: (values) => {
313
+ const next = {
314
+ ...record,
315
+ transform: {
316
+ x: values.x,
317
+ y: values.y,
318
+ width: values.width,
319
+ height: values.height,
320
+ rotate: values.rotate,
321
+ scale: values.scale,
322
+ },
323
+ };
324
+ setRecord(next);
325
+ // debounce + POST to your API
326
+ // await fetch("/api/crops", { method: "POST", body: JSON.stringify(next) })
327
+ },
328
+ });
329
+ ```
330
+
331
+ Example JSON in the database:
332
+
333
+ ```json
334
+ {
335
+ "imageUrl": "https://cdn.example.com/uploads/user-123.jpg",
336
+ "imageType": "image/jpeg",
337
+ "frameSize": { "width": 600, "height": 600 },
338
+ "transform": {
339
+ "x": 0.32,
340
+ "y": -0.15,
341
+ "width": 1.6,
342
+ "height": 1.6,
343
+ "rotate": 45,
344
+ "scale": 0
345
+ }
346
+ }
347
+ ```
348
+
349
+ ---
350
+
351
+ ## 8. Restore a saved edit
352
+
353
+ Pass the **same object** back into `setLego`:
354
+
355
+ ```jsx
356
+ useEffect(() => {
357
+ if (!ready || !saved?.imageUrl) return;
358
+
359
+ setLego({
360
+ imageUrl: saved.imageUrl,
361
+ imageType: saved.imageType,
362
+ frameSize: saved.frameSize,
363
+ transform: saved.transform,
364
+ });
365
+ }, [ready, saved, setLego]);
366
+ ```
367
+
368
+ ---
369
+
370
+ ## 9. Zoom, rotate, reset, frame size
371
+
372
+ ```jsx
373
+ const {
374
+ zoomIn,
375
+ zoomOut,
376
+ zoomToScale,
377
+ getZoomLimits,
378
+ rotateTo,
379
+ rotateBy,
380
+ rotateLeft,
381
+ rotateRight,
382
+ resetImage,
383
+ setFrameSize,
384
+ getFrameSize,
385
+ } = useImageCrop();
386
+
387
+ zoomIn();
388
+ zoomOut();
389
+ zoomToScale(1.2); // 0 = cover minimum
390
+ const limits = getZoomLimits(); // { min, max, scale, ... }
391
+
392
+ rotateTo(45);
393
+ rotateBy(15);
394
+ rotateLeft(); // -90°
395
+ rotateRight(); // +90°
396
+
397
+ resetImage(); // back to cover fit
398
+
399
+ await setFrameSize(800, 400);
400
+ const size = getFrameSize(); // { width, height }
401
+ ```
402
+
403
+ When the frame size changes, keep your outer CSS box in sync:
404
+
405
+ ```jsx
406
+ const [frame, setFrame] = useState({ width: 600, height: 600 });
407
+
408
+ await setFrameSize(800, 400);
409
+ setFrame({ width: 800, height: 400 });
410
+
411
+ <div style={{ width: frame.width, height: frame.height, overflow: "hidden" }}>
412
+ <canvas ref={canvasRef} />
413
+ </div>
414
+ ```
415
+
416
+ ---
417
+
418
+ ## 10. Export the cropped image
419
+
420
+ ```jsx
421
+ const { getCanvasDataUrl, getExportMimeType, getSourceMimeType } =
422
+ useImageCrop();
423
+
424
+ // Auto format (PNG stays PNG, JPEG stays JPEG when possible)
425
+ const dataUrl = getCanvasDataUrl();
426
+
427
+ // Force JPEG
428
+ const jpeg = getCanvasDataUrl("image/jpeg", 0.92);
429
+
430
+ const mime = getExportMimeType();
431
+ const sourceMime = getSourceMimeType();
432
+ ```
433
+
434
+ Upload example:
435
+
436
+ ```js
437
+ async function uploadCrop() {
438
+ const dataUrl = getCanvasDataUrl();
439
+ const res = await fetch(dataUrl);
440
+ const blob = await res.blob();
441
+ const form = new FormData();
442
+ form.append("file", blob, "crop.png");
443
+ await fetch("/api/upload", { method: "POST", body: form });
444
+ }
445
+ ```
446
+
447
+ ---
448
+
449
+ ## 11. Optional: CSS / DOM preview
450
+
451
+ Sometimes you want an `<img>` that mirrors the crop (for a lighter UI).
452
+ Use the helpers — they convert fractions → pixels.
453
+
454
+ ```jsx
455
+ import {
456
+ useImageCrop,
457
+ transformToPixels,
458
+ pixelsToCssTransform,
459
+ } from "@crafing/react-image-crop";
460
+
461
+ const { transform, frameSize } = useImageCrop({ onChange: () => {} });
462
+
463
+ const px =
464
+ transform && frameSize
465
+ ? transformToPixels(transform, frameSize.width, frameSize.height)
466
+ : null;
467
+
468
+ {px ? (
469
+ <img
470
+ alt=""
471
+ src={imageUrl}
472
+ style={{
473
+ position: "absolute",
474
+ left: 0,
475
+ top: 0,
476
+ width: px.width,
477
+ height: px.height,
478
+ transformOrigin: "0 0",
479
+ objectFit: "contain",
480
+ transform: pixelsToCssTransform(px),
481
+ }}
482
+ />
483
+ ) : null}
484
+ ```
485
+
486
+ | Helper | Purpose |
487
+ |--------|---------|
488
+ | `transformToPixels(transform, frameW, frameH)` | Fractions → `{ left, top, width, height, rotate, scale }` |
489
+ | `pixelsToTransform(px, frameW, frameH)` | Opposite direction |
490
+ | `pixelsToCssTransform(px)` | `translate(...) rotate(...)` string |
491
+
492
+ **Rule:** store fractions from `onChange`. Convert to pixels only for CSS.
493
+
494
+ ---
495
+
496
+ ## 12. Upload from a file input
497
+
498
+ ```jsx
499
+ function onFileChange(e) {
500
+ const file = e.target.files?.[0];
501
+ if (!file || !ready) return;
502
+
503
+ const reader = new FileReader();
504
+ reader.onload = async () => {
505
+ await setLego({
506
+ imageUrl: reader.result, // data URL
507
+ imageType: file.type,
508
+ frameSize: { width: 600, height: 600 },
509
+ });
510
+ };
511
+ reader.readAsDataURL(file);
512
+ }
513
+
514
+ <input type="file" accept="image/*" onChange={onFileChange} />
515
+ ```
516
+
517
+ Or with a blob URL:
518
+
519
+ ```js
520
+ const url = URL.createObjectURL(file);
521
+ await setLego({
522
+ imageUrl: url,
523
+ imageType: file.type,
524
+ frameSize: { width: 600, height: 600 },
525
+ });
526
+ // later: URL.revokeObjectURL(url)
527
+ ```
528
+
529
+ ---
530
+
531
+ ## 13. Full API reference
532
+
533
+ ### `useImageCrop({ onChange? })`
534
+
535
+ #### State
536
+
537
+ | Field | Type | Meaning |
538
+ |-------|------|---------|
539
+ | `canvasRef` | ref | Put on `<canvas ref={canvasRef} />` |
540
+ | `ready` | `boolean` | Cropper attached to canvas |
541
+ | `loaded` | `boolean` | `setLego` succeeded |
542
+ | `error` | `string \| null` | Last error message |
543
+ | `transform` | object \| `null` | Latest `onChange` values |
544
+ | `frameSize` | `{ width, height } \| null` | Current frame |
545
+
546
+ #### Methods
547
+
548
+ | Method | Description |
549
+ |--------|-------------|
550
+ | `setLego(conf)` | Load / restore (`Promise`) |
551
+ | `resetImage()` | Cover fit |
552
+ | `zoomIn()` / `zoomOut()` / `zoomToScale(n)` | Zoom |
553
+ | `getZoomLimits()` | Current zoom limits |
554
+ | `rotateTo(deg)` / `rotateBy(delta)` | Rotate |
555
+ | `rotateLeft()` / `rotateRight()` | ±90° |
556
+ | `setFrameSize(w, h)` | Resize frame (`Promise`) |
557
+ | `getFrameSize()` | Current frame size |
558
+ | `getImageSize()` | Source image size if available |
559
+ | `getCanvasDataUrl(type?, quality?)` | Export data URL |
560
+ | `getSourceMimeType()` | Source MIME |
561
+ | `getExportMimeType()` | Export MIME |
562
+
563
+ #### `controllerProps`
564
+
565
+ ```js
566
+ { canvasRef }
567
+ ```
568
+
569
+ ---
570
+
571
+ ## 14. Data format reference
572
+
573
+ ### `setLego` config
574
+
575
+ | Field | Required | Description |
576
+ |-------|----------|-------------|
577
+ | `imageUrl` | yes | URL / blob URL / data URL |
578
+ | `imageType` | no | MIME type |
579
+ | `frameSize` | no | `{ width, height }` in pixels |
580
+ | `transform` | no | Saved edit; omit for cover fit |
581
+
582
+ ### `transform` fields
583
+
584
+ | Field | Meaning |
585
+ |-------|---------|
586
+ | `x`, `y` | Visual top-left as **fraction** of frame size |
587
+ | `width`, `height` | Drawn image size as **fraction** of frame |
588
+ | `rotate` | Degrees around **frame center** |
589
+ | `scale` | Extra zoom above cover; **`0` = minimum cover** |
590
+
591
+ ---
592
+
593
+ ## 15. Common mistakes
594
+
595
+ 1. **No `<canvas ref={canvasRef} />`**
596
+ The hook cannot start. `ready` stays false.
597
+
598
+ 2. **Calling `setLego` before `ready`**
599
+ Wait for `ready === true` (usually in a `useEffect`).
600
+
601
+ 3. **Setting `<canvas width={600} height={600}>` as React props**
602
+ That clears/resizes the bitmap incorrectly. Use `frameSize` / `setFrameSize` instead, and size the **wrapper div** with CSS.
603
+
604
+ 4. **Wrapper div size ≠ frameSize**
605
+ The visible crop area will look wrong. Keep them equal.
606
+
607
+ 5. **Saving pixels instead of fractions**
608
+ Restore will break when the frame size changes. Save `transform` from `onChange`.
609
+
610
+ 6. **Expecting a full crop UI from the package**
611
+ There is none — only the hook. Buttons and layout are yours.
612
+
613
+ ---
614
+
615
+ ## License
616
+
617
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ import type { RefObject } from "react";
2
+
3
+ /** Canonical transform from lego-image `onChange` / `setLego`. */
4
+ export interface ImageCropTransform {
5
+ /** Visual top-left X as fraction of frame width */
6
+ x: number;
7
+ /** Visual top-left Y as fraction of frame height */
8
+ y: number;
9
+ /** Image width as fraction of frame width */
10
+ width: number;
11
+ /** Image height as fraction of frame height */
12
+ height: number;
13
+ /** Degrees around frame center */
14
+ rotate: number;
15
+ /** Extra zoom above cover fit; `0` = cover minimum */
16
+ scale?: number;
17
+ }
18
+
19
+ export interface ImageCropFrameSize {
20
+ width: number;
21
+ height: number;
22
+ }
23
+
24
+ export interface ImageCropSetLegoConfig {
25
+ imageUrl: string;
26
+ imageType?: string;
27
+ mimeType?: string;
28
+ frameSize?: ImageCropFrameSize;
29
+ transform?: ImageCropTransform;
30
+ /** @deprecated Use `transform` */
31
+ pos?: { x: number; y: number };
32
+ /** @deprecated Use `transform.scale` */
33
+ scale?: number;
34
+ /** @deprecated Use `transform.rotate` */
35
+ rotate?: number;
36
+ }
37
+
38
+ export interface ImageCropZoomLimits {
39
+ min: number;
40
+ max: number;
41
+ scale: number;
42
+ minLevel?: number;
43
+ maxLevel?: number;
44
+ level?: number;
45
+ }
46
+
47
+ export interface ImageCropPixels {
48
+ left: number;
49
+ top: number;
50
+ width: number;
51
+ height: number;
52
+ rotate: number;
53
+ scale: number;
54
+ }
55
+
56
+ export function transformToPixels(
57
+ values: ImageCropTransform,
58
+ frameW: number,
59
+ frameH: number,
60
+ ): ImageCropPixels;
61
+
62
+ export function pixelsToTransform(
63
+ px: {
64
+ left: number;
65
+ top: number;
66
+ width: number;
67
+ height: number;
68
+ rotate?: number;
69
+ scale?: number;
70
+ },
71
+ frameW: number,
72
+ frameH: number,
73
+ ): ImageCropTransform;
74
+
75
+ export function pixelsToCssTransform(px: ImageCropPixels): string;
76
+
77
+ export interface UseImageCropOptions {
78
+ onChange?: (transform: ImageCropTransform) => void;
79
+ }
80
+
81
+ export interface UseImageCropResult {
82
+ /** Put on your own `<canvas ref={canvasRef} />` */
83
+ canvasRef: RefObject<HTMLCanvasElement | null>;
84
+ /** `true` after initLego bound to the canvas */
85
+ ready: boolean;
86
+ /** `true` after a successful `setLego` */
87
+ loaded: boolean;
88
+ error: string | null;
89
+ /** Latest transform from cropper `onChange` */
90
+ transform: ImageCropTransform | null;
91
+ frameSize: ImageCropFrameSize | null;
92
+ setLego: (conf: ImageCropSetLegoConfig) => Promise<void>;
93
+ resetImage: () => void;
94
+ zoomIn: () => void;
95
+ zoomOut: () => void;
96
+ zoomToScale: (scale: number) => void;
97
+ getZoomLimits: () => ImageCropZoomLimits;
98
+ rotateTo: (degrees: number) => void;
99
+ rotateBy: (delta: number) => void;
100
+ rotateRight: () => void;
101
+ rotateLeft: () => void;
102
+ setFrameSize: (width: number, height: number) => Promise<void>;
103
+ getFrameSize: () => ImageCropFrameSize;
104
+ getImageSize: () => { width: number; height: number } | null;
105
+ getCanvasDataUrl: (type?: string, quality?: number) => string | null;
106
+ getSourceMimeType: () => string | null;
107
+ getExportMimeType: () => string | null;
108
+ /** `{ canvasRef }` for hosts that prefer a props bag */
109
+ controllerProps: { canvasRef: RefObject<HTMLCanvasElement | null> };
110
+ }
111
+
112
+ export declare function useImageCrop(
113
+ options?: UseImageCropOptions,
114
+ ): UseImageCropResult;
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@crafing/react-image-crop",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "React state wrapper for lego-image cropper (no UI — host apps render the canvas)",
5
+ "type": "module",
6
+ "main": "./ricrp.js",
7
+ "module": "./ricrp.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "import": "./ricrp.js",
12
+ "default": "./ricrp.js"
13
+ }
14
+ },
15
+ "types": "./index.d.ts",
16
+ "files": [
17
+ "ricrp.js",
18
+ "index.d.ts",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "sideEffects": false,
23
+ "dependencies": {
24
+ "lego-image": "^2.0.2"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=18"
28
+ },
29
+ "keywords": [
30
+ "image-crop",
31
+ "lego-image",
32
+ "react",
33
+ "cropper",
34
+ "canvas",
35
+ "hook"
36
+ ],
37
+ "license": "MIT"
38
+ }
package/ricrp.js ADDED
@@ -0,0 +1,3 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import initLego from "lego-image";
3
+ (function(_0x2fc0aa,_0x56dcc2){const _0x28b241=_0x422f,_0x2b64f6=_0x2fc0aa();while(!![]){try{const _0x24c154=-parseInt(_0x28b241(0x225))/0x1*(-parseInt(_0x28b241(0x1e8))/0x2)+-parseInt(_0x28b241(0x22b))/0x3*(parseInt(_0x28b241(0x21f))/0x4)+-parseInt(_0x28b241(0x1fa))/0x5+-parseInt(_0x28b241(0x234))/0x6*(parseInt(_0x28b241(0x236))/0x7)+parseInt(_0x28b241(0x237))/0x8+-parseInt(_0x28b241(0x1ee))/0x9+parseInt(_0x28b241(0x1fe))/0xa*(parseInt(_0x28b241(0x20e))/0xb);if(_0x24c154===_0x56dcc2)break;else _0x2b64f6['push'](_0x2b64f6['shift']());}catch(_0x2aae31){_0x2b64f6['push'](_0x2b64f6['shift']());}}}(_0x6c4d,0x479ca));function _0x6c4d(){const _0x29659c=['yu9ACxG','CeHuB1a','EM9VBuLU','zNHQywC','EM9VBu91Da','oti4me5fBhbnwa','CM90yxrL','r1nwALK','AwHryKy','D1jiq1u','sLLtCvq','mZC4mZC5yvHfCfLw','D2LKDgG','wu5czxC','BLnorMu','vfvyC0C','Bwf4','ndCXBvjZyM9Q','D3fTzuq','C2v0tgvNBW','A3ztq0C','DKHfy1C','CMvZzxrjBwfNzq','sxj5rue','C2v0rNjHBwvtAxPL','z2v0u291CMnLtwLTzvr5Cgu','mJy1otHhu3fbCeK','swTXwg0','mJmXzgHrtKPf','nJG3nJaWDKLYqwnR','CM90yxrLqNK','tevSswm','EM9VBvrVu2nHBgu','uLLWwfm','tKX4Cwm','mKjMzKHMAG','z2v0q2fUDMfZrgf0yvvYBa','BgvMDa','vgjIDLa','z2v0sw1Hz2vtAxPL','qKTRDfK','mtu5oty4n3HduKHZsa','Dg9W','z1bkweK','z2v0rxHWB3j0twLTzvr5Cgu','terOB1q','thPcsKy','zgvZDhjVEq','DLPdD1i','A1DRuK0','DKLtCMq','z2v0wM9VBuXPBwL0CW','qw1jExq','mta3mJGWnw5wt0Dltq','C29zzK4','Cvv2D2W','Eg9AqMK','nJb2yuHLy0O','u2zWC0C','AgvPz2H0','quvdDNq','sw1Hz2uGy3jVChbLCIbPCYbUB3qGCMvHzhKG4Ocuig1VDw50igeGpgnHBNzHCYbYzwy9E2nHBNzHC1jLzN0GlZ4GzMLYC3q','ChGSia','zgvNkq','rwTOvMq','sgzMuLu','ChGPihjVDgf0zsG','ue5kDxG','AeHPELG','zevszNa','CM90yxrLtgvMDa','CM90yxrLvg8','v2Xjq04','mtm0mty4mwrcweP4Ca','z2v0rNjHBwvtAxPL','BwvZC2fNzq','CM90yxrLuMLNAhq','t0rTqvG','u0v5qxO','uLfpBe0','rwXpAfm','DhjHBNnSyxrLka','u3HuEuy','C2nHBgu','y3vYCMvUDa'];_0x6c4d=function(){return _0x29659c;};return _0x6c4d();}function useImageCrop({onChange:_0x192ac3}={}){const _0x37e94f=_0x422f,_0x70b5eb={'IryEA':function(_0x285a89,_0x1409f2){return _0x285a89(_0x1409f2);},'ElOhS':function(_0x30fe8f,_0x30de70){return _0x30fe8f(_0x30de70);},'fxjag':function(_0xd21608,_0x3cb069){return _0xd21608(_0x3cb069);},'PNJux':function(_0x29c384,_0x453507){return _0x29c384(_0x453507);},'kvSCG':function(_0x32a288,_0x3e0f57){return _0x32a288(_0x3e0f57);},'JYSqT':function(_0x1290e4,_0x28a1c6){return _0x1290e4 instanceof _0x28a1c6;},'soYfN':_0x37e94f(0x202),'wRHCU':function(_0x520efe,_0x33c838){return _0x520efe(_0x33c838);},'SEyAz':function(_0x4b43a7,_0x42c35){return _0x4b43a7(_0x42c35);},'ihQbF':function(_0x34eb4b,_0x5c525a){return _0x34eb4b instanceof _0x5c525a;},'vHEcW':function(_0x111dee,_0x5955e3){return _0x111dee(_0x5955e3);},'AECvt':function(_0x3aa0e7,_0x5ddadd){return _0x3aa0e7(_0x5ddadd);},'GSVjY':function(_0x164529,_0x308493){return _0x164529(_0x308493);},'SfpsG':function(_0x2c5884,_0x12665a){return _0x2c5884(_0x12665a);},'YNBew':function(_0x57a21c,_0xb82dd1){return _0x57a21c(_0xb82dd1);},'EkhVd':function(_0x51c3b0,_0x3d1d84){return _0x51c3b0(_0x3d1d84);},'vZCwR':function(_0x15d98f,_0x59488b){return _0x15d98f(_0x59488b);},'hHizX':function(_0x2cdad9,_0x215f19){return _0x2cdad9(_0x215f19);},'pHToP':function(_0x24d70e,_0x49214f){return _0x24d70e(_0x49214f);},'ODmAX':function(_0xf86782,_0x1e51ea){return _0xf86782(_0x1e51ea);},'AmIyt':function(_0x16c7f2,_0x21001c){return _0x16c7f2(_0x21001c);},'RYpXS':function(_0x10361a,_0x3d8353,_0x224246){return _0x10361a(_0x3d8353,_0x224246);},'SxTyF':function(_0x58ecd8,_0xfc651,_0x87e057){return _0x58ecd8(_0xfc651,_0x87e057);},'vISrd':function(_0x44da78,_0x2c199,_0x3e51c0){return _0x44da78(_0x2c199,_0x3e51c0);},'dERfp':function(_0x5677a8,_0x2dc475,_0x77c93){return _0x5677a8(_0x2dc475,_0x77c93);}},_0x386ea1=_0x70b5eb[_0x37e94f(0x201)](useRef,null),_0x52899b=useRef(null),_0x1cf07a=useRef(_0x192ac3);_0x1cf07a[_0x37e94f(0x219)]=_0x192ac3;const [_0x18dd7e,_0x2b58fb]=_0x70b5eb[_0x37e94f(0x209)](useState,![]),[_0x5e075d,_0xf51b52]=_0x70b5eb[_0x37e94f(0x21b)](useState,null),[_0x1bc103,_0x47b085]=useState(null),[_0x3fe14d,_0x410999]=_0x70b5eb[_0x37e94f(0x212)](useState,null),[_0x2dc140,_0x246728]=_0x70b5eb[_0x37e94f(0x1f9)](useState,![]);_0x70b5eb[_0x37e94f(0x1e6)](useEffect,()=>{const _0x2c9c5f=_0x37e94f,_0x451816={'IkqXm':function(_0x49bbe3,_0x4ac06e){return _0x49bbe3(_0x4ac06e);},'HffRU':function(_0x45d4c5,_0x3c8872){const _0x5145a3=_0x422f;return _0x70b5eb[_0x5145a3(0x231)](_0x45d4c5,_0x3c8872);},'LzBJF':function(_0x3f0163,_0x49a8d6){const _0x8f8682=_0x422f;return _0x70b5eb[_0x8f8682(0x215)](_0x3f0163,_0x49a8d6);}},_0x4ea3df=_0x386ea1[_0x2c9c5f(0x219)];if(!_0x4ea3df)return void 0x0;let _0x1be0c0=![];try{const _0x2186f8=_0x70b5eb[_0x2c9c5f(0x21d)](initLego,{'canvas':_0x4ea3df,'onChange':_0x579145=>{const _0x3f0ca2=_0x2c9c5f;if(_0x1be0c0)return;_0x451816[_0x3f0ca2(0x235)](_0xf51b52,_0x579145),_0x1cf07a[_0x3f0ca2(0x219)]?.(_0x579145);}});_0x52899b[_0x2c9c5f(0x219)]=_0x2186f8,_0x70b5eb[_0x2c9c5f(0x208)](_0x2b58fb,!![]),_0x70b5eb[_0x2c9c5f(0x22e)](_0x410999,null);}catch(_0x31ff4e){_0x70b5eb[_0x2c9c5f(0x231)](_0x410999,_0x70b5eb[_0x2c9c5f(0x224)](_0x31ff4e,Error)?_0x31ff4e[_0x2c9c5f(0x210)]:String(_0x31ff4e)),_0x2b58fb(![]),_0x52899b[_0x2c9c5f(0x219)]=null;}return()=>{const _0x1dff57=_0x2c9c5f;_0x1be0c0=!![];try{_0x52899b[_0x1dff57(0x219)]?.[_0x1dff57(0x1f4)]?.();}catch{}_0x52899b[_0x1dff57(0x219)]=null,_0x451816[_0x1dff57(0x206)](_0x2b58fb,![]),_0x451816[_0x1dff57(0x1f3)](_0x246728,![]);};},[]);const _0x3ef5ec=useCallback(_0x36715f=>{const _0xee5c73=_0x37e94f,_0x10d4f2=_0x52899b[_0xee5c73(0x219)];if(!_0x10d4f2)throw new Error(_0x70b5eb[_0xee5c73(0x1fb)]);return _0x70b5eb[_0xee5c73(0x21d)](_0x36715f,_0x10d4f2);},[]),_0xd9aa2c=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,async _0x3efa32=>{const _0x24b458=_0x37e94f;_0x70b5eb[_0x24b458(0x208)](_0x410999,null);try{await _0x70b5eb[_0x24b458(0x223)](_0x3ef5ec,_0x42d1db=>_0x42d1db[_0x24b458(0x22d)](_0x3efa32));const _0x4f31da=_0x70b5eb[_0x24b458(0x213)](_0x3ef5ec,_0x3f5bb7=>_0x3f5bb7[_0x24b458(0x20f)]?.()??null);if(_0x4f31da)_0x70b5eb[_0x24b458(0x215)](_0x47b085,_0x4f31da);_0x70b5eb[_0x24b458(0x215)](_0x246728,!![]);}catch(_0x12147b){_0x70b5eb[_0x24b458(0x215)](_0x410999,_0x70b5eb[_0x24b458(0x222)](_0x12147b,Error)?_0x12147b[_0x24b458(0x210)]:_0x70b5eb[_0x24b458(0x22f)](String,_0x12147b)),_0x70b5eb[_0x24b458(0x213)](_0x246728,![]);throw _0x12147b;}},[_0x3ef5ec]),_0x34ecff=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,()=>{const _0xdf4cc3=_0x37e94f;_0x70b5eb[_0xdf4cc3(0x201)](_0x3ef5ec,_0x4ac6a8=>_0x4ac6a8[_0xdf4cc3(0x230)]());},[_0x3ef5ec]),_0x80acb8=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,()=>{const _0x318d88=_0x37e94f;_0x70b5eb[_0x318d88(0x22f)](_0x3ef5ec,_0x7b30ee=>_0x7b30ee[_0x318d88(0x21c)]());},[_0x3ef5ec]),_0x5296ee=useCallback(()=>{const _0x4df030=_0x37e94f;_0x70b5eb[_0x4df030(0x221)](_0x3ef5ec,_0x1746d5=>_0x1746d5[_0x4df030(0x21e)]());},[_0x3ef5ec]),_0x4ddc2b=useCallback(_0x45f88d=>{const _0x4afc2c=_0x37e94f;_0x70b5eb[_0x4afc2c(0x1ff)](_0x3ef5ec,_0x14e9d6=>_0x14e9d6[_0x4afc2c(0x1e5)](_0x45f88d));},[_0x3ef5ec]),_0x16c7be=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,()=>{const _0x389ad1=_0x37e94f;return _0x70b5eb[_0x389ad1(0x213)](_0x3ef5ec,_0x43fb6b=>_0x43fb6b[_0x389ad1(0x1f8)]());},[_0x3ef5ec]),_0xa4e567=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,_0x567dc2=>{const _0x524f16=_0x37e94f;_0x3ef5ec(_0x1bc359=>_0x1bc359[_0x524f16(0x20c)](_0x567dc2));},[_0x3ef5ec]),_0x22c952=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,_0x28239b=>{const _0x31a756=_0x37e94f;_0x70b5eb[_0x31a756(0x22f)](_0x3ef5ec,_0x296787=>_0x296787[_0x31a756(0x238)](_0x28239b));},[_0x3ef5ec]),_0x4b03b7=_0x70b5eb[_0x37e94f(0x217)](useCallback,()=>{const _0x309eff=_0x37e94f;_0x70b5eb[_0x309eff(0x227)](_0x3ef5ec,_0x72f7a6=>_0x72f7a6[_0x309eff(0x211)]());},[_0x3ef5ec]),_0x46a016=_0x70b5eb[_0x37e94f(0x1e6)](useCallback,()=>{const _0x30bb14=_0x37e94f;_0x3ef5ec(_0x2eca6e=>_0x2eca6e[_0x30bb14(0x20b)]());},[_0x3ef5ec]),_0x577bdf=_0x70b5eb[_0x37e94f(0x217)](useCallback,async(_0x387d53,_0x38aaeb)=>{const _0x53e42f=_0x37e94f;await _0x3ef5ec(_0x162a0f=>_0x162a0f[_0x53e42f(0x232)](_0x387d53,_0x38aaeb)),_0x70b5eb[_0x53e42f(0x22e)](_0x47b085,{'width':_0x387d53,'height':_0x38aaeb});},[_0x3ef5ec]),_0x59e069=_0x70b5eb[_0x37e94f(0x1f7)](useCallback,()=>{const _0x54cb1d=_0x37e94f;return _0x70b5eb[_0x54cb1d(0x201)](_0x3ef5ec,_0x12b729=>_0x12b729[_0x54cb1d(0x20f)]());},[_0x3ef5ec]),_0x3c90b5=useCallback(()=>{const _0x3441fc=_0x37e94f;return _0x70b5eb[_0x3441fc(0x205)](_0x3ef5ec,_0x66f543=>_0x66f543[_0x3441fc(0x1ec)]?.()??null);},[_0x3ef5ec]),_0x47f467=_0x70b5eb[_0x37e94f(0x217)](useCallback,(_0x263a4e,_0x26fcc7)=>{const _0x36687b=_0x37e94f;return _0x3ef5ec(_0x3ccbff=>_0x3ccbff[_0x36687b(0x1e9)](_0x263a4e,_0x26fcc7));},[_0x3ef5ec]),_0xfc5fa9=_0x70b5eb[_0x37e94f(0x20a)](useCallback,()=>{const _0x1031aa=_0x37e94f;return _0x70b5eb[_0x1031aa(0x1f5)](_0x3ef5ec,_0xe68e65=>_0xe68e65[_0x1031aa(0x233)]());},[_0x3ef5ec]),_0x453cab=useCallback(()=>{const _0x580e89=_0x37e94f;return _0x3ef5ec(_0x185a88=>_0x185a88[_0x580e89(0x1f1)]());},[_0x3ef5ec]),_0x554cbc={'canvasRef':_0x386ea1};return{'canvasRef':_0x386ea1,'ready':_0x18dd7e,'loaded':_0x2dc140,'error':_0x3fe14d,'transform':_0x5e075d,'frameSize':_0x1bc103,'setLego':_0xd9aa2c,'resetImage':_0x34ecff,'zoomIn':_0x80acb8,'zoomOut':_0x5296ee,'zoomToScale':_0x4ddc2b,'getZoomLimits':_0x16c7be,'rotateTo':_0xa4e567,'rotateBy':_0x22c952,'rotateRight':_0x4b03b7,'rotateLeft':_0x46a016,'setFrameSize':_0x577bdf,'getFrameSize':_0x59e069,'getImageSize':_0x3c90b5,'getCanvasDataUrl':_0x47f467,'getSourceMimeType':_0xfc5fa9,'getExportMimeType':_0x453cab,'controllerProps':_0x554cbc};}function transformToPixels(_0x16bfa8,_0x2379d3,_0x33df6c){const _0x495168=_0x422f,_0x14659f={'WlICN':function(_0x486ec4,_0x403b2e){return _0x486ec4(_0x403b2e);},'wqmeD':function(_0x1b64fc,_0x3a023a){return _0x1b64fc(_0x3a023a);},'kWkRM':function(_0x44ed2e,_0x4fa806){return _0x44ed2e*_0x4fa806;},'TbbvP':function(_0x4401cd,_0x332187){return _0x4401cd(_0x332187);},'aOZqx':function(_0x31de74,_0x5660d1){return _0x31de74(_0x5660d1);},'BKktY':function(_0x5a2969,_0x5d21b4){return _0x5a2969(_0x5d21b4);},'nSNFe':function(_0x43bf12,_0x3b09ff){return _0x43bf12*_0x3b09ff;},'LElIc':function(_0x265721,_0x3379b1){return _0x265721(_0x3379b1);},'NLxqc':function(_0x3f0cad,_0x4089df){return _0x3f0cad(_0x4089df);}},_0x1655f5=_0x14659f[_0x495168(0x20d)](Number,_0x2379d3)||0x0,_0x3d3dc3=_0x14659f[_0x495168(0x22c)](Number,_0x33df6c)||0x0;return{'left':_0x14659f[_0x495168(0x1f6)](_0x14659f[_0x495168(0x1eb)](Number,_0x16bfa8?.['x'])||0x0,_0x1655f5),'top':_0x14659f[_0x495168(0x1f6)](_0x14659f[_0x495168(0x21a)](Number,_0x16bfa8?.['y'])||0x0,_0x3d3dc3),'width':_0x14659f[_0x495168(0x1f6)](_0x14659f[_0x495168(0x1ed)](Number,_0x16bfa8?.[_0x495168(0x226)])||0x0,_0x1655f5),'height':_0x14659f[_0x495168(0x228)](Number(_0x16bfa8?.[_0x495168(0x200)])||0x0,_0x3d3dc3),'rotate':_0x14659f[_0x495168(0x239)](Number,_0x16bfa8?.[_0x495168(0x220)])||0x0,'scale':Math[_0x495168(0x22a)](0x0,_0x14659f[_0x495168(0x1e7)](Number,_0x16bfa8?.[_0x495168(0x218)])||0x0)};}function _0x422f(_0x3a4e09,_0x97d3e1){_0x3a4e09=_0x3a4e09-0x1e5;const _0x6c4dbd=_0x6c4d();let _0x422f07=_0x6c4dbd[_0x3a4e09];if(_0x422f['KsIYFL']===undefined){var _0x41de2e=function(_0x17fb56){const _0x1c167b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2e1bde='',_0x421be2='';for(let _0x4dc9b0=0x0,_0x4ff242,_0x2d665e,_0x18b213=0x0;_0x2d665e=_0x17fb56['charAt'](_0x18b213++);~_0x2d665e&&(_0x4ff242=_0x4dc9b0%0x4?_0x4ff242*0x40+_0x2d665e:_0x2d665e,_0x4dc9b0++%0x4)?_0x2e1bde+=String['fromCharCode'](0xff&_0x4ff242>>(-0x2*_0x4dc9b0&0x6)):0x0){_0x2d665e=_0x1c167b['indexOf'](_0x2d665e);}for(let _0x38bf88=0x0,_0x7d3a3b=_0x2e1bde['length'];_0x38bf88<_0x7d3a3b;_0x38bf88++){_0x421be2+='%'+('00'+_0x2e1bde['charCodeAt'](_0x38bf88)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x421be2);};_0x422f['jaRRXZ']=_0x41de2e,_0x422f['HpHoxO']={},_0x422f['KsIYFL']=!![];}const _0x3b479b=_0x6c4dbd[0x0];_0x422f['OYpBtD']!==_0x3b479b&&(_0x422f['HpHoxO']={},_0x422f['OYpBtD']=_0x3b479b);const _0x4b4498=_0x422f['HpHoxO'][_0x3a4e09];return _0x4b4498===undefined?(_0x422f07=_0x422f['jaRRXZ'](_0x422f07),_0x422f['HpHoxO'][_0x3a4e09]=_0x422f07):_0x422f07=_0x4b4498,_0x422f07;}function pixelsToTransform(_0x1e78fe,_0xf3be93,_0x3a60e5){const _0x2ddb33=_0x422f,_0x1490a8={'gPJXI':function(_0x570421,_0x22ddbc){return _0x570421(_0x22ddbc);},'RQOlM':function(_0x3fe878,_0x598de8){return _0x3fe878/_0x598de8;},'qUvwl':function(_0x3d24de,_0x5c76c0){return _0x3d24de(_0x5c76c0);},'TUXsG':function(_0x5a2bb3,_0xe6f820){return _0x5a2bb3(_0xe6f820);},'xoZBi':function(_0xc9c6a5,_0x57a216){return _0xc9c6a5(_0x57a216);},'LDhoT':function(_0x5cfa7d,_0x1c20f7){return _0x5cfa7d(_0x1c20f7);}},_0xca1a3e=Number(_0xf3be93)||0x1,_0x3fed5c=_0x1490a8[_0x2ddb33(0x1f0)](Number,_0x3a60e5)||0x1;return{'x':_0x1490a8[_0x2ddb33(0x214)](Number(_0x1e78fe?.[_0x2ddb33(0x1ea)])||0x0,_0xca1a3e),'y':_0x1490a8[_0x2ddb33(0x214)](_0x1490a8[_0x2ddb33(0x1fc)](Number,_0x1e78fe?.[_0x2ddb33(0x1ef)])||0x0,_0x3fed5c),'width':(_0x1490a8[_0x2ddb33(0x229)](Number,_0x1e78fe?.[_0x2ddb33(0x226)])||0x0)/_0xca1a3e,'height':_0x1490a8[_0x2ddb33(0x214)](Number(_0x1e78fe?.[_0x2ddb33(0x200)])||0x0,_0x3fed5c),'rotate':_0x1490a8[_0x2ddb33(0x1fd)](Number,_0x1e78fe?.[_0x2ddb33(0x220)])||0x0,'scale':Math[_0x2ddb33(0x22a)](0x0,_0x1490a8[_0x2ddb33(0x1f2)](Number,_0x1e78fe?.[_0x2ddb33(0x218)])||0x0)};}function pixelsToCssTransform(_0x261e61){const _0x58a630=_0x422f,_0x134dbc=Number(_0x261e61?.[_0x58a630(0x1ea)])||0x0,_0x2b3905=Number(_0x261e61?.[_0x58a630(0x1ef)])||0x0,_0x2c3f9b=Number(_0x261e61?.[_0x58a630(0x220)])||0x0;return _0x58a630(0x216)+_0x134dbc+_0x58a630(0x203)+_0x2b3905+_0x58a630(0x207)+_0x2c3f9b+_0x58a630(0x204);}export{pixelsToCssTransform,pixelsToTransform,transformToPixels,useImageCrop};