@blocz/react-responsive 3.0.3 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,6 @@ If you need a responsive layout and adaptive components, `@blocz/react-responsiv
10
10
 
11
11
  ## Table of contents <!-- omit in toc -->
12
12
 
13
-
14
13
  1. [How to use](#how-to-use)
15
14
  1. [`<Only>`](#only)
16
15
  1. [Default breakpoints](#default-breakpoints)
@@ -20,26 +19,19 @@ If you need a responsive layout and adaptive components, `@blocz/react-responsiv
20
19
  2. [Hooks](#hooks)
21
20
  1. [`useBreakpoint()`](#usebreakpoint)
22
21
  2. [`useMediaQuery()`](#usemediaquery)
23
- 3. [`<Match>`](#match)
24
- 1. [`only` and `matchMedia` props](#only-and-matchmedia-props)
25
- 2. [Use a custom component in Match](#use-a-custom-component-in-match)
26
- 4. [`<BreakpointsProvider>`](#breakpointsprovider)
22
+ 3. [`<BreakpointsProvider>`](#breakpointsprovider)
27
23
  1. [Add more breakpoints](#add-more-breakpoints)
28
24
  2. [Change default breakpoints](#change-default-breakpoints)
29
25
  3. [Units](#units)
30
26
  4. [Direction](#direction)
31
- 5. [CSS in JS](#css-in-js)
32
- 1. [`toJSON`](#tojson)
33
- 2. [`toCSS`](#tocss)
34
- 6. [Comparison to other libraries](#comparison-to-other-libraries)
35
- 7. [`matchMedia` polyfill](#matchmedia-polyfill)
27
+ 4. [Comparison to other libraries](#comparison-to-other-libraries)
28
+ 5. [`matchMedia` polyfill](#matchmedia-polyfill)
36
29
  1. [Browser](#browser)
37
30
  2. [Node](#node)
38
- 8. [FAQ](#faq)
31
+ 6. [FAQ](#faq)
39
32
 
40
33
  ## How to use
41
34
 
42
-
43
35
  ### `<Only>`
44
36
 
45
37
  #### Default breakpoints
@@ -216,96 +208,6 @@ const App = () => {
216
208
  };
217
209
  ```
218
210
 
219
- ### `<Match>`
220
-
221
- #### `only` and `matchMedia` props
222
-
223
- The `Match` will look into every props of its children (and event nested children) to detect `only` and `matchMedia` props. If one of those is found, it will wrap the child in a `Only` component will those props auto-set.
224
-
225
- ```javascript
226
- import React from "react";
227
- import { Only, Match } from "@blocz/react-responsive";
228
-
229
- const App = () => (
230
- <Match>
231
- <div only="xs">xs</div>
232
- <div only="sm">sm</div>
233
- <div only="md">md</div>
234
- <div only="sm lg">sm and lg</div>
235
- <div only="xl">xl</div>
236
- <div>
237
- <div>
238
- <div>
239
- <div only="smDown">nested smDown</div>
240
- </div>
241
- </div>
242
- </div>
243
- <div matchMedia="(min-width:768px) and (max-width:992px),(max-width:576px)">
244
- {"(min-width:768px) and (max-width:992px),(max-width:576px)"}
245
- </div>
246
- </Match>
247
- );
248
- ```
249
-
250
- #### Use a custom component in Match
251
-
252
- You can also render the `Match` component as another one:
253
-
254
- ```javascript
255
- import React from "react";
256
- import { Only, Match } from "@blocz/react-responsive";
257
-
258
- const App = () => (
259
- <Match as="ul">
260
- <li only="xs">xs</li>
261
- <li only="sm">sm</li>
262
- <li only="md">md</li>
263
- <li only="lg">lg</li>
264
- <li only="xl">xl</li>
265
- </Match>
266
- );
267
- ```
268
-
269
- If you’re using TypeScript, `Match` will work out of the box for native DOM elements.
270
- But if you want to use it for custom components, you’ll have to use the type `MatchChildProps`:
271
-
272
- ```tsx
273
- import * as React from "react";
274
- import { Match, MatchChildProps } from "@blocz/react-responsive";
275
-
276
- // MatchChildProps includes the props `only` and `matchMedia`
277
- interface CustomProps extends MatchChildProps {
278
- title: string;
279
- }
280
-
281
- const Custom: React.FunctionComponent<CustomProps> = ({ title, children }) => (
282
- <React.Fragment>
283
- <h3>{title}</h3>
284
- <p>{children}</p>
285
- </React.Fragment>
286
- );
287
-
288
- const App = () => (
289
- <Match>
290
- <Custom only="xs" title="xs">
291
- xs
292
- </Custom>
293
- <Custom only="sm" title="sm">
294
- sm
295
- </Custom>
296
- <Custom only="md" title="md">
297
- md
298
- </Custom>
299
- <Custom only="lg" title="lg">
300
- lg
301
- </Custom>
302
- <Custom only="xl" title="xl">
303
- xl
304
- </Custom>
305
- </Match>
306
- );
307
- ```
308
-
309
211
  ### `<BreakpointsProvider>`
310
212
 
311
213
  `BreakpointsProvider` defines the values of every breakpoints.
@@ -394,88 +296,6 @@ Every CSS units are supported.
394
296
 
395
297
  The default unit is `px`.
396
298
 
397
- ### CSS in JS
398
-
399
- `@blocz/react-responsive` includes 2 utility functions `toJSON` and `toCSS` so that you can re-use `@blocz/react-responsive` breakpoints as media queries for `css-in-js` libraries.
400
-
401
- #### `toJSON`
402
-
403
- Example with [`styletron`](https://github.com/styletron/styletron):
404
-
405
- ```jsx
406
- import React from "react";
407
- import { toJSON as createToJSON, BreakpointsContext } from "@blocz/react-responsive";
408
- import { styled } from "styletron-react";
409
-
410
- const styles = {
411
- mdDown: {
412
- color: "red",
413
- ":hover": { color: "blue" },
414
- },
415
- lgUp: {
416
- color: "green",
417
- },
418
- };
419
-
420
- const Panel = styled("div", (props) => ({
421
- ...props.$toJSON(styles),
422
- }));
423
-
424
- const App = () => {
425
- const breakpoints = React.useContext(BreakpointsContext);
426
- const toJSON = createToJSON(breakpoints);
427
- // toJSON(styles) returns:
428
- // {
429
- // "@media (max-width:991px)": {
430
- // "color": "red",
431
- // ":hover": {
432
- // "color": "blue"
433
- // }
434
- // },
435
- // "@media (min-width:992px)": {
436
- // "color": "green"
437
- // }
438
- // }
439
- return <Panel $toJSON={toJSON}>content</Panel>;
440
- };
441
- ```
442
-
443
- #### `toCSS`
444
-
445
- Example with [`emotion`](https://emotion.sh):
446
-
447
- ```jsx
448
- import React from "react";
449
- import { toCSS as createToCSS, BreakpointsContext } from "@blocz/react-responsive";
450
- import { css } from "@emotion/css";
451
-
452
- const styles = {
453
- mdDown: {
454
- color: "red",
455
- ":hover": { color: "blue" },
456
- },
457
- lgUp: {
458
- color: "green",
459
- },
460
- };
461
-
462
- const App = () => {
463
- const breakpoints = React.useContext(BreakpointsContext);
464
- const toCSS = createToCSS(breakpoints);
465
- // toCSS(styles) returns:
466
- // `@media (max-width:991px) {
467
- // color: red;
468
- // :hover {
469
- // color: blue;
470
- // }
471
- // }
472
- // @media (min-width:992px) {
473
- // color: green;
474
- // }`
475
- return <div className={css(toCSS(styles))}>content</div>;
476
- };
477
- ```
478
-
479
299
  ### Comparison to other libraries
480
300
 
481
301
  | Lib | Breakpoints | Custom breakpoints | Media query | `matchMedia` listener' | hooks | SSR support |
@@ -502,5 +322,3 @@ And if you need an example with `Jest`, `@testing-library/react`, `React` and `@
502
322
  ### FAQ
503
323
 
504
324
  For other questions, please take a look at our [FAQ document](https://github.com/bloczjs/react-responsive/blob/master/FAQ.md).
505
-
506
-
@@ -1,9 +1,9 @@
1
- import * as React from "react";
2
- import { ExposedBreakpoints, Breakpoints } from "./sanitize";
3
- export declare const BreakpointsContext: React.Context<Breakpoints>;
4
- interface BreakpointsProviderProps {
5
- breakpoints?: ExposedBreakpoints;
6
- additionalBreakpoints?: ExposedBreakpoints;
7
- }
8
- export declare const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>>;
9
- export {};
1
+ import * as React from "react";
2
+ import { ExposedBreakpoints, Breakpoints } from "./sanitize";
3
+ export declare const BreakpointsContext: React.Context<Breakpoints>;
4
+ interface BreakpointsProviderProps {
5
+ breakpoints?: ExposedBreakpoints;
6
+ additionalBreakpoints?: ExposedBreakpoints;
7
+ }
8
+ export declare const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>>;
9
+ export {};
package/lib/Only.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import * as React from "react";
2
- export declare type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {
3
- matchMedia?: string;
4
- on?: string;
5
- as?: string | React.ComponentType<OtherProps>;
6
- };
7
- export declare function Only<OtherProps = Record<string, never>>({ matchMedia, on, as, children, ...props }: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null;
8
- export declare namespace Only {
9
- var displayName: string;
10
- }
1
+ import * as React from "react";
2
+ export type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {
3
+ matchMedia?: string;
4
+ on?: string;
5
+ as?: string | React.ComponentType<OtherProps>;
6
+ };
7
+ export declare function Only<OtherProps = Record<string, never>>({ matchMedia, on, as, children, ...props }: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null;
@@ -1,12 +1,12 @@
1
- import { CSSProperties } from "react";
2
- import { Breakpoints } from "./sanitize";
3
- declare type CSSinJSProperties = CSSProperties | {
4
- [key: string]: CSSProperties;
5
- };
6
- interface Points {
7
- [breakpoint: string]: CSSinJSProperties;
8
- }
9
- declare type CSSinJS = Record<string, CSSinJSProperties>;
10
- export declare const toJSON: (breakpoints: Breakpoints) => (points: Points) => CSSinJS;
11
- export declare const toCSS: (breakpoints: Breakpoints) => (points: Points) => string;
12
- export {};
1
+ import { CSSProperties } from "react";
2
+ import { Breakpoints } from "./sanitize";
3
+ type CSSinJSProperties = CSSProperties | {
4
+ [key: string]: CSSProperties;
5
+ };
6
+ interface Points {
7
+ [breakpoint: string]: CSSinJSProperties;
8
+ }
9
+ type CSSinJS = Record<string, CSSinJSProperties>;
10
+ export declare const toJSON: (breakpoints: Breakpoints) => (points: Points) => CSSinJS;
11
+ export declare const toCSS: (breakpoints: Breakpoints) => (points: Points) => string;
12
+ export {};
@@ -1,2 +1,2 @@
1
- import { Breakpoint } from "./sanitize";
2
- export declare const fromBreakpointToMedia: (breakpoint: Breakpoint) => string;
1
+ import { Breakpoint } from "./sanitize";
2
+ export declare const fromBreakpointToMedia: (breakpoint: Breakpoint) => string;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- export { BreakpointsProvider, BreakpointsContext } from "./BreakpointsContext";
2
- export { Match, MatchChildProps } from "./Match";
3
- export { Only } from "./Only";
4
- export { useBreakpoint } from "./useBreakpoint";
5
- export { useMediaQuery } from "./useMediaQuery";
6
- export { Units } from "./sanitize";
7
- export { toJSON, toCSS } from "./css-in-js";
1
+ export { BreakpointsProvider, BreakpointsContext } from "./BreakpointsContext";
2
+ export { Only } from "./Only";
3
+ export { useBreakpoint } from "./useBreakpoint";
4
+ export { useMediaQuery } from "./useMediaQuery";
5
+ export { type Units } from "./sanitize";
@@ -1,2 +1,2 @@
1
- import { Breakpoints } from "./sanitize";
2
- export declare const mediaQueryBuilder: (breakpoints: Breakpoints) => (on?: string) => string;
1
+ import { Breakpoints } from "./sanitize";
2
+ export declare const mediaQueryBuilder: (breakpoints: Breakpoints) => (on?: string) => string;
@@ -1,2 +1,2 @@
1
- function e(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}}),r.default=e,r}var r=/*#__PURE__*/e(require("react"));function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},n.apply(this,arguments)}function t(e,r){if(null==e)return{};var n,t,i={},a=Object.keys(e);for(t=0;t<a.length;t++)r.indexOf(n=a[t])>=0||(i[n]=e[n]);return i}var i=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],a=["width","height"],o=function(e){return Object.keys(e).reduce(function(r,n){var t=e[n];if(!Array.isArray(t)||t.length<=1)return r;var o,u,c=t[0],f=t[1],s=t[2],l=t.slice(3);if(l.length>0){var p=new Error('The following fields "'+l+'" have been ignored');console.error(p)}if("number"!=typeof c||"number"!=typeof f)return r;"string"==typeof s?o=s:"object"==typeof s&&(u=s.direction,o=s.unit);var d=Math.min(c,f),v=Math.max(c,f),m=o&&i.includes(o)?o:"px",h=u&&a.includes(u)?u:"width";return r[n]=[d,v,m,h],r[n+"Up"]=[d,Infinity,m,h],r[n+"Down"]=[0,v,m,h],r},{})},u={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},c=r.createContext(o(u)),f=function(e){var t=e.breakpoints,i=e.additionalBreakpoints,a=e.children;return r.createElement(c.Provider,{value:o(n({},void 0===t?u:t,void 0===i?{}:i))},a)};f.displayName="BreakpointsProvider";var s=function(e){var r=[],n=e[0],t=e[1],i=e[2],a=e[3];return 0!==n&&r.push("(min-"+a+":"+n+i+")"),Infinity!==t&&r.push("(max-"+a+":"+t+i+")")," "+r.join(" and ")},l=function(e){var n=r.useMemo(function(){return matchMedia(e)},[e]),t=r.useState(n.matches),i=t[0],a=t[1];return r.useLayoutEffect(function(){a(n.matches);var e=function(e){a(e.matches)};return n.addListener(e),function(){n.removeListener(e)}},[n]),i},p=function(e){var n=r.useContext(c),t=r.useMemo(function(){return function(e){return function(r){if(void 0===r&&(r=""),!r)return"";var n=r.split(" "),t=n.map(function(r){return e[r]}).filter(Boolean).map(function(e){return s(e)}).filter(Boolean).join(",");if(!t){var i=1===n.length;console.error('"'+n.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(n)},[n]),i=r.useMemo(function(){return t(e)},[t,e]);return l(i||"-")},d=["matchMedia","on","as","children"];function v(e){var n=e.matchMedia,i=e.on,a=e.as,o=e.children,u=t(e,d),c=p(i),f=l(n||"-");return c||f?r.createElement(a||r.Fragment,a?u:void 0,o):null}v.displayName="Only";var m=["only","matchMedia"],h=["children","as"],y=function e(n){if(!n||!n.props)return n;var i=n.props.children;if(!i)return null;var a=r.Children.map(i,e),o=n.props,u=o.only,c=o.matchMedia,f=t(o,m),s=r.createElement(n.type,f,a);return u||c?r.createElement(v,{on:u||"",matchMedia:c||""},s):s},x=function(e){var n=e.children,i=e.as,a=t(e,h),o=r.Children.map(n,y);return i?r.createElement(i,a,o):r.createElement(r.Fragment,null,o)};x.displayName="Match";var b=function(e){return function(r){var n={};return Object.keys(r).forEach(function(t){var i=e[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(e));n["@media "+s(i)]=r[t]}),n}},O=function e(r){var n="";return Object.entries(r).forEach(function(r){var t=r[0],i=r[1];n+="object"==typeof i?t+" {\n"+e(i)+"}\n":t+": "+i+";\n"}),n};exports.BreakpointsContext=c,exports.BreakpointsProvider=f,exports.Match=x,exports.Only=v,exports.toCSS=function(e){return function(r){return O(b(e)(r))}},exports.toJSON=b,exports.useBreakpoint=p,exports.useMediaQuery=l;
1
+ function e(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var n=/*#__PURE__*/e(require("react"));function r(){return r=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},r.apply(null,arguments)}var t=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],i=["width","height"],o=function(e){return Object.keys(e).reduce(function(n,r){var o=e[r];if(!Array.isArray(o)||o.length<=1)return n;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var p=new Error('The following fields "'+l+'" have been ignored');console.error(p)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var v=Math.min(c,f),d=Math.max(c,f),m=a&&t.includes(a)?a:"px",h=u&&i.includes(u)?u:"width";return n[r]=[v,d,m,h],n[r+"Up"]=[v,Infinity,m,h],n[r+"Down"]=[0,d,m,h],n},{})},a={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},u=n.createContext(o(a)),c=function(e){var t=e.breakpoints,i=e.children;return n.createElement(u.Provider,{value:o(r({},void 0===t?a:t,e.additionalBreakpoints))},i)};c.displayName="BreakpointsProvider";var f=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(r.matches);var e=function(e){o(e.matches)};return r.addListener(e),function(){r.removeListener(e)}},[r]),i},s=function(e){var r=n.useContext(u),t=n.useMemo(function(){return function(e){return function(n){if(void 0===n&&(n=""),!n)return"";var r=n.split(" "),t=r.map(function(n){return e[n]}).filter(Boolean).map(function(e){return function(e){var n=[],r=e[0],t=e[1],i=e[2],o=e[3];return 0!==r&&n.push("(min-"+o+":"+r+i+")"),Infinity!==t&&n.push("(max-"+o+":"+t+i+")")," "+n.join(" and ")}(e)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return f(i||"-")},l=["matchMedia","on","as","children"];exports.BreakpointsContext=u,exports.BreakpointsProvider=c,exports.Only=function(e){var r=e.matchMedia,t=e.on,i=e.as,o=e.children,a=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(e,l),u=s(t),c=f(r||"-");return u||c?n.createElement(i||n.Fragment,i?a:void 0,o):null},exports.useBreakpoint=s,exports.useMediaQuery=f;
2
2
  //# sourceMappingURL=react-responsive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-responsive.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"6pBAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KAC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AMA,EACjB,SAAC7F,GAAD,OACC8F,SAAAA,GACC,IAASC,EAAY,GAQrB,OAPAlG,OAAOC,KAAKgG,GAAQE,QAAQ,SAACC,GAC3B,IAAM7F,EAAaJ,EAAYiG,GAC/B,IAAK7F,EACH,MAAM,IAAAS,MAAaoF,EAA2DpG,sDAAAA,OAAOC,KAAKE,IAE5F+F,YAAcvD,EAAsBpC,IAAiB0F,EAAOG,KAG/DF,IAEYG,EAAG,SAAAA,EAACC,GACjB,IAAIC,EAAS,GAQb,OAPAvG,OAAOwG,QAAQF,GAAQH,QAAQ,SAAA/D,OAAiBqE,EAAArE,EAAA,GAAVI,EAAUJ,EAAA,GAK9CmE,GAJqB,iBAAV/D,EAIEiE,EAAUJ,OAAAA,EAAU7D,GAClC,MAJgBiE,EAAP,KAAejE,EAArB,QAKG+D,2GAIP,SAACpG,GAAD,OACC8F,SAAAA,UACUI,EAACL,EAAO7F,EAAP6F,CAAoBC"}
1
+ {"version":3,"file":"react-responsive.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext: React.Context<Breakpoints> = React.createContext<Breakpoints>(\n sanitize(defaultBreakpoints),\n);\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints,\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // Those are important updates, so we don't want to use transitions on them\n setIsShown(event.matches);\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","children","Provider","value","_extends","additionalBreakpoints","displayName","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","mediaList","minValue","maxValue","push","str","join","fromBreakpointToMedia","isUniqBreakpoint","mediaQueryBuilder","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined"],"mappings":"6gBAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,IAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,EAXGC,EAA8CN,EAAU,GAA3CO,EAAiCP,EAApBQ,GAAAA,EAAoBR,EAAU,GAAlBS,EAAQT,EAAUU,SAC/D,GAAID,EAAKN,OAAS,EAAG,CACnB,IAAMQ,EAAQ,IAAIC,MAA+BH,yBAAAA,EAAyB,uBAC1EI,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBL,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQM,UAC5BV,EAAeI,EAAQO,MAGzB,IAAMC,EAAMC,KAAKD,IAAIV,EAAaC,GAC5BW,EAAMD,KAAKC,IAAIZ,EAAaC,G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ASX"}
@@ -1,2 +1,2 @@
1
- import*as n from"react";function e(){return e=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},e.apply(this,arguments)}function r(n,e){if(null==n)return{};var r,t,i={},a=Object.keys(n);for(t=0;t<a.length;t++)e.indexOf(r=a[t])>=0||(i[r]=n[r]);return i}var t=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],i=["width","height"],a=function(n){return Object.keys(n).reduce(function(e,r){var a=n[r];if(!Array.isArray(a)||a.length<=1)return e;var o,u,c=a[0],f=a[1],l=a[2],s=a.slice(3);if(s.length>0){var m=new Error('The following fields "'+s+'" have been ignored');console.error(m)}if("number"!=typeof c||"number"!=typeof f)return e;"string"==typeof l?o=l:"object"==typeof l&&(u=l.direction,o=l.unit);var p=Math.min(c,f),d=Math.max(c,f),v=o&&t.includes(o)?o:"px",h=u&&i.includes(u)?u:"width";return e[r]=[p,d,v,h],e[r+"Up"]=[p,Infinity,v,h],e[r+"Down"]=[0,d,v,h],e},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},u=n.createContext(a(o)),c=function(r){var t=r.breakpoints,i=r.additionalBreakpoints,c=r.children;return n.createElement(u.Provider,{value:a(e({},void 0===t?o:t,void 0===i?{}:i))},c)};c.displayName="BreakpointsProvider";var f=function(n){var e=[],r=n[0],t=n[1],i=n[2],a=n[3];return 0!==r&&e.push("(min-"+a+":"+r+i+")"),Infinity!==t&&e.push("(max-"+a+":"+t+i+")")," "+e.join(" and ")},l=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],a=t[1];return n.useLayoutEffect(function(){a(r.matches);var n=function(n){a(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),i},s=function(e){var r=n.useContext(u),t=n.useMemo(function(){return function(n){return function(e){if(void 0===e&&(e=""),!e)return"";var r=e.split(" "),t=r.map(function(e){return n[e]}).filter(Boolean).map(function(n){return f(n)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return l(i||"-")},m=["matchMedia","on","as","children"];function p(e){var t=e.matchMedia,i=e.on,a=e.as,o=e.children,u=r(e,m),c=s(i),f=l(t||"-");return c||f?n.createElement(a||n.Fragment,a?u:void 0,o):null}p.displayName="Only";var d=["only","matchMedia"],v=["children","as"],h=function e(t){if(!t||!t.props)return t;var i=t.props.children;if(!i)return null;var a=n.Children.map(i,e),o=t.props,u=o.only,c=o.matchMedia,f=r(o,d),l=n.createElement(t.type,f,a);return u||c?n.createElement(p,{on:u||"",matchMedia:c||""},l):l},y=function(e){var t=e.children,i=e.as,a=r(e,v),o=n.Children.map(t,h);return i?n.createElement(i,a,o):n.createElement(n.Fragment,null,o)};y.displayName="Match";var b=function(n){return function(e){var r={};return Object.keys(e).forEach(function(t){var i=n[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(n));r["@media "+f(i)]=e[t]}),r}},x=function n(e){var r="";return Object.entries(e).forEach(function(e){var t=e[0],i=e[1];r+="object"==typeof i?t+" {\n"+n(i)+"}\n":t+": "+i+";\n"}),r},g=function(n){return function(e){return x(b(n)(e))}};export{u as BreakpointsContext,c as BreakpointsProvider,y as Match,p as Only,g as toCSS,b as toJSON,s as useBreakpoint,l as useMediaQuery};
1
+ import*as n from"react";function e(){return e=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)({}).hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},e.apply(null,arguments)}var r=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],t=["width","height"],i=function(n){return Object.keys(n).reduce(function(e,i){var o=n[i];if(!Array.isArray(o)||o.length<=1)return e;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var m=new Error('The following fields "'+l+'" have been ignored');console.error(m)}if("number"!=typeof c||"number"!=typeof f)return e;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var v=Math.min(c,f),p=Math.max(c,f),d=a&&r.includes(a)?a:"px",h=u&&t.includes(u)?u:"width";return e[i]=[v,p,d,h],e[i+"Up"]=[v,Infinity,d,h],e[i+"Down"]=[0,p,d,h],e},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},a=n.createContext(i(o)),u=function(r){var t=r.breakpoints,u=r.children;return n.createElement(a.Provider,{value:i(e({},void 0===t?o:t,r.additionalBreakpoints))},u)};u.displayName="BreakpointsProvider";var c=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(r.matches);var n=function(n){o(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),i},f=function(e){var r=n.useContext(a),t=n.useMemo(function(){return function(n){return function(e){if(void 0===e&&(e=""),!e)return"";var r=e.split(" "),t=r.map(function(e){return n[e]}).filter(Boolean).map(function(n){return function(n){var e=[],r=n[0],t=n[1],i=n[2],o=n[3];return 0!==r&&e.push("(min-"+o+":"+r+i+")"),Infinity!==t&&e.push("(max-"+o+":"+t+i+")")," "+e.join(" and ")}(n)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return c(i||"-")},s=["matchMedia","on","as","children"];function l(e){var r=e.matchMedia,t=e.on,i=e.as,o=e.children,a=function(n,e){if(null==n)return{};var r={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(e.includes(t))continue;r[t]=n[t]}return r}(e,s),u=f(t),l=c(r||"-");return u||l?n.createElement(i||n.Fragment,i?a:void 0,o):null}export{a as BreakpointsContext,u as BreakpointsProvider,l as Only,f as useBreakpoint,c as useMediaQuery};
2
2
  //# sourceMappingURL=react-responsive.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-responsive.modern.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key","toCSS"],"mappings":"gYAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAK6BC,EAAiB,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,MAAmBL,EAAcK,GAEjC,IAAKC,MAAMC,QAAQC,IAAeA,EAAWC,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,IAXiDH,EAAjCI,GAAAA,EAAiCJ,EAArD,GAAiCK,EAAoBL,EAARM,GAAAA,EAAQN,EACrDO,MAAA,GAAA,GAAID,EAAKL,OAAS,EAAG,CACnB,IAAWO,EAAG,IAAIC,+BAA+BH,EAAnC,uBACdI,QAAQF,MAAMA,GAGhB,GAA2B,iBAAhBG,GAAmD,iBAAhBP,EAC5C,OACDR,EAIsB,iBAAZS,EACTH,EAAeG,EACa,qBAC5BF,EAAoBE,EAAQO,UAC5BV,EAAeG,EAAQQ,MAGzB,IAAMC,EAAMC,KAAKD,IAAIH,EAAaP,GACzBY,EAAGD,KAAKC,IAAIL,EAAaP,GAC5BS,EAAOX,GAAgBb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ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext: React.Context<Breakpoints> = React.createContext<Breakpoints>(\n sanitize(defaultBreakpoints),\n);\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints,\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // Those are important updates, so we don't want to use transitions on them\n setIsShown(event.matches);\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","children","Provider","value","_extends","additionalBreakpoints","displayName","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","mediaList","minValue","maxValue","push","str","join","fromBreakpointToMedia","isUniqBreakpoint","mediaQueryBuilder","Only","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined"],"mappings":"gPAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAe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QAAYE,MAAAA,EAAmB,KAAO,OAAK,QACrEA,EAAmB,KAAO,IAC5B,oBAAmBA,EAAmB,GAAK,KAE/C,CACA,OAAO9B,CACT,CAAC,CDdwC+B,CAAkBzE,EAAY,EAAE,CAACA,IAEpE0C,EAAaZ,EAAMc,QAAQ,WAAM,OAAAe,EAAaF,EAAG,EAAE,CAACE,EAAcF,IAExE,OAAOhB,EAAcC,GAAc,IACrC,wCEJgB,SAAAgC,EAAIzC,GAClB,IAAAY,EAAUZ,EAAVY,WACAY,EAAExB,EAAFwB,GACAkB,EAAE1C,EAAF0C,GACAxC,EAAQF,EAARE,SACGyC,yIAAKC,CAAA5C,EAAA6C,GAEFC,EAAUvB,EAAcC,GACxBuB,EAAavC,EAAcI,GAAc,KAG/C,OAFgBkC,GAAWC,EAMpBlD,EAAMmD,cAEXN,GAAM7C,EAAMoD,SACZP,EAAMC,OAAuBO,EAC7BhD,GAPO,IASX"}
@@ -1,2 +1,2 @@
1
- import*as n from"react";function e(){return e=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},e.apply(this,arguments)}function r(n,e){if(null==n)return{};var r,t,i={},a=Object.keys(n);for(t=0;t<a.length;t++)e.indexOf(r=a[t])>=0||(i[r]=n[r]);return i}var t=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],i=["width","height"],a=function(n){return Object.keys(n).reduce(function(e,r){var a=n[r];if(!Array.isArray(a)||a.length<=1)return e;var o,u,c=a[0],f=a[1],l=a[2],s=a.slice(3);if(s.length>0){var m=new Error('The following fields "'+s+'" have been ignored');console.error(m)}if("number"!=typeof c||"number"!=typeof f)return e;"string"==typeof l?o=l:"object"==typeof l&&(u=l.direction,o=l.unit);var p=Math.min(c,f),d=Math.max(c,f),v=o&&t.includes(o)?o:"px",h=u&&i.includes(u)?u:"width";return e[r]=[p,d,v,h],e[r+"Up"]=[p,Infinity,v,h],e[r+"Down"]=[0,d,v,h],e},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},u=n.createContext(a(o)),c=function(r){var t=r.breakpoints,i=r.additionalBreakpoints,c=r.children;return n.createElement(u.Provider,{value:a(e({},void 0===t?o:t,void 0===i?{}:i))},c)};c.displayName="BreakpointsProvider";var f=function(n){var e=[],r=n[0],t=n[1],i=n[2],a=n[3];return 0!==r&&e.push("(min-"+a+":"+r+i+")"),Infinity!==t&&e.push("(max-"+a+":"+t+i+")")," "+e.join(" and ")},l=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],a=t[1];return n.useLayoutEffect(function(){a(r.matches);var n=function(n){a(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),i},s=function(e){var r=n.useContext(u),t=n.useMemo(function(){return function(n){return function(e){if(void 0===e&&(e=""),!e)return"";var r=e.split(" "),t=r.map(function(e){return n[e]}).filter(Boolean).map(function(n){return f(n)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return l(i||"-")},m=["matchMedia","on","as","children"];function p(e){var t=e.matchMedia,i=e.on,a=e.as,o=e.children,u=r(e,m),c=s(i),f=l(t||"-");return c||f?n.createElement(a||n.Fragment,a?u:void 0,o):null}p.displayName="Only";var d=["only","matchMedia"],v=["children","as"],h=function e(t){if(!t||!t.props)return t;var i=t.props.children;if(!i)return null;var a=n.Children.map(i,e),o=t.props,u=o.only,c=o.matchMedia,f=r(o,d),l=n.createElement(t.type,f,a);return u||c?n.createElement(p,{on:u||"",matchMedia:c||""},l):l},y=function(e){var t=e.children,i=e.as,a=r(e,v),o=n.Children.map(t,h);return i?n.createElement(i,a,o):n.createElement(n.Fragment,null,o)};y.displayName="Match";var b=function(n){return function(e){var r={};return Object.keys(e).forEach(function(t){var i=n[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(n));r["@media "+f(i)]=e[t]}),r}},x=function n(e){var r="";return Object.entries(e).forEach(function(e){var t=e[0],i=e[1];r+="object"==typeof i?t+" {\n"+n(i)+"}\n":t+": "+i+";\n"}),r},g=function(n){return function(e){return x(b(n)(e))}};export{u as BreakpointsContext,c as BreakpointsProvider,y as Match,p as Only,g as toCSS,b as toJSON,s as useBreakpoint,l as useMediaQuery};
1
+ import*as n from"react";function e(){return e=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)({}).hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},e.apply(null,arguments)}var r=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],t=["width","height"],i=function(n){return Object.keys(n).reduce(function(e,i){var o=n[i];if(!Array.isArray(o)||o.length<=1)return e;var a,u,c=o[0],f=o[1],s=o[2],l=o.slice(3);if(l.length>0){var m=new Error('The following fields "'+l+'" have been ignored');console.error(m)}if("number"!=typeof c||"number"!=typeof f)return e;"string"==typeof s?a=s:"object"==typeof s&&(u=s.direction,a=s.unit);var v=Math.min(c,f),p=Math.max(c,f),d=a&&r.includes(a)?a:"px",h=u&&t.includes(u)?u:"width";return e[i]=[v,p,d,h],e[i+"Up"]=[v,Infinity,d,h],e[i+"Down"]=[0,p,d,h],e},{})},o={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},a=n.createContext(i(o)),u=function(r){var t=r.breakpoints,u=r.children;return n.createElement(a.Provider,{value:i(e({},void 0===t?o:t,r.additionalBreakpoints))},u)};u.displayName="BreakpointsProvider";var c=function(e){var r=n.useMemo(function(){return matchMedia(e)},[e]),t=n.useState(r.matches),i=t[0],o=t[1];return n.useLayoutEffect(function(){o(r.matches);var n=function(n){o(n.matches)};return r.addListener(n),function(){r.removeListener(n)}},[r]),i},f=function(e){var r=n.useContext(a),t=n.useMemo(function(){return function(n){return function(e){if(void 0===e&&(e=""),!e)return"";var r=e.split(" "),t=r.map(function(e){return n[e]}).filter(Boolean).map(function(n){return function(n){var e=[],r=n[0],t=n[1],i=n[2],o=n[3];return 0!==r&&e.push("(min-"+o+":"+r+i+")"),Infinity!==t&&e.push("(max-"+o+":"+t+i+")")," "+e.join(" and ")}(n)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(r)},[r]),i=n.useMemo(function(){return t(e)},[t,e]);return c(i||"-")},s=["matchMedia","on","as","children"];function l(e){var r=e.matchMedia,t=e.on,i=e.as,o=e.children,a=function(n,e){if(null==n)return{};var r={};for(var t in n)if({}.hasOwnProperty.call(n,t)){if(e.includes(t))continue;r[t]=n[t]}return r}(e,s),u=f(t),l=c(r||"-");return u||l?n.createElement(i||n.Fragment,i?a:void 0,o):null}export{a as BreakpointsContext,u as BreakpointsProvider,l as Only,f as useBreakpoint,c as useMediaQuery};
2
2
  //# sourceMappingURL=react-responsive.modern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-responsive.modern.mjs","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/fromBreakpointToMedia.ts","../src/Only.tsx"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext: React.Context<Breakpoints> = React.createContext<Breakpoints>(\n sanitize(defaultBreakpoints),\n);\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints,\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import * as React from \"react\";\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // Those are important updates, so we don't want to use transitions on them\n setIsShown(event.matches);\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedMin","supposedMax","options","rest","error","Error","console","supposedUnit","supposedDirection","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","additionalBreakpoints","children","Provider","value","_extends","displayName","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","isShown","setIsShown","useState","matches","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","mediaList","minValue","maxValue","str","push","join","fromBreakpointToMedia","isUniqBreakpoint","mediaQueryBuilder","Only","_ref","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined"],"mappings":"gPAiBA,MAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAYC,GAChBC,OAAOC,KAAKF,GAAeG,OAAoB,CAACC,EAAaC,KAClE,MAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,MAAOM,EAAaC,EAAaC,KAAYC,GAAQP,EACrD,GAAIO,EAAKJ,OAAS,EAAG,CACnB,MAAMK,EAAQ,IAAIC,MAAM,yBAAyBF,wBACjDG,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBJ,GAAmD,iBAAhBC,EAC5C,OAAOP,EAGT,IAAIa,EACAC,EACmB,iBAAZN,EACTK,EAAeL,EACa,iBAAZA,IAChBM,EA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KA,EACH,MAAO,GAET,MAAMG,EAAqBH,EAAGI,MAAM,KAE9BlB,EADsBiB,EAAmBE,IAAKzD,GAAmBD,EAAYC,IAAiB0D,OAAOC,SAExGF,IAAKxD,GCV0BA,KACpC,MAAM2D,EAAsB,IACrBC,EAAUC,EAAU/C,EAAMD,GAAab,EAC9C,IAAI8D,EAcJ,OAXiB,IAAbF,IACFE,EAAM,GAAGF,IAAW9C,IACpB6C,EAAUI,KAAK,QAAQlD,KAAaiD,OAIrB3C,WAAb0C,IACFC,EAAM,GAAGD,IAAW/C,IACpB6C,EAAUI,KAAK,QAAQlD,KAAaiD,OAG/B,IAAMH,EAAUK,KAAK,QAAO,EDPVC,CAAsBjE,IAC1CyD,OAAOC,SACPM,KAAK,KACR,IAAK3B,EAAY,CACf,MAAM6B,EAAiD,IAA9BZ,EAAmBnD,OAC5CO,QAAQF,MACN,IAAI8C,EAAmBU,KAAK,YAAYE,EAAmB,KAAO,YAChEA,EAAmB,KAAO,qBACTA,EAAmB,GAAK,MAE/C,CACA,OAAO7B,GDbgC8B,CAAkBrE,GAAc,CAACA,IAEpEuC,EAAaV,EAAMY,QAAQ,IAAMc,EAAaF,GAAK,CAACE,EAAcF,IAExE,OAAOf,EAAcC,GAAc,IAAG,wCGHxB,SAAA+B,EAAIC,OAAqC7B,WACvDA,EAAUW,GACVA,EAAEmB,GACFA,EAAEvC,SACFA,GAE+CsC,EAD5CE,yIAAKC,CAAAH,EAAAI,GAER,MAAMC,EAAUxB,EAAcC,GACxBwB,EAAavC,EAAcI,GAAc,KAG/C,OAFgBkC,GAAWC,EAMpBhD,EAAMiD,cAEXN,GAAM3C,EAAMkD,SACZP,EAAMC,OAAuBO,EAC7B/C,OAEJ"}
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self)["@blocz/react-responsive"]={},e.React)}(this,function(e,n){function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var t=/*#__PURE__*/r(n);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},i.apply(this,arguments)}function o(e,n){if(null==e)return{};var r,t,i={},o=Object.keys(e);for(t=0;t<o.length;t++)n.indexOf(r=o[t])>=0||(i[r]=e[r]);return i}var a=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],u=["width","height"],c=function(e){return Object.keys(e).reduce(function(n,r){var t=e[r];if(!Array.isArray(t)||t.length<=1)return n;var i,o,c=t[0],f=t[1],l=t[2],s=t.slice(3);if(s.length>0){var d=new Error('The following fields "'+s+'" have been ignored');console.error(d)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof l?i=l:"object"==typeof l&&(o=l.direction,i=l.unit);var p=Math.min(c,f),m=Math.max(c,f),v=i&&a.includes(i)?i:"px",h=o&&u.includes(o)?o:"width";return n[r]=[p,m,v,h],n[r+"Up"]=[p,Infinity,v,h],n[r+"Down"]=[0,m,v,h],n},{})},f={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},l=t.createContext(c(f)),s=function(e){var n=e.breakpoints,r=e.additionalBreakpoints,o=e.children;return t.createElement(l.Provider,{value:c(i({},void 0===n?f:n,void 0===r?{}:r))},o)};s.displayName="BreakpointsProvider";var d=function(e){var n=[],r=e[0],t=e[1],i=e[2],o=e[3];return 0!==r&&n.push("(min-"+o+":"+r+i+")"),Infinity!==t&&n.push("(max-"+o+":"+t+i+")")," "+n.join(" and ")},p=function(e){var n=t.useMemo(function(){return matchMedia(e)},[e]),r=t.useState(n.matches),i=r[0],o=r[1];return t.useLayoutEffect(function(){o(n.matches);var e=function(e){o(e.matches)};return n.addListener(e),function(){n.removeListener(e)}},[n]),i},m=function(e){var n=t.useContext(l),r=t.useMemo(function(){return function(e){return function(n){if(void 0===n&&(n=""),!n)return"";var r=n.split(" "),t=r.map(function(n){return e[n]}).filter(Boolean).map(function(e){return d(e)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(n)},[n]),i=t.useMemo(function(){return r(e)},[r,e]);return p(i||"-")},v=["matchMedia","on","as","children"];function h(e){var n=e.matchMedia,r=e.on,i=e.as,a=e.children,u=o(e,v),c=m(r),f=p(n||"-");return c||f?t.createElement(i||t.Fragment,i?u:void 0,a):null}h.displayName="Only";var y=["only","matchMedia"],b=["children","as"],x=function e(n){if(!n||!n.props)return n;var r=n.props.children;if(!r)return null;var i=t.Children.map(r,e),a=n.props,u=a.only,c=a.matchMedia,f=o(a,y),l=t.createElement(n.type,f,i);return u||c?t.createElement(h,{on:u||"",matchMedia:c||""},l):l},g=function(e){var n=e.children,r=e.as,i=o(e,b),a=t.Children.map(n,x);return r?t.createElement(r,i,a):t.createElement(t.Fragment,null,a)};g.displayName="Match";var j=function(e){return function(n){var r={};return Object.keys(n).forEach(function(t){var i=e[t];if(!i)throw new Error(t+" is not a valid breakpoint\nValid breakpoints are: "+Object.keys(e));r["@media "+d(i)]=n[t]}),r}},O=function e(n){var r="";return Object.entries(n).forEach(function(n){var t=n[0],i=n[1];r+="object"==typeof i?t+" {\n"+e(i)+"}\n":t+": "+i+";\n"}),r};e.BreakpointsContext=l,e.BreakpointsProvider=s,e.Match=g,e.Only=h,e.toCSS=function(e){return function(n){return O(j(e)(n))}},e.toJSON=j,e.useBreakpoint=m,e.useMediaQuery=p});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self)["@blocz/react-responsive"]={},e.React)}(this,function(e,n){function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var t=/*#__PURE__*/r(n);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},i.apply(null,arguments)}var o=["em","ex","%","px","cm","mm","in","pt","pc","ch","rem","vh","vw","vmin","vmax"],a=["width","height"],u=function(e){return Object.keys(e).reduce(function(n,r){var t=e[r];if(!Array.isArray(t)||t.length<=1)return n;var i,u,c=t[0],f=t[1],s=t[2],l=t.slice(3);if(l.length>0){var d=new Error('The following fields "'+l+'" have been ignored');console.error(d)}if("number"!=typeof c||"number"!=typeof f)return n;"string"==typeof s?i=s:"object"==typeof s&&(u=s.direction,i=s.unit);var p=Math.min(c,f),v=Math.max(c,f),m=i&&o.includes(i)?i:"px",h=u&&a.includes(u)?u:"width";return n[r]=[p,v,m,h],n[r+"Up"]=[p,Infinity,m,h],n[r+"Down"]=[0,v,m,h],n},{})},c={xs:[0,575,"px"],sm:[576,767,"px"],md:[768,991,"px"],lg:[992,1199,"px"],xl:[1200,Infinity,"px"]},f=t.createContext(u(c)),s=function(e){var n=e.breakpoints,r=e.children;return t.createElement(f.Provider,{value:u(i({},void 0===n?c:n,e.additionalBreakpoints))},r)};s.displayName="BreakpointsProvider";var l=function(e){var n=t.useMemo(function(){return matchMedia(e)},[e]),r=t.useState(n.matches),i=r[0],o=r[1];return t.useLayoutEffect(function(){o(n.matches);var e=function(e){o(e.matches)};return n.addListener(e),function(){n.removeListener(e)}},[n]),i},d=function(e){var n=t.useContext(f),r=t.useMemo(function(){return function(e){return function(n){if(void 0===n&&(n=""),!n)return"";var r=n.split(" "),t=r.map(function(n){return e[n]}).filter(Boolean).map(function(e){return function(e){var n=[],r=e[0],t=e[1],i=e[2],o=e[3];return 0!==r&&n.push("(min-"+o+":"+r+i+")"),Infinity!==t&&n.push("(max-"+o+":"+t+i+")")," "+n.join(" and ")}(e)}).filter(Boolean).join(",");if(!t){var i=1===r.length;console.error('"'+r.join('", "')+'" '+(i?"is":"are")+"n't "+(i?"a ":"")+"valid breakpoint"+(i?"":"s"))}return t}}(n)},[n]),i=t.useMemo(function(){return r(e)},[r,e]);return l(i||"-")},p=["matchMedia","on","as","children"];e.BreakpointsContext=f,e.BreakpointsProvider=s,e.Only=function(e){var n=e.matchMedia,r=e.on,i=e.as,o=e.children,a=function(e,n){if(null==e)return{};var r={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(n.includes(t))continue;r[t]=e[t]}return r}(e,p),u=d(r),c=l(n||"-");return u||c?t.createElement(i||t.Fragment,i?a:void 0,o):null},e.useBreakpoint=d,e.useMediaQuery=l});
2
2
  //# sourceMappingURL=react-responsive.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-responsive.umd.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx","../src/Match.tsx","../src/css-in-js.ts"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext = React.createContext<Breakpoints>(sanitize(defaultBreakpoints));\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints = {},\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\n// const startTransitionFallbackForReact17AndBellow = (cb: () => void) => cb();\n// // @ts-expect-error not supported yet\n// const startTransition = React.startTransition || startTransitionFallbackForReact17AndBellow;\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // We use startTransition as those update aren't urgent\n // startTransition(() => {\n setIsShown(event.matches);\n // });\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(as || React.Fragment, as ? (props as OtherProps) : undefined, children);\n}\n\nOnly.displayName = \"Only\";\n","import * as React from \"react\";\n\nimport { Only } from \"./Only\";\n\nexport interface MatchChildProps {\n matchMedia?: string;\n only?: string;\n}\n\ndeclare module \"react\" {\n interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {}\n}\n\ntype Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;\n\nconst parseChildren = (element: Element): Element => {\n if (!element || !element.props) {\n return element;\n }\n\n const _children: Element | Element[] | null = element.props.children;\n if (!_children) {\n return null;\n }\n const children = React.Children.map(_children, parseChildren);\n const { only, matchMedia, ...props } = element.props;\n const clone = React.createElement(element.type, props, children);\n if (!only && !matchMedia) {\n return clone;\n }\n return (\n <Only on={only || \"\"} matchMedia={matchMedia || \"\"}>\n {clone}\n </Only>\n );\n};\n\ninterface MatchProps {\n [key: string]: any;\n children: Element | Element[] | null;\n as?: string;\n}\n\nexport const Match: React.FunctionComponent<MatchProps> = ({ children, as, ...props }) => {\n const computedChildren = React.Children.map(children, parseChildren);\n if (as) {\n return React.createElement(as, props, computedChildren);\n }\n return React.createElement(React.Fragment, null, computedChildren);\n};\n\nMatch.displayName = \"Match\";\n","import { CSSProperties } from \"react\";\nimport { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\ntype CSSinJSProperties =\n | CSSProperties\n | {\n [key: string]: CSSProperties;\n };\n\ninterface Points {\n [breakpoint: string]: CSSinJSProperties;\n}\n\ntype CSSinJS = Record<string, CSSinJSProperties>;\nexport const toJSON =\n (breakpoints: Breakpoints) =>\n (points: Points): CSSinJS => {\n const css: CSSinJS = {};\n Object.keys(points).forEach((point) => {\n const breakpoint = breakpoints[point];\n if (!breakpoint) {\n throw new Error(`${point} is not a valid breakpoint\\nValid breakpoints are: ${Object.keys(breakpoints)}`);\n }\n css[`@media ${fromBreakpointToMedia(breakpoint)}`] = points[point];\n });\n return css;\n };\n\nconst stringify = (object: CSSinJSProperties) => {\n let string = \"\";\n Object.entries(object).forEach(([key, value]) => {\n if (typeof value !== \"object\") {\n string += `${key}: ${value};\\n`;\n return;\n }\n string += `${key} {\\n${stringify(value)}}\\n`;\n });\n return string;\n};\n\nexport const toCSS =\n (breakpoints: Breakpoints) =>\n (points: Points): string =>\n stringify(toJSON(breakpoints)(points));\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","Array","isArray","breakpoint","length","supposedUnit","supposedDirection","supposedMax","options","rest","slice","error","Error","console","supposedMin","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","additionalBreakpoints","children","Provider","value","_ref$additionalBreakp","displayName","fromBreakpointToMedia","mediaList","minValue","maxValue","push","str","join","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","isUniqBreakpoint","Only","as","props","matchOn","useBreakpoint","matchQuery","createElement","Fragment","undefined","parseChildren","element","_children","Children","only","_objectWithoutPropertiesLoose","_element$props","_excluded","type","clone","_excluded2","computedChildren","Match","toJSON","points","css","forEach","point","stringify","object","string","entries","key"],"mappings":"q6BAiBA,IAA0BA,EAAY,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAK6BC,EAAiB,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,MAAmBL,EAAcK,GAEjC,IAAKC,MAAMC,QAAQC,IAAeA,EAAWC,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,I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AOG,KAG/DF,IAEYG,EAAG,SAAAA,EAACC,GACjB,IAAIC,EAAS,GAQb,OAPAvG,OAAOwG,QAAQF,GAAQH,QAAQ,SAAA/D,OAAiBqE,EAAArE,EAAA,GAAVI,EAAUJ,EAAA,GAK9CmE,GAJqB,iBAAV/D,EAIEiE,EAAUJ,OAAAA,EAAU7D,GAClC,MAJgBiE,EAAP,KAAejE,EAArB,QAKG+D,6EAIP,SAACpG,GAAD,OACC8F,SAAAA,UACUI,EAACL,EAAO7F,EAAP6F,CAAoBC"}
1
+ {"version":3,"file":"react-responsive.umd.js","sources":["../src/sanitize.ts","../src/BreakpointsContext.tsx","../src/fromBreakpointToMedia.ts","../src/useMediaQuery.ts","../src/useBreakpoint.ts","../src/mediaQueryBuilder.ts","../src/Only.tsx"],"sourcesContent":["export type Units =\n | \"em\"\n | \"ex\"\n | \"%\"\n | \"px\"\n | \"cm\"\n | \"mm\"\n | \"in\"\n | \"pt\"\n | \"pc\"\n | \"ch\"\n | \"rem\"\n | \"vh\"\n | \"vw\"\n | \"vmin\"\n | \"vmax\";\n\nconst listOfSupportedUnits: Units[] = [\n \"em\",\n \"ex\",\n \"%\",\n \"px\",\n \"cm\",\n \"mm\",\n \"in\",\n \"pt\",\n \"pc\",\n \"ch\",\n \"rem\",\n \"vh\",\n \"vw\",\n \"vmin\",\n \"vmax\",\n];\n\ntype Directions = \"width\" | \"height\";\n\nconst listOfSupportedDirections: Directions[] = [\"width\", \"height\"];\n\nexport type ExposedBreakpoint =\n | [number, number]\n | [number, number, Units]\n | [number, number, { unit?: Units; direction?: Directions }];\n\nexport interface ExposedBreakpoints {\n [key: string]: ExposedBreakpoint;\n}\n\nexport type Breakpoint = [number, number, Units, Directions];\n\nexport interface Breakpoints {\n [breakpoint: string]: Breakpoint;\n}\n\nexport const sanitize = (inBreakpoints: ExposedBreakpoints): Breakpoints => {\n return Object.keys(inBreakpoints).reduce<Breakpoints>((breakpoints, breakpointName) => {\n const breakpoint = inBreakpoints[breakpointName];\n\n if (!Array.isArray(breakpoint) || breakpoint.length <= 1) {\n return breakpoints;\n }\n\n const [supposedMin, supposedMax, options, ...rest] = breakpoint;\n if (rest.length > 0) {\n const error = new Error(`The following fields \"${rest}\" have been ignored`);\n console.error(error);\n }\n\n if (typeof supposedMin !== \"number\" || typeof supposedMax !== \"number\") {\n return breakpoints;\n }\n\n let supposedUnit: Units | undefined;\n let supposedDirection: Directions | undefined;\n if (typeof options === \"string\") {\n supposedUnit = options;\n } else if (typeof options === \"object\") {\n supposedDirection = options.direction;\n supposedUnit = options.unit;\n }\n\n const min = Math.min(supposedMin, supposedMax);\n const max = Math.max(supposedMin, supposedMax);\n const unit = supposedUnit && listOfSupportedUnits.includes(supposedUnit) ? supposedUnit : \"px\";\n const direction =\n supposedDirection && listOfSupportedDirections.includes(supposedDirection) ? supposedDirection : \"width\";\n\n breakpoints[breakpointName] = [min, max, unit, direction];\n breakpoints[`${breakpointName}Up`] = [min, Infinity, unit, direction];\n breakpoints[`${breakpointName}Down`] = [0, max, unit, direction];\n\n return breakpoints;\n }, {});\n};\n","import * as React from \"react\";\n\nimport { sanitize, ExposedBreakpoints, Breakpoints } from \"./sanitize\";\n\nconst defaultBreakpoints: ExposedBreakpoints = {\n xs: [0, 575, \"px\"], // Extra small devices (portrait phones)\n sm: [576, 767, \"px\"], // Small devices (landscape phones)\n md: [768, 991, \"px\"], // Medium devices (tablets)\n lg: [992, 1199, \"px\"], // Large devices (desktops)\n xl: [1200, Infinity, \"px\"], // Extra large devices (large desktops)\n};\n\nexport const BreakpointsContext: React.Context<Breakpoints> = React.createContext<Breakpoints>(\n sanitize(defaultBreakpoints),\n);\n\ninterface BreakpointsProviderProps {\n breakpoints?: ExposedBreakpoints;\n additionalBreakpoints?: ExposedBreakpoints;\n}\n\nexport const BreakpointsProvider: React.FunctionComponent<React.PropsWithChildren<BreakpointsProviderProps>> = ({\n breakpoints = defaultBreakpoints,\n additionalBreakpoints,\n children,\n}) => {\n return (\n <BreakpointsContext.Provider\n value={sanitize({\n ...breakpoints,\n ...additionalBreakpoints,\n })}\n >\n {children}\n </BreakpointsContext.Provider>\n );\n};\n\nBreakpointsProvider.displayName = \"BreakpointsProvider\";\n","import { Breakpoint } from \"./sanitize\";\n\nexport const fromBreakpointToMedia = (breakpoint: Breakpoint): string => {\n const mediaList: string[] = [];\n const [minValue, maxValue, unit, direction] = breakpoint;\n let str;\n\n // Min value\n if (minValue !== 0) {\n str = `${minValue}${unit}`;\n mediaList.push(`(min-${direction}:${str})`);\n }\n\n // Max value\n if (maxValue !== Infinity) {\n str = `${maxValue}${unit}`;\n mediaList.push(`(max-${direction}:${str})`);\n }\n\n return \" \" + mediaList.join(\" and \");\n};\n","import * as React from \"react\";\n\nexport const useMediaQuery = (mediaQuery: string): boolean => {\n const mediaQueryList = React.useMemo(() => matchMedia(mediaQuery), [mediaQuery]);\n const [isShown, setIsShown] = React.useState<boolean>(mediaQueryList.matches);\n\n React.useLayoutEffect(() => {\n setIsShown(mediaQueryList.matches);\n const listener = (event: MediaQueryListEvent) => {\n // Those are important updates, so we don't want to use transitions on them\n setIsShown(event.matches);\n };\n\n // cannot use addEventListener for IE 11 and safari 13-\n mediaQueryList.addListener(listener);\n return () => {\n mediaQueryList.removeListener(listener);\n };\n }, [mediaQueryList]);\n\n return isShown;\n};\n","import * as React from \"react\";\n\nimport { BreakpointsContext } from \"./BreakpointsContext\";\n\nimport { mediaQueryBuilder } from \"./mediaQueryBuilder\";\n\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport const useBreakpoint = (on?: string): boolean => {\n const breakpoints = React.useContext(BreakpointsContext);\n const toMediaQuery = React.useMemo(() => mediaQueryBuilder(breakpoints), [breakpoints]);\n\n const mediaQuery = React.useMemo(() => toMediaQuery(on), [toMediaQuery, on]);\n\n return useMediaQuery(mediaQuery || \"-\");\n};\n","import { Breakpoints } from \"./sanitize\";\nimport { fromBreakpointToMedia } from \"./fromBreakpointToMedia\";\n\nexport const mediaQueryBuilder =\n (breakpoints: Breakpoints) =>\n (on = \"\"): string => {\n if (!on) {\n return \"\";\n }\n const rawBreakpointNames = on.split(\" \");\n const filteredBreakpoints = rawBreakpointNames.map((breakpointName) => breakpoints[breakpointName]).filter(Boolean);\n const mediaQuery = filteredBreakpoints\n .map((breakpoint) => fromBreakpointToMedia(breakpoint))\n .filter(Boolean)\n .join(\",\");\n if (!mediaQuery) {\n const isUniqBreakpoint = rawBreakpointNames.length === 1;\n console.error(\n `\"${rawBreakpointNames.join('\", \"')}\" ${isUniqBreakpoint ? \"is\" : \"are\"}n't ${\n isUniqBreakpoint ? \"a \" : \"\"\n }valid breakpoint${isUniqBreakpoint ? \"\" : \"s\"}`,\n );\n }\n return mediaQuery;\n };\n","import * as React from \"react\";\n\nimport { useBreakpoint } from \"./useBreakpoint\";\nimport { useMediaQuery } from \"./useMediaQuery\";\n\nexport type OnlyProps<OtherProps = Record<string, never>> = OtherProps & {\n matchMedia?: string;\n on?: string;\n as?: string | React.ComponentType<OtherProps>;\n};\n\nexport function Only<OtherProps = Record<string, never>>({\n matchMedia,\n on,\n as,\n children,\n ...props\n}: React.PropsWithChildren<OnlyProps<OtherProps>>): React.ReactElement | null {\n const matchOn = useBreakpoint(on);\n const matchQuery = useMediaQuery(matchMedia || \"-\");\n const isShown = matchOn || matchQuery;\n\n if (!isShown) {\n return null;\n }\n\n return React.createElement(\n // @ts-expect-error – this is a complex type\n as || React.Fragment,\n as ? (props as OtherProps) : undefined,\n children,\n );\n}\n"],"names":["listOfSupportedUnits","listOfSupportedDirections","sanitize","inBreakpoints","Object","keys","reduce","breakpoints","breakpointName","breakpoint","Array","isArray","length","supposedUnit","supposedDirection","supposedMin","supposedMax","options","rest","slice","error","Error","console","direction","unit","min","Math","max","includes","Infinity","defaultBreakpoints","xs","sm","md","lg","xl","BreakpointsContext","React","createContext","BreakpointsProvider","_ref","_ref$breakpoints","children","Provider","value","_extends","additionalBreakpoints","displayName","useMediaQuery","mediaQuery","mediaQueryList","useMemo","matchMedia","_React$useState","useState","matches","isShown","setIsShown","useLayoutEffect","listener","event","addListener","removeListener","useBreakpoint","on","useContext","toMediaQuery","rawBreakpointNames","split","map","filter","Boolean","mediaList","minValue","maxValue","push","str","join","fromBreakpointToMedia","isUniqBreakpoint","mediaQueryBuilder","as","props","_objectWithoutPropertiesLoose","_excluded","matchOn","matchQuery","createElement","Fragment","undefined"],"mappings":"qxBAiBA,IAAMA,EAAgC,CACpC,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,MACA,KACA,KACA,OACA,QAKIC,EAA0C,CAAC,QAAS,UAiB7CC,EAAW,SAACC,GACvB,OAAOC,OAAOC,KAAKF,GAAeG,OAAoB,SAACC,EAAaC,GAClE,IAAMC,EAAaN,EAAcK,GAEjC,IAAKE,MAAMC,QAAQF,IAAeA,EAAWG,QAAU,EACrD,OAAOL,EAGT,IAUIM,EACAC,EAXGC,EAA8CN,EAAU,GAA3CO,EAAiCP,EAApBQ,GAAAA,EAAoBR,EAAU,GAAlBS,EAAQT,EAAUU,SAC/D,GAAID,EAAKN,OAAS,EAAG,CACnB,IAAMQ,EAAQ,IAAIC,MAA+BH,yBAAAA,EAAyB,uBAC1EI,QAAQF,MAAMA,EAChB,CAEA,GAA2B,iBAAhBL,GAAmD,iBAAhBC,EAC5C,OAAOT,EAKc,iBAAZU,EACTJ,EAAeI,EACa,iBAAZA,IAChBH,EAAoBG,EAAQM,UAC5BV,EAAeI,EAAQO,MAGzB,IAAMC,EAAMC,KAAKD,IAAIV,EAAaC,GAC5BW,EAAMD,KAAKC,IAAIZ,EAAaC,GAC5BQ,EAAOX,GAAgBb,EAAqB4B,SAASf,GAAgBA,EAAe,KACpFU,EACJT,GAAqBb,EAA0B2B,SAASd,GAAqBA,EAAoB,QAMnG,OAJAP,EAAYC,GAAkB,CAACiB,EAAKE,EAAKH,EAAMD,GAC/ChB,EAAeC,EAAc,MAAQ,CAACiB,EAAKI,SAAUL,EAAMD,GAC3DhB,EAAeC,EAAc,QAAU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sB,GACrBC,EAAuChE,KAA7BiE,EAA6BjE,EAAnBe,GAAAA,EAAmBf,EAAU,GAAvBc,EAAad,KAe9C,OAXiB,IAAbgE,GAEFD,EAAUG,KAAI,QAASpD,EAAaqD,IAD3BH,EAAWjD,OAKLK,WAAb6C,GAEFF,EAAUG,aAAapD,EAAS,IADvBmD,EAAWlD,EACsB,KAGrC,IAAMgD,EAAUK,KAAK,QAC9B,CGR2BC,CAAsBrE,EAAW,GACrD6D,OAAOC,SACPM,KAAK,KACR,IAAK5B,EAAY,CACf,IAAM8B,EAAiD,IAA9BZ,EAAmBvD,OAC5CU,QAAQF,MACF+C,IAAAA,EAAmBU,KAAK,QAAYE,MAAAA,EAAmB,KAAO,OAAK,QACrEA,EAAmB,KAAO,IAC5B,oBAAmBA,EAAmB,GAAK,KAE/C,CACA,OAAO9B,CACT,CAAC,CDdwC+B,CAAkBzE,EAAY,EAAE,CAACA,IAEpE0C,EAAaZ,EAAMc,QAAQ,WAAM,OAAAe,EAAaF,EAAG,EAAE,CAACE,EAAcF,IAExE,OAAOhB,EAAcC,GAAc,IACrC,8FEJgB,SAAIT,GAClB,IAAAY,EAAUZ,EAAVY,WACAY,EAAExB,EAAFwB,GACAiB,EAAEzC,EAAFyC,GACAvC,EAAQF,EAARE,SACGwC,yIAAKC,CAAA3C,EAAA4C,GAEFC,EAAUtB,EAAcC,GACxBsB,EAAatC,EAAcI,GAAc,KAG/C,OAFgBiC,GAAWC,EAMpBjD,EAAMkD,cAEXN,GAAM5C,EAAMmD,SACZP,EAAMC,OAAuBO,EAC7B/C,GAPO,IASX"}
package/lib/sanitize.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export declare type Units = "em" | "ex" | "%" | "px" | "cm" | "mm" | "in" | "pt" | "pc" | "ch" | "rem" | "vh" | "vw" | "vmin" | "vmax";
2
- declare type Directions = "width" | "height";
3
- export declare type ExposedBreakpoint = [number, number] | [number, number, Units] | [number, number, {
4
- unit?: Units;
5
- direction?: Directions;
6
- }];
7
- export interface ExposedBreakpoints {
8
- [key: string]: ExposedBreakpoint;
9
- }
10
- export declare type Breakpoint = [number, number, Units, Directions];
11
- export interface Breakpoints {
12
- [breakpoint: string]: Breakpoint;
13
- }
14
- export declare const sanitize: (inBreakpoints: ExposedBreakpoints) => Breakpoints;
15
- export {};
1
+ export type Units = "em" | "ex" | "%" | "px" | "cm" | "mm" | "in" | "pt" | "pc" | "ch" | "rem" | "vh" | "vw" | "vmin" | "vmax";
2
+ type Directions = "width" | "height";
3
+ export type ExposedBreakpoint = [number, number] | [number, number, Units] | [number, number, {
4
+ unit?: Units;
5
+ direction?: Directions;
6
+ }];
7
+ export interface ExposedBreakpoints {
8
+ [key: string]: ExposedBreakpoint;
9
+ }
10
+ export type Breakpoint = [number, number, Units, Directions];
11
+ export interface Breakpoints {
12
+ [breakpoint: string]: Breakpoint;
13
+ }
14
+ export declare const sanitize: (inBreakpoints: ExposedBreakpoints) => Breakpoints;
15
+ export {};
@@ -1 +1 @@
1
- export declare const useBreakpoint: (on?: string) => boolean;
1
+ export declare const useBreakpoint: (on?: string) => boolean;
@@ -1 +1 @@
1
- export declare const useMediaQuery: (mediaQuery: string) => boolean;
1
+ export declare const useMediaQuery: (mediaQuery: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocz/react-responsive",
3
- "version": "3.0.3",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "🔍 <Only /> displays some contents for a specific screen size",
5
5
  "source": "src/index.ts",
6
6
  "sideEffects": false,
@@ -18,7 +18,9 @@
18
18
  },
19
19
  "./package.json": "./package.json"
20
20
  },
21
- "repository": "git@github.com:bloczjs/react-responsive.git",
21
+ "repository": {
22
+ "url": "git+ssh://git@github.com/bloczjs/react-responsive.git"
23
+ },
22
24
  "keywords": [
23
25
  "adaptive",
24
26
  "breakpoint",
@@ -40,10 +42,10 @@
40
42
  },
41
43
  "homepage": "https://github.com/bloczjs/react-responsive#readme",
42
44
  "devDependencies": {
43
- "@types/react": "^18.0.12",
44
- "microbundle": "^0.15.0"
45
+ "@types/react": "^19.0.1",
46
+ "microbundle": "^0.15.1"
45
47
  },
46
48
  "peerDependencies": {
47
- "react": "16.8.0 - 18.x.x"
49
+ "react": "16.8.0 - 19.x.x"
48
50
  }
49
51
  }
package/lib/Match.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import * as React from "react";
2
- export interface MatchChildProps {
3
- matchMedia?: string;
4
- only?: string;
5
- }
6
- declare module "react" {
7
- interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T>, MatchChildProps {
8
- }
9
- }
10
- declare type Element = React.ReactElement<MatchChildProps & any, string | React.ComponentType<MatchChildProps & any>> | null;
11
- interface MatchProps {
12
- [key: string]: any;
13
- children: Element | Element[] | null;
14
- as?: string;
15
- }
16
- export declare const Match: React.FunctionComponent<MatchProps>;
17
- export {};