Urara-Blog/node_modules/.pnpm-store/v3/files/04/0abb118afb21e706e6ed80ea1b0c8bfd65103a9a9f954c5476378b7e64d19a4132a6495b5dd9df74802d3a7d960bac467ad868ef5a8700a847fa829f9e6b75
2022-08-14 01:14:53 +08:00

73 lines
2.3 KiB
Text

/**
* A function that normalizes the various forms that the screens object can be
* provided in.
*
* Input(s):
* - ['100px', '200px'] // Raw strings
* - { sm: '100px', md: '200px' } // Object with string values
* - { sm: { min: '100px' }, md: { max: '100px' } } // Object with object values
* - { sm: [{ min: '100px' }, { max: '200px' }] } // Object with object array (multiple values)
*
* Output(s):
* - [{ name: 'sm', values: [{ min: '100px', max: '200px' }] }] // List of objects, that contains multiple values
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "normalizeScreens", {
enumerable: true,
get: ()=>normalizeScreens
});
function normalizeScreens(screens, root = true) {
if (Array.isArray(screens)) {
return screens.map((screen)=>{
if (root && Array.isArray(screen)) {
throw new Error("The tuple syntax is not supported for `screens`.");
}
if (typeof screen === "string") {
return {
name: screen.toString(),
values: [
{
min: screen,
max: undefined
}
]
};
}
let [name, options] = screen;
name = name.toString();
if (typeof options === "string") {
return {
name,
values: [
{
min: options,
max: undefined
}
]
};
}
if (Array.isArray(options)) {
return {
name,
values: options.map((option)=>resolveValue(option))
};
}
return {
name,
values: [
resolveValue(options)
]
};
});
}
return normalizeScreens(Object.entries(screens !== null && screens !== void 0 ? screens : {}), false);
}
function resolveValue({ "min-width": _minWidth , min =_minWidth , max , raw } = {}) {
return {
min,
max,
raw
};
}