assui 2.0.2 → 2.0.6

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.
Files changed (245) hide show
  1. package/es/button-drawer/index.d.ts +10 -0
  2. package/es/button-drawer/index.js +116 -0
  3. package/es/button-drawer/style/index.d.ts +1 -0
  4. package/es/button-drawer/style/index.js +1 -0
  5. package/es/button-modal/index.d.ts +14 -0
  6. package/es/button-modal/index.js +131 -0
  7. package/es/button-modal/style/index.d.ts +1 -0
  8. package/es/button-modal/style/index.js +1 -0
  9. package/es/condition-input/index.d.ts +15 -0
  10. package/es/condition-input/index.js +108 -0
  11. package/es/condition-input/parse2RegexOption.d.ts +13 -0
  12. package/es/condition-input/parse2RegexOption.js +57 -0
  13. package/es/condition-input/style/index.d.ts +1 -0
  14. package/es/condition-input/style/index.js +1 -0
  15. package/es/copy-to-clipboard/index.d.ts +22 -0
  16. package/es/copy-to-clipboard/index.js +95 -0
  17. package/es/copy-to-clipboard/style/index.css +249 -0
  18. package/es/copy-to-clipboard/style/index.d.ts +1 -0
  19. package/es/copy-to-clipboard/style/index.js +1 -0
  20. package/es/copy-to-clipboard/style/index.less +1 -0
  21. package/es/highlight-textarea/HighlighedContents.d.ts +7 -0
  22. package/es/highlight-textarea/HighlighedContents.js +15 -0
  23. package/es/highlight-textarea/extractSpansOfClasses.d.ts +15 -0
  24. package/es/highlight-textarea/extractSpansOfClasses.js +159 -0
  25. package/es/highlight-textarea/getRanges.d.ts +2 -0
  26. package/es/highlight-textarea/getRanges.js +142 -0
  27. package/es/highlight-textarea/getType.d.ts +2 -0
  28. package/es/highlight-textarea/getType.js +29 -0
  29. package/es/highlight-textarea/index.d.ts +12 -0
  30. package/es/highlight-textarea/index.js +132 -0
  31. package/es/highlight-textarea/style/index.css +38 -0
  32. package/es/highlight-textarea/style/index.d.ts +2 -0
  33. package/es/highlight-textarea/style/index.js +2 -0
  34. package/es/highlight-textarea/style/index.less +42 -0
  35. package/es/highlight-textarea/types.d.ts +16 -0
  36. package/es/highlight-textarea/types.js +0 -0
  37. package/es/highlight-words/index.d.ts +3 -0
  38. package/es/highlight-words/index.js +2 -0
  39. package/es/highlight-words/style/index.d.ts +1 -0
  40. package/es/highlight-words/style/index.js +0 -0
  41. package/es/icon/demo/svg/check-circle-filled.svg +6 -0
  42. package/es/icon/demo/svg/coin-circle.svg +9 -0
  43. package/es/icon/index.d.ts +27 -0
  44. package/es/icon/index.js +95 -0
  45. package/es/icon/style/index.d.ts +1 -0
  46. package/es/icon/style/index.js +0 -0
  47. package/es/icon/utils.d.ts +6 -0
  48. package/es/icon/utils.js +22 -0
  49. package/es/img-crop/EasyCrop.d.ts +6 -0
  50. package/es/img-crop/EasyCrop.js +113 -0
  51. package/es/img-crop/getCroppedImg.d.ts +6 -0
  52. package/es/img-crop/getCroppedImg.js +199 -0
  53. package/es/img-crop/index.d.ts +53 -0
  54. package/es/img-crop/index.js +531 -0
  55. package/es/img-crop/style/index.css +52 -0
  56. package/es/img-crop/style/index.d.ts +3 -0
  57. package/es/img-crop/style/index.js +3 -0
  58. package/es/img-crop/style/index.less +54 -0
  59. package/es/index.d.ts +34 -2
  60. package/es/index.js +18 -2
  61. package/es/keep-tab/demo/index.modules.less +66 -0
  62. package/es/keep-tab/index.d.ts +29 -0
  63. package/es/keep-tab/index.js +129 -0
  64. package/es/keep-tab/style/index.css +1129 -0
  65. package/es/keep-tab/style/index.d.ts +2 -0
  66. package/es/keep-tab/style/index.js +2 -0
  67. package/es/keep-tab/style/index.less +2 -0
  68. package/es/number-input/index.d.ts +22 -7
  69. package/es/number-input/index.js +22 -11
  70. package/es/number-input/style/index.d.ts +1 -1
  71. package/es/number-input/style/index.js +1 -1
  72. package/es/number-input/utils.d.ts +10 -11
  73. package/es/number-input/utils.js +7 -7
  74. package/es/rc-echart/core.d.ts +32 -0
  75. package/es/rc-echart/core.js +136 -0
  76. package/es/rc-echart/index.d.ts +21 -0
  77. package/es/rc-echart/index.js +27 -0
  78. package/es/rc-echart/style/index.d.ts +1 -0
  79. package/es/rc-echart/style/index.js +0 -0
  80. package/es/rc-motion/demo/CSSMotion.less +91 -0
  81. package/es/rc-motion/index.d.ts +2 -0
  82. package/es/rc-motion/index.js +2 -0
  83. package/es/rc-motion/style/index.d.ts +1 -0
  84. package/es/rc-motion/style/index.js +0 -0
  85. package/es/rc-qrcode/index.d.ts +20 -0
  86. package/es/rc-qrcode/index.js +57 -0
  87. package/es/rc-qrcode/style/index.d.ts +1 -0
  88. package/es/rc-qrcode/style/index.js +0 -0
  89. package/es/rc-qrcode/useQrcode.d.ts +4 -0
  90. package/es/rc-qrcode/useQrcode.js +50 -0
  91. package/es/rc-transition-group/index.d.ts +2 -0
  92. package/es/rc-transition-group/index.js +2 -0
  93. package/es/rc-transition-group/style/index.d.ts +1 -0
  94. package/es/rc-transition-group/style/index.js +0 -0
  95. package/es/single-img-upload/index.d.ts +19 -0
  96. package/es/single-img-upload/index.js +199 -0
  97. package/es/single-img-upload/style/index.css +74 -0
  98. package/es/single-img-upload/style/index.d.ts +3 -0
  99. package/es/single-img-upload/style/index.js +3 -0
  100. package/es/single-img-upload/style/index.less +85 -0
  101. package/es/sortable-hoc/demo/VerticalListBase/index.modules.less +63 -0
  102. package/es/sortable-hoc/demo/index.modules.less +248 -0
  103. package/es/sortable-hoc/index.d.ts +2 -0
  104. package/es/sortable-hoc/index.js +2 -0
  105. package/es/sortable-hoc/style/index.d.ts +1 -0
  106. package/es/sortable-hoc/style/index.js +0 -0
  107. package/es/split-pane/index.d.ts +59 -0
  108. package/es/split-pane/index.js +21 -0
  109. package/es/split-pane/style/index.css +41 -0
  110. package/es/split-pane/style/index.d.ts +1 -0
  111. package/es/split-pane/style/index.js +1 -0
  112. package/es/split-pane/style/index.less +49 -0
  113. package/es/text-area/index.d.ts +12 -0
  114. package/es/text-area/index.js +96 -0
  115. package/es/text-area/style/index.d.ts +1 -0
  116. package/es/text-area/style/index.js +1 -0
  117. package/es/text-input/index.d.ts +5 -0
  118. package/es/text-input/index.js +85 -0
  119. package/es/{number-input → text-input}/style/index.css +0 -3
  120. package/es/text-input/style/index.d.ts +1 -0
  121. package/es/text-input/style/index.js +1 -0
  122. package/es/{number-input → text-input}/style/index.less +0 -4
  123. package/lib/button-drawer/index.d.ts +10 -0
  124. package/lib/button-drawer/index.js +164 -0
  125. package/lib/button-drawer/style/index.d.ts +1 -0
  126. package/lib/button-drawer/style/index.js +7 -0
  127. package/lib/button-modal/index.d.ts +14 -0
  128. package/lib/button-modal/index.js +178 -0
  129. package/lib/button-modal/style/index.d.ts +1 -0
  130. package/lib/button-modal/style/index.js +7 -0
  131. package/lib/condition-input/index.d.ts +15 -0
  132. package/lib/condition-input/index.js +158 -0
  133. package/lib/condition-input/parse2RegexOption.d.ts +13 -0
  134. package/lib/condition-input/parse2RegexOption.js +72 -0
  135. package/lib/condition-input/style/index.d.ts +1 -0
  136. package/lib/condition-input/style/index.js +7 -0
  137. package/lib/copy-to-clipboard/index.d.ts +22 -0
  138. package/lib/copy-to-clipboard/index.js +143 -0
  139. package/lib/copy-to-clipboard/style/index.css +249 -0
  140. package/lib/copy-to-clipboard/style/index.d.ts +1 -0
  141. package/lib/copy-to-clipboard/style/index.js +7 -0
  142. package/lib/copy-to-clipboard/style/index.less +1 -0
  143. package/lib/highlight-textarea/HighlighedContents.d.ts +7 -0
  144. package/lib/highlight-textarea/HighlighedContents.js +29 -0
  145. package/lib/highlight-textarea/extractSpansOfClasses.d.ts +15 -0
  146. package/lib/highlight-textarea/extractSpansOfClasses.js +173 -0
  147. package/lib/highlight-textarea/getRanges.d.ts +2 -0
  148. package/lib/highlight-textarea/getRanges.js +156 -0
  149. package/lib/highlight-textarea/getType.d.ts +2 -0
  150. package/lib/highlight-textarea/getType.js +37 -0
  151. package/lib/highlight-textarea/index.d.ts +12 -0
  152. package/lib/highlight-textarea/index.js +183 -0
  153. package/lib/highlight-textarea/style/index.css +38 -0
  154. package/lib/highlight-textarea/style/index.d.ts +2 -0
  155. package/lib/highlight-textarea/style/index.js +9 -0
  156. package/lib/highlight-textarea/style/index.less +42 -0
  157. package/lib/highlight-textarea/types.d.ts +16 -0
  158. package/lib/highlight-textarea/types.js +5 -0
  159. package/lib/highlight-words/index.d.ts +3 -0
  160. package/lib/highlight-words/index.js +15 -0
  161. package/lib/highlight-words/style/index.d.ts +1 -0
  162. package/lib/highlight-words/style/index.js +0 -0
  163. package/lib/icon/demo/svg/check-circle-filled.svg +6 -0
  164. package/lib/icon/demo/svg/coin-circle.svg +9 -0
  165. package/lib/icon/index.d.ts +27 -0
  166. package/lib/icon/index.js +143 -0
  167. package/lib/icon/style/index.d.ts +1 -0
  168. package/lib/icon/style/index.js +0 -0
  169. package/lib/icon/utils.d.ts +6 -0
  170. package/lib/icon/utils.js +32 -0
  171. package/lib/img-crop/EasyCrop.d.ts +6 -0
  172. package/lib/img-crop/EasyCrop.js +160 -0
  173. package/lib/img-crop/getCroppedImg.d.ts +6 -0
  174. package/lib/img-crop/getCroppedImg.js +205 -0
  175. package/lib/img-crop/index.d.ts +53 -0
  176. package/lib/img-crop/index.js +582 -0
  177. package/lib/img-crop/style/index.css +52 -0
  178. package/lib/img-crop/style/index.d.ts +3 -0
  179. package/lib/img-crop/style/index.js +11 -0
  180. package/lib/img-crop/style/index.less +54 -0
  181. package/lib/index.d.ts +34 -2
  182. package/lib/index.js +160 -9
  183. package/lib/keep-tab/demo/index.modules.less +66 -0
  184. package/lib/keep-tab/index.d.ts +29 -0
  185. package/lib/keep-tab/index.js +181 -0
  186. package/lib/keep-tab/style/index.css +1129 -0
  187. package/lib/keep-tab/style/index.d.ts +2 -0
  188. package/lib/keep-tab/style/index.js +9 -0
  189. package/lib/keep-tab/style/index.less +2 -0
  190. package/lib/number-input/index.d.ts +22 -7
  191. package/lib/number-input/index.js +22 -11
  192. package/lib/number-input/style/index.d.ts +1 -1
  193. package/lib/number-input/style/index.js +1 -1
  194. package/lib/number-input/utils.d.ts +10 -11
  195. package/lib/number-input/utils.js +8 -8
  196. package/lib/rc-echart/core.d.ts +32 -0
  197. package/lib/rc-echart/core.js +185 -0
  198. package/lib/rc-echart/index.d.ts +21 -0
  199. package/lib/rc-echart/index.js +75 -0
  200. package/lib/rc-echart/style/index.d.ts +1 -0
  201. package/lib/rc-echart/style/index.js +0 -0
  202. package/lib/rc-motion/demo/CSSMotion.less +91 -0
  203. package/lib/rc-motion/index.d.ts +2 -0
  204. package/lib/rc-motion/index.js +43 -0
  205. package/lib/rc-motion/style/index.d.ts +1 -0
  206. package/lib/rc-motion/style/index.js +0 -0
  207. package/lib/rc-qrcode/index.d.ts +20 -0
  208. package/lib/rc-qrcode/index.js +108 -0
  209. package/lib/rc-qrcode/style/index.d.ts +1 -0
  210. package/lib/rc-qrcode/style/index.js +0 -0
  211. package/lib/rc-qrcode/useQrcode.d.ts +4 -0
  212. package/lib/rc-qrcode/useQrcode.js +66 -0
  213. package/lib/rc-transition-group/index.d.ts +2 -0
  214. package/lib/rc-transition-group/index.js +43 -0
  215. package/lib/rc-transition-group/style/index.d.ts +1 -0
  216. package/lib/rc-transition-group/style/index.js +0 -0
  217. package/lib/single-img-upload/index.d.ts +19 -0
  218. package/lib/single-img-upload/index.js +250 -0
  219. package/lib/single-img-upload/style/index.css +74 -0
  220. package/lib/single-img-upload/style/index.d.ts +3 -0
  221. package/lib/single-img-upload/style/index.js +11 -0
  222. package/lib/single-img-upload/style/index.less +85 -0
  223. package/lib/sortable-hoc/demo/VerticalListBase/index.modules.less +63 -0
  224. package/lib/sortable-hoc/demo/index.modules.less +248 -0
  225. package/lib/sortable-hoc/index.d.ts +2 -0
  226. package/lib/sortable-hoc/index.js +43 -0
  227. package/lib/sortable-hoc/style/index.d.ts +1 -0
  228. package/lib/sortable-hoc/style/index.js +0 -0
  229. package/lib/split-pane/index.d.ts +59 -0
  230. package/lib/split-pane/index.js +69 -0
  231. package/lib/split-pane/style/index.css +41 -0
  232. package/lib/split-pane/style/index.d.ts +1 -0
  233. package/lib/split-pane/style/index.js +7 -0
  234. package/lib/split-pane/style/index.less +49 -0
  235. package/lib/text-area/index.d.ts +12 -0
  236. package/lib/text-area/index.js +144 -0
  237. package/lib/text-area/style/index.d.ts +1 -0
  238. package/lib/text-area/style/index.js +7 -0
  239. package/lib/text-input/index.d.ts +5 -0
  240. package/lib/text-input/index.js +99 -0
  241. package/lib/{number-input → text-input}/style/index.css +0 -3
  242. package/lib/text-input/style/index.d.ts +1 -0
  243. package/lib/text-input/style/index.js +7 -0
  244. package/lib/{number-input → text-input}/style/index.less +0 -4
  245. package/package.json +20 -3
