HKC_Blazor/MasaBlazorApp3/wwwroot/signature.js

2 lines
9.4 KiB
JavaScript
Raw Permalink Normal View History

2025-04-18 11:01:56 +08:00
!function (t, i) { "object" == typeof exports && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : (t = "undefined" != typeof globalThis ? globalThis : t || self).SmoothSignature = i() }(this, (function () { "use strict"; function t(t, i) { for (var e = 0; i.length > e; e++) { var n = i[e]; n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(t, n.key, n) } } var i = /Android|iPhone|iPad|Mobile/i.test(navigator.userAgent), e = function () { function e(t, n) { var a = this; !function (t, i) { if (!(t instanceof i)) throw new TypeError("Cannot call a class as a function") }(this, e), this.canvas = {}, this.ctx = {}, this.width = 320, this.height = 200, this.scale = window.devicePixelRatio || 1, this.color = "black", this.bgColor = "", this.canDraw = !1, this.openSmooth = !0, this.minWidth = 2, this.maxWidth = 6, this.minSpeed = 1.5, this.maxWidthDiffRate = 20, this.points = [], this.canAddHistory = !0, this.historyList = [], this.maxHistoryLength = 20, this.onStart = function () { }, this.onEnd = function () { }, this.addListener = function () { a.removeListener(), a.canvas.style.touchAction = "none", i && ("ontouchstart" in window || navigator.maxTouchPoints) ? (a.canvas.addEventListener("touchstart", a.onDrawStart, { passive: !1 }), a.canvas.addEventListener("touchmove", a.onDrawMove, { passive: !1 }), document.addEventListener("touchcancel", a.onDrawEnd, { passive: !1 }), document.addEventListener("touchend", a.onDrawEnd, { passive: !1 })) : (a.canvas.addEventListener("mousedown", a.onDrawStart), a.canvas.addEventListener("mousemove", a.onDrawMove), document.addEventListener("mouseup", a.onDrawEnd)) }, this.removeListener = function () { a.canvas.style.touchAction = "auto", a.canvas.removeEventListener("touchstart", a.onDrawStart), a.canvas.removeEventListener("touchmove", a.onDrawMove), document.removeEventListener("touchend", a.onDrawEnd), document.removeEventListener("touchcancel", a.onDrawEnd), a.canvas.removeEventListener("mousedown", a.onDrawStart), a.canvas.removeEventListener("mousemove", a.onDrawMove), document.removeEventListener("mouseup", a.onDrawEnd) }, this.onDrawStart = function (t) { t.preventDefault(), a.canDraw = !0, a.canAddHistory = !0, a.ctx.strokeStyle = a.color, a.initPoint(t), a.onStart && a.onStart(t) }, this.onDrawMove = function (t) { if (t.preventDefault(), a.canDraw && (a.initPoint(t), a.points.length >= 2)) { a.addHistory(); var i = a.points.slice(-1)[0], e = a.points.slice(-2, -1)[0]; window.requestAnimationFrame ? window.requestAnimationFrame((function () { return a.onDraw(e, i) })) : a.onDraw(e, i) } }, this.onDraw = function (t, i) { a.openSmooth ? a.drawSmoothLine(t, i) : a.drawNoSmoothLine(t, i) }, this.onDrawEnd = function (t) { a.canDraw && (a.canDraw = !1, a.canAddHistory = !0, a.points = [], a.onEnd && a.onEnd(t)) }, this.getLineWidth = function (t) { return Math.min(Math.max(a.maxWidth - (a.maxWidth - a.minWidth) * t / (a.minSpeed > 10 ? 10 : 1 > a.minSpeed ? 1 : a.minSpeed), a.minWidth), a.maxWidth) }, this.getRadianData = function (t, i, e, n) { var a = e - t, o = n - i; if (0 === a) return { val: 0, pos: -1 }; if (0 === o) return { val: 0, pos: 1 }; var s = Math.abs(Math.atan(o / a)); return e > t && i > n || t > e && n > i ? { val: s, pos: 1 } : { val: s, pos: -1 } }, this.getRadianPoints = function (t, i, e, n) { if (0 === t.val) return 1 === t.pos ? [{ x: i, y: e + n }, { x: i, y: e - n }] : [{ y: e, x: i + n }, { y: e, x: i - n }]; var a = Math.sin(t.val) * n, o = Math.cos(t.val) * n; return 1 === t.pos ? [{ x: i + a, y: e + o }, { x: i - a, y: e - o }] : [{ x: i + a, y: e - o }, { x: i - a, y: e + o }] }, this.initPoint = function (t) { var i = Date.now(), e = a.points.slice(-1)[0]; if (!e || e.t !== i) { var n = a.canvas.getBoundingClientRect(), o = t.touches && t.touches[0] || t, s = o.clientX - n.left, h = o.clientY - n.top; if (!e || e.x !== s || e.y !== h) { var r = { x: s, y: h, t: i }; if (a.openSmooth && e) { var d = a.points.slice(-2, -1)[0]