generated from lit/lit-element-starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage-box.generator.js
60 lines (60 loc) · 2.25 KB
/
message-box.generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Gets the zIndex of an element based on doc
*
* @param {Element} element
* @param {Document} doc
* @returns {number} zIndex
*/
function getZIndex(element, doc = document) {
var _a;
const zIndex = (_a = doc.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(element).getPropertyValue('z-index');
const zIndexNumber = Number(zIndex);
if (isNaN(zIndexNumber)) {
if (element.parentNode === doc) {
return 0;
}
if (element.parentNode instanceof Element) {
return getZIndex(element.parentNode, doc);
}
}
return zIndexNumber;
}
/**
* For quickly generate a message-box
*
* @param children - children of `<message-box/>`
* @param propertiesDict - properties dictionary for initialize, optional
* @param stylesDict - stylesheet dictionary for initialize, optional
* @param mountPoint - reference to mount point element for computing style, optional
* @param doc - reference to document, optional
* @returns {MessageBox} instance
*/
function generator(children, propertiesDict = {}, stylesDict = {}, mountPoint = null, doc = document) {
var _a;
const $messageBox = doc.createElement('message-box');
if (children instanceof HTMLElement) {
$messageBox.appendChild(children);
}
else if (Array.isArray(children)) {
for (const element of children) {
$messageBox.appendChild(element);
}
}
else if (typeof children === 'string') {
$messageBox.innerHTML = children;
}
Object.assign($messageBox, propertiesDict);
for (const [name, value] of Object.entries(stylesDict)) {
if (value === undefined)
continue;
if (name === 'z-index' && value === 'max') {
const maxZIndex = Math.max(...Array.from(doc.querySelectorAll(`${(_a = mountPoint === null || mountPoint === void 0 ? void 0 : mountPoint.tagName) !== null && _a !== void 0 ? _a : 'BODY'} > *`)).map(($element) => getZIndex($element)));
$messageBox.style.setProperty(name, String(maxZIndex));
continue;
}
$messageBox.style.setProperty(name, value);
}
return $messageBox;
}
export default generator;
//# sourceMappingURL=message-box.generator.js.map