UNPKG

overlayscrollbars

Version:

A javascript scrollbar plugin that hides the native scrollbars, provides custom styleable overlay scrollbars, and preserves the native functionality and feel.

2,064 lines (1,851 loc) 69.4 kB
/*! * OverlayScrollbars * Version: 2.10.0 * * Copyright (c) Rene Haas | KingSora. * https://github.com/KingSora * * Released under the MIT license. */ const createCache = (t, n) => { const {o: o, i: s, u: e} = t; let c = o; let r; const cacheUpdateContextual = (t, n) => { const o = c; const l = t; const i = n || (s ? !s(o, l) : o !== l); if (i || e) { c = l; r = o; } return [ c, i, r ]; }; const cacheUpdateIsolated = t => cacheUpdateContextual(n(c, r), t); const getCurrentCache = t => [ c, !!t, r ]; return [ n ? cacheUpdateIsolated : cacheUpdateContextual, getCurrentCache ]; }; const t = typeof window !== "undefined" && typeof HTMLElement !== "undefined" && !!window.document; const n = t ? window : {}; const o = Math.max; const s = Math.min; const e = Math.round; const c = Math.abs; const r = Math.sign; const l = n.cancelAnimationFrame; const i = n.requestAnimationFrame; const a = n.setTimeout; const u = n.clearTimeout; const getApi = t => typeof n[t] !== "undefined" ? n[t] : void 0; const _ = getApi("MutationObserver"); const d = getApi("IntersectionObserver"); const f = getApi("ResizeObserver"); const v = getApi("ScrollTimeline"); const isUndefined = t => t === void 0; const isNull = t => t === null; const isNumber = t => typeof t === "number"; const isString = t => typeof t === "string"; const isBoolean = t => typeof t === "boolean"; const isFunction = t => typeof t === "function"; const isArray = t => Array.isArray(t); const isObject = t => typeof t === "object" && !isArray(t) && !isNull(t); const isArrayLike = t => { const n = !!t && t.length; const o = isNumber(n) && n > -1 && n % 1 == 0; return isArray(t) || !isFunction(t) && o ? n > 0 && isObject(t) ? n - 1 in t : true : false; }; const isPlainObject = t => !!t && t.constructor === Object; const isHTMLElement = t => t instanceof HTMLElement; const isElement = t => t instanceof Element; const animationCurrentTime = () => performance.now(); const animateNumber = (t, n, s, e, c) => { let r = 0; const a = animationCurrentTime(); const u = o(0, s); const frame = s => { const l = animationCurrentTime(); const _ = l - a; const d = _ >= u; const f = s ? 1 : 1 - (o(0, a + u - l) / u || 0); const v = (n - t) * (isFunction(c) ? c(f, f * u, 0, 1, u) : f) + t; const p = d || f === 1; e && e(v, f, p); r = p ? 0 : i((() => frame())); }; frame(); return t => { l(r); t && frame(t); }; }; function each(t, n) { if (isArrayLike(t)) { for (let o = 0; o < t.length; o++) { if (n(t[o], o, t) === false) { break; } } } else if (t) { each(Object.keys(t), (o => n(t[o], o, t))); } return t; } const inArray = (t, n) => t.indexOf(n) >= 0; const concat = (t, n) => t.concat(n); const push = (t, n, o) => { !o && !isString(n) && isArrayLike(n) ? Array.prototype.push.apply(t, n) : t.push(n); return t; }; const from = t => Array.from(t || []); const createOrKeepArray = t => { if (isArray(t)) { return t; } return !isString(t) && isArrayLike(t) ? from(t) : [ t ]; }; const isEmptyArray = t => !!t && !t.length; const deduplicateArray = t => from(new Set(t)); const runEachAndClear = (t, n, o) => { const runFn = t => t ? t.apply(void 0, n || []) : true; each(t, runFn); !o && (t.length = 0); }; const p = "paddingTop"; const h = "paddingRight"; const g = "paddingLeft"; const b = "paddingBottom"; const w = "marginLeft"; const y = "marginRight"; const S = "marginBottom"; const m = "overflowX"; const O = "overflowY"; const $ = "width"; const C = "height"; const x = "visible"; const H = "hidden"; const E = "scroll"; const capitalizeFirstLetter = t => { const n = String(t || ""); return n ? n[0].toUpperCase() + n.slice(1) : ""; }; const equal = (t, n, o, s) => { if (t && n) { let e = true; each(o, (o => { const c = s ? s(t[o]) : t[o]; const r = s ? s(n[o]) : n[o]; if (c !== r) { e = false; } })); return e; } return false; }; const equalWH = (t, n) => equal(t, n, [ "w", "h" ]); const equalXY = (t, n) => equal(t, n, [ "x", "y" ]); const equalTRBL = (t, n) => equal(t, n, [ "t", "r", "b", "l" ]); const noop = () => {}; const bind = (t, ...n) => t.bind(0, ...n); const selfClearTimeout = t => { let n; const o = t ? a : i; const s = t ? u : l; return [ e => { s(n); n = o((() => e()), isFunction(t) ? t() : t); }, () => s(n) ]; }; const debounce = (t, n) => { const {_: o, v: s, p: e, S: c} = n || {}; let r; let _; let d; let f; let v = noop; const p = function invokeFunctionToDebounce(n) { v(); u(r); f = r = _ = void 0; v = noop; t.apply(this, n); }; const mergeParms = t => c && _ ? c(_, t) : t; const flush = () => { if (v !== noop) { p(mergeParms(d) || d); } }; const h = function debouncedFn() { const t = from(arguments); const n = isFunction(o) ? o() : o; const c = isNumber(n) && n >= 0; if (c) { const o = isFunction(s) ? s() : s; const c = isNumber(o) && o >= 0; const h = n > 0 ? a : i; const g = n > 0 ? u : l; const b = mergeParms(t); const w = b || t; const y = p.bind(0, w); let S; v(); if (e && !f) { y(); f = true; S = h((() => f = void 0), n); } else { S = h(y, n); if (c && !r) { r = a(flush, o); } } v = () => g(S); _ = d = w; } else { p(t); } }; h.m = flush; return h; }; const hasOwnProperty = (t, n) => Object.prototype.hasOwnProperty.call(t, n); const keys = t => t ? Object.keys(t) : []; const assignDeep = (t, n, o, s, e, c, r) => { const l = [ n, o, s, e, c, r ]; if ((typeof t !== "object" || isNull(t)) && !isFunction(t)) { t = {}; } each(l, (n => { each(n, ((o, s) => { const e = n[s]; if (t === e) { return true; } const c = isArray(e); if (e && isPlainObject(e)) { const n = t[s]; let o = n; if (c && !isArray(n)) { o = []; } else if (!c && !isPlainObject(n)) { o = {}; } t[s] = assignDeep(o, e); } else { t[s] = c ? e.slice() : e; } })); })); return t; }; const removeUndefinedProperties = (t, n) => each(assignDeep({}, t), ((t, o, s) => { if (t === void 0) { delete s[o]; } else if (n && t && isPlainObject(t)) { s[o] = removeUndefinedProperties(t, n); } })); const isEmptyObject = t => !keys(t).length; const capNumber = (t, n, e) => o(t, s(n, e)); const getDomTokensArray = t => deduplicateArray((isArray(t) ? t : (t || "").split(" ")).filter((t => t))); const getAttr = (t, n) => t && t.getAttribute(n); const hasAttr = (t, n) => t && t.hasAttribute(n); const setAttrs = (t, n, o) => { each(getDomTokensArray(n), (n => { t && t.setAttribute(n, String(o || "")); })); }; const removeAttrs = (t, n) => { each(getDomTokensArray(n), (n => t && t.removeAttribute(n))); }; const domTokenListAttr = (t, n) => { const o = getDomTokensArray(getAttr(t, n)); const s = bind(setAttrs, t, n); const domTokenListOperation = (t, n) => { const s = new Set(o); each(getDomTokensArray(t), (t => { s[n](t); })); return from(s).join(" "); }; return { O: t => s(domTokenListOperation(t, "delete")), $: t => s(domTokenListOperation(t, "add")), C: t => { const n = getDomTokensArray(t); return n.reduce(((t, n) => t && o.includes(n)), n.length > 0); } }; }; const removeAttrClass = (t, n, o) => { domTokenListAttr(t, n).O(o); return bind(addAttrClass, t, n, o); }; const addAttrClass = (t, n, o) => { domTokenListAttr(t, n).$(o); return bind(removeAttrClass, t, n, o); }; const addRemoveAttrClass = (t, n, o, s) => (s ? addAttrClass : removeAttrClass)(t, n, o); const hasAttrClass = (t, n, o) => domTokenListAttr(t, n).C(o); const createDomTokenListClass = t => domTokenListAttr(t, "class"); const removeClass = (t, n) => { createDomTokenListClass(t).O(n); }; const addClass = (t, n) => { createDomTokenListClass(t).$(n); return bind(removeClass, t, n); }; const find = (t, n) => { const o = n ? isElement(n) && n : document; return o ? from(o.querySelectorAll(t)) : []; }; const findFirst = (t, n) => { const o = n ? isElement(n) && n : document; return o && o.querySelector(t); }; const is = (t, n) => isElement(t) && t.matches(n); const isBodyElement = t => is(t, "body"); const contents = t => t ? from(t.childNodes) : []; const parent = t => t && t.parentElement; const closest = (t, n) => isElement(t) && t.closest(n); const getFocusedElement = t => (t || document).activeElement; const liesBetween = (t, n, o) => { const s = closest(t, n); const e = t && findFirst(o, s); const c = closest(e, n) === s; return s && e ? s === t || e === t || c && closest(closest(t, o), n) !== s : false; }; const removeElements = t => { each(createOrKeepArray(t), (t => { const n = parent(t); t && n && n.removeChild(t); })); }; const appendChildren = (t, n) => bind(removeElements, t && n && each(createOrKeepArray(n), (n => { n && t.appendChild(n); }))); const createDiv = t => { const n = document.createElement("div"); setAttrs(n, "class", t); return n; }; const createDOM = t => { const n = createDiv(); n.innerHTML = t.trim(); return each(contents(n), (t => removeElements(t))); }; const getCSSVal = (t, n) => t.getPropertyValue(n) || t[n] || ""; const validFiniteNumber = t => { const n = t || 0; return isFinite(n) ? n : 0; }; const parseToZeroOrNumber = t => validFiniteNumber(parseFloat(t || "")); const roundCssNumber = t => Math.round(t * 1e4) / 1e4; const numberToCssPx = t => `${roundCssNumber(validFiniteNumber(t))}px`; function setStyles(t, n) { t && n && each(n, ((n, o) => { try { const s = t.style; const e = isNull(n) || isBoolean(n) ? "" : isNumber(n) ? numberToCssPx(n) : n; if (o.indexOf("--") === 0) { s.setProperty(o, e); } else { s[o] = e; } } catch (s) {} })); } function getStyles(t, o, s) { const e = isString(o); let c = e ? "" : {}; if (t) { const r = n.getComputedStyle(t, s) || t.style; c = e ? getCSSVal(r, o) : from(o).reduce(((t, n) => { t[n] = getCSSVal(r, n); return t; }), c); } return c; } const topRightBottomLeft = (t, n, o) => { const s = n ? `${n}-` : ""; const e = o ? `-${o}` : ""; const c = `${s}top${e}`; const r = `${s}right${e}`; const l = `${s}bottom${e}`; const i = `${s}left${e}`; const a = getStyles(t, [ c, r, l, i ]); return { t: parseToZeroOrNumber(a[c]), r: parseToZeroOrNumber(a[r]), b: parseToZeroOrNumber(a[l]), l: parseToZeroOrNumber(a[i]) }; }; const getTrasformTranslateValue = (t, n) => `translate${isObject(t) ? `(${t.x},${t.y})` : `${n ? "X" : "Y"}(${t})`}`; const elementHasDimensions = t => !!(t.offsetWidth || t.offsetHeight || t.getClientRects().length); const z = { w: 0, h: 0 }; const getElmWidthHeightProperty = (t, n) => n ? { w: n[`${t}Width`], h: n[`${t}Height`] } : z; const getWindowSize = t => getElmWidthHeightProperty("inner", t || n); const I = bind(getElmWidthHeightProperty, "offset"); const A = bind(getElmWidthHeightProperty, "client"); const D = bind(getElmWidthHeightProperty, "scroll"); const getFractionalSize = t => { const n = parseFloat(getStyles(t, $)) || 0; const o = parseFloat(getStyles(t, C)) || 0; return { w: n - e(n), h: o - e(o) }; }; const getBoundingClientRect = t => t.getBoundingClientRect(); const hasDimensions = t => !!t && elementHasDimensions(t); const domRectHasDimensions = t => !!(t && (t[C] || t[$])); const domRectAppeared = (t, n) => { const o = domRectHasDimensions(t); const s = domRectHasDimensions(n); return !s && o; }; const removeEventListener = (t, n, o, s) => { each(getDomTokensArray(n), (n => { t && t.removeEventListener(n, o, s); })); }; const addEventListener = (t, n, o, s) => { var e; const c = (e = s && s.H) != null ? e : true; const r = s && s.I || false; const l = s && s.A || false; const i = { passive: c, capture: r }; return bind(runEachAndClear, getDomTokensArray(n).map((n => { const s = l ? e => { removeEventListener(t, n, s, r); o && o(e); } : o; t && t.addEventListener(n, s, i); return bind(removeEventListener, t, n, s, r); }))); }; const stopPropagation = t => t.stopPropagation(); const preventDefault = t => t.preventDefault(); const stopAndPrevent = t => stopPropagation(t) || preventDefault(t); const scrollElementTo = (t, n) => { const {x: o, y: s} = isNumber(n) ? { x: n, y: n } : n || {}; isNumber(o) && (t.scrollLeft = o); isNumber(s) && (t.scrollTop = s); }; const getElementScroll = t => ({ x: t.scrollLeft, y: t.scrollTop }); const getZeroScrollCoordinates = () => ({ D: { x: 0, y: 0 }, M: { x: 0, y: 0 } }); const sanitizeScrollCoordinates = (t, n) => { const {D: o, M: s} = t; const {w: e, h: l} = n; const sanitizeAxis = (t, n, o) => { let s = r(t) * o; let e = r(n) * o; if (s === e) { const o = c(t); const r = c(n); e = o > r ? 0 : e; s = o < r ? 0 : s; } s = s === e ? 0 : s; return [ s + 0, e + 0 ]; }; const [i, a] = sanitizeAxis(o.x, s.x, e); const [u, _] = sanitizeAxis(o.y, s.y, l); return { D: { x: i, y: u }, M: { x: a, y: _ } }; }; const isDefaultDirectionScrollCoordinates = ({D: t, M: n}) => { const getAxis = (t, n) => t === 0 && t <= n; return { x: getAxis(t.x, n.x), y: getAxis(t.y, n.y) }; }; const getScrollCoordinatesPercent = ({D: t, M: n}, o) => { const getAxis = (t, n, o) => capNumber(0, 1, (t - o) / (t - n) || 0); return { x: getAxis(t.x, n.x, o.x), y: getAxis(t.y, n.y, o.y) }; }; const focusElement = t => { if (t && t.focus) { t.focus({ preventScroll: true }); } }; const manageListener = (t, n) => { each(createOrKeepArray(n), t); }; const createEventListenerHub = t => { const n = new Map; const removeEvent = (t, o) => { if (t) { const s = n.get(t); manageListener((t => { if (s) { s[t ? "delete" : "clear"](t); } }), o); } else { n.forEach((t => { t.clear(); })); n.clear(); } }; const addEvent = (t, o) => { if (isString(t)) { const s = n.get(t) || new Set; n.set(t, s); manageListener((t => { isFunction(t) && s.add(t); }), o); return bind(removeEvent, t, o); } if (isBoolean(o) && o) { removeEvent(); } const s = keys(t); const e = []; each(s, (n => { const o = t[n]; o && push(e, addEvent(n, o)); })); return bind(runEachAndClear, e); }; const triggerEvent = (t, o) => { each(from(n.get(t)), (t => { if (o && !isEmptyArray(o)) { t.apply(0, o); } else { t(); } })); }; addEvent(t || {}); return [ addEvent, removeEvent, triggerEvent ]; }; const opsStringify = t => JSON.stringify(t, ((t, n) => { if (isFunction(n)) { throw 0; } return n; })); const getPropByPath = (t, n) => t ? `${n}`.split(".").reduce(((t, n) => t && hasOwnProperty(t, n) ? t[n] : void 0), t) : void 0; const M = { paddingAbsolute: false, showNativeOverlaidScrollbars: false, update: { elementEvents: [ [ "img", "load" ] ], debounce: [ 0, 33 ], attributes: null, ignoreMutation: null }, overflow: { x: "scroll", y: "scroll" }, scrollbars: { theme: "os-theme-dark", visibility: "auto", autoHide: "never", autoHideDelay: 1300, autoHideSuspend: false, dragScroll: true, clickScroll: false, pointers: [ "mouse", "touch", "pen" ] } }; const getOptionsDiff = (t, n) => { const o = {}; const s = concat(keys(n), keys(t)); each(s, (s => { const e = t[s]; const c = n[s]; if (isObject(e) && isObject(c)) { assignDeep(o[s] = {}, getOptionsDiff(e, c)); if (isEmptyObject(o[s])) { delete o[s]; } } else if (hasOwnProperty(n, s) && c !== e) { let t = true; if (isArray(e) || isArray(c)) { try { if (opsStringify(e) === opsStringify(c)) { t = false; } } catch (r) {} } if (t) { o[s] = c; } } })); return o; }; const createOptionCheck = (t, n, o) => s => [ getPropByPath(t, s), o || getPropByPath(n, s) !== void 0 ]; const T = `data-overlayscrollbars`; const k = "os-environment"; const R = `${k}-scrollbar-hidden`; const V = `${T}-initialize`; const L = "noClipping"; const U = `${T}-body`; const P = T; const N = "host"; const q = `${T}-viewport`; const B = m; const F = O; const j = "arrange"; const X = "measuring"; const Y = "scrolling"; const W = "scrollbarHidden"; const J = "noContent"; const G = `${T}-padding`; const K = `${T}-content`; const Q = "os-size-observer"; const Z = `${Q}-appear`; const tt = `${Q}-listener`; const nt = `${tt}-scroll`; const ot = `${tt}-item`; const st = `${ot}-final`; const et = "os-trinsic-observer"; const ct = "os-theme-none"; const rt = "os-scrollbar"; const lt = `${rt}-rtl`; const it = `${rt}-horizontal`; const at = `${rt}-vertical`; const ut = `${rt}-track`; const _t = `${rt}-handle`; const dt = `${rt}-visible`; const ft = `${rt}-cornerless`; const vt = `${rt}-interaction`; const pt = `${rt}-unusable`; const ht = `${rt}-auto-hide`; const gt = `${ht}-hidden`; const bt = `${rt}-wheel`; const wt = `${ut}-interactive`; const yt = `${_t}-interactive`; let St; const getNonce = () => St; const setNonce = t => { St = t; }; let mt; const createEnvironment = () => { const getNativeScrollbarSize = (t, n, o) => { appendChildren(document.body, t); appendChildren(document.body, t); const s = A(t); const e = I(t); const c = getFractionalSize(n); o && removeElements(t); return { x: e.h - s.h + c.h, y: e.w - s.w + c.w }; }; const getNativeScrollbarsHiding = t => { let n = false; const o = addClass(t, R); try { n = getStyles(t, "scrollbar-width") === "none" || getStyles(t, "display", "::-webkit-scrollbar") === "none"; } catch (s) {} o(); return n; }; const t = `.${k}{scroll-behavior:auto!important;position:fixed;opacity:0;visibility:hidden;overflow:scroll;height:200px;width:200px;z-index:-1}.${k} div{width:200%;height:200%;margin:10px 0}.${R}{scrollbar-width:none!important}.${R}::-webkit-scrollbar,.${R}::-webkit-scrollbar-corner{appearance:none!important;display:none!important;width:0!important;height:0!important}`; const o = createDOM(`<div class="${k}"><div></div><style>${t}</style></div>`); const s = o[0]; const e = s.firstChild; const c = s.lastChild; const r = getNonce(); if (r) { c.nonce = r; } const [l, , i] = createEventListenerHub(); const [a, u] = createCache({ o: getNativeScrollbarSize(s, e), i: equalXY }, bind(getNativeScrollbarSize, s, e, true)); const [_] = u(); const d = getNativeScrollbarsHiding(s); const f = { x: _.x === 0, y: _.y === 0 }; const p = { elements: { host: null, padding: !d, viewport: t => d && isBodyElement(t) && t, content: false }, scrollbars: { slot: true }, cancel: { nativeScrollbarsOverlaid: false, body: null } }; const h = assignDeep({}, M); const g = bind(assignDeep, {}, h); const b = bind(assignDeep, {}, p); const w = { T: _, k: f, R: d, V: !!v, L: bind(l, "r"), U: b, P: t => assignDeep(p, t) && b(), N: g, q: t => assignDeep(h, t) && g(), B: assignDeep({}, p), F: assignDeep({}, h) }; removeAttrs(s, "style"); removeElements(s); addEventListener(n, "resize", (() => { i("r", []); })); if (isFunction(n.matchMedia) && !d && (!f.x || !f.y)) { const addZoomListener = t => { const o = n.matchMedia(`(resolution: ${n.devicePixelRatio}dppx)`); addEventListener(o, "change", (() => { t(); addZoomListener(t); }), { A: true }); }; addZoomListener((() => { const [t, n] = a(); assignDeep(w.T, t); i("r", [ n ]); })); } return w; }; const getEnvironment = () => { if (!mt) { mt = createEnvironment(); } return mt; }; const resolveInitialization = (t, n) => isFunction(n) ? n.apply(0, t) : n; const staticInitializationElement = (t, n, o, s) => { const e = isUndefined(s) ? o : s; const c = resolveInitialization(t, e); return c || n.apply(0, t); }; const dynamicInitializationElement = (t, n, o, s) => { const e = isUndefined(s) ? o : s; const c = resolveInitialization(t, e); return !!c && (isHTMLElement(c) ? c : n.apply(0, t)); }; const cancelInitialization = (t, n) => { const {nativeScrollbarsOverlaid: o, body: s} = n || {}; const {k: e, R: c, U: r} = getEnvironment(); const {nativeScrollbarsOverlaid: l, body: i} = r().cancel; const a = o != null ? o : l; const u = isUndefined(s) ? i : s; const _ = (e.x || e.y) && a; const d = t && (isNull(u) ? !c : u); return !!_ || !!d; }; const Ot = new WeakMap; const addInstance = (t, n) => { Ot.set(t, n); }; const removeInstance = t => { Ot.delete(t); }; const getInstance = t => Ot.get(t); const createEventContentChange = (t, n, o) => { let s = false; const e = o ? new WeakMap : false; const destroy = () => { s = true; }; const updateElements = c => { if (e && o) { const r = o.map((n => { const [o, s] = n || []; const e = s && o ? (c || find)(o, t) : []; return [ e, s ]; })); each(r, (o => each(o[0], (c => { const r = o[1]; const l = e.get(c) || []; const i = t.contains(c); if (i && r) { const t = addEventListener(c, r, (o => { if (s) { t(); e.delete(c); } else { n(o); } })); e.set(c, push(l, t)); } else { runEachAndClear(l); e.delete(c); } })))); } }; updateElements(); return [ destroy, updateElements ]; }; const createDOMObserver = (t, n, o, s) => { let e = false; const {j: c, X: r, Y: l, W: i, J: a, G: u} = s || {}; const d = debounce((() => e && o(true)), { _: 33, v: 99 }); const [f, v] = createEventContentChange(t, d, l); const p = c || []; const h = r || []; const g = concat(p, h); const observerCallback = (e, c) => { if (!isEmptyArray(c)) { const r = a || noop; const l = u || noop; const _ = []; const d = []; let f = false; let p = false; each(c, (o => { const {attributeName: e, target: c, type: a, oldValue: u, addedNodes: v, removedNodes: g} = o; const b = a === "attributes"; const w = a === "childList"; const y = t === c; const S = b && e; const m = S && getAttr(c, e || ""); const O = isString(m) ? m : null; const $ = S && u !== O; const C = inArray(h, e) && $; if (n && (w || !y)) { const n = b && $; const a = n && i && is(c, i); const d = a ? !r(c, e, u, O) : !b || n; const f = d && !l(o, !!a, t, s); each(v, (t => push(_, t))); each(g, (t => push(_, t))); p = p || f; } if (!n && y && $ && !r(c, e, u, O)) { push(d, e); f = f || C; } })); v((t => deduplicateArray(_).reduce(((n, o) => { push(n, find(t, o)); return is(o, t) ? push(n, o) : n; }), []))); if (n) { !e && p && o(false); return [ false ]; } if (!isEmptyArray(d) || f) { const t = [ deduplicateArray(d), f ]; !e && o.apply(0, t); return t; } } }; const b = new _(bind(observerCallback, false)); return [ () => { b.observe(t, { attributes: true, attributeOldValue: true, attributeFilter: g, subtree: n, childList: n, characterData: n }); e = true; return () => { if (e) { f(); b.disconnect(); e = false; } }; }, () => { if (e) { d.m(); return observerCallback(true, b.takeRecords()); } } ]; }; const $t = {}; const Ct = {}; const addPlugins = t => { each(t, (t => each(t, ((n, o) => { $t[o] = t[o]; })))); }; const registerPluginModuleInstances = (t, n, o) => keys(t).map((s => { const {static: e, instance: c} = t[s]; const [r, l, i] = o || []; const a = o ? c : e; if (a) { const t = o ? a(r, l, n) : a(n); return (i || Ct)[s] = t; } })); const getStaticPluginModuleInstance = t => Ct[t]; const xt = "__osOptionsValidationPlugin"; const Ht = "__osSizeObserverPlugin"; const Et = /* @__PURE__ */ (() => ({ [Ht]: { static: () => (t, n, o) => { const s = 3333333; const e = "scroll"; const c = createDOM(`<div class="${ot}" dir="ltr"><div class="${ot}"><div class="${st}"></div></div><div class="${ot}"><div class="${st}" style="width: 200%; height: 200%"></div></div></div>`); const r = c[0]; const a = r.lastChild; const u = r.firstChild; const _ = u == null ? void 0 : u.firstChild; let d = I(r); let f = d; let v = false; let p; const reset = () => { scrollElementTo(u, s); scrollElementTo(a, s); }; const onResized = t => { p = 0; if (v) { d = f; n(t === true); } }; const onScroll = t => { f = I(r); v = !t || !equalWH(f, d); if (t) { stopPropagation(t); if (v && !p) { l(p); p = i(onResized); } } else { onResized(t === false); } reset(); }; const h = [ appendChildren(t, c), addEventListener(u, e, onScroll), addEventListener(a, e, onScroll) ]; addClass(t, nt); setStyles(_, { [$]: s, [C]: s }); i(reset); return [ o ? bind(onScroll, false) : reset, h ]; } } }))(); const getShowNativeOverlaidScrollbars = (t, n) => { const {k: o} = n; const [s, e] = t("showNativeOverlaidScrollbars"); return [ s && o.x && o.y, e ]; }; const overflowIsVisible = t => t.indexOf(x) === 0; const createViewportOverflowState = (t, n) => { const getAxisOverflowStyle = (t, n, o, s) => { const e = t === x ? H : t.replace(`${x}-`, ""); const c = overflowIsVisible(t); const r = overflowIsVisible(o); if (!n && !s) { return H; } if (c && r) { return x; } if (c) { const t = n ? x : H; return n && s ? e : t; } const l = r && s ? x : H; return n ? e : l; }; const o = { x: getAxisOverflowStyle(n.x, t.x, n.y, t.y), y: getAxisOverflowStyle(n.y, t.y, n.x, t.x) }; return { K: o, Z: { x: o.x === E, y: o.y === E } }; }; const zt = "__osScrollbarsHidingPlugin"; const It = /* @__PURE__ */ (() => ({ [zt]: { static: () => ({ tt: (t, n, o, s, e) => { const {nt: c, ot: r} = t; const {R: l, k: i, T: a} = s; const u = !c && !l && (i.x || i.y); const [_] = getShowNativeOverlaidScrollbars(e, s); const readViewportOverflowState = () => { const getStatePerAxis = t => { const n = getStyles(r, t); const o = n === E; return [ n, o ]; }; const [t, n] = getStatePerAxis(m); const [o, s] = getStatePerAxis(O); return { K: { x: t, y: o }, Z: { x: n, y: s } }; }; const _getViewportOverflowHideOffset = t => { const {Z: n} = t; const o = l || _ ? 0 : 42; const getHideOffsetPerAxis = (t, n, s) => { const e = t ? o : s; const c = n && !l ? e : 0; const r = t && !!o; return [ c, r ]; }; const [s, e] = getHideOffsetPerAxis(i.x, n.x, a.x); const [c, r] = getHideOffsetPerAxis(i.y, n.y, a.y); return { st: { x: s, y: c }, et: { x: e, y: r } }; }; const _hideNativeScrollbars = (t, {ct: o}, s) => { if (!c) { const e = assignDeep({}, { [y]: 0, [S]: 0, [w]: 0 }); const {st: c, et: r} = _getViewportOverflowHideOffset(t); const {x: l, y: i} = r; const {x: a, y: u} = c; const {rt: _} = n; const d = o ? w : y; const f = o ? g : h; const v = _[d]; const p = _[S]; const m = _[f]; const O = _[b]; e[$] = `calc(100% + ${u + v * -1}px)`; e[d] = -u + v; e[S] = -a + p; if (s) { e[f] = m + (i ? u : 0); e[b] = O + (l ? a : 0); } return e; } }; const _arrangeViewport = (t, s, e) => { if (u) { const {rt: c} = n; const {st: l, et: i} = _getViewportOverflowHideOffset(t); const {x: a, y: u} = i; const {x: _, y: d} = l; const {ct: f} = o; const v = f ? h : g; const p = c[v]; const b = c.paddingTop; const w = s.w + e.w; const y = s.h + e.h; const S = { w: d && u ? `${d + w - p}px` : "", h: _ && a ? `${_ + y - b}px` : "" }; setStyles(r, { "--os-vaw": S.w, "--os-vah": S.h }); } return u; }; const _undoViewportArrange = t => { if (u) { const s = t || readViewportOverflowState(); const {rt: e} = n; const {et: c} = _getViewportOverflowHideOffset(s); const {x: l, y: i} = c; const a = {}; const assignProps = t => each(t, (t => { a[t] = e[t]; })); if (l) { assignProps([ S, p, b ]); } if (i) { assignProps([ w, y, g, h ]); } const _ = getStyles(r, keys(a)); const d = removeAttrClass(r, q, j); setStyles(r, a); return [ () => { setStyles(r, assignDeep({}, _, _hideNativeScrollbars(s, o, u))); d(); }, s ]; } return [ noop ]; }; return { lt: _getViewportOverflowHideOffset, it: _arrangeViewport, ut: _undoViewportArrange, _t: _hideNativeScrollbars }; } }) } }))(); const At = "__osClickScrollPlugin"; const Dt = /* @__PURE__ */ (() => ({ [At]: { static: () => (t, n, o, s) => { let e = false; let c = noop; const r = 133; const l = 222; const [i, a] = selfClearTimeout(r); const u = Math.sign(n); const _ = o * u; const d = _ / 2; const easing = t => 1 - (1 - t) * (1 - t); const easedEndPressAnimation = (n, o) => animateNumber(n, o, l, t, easing); const linearPressAnimation = (o, s) => animateNumber(o, n - _, r * s, ((o, s, e) => { t(o); if (e) { c = easedEndPressAnimation(o, n); } })); const f = animateNumber(0, _, l, ((r, l, a) => { t(r); if (a) { s(e); if (!e) { const t = n - r; const s = Math.sign(t - d) === u; s && i((() => { const s = t - _; const e = Math.sign(s) === u; c = e ? linearPressAnimation(r, Math.abs(s) / o) : easedEndPressAnimation(r, n); })); } } }), easing); return t => { e = true; if (t) { f(); } a(); c(); }; } } }))(); const createSizeObserver = (t, n, o) => { const {dt: s} = o || {}; const e = getStaticPluginModuleInstance(Ht); const [c] = createCache({ o: false, u: true }); return () => { const o = []; const r = createDOM(`<div class="${Q}"><div class="${tt}"></div></div>`); const l = r[0]; const i = l.firstChild; const onSizeChangedCallbackProxy = t => { const o = t instanceof ResizeObserverEntry; let s = false; let e = false; if (o) { const [n, , o] = c(t.contentRect); const r = domRectHasDimensions(n); e = domRectAppeared(n, o); s = !e && !r; } else { e = t === true; } if (!s) { n({ ft: true, dt: e }); } }; if (f) { const t = new f((t => onSizeChangedCallbackProxy(t.pop()))); t.observe(i); push(o, (() => { t.disconnect(); })); } else if (e) { const [t, n] = e(i, onSizeChangedCallbackProxy, s); push(o, concat([ addClass(l, Z), addEventListener(l, "animationstart", t) ], n)); } else { return noop; } return bind(runEachAndClear, push(o, appendChildren(t, l))); }; }; const createTrinsicObserver = (t, n) => { let o; const isHeightIntrinsic = t => t.h === 0 || t.isIntersecting || t.intersectionRatio > 0; const s = createDiv(et); const [e] = createCache({ o: false }); const triggerOnTrinsicChangedCallback = (t, o) => { if (t) { const s = e(isHeightIntrinsic(t)); const [, c] = s; return c && !o && n(s) && [ s ]; } }; const intersectionObserverCallback = (t, n) => triggerOnTrinsicChangedCallback(n.pop(), t); return [ () => { const n = []; if (d) { o = new d(bind(intersectionObserverCallback, false), { root: t }); o.observe(s); push(n, (() => { o.disconnect(); })); } else { const onSizeChanged = () => { const t = I(s); triggerOnTrinsicChangedCallback(t); }; push(n, createSizeObserver(s, onSizeChanged)()); onSizeChanged(); } return bind(runEachAndClear, push(n, appendChildren(t, s))); }, () => o && intersectionObserverCallback(true, o.takeRecords()) ]; }; const createObserversSetup = (t, n, o, s) => { let e; let c; let r; let l; let i; let a; const u = `[${P}]`; const _ = `[${q}]`; const d = [ "id", "class", "style", "open", "wrap", "cols", "rows" ]; const {vt: v, ht: p, ot: h, gt: g, bt: b, nt: w, wt: y, yt: S, St: m, Ot: O} = t; const getDirectionIsRTL = t => getStyles(t, "direction") === "rtl"; const $ = { $t: false, ct: getDirectionIsRTL(v) }; const C = getEnvironment(); const x = getStaticPluginModuleInstance(zt); const [H] = createCache({ i: equalWH, o: { w: 0, h: 0 } }, (() => { const s = x && x.tt(t, n, $, C, o).ut; const e = y && w; const c = !e && hasAttrClass(p, P, L); const r = !w && S(j); const l = r && getElementScroll(g); const i = l && O(); const a = m(X, c); const u = r && s && s()[0]; const _ = D(h); const d = getFractionalSize(h); u && u(); scrollElementTo(g, l); i && i(); c && a(); return { w: _.w + d.w, h: _.h + d.h }; })); const E = debounce(s, { _: () => e, v: () => c, S(t, n) { const [o] = t; const [s] = n; return [ concat(keys(o), keys(s)).reduce(((t, n) => { t[n] = o[n] || s[n]; return t; }), {}) ]; } }); const setDirection = t => { const n = getDirectionIsRTL(v); assignDeep(t, { Ct: a !== n }); assignDeep($, { ct: n }); a = n; }; const onTrinsicChanged = (t, n) => { const [o, e] = t; const c = { xt: e }; assignDeep($, { $t: o }); !n && s(c); return c; }; const onSizeChanged = ({ft: t, dt: n}) => { const o = t && !n; const e = !o && C.R ? E : s; const c = { ft: t || n, dt: n }; setDirection(c); e(c); }; const onContentMutation = (t, n) => { const [, o] = H(); const e = { Ht: o }; setDirection(e); const c = t ? s : E; o && !n && c(e); return e; }; const onHostMutation = (t, n, o) => { const s = { Et: n }; setDirection(s); if (n && !o) { E(s); } return s; }; const [z, I] = b ? createTrinsicObserver(p, onTrinsicChanged) : []; const A = !w && createSizeObserver(p, onSizeChanged, { dt: true }); const [M, T] = createDOMObserver(p, false, onHostMutation, { X: d, j: d }); const k = w && f && new f((t => { const n = t[t.length - 1].contentRect; onSizeChanged({ ft: true, dt: domRectAppeared(n, i) }); i = n; })); const R = debounce((() => { const [, t] = H(); s({ Ht: t }); }), { _: 222, p: true }); return [ () => { k && k.observe(p); const t = A && A(); const n = z && z(); const o = M(); const s = C.L((t => { if (t) { E({ zt: t }); } else { R(); } })); return () => { k && k.disconnect(); t && t(); n && n(); l && l(); o(); s(); }; }, ({It: t, At: n, Dt: o}) => { const s = {}; const [i] = t("update.ignoreMutation"); const [a, f] = t("update.attributes"); const [v, p] = t("update.elementEvents"); const [g, y] = t("update.debounce"); const S = p || f; const m = n || o; const ignoreMutationFromOptions = t => isFunction(i) && i(t); if (S) { r && r(); l && l(); const [t, n] = createDOMObserver(b || h, true, onContentMutation, { j: concat(d, a || []), Y: v, W: u, G: (t, n) => { const {target: o, attributeName: s} = t; const e = !n && s && !w ? liesBetween(o, u, _) : false; return e || !!closest(o, `.${rt}`) || !!ignoreMutationFromOptions(t); } }); l = t(); r = n; } if (y) { E.m(); if (isArray(g)) { const t = g[0]; const n = g[1]; e = isNumber(t) && t; c = isNumber(n) && n; } else if (isNumber(g)) { e = g; c = false; } else { e = false; c = false; } } if (m) { const t = T(); const n = I && I(); const o = r && r(); t && assignDeep(s, onHostMutation(t[0], t[1], m)); n && assignDeep(s, onTrinsicChanged(n[0], m)); o && assignDeep(s, onContentMutation(o[0], m)); } setDirection(s); return s; }, $ ]; }; const createScrollbarsSetupElements = (t, n, o, s) => { const e = "--os-viewport-percent"; const c = "--os-scroll-percent"; const r = "--os-scroll-direction"; const {U: l} = getEnvironment(); const {scrollbars: i} = l(); const {slot: a} = i; const {vt: u, ht: _, ot: d, Mt: f, gt: p, wt: h, nt: g} = n; const {scrollbars: b} = f ? {} : t; const {slot: w} = b || {}; const y = []; const S = []; const m = []; const O = dynamicInitializationElement([ u, _, d ], (() => g && h ? u : _), a, w); const initScrollTimeline = t => { if (v) { const n = new v({ source: p, axis: t }); const _addScrollPercentAnimation = t => { const o = t.Tt.animate({ clear: [ "left" ], [c]: [ 0, 1 ] }, { timeline: n }); return () => o.cancel(); }; return { kt: _addScrollPercentAnimation }; } }; const $ = { x: initScrollTimeline("x"), y: initScrollTimeline("y") }; const getViewportPercent = () => { const {Rt: t, Vt: n} = o; const getAxisValue = (t, n) => capNumber(0, 1, t / (t + n) || 0); return { x: getAxisValue(n.x, t.x), y: getAxisValue(n.y, t.y) }; }; const scrollbarStructureAddRemoveClass = (t, n, o) => { const s = o ? addClass : removeClass; each(t, (t => { s(t.Tt, n); })); }; const scrollbarStyle = (t, n) => { each(t, (t => { const [o, s] = n(t); setStyles(o, s); })); }; const scrollbarsAddRemoveClass = (t, n, o) => { const s = isBoolean(o); const e = s ? o : true; const c = s ? !o : true; e && scrollbarStructureAddRemoveClass(S, t, n); c && scrollbarStructureAddRemoveClass(m, t, n); }; const refreshScrollbarsHandleLength = () => { const t = getViewportPercent(); const createScrollbarStyleFn = t => n => [ n.Tt, { [e]: roundCssNumber(t) + "" } ]; scrollbarStyle(S, createScrollbarStyleFn(t.x)); scrollbarStyle(m, createScrollbarStyleFn(t.y)); }; const refreshScrollbarsHandleOffset = () => { if (!v) { const {Lt: t} = o; const n = getScrollCoordinatesPercent(t, getElementScroll(p)); const createScrollbarStyleFn = t => n => [ n.Tt, { [c]: roundCssNumber(t) + "" } ]; scrollbarStyle(S, createScrollbarStyleFn(n.x)); scrollbarStyle(m, createScrollbarStyleFn(n.y)); } }; const refreshScrollbarsScrollCoordinates = () => { const {Lt: t} = o; const n = isDefaultDirectionScrollCoordinates(t); const createScrollbarStyleFn = t => n => [ n.Tt, { [r]: t ? "0" : "1" } ]; scrollbarStyle(S, createScrollbarStyleFn(n.x)); scrollbarStyle(m, createScrollbarStyleFn(n.y)); }; const refreshScrollbarsScrollbarOffset = () => { if (g && !h) { const {Rt: t, Lt: n} = o; const s = isDefaultDirectionScrollCoordinates(n); const e = getScrollCoordinatesPercent(n, getElementScroll(p)); const styleScrollbarPosition = n => { const {Tt: o} = n; const c = parent(o) === d && o; const getTranslateValue = (t, n, o) => { const s = n * t; return numberToCssPx(o ? s : -s); }; return [ c, c && { transform: getTrasformTranslateValue({ x: getTranslateValue(e.x, t.x, s.x), y: getTranslateValue(e.y, t.y, s.y) }) } ]; }; scrollbarStyle(S, styleScrollbarPosition); scrollbarStyle(m, styleScrollbarPosition); } }; const generateScrollbarDOM = t => { const n = t ? "x" : "y"; const o = t ? it : at; const e = createDiv(`${rt} ${o}`); const c = createDiv(ut); const r = createDiv(_t); const l = { Tt: e, Ut: c, Pt: r }; const i = $[n]; push(t ? S : m, l); push(y, [ appendChildren(e, c), appendChildren(c, r), bind(removeElements, e), i && i.kt(l), s(l, scrollbarsAddRemoveClass, t) ]); return l; }; const C = bind(generateScrollbarDOM, true); const x = bind(generateScrollbarDOM, false); const appendElements = () => { appendChildren(O, S[0].Tt); appendChildren(O, m[0].Tt); return bind(runEachAndClear, y); }; C(); x(); return [ { Nt: refreshScrollbarsHandleLength, qt: refreshScrollbarsHandleOffset, Bt: refreshScrollbarsScrollCoordinates, Ft: refreshScrollbarsScrollbarOffset, jt: scrollbarsAddRemoveClass, Xt: { Yt: S, Wt: C, Jt: bind(scrollbarStyle, S) }, Gt: { Yt: m, Wt: x, Jt: bind(scrollbarStyle, m) } }, appendElements ]; }; const createScrollbarsSetupEvents = (t, n, o, s) => (r, l, i) => { const {ht: u, ot: _, nt: d, gt: f, Kt: v, Ot: p} = n; const {Tt: h, Ut: g, Pt: b} = r; const [w, y] = selfClearTimeout(333); const [S, m] = selfClearTimeout(444); const scrollOffsetElementScrollBy = t => { isFunction(f.scrollBy) && f.scrollBy({ behavior: "smooth", left: t.x, top: t.y }); }; const createInteractiveScrollEvents = () => { const n = "pointerup pointercancel lostpointercapture"; const s = `client${i ? "X" : "Y"}`; const r = i ? $ : C; const l = i ? "left" : "top"; const a = i ? "w" : "h"; const u = i ? "x" : "y"; const createRelativeHandleMove = (t, n) => s => { const {Rt: e} = o; const c = I(g)[a] - I(b)[a]; const r = n * s / c; const l = r * e[u]; scrollElementTo(f, { [u]: t + l }); }; const _ = []; return addEventListener(g, "pointerdown", (o => { const i = closest(o.target, `.${_t}`) === b; const d = i ? b : g; const h = t.scrollbars; const w = h[i ? "dragScroll" : "clickScroll"]; const {button: y, isPrimary: O, pointerType: $} = o; const {pointers: C} = h; const x = y === 0 && O && w && (C || []).includes($); if (x) { runEachAndClear(_); m(); const t = !i && (o.shiftKey || w === "instant"); const h = bind(getBoundingClientRect, b); const y = bind(getBoundingClientRect, g); const getHandleOffset = (t, n) => (t || h())[l] - (n || y())[l]; const O = e(getBoundingClientRect(f)[r]) / I(f)[a] || 1; const $ = createRelativeHandleMove(getElementScroll(f)[u], 1 / O); const C = o[s]; const x = h(); const H = y(); const E = x[r]; const z = getHandleOffset(x, H) + E / 2; const A = C - H[l]; const D = i ? 0 : A - z; const releasePointerCapture = t => { runEachAndClear(k); d.releasePointerCapture(t.pointerId); }; const M = i || t; const T = p(); const k = [ addEventListener(v, n, releasePointerCapture), addEventListener(v, "selectstart", (t => preventDefault(t)), { H: false }), addEventListener(g, n, releasePointerCapture), M && addEventListener(g, "pointermove", (t => $(D + (t[s] - C)))), M && (() => { const t = getElementScroll(f); T(); const n = getElementScroll(f); const o = { x: n.x - t.x, y: n.y - t.y }; if (c(o.x) > 3 || c(o.y) > 3) { p(); scrollElementTo(f, t); scrollOffsetElementScrollBy(o); S(T); } }) ]; d.setPointerCapture(o.pointerId); if (t) { $(D); } else if (!i) { const t = getStaticPluginModuleInstance(At); if (t) { const n = t($, D, E, (t => { if (t) { T(); } else { push(k, T); } })); push(k, n); push(_, bind(n, true)); } } } })); }; let O = true; return bind(runEachAndClear, [ addEventListener(b, "pointermove pointerleave", s), addEventListener(h, "pointerenter", (() => { l(vt, true); })), addEventListener(h, "pointerleave pointercancel", (() => { l(vt, false); })), !d && addEventListener(h, "mousedown", (() => { const t = getFocusedElement(); if (hasAttr(t, q) || hasAttr(t, P) || t === document.body) { a(bind(focusElement, _), 25); } })), addEventListener(h, "wheel", (t => { const {deltaX: n, deltaY: o, deltaMode: s} = t; if (O && s === 0 && parent(h) === u) { scrollOffsetElementScrollBy({ x: n, y: o }); } O = false; l(bt, true); w((() => { O = true; l(bt); })); preventDefault(t); }), { H: false, I: true }), addEventListener(h, "pointerdown", bind(addEventListener, v, "click", stopAndPrevent, { A: true, I: true, H: false }), { I: true }), createInteractiveScrollEvents(), y, m ]); }; const createScrollbarsSetup = (t, n, o, s, e, c) => { let r; let l; let i; let a; let u; let _ = noop; let d = 0; const isHoverablePointerType = t => t.pointerType === "mouse"; const [f, v] = selfClearTimeout(); const [p, h] = selfClearTimeout(100); const [g, b] = selfClearTimeout(100); const [w, y] = selfClearTimeout((() => d)); const [S, m] = createScrollbarsSetupElements(t, e, s, createScrollbarsSetupEvents(n, e, s, (t => isHoverablePointerType(t) && manageScrollbarsAutoHideInstantInteraction()))); const {ht: O, Qt: $, wt: C} = e; const {jt: H, Nt: z, qt: I, Bt: A, Ft: D} = S; const manageScrollbarsAutoHide = (t, n) => { y(); if (t) { H(gt); } else { const t = bind(H, gt, true); if (d > 0 && !n) { w(t); } else { t(); } } }; const manageScrollbarsAutoHideInstantInteraction = () => { if (i ? !r : !a) { manageScrollbarsAutoHide(true); p((() => { manageScrollbarsAutoHide(false); })); } }; const manageAutoHideSuspension = t => { H(ht, t, true); H(ht, t, false); }; const onHostMouseEnter = t => { if (isHoverablePointerType(t)) { r = i; i && manageScrollbarsAutoHide(true); } }; const M = [ y, h, b, v, () => _(), addEventListener(O, "pointerover", onHostMouseEnter, { A: true }), addEventListener(O, "pointerenter", onHostMouseEnter), addEventListener(O, "pointerleave", (t => { if (isHoverablePointerType(t)) { r = false; i && manageScrollbarsAutoHide(false); } })), addEventListener(O, "pointermove", (t => { isHoverablePointerType(t) && l && manageScrollbarsAutoHideInstantInteraction(); })), addEventListener($, "scroll", (t => { f((() => { I(); manageScrollbarsAutoHideInstantInteraction(); })); c(t); D(); })) ];