UNPKG

@huluvu424242/honey-slideshow

Version:

Text to Speech component wich is reading texts from DOM elements.

38 lines (35 loc) 1.18 kB
'use strict'; const attachComponent = async (delegate, container, component, cssClasses, componentProps) => { if (delegate) { return delegate.attachViewToDom(container, component, componentProps, cssClasses); } if (typeof component !== 'string' && !(component instanceof HTMLElement)) { throw new Error('framework delegate is missing'); } const el = (typeof component === 'string') ? container.ownerDocument && container.ownerDocument.createElement(component) : component; if (cssClasses) { cssClasses.forEach(c => el.classList.add(c)); } if (componentProps) { Object.assign(el, componentProps); } container.appendChild(el); if (el.componentOnReady) { await el.componentOnReady(); } return el; }; const detachComponent = (delegate, element) => { if (element) { if (delegate) { const container = element.parentElement; return delegate.removeViewFromDom(container, element); } element.remove(); } return Promise.resolve(); }; exports.attachComponent = attachComponent; exports.detachComponent = detachComponent;