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