mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-05 19:49:57 +09:00
Ref https://prettier.io/blog/2023/07/05/3.0.0.html Smaller package size, trailing comma for types always enabled, though I disabled it for code.
18 lines
656 B
TypeScript
18 lines
656 B
TypeScript
import { compareMedia } from "@webstudio-is/css-engine";
|
|
import { isBaseBreakpoint } from "./is-base-breakpoint";
|
|
|
|
// We group in 3 groups: min-width, base (no min/max), max-width conditions
|
|
export const groupBreakpoints = <
|
|
Breakpoint extends { minWidth?: number; maxWidth?: number },
|
|
>(
|
|
breakpoints: Array<Breakpoint>
|
|
) => {
|
|
const sorted = [...breakpoints].sort(compareMedia);
|
|
const maxs = sorted.filter((breakpoint) => breakpoint.maxWidth !== undefined);
|
|
const mins = sorted
|
|
.filter((breakpoint) => breakpoint.minWidth !== undefined)
|
|
.reverse();
|
|
const base = sorted.filter(isBaseBreakpoint);
|
|
return [...mins, ...base, ...maxs];
|
|
};
|