uview-pro 0.2.1 → 0.2.2

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 (243) hide show
  1. package/changelog.md +501 -481
  2. package/components/common/props.ts +22 -22
  3. package/components/u-action-sheet/types.ts +35 -35
  4. package/components/u-action-sheet/u-action-sheet.vue +160 -160
  5. package/components/u-alert-tips/types.ts +39 -39
  6. package/components/u-alert-tips/u-alert-tips.vue +212 -212
  7. package/components/u-avatar/types.ts +34 -34
  8. package/components/u-avatar/u-avatar.vue +193 -193
  9. package/components/u-avatar-cropper/types.ts +23 -23
  10. package/components/u-avatar-cropper/u-avatar-cropper.vue +286 -286
  11. package/components/u-avatar-cropper/weCropper.d.ts +62 -62
  12. package/components/u-avatar-cropper/weCropper.js +1253 -1253
  13. package/components/u-avatar-cropper/weCropper.ts +1255 -1255
  14. package/components/u-back-top/types.ts +39 -39
  15. package/components/u-back-top/u-back-top.vue +125 -125
  16. package/components/u-badge/types.ts +36 -36
  17. package/components/u-badge/u-badge.vue +165 -165
  18. package/components/u-button/types.ts +66 -66
  19. package/components/u-button/u-button.vue +556 -556
  20. package/components/u-calendar/types.ts +73 -73
  21. package/components/u-calendar/u-calendar.vue +638 -638
  22. package/components/u-car-keyboard/types.ts +12 -12
  23. package/components/u-car-keyboard/u-car-keyboard.vue +234 -234
  24. package/components/u-card/types.ts +59 -59
  25. package/components/u-card/u-card.vue +194 -194
  26. package/components/u-cell-group/types.ts +17 -17
  27. package/components/u-cell-group/u-cell-group.vue +50 -50
  28. package/components/u-cell-item/types.ts +54 -54
  29. package/components/u-cell-item/u-cell-item.vue +202 -202
  30. package/components/u-checkbox/types.ts +31 -31
  31. package/components/u-checkbox/u-checkbox.vue +267 -267
  32. package/components/u-checkbox-group/types.ts +32 -32
  33. package/components/u-checkbox-group/u-checkbox-group.vue +79 -79
  34. package/components/u-circle-progress/types.ts +52 -52
  35. package/components/u-circle-progress/u-circle-progress.vue +187 -187
  36. package/components/u-city-select/types.ts +20 -20
  37. package/components/u-city-select/u-city-select.vue +236 -236
  38. package/components/u-col/types.ts +30 -30
  39. package/components/u-col/u-col.vue +123 -123
  40. package/components/u-collapse/types.ts +33 -33
  41. package/components/u-collapse/u-collapse.vue +69 -69
  42. package/components/u-collapse-item/types.ts +27 -27
  43. package/components/u-collapse-item/u-collapse-item.vue +213 -201
  44. package/components/u-column-notice/types.ts +48 -48
  45. package/components/u-column-notice/u-column-notice.vue +176 -176
  46. package/components/u-count-down/types.ts +42 -42
  47. package/components/u-count-down/u-count-down.vue +258 -258
  48. package/components/u-count-to/types.ts +32 -32
  49. package/components/u-count-to/u-count-to.vue +241 -241
  50. package/components/u-divider/types.ts +31 -31
  51. package/components/u-divider/u-divider.vue +121 -121
  52. package/components/u-dropdown/types.ts +32 -32
  53. package/components/u-dropdown/u-dropdown.vue +289 -289
  54. package/components/u-dropdown-item/types.ts +27 -27
  55. package/components/u-dropdown-item/u-dropdown-item.vue +123 -123
  56. package/components/u-empty/types.ts +36 -36
  57. package/components/u-empty/u-empty.vue +88 -88
  58. package/components/u-field/types.ts +69 -69
  59. package/components/u-field/u-field.vue +354 -354
  60. package/components/u-form/u-form.vue +132 -132
  61. package/components/u-form-item/u-form-item.vue +417 -417
  62. package/components/u-full-screen/types.ts +14 -14
  63. package/components/u-full-screen/u-full-screen.vue +82 -82
  64. package/components/u-gap/types.ts +18 -18
  65. package/components/u-gap/u-gap.vue +40 -40
  66. package/components/u-grid/types.ts +19 -19
  67. package/components/u-grid/u-grid.vue +93 -93
  68. package/components/u-grid-item/types.ts +16 -16
  69. package/components/u-grid-item/u-grid-item.vue +130 -130
  70. package/components/u-icon/types.ts +62 -62
  71. package/components/u-icon/u-icon.vue +281 -281
  72. package/components/u-image/types.ts +51 -51
  73. package/components/u-image/u-image.vue +222 -222
  74. package/components/u-index-anchor/types.ts +16 -16
  75. package/components/u-index-anchor/u-index-anchor.vue +86 -86
  76. package/components/u-index-list/types.ts +43 -43
  77. package/components/u-index-list/u-index-list.vue +355 -355
  78. package/components/u-input/types.ts +140 -140
  79. package/components/u-input/u-input.vue +264 -264
  80. package/components/u-keyboard/types.ts +40 -40
  81. package/components/u-keyboard/u-keyboard.vue +158 -158
  82. package/components/u-lazy-load/types.ts +37 -37
  83. package/components/u-lazy-load/u-lazy-load.vue +233 -233
  84. package/components/u-line/types.ts +44 -44
  85. package/components/u-line/u-line.vue +59 -59
  86. package/components/u-line-progress/types.ts +58 -58
  87. package/components/u-line-progress/u-line-progress.vue +109 -109
  88. package/components/u-link/types.ts +43 -43
  89. package/components/u-link/u-link.vue +75 -75
  90. package/components/u-loading/types.ts +35 -35
  91. package/components/u-loading/u-loading.vue +90 -90
  92. package/components/u-loading-popup/types.ts +26 -26
  93. package/components/u-loading-popup/u-loading-popup.vue +239 -239
  94. package/components/u-loadmore/types.ts +79 -79
  95. package/components/u-loadmore/u-loadmore.vue +140 -140
  96. package/components/u-mask/types.ts +43 -43
  97. package/components/u-mask/u-mask.vue +106 -106
  98. package/components/u-message-input/types.ts +74 -74
  99. package/components/u-message-input/u-message-input.vue +255 -255
  100. package/components/u-modal/types.ts +118 -118
  101. package/components/u-modal/u-modal.vue +204 -204
  102. package/components/u-navbar/types.ts +103 -103
  103. package/components/u-navbar/u-navbar.vue +226 -226
  104. package/components/u-no-network/image.ts +2 -2
  105. package/components/u-no-network/types.ts +28 -28
  106. package/components/u-no-network/u-no-network.vue +290 -290
  107. package/components/u-notice-bar/types.ts +111 -111
  108. package/components/u-notice-bar/u-notice-bar.vue +174 -174
  109. package/components/u-number-box/types.ts +42 -42
  110. package/components/u-number-box/u-number-box.vue +312 -312
  111. package/components/u-number-keyboard/types.ts +26 -26
  112. package/components/u-number-keyboard/u-number-keyboard.vue +166 -166
  113. package/components/u-picker/types.ts +123 -123
  114. package/components/u-picker/u-picker.vue +637 -637
  115. package/components/u-popup/types.ts +59 -59
  116. package/components/u-popup/u-popup.vue +359 -359
  117. package/components/u-radio/types.ts +25 -25
  118. package/components/u-radio/u-radio.vue +258 -258
  119. package/components/u-radio-group/types.ts +29 -29
  120. package/components/u-radio-group/u-radio-group.vue +98 -98
  121. package/components/u-rate/types.ts +40 -40
  122. package/components/u-rate/u-rate.vue +234 -234
  123. package/components/u-read-more/types.ts +35 -35
  124. package/components/u-read-more/u-read-more.vue +150 -150
  125. package/components/u-root-portal/u-root-portal.vue +54 -0
  126. package/components/u-row/types.ts +20 -20
  127. package/components/u-row/u-row.vue +87 -87
  128. package/components/u-row-notice/types.ts +39 -39
  129. package/components/u-row-notice/u-row-notice.vue +213 -213
  130. package/components/u-safe-bottom/u-safe-bottom.vue +46 -46
  131. package/components/u-search/types.ts +53 -53
  132. package/components/u-search/u-search.vue +256 -256
  133. package/components/u-section/types.ts +32 -32
  134. package/components/u-section/u-section.vue +125 -125
  135. package/components/u-select/types.ts +43 -43
  136. package/components/u-select/u-select.vue +361 -361
  137. package/components/u-skeleton/types.ts +20 -20
  138. package/components/u-skeleton/u-skeleton.vue +205 -205
  139. package/components/u-slider/types.ts +32 -32
  140. package/components/u-slider/u-slider.vue +238 -238
  141. package/components/u-status-bar/u-status-bar.vue +65 -65
  142. package/components/u-steps/types.ts +28 -28
  143. package/components/u-steps/u-steps.vue +160 -160
  144. package/components/u-sticky/types.ts +22 -22
  145. package/components/u-sticky/u-sticky.vue +159 -159
  146. package/components/u-subsection/types.ts +36 -36
  147. package/components/u-subsection/u-subsection.vue +328 -328
  148. package/components/u-swipe-action/types.ts +50 -50
  149. package/components/u-swipe-action/u-swipe-action.vue +253 -253
  150. package/components/u-swiper/types.ts +47 -47
  151. package/components/u-swiper/u-swiper.vue +266 -266
  152. package/components/u-switch/types.ts +28 -28
  153. package/components/u-switch/u-switch.vue +136 -136
  154. package/components/u-tabbar/types.ts +36 -36
  155. package/components/u-tabbar/u-tabbar.vue +280 -280
  156. package/components/u-table/types.ts +25 -25
  157. package/components/u-table/u-table.vue +55 -55
  158. package/components/u-tabs/types.ts +51 -51
  159. package/components/u-tabs/u-tabs.vue +284 -284
  160. package/components/u-tabs-swiper/types.ts +53 -53
  161. package/components/u-tabs-swiper/u-tabs-swiper.vue +379 -379
  162. package/components/u-tag/types.ts +37 -37
  163. package/components/u-tag/u-tag.vue +244 -244
  164. package/components/u-td/types.ts +12 -12
  165. package/components/u-td/u-td.vue +87 -87
  166. package/components/u-text/types.ts +69 -69
  167. package/components/u-text/u-text.vue +326 -326
  168. package/components/u-th/types.ts +12 -12
  169. package/components/u-th/u-th.vue +81 -81
  170. package/components/u-time-line/u-time-line.vue +39 -39
  171. package/components/u-time-line-item/types.ts +14 -14
  172. package/components/u-time-line-item/u-time-line-item.vue +78 -78
  173. package/components/u-toast/types.ts +36 -36
  174. package/components/u-toast/u-toast.vue +233 -233
  175. package/components/u-top-tips/types.ts +14 -14
  176. package/components/u-top-tips/u-top-tips.vue +113 -113
  177. package/components/u-tr/types.ts +8 -8
  178. package/components/u-tr/u-tr.vue +24 -24
  179. package/components/u-upload/types.ts +74 -74
  180. package/components/u-upload/u-upload.vue +545 -545
  181. package/components/u-verification-code/types.ts +22 -22
  182. package/components/u-verification-code/u-verification-code.vue +164 -164
  183. package/components/u-waterfall/types.ts +16 -16
  184. package/components/u-waterfall/u-waterfall.vue +175 -175
  185. package/iconfont.css +912 -912
  186. package/index.scss +25 -25
  187. package/index.ts +29 -29
  188. package/libs/config/config.ts +26 -26
  189. package/libs/config/zIndex.ts +37 -37
  190. package/libs/css/color.scss +155 -155
  191. package/libs/css/common.scss +178 -178
  192. package/libs/css/style.components.scss +16 -16
  193. package/libs/css/style.h5.scss +8 -8
  194. package/libs/css/style.mp.scss +72 -72
  195. package/libs/css/style.nvue.scss +15 -15
  196. package/libs/css/style.vue.scss +188 -188
  197. package/libs/function/$parent.ts +21 -21
  198. package/libs/function/addUnit.ts +13 -13
  199. package/libs/function/color.ts +37 -37
  200. package/libs/function/colorGradient.ts +125 -125
  201. package/libs/function/debounce.ts +28 -28
  202. package/libs/function/deepClone.ts +39 -39
  203. package/libs/function/deepMerge.ts +34 -34
  204. package/libs/function/getParent.ts +59 -59
  205. package/libs/function/getRect.ts +26 -26
  206. package/libs/function/guid.ts +42 -42
  207. package/libs/function/md5.ts +391 -391
  208. package/libs/function/parent.ts +21 -21
  209. package/libs/function/queryParams.ts +60 -60
  210. package/libs/function/random.ts +16 -16
  211. package/libs/function/randomArray.ts +11 -11
  212. package/libs/function/route.ts +118 -118
  213. package/libs/function/styleUtils.ts +83 -83
  214. package/libs/function/sys.ts +15 -15
  215. package/libs/function/test.ts +285 -285
  216. package/libs/function/throttle.ts +31 -31
  217. package/libs/function/timeFormat.ts +54 -54
  218. package/libs/function/timeFrom.ts +48 -48
  219. package/libs/function/toast.ts +14 -14
  220. package/libs/function/trim.ts +21 -21
  221. package/libs/function/type2icon.ts +36 -36
  222. package/libs/hooks/index.ts +3 -3
  223. package/libs/hooks/useEmitter.ts +77 -77
  224. package/libs/hooks/useParent.ts +31 -31
  225. package/libs/hooks/useRect.ts +33 -33
  226. package/libs/index.ts +291 -291
  227. package/libs/request/auto-http.ts +76 -76
  228. package/libs/request/index.ts +223 -223
  229. package/libs/store/index.ts +88 -88
  230. package/libs/util/async-validator.d.ts +62 -62
  231. package/libs/util/async-validator.js +1 -1
  232. package/libs/util/calendar.d.ts +57 -57
  233. package/libs/util/emitter.ts +102 -102
  234. package/libs/util/mitt.ts +115 -115
  235. package/libs/util/parent.ts +20 -20
  236. package/package.json +1 -1
  237. package/readme.md +239 -237
  238. package/theme.scss +38 -38
  239. package/types/components.d.ts +97 -96
  240. package/types/global.d.ts +295 -295
  241. package/types/ignore-errors.d.ts +30 -30
  242. package/types/index.d.ts +19 -19
  243. 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;