UNPKG

@web-atoms/core

Version:
226 lines (225 loc) • 6.17 kB
System.register([], function (_export, _context) { "use strict"; var AncestorEnumerator, ChildEnumerator, AtomUI; function* descendentElementIterator(e) { const stack = []; const start = e; if (start) { stack.push(start); } while (stack.length) { const pop = stack.pop(); const next = pop.nextElementSibling; yield pop; if (next) { stack.push(next); } const child = pop.firstElementChild; if (child) { stack.push(child); } } } function* descendentIterator(e) { const stack = []; const start = e; if (start) { stack.push(start); } while (stack.length) { const pop = stack.pop(); const next = pop.nextSibling; yield pop; if (next) { stack.push(next); } const child = pop.firstChild; if (child) { stack.push(child); } } } _export({ AncestorEnumerator: void 0, ChildEnumerator: void 0, descendentElementIterator: descendentElementIterator, descendentIterator: descendentIterator, AtomUI: void 0 }); return { setters: [], execute: function () { _export("AncestorEnumerator", AncestorEnumerator = class AncestorEnumerator { static find(e, filter) { let start = e === null || e === void 0 ? void 0 : e.parentElement; while (start) { if (filter(start)) { return start; } start = start.parentElement; } } static findSelector(e, selector) { let start = e === null || e === void 0 ? void 0 : e.parentElement; while (start) { const found = start.matches(selector); if (found) { return start; } start = start.parentElement; } } }); _export("ChildEnumerator", ChildEnumerator = class ChildEnumerator { static find(e, filter) { let item = e === null || e === void 0 ? void 0 : e.firstElementChild; while (item) { const next = item.nextElementSibling; if (filter(item)) { return item; } item = next; } } static *where(e, filter) { let item = e === null || e === void 0 ? void 0 : e.firstElementChild; while (item) { const next = item.nextElementSibling; if (filter(item)) { yield item; } item = next; } } static *enumerate(e) { let item = e === null || e === void 0 ? void 0 : e.firstElementChild; while (item) { const next = item.nextElementSibling; yield item; item = next; } } get current() { return this.item; } constructor(e) { this.e = e; } next() { var _a; if (!this.item) { this.item = (_a = this.e) === null || _a === void 0 ? void 0 : _a.firstElementChild; } else { this.item = this.item.nextElementSibling; } return this.item ? true : false; } }); _export("AtomUI", AtomUI = class AtomUI { static outerHeight(el, margin = false) { let height = el.offsetHeight; if (!margin) { return height; } const style = getComputedStyle(el); height += parseInt(style.marginTop, 10) + parseInt(style.marginBottom, 10); return height; } static outerWidth(el, margin = false) { let width = el.offsetWidth; if (!margin) { return width; } const style = getComputedStyle(el); width += parseInt(style.marginLeft, 10) + parseInt(style.marginRight, 10); return width; } static innerWidth(el) { return el.clientWidth; } static innerHeight(el) { return el.clientHeight; } static scrollTop(el, y) { el.scrollTo(0, y); } static screenOffset(e) { const r = { x: e.offsetLeft, y: e.offsetTop, width: e.offsetWidth, height: e.offsetHeight }; if (e.offsetParent) { const p = this.screenOffset(e.offsetParent); r.x += p.x; r.y += p.y; } return r; } static parseUrl(url) { const r = {}; const plist = url.split("&"); for (const item of plist) { const p = item.split("="); const key = decodeURIComponent(p[0]); if (!key) { continue; } let val = p[1]; if (val) { val = decodeURIComponent(val); } r[key] = this.parseValue(val); } return r; } static parseValue(val) { let n; if (/^[0-9]+$/.test(val)) { n = parseInt(val, 10); if (!isNaN(n)) { return n; } return val; } if (/^[0-9]+\.[0-9]+/gi.test(val)) { n = parseFloat(val); if (!isNaN(n)) { return n; } return val; } if (val === "true") { return true; } if (val === "false") { return false; } return val; } static assignID(element) { if (!element.id) { element.id = "__waID" + AtomUI.getNewIndex(); } return element.id; } static toNumber(text) { if (!text) { return 0; } if (text.constructor === String) { return parseFloat(text); } return 0; } static getNewIndex() { AtomUI.index = AtomUI.index + 1; return AtomUI.index; } }); AtomUI.index = 1001; } }; }); //# sourceMappingURL=AtomUI.js.map