UNPKG

@sandlada/mdc

Version:

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

8 lines 1.62 kB
import"../../node_modules/lit/index.js"; /** * @license * Copyright 2026 Kai-Orion & Sandlada * SPDX-License-Identifier: MIT */ var e=class{constructor(e,t){this.currentAnimation=null,this.mutationObserver=null,this.rafId=null,this.hasRendered=!1,this.onMutation=()=>{this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null;let e=this.options.target();!e||!this.hasRendered||this.animate(e)}))},this.host=e,this.options={duration:300,easing:`cubic-bezier(0.2, 0, 0.2, 1)`,...t},e.addController(this)}hostConnected(){this.hasRendered=!1,this.cancelPendingRaf(),this.cancelAnimation(),this.mutationObserver=new MutationObserver(this.onMutation),this.mutationObserver.observe(this.host,{childList:!0,subtree:!0,characterData:!0,attributes:!1})}hostDisconnected(){this.mutationObserver?.disconnect(),this.mutationObserver=null,this.cancelPendingRaf(),this.cancelAnimation(),this.hasRendered=!1}hostUpdated(){let e=this.options.target();if(e){if(!this.hasRendered){this.hasRendered=!0;return}this.rafId===null&&this.animate(e)}}animate(e){let{duration:t,easing:n}=this.options;this.cancelAnimation();let r=e.animate([{opacity:`0`,offset:0},{opacity:`0`,offset:.15},{opacity:`1`,offset:1}],{duration:t,easing:n,fill:`none`});this.currentAnimation=r,r.finished.then(()=>{this.currentAnimation===r&&(this.currentAnimation=null)}).catch(()=>{})}cancelAnimation(){this.currentAnimation&&=(this.currentAnimation.cancel(),null)}cancelPendingRaf(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}};export{e as OpacityTransitionController}; //# sourceMappingURL=opacity-transition-controller.js.map