@alien6-studio/elea-media 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +47 -2
- package/dist/AdjustableCrop.d.ts +37 -0
- package/dist/AdjustableCrop.d.ts.map +1 -0
- package/dist/AdjustableCrop.js +11 -0
- package/dist/AdjustableCrop.js.map +1 -0
- package/dist/CropFormatControls.d.ts +49 -0
- package/dist/CropFormatControls.d.ts.map +1 -0
- package/dist/CropFormatControls.js +50 -0
- package/dist/CropFormatControls.js.map +1 -0
- package/dist/CropMask.d.ts +11 -0
- package/dist/CropMask.d.ts.map +1 -0
- package/dist/CropMask.js +107 -0
- package/dist/CropMask.js.map +1 -0
- package/dist/DropZone.d.ts +32 -0
- package/dist/DropZone.d.ts.map +1 -0
- package/dist/DropZone.js +70 -0
- package/dist/DropZone.js.map +1 -0
- package/dist/ImageCropper.d.ts +45 -0
- package/dist/ImageCropper.d.ts.map +1 -0
- package/dist/ImageCropper.js +136 -0
- package/dist/ImageCropper.js.map +1 -0
- package/dist/bundle.css +8 -0
- package/dist/createCropFormats.d.ts +7 -0
- package/dist/createCropFormats.d.ts.map +1 -0
- package/dist/createCropFormats.js +8 -0
- package/dist/createCropFormats.js.map +1 -0
- package/dist/crop-adjustments.css +47 -0
- package/dist/crop.d.ts +56 -0
- package/dist/crop.d.ts.map +1 -0
- package/dist/crop.js +138 -0
- package/dist/crop.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +50 -0
- package/dist/useObjectUrl.d.ts +3 -0
- package/dist/useObjectUrl.d.ts.map +1 -0
- package/dist/useObjectUrl.js +17 -0
- package/dist/useObjectUrl.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @alien6-studio/elea-media
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Media components for React on Elea tokens: a drop zone for files and an image cropper with
|
|
4
|
+
zoom and rotation. Labels come from the host; styles come from `styles.css` and read
|
|
5
|
+
`--elea-*` variables only.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { createCropFormats, DropZone, ImageCropper } from "@alien6-studio/elea-media";
|
|
9
|
+
import "@alien6-studio/elea-media/bundle.css"; // the tokens, then styles.css
|
|
10
|
+
|
|
11
|
+
<DropZone accept="image/*" label="Click to add an image" hint="or drop one here" onFiles={([file]) => setFile(file)} />
|
|
12
|
+
|
|
13
|
+
<ImageCropper
|
|
14
|
+
file={file}
|
|
15
|
+
aspect={16 / 9}
|
|
16
|
+
labels={{ zoom: "Zoom", rotation: "Rotation", confirm: "Use this image", cancel: "Cancel", image: "Picture to frame" }}
|
|
17
|
+
onConfirm={(blob) => upload(blob ?? file)}
|
|
18
|
+
/>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The geometry (`cropRect`, `coverScale`, `exportCrop`) is exported on its own for hosts that draw
|
|
22
|
+
their own frame.
|
|
23
|
+
|
|
24
|
+
Pass `export={{ outputSize: { width: 1200, height: 800 } }}` for an exact pixel size, including
|
|
25
|
+
upscaling. The preview uses that ratio. Exact dimensions take precedence over `aspect` and
|
|
26
|
+
`maxWidth`. Each side accepts 1–8192 whole pixels, up to 16,777,216 pixels in total.
|
|
27
|
+
|
|
28
|
+
Pass `formats={createCropFormats(options)}` to let people move and resize a crop area on the photo. The corner handle
|
|
29
|
+
resizes it. Both controls accept arrow keys. Choose the original ratio, a square
|
|
30
|
+
(1080 × 1080), landscape (1600 × 900), portrait (1080 × 1350), custom pixel dimensions or
|
|
31
|
+
a free ratio. Free crops export the selected source pixels at their natural resolution.
|
|
32
|
+
The media `bundle.css` includes the format controls. When importing individual styles,
|
|
33
|
+
load the media `styles.css` and `crop-adjustments.css` alongside the UI styles for Field,
|
|
34
|
+
Select, Slider and Button.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
<ImageCropper file={file} labels={labels} onConfirm={saveCrop}
|
|
38
|
+
formats={createCropFormats({
|
|
39
|
+
defaultValue: "landscape",
|
|
40
|
+
labels: {
|
|
41
|
+
format: "Crop format", original: "Original ratio", free: "Free ratio",
|
|
42
|
+
custom: "Custom dimensions", width: "Width (px)", height: "Height (px)",
|
|
43
|
+
move: "Move crop area", resize: "Resize crop area",
|
|
44
|
+
invalidSize: "Use whole pixels from 1 to 8192 per side, up to 16,777,216 pixels in total.",
|
|
45
|
+
},
|
|
46
|
+
})}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { CropRect, Size } from "./crop.js";
|
|
3
|
+
import { type CropFormatOptions } from "./CropFormatControls.js";
|
|
4
|
+
export interface CropLayout {
|
|
5
|
+
outputSize?: Size | undefined;
|
|
6
|
+
mask?: CropRect;
|
|
7
|
+
overlay?: ReactNode;
|
|
8
|
+
controls?: ReactNode;
|
|
9
|
+
invalid: boolean;
|
|
10
|
+
Button?: ComponentType<CropButtonProps>;
|
|
11
|
+
Slider?: ComponentType<CropSliderProps>;
|
|
12
|
+
}
|
|
13
|
+
export interface CropButtonProps {
|
|
14
|
+
variant: "primary" | "outline";
|
|
15
|
+
onClick: () => void;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export interface CropSliderProps {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
step: number;
|
|
23
|
+
label: string;
|
|
24
|
+
value: number;
|
|
25
|
+
onChange: (value: number) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface AdjustableCropProps {
|
|
28
|
+
formats: CropFormatOptions;
|
|
29
|
+
frame: Size;
|
|
30
|
+
natural: Size | null;
|
|
31
|
+
initialSize?: Size | undefined;
|
|
32
|
+
disabled: boolean;
|
|
33
|
+
children: (layout: CropLayout) => ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/** Load the format picker and direct manipulation only for hosts that request them. */
|
|
36
|
+
export default function AdjustableCrop({ formats, frame, natural, initialSize, disabled, children }: AdjustableCropProps): ReactNode;
|
|
37
|
+
//# sourceMappingURL=AdjustableCrop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdjustableCrop.d.ts","sourceRoot":"","sources":["../src/AdjustableCrop.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGhF,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,EAAE,IAAI,CAAC;IACZ,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,SAAS,CAAC;CAC7C;AAED,uFAAuF;AACvF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,mBAAmB,aAKvH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Button, Slider } from "@alien6-studio/elea-ui";
|
|
2
|
+
import { useCropFormat } from "./CropFormatControls.js";
|
|
3
|
+
import { useCropMask } from "./CropMask.js";
|
|
4
|
+
/** Load the format picker and direct manipulation only for hosts that request them. */
|
|
5
|
+
export default function AdjustableCrop({ formats, frame, natural, initialSize, disabled, children }) {
|
|
6
|
+
const { controls, outputSize, invalid, free } = useCropFormat(formats, initialSize, natural, disabled);
|
|
7
|
+
const ratio = outputSize ? outputSize.width / outputSize.height : frame.width / frame.height;
|
|
8
|
+
const { rect, overlay } = useCropMask(frame, free ? undefined : ratio, formats.labels, disabled);
|
|
9
|
+
return children({ controls, outputSize, invalid, mask: rect, overlay, Button, Slider });
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=AdjustableCrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdjustableCrop.js","sourceRoot":"","sources":["../src/AdjustableCrop.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,aAAa,EAA0B,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAqC5C,uFAAuF;AACvF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAuB;IACtH,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACvG,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7F,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjG,OAAO,QAAQ,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Size } from "./crop.js";
|
|
3
|
+
declare const presets: {
|
|
4
|
+
readonly square: {
|
|
5
|
+
readonly ratio: "1:1";
|
|
6
|
+
readonly size: {
|
|
7
|
+
readonly width: 1080;
|
|
8
|
+
readonly height: 1080;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
readonly landscape: {
|
|
12
|
+
readonly ratio: "16:9";
|
|
13
|
+
readonly size: {
|
|
14
|
+
readonly width: 1600;
|
|
15
|
+
readonly height: 900;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly portrait: {
|
|
19
|
+
readonly ratio: "4:5";
|
|
20
|
+
readonly size: {
|
|
21
|
+
readonly width: 1080;
|
|
22
|
+
readonly height: 1350;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type Format = keyof typeof presets | "original" | "custom" | "free";
|
|
27
|
+
export interface CropFormatOptions {
|
|
28
|
+
labels: {
|
|
29
|
+
format: string;
|
|
30
|
+
original: string;
|
|
31
|
+
free: string;
|
|
32
|
+
custom: string;
|
|
33
|
+
move: string;
|
|
34
|
+
resize: string;
|
|
35
|
+
width: string;
|
|
36
|
+
height: string;
|
|
37
|
+
invalidSize: string;
|
|
38
|
+
};
|
|
39
|
+
/** Defaults to the supplied output size in custom mode, otherwise to the original aspect. */
|
|
40
|
+
defaultValue?: Format | undefined;
|
|
41
|
+
}
|
|
42
|
+
export declare function useCropFormat(formats: CropFormatOptions | undefined, initialSize?: Size, natural?: Size | null, disabled?: boolean): {
|
|
43
|
+
controls: ReactNode;
|
|
44
|
+
outputSize: Size | undefined;
|
|
45
|
+
invalid: boolean;
|
|
46
|
+
free: boolean;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=CropFormatControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CropFormatControls.d.ts","sourceRoot":"","sources":["../src/CropFormatControls.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAA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
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { Field, Input, Select } from "@alien6-studio/elea-ui";
|
|
5
|
+
import { isValidOutputSize, MAX_OUTPUT_DIMENSION } from "./crop.js";
|
|
6
|
+
const presets = {
|
|
7
|
+
square: { ratio: "1:1", size: { width: 1080, height: 1080 } },
|
|
8
|
+
landscape: { ratio: "16:9", size: { width: 1600, height: 900 } },
|
|
9
|
+
portrait: { ratio: "4:5", size: { width: 1080, height: 1350 } },
|
|
10
|
+
};
|
|
11
|
+
export function useCropFormat(formats, initialSize, natural, disabled = false) {
|
|
12
|
+
const errorId = useId();
|
|
13
|
+
const [choice, setChoice] = useState();
|
|
14
|
+
const [draft, setDraft] = useState();
|
|
15
|
+
if (!formats)
|
|
16
|
+
return { controls: null, outputSize: initialSize, invalid: false, free: false };
|
|
17
|
+
const format = choice ?? formats.defaultValue ?? (initialSize ? "custom" : "original");
|
|
18
|
+
const initial = initialSize ?? (isValidOutputSize(natural) ? natural : presets.square.size);
|
|
19
|
+
const custom = draft ?? { width: String(initial.width), height: String(initial.height), lastValid: isValidOutputSize(initial) ? initial : undefined };
|
|
20
|
+
const size = { width: Number(custom.width), height: Number(custom.height) };
|
|
21
|
+
const invalid = format === "custom" && !isValidOutputSize(size);
|
|
22
|
+
const free = format === "free";
|
|
23
|
+
let outputSize;
|
|
24
|
+
if (format === "custom")
|
|
25
|
+
outputSize = custom.lastValid;
|
|
26
|
+
else if (!free && format !== "original")
|
|
27
|
+
outputSize = presets[format].size;
|
|
28
|
+
const { labels } = formats;
|
|
29
|
+
function edit(axis, text) {
|
|
30
|
+
const next = { ...custom, [axis]: text };
|
|
31
|
+
const nextSize = { width: Number(next.width), height: Number(next.height) };
|
|
32
|
+
if (isValidOutputSize(nextSize))
|
|
33
|
+
next.lastValid = nextSize;
|
|
34
|
+
setDraft(next);
|
|
35
|
+
}
|
|
36
|
+
// A pixel-area error involves both dimensions. A bad width or height belongs to its own field.
|
|
37
|
+
const badWidth = !isValidOutputSize({ width: size.width, height: 1 });
|
|
38
|
+
const badHeight = !isValidOutputSize({ width: 1, height: size.height });
|
|
39
|
+
const badArea = invalid && !badWidth && !badHeight;
|
|
40
|
+
const dimension = (axis, hasError) => (_jsx(Field, { label: labels[axis], className: "elea-cropper__format-field", children: control => _jsx(Input, { id: control.id, type: "number", inputMode: "numeric", min: 1, max: MAX_OUTPUT_DIMENSION, step: 1, disabled: disabled, value: custom[axis], onChange: event => edit(axis, event.currentTarget.value), invalid: hasError, "aria-describedby": hasError ? errorId : undefined }) }));
|
|
41
|
+
const options = [
|
|
42
|
+
{ value: "original", label: labels.original },
|
|
43
|
+
{ value: "free", label: labels.free },
|
|
44
|
+
...Object.entries(presets).map(([value, { ratio, size }]) => ({ value, label: `${ratio} · ${size.width} × ${size.height}` })),
|
|
45
|
+
{ value: "custom", label: labels.custom },
|
|
46
|
+
];
|
|
47
|
+
const controls = (_jsxs("div", { className: "elea-cropper__formats", children: [_jsx(Field, { label: labels.format, className: "elea-cropper__format-field", children: control => _jsx(Select, { id: control.id, label: labels.format, options: options, value: format, disabled: disabled, onChange: next => setChoice(next) }) }), format === "custom" && _jsxs("div", { className: "elea-cropper__dimensions", children: [dimension("width", badWidth || badArea), dimension("height", badHeight || badArea)] }), invalid && _jsx("p", { id: errorId, className: "elea-field__error elea-cropper__format-error", role: "alert", children: labels.invalidSize })] }));
|
|
48
|
+
return { controls, outputSize, invalid, free };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=CropFormatControls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CropFormatControls.js","sourceRoot":"","sources":["../src/CropFormatControls.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MA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C,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7H,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;KAC1C,CAAC;IACF,MAAM,QAAQ,GAAG,CACf,eAAK,SAAS,EAAC,uBAAuB,aACpC,KAAC,KAAK,IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAC,4BAA4B,YAChE,OAAO,CAAC,EAAE,CAAC,KAAC,MAAM,IAAC,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EACvF,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAc,CAAC,GAAI,GAC/D,EACP,MAAM,KAAK,QAAQ,IAAI,eAAK,SAAS,EAAC,0BAA0B,aAC9D,SAAS,CAAC,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,EACvC,SAAS,CAAC,QAAQ,EAAE,SAAS,IAAI,OAAO,CAAC,IACtC,EACL,OAAO,IAAI,YAAG,EAAE,EAAE,OAAO,EAAE,SAAS,EAAC,8CAA8C,EAAC,IAAI,EAAC,OAAO,YAAE,MAAM,CAAC,WAAW,GAAK,IACtH,CACP,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { CropRect, Size } from "./crop.js";
|
|
3
|
+
/** The movable window and its rectangle in stage pixels, shared by the preview and export. */
|
|
4
|
+
export declare function useCropMask(stage: Size, aspect: number | undefined, labels: {
|
|
5
|
+
move: string;
|
|
6
|
+
resize: string;
|
|
7
|
+
} | undefined, disabled: boolean): {
|
|
8
|
+
rect: CropRect;
|
|
9
|
+
overlay: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=CropMask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CropMask.d.ts","sourceRoot":"","sources":["../src/CropMask.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAkE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvG,OAAO,KAAK,EAAE,QAAQ,EAAS,IAAI,EAAE,MAAM,WAAW,CAAC;AAqEvD,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG;IAC7I,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,SAAS,CAAC;CACpB,CA0DA"}
|
package/dist/CropMask.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useRef, useState } from "react";
|
|
4
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
5
|
+
const MIN_SIDE = 24;
|
|
6
|
+
function bounds(selection, stage) {
|
|
7
|
+
const { aspect, span, center } = selection;
|
|
8
|
+
let width = span.width * stage.width;
|
|
9
|
+
let height = span.height * stage.height;
|
|
10
|
+
if (aspect !== undefined) {
|
|
11
|
+
const coverage = Math.max(span.width, span.height);
|
|
12
|
+
width = Math.min(stage.width, stage.height * aspect) * coverage;
|
|
13
|
+
height = width / aspect;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
x: clamp(center.x * stage.width - width / 2, 0, stage.width - width),
|
|
17
|
+
y: clamp(center.y * stage.height - height / 2, 0, stage.height - height),
|
|
18
|
+
width, height,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function remember(rect, stage, aspect) {
|
|
22
|
+
return {
|
|
23
|
+
center: { x: (rect.x + rect.width / 2) / stage.width, y: (rect.y + rect.height / 2) / stage.height },
|
|
24
|
+
span: { width: rect.width / stage.width, height: rect.height / stage.height },
|
|
25
|
+
aspect,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function adjust(action, rect, stage, aspect, dx, dy, rtl) {
|
|
29
|
+
if (action === "move")
|
|
30
|
+
return { ...rect,
|
|
31
|
+
x: clamp(rect.x + dx, 0, stage.width - rect.width), y: clamp(rect.y + dy, 0, stage.height - rect.height),
|
|
32
|
+
};
|
|
33
|
+
const end = rect.x + rect.width;
|
|
34
|
+
const roomX = rtl ? end : stage.width - rect.x;
|
|
35
|
+
const roomY = stage.height - rect.y;
|
|
36
|
+
const across = rtl ? -dx : dx;
|
|
37
|
+
let width = clamp(rect.width + across, MIN_SIDE, roomX);
|
|
38
|
+
let height = clamp(rect.height + dy, MIN_SIDE, roomY);
|
|
39
|
+
if (aspect !== undefined) {
|
|
40
|
+
const delta = Math.abs(across) >= Math.abs(dy * aspect) ? across : dy * aspect;
|
|
41
|
+
// A very wide or tall format can have a subpixel short edge.
|
|
42
|
+
const minWidth = MIN_SIDE * Math.min(1, aspect);
|
|
43
|
+
width = clamp(rect.width + delta, minWidth, Math.min(roomX, roomY * aspect));
|
|
44
|
+
height = width / aspect;
|
|
45
|
+
}
|
|
46
|
+
return { x: rtl ? end - width : rect.x, y: rect.y, width, height };
|
|
47
|
+
}
|
|
48
|
+
const steps = {
|
|
49
|
+
ArrowLeft: { x: -1, y: 0 }, ArrowRight: { x: 1, y: 0 },
|
|
50
|
+
ArrowUp: { x: 0, y: -1 }, ArrowDown: { x: 0, y: 1 },
|
|
51
|
+
};
|
|
52
|
+
/** The movable window and its rectangle in stage pixels, shared by the preview and export. */
|
|
53
|
+
export function useCropMask(stage, aspect, labels, disabled) {
|
|
54
|
+
const ratio = aspect !== undefined && Number.isFinite(aspect) && aspect > 0 ? aspect : undefined;
|
|
55
|
+
const [selection, setSelection] = useState({ center: { x: 0.5, y: 0.5 }, span: { width: 0.8, height: 0.8 }, aspect: ratio });
|
|
56
|
+
const drag = useRef(null);
|
|
57
|
+
const descriptionId = useId();
|
|
58
|
+
if (!labels || stage.width <= 0 || stage.height <= 0)
|
|
59
|
+
return { rect: { x: 0, y: 0, ...stage }, overlay: null };
|
|
60
|
+
let rect = bounds(selection, stage);
|
|
61
|
+
if (ratio !== selection.aspect) {
|
|
62
|
+
// Capture the actual old window before switching aspect, including when unlocking it.
|
|
63
|
+
const next = remember(rect, stage, ratio);
|
|
64
|
+
setSelection(next);
|
|
65
|
+
rect = bounds(next, stage);
|
|
66
|
+
}
|
|
67
|
+
function start(event, action) {
|
|
68
|
+
event.stopPropagation();
|
|
69
|
+
if (disabled || event.button !== 0 || (drag.current && !event.isPrimary))
|
|
70
|
+
return;
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
73
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
74
|
+
drag.current = { id: event.pointerId, origin: { x: event.clientX, y: event.clientY }, selection: remember(rect, stage, ratio), action,
|
|
75
|
+
rtl: getComputedStyle(event.currentTarget).direction === "rtl" };
|
|
76
|
+
}
|
|
77
|
+
function move(event) {
|
|
78
|
+
const from = drag.current;
|
|
79
|
+
if (disabled || from?.id !== event.pointerId)
|
|
80
|
+
return;
|
|
81
|
+
event.stopPropagation();
|
|
82
|
+
if (from.selection.aspect !== ratio)
|
|
83
|
+
return;
|
|
84
|
+
const next = adjust(from.action, bounds(from.selection, stage), stage, ratio, event.clientX - from.origin.x, event.clientY - from.origin.y, from.rtl);
|
|
85
|
+
setSelection(remember(next, stage, ratio));
|
|
86
|
+
}
|
|
87
|
+
function stop(event) {
|
|
88
|
+
if (drag.current?.id !== event.pointerId)
|
|
89
|
+
return;
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
drag.current = null;
|
|
92
|
+
}
|
|
93
|
+
function key(event, action) {
|
|
94
|
+
const step = steps[event.key];
|
|
95
|
+
if (disabled || !step || event.altKey || event.ctrlKey || event.metaKey)
|
|
96
|
+
return;
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
const amount = event.shiftKey ? 10 : 1;
|
|
100
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
101
|
+
setSelection(remember(adjust(action, rect, stage, ratio, step.x * amount, step.y * amount, rtl), stage, ratio));
|
|
102
|
+
}
|
|
103
|
+
const control = (action, label, description) => (_jsx("button", { type: "button", className: `elea-cropper__${action}`, "aria-label": label, "aria-describedby": `${descriptionId}-${action}`, "aria-keyshortcuts": "ArrowLeft ArrowRight ArrowUp ArrowDown Shift+ArrowLeft Shift+ArrowRight Shift+ArrowUp Shift+ArrowDown", disabled: disabled, onKeyDown: event => key(event, action), onPointerDown: event => start(event, action), onPointerMove: move, onPointerUp: stop, onPointerCancel: stop, onLostPointerCapture: stop, children: _jsx("span", { hidden: true, id: `${descriptionId}-${action}`, children: description }) }));
|
|
104
|
+
const overlay = _jsxs("div", { className: "elea-cropper__crop-window", style: { left: rect.x, top: rect.y, width: rect.width, height: rect.height }, children: [control("move", labels.move, `x: ${Math.round(rect.x)}, y: ${Math.round(rect.y)}`), control("resize", labels.resize, `${Math.round(rect.width)} × ${Math.round(rect.height)}`)] });
|
|
105
|
+
return { rect, overlay };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=CropMask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CropMask.js","sourceRoot":"","sources":["../src/CropMask.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAyD,MAAM,OAAO,CAAC;AAk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E,uBACzG,uGAAuG,EACzH,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,EACxG,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,YACzF,eAAM,MAAM,QAAC,EAAE,EAAE,GAAG,aAAa,IAAI,MAAM,EAAE,YAAG,WAAW,GAAQ,GAC5D,CACV,CAAC;IACF,MAAM,OAAO,GAAG,eAAK,SAAS,EAAC,2BAA2B,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,aACpI,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAClF,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IACvF,CAAC;IACP,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface DropZoneProps {
|
|
3
|
+
/** Receives the files dropped or picked; one at most unless `multiple`. */
|
|
4
|
+
onFiles: (files: File[]) => void;
|
|
5
|
+
/** The `accept` of the file input, e.g. `image/*`; dropped files outside it are refused. */
|
|
6
|
+
accept?: string | undefined;
|
|
7
|
+
multiple?: boolean | undefined;
|
|
8
|
+
disabled?: boolean | undefined;
|
|
9
|
+
/** Shown while the host processes the files: the zone stays visible but inert. */
|
|
10
|
+
busy?: boolean | undefined;
|
|
11
|
+
/** The main line, e.g. "Click to add an image". */
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
/** The second line, e.g. "or drag and drop". */
|
|
14
|
+
hint?: ReactNode | undefined;
|
|
15
|
+
/** What to say while busy, in place of the label. */
|
|
16
|
+
busyLabel?: ReactNode | undefined;
|
|
17
|
+
icon?: ReactNode | undefined;
|
|
18
|
+
error?: ReactNode | undefined;
|
|
19
|
+
/** Replaces the label, hint and icon with custom content. */
|
|
20
|
+
children?: ReactNode | undefined;
|
|
21
|
+
className?: string | undefined;
|
|
22
|
+
/** Text matching `accept`, announced when a dropped file is refused. */
|
|
23
|
+
onRejected?: ((files: File[]) => void) | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** A file matches an `accept` list the way the browser's file picker reads it. */
|
|
26
|
+
export declare function acceptsFile(file: File, accept: string | undefined): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A zone that takes files by drop, click or keyboard. The input is a real file input, so forms,
|
|
29
|
+
* assistive technology and test tooling see it; the label makes the whole zone its target.
|
|
30
|
+
*/
|
|
31
|
+
export declare function DropZone({ onFiles, accept, multiple, disabled, busy, label, hint, busyLabel, icon, error, children, className, onRejected }: Readonly<DropZoneProps>): import("react").JSX.Element;
|
|
32
|
+
//# sourceMappingURL=DropZone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropZone.d.ts","sourceRoot":"","sources":["../src/DropZone.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA+D,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpG,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAA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