@verbb/formie-vue 1.0.0 → 1.0.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/CHANGELOG.md +18 -0
- package/dist/index.js +1331 -1216
- package/dist/signature_pad-CKGlHEaq.js +464 -0
- package/package.json +5 -5
- package/dist/signature_pad-69C-Dgt3.js +0 -389
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/signature_pad/dist/signature_pad.js
|
|
2
|
-
var e = class {
|
|
3
|
-
x;
|
|
4
|
-
y;
|
|
5
|
-
pressure;
|
|
6
|
-
time;
|
|
7
|
-
constructor(e, t, n, r) {
|
|
8
|
-
if (isNaN(e) || isNaN(t)) throw Error(`Point is invalid: (${e}, ${t})`);
|
|
9
|
-
this.x = +e, this.y = +t, this.pressure = n || 0, this.time = r || Date.now();
|
|
10
|
-
}
|
|
11
|
-
distanceTo(e) {
|
|
12
|
-
return Math.sqrt((this.x - e.x) ** 2 + (this.y - e.y) ** 2);
|
|
13
|
-
}
|
|
14
|
-
equals(e) {
|
|
15
|
-
return this.x === e.x && this.y === e.y && this.pressure === e.pressure && this.time === e.time;
|
|
16
|
-
}
|
|
17
|
-
velocityFrom(e) {
|
|
18
|
-
return this.time === e.time ? 0 : this.distanceTo(e) / (this.time - e.time);
|
|
19
|
-
}
|
|
20
|
-
}, t = class t {
|
|
21
|
-
constructor(e, t, n, r, i, a) {
|
|
22
|
-
this.startPoint = e, this.control2 = t, this.control1 = n, this.endPoint = r, this.startWidth = i, this.endWidth = a;
|
|
23
|
-
}
|
|
24
|
-
static fromPoints(e, n) {
|
|
25
|
-
let r = this.calculateControlPoints(e[0], e[1], e[2]).c2, i = this.calculateControlPoints(e[1], e[2], e[3]).c1;
|
|
26
|
-
return new t(e[1], r, i, e[2], n.start, n.end);
|
|
27
|
-
}
|
|
28
|
-
static calculateControlPoints(t, n, r) {
|
|
29
|
-
let i = t.x - n.x, a = t.y - n.y, o = n.x - r.x, s = n.y - r.y, c = {
|
|
30
|
-
x: (t.x + n.x) / 2,
|
|
31
|
-
y: (t.y + n.y) / 2
|
|
32
|
-
}, l = {
|
|
33
|
-
x: (n.x + r.x) / 2,
|
|
34
|
-
y: (n.y + r.y) / 2
|
|
35
|
-
}, u = Math.sqrt(i * i + a * a), d = Math.sqrt(o * o + s * s), f = c.x - l.x, p = c.y - l.y, m = u + d == 0 ? 0 : d / (u + d), h = {
|
|
36
|
-
x: l.x + f * m,
|
|
37
|
-
y: l.y + p * m
|
|
38
|
-
}, g = n.x - h.x, _ = n.y - h.y;
|
|
39
|
-
return {
|
|
40
|
-
c1: new e(c.x + g, c.y + _),
|
|
41
|
-
c2: new e(l.x + g, l.y + _)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
length() {
|
|
45
|
-
let e = 0, t, n;
|
|
46
|
-
for (let r = 0; r <= 10; r += 1) {
|
|
47
|
-
let i = r / 10, a = this.point(i, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x), o = this.point(i, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
|
|
48
|
-
if (r > 0) {
|
|
49
|
-
let r = a - t, i = o - n;
|
|
50
|
-
e += Math.sqrt(r * r + i * i);
|
|
51
|
-
}
|
|
52
|
-
t = a, n = o;
|
|
53
|
-
}
|
|
54
|
-
return e;
|
|
55
|
-
}
|
|
56
|
-
point(e, t, n, r, i) {
|
|
57
|
-
return t * (1 - e) * (1 - e) * (1 - e) + 3 * n * (1 - e) * (1 - e) * e + 3 * r * (1 - e) * e * e + i * e * e * e;
|
|
58
|
-
}
|
|
59
|
-
}, n = class {
|
|
60
|
-
_et;
|
|
61
|
-
constructor() {
|
|
62
|
-
try {
|
|
63
|
-
this._et = new EventTarget();
|
|
64
|
-
} catch {
|
|
65
|
-
this._et = document;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
addEventListener(e, t, n) {
|
|
69
|
-
this._et.addEventListener(e, t, n);
|
|
70
|
-
}
|
|
71
|
-
dispatchEvent(e) {
|
|
72
|
-
return this._et.dispatchEvent(e);
|
|
73
|
-
}
|
|
74
|
-
removeEventListener(e, t, n) {
|
|
75
|
-
this._et.removeEventListener(e, t, n);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
function r(e, t = 250) {
|
|
79
|
-
let n = 0, r = null, i, a, o, s = () => {
|
|
80
|
-
n = Date.now(), r = null, i = e.apply(a, o), r || (a = null, o = []);
|
|
81
|
-
};
|
|
82
|
-
return function(...c) {
|
|
83
|
-
let l = Date.now(), u = t - (l - n);
|
|
84
|
-
return a = this, o = c, u <= 0 || u > t ? (r &&= (clearTimeout(r), null), n = l, i = e.apply(a, o), r || (a = null, o = [])) : r ||= window.setTimeout(s, u), i;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
var i = class i extends n {
|
|
88
|
-
constructor(e, t = {}) {
|
|
89
|
-
super(), this.canvas = e, this.velocityFilterWeight = t.velocityFilterWeight || .7, this.minWidth = t.minWidth || .5, this.maxWidth = t.maxWidth || 2.5, this.throttle = t.throttle ?? 16, this.minDistance = t.minDistance ?? 5, this.dotSize = t.dotSize || 0, this.penColor = t.penColor || "black", this.backgroundColor = t.backgroundColor || "rgba(0,0,0,0)", this.compositeOperation = t.compositeOperation || "source-over", this.canvasContextOptions = t.canvasContextOptions ?? {}, this._strokeMoveUpdate = this.throttle ? r(i.prototype._strokeUpdate, this.throttle) : i.prototype._strokeUpdate, this._handleMouseDown = this._handleMouseDown.bind(this), this._handleMouseMove = this._handleMouseMove.bind(this), this._handleMouseUp = this._handleMouseUp.bind(this), this._handleTouchStart = this._handleTouchStart.bind(this), this._handleTouchMove = this._handleTouchMove.bind(this), this._handleTouchEnd = this._handleTouchEnd.bind(this), this._handlePointerDown = this._handlePointerDown.bind(this), this._handlePointerMove = this._handlePointerMove.bind(this), this._handlePointerUp = this._handlePointerUp.bind(this), this._handlePointerCancel = this._handlePointerCancel.bind(this), this._handleTouchCancel = this._handleTouchCancel.bind(this), this._ctx = e.getContext("2d", this.canvasContextOptions), this.clear(), this.on();
|
|
90
|
-
}
|
|
91
|
-
dotSize;
|
|
92
|
-
minWidth;
|
|
93
|
-
maxWidth;
|
|
94
|
-
penColor;
|
|
95
|
-
minDistance;
|
|
96
|
-
velocityFilterWeight;
|
|
97
|
-
compositeOperation;
|
|
98
|
-
backgroundColor;
|
|
99
|
-
throttle;
|
|
100
|
-
canvasContextOptions;
|
|
101
|
-
_ctx;
|
|
102
|
-
_drawingStroke = !1;
|
|
103
|
-
_isEmpty = !0;
|
|
104
|
-
_dataUrl;
|
|
105
|
-
_dataUrlOptions;
|
|
106
|
-
_lastPoints = [];
|
|
107
|
-
_data = [];
|
|
108
|
-
_lastVelocity = 0;
|
|
109
|
-
_lastWidth = 0;
|
|
110
|
-
_strokeMoveUpdate;
|
|
111
|
-
_strokePointerId;
|
|
112
|
-
clear() {
|
|
113
|
-
let { _ctx: e, canvas: t } = this;
|
|
114
|
-
e.fillStyle = this.backgroundColor, e.clearRect(0, 0, t.width, t.height), e.fillRect(0, 0, t.width, t.height), this._data = [], this._reset(this._getPointGroupOptions()), this._isEmpty = !0, this._dataUrl = void 0, this._dataUrlOptions = void 0, this._strokePointerId = void 0;
|
|
115
|
-
}
|
|
116
|
-
redraw() {
|
|
117
|
-
let e = this._data, t = this._dataUrl, n = this._dataUrlOptions;
|
|
118
|
-
this.clear(), t && this.fromDataURL(t, n), this.fromData(e, { clear: !1 });
|
|
119
|
-
}
|
|
120
|
-
fromDataURL(e, t = {}) {
|
|
121
|
-
return new Promise((n, r) => {
|
|
122
|
-
let i = new Image(), a = t.ratio || window.devicePixelRatio || 1, o = t.width || this.canvas.width / a, s = t.height || this.canvas.height / a, c = t.xOffset || 0, l = t.yOffset || 0;
|
|
123
|
-
this._reset(this._getPointGroupOptions()), i.onload = () => {
|
|
124
|
-
this._ctx.drawImage(i, c, l, o, s), n();
|
|
125
|
-
}, i.onerror = (e) => {
|
|
126
|
-
r(e);
|
|
127
|
-
}, i.crossOrigin = "anonymous", i.src = e, this._isEmpty = !1, this._dataUrl = e, this._dataUrlOptions = { ...t };
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
toDataURL(e = "image/png", t) {
|
|
131
|
-
switch (e) {
|
|
132
|
-
case "image/svg+xml": return typeof t != "object" && (t = void 0), `data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;
|
|
133
|
-
default: return typeof t != "number" && (t = void 0), this.canvas.toDataURL(e, t);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
on() {
|
|
137
|
-
this.canvas.style.touchAction = "none", this.canvas.style.msTouchAction = "none", this.canvas.style.userSelect = "none", this.canvas.style.webkitUserSelect = "none";
|
|
138
|
-
let e = /Macintosh/.test(navigator.userAgent) && "ontouchstart" in document;
|
|
139
|
-
window.PointerEvent && !e ? this._handlePointerEvents() : (this._handleMouseEvents(), "ontouchstart" in window && this._handleTouchEvents());
|
|
140
|
-
}
|
|
141
|
-
off() {
|
|
142
|
-
this.canvas.style.touchAction = "auto", this.canvas.style.msTouchAction = "auto", this.canvas.style.userSelect = "auto", this.canvas.style.webkitUserSelect = "auto", this.canvas.removeEventListener("pointerdown", this._handlePointerDown), this.canvas.removeEventListener("mousedown", this._handleMouseDown), this.canvas.removeEventListener("touchstart", this._handleTouchStart), this._removeMoveUpEventListeners();
|
|
143
|
-
}
|
|
144
|
-
_getListenerFunctions() {
|
|
145
|
-
let e = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
|
|
146
|
-
return {
|
|
147
|
-
addEventListener: e.addEventListener.bind(e),
|
|
148
|
-
removeEventListener: e.removeEventListener.bind(e)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
_removeMoveUpEventListeners() {
|
|
152
|
-
let { removeEventListener: e } = this._getListenerFunctions();
|
|
153
|
-
e("pointermove", this._handlePointerMove), e("pointerup", this._handlePointerUp), e("pointercancel", this._handlePointerCancel), e("mousemove", this._handleMouseMove), e("mouseup", this._handleMouseUp), e("touchmove", this._handleTouchMove), e("touchend", this._handleTouchEnd), e("touchcancel", this._handleTouchCancel);
|
|
154
|
-
}
|
|
155
|
-
isEmpty() {
|
|
156
|
-
return this._isEmpty;
|
|
157
|
-
}
|
|
158
|
-
fromData(e, { clear: t = !0 } = {}) {
|
|
159
|
-
t && this.clear(), this._fromData(e, this._drawCurve.bind(this), this._drawDot.bind(this)), this._data = this._data.concat(e);
|
|
160
|
-
}
|
|
161
|
-
toData() {
|
|
162
|
-
return this._data;
|
|
163
|
-
}
|
|
164
|
-
_isLeftButtonPressed(e, t) {
|
|
165
|
-
return t ? e.buttons === 1 : (e.buttons & 1) == 1;
|
|
166
|
-
}
|
|
167
|
-
_pointerEventToSignatureEvent(e) {
|
|
168
|
-
return {
|
|
169
|
-
event: e,
|
|
170
|
-
type: e.type,
|
|
171
|
-
x: e.clientX,
|
|
172
|
-
y: e.clientY,
|
|
173
|
-
pressure: "pressure" in e ? e.pressure : 0
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
_touchEventToSignatureEvent(e) {
|
|
177
|
-
let t = e.changedTouches[0];
|
|
178
|
-
return {
|
|
179
|
-
event: e,
|
|
180
|
-
type: e.type,
|
|
181
|
-
x: t.clientX,
|
|
182
|
-
y: t.clientY,
|
|
183
|
-
pressure: t.force
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
_handleMouseDown(e) {
|
|
187
|
-
!this._isLeftButtonPressed(e, !0) || this._drawingStroke || this._strokeBegin(this._pointerEventToSignatureEvent(e));
|
|
188
|
-
}
|
|
189
|
-
_handleMouseMove(e) {
|
|
190
|
-
if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
|
|
191
|
-
this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e));
|
|
195
|
-
}
|
|
196
|
-
_handleMouseUp(e) {
|
|
197
|
-
this._isLeftButtonPressed(e) || this._strokeEnd(this._pointerEventToSignatureEvent(e));
|
|
198
|
-
}
|
|
199
|
-
_handleTouchStart(e) {
|
|
200
|
-
e.targetTouches.length !== 1 || this._drawingStroke || (e.cancelable && e.preventDefault(), this._strokeBegin(this._touchEventToSignatureEvent(e)));
|
|
201
|
-
}
|
|
202
|
-
_handleTouchMove(e) {
|
|
203
|
-
if (e.targetTouches.length === 1) {
|
|
204
|
-
if (e.cancelable && e.preventDefault(), !this._drawingStroke) {
|
|
205
|
-
this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this._strokeMoveUpdate(this._touchEventToSignatureEvent(e));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
_handleTouchEnd(e) {
|
|
212
|
-
e.targetTouches.length === 0 && (e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e)));
|
|
213
|
-
}
|
|
214
|
-
_handlePointerCancel(e) {
|
|
215
|
-
this._allowPointerId(e) && (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e), !1));
|
|
216
|
-
}
|
|
217
|
-
_handleTouchCancel(e) {
|
|
218
|
-
e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
|
|
219
|
-
}
|
|
220
|
-
_getPointerId(e) {
|
|
221
|
-
return e.persistentDeviceId || e.pointerId;
|
|
222
|
-
}
|
|
223
|
-
_allowPointerId(e, t = !1) {
|
|
224
|
-
return this._strokePointerId === void 0 ? t : this._getPointerId(e) === this._strokePointerId;
|
|
225
|
-
}
|
|
226
|
-
_handlePointerDown(e) {
|
|
227
|
-
this._drawingStroke || !this._isLeftButtonPressed(e) || !this._allowPointerId(e, !0) || (this._strokePointerId = this._getPointerId(e), e.preventDefault(), this._strokeBegin(this._pointerEventToSignatureEvent(e)));
|
|
228
|
-
}
|
|
229
|
-
_handlePointerMove(e) {
|
|
230
|
-
if (this._allowPointerId(e)) {
|
|
231
|
-
if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
|
|
232
|
-
this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
e.preventDefault(), this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
_handlePointerUp(e) {
|
|
239
|
-
this._isLeftButtonPressed(e) || !this._allowPointerId(e) || (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e)));
|
|
240
|
-
}
|
|
241
|
-
_getPointGroupOptions(e) {
|
|
242
|
-
return {
|
|
243
|
-
penColor: e && "penColor" in e ? e.penColor : this.penColor,
|
|
244
|
-
dotSize: e && "dotSize" in e ? e.dotSize : this.dotSize,
|
|
245
|
-
minWidth: e && "minWidth" in e ? e.minWidth : this.minWidth,
|
|
246
|
-
maxWidth: e && "maxWidth" in e ? e.maxWidth : this.maxWidth,
|
|
247
|
-
velocityFilterWeight: e && "velocityFilterWeight" in e ? e.velocityFilterWeight : this.velocityFilterWeight,
|
|
248
|
-
compositeOperation: e && "compositeOperation" in e ? e.compositeOperation : this.compositeOperation
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
_strokeBegin(e) {
|
|
252
|
-
if (!this.dispatchEvent(new CustomEvent("beginStroke", {
|
|
253
|
-
detail: e,
|
|
254
|
-
cancelable: !0
|
|
255
|
-
}))) return;
|
|
256
|
-
let { addEventListener: t } = this._getListenerFunctions();
|
|
257
|
-
switch (e.event.type) {
|
|
258
|
-
case "mousedown":
|
|
259
|
-
t("mousemove", this._handleMouseMove, { passive: !1 }), t("mouseup", this._handleMouseUp, { passive: !1 });
|
|
260
|
-
break;
|
|
261
|
-
case "touchstart":
|
|
262
|
-
t("touchmove", this._handleTouchMove, { passive: !1 }), t("touchend", this._handleTouchEnd, { passive: !1 }), t("touchcancel", this._handleTouchCancel, { passive: !1 });
|
|
263
|
-
break;
|
|
264
|
-
case "pointerdown":
|
|
265
|
-
t("pointermove", this._handlePointerMove, { passive: !1 }), t("pointerup", this._handlePointerUp, { passive: !1 }), t("pointercancel", this._handlePointerCancel, { passive: !1 });
|
|
266
|
-
break;
|
|
267
|
-
default:
|
|
268
|
-
}
|
|
269
|
-
this._drawingStroke = !0;
|
|
270
|
-
let n = this._getPointGroupOptions(), r = {
|
|
271
|
-
...n,
|
|
272
|
-
points: []
|
|
273
|
-
};
|
|
274
|
-
this._data.push(r), this._reset(n), this._strokeUpdate(e);
|
|
275
|
-
}
|
|
276
|
-
_strokeUpdate(e) {
|
|
277
|
-
if (!this._drawingStroke) return;
|
|
278
|
-
if (this._data.length === 0) {
|
|
279
|
-
this._strokeBegin(e);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail: e }));
|
|
283
|
-
let t = this._createPoint(e.x, e.y, e.pressure), n = this._data[this._data.length - 1], r = n.points, i = r.length > 0 && r[r.length - 1], a = i ? t.distanceTo(i) <= this.minDistance : !1, o = this._getPointGroupOptions(n);
|
|
284
|
-
if (!i || !(i && a)) {
|
|
285
|
-
let e = this._addPoint(t, o);
|
|
286
|
-
i ? e && this._drawCurve(e, o) : this._drawDot(t, o), r.push({
|
|
287
|
-
time: t.time,
|
|
288
|
-
x: t.x,
|
|
289
|
-
y: t.y,
|
|
290
|
-
pressure: t.pressure
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail: e }));
|
|
294
|
-
}
|
|
295
|
-
_strokeEnd(e, t = !0) {
|
|
296
|
-
this._removeMoveUpEventListeners(), this._drawingStroke && (t && this._strokeUpdate(e), this._drawingStroke = !1, this._strokePointerId = void 0, this.dispatchEvent(new CustomEvent("endStroke", { detail: e })));
|
|
297
|
-
}
|
|
298
|
-
_handlePointerEvents() {
|
|
299
|
-
this._drawingStroke = !1, this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: !1 });
|
|
300
|
-
}
|
|
301
|
-
_handleMouseEvents() {
|
|
302
|
-
this._drawingStroke = !1, this.canvas.addEventListener("mousedown", this._handleMouseDown, { passive: !1 });
|
|
303
|
-
}
|
|
304
|
-
_handleTouchEvents() {
|
|
305
|
-
this.canvas.addEventListener("touchstart", this._handleTouchStart, { passive: !1 });
|
|
306
|
-
}
|
|
307
|
-
_reset(e) {
|
|
308
|
-
this._lastPoints = [], this._lastVelocity = 0, this._lastWidth = (e.minWidth + e.maxWidth) / 2, this._ctx.fillStyle = e.penColor, this._ctx.globalCompositeOperation = e.compositeOperation;
|
|
309
|
-
}
|
|
310
|
-
_createPoint(t, n, r) {
|
|
311
|
-
let i = this.canvas.getBoundingClientRect();
|
|
312
|
-
return new e(t - i.left, n - i.top, r, (/* @__PURE__ */ new Date()).getTime());
|
|
313
|
-
}
|
|
314
|
-
_addPoint(e, n) {
|
|
315
|
-
let { _lastPoints: r } = this;
|
|
316
|
-
if (r.push(e), r.length > 2) {
|
|
317
|
-
r.length === 3 && r.unshift(r[0]);
|
|
318
|
-
let e = this._calculateCurveWidths(r[1], r[2], n), i = t.fromPoints(r, e);
|
|
319
|
-
return r.shift(), i;
|
|
320
|
-
}
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
_calculateCurveWidths(e, t, n) {
|
|
324
|
-
let r = n.velocityFilterWeight * t.velocityFrom(e) + (1 - n.velocityFilterWeight) * this._lastVelocity, i = this._strokeWidth(r, n), a = {
|
|
325
|
-
end: i,
|
|
326
|
-
start: this._lastWidth
|
|
327
|
-
};
|
|
328
|
-
return this._lastVelocity = r, this._lastWidth = i, a;
|
|
329
|
-
}
|
|
330
|
-
_strokeWidth(e, t) {
|
|
331
|
-
return Math.max(t.maxWidth / (e + 1), t.minWidth);
|
|
332
|
-
}
|
|
333
|
-
_drawCurveSegment(e, t, n) {
|
|
334
|
-
let r = this._ctx;
|
|
335
|
-
r.moveTo(e, t), r.arc(e, t, n, 0, 2 * Math.PI, !1), this._isEmpty = !1;
|
|
336
|
-
}
|
|
337
|
-
_drawCurve(e, t) {
|
|
338
|
-
let n = this._ctx, r = e.endWidth - e.startWidth, i = Math.ceil(e.length()) * 2;
|
|
339
|
-
n.beginPath(), n.fillStyle = t.penColor;
|
|
340
|
-
for (let n = 0; n < i; n += 1) {
|
|
341
|
-
let a = n / i, o = a * a, s = o * a, c = 1 - a, l = c * c, u = l * c, d = u * e.startPoint.x;
|
|
342
|
-
d += 3 * l * a * e.control1.x, d += 3 * c * o * e.control2.x, d += s * e.endPoint.x;
|
|
343
|
-
let f = u * e.startPoint.y;
|
|
344
|
-
f += 3 * l * a * e.control1.y, f += 3 * c * o * e.control2.y, f += s * e.endPoint.y;
|
|
345
|
-
let p = Math.min(e.startWidth + s * r, t.maxWidth);
|
|
346
|
-
this._drawCurveSegment(d, f, p);
|
|
347
|
-
}
|
|
348
|
-
n.closePath(), n.fill();
|
|
349
|
-
}
|
|
350
|
-
_drawDot(e, t) {
|
|
351
|
-
let n = this._ctx, r = t.dotSize > 0 ? t.dotSize : (t.minWidth + t.maxWidth) / 2;
|
|
352
|
-
n.beginPath(), this._drawCurveSegment(e.x, e.y, r), n.closePath(), n.fillStyle = t.penColor, n.fill();
|
|
353
|
-
}
|
|
354
|
-
_fromData(t, n, r) {
|
|
355
|
-
for (let i of t) {
|
|
356
|
-
let { points: t } = i, a = this._getPointGroupOptions(i);
|
|
357
|
-
if (t.length > 1) for (let r = 0; r < t.length; r += 1) {
|
|
358
|
-
let i = t[r], o = new e(i.x, i.y, i.pressure, i.time);
|
|
359
|
-
r === 0 && this._reset(a);
|
|
360
|
-
let s = this._addPoint(o, a);
|
|
361
|
-
s && n(s, a);
|
|
362
|
-
}
|
|
363
|
-
else this._reset(a), r(t[0], a);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
toSVG({ includeBackgroundColor: e = !1, includeDataUrl: t = !1 } = {}) {
|
|
367
|
-
let n = this._data, r = Math.max(window.devicePixelRatio || 1, 1), i = this.canvas.width / r, a = this.canvas.height / r, o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
368
|
-
if (o.setAttribute("xmlns", "http://www.w3.org/2000/svg"), o.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"), o.setAttribute("viewBox", `0 0 ${i} ${a}`), o.setAttribute("width", i.toString()), o.setAttribute("height", a.toString()), e && this.backgroundColor) {
|
|
369
|
-
let e = document.createElement("rect");
|
|
370
|
-
e.setAttribute("width", "100%"), e.setAttribute("height", "100%"), e.setAttribute("fill", this.backgroundColor), o.appendChild(e);
|
|
371
|
-
}
|
|
372
|
-
if (t && this._dataUrl) {
|
|
373
|
-
let e = this._dataUrlOptions?.ratio || window.devicePixelRatio || 1, t = this._dataUrlOptions?.width || this.canvas.width / e, n = this._dataUrlOptions?.height || this.canvas.height / e, r = this._dataUrlOptions?.xOffset || 0, i = this._dataUrlOptions?.yOffset || 0, a = document.createElement("image");
|
|
374
|
-
a.setAttribute("x", r.toString()), a.setAttribute("y", i.toString()), a.setAttribute("width", t.toString()), a.setAttribute("height", n.toString()), a.setAttribute("preserveAspectRatio", "none"), a.setAttribute("href", this._dataUrl), o.appendChild(a);
|
|
375
|
-
}
|
|
376
|
-
return this._fromData(n, (e, { penColor: t }) => {
|
|
377
|
-
let n = document.createElement("path");
|
|
378
|
-
if (!isNaN(e.control1.x) && !isNaN(e.control1.y) && !isNaN(e.control2.x) && !isNaN(e.control2.y)) {
|
|
379
|
-
let r = `M ${e.startPoint.x.toFixed(3)},${e.startPoint.y.toFixed(3)} C ${e.control1.x.toFixed(3)},${e.control1.y.toFixed(3)} ${e.control2.x.toFixed(3)},${e.control2.y.toFixed(3)} ${e.endPoint.x.toFixed(3)},${e.endPoint.y.toFixed(3)}`;
|
|
380
|
-
n.setAttribute("d", r), n.setAttribute("stroke-width", (e.endWidth * 2.25).toFixed(3)), n.setAttribute("stroke", t), n.setAttribute("fill", "none"), n.setAttribute("stroke-linecap", "round"), o.appendChild(n);
|
|
381
|
-
}
|
|
382
|
-
}, (e, { penColor: t, dotSize: n, minWidth: r, maxWidth: i }) => {
|
|
383
|
-
let a = document.createElement("circle"), s = n > 0 ? n : (r + i) / 2;
|
|
384
|
-
a.setAttribute("r", s.toString()), a.setAttribute("cx", e.x.toString()), a.setAttribute("cy", e.y.toString()), a.setAttribute("fill", t), o.appendChild(a);
|
|
385
|
-
}), o.outerHTML;
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
//#endregion
|
|
389
|
-
export { i as default };
|