@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
218 lines (217 loc) • 7.09 kB
JavaScript
import { DEFAULT_PREFIX as R, DEFAULT_VALIDATION_MESSAGE_TYPE as S, VALIDATION_MESSAGE_TYPES as r } from "../constants/index.js";
import { configVue2StyleClassAttrs as c } from "../config/index.js";
import { Comment as y, Text as x, h as C } from "vue";
let A = 0, s;
const O = "input:not([type=hidden]):not(:disabled)", T = "select:not(:disabled),textarea:not(:disabled),button:not(:disabled)", L = `${O},${T}`, _ = `a,frame,iframe,${L},*[tabindex]`, w = typeof setImmediate == "function" ? setImmediate : setTimeout;
function N(e = R) {
return `${e}${A++}`;
}
function I(e, t) {
if (t) {
const n = U(t);
return e[Math.abs(n) % e.length];
} else
return e[u(e.length)];
}
function U(e) {
let t;
for (let n = 0; n < e.length; n++)
t = Math.imul(31, t) + e.charCodeAt(n) | 0;
return t;
}
function u(e) {
return Math.floor(Math.random() * e);
}
function $(e) {
return e ? e.map((t) => typeof t == "string" ? {
message: t,
type: S
} : t) : [];
}
function D(e) {
const t = l(e);
return !e || !t ? [] : e.filter((n) => !!n.message && n.type === t);
}
function l(e) {
return e ? o(e, r.ERROR) ? r.ERROR : o(e, r.WARNING) ? r.WARNING : o(e, r.SUCCESS) ? r.SUCCESS : null : null;
}
function o(e, t) {
return !e || !t ? !1 : e.some((n) => (n == null ? void 0 : n.type) === t);
}
function oe(e) {
return e == null ? void 0 : e.querySelector(_);
}
const F = (e) => C("div", { innerHTML: e.html }), j = () => new Promise((e) => {
w(e);
});
function ie(e, t = {}) {
return e ? e(t).some((n) => n.type === y || Array.isArray(n.children) && !n.children.length ? !1 : n.type !== x || typeof n.children == "string" && n.children.trim() !== "") : !1;
}
const W = (e) => e == null ? void 0 : e.toLowerCase().split("-").map((t) => t.charAt(0).toUpperCase() + t.slice(1)).join(""), se = (e) => e.replace(/\.?([A-Z0-9]+)/g, (t, n) => "-" + n.toLowerCase()).replace(/^-/, ""), P = (e) => {
const t = Object.entries(e).filter(([n]) => n.match(/on[A-Z]/));
return Object.fromEntries(t);
}, a = (e) => (e == null ? void 0 : e.nodeType) === Node.ELEMENT_NODE ? e : e != null && e.nodeType ? a(e == null ? void 0 : e.nextSibling) : null;
function k(e) {
if (!c) return e;
const t = Object.entries(e).filter(([n]) => !["class", "style"].includes(n));
return Object.fromEntries(t);
}
function v(e) {
return c ? {
class: e.class,
style: e.style
} : {};
}
function z(e, t = 300) {
clearTimeout(s), s = setTimeout(e, t);
}
function B(e) {
const t = e.getBoundingClientRect(), n = {
top: t.top < 0,
left: t.left < 0,
bottom: t.bottom > (window.innerHeight || document.documentElement.clientHeight),
right: t.right > (window.innerWidth || document.documentElement.clientWidth)
};
return n.any = Object.values(n).some((i) => i), n.all = Object.values(n).every((i) => i), n;
}
const H = /(?:(?:[^\s!@#$%^&*()_=+[\]{}\\|;:'",.<>/?]+)\.)/, M = new RegExp(
"(?:com|ru|org|net|de|jp|uk|br|it|pl|fr|in|au|ir|info|nl|cn|es|cz|kr|ca|eu|ua|co|gr|za|ro|biz|ch|se|tw|mx|vn|hu|be|tr|at|dk|tv|me|ar|sk|no|us|fi|id|cl|xyz|io|pt|by|il|ie|nz|kz|hk|lt|cc|my|sg|club|bg|edu|рф|pk|su|top|th|hr|rs|pe|pro|si|az|lv|pw|ae|ph|online|ng|ee|ws|ve|cat)"
), V = new RegExp(
"(?:(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])"
), f = new RegExp(
"(?:" + [
[
H.source,
M.source
].join("+"),
V.source
].join("|") + ")"
), G = /(?:(?:[;/][^#?<>\s]*)?)/, d = /(?:(?:\?[^#<>\s]+)?(?:#[^<>\s]+)?)/, h = new RegExp(
"\\b" + [
f.source,
G.source,
d.source,
"(?!\\w)"
].join("+")
), m = /\b[a-z\d.-]+:\/\/[^<>\s]+/, E = new RegExp(
"(?:mailto:)?[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@" + [
f.source,
d.source
].join("+") + "(?!\\w)"
);
function b(e = 7, t = 15) {
try {
return new RegExp(
`(?:^|(?<=\\W))(?![\\s\\-])\\+?(?:[0-9()\\- \\t]{${e},${t}})(?=\\b)(?=\\W(?=\\W|$)|\\s|$)`
);
} catch {
console.warn("This browser doesn't support regex lookahead/lookbehind");
}
return new RegExp(
`(?![\\s\\-])\\+?(?:[0-9()\\- \\t]{${e},${t}})(?=\\b)(?=\\W(?=\\W|$)|\\s|$)`
);
}
const p = b(), q = new RegExp(
[
h.source,
m.source,
E.source,
p.source
].join("|"),
"gi"
);
function K(e) {
var t;
return !e || !["string", "number"].includes(typeof e) ? !1 : (e = e.toString(), ((t = p.exec(e)) == null ? void 0 : t[0]) === e);
}
function Q(e) {
var t, n;
return !e || typeof e != "string" ? !1 : ((t = h.exec(e)) == null ? void 0 : t[0]) === e || ((n = m.exec(e)) == null ? void 0 : n[0]) === e;
}
function Y(e) {
var t;
return !e || typeof e != "string" ? !1 : ((t = E.exec(e)) == null ? void 0 : t[0]) === e;
}
function Z(e) {
return e.filter((t) => !!t).join(", ");
}
function X(e, t = "en-US") {
return e.replace(new RegExp("^\\p{CWU}", "u"), (n) => n.toLocaleUpperCase(t));
}
function ce(e, t) {
typeof process > "u" || process.env.NODE_ENV === "test" && (!e || !(e instanceof HTMLElement) || !(document != null && document.body) || document.body.contains(e) || console.warn(`The ${t} component is not attached to the document body. This may cause issues.`));
}
function g(e = document.documentElement) {
return !!e.hasAttribute("data-overlayscrollbars");
}
function J(e = document.documentElement) {
g(e) ? e.classList.add("d-scrollbar-disabled") : e.classList.add("d-of-hidden");
}
function ee(e = document.documentElement) {
g(e) ? e.classList.remove("d-scrollbar-disabled") : e.classList.remove("d-of-hidden");
}
function ue(e) {
return e.replaceAll(/[ -]/g, "_").replaceAll(/\W/g, "").toUpperCase();
}
const le = {
getUniqueString: N,
getRandomElement: I,
getRandomInt: u,
formatMessages: $,
filterFormattedMessages: D,
hasFormattedMessageOfType: o,
getValidationState: l,
htmlFragment: F,
flushPromises: j,
kebabCaseToPascalCase: W,
extractVueListeners: P,
removeClassStyleAttrs: k,
addClassStyleAttrs: v,
returnFirstEl: a,
debounce: z,
isOutOfViewPort: B,
getPhoneNumberRegex: b,
linkRegex: q,
isEmailAddress: Y,
isPhoneNumber: K,
isURL: Q,
safeConcatStrings: Z,
capitalizeFirstLetter: X,
disableRootScrolling: J,
enableRootScrolling: ee
};
export {
v as addClassStyleAttrs,
X as capitalizeFirstLetter,
z as debounce,
le as default,
J as disableRootScrolling,
ee as enableRootScrolling,
P as extractVueListeners,
D as filterFormattedMessages,
oe as findFirstFocusableNode,
j as flushPromises,
$ as formatMessages,
b as getPhoneNumberRegex,
I as getRandomElement,
u as getRandomInt,
N as getUniqueString,
l as getValidationState,
o as hasFormattedMessageOfType,
ie as hasSlotContent,
F as htmlFragment,
Y as isEmailAddress,
B as isOutOfViewPort,
K as isPhoneNumber,
Q as isURL,
U as javaHashCode,
W as kebabCaseToPascalCase,
q as linkRegex,
se as pascalCaseToKebabCase,
k as removeClassStyleAttrs,
a as returnFirstEl,
Z as safeConcatStrings,
ue as toFluentKeyString,
ce as warnIfUnmounted
};
//# sourceMappingURL=index.js.map