UNPKG

@gez/date-time-kit

Version:

60 lines (59 loc) 2.54 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); export const html = (strings, ...values) => String.raw(strings, ...values); export const css = html; export const closestByEvent = (e, selector, root) => { for (const target of e.composedPath()) { if (target === root) return null; if (!(target instanceof HTMLElement)) continue; if (target.matches(selector)) { return target; } } return null; }; export function debounce(fn, delay = 0) { let timer = null; return function(...args) { if (timer !== null) clearTimeout(timer); timer = setTimeout(() => { fn.apply(this, args); }, delay); }; } export const getCurrentTzOffset = () => (/* @__PURE__ */ new Date()).getTimezoneOffset(); export const getCurrentTzOffsetMs = () => getCurrentTzOffset() * 60 * 1e3; const ltrLangs = ":lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)"; export const cssDirLtrSelector1 = ":-webkit-any(".concat(ltrLangs, ")"); export const cssDirLtrSelector2 = ":-moz-any(".concat(ltrLangs, ")"); export const cssDirLtrSelector3 = ":is(".concat(ltrLangs, ")"); export const dirLtr = (rule) => rule.replaceAll(":dir(ltr)", cssDirLtrSelector1) + rule.replaceAll(":dir(ltr)", cssDirLtrSelector2) + rule.replaceAll(":dir(ltr)", cssDirLtrSelector3); class SmallScreenObserver { constructor(thresholds = 750) { __publicField(this, "_mql"); __publicField(this, "_map", /* @__PURE__ */ new Map()); __publicField(this, "_onMqlChange", (e) => { const isSmall = e.matches; for (const cb of this._map.values()) { cb(isSmall); } }); if (typeof matchMedia === "undefined") return; this._mql = matchMedia("(max-width: ".concat(thresholds, "px)")); this._mql.addEventListener("change", this._onMqlChange); } get isSmall() { var _a, _b; return (_b = (_a = this._mql) == null ? void 0 : _a.matches) != null ? _b : false; } observe(el, cb) { this._map.set(el, cb); cb(this.isSmall); } unobserve(el) { this._map.delete(el); } } export const smallScreenObserver = new SmallScreenObserver(750); export { granHelper } from "./granularity.mjs";