@kdcloudjs/kdesign 1.7.58 → 1.7.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/kdesign-complete.less +126 -1
  3. package/dist/kdesign.css +212 -1
  4. package/dist/kdesign.css.map +1 -1
  5. package/dist/kdesign.js +2217 -181
  6. package/dist/kdesign.js.map +1 -1
  7. package/dist/kdesign.min.css +2 -2
  8. package/dist/kdesign.min.js +16 -12
  9. package/dist/kdesign.min.js.map +1 -1
  10. package/es/_utils/domUtil.d.ts +2 -0
  11. package/es/_utils/domUtil.js +15 -0
  12. package/es/cascader/cascader.js +41 -10
  13. package/es/config-provider/compDefaultProps.d.ts +7 -0
  14. package/es/config-provider/compDefaultProps.js +7 -0
  15. package/es/date-picker/date-picker.js +19 -17
  16. package/es/date-picker/hooks/use-range-view-dates.js +8 -2
  17. package/es/date-picker/panel/time/time.js +18 -3
  18. package/es/date-picker/range-picker.js +18 -28
  19. package/es/index.d.ts +1 -0
  20. package/es/index.js +2 -1
  21. package/es/locale/locale.d.ts +5 -0
  22. package/es/locale/zh-CN.d.ts +5 -0
  23. package/es/locale/zh-CN.js +6 -1
  24. package/es/signature/drawingBoard.d.ts +15 -0
  25. package/es/signature/drawingBoard.js +163 -0
  26. package/es/signature/index.d.ts +3 -0
  27. package/es/signature/index.js +3 -0
  28. package/es/signature/signature.d.ts +32 -0
  29. package/es/signature/signature.js +268 -0
  30. package/es/signature/style/css.js +2 -0
  31. package/es/signature/style/index.css +210 -0
  32. package/es/signature/style/index.d.ts +2 -0
  33. package/es/signature/style/index.js +2 -0
  34. package/es/signature/style/index.less +95 -0
  35. package/es/signature/style/mixin.less +6 -0
  36. package/es/signature/style/token.less +22 -0
  37. package/es/signature/utils/signature_pad.d.ts +106 -0
  38. package/es/signature/utils/signature_pad.js +690 -0
  39. package/es/style/themes/default.less +1 -1
  40. package/es/tree-select/tree-select.js +1 -1
  41. package/lib/_utils/domUtil.d.ts +2 -0
  42. package/lib/_utils/domUtil.js +23 -0
  43. package/lib/cascader/cascader.js +41 -10
  44. package/lib/config-provider/compDefaultProps.d.ts +7 -0
  45. package/lib/config-provider/compDefaultProps.js +7 -0
  46. package/lib/date-picker/date-picker.js +18 -16
  47. package/lib/date-picker/hooks/use-range-view-dates.js +7 -1
  48. package/lib/date-picker/panel/time/time.js +17 -2
  49. package/lib/date-picker/range-picker.js +18 -28
  50. package/lib/index.d.ts +1 -0
  51. package/lib/index.js +7 -0
  52. package/lib/locale/locale.d.ts +5 -0
  53. package/lib/locale/zh-CN.d.ts +5 -0
  54. package/lib/locale/zh-CN.js +6 -1
  55. package/lib/signature/drawingBoard.d.ts +15 -0
  56. package/lib/signature/drawingBoard.js +176 -0
  57. package/lib/signature/index.d.ts +3 -0
  58. package/lib/signature/index.js +27 -0
  59. package/lib/signature/signature.d.ts +32 -0
  60. package/lib/signature/signature.js +282 -0
  61. package/lib/signature/style/css.js +4 -0
  62. package/lib/signature/style/index.css +210 -0
  63. package/lib/signature/style/index.d.ts +2 -0
  64. package/lib/signature/style/index.js +4 -0
  65. package/lib/signature/style/index.less +95 -0
  66. package/lib/signature/style/mixin.less +6 -0
  67. package/lib/signature/style/token.less +22 -0
  68. package/lib/signature/utils/signature_pad.d.ts +106 -0
  69. package/lib/signature/utils/signature_pad.js +697 -0
  70. package/lib/style/components.less +1 -0
  71. package/lib/style/themes/default.less +1 -1
  72. package/lib/tree-select/tree-select.js +1 -1
  73. package/package.json +3 -2
