@jxstjh/jhvideo
Version:
HTML5 jhvideo base on MPEG2-TS Stream Player
759 lines (758 loc) • 27.8 kB
JavaScript
var Yt = Object.defineProperty;
var Ft = (h, t, e) => t in h ? Yt(h, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[t] = e;
var Q = (h, t, e) => (Ft(h, typeof t != "symbol" ? t + "" : t, e), e), gt = (h, t, e) => {
if (!t.has(h))
throw TypeError("Cannot " + e);
};
var r = (h, t, e) => (gt(h, t, "read from private field"), e ? e.call(h) : t.get(h)), S = (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 = (h, t, e, a) => (gt(h, t, "write to private field"), a ? a.call(h, e) : t.set(h, e), e);
var z = (h, t, e) => (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;
const _t = /* @__PURE__ */ Lt(Ot), $t = (h, t = "MM/DD HH:mm") => _t(h).format(t), Tt = (h, t) => {
let e, a = 0;
return (...f) => {
const d = Date.now(), g = d - a;
!a || g >= t ? (a = d, h.apply(void 0, f)) : e || (e = setTimeout(() => {
a = d, h.apply(void 0, f), e = null;
}, t - g));
};
}, Et = (h, t) => {
const e = document.createElement("canvas");
e.width = e.height = 1;
const a = e.getContext("2d");
a.fillStyle = h, a.fillRect(0, 0, 1, 1);
const f = a.getImageData(0, 0, 1, 1).data;
return `rgba(${f[0]}, ${f[1]}, ${f[2]}, ${t})`;
}, Wt = ({
xCenterPoint: h,
cfg: t,
timePerPixel: e,
timeSpacing: a,
currentTime: f,
$canvas: d,
screenScaleCount: g,
scaleHeight: M,
startTime: p,
drawLine: w,
drawText: Y,
drawArea: T
}) => {
const A = ({
space: I,
scaleTimeFormat: et,
bgTimeFormat: ft,
pointerTimeFormat: mt
}) => {
Y({
x: d.width - h / 10,
y: 6,
text: $t(f, ft),
fontSize: `${d.height - 5}px`,
align: "right",
baseLine: "top",
color: t.bgTextColor
});
const it = p % a, q = it / e;
for (let R = 0; R < g; R++) {
const 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;
class It {
constructor(t, e) {
// 拖拽
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, ({ x: t, y: e, width: a = 1, color: f = this.cfg.scaleColor }) => {
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, ({
x: t,
y: e,
text: a,
color: f = this.cfg.textColor,
fontSize: d = "11px",
align: g = "center",
baseLine: M = "alphabetic"
}) => {
this.ctx.beginPath(), this.ctx.font = `${d} ${this.cfg.fontFamily}`, this.ctx.fillStyle = f, this.ctx.textAlign = g, this.ctx.textBaseline = M, this.ctx.fillText(a, t, e);
});
// 绘制区域
S(this, U, ({ startX: t, startY: e, endX: a, endY: f, bgColor: d }) => {
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 = { ...kt, ...e }, e != null && e.pointColor && (this.cfg.pointerColor = e.pointColor), e != null && e.pointWidth && (this.cfg.pointerWidth = e.pointWidth);
const {
fill: a,
width: f,
height: d,
zoom: g,
timeSpacingList: M,
scaleHeight: p,
textColor: w,
bgTextColor: Y
} = this.cfg;
if (Y || (this.cfg.bgTextColor = Et(w, 0.18)), g < 0 || g >= M.length || g % 1 !== 0)
throw new Error(
`zoom must be 0 ~ ${M.length - 1}, and must be an integer`
);
if (a) {
const 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));
}
// 动画
setTimeMove({ timestamp: t, direction: e }, a = !0) {
if (!r(this, k) && !r(this, j)) {
let f = t;
a || (f = e ? r(this, x) + t : r(this, x) - t), this.draw({
currentTime: f,
areas: r(this, _),
_privateFlag: !0
});
}
}
// 绘制时间轴
draw({ currentTime: t, areas: e, _privateFlag: a } = {}) {
if (r(this, j) && !a)
return;
C(this, x, t || Date.now()), C(this, _, e || []);
const 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((Y) => {
const 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);
}
// 获取当前时间
getCurrentTime() {
return r(this, x);
}
setZoom(t = !0) {
const e = this.cfg.timeSpacingList.findIndex(
(a) => 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);
}
// 清空画布
clear() {
this.ctx && this.ctx.clearRect(0, 0, this.$canvas.width, this.$canvas.height);
}
on(t, e) {
r(this, J).on(t, e);
}
off(t, e) {
r(this, J).off(t, e);
}
}
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) {
C(this, j, !0);
let e = 0, a = r(this, x);
const f = Tt(({ offsetX: M }) => {
if (!r(this, j))
return;
const 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 = ({ offsetX: M, offsetY: p }) => {
(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 = () => {
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(() => {
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) {
t.preventDefault();
const e = this.cfg.timeSpacingList.findIndex(
(a) => 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() {
const t = () => r(this, v) < 1e3 ? `${r(this, v)}ms` : r(this, v) < 6e4 ? `${Math.round(r(this, v) / 100) / 10}sec` : r(this, v) < 36e5 ? `${Math.round(r(this, v) / 100 / 60) / 10}min` : r(this, v) < 864e5 ? `${Math.round(r(this, v) / 100 / 60 / 60) / 10}hours` : r(this, v) < 6048e5 ? `${Math.round(r(this, v) / 100 / 60 / 60 / 24) / 10}days` : `${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(...t) {
r(this, J).emit(...t);
};
export {
It as default,
$t as format
};