@lucky-scratch/mini 1.1.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.
- package/LICENSE +201 -0
- package/README.md +103 -0
- package/dist/lucky-scratch-component/index.js +1070 -0
- package/dist/lucky-scratch-component/index.js.map +1 -0
- package/dist/lucky-scratch-component/index.json +5 -0
- package/dist/lucky-scratch-component/index.wxml +19 -0
- package/dist/lucky-scratch-component/index.wxss +11 -0
- package/package.json +77 -0
|
@@ -0,0 +1,1070 @@
|
|
|
1
|
+
module.exports =
|
|
2
|
+
/******/ (function(modules) { // webpackBootstrap
|
|
3
|
+
/******/ // The module cache
|
|
4
|
+
/******/ var installedModules = {};
|
|
5
|
+
/******/
|
|
6
|
+
/******/ // The require function
|
|
7
|
+
/******/ function __webpack_require__(moduleId) {
|
|
8
|
+
/******/
|
|
9
|
+
/******/ // Check if module is in cache
|
|
10
|
+
/******/ if(installedModules[moduleId]) {
|
|
11
|
+
/******/ return installedModules[moduleId].exports;
|
|
12
|
+
/******/ }
|
|
13
|
+
/******/ // Create a new module (and put it into the cache)
|
|
14
|
+
/******/ var module = installedModules[moduleId] = {
|
|
15
|
+
/******/ i: moduleId,
|
|
16
|
+
/******/ l: false,
|
|
17
|
+
/******/ exports: {}
|
|
18
|
+
/******/ };
|
|
19
|
+
/******/
|
|
20
|
+
/******/ // Execute the module function
|
|
21
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
22
|
+
/******/
|
|
23
|
+
/******/ // Flag the module as loaded
|
|
24
|
+
/******/ module.l = true;
|
|
25
|
+
/******/
|
|
26
|
+
/******/ // Return the exports of the module
|
|
27
|
+
/******/ return module.exports;
|
|
28
|
+
/******/ }
|
|
29
|
+
/******/
|
|
30
|
+
/******/
|
|
31
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
32
|
+
/******/ __webpack_require__.m = modules;
|
|
33
|
+
/******/
|
|
34
|
+
/******/ // expose the module cache
|
|
35
|
+
/******/ __webpack_require__.c = installedModules;
|
|
36
|
+
/******/
|
|
37
|
+
/******/ // define getter function for harmony exports
|
|
38
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
39
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
40
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ };
|
|
43
|
+
/******/
|
|
44
|
+
/******/ // define __esModule on exports
|
|
45
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
46
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
47
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
|
+
/******/ };
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // create a fake namespace object
|
|
53
|
+
/******/ // mode & 1: value is a module id, require it
|
|
54
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
55
|
+
/******/ // mode & 4: return value when already ns object
|
|
56
|
+
/******/ // mode & 8|1: behave like require
|
|
57
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
58
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
59
|
+
/******/ if(mode & 8) return value;
|
|
60
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
61
|
+
/******/ var ns = Object.create(null);
|
|
62
|
+
/******/ __webpack_require__.r(ns);
|
|
63
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
64
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
65
|
+
/******/ return ns;
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/
|
|
68
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
69
|
+
/******/ __webpack_require__.n = function(module) {
|
|
70
|
+
/******/ var getter = module && module.__esModule ?
|
|
71
|
+
/******/ function getDefault() { return module['default']; } :
|
|
72
|
+
/******/ function getModuleExports() { return module; };
|
|
73
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
74
|
+
/******/ return getter;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
78
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
79
|
+
/******/
|
|
80
|
+
/******/ // __webpack_public_path__
|
|
81
|
+
/******/ __webpack_require__.p = "";
|
|
82
|
+
/******/
|
|
83
|
+
/******/
|
|
84
|
+
/******/ // Load entry module and return exports
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
|
86
|
+
/******/ })
|
|
87
|
+
/************************************************************************/
|
|
88
|
+
/******/ ([
|
|
89
|
+
/* 0 */
|
|
90
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
91
|
+
|
|
92
|
+
"use strict";
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
var _luckyScratch = __webpack_require__(1);
|
|
96
|
+
var _utils = __webpack_require__(2);
|
|
97
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
98
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
99
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
100
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
101
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
102
|
+
Component({
|
|
103
|
+
properties: {
|
|
104
|
+
width: {
|
|
105
|
+
type: String,
|
|
106
|
+
value: '600rpx'
|
|
107
|
+
},
|
|
108
|
+
height: {
|
|
109
|
+
type: String,
|
|
110
|
+
value: '400rpx'
|
|
111
|
+
},
|
|
112
|
+
mask: {
|
|
113
|
+
type: Object,
|
|
114
|
+
value: {
|
|
115
|
+
type: 'color',
|
|
116
|
+
color: '#ccc'
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
scratch: {
|
|
120
|
+
type: Object,
|
|
121
|
+
value: {
|
|
122
|
+
radius: 20,
|
|
123
|
+
percent: 0.5
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
data: {
|
|
128
|
+
lucky: null,
|
|
129
|
+
isShow: false
|
|
130
|
+
},
|
|
131
|
+
observers: {
|
|
132
|
+
'mask.**': function mask(newData, oldData) {
|
|
133
|
+
if (this.lucky) {
|
|
134
|
+
this.lucky.mask = newData;
|
|
135
|
+
this.lucky.init();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
'scratch.**': function scratch(newData, oldData) {
|
|
139
|
+
if (this.lucky && this.dpr) {
|
|
140
|
+
// 因为使用了 ctx.scale(dpr, dpr),而核心库内部会将半径乘以 dpr
|
|
141
|
+
// 导致双重放大,所以这里先除以 dpr 抵消
|
|
142
|
+
this.lucky.scratch = _extends({}, newData, {
|
|
143
|
+
radius: newData.radius / this.dpr
|
|
144
|
+
});
|
|
145
|
+
} else if (this.lucky) {
|
|
146
|
+
// 如果 dpr 还没初始化,直接赋值(这种情况很少见)
|
|
147
|
+
this.lucky.scratch = newData;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
ready: function ready() {
|
|
152
|
+
var _this = this;
|
|
153
|
+
console.log('LuckyScratch 123:', _luckyScratch.LuckyScratch);
|
|
154
|
+
wx.createSelectorQuery()["in"](this).select('#lucky-scratch').fields({
|
|
155
|
+
node: true,
|
|
156
|
+
size: true
|
|
157
|
+
}).exec(function (res) {
|
|
158
|
+
if (!res[0] || !res[0].node) {
|
|
159
|
+
return console.error('lucky-scratch 获取不到 canvas 标签');
|
|
160
|
+
}
|
|
161
|
+
var canvas = _this.canvas = res[0].node;
|
|
162
|
+
var dpr = _this.dpr = wx.getSystemInfoSync().pixelRatio;
|
|
163
|
+
var ctx = _this.ctx = canvas.getContext('2d');
|
|
164
|
+
var data = _this.data;
|
|
165
|
+
canvas.width = res[0].width * dpr;
|
|
166
|
+
canvas.height = res[0].height * dpr;
|
|
167
|
+
// 参考 Taro 和 UniApp 实现:小程序端需要 ctx.scale
|
|
168
|
+
ctx.scale(dpr, dpr);
|
|
169
|
+
_this.lucky = new _luckyScratch.LuckyScratch({
|
|
170
|
+
flag: 'MP-WX',
|
|
171
|
+
ctx: ctx,
|
|
172
|
+
dpr: dpr,
|
|
173
|
+
offscreenCanvas: wx.createOffscreenCanvas({
|
|
174
|
+
type: '2d',
|
|
175
|
+
width: 300,
|
|
176
|
+
height: 150
|
|
177
|
+
}),
|
|
178
|
+
setTimeout: setTimeout,
|
|
179
|
+
clearTimeout: clearTimeout,
|
|
180
|
+
setInterval: setInterval,
|
|
181
|
+
clearInterval: clearInterval,
|
|
182
|
+
unitFunc: function unitFunc(num, unit) {
|
|
183
|
+
return (0, _utils.changeUnits)(num + unit);
|
|
184
|
+
},
|
|
185
|
+
afterStart: function afterStart() {
|
|
186
|
+
_this.lucky.draw();
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
width: res[0].width,
|
|
190
|
+
height: res[0].height,
|
|
191
|
+
mask: data.mask,
|
|
192
|
+
scratch: _extends({}, data.scratch, {
|
|
193
|
+
// 因为使用了 ctx.scale(dpr, dpr),而核心库内部会将半径乘以 dpr
|
|
194
|
+
// 导致双重放大,所以这里先除以 dpr 抵消
|
|
195
|
+
radius: data.scratch.radius / dpr
|
|
196
|
+
}),
|
|
197
|
+
onceBeforeStart: function () {
|
|
198
|
+
var _onceBeforeStart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
199
|
+
var result;
|
|
200
|
+
return _regenerator().w(function (_context) {
|
|
201
|
+
while (1) switch (_context.n) {
|
|
202
|
+
case 0:
|
|
203
|
+
console.log('onceBeforeStart :');
|
|
204
|
+
// 小程序环境下,如果没有监听器,Promise 会一直等待
|
|
205
|
+
// 参考 React/Taro 的实现,设置超时自动通过
|
|
206
|
+
_context.n = 1;
|
|
207
|
+
return Promise.race([new Promise(function (resolve) {
|
|
208
|
+
_this.triggerEvent('once-before-start', {
|
|
209
|
+
resolve: resolve
|
|
210
|
+
});
|
|
211
|
+
}), new Promise(function (resolve) {
|
|
212
|
+
// 如果 50ms 内没有响应,说明没有监听器,自动通过
|
|
213
|
+
setTimeout(function () {
|
|
214
|
+
return resolve(true);
|
|
215
|
+
}, 50);
|
|
216
|
+
})]);
|
|
217
|
+
case 1:
|
|
218
|
+
result = _context.v;
|
|
219
|
+
console.log('onceBeforeStart result:', result);
|
|
220
|
+
return _context.a(2, result !== false);
|
|
221
|
+
}
|
|
222
|
+
}, _callee);
|
|
223
|
+
}));
|
|
224
|
+
function onceBeforeStart() {
|
|
225
|
+
return _onceBeforeStart.apply(this, arguments);
|
|
226
|
+
}
|
|
227
|
+
return onceBeforeStart;
|
|
228
|
+
}(),
|
|
229
|
+
beforeStart: function () {
|
|
230
|
+
var _beforeStart = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
231
|
+
var result;
|
|
232
|
+
return _regenerator().w(function (_context2) {
|
|
233
|
+
while (1) switch (_context2.n) {
|
|
234
|
+
case 0:
|
|
235
|
+
console.log('beforeStart compose:');
|
|
236
|
+
// 小程序环境下,如果没有监听器,Promise 会一直等待
|
|
237
|
+
// 参考 React/Taro 的实现,设置超时自动通过
|
|
238
|
+
_context2.n = 1;
|
|
239
|
+
return Promise.race([new Promise(function (resolve) {
|
|
240
|
+
_this.triggerEvent('before-start', {
|
|
241
|
+
resolve: resolve
|
|
242
|
+
});
|
|
243
|
+
}), new Promise(function (resolve) {
|
|
244
|
+
// 如果 50ms 内没有响应,说明没有监听器,自动通过
|
|
245
|
+
setTimeout(function () {
|
|
246
|
+
return resolve(true);
|
|
247
|
+
}, 50);
|
|
248
|
+
})]);
|
|
249
|
+
case 1:
|
|
250
|
+
result = _context2.v;
|
|
251
|
+
console.log('beforeStart result:', result);
|
|
252
|
+
return _context2.a(2, result !== false);
|
|
253
|
+
}
|
|
254
|
+
}, _callee2);
|
|
255
|
+
}));
|
|
256
|
+
function beforeStart() {
|
|
257
|
+
return _beforeStart.apply(this, arguments);
|
|
258
|
+
}
|
|
259
|
+
return beforeStart;
|
|
260
|
+
}(),
|
|
261
|
+
start: function start() {
|
|
262
|
+
console.log('Start compose:');
|
|
263
|
+
_this.triggerEvent('start');
|
|
264
|
+
},
|
|
265
|
+
end: function end() {
|
|
266
|
+
_this.triggerEvent('end');
|
|
267
|
+
},
|
|
268
|
+
success: function success(progress) {
|
|
269
|
+
_this.triggerEvent('success', {
|
|
270
|
+
progress: progress
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
afterInit: function afterInit() {
|
|
274
|
+
_this.triggerEvent('ready');
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
// 为了保证 onload 回调准确
|
|
278
|
+
_this.setData({
|
|
279
|
+
isShow: true
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
methods: {
|
|
284
|
+
imgBindload: function imgBindload(e) {
|
|
285
|
+
var _e$currentTarget$data = e.currentTarget.dataset,
|
|
286
|
+
name = _e$currentTarget$data.name,
|
|
287
|
+
index = _e$currentTarget$data.index;
|
|
288
|
+
var img = this.data[name];
|
|
289
|
+
if (img && img.src) {
|
|
290
|
+
(0, _utils.resolveImage)(e, img, this.canvas);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
init: function init() {
|
|
294
|
+
var _this$lucky;
|
|
295
|
+
this.lucky && (_this$lucky = this.lucky).init.apply(_this$lucky, arguments);
|
|
296
|
+
},
|
|
297
|
+
setDisabled: function setDisabled(disabled) {
|
|
298
|
+
this.lucky && this.lucky.setDisabled(disabled);
|
|
299
|
+
},
|
|
300
|
+
handleTouchStart: function handleTouchStart(e) {
|
|
301
|
+
var _this2 = this;
|
|
302
|
+
if (!this.lucky) return;
|
|
303
|
+
var touch = e.touches[0];
|
|
304
|
+
// 实时获取 canvas 位置,计算相对于 canvas 的坐标
|
|
305
|
+
var query = wx.createSelectorQuery()["in"](this);
|
|
306
|
+
query.select('#lucky-scratch').boundingClientRect(function (rect) {
|
|
307
|
+
if (!rect) return;
|
|
308
|
+
// 计算相对于 canvas 的坐标(逻辑像素)
|
|
309
|
+
var x = touch.clientX - rect.left;
|
|
310
|
+
var y = touch.clientY - rect.top;
|
|
311
|
+
// 因为使用了 ctx.scale(dpr, dpr),而核心库内部会再乘以 dpr
|
|
312
|
+
// 导致双重放大,所以这里先除以 dpr 抵消
|
|
313
|
+
_this2.lucky.handleTouchStart(x / _this2.dpr, y / _this2.dpr);
|
|
314
|
+
});
|
|
315
|
+
query.exec();
|
|
316
|
+
},
|
|
317
|
+
handleTouchMove: function handleTouchMove(e) {
|
|
318
|
+
var _this3 = this;
|
|
319
|
+
if (!this.lucky) return;
|
|
320
|
+
var touch = e.touches[0];
|
|
321
|
+
// 实时获取 canvas 位置,计算相对于 canvas 的坐标
|
|
322
|
+
var query = wx.createSelectorQuery()["in"](this);
|
|
323
|
+
query.select('#lucky-scratch').boundingClientRect(function (rect) {
|
|
324
|
+
if (!rect) return;
|
|
325
|
+
// 计算相对于 canvas 的坐标(逻辑像素)
|
|
326
|
+
var x = touch.clientX - rect.left;
|
|
327
|
+
var y = touch.clientY - rect.top;
|
|
328
|
+
// 因为使用了 ctx.scale(dpr, dpr),而核心库内部会再乘以 dpr
|
|
329
|
+
// 导致双重放大,所以这里先除以 dpr 抵消
|
|
330
|
+
_this3.lucky.handleTouchMove(x / _this3.dpr, y / _this3.dpr);
|
|
331
|
+
});
|
|
332
|
+
query.exec();
|
|
333
|
+
},
|
|
334
|
+
handleTouchEnd: function handleTouchEnd() {
|
|
335
|
+
if (!this.lucky) return;
|
|
336
|
+
// 调用核心库暴露的公共方法
|
|
337
|
+
this.lucky.handleTouchEnd();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
/***/ }),
|
|
343
|
+
/* 1 */
|
|
344
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
345
|
+
|
|
346
|
+
"use strict";
|
|
347
|
+
__webpack_require__.r(__webpack_exports__);
|
|
348
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LuckyScratch", function() { return y; });
|
|
349
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cutRound", function() { return b; });
|
|
350
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "opacity", function() { return w; });
|
|
351
|
+
/*! *****************************************************************************
|
|
352
|
+
Copyright (c) Microsoft Corporation.
|
|
353
|
+
|
|
354
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
355
|
+
purpose with or without fee is hereby granted.
|
|
356
|
+
|
|
357
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
358
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
359
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
360
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
361
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
362
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
363
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
364
|
+
***************************************************************************** */
|
|
365
|
+
var t = function (e, n) {
|
|
366
|
+
return t = Object.setPrototypeOf || {
|
|
367
|
+
__proto__: []
|
|
368
|
+
} instanceof Array && function (t, e) {
|
|
369
|
+
t.__proto__ = e;
|
|
370
|
+
} || function (t, e) {
|
|
371
|
+
for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && (t[n] = e[n]);
|
|
372
|
+
}, t(e, n);
|
|
373
|
+
};
|
|
374
|
+
var e = function () {
|
|
375
|
+
return e = Object.assign || function (t) {
|
|
376
|
+
for (var e, n = 1, i = arguments.length; n < i; n++) for (var r in e = arguments[n]) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
|
|
377
|
+
return t;
|
|
378
|
+
}, e.apply(this, arguments);
|
|
379
|
+
};
|
|
380
|
+
function n(t, e, n, i) {
|
|
381
|
+
return new (n || (n = Promise))(function (r, o) {
|
|
382
|
+
function s(t) {
|
|
383
|
+
try {
|
|
384
|
+
c(i.next(t));
|
|
385
|
+
} catch (t) {
|
|
386
|
+
o(t);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function a(t) {
|
|
390
|
+
try {
|
|
391
|
+
c(i.throw(t));
|
|
392
|
+
} catch (t) {
|
|
393
|
+
o(t);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function c(t) {
|
|
397
|
+
var e;
|
|
398
|
+
t.done ? r(t.value) : (e = t.value, e instanceof n ? e : new n(function (t) {
|
|
399
|
+
t(e);
|
|
400
|
+
})).then(s, a);
|
|
401
|
+
}
|
|
402
|
+
c((i = i.apply(t, e || [])).next());
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function i(t, e) {
|
|
406
|
+
var n,
|
|
407
|
+
i,
|
|
408
|
+
r,
|
|
409
|
+
o,
|
|
410
|
+
s = {
|
|
411
|
+
label: 0,
|
|
412
|
+
sent: function () {
|
|
413
|
+
if (1 & r[0]) throw r[1];
|
|
414
|
+
return r[1];
|
|
415
|
+
},
|
|
416
|
+
trys: [],
|
|
417
|
+
ops: []
|
|
418
|
+
};
|
|
419
|
+
return o = {
|
|
420
|
+
next: a(0),
|
|
421
|
+
throw: a(1),
|
|
422
|
+
return: a(2)
|
|
423
|
+
}, "function" == typeof Symbol && (o[Symbol.iterator] = function () {
|
|
424
|
+
return this;
|
|
425
|
+
}), o;
|
|
426
|
+
function a(o) {
|
|
427
|
+
return function (a) {
|
|
428
|
+
return function (o) {
|
|
429
|
+
if (n) throw new TypeError("Generator is already executing.");
|
|
430
|
+
for (; s;) try {
|
|
431
|
+
if (n = 1, i && (r = 2 & o[0] ? i.return : o[0] ? i.throw || ((r = i.return) && r.call(i), 0) : i.next) && !(r = r.call(i, o[1])).done) return r;
|
|
432
|
+
switch (i = 0, r && (o = [2 & o[0], r.value]), o[0]) {
|
|
433
|
+
case 0:
|
|
434
|
+
case 1:
|
|
435
|
+
r = o;
|
|
436
|
+
break;
|
|
437
|
+
case 4:
|
|
438
|
+
return s.label++, {
|
|
439
|
+
value: o[1],
|
|
440
|
+
done: !1
|
|
441
|
+
};
|
|
442
|
+
case 5:
|
|
443
|
+
s.label++, i = o[1], o = [0];
|
|
444
|
+
continue;
|
|
445
|
+
case 7:
|
|
446
|
+
o = s.ops.pop(), s.trys.pop();
|
|
447
|
+
continue;
|
|
448
|
+
default:
|
|
449
|
+
if (!(r = s.trys, (r = r.length > 0 && r[r.length - 1]) || 6 !== o[0] && 2 !== o[0])) {
|
|
450
|
+
s = 0;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (3 === o[0] && (!r || o[1] > r[0] && o[1] < r[3])) {
|
|
454
|
+
s.label = o[1];
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
if (6 === o[0] && s.label < r[1]) {
|
|
458
|
+
s.label = r[1], r = o;
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
if (r && s.label < r[2]) {
|
|
462
|
+
s.label = r[2], s.ops.push(o);
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
r[2] && s.ops.pop(), s.trys.pop();
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
o = e.call(t, s);
|
|
469
|
+
} catch (t) {
|
|
470
|
+
o = [6, t], i = 0;
|
|
471
|
+
} finally {
|
|
472
|
+
n = r = 0;
|
|
473
|
+
}
|
|
474
|
+
if (5 & o[0]) throw o[1];
|
|
475
|
+
return {
|
|
476
|
+
value: o[0] ? o[1] : void 0,
|
|
477
|
+
done: !0
|
|
478
|
+
};
|
|
479
|
+
}([o, a]);
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function r(t, e) {
|
|
484
|
+
for (var n = 0, i = e.length, r = t.length; n < i; n++, r++) t[r] = e[n];
|
|
485
|
+
return t;
|
|
486
|
+
}
|
|
487
|
+
Array.prototype.includes || Object.defineProperty(Array.prototype, "includes", {
|
|
488
|
+
value: function (t, e) {
|
|
489
|
+
if (null == this) throw new TypeError('"this" is null or not defined');
|
|
490
|
+
var n = Object(this),
|
|
491
|
+
i = n.length >>> 0;
|
|
492
|
+
if (0 === i) return !1;
|
|
493
|
+
var r = 0 | e,
|
|
494
|
+
o = Math.max(r >= 0 ? r : i - Math.abs(r), 0);
|
|
495
|
+
function s(t, e) {
|
|
496
|
+
return t === e || "number" == typeof t && "number" == typeof e && isNaN(t) && isNaN(e);
|
|
497
|
+
}
|
|
498
|
+
for (; o < i;) {
|
|
499
|
+
if (s(n[o], t)) return !0;
|
|
500
|
+
o++;
|
|
501
|
+
}
|
|
502
|
+
return !1;
|
|
503
|
+
}
|
|
504
|
+
}), String.prototype.includes || (String.prototype.includes = function (t, e) {
|
|
505
|
+
return "number" != typeof e && (e = 0), !(e + t.length > this.length) && -1 !== this.indexOf(t, e);
|
|
506
|
+
}), Array.prototype.find || Object.defineProperty(Array.prototype, "find", {
|
|
507
|
+
value: function (t) {
|
|
508
|
+
if (null == this) throw new TypeError('"this" is null or not defined');
|
|
509
|
+
var e = Object(this),
|
|
510
|
+
n = e.length >>> 0;
|
|
511
|
+
if ("function" != typeof t) throw new TypeError("predicate must be a function");
|
|
512
|
+
for (var i = arguments[1], r = 0; r < n;) {
|
|
513
|
+
var o = e[r];
|
|
514
|
+
if (t.call(i, o, r, e)) return o;
|
|
515
|
+
r++;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
var o = function (t) {
|
|
520
|
+
for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
|
|
521
|
+
return e.some(function (e) {
|
|
522
|
+
return Object.prototype.toString.call(t).slice(8, -1).toLowerCase() === e;
|
|
523
|
+
});
|
|
524
|
+
},
|
|
525
|
+
s = "1.1.1",
|
|
526
|
+
a = function () {
|
|
527
|
+
function t() {
|
|
528
|
+
this.subs = [];
|
|
529
|
+
}
|
|
530
|
+
return t.prototype.addSub = function (t) {
|
|
531
|
+
this.subs.includes(t) || this.subs.push(t);
|
|
532
|
+
}, t.prototype.notify = function () {
|
|
533
|
+
this.subs.forEach(function (t) {
|
|
534
|
+
t.update();
|
|
535
|
+
});
|
|
536
|
+
}, t;
|
|
537
|
+
}(),
|
|
538
|
+
c = "__proto__" in {};
|
|
539
|
+
function h(t, e, n, i) {
|
|
540
|
+
Object.defineProperty(t, e, {
|
|
541
|
+
value: n,
|
|
542
|
+
enumerable: !!i,
|
|
543
|
+
writable: !0,
|
|
544
|
+
configurable: !0
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
var l = Array.prototype,
|
|
548
|
+
u = Object.create(l);
|
|
549
|
+
["push", "pop", "shift", "unshift", "sort", "splice", "reverse"].forEach(function (t) {
|
|
550
|
+
u[t] = function () {
|
|
551
|
+
for (var e = [], n = 0; n < arguments.length; n++) e[n] = arguments[n];
|
|
552
|
+
var i = l[t].apply(this, e),
|
|
553
|
+
r = this.__luckyOb__;
|
|
554
|
+
return ["push", "unshift", "splice"].includes(t) && r.walk(this), r.dep.notify(), i;
|
|
555
|
+
};
|
|
556
|
+
});
|
|
557
|
+
var f = function () {
|
|
558
|
+
function t(t) {
|
|
559
|
+
this.dep = new a(), h(t, "__luckyOb__", this), Array.isArray(t) && (c ? t.__proto__ = u : Object.getOwnPropertyNames(u).forEach(function (e) {
|
|
560
|
+
h(t, e, u[e]);
|
|
561
|
+
})), this.walk(t);
|
|
562
|
+
}
|
|
563
|
+
return t.prototype.walk = function (t) {
|
|
564
|
+
Object.keys(t).forEach(function (e) {
|
|
565
|
+
p(t, e, t[e]);
|
|
566
|
+
});
|
|
567
|
+
}, t;
|
|
568
|
+
}();
|
|
569
|
+
function d(t) {
|
|
570
|
+
if (t && "object" == typeof t) return "__luckyOb__" in t ? t.__luckyOb__ : new f(t);
|
|
571
|
+
}
|
|
572
|
+
function p(t, e, n) {
|
|
573
|
+
var i = new a(),
|
|
574
|
+
r = Object.getOwnPropertyDescriptor(t, e);
|
|
575
|
+
if (!r || !1 !== r.configurable) {
|
|
576
|
+
var o = r && r.get,
|
|
577
|
+
s = r && r.set;
|
|
578
|
+
o && !s || 2 !== arguments.length || (n = t[e]);
|
|
579
|
+
var c = d(n);
|
|
580
|
+
Object.defineProperty(t, e, {
|
|
581
|
+
get: function () {
|
|
582
|
+
var e = o ? o.call(t) : n;
|
|
583
|
+
return a.target && (i.addSub(a.target), c && c.dep.addSub(a.target)), e;
|
|
584
|
+
},
|
|
585
|
+
set: function (e) {
|
|
586
|
+
e !== n && (n = e, o && !s || (s ? s.call(t, e) : n = e, c = d(e), i.notify()));
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
var v = 0,
|
|
592
|
+
g = function () {
|
|
593
|
+
function t(t, e, n, i) {
|
|
594
|
+
void 0 === i && (i = {}), this.id = v++, this.$lucky = t, this.expr = e, this.deep = !!i.deep, this.getter = "function" == typeof e ? e : function (t) {
|
|
595
|
+
t += ".";
|
|
596
|
+
for (var e = [], n = "", i = 0; i < t.length; i++) {
|
|
597
|
+
var r = t[i];
|
|
598
|
+
if (/\[|\./.test(r)) e.push(n), n = "";else {
|
|
599
|
+
if (/\W/.test(r)) continue;
|
|
600
|
+
n += r;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return function (t) {
|
|
604
|
+
return e.reduce(function (t, e) {
|
|
605
|
+
return t[e];
|
|
606
|
+
}, t);
|
|
607
|
+
};
|
|
608
|
+
}(e), this.cb = n, this.value = this.get();
|
|
609
|
+
}
|
|
610
|
+
return t.prototype.get = function () {
|
|
611
|
+
a.target = this;
|
|
612
|
+
var t = this.getter.call(this.$lucky, this.$lucky);
|
|
613
|
+
return this.deep && function (t) {
|
|
614
|
+
var e = function (t) {
|
|
615
|
+
o(t, "array", "object") && Object.keys(t).forEach(function (n) {
|
|
616
|
+
var i = t[n];
|
|
617
|
+
e(i);
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
e(t);
|
|
621
|
+
}(t), a.target = null, t;
|
|
622
|
+
}, t.prototype.update = function () {
|
|
623
|
+
var t = this.get(),
|
|
624
|
+
e = this.value;
|
|
625
|
+
this.value = t, this.cb.call(this.$lucky, t, e);
|
|
626
|
+
}, t;
|
|
627
|
+
}(),
|
|
628
|
+
y = function (r) {
|
|
629
|
+
function o(t, e) {
|
|
630
|
+
var n = r.call(this, t, {
|
|
631
|
+
width: e.width || "300px",
|
|
632
|
+
height: e.height || "150px"
|
|
633
|
+
}) || this;
|
|
634
|
+
return n.mask = {}, n.scratch = {
|
|
635
|
+
radius: 20,
|
|
636
|
+
percent: .5
|
|
637
|
+
}, n.progress = 0, n.isScratching = !1, n.isCompleted = !1, n.disabled = !1, n.isFirstScratch = !0, n.eventsInitialized = !1, n.initData(e), n.init(), n;
|
|
638
|
+
}
|
|
639
|
+
return function (e, n) {
|
|
640
|
+
if ("function" != typeof n && null !== n) throw new TypeError("Class extends value " + String(n) + " is not a constructor or null");
|
|
641
|
+
function i() {
|
|
642
|
+
this.constructor = e;
|
|
643
|
+
}
|
|
644
|
+
t(e, n), e.prototype = null === n ? Object.create(n) : (i.prototype = n.prototype, new i());
|
|
645
|
+
}(o, r), o.prototype.initData = function (t) {
|
|
646
|
+
this.$set(this, "mask", e({
|
|
647
|
+
type: "color",
|
|
648
|
+
color: "#ccc"
|
|
649
|
+
}, t.mask)), this.$set(this, "scratch", e({
|
|
650
|
+
radius: 20,
|
|
651
|
+
percent: .5
|
|
652
|
+
}, t.scratch)), this.$set(this, "onceBeforeStartCallback", t.onceBeforeStart), this.$set(this, "beforeStartCallback", t.beforeStart), this.$set(this, "startCallback", t.start), this.$set(this, "endCallback", t.end), this.$set(this, "successCallback", t.success), this.$set(this, "afterInitCallback", t.afterInit);
|
|
653
|
+
}, o.prototype.resize = function () {
|
|
654
|
+
var t, e;
|
|
655
|
+
r.prototype.resize.call(this), this.draw(), null === (e = (t = this.config).afterResize) || void 0 === e || e.call(t);
|
|
656
|
+
}, o.prototype.init = function () {
|
|
657
|
+
var t;
|
|
658
|
+
return n(this, void 0, void 0, function () {
|
|
659
|
+
return i(this, function (e) {
|
|
660
|
+
switch (e.label) {
|
|
661
|
+
case 0:
|
|
662
|
+
return this.initLucky(), this.progress = 0, this.isScratching = !1, this.isCompleted = !1, this.isFirstScratch = !0, [4, this.draw()];
|
|
663
|
+
case 1:
|
|
664
|
+
return e.sent(), this.handleBindEvents(), null === (t = this.afterInitCallback) || void 0 === t || t.call(this), [2];
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
}, o.prototype.draw = function () {
|
|
669
|
+
var t, e, r, o;
|
|
670
|
+
return n(this, void 0, void 0, function () {
|
|
671
|
+
var n, s, a;
|
|
672
|
+
return i(this, function (i) {
|
|
673
|
+
switch (i.label) {
|
|
674
|
+
case 0:
|
|
675
|
+
return null === (e = (t = this.config).beforeInit) || void 0 === e || e.call(t), this.clearCanvas(), s = (n = this).mask, n.scratch, "image" === s.type && s.src ? [4, this.loadImg(s.src, {
|
|
676
|
+
src: s.src
|
|
677
|
+
})] : [3, 2];
|
|
678
|
+
case 1:
|
|
679
|
+
return a = i.sent(), this.ctx.drawImage(a, 0, 0, this.boxWidth, this.boxHeight), [3, 3];
|
|
680
|
+
case 2:
|
|
681
|
+
this.ctx.fillStyle = s.color || "#ccc", this.ctx.fillRect(0, 0, this.boxWidth, this.boxHeight), i.label = 3;
|
|
682
|
+
case 3:
|
|
683
|
+
return null === (o = (r = this.config).afterInit) || void 0 === o || o.call(r), [2];
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
}, o.prototype.handleBindEvents = function () {
|
|
688
|
+
var t = this;
|
|
689
|
+
if (!this.eventsInitialized) {
|
|
690
|
+
this.eventsInitialized = !0;
|
|
691
|
+
var e = this.config.canvasElement;
|
|
692
|
+
e && (e.addEventListener("touchstart", function (e) {
|
|
693
|
+
t.handleStart(e.touches[0]);
|
|
694
|
+
}), e.addEventListener("touchmove", function (e) {
|
|
695
|
+
e.preventDefault(), t.handleMove(e.touches[0]);
|
|
696
|
+
}), e.addEventListener("touchend", function () {
|
|
697
|
+
t.handleEnd();
|
|
698
|
+
}), e.addEventListener("mousedown", function (e) {
|
|
699
|
+
t.handleStart(e);
|
|
700
|
+
}), e.addEventListener("mousemove", function (e) {
|
|
701
|
+
e.preventDefault(), t.handleMove(e);
|
|
702
|
+
}), document.addEventListener("mouseup", function () {
|
|
703
|
+
t.handleEnd();
|
|
704
|
+
}));
|
|
705
|
+
}
|
|
706
|
+
}, o.prototype.handleStart = function (t) {
|
|
707
|
+
var e;
|
|
708
|
+
return n(this, void 0, void 0, function () {
|
|
709
|
+
var n, r;
|
|
710
|
+
return i(this, function (i) {
|
|
711
|
+
switch (i.label) {
|
|
712
|
+
case 0:
|
|
713
|
+
if (this.isCompleted || this.disabled) return [2];
|
|
714
|
+
if (!this.isFirstScratch || !this.onceBeforeStartCallback) return [3, 5];
|
|
715
|
+
i.label = 1;
|
|
716
|
+
case 1:
|
|
717
|
+
return i.trys.push([1, 3,, 4]), [4, this.onceBeforeStartCallback()];
|
|
718
|
+
case 2:
|
|
719
|
+
return !1 === i.sent() ? [2] : [3, 4];
|
|
720
|
+
case 3:
|
|
721
|
+
return n = i.sent(), console.error("onceBeforeStart 回调执行出错:", n), [2];
|
|
722
|
+
case 4:
|
|
723
|
+
this.isFirstScratch = !1, i.label = 5;
|
|
724
|
+
case 5:
|
|
725
|
+
if (!this.beforeStartCallback) return [3, 9];
|
|
726
|
+
i.label = 6;
|
|
727
|
+
case 6:
|
|
728
|
+
return i.trys.push([6, 8,, 9]), [4, this.beforeStartCallback()];
|
|
729
|
+
case 7:
|
|
730
|
+
return !1 === i.sent() ? [2] : [3, 9];
|
|
731
|
+
case 8:
|
|
732
|
+
return r = i.sent(), console.error("beforeStart 回调执行出错:", r), [2];
|
|
733
|
+
case 9:
|
|
734
|
+
return this.isScratching = !0, null === (e = this.startCallback) || void 0 === e || e.call(this), this.drawArc(t), [2];
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
}, o.prototype.handleMove = function (t) {
|
|
739
|
+
!this.isScratching || this.isCompleted || this.disabled || this.drawArc(t);
|
|
740
|
+
}, o.prototype.handleEnd = function () {
|
|
741
|
+
var t;
|
|
742
|
+
!this.isScratching || this.isCompleted || this.disabled || (this.isScratching = !1, this.checkProgress(), null === (t = this.endCallback) || void 0 === t || t.call(this));
|
|
743
|
+
}, o.prototype.drawArc = function (t) {
|
|
744
|
+
var e = this.config.canvasElement;
|
|
745
|
+
if (e) {
|
|
746
|
+
var n = e.getBoundingClientRect(),
|
|
747
|
+
i = (t.clientX - n.left) * this.config.dpr,
|
|
748
|
+
r = (t.clientY - n.top) * this.config.dpr;
|
|
749
|
+
this.drawArcAt(i, r);
|
|
750
|
+
}
|
|
751
|
+
}, o.prototype.drawArcAt = function (t, e) {
|
|
752
|
+
this.ctx.globalCompositeOperation = "destination-out", this.ctx.beginPath(), this.ctx.arc(t, e, this.scratch.radius * this.config.dpr, 0, 2 * Math.PI), this.ctx.fill(), this.ctx.globalCompositeOperation = "source-over";
|
|
753
|
+
}, o.prototype.checkProgress = function () {
|
|
754
|
+
var t;
|
|
755
|
+
try {
|
|
756
|
+
for (var e = this.ctx.getImageData(0, 0, this.boxWidth * this.config.dpr, this.boxHeight * this.config.dpr).data, n = 0, i = 0; i < e.length; i += 4) e[i + 3] < 128 && n++;
|
|
757
|
+
this.progress = n / (e.length / 4), this.progress >= this.scratch.percent && (this.isCompleted = !0, this.clearCanvas(), null === (t = this.successCallback) || void 0 === t || t.call(this, this.progress));
|
|
758
|
+
} catch (t) {
|
|
759
|
+
console.error("无法计算刮开进度,可能是因为图片跨域:", t);
|
|
760
|
+
}
|
|
761
|
+
}, o.prototype.setDisabled = function (t) {
|
|
762
|
+
this.disabled = t;
|
|
763
|
+
}, o.prototype.handleTouchStart = function (t, e) {
|
|
764
|
+
var r;
|
|
765
|
+
return n(this, void 0, void 0, function () {
|
|
766
|
+
var n, o;
|
|
767
|
+
return i(this, function (i) {
|
|
768
|
+
switch (i.label) {
|
|
769
|
+
case 0:
|
|
770
|
+
if (this.isCompleted || this.disabled) return [2];
|
|
771
|
+
if (!this.isFirstScratch || !this.onceBeforeStartCallback) return [3, 5];
|
|
772
|
+
i.label = 1;
|
|
773
|
+
case 1:
|
|
774
|
+
return i.trys.push([1, 3,, 4]), [4, this.onceBeforeStartCallback()];
|
|
775
|
+
case 2:
|
|
776
|
+
return !1 === i.sent() ? [2] : [3, 4];
|
|
777
|
+
case 3:
|
|
778
|
+
return n = i.sent(), console.error("onceBeforeStart 回调执行出错:", n), [2];
|
|
779
|
+
case 4:
|
|
780
|
+
this.isFirstScratch = !1, i.label = 5;
|
|
781
|
+
case 5:
|
|
782
|
+
if (!this.beforeStartCallback) return [3, 9];
|
|
783
|
+
i.label = 6;
|
|
784
|
+
case 6:
|
|
785
|
+
return i.trys.push([6, 8,, 9]), [4, this.beforeStartCallback()];
|
|
786
|
+
case 7:
|
|
787
|
+
return !1 === i.sent() ? [2] : [3, 9];
|
|
788
|
+
case 8:
|
|
789
|
+
return o = i.sent(), console.error("beforeStart 回调执行出错:", o), [2];
|
|
790
|
+
case 9:
|
|
791
|
+
return this.isScratching = !0, null === (r = this.startCallback) || void 0 === r || r.call(this), this.drawArcAt(t * this.config.dpr, e * this.config.dpr), [2];
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
}, o.prototype.handleTouchMove = function (t, e) {
|
|
796
|
+
!this.isScratching || this.isCompleted || this.disabled || this.drawArcAt(t * this.config.dpr, e * this.config.dpr);
|
|
797
|
+
}, o.prototype.handleTouchEnd = function () {
|
|
798
|
+
var t;
|
|
799
|
+
!this.isScratching || this.isCompleted || this.disabled || (this.isScratching = !1, this.checkProgress(), null === (t = this.endCallback) || void 0 === t || t.call(this));
|
|
800
|
+
}, o;
|
|
801
|
+
}(function () {
|
|
802
|
+
function t(t, e) {
|
|
803
|
+
var n = this;
|
|
804
|
+
this.version = s, this.htmlFontSize = 16, this.rAF = function () {}, this.boxWidth = 0, this.boxHeight = 0, "string" == typeof t ? t = {
|
|
805
|
+
el: t
|
|
806
|
+
} : 1 === t.nodeType && (t = {
|
|
807
|
+
el: "",
|
|
808
|
+
divElement: t
|
|
809
|
+
}), this.config = t, this.data = e, t.flag || (t.flag = "WEB"), t.el && (t.divElement = document.querySelector(t.el)), t.divElement && (t.canvasElement = document.createElement("canvas"), t.divElement.appendChild(t.canvasElement)), t.canvasElement && (t.ctx = t.canvasElement.getContext("2d"), t.canvasElement.setAttribute("package", "".concat("lucky-scratch", "@").concat(s)), t.canvasElement.addEventListener("click", function (t) {
|
|
810
|
+
return n.handleClick(t);
|
|
811
|
+
})), this.ctx = t.ctx, this.initWindowFunction(), this.config.ctx || console.error("无法获取到 CanvasContext2D"), window && "function" == typeof window.addEventListener && window.addEventListener("resize", function (t, e) {
|
|
812
|
+
void 0 === e && (e = 300);
|
|
813
|
+
var n = null;
|
|
814
|
+
return function () {
|
|
815
|
+
for (var i = this, r = [], o = 0; o < arguments.length; o++) r[o] = arguments[o];
|
|
816
|
+
n || (n = setTimeout(function () {
|
|
817
|
+
t.apply(i, r), clearTimeout(n), n = null;
|
|
818
|
+
}, e));
|
|
819
|
+
};
|
|
820
|
+
}(function () {
|
|
821
|
+
return n.resize();
|
|
822
|
+
}, 300)), window && window.document && "function" == typeof window.MutationObserver && "WEB" === this.config.flag && new window.MutationObserver(function () {
|
|
823
|
+
n.resize();
|
|
824
|
+
}).observe(document.documentElement, {
|
|
825
|
+
attributes: !0
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
return t.prototype.resize = function () {
|
|
829
|
+
var t, e;
|
|
830
|
+
null === (e = (t = this.config).beforeResize) || void 0 === e || e.call(t), this.setHTMLFontSize(), this.setDpr(), this.resetWidthAndHeight(), this.zoomCanvas();
|
|
831
|
+
}, t.prototype.initLucky = function () {
|
|
832
|
+
if (this.resize(), !this.boxWidth || !this.boxHeight) return console.error("无法获取到宽度或高度");
|
|
833
|
+
}, t.prototype.handleClick = function (t) {}, t.prototype.setHTMLFontSize = function () {
|
|
834
|
+
window && window.getComputedStyle && (this.htmlFontSize = +window.getComputedStyle(document.documentElement).fontSize.slice(0, -2));
|
|
835
|
+
}, t.prototype.clearCanvas = function () {
|
|
836
|
+
var t = [this.boxWidth, this.boxHeight],
|
|
837
|
+
e = t[0],
|
|
838
|
+
n = t[1];
|
|
839
|
+
this.ctx.clearRect(-e, -n, 2 * e, 2 * n);
|
|
840
|
+
}, t.prototype.setDpr = function () {
|
|
841
|
+
var t = this.config;
|
|
842
|
+
t.dpr || (window ? window.dpr = t.dpr = window.devicePixelRatio || 1 : t.dpr || console.error(t, "未传入 dpr 可能会导致绘制异常"));
|
|
843
|
+
}, t.prototype.resetWidthAndHeight = function () {
|
|
844
|
+
var t = this.config,
|
|
845
|
+
e = this.data,
|
|
846
|
+
n = 0,
|
|
847
|
+
i = 0;
|
|
848
|
+
t.divElement && (n = t.divElement.offsetWidth, i = t.divElement.offsetHeight), this.boxWidth = this.getLength(e.width || t.width) || n, this.boxHeight = this.getLength(e.height || t.height) || i, t.divElement && (t.divElement.style.overflow = "hidden", t.divElement.style.width = this.boxWidth + "px", t.divElement.style.height = this.boxHeight + "px");
|
|
849
|
+
}, t.prototype.zoomCanvas = function () {
|
|
850
|
+
var t = this.config,
|
|
851
|
+
e = this.ctx,
|
|
852
|
+
n = t.canvasElement,
|
|
853
|
+
i = t.dpr,
|
|
854
|
+
r = [this.boxWidth * i, this.boxHeight * i],
|
|
855
|
+
o = r[0],
|
|
856
|
+
s = r[1];
|
|
857
|
+
n && (n.width = o, n.height = s, n.style.width = "".concat(o, "px"), n.style.height = "".concat(s, "px"), n.style["transform-origin"] = "left top", n.style.transform = "scale(".concat(1 / i, ")"), e.scale(i, i));
|
|
858
|
+
}, t.prototype.initWindowFunction = function () {
|
|
859
|
+
var t = this.config;
|
|
860
|
+
if (window) return this.rAF = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (t) {
|
|
861
|
+
window.setTimeout(t, 1e3 / 60);
|
|
862
|
+
}, t.setTimeout = window.setTimeout, t.setInterval = window.setInterval, t.clearTimeout = window.clearTimeout, void (t.clearInterval = window.clearInterval);
|
|
863
|
+
if (t.rAF) this.rAF = t.rAF;else if (t.setTimeout) {
|
|
864
|
+
var e = t.setTimeout;
|
|
865
|
+
this.rAF = function (t) {
|
|
866
|
+
return e(t, 16.7);
|
|
867
|
+
};
|
|
868
|
+
} else this.rAF = function (t) {
|
|
869
|
+
return setTimeout(t, 16.7);
|
|
870
|
+
};
|
|
871
|
+
}, t.prototype.isWeb = function () {
|
|
872
|
+
return ["WEB", "UNI-H5", "TARO-H5"].includes(this.config.flag);
|
|
873
|
+
}, t.prototype.loadImg = function (t, e, n) {
|
|
874
|
+
var i = this;
|
|
875
|
+
return void 0 === n && (n = "$resolve"), new Promise(function (r, o) {
|
|
876
|
+
if (t || o("=> '".concat(e.src, "' 不能为空或不合法")), "WEB" !== i.config.flag) return e[n] = r, void (e.$reject = o);
|
|
877
|
+
var s = new Image();
|
|
878
|
+
s.crossorigin = "anonymous", s.onload = function () {
|
|
879
|
+
return r(s);
|
|
880
|
+
}, s.onerror = function () {
|
|
881
|
+
return o("=> '".concat(e.src, "' 图片加载失败"));
|
|
882
|
+
}, s.src = t;
|
|
883
|
+
});
|
|
884
|
+
}, t.prototype.drawImage = function (t, e) {
|
|
885
|
+
for (var n, i, o, s = [], a = 2; a < arguments.length; a++) s[a - 2] = arguments[a];
|
|
886
|
+
var c = this.config,
|
|
887
|
+
h = c.flag,
|
|
888
|
+
l = c.dpr;
|
|
889
|
+
if (["WEB", "MP-WX"].includes(h)) o = e;else {
|
|
890
|
+
if (!["UNI-H5", "UNI-MP", "TARO-H5", "TARO-MP"].includes(h)) return console.error("意料之外的 flag, 该平台尚未兼容!");
|
|
891
|
+
o = e.path;
|
|
892
|
+
}
|
|
893
|
+
var u = null === (i = (n = o.canvas || o).getContext) || void 0 === i ? void 0 : i.call(n, "2d");
|
|
894
|
+
if (u && !this.isWeb()) {
|
|
895
|
+
s = s.map(function (t) {
|
|
896
|
+
return t * l;
|
|
897
|
+
});
|
|
898
|
+
var f = u.getImageData.apply(u, s.slice(0, 4));
|
|
899
|
+
t.putImageData.apply(t, r([f], s.slice(4, 6)));
|
|
900
|
+
} else {
|
|
901
|
+
8 === s.length && (s = s.map(function (t, e) {
|
|
902
|
+
return e < 4 ? t * l : t;
|
|
903
|
+
}));
|
|
904
|
+
try {
|
|
905
|
+
t.drawImage.apply(t, r([o], s));
|
|
906
|
+
} catch (t) {}
|
|
907
|
+
}
|
|
908
|
+
}, t.prototype.computedWidthAndHeight = function (t, e, n, i) {
|
|
909
|
+
if (!e.width && !e.height) return [t.width, t.height];
|
|
910
|
+
if (e.width && !e.height) {
|
|
911
|
+
var r = this.getLength(e.width, n);
|
|
912
|
+
return [r, t.height * (r / t.width)];
|
|
913
|
+
}
|
|
914
|
+
if (!e.width && e.height) {
|
|
915
|
+
var o = this.getLength(e.height, i);
|
|
916
|
+
return [t.width * (o / t.height), o];
|
|
917
|
+
}
|
|
918
|
+
return [this.getLength(e.width, n), this.getLength(e.height, i)];
|
|
919
|
+
}, t.prototype.changeUnits = function (t, e) {
|
|
920
|
+
var n = this;
|
|
921
|
+
void 0 === e && (e = 1);
|
|
922
|
+
var i = this.config;
|
|
923
|
+
return Number(t.replace(/^([-]*[0-9.]*)([a-z%]*)$/, function (t, r, o) {
|
|
924
|
+
var s = {
|
|
925
|
+
"%": function (t) {
|
|
926
|
+
return t * (e / 100);
|
|
927
|
+
},
|
|
928
|
+
px: function (t) {
|
|
929
|
+
return 1 * t;
|
|
930
|
+
},
|
|
931
|
+
rem: function (t) {
|
|
932
|
+
return t * n.htmlFontSize;
|
|
933
|
+
},
|
|
934
|
+
vw: function (t) {
|
|
935
|
+
return t / 100 * window.innerWidth;
|
|
936
|
+
}
|
|
937
|
+
}[o];
|
|
938
|
+
if (s) return s(r);
|
|
939
|
+
var a = i.handleCssUnit || i.unitFunc;
|
|
940
|
+
return a ? a(r, o) : r;
|
|
941
|
+
}));
|
|
942
|
+
}, t.prototype.getLength = function (t, e) {
|
|
943
|
+
return o(t, "number") ? t : o(t, "string") ? this.changeUnits(t, e) : 0;
|
|
944
|
+
}, t.prototype.getOffsetX = function (t, e) {
|
|
945
|
+
return void 0 === e && (e = 0), (e - t) / 2;
|
|
946
|
+
}, t.prototype.getOffscreenCanvas = function (t, e) {
|
|
947
|
+
if (!(n = this, i = "_offscreenCanvas", Object.prototype.hasOwnProperty.call(n, i) || (window && window.document && "WEB" === this.config.flag ? this._offscreenCanvas = document.createElement("canvas") : this._offscreenCanvas = this.config.offscreenCanvas, this._offscreenCanvas))) return console.error("离屏 Canvas 无法渲染!");
|
|
948
|
+
var n,
|
|
949
|
+
i,
|
|
950
|
+
r = this.config.dpr,
|
|
951
|
+
o = this._offscreenCanvas;
|
|
952
|
+
o.width = (t || 300) * r, o.height = (e || 150) * r;
|
|
953
|
+
var s = o.getContext("2d");
|
|
954
|
+
return s.clearRect(0, 0, t, e), s.scale(r, r), s.dpr = r, {
|
|
955
|
+
_offscreenCanvas: o,
|
|
956
|
+
_ctx: s
|
|
957
|
+
};
|
|
958
|
+
}, t.prototype.$set = function (t, e, n) {
|
|
959
|
+
t && "object" == typeof t && p(t, e, n);
|
|
960
|
+
}, t.prototype.$computed = function (t, e, n) {
|
|
961
|
+
var i = this;
|
|
962
|
+
Object.defineProperty(t, e, {
|
|
963
|
+
get: function () {
|
|
964
|
+
return n.call(i);
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}, t.prototype.$watch = function (t, e, n) {
|
|
968
|
+
void 0 === n && (n = {}), "object" == typeof e && (e = (n = e).handler);
|
|
969
|
+
var i = new g(this, t, e, n);
|
|
970
|
+
return n.immediate && e.call(this, i.value), function () {};
|
|
971
|
+
}, t.version = s, t;
|
|
972
|
+
}()),
|
|
973
|
+
b = function (t, e) {
|
|
974
|
+
var n = document.createElement("canvas"),
|
|
975
|
+
i = n.getContext("2d"),
|
|
976
|
+
r = t.width,
|
|
977
|
+
o = t.height;
|
|
978
|
+
return n.width = r, n.height = o, function (t) {
|
|
979
|
+
for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
|
|
980
|
+
var i = e[0],
|
|
981
|
+
r = e[1],
|
|
982
|
+
o = e[2],
|
|
983
|
+
s = e[3],
|
|
984
|
+
a = e[4],
|
|
985
|
+
c = Math.min(o, s),
|
|
986
|
+
h = Math.PI;
|
|
987
|
+
a > c / 2 && (a = c / 2), t.beginPath(), t.moveTo(i + a, r), t.lineTo(i + a, r), t.lineTo(i + o - a, r), t.arc(i + o - a, r + a, a, -h / 2, 0), t.lineTo(i + o, r + s - a), t.arc(i + o - a, r + s - a, a, 0, h / 2), t.lineTo(i + a, r + s), t.arc(i + a, r + s - a, a, h / 2, h), t.lineTo(i, r + a), t.arc(i + a, r + a, a, h, -h / 2), t.closePath();
|
|
988
|
+
}(i, 0, 0, r, o, e), i.clip(), i.drawImage(t, 0, 0, r, o), n;
|
|
989
|
+
},
|
|
990
|
+
w = function (t, e) {
|
|
991
|
+
var n = document.createElement("canvas"),
|
|
992
|
+
i = n.getContext("2d"),
|
|
993
|
+
r = t.width,
|
|
994
|
+
o = t.height;
|
|
995
|
+
if (n.width = r, n.height = o, "string" == typeof i.filter) i.filter = "opacity(".concat(100 * e, "%)"), i.drawImage(t, 0, 0, r, o);else {
|
|
996
|
+
i.drawImage(t, 0, 0, r, o);
|
|
997
|
+
for (var s = i.getImageData(0, 0, r, o), a = s.data, c = a.length, h = 0; h < c; h += 4) {
|
|
998
|
+
var l = a[h + 3];
|
|
999
|
+
0 !== l && (a[h + 3] = l * e);
|
|
1000
|
+
}
|
|
1001
|
+
i.putImageData(s, 0, 0);
|
|
1002
|
+
}
|
|
1003
|
+
return n;
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
/***/ }),
|
|
1008
|
+
/* 2 */
|
|
1009
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1010
|
+
|
|
1011
|
+
"use strict";
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
exports.__esModule = true;
|
|
1015
|
+
exports.changeUnits = void 0;
|
|
1016
|
+
exports.getImage = getImage;
|
|
1017
|
+
exports.rpx2px = exports.resolveImage = void 0;
|
|
1018
|
+
var windowWidth = wx.getSystemInfoSync().windowWidth;
|
|
1019
|
+
var rpx2px = exports.rpx2px = function rpx2px(value) {
|
|
1020
|
+
if (typeof value === 'string') value = Number(value.replace(/[a-z]*/g, ''));
|
|
1021
|
+
return windowWidth / 750 * value;
|
|
1022
|
+
};
|
|
1023
|
+
var changeUnits = exports.changeUnits = function changeUnits(value) {
|
|
1024
|
+
value = String(value);
|
|
1025
|
+
return Number(value.replace(/^(\-*[0-9.]*)([a-z%]*)$/, function (value, num, unit) {
|
|
1026
|
+
switch (unit) {
|
|
1027
|
+
case 'px':
|
|
1028
|
+
num *= 1;
|
|
1029
|
+
break;
|
|
1030
|
+
case 'rpx':
|
|
1031
|
+
num = rpx2px(num);
|
|
1032
|
+
break;
|
|
1033
|
+
default:
|
|
1034
|
+
num *= 1;
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
return num;
|
|
1038
|
+
}));
|
|
1039
|
+
};
|
|
1040
|
+
var resolveImage = exports.resolveImage = function resolveImage(e, img, canvas, srcName, resolveName) {
|
|
1041
|
+
if (srcName === void 0) {
|
|
1042
|
+
srcName = 'src';
|
|
1043
|
+
}
|
|
1044
|
+
if (resolveName === void 0) {
|
|
1045
|
+
resolveName = '$resolve';
|
|
1046
|
+
}
|
|
1047
|
+
var imgObj = canvas.createImage();
|
|
1048
|
+
imgObj.onload = function () {
|
|
1049
|
+
img[resolveName](imgObj);
|
|
1050
|
+
};
|
|
1051
|
+
imgObj.src = img[srcName];
|
|
1052
|
+
};
|
|
1053
|
+
function getImage() {
|
|
1054
|
+
var _this = this;
|
|
1055
|
+
return new Promise(function (resolve, reject) {
|
|
1056
|
+
wx.canvasToTempFilePath({
|
|
1057
|
+
canvas: _this.canvas,
|
|
1058
|
+
success: function success(res) {
|
|
1059
|
+
return resolve(res);
|
|
1060
|
+
},
|
|
1061
|
+
fail: function fail(err) {
|
|
1062
|
+
return reject(err);
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/***/ })
|
|
1069
|
+
/******/ ]);
|
|
1070
|
+
//# sourceMappingURL=index.js.map
|