@vime/core
Version:
Customizable, extensible, accessible and framework agnostic media player.
37 lines (36 loc) • 1.22 kB
JavaScript
/**
* INSPIRED BY: https://github.com/shoelace-style/shoelace/blob/next/src/components/icon-library/icon-library-registry.ts
*/
import { getElement } from '@stencil/core';
import { createStencilHook } from '../../../utils/stencil';
import { isUndefined } from '../../../utils/unit';
export const ICONS_BASE_CDN_URL = process.env.NODE_ENV === 'development'
? '/icons'
: 'https://cdn.jsdelivr.net/npm/@vime/core@latest/icons';
const registry = new Map(Object.entries({
vime: iconName => `${ICONS_BASE_CDN_URL}/vime/vm-${iconName}.svg`,
material: iconName => `${ICONS_BASE_CDN_URL}/material/md-${iconName}.svg`,
}));
const watch = new Set();
export function withIconRegistry(component) {
const el = getElement(component);
createStencilHook(component, () => {
watch.add(el);
}, () => {
watch.delete(el);
});
}
export const getIconLibraryResolver = (name) => registry.get(name);
export function registerIconLibrary(name, resolver) {
if (!isUndefined(resolver)) {
registry.set(name, resolver);
}
// Redraw watched icons.
watch.forEach(iconEl => {
if (iconEl.library === name)
iconEl.redraw();
});
}
export function deregisterIconLibrary(name) {
registry.delete(name);
}