@feedmepos/mf-payment 1.3.1 → 1.3.3

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.
@@ -0,0 +1,460 @@
1
+ import { defineComponent as D, h as P } from "vue";
2
+ /*!
3
+ * Signature Pad v3.0.0-beta.4 | https://github.com/szimek/signature_pad
4
+ * (c) 2020 Szymon Nowak | Released under the MIT license
5
+ */
6
+ class y {
7
+ constructor(t, e, i) {
8
+ this.x = t, this.y = e, this.time = i || Date.now();
9
+ }
10
+ distanceTo(t) {
11
+ return Math.sqrt(Math.pow(this.x - t.x, 2) + Math.pow(this.y - t.y, 2));
12
+ }
13
+ equals(t) {
14
+ return this.x === t.x && this.y === t.y && this.time === t.time;
15
+ }
16
+ velocityFrom(t) {
17
+ return this.time !== t.time ? this.distanceTo(t) / (this.time - t.time) : 0;
18
+ }
19
+ }
20
+ class x {
21
+ constructor(t, e, i, n, o, r) {
22
+ this.startPoint = t, this.control2 = e, this.control1 = i, this.endPoint = n, this.startWidth = o, this.endWidth = r;
23
+ }
24
+ static fromPoints(t, e) {
25
+ const i = this.calculateControlPoints(t[0], t[1], t[2]).c2, n = this.calculateControlPoints(t[1], t[2], t[3]).c1;
26
+ return new x(t[1], i, n, t[2], e.start, e.end);
27
+ }
28
+ static calculateControlPoints(t, e, i) {
29
+ const n = t.x - e.x, o = t.y - e.y, r = e.x - i.x, a = e.y - i.y, d = { x: (t.x + e.x) / 2, y: (t.y + e.y) / 2 }, h = { x: (e.x + i.x) / 2, y: (e.y + i.y) / 2 }, c = Math.sqrt(n * n + o * o), g = Math.sqrt(r * r + a * a), f = d.x - h.x, m = d.y - h.y, l = g / (c + g), u = { x: h.x + f * l, y: h.y + m * l }, v = e.x - u.x, p = e.y - u.y;
30
+ return {
31
+ c1: new y(d.x + v, d.y + p),
32
+ c2: new y(h.x + v, h.y + p)
33
+ };
34
+ }
35
+ length() {
36
+ let e = 0, i, n;
37
+ for (let o = 0; o <= 10; o += 1) {
38
+ const r = o / 10, a = this.point(r, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x), d = this.point(r, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
39
+ if (o > 0) {
40
+ const h = a - i, c = d - n;
41
+ e += Math.sqrt(h * h + c * c);
42
+ }
43
+ i = a, n = d;
44
+ }
45
+ return e;
46
+ }
47
+ point(t, e, i, n, o) {
48
+ return e * (1 - t) * (1 - t) * (1 - t) + 3 * i * (1 - t) * (1 - t) * t + 3 * n * (1 - t) * t * t + o * t * t * t;
49
+ }
50
+ }
51
+ function S(s, t = 250) {
52
+ let e = 0, i = null, n, o, r;
53
+ const a = () => {
54
+ e = Date.now(), i = null, n = s.apply(o, r), i || (o = null, r = []);
55
+ };
56
+ return function(...h) {
57
+ const c = Date.now(), g = t - (c - e);
58
+ return o = this, r = h, g <= 0 || g > t ? (i && (clearTimeout(i), i = null), e = c, n = s.apply(o, r), i || (o = null, r = [])) : i || (i = window.setTimeout(a, g)), n;
59
+ };
60
+ }
61
+ class w {
62
+ constructor(t, e = {}) {
63
+ this.canvas = t, this.options = e, this._handleMouseDown = (i) => {
64
+ i.which === 1 && (this._mouseButtonDown = !0, this._strokeBegin(i));
65
+ }, this._handleMouseMove = (i) => {
66
+ this._mouseButtonDown && this._strokeMoveUpdate(i);
67
+ }, this._handleMouseUp = (i) => {
68
+ i.which === 1 && this._mouseButtonDown && (this._mouseButtonDown = !1, this._strokeEnd(i));
69
+ }, this._handleTouchStart = (i) => {
70
+ if (i.preventDefault(), i.targetTouches.length === 1) {
71
+ const n = i.changedTouches[0];
72
+ this._strokeBegin(n);
73
+ }
74
+ }, this._handleTouchMove = (i) => {
75
+ i.preventDefault();
76
+ const n = i.targetTouches[0];
77
+ this._strokeMoveUpdate(n);
78
+ }, this._handleTouchEnd = (i) => {
79
+ if (i.target === this.canvas) {
80
+ i.preventDefault();
81
+ const o = i.changedTouches[0];
82
+ this._strokeEnd(o);
83
+ }
84
+ }, this.velocityFilterWeight = e.velocityFilterWeight || 0.7, this.minWidth = e.minWidth || 0.5, this.maxWidth = e.maxWidth || 2.5, this.throttle = "throttle" in e ? e.throttle : 16, this.minDistance = "minDistance" in e ? e.minDistance : 5, this.dotSize = e.dotSize || function() {
85
+ return (this.minWidth + this.maxWidth) / 2;
86
+ }, this.penColor = e.penColor || "black", this.backgroundColor = e.backgroundColor || "rgba(0,0,0,0)", this.onBegin = e.onBegin, this.onEnd = e.onEnd, this._strokeMoveUpdate = this.throttle ? S(w.prototype._strokeUpdate, this.throttle) : w.prototype._strokeUpdate, this._ctx = t.getContext("2d"), this.clear(), this.on();
87
+ }
88
+ clear() {
89
+ const { _ctx: t, canvas: e } = this;
90
+ t.fillStyle = this.backgroundColor, t.clearRect(0, 0, e.width, e.height), t.fillRect(0, 0, e.width, e.height), this._data = [], this._reset(), this._isEmpty = !0;
91
+ }
92
+ fromDataURL(t, e = {}, i) {
93
+ const n = new Image(), o = e.ratio || window.devicePixelRatio || 1, r = e.width || this.canvas.width / o, a = e.height || this.canvas.height / o;
94
+ this._reset(), n.onload = () => {
95
+ this._ctx.drawImage(n, 0, 0, r, a), i && i();
96
+ }, n.onerror = (d) => {
97
+ i && i(d);
98
+ }, n.src = t, this._isEmpty = !1;
99
+ }
100
+ toDataURL(t = "image/png", e) {
101
+ switch (t) {
102
+ case "image/svg+xml":
103
+ return this._toSVG();
104
+ default:
105
+ return this.canvas.toDataURL(t, e);
106
+ }
107
+ }
108
+ on() {
109
+ this.canvas.style.touchAction = "none", this.canvas.style.msTouchAction = "none", window.PointerEvent ? this._handlePointerEvents() : (this._handleMouseEvents(), "ontouchstart" in window && this._handleTouchEvents());
110
+ }
111
+ off() {
112
+ this.canvas.style.touchAction = "auto", this.canvas.style.msTouchAction = "auto", this.canvas.removeEventListener("pointerdown", this._handleMouseDown), this.canvas.removeEventListener("pointermove", this._handleMouseMove), document.removeEventListener("pointerup", this._handleMouseUp), this.canvas.removeEventListener("mousedown", this._handleMouseDown), this.canvas.removeEventListener("mousemove", this._handleMouseMove), document.removeEventListener("mouseup", this._handleMouseUp), this.canvas.removeEventListener("touchstart", this._handleTouchStart), this.canvas.removeEventListener("touchmove", this._handleTouchMove), this.canvas.removeEventListener("touchend", this._handleTouchEnd);
113
+ }
114
+ isEmpty() {
115
+ return this._isEmpty;
116
+ }
117
+ fromData(t) {
118
+ this.clear(), this._fromData(t, ({ color: e, curve: i }) => this._drawCurve({ color: e, curve: i }), ({ color: e, point: i }) => this._drawDot({ color: e, point: i })), this._data = t;
119
+ }
120
+ toData() {
121
+ return this._data;
122
+ }
123
+ _strokeBegin(t) {
124
+ const e = {
125
+ color: this.penColor,
126
+ points: []
127
+ };
128
+ typeof this.onBegin == "function" && this.onBegin(t), this._data.push(e), this._reset(), this._strokeUpdate(t);
129
+ }
130
+ _strokeUpdate(t) {
131
+ if (this._data.length === 0) {
132
+ this._strokeBegin(t);
133
+ return;
134
+ }
135
+ const e = t.clientX, i = t.clientY, n = this._createPoint(e, i), o = this._data[this._data.length - 1], r = o.points, a = r.length > 0 && r[r.length - 1], d = a ? n.distanceTo(a) <= this.minDistance : !1, h = o.color;
136
+ if (!a || !(a && d)) {
137
+ const c = this._addPoint(n);
138
+ a ? c && this._drawCurve({ color: h, curve: c }) : this._drawDot({ color: h, point: n }), r.push({
139
+ time: n.time,
140
+ x: n.x,
141
+ y: n.y
142
+ });
143
+ }
144
+ }
145
+ _strokeEnd(t) {
146
+ this._strokeUpdate(t), typeof this.onEnd == "function" && this.onEnd(t);
147
+ }
148
+ _handlePointerEvents() {
149
+ this._mouseButtonDown = !1, this.canvas.addEventListener("pointerdown", this._handleMouseDown), this.canvas.addEventListener("pointermove", this._handleMouseMove), document.addEventListener("pointerup", this._handleMouseUp);
150
+ }
151
+ _handleMouseEvents() {
152
+ this._mouseButtonDown = !1, this.canvas.addEventListener("mousedown", this._handleMouseDown), this.canvas.addEventListener("mousemove", this._handleMouseMove), document.addEventListener("mouseup", this._handleMouseUp);
153
+ }
154
+ _handleTouchEvents() {
155
+ this.canvas.addEventListener("touchstart", this._handleTouchStart), this.canvas.addEventListener("touchmove", this._handleTouchMove), this.canvas.addEventListener("touchend", this._handleTouchEnd);
156
+ }
157
+ _reset() {
158
+ this._lastPoints = [], this._lastVelocity = 0, this._lastWidth = (this.minWidth + this.maxWidth) / 2, this._ctx.fillStyle = this.penColor;
159
+ }
160
+ _createPoint(t, e) {
161
+ const i = this.canvas.getBoundingClientRect();
162
+ return new y(t - i.left, e - i.top, (/* @__PURE__ */ new Date()).getTime());
163
+ }
164
+ _addPoint(t) {
165
+ const { _lastPoints: e } = this;
166
+ if (e.push(t), e.length > 2) {
167
+ e.length === 3 && e.unshift(e[0]);
168
+ const i = this._calculateCurveWidths(e[1], e[2]), n = x.fromPoints(e, i);
169
+ return e.shift(), n;
170
+ }
171
+ return null;
172
+ }
173
+ _calculateCurveWidths(t, e) {
174
+ const i = this.velocityFilterWeight * e.velocityFrom(t) + (1 - this.velocityFilterWeight) * this._lastVelocity, n = this._strokeWidth(i), o = {
175
+ end: n,
176
+ start: this._lastWidth
177
+ };
178
+ return this._lastVelocity = i, this._lastWidth = n, o;
179
+ }
180
+ _strokeWidth(t) {
181
+ return Math.max(this.maxWidth / (t + 1), this.minWidth);
182
+ }
183
+ _drawCurveSegment(t, e, i) {
184
+ const n = this._ctx;
185
+ n.moveTo(t, e), n.arc(t, e, i, 0, 2 * Math.PI, !1), this._isEmpty = !1;
186
+ }
187
+ _drawCurve({ color: t, curve: e }) {
188
+ const i = this._ctx, n = e.endWidth - e.startWidth, o = Math.floor(e.length()) * 2;
189
+ i.beginPath(), i.fillStyle = t;
190
+ for (let r = 0; r < o; r += 1) {
191
+ const a = r / o, d = a * a, h = d * a, c = 1 - a, g = c * c, f = g * c;
192
+ let m = f * e.startPoint.x;
193
+ m += 3 * g * a * e.control1.x, m += 3 * c * d * e.control2.x, m += h * e.endPoint.x;
194
+ let l = f * e.startPoint.y;
195
+ l += 3 * g * a * e.control1.y, l += 3 * c * d * e.control2.y, l += h * e.endPoint.y;
196
+ const u = Math.min(e.startWidth + h * n, this.maxWidth);
197
+ this._drawCurveSegment(m, l, u);
198
+ }
199
+ i.closePath(), i.fill();
200
+ }
201
+ _drawDot({ color: t, point: e }) {
202
+ const i = this._ctx, n = typeof this.dotSize == "function" ? this.dotSize() : this.dotSize;
203
+ i.beginPath(), this._drawCurveSegment(e.x, e.y, n), i.closePath(), i.fillStyle = t, i.fill();
204
+ }
205
+ _fromData(t, e, i) {
206
+ for (const n of t) {
207
+ const { color: o, points: r } = n;
208
+ if (r.length > 1)
209
+ for (let a = 0; a < r.length; a += 1) {
210
+ const d = r[a], h = new y(d.x, d.y, d.time);
211
+ this.penColor = o, a === 0 && this._reset();
212
+ const c = this._addPoint(h);
213
+ c && e({ color: o, curve: c });
214
+ }
215
+ else
216
+ this._reset(), i({
217
+ color: o,
218
+ point: r[0]
219
+ });
220
+ }
221
+ }
222
+ _toSVG() {
223
+ const t = this._data, e = Math.max(window.devicePixelRatio || 1, 1), i = 0, n = 0, o = this.canvas.width / e, r = this.canvas.height / e, a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
224
+ a.setAttribute("width", this.canvas.width.toString()), a.setAttribute("height", this.canvas.height.toString()), this._fromData(t, ({ color: m, curve: l }) => {
225
+ const u = document.createElement("path");
226
+ if (!isNaN(l.control1.x) && !isNaN(l.control1.y) && !isNaN(l.control2.x) && !isNaN(l.control2.y)) {
227
+ const v = `M ${l.startPoint.x.toFixed(3)},${l.startPoint.y.toFixed(3)} C ${l.control1.x.toFixed(3)},${l.control1.y.toFixed(3)} ${l.control2.x.toFixed(3)},${l.control2.y.toFixed(3)} ${l.endPoint.x.toFixed(3)},${l.endPoint.y.toFixed(3)}`;
228
+ u.setAttribute("d", v), u.setAttribute("stroke-width", (l.endWidth * 2.25).toFixed(3)), u.setAttribute("stroke", m), u.setAttribute("fill", "none"), u.setAttribute("stroke-linecap", "round"), a.appendChild(u);
229
+ }
230
+ }, ({ color: m, point: l }) => {
231
+ const u = document.createElement("circle"), v = typeof this.dotSize == "function" ? this.dotSize() : this.dotSize;
232
+ u.setAttribute("r", v.toString()), u.setAttribute("cx", l.x.toString()), u.setAttribute("cy", l.y.toString()), u.setAttribute("fill", m), a.appendChild(u);
233
+ });
234
+ const d = "data:image/svg+xml;base64,", h = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="${i} ${n} ${o} ${r}" width="${o}" height="${r}">`;
235
+ let c = a.innerHTML;
236
+ if (c === void 0) {
237
+ const m = document.createElement("dummy"), l = a.childNodes;
238
+ m.innerHTML = "";
239
+ for (let u = 0; u < l.length; u += 1)
240
+ m.appendChild(l[u].cloneNode(!0));
241
+ c = m.innerHTML;
242
+ }
243
+ const f = h + c + "</svg>";
244
+ return d + btoa(f);
245
+ }
246
+ }
247
+ var M = {
248
+ format: "image/png",
249
+ quality: 0.92,
250
+ width: void 0,
251
+ height: void 0,
252
+ Canvas: void 0,
253
+ crossOrigin: void 0
254
+ }, E = function(s, t) {
255
+ return s === void 0 && (s = []), t === void 0 && (t = {}), new Promise(function(e) {
256
+ t = Object.assign({}, M, t);
257
+ var i = t.Canvas ? new t.Canvas() : window.document.createElement("canvas"), n = t.Canvas ? t.Canvas.Image : window.Image;
258
+ t.Canvas && (t.quality *= 100);
259
+ var o = s.map(function(a) {
260
+ return new Promise(function(d, h) {
261
+ a.constructor.name !== "Object" && (a = { src: a });
262
+ var c = new n();
263
+ c.crossOrigin = t.crossOrigin, c.onerror = function() {
264
+ return h(new Error("Couldn't load image"));
265
+ }, c.onload = function() {
266
+ return d(Object.assign({}, a, { img: c }));
267
+ }, c.src = a.src;
268
+ });
269
+ }), r = i.getContext("2d");
270
+ e(Promise.all(o).then(function(a) {
271
+ var d = function(h) {
272
+ return t[h] || Math.max.apply(Math, a.map(function(c) {
273
+ return c.img[h];
274
+ }));
275
+ };
276
+ return i.width = d("width"), i.height = d("height"), a.forEach(function(h) {
277
+ return r.globalAlpha = h.opacity ? h.opacity : 1, r.drawImage(h.img, h.x || 0, h.y || 0);
278
+ }), t.Canvas && t.format === "image/jpeg" ? new Promise(function(h) {
279
+ i.toDataURL(t.format, {
280
+ quality: t.quality,
281
+ progressive: !1
282
+ }, function(c, g) {
283
+ if (c)
284
+ throw c;
285
+ h(g);
286
+ });
287
+ }) : i.toDataURL(t.format, t.quality);
288
+ }));
289
+ });
290
+ };
291
+ const _ = ["image/png", "image/jpeg", "image/svg+xml"], T = (s) => _.includes(s), b = {
292
+ dotSize: (0.5 + 2.5) / 2,
293
+ minWidth: 0.5,
294
+ maxWidth: 2.5,
295
+ throttle: 16,
296
+ minDistance: 5,
297
+ backgroundColor: "rgba(0,0,0,0)",
298
+ penColor: "black",
299
+ velocityFilterWeight: 0.7,
300
+ onBegin: () => {
301
+ },
302
+ onEnd: () => {
303
+ }
304
+ }, C = (s) => JSON.parse(JSON.stringify(s)), A = {
305
+ src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
306
+ x: 0,
307
+ y: 0
308
+ };
309
+ var W = D({
310
+ name: "VueSignaturePad",
311
+ props: {
312
+ width: {
313
+ type: String,
314
+ default: "100%"
315
+ },
316
+ height: {
317
+ type: String,
318
+ default: "100%"
319
+ },
320
+ customStyle: {
321
+ type: Object,
322
+ default: () => ({})
323
+ },
324
+ options: {
325
+ type: Object,
326
+ default: () => ({})
327
+ },
328
+ images: {
329
+ type: Array,
330
+ default: () => []
331
+ },
332
+ scaleToDevicePixelRatio: {
333
+ type: Boolean,
334
+ default: () => !0
335
+ }
336
+ },
337
+ data: () => ({
338
+ signaturePad: {},
339
+ cacheImages: [],
340
+ signatureData: A,
341
+ onResizeHandler: null
342
+ }),
343
+ computed: {
344
+ propsImagesAndCustomImages() {
345
+ const s = C(this.images), t = C(this.cacheImages);
346
+ return [...s, ...t];
347
+ }
348
+ },
349
+ watch: {
350
+ options: function(s) {
351
+ Object.keys(s).forEach((t) => {
352
+ this.signaturePad[t] && (this.signaturePad[t] = s[t]);
353
+ });
354
+ }
355
+ },
356
+ mounted() {
357
+ const {
358
+ options: s
359
+ } = this, t = this.$refs.signaturePadCanvas, e = new w(t, {
360
+ ...b,
361
+ ...s
362
+ });
363
+ this.signaturePad = e, s.resizeHandler && (this.resizeCanvas = s.resizeHandler.bind(this)), this.onResizeHandler = this.resizeCanvas.bind(this), window.addEventListener("resize", this.onResizeHandler, !1), this.resizeCanvas();
364
+ },
365
+ beforeUnmount() {
366
+ this.onResizeHandler && window.removeEventListener("resize", this.onResizeHandler, !1);
367
+ },
368
+ methods: {
369
+ resizeCanvas() {
370
+ const s = this.$refs.signaturePadCanvas, t = this.signaturePad.toData(), e = this.scaleToDevicePixelRatio ? Math.max(window.devicePixelRatio || 1, 1) : 1;
371
+ s.width = s.offsetWidth * e, s.height = s.offsetHeight * e, s.getContext("2d").scale(e, e), this.signaturePad.clear(), this.signatureData = A, this.signaturePad.fromData(t);
372
+ },
373
+ saveSignature() {
374
+ let s = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _[0], t = arguments.length > 1 ? arguments[1] : void 0;
375
+ const {
376
+ signaturePad: e
377
+ } = this, i = {
378
+ isEmpty: !1,
379
+ data: void 0
380
+ };
381
+ if (!T(s)) {
382
+ const n = _.join(", ");
383
+ throw new Error(`The Image type is incorrect! We are support ${n} types.`);
384
+ }
385
+ return e.isEmpty() ? {
386
+ ...i,
387
+ isEmpty: !0
388
+ } : (this.signatureData = e.toDataURL(s, t), {
389
+ ...i,
390
+ data: this.signatureData
391
+ });
392
+ },
393
+ undoSignature() {
394
+ const {
395
+ signaturePad: s
396
+ } = this, t = s.toData();
397
+ if (t)
398
+ return s.fromData(t.slice(0, -1));
399
+ },
400
+ mergeImageAndSignature(s) {
401
+ return this.signatureData = s, E([...this.images, ...this.cacheImages, this.signatureData]);
402
+ },
403
+ addImages() {
404
+ let s = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
405
+ return this.cacheImages = [...this.cacheImages, ...s], E([...this.images, ...this.cacheImages, this.signatureData]);
406
+ },
407
+ fromDataURL(s) {
408
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, e = arguments.length > 2 ? arguments[2] : void 0;
409
+ return this.signaturePad.fromDataURL(s, t, e);
410
+ },
411
+ fromData(s) {
412
+ return this.signaturePad.fromData(s);
413
+ },
414
+ toData() {
415
+ return this.signaturePad.toData();
416
+ },
417
+ lockSignaturePad() {
418
+ return this.signaturePad.off();
419
+ },
420
+ openSignaturePad() {
421
+ return this.signaturePad.on();
422
+ },
423
+ isEmpty() {
424
+ return this.signaturePad.isEmpty();
425
+ },
426
+ getPropImagesAndCacheImages() {
427
+ return this.propsImagesAndCustomImages;
428
+ },
429
+ clearCacheImages() {
430
+ return this.cacheImages = [], this.cacheImages;
431
+ },
432
+ clearSignature() {
433
+ return this.signaturePad.clear();
434
+ }
435
+ },
436
+ render() {
437
+ const {
438
+ width: s,
439
+ height: t,
440
+ customStyle: e
441
+ } = this;
442
+ return P("div", {
443
+ style: {
444
+ width: s,
445
+ height: t,
446
+ ...e
447
+ }
448
+ }, [P("canvas", {
449
+ style: {
450
+ width: s,
451
+ height: t
452
+ },
453
+ ref: "signaturePadCanvas"
454
+ })]);
455
+ }
456
+ });
457
+ W.__file = "src/components/VueSignaturePad.vue";
458
+ export {
459
+ W as s
460
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedmepos/mf-payment",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"