@haxtheweb/haxcms-nodejs
Version:
HAXcms single and multisite nodejs server, api, and administration
6 lines • 1.06 kB
JavaScript
import{noChange as t}from"../lit-html.js";import{directive as e,Directive as s,PartType as r}from"../directive.js";
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const n="important",i=" !"+n,o=e(class extends s{constructor(t){if(super(t),t.type!==r.ATTRIBUTE||"style"!==t.name||t.strings?.length>2)throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(t){return Object.keys(t).reduce(((e,s)=>{const r=t[s];return null==r?e:e+`${s=s.includes("-")?s:s.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase()}:${r};`}),"")}update(e,[s]){const{style:r}=e.element;if(void 0===this.ft)return this.ft=new Set(Object.keys(s)),this.render(s);for(const t of this.ft)null==s[t]&&(this.ft.delete(t),t.includes("-")?r.removeProperty(t):r[t]=null);for(const t in s){const e=s[t];if(null!=e){this.ft.add(t);const s="string"==typeof e&&e.endsWith(i);t.includes("-")||s?r.setProperty(t,s?e.slice(0,-11):e,s?n:""):r[t]=e}}return t}});export{o as styleMap};