@realsee/dnalogel
Version:
107 lines (106 loc) • 3.79 kB
JavaScript
var R = Object.defineProperty;
var H = Object.getOwnPropertySymbols;
var w = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
var S = (e, a, t) => a in e ? R(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t, g = (e, a) => {
for (var t in a || (a = {}))
w.call(a, t) && S(e, t, a[t]);
if (H)
for (var t of H(a))
x.call(a, t) && S(e, t, a[t]);
return e;
};
var E = (e, a, t) => new Promise((r, s) => {
var l = (y) => {
try {
d(t.next(y));
} catch (i) {
s(i);
}
}, f = (y) => {
try {
d(t.throw(y));
} catch (i) {
s(i);
}
}, d = (y) => y.done ? r(y.value) : Promise.resolve(y.value).then(l, f);
d((t = t.apply(e, a)).next());
});
import D from "animejs";
import { toArray as v } from "../util.js";
const c = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
function b(e) {
v(e).forEach((t) => {
var r, s;
c.has(t) || (t instanceof HTMLElement ? c.set(t, {
opacity: t.style.opacity === "" ? void 0 : t.style.opacity,
visible: {
display: t.style.display,
visibility: t.style.visibility
}
}) : t.isObject3D && c.set(t, {
opacity: (r = t.material) == null ? void 0 : r.opacity,
transparent: (s = t.material) == null ? void 0 : s.transparent,
visible: t.visible
}));
});
}
function k(e) {
v(e).forEach((t) => {
const r = c.get(t);
r && (t instanceof HTMLElement && (t.style.opacity = r.opacity, t.style.display = r.visible.display, t.style.visibility = r.visible.visibility, t.style.display = r.visible.display), t.isObject3D && (t.visible = r.visible, t.material && (t.material.opacity = r.opacity, t.material.transparent = r.transparent)), c.delete(t));
});
}
function N(e, a) {
return E(this, null, function* () {
var d, y;
const t = (d = a == null ? void 0 : a.traverseTHREEObject) != null ? d : !0;
let r = v(e);
const s = [];
r.forEach((i) => {
i instanceof HTMLElement ? s.push(i) : i.isObject3D && (t ? (s.push(i), i.traverse((u) => {
u && s.push(u);
})) : s.push(i));
}), r = [...new Set(s)], b(r);
const l = D(g({
targets: r,
duration: 300,
easing: "linear",
direction: "alternate",
loop: 4,
autoplay: !1,
update: (i) => {
var u;
i.animatables.forEach((L) => {
var M;
const p = L.target;
if (!c.has(p))
return;
const h = Number((M = c.get(p).opacity) != null ? M : 1) * (100 - i.progress) / 100;
p instanceof HTMLElement ? p.style.opacity = String(h) : p.material && (p.material.opacity = h, p.material.transparent = !0);
}), (u = a == null ? void 0 : a.updateRender) == null || u.call(a);
}
}, a)), f = T.get(e);
f == null || f.pause(), f == null || f.seek(0), T.set(e, l), l.play(), yield l.finished, k(r), (y = a == null ? void 0 : a.updateRender) == null || y.call(a);
});
}
function C(e, a) {
return E(this, null, function* () {
return N(e, g({
update: (t) => {
var r;
t.animatables.forEach((s) => {
var i, u;
const l = s.target;
if (!c.has(l))
return;
const f = c.get(l), y = ((u = (i = f == null ? void 0 : f.opacity) != null ? i : a == null ? void 0 : a.maxOpacity) != null ? u : 1) * (t.progress / 100);
l instanceof HTMLElement ? (l.style.opacity = String(y), l.style.visibility = "visible") : l.isObject3D && (v(e).includes(l) && (l.visible = !0), l.material && (l.material.opacity = y, l.material.transparent = !0));
}), (r = a == null ? void 0 : a.updateRender) == null || r.call(a);
}
}, a));
});
}
export {
N as blink,
C as reblink
};