@sandlada/mdc
Version:
@sandlada/mdc is an open source component library that follows the Material Design 3 design specifications.
7 lines (6 loc) • 693 B
JavaScript
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const t=Symbol("dispatchHooks");function e(e,n){const o=e[t];if(!o)throw new Error(`'${e.type}' event needs setupDispatchHooks().`);o.addEventListener("after",n)}const n=new WeakMap;function o(e,...o){let s=n.get(e);s||(s=new Set,n.set(e,s));for(const n of o){if(s.has(n))continue;let o=!1;e.addEventListener(n,n=>{if(o)return;n.stopImmediatePropagation();const s=Reflect.construct(n.constructor,[n.type,n]),c=new EventTarget;s[t]=c,o=!0;const r=e.dispatchEvent(s);o=!1,r||n.preventDefault(),c.dispatchEvent(new Event("after"))},{capture:!0}),s.add(n)}}export{e as afterDispatch,o as setupDispatchHooks};