uview-pro 0.0.13 → 0.0.15

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 (234) hide show
  1. package/changelog.md +236 -217
  2. package/components/u-action-sheet/types.ts +35 -35
  3. package/components/u-action-sheet/u-action-sheet.vue +160 -160
  4. package/components/u-alert-tips/types.ts +39 -39
  5. package/components/u-alert-tips/u-alert-tips.vue +212 -212
  6. package/components/u-avatar/types.ts +34 -34
  7. package/components/u-avatar/u-avatar.vue +193 -193
  8. package/components/u-avatar-cropper/types.ts +23 -23
  9. package/components/u-avatar-cropper/u-avatar-cropper.vue +286 -286
  10. package/components/u-avatar-cropper/weCropper.d.ts +62 -62
  11. package/components/u-avatar-cropper/weCropper.js +1253 -1253
  12. package/components/u-avatar-cropper/weCropper.ts +1255 -1255
  13. package/components/u-back-top/types.ts +39 -39
  14. package/components/u-back-top/u-back-top.vue +125 -125
  15. package/components/u-badge/types.ts +36 -36
  16. package/components/u-badge/u-badge.vue +165 -165
  17. package/components/u-button/types.ts +66 -66
  18. package/components/u-button/u-button.vue +554 -554
  19. package/components/u-calendar/types.ts +63 -63
  20. package/components/u-calendar/u-calendar.vue +592 -592
  21. package/components/u-car-keyboard/types.ts +12 -12
  22. package/components/u-car-keyboard/u-car-keyboard.vue +234 -234
  23. package/components/u-card/types.ts +59 -59
  24. package/components/u-card/u-card.vue +194 -194
  25. package/components/u-cell-group/types.ts +17 -17
  26. package/components/u-cell-group/u-cell-group.vue +50 -50
  27. package/components/u-cell-item/types.ts +54 -54
  28. package/components/u-cell-item/u-cell-item.vue +202 -202
  29. package/components/u-checkbox/types.ts +31 -31
  30. package/components/u-checkbox/u-checkbox.vue +265 -265
  31. package/components/u-checkbox-group/types.ts +32 -32
  32. package/components/u-checkbox-group/u-checkbox-group.vue +79 -79
  33. package/components/u-circle-progress/types.ts +52 -52
  34. package/components/u-circle-progress/u-circle-progress.vue +189 -189
  35. package/components/u-city-select/types.ts +20 -20
  36. package/components/u-city-select/u-city-select.vue +236 -236
  37. package/components/u-col/types.ts +30 -30
  38. package/components/u-col/u-col.vue +123 -123
  39. package/components/u-collapse/types.ts +31 -31
  40. package/components/u-collapse/u-collapse.vue +68 -68
  41. package/components/u-collapse-item/types.ts +25 -25
  42. package/components/u-collapse-item/u-collapse-item.vue +176 -176
  43. package/components/u-column-notice/types.ts +48 -48
  44. package/components/u-column-notice/u-column-notice.vue +176 -176
  45. package/components/u-count-down/types.ts +42 -42
  46. package/components/u-count-down/u-count-down.vue +258 -258
  47. package/components/u-count-to/types.ts +32 -32
  48. package/components/u-count-to/u-count-to.vue +241 -241
  49. package/components/u-divider/types.ts +31 -31
  50. package/components/u-divider/u-divider.vue +121 -121
  51. package/components/u-dropdown/types.ts +32 -32
  52. package/components/u-dropdown/u-dropdown.vue +289 -289
  53. package/components/u-dropdown-item/types.ts +27 -27
  54. package/components/u-dropdown-item/u-dropdown-item.vue +123 -123
  55. package/components/u-empty/types.ts +36 -36
  56. package/components/u-empty/u-empty.vue +88 -88
  57. package/components/u-field/types.ts +69 -69
  58. package/components/u-field/u-field.vue +354 -354
  59. package/components/u-form/types.ts +6 -4
  60. package/components/u-form/u-form.vue +19 -5
  61. package/components/u-form-item/types.ts +2 -2
  62. package/components/u-form-item/u-form-item.vue +7 -6
  63. package/components/u-full-screen/types.ts +14 -14
  64. package/components/u-full-screen/u-full-screen.vue +82 -82
  65. package/components/u-gap/types.ts +18 -18
  66. package/components/u-gap/u-gap.vue +40 -40
  67. package/components/u-grid/types.ts +19 -19
  68. package/components/u-grid/u-grid.vue +93 -93
  69. package/components/u-grid-item/types.ts +16 -16
  70. package/components/u-grid-item/u-grid-item.vue +130 -130
  71. package/components/u-icon/types.ts +62 -62
  72. package/components/u-icon/u-icon.vue +274 -274
  73. package/components/u-image/types.ts +51 -49
  74. package/components/u-image/u-image.vue +222 -218
  75. package/components/u-index-anchor/types.ts +16 -16
  76. package/components/u-index-anchor/u-index-anchor.vue +86 -86
  77. package/components/u-index-list/types.ts +43 -43
  78. package/components/u-index-list/u-index-list.vue +355 -355
  79. package/components/u-input/types.ts +140 -140
  80. package/components/u-input/u-input.vue +255 -255
  81. package/components/u-keyboard/types.ts +40 -40
  82. package/components/u-keyboard/u-keyboard.vue +158 -158
  83. package/components/u-lazy-load/types.ts +37 -37
  84. package/components/u-lazy-load/u-lazy-load.vue +233 -233
  85. package/components/u-line/types.ts +44 -44
  86. package/components/u-line/u-line.vue +59 -59
  87. package/components/u-line-progress/types.ts +58 -58
  88. package/components/u-line-progress/u-line-progress.vue +109 -109
  89. package/components/u-link/types.ts +43 -43
  90. package/components/u-link/u-link.vue +75 -75
  91. package/components/u-loading/types.ts +35 -35
  92. package/components/u-loading/u-loading.vue +90 -90
  93. package/components/u-loadmore/types.ts +79 -79
  94. package/components/u-loadmore/u-loadmore.vue +140 -140
  95. package/components/u-mask/types.ts +43 -43
  96. package/components/u-mask/u-mask.vue +106 -106
  97. package/components/u-message-input/types.ts +74 -74
  98. package/components/u-message-input/u-message-input.vue +255 -255
  99. package/components/u-modal/types.ts +118 -118
  100. package/components/u-modal/u-modal.vue +200 -200
  101. package/components/u-navbar/types.ts +103 -103
  102. package/components/u-navbar/u-navbar.vue +226 -226
  103. package/components/u-no-network/image.ts +2 -2
  104. package/components/u-no-network/types.ts +28 -28
  105. package/components/u-no-network/u-no-network.vue +290 -290
  106. package/components/u-notice-bar/types.ts +111 -111
  107. package/components/u-notice-bar/u-notice-bar.vue +174 -174
  108. package/components/u-number-box/types.ts +42 -42
  109. package/components/u-number-box/u-number-box.vue +312 -312
  110. package/components/u-number-keyboard/types.ts +26 -26
  111. package/components/u-number-keyboard/u-number-keyboard.vue +166 -166
  112. package/components/u-picker/types.ts +111 -111
  113. package/components/u-picker/u-picker.vue +637 -637
  114. package/components/u-popup/types.ts +59 -59
  115. package/components/u-popup/u-popup.vue +359 -359
  116. package/components/u-radio/types.ts +25 -25
  117. package/components/u-radio/u-radio.vue +258 -258
  118. package/components/u-radio-group/types.ts +29 -29
  119. package/components/u-radio-group/u-radio-group.vue +98 -98
  120. package/components/u-rate/types.ts +40 -40
  121. package/components/u-rate/u-rate.vue +234 -234
  122. package/components/u-read-more/types.ts +35 -35
  123. package/components/u-read-more/u-read-more.vue +150 -150
  124. package/components/u-row/types.ts +20 -20
  125. package/components/u-row/u-row.vue +87 -87
  126. package/components/u-row-notice/types.ts +39 -39
  127. package/components/u-row-notice/u-row-notice.vue +213 -213
  128. package/components/u-search/types.ts +53 -53
  129. package/components/u-search/u-search.vue +256 -256
  130. package/components/u-section/types.ts +32 -32
  131. package/components/u-section/u-section.vue +125 -125
  132. package/components/u-select/types.ts +43 -43
  133. package/components/u-select/u-select.vue +361 -345
  134. package/components/u-skeleton/types.ts +20 -20
  135. package/components/u-skeleton/u-skeleton.vue +205 -205
  136. package/components/u-slider/types.ts +32 -32
  137. package/components/u-slider/u-slider.vue +238 -238
  138. package/components/u-steps/types.ts +28 -28
  139. package/components/u-steps/u-steps.vue +160 -160
  140. package/components/u-sticky/types.ts +22 -22
  141. package/components/u-sticky/u-sticky.vue +159 -159
  142. package/components/u-subsection/types.ts +36 -36
  143. package/components/u-subsection/u-subsection.vue +328 -328
  144. package/components/u-swipe-action/types.ts +50 -50
  145. package/components/u-swipe-action/u-swipe-action.vue +253 -252
  146. package/components/u-swiper/types.ts +47 -47
  147. package/components/u-swiper/u-swiper.vue +266 -266
  148. package/components/u-switch/types.ts +28 -28
  149. package/components/u-switch/u-switch.vue +128 -128
  150. package/components/u-tabbar/types.ts +36 -36
  151. package/components/u-tabbar/u-tabbar.vue +280 -280
  152. package/components/u-table/types.ts +25 -25
  153. package/components/u-table/u-table.vue +55 -55
  154. package/components/u-tabs/types.ts +51 -51
  155. package/components/u-tabs/u-tabs.vue +284 -284
  156. package/components/u-tabs-swiper/types.ts +53 -53
  157. package/components/u-tabs-swiper/u-tabs-swiper.vue +379 -379
  158. package/components/u-tag/types.ts +37 -37
  159. package/components/u-tag/u-tag.vue +244 -244
  160. package/components/u-td/types.ts +12 -12
  161. package/components/u-td/u-td.vue +69 -69
  162. package/components/u-th/types.ts +12 -12
  163. package/components/u-th/u-th.vue +63 -63
  164. package/components/u-time-line/u-time-line.vue +39 -39
  165. package/components/u-time-line-item/types.ts +14 -14
  166. package/components/u-time-line-item/u-time-line-item.vue +78 -78
  167. package/components/u-toast/types.ts +36 -36
  168. package/components/u-toast/u-toast.vue +233 -233
  169. package/components/u-top-tips/types.ts +14 -14
  170. package/components/u-top-tips/u-top-tips.vue +113 -113
  171. package/components/u-tr/types.ts +8 -8
  172. package/components/u-tr/u-tr.vue +24 -24
  173. package/components/u-upload/types.ts +71 -71
  174. package/components/u-upload/u-upload.vue +545 -545
  175. package/components/u-verification-code/types.ts +22 -22
  176. package/components/u-verification-code/u-verification-code.vue +164 -164
  177. package/components/u-waterfall/types.ts +16 -16
  178. package/components/u-waterfall/u-waterfall.vue +170 -170
  179. package/iconfont.css +910 -910
  180. package/index.scss +22 -22
  181. package/index.ts +202 -202
  182. package/libs/config/config.ts +26 -26
  183. package/libs/config/zIndex.ts +37 -37
  184. package/libs/css/color.scss +155 -155
  185. package/libs/css/common.scss +175 -175
  186. package/libs/css/style.components.scss +6 -6
  187. package/libs/css/style.h5.scss +8 -8
  188. package/libs/css/style.mp.scss +72 -72
  189. package/libs/css/style.nvue.scss +2 -2
  190. package/libs/css/style.vue.scss +175 -175
  191. package/libs/function/$parent.ts +22 -22
  192. package/libs/function/addUnit.ts +13 -13
  193. package/libs/function/color.ts +36 -36
  194. package/libs/function/colorGradient.ts +125 -125
  195. package/libs/function/debounce.ts +28 -28
  196. package/libs/function/deepClone.ts +39 -39
  197. package/libs/function/deepMerge.ts +34 -34
  198. package/libs/function/getParent.ts +58 -58
  199. package/libs/function/getRect.ts +26 -26
  200. package/libs/function/guid.ts +42 -42
  201. package/libs/function/md5.ts +398 -398
  202. package/libs/function/parent.ts +21 -21
  203. package/libs/function/queryParams.ts +60 -60
  204. package/libs/function/random.ts +16 -16
  205. package/libs/function/randomArray.ts +11 -11
  206. package/libs/function/route.ts +118 -118
  207. package/libs/function/sys.ts +15 -15
  208. package/libs/function/test.ts +229 -229
  209. package/libs/function/throttle.ts +31 -31
  210. package/libs/function/timeFormat.ts +54 -54
  211. package/libs/function/timeFrom.ts +48 -48
  212. package/libs/function/toast.ts +14 -14
  213. package/libs/function/trim.ts +21 -21
  214. package/libs/function/type2icon.ts +36 -36
  215. package/libs/hooks/useEmitter.ts +77 -77
  216. package/libs/hooks/useParent.ts +29 -29
  217. package/libs/request/auto-http.ts +76 -76
  218. package/libs/request/index.ts +237 -237
  219. package/libs/request/uni-http.md +156 -156
  220. package/libs/request/uni-http.ts +434 -434
  221. package/libs/store/index.ts +88 -88
  222. package/libs/util/async-validator.d.ts +62 -62
  223. package/libs/util/async-validator.js +1356 -1356
  224. package/libs/util/emitter.ts +112 -112
  225. package/libs/util/mitt.ts +118 -118
  226. package/libs/util/parent.ts +20 -20
  227. package/package.json +107 -107
  228. package/readme.md +231 -236
  229. package/theme.scss +38 -38
  230. package/types/components.d.ts +94 -94
  231. package/types/global.d.ts +221 -208
  232. package/types/ignore-errors.d.ts +30 -30
  233. package/types/index.d.ts +90 -90
  234. package/types/uni-app.d.ts +63 -63
