overlayscrollbars-solid
Version:
OverlayScrollbars for Solid.
100 lines (99 loc) • 2.76 kB
JavaScript
import { createComponent as g, Dynamic as h, mergeProps as C, memo as I, getNextElement as w, use as A, insert as E, template as P } from "solid-js/web";
import { createRenderEffect as p, onCleanup as b, splitProps as R, mergeProps as S, createSignal as y, children as q, createEffect as D } from "solid-js";
import { OverlayScrollbars as m } from "overlayscrollbars";
const F = () => {
if (typeof window > "u") {
const i = () => {
};
return [i, i];
}
let t, e;
const o = window, l = typeof o.requestIdleCallback == "function", s = o.requestAnimationFrame, a = o.cancelAnimationFrame, d = l ? o.requestIdleCallback : s, n = l ? o.cancelIdleCallback : a, c = () => {
n(t), a(e);
};
return [
(i, r) => {
c(), t = d(
l ? () => {
c(), e = s(i);
} : i,
typeof r == "object" ? r : { timeout: 2233 }
);
},
c
];
}, O = (t) => typeof t == "function", f = (t) => O(t) ? t() : t, $ = (t) => {
let e = null, o, l, s;
const [a, d] = F();
return p(() => {
var n;
s = f((n = f(t)) == null ? void 0 : n.defer);
}), p(() => {
var n;
o = f((n = f(t)) == null ? void 0 : n.options), m.valid(e) && e.options(o || {}, !0);
}), p(() => {
var n;
l = f((n = f(t)) == null ? void 0 : n.events), m.valid(e) && e.on(l || {}, !0);
}), b(() => {
d(), e == null || e.destroy();
}), [
(n) => {
if (m.valid(e))
return e;
const c = () => e = m(n, o || {}, l || {});
s ? a(c, s) : c();
},
() => e
];
};
var k = /* @__PURE__ */ P('<div data-overlayscrollbars-contents="">');
const N = (t) => {
const [e, o] = R(S({
element: "div"
}, t), ["element", "options", "events", "defer", "ref", "children"]), [l, s] = y(), [a, d] = y(), [n, c] = $(e), i = q(() => e.children);
return D(() => {
const r = l(), u = a();
r && (n(e.element === "body" ? {
target: r,
cancel: {
body: null
}
} : {
target: r,
elements: {
viewport: u,
content: u
}
}), b(() => {
var v;
(v = c()) == null || v.destroy();
}));
}), p(() => {
const r = {
osInstance: c,
getElement: () => (
/* c8 ignore next */
l() || null
)
};
typeof e.ref == "function" ? e.ref(r) : e.ref = r;
}), g(h, C({
get component() {
return e.element;
},
"data-overlayscrollbars-initialize": "",
ref: s
}, o, {
get children() {
return I(() => e.element === "body")() ? i() : (() => {
var r = w(k);
return A(d, r), E(r, i), r;
})();
}
}));
};
export {
N as OverlayScrollbarsComponent,
$ as createOverlayScrollbars
};
//# sourceMappingURL=overlayscrollbars-solid.mjs.map