Skip to content

Instantly share code, notes, and snippets.

@redjab
Created August 11, 2020 16:34
Show Gist options
  • Save redjab/283da2aab31af5dfd2e51549905dfe43 to your computer and use it in GitHub Desktop.
Save redjab/283da2aab31af5dfd2e51549905dfe43 to your computer and use it in GitHub Desktop.
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function t(t, e, i, n) {
var s,
r = arguments.length,
o = r < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, i) : n;if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) o = Reflect.decorate(t, e, i, n);else for (var a = t.length - 1; a >= 0; a--) (s = t[a]) && (o = (r < 3 ? s(o) : r > 3 ? s(e, i, o) : s(e, i)) || o);return r > 3 && o && Object.defineProperty(e, i, o), o;
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
}const e = "undefined" != typeof window && null != window.customElements && void 0 !== window.customElements.polyfillWrapFlushCallback,
i = (t, e, i = null) => {
for (; e !== i;) {
const i = e.nextSibling;t.removeChild(e), e = i;
}
},
n = `{{lit-${String(Math.random()).slice(2)}}}`,
s = `\x3c!--${n}--\x3e`,
r = new RegExp(`${n}|${s}`);class o {
constructor(t, e) {
this.parts = [], this.element = e;const i = [],
s = [],
o = document.createTreeWalker(e.content, 133, null, !1);let l = 0,
u = -1,
h = 0;const { strings: p, values: { length: m } } = t;for (; h < m;) {
const t = o.nextNode();if (null !== t) {
if (u++, 1 === t.nodeType) {
if (t.hasAttributes()) {
const e = t.attributes,
{ length: i } = e;let n = 0;for (let t = 0; t < i; t++) a(e[t].name, "$lit$") && n++;for (; n-- > 0;) {
const e = p[h],
i = c.exec(e)[2],
n = i.toLowerCase() + "$lit$",
s = t.getAttribute(n);t.removeAttribute(n);const o = s.split(r);this.parts.push({ type: "attribute", index: u, name: i, strings: o }), h += o.length - 1;
}
}"TEMPLATE" === t.tagName && (s.push(t), o.currentNode = t.content);
} else if (3 === t.nodeType) {
const e = t.data;if (e.indexOf(n) >= 0) {
const n = t.parentNode,
s = e.split(r),
o = s.length - 1;for (let e = 0; e < o; e++) {
let i,
r = s[e];if ("" === r) i = d();else {
const t = c.exec(r);null !== t && a(t[2], "$lit$") && (r = r.slice(0, t.index) + t[1] + t[2].slice(0, -"$lit$".length) + t[3]), i = document.createTextNode(r);
}n.insertBefore(i, t), this.parts.push({ type: "node", index: ++u });
}"" === s[o] ? (n.insertBefore(d(), t), i.push(t)) : t.data = s[o], h += o;
}
} else if (8 === t.nodeType) if (t.data === n) {
const e = t.parentNode;null !== t.previousSibling && u !== l || (u++, e.insertBefore(d(), t)), l = u, this.parts.push({ type: "node", index: u }), null === t.nextSibling ? t.data = "" : (i.push(t), u--), h++;
} else {
let e = -1;for (; -1 !== (e = t.data.indexOf(n, e + 1));) this.parts.push({ type: "node", index: -1 }), h++;
}
} else o.currentNode = s.pop();
}for (const t of i) t.parentNode.removeChild(t);
}
}const a = (t, e) => {
const i = t.length - e.length;return i >= 0 && t.slice(i) === e;
},
l = t => -1 !== t.index,
d = () => document.createComment(""),
c = /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function u(t, e) {
const { element: { content: i }, parts: n } = t,
s = document.createTreeWalker(i, 133, null, !1);let r = p(n),
o = n[r],
a = -1,
l = 0;const d = [];let c = null;for (; s.nextNode();) {
a++;const t = s.currentNode;for (t.previousSibling === c && (c = null), e.has(t) && (d.push(t), null === c && (c = t)), null !== c && l++; void 0 !== o && o.index === a;) o.index = null !== c ? -1 : o.index - l, r = p(n, r), o = n[r];
}d.forEach(t => t.parentNode.removeChild(t));
}const h = t => {
let e = 11 === t.nodeType ? 0 : 1;const i = document.createTreeWalker(t, 133, null, !1);for (; i.nextNode();) e++;return e;
},
p = (t, e = -1) => {
for (let i = e + 1; i < t.length; i++) {
const e = t[i];if (l(e)) return i;
}return -1;
};
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
const m = new WeakMap(),
f = t => "function" == typeof t && m.has(t),
g = {},
_ = {};
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
class y {
constructor(t, e, i) {
this.__parts = [], this.template = t, this.processor = e, this.options = i;
}update(t) {
let e = 0;for (const i of this.__parts) void 0 !== i && i.setValue(t[e]), e++;for (const t of this.__parts) void 0 !== t && t.commit();
}_clone() {
const t = e ? this.template.element.content.cloneNode(!0) : document.importNode(this.template.element.content, !0),
i = [],
n = this.template.parts,
s = document.createTreeWalker(t, 133, null, !1);let r,
o = 0,
a = 0,
d = s.nextNode();for (; o < n.length;) if (r = n[o], l(r)) {
for (; a < r.index;) a++, "TEMPLATE" === d.nodeName && (i.push(d), s.currentNode = d.content), null === (d = s.nextNode()) && (s.currentNode = i.pop(), d = s.nextNode());if ("node" === r.type) {
const t = this.processor.handleTextExpression(this.options);t.insertAfterNode(d.previousSibling), this.__parts.push(t);
} else this.__parts.push(...this.processor.handleAttributeExpressions(d, r.name, r.strings, this.options));o++;
} else this.__parts.push(void 0), o++;return e && (document.adoptNode(t), customElements.upgrade(t)), t;
}
}
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/const v = ` ${n} `;class S {
constructor(t, e, i, n) {
this.strings = t, this.values = e, this.type = i, this.processor = n;
}getHTML() {
const t = this.strings.length - 1;let e = "",
i = !1;for (let r = 0; r < t; r++) {
const t = this.strings[r],
o = t.lastIndexOf("\x3c!--");i = (o > -1 || i) && -1 === t.indexOf("--\x3e", o + 1);const a = c.exec(t);e += null === a ? t + (i ? v : s) : t.substr(0, a.index) + a[1] + a[2] + "$lit$" + a[3] + n;
}return e += this.strings[t], e;
}getTemplateElement() {
const t = document.createElement("template");return t.innerHTML = this.getHTML(), t;
}
}
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/const w = t => null === t || !("object" == typeof t || "function" == typeof t),
b = t => Array.isArray(t) || !(!t || !t[Symbol.iterator]);class C {
constructor(t, e, i) {
this.dirty = !0, this.element = t, this.name = e, this.strings = i, this.parts = [];for (let t = 0; t < i.length - 1; t++) this.parts[t] = this._createPart();
}_createPart() {
return new x(this);
}_getValue() {
const t = this.strings,
e = t.length - 1;let i = "";for (let n = 0; n < e; n++) {
i += t[n];const e = this.parts[n];if (void 0 !== e) {
const t = e.value;if (w(t) || !b(t)) i += "string" == typeof t ? t : String(t);else for (const e of t) i += "string" == typeof e ? e : String(e);
}
}return i += t[e], i;
}commit() {
this.dirty && (this.dirty = !1, this.element.setAttribute(this.name, this._getValue()));
}
}class x {
constructor(t) {
this.value = void 0, this.committer = t;
}setValue(t) {
t === g || w(t) && t === this.value || (this.value = t, f(t) || (this.committer.dirty = !0));
}commit() {
for (; f(this.value);) {
const t = this.value;this.value = g, t(this);
}this.value !== g && this.committer.commit();
}
}class P {
constructor(t) {
this.value = void 0, this.__pendingValue = void 0, this.options = t;
}appendInto(t) {
this.startNode = t.appendChild(d()), this.endNode = t.appendChild(d());
}insertAfterNode(t) {
this.startNode = t, this.endNode = t.nextSibling;
}appendIntoPart(t) {
t.__insert(this.startNode = d()), t.__insert(this.endNode = d());
}insertAfterPart(t) {
t.__insert(this.startNode = d()), this.endNode = t.endNode, t.endNode = this.startNode;
}setValue(t) {
this.__pendingValue = t;
}commit() {
if (null === this.startNode.parentNode) return;for (; f(this.__pendingValue);) {
const t = this.__pendingValue;this.__pendingValue = g, t(this);
}const t = this.__pendingValue;t !== g && (w(t) ? t !== this.value && this.__commitText(t) : t instanceof S ? this.__commitTemplateResult(t) : t instanceof Node ? this.__commitNode(t) : b(t) ? this.__commitIterable(t) : t === _ ? (this.value = _, this.clear()) : this.__commitText(t));
}__insert(t) {
this.endNode.parentNode.insertBefore(t, this.endNode);
}__commitNode(t) {
this.value !== t && (this.clear(), this.__insert(t), this.value = t);
}__commitText(t) {
const e = this.startNode.nextSibling,
i = "string" == typeof (t = null == t ? "" : t) ? t : String(t);e === this.endNode.previousSibling && 3 === e.nodeType ? e.data = i : this.__commitNode(document.createTextNode(i)), this.value = t;
}__commitTemplateResult(t) {
const e = this.options.templateFactory(t);if (this.value instanceof y && this.value.template === e) this.value.update(t.values);else {
const i = new y(e, t.processor, this.options),
n = i._clone();i.update(t.values), this.__commitNode(n), this.value = i;
}
}__commitIterable(t) {
Array.isArray(this.value) || (this.value = [], this.clear());const e = this.value;let i,
n = 0;for (const s of t) i = e[n], void 0 === i && (i = new P(this.options), e.push(i), 0 === n ? i.appendIntoPart(this) : i.insertAfterPart(e[n - 1])), i.setValue(s), i.commit(), n++;n < e.length && (e.length = n, this.clear(i && i.endNode));
}clear(t = this.startNode) {
i(this.startNode.parentNode, t.nextSibling, this.endNode);
}
}class N {
constructor(t, e, i) {
if (this.value = void 0, this.__pendingValue = void 0, 2 !== i.length || "" !== i[0] || "" !== i[1]) throw new Error("Boolean attributes can only contain a single expression");this.element = t, this.name = e, this.strings = i;
}setValue(t) {
this.__pendingValue = t;
}commit() {
for (; f(this.__pendingValue);) {
const t = this.__pendingValue;this.__pendingValue = g, t(this);
}if (this.__pendingValue === g) return;const t = !!this.__pendingValue;this.value !== t && (t ? this.element.setAttribute(this.name, "") : this.element.removeAttribute(this.name), this.value = t), this.__pendingValue = g;
}
}class M extends C {
constructor(t, e, i) {
super(t, e, i), this.single = 2 === i.length && "" === i[0] && "" === i[1];
}_createPart() {
return new T(this);
}_getValue() {
return this.single ? this.parts[0].value : super._getValue();
}commit() {
this.dirty && (this.dirty = !1, this.element[this.name] = this._getValue());
}
}class T extends x {}let E = !1;(() => {
try {
const t = { get capture() {
return E = !0, !1;
} };window.addEventListener("test", t, t), window.removeEventListener("test", t, t);
} catch (t) {}
})();class k {
constructor(t, e, i) {
this.value = void 0, this.__pendingValue = void 0, this.element = t, this.eventName = e, this.eventContext = i, this.__boundHandleEvent = t => this.handleEvent(t);
}setValue(t) {
this.__pendingValue = t;
}commit() {
for (; f(this.__pendingValue);) {
const t = this.__pendingValue;this.__pendingValue = g, t(this);
}if (this.__pendingValue === g) return;const t = this.__pendingValue,
e = this.value,
i = null == t || null != e && (t.capture !== e.capture || t.once !== e.once || t.passive !== e.passive),
n = null != t && (null == e || i);i && this.element.removeEventListener(this.eventName, this.__boundHandleEvent, this.__options), n && (this.__options = A(t), this.element.addEventListener(this.eventName, this.__boundHandleEvent, this.__options)), this.value = t, this.__pendingValue = g;
}handleEvent(t) {
"function" == typeof this.value ? this.value.call(this.eventContext || this.element, t) : this.value.handleEvent(t);
}
}const A = t => t && (E ? { capture: t.capture, passive: t.passive, once: t.once } : t.capture)
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/;function D(t) {
let e = V.get(t.type);void 0 === e && (e = { stringsArray: new WeakMap(), keyString: new Map() }, V.set(t.type, e));let i = e.stringsArray.get(t.strings);if (void 0 !== i) return i;const s = t.strings.join(n);return i = e.keyString.get(s), void 0 === i && (i = new o(t, t.getTemplateElement()), e.keyString.set(s, i)), e.stringsArray.set(t.strings, i), i;
}const V = new Map(),
O = new WeakMap();
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/const R = new
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
class {
handleAttributeExpressions(t, e, i, n) {
const s = e[0];if ("." === s) {
return new M(t, e.slice(1), i).parts;
}if ("@" === s) return [new k(t, e.slice(1), n.eventContext)];if ("?" === s) return [new N(t, e.slice(1), i)];return new C(t, e, i).parts;
}handleTextExpression(t) {
return new P(t);
}
}();
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/"undefined" != typeof window && (window.litHtmlVersions || (window.litHtmlVersions = [])).push("1.2.1");const Y = (t, ...e) => new S(t, e, "html", R)
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/,
U = (t, e) => `${t}--${e}`;let H = !0;void 0 === window.ShadyCSS ? H = !1 : void 0 === window.ShadyCSS.prepareTemplateDom && (console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."), H = !1);const z = t => e => {
const i = U(e.type, t);let s = V.get(i);void 0 === s && (s = { stringsArray: new WeakMap(), keyString: new Map() }, V.set(i, s));let r = s.stringsArray.get(e.strings);if (void 0 !== r) return r;const a = e.strings.join(n);if (r = s.keyString.get(a), void 0 === r) {
const i = e.getTemplateElement();H && window.ShadyCSS.prepareTemplateDom(i, t), r = new o(e, i), s.keyString.set(a, r);
}return s.stringsArray.set(e.strings, r), r;
},
j = ["html", "svg"],
F = new Set(),
I = (t, e, i) => {
F.add(t);const n = i ? i.element : document.createElement("template"),
s = e.querySelectorAll("style"),
{ length: r } = s;if (0 === r) return void window.ShadyCSS.prepareTemplateStyles(n, t);const o = document.createElement("style");for (let t = 0; t < r; t++) {
const e = s[t];e.parentNode.removeChild(e), o.textContent += e.textContent;
}(t => {
j.forEach(e => {
const i = V.get(U(e, t));void 0 !== i && i.keyString.forEach(t => {
const { element: { content: e } } = t,
i = new Set();Array.from(e.querySelectorAll("style")).forEach(t => {
i.add(t);
}), u(t, i);
});
});
})(t);const a = n.content;i ? function (t, e, i = null) {
const { element: { content: n }, parts: s } = t;if (null == i) return void n.appendChild(e);const r = document.createTreeWalker(n, 133, null, !1);let o = p(s),
a = 0,
l = -1;for (; r.nextNode();) {
l++;for (r.currentNode === i && (a = h(e), i.parentNode.insertBefore(e, i)); -1 !== o && s[o].index === l;) {
if (a > 0) {
for (; -1 !== o;) s[o].index += a, o = p(s, o);return;
}o = p(s, o);
}
}
}(i, o, a.firstChild) : a.insertBefore(o, a.firstChild), window.ShadyCSS.prepareTemplateStyles(n, t);const l = a.querySelector("style");if (window.ShadyCSS.nativeShadow && null !== l) e.insertBefore(l.cloneNode(!0), e.firstChild);else if (i) {
a.insertBefore(o, a.firstChild);const t = new Set();t.add(o), u(i, t);
}
};window.JSCompiler_renameProperty = (t, e) => t;const $ = { toAttribute(t, e) {
switch (e) {case Boolean:
return t ? "" : null;case Object:case Array:
return null == t ? t : JSON.stringify(t);}return t;
}, fromAttribute(t, e) {
switch (e) {case Boolean:
return null !== t;case Number:
return null === t ? null : Number(t);case Object:case Array:
return JSON.parse(t);}return t;
} },
q = (t, e) => e !== t && (e == e || t == t),
L = { attribute: !0, type: String, converter: $, reflect: !1, hasChanged: q };class B extends HTMLElement {
constructor() {
super(), this._updateState = 0, this._instanceProperties = void 0, this._updatePromise = new Promise(t => this._enableUpdatingResolver = t), this._changedProperties = new Map(), this._reflectingProperties = void 0, this.initialize();
}static get observedAttributes() {
this.finalize();const t = [];return this._classProperties.forEach((e, i) => {
const n = this._attributeNameForProperty(i, e);void 0 !== n && (this._attributeToPropertyMap.set(n, i), t.push(n));
}), t;
}static _ensureClassProperties() {
if (!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties", this))) {
this._classProperties = new Map();const t = Object.getPrototypeOf(this)._classProperties;void 0 !== t && t.forEach((t, e) => this._classProperties.set(e, t));
}
}static createProperty(t, e = L) {
if (this._ensureClassProperties(), this._classProperties.set(t, e), e.noAccessor || this.prototype.hasOwnProperty(t)) return;const i = "symbol" == typeof t ? Symbol() : "__" + t,
n = this.getPropertyDescriptor(t, i, e);void 0 !== n && Object.defineProperty(this.prototype, t, n);
}static getPropertyDescriptor(t, e, i) {
return { get() {
return this[e];
}, set(i) {
const n = this[t];this[e] = i, this._requestUpdate(t, n);
}, configurable: !0, enumerable: !0 };
}static getPropertyOptions(t) {
return this._classProperties && this._classProperties.get(t) || L;
}static finalize() {
const t = Object.getPrototypeOf(this);if (t.hasOwnProperty("finalized") || t.finalize(), this.finalized = !0, this._ensureClassProperties(), this._attributeToPropertyMap = new Map(), this.hasOwnProperty(JSCompiler_renameProperty("properties", this))) {
const t = this.properties,
e = [...Object.getOwnPropertyNames(t), ...("function" == typeof Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(t) : [])];for (const i of e) this.createProperty(i, t[i]);
}
}static _attributeNameForProperty(t, e) {
const i = e.attribute;return !1 === i ? void 0 : "string" == typeof i ? i : "string" == typeof t ? t.toLowerCase() : void 0;
}static _valueHasChanged(t, e, i = q) {
return i(t, e);
}static _propertyValueFromAttribute(t, e) {
const i = e.type,
n = e.converter || $,
s = "function" == typeof n ? n : n.fromAttribute;return s ? s(t, i) : t;
}static _propertyValueToAttribute(t, e) {
if (void 0 === e.reflect) return;const i = e.type,
n = e.converter;return (n && n.toAttribute || $.toAttribute)(t, i);
}initialize() {
this._saveInstanceProperties(), this._requestUpdate();
}_saveInstanceProperties() {
this.constructor._classProperties.forEach((t, e) => {
if (this.hasOwnProperty(e)) {
const t = this[e];delete this[e], this._instanceProperties || (this._instanceProperties = new Map()), this._instanceProperties.set(e, t);
}
});
}_applyInstanceProperties() {
this._instanceProperties.forEach((t, e) => this[e] = t), this._instanceProperties = void 0;
}connectedCallback() {
this.enableUpdating();
}enableUpdating() {
void 0 !== this._enableUpdatingResolver && (this._enableUpdatingResolver(), this._enableUpdatingResolver = void 0);
}disconnectedCallback() {}attributeChangedCallback(t, e, i) {
e !== i && this._attributeToProperty(t, i);
}_propertyToAttribute(t, e, i = L) {
const n = this.constructor,
s = n._attributeNameForProperty(t, i);if (void 0 !== s) {
const t = n._propertyValueToAttribute(e, i);if (void 0 === t) return;this._updateState = 8 | this._updateState, null == t ? this.removeAttribute(s) : this.setAttribute(s, t), this._updateState = -9 & this._updateState;
}
}_attributeToProperty(t, e) {
if (8 & this._updateState) return;const i = this.constructor,
n = i._attributeToPropertyMap.get(t);if (void 0 !== n) {
const t = i.getPropertyOptions(n);this._updateState = 16 | this._updateState, this[n] = i._propertyValueFromAttribute(e, t), this._updateState = -17 & this._updateState;
}
}_requestUpdate(t, e) {
let i = !0;if (void 0 !== t) {
const n = this.constructor,
s = n.getPropertyOptions(t);n._valueHasChanged(this[t], e, s.hasChanged) ? (this._changedProperties.has(t) || this._changedProperties.set(t, e), !0 !== s.reflect || 16 & this._updateState || (void 0 === this._reflectingProperties && (this._reflectingProperties = new Map()), this._reflectingProperties.set(t, s))) : i = !1;
}!this._hasRequestedUpdate && i && (this._updatePromise = this._enqueueUpdate());
}requestUpdate(t, e) {
return this._requestUpdate(t, e), this.updateComplete;
}async _enqueueUpdate() {
this._updateState = 4 | this._updateState;try {
await this._updatePromise;
} catch (t) {}const t = this.performUpdate();return null != t && (await t), !this._hasRequestedUpdate;
}get _hasRequestedUpdate() {
return 4 & this._updateState;
}get hasUpdated() {
return 1 & this._updateState;
}performUpdate() {
this._instanceProperties && this._applyInstanceProperties();let t = !1;const e = this._changedProperties;try {
t = this.shouldUpdate(e), t ? this.update(e) : this._markUpdated();
} catch (e) {
throw t = !1, this._markUpdated(), e;
}t && (1 & this._updateState || (this._updateState = 1 | this._updateState, this.firstUpdated(e)), this.updated(e));
}_markUpdated() {
this._changedProperties = new Map(), this._updateState = -5 & this._updateState;
}get updateComplete() {
return this._getUpdateComplete();
}_getUpdateComplete() {
return this._updatePromise;
}shouldUpdate(t) {
return !0;
}update(t) {
void 0 !== this._reflectingProperties && this._reflectingProperties.size > 0 && (this._reflectingProperties.forEach((t, e) => this._propertyToAttribute(e, this[e], t)), this._reflectingProperties = void 0), this._markUpdated();
}updated(t) {}firstUpdated(t) {}
}B.finalized = !0;
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
const W = (t, e) => "method" === e.kind && e.descriptor && !("value" in e.descriptor) ? Object.assign(Object.assign({}, e), { finisher(i) {
i.createProperty(e.key, t);
} }) : { kind: "field", key: Symbol(), placement: "own", descriptor: {}, initializer() {
"function" == typeof e.initializer && (this[e.key] = e.initializer.call(this));
}, finisher(i) {
i.createProperty(e.key, t);
} };function J(t) {
return (e, i) => void 0 !== i ? ((t, e, i) => {
e.constructor.createProperty(i, t);
})(t, e, i) : W(t, e);
}
/**
@license
Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
*/const Z = "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype,
Q = Symbol();class K {
constructor(t, e) {
if (e !== Q) throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText = t;
}get styleSheet() {
return void 0 === this._styleSheet && (Z ? (this._styleSheet = new CSSStyleSheet(), this._styleSheet.replaceSync(this.cssText)) : this._styleSheet = null), this._styleSheet;
}toString() {
return this.cssText;
}
}const G = (t, ...e) => {
const i = e.reduce((e, i, n) => e + (t => {
if (t instanceof K) return t.cssText;if ("number" == typeof t) return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`);
})(i) + t[n + 1], t[0]);return new K(i, Q);
};
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
(window.litElementVersions || (window.litElementVersions = [])).push("2.3.1");const X = {};class tt extends B {
static getStyles() {
return this.styles;
}static _getUniqueStyles() {
if (this.hasOwnProperty(JSCompiler_renameProperty("_styles", this))) return;const t = this.getStyles();if (void 0 === t) this._styles = [];else if (Array.isArray(t)) {
const e = (t, i) => t.reduceRight((t, i) => Array.isArray(i) ? e(i, t) : (t.add(i), t), i),
i = e(t, new Set()),
n = [];i.forEach(t => n.unshift(t)), this._styles = n;
} else this._styles = [t];
}initialize() {
super.initialize(), this.constructor._getUniqueStyles(), this.renderRoot = this.createRenderRoot(), window.ShadowRoot && this.renderRoot instanceof window.ShadowRoot && this.adoptStyles();
}createRenderRoot() {
return this.attachShadow({ mode: "open" });
}adoptStyles() {
const t = this.constructor._styles;0 !== t.length && (void 0 === window.ShadyCSS || window.ShadyCSS.nativeShadow ? Z ? this.renderRoot.adoptedStyleSheets = t.map(t => t.styleSheet) : this._needsShimAdoptedStyleSheets = !0 : window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t => t.cssText), this.localName));
}connectedCallback() {
super.connectedCallback(), this.hasUpdated && void 0 !== window.ShadyCSS && window.ShadyCSS.styleElement(this);
}update(t) {
const e = this.render();super.update(t), e !== X && this.constructor.render(e, this.renderRoot, { scopeName: this.localName, eventContext: this }), this._needsShimAdoptedStyleSheets && (this._needsShimAdoptedStyleSheets = !1, this.constructor._styles.forEach(t => {
const e = document.createElement("style");e.textContent = t.cssText, this.renderRoot.appendChild(e);
}));
}render() {
return X;
}
}tt.finalized = !0, tt.render = (t, e, n) => {
if (!n || "object" != typeof n || !n.scopeName) throw new Error("The `scopeName` option is required.");const s = n.scopeName,
r = O.has(e),
o = H && 11 === e.nodeType && !!e.host,
a = o && !F.has(s),
l = a ? document.createDocumentFragment() : e;if (((t, e, n) => {
let s = O.get(e);void 0 === s && (i(e, e.firstChild), O.set(e, s = new P(Object.assign({ templateFactory: D }, n))), s.appendInto(e)), s.setValue(t), s.commit();
})(t, l, Object.assign({ templateFactory: z(s) }, n)), a) {
const t = O.get(l);O.delete(l);const n = t.value instanceof y ? t.value.template : void 0;I(s, l, n), i(e, e.firstChild), e.appendChild(l), O.set(e, t);
}!r && o && window.ShadyCSS.styleElement(e.host);
};
/**
* @license
* Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
const et = new WeakMap(),
it = (nt = t => e => {
const i = et.get(e);if (void 0 === t && e instanceof x) {
if (void 0 !== i || !et.has(e)) {
const t = e.committer.name;e.committer.element.removeAttribute(t);
}
} else t !== i && e.setValue(t);et.set(e, t);
}, (...t) => {
const e = nt(...t);return m.set(e, !0), e;
});var nt,
st = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,
rt = "[^\\s]+",
ot = /\[([^]*?)\]/gm;function at(t, e) {
for (var i = [], n = 0, s = t.length; n < s; n++) i.push(t[n].substr(0, e));return i;
}var lt = function (t) {
return function (e, i) {
var n = i[t].map(function (t) {
return t.toLowerCase();
}).indexOf(e.toLowerCase());return n > -1 ? n : null;
};
};function dt(t) {
for (var e = [], i = 1; i < arguments.length; i++) e[i - 1] = arguments[i];for (var n = 0, s = e; n < s.length; n++) {
var r = s[n];for (var o in r) t[o] = r[o];
}return t;
}var ct = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
ut = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
ht = at(ut, 3),
pt = { dayNamesShort: at(ct, 3), dayNames: ct, monthNamesShort: ht, monthNames: ut, amPm: ["am", "pm"], DoFn: function (t) {
return t + ["th", "st", "nd", "rd"][t % 10 > 3 ? 0 : (t - t % 10 != 10 ? 1 : 0) * t % 10];
} },
mt = dt({}, pt),
ft = function (t, e) {
for (void 0 === e && (e = 2), t = String(t); t.length < e;) t = "0" + t;return t;
},
gt = { D: function (t) {
return String(t.getDate());
}, DD: function (t) {
return ft(t.getDate());
}, Do: function (t, e) {
return e.DoFn(t.getDate());
}, d: function (t) {
return String(t.getDay());
}, dd: function (t) {
return ft(t.getDay());
}, ddd: function (t, e) {
return e.dayNamesShort[t.getDay()];
}, dddd: function (t, e) {
return e.dayNames[t.getDay()];
}, M: function (t) {
return String(t.getMonth() + 1);
}, MM: function (t) {
return ft(t.getMonth() + 1);
}, MMM: function (t, e) {
return e.monthNamesShort[t.getMonth()];
}, MMMM: function (t, e) {
return e.monthNames[t.getMonth()];
}, YY: function (t) {
return ft(String(t.getFullYear()), 4).substr(2);
}, YYYY: function (t) {
return ft(t.getFullYear(), 4);
}, h: function (t) {
return String(t.getHours() % 12 || 12);
}, hh: function (t) {
return ft(t.getHours() % 12 || 12);
}, H: function (t) {
return String(t.getHours());
}, HH: function (t) {
return ft(t.getHours());
}, m: function (t) {
return String(t.getMinutes());
}, mm: function (t) {
return ft(t.getMinutes());
}, s: function (t) {
return String(t.getSeconds());
}, ss: function (t) {
return ft(t.getSeconds());
}, S: function (t) {
return String(Math.round(t.getMilliseconds() / 100));
}, SS: function (t) {
return ft(Math.round(t.getMilliseconds() / 10), 2);
}, SSS: function (t) {
return ft(t.getMilliseconds(), 3);
}, a: function (t, e) {
return t.getHours() < 12 ? e.amPm[0] : e.amPm[1];
}, A: function (t, e) {
return t.getHours() < 12 ? e.amPm[0].toUpperCase() : e.amPm[1].toUpperCase();
}, ZZ: function (t) {
var e = t.getTimezoneOffset();return (e > 0 ? "-" : "+") + ft(100 * Math.floor(Math.abs(e) / 60) + Math.abs(e) % 60, 4);
}, Z: function (t) {
var e = t.getTimezoneOffset();return (e > 0 ? "-" : "+") + ft(Math.floor(Math.abs(e) / 60), 2) + ":" + ft(Math.abs(e) % 60, 2);
} },
_t = function (t) {
return +t - 1;
},
yt = [null, "[1-9]\\d?"],
vt = [null, rt],
St = ["isPm", rt, function (t, e) {
var i = t.toLowerCase();return i === e.amPm[0] ? 0 : i === e.amPm[1] ? 1 : null;
}],
wt = ["timezoneOffset", "[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?", function (t) {
var e = (t + "").match(/([+-]|\d\d)/gi);if (e) {
var i = 60 * +e[1] + parseInt(e[2], 10);return "+" === e[0] ? i : -i;
}return 0;
}],
bt = (lt("monthNamesShort"), lt("monthNames"), { default: "ddd MMM DD YYYY HH:mm:ss", shortDate: "M/D/YY", mediumDate: "MMM D, YYYY", longDate: "MMMM D, YYYY", fullDate: "dddd, MMMM D, YYYY", isoDate: "YYYY-MM-DD", isoDateTime: "YYYY-MM-DDTHH:mm:ssZ", shortTime: "HH:mm", mediumTime: "HH:mm:ss", longTime: "HH:mm:ss.SSS" });var Ct = function (t, e, i) {
if (void 0 === e && (e = bt.default), void 0 === i && (i = {}), "number" == typeof t && (t = new Date(t)), "[object Date]" !== Object.prototype.toString.call(t) || isNaN(t.getTime())) throw new Error("Invalid Date pass to format");var n = [];e = (e = bt[e] || e).replace(ot, function (t, e) {
return n.push(e), "@@@";
});var s = dt(dt({}, mt), i);return (e = e.replace(st, function (e) {
return gt[e](t, s);
})).replace(/@@@/g, function () {
return n.shift();
});
},
xt = (function () {
try {
new Date().toLocaleDateString("i");
} catch (t) {
return "RangeError" === t.name;
}
}(), function () {
try {
new Date().toLocaleString("i");
} catch (t) {
return "RangeError" === t.name;
}
}(), function () {
try {
new Date().toLocaleTimeString("i");
} catch (t) {
return "RangeError" === t.name;
}
}(), new Set(["call-service", "divider", "section", "weblink", "cast", "select"])),
Pt = { alert: "toggle", automation: "toggle", climate: "climate", cover: "cover", fan: "toggle", group: "group", input_boolean: "toggle", input_number: "input-number", input_select: "input-select", input_text: "input-text", light: "toggle", lock: "lock", media_player: "media-player", remote: "toggle", scene: "scene", script: "script", sensor: "sensor", timer: "timer", switch: "toggle", vacuum: "toggle", water_heater: "climate", input_datetime: "input-datetime" },
Nt = function (t, e) {
void 0 === e && (e = !1);var i = function (t, e) {
return n("hui-error-card", { type: "error", error: t, config: e });
},
n = function (t, e) {
var n = window.document.createElement(t);try {
n.setConfig(e);
} catch (n) {
return console.error(t, n), i(n.message, e);
}return n;
};if (!t || "object" != typeof t || !e && !t.type) return i("No type defined", t);var s = t.type;if (s && s.startsWith("custom:")) s = s.substr("custom:".length);else if (e) {
if (xt.has(s)) s = "hui-" + s + "-row";else {
if (!t.entity) return i("Invalid config given.", t);var r = t.entity.split(".", 1)[0];s = "hui-" + (Pt[r] || "text") + "-entity-row";
}
} else s = "hui-" + s + "-card";if (customElements.get(s)) return n(s, t);var o = i("Custom element doesn't exist: " + t.type + ".", t);o.style.display = "None";var a = setTimeout(function () {
o.style.display = "";
}, 2e3);return customElements.whenDefined(t.type).then(function () {
clearTimeout(a), function (t, e, i, n) {
n = n || {}, i = null == i ? {} : i;var s = new Event(e, { bubbles: void 0 === n.bubbles || n.bubbles, cancelable: Boolean(n.cancelable), composed: void 0 === n.composed || n.composed });s.detail = i, t.dispatchEvent(s);
}(o, "ll-rebuild", {}, o);
}), o;
};console.info("%c STACK-IN-CARD \n%c Version 0.1.1 ", "color: orange; font-weight: bold; background: black", "color: white; font-weight: bold; background: dimgray");const Mt = window.loadCardHelpers ? window.loadCardHelpers() : void 0;let Tt = class extends tt {
constructor() {
super(...arguments), this._initialized = !1, this.promiseQueue = [];
}set hass(t) {
this._hass = t, this._card && (this._card.hass = t);
}static get styles() {
return G`
ha-card {
overflow: hidden;
}
`;
}setConfig(t) {
var e, i;if (!t.cards) throw new Error("There is no cards parameter defined");this._config = Object.assign(Object.assign({ mode: "vertical" }, t), { keep: Object.assign({ background: !1, margin: !1, box_shadow: !1, border_radius: !1 }, t.keep) }), (null === (e = this._config.keep) || void 0 === e ? void 0 : e.margin) && void 0 === (null === (i = this._config.keep) || void 0 === i ? void 0 : i.outer_padding) && (this._config.keep.outer_padding = !0), this._initialized = !1;
}render() {
if (!this._hass || !this._config) return Y``;if (!this._initialized) {
const t = this._createCard({ type: this._config.mode + "-stack", cards: this._config.cards }).then(t => {
this._card = t, this._waitForChildren(t, !1), window.setTimeout(() => {
var e, i, n, s, r;if ((null === (i = null === (e = this._config) || void 0 === e ? void 0 : e.keep) || void 0 === i ? void 0 : i.background) || this._waitForChildren(t, !0), (null === (s = null === (n = this._config) || void 0 === n ? void 0 : n.keep) || void 0 === s ? void 0 : s.outer_padding) && (null === (r = this._card) || void 0 === r ? void 0 : r.shadowRoot)) {
const t = this._card.shadowRoot.getElementById("root");t && (t.style.padding = "8px");
}
}, 500), this._initialized = !0;
});this.promiseQueue.push(t);
}return Y`
<ha-card header=${it(this._config.title)}>
<div>${this._card}</div>
</ha-card>
`;
}_updateStyle(t, e) {
var i, n, s, r, o, a;t && ((null === (n = null === (i = this._config) || void 0 === i ? void 0 : i.keep) || void 0 === n ? void 0 : n.box_shadow) || (t.style.boxShadow = "none"), !(null === (r = null === (s = this._config) || void 0 === s ? void 0 : s.keep) || void 0 === r ? void 0 : r.background) && e && "true" !== getComputedStyle(t).getPropertyValue("--keep-background").trim() && (t.style.background = "transparent"), (null === (a = null === (o = this._config) || void 0 === o ? void 0 : o.keep) || void 0 === a ? void 0 : a.border_radius) || (t.style.borderRadius = "0"));
}_loopChildren(t, e) {
t.childNodes.forEach(t => {
var i, n;"STACK-IN-CARD" !== t.tagName && (!(null === (n = null === (i = this._config) || void 0 === i ? void 0 : i.keep) || void 0 === n ? void 0 : n.margin) && t.style && (t.style.margin = "0px"), this._waitForChildren(t, e));
});
}_updateChildren(t, e) {
if (t) if (t.shadowRoot) {
const i = t.shadowRoot.querySelector("ha-card");if (i) this._updateStyle(i, e);else {
const i = t.shadowRoot.getElementById("root") || t.shadowRoot.getElementById("card");if (!i) return;this._loopChildren(i, e);
}
} else "function" == typeof t.querySelector && t.querySelector("ha-card") && this._updateStyle(t.querySelector("ha-card"), e), this._loopChildren(t, e);
}_waitForChildren(t, e) {
t.updateComplete ? t.updateComplete.then(() => {
this._updateChildren(t, e);
}) : this._updateChildren(t, e);
}async _createCard(t) {
let e;return e = Mt ? (await Mt).createCardElement(t) : Nt(t), this._hass && (e.hass = this._hass), e && e.addEventListener("ll-rebuild", i => {
i.stopPropagation(), this._rebuildCard(e, t);
}, { once: !0 }), e;
}async _rebuildCard(t, e) {
const i = this._createCard(e);this.promiseQueue.push(i);const n = await i;return t.replaceWith(n), this._card = n, window.setTimeout(() => {
var t, e, i, n, s;if ((null === (e = null === (t = this._config) || void 0 === t ? void 0 : t.keep) || void 0 === e ? void 0 : e.background) || this._waitForChildren(this._card, !0), (null === (n = null === (i = this._config) || void 0 === i ? void 0 : i.keep) || void 0 === n ? void 0 : n.outer_padding) && (null === (s = this._card) || void 0 === s ? void 0 : s.shadowRoot)) {
const t = this._card.shadowRoot.getElementById("root");t && (t.style.padding = "8px");
}
}, 500), n;
}getCardSize() {
return this._initialized || this.render(), this.promiseQueue.length ? Promise.all(this.promiseQueue).then(() => this.cardSize) : this.cardSize;
}get cardSize() {
return this._card && "function" == typeof this._card.getCardSize ? this._card.getCardSize() : 1;
}
};var Et;t([J()], Tt.prototype, "_card", void 0), t([J()], Tt.prototype, "_config", void 0), t([J()], Tt.prototype, "_hass", void 0), Tt = t([(Et = "stack-in-card", t => "function" == typeof t ? ((t, e) => (window.customElements.define(t, e), e))(Et, t) : ((t, e) => {
const { kind: i, elements: n } = e;return { kind: i, elements: n, finisher(e) {
window.customElements.define(t, e);
} };
})(Et, t))], Tt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment