Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
import { compareMedia } from "./compare-media";
import { matchMedia } from "./match-media";
import type { MediaRuleOptions } from "./rules";
/**
* Find the applicable media rule that matches the given width.
* Only matches width-based breakpoints (minWidth/maxWidth).
* Custom condition breakpoints are not matched by this function.
*/
export const findApplicableMedia = <Media extends MediaRuleOptions>(
media: Array<Media>,
width: number
) => {
const sortedMedia = [...media]
.sort(compareMedia)
// Reverse order is needed because the last rule in CSSOM has higher source order specificity.
.reverse();
for (const options of sortedMedia) {
if (matchMedia(options, width)) {
return options;
}
}
};