UNPKG

5.42 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.MediaQueries = void 0;
7
8var _Breakpoints = require("./Breakpoints");
9
10var _Interactions = require("./Interactions");
11
12var _Utils = require("./Utils");
13
14function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
15
16function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
18function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
19
20function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
21
22function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
23
24function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
25
26function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
27
28function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
30function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
31
32function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
33
34function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
36/**
37 * Encapsulates all interaction data (and breakpoint data in the superclass)
38 * needed by the Media component. The data is generated on initialization so no
39 * further runtime work is necessary.
40 */
41var MediaQueries =
42/*#__PURE__*/
43function () {
44 _createClass(MediaQueries, null, [{
45 key: "validKeys",
46 value: function validKeys() {
47 return _toConsumableArray(_Breakpoints.Breakpoints.validKeys()).concat(_toConsumableArray(_Interactions.Interactions.validKeys()));
48 }
49 }]);
50
51 function MediaQueries(breakpoints, interactions) {
52 var _this = this;
53
54 _classCallCheck(this, MediaQueries);
55
56 _defineProperty(this, "_breakpoints", void 0);
57
58 _defineProperty(this, "_interactions", void 0);
59
60 _defineProperty(this, "toStyle", function () {
61 return [// Don’t add any size to the layout
62 ".fresnel-container{margin:0;padding:0;}"].concat(_toConsumableArray(_this._breakpoints.toRuleSets()), _toConsumableArray(_this._interactions.toRuleSets())).join("\n");
63 });
64
65 this._breakpoints = new _Breakpoints.Breakpoints(breakpoints);
66 this._interactions = new _Interactions.Interactions(interactions || {});
67 }
68
69 _createClass(MediaQueries, [{
70 key: "shouldRenderMediaQuery",
71 value: function shouldRenderMediaQuery(mediaQueryProps, onlyMatch) {
72 var interaction = mediaQueryProps.interaction,
73 breakpointProps = _objectWithoutProperties(mediaQueryProps, ["interaction"]);
74
75 if (interaction) {
76 return this._interactions.shouldRenderMediaQuery(interaction, onlyMatch);
77 } // Remove any interaction possibilities from the list.
78
79
80 var onlyMatchBreakpoints = (0, _Utils.intersection)(onlyMatch, this._breakpoints.sortedBreakpoints);
81 return this._breakpoints.shouldRenderMediaQuery(breakpointProps, onlyMatchBreakpoints);
82 }
83 }, {
84 key: "breakpoints",
85 get: function get() {
86 return this._breakpoints;
87 }
88 }, {
89 key: "mediaQueryTypes",
90 get: function get() {
91 return _toConsumableArray(this._breakpoints.sortedBreakpoints).concat(_toConsumableArray(this._interactions.interactions));
92 }
93 }, {
94 key: "dynamicResponsiveMediaQueries",
95 get: function get() {
96 return _objectSpread({}, this._breakpoints.dynamicResponsiveMediaQueries, this._interactions.dynamicResponsiveMediaQueries);
97 }
98 }]);
99
100 return MediaQueries;
101}();
102
103exports.MediaQueries = MediaQueries;
104//# sourceMappingURL=MediaQueries.js.map
\No newline at end of file