UNPKG

@sandlada/mdc

Version:

@sandlada/mdc is an open source component library that follows the Material Design 3 design specifications.

11 lines 1.35 kB
import"../../node_modules/lit/index.js"; /** * @license * Copyright 2023 Google LLC * SPDX-License-Identifier: Apache-2.0 * * @link * https://github.com/material-components/material-web/blob/main/internal/controller/attachable-controller.ts */ const e=Symbol(`attachableController`);let t;t=new MutationObserver(t=>{for(let n of t)n.target[e]?.hostConnected()});var n=class{get htmlFor(){return this.host.getAttribute(`for`)}set htmlFor(e){e===null?this.host.removeAttribute(`for`):this.host.setAttribute(`for`,e)}get control(){return this.host.hasAttribute(`for`)?!this.htmlFor||!this.host.isConnected?null:this.host.getRootNode().querySelector(`#${this.htmlFor}`):this.currentControl||this.host.parentElement}set control(e){e?this.attach(e):this.detach()}constructor(n,r){this.currentControl=null,this.host=n,this.onControlChange=r,n.addController(this),n[e]=this,t?.observe(n,{attributeFilter:[`for`]})}attach(e){e!==this.currentControl&&(this.setCurrentControl(e),this.host.removeAttribute(`for`))}detach(){this.setCurrentControl(null),this.host.setAttribute(`for`,``)}hostConnected(){this.setCurrentControl(this.control)}hostDisconnected(){this.setCurrentControl(null)}setCurrentControl(e){this.onControlChange(this.currentControl,e),this.currentControl=e}};export{n as AttachableController}; //# sourceMappingURL=attachable-controller.js.map