@@ -0,0 +1,6 @@
1
+ interface pixelCropType {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ declare function getCroppedImg(imageSrc: string, pixelCrop: pixelCropType, name: string, type: string): Promise<unknown>;
6
+ export default getCroppedImg;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+
3
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P ? value : new P(function (resolve) {
6
+ resolve(value);
7
+ });
8
+ }
9
+
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) {
12
+ try {
13
+ step(generator.next(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ }
18
+
19
+ function rejected(value) {
20
+ try {
21
+ step(generator["throw"](value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ }
26
+
27
+ function step(result) {
28
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
29
+ }
30
+
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+
35
+ var __generator = this && this.__generator || function (thisArg, body) {
36
+ var _ = {
37
+ label: 0,
38
+ sent: function sent() {
39
+ if (t[0] & 1) throw t[1];
40
+ return t[1];
41
+ },
42
+ trys: [],
43
+ ops: []
44
+ },
45
+ f,
46
+ y,
47
+ t,
48
+ g;
49
+ return g = {
50
+ next: verb(0),
51
+ "throw": verb(1),
52
+ "return": verb(2)
53
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
54
+ return this;
55
+ }), g;
56
+
57
+ function verb(n) {
58
+ return function (v) {
59
+ return step([n, v]);
60
+ };
61
+ }
62
+
63
+ function step(op) {
64
+ if (f) throw new TypeError("Generator is already executing.");
65
+
66
+ while (_) {
67
+ try {
68
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
69
+ if (y = 0, t) op = [op[0] & 2, t.value];
70
+
71
+ switch (op[0]) {
72
+ case 0:
73
+ case 1:
74
+ t = op;
75
+ break;
76
+
77
+ case 4:
78
+ _.label++;
79
+ return {
80
+ value: op[1],
81
+ done: false
82
+ };
83
+
84
+ case 5:
85
+ _.label++;
86
+ y = op[1];
87
+ op = [0];
88
+ continue;
89
+
90
+ case 7:
91
+ op = _.ops.pop();
92
+
93
+ _.trys.pop();
94
+
95
+ continue;
96
+
97
+ default:
98
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
99
+ _ = 0;
100
+ continue;
101
+ }
102
+
103
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
104
+ _.label = op[1];
105
+ break;
106
+ }
107
+
108
+ if (op[0] === 6 && _.label < t[1]) {
109
+ _.label = t[1];
110
+ t = op;
111
+ break;
112
+ }
113
+
114
+ if (t && _.label < t[2]) {
115
+ _.label = t[2];
116
+
117
+ _.ops.push(op);
118
+
119
+ break;
120
+ }
121
+
122
+ if (t[2]) _.ops.pop();
123
+
124
+ _.trys.pop();
125
+
126
+ continue;
127
+ }
128
+
129
+ op = body.call(thisArg, _);
130
+ } catch (e) {
131
+ op = [6, e];
132
+ y = 0;
133
+ } finally {
134
+ f = t = 0;
135
+ }
136
+ }
137
+
138
+ if (op[0] & 5) throw op[1];
139
+ return {
140
+ value: op[0] ? op[1] : void 0,
141
+ done: true
142
+ };
143
+ }
144
+ };
145
+
146
+ Object.defineProperty(exports, "__esModule", {
147
+ value: true
148
+ });
149
+
150
+ var createImage = function createImage(url) {
151
+ return new Promise(function (resolve, reject) {
152
+ var image = new Image();
153
+ image.addEventListener('load', function () {
154
+ return resolve(image);
155
+ });
156
+ image.addEventListener('error', function (error) {
157
+ return reject(error);
158
+ });
159
+ image.setAttribute('crossOrigin', 'anonymous'); // needed to avoid cross-origin issues on CodeSandbox
160
+
161
+ image.src = url;
162
+ });
163
+ };
164
+
165
+ function getCroppedImg(imageSrc, pixelCrop, name, type) {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ var _a, width, _b, height, image, bodyEl, canvas, ctx;
168
+
169
+ return __generator(this, function (_c) {
170
+ switch (_c.label) {
171
+ case 0:
172
+ _a = pixelCrop.width, width = _a === void 0 ? 670 : _a, _b = pixelCrop.height, height = _b === void 0 ? 280 : _b;
173
+ return [4
174
+ /*yield*/
175
+ , createImage(imageSrc)];
176
+
177
+ case 1:
178
+ image = _c.sent();
179
+ bodyEl = document.querySelector('body');
180
+ bodyEl.appendChild(image);
181
+ canvas = document.createElement('canvas');
182
+ ctx = canvas.getContext('2d');
183
+ canvas.width = width;
184
+ canvas.height = height;
185
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(image, 0, 0, width, height);
186
+ bodyEl.removeChild(image); // As a blob
187
+
188
+ return [2
189
+ /*return*/
190
+ , new Promise(function (resolve) {
191
+ canvas.toBlob(function (file) {
192
+ resolve({
193
+ url: URL.createObjectURL(file),
194
+ fileObj: new File([file], name, {
195
+ type: type
196
+ })
197
+ });
198
+ }, type);
199
+ })];
200
+ }
201
+ });
202
+ });
203
+ }
204
+
205
+ exports["default"] = getCroppedImg;
@@ -0,0 +1,53 @@
1
+ import * as React from 'react';
2
+ import { CropperProps } from 'react-easy-crop';
3
+ import getCroppedImg from './getCroppedImg';
4
+ import './style/index.less';
5
+ export interface RcFile extends File {
6
+ uid: string;
7
+ }
8
+ export interface ImgCropProps {
9
+ prefix: string;
10
+ aspect: number;
11
+ shape: 'rect' | 'round';
12
+ grid?: boolean;
13
+ quality?: number;
14
+ zoom?: boolean;
15
+ rotate?: boolean;
16
+ minZoom: number;
17
+ maxZoom: number;
18
+ fillColor: string;
19
+ modalTitle: string;
20
+ modalWidth?: string | number;
21
+ modalCancel?: string;
22
+ modalOk?: string;
23
+ zipImg?: {
24
+ width: number;
25
+ height: number;
26
+ };
27
+ beforeCrop?: (file: RcFile, fileList: RcFile[]) => boolean;
28
+ cropperProps?: CropperProps;
29
+ children?: React.ReactElement;
30
+ }
31
+ export declare type Area = {
32
+ width: number;
33
+ height: number;
34
+ x: number;
35
+ y: number;
36
+ };
37
+ declare const ImgCrop: {
38
+ (props: ImgCropProps): JSX.Element;
39
+ defaultProps: {
40
+ prefix: string;
41
+ aspect: number;
42
+ shape: string;
43
+ grid: boolean;
44
+ quality: number;
45
+ zoom: boolean;
46
+ rotate: boolean;
47
+ minZoom: number;
48
+ maxZoom: number;
49
+ fillColor: string;
50
+ };
51
+ getCroppedImg: typeof getCroppedImg;
52
+ };
53
+ export default ImgCrop;
@@ -0,0 +1,582 @@
1
+ "use strict";
2
+
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+
8
+ for (var p in s) {
9
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10
+ }
11
+ }
12
+
13
+ return t;
14
+ };
15
+
16
+ return __assign.apply(this, arguments);
17
+ };
18
+
19
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ Object.defineProperty(o, k2, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return m[k];
25
+ }
26
+ });
27
+ } : function (o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ });
31
+
32
+ var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
33
+ Object.defineProperty(o, "default", {
34
+ enumerable: true,
35
+ value: v
36
+ });
37
+ } : function (o, v) {
38
+ o["default"] = v;
39
+ });
40
+
41
+ var __importStar = this && this.__importStar || function (mod) {
42
+ if (mod && mod.__esModule) return mod;
43
+ var result = {};
44
+ if (mod != null) for (var k in mod) {
45
+ if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
46
+ }
47
+
48
+ __setModuleDefault(result, mod);
49
+
50
+ return result;
51
+ };
52
+
53
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
54
+ function adopt(value) {
55
+ return value instanceof P ? value : new P(function (resolve) {
56
+ resolve(value);
57
+ });
58
+ }
59
+
60
+ return new (P || (P = Promise))(function (resolve, reject) {
61
+ function fulfilled(value) {
62
+ try {
63
+ step(generator.next(value));
64
+ } catch (e) {
65
+ reject(e);
66
+ }
67
+ }
68
+
69
+ function rejected(value) {
70
+ try {
71
+ step(generator["throw"](value));
72
+ } catch (e) {
73
+ reject(e);
74
+ }
75
+ }
76
+
77
+ function step(result) {
78
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
79
+ }
80
+
81
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
82
+ });
83
+ };
84
+
85
+ var __generator = this && this.__generator || function (thisArg, body) {
86
+ var _ = {
87
+ label: 0,
88
+ sent: function sent() {
89
+ if (t[0] & 1) throw t[1];
90
+ return t[1];
91
+ },
92
+ trys: [],
93
+ ops: []
94
+ },
95
+ f,
96
+ y,
97
+ t,
98
+ g;
99
+ return g = {
100
+ next: verb(0),
101
+ "throw": verb(1),
102
+ "return": verb(2)
103
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
104
+ return this;
105
+ }), g;
106
+
107
+ function verb(n) {
108
+ return function (v) {
109
+ return step([n, v]);
110
+ };
111
+ }
112
+
113
+ function step(op) {
114
+ if (f) throw new TypeError("Generator is already executing.");
115
+
116
+ while (_) {
117
+ try {
118
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
119
+ if (y = 0, t) op = [op[0] & 2, t.value];
120
+
121
+ switch (op[0]) {
122
+ case 0:
123
+ case 1:
124
+ t = op;
125
+ break;
126
+
127
+ case 4:
128
+ _.label++;
129
+ return {
130
+ value: op[1],
131
+ done: false
132
+ };
133
+
134
+ case 5:
135
+ _.label++;
136
+ y = op[1];
137
+ op = [0];
138
+ continue;
139
+
140
+ case 7:
141
+ op = _.ops.pop();
142
+
143
+ _.trys.pop();
144
+
145
+ continue;
146
+
147
+ default:
148
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
149
+ _ = 0;
150
+ continue;
151
+ }
152
+
153
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
154
+ _.label = op[1];
155
+ break;
156
+ }
157
+
158
+ if (op[0] === 6 && _.label < t[1]) {
159
+ _.label = t[1];
160
+ t = op;
161
+ break;
162
+ }
163
+
164
+ if (t && _.label < t[2]) {
165
+ _.label = t[2];
166
+
167
+ _.ops.push(op);
168
+
169
+ break;
170
+ }
171
+
172
+ if (t[2]) _.ops.pop();
173
+
174
+ _.trys.pop();
175
+
176
+ continue;
177
+ }
178
+
179
+ op = body.call(thisArg, _);
180
+ } catch (e) {
181
+ op = [6, e];
182
+ y = 0;
183
+ } finally {
184
+ f = t = 0;
185
+ }
186
+ }
187
+
188
+ if (op[0] & 5) throw op[1];
189
+ return {
190
+ value: op[0] ? op[1] : void 0,
191
+ done: true
192
+ };
193
+ }
194
+ };
195
+
196
+ var __rest = this && this.__rest || function (s, e) {
197
+ var t = {};
198
+
199
+ for (var p in s) {
200
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
201
+ }
202
+
203
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
204
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
205
+ }
206
+ return t;
207
+ };
208
+
209
+ var __read = this && this.__read || function (o, n) {
210
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
211
+ if (!m) return o;
212
+ var i = m.call(o),
213
+ r,
214
+ ar = [],
215
+ e;
216
+
217
+ try {
218
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
219
+ ar.push(r.value);
220
+ }
221
+ } catch (error) {
222
+ e = {
223
+ error: error
224
+ };
225
+ } finally {
226
+ try {
227
+ if (r && !r.done && (m = i["return"])) m.call(i);
228
+ } finally {
229
+ if (e) throw e.error;
230
+ }
231
+ }
232
+
233
+ return ar;
234
+ };
235
+
236
+ var __importDefault = this && this.__importDefault || function (mod) {
237
+ return mod && mod.__esModule ? mod : {
238
+ "default": mod
239
+ };
240
+ };
241
+
242
+ Object.defineProperty(exports, "__esModule", {
243
+ value: true
244
+ });
245
+
246
+ var React = __importStar(require("react"));
247
+
248
+ var modal_1 = __importDefault(require("antd/lib/modal"));
249
+
250
+ var slider_1 = __importDefault(require("antd/lib/slider"));
251
+
252
+ var getCroppedImg_1 = __importDefault(require("./getCroppedImg"));
253
+
254
+ var EasyCrop_1 = __importDefault(require("./EasyCrop"));
255
+
256
+ require("./style/index.less");
257
+
258
+ var noop = function noop() {};
259
+
260
+ var ZOOM_STEP = 0.1;
261
+ var MIN_ROTATE = 0;
262
+ var MAX_ROTATE = 360;
263
+ var ROTATE_STEP = 1;
264
+
265
+ var ImgCrop = function ImgCrop(props) {
266
+ var aspect = props.aspect,
267
+ shape = props.shape,
268
+ grid = props.grid,
269
+ quality = props.quality,
270
+ zoom = props.zoom,
271
+ rotate = props.rotate,
272
+ minZoom = props.minZoom,
273
+ maxZoom = props.maxZoom,
274
+ fillColor = props.fillColor,
275
+ prefix = props.prefix,
276
+ modalTitle = props.modalTitle,
277
+ modalWidth = props.modalWidth,
278
+ modalOk = props.modalOk,
279
+ modalCancel = props.modalCancel,
280
+ beforeCrop = props.beforeCrop,
281
+ zipImg = props.zipImg,
282
+ children = props.children,
283
+ cropperProps = props.cropperProps;
284
+ var pkg = prefix + "-img-crop";
285
+ var MEDIA_CLASS = pkg + "-media";
286
+ var hasZoom = zoom === true;
287
+ var hasRotate = rotate === true;
288
+
289
+ var _a = __read(React.useState(''), 2),
290
+ src = _a[0],
291
+ setSrc = _a[1];
292
+
293
+ var _b = __read(React.useState(1), 2),
294
+ zoomVal = _b[0],
295
+ setZoomVal = _b[1];
296
+
297
+ var _c = __read(React.useState(0), 2),
298
+ rotateVal = _c[0],
299
+ setRotateVal = _c[1];
300
+
301
+ var beforeUploadRef = React.useRef();
302
+ var fileRef = React.useRef();
303
+ var resolveRef = React.useRef(noop);
304
+ var rejectRef = React.useRef(noop);
305
+ var cropPixelsRef = React.useRef();
306
+ /**
307
+ * Upload
308
+ */
309
+
310
+ var renderUpload = React.useCallback(function () {
311
+ var upload = Array.isArray(children) ? children[0] : children;
312
+
313
+ var _a = upload.props,
314
+ beforeUpload = _a.beforeUpload,
315
+ accept = _a.accept,
316
+ restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
317
+
318
+ beforeUploadRef.current = beforeUpload;
319
+ return __assign(__assign({}, upload), {
320
+ props: __assign(__assign({}, restUploadProps), {
321
+ accept: accept || 'image/*',
322
+ beforeUpload: function beforeUpload(file, fileList) {
323
+ return new Promise(function (resolve, reject) {
324
+ if (beforeCrop && !beforeCrop(file, fileList)) {
325
+ reject();
326
+ return;
327
+ }
328
+
329
+ fileRef.current = file;
330
+ resolveRef.current = resolve;
331
+ rejectRef.current = reject;
332
+ var reader = new FileReader();
333
+ reader.addEventListener('load', function () {
334
+ setSrc(reader.result);
335
+ });
336
+ reader.readAsDataURL(file);
337
+ });
338
+ }
339
+ })
340
+ });
341
+ }, [beforeCrop, children]);
342
+ /**
343
+ * EasyCrop
344
+ */
345
+
346
+ var onComplete = React.useCallback(function (croppedAreaPixels) {
347
+ cropPixelsRef.current = croppedAreaPixels;
348
+ }, []);
349
+ /**
350
+ * Controls
351
+ */
352
+
353
+ var isMinZoom = zoomVal - ZOOM_STEP < minZoom;
354
+ var isMaxZoom = zoomVal + ZOOM_STEP > maxZoom;
355
+ var isMinRotate = rotateVal === MIN_ROTATE;
356
+ var isMaxRotate = rotateVal === MAX_ROTATE;
357
+ var subZoomVal = React.useCallback(function () {
358
+ if (!isMinZoom) setZoomVal(zoomVal - ZOOM_STEP);
359
+ }, [isMinZoom, zoomVal]);
360
+ var addZoomVal = React.useCallback(function () {
361
+ if (!isMaxZoom) setZoomVal(zoomVal + ZOOM_STEP);
362
+ }, [isMaxZoom, zoomVal]);
363
+ var subRotateVal = React.useCallback(function () {
364
+ if (!isMinRotate) setRotateVal(rotateVal - ROTATE_STEP);
365
+ }, [isMinRotate, rotateVal]);
366
+ var addRotateVal = React.useCallback(function () {
367
+ if (!isMaxRotate) setRotateVal(rotateVal + ROTATE_STEP);
368
+ }, [isMaxRotate, rotateVal]);
369
+ /**
370
+ * Modal
371
+ */
372
+
373
+ var modalProps = React.useMemo(function () {
374
+ var obj = {
375
+ width: modalWidth,
376
+ okText: modalOk,
377
+ cancelText: modalCancel
378
+ };
379
+ return obj;
380
+ }, [modalCancel, modalOk, modalWidth]);
381
+ var onClose = React.useCallback(function () {
382
+ setSrc('');
383
+ setZoomVal(1);
384
+ setRotateVal(0);
385
+ }, []);
386
+ var onOk = React.useCallback(function () {
387
+ return __awaiter(void 0, void 0, void 0, function () {
388
+ var naturalImg, naturalWidth, naturalHeight, canvas, ctx, maxLen, halfMax, left, top, maxImgData, _a, width, height, x, y, _b, type, name, uid;
389
+
390
+ return __generator(this, function (_c) {
391
+ onClose();
392
+ naturalImg = document.querySelector("." + MEDIA_CLASS);
393
+ naturalWidth = naturalImg.naturalWidth, naturalHeight = naturalImg.naturalHeight;
394
+ canvas = document.createElement('canvas');
395
+ ctx = canvas.getContext('2d');
396
+ maxLen = Math.sqrt(Math.pow(naturalWidth, 2) + Math.pow(naturalHeight, 2));
397
+ canvas.width = maxLen;
398
+ canvas.height = maxLen; // rotate the image
399
+
400
+ if (hasRotate && rotateVal > 0 && rotateVal < 360) {
401
+ halfMax = maxLen / 2;
402
+ ctx === null || ctx === void 0 ? void 0 : ctx.translate(halfMax, halfMax);
403
+ ctx === null || ctx === void 0 ? void 0 : ctx.rotate(rotateVal * Math.PI / 180);
404
+ ctx === null || ctx === void 0 ? void 0 : ctx.translate(-halfMax, -halfMax);
405
+ }
406
+
407
+ ctx.fillStyle = fillColor;
408
+ ctx === null || ctx === void 0 ? void 0 : ctx.fillRect(0, 0, canvas.width, canvas.height);
409
+ left = (maxLen - naturalWidth) / 2;
410
+ top = (maxLen - naturalHeight) / 2;
411
+ ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(naturalImg, left, top);
412
+ maxImgData = ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(0, 0, maxLen, maxLen);
413
+ _a = cropPixelsRef.current, width = _a.width, height = _a.height, x = _a.x, y = _a.y;
414
+ canvas.width = width;
415
+ canvas.height = height;
416
+ ctx.putImageData(maxImgData, Math.round(-left - x), Math.round(-top - y));
417
+ _b = fileRef.current, type = _b.type, name = _b.name, uid = _b.uid;
418
+ canvas.toBlob(function (blob) {
419
+ return __awaiter(void 0, void 0, void 0, function () {
420
+ var newFile, url, imgUrl, fileObj, res, passedFile, fileType, err_1;
421
+ return __generator(this, function (_a) {
422
+ switch (_a.label) {
423
+ case 0:
424
+ newFile = new File([blob], name, {
425
+ type: type
426
+ });
427
+ if (!zipImg) return [3
428
+ /*break*/
429
+ , 2];
430
+ url = window.URL || window.webkitURL;
431
+ imgUrl = url.createObjectURL(newFile);
432
+ return [4
433
+ /*yield*/
434
+ , getCroppedImg_1["default"](imgUrl, zipImg, name, type)];
435
+
436
+ case 1:
437
+ fileObj = _a.sent().fileObj;
438
+ newFile = fileObj;
439
+ _a.label = 2;
440
+
441
+ case 2:
442
+ newFile.uid = uid;
443
+ if (typeof beforeUploadRef.current !== 'function') return [2
444
+ /*return*/
445
+ , resolveRef.current(newFile)];
446
+ res = beforeUploadRef.current(newFile, [newFile]);
447
+ if (!(typeof res !== 'boolean' && !res)) return [3
448
+ /*break*/
449
+ , 3];
450
+ console.error('beforeUpload must return a boolean or Promise');
451
+ return [3
452
+ /*break*/
453
+ , 7];
454
+
455
+ case 3:
456
+ if (res === true) return [2
457
+ /*return*/
458
+ , resolveRef.current(newFile)];
459
+ if (res === false) return [2
460
+ /*return*/
461
+ , rejectRef.current('not upload')];
462
+ if (!(res && typeof res.then === 'function')) return [3
463
+ /*break*/
464
+ , 7];
465
+ _a.label = 4;
466
+
467
+ case 4:
468
+ _a.trys.push([4, 6,, 7]);
469
+
470
+ return [4
471
+ /*yield*/
472
+ , res];
473
+
474
+ case 5:
475
+ passedFile = _a.sent();
476
+ fileType = Object.prototype.toString.call(passedFile);
477
+ if (fileType === '[object File]' || fileType === '[object Blob]') newFile = passedFile;
478
+ resolveRef.current(newFile);
479
+ return [3
480
+ /*break*/
481
+ , 7];
482
+
483
+ case 6:
484
+ err_1 = _a.sent();
485
+ rejectRef.current(err_1);
486
+ return [3
487
+ /*break*/
488
+ , 7];
489
+
490
+ case 7:
491
+ return [2
492
+ /*return*/
493
+ , null];
494
+ }
495
+ });
496
+ });
497
+ }, type, quality);
498
+ return [2
499
+ /*return*/
500
+ ];
501
+ });
502
+ });
503
+ }, [hasRotate, onClose, quality, rotateVal]);
504
+
505
+ var renderComponent = function renderComponent(titleOfModal) {
506
+ return React.createElement(React.Fragment, null, renderUpload(), src && React.createElement(modal_1["default"], __assign({
507
+ visible: true,
508
+ wrapClassName: pkg + "-modal",
509
+ title: titleOfModal,
510
+ onOk: onOk,
511
+ onCancel: onClose,
512
+ maskClosable: false,
513
+ destroyOnClose: true
514
+ }, modalProps), React.createElement(EasyCrop_1["default"], __assign({
515
+ image: src,
516
+ aspect: aspect,
517
+ cropShape: shape,
518
+ showGrid: grid,
519
+ zoomWithScroll: hasZoom,
520
+ zoom: zoomVal,
521
+ rotation: rotateVal,
522
+ onZoomChange: setZoomVal,
523
+ onRotationChange: setRotateVal,
524
+ minZoom: minZoom,
525
+ maxZoom: maxZoom,
526
+ onComplete: onComplete,
527
+ classes: {
528
+ containerClassName: pkg + "-container",
529
+ mediaClassName: MEDIA_CLASS
530
+ }
531
+ }, cropperProps)), hasZoom && React.createElement("div", {
532
+ className: pkg + "-control zoom"
533
+ }, React.createElement("button", {
534
+ type: "button",
535
+ onClick: subZoomVal,
536
+ disabled: isMinZoom
537
+ }, "\uFF0D"), React.createElement(slider_1["default"], {
538
+ min: minZoom,
539
+ max: maxZoom,
540
+ step: ZOOM_STEP,
541
+ value: zoomVal,
542
+ onChange: setZoomVal
543
+ }), React.createElement("button", {
544
+ type: "button",
545
+ onClick: addZoomVal,
546
+ disabled: isMaxZoom
547
+ }, "\uFF0B")), hasRotate && React.createElement("div", {
548
+ className: pkg + "-control rotate"
549
+ }, React.createElement("button", {
550
+ type: "button",
551
+ onClick: subRotateVal,
552
+ disabled: isMinRotate
553
+ }, "\u21BA"), React.createElement(slider_1["default"], {
554
+ min: MIN_ROTATE,
555
+ max: MAX_ROTATE,
556
+ step: ROTATE_STEP,
557
+ value: rotateVal,
558
+ onChange: setRotateVal
559
+ }), React.createElement("button", {
560
+ type: "button",
561
+ onClick: addRotateVal,
562
+ disabled: isMaxRotate
563
+ }, "\u21BB"))));
564
+ };
565
+
566
+ return renderComponent(modalTitle);
567
+ };
568
+
569
+ ImgCrop.defaultProps = {
570
+ prefix: 'ant',
571
+ aspect: 1,
572
+ shape: 'rect',
573
+ grid: false,
574
+ quality: 0.4,
575
+ zoom: true,
576
+ rotate: false,
577
+ minZoom: 1,
578
+ maxZoom: 3,
579
+ fillColor: 'rgba(0,0,0,0)'
580
+ };
581
+ ImgCrop.getCroppedImg = getCroppedImg_1["default"];
582
+ exports["default"] = ImgCrop;