@@ -0,0 +1,697 @@
1
+ "use strict";
2
+
3
+ var _Reflect$construct = require("@babel/runtime-corejs3/core-js-stable/reflect/construct");
4
+ var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
5
+ var _Array$from = require("@babel/runtime-corejs3/core-js-stable/array/from");
6
+ var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
7
+ var _getIteratorMethod = require("@babel/runtime-corejs3/core-js/get-iterator-method");
8
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.default = void 0;
13
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
14
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
15
+ var _fill = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/fill"));
16
+ var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
17
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/inherits"));
19
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/possibleConstructorReturn"));
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/getPrototypeOf"));
21
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
22
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
23
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && _getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
24
+ function _unsupportedIterableToArray(o, minLen) { var _context9; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context9 = Object.prototype.toString.call(o)).call(_context9, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
26
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
27
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
28
+ /*!
29
+ * Signature Pad v4.1.7 | https://github.com/szimek/signature_pad
30
+ * (c) 2023 Szymon Nowak | Released under the MIT license
31
+ */
32
+ var Point = /*#__PURE__*/function () {
33
+ function Point(x, y, pressure, time) {
34
+ (0, _classCallCheck2.default)(this, Point);
35
+ if (isNaN(x) || isNaN(y)) {
36
+ var _context;
37
+ throw new Error((0, _concat.default)(_context = "Point is invalid: (".concat(x, ", ")).call(_context, y, ")"));
38
+ }
39
+ this.x = +x;
40
+ this.y = +y;
41
+ this.pressure = pressure || 0;
42
+ this.time = time || Date.now();
43
+ }
44
+ (0, _createClass2.default)(Point, [{
45
+ key: "distanceTo",
46
+ value: function distanceTo(start) {
47
+ return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
48
+ }
49
+ }, {
50
+ key: "equals",
51
+ value: function equals(other) {
52
+ return this.x === other.x && this.y === other.y && this.pressure === other.pressure && this.time === other.time;
53
+ }
54
+ }, {
55
+ key: "velocityFrom",
56
+ value: function velocityFrom(start) {
57
+ return this.time !== start.time ? this.distanceTo(start) / (this.time - start.time) : 0;
58
+ }
59
+ }]);
60
+ return Point;
61
+ }();
62
+ var Bezier = /*#__PURE__*/function () {
63
+ function Bezier(startPoint, control2, control1, endPoint, startWidth, endWidth) {
64
+ (0, _classCallCheck2.default)(this, Bezier);
65
+ this.startPoint = startPoint;
66
+ this.control2 = control2;
67
+ this.control1 = control1;
68
+ this.endPoint = endPoint;
69
+ this.startWidth = startWidth;
70
+ this.endWidth = endWidth;
71
+ }
72
+ (0, _createClass2.default)(Bezier, [{
73
+ key: "length",
74
+ value: function length() {
75
+ var steps = 10;
76
+ var length = 0;
77
+ var px;
78
+ var py;
79
+ for (var i = 0; i <= steps; i += 1) {
80
+ var t = i / steps;
81
+ var cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
82
+ var cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
83
+ if (i > 0) {
84
+ var xdiff = cx - px;
85
+ var ydiff = cy - py;
86
+ length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
87
+ }
88
+ px = cx;
89
+ py = cy;
90
+ }
91
+ return length;
92
+ }
93
+ }, {
94
+ key: "point",
95
+ value: function point(t, start, c1, c2, end) {
96
+ return start * (1.0 - t) * (1.0 - t) * (1.0 - t) + 3.0 * c1 * (1.0 - t) * (1.0 - t) * t + 3.0 * c2 * (1.0 - t) * t * t + end * t * t * t;
97
+ }
98
+ }], [{
99
+ key: "fromPoints",
100
+ value: function fromPoints(points, widths) {
101
+ var c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
102
+ var c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
103
+ return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
104
+ }
105
+ }, {
106
+ key: "calculateControlPoints",
107
+ value: function calculateControlPoints(s1, s2, s3) {
108
+ var dx1 = s1.x - s2.x;
109
+ var dy1 = s1.y - s2.y;
110
+ var dx2 = s2.x - s3.x;
111
+ var dy2 = s2.y - s3.y;
112
+ var m1 = {
113
+ x: (s1.x + s2.x) / 2.0,
114
+ y: (s1.y + s2.y) / 2.0
115
+ };
116
+ var m2 = {
117
+ x: (s2.x + s3.x) / 2.0,
118
+ y: (s2.y + s3.y) / 2.0
119
+ };
120
+ var l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
121
+ var l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
122
+ var dxm = m1.x - m2.x;
123
+ var dym = m1.y - m2.y;
124
+ var k = l2 / (l1 + l2);
125
+ var cm = {
126
+ x: m2.x + dxm * k,
127
+ y: m2.y + dym * k
128
+ };
129
+ var tx = s2.x - cm.x;
130
+ var ty = s2.y - cm.y;
131
+ return {
132
+ c1: new Point(m1.x + tx, m1.y + ty),
133
+ c2: new Point(m2.x + tx, m2.y + ty)
134
+ };
135
+ }
136
+ }]);
137
+ return Bezier;
138
+ }();
139
+ var SignatureEventTarget = /*#__PURE__*/function () {
140
+ function SignatureEventTarget() {
141
+ (0, _classCallCheck2.default)(this, SignatureEventTarget);
142
+ try {
143
+ this._et = new EventTarget();
144
+ } catch (error) {
145
+ this._et = document;
146
+ }
147
+ }
148
+ (0, _createClass2.default)(SignatureEventTarget, [{
149
+ key: "addEventListener",
150
+ value: function addEventListener(type, listener) {
151
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
152
+ this._et.addEventListener(type, listener, options);
153
+ }
154
+ }, {
155
+ key: "dispatchEvent",
156
+ value: function dispatchEvent(event) {
157
+ return this._et.dispatchEvent(event);
158
+ }
159
+ }, {
160
+ key: "removeEventListener",
161
+ value: function removeEventListener(type, callback) {
162
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
163
+ this._et.removeEventListener(type, callback, options);
164
+ }
165
+ }]);
166
+ return SignatureEventTarget;
167
+ }();
168
+ function throttle(fn) {
169
+ var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
170
+ var previous = 0;
171
+ var timeout = null;
172
+ var result;
173
+ var storedContext;
174
+ var storedArgs;
175
+ var later = function later() {
176
+ previous = Date.now();
177
+ timeout = null;
178
+ result = fn.apply(storedContext, storedArgs);
179
+ if (!timeout) {
180
+ storedContext = null;
181
+ storedArgs = [];
182
+ }
183
+ };
184
+ return function wrapper() {
185
+ var now = Date.now();
186
+ var remaining = wait - (now - previous);
187
+ storedContext = this;
188
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
189
+ args[_key] = arguments[_key];
190
+ }
191
+ storedArgs = args;
192
+ if (remaining <= 0 || remaining > wait) {
193
+ if (timeout) {
194
+ clearTimeout(timeout);
195
+ timeout = null;
196
+ }
197
+ previous = now;
198
+ result = fn.apply(storedContext, storedArgs);
199
+ if (!timeout) {
200
+ storedContext = null;
201
+ storedArgs = [];
202
+ }
203
+ } else if (!timeout) {
204
+ timeout = window.setTimeout(later, remaining);
205
+ }
206
+ return result;
207
+ };
208
+ }
209
+ var SignaturePad = /*#__PURE__*/function (_SignatureEventTarget) {
210
+ (0, _inherits2.default)(SignaturePad, _SignatureEventTarget);
211
+ var _super = _createSuper(SignaturePad);
212
+ function SignaturePad(canvas) {
213
+ var _this;
214
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
215
+ (0, _classCallCheck2.default)(this, SignaturePad);
216
+ _this = _super.call(this);
217
+ _this.canvas = canvas;
218
+ _this._drawingStroke = false;
219
+ _this._isEmpty = true;
220
+ _this._lastPoints = [];
221
+ _this._data = [];
222
+ _this._lastVelocity = 0;
223
+ _this._lastWidth = 0;
224
+ _this._handleMouseDown = function (event) {
225
+ if (event.buttons === 1) {
226
+ _this._strokeBegin(event);
227
+ }
228
+ };
229
+ _this._handleMouseMove = function (event) {
230
+ _this._strokeMoveUpdate(event);
231
+ };
232
+ _this._handleMouseUp = function (event) {
233
+ if (event.buttons === 1) {
234
+ _this._strokeEnd(event);
235
+ }
236
+ };
237
+ _this._handleTouchStart = function (event) {
238
+ if (event.cancelable) {
239
+ event.preventDefault();
240
+ }
241
+ if (event.targetTouches.length === 1) {
242
+ var touch = event.changedTouches[0];
243
+ _this._strokeBegin(touch);
244
+ }
245
+ };
246
+ _this._handleTouchMove = function (event) {
247
+ if (event.cancelable) {
248
+ event.preventDefault();
249
+ }
250
+ var touch = event.targetTouches[0];
251
+ _this._strokeMoveUpdate(touch);
252
+ };
253
+ _this._handleTouchEnd = function (event) {
254
+ var wasCanvasTouched = event.target === _this.canvas;
255
+ if (wasCanvasTouched) {
256
+ if (event.cancelable) {
257
+ event.preventDefault();
258
+ }
259
+ var touch = event.changedTouches[0];
260
+ _this._strokeEnd(touch);
261
+ }
262
+ };
263
+ _this._handlePointerStart = function (event) {
264
+ event.preventDefault();
265
+ _this._strokeBegin(event);
266
+ };
267
+ _this._handlePointerMove = function (event) {
268
+ _this._strokeMoveUpdate(event);
269
+ };
270
+ _this._handlePointerEnd = function (event) {
271
+ if (_this._drawingStroke) {
272
+ event.preventDefault();
273
+ _this._strokeEnd(event);
274
+ }
275
+ };
276
+ _this.velocityFilterWeight = options.velocityFilterWeight || 0.7;
277
+ _this.minWidth = options.minWidth || 0.5;
278
+ _this.maxWidth = options.maxWidth || 2.5;
279
+ _this.throttle = 'throttle' in options ? options.throttle : 16;
280
+ _this.minDistance = 'minDistance' in options ? options.minDistance : 5;
281
+ _this.dotSize = options.dotSize || 0;
282
+ _this.penColor = options.penColor || 'black';
283
+ _this.backgroundColor = options.backgroundColor || 'rgba(0,0,0,0)';
284
+ _this.compositeOperation = options.compositeOperation || 'source-over';
285
+ _this._strokeMoveUpdate = _this.throttle ? throttle(SignaturePad.prototype._strokeUpdate, _this.throttle) : SignaturePad.prototype._strokeUpdate;
286
+ _this._ctx = canvas.getContext('2d');
287
+ _this.clear();
288
+ _this.on();
289
+ return _this;
290
+ }
291
+ (0, _createClass2.default)(SignaturePad, [{
292
+ key: "clear",
293
+ value: function clear() {
294
+ var ctx = this._ctx,
295
+ canvas = this.canvas;
296
+ ctx.fillStyle = this.backgroundColor;
297
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
298
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
299
+ this._data = [];
300
+ this._reset(this._getPointGroupOptions());
301
+ this._isEmpty = true;
302
+ }
303
+ }, {
304
+ key: "fromDataURL",
305
+ value: function fromDataURL(dataUrl) {
306
+ var _this2 = this;
307
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
308
+ return new _promise.default(function (resolve, reject) {
309
+ var image = new Image();
310
+ var ratio = options.ratio || window.devicePixelRatio || 1;
311
+ var width = options.width || _this2.canvas.width / ratio;
312
+ var height = options.height || _this2.canvas.height / ratio;
313
+ var xOffset = options.xOffset || 0;
314
+ var yOffset = options.yOffset || 0;
315
+ _this2._reset(_this2._getPointGroupOptions());
316
+ image.onload = function () {
317
+ _this2._ctx.drawImage(image, xOffset, yOffset, width, height);
318
+ resolve();
319
+ };
320
+ image.onerror = function (error) {
321
+ reject(error);
322
+ };
323
+ image.crossOrigin = 'anonymous';
324
+ image.src = dataUrl;
325
+ _this2._isEmpty = false;
326
+ });
327
+ }
328
+ }, {
329
+ key: "toDataURL",
330
+ value: function toDataURL() {
331
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'image/png';
332
+ var encoderOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
333
+ switch (type) {
334
+ case 'image/svg+xml':
335
+ if ((0, _typeof2.default)(encoderOptions) !== 'object') {
336
+ encoderOptions = undefined;
337
+ }
338
+ return "data:image/svg+xml;base64,".concat(btoa(this.toSVG(encoderOptions)));
339
+ default:
340
+ if (typeof encoderOptions !== 'number') {
341
+ encoderOptions = undefined;
342
+ }
343
+ return this.canvas.toDataURL(type, encoderOptions);
344
+ }
345
+ }
346
+ }, {
347
+ key: "on",
348
+ value: function on() {
349
+ this.canvas.style.touchAction = 'none';
350
+ this.canvas.style.msTouchAction = 'none';
351
+ this.canvas.style.userSelect = 'none';
352
+ var isIOS = /Macintosh/.test(navigator.userAgent) && 'ontouchstart' in document;
353
+ if (window.PointerEvent && !isIOS) {
354
+ this._handlePointerEvents();
355
+ } else {
356
+ this._handleMouseEvents();
357
+ if ('ontouchstart' in window) {
358
+ this._handleTouchEvents();
359
+ }
360
+ }
361
+ }
362
+ }, {
363
+ key: "off",
364
+ value: function off() {
365
+ this.canvas.style.touchAction = 'auto';
366
+ this.canvas.style.msTouchAction = 'auto';
367
+ this.canvas.style.userSelect = 'auto';
368
+ this.canvas.removeEventListener('pointerdown', this._handlePointerStart);
369
+ this.canvas.removeEventListener('pointermove', this._handlePointerMove);
370
+ this.canvas.ownerDocument.removeEventListener('pointerup', this._handlePointerEnd);
371
+ this.canvas.removeEventListener('mousedown', this._handleMouseDown);
372
+ this.canvas.removeEventListener('mousemove', this._handleMouseMove);
373
+ this.canvas.ownerDocument.removeEventListener('mouseup', this._handleMouseUp);
374
+ this.canvas.removeEventListener('touchstart', this._handleTouchStart);
375
+ this.canvas.removeEventListener('touchmove', this._handleTouchMove);
376
+ this.canvas.removeEventListener('touchend', this._handleTouchEnd);
377
+ }
378
+ }, {
379
+ key: "isEmpty",
380
+ value: function isEmpty() {
381
+ return this._isEmpty;
382
+ }
383
+ }, {
384
+ key: "fromData",
385
+ value: function fromData(pointGroups) {
386
+ var _context2;
387
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
388
+ _ref$clear = _ref.clear,
389
+ clear = _ref$clear === void 0 ? true : _ref$clear;
390
+ if (clear) {
391
+ this.clear();
392
+ }
393
+ this._fromData(pointGroups, this._drawCurve.bind(this), this._drawDot.bind(this));
394
+ this._data = (0, _concat.default)(_context2 = this._data).call(_context2, pointGroups);
395
+ }
396
+ }, {
397
+ key: "toData",
398
+ value: function toData() {
399
+ return this._data;
400
+ }
401
+ }, {
402
+ key: "_getPointGroupOptions",
403
+ value: function _getPointGroupOptions(group) {
404
+ return {
405
+ penColor: group && 'penColor' in group ? group.penColor : this.penColor,
406
+ dotSize: group && 'dotSize' in group ? group.dotSize : this.dotSize,
407
+ minWidth: group && 'minWidth' in group ? group.minWidth : this.minWidth,
408
+ maxWidth: group && 'maxWidth' in group ? group.maxWidth : this.maxWidth,
409
+ velocityFilterWeight: group && 'velocityFilterWeight' in group ? group.velocityFilterWeight : this.velocityFilterWeight,
410
+ compositeOperation: group && 'compositeOperation' in group ? group.compositeOperation : this.compositeOperation
411
+ };
412
+ }
413
+ }, {
414
+ key: "_strokeBegin",
415
+ value: function _strokeBegin(event) {
416
+ // const cancelled = !this.dispatchEvent(new CustomEvent('beginStroke', { detail: event, cancelable: true }));
417
+ var customEvent = document.createEvent('CustomEvent');
418
+ customEvent.initCustomEvent('beginStroke', true, true, event);
419
+ var cancelled = !this.dispatchEvent(customEvent);
420
+ if (cancelled) {
421
+ return;
422
+ }
423
+ this._drawingStroke = true;
424
+ var pointGroupOptions = this._getPointGroupOptions();
425
+ var newPointGroup = (0, _extends2.default)((0, _extends2.default)({}, pointGroupOptions), {
426
+ points: []
427
+ });
428
+ this._data.push(newPointGroup);
429
+ this._reset(pointGroupOptions);
430
+ this._strokeUpdate(event);
431
+ }
432
+ }, {
433
+ key: "_strokeUpdate",
434
+ value: function _strokeUpdate(event) {
435
+ if (!this._drawingStroke) {
436
+ return;
437
+ }
438
+ if (this._data.length === 0) {
439
+ this._strokeBegin(event);
440
+ return;
441
+ }
442
+ // this.dispatchEvent(new CustomEvent('beforeUpdateStroke', { detail: event }));
443
+ var customEvent_one = document.createEvent('CustomEvent');
444
+ customEvent_one.initCustomEvent('beforeUpdateStroke', true, true, event);
445
+ this.dispatchEvent(customEvent_one);
446
+ var x = event.clientX;
447
+ var y = event.clientY;
448
+ var pressure = event.pressure !== undefined ? event.pressure : event.force !== undefined ? event.force : 0;
449
+ var point = this._createPoint(x, y, pressure);
450
+ var lastPointGroup = this._data[this._data.length - 1];
451
+ var lastPoints = lastPointGroup.points;
452
+ var lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
453
+ var isLastPointTooClose = lastPoint ? point.distanceTo(lastPoint) <= this.minDistance : false;
454
+ var pointGroupOptions = this._getPointGroupOptions(lastPointGroup);
455
+ if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
456
+ var curve = this._addPoint(point, pointGroupOptions);
457
+ if (!lastPoint) {
458
+ this._drawDot(point, pointGroupOptions);
459
+ } else if (curve) {
460
+ this._drawCurve(curve, pointGroupOptions);
461
+ }
462
+ lastPoints.push({
463
+ time: point.time,
464
+ x: point.x,
465
+ y: point.y,
466
+ pressure: point.pressure
467
+ });
468
+ }
469
+ // this.dispatchEvent(new CustomEvent('afterUpdateStroke', { detail: event }));
470
+ var customEvent_two = document.createEvent('CustomEvent');
471
+ customEvent_two.initCustomEvent('afterUpdateStroke', true, true, event);
472
+ this.dispatchEvent(customEvent_two);
473
+ }
474
+ }, {
475
+ key: "_strokeEnd",
476
+ value: function _strokeEnd(event) {
477
+ if (!this._drawingStroke) {
478
+ return;
479
+ }
480
+ this._strokeUpdate(event);
481
+ this._drawingStroke = false;
482
+ // this.dispatchEvent(new CustomEvent('endStroke', { detail: event }));
483
+ var customEvent = document.createEvent('CustomEvent');
484
+ customEvent.initCustomEvent('endStroke', true, true, event);
485
+ this.dispatchEvent(customEvent);
486
+ }
487
+ }, {
488
+ key: "_handlePointerEvents",
489
+ value: function _handlePointerEvents() {
490
+ this._drawingStroke = false;
491
+ this.canvas.addEventListener('pointerdown', this._handlePointerStart);
492
+ this.canvas.addEventListener('pointermove', this._handlePointerMove);
493
+ this.canvas.ownerDocument.addEventListener('pointerup', this._handlePointerEnd);
494
+ }
495
+ }, {
496
+ key: "_handleMouseEvents",
497
+ value: function _handleMouseEvents() {
498
+ this._drawingStroke = false;
499
+ this.canvas.addEventListener('mousedown', this._handleMouseDown);
500
+ this.canvas.addEventListener('mousemove', this._handleMouseMove);
501
+ this.canvas.ownerDocument.addEventListener('mouseup', this._handleMouseUp);
502
+ }
503
+ }, {
504
+ key: "_handleTouchEvents",
505
+ value: function _handleTouchEvents() {
506
+ this.canvas.addEventListener('touchstart', this._handleTouchStart);
507
+ this.canvas.addEventListener('touchmove', this._handleTouchMove);
508
+ this.canvas.addEventListener('touchend', this._handleTouchEnd);
509
+ }
510
+ }, {
511
+ key: "_reset",
512
+ value: function _reset(options) {
513
+ this._lastPoints = [];
514
+ this._lastVelocity = 0;
515
+ this._lastWidth = (options.minWidth + options.maxWidth) / 2;
516
+ this._ctx.fillStyle = options.penColor;
517
+ this._ctx.globalCompositeOperation = options.compositeOperation;
518
+ }
519
+ }, {
520
+ key: "_createPoint",
521
+ value: function _createPoint(x, y, pressure) {
522
+ var rect = this.canvas.getBoundingClientRect();
523
+ return new Point(x - rect.left, y - rect.top, pressure, new Date().getTime());
524
+ }
525
+ }, {
526
+ key: "_addPoint",
527
+ value: function _addPoint(point, options) {
528
+ var _lastPoints = this._lastPoints;
529
+ _lastPoints.push(point);
530
+ if (_lastPoints.length > 2) {
531
+ if (_lastPoints.length === 3) {
532
+ _lastPoints.unshift(_lastPoints[0]);
533
+ }
534
+ var widths = this._calculateCurveWidths(_lastPoints[1], _lastPoints[2], options);
535
+ var curve = Bezier.fromPoints(_lastPoints, widths);
536
+ _lastPoints.shift();
537
+ return curve;
538
+ }
539
+ return null;
540
+ }
541
+ }, {
542
+ key: "_calculateCurveWidths",
543
+ value: function _calculateCurveWidths(startPoint, endPoint, options) {
544
+ var velocity = options.velocityFilterWeight * endPoint.velocityFrom(startPoint) + (1 - options.velocityFilterWeight) * this._lastVelocity;
545
+ var newWidth = this._strokeWidth(velocity, options);
546
+ var widths = {
547
+ end: newWidth,
548
+ start: this._lastWidth
549
+ };
550
+ this._lastVelocity = velocity;
551
+ this._lastWidth = newWidth;
552
+ return widths;
553
+ }
554
+ }, {
555
+ key: "_strokeWidth",
556
+ value: function _strokeWidth(velocity, options) {
557
+ return Math.max(options.maxWidth / (velocity + 1), options.minWidth);
558
+ }
559
+ }, {
560
+ key: "_drawCurveSegment",
561
+ value: function _drawCurveSegment(x, y, width) {
562
+ var ctx = this._ctx;
563
+ ctx.moveTo(x, y);
564
+ ctx.arc(x, y, width, 0, 2 * Math.PI, false);
565
+ this._isEmpty = false;
566
+ }
567
+ }, {
568
+ key: "_drawCurve",
569
+ value: function _drawCurve(curve, options) {
570
+ var ctx = this._ctx;
571
+ var widthDelta = curve.endWidth - curve.startWidth;
572
+ var drawSteps = Math.ceil(curve.length()) * 2;
573
+ ctx.beginPath();
574
+ ctx.fillStyle = options.penColor;
575
+ for (var i = 0; i < drawSteps; i += 1) {
576
+ var t = i / drawSteps;
577
+ var tt = t * t;
578
+ var ttt = tt * t;
579
+ var u = 1 - t;
580
+ var uu = u * u;
581
+ var uuu = uu * u;
582
+ var x = uuu * curve.startPoint.x;
583
+ x += 3 * uu * t * curve.control1.x;
584
+ x += 3 * u * tt * curve.control2.x;
585
+ x += ttt * curve.endPoint.x;
586
+ var y = uuu * curve.startPoint.y;
587
+ y += 3 * uu * t * curve.control1.y;
588
+ y += 3 * u * tt * curve.control2.y;
589
+ y += ttt * curve.endPoint.y;
590
+ var width = Math.min(curve.startWidth + ttt * widthDelta, options.maxWidth);
591
+ this._drawCurveSegment(x, y, width);
592
+ }
593
+ ctx.closePath();
594
+ (0, _fill.default)(ctx).call(ctx);
595
+ }
596
+ }, {
597
+ key: "_drawDot",
598
+ value: function _drawDot(point, options) {
599
+ var ctx = this._ctx;
600
+ var width = options.dotSize > 0 ? options.dotSize : (options.minWidth + options.maxWidth) / 2;
601
+ ctx.beginPath();
602
+ this._drawCurveSegment(point.x, point.y, width);
603
+ ctx.closePath();
604
+ ctx.fillStyle = options.penColor;
605
+ (0, _fill.default)(ctx).call(ctx);
606
+ }
607
+ }, {
608
+ key: "_fromData",
609
+ value: function _fromData(pointGroups, drawCurve, drawDot) {
610
+ var _iterator = _createForOfIteratorHelper(pointGroups),
611
+ _step;
612
+ try {
613
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
614
+ var group = _step.value;
615
+ var points = group.points;
616
+ var pointGroupOptions = this._getPointGroupOptions(group);
617
+ if (points.length > 1) {
618
+ for (var j = 0; j < points.length; j += 1) {
619
+ var basicPoint = points[j];
620
+ var point = new Point(basicPoint.x, basicPoint.y, basicPoint.pressure, basicPoint.time);
621
+ if (j === 0) {
622
+ this._reset(pointGroupOptions);
623
+ }
624
+ var curve = this._addPoint(point, pointGroupOptions);
625
+ if (curve) {
626
+ drawCurve(curve, pointGroupOptions);
627
+ }
628
+ }
629
+ } else {
630
+ this._reset(pointGroupOptions);
631
+ drawDot(points[0], pointGroupOptions);
632
+ }
633
+ }
634
+ } catch (err) {
635
+ _iterator.e(err);
636
+ } finally {
637
+ _iterator.f();
638
+ }
639
+ }
640
+ }, {
641
+ key: "toSVG",
642
+ value: function toSVG() {
643
+ var _context3, _context4;
644
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
645
+ _ref2$includeBackgrou = _ref2.includeBackgroundColor,
646
+ includeBackgroundColor = _ref2$includeBackgrou === void 0 ? false : _ref2$includeBackgrou;
647
+ var pointGroups = this._data;
648
+ var ratio = Math.max(window.devicePixelRatio || 1, 1);
649
+ var minX = 0;
650
+ var minY = 0;
651
+ var maxX = this.canvas.width / ratio;
652
+ var maxY = this.canvas.height / ratio;
653
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
654
+ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
655
+ svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
656
+ svg.setAttribute('viewBox', (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = "".concat(minX, " ").concat(minY, " ")).call(_context4, maxX, " ")).call(_context3, maxY));
657
+ svg.setAttribute('width', maxX.toString());
658
+ svg.setAttribute('height', maxY.toString());
659
+ if (includeBackgroundColor && this.backgroundColor) {
660
+ var rect = document.createElement('rect');
661
+ rect.setAttribute('width', '100%');
662
+ rect.setAttribute('height', '100%');
663
+ rect.setAttribute('fill', this.backgroundColor);
664
+ svg.appendChild(rect);
665
+ }
666
+ this._fromData(pointGroups, function (curve, _ref3) {
667
+ var penColor = _ref3.penColor;
668
+ var path = document.createElement('path');
669
+ if (!isNaN(curve.control1.x) && !isNaN(curve.control1.y) && !isNaN(curve.control2.x) && !isNaN(curve.control2.y)) {
670
+ var _context5, _context6, _context7, _context8;
671
+ var attr = (0, _concat.default)(_context5 = "M ".concat(curve.startPoint.x.toFixed(3), ",")).call(_context5, curve.startPoint.y.toFixed(3), " ") + (0, _concat.default)(_context6 = "C ".concat(curve.control1.x.toFixed(3), ",")).call(_context6, curve.control1.y.toFixed(3), " ") + (0, _concat.default)(_context7 = "".concat(curve.control2.x.toFixed(3), ",")).call(_context7, curve.control2.y.toFixed(3), " ") + (0, _concat.default)(_context8 = "".concat(curve.endPoint.x.toFixed(3), ",")).call(_context8, curve.endPoint.y.toFixed(3));
672
+ path.setAttribute('d', attr);
673
+ path.setAttribute('stroke-width', (curve.endWidth * 2.25).toFixed(3));
674
+ path.setAttribute('stroke', penColor);
675
+ path.setAttribute('fill', 'none');
676
+ path.setAttribute('stroke-linecap', 'round');
677
+ svg.appendChild(path);
678
+ }
679
+ }, function (point, _ref4) {
680
+ var penColor = _ref4.penColor,
681
+ dotSize = _ref4.dotSize,
682
+ minWidth = _ref4.minWidth,
683
+ maxWidth = _ref4.maxWidth;
684
+ var circle = document.createElement('circle');
685
+ var size = dotSize > 0 ? dotSize : (minWidth + maxWidth) / 2;
686
+ circle.setAttribute('r', size.toString());
687
+ circle.setAttribute('cx', point.x.toString());
688
+ circle.setAttribute('cy', point.y.toString());
689
+ circle.setAttribute('fill', penColor);
690
+ svg.appendChild(circle);
691
+ });
692
+ return svg.outerHTML;
693
+ }
694
+ }]);
695
+ return SignaturePad;
696
+ }(SignatureEventTarget);
697
+ exports.default = SignaturePad;