Skip to content

Commit

Permalink
chore: rebuild lib
Browse files Browse the repository at this point in the history
  • Loading branch information
codeacme17 committed Mar 31, 2023
1 parent 8c40f57 commit 0903435
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 62 deletions.
123 changes: 63 additions & 60 deletions lib/1llest-waveform-vue.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var $ = Object.defineProperty;
var I = (i, e, t) => e in i ? $(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var u = (i, e, t) => (I(i, typeof e != "symbol" ? e + "" : e, t), t);
import { defineComponent as L, ref as d, onMounted as E, watchEffect as m, onUnmounted as O, openBlock as P, createElementBlock as X, normalizeStyle as y, createVNode as Y, Transition as V, withCtx as q, withDirectives as _, createElementVNode as C, vShow as A } from "vue";
var l = (i, e, t) => (I(i, typeof e != "symbol" ? e + "" : e, t), t);
import { defineComponent as L, ref as d, onMounted as E, watchEffect as m, onUnmounted as P, openBlock as O, createElementBlock as X, normalizeStyle as y, createVNode as Y, Transition as V, withCtx as q, withDirectives as _, createElementVNode as C, vShow as k } from "vue";
class U {
constructor(e, t, a) {
u(this, "canvasCtx");
l(this, "canvasCtx");
var n;
this.canvas = e, this.props = t, this.filteredData = a, this.canvas = e, this.canvasCtx = (n = this.canvas) == null ? void 0 : n.getContext("2d"), this.props = t, this.filteredData = a;
}
Expand Down Expand Up @@ -32,12 +32,12 @@ class U {
drawCanvasLines() {
const { canvas: e, canvasCtx: t, filteredData: a } = this;
a.forEach((n, o) => {
const c = e.width / a.length, l = c * o - c / 2;
const c = e.width / a.length, u = c * o - c / 2;
t.moveTo(
l,
u,
e.height / 2 - Math.abs(n[0]) * e.height * 0.4
), t.lineTo(
l,
u,
e.height / 2 + Math.abs(n[0]) * e.height * 0.4
);
});
Expand All @@ -57,12 +57,12 @@ class U {
}
class j {
constructor(e) {
u(this, "props");
u(this, "audioCtx");
u(this, "audioBuffer");
u(this, "audioBufferSourceNode");
u(this, "filterData");
u(this, "arrayBuffer");
l(this, "props");
l(this, "audioCtx");
l(this, "audioBuffer");
l(this, "audioBufferSourceNode");
l(this, "filterData");
l(this, "arrayBuffer");
this.props = e, this.audioCtx = new AudioContext();
}
get _filterData() {
Expand Down Expand Up @@ -93,9 +93,9 @@ class j {
a.push(this.audioBuffer.getChannelData(o));
for (let o = 0; o < e; o++) {
const c = [0, 0];
for (let l = 0; l < t; l++) {
const r = Math.floor(a[l].length / e);
c[l] = a[l][o * r];
for (let u = 0; u < t; u++) {
const r = Math.floor(a[u].length / e);
c[u] = a[u][o * r];
}
n.push(c);
}
Expand All @@ -114,10 +114,10 @@ class j {
class G extends j {
constructor(t) {
super(t);
u(this, "startAt");
u(this, "pauseAt");
u(this, "pickAt");
u(this, "playing");
l(this, "startAt");
l(this, "pauseAt");
l(this, "pickAt");
l(this, "playing");
this.startAt = 0, this.pauseAt = 0, this.pickAt = 0, this.playing = !1;
}
get _playing() {
Expand All @@ -135,11 +135,14 @@ class G extends j {
this.stop(), this.pauseAt = t;
}
pick(t) {
t <= 0 && (t = 0), t >= this._audioDuration && (t = this._audioDuration), this.pickAt = t, this.playing && (this.stopSource(), this.play());
this.pickAt = t, this.playing && (this.stopSource(), this.play());
}
replay() {
this.audioBufferSourceNode && this.stop(), this.play();
}
finish() {
this.pauseAt = 0, this.stop();
}
stop() {
this.stopSource(), this.initializeState();
}
Expand All @@ -150,18 +153,18 @@ class G extends j {
this.playing = !1, this.startAt = 0, this.pauseAt = 0, this.pickAt = 0;
}
}
function D(i) {
function B(i) {
const e = Math.floor(i / 60), t = Math.floor(i % 60);
return `${e}:${t < 10 ? "0" : ""}${t}`;
}
function J(i, e) {
const t = Q(() => k(i, e), 500);
const t = Q(() => A(i, e), 500);
document.addEventListener("scroll", () => t());
}
function K(i, e) {
document.removeEventListener("scroll", () => k(i, e));
document.removeEventListener("scroll", () => A(i, e));
}
function k(i, e) {
function A(i, e) {
const t = window.innerHeight, a = window.scrollY, n = window.pageYOffset + i.getBoundingClientRect().top;
n >= a - t / 4 && n - a - t < t / 4 && e();
}
Expand Down Expand Up @@ -201,86 +204,86 @@ const Z = /* @__PURE__ */ L({
setup(i, { expose: e, emit: t }) {
const a = i, n = d(!1), o = d(null);
E(async () => {
a.lazy ? (k(o.value, c), J(
a.lazy ? (A(o.value, c), J(
o.value,
c
), m(async () => {
n.value && await x();
})) : await x();
}), O(() => {
}), P(() => {
a.lazy && K(o.value, c);
});
function c() {
n.value = !0;
}
const l = d(null), r = d(!1);
let s, h;
const u = d(null), r = d(!1);
let s, f;
async function x() {
r.value || (t("onInit", !0), await S(), await W(), r.value = !0, t("onReady", r.value));
r.value || (t("onInit", !0), await S(), await D(), r.value = !0, t("onReady", r.value));
}
async function S() {
s = new G(a), await s.fetchAudioFile(), t("onFetched", !0), await s.setupAudio(), R();
}
async function W() {
h = new U(
l.value,
async function D() {
f = new U(
u.value,
a,
s._filterData
), h.setupCanvas(), m(() => {
h._props = a, h.setWaveStyle(w.value);
), f.setupCanvas(), m(() => {
f._props = a, f.setWaveStyle(w.value);
});
}
const v = d(0), p = d(0), w = d(0);
const p = d(0), v = d(0), w = d(0);
function g() {
!s._playing || (requestAnimationFrame(g), p.value = s._currentTime, w.value = p.value / s._audioDuration * h._canvas.width);
!s._playing || (requestAnimationFrame(g), v.value = s._currentTime, w.value = v.value / s._audioDuration * f._canvas.width);
}
function T(f) {
!r.value || !a.interact || (f.layerX <= 0 ? v.value = 0 : f.layerX >= h._canvas.width ? v.value = h._canvas.width : v.value = f.layerX);
function W(h) {
!r.value || !a.interact || (h.layerX <= 0 ? p.value = 0 : h.layerX >= f._canvas.width ? p.value = f._canvas.width : p.value = h.layerX);
}
function N() {
function T() {
if (!r.value || !a.interact)
return;
w.value = v.value;
const f = v.value / h._canvas.width * s._audioDuration;
s.pick(f), p.value = f, t("onClick", o), t("onFinish", !1);
w.value = p.value;
const h = p.value / f._canvas.width * s._audioDuration;
s.pick(h), v.value = h, t("onClick", o), t("onFinish", !1);
}
function b() {
!r.value || (s.play(), t("onPlay", !0), g());
}
function F() {
function N() {
s.replay(), t("onFinish", !1), t("onPlay", !0), g();
}
function B() {
function F() {
s.pause(), t("onPause", !1);
}
function M() {
t("onFinish", !0);
s.finish(), t("onPlay", !1), t("onFinish", !0);
}
function R() {
m(() => {
p.value < s._audioDuration || (B(), M());
v.value <= s._audioDuration || M();
});
}
function z() {
return D(p.value);
return B(v.value);
}
function H() {
const f = s._audioDuration;
return D(f);
const h = s._audioDuration;
return B(h);
}
return e({
play: b,
pause: B,
replay: F,
pause: F,
replay: N,
getCurrentTime: z,
getDuration: H
}), (f, at) => (P(), X("section", {
}), (h, at) => (O(), X("section", {
id: "illest-wave-container",
ref_key: "waveformContainer",
ref: o,
style: y(`${r.value && i.interact ? "cursor: pointer" : ""}`),
onMousemove: T,
onClick: N
onMousemove: W,
onClick: T
}, [
Y(V, { name: "fade" }, {
default: q(() => [
Expand All @@ -292,24 +295,24 @@ const Z = /* @__PURE__ */ L({
id: "illest-skeleton__load",
style: y(`background-color: ${i.skeletonColor}`)
}, null, 4), [
[A, !r.value]
[k, !r.value]
])
], 4), [
[A, a.skeleton && !r.value]
[k, a.skeleton && !r.value]
])
]),
_: 1
}),
C("canvas", {
id: "illest-wave",
ref_key: "waveRef",
ref: l
ref: u
}, null, 512),
_(C("div", {
id: "illest-cursor",
style: y(`width:${a.cursorWidth}px; transform: translateX(${v.value}px);background-color: ${a.cursorColor}; `)
style: y(`width:${a.cursorWidth}px; transform: translateX(${p.value}px);background-color: ${a.cursorColor}; `)
}, null, 4), [
[A, r.value && a.interact]
[k, r.value && a.interact]
])
], 36));
}
Expand All @@ -319,7 +322,7 @@ const tt = (i, e) => {
for (const [a, n] of e)
t[a] = n;
return t;
}, et = /* @__PURE__ */ tt(Z, [["__scopeId", "data-v-10d3d361"]]), ot = {
}, et = /* @__PURE__ */ tt(Z, [["__scopeId", "data-v-020db612"]]), ot = {
install: (i) => {
i.component("IllestWaveform", et);
}
Expand Down
Loading

0 comments on commit 0903435

Please sign in to comment.