Skip to content

Commit

Permalink
chore: bump to version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosabot committed Aug 12, 2024
1 parent 26cbfe3 commit 2ab5785
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 95 deletions.
197 changes: 103 additions & 94 deletions dist/streamline-card.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
var f = Object.defineProperty;
var h = (e, s, o) => s in e ? f(e, s, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[s] = o;
var n = (e, s, o) => h(e, typeof s != "symbol" ? s + "" : s, o);
function deepReplace(e, s) {
if (!e && !s.default)
return s.card;
let o = [];
e && (o = e.slice(0)), s.default && (o = o.concat(s.default));
let r = s.card ? JSON.stringify(s.card) : JSON.stringify(s.element);
return o.forEach((t) => {
const a = Object.keys(t)[0], c = Object.values(t)[0];
if (typeof c == "number" || typeof c == "boolean") {
const d = new RegExp(`"\\[\\[${a}\\]\\]"`, "gm");
r = r.replace(d, c);
}
if (typeof c == "object") {
const d = new RegExp(`"\\[\\[${a}\\]\\]"`, "gm"), l = JSON.stringify(c);
r = r.replace(d, l);
} else {
const d = new RegExp(`\\[\\[${a}\\]\\]`, "gm");
r = r.replace(d, c);
}
}), JSON.parse(r);
}
function getLovelaceCast() {
var c = Object.defineProperty;
var f = (e, r, s) => r in e ? c(e, r, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[r] = s;
var d = (e, r, s) => f(e, typeof r != "symbol" ? r + "" : r, s);
const getLovelaceCast = () => {
let e = document.querySelector("hc-main");
if (e = e && e.shadowRoot, e = e && e.querySelector("hc-lovelace"), e = e && e.shadowRoot, e = e && e.querySelector("hui-view"), e) {
const s = e.lovelace;
return s.current_view = e.___curView, s;
if (e && (e = e.shadowRoot), e && (e = e.querySelector("hc-lovelace")), e && (e = e.shadowRoot), e && (e = e.querySelector("hui-view")), e) {
const r = e.lovelace;
return r.current_view = e.___curView, r;
}
return null;
}
function getLovelace() {
}, getLovelace = () => {
let e = document.querySelector("home-assistant");
if (e = e && e.shadowRoot, e = e && e.querySelector("home-assistant-main"), e = e && e.shadowRoot, e = e && e.querySelector("app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver"), e = e && e.shadowRoot || e, e = e && e.querySelector("ha-panel-lovelace"), e = e && e.shadowRoot, e = e && e.querySelector("hui-root"), e) {
const s = e.lovelace;
return s.current_view = e.___curView, s;
if (e && (e = e.shadowRoot), e && (e = e.querySelector("home-assistant-main")), e && (e = e.shadowRoot), e && (e = e.querySelector(
"app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver"
)), e = e && e.shadowRoot || e, e && (e = e.querySelector("ha-panel-lovelace")), e && (e = e.shadowRoot), e && (e = e.querySelector("hui-root")), e) {
const r = e.lovelace;
return r.current_view = e.___curView, r;
}
return null;
};
function deepReplace(e, r) {
if (!r && !e.default)
return e.card;
let s = [];
r && (s = r.slice(0)), e.default && (s = s.concat(e.default));
let a = e.card ? JSON.stringify(e.card) : JSON.stringify(e.element);
return s.forEach((n) => {
const [t] = Object.keys(n), [i] = Object.values(n);
if (typeof i == "number" || typeof i == "boolean") {
const o = new RegExp(`"\\[\\[${t}\\]\\]"`, "gmu");
a = a.replace(o, i);
} else if (typeof i == "object") {
const o = new RegExp(`"\\[\\[${t}\\]\\]"`, "gmu"), l = JSON.stringify(i);
a = a.replace(o, l);
} else {
const o = new RegExp(`\\[\\[${t}\\]\\]`, "gmu");
a = a.replace(o, i);
}
}), JSON.parse(a);
}
const version = "0.0.3";
function evaluateConfig(config, hass) {
const configKeys = Object.keys(config);
for (let key of configKeys)
if (config[key] instanceof Array) {
for (let i = 0; i < config[key].length; i++)
if (typeof config[key][i] == "object")
evaluateConfig(config[key][i], hass);
else {
const states = (hass == null ? void 0 : hass.states) ?? void 0, user = (hass == null ? void 0 : hass.user) ?? void 0, prefix = `
var states = ${JSON.stringify(states)};
var user = ${JSON.stringify(user)};
`, keyWithoutJavascript = key.replace("_javascript", ""), stringToEvaluatate = `${prefix} ${config[key][i]}`;
const getPrefixFromHass = (e) => {
const r = (e == null ? void 0 : e.states) ?? void 0, s = (e == null ? void 0 : e.user) ?? void 0;
return `
var states = ${JSON.stringify(r)};
var user = ${JSON.stringify(s)};
`;
}, doEval = (string) => eval(string), evaluateConfig = (e, r) => {
const s = Object.keys(e);
for (const a of s)
if (e[a] instanceof Array) {
let n;
for (let t = 0; t < e[a].length; t += 1)
if (typeof e[a][t] == "object")
evaluateConfig(e[a][t], r);
else if (a.endsWith("_javascript")) {
const i = getPrefixFromHass(r), o = a.replace("_javascript", "");
try {
config[keyWithoutJavascript] = config[keyWithoutJavascript] || {}, config[keyWithoutJavascript][i] = eval(stringToEvaluatate);
} catch (e) {
config[keyWithoutJavascript][i] = void 0;
e[o] || (e[o] = []), e[o][t] = doEval(
`${i} ${e[a][t]}`
);
} catch (l) {
n = l;
}
}
key.endsWith("_javascript") && delete config[key];
} else if (typeof config[key] == "object")
evaluateConfig(config[key], hass);
else if (key.endsWith("_javascript")) {
const states = (hass == null ? void 0 : hass.states) ?? void 0, user = (hass == null ? void 0 : hass.user) ?? void 0, prefix = `
var states = ${JSON.stringify(states)};
var user = ${JSON.stringify(user)};
`, keyWithoutJavascript = key.replace("_javascript", ""), stringToEvaluatate = `${prefix} ${config[key]}`;
try {
config[keyWithoutJavascript] = eval(stringToEvaluatate), delete config[key];
} catch (e) {
config[keyWithoutJavascript] = void 0;
}
if (a.endsWith("_javascript"))
if (typeof n > "u")
delete e[a];
else
throw delete e[a.replace("_javascript", "")], n;
} else if (typeof e[a] == "object")
evaluateConfig(e[a], r);
else if (a.endsWith("_javascript")) {
const n = getPrefixFromHass(r), t = a.replace("_javascript", "");
e[t] = doEval(`${n} ${e[a]}`), delete e[a];
}
}
(async function() {
const e = window.loadCardHelpers ? await window.loadCardHelpers() : void 0;
}, version = "0.0.4";
(async function e() {
const r = window.loadCardHelpers ? await window.loadCardHelpers() : void 0;
class s extends HTMLElement {
constructor() {
super();
n(this, "_editMode", !1);
n(this, "_isConnected", !1);
n(this, "_config", {});
n(this, "_originalConfig", {});
n(this, "_hass", {});
n(this, "_card");
n(this, "_shadow");
n(this, "_accessedProperties", /* @__PURE__ */ new Set());
d(this, "_editMode", !1);
d(this, "_isConnected", !1);
d(this, "_config", {});
d(this, "_originalConfig", {});
d(this, "_hass", {});
d(this, "_card");
d(this, "_shadow");
d(this, "_accessedProperties", /* @__PURE__ */ new Set());
this._shadow = this.shadowRoot || this.attachShadow({ mode: "open" });
}
updateCardHass() {
Expand All @@ -94,31 +96,38 @@ function evaluateConfig(config, hass) {
this._isConnected && this._card && (this._card.editMode = this._editMode);
}
updateCardConfig() {
var t, a;
this._isConnected && this._card && this._config.card && ((a = (t = this._card).setConfig) == null || a.call(t, this._config.card));
var t, i;
this._isConnected && this._card && this._config && ((i = (t = this._card).setConfig) == null || i.call(t, this._config));
}
connectedCallback() {
this._isConnected = !0, this.updateCardConfig(), this.updateCardEditMode(), this.updateCardHass();
}
disconnectedCallback() {
this._isConnected = !1;
}
get editMode() {
return this._editMode;
}
set editMode(t) {
t !== this._editMode && (this._editMode = t, this.updateCardEditMode());
}
get hass() {
return this._hass;
}
set hass(t) {
this._hass = t, this.parseConfig(), this.updateCardHass();
this._hass = t, this.parseConfig(), this.updateCardConfig(), this.updateCardHass();
}
parseConfig() {
var l;
const t = getLovelace() || getLovelaceCast();
if (!t.config && !t.config.streamline_templates)
throw new Error(
"The object streamline_templates doesn't exist in your main lovelace config."
);
const a = t.config.streamline_templates[this._originalConfig.template];
if (a)
if (a.card || a.element) {
if (a.card && a.element)
const i = t.config.streamline_templates[this._originalConfig.template];
if (i)
if (i.card || i.element) {
if (i.card && i.element)
throw new Error("You can define a card and an element in the template");
} else throw new Error(
"You should define either a card or an element in the template"
Expand All @@ -127,32 +136,32 @@ function evaluateConfig(config, hass) {
`The template "${this._originalConfig.template}" doesn't exist in streamline_templates`
);
this._config = deepReplace(
this._originalConfig.variables,
a
), evaluateConfig(this._config, this._hass);
i,
this._originalConfig.variables
), typeof (((l = this._hass) == null ? void 0 : l.states) ?? void 0) < "u" && evaluateConfig(this._config, this._hass);
}
async setConfig(t) {
if (this._originalConfig = t, this.parseConfig(), this._card === void 0) {
if (this._config.type === void 0)
setConfig(t) {
if (this._originalConfig = t, this.parseConfig(), typeof this._card > "u") {
if (typeof this._config.type > "u")
throw new Error("[Streamline Card] You need to define a type");
this._card = e.createCardElement(this._config), this._shadow.appendChild(this._card);
this._card = r.createCardElement(this._config), this._shadow.appendChild(this._card);
}
this.updateCardConfig();
}
getCardSize() {
var t, a;
return ((a = (t = this._card) == null ? void 0 : t.getCardSize) == null ? void 0 : a.call(t)) ?? 1;
var t, i;
return ((i = (t = this._card) == null ? void 0 : t.getCardSize) == null ? void 0 : i.call(t)) ?? 1;
}
getLayoutOptions() {
var t, a;
return (a = (t = this._card) == null ? void 0 : t.getLayoutOptions) == null ? void 0 : a.call(t);
var t, i;
return (i = (t = this._card) == null ? void 0 : t.getLayoutOptions) == null ? void 0 : i.call(t);
}
}
customElements.define("streamline-card", s), window.customCards = window.customCards || [], window.customCards.push({
type: "streamline-card",
customElements.define("streamline-card", s), window.customCards || (window.customCards = []), window.customCards.push({
description: "A config simplifier.",
name: "Streamline Card",
preview: !1,
description: "A config simplifier."
type: "streamline-card"
}), console.info(
`%c Streamline Card %c ${version}`,
"background-color:#c2b280;color:#242424;padding:4px 4px 4px 8px;border-radius:20px 0 0 20px;font-family:sans-serif;",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "streamline-card",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"type": "module",
"main": "src/streamline-card.js",
Expand Down

0 comments on commit 2ab5785

Please sign in to comment.