UNPKG

@jxstjh/jhvideo

Version:

HTML5 jhvideo base on MPEG2-TS Stream Player

753 lines 33.4 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var Yt = Object.defineProperty; var Ft = function (h, t, e) { return t in h ? Yt(h, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[t] = e; }; var Q = function (h, t, e) { return (Ft(h, typeof t != "symbol" ? t + "" : t, e), e); }, gt = function (h, t, e) { if (!t.has(h)) throw TypeError("Cannot " + e); }; var r = function (h, t, e) { return (gt(h, t, "read from private field"), e ? e.call(h) : t.get(h)); }, S = function (h, t, e) { if (t.has(h)) throw TypeError("Cannot add the same private member more than once"); t instanceof WeakSet ? t.add(h) : t.set(h, e); }, C = function (h, t, e, a) { return (gt(h, t, "write to private field"), a ? a.call(h, e) : t.set(h, e), e); }; var z = function (h, t, e) { return (gt(h, t, "access private method"), e); }; function Ct(h) { return { all: h = h || /* @__PURE__ */ new Map(), on: function (t, e) { var a = h.get(t); a ? a.push(e) : h.set(t, [e]); }, off: function (t, e) { var a = h.get(t); a && (e ? a.splice(a.indexOf(e) >>> 0, 1) : h.set(t, [])); }, emit: function (t, e) { var a = h.get(t); a && a.slice().map(function (f) { f(e); }), (a = h.get("*")) && a.slice().map(function (f) { f(t, e); }); } }; } var Ht = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function Lt(h) { return h && h.__esModule && Object.prototype.hasOwnProperty.call(h, "default") ? h.default : h; } var Dt = { exports: {} }; (function (h, t) { (function (e, a) { h.exports = a(); })(Ht, function () { var e = 1e3, a = 6e4, f = 36e5, d = "millisecond", g = "second", M = "minute", p = "hour", w = "day", Y = "week", T = "month", A = "quarter", H = "year", I = "date", et = "Invalid Date", ft = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, mt = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, it = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function (c) { var n = ["th", "st", "nd", "rd"], i = c % 100; return "[" + c + (n[(i - 20) % 10] || n[i] || n[0]) + "]"; } }, q = function (c, n, i) { var o = String(c); return !o || o.length >= n ? c : "" + Array(n + 1 - o.length).join(i) + c; }, R = { s: q, z: function (c) { var n = -c.utcOffset(), i = Math.abs(n), o = Math.floor(i / 60), s = i % 60; return (n <= 0 ? "+" : "-") + q(o, 2, "0") + ":" + q(s, 2, "0"); }, m: function c(n, i) { if (n.date() < i.date()) return -c(i, n); var o = 12 * (i.year() - n.year()) + (i.month() - n.month()), s = n.clone().add(o, T), u = i - s < 0, l = n.clone().add(o + (u ? -1 : 1), T); return +(-(o + (i - s) / (u ? s - l : l - s)) || 0); }, a: function (c) { return c < 0 ? Math.ceil(c) || 0 : Math.floor(c); }, p: function (c) { return { M: T, y: H, w: Y, d: w, D: I, h: p, m: M, s: g, ms: d, Q: A }[c] || String(c || "").toLowerCase().replace(/s$/, ""); }, u: function (c) { return c === void 0; } }, W = "en", E = {}; E[W] = it; var pt = "$isDayjsObject", dt = function (c) { return c instanceof nt || !(!c || !c[pt]); }, st = function c(n, i, o) { var s; if (!n) return W; if (typeof n == "string") { var u = n.toLowerCase(); E[u] && (s = u), i && (E[u] = i, s = u); var l = n.split("-"); if (!s && l.length > 1) return c(l[0]); } else { var $ = n.name; E[$] = n, s = $; } return !o && s && (W = s), s || !o && W; }, y = function (c, n) { if (dt(c)) return c.clone(); var i = typeof n == "object" ? n : {}; return i.date = c, i.args = arguments, new nt(i); }, m = R; m.l = st, m.i = dt, m.w = function (c, n) { return y(c, { locale: n.$L, utc: n.$u, x: n.$x, $offset: n.$offset }); }; var nt = function () { function c(i) { this.$L = st(i.locale, null, !0), this.parse(i), this.$x = this.$x || i.x || {}, this[pt] = !0; } var n = c.prototype; return n.parse = function (i) { this.$d = function (o) { var s = o.date, u = o.utc; if (s === null) return /* @__PURE__ */ new Date(NaN); if (m.u(s)) return /* @__PURE__ */ new Date(); if (s instanceof Date) return new Date(s); if (typeof s == "string" && !/Z$/i.test(s)) { var l = s.match(ft); if (l) { var $ = l[2] - 1 || 0, D = (l[7] || "0").substring(0, 3); return u ? new Date(Date.UTC(l[1], $, l[3] || 1, l[4] || 0, l[5] || 0, l[6] || 0, D)) : new Date(l[1], $, l[3] || 1, l[4] || 0, l[5] || 0, l[6] || 0, D); } } return new Date(s); }(i), this.init(); }, n.init = function () { var i = this.$d; this.$y = i.getFullYear(), this.$M = i.getMonth(), this.$D = i.getDate(), this.$W = i.getDay(), this.$H = i.getHours(), this.$m = i.getMinutes(), this.$s = i.getSeconds(), this.$ms = i.getMilliseconds(); }, n.$utils = function () { return m; }, n.isValid = function () { return this.$d.toString() !== et; }, n.isSame = function (i, o) { var s = y(i); return this.startOf(o) <= s && s <= this.endOf(o); }, n.isAfter = function (i, o) { return y(i) < this.startOf(o); }, n.isBefore = function (i, o) { return this.endOf(o) < y(i); }, n.$g = function (i, o, s) { return m.u(i) ? this[o] : this.set(s, i); }, n.unix = function () { return Math.floor(this.valueOf() / 1e3); }, n.valueOf = function () { return this.$d.getTime(); }, n.startOf = function (i, o) { var s = this, u = !!m.u(o) || o, l = m.p(i), $ = function (X, L) { var P = m.w(s.$u ? Date.UTC(s.$y, L, X) : new Date(s.$y, L, X), s); return u ? P : P.endOf(w); }, D = function (X, L) { return m.w(s.toDate()[X].apply(s.toDate("s"), (u ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(L)), s); }, b = this.$W, F = this.$M, O = this.$D, B = "set" + (this.$u ? "UTC" : ""); switch (l) { case H: return u ? $(1, 0) : $(31, 11); case T: return u ? $(1, F) : $(0, F + 1); case Y: var N = this.$locale().weekStart || 0, V = (b < N ? b + 7 : b) - N; return $(u ? O - V : O + (6 - V), F); case w: case I: return D(B + "Hours", 0); case p: return D(B + "Minutes", 1); case M: return D(B + "Seconds", 2); case g: return D(B + "Milliseconds", 3); default: return this.clone(); } }, n.endOf = function (i) { return this.startOf(i, !1); }, n.$set = function (i, o) { var s, u = m.p(i), l = "set" + (this.$u ? "UTC" : ""), $ = (s = {}, s[w] = l + "Date", s[I] = l + "Date", s[T] = l + "Month", s[H] = l + "FullYear", s[p] = l + "Hours", s[M] = l + "Minutes", s[g] = l + "Seconds", s[d] = l + "Milliseconds", s)[u], D = u === w ? this.$D + (o - this.$W) : o; if (u === T || u === H) { var b = this.clone().set(I, 1); b.$d[$](D), b.init(), this.$d = b.set(I, Math.min(this.$D, b.daysInMonth())).$d; } else $ && this.$d[$](D); return this.init(), this; }, n.set = function (i, o) { return this.clone().$set(i, o); }, n.get = function (i) { return this[m.p(i)](); }, n.add = function (i, o) { var s, u = this; i = Number(i); var l = m.p(o), $ = function (F) { var O = y(u); return m.w(O.date(O.date() + Math.round(F * i)), u); }; if (l === T) return this.set(T, this.$M + i); if (l === H) return this.set(H, this.$y + i); if (l === w) return $(1); if (l === Y) return $(7); var D = (s = {}, s[M] = a, s[p] = f, s[g] = e, s)[l] || 1, b = this.$d.getTime() + i * D; return m.w(b, this); }, n.subtract = function (i, o) { return this.add(-1 * i, o); }, n.format = function (i) { var o = this, s = this.$locale(); if (!this.isValid()) return s.invalidDate || et; var u = i || "YYYY-MM-DDTHH:mm:ssZ", l = m.z(this), $ = this.$H, D = this.$m, b = this.$M, F = s.weekdays, O = s.months, B = s.meridiem, N = function (L, P, G, rt) { return L && (L[P] || L(o, u)) || G[P].slice(0, rt); }, V = function (L) { return m.s($ % 12 || 12, L, "0"); }, X = B || function (L, P, G) { var rt = L < 12 ? "AM" : "PM"; return G ? rt.toLowerCase() : rt; }; return u.replace(mt, function (L, P) { return P || function (G) { switch (G) { case "YY": return String(o.$y).slice(-2); case "YYYY": return m.s(o.$y, 4, "0"); case "M": return b + 1; case "MM": return m.s(b + 1, 2, "0"); case "MMM": return N(s.monthsShort, b, O, 3); case "MMMM": return N(O, b); case "D": return o.$D; case "DD": return m.s(o.$D, 2, "0"); case "d": return String(o.$W); case "dd": return N(s.weekdaysMin, o.$W, F, 2); case "ddd": return N(s.weekdaysShort, o.$W, F, 3); case "dddd": return F[o.$W]; case "H": return String($); case "HH": return m.s($, 2, "0"); case "h": return V(1); case "hh": return V(2); case "a": return X($, D, !0); case "A": return X($, D, !1); case "m": return String(D); case "mm": return m.s(D, 2, "0"); case "s": return String(o.$s); case "ss": return m.s(o.$s, 2, "0"); case "SSS": return m.s(o.$ms, 3, "0"); case "Z": return l; } return null; }(L) || l.replace(":", ""); }); }, n.utcOffset = function () { return 15 * -Math.round(this.$d.getTimezoneOffset() / 15); }, n.diff = function (i, o, s) { var u, l = this, $ = m.p(o), D = y(i), b = (D.utcOffset() - this.utcOffset()) * a, F = this - D, O = function () { return m.m(l, D); }; switch ($) { case H: u = O() / 12; break; case T: u = O(); break; case A: u = O() / 3; break; case Y: u = (F - b) / 6048e5; break; case w: u = (F - b) / 864e5; break; case p: u = F / f; break; case M: u = F / a; break; case g: u = F / e; break; default: u = F; } return s ? u : m.a(u); }, n.daysInMonth = function () { return this.endOf(T).$D; }, n.$locale = function () { return E[this.$L]; }, n.locale = function (i, o) { if (!i) return this.$L; var s = this.clone(), u = st(i, o, !0); return u && (s.$L = u), s; }, n.clone = function () { return m.w(this.$d, this); }, n.toDate = function () { return new Date(this.valueOf()); }, n.toJSON = function () { return this.isValid() ? this.toISOString() : null; }, n.toISOString = function () { return this.$d.toISOString(); }, n.toString = function () { return this.$d.toUTCString(); }, c; }(), Mt = nt.prototype; return y.prototype = Mt, [["$ms", d], ["$s", g], ["$m", M], ["$H", p], ["$W", w], ["$M", T], ["$y", H], ["$D", I]].forEach(function (c) { Mt[c[1]] = function (n) { return this.$g(n, c[0], c[1]); }; }), y.extend = function (c, n) { return c.$i || (c(n, nt, y), c.$i = !0), y; }, y.locale = st, y.isDayjs = dt, y.unix = function (c) { return y(1e3 * c); }, y.en = E[W], y.Ls = E, y.p = {}, y; }); })(Dt); var Ot = Dt.exports; var _t = /* @__PURE__ */ Lt(Ot), $t = function (h, t) { if (t === void 0) { t = "MM/DD HH:mm"; } return _t(h).format(t); }, Tt = function (h, t) { var e, a = 0; return function () { var f = []; for (var _i = 0; _i < arguments.length; _i++) { f[_i] = arguments[_i]; } var d = Date.now(), g = d - a; !a || g >= t ? (a = d, h.apply(void 0, f)) : e || (e = setTimeout(function () { a = d, h.apply(void 0, f), e = null; }, t - g)); }; }, Et = function (h, t) { var e = document.createElement("canvas"); e.width = e.height = 1; var a = e.getContext("2d"); a.fillStyle = h, a.fillRect(0, 0, 1, 1); var f = a.getImageData(0, 0, 1, 1).data; return "rgba(".concat(f[0], ", ").concat(f[1], ", ").concat(f[2], ", ").concat(t, ")"); }, Wt = function (_a) { var h = _a.xCenterPoint, t = _a.cfg, e = _a.timePerPixel, a = _a.timeSpacing, f = _a.currentTime, d = _a.$canvas, g = _a.screenScaleCount, M = _a.scaleHeight, p = _a.startTime, w = _a.drawLine, Y = _a.drawText, T = _a.drawArea; var A = function (_a) { var I = _a.space, et = _a.scaleTimeFormat, ft = _a.bgTimeFormat, mt = _a.pointerTimeFormat; Y({ x: d.width - h / 10, y: 6, text: $t(f, ft), fontSize: "".concat(d.height - 5, "px"), align: "right", baseLine: "top", color: t.bgTextColor }); var it = p % a, q = it / e; for (var R = 0; R < g; R++) { var W = R * t.scaleSpacing - q - t.pointerWidth / 2, E = p + R * a - it; if (E % (a * I) === 0) { w({ x: W, y: M.long }), Y({ x: W, y: d.height - M.long - 5, text: $t(E, et), baseLine: "bottom" }); continue; } w({ x: W, y: M.short }); } w({ x: h - t.pointerWidth / 2, y: d.height, width: t.pointerWidth, color: t.pointerColor }), T({ startX: h - t.pointerDisplayWidth / 2, startY: 4, endX: h + t.pointerDisplayWidth / 2, endY: 4 + t.pointerDisplayHeight, bgColor: t.pointerColor }), Y({ x: h, y: t.pointerDisplayHeight / 2 + 5, text: $t(f, mt), align: "center", baseLine: "middle" }); }, H = t.thresholdsConfig[a]; H && A({ space: H.space, scaleTimeFormat: H.scaleTimeFormat, bgTimeFormat: H.bgTimeFormat, pointerTimeFormat: H.pointerTimeFormat }); }, kt = { fill: !0, width: 1e3, height: 60, bgColor: "rgba(0,0,0,0.5)", textColor: "#ffffff", fontFamily: "Arial", scaleColor: "#ffffff", scaleSpacing: 7, areaBgColor: "#ffffff55", pointerColor: "#00aeec", pointerWidth: 3, pointerDisplayWidth: 100, pointerDisplayHeight: 14, fps: 60, zoom: 3, isDrawScale: !1, timeNumber: 600, timeSpacingList: [5e3, 1e4, 6e4, 6e5, 36e5], // timeSpacingList: [ 10, 100, 1000, 10000, 60000, 600000, 3600000, 86400000, 604800000 ], // scaleHeight: , // bgTextColor: , thresholdsConfig: { 10: { scaleTimeFormat: "mm:ss:SSS", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss:SSS", space: 10 }, 100: { scaleTimeFormat: "mm:ss", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss:SSS", space: 10 }, 5e3: { scaleTimeFormat: "mm:ss", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss", space: 10 }, 1e4: { scaleTimeFormat: "HH:mm:ss", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss", space: 12 }, 6e4: { scaleTimeFormat: "HH:mm", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss", space: 10 }, 6e5: { scaleTimeFormat: "HH:mm", bgTimeFormat: "YYYY/MM/DD", pointerTimeFormat: "HH:mm:ss", space: 10 }, 36e5: { scaleTimeFormat: "MM/DD HH:mm", bgTimeFormat: "YYYY/MM", pointerTimeFormat: "MM/DD HH:mm", space: 12 }, 864e5: { scaleTimeFormat: "MM/DD HH:mm", bgTimeFormat: "YYYY/MM", pointerTimeFormat: "YYYY/MM/DD HH:mm", space: 12 }, 6048e5: { scaleTimeFormat: "YYYY/MM/DD", bgTimeFormat: "YYYY", pointerTimeFormat: "YYYY/MM/DD", space: 10 } // { // 10: { // scaleTimeFormat: "mm:ss:SSS", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss:SSS", // space: 10, // }, // 100: { // scaleTimeFormat: "mm:ss", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss:SSS", // space: 10, // }, // 1000: { // scaleTimeFormat: "mm:ss", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss", // space: 10, // }, // 10000: { // scaleTimeFormat: "HH:mm:ss", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss", // space: 12, // }, // 60000: { // scaleTimeFormat: "HH:mm", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss", // space: 10, // }, // 600000: { // scaleTimeFormat: "HH:mm", // bgTimeFormat: "YYYY/MM/DD", // pointerTimeFormat: "HH:mm:ss", // space: 10, // }, // 3600000: { // scaleTimeFormat: "MM/DD HH:mm", // bgTimeFormat: "YYYY/MM", // pointerTimeFormat: "MM/DD HH:mm", // space: 12, // }, // 86400000: { // scaleTimeFormat: "MM/DD HH:mm", // bgTimeFormat: "YYYY/MM", // pointerTimeFormat: "YYYY/MM/DD HH:mm", // space: 12, // }, // 604800000: { // scaleTimeFormat: "YYYY/MM/DD", // bgTimeFormat: "YYYY", // pointerTimeFormat: "YYYY/MM/DD", // space: 10, // }, } }; var J, x, _, v, Z, j, k, at, wt, ot, yt, ht, bt, ct, St, ut, xt, lt, K, U, tt, vt; var It = /** @class */ (function () { function It(t, e) { var _this = this; // 拖拽 S(this, at); // 缩放 S(this, ot); // 父元素size变化 S(this, ht); // 清空画布 S(this, ct); // 绘制比例尺 S(this, ut); S(this, tt); Q(this, "$canvas"); Q(this, "$canvasParent"); Q(this, "ctx"); Q(this, "cfg"); S(this, J, Ct()); S(this, x, 0); S(this, _, void 0); S(this, v, void 0); S(this, Z, void 0); S(this, j, !1); S(this, k, null); // 绘制线条 S(this, lt, function (_a) { var t = _a.x, e = _a.y, _b = _a.width, a = _b === void 0 ? 1 : _b, _c = _a.color, f = _c === void 0 ? _this.cfg.scaleColor : _c; _this.ctx.beginPath(), _this.ctx.moveTo(t, _this.$canvas.height), _this.ctx.lineTo(t, _this.$canvas.height - e), _this.ctx.closePath(), _this.ctx.strokeStyle = f, _this.ctx.lineWidth = a, _this.ctx.stroke(); }); // 绘制文字 S(this, K, function (_a) { var t = _a.x, e = _a.y, a = _a.text, _b = _a.color, f = _b === void 0 ? _this.cfg.textColor : _b, _c = _a.fontSize, d = _c === void 0 ? "11px" : _c, _d = _a.align, g = _d === void 0 ? "center" : _d, _e = _a.baseLine, M = _e === void 0 ? "alphabetic" : _e; _this.ctx.beginPath(), _this.ctx.font = "".concat(d, " ").concat(_this.cfg.fontFamily), _this.ctx.fillStyle = f, _this.ctx.textAlign = g, _this.ctx.textBaseline = M, _this.ctx.fillText(a, t, e); }); // 绘制区域 S(this, U, function (_a) { var t = _a.startX, e = _a.startY, a = _a.endX, f = _a.endY, d = _a.bgColor; _this.ctx.beginPath(), _this.ctx.rect(t, e, a - t, f - e), _this.ctx.fillStyle = d, _this.ctx.fill(); }); if (!t) throw new Error("canvas Element Or Element ID is required!"); typeof t == "string" ? this.$canvas = document.querySelector(t) : this.$canvas = t, this.ctx = this.$canvas.getContext("2d"), this.cfg = __assign(__assign({}, kt), e), e != null && e.pointColor && (this.cfg.pointerColor = e.pointColor), e != null && e.pointWidth && (this.cfg.pointerWidth = e.pointWidth); var _a = this.cfg, a = _a.fill, f = _a.width, d = _a.height, g = _a.zoom, M = _a.timeSpacingList, p = _a.scaleHeight, w = _a.textColor, Y = _a.bgTextColor; if (Y || (this.cfg.bgTextColor = Et(w, 0.18)), g < 0 || g >= M.length || g % 1 !== 0) throw new Error("zoom must be 0 ~ ".concat(M.length - 1, ", and must be an integer")); if (a) { var T = this.$canvas.parentElement; this.$canvasParent = T, this.$canvas.width = T.clientWidth, this.$canvas.height = T.clientHeight, new ResizeObserver(Tt(z(this, ht, bt).bind(this), 200)).observe(T); } else this.$canvas.width = f, this.$canvas.height = d; C(this, v, M[g]), p != null && p.long && (p != null && p.short) ? C(this, Z, p) : C(this, Z, { long: this.$canvas.height / 3, medium: this.$canvas.height / 6, short: this.$canvas.height / 10 }), this.draw(), this.$canvas.addEventListener("wheel", z(this, ot, yt).bind(this), { passive: !1 }), this.$canvas.addEventListener("mousedown", z(this, at, wt).bind(this)); } // 动画 It.prototype.setTimeMove = function (_a, a) { var t = _a.timestamp, e = _a.direction; if (a === void 0) { a = !0; } if (!r(this, k) && !r(this, j)) { var f = t; a || (f = e ? r(this, x) + t : r(this, x) - t), this.draw({ currentTime: f, areas: r(this, _), _privateFlag: !0 }); } }; // 绘制时间轴 It.prototype.draw = function (_a) { var _this = this; var _b = _a === void 0 ? {} : _a, t = _b.currentTime, e = _b.areas, a = _b._privateFlag; if (r(this, j) && !a) return; C(this, x, t || Date.now()), C(this, _, e || []); var f = Math.ceil(this.$canvas.width / this.cfg.scaleSpacing), d = f * r(this, v), g = r(this, x) - d / 2, M = r(this, x) + d / 2, p = this.$canvas.width / 2, w = d / this.$canvas.width; z(this, ct, St).call(this), r(this, U).call(this, { startX: 0, startY: 0, endX: this.$canvas.width, endY: this.$canvas.height, bgColor: this.cfg.bgColor }), r(this, _).forEach(function (Y) { var T = Y.startTime <= g ? 0 : Math.round((Y.startTime - g) / w), A = Y.endTime >= M ? _this.$canvas.width : Math.round((Y.endTime - g) / w); T < _this.$canvas.width && A > 0 && r(_this, U).call(_this, { startX: T, startY: 0, endX: A, endY: _this.$canvas.height, bgColor: Y.bgColor || _this.cfg.areaBgColor }); }), Wt.bind(this)({ xCenterPoint: p, screenScaleCount: f, startTime: g, timePerPixel: w, scaleHeight: r(this, Z), timeSpacing: r(this, v), currentTime: r(this, x), $canvas: this.$canvas, cfg: this.cfg, drawLine: r(this, lt).bind(this), drawText: r(this, K).bind(this), drawArea: r(this, U).bind(this) }), this.cfg.isDrawScale && z(this, ut, xt).call(this); }; // 获取当前时间 It.prototype.getCurrentTime = function () { return r(this, x); }; It.prototype.setZoom = function (t) { var _this = this; if (t === void 0) { t = !0; } var e = this.cfg.timeSpacingList.findIndex(function (a) { return a === r(_this, v); }); return e > 0 && t && (C(this, v, this.cfg.timeSpacingList[e - 1]), this.draw({ currentTime: r(this, x), areas: r(this, _), _privateFlag: !0 })), e < this.cfg.timeSpacingList.length - 1 && !t && (C(this, v, this.cfg.timeSpacingList[e + 1]), this.draw({ currentTime: r(this, x), areas: r(this, _), _privateFlag: !0 })), r(this, v); }; // 清空画布 It.prototype.clear = function () { this.ctx && this.ctx.clearRect(0, 0, this.$canvas.width, this.$canvas.height); }; It.prototype.on = function (t, e) { r(this, J).on(t, e); }; It.prototype.off = function (t, e) { r(this, J).off(t, e); }; return It; }()); J = new WeakMap(), x = new WeakMap(), _ = new WeakMap(), v = new WeakMap(), Z = new WeakMap(), j = new WeakMap(), k = new WeakMap(), at = new WeakSet(), wt = function (t) { var _this = this; C(this, j, !0); var e = 0, a = r(this, x); var f = Tt(function (_a) { var M = _a.offsetX; if (!r(_this, j)) return; var p = M - t.offsetX; a = Math.round(r(_this, x) - r(_this, v) / _this.cfg.scaleSpacing * (p - e)), e = p, _this.draw({ currentTime: a, areas: r(_this, _), _privateFlag: !0 }); }, 1e3 / this.cfg.fps), d = function (_a) { var M = _a.offsetX, p = _a.offsetY; (M < 3 || M > _this.$canvas.width - 3 || p < 3 || p > _this.$canvas.height - 3) && (_this.$canvas.removeEventListener("mousemove", f), _this.$canvas.removeEventListener("mousemove", d)); }, g = function () { _this.$canvas.removeEventListener("mousemove", f), _this.$canvas.removeEventListener("mousemove", d), document.removeEventListener("mouseup", g), C(_this, j, !1), r(_this, k) && (clearTimeout(r(_this, k)), C(_this, k, null)), C(_this, k, setTimeout(function () { z(_this, tt, vt).call(_this, "dragged", a), C(_this, k, null); }, _this.cfg.timeNumber)); }; this.$canvas.addEventListener("mousemove", f), this.$canvas.addEventListener("mousemove", d), document.addEventListener("mouseup", g); }, ot = new WeakSet(), yt = function (t) { var _this = this; t.preventDefault(); var e = this.cfg.timeSpacingList.findIndex(function (a) { return a === r(_this, v); }); t.deltaY < 0 && e > 0 ? (C(this, v, this.cfg.timeSpacingList[e - 1]), this.draw({ currentTime: r(this, x), areas: r(this, _), _privateFlag: !0 })) : t.deltaY > 0 && e < this.cfg.timeSpacingList.length - 1 && (C(this, v, this.cfg.timeSpacingList[e + 1]), this.draw({ currentTime: r(this, x), areas: r(this, _), _privateFlag: !0 })), z(this, tt, vt).call(this, "zoom", r(this, v)); }, ht = new WeakSet(), bt = function () { this.$canvasParent && (this.$canvas.width = this.$canvasParent.clientWidth, this.$canvas.height = this.$canvasParent.clientHeight, this.cfg.scaleHeight || C(this, Z, { long: this.$canvas.height / 3, medium: this.$canvas.height / 6, short: this.$canvas.height / 10 }), this.draw({ currentTime: r(this, x), areas: r(this, _) })); }, ct = new WeakSet(), St = function () { this.ctx.clearRect(0, 0, this.$canvas.width, this.$canvas.height); }, ut = new WeakSet(), xt = function () { var _this = this; var t = function () { return r(_this, v) < 1e3 ? "".concat(r(_this, v), "ms") : r(_this, v) < 6e4 ? "".concat(Math.round(r(_this, v) / 100) / 10, "sec") : r(_this, v) < 36e5 ? "".concat(Math.round(r(_this, v) / 100 / 60) / 10, "min") : r(_this, v) < 864e5 ? "".concat(Math.round(r(_this, v) / 100 / 60 / 60) / 10, "hours") : r(_this, v) < 6048e5 ? "".concat(Math.round(r(_this, v) / 100 / 60 / 60 / 24) / 10, "days") : "".concat(Math.round(r(_this, v) / 100 / 60 / 60 / 24 / 7) / 10, "weeks"); }; r(this, K).call(this, { x: this.cfg.scaleSpacing + 12, y: 9, text: t(), align: "left", baseLine: "middle" }), this.ctx.beginPath(), this.ctx.moveTo(5, 6), this.ctx.lineTo(5, 10), this.ctx.lineTo(this.cfg.scaleSpacing + 6, 10), this.ctx.lineTo(this.cfg.scaleSpacing + 6, 6), this.ctx.strokeStyle = this.cfg.scaleColor, this.ctx.lineWidth = 1.5, this.ctx.stroke(); }, lt = new WeakMap(), K = new WeakMap(), U = new WeakMap(), tt = new WeakSet(), vt = function () { var _a; var t = []; for (var _i = 0; _i < arguments.length; _i++) { t[_i] = arguments[_i]; } (_a = r(this, J)).emit.apply(_a, t); }; export { It as default, $t as format }; //# sourceMappingURL=timeline.es.js.map