Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

styled-breakpoints

Package Overview
Dependencies
Maintainers
1
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

styled-breakpoints - npm Package Compare versions

Comparing version 13.1.4 to 14.0.0

2

package.json
{
"name": "styled-breakpoints",
"version": "13.1.4",
"version": "14.0.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Simple and powerful css breakpoints for styled-components and emotion",

/**
* Calculates the maximum breakpoint width based on the provided minimum width value.
*
* The maximum value is calculated as the minimum of the next one less 0.02px
* to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths.
* The maximum value is reduced by 0.02px to work around the limitations of
* `min-` and `max-` prefixes and viewports with fractional widths.
* See https://www.w3.org/TR/mediaqueries-4/#mq-min-max

@@ -7,0 +7,0 @@ * Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.

const { useState, useLayoutEffect, useEffect } = require('react');
exports.useMediaQuery = useMediaQuery;
/* istanbul ignore next */
const isBrowser = typeof window !== 'undefined';
const IS_BROWSER = typeof window !== 'undefined';
/* istanbul ignore next */
const useEnhancedEffect = isBrowser ? useLayoutEffect : useEffect;
const useEnhancedEffect = IS_BROWSER ? useLayoutEffect : useEffect;
exports.useMediaQuery = useMediaQuery;
/**

@@ -13,9 +17,6 @@ * Custom hook for handling media queries.

*/
exports.useMediaQuery = function useMediaQuery(query) {
const [isMatch, setIsMatch] = useState(isBrowser && getMatches(query));
function useMediaQuery(query) {
const [state, setState] = useState(IS_BROWSER && getInitialState(query));
useEnhancedEffect(() => {
/* istanbul ignore next */
if (!isBrowser) return;
let mounted = true;

@@ -29,31 +30,19 @@ const mediaQueryList = window.matchMedia(query.replace(/^@media\s*/, ''));

/* istanbul ignore next */
setIsMatch(mediaQueryList.matches);
setState(mediaQueryList.matches);
};
// Safari < 14 can't use addEventListener on a MediaQueryList
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
const listenerMethod = mediaQueryList.addListener
? 'addListener'
: 'addEventListener';
mediaQueryList[listenerMethod]('change', handleChange);
setState(mediaQueryList.matches);
setIsMatch(mediaQueryList.matches);
// eslint-disable-next-line consistent-return
return () => {
mounted = false;
if (mediaQueryList.addListener) {
mediaQueryList.removeListener(handleChange);
} else {
mediaQueryList.removeEventListener('change', handleChange);
}
mediaQueryList.removeEventListener('change', handleChange);
};
}, [query]);
return isMatch;
};
return state;
}
function getMatches(query) {
function getInitialState(query) {
return window.matchMedia(query).matches;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc