/*! For license information please see class-map.js.LICENSE.txt */
import{AttributePart as t,directive as e,PropertyPart as s}from"../lit-html.js";class c{constructor(t){this.classes=new Set,this.changed=!1,this.element=t;const e=(t.getAttribute("class")||"").split(/\s+/);for(const s of e)this.classes.add(s)}add(t){this.classes.add(t),this.changed=!0}remove(t){this.classes.delete(t),this.changed=!0}commit(){if(this.changed){let t="";this.classes.forEach((e=>t+=e+" ")),this.element.setAttribute("class",t)}}}const i=new WeakMap;export const classMap=e((e=>a=>{if(!(a instanceof t)||a instanceof s||"class"!==a.committer.name||a.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:n}=a,{element:o}=n;let r=i.get(a);void 0===r&&(o.setAttribute("class",n.strings.join(" ")),i.set(a,r=new Set));const l=o.classList||new c(o);r.forEach((t=>{t in e||(l.remove(t),r.delete(t))}));for(const t in e){const s=e[t];s!=r.has(t)&&(s?(l.add(t),r.add(t)):(l.remove(t),r.delete(t)))}"function"===typeof l.commit&&l.commit()}));