dap-design-system
Version:
Official design system for the DÁP (dap.gov.hu)
38 lines (37 loc) • 1.4 kB
JavaScript
import { noChange as l } from "../lit-html.js";
import { directive as c, Directive as a, PartType as u } from "../directive.js";
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const o = "important", d = " !" + o, h = c(class extends a {
constructor(n) {
var t;
if (super(n), n.type !== u.ATTRIBUTE || n.name !== "style" || ((t = n.strings) == null ? void 0 : t.length) > 2) throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.");
}
render(n) {
return Object.keys(n).reduce((t, s) => {
const e = n[s];
return e == null ? t : t + `${s = s.includes("-") ? s : s.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, "-$&").toLowerCase()}:${e};`;
}, "");
}
update(n, [t]) {
const { style: s } = n.element;
if (this.ft === void 0) return this.ft = new Set(Object.keys(t)), this.render(t);
for (const e of this.ft) t[e] == null && (this.ft.delete(e), e.includes("-") ? s.removeProperty(e) : s[e] = null);
for (const e in t) {
const r = t[e];
if (r != null) {
this.ft.add(e);
const i = typeof r == "string" && r.endsWith(d);
e.includes("-") || i ? s.setProperty(e, i ? r.slice(0, -11) : r, i ? o : "") : s[e] = r;
}
}
return l;
}
});
export {
h as styleMap
};
//# sourceMappingURL=style-map.js.map