@stories-js/core
Version:
Stories web components to build stories
43 lines • 1.45 kB
JavaScript
/*!
* (C) StoriesJS https://storiesjs.org - GPL-2.0 License
*/
export const hostContext = (selector, el) => {
return el.closest(selector) !== null;
};
export const findElement = (selector, el) => {
return el.closest(selector);
};
export const createColorClasses = (color, cssClassMap) => {
return (typeof color === 'string' && color.length > 0) ? Object.assign({ 'stories-color': true, [`stories-color-${color}`]: true }, cssClassMap) : cssClassMap;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const SIZE_TO_MEDIA = {
'xs': '(min-width: 0px)',
'sm': '(min-width: 576px)',
'md': '(min-width: 768px)',
'lg': '(min-width: 992px)',
'xl': '(min-width: 1200px)',
};
// Check if the window matches the media query
// at the breakpoint passed
// e.g. matchBreakpoint('sm') => true if screen width exceeds 576px
export const matchBreakpoint = (breakpoint) => {
if (breakpoint === undefined || breakpoint === '') {
return true;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (window.matchMedia) {
const mediaQuery = SIZE_TO_MEDIA[breakpoint];
return window.matchMedia(mediaQuery).matches;
}
return false;
};
const SCHEME = /^[a-z][a-z0-9+\-.]*:/;
export const openURL = async (url) => {
if (url != null && url[0] !== '#' && !SCHEME.test(url)) {
// TODO: organise navigation
return Promise.resolve(true);
}
return false;
};
//# sourceMappingURL=utils.js.map