UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

131 lines (130 loc) 3.11 kB
//#region components/resizable/resizable_constants.ts var e = "50p", t = 10, n = Symbol("resizable-context"); function r(e, t) { return `${e}:${t}`; } //#endregion //#region components/resizable/resizable_utils.ts var i = /* @__PURE__ */ new Map(), a = null; function o() { return a === null && (a = typeof document < "u" && parseFloat(getComputedStyle(document.documentElement).fontSize) || 10), a; } function s(e) { if (i.has(e)) return i.get(e); if (typeof document < "u") { let t = getComputedStyle(document.documentElement).getPropertyValue(`--dt-size-${e}`).trim(); if (t) { let n = t.match(/^([\d.]+)rem$/); if (n) { let t = parseFloat(n[1]) * o(); return i.set(e, t), t; } let r = t.match(/^([\d.]+)px$/); if (r) { let t = parseFloat(r[1]); return i.set(e, t), t; } } } if (e in c) { let t = c[e]; return i.set(e, t), t; } } var c = { 0: 0, 50: .5, 100: 1, 200: 2, 300: 4, 350: 6, 400: 8, 450: 12, 500: 16, 525: 20, 550: 24, 600: 32, 625: 42, 650: 48, 700: 64, 720: 72, 730: 84, 750: 96, 760: 102, 775: 114, 800: 128, 825: 164, 850: 192, 875: 216, 900: 256, 905: 264, 925: 332, 950: 384, 975: 464, 1e3: 512, 1020: 628, 1040: 764, 1050: 768, 1060: 828, 1080: 912, 1100: 1024, 1115: 1140, 1120: 1268, 1125: 1280, 1130: 1340, 1150: 1536, 1200: 2048 }; function l(e) { if (!e.endsWith("p")) return; let t = parseFloat(e.slice(0, -1)); return isFinite(t) && t >= 0 && t <= 100 ? t : void 0; } function u(e) { return s(e) !== void 0; } function d(e) { return l(e) !== void 0; } function f(e) { return u(e) || d(e); } function p(e, t) { let n = s(e); if (n !== void 0) return n; let r = l(e); return r === void 0 ? (console.warn(`[resizable] Invalid sizing value: ${e}`), 0) : r / 100 * t; } function m(e, t, n) { let { clampToContainer: r = !0 } = n ?? {}, i = h(t); if (g(i, e)) return 0; let a = i === 0 ? 1e3 : i; return typeof e == "string" && f(e) ? _(p(e, a), e, i, r) : (console.warn(`[resizable] Invalid ResizableSizeValue: ${e}. Expected a size token or percentage with 'p' suffix.`), 0); } function h(e) { return !isFinite(e) || e < 0 ? (console.warn(`[resizable] Invalid containerSize: ${e}. Using fallback value of 1000px.`), 1e3) : e > 1e4 ? (console.warn(`[resizable] Unusually large containerSize: ${e}px. Capping at 10000px.`), 1e4) : e; } function g(e, t) { return e === 0 && t === "0"; } function _(e, t, n, r) { return !isFinite(e) || e < 0 ? (console.warn(`[resizable] Invalid pixel calculation result: ${e} for value: ${t}, containerSize: ${n}`), 0) : r && n > 0 && e > n ? (console.warn(`[resizable] Size value '${t}' (${e}px) exceeds container (${n}px). Clamping to container.`), n) : e; } function v(e) { return d(e); } function y(e) { return u(e); } function b(e, t) { return e / t * 100; } function x(e) { return e.userMinSize ? d(e.userMinSize) : !1; } function S() { i.clear(), a = null; } //#endregion export { f as a, h as c, n as d, r as f, v as i, e as l, S as n, m as o, y as r, b as s, x as t, t as u }; //# sourceMappingURL=resizable_utils-BComtrMV.js.map