@@ -1,1253 +1,1253 @@
1
- // @ts-nocheck
2
- /**
3
- * we-cropper v1.3.9
4
- * (c) 2020 dlhandsome
5
- * @license MIT
6
- */
7
- (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined'
9
- ? (module.exports = factory())
10
- : typeof define === 'function' && define.amd
11
- ? define(factory)
12
- : (global.WeCropper = factory());
13
- })(this, function () {
14
- 'use strict';
15
-
16
- var device = void 0;
17
- var TOUCH_STATE = ['touchstarted', 'touchmoved', 'touchended'];
18
-
19
- function firstLetterUpper(str) {
20
- return str.charAt(0).toUpperCase() + str.slice(1);
21
- }
22
-
23
- function setTouchState(instance) {
24
- var arg = [],
25
- len = arguments.length - 1;
26
- while (len-- > 0) arg[len] = arguments[len + 1];
27
-
28
- TOUCH_STATE.forEach(function (key, i) {
29
- if (arg[i] !== undefined) {
30
- instance[key] = arg[i];
31
- }
32
- });
33
- }
34
-
35
- function validator(instance, o) {
36
- Object.defineProperties(instance, o);
37
- }
38
-
39
- function getDevice() {
40
- if (!device) {
41
- device = uni.getSystemInfoSync();
42
- }
43
- return device;
44
- }
45
-
46
- var tmp = {};
47
-
48
- var ref = getDevice();
49
- var pixelRatio = ref.pixelRatio;
50
-
51
- var DEFAULT = {
52
- id: {
53
- default: 'cropper',
54
- get: function get() {
55
- return tmp.id;
56
- },
57
- set: function set(value) {
58
- if (typeof value !== 'string') {
59
- console.error('id:' + value + ' is invalid');
60
- }
61
- tmp.id = value;
62
- }
63
- },
64
- width: {
65
- default: 750,
66
- get: function get() {
67
- return tmp.width;
68
- },
69
- set: function set(value) {
70
- if (typeof value !== 'number') {
71
- console.error('width:' + value + ' is invalid');
72
- }
73
- tmp.width = value;
74
- }
75
- },
76
- height: {
77
- default: 750,
78
- get: function get() {
79
- return tmp.height;
80
- },
81
- set: function set(value) {
82
- if (typeof value !== 'number') {
83
- console.error('height:' + value + ' is invalid');
84
- }
85
- tmp.height = value;
86
- }
87
- },
88
- pixelRatio: {
89
- default: pixelRatio,
90
- get: function get() {
91
- return tmp.pixelRatio;
92
- },
93
- set: function set(value) {
94
- if (typeof value !== 'number') {
95
- console.error('pixelRatio:' + value + ' is invalid');
96
- }
97
- tmp.pixelRatio = value;
98
- }
99
- },
100
- scale: {
101
- default: 2.5,
102
- get: function get() {
103
- return tmp.scale;
104
- },
105
- set: function set(value) {
106
- if (typeof value !== 'number') {
107
- console.error('scale:' + value + ' is invalid');
108
- }
109
- tmp.scale = value;
110
- }
111
- },
112
- zoom: {
113
- default: 5,
114
- get: function get() {
115
- return tmp.zoom;
116
- },
117
- set: function set(value) {
118
- if (typeof value !== 'number') {
119
- console.error('zoom:' + value + ' is invalid');
120
- } else if (value < 0 || value > 10) {
121
- console.error('zoom should be ranged in 0 ~ 10');
122
- }
123
- tmp.zoom = value;
124
- }
125
- },
126
- src: {
127
- default: '',
128
- get: function get() {
129
- return tmp.src;
130
- },
131
- set: function set(value) {
132
- if (typeof value !== 'string') {
133
- console.error('src:' + value + ' is invalid');
134
- }
135
- tmp.src = value;
136
- }
137
- },
138
- cut: {
139
- default: {},
140
- get: function get() {
141
- return tmp.cut;
142
- },
143
- set: function set(value) {
144
- if (typeof value !== 'object') {
145
- console.error('cut:' + value + ' is invalid');
146
- }
147
- tmp.cut = value;
148
- }
149
- },
150
- boundStyle: {
151
- default: {},
152
- get: function get() {
153
- return tmp.boundStyle;
154
- },
155
- set: function set(value) {
156
- if (typeof value !== 'object') {
157
- console.error('boundStyle:' + value + ' is invalid');
158
- }
159
- tmp.boundStyle = value;
160
- }
161
- },
162
- onReady: {
163
- default: null,
164
- get: function get() {
165
- return tmp.ready;
166
- },
167
- set: function set(value) {
168
- tmp.ready = value;
169
- }
170
- },
171
- onBeforeImageLoad: {
172
- default: null,
173
- get: function get() {
174
- return tmp.beforeImageLoad;
175
- },
176
- set: function set(value) {
177
- tmp.beforeImageLoad = value;
178
- }
179
- },
180
- onImageLoad: {
181
- default: null,
182
- get: function get() {
183
- return tmp.imageLoad;
184
- },
185
- set: function set(value) {
186
- tmp.imageLoad = value;
187
- }
188
- },
189
- onBeforeDraw: {
190
- default: null,
191
- get: function get() {
192
- return tmp.beforeDraw;
193
- },
194
- set: function set(value) {
195
- tmp.beforeDraw = value;
196
- }
197
- }
198
- };
199
-
200
- var ref$1 = getDevice();
201
- var windowWidth = ref$1.windowWidth;
202
-
203
- function prepare() {
204
- var self = this;
205
-
206
- // v1.4.0 版本中将不再自动绑定we-cropper实例
207
- self.attachPage = function () {
208
- var pages = getCurrentPages();
209
- // 获取到当前page上下文
210
- var pageContext = pages[pages.length - 1];
211
- // 把this依附在Page上下文的wecropper属性上,便于在page钩子函数中访问
212
- Object.defineProperty(pageContext, 'wecropper', {
213
- get: function get() {
214
- console.warn(
215
- 'Instance will not be automatically bound to the page after v1.4.0\n\n' +
216
- 'Please use a custom instance name instead\n\n' +
217
- 'Example: \n' +
218
- 'this.mycropper = new WeCropper(options)\n\n' +
219
- '// ...\n' +
220
- 'this.mycropper.getCropperImage()'
221
- );
222
- return self;
223
- },
224
- configurable: true
225
- });
226
- };
227
-
228
- self.createCtx = function () {
229
- var id = self.id;
230
- var targetId = self.targetId;
231
-
232
- if (id) {
233
- self.ctx = self.ctx || uni.createCanvasContext(id);
234
- self.targetCtx = self.targetCtx || uni.createCanvasContext(targetId);
235
- } else {
236
- console.error("constructor: create canvas context failed, 'id' must be valuable");
237
- }
238
- };
239
-
240
- self.deviceRadio = windowWidth / 750;
241
- }
242
-
243
- var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
244
-
245
- function createCommonjsModule(fn, module) {
246
- return (
247
- (module = {
248
- exports: {}
249
- }),
250
- fn(module, module.exports),
251
- module.exports
252
- );
253
- }
254
-
255
- var tools = createCommonjsModule(function (module, exports) {
256
- /**
257
- * String type check
258
- */
259
- exports.isStr = function (v) {
260
- return typeof v === 'string';
261
- };
262
- /**
263
- * Number type check
264
- */
265
- exports.isNum = function (v) {
266
- return typeof v === 'number';
267
- };
268
- /**
269
- * Array type check
270
- */
271
- exports.isArr = Array.isArray;
272
- /**
273
- * undefined type check
274
- */
275
- exports.isUndef = function (v) {
276
- return v === undefined;
277
- };
278
-
279
- exports.isTrue = function (v) {
280
- return v === true;
281
- };
282
-
283
- exports.isFalse = function (v) {
284
- return v === false;
285
- };
286
- /**
287
- * Function type check
288
- */
289
- exports.isFunc = function (v) {
290
- return typeof v === 'function';
291
- };
292
- /**
293
- * Quick object check - this is primarily used to tell
294
- * Objects from primitive values when we know the value
295
- * is a JSON-compliant type.
296
- */
297
- exports.isObj = exports.isObject = function (obj) {
298
- return obj !== null && typeof obj === 'object';
299
- };
300
-
301
- /**
302
- * Strict object type check. Only returns true
303
- * for plain JavaScript objects.
304
- */
305
- var _toString = Object.prototype.toString;
306
- exports.isPlainObject = function (obj) {
307
- return _toString.call(obj) === '[object Object]';
308
- };
309
-
310
- /**
311
- * Check whether the object has the property.
312
- */
313
- var hasOwnProperty = Object.prototype.hasOwnProperty;
314
- exports.hasOwn = function (obj, key) {
315
- return hasOwnProperty.call(obj, key);
316
- };
317
-
318
- /**
319
- * Perform no operation.
320
- * Stubbing args to make Flow happy without leaving useless transpiled code
321
- * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/)
322
- */
323
- exports.noop = function (a, b, c) {};
324
-
325
- /**
326
- * Check if val is a valid array index.
327
- */
328
- exports.isValidArrayIndex = function (val) {
329
- var n = parseFloat(String(val));
330
- return n >= 0 && Math.floor(n) === n && isFinite(val);
331
- };
332
- });
333
-
334
- var tools_7 = tools.isFunc;
335
- var tools_10 = tools.isPlainObject;
336
-
337
- var EVENT_TYPE = ['ready', 'beforeImageLoad', 'beforeDraw', 'imageLoad'];
338
-
339
- function observer() {
340
- var self = this;
341
-
342
- self.on = function (event, fn) {
343
- if (EVENT_TYPE.indexOf(event) > -1) {
344
- if (tools_7(fn)) {
345
- event === 'ready' ? fn(self) : (self['on' + firstLetterUpper(event)] = fn);
346
- }
347
- } else {
348
- console.error('event: ' + event + ' is invalid');
349
- }
350
- return self;
351
- };
352
- }
353
-
354
- function wxPromise(fn) {
355
- return function (obj) {
356
- var args = [],
357
- len = arguments.length - 1;
358
- while (len-- > 0) args[len] = arguments[len + 1];
359
-
360
- if (obj === void 0) obj = {};
361
- return new Promise(function (resolve, reject) {
362
- obj.success = function (res) {
363
- resolve(res);
364
- };
365
- obj.fail = function (err) {
366
- reject(err);
367
- };
368
- fn.apply(void 0, [obj].concat(args));
369
- });
370
- };
371
- }
372
-
373
- function draw(ctx, reserve) {
374
- if (reserve === void 0) reserve = false;
375
-
376
- return new Promise(function (resolve) {
377
- ctx.draw(reserve, resolve);
378
- });
379
- }
380
-
381
- var getImageInfo = wxPromise(uni.getImageInfo);
382
-
383
- var canvasToTempFilePath = wxPromise(uni.canvasToTempFilePath);
384
-
385
- var base64 = createCommonjsModule(function (module, exports) {
386
- /*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */
387
- (function (root) {
388
- // Detect free variables `exports`.
389
- var freeExports = 'object' == 'object' && exports;
390
-
391
- // Detect free variable `module`.
392
- var freeModule = 'object' == 'object' && module && module.exports == freeExports && module;
393
-
394
- // Detect free variable `global`, from Node.js or Browserified code, and use
395
- // it as `root`.
396
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
397
- if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
398
- root = freeGlobal;
399
- }
400
-
401
- /*--------------------------------------------------------------------------*/
402
-
403
- var InvalidCharacterError = function (message) {
404
- this.message = message;
405
- };
406
- InvalidCharacterError.prototype = new Error();
407
- InvalidCharacterError.prototype.name = 'InvalidCharacterError';
408
-
409
- var error = function (message) {
410
- // Note: the error messages used throughout this file match those used by
411
- // the native `atob`/`btoa` implementation in Chromium.
412
- throw new InvalidCharacterError(message);
413
- };
414
-
415
- var TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
416
- // http://whatwg.org/html/common-microsyntaxes.html#space-character
417
- var REGEX_SPACE_CHARACTERS = /[\t\n\f\r ]/g;
418
-
419
- // `decode` is designed to be fully compatible with `atob` as described in the
420
- // HTML Standard. http://whatwg.org/html/webappapis.html#dom-windowbase64-atob
421
- // The optimized base64-decoding algorithm used is based on @atk’s excellent
422
- // implementation. https://gist.github.com/atk/1020396
423
- var decode = function (input) {
424
- input = String(input).replace(REGEX_SPACE_CHARACTERS, '');
425
- var length = input.length;
426
- if (length % 4 == 0) {
427
- input = input.replace(/==?$/, '');
428
- length = input.length;
429
- }
430
- if (
431
- length % 4 == 1 ||
432
- // http://whatwg.org/C#alphanumeric-ascii-characters
433
- /[^+a-zA-Z0-9/]/.test(input)
434
- ) {
435
- error('Invalid character: the string to be decoded is not correctly encoded.');
436
- }
437
- var bitCounter = 0;
438
- var bitStorage;
439
- var buffer;
440
- var output = '';
441
- var position = -1;
442
- while (++position < length) {
443
- buffer = TABLE.indexOf(input.charAt(position));
444
- bitStorage = bitCounter % 4 ? bitStorage * 64 + buffer : buffer;
445
- // Unless this is the first of a group of 4 characters…
446
- if (bitCounter++ % 4) {
447
- // …convert the first 8 bits to a single ASCII character.
448
- output += String.fromCharCode(0xff & (bitStorage >> ((-2 * bitCounter) & 6)));
449
- }
450
- }
451
- return output;
452
- };
453
-
454
- // `encode` is designed to be fully compatible with `btoa` as described in the
455
- // HTML Standard: http://whatwg.org/html/webappapis.html#dom-windowbase64-btoa
456
- var encode = function (input) {
457
- input = String(input);
458
- if (/[^\0-\xFF]/.test(input)) {
459
- // Note: no need to special-case astral symbols here, as surrogates are
460
- // matched, and the input is supposed to only contain ASCII anyway.
461
- error('The string to be encoded contains characters outside of the ' + 'Latin1 range.');
462
- }
463
- var padding = input.length % 3;
464
- var output = '';
465
- var position = -1;
466
- var a;
467
- var b;
468
- var c;
469
- var buffer;
470
- // Make sure any padding is handled outside of the loop.
471
- var length = input.length - padding;
472
-
473
- while (++position < length) {
474
- // Read three bytes, i.e. 24 bits.
475
- a = input.charCodeAt(position) << 16;
476
- b = input.charCodeAt(++position) << 8;
477
- c = input.charCodeAt(++position);
478
- buffer = a + b + c;
479
- // Turn the 24 bits into four chunks of 6 bits each, and append the
480
- // matching character for each of them to the output.
481
- output += TABLE.charAt((buffer >> 18) & 0x3f) + TABLE.charAt((buffer >> 12) & 0x3f) + TABLE.charAt((buffer >> 6) & 0x3f) + TABLE.charAt(buffer & 0x3f);
482
- }
483
-
484
- if (padding == 2) {
485
- a = input.charCodeAt(position) << 8;
486
- b = input.charCodeAt(++position);
487
- buffer = a + b;
488
- output += TABLE.charAt(buffer >> 10) + TABLE.charAt((buffer >> 4) & 0x3f) + TABLE.charAt((buffer << 2) & 0x3f) + '=';
489
- } else if (padding == 1) {
490
- buffer = input.charCodeAt(position);
491
- output += TABLE.charAt(buffer >> 2) + TABLE.charAt((buffer << 4) & 0x3f) + '==';
492
- }
493
-
494
- return output;
495
- };
496
-
497
- var base64 = {
498
- encode: encode,
499
- decode: decode,
500
- version: '0.1.0'
501
- };
502
-
503
- // Some AMD build optimizers, like r.js, check for specific condition patterns
504
- // like the following:
505
- if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
506
- undefined(function () {
507
- return base64;
508
- });
509
- } else if (freeExports && !freeExports.nodeType) {
510
- if (freeModule) {
511
- // in Node.js or RingoJS v0.8.0+
512
- freeModule.exports = base64;
513
- } else {
514
- // in Narwhal or RingoJS v0.7.0-
515
- for (var key in base64) {
516
- base64.hasOwnProperty(key) && (freeExports[key] = base64[key]);
517
- }
518
- }
519
- } else {
520
- // in Rhino or a web browser
521
- root.base64 = base64;
522
- }
523
- })(commonjsGlobal);
524
- });
525
-
526
- function makeURI(strData, type) {
527
- return 'data:' + type + ';base64,' + strData;
528
- }
529
-
530
- function fixType(type) {
531
- type = type.toLowerCase().replace(/jpg/i, 'jpeg');
532
- var r = type.match(/png|jpeg|bmp|gif/)[0];
533
- return 'image/' + r;
534
- }
535
-
536
- function encodeData(data) {
537
- var str = '';
538
- if (typeof data === 'string') {
539
- str = data;
540
- } else {
541
- for (var i = 0; i < data.length; i++) {
542
- str += String.fromCharCode(data[i]);
543
- }
544
- }
545
- return base64.encode(str);
546
- }
547
-
548
- /**
549
- * 获取图像区域隐含的像素数据
550
- * @param canvasId canvas标识
551
- * @param x 将要被提取的图像数据矩形区域的左上角 x 坐标
552
- * @param y 将要被提取的图像数据矩形区域的左上角 y 坐标
553
- * @param width 将要被提取的图像数据矩形区域的宽度
554
- * @param height 将要被提取的图像数据矩形区域的高度
555
- * @param done 完成回调
556
- */
557
- function getImageData(canvasId, x, y, width, height, done) {
558
- uni.canvasGetImageData({
559
- canvasId: canvasId,
560
- x: x,
561
- y: y,
562
- width: width,
563
- height: height,
564
- success: function success(res) {
565
- done(res, null);
566
- },
567
- fail: function fail(res) {
568
- done(null, res);
569
- }
570
- });
571
- }
572
-
573
- /**
574
- * 生成bmp格式图片
575
- * 按照规则生成图片响应头和响应体
576
- * @param oData 用来描述 canvas 区域隐含的像素数据 { data, width, height } = oData
577
- * @returns {*} base64字符串
578
- */
579
- function genBitmapImage(oData) {
580
- //
581
- // BITMAPFILEHEADER: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
582
- // BITMAPINFOHEADER: http://msdn.microsoft.com/en-us/library/dd183376.aspx
583
- //
584
- var biWidth = oData.width;
585
- var biHeight = oData.height;
586
- var biSizeImage = biWidth * biHeight * 3;
587
- var bfSize = biSizeImage + 54; // total header size = 54 bytes
588
-
589
- //
590
- // typedef struct tagBITMAPFILEHEADER {
591
- // WORD bfType;
592
- // DWORD bfSize;
593
- // WORD bfReserved1;
594
- // WORD bfReserved2;
595
- // DWORD bfOffBits;
596
- // } BITMAPFILEHEADER;
597
- //
598
- var BITMAPFILEHEADER = [
599
- // WORD bfType -- The file type signature; must be "BM"
600
- 0x42,
601
- 0x4d,
602
- // DWORD bfSize -- The size, in bytes, of the bitmap file
603
- bfSize & 0xff,
604
- (bfSize >> 8) & 0xff,
605
- (bfSize >> 16) & 0xff,
606
- (bfSize >> 24) & 0xff,
607
- // WORD bfReserved1 -- Reserved; must be zero
608
- 0,
609
- 0,
610
- // WORD bfReserved2 -- Reserved; must be zero
611
- 0,
612
- 0,
613
- // DWORD bfOffBits -- The offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.
614
- 54,
615
- 0,
616
- 0,
617
- 0
618
- ];
619
-
620
- //
621
- // typedef struct tagBITMAPINFOHEADER {
622
- // DWORD biSize;
623
- // LONG biWidth;
624
- // LONG biHeight;
625
- // WORD biPlanes;
626
- // WORD biBitCount;
627
- // DWORD biCompression;
628
- // DWORD biSizeImage;
629
- // LONG biXPelsPerMeter;
630
- // LONG biYPelsPerMeter;
631
- // DWORD biClrUsed;
632
- // DWORD biClrImportant;
633
- // } BITMAPINFOHEADER, *PBITMAPINFOHEADER;
634
- //
635
- var BITMAPINFOHEADER = [
636
- // DWORD biSize -- The number of bytes required by the structure
637
- 40,
638
- 0,
639
- 0,
640
- 0,
641
- // LONG biWidth -- The width of the bitmap, in pixels
642
- biWidth & 0xff,
643
- (biWidth >> 8) & 0xff,
644
- (biWidth >> 16) & 0xff,
645
- (biWidth >> 24) & 0xff,
646
- // LONG biHeight -- The height of the bitmap, in pixels
647
- biHeight & 0xff,
648
- (biHeight >> 8) & 0xff,
649
- (biHeight >> 16) & 0xff,
650
- (biHeight >> 24) & 0xff,
651
- // WORD biPlanes -- The number of planes for the target device. This value must be set to 1
652
- 1,
653
- 0,
654
- // WORD biBitCount -- The number of bits-per-pixel, 24 bits-per-pixel -- the bitmap
655
- // has a maximum of 2^24 colors (16777216, Truecolor)
656
- 24,
657
- 0,
658
- // DWORD biCompression -- The type of compression, BI_RGB (code 0) -- uncompressed
659
- 0,
660
- 0,
661
- 0,
662
- 0,
663
- // DWORD biSizeImage -- The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps
664
- biSizeImage & 0xff,
665
- (biSizeImage >> 8) & 0xff,
666
- (biSizeImage >> 16) & 0xff,
667
- (biSizeImage >> 24) & 0xff,
668
- // LONG biXPelsPerMeter, unused
669
- 0,
670
- 0,
671
- 0,
672
- 0,
673
- // LONG biYPelsPerMeter, unused
674
- 0,
675
- 0,
676
- 0,
677
- 0,
678
- // DWORD biClrUsed, the number of color indexes of palette, unused
679
- 0,
680
- 0,
681
- 0,
682
- 0,
683
- // DWORD biClrImportant, unused
684
- 0,
685
- 0,
686
- 0,
687
- 0
688
- ];
689
-
690
- var iPadding = (4 - ((biWidth * 3) % 4)) % 4;
691
-
692
- var aImgData = oData.data;
693
-
694
- var strPixelData = '';
695
- var biWidth4 = biWidth << 2;
696
- var y = biHeight;
697
- var fromCharCode = String.fromCharCode;
698
-
699
- do {
700
- var iOffsetY = biWidth4 * (y - 1);
701
- var strPixelRow = '';
702
- for (var x = 0; x < biWidth; x++) {
703
- var iOffsetX = x << 2;
704
- strPixelRow += fromCharCode(aImgData[iOffsetY + iOffsetX + 2]) + fromCharCode(aImgData[iOffsetY + iOffsetX + 1]) + fromCharCode(aImgData[iOffsetY + iOffsetX]);
705
- }
706
-
707
- for (var c = 0; c < iPadding; c++) {
708
- strPixelRow += String.fromCharCode(0);
709
- }
710
-
711
- strPixelData += strPixelRow;
712
- } while (--y);
713
-
714
- var strEncoded = encodeData(BITMAPFILEHEADER.concat(BITMAPINFOHEADER)) + encodeData(strPixelData);
715
-
716
- return strEncoded;
717
- }
718
-
719
- /**
720
- * 转换为图片base64
721
- * @param canvasId canvas标识
722
- * @param x 将要被提取的图像数据矩形区域的左上角 x 坐标
723
- * @param y 将要被提取的图像数据矩形区域的左上角 y 坐标
724
- * @param width 将要被提取的图像数据矩形区域的宽度
725
- * @param height 将要被提取的图像数据矩形区域的高度
726
- * @param type 转换图片类型
727
- * @param done 完成回调
728
- */
729
- function convertToImage(canvasId, x, y, width, height, type, done) {
730
- if (done === void 0) done = function () {};
731
-
732
- if (type === undefined) {
733
- type = 'png';
734
- }
735
- type = fixType(type);
736
- if (/bmp/.test(type)) {
737
- getImageData(canvasId, x, y, width, height, function (data, err) {
738
- var strData = genBitmapImage(data);
739
- tools_7(done) && done(makeURI(strData, 'image/' + type), err);
740
- });
741
- } else {
742
- console.error("暂不支持生成'" + type + "'类型的base64图片");
743
- }
744
- }
745
-
746
- var CanvasToBase64 = {
747
- convertToImage: convertToImage,
748
- // convertToPNG: function (width, height, done) {
749
- // return convertToImage(width, height, 'png', done)
750
- // },
751
- // convertToJPEG: function (width, height, done) {
752
- // return convertToImage(width, height, 'jpeg', done)
753
- // },
754
- // convertToGIF: function (width, height, done) {
755
- // return convertToImage(width, height, 'gif', done)
756
- // },
757
- convertToBMP: function (ref, done) {
758
- if (ref === void 0) ref = {};
759
- var canvasId = ref.canvasId;
760
- var x = ref.x;
761
- var y = ref.y;
762
- var width = ref.width;
763
- var height = ref.height;
764
- if (done === void 0) done = function () {};
765
-
766
- return convertToImage(canvasId, x, y, width, height, 'bmp', done);
767
- }
768
- };
769
-
770
- function methods() {
771
- var self = this;
772
-
773
- var boundWidth = self.width; // 裁剪框默认宽度,即整个画布宽度
774
- var boundHeight = self.height; // 裁剪框默认高度,即整个画布高度
775
-
776
- var id = self.id;
777
- var targetId = self.targetId;
778
- var pixelRatio = self.pixelRatio;
779
-
780
- var ref = self.cut;
781
- var x = ref.x;
782
- if (x === void 0) x = 0;
783
- var y = ref.y;
784
- if (y === void 0) y = 0;
785
- var width = ref.width;
786
- if (width === void 0) width = boundWidth;
787
- var height = ref.height;
788
- if (height === void 0) height = boundHeight;
789
-
790
- self.updateCanvas = function (done) {
791
- if (self.croperTarget) {
792
- // 画布绘制图片
793
- self.ctx.drawImage(self.croperTarget, self.imgLeft, self.imgTop, self.scaleWidth, self.scaleHeight);
794
- }
795
- tools_7(self.onBeforeDraw) && self.onBeforeDraw(self.ctx, self);
796
-
797
- self.setBoundStyle(self.boundStyle); // 设置边界样式
798
-
799
- self.ctx.draw(false, done);
800
- return self;
801
- };
802
-
803
- self.pushOrigin = self.pushOrign = function (src) {
804
- self.src = src;
805
-
806
- tools_7(self.onBeforeImageLoad) && self.onBeforeImageLoad(self.ctx, self);
807
-
808
- return getImageInfo({
809
- src: src
810
- })
811
- .then(function (res) {
812
- var innerAspectRadio = res.width / res.height;
813
- var customAspectRadio = width / height;
814
-
815
- self.croperTarget = res.path;
816
-
817
- if (innerAspectRadio < customAspectRadio) {
818
- self.rectX = x;
819
- self.baseWidth = width;
820
- self.baseHeight = width / innerAspectRadio;
821
- self.rectY = y - Math.abs((height - self.baseHeight) / 2);
822
- } else {
823
- self.rectY = y;
824
- self.baseWidth = height * innerAspectRadio;
825
- self.baseHeight = height;
826
- self.rectX = x - Math.abs((width - self.baseWidth) / 2);
827
- }
828
-
829
- self.imgLeft = self.rectX;
830
- self.imgTop = self.rectY;
831
- self.scaleWidth = self.baseWidth;
832
- self.scaleHeight = self.baseHeight;
833
-
834
- self.update();
835
-
836
- return new Promise(function (resolve) {
837
- self.updateCanvas(resolve);
838
- });
839
- })
840
- .then(function () {
841
- tools_7(self.onImageLoad) && self.onImageLoad(self.ctx, self);
842
- });
843
- };
844
-
845
- self.removeImage = function () {
846
- self.src = '';
847
- self.croperTarget = '';
848
- return draw(self.ctx);
849
- };
850
-
851
- self.getCropperBase64 = function (done) {
852
- if (done === void 0) done = function () {};
853
-
854
- CanvasToBase64.convertToBMP(
855
- {
856
- canvasId: id,
857
- x: x,
858
- y: y,
859
- width: width,
860
- height: height
861
- },
862
- done
863
- );
864
- };
865
-
866
- self.getCropperImage = function (opt, fn) {
867
- var customOptions = opt;
868
-
869
- var canvasOptions = {
870
- canvasId: id,
871
- x: x,
872
- y: y,
873
- width: width,
874
- height: height
875
- };
876
-
877
- var task = function () {
878
- return Promise.resolve();
879
- };
880
-
881
- if (tools_10(customOptions) && customOptions.original) {
882
- // original mode
883
- task = function () {
884
- self.targetCtx.drawImage(self.croperTarget, self.imgLeft * pixelRatio, self.imgTop * pixelRatio, self.scaleWidth * pixelRatio, self.scaleHeight * pixelRatio);
885
-
886
- canvasOptions = {
887
- canvasId: targetId,
888
- x: x * pixelRatio,
889
- y: y * pixelRatio,
890
- width: width * pixelRatio,
891
- height: height * pixelRatio
892
- };
893
-
894
- return draw(self.targetCtx);
895
- };
896
- }
897
-
898
- return task()
899
- .then(function () {
900
- if (tools_10(customOptions)) {
901
- canvasOptions = Object.assign({}, canvasOptions, customOptions);
902
- }
903
-
904
- if (tools_7(customOptions)) {
905
- fn = customOptions;
906
- }
907
-
908
- var arg = canvasOptions.componentContext ? [canvasOptions, canvasOptions.componentContext] : [canvasOptions];
909
-
910
- return canvasToTempFilePath.apply(null, arg);
911
- })
912
- .then(function (res) {
913
- var tempFilePath = res.tempFilePath;
914
-
915
- return tools_7(fn) ? fn.call(self, tempFilePath, null) : tempFilePath;
916
- })
917
- .catch(function (err) {
918
- if (tools_7(fn)) {
919
- fn.call(self, null, err);
920
- } else {
921
- throw err;
922
- }
923
- });
924
- };
925
- }
926
-
927
- /**
928
- * 获取最新缩放值
929
- * @param oldScale 上一次触摸结束后的缩放值
930
- * @param oldDistance 上一次触摸结束后的双指距离
931
- * @param zoom 缩放系数
932
- * @param touch0 第一指touch对象
933
- * @param touch1 第二指touch对象
934
- * @returns {*}
935
- */
936
- var getNewScale = function (oldScale, oldDistance, zoom, touch0, touch1) {
937
- var xMove, yMove, newDistance;
938
- // 计算二指最新距离
939
- xMove = Math.round(touch1.x - touch0.x);
940
- yMove = Math.round(touch1.y - touch0.y);
941
- newDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
942
-
943
- return oldScale + 0.001 * zoom * (newDistance - oldDistance);
944
- };
945
-
946
- function update() {
947
- var self = this;
948
-
949
- if (!self.src) {
950
- return;
951
- }
952
-
953
- self.__oneTouchStart = function (touch) {
954
- self.touchX0 = Math.round(touch.x);
955
- self.touchY0 = Math.round(touch.y);
956
- };
957
-
958
- self.__oneTouchMove = function (touch) {
959
- var xMove, yMove;
960
- // 计算单指移动的距离
961
- if (self.touchended) {
962
- return self.updateCanvas();
963
- }
964
- xMove = Math.round(touch.x - self.touchX0);
965
- yMove = Math.round(touch.y - self.touchY0);
966
-
967
- var imgLeft = Math.round(self.rectX + xMove);
968
- var imgTop = Math.round(self.rectY + yMove);
969
-
970
- self.outsideBound(imgLeft, imgTop);
971
-
972
- self.updateCanvas();
973
- };
974
-
975
- self.__twoTouchStart = function (touch0, touch1) {
976
- var xMove, yMove, oldDistance;
977
-
978
- self.touchX1 = Math.round(self.rectX + self.scaleWidth / 2);
979
- self.touchY1 = Math.round(self.rectY + self.scaleHeight / 2);
980
-
981
- // 计算两指距离
982
- xMove = Math.round(touch1.x - touch0.x);
983
- yMove = Math.round(touch1.y - touch0.y);
984
- oldDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
985
-
986
- self.oldDistance = oldDistance;
987
- };
988
-
989
- self.__twoTouchMove = function (touch0, touch1) {
990
- var oldScale = self.oldScale;
991
- var oldDistance = self.oldDistance;
992
- var scale = self.scale;
993
- var zoom = self.zoom;
994
-
995
- self.newScale = getNewScale(oldScale, oldDistance, zoom, touch0, touch1);
996
-
997
- // 设定缩放范围
998
- self.newScale <= 1 && (self.newScale = 1);
999
- self.newScale >= scale && (self.newScale = scale);
1000
-
1001
- self.scaleWidth = Math.round(self.newScale * self.baseWidth);
1002
- self.scaleHeight = Math.round(self.newScale * self.baseHeight);
1003
- var imgLeft = Math.round(self.touchX1 - self.scaleWidth / 2);
1004
- var imgTop = Math.round(self.touchY1 - self.scaleHeight / 2);
1005
-
1006
- self.outsideBound(imgLeft, imgTop);
1007
-
1008
- self.updateCanvas();
1009
- };
1010
-
1011
- self.__xtouchEnd = function () {
1012
- self.oldScale = self.newScale;
1013
- self.rectX = self.imgLeft;
1014
- self.rectY = self.imgTop;
1015
- };
1016
- }
1017
-
1018
- var handle = {
1019
- // 图片手势初始监测
1020
- touchStart: function touchStart(e) {
1021
- var self = this;
1022
- var ref = e.touches;
1023
- var touch0 = ref[0];
1024
- var touch1 = ref[1];
1025
-
1026
- if (!self.src) {
1027
- return;
1028
- }
1029
-
1030
- setTouchState(self, true, null, null);
1031
-
1032
- // 计算第一个触摸点的位置,并参照改点进行缩放
1033
- self.__oneTouchStart(touch0);
1034
-
1035
- // 两指手势触发
1036
- if (e.touches.length >= 2) {
1037
- self.__twoTouchStart(touch0, touch1);
1038
- }
1039
- },
1040
-
1041
- // 图片手势动态缩放
1042
- touchMove: function touchMove(e) {
1043
- var self = this;
1044
- var ref = e.touches;
1045
- var touch0 = ref[0];
1046
- var touch1 = ref[1];
1047
-
1048
- if (!self.src) {
1049
- return;
1050
- }
1051
-
1052
- setTouchState(self, null, true);
1053
-
1054
- // 单指手势时触发
1055
- if (e.touches.length === 1) {
1056
- self.__oneTouchMove(touch0);
1057
- }
1058
- // 两指手势触发
1059
- if (e.touches.length >= 2) {
1060
- self.__twoTouchMove(touch0, touch1);
1061
- }
1062
- },
1063
-
1064
- touchEnd: function touchEnd(e) {
1065
- var self = this;
1066
-
1067
- if (!self.src) {
1068
- return;
1069
- }
1070
-
1071
- setTouchState(self, false, false, true);
1072
- self.__xtouchEnd();
1073
- }
1074
- };
1075
-
1076
- function cut() {
1077
- var self = this;
1078
- var boundWidth = self.width; // 裁剪框默认宽度,即整个画布宽度
1079
- var boundHeight = self.height;
1080
- // 裁剪框默认高度,即整个画布高度
1081
- var ref = self.cut;
1082
- var x = ref.x;
1083
- if (x === void 0) x = 0;
1084
- var y = ref.y;
1085
- if (y === void 0) y = 0;
1086
- var width = ref.width;
1087
- if (width === void 0) width = boundWidth;
1088
- var height = ref.height;
1089
- if (height === void 0) height = boundHeight;
1090
-
1091
- /**
1092
- * 设置边界
1093
- * @param imgLeft 图片左上角横坐标值
1094
- * @param imgTop 图片左上角纵坐标值
1095
- */
1096
- self.outsideBound = function (imgLeft, imgTop) {
1097
- self.imgLeft = imgLeft >= x ? x : self.scaleWidth + imgLeft - x <= width ? x + width - self.scaleWidth : imgLeft;
1098
-
1099
- self.imgTop = imgTop >= y ? y : self.scaleHeight + imgTop - y <= height ? y + height - self.scaleHeight : imgTop;
1100
- };
1101
-
1102
- /**
1103
- * 设置边界样式
1104
- * @param color 边界颜色
1105
- */
1106
- self.setBoundStyle = function (ref) {
1107
- if (ref === void 0) ref = {};
1108
- var color = ref.color;
1109
- if (color === void 0) color = '#04b00f';
1110
- var mask = ref.mask;
1111
- if (mask === void 0) mask = 'rgba(0, 0, 0, 0.3)';
1112
- var lineWidth = ref.lineWidth;
1113
- if (lineWidth === void 0) lineWidth = 1;
1114
-
1115
- var half = lineWidth / 2;
1116
- var boundOption = [
1117
- {
1118
- start: {
1119
- x: x - half,
1120
- y: y + 10 - half
1121
- },
1122
- step1: {
1123
- x: x - half,
1124
- y: y - half
1125
- },
1126
- step2: {
1127
- x: x + 10 - half,
1128
- y: y - half
1129
- }
1130
- },
1131
- {
1132
- start: {
1133
- x: x - half,
1134
- y: y + height - 10 + half
1135
- },
1136
- step1: {
1137
- x: x - half,
1138
- y: y + height + half
1139
- },
1140
- step2: {
1141
- x: x + 10 - half,
1142
- y: y + height + half
1143
- }
1144
- },
1145
- {
1146
- start: {
1147
- x: x + width - 10 + half,
1148
- y: y - half
1149
- },
1150
- step1: {
1151
- x: x + width + half,
1152
- y: y - half
1153
- },
1154
- step2: {
1155
- x: x + width + half,
1156
- y: y + 10 - half
1157
- }
1158
- },
1159
- {
1160
- start: {
1161
- x: x + width + half,
1162
- y: y + height - 10 + half
1163
- },
1164
- step1: {
1165
- x: x + width + half,
1166
- y: y + height + half
1167
- },
1168
- step2: {
1169
- x: x + width - 10 + half,
1170
- y: y + height + half
1171
- }
1172
- }
1173
- ];
1174
-
1175
- // 绘制半透明层
1176
- self.ctx.beginPath();
1177
- self.ctx.setFillStyle(mask);
1178
- self.ctx.fillRect(0, 0, x, boundHeight);
1179
- self.ctx.fillRect(x, 0, width, y);
1180
- self.ctx.fillRect(x, y + height, width, boundHeight - y - height);
1181
- self.ctx.fillRect(x + width, 0, boundWidth - x - width, boundHeight);
1182
- self.ctx.fill();
1183
-
1184
- boundOption.forEach(function (op) {
1185
- self.ctx.beginPath();
1186
- self.ctx.setStrokeStyle(color);
1187
- self.ctx.setLineWidth(lineWidth);
1188
- self.ctx.moveTo(op.start.x, op.start.y);
1189
- self.ctx.lineTo(op.step1.x, op.step1.y);
1190
- self.ctx.lineTo(op.step2.x, op.step2.y);
1191
- self.ctx.stroke();
1192
- });
1193
- };
1194
- }
1195
-
1196
- var version = '1.3.9';
1197
-
1198
- var WeCropper = function WeCropper(params) {
1199
- var self = this;
1200
- var _default = {};
1201
-
1202
- validator(self, DEFAULT);
1203
-
1204
- Object.keys(DEFAULT).forEach(function (key) {
1205
- _default[key] = DEFAULT[key].default;
1206
- });
1207
- Object.assign(self, _default, params);
1208
-
1209
- self.prepare();
1210
- self.attachPage();
1211
- self.createCtx();
1212
- self.observer();
1213
- self.cutt();
1214
- self.methods();
1215
- self.init();
1216
- self.update();
1217
-
1218
- return self;
1219
- };
1220
-
1221
- WeCropper.prototype.init = function init() {
1222
- var self = this;
1223
- var src = self.src;
1224
-
1225
- self.version = version;
1226
-
1227
- typeof self.onReady === 'function' && self.onReady(self.ctx, self);
1228
-
1229
- if (src) {
1230
- self.pushOrign(src);
1231
- } else {
1232
- self.updateCanvas();
1233
- }
1234
- setTouchState(self, false, false, false);
1235
-
1236
- self.oldScale = 1;
1237
- self.newScale = 1;
1238
-
1239
- return self;
1240
- };
1241
-
1242
- Object.assign(WeCropper.prototype, handle);
1243
-
1244
- WeCropper.prototype.prepare = prepare;
1245
- WeCropper.prototype.observer = observer;
1246
- WeCropper.prototype.methods = methods;
1247
- WeCropper.prototype.cutt = cut;
1248
- WeCropper.prototype.update = update;
1249
-
1250
- return WeCropper;
1251
- });
1252
-
1253
- exports.default = WeCropper;
1
+ // @ts-nocheck
2
+ /**
3
+ * we-cropper v1.3.9
4
+ * (c) 2020 dlhandsome
5
+ * @license MIT
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined'
9
+ ? (module.exports = factory())
10
+ : typeof define === 'function' && define.amd
11
+ ? define(factory)
12
+ : (global.WeCropper = factory());
13
+ })(this, function () {
14
+ 'use strict';
15
+
16
+ var device = void 0;
17
+ var TOUCH_STATE = ['touchstarted', 'touchmoved', 'touchended'];
18
+
19
+ function firstLetterUpper(str) {
20
+ return str.charAt(0).toUpperCase() + str.slice(1);
21
+ }
22
+
23
+ function setTouchState(instance) {
24
+ var arg = [],
25
+ len = arguments.length - 1;
26
+ while (len-- > 0) arg[len] = arguments[len + 1];
27
+
28
+ TOUCH_STATE.forEach(function (key, i) {
29
+ if (arg[i] !== undefined) {
30
+ instance[key] = arg[i];
31
+ }
32
+ });
33
+ }
34
+
35
+ function validator(instance, o) {
36
+ Object.defineProperties(instance, o);
37
+ }
38
+
39
+ function getDevice() {
40
+ if (!device) {
41
+ device = uni.getSystemInfoSync();
42
+ }
43
+ return device;
44
+ }
45
+
46
+ var tmp = {};
47
+
48
+ var ref = getDevice();
49
+ var pixelRatio = ref.pixelRatio;
50
+
51
+ var DEFAULT = {
52
+ id: {
53
+ default: 'cropper',
54
+ get: function get() {
55
+ return tmp.id;
56
+ },
57
+ set: function set(value) {
58
+ if (typeof value !== 'string') {
59
+ console.error('id:' + value + ' is invalid');
60
+ }
61
+ tmp.id = value;
62
+ }
63
+ },
64
+ width: {
65
+ default: 750,
66
+ get: function get() {
67
+ return tmp.width;
68
+ },
69
+ set: function set(value) {
70
+ if (typeof value !== 'number') {
71
+ console.error('width:' + value + ' is invalid');
72
+ }
73
+ tmp.width = value;
74
+ }
75
+ },
76
+ height: {
77
+ default: 750,
78
+ get: function get() {
79
+ return tmp.height;
80
+ },
81
+ set: function set(value) {
82
+ if (typeof value !== 'number') {
83
+ console.error('height:' + value + ' is invalid');
84
+ }
85
+ tmp.height = value;
86
+ }
87
+ },
88
+ pixelRatio: {
89
+ default: pixelRatio,
90
+ get: function get() {
91
+ return tmp.pixelRatio;
92
+ },
93
+ set: function set(value) {
94
+ if (typeof value !== 'number') {
95
+ console.error('pixelRatio:' + value + ' is invalid');
96
+ }
97
+ tmp.pixelRatio = value;
98
+ }
99
+ },
100
+ scale: {
101
+ default: 2.5,
102
+ get: function get() {
103
+ return tmp.scale;
104
+ },
105
+ set: function set(value) {
106
+ if (typeof value !== 'number') {
107
+ console.error('scale:' + value + ' is invalid');
108
+ }
109
+ tmp.scale = value;
110
+ }
111
+ },
112
+ zoom: {
113
+ default: 5,
114
+ get: function get() {
115
+ return tmp.zoom;
116
+ },
117
+ set: function set(value) {
118
+ if (typeof value !== 'number') {
119
+ console.error('zoom:' + value + ' is invalid');
120
+ } else if (value < 0 || value > 10) {
121
+ console.error('zoom should be ranged in 0 ~ 10');
122
+ }
123
+ tmp.zoom = value;
124
+ }
125
+ },
126
+ src: {
127
+ default: '',
128
+ get: function get() {
129
+ return tmp.src;
130
+ },
131
+ set: function set(value) {
132
+ if (typeof value !== 'string') {
133
+ console.error('src:' + value + ' is invalid');
134
+ }
135
+ tmp.src = value;
136
+ }
137
+ },
138
+ cut: {
139
+ default: {},
140
+ get: function get() {
141
+ return tmp.cut;
142
+ },
143
+ set: function set(value) {
144
+ if (typeof value !== 'object') {
145
+ console.error('cut:' + value + ' is invalid');
146
+ }
147
+ tmp.cut = value;
148
+ }
149
+ },
150
+ boundStyle: {
151
+ default: {},
152
+ get: function get() {
153
+ return tmp.boundStyle;
154
+ },
155
+ set: function set(value) {
156
+ if (typeof value !== 'object') {
157
+ console.error('boundStyle:' + value + ' is invalid');
158
+ }
159
+ tmp.boundStyle = value;
160
+ }
161
+ },
162
+ onReady: {
163
+ default: null,
164
+ get: function get() {
165
+ return tmp.ready;
166
+ },
167
+ set: function set(value) {
168
+ tmp.ready = value;
169
+ }
170
+ },
171
+ onBeforeImageLoad: {
172
+ default: null,
173
+ get: function get() {
174
+ return tmp.beforeImageLoad;
175
+ },
176
+ set: function set(value) {
177
+ tmp.beforeImageLoad = value;
178
+ }
179
+ },
180
+ onImageLoad: {
181
+ default: null,
182
+ get: function get() {
183
+ return tmp.imageLoad;
184
+ },
185
+ set: function set(value) {
186
+ tmp.imageLoad = value;
187
+ }
188
+ },
189
+ onBeforeDraw: {
190
+ default: null,
191
+ get: function get() {
192
+ return tmp.beforeDraw;
193
+ },
194
+ set: function set(value) {
195
+ tmp.beforeDraw = value;
196
+ }
197
+ }
198
+ };
199
+
200
+ var ref$1 = getDevice();
201
+ var windowWidth = ref$1.windowWidth;
202
+
203
+ function prepare() {
204
+ var self = this;
205
+
206
+ // v1.4.0 版本中将不再自动绑定we-cropper实例
207
+ self.attachPage = function () {
208
+ var pages = getCurrentPages();
209
+ // 获取到当前page上下文
210
+ var pageContext = pages[pages.length - 1];
211
+ // 把this依附在Page上下文的wecropper属性上,便于在page钩子函数中访问
212
+ Object.defineProperty(pageContext, 'wecropper', {
213
+ get: function get() {
214
+ console.warn(
215
+ 'Instance will not be automatically bound to the page after v1.4.0\n\n' +
216
+ 'Please use a custom instance name instead\n\n' +
217
+ 'Example: \n' +
218
+ 'this.mycropper = new WeCropper(options)\n\n' +
219
+ '// ...\n' +
220
+ 'this.mycropper.getCropperImage()'
221
+ );
222
+ return self;
223
+ },
224
+ configurable: true
225
+ });
226
+ };
227
+
228
+ self.createCtx = function () {
229
+ var id = self.id;
230
+ var targetId = self.targetId;
231
+
232
+ if (id) {
233
+ self.ctx = self.ctx || uni.createCanvasContext(id);
234
+ self.targetCtx = self.targetCtx || uni.createCanvasContext(targetId);
235
+ } else {
236
+ console.error("constructor: create canvas context failed, 'id' must be valuable");
237
+ }
238
+ };
239
+
240
+ self.deviceRadio = windowWidth / 750;
241
+ }
242
+
243
+ var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
244
+
245
+ function createCommonjsModule(fn, module) {
246
+ return (
247
+ (module = {
248
+ exports: {}
249
+ }),
250
+ fn(module, module.exports),
251
+ module.exports
252
+ );
253
+ }
254
+
255
+ var tools = createCommonjsModule(function (module, exports) {
256
+ /**
257
+ * String type check
258
+ */
259
+ exports.isStr = function (v) {
260
+ return typeof v === 'string';
261
+ };
262
+ /**
263
+ * Number type check
264
+ */
265
+ exports.isNum = function (v) {
266
+ return typeof v === 'number';
267
+ };
268
+ /**
269
+ * Array type check
270
+ */
271
+ exports.isArr = Array.isArray;
272
+ /**
273
+ * undefined type check
274
+ */
275
+ exports.isUndef = function (v) {
276
+ return v === undefined;
277
+ };
278
+
279
+ exports.isTrue = function (v) {
280
+ return v === true;
281
+ };
282
+
283
+ exports.isFalse = function (v) {
284
+ return v === false;
285
+ };
286
+ /**
287
+ * Function type check
288
+ */
289
+ exports.isFunc = function (v) {
290
+ return typeof v === 'function';
291
+ };
292
+ /**
293
+ * Quick object check - this is primarily used to tell
294
+ * Objects from primitive values when we know the value
295
+ * is a JSON-compliant type.
296
+ */
297
+ exports.isObj = exports.isObject = function (obj) {
298
+ return obj !== null && typeof obj === 'object';
299
+ };
300
+
301
+ /**
302
+ * Strict object type check. Only returns true
303
+ * for plain JavaScript objects.
304
+ */
305
+ var _toString = Object.prototype.toString;
306
+ exports.isPlainObject = function (obj) {
307
+ return _toString.call(obj) === '[object Object]';
308
+ };
309
+
310
+ /**
311
+ * Check whether the object has the property.
312
+ */
313
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
314
+ exports.hasOwn = function (obj, key) {
315
+ return hasOwnProperty.call(obj, key);
316
+ };
317
+
318
+ /**
319
+ * Perform no operation.
320
+ * Stubbing args to make Flow happy without leaving useless transpiled code
321
+ * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/)
322
+ */
323
+ exports.noop = function (a, b, c) {};
324
+
325
+ /**
326
+ * Check if val is a valid array index.
327
+ */
328
+ exports.isValidArrayIndex = function (val) {
329
+ var n = parseFloat(String(val));
330
+ return n >= 0 && Math.floor(n) === n && isFinite(val);
331
+ };
332
+ });
333
+
334
+ var tools_7 = tools.isFunc;
335
+ var tools_10 = tools.isPlainObject;
336
+
337
+ var EVENT_TYPE = ['ready', 'beforeImageLoad', 'beforeDraw', 'imageLoad'];
338
+
339
+ function observer() {
340
+ var self = this;
341
+
342
+ self.on = function (event, fn) {
343
+ if (EVENT_TYPE.indexOf(event) > -1) {
344
+ if (tools_7(fn)) {
345
+ event === 'ready' ? fn(self) : (self['on' + firstLetterUpper(event)] = fn);
346
+ }
347
+ } else {
348
+ console.error('event: ' + event + ' is invalid');
349
+ }
350
+ return self;
351
+ };
352
+ }
353
+
354
+ function wxPromise(fn) {
355
+ return function (obj) {
356
+ var args = [],
357
+ len = arguments.length - 1;
358
+ while (len-- > 0) args[len] = arguments[len + 1];
359
+
360
+ if (obj === void 0) obj = {};
361
+ return new Promise(function (resolve, reject) {
362
+ obj.success = function (res) {
363
+ resolve(res);
364
+ };
365
+ obj.fail = function (err) {
366
+ reject(err);
367
+ };
368
+ fn.apply(void 0, [obj].concat(args));
369
+ });
370
+ };
371
+ }
372
+
373
+ function draw(ctx, reserve) {
374
+ if (reserve === void 0) reserve = false;
375
+
376
+ return new Promise(function (resolve) {
377
+ ctx.draw(reserve, resolve);
378
+ });
379
+ }
380
+
381
+ var getImageInfo = wxPromise(uni.getImageInfo);
382
+
383
+ var canvasToTempFilePath = wxPromise(uni.canvasToTempFilePath);
384
+
385
+ var base64 = createCommonjsModule(function (module, exports) {
386
+ /*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */
387
+ (function (root) {
388
+ // Detect free variables `exports`.
389
+ var freeExports = 'object' == 'object' && exports;
390
+
391
+ // Detect free variable `module`.
392
+ var freeModule = 'object' == 'object' && module && module.exports == freeExports && module;
393
+
394
+ // Detect free variable `global`, from Node.js or Browserified code, and use
395
+ // it as `root`.
396
+ var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
397
+ if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
398
+ root = freeGlobal;
399
+ }
400
+
401
+ /*--------------------------------------------------------------------------*/
402
+
403
+ var InvalidCharacterError = function (message) {
404
+ this.message = message;
405
+ };
406
+ InvalidCharacterError.prototype = new Error();
407
+ InvalidCharacterError.prototype.name = 'InvalidCharacterError';
408
+
409
+ var error = function (message) {
410
+ // Note: the error messages used throughout this file match those used by
411
+ // the native `atob`/`btoa` implementation in Chromium.
412
+ throw new InvalidCharacterError(message);
413
+ };
414
+
415
+ var TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
416
+ // http://whatwg.org/html/common-microsyntaxes.html#space-character
417
+ var REGEX_SPACE_CHARACTERS = /[\t\n\f\r ]/g;
418
+
419
+ // `decode` is designed to be fully compatible with `atob` as described in the
420
+ // HTML Standard. http://whatwg.org/html/webappapis.html#dom-windowbase64-atob
421
+ // The optimized base64-decoding algorithm used is based on @atk’s excellent
422
+ // implementation. https://gist.github.com/atk/1020396
423
+ var decode = function (input) {
424
+ input = String(input).replace(REGEX_SPACE_CHARACTERS, '');
425
+ var length = input.length;
426
+ if (length % 4 == 0) {
427
+ input = input.replace(/==?$/, '');
428
+ length = input.length;
429
+ }
430
+ if (
431
+ length % 4 == 1 ||
432
+ // http://whatwg.org/C#alphanumeric-ascii-characters
433
+ /[^+a-zA-Z0-9/]/.test(input)
434
+ ) {
435
+ error('Invalid character: the string to be decoded is not correctly encoded.');
436
+ }
437
+ var bitCounter = 0;
438
+ var bitStorage;
439
+ var buffer;
440
+ var output = '';
441
+ var position = -1;
442
+ while (++position < length) {
443
+ buffer = TABLE.indexOf(input.charAt(position));
444
+ bitStorage = bitCounter % 4 ? bitStorage * 64 + buffer : buffer;
445
+ // Unless this is the first of a group of 4 characters…
446
+ if (bitCounter++ % 4) {
447
+ // …convert the first 8 bits to a single ASCII character.
448
+ output += String.fromCharCode(0xff & (bitStorage >> ((-2 * bitCounter) & 6)));
449
+ }
450
+ }
451
+ return output;
452
+ };
453
+
454
+ // `encode` is designed to be fully compatible with `btoa` as described in the
455
+ // HTML Standard: http://whatwg.org/html/webappapis.html#dom-windowbase64-btoa
456
+ var encode = function (input) {
457
+ input = String(input);
458
+ if (/[^\0-\xFF]/.test(input)) {
459
+ // Note: no need to special-case astral symbols here, as surrogates are
460
+ // matched, and the input is supposed to only contain ASCII anyway.
461
+ error('The string to be encoded contains characters outside of the ' + 'Latin1 range.');
462
+ }
463
+ var padding = input.length % 3;
464
+ var output = '';
465
+ var position = -1;
466
+ var a;
467
+ var b;
468
+ var c;
469
+ var buffer;
470
+ // Make sure any padding is handled outside of the loop.
471
+ var length = input.length - padding;
472
+
473
+ while (++position < length) {
474
+ // Read three bytes, i.e. 24 bits.
475
+ a = input.charCodeAt(position) << 16;
476
+ b = input.charCodeAt(++position) << 8;
477
+ c = input.charCodeAt(++position);
478
+ buffer = a + b + c;
479
+ // Turn the 24 bits into four chunks of 6 bits each, and append the
480
+ // matching character for each of them to the output.
481
+ output += TABLE.charAt((buffer >> 18) & 0x3f) + TABLE.charAt((buffer >> 12) & 0x3f) + TABLE.charAt((buffer >> 6) & 0x3f) + TABLE.charAt(buffer & 0x3f);
482
+ }
483
+
484
+ if (padding == 2) {
485
+ a = input.charCodeAt(position) << 8;
486
+ b = input.charCodeAt(++position);
487
+ buffer = a + b;
488
+ output += TABLE.charAt(buffer >> 10) + TABLE.charAt((buffer >> 4) & 0x3f) + TABLE.charAt((buffer << 2) & 0x3f) + '=';
489
+ } else if (padding == 1) {
490
+ buffer = input.charCodeAt(position);
491
+ output += TABLE.charAt(buffer >> 2) + TABLE.charAt((buffer << 4) & 0x3f) + '==';
492
+ }
493
+
494
+ return output;
495
+ };
496
+
497
+ var base64 = {
498
+ encode: encode,
499
+ decode: decode,
500
+ version: '0.1.0'
501
+ };
502
+
503
+ // Some AMD build optimizers, like r.js, check for specific condition patterns
504
+ // like the following:
505
+ if (typeof undefined == 'function' && typeof undefined.amd == 'object' && undefined.amd) {
506
+ undefined(function () {
507
+ return base64;
508
+ });
509
+ } else if (freeExports && !freeExports.nodeType) {
510
+ if (freeModule) {
511
+ // in Node.js or RingoJS v0.8.0+
512
+ freeModule.exports = base64;
513
+ } else {
514
+ // in Narwhal or RingoJS v0.7.0-
515
+ for (var key in base64) {
516
+ base64.hasOwnProperty(key) && (freeExports[key] = base64[key]);
517
+ }
518
+ }
519
+ } else {
520
+ // in Rhino or a web browser
521
+ root.base64 = base64;
522
+ }
523
+ })(commonjsGlobal);
524
+ });
525
+
526
+ function makeURI(strData, type) {
527
+ return 'data:' + type + ';base64,' + strData;
528
+ }
529
+
530
+ function fixType(type) {
531
+ type = type.toLowerCase().replace(/jpg/i, 'jpeg');
532
+ var r = type.match(/png|jpeg|bmp|gif/)[0];
533
+ return 'image/' + r;
534
+ }
535
+
536
+ function encodeData(data) {
537
+ var str = '';
538
+ if (typeof data === 'string') {
539
+ str = data;
540
+ } else {
541
+ for (var i = 0; i < data.length; i++) {
542
+ str += String.fromCharCode(data[i]);
543
+ }
544
+ }
545
+ return base64.encode(str);
546
+ }
547
+
548
+ /**
549
+ * 获取图像区域隐含的像素数据
550
+ * @param canvasId canvas标识
551
+ * @param x 将要被提取的图像数据矩形区域的左上角 x 坐标
552
+ * @param y 将要被提取的图像数据矩形区域的左上角 y 坐标
553
+ * @param width 将要被提取的图像数据矩形区域的宽度
554
+ * @param height 将要被提取的图像数据矩形区域的高度
555
+ * @param done 完成回调
556
+ */
557
+ function getImageData(canvasId, x, y, width, height, done) {
558
+ uni.canvasGetImageData({
559
+ canvasId: canvasId,
560
+ x: x,
561
+ y: y,
562
+ width: width,
563
+ height: height,
564
+ success: function success(res) {
565
+ done(res, null);
566
+ },
567
+ fail: function fail(res) {
568
+ done(null, res);
569
+ }
570
+ });
571
+ }
572
+
573
+ /**
574
+ * 生成bmp格式图片
575
+ * 按照规则生成图片响应头和响应体
576
+ * @param oData 用来描述 canvas 区域隐含的像素数据 { data, width, height } = oData
577
+ * @returns {*} base64字符串
578
+ */
579
+ function genBitmapImage(oData) {
580
+ //
581
+ // BITMAPFILEHEADER: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
582
+ // BITMAPINFOHEADER: http://msdn.microsoft.com/en-us/library/dd183376.aspx
583
+ //
584
+ var biWidth = oData.width;
585
+ var biHeight = oData.height;
586
+ var biSizeImage = biWidth * biHeight * 3;
587
+ var bfSize = biSizeImage + 54; // total header size = 54 bytes
588
+
589
+ //
590
+ // typedef struct tagBITMAPFILEHEADER {
591
+ // WORD bfType;
592
+ // DWORD bfSize;
593
+ // WORD bfReserved1;
594
+ // WORD bfReserved2;
595
+ // DWORD bfOffBits;
596
+ // } BITMAPFILEHEADER;
597
+ //
598
+ var BITMAPFILEHEADER = [
599
+ // WORD bfType -- The file type signature; must be "BM"
600
+ 0x42,
601
+ 0x4d,
602
+ // DWORD bfSize -- The size, in bytes, of the bitmap file
603
+ bfSize & 0xff,
604
+ (bfSize >> 8) & 0xff,
605
+ (bfSize >> 16) & 0xff,
606
+ (bfSize >> 24) & 0xff,
607
+ // WORD bfReserved1 -- Reserved; must be zero
608
+ 0,
609
+ 0,
610
+ // WORD bfReserved2 -- Reserved; must be zero
611
+ 0,
612
+ 0,
613
+ // DWORD bfOffBits -- The offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.
614
+ 54,
615
+ 0,
616
+ 0,
617
+ 0
618
+ ];
619
+
620
+ //
621
+ // typedef struct tagBITMAPINFOHEADER {
622
+ // DWORD biSize;
623
+ // LONG biWidth;
624
+ // LONG biHeight;
625
+ // WORD biPlanes;
626
+ // WORD biBitCount;
627
+ // DWORD biCompression;
628
+ // DWORD biSizeImage;
629
+ // LONG biXPelsPerMeter;
630
+ // LONG biYPelsPerMeter;
631
+ // DWORD biClrUsed;
632
+ // DWORD biClrImportant;
633
+ // } BITMAPINFOHEADER, *PBITMAPINFOHEADER;
634
+ //
635
+ var BITMAPINFOHEADER = [
636
+ // DWORD biSize -- The number of bytes required by the structure
637
+ 40,
638
+ 0,
639
+ 0,
640
+ 0,
641
+ // LONG biWidth -- The width of the bitmap, in pixels
642
+ biWidth & 0xff,
643
+ (biWidth >> 8) & 0xff,
644
+ (biWidth >> 16) & 0xff,
645
+ (biWidth >> 24) & 0xff,
646
+ // LONG biHeight -- The height of the bitmap, in pixels
647
+ biHeight & 0xff,
648
+ (biHeight >> 8) & 0xff,
649
+ (biHeight >> 16) & 0xff,
650
+ (biHeight >> 24) & 0xff,
651
+ // WORD biPlanes -- The number of planes for the target device. This value must be set to 1
652
+ 1,
653
+ 0,
654
+ // WORD biBitCount -- The number of bits-per-pixel, 24 bits-per-pixel -- the bitmap
655
+ // has a maximum of 2^24 colors (16777216, Truecolor)
656
+ 24,
657
+ 0,
658
+ // DWORD biCompression -- The type of compression, BI_RGB (code 0) -- uncompressed
659
+ 0,
660
+ 0,
661
+ 0,
662
+ 0,
663
+ // DWORD biSizeImage -- The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps
664
+ biSizeImage & 0xff,
665
+ (biSizeImage >> 8) & 0xff,
666
+ (biSizeImage >> 16) & 0xff,
667
+ (biSizeImage >> 24) & 0xff,
668
+ // LONG biXPelsPerMeter, unused
669
+ 0,
670
+ 0,
671
+ 0,
672
+ 0,
673
+ // LONG biYPelsPerMeter, unused
674
+ 0,
675
+ 0,
676
+ 0,
677
+ 0,
678
+ // DWORD biClrUsed, the number of color indexes of palette, unused
679
+ 0,
680
+ 0,
681
+ 0,
682
+ 0,
683
+ // DWORD biClrImportant, unused
684
+ 0,
685
+ 0,
686
+ 0,
687
+ 0
688
+ ];
689
+
690
+ var iPadding = (4 - ((biWidth * 3) % 4)) % 4;
691
+
692
+ var aImgData = oData.data;
693
+
694
+ var strPixelData = '';
695
+ var biWidth4 = biWidth << 2;
696
+ var y = biHeight;
697
+ var fromCharCode = String.fromCharCode;
698
+
699
+ do {
700
+ var iOffsetY = biWidth4 * (y - 1);
701
+ var strPixelRow = '';
702
+ for (var x = 0; x < biWidth; x++) {
703
+ var iOffsetX = x << 2;
704
+ strPixelRow += fromCharCode(aImgData[iOffsetY + iOffsetX + 2]) + fromCharCode(aImgData[iOffsetY + iOffsetX + 1]) + fromCharCode(aImgData[iOffsetY + iOffsetX]);
705
+ }
706
+
707
+ for (var c = 0; c < iPadding; c++) {
708
+ strPixelRow += String.fromCharCode(0);
709
+ }
710
+
711
+ strPixelData += strPixelRow;
712
+ } while (--y);
713
+
714
+ var strEncoded = encodeData(BITMAPFILEHEADER.concat(BITMAPINFOHEADER)) + encodeData(strPixelData);
715
+
716
+ return strEncoded;
717
+ }
718
+
719
+ /**
720
+ * 转换为图片base64
721
+ * @param canvasId canvas标识
722
+ * @param x 将要被提取的图像数据矩形区域的左上角 x 坐标
723
+ * @param y 将要被提取的图像数据矩形区域的左上角 y 坐标
724
+ * @param width 将要被提取的图像数据矩形区域的宽度
725
+ * @param height 将要被提取的图像数据矩形区域的高度
726
+ * @param type 转换图片类型
727
+ * @param done 完成回调
728
+ */
729
+ function convertToImage(canvasId, x, y, width, height, type, done) {
730
+ if (done === void 0) done = function () {};
731
+
732
+ if (type === undefined) {
733
+ type = 'png';
734
+ }
735
+ type = fixType(type);
736
+ if (/bmp/.test(type)) {
737
+ getImageData(canvasId, x, y, width, height, function (data, err) {
738
+ var strData = genBitmapImage(data);
739
+ tools_7(done) && done(makeURI(strData, 'image/' + type), err);
740
+ });
741
+ } else {
742
+ console.error("暂不支持生成'" + type + "'类型的base64图片");
743
+ }
744
+ }
745
+
746
+ var CanvasToBase64 = {
747
+ convertToImage: convertToImage,
748
+ // convertToPNG: function (width, height, done) {
749
+ // return convertToImage(width, height, 'png', done)
750
+ // },
751
+ // convertToJPEG: function (width, height, done) {
752
+ // return convertToImage(width, height, 'jpeg', done)
753
+ // },
754
+ // convertToGIF: function (width, height, done) {
755
+ // return convertToImage(width, height, 'gif', done)
756
+ // },
757
+ convertToBMP: function (ref, done) {
758
+ if (ref === void 0) ref = {};
759
+ var canvasId = ref.canvasId;
760
+ var x = ref.x;
761
+ var y = ref.y;
762
+ var width = ref.width;
763
+ var height = ref.height;
764
+ if (done === void 0) done = function () {};
765
+
766
+ return convertToImage(canvasId, x, y, width, height, 'bmp', done);
767
+ }
768
+ };
769
+
770
+ function methods() {
771
+ var self = this;
772
+
773
+ var boundWidth = self.width; // 裁剪框默认宽度,即整个画布宽度
774
+ var boundHeight = self.height; // 裁剪框默认高度,即整个画布高度
775
+
776
+ var id = self.id;
777
+ var targetId = self.targetId;
778
+ var pixelRatio = self.pixelRatio;
779
+
780
+ var ref = self.cut;
781
+ var x = ref.x;
782
+ if (x === void 0) x = 0;
783
+ var y = ref.y;
784
+ if (y === void 0) y = 0;
785
+ var width = ref.width;
786
+ if (width === void 0) width = boundWidth;
787
+ var height = ref.height;
788
+ if (height === void 0) height = boundHeight;
789
+
790
+ self.updateCanvas = function (done) {
791
+ if (self.croperTarget) {
792
+ // 画布绘制图片
793
+ self.ctx.drawImage(self.croperTarget, self.imgLeft, self.imgTop, self.scaleWidth, self.scaleHeight);
794
+ }
795
+ tools_7(self.onBeforeDraw) && self.onBeforeDraw(self.ctx, self);
796
+
797
+ self.setBoundStyle(self.boundStyle); // 设置边界样式
798
+
799
+ self.ctx.draw(false, done);
800
+ return self;
801
+ };
802
+
803
+ self.pushOrigin = self.pushOrign = function (src) {
804
+ self.src = src;
805
+
806
+ tools_7(self.onBeforeImageLoad) && self.onBeforeImageLoad(self.ctx, self);
807
+
808
+ return getImageInfo({
809
+ src: src
810
+ })
811
+ .then(function (res) {
812
+ var innerAspectRadio = res.width / res.height;
813
+ var customAspectRadio = width / height;
814
+
815
+ self.croperTarget = res.path;
816
+
817
+ if (innerAspectRadio < customAspectRadio) {
818
+ self.rectX = x;
819
+ self.baseWidth = width;
820
+ self.baseHeight = width / innerAspectRadio;
821
+ self.rectY = y - Math.abs((height - self.baseHeight) / 2);
822
+ } else {
823
+ self.rectY = y;
824
+ self.baseWidth = height * innerAspectRadio;
825
+ self.baseHeight = height;
826
+ self.rectX = x - Math.abs((width - self.baseWidth) / 2);
827
+ }
828
+
829
+ self.imgLeft = self.rectX;
830
+ self.imgTop = self.rectY;
831
+ self.scaleWidth = self.baseWidth;
832
+ self.scaleHeight = self.baseHeight;
833
+
834
+ self.update();
835
+
836
+ return new Promise(function (resolve) {
837
+ self.updateCanvas(resolve);
838
+ });
839
+ })
840
+ .then(function () {
841
+ tools_7(self.onImageLoad) && self.onImageLoad(self.ctx, self);
842
+ });
843
+ };
844
+
845
+ self.removeImage = function () {
846
+ self.src = '';
847
+ self.croperTarget = '';
848
+ return draw(self.ctx);
849
+ };
850
+
851
+ self.getCropperBase64 = function (done) {
852
+ if (done === void 0) done = function () {};
853
+
854
+ CanvasToBase64.convertToBMP(
855
+ {
856
+ canvasId: id,
857
+ x: x,
858
+ y: y,
859
+ width: width,
860
+ height: height
861
+ },
862
+ done
863
+ );
864
+ };
865
+
866
+ self.getCropperImage = function (opt, fn) {
867
+ var customOptions = opt;
868
+
869
+ var canvasOptions = {
870
+ canvasId: id,
871
+ x: x,
872
+ y: y,
873
+ width: width,
874
+ height: height
875
+ };
876
+
877
+ var task = function () {
878
+ return Promise.resolve();
879
+ };
880
+
881
+ if (tools_10(customOptions) && customOptions.original) {
882
+ // original mode
883
+ task = function () {
884
+ self.targetCtx.drawImage(self.croperTarget, self.imgLeft * pixelRatio, self.imgTop * pixelRatio, self.scaleWidth * pixelRatio, self.scaleHeight * pixelRatio);
885
+
886
+ canvasOptions = {
887
+ canvasId: targetId,
888
+ x: x * pixelRatio,
889
+ y: y * pixelRatio,
890
+ width: width * pixelRatio,
891
+ height: height * pixelRatio
892
+ };
893
+
894
+ return draw(self.targetCtx);
895
+ };
896
+ }
897
+
898
+ return task()
899
+ .then(function () {
900
+ if (tools_10(customOptions)) {
901
+ canvasOptions = Object.assign({}, canvasOptions, customOptions);
902
+ }
903
+
904
+ if (tools_7(customOptions)) {
905
+ fn = customOptions;
906
+ }
907
+
908
+ var arg = canvasOptions.componentContext ? [canvasOptions, canvasOptions.componentContext] : [canvasOptions];
909
+
910
+ return canvasToTempFilePath.apply(null, arg);
911
+ })
912
+ .then(function (res) {
913
+ var tempFilePath = res.tempFilePath;
914
+
915
+ return tools_7(fn) ? fn.call(self, tempFilePath, null) : tempFilePath;
916
+ })
917
+ .catch(function (err) {
918
+ if (tools_7(fn)) {
919
+ fn.call(self, null, err);
920
+ } else {
921
+ throw err;
922
+ }
923
+ });
924
+ };
925
+ }
926
+
927
+ /**
928
+ * 获取最新缩放值
929
+ * @param oldScale 上一次触摸结束后的缩放值
930
+ * @param oldDistance 上一次触摸结束后的双指距离
931
+ * @param zoom 缩放系数
932
+ * @param touch0 第一指touch对象
933
+ * @param touch1 第二指touch对象
934
+ * @returns {*}
935
+ */
936
+ var getNewScale = function (oldScale, oldDistance, zoom, touch0, touch1) {
937
+ var xMove, yMove, newDistance;
938
+ // 计算二指最新距离
939
+ xMove = Math.round(touch1.x - touch0.x);
940
+ yMove = Math.round(touch1.y - touch0.y);
941
+ newDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
942
+
943
+ return oldScale + 0.001 * zoom * (newDistance - oldDistance);
944
+ };
945
+
946
+ function update() {
947
+ var self = this;
948
+
949
+ if (!self.src) {
950
+ return;
951
+ }
952
+
953
+ self.__oneTouchStart = function (touch) {
954
+ self.touchX0 = Math.round(touch.x);
955
+ self.touchY0 = Math.round(touch.y);
956
+ };
957
+
958
+ self.__oneTouchMove = function (touch) {
959
+ var xMove, yMove;
960
+ // 计算单指移动的距离
961
+ if (self.touchended) {
962
+ return self.updateCanvas();
963
+ }
964
+ xMove = Math.round(touch.x - self.touchX0);
965
+ yMove = Math.round(touch.y - self.touchY0);
966
+
967
+ var imgLeft = Math.round(self.rectX + xMove);
968
+ var imgTop = Math.round(self.rectY + yMove);
969
+
970
+ self.outsideBound(imgLeft, imgTop);
971
+
972
+ self.updateCanvas();
973
+ };
974
+
975
+ self.__twoTouchStart = function (touch0, touch1) {
976
+ var xMove, yMove, oldDistance;
977
+
978
+ self.touchX1 = Math.round(self.rectX + self.scaleWidth / 2);
979
+ self.touchY1 = Math.round(self.rectY + self.scaleHeight / 2);
980
+
981
+ // 计算两指距离
982
+ xMove = Math.round(touch1.x - touch0.x);
983
+ yMove = Math.round(touch1.y - touch0.y);
984
+ oldDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
985
+
986
+ self.oldDistance = oldDistance;
987
+ };
988
+
989
+ self.__twoTouchMove = function (touch0, touch1) {
990
+ var oldScale = self.oldScale;
991
+ var oldDistance = self.oldDistance;
992
+ var scale = self.scale;
993
+ var zoom = self.zoom;
994
+
995
+ self.newScale = getNewScale(oldScale, oldDistance, zoom, touch0, touch1);
996
+
997
+ // 设定缩放范围
998
+ self.newScale <= 1 && (self.newScale = 1);
999
+ self.newScale >= scale && (self.newScale = scale);
1000
+
1001
+ self.scaleWidth = Math.round(self.newScale * self.baseWidth);
1002
+ self.scaleHeight = Math.round(self.newScale * self.baseHeight);
1003
+ var imgLeft = Math.round(self.touchX1 - self.scaleWidth / 2);
1004
+ var imgTop = Math.round(self.touchY1 - self.scaleHeight / 2);
1005
+
1006
+ self.outsideBound(imgLeft, imgTop);
1007
+
1008
+ self.updateCanvas();
1009
+ };
1010
+
1011
+ self.__xtouchEnd = function () {
1012
+ self.oldScale = self.newScale;
1013
+ self.rectX = self.imgLeft;
1014
+ self.rectY = self.imgTop;
1015
+ };
1016
+ }
1017
+
1018
+ var handle = {
1019
+ // 图片手势初始监测
1020
+ touchStart: function touchStart(e) {
1021
+ var self = this;
1022
+ var ref = e.touches;
1023
+ var touch0 = ref[0];
1024
+ var touch1 = ref[1];
1025
+
1026
+ if (!self.src) {
1027
+ return;
1028
+ }
1029
+
1030
+ setTouchState(self, true, null, null);
1031
+
1032
+ // 计算第一个触摸点的位置,并参照改点进行缩放
1033
+ self.__oneTouchStart(touch0);
1034
+
1035
+ // 两指手势触发
1036
+ if (e.touches.length >= 2) {
1037
+ self.__twoTouchStart(touch0, touch1);
1038
+ }
1039
+ },
1040
+
1041
+ // 图片手势动态缩放
1042
+ touchMove: function touchMove(e) {
1043
+ var self = this;
1044
+ var ref = e.touches;
1045
+ var touch0 = ref[0];
1046
+ var touch1 = ref[1];
1047
+
1048
+ if (!self.src) {
1049
+ return;
1050
+ }
1051
+
1052
+ setTouchState(self, null, true);
1053
+
1054
+ // 单指手势时触发
1055
+ if (e.touches.length === 1) {
1056
+ self.__oneTouchMove(touch0);
1057
+ }
1058
+ // 两指手势触发
1059
+ if (e.touches.length >= 2) {
1060
+ self.__twoTouchMove(touch0, touch1);
1061
+ }
1062
+ },
1063
+
1064
+ touchEnd: function touchEnd(e) {
1065
+ var self = this;
1066
+
1067
+ if (!self.src) {
1068
+ return;
1069
+ }
1070
+
1071
+ setTouchState(self, false, false, true);
1072
+ self.__xtouchEnd();
1073
+ }
1074
+ };
1075
+
1076
+ function cut() {
1077
+ var self = this;
1078
+ var boundWidth = self.width; // 裁剪框默认宽度,即整个画布宽度
1079
+ var boundHeight = self.height;
1080
+ // 裁剪框默认高度,即整个画布高度
1081
+ var ref = self.cut;
1082
+ var x = ref.x;
1083
+ if (x === void 0) x = 0;
1084
+ var y = ref.y;
1085
+ if (y === void 0) y = 0;
1086
+ var width = ref.width;
1087
+ if (width === void 0) width = boundWidth;
1088
+ var height = ref.height;
1089
+ if (height === void 0) height = boundHeight;
1090
+
1091
+ /**
1092
+ * 设置边界
1093
+ * @param imgLeft 图片左上角横坐标值
1094
+ * @param imgTop 图片左上角纵坐标值
1095
+ */
1096
+ self.outsideBound = function (imgLeft, imgTop) {
1097
+ self.imgLeft = imgLeft >= x ? x : self.scaleWidth + imgLeft - x <= width ? x + width - self.scaleWidth : imgLeft;
1098
+
1099
+ self.imgTop = imgTop >= y ? y : self.scaleHeight + imgTop - y <= height ? y + height - self.scaleHeight : imgTop;
1100
+ };
1101
+
1102
+ /**
1103
+ * 设置边界样式
1104
+ * @param color 边界颜色
1105
+ */
1106
+ self.setBoundStyle = function (ref) {
1107
+ if (ref === void 0) ref = {};
1108
+ var color = ref.color;
1109
+ if (color === void 0) color = '#04b00f';
1110
+ var mask = ref.mask;
1111
+ if (mask === void 0) mask = 'rgba(0, 0, 0, 0.3)';
1112
+ var lineWidth = ref.lineWidth;
1113
+ if (lineWidth === void 0) lineWidth = 1;
1114
+
1115
+ var half = lineWidth / 2;
1116
+ var boundOption = [
1117
+ {
1118
+ start: {
1119
+ x: x - half,
1120
+ y: y + 10 - half
1121
+ },
1122
+ step1: {
1123
+ x: x - half,
1124
+ y: y - half
1125
+ },
1126
+ step2: {
1127
+ x: x + 10 - half,
1128
+ y: y - half
1129
+ }
1130
+ },
1131
+ {
1132
+ start: {
1133
+ x: x - half,
1134
+ y: y + height - 10 + half
1135
+ },
1136
+ step1: {
1137
+ x: x - half,
1138
+ y: y + height + half
1139
+ },
1140
+ step2: {
1141
+ x: x + 10 - half,
1142
+ y: y + height + half
1143
+ }
1144
+ },
1145
+ {
1146
+ start: {
1147
+ x: x + width - 10 + half,
1148
+ y: y - half
1149
+ },
1150
+ step1: {
1151
+ x: x + width + half,
1152
+ y: y - half
1153
+ },
1154
+ step2: {
1155
+ x: x + width + half,
1156
+ y: y + 10 - half
1157
+ }
1158
+ },
1159
+ {
1160
+ start: {
1161
+ x: x + width + half,
1162
+ y: y + height - 10 + half
1163
+ },
1164
+ step1: {
1165
+ x: x + width + half,
1166
+ y: y + height + half
1167
+ },
1168
+ step2: {
1169
+ x: x + width - 10 + half,
1170
+ y: y + height + half
1171
+ }
1172
+ }
1173
+ ];
1174
+
1175
+ // 绘制半透明层
1176
+ self.ctx.beginPath();
1177
+ self.ctx.setFillStyle(mask);
1178
+ self.ctx.fillRect(0, 0, x, boundHeight);
1179
+ self.ctx.fillRect(x, 0, width, y);
1180
+ self.ctx.fillRect(x, y + height, width, boundHeight - y - height);
1181
+ self.ctx.fillRect(x + width, 0, boundWidth - x - width, boundHeight);
1182
+ self.ctx.fill();
1183
+
1184
+ boundOption.forEach(function (op) {
1185
+ self.ctx.beginPath();
1186
+ self.ctx.setStrokeStyle(color);
1187
+ self.ctx.setLineWidth(lineWidth);
1188
+ self.ctx.moveTo(op.start.x, op.start.y);
1189
+ self.ctx.lineTo(op.step1.x, op.step1.y);
1190
+ self.ctx.lineTo(op.step2.x, op.step2.y);
1191
+ self.ctx.stroke();
1192
+ });
1193
+ };
1194
+ }
1195
+
1196
+ var version = '1.3.9';
1197
+
1198
+ var WeCropper = function WeCropper(params) {
1199
+ var self = this;
1200
+ var _default = {};
1201
+
1202
+ validator(self, DEFAULT);
1203
+
1204
+ Object.keys(DEFAULT).forEach(function (key) {
1205
+ _default[key] = DEFAULT[key].default;
1206
+ });
1207
+ Object.assign(self, _default, params);
1208
+
1209
+ self.prepare();
1210
+ self.attachPage();
1211
+ self.createCtx();
1212
+ self.observer();
1213
+ self.cutt();
1214
+ self.methods();
1215
+ self.init();
1216
+ self.update();
1217
+
1218
+ return self;
1219
+ };
1220
+
1221
+ WeCropper.prototype.init = function init() {
1222
+ var self = this;
1223
+ var src = self.src;
1224
+
1225
+ self.version = version;
1226
+
1227
+ typeof self.onReady === 'function' && self.onReady(self.ctx, self);
1228
+
1229
+ if (src) {
1230
+ self.pushOrign(src);
1231
+ } else {
1232
+ self.updateCanvas();
1233
+ }
1234
+ setTouchState(self, false, false, false);
1235
+
1236
+ self.oldScale = 1;
1237
+ self.newScale = 1;
1238
+
1239
+ return self;
1240
+ };
1241
+
1242
+ Object.assign(WeCropper.prototype, handle);
1243
+
1244
+ WeCropper.prototype.prepare = prepare;
1245
+ WeCropper.prototype.observer = observer;
1246
+ WeCropper.prototype.methods = methods;
1247
+ WeCropper.prototype.cutt = cut;
1248
+ WeCropper.prototype.update = update;
1249
+
1250
+ return WeCropper;
1251
+ });
1252
+
1253
+ exports.default = WeCropper;