build/scripts/viewport
index.js
7.2 KB
4 months ago
index.js.map
11.7 KB
4 months ago
index.min.asset.php
120 B
4 months ago
index.min.js
2.3 KB
4 months ago
index.min.js.map
12.5 KB
4 months ago
| 1 | "use strict"; |
| 2 | var wp; |
| 3 | (wp ||= {}).viewport = (() => { |
| 4 | var __create = Object.create; |
| 5 | var __defProp = Object.defineProperty; |
| 6 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 7 | var __getOwnPropNames = Object.getOwnPropertyNames; |
| 8 | var __getProtoOf = Object.getPrototypeOf; |
| 9 | var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 10 | var __commonJS = (cb, mod) => function __require() { |
| 11 | return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 12 | }; |
| 13 | var __export = (target, all) => { |
| 14 | for (var name in all) |
| 15 | __defProp(target, name, { get: all[name], enumerable: true }); |
| 16 | }; |
| 17 | var __copyProps = (to, from, except, desc) => { |
| 18 | if (from && typeof from === "object" || typeof from === "function") { |
| 19 | for (let key of __getOwnPropNames(from)) |
| 20 | if (!__hasOwnProp.call(to, key) && key !== except) |
| 21 | __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 22 | } |
| 23 | return to; |
| 24 | }; |
| 25 | var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 26 | // If the importer is in node compatibility mode or this is not an ESM |
| 27 | // file that has been converted to a CommonJS file using a Babel- |
| 28 | // compatible transform (i.e. "__esModule" has not been set), then set |
| 29 | // "default" to the CommonJS "module.exports" for node compatibility. |
| 30 | isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 31 | mod |
| 32 | )); |
| 33 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 34 | |
| 35 | // package-external:@wordpress/compose |
| 36 | var require_compose = __commonJS({ |
| 37 | "package-external:@wordpress/compose"(exports, module) { |
| 38 | module.exports = window.wp.compose; |
| 39 | } |
| 40 | }); |
| 41 | |
| 42 | // package-external:@wordpress/data |
| 43 | var require_data = __commonJS({ |
| 44 | "package-external:@wordpress/data"(exports, module) { |
| 45 | module.exports = window.wp.data; |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | // package-external:@wordpress/element |
| 50 | var require_element = __commonJS({ |
| 51 | "package-external:@wordpress/element"(exports, module) { |
| 52 | module.exports = window.wp.element; |
| 53 | } |
| 54 | }); |
| 55 | |
| 56 | // packages/viewport/build-module/index.mjs |
| 57 | var index_exports = {}; |
| 58 | __export(index_exports, { |
| 59 | ifViewportMatches: () => if_viewport_matches_default, |
| 60 | store: () => store, |
| 61 | withViewportMatch: () => with_viewport_match_default |
| 62 | }); |
| 63 | |
| 64 | // packages/viewport/build-module/listener.mjs |
| 65 | var import_compose = __toESM(require_compose(), 1); |
| 66 | var import_data2 = __toESM(require_data(), 1); |
| 67 | |
| 68 | // packages/viewport/build-module/store/index.mjs |
| 69 | var import_data = __toESM(require_data(), 1); |
| 70 | |
| 71 | // packages/viewport/build-module/store/reducer.mjs |
| 72 | function reducer(state = {}, action) { |
| 73 | switch (action.type) { |
| 74 | case "SET_IS_MATCHING": |
| 75 | return action.values; |
| 76 | } |
| 77 | return state; |
| 78 | } |
| 79 | var reducer_default = reducer; |
| 80 | |
| 81 | // packages/viewport/build-module/store/actions.mjs |
| 82 | var actions_exports = {}; |
| 83 | __export(actions_exports, { |
| 84 | setIsMatching: () => setIsMatching |
| 85 | }); |
| 86 | function setIsMatching(values) { |
| 87 | return { |
| 88 | type: "SET_IS_MATCHING", |
| 89 | values |
| 90 | }; |
| 91 | } |
| 92 | |
| 93 | // packages/viewport/build-module/store/selectors.mjs |
| 94 | var selectors_exports = {}; |
| 95 | __export(selectors_exports, { |
| 96 | isViewportMatch: () => isViewportMatch |
| 97 | }); |
| 98 | function isViewportMatch(state, query) { |
| 99 | if (query.indexOf(" ") === -1) { |
| 100 | query = ">= " + query; |
| 101 | } |
| 102 | return !!state[query]; |
| 103 | } |
| 104 | |
| 105 | // packages/viewport/build-module/store/index.mjs |
| 106 | var STORE_NAME = "core/viewport"; |
| 107 | var store = (0, import_data.createReduxStore)(STORE_NAME, { |
| 108 | reducer: reducer_default, |
| 109 | actions: actions_exports, |
| 110 | selectors: selectors_exports |
| 111 | }); |
| 112 | (0, import_data.register)(store); |
| 113 | |
| 114 | // packages/viewport/build-module/listener.mjs |
| 115 | var addDimensionsEventListener = (breakpoints, operators) => { |
| 116 | const setIsMatching2 = (0, import_compose.debounce)( |
| 117 | () => { |
| 118 | const values = Object.fromEntries( |
| 119 | queries.map(([key, query]) => [key, query.matches]) |
| 120 | ); |
| 121 | (0, import_data2.dispatch)(store).setIsMatching(values); |
| 122 | }, |
| 123 | 0, |
| 124 | { leading: true } |
| 125 | ); |
| 126 | const operatorEntries = Object.entries(operators); |
| 127 | const queries = Object.entries(breakpoints).flatMap( |
| 128 | ([name, width]) => { |
| 129 | return operatorEntries.map( |
| 130 | ([operator, condition]) => { |
| 131 | const list = window.matchMedia( |
| 132 | `(${condition}: ${width}px)` |
| 133 | ); |
| 134 | list.addEventListener("change", setIsMatching2); |
| 135 | return [`${operator} ${name}`, list]; |
| 136 | } |
| 137 | ); |
| 138 | } |
| 139 | ); |
| 140 | window.addEventListener("orientationchange", setIsMatching2); |
| 141 | setIsMatching2(); |
| 142 | setIsMatching2.flush(); |
| 143 | }; |
| 144 | var listener_default = addDimensionsEventListener; |
| 145 | |
| 146 | // packages/viewport/build-module/if-viewport-matches.mjs |
| 147 | var import_compose3 = __toESM(require_compose(), 1); |
| 148 | |
| 149 | // packages/viewport/build-module/with-viewport-match.mjs |
| 150 | var import_element = __toESM(require_element(), 1); |
| 151 | var import_compose2 = __toESM(require_compose(), 1); |
| 152 | var withViewportMatch = (queries) => { |
| 153 | const queryEntries = Object.entries(queries); |
| 154 | const useViewPortQueriesResult = () => Object.fromEntries( |
| 155 | queryEntries.map(([key, query]) => { |
| 156 | let [operator, breakpointName] = query.split(" "); |
| 157 | if (breakpointName === void 0) { |
| 158 | breakpointName = operator; |
| 159 | operator = ">="; |
| 160 | } |
| 161 | return [ |
| 162 | key, |
| 163 | // Hooks should unconditionally execute in the same order, |
| 164 | // we are respecting that as from the static query of the HOC we generate |
| 165 | // a hook that calls other hooks always in the same order (because the query never changes). |
| 166 | // eslint-disable-next-line react-hooks/rules-of-hooks |
| 167 | (0, import_compose2.useViewportMatch)( |
| 168 | breakpointName, |
| 169 | operator |
| 170 | ) |
| 171 | ]; |
| 172 | }) |
| 173 | ); |
| 174 | return (0, import_compose2.createHigherOrderComponent)( |
| 175 | (WrappedComponent) => { |
| 176 | const WrappedWithViewport = (props) => { |
| 177 | const queriesResult = useViewPortQueriesResult(); |
| 178 | return (0, import_element.createElement)(WrappedComponent, { |
| 179 | ...props, |
| 180 | ...queriesResult |
| 181 | }); |
| 182 | }; |
| 183 | return (0, import_compose2.pure)(WrappedWithViewport); |
| 184 | }, |
| 185 | "withViewportMatch" |
| 186 | ); |
| 187 | }; |
| 188 | var with_viewport_match_default = withViewportMatch; |
| 189 | |
| 190 | // packages/viewport/build-module/if-viewport-matches.mjs |
| 191 | var ifViewportMatches = (query) => (0, import_compose3.createHigherOrderComponent)( |
| 192 | (0, import_compose3.compose)([ |
| 193 | with_viewport_match_default({ |
| 194 | isViewportMatch: query |
| 195 | }), |
| 196 | (0, import_compose3.ifCondition)( |
| 197 | (props) => props.isViewportMatch |
| 198 | ) |
| 199 | ]), |
| 200 | "ifViewportMatches" |
| 201 | ); |
| 202 | var if_viewport_matches_default = ifViewportMatches; |
| 203 | |
| 204 | // packages/viewport/build-module/index.mjs |
| 205 | var BREAKPOINTS = { |
| 206 | huge: 1440, |
| 207 | wide: 1280, |
| 208 | large: 960, |
| 209 | medium: 782, |
| 210 | small: 600, |
| 211 | mobile: 480 |
| 212 | }; |
| 213 | var OPERATORS = { |
| 214 | "<": "max-width", |
| 215 | ">=": "min-width" |
| 216 | }; |
| 217 | listener_default(BREAKPOINTS, OPERATORS); |
| 218 | return __toCommonJS(index_exports); |
| 219 | })(); |
| 220 | //# sourceMappingURL=index.js.map |
| 221 |