uview-pro 0.2.4 → 0.3.1

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