@popeindustries/lit-html
Version:
Seamlessly and efficiently use @popeindustries/lit-html-server rendered HTML to hydrate lit-html templates in the browser
6 lines (5 loc) • 1.15 kB
JavaScript
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/import{noChange as o}from"../lit-html.js";import{directive as u,Directive as n,PartType as l}from"../directive.js";class d extends n{constructor(r){var t;if(super(r),r.type!==l.ATTRIBUTE||r.name!=="style"||((t=r.strings)===null||t===void 0?void 0:t.length)>2)throw new Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.")}render(r){return Object.keys(r).reduce((t,i)=>{const e=r[i];return e==null?t:(i=i.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g,"-$&").toLowerCase(),t+`${i}:${e};`)},"")}update(r,[t]){const{style:i}=r.element;if(this._previousStyleProperties===void 0){this._previousStyleProperties=new Set;for(const e in t)this._previousStyleProperties.add(e);return this.render(t)}this._previousStyleProperties.forEach(e=>{t[e]==null&&(this._previousStyleProperties.delete(e),e.includes("-")?i.removeProperty(e):i[e]="")});for(const e in t){const s=t[e];s!=null&&(this._previousStyleProperties.add(e),e.includes("-")?i.setProperty(e,s):i[e]=s)}return o}}const v=u(d);export{v as styleMap};