PluginProbe
Gutenberg / 17.6.2
Gutenberg v17.6.2
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
gutenberg / build / style-engine / index.js

index.js in Gutenberg 17.6.2, at build/style-engine/index.js

1,129 lines 37.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ (() => {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = (exports, definition) => {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ (() => {
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22 /******/ })();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ (() => {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = (exports) => {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ })();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 compileCSS: () => (/* binding */ compileCSS),
43 getCSSRules: () => (/* binding */ getCSSRules)
44 });
45
46 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.mjs
47 /******************************************************************************
48 Copyright (c) Microsoft Corporation.
49
50 Permission to use, copy, modify, and/or distribute this software for any
51 purpose with or without fee is hereby granted.
52
53 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
54 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
55 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
56 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
57 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
58 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
59 PERFORMANCE OF THIS SOFTWARE.
60 ***************************************************************************** */
61 /* global Reflect, Promise, SuppressedError, Symbol */
62
63 var extendStatics = function(d, b) {
64 extendStatics = Object.setPrototypeOf ||
65 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
66 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
67 return extendStatics(d, b);
68 };
69
70 function __extends(d, b) {
71 if (typeof b !== "function" && b !== null)
72 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
73 extendStatics(d, b);
74 function __() { this.constructor = d; }
75 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
76 }
77
78 var __assign = function() {
79 __assign = Object.assign || function __assign(t) {
80 for (var s, i = 1, n = arguments.length; i < n; i++) {
81 s = arguments[i];
82 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
83 }
84 return t;
85 }
86 return __assign.apply(this, arguments);
87 }
88
89 function __rest(s, e) {
90 var t = {};
91 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
92 t[p] = s[p];
93 if (s != null && typeof Object.getOwnPropertySymbols === "function")
94 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
95 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
96 t[p[i]] = s[p[i]];
97 }
98 return t;
99 }
100
101 function __decorate(decorators, target, key, desc) {
102 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
103 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
104 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
105 return c > 3 && r && Object.defineProperty(target, key, r), r;
106 }
107
108 function __param(paramIndex, decorator) {
109 return function (target, key) { decorator(target, key, paramIndex); }
110 }
111
112 function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
113 function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
114 var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
115 var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
116 var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
117 var _, done = false;
118 for (var i = decorators.length - 1; i >= 0; i--) {
119 var context = {};
120 for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
121 for (var p in contextIn.access) context.access[p] = contextIn.access[p];
122 context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
123 var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
124 if (kind === "accessor") {
125 if (result === void 0) continue;
126 if (result === null || typeof result !== "object") throw new TypeError("Object expected");
127 if (_ = accept(result.get)) descriptor.get = _;
128 if (_ = accept(result.set)) descriptor.set = _;
129 if (_ = accept(result.init)) initializers.unshift(_);
130 }
131 else if (_ = accept(result)) {
132 if (kind === "field") initializers.unshift(_);
133 else descriptor[key] = _;
134 }
135 }
136 if (target) Object.defineProperty(target, contextIn.name, descriptor);
137 done = true;
138 };
139
140 function __runInitializers(thisArg, initializers, value) {
141 var useValue = arguments.length > 2;
142 for (var i = 0; i < initializers.length; i++) {
143 value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
144 }
145 return useValue ? value : void 0;
146 };
147
148 function __propKey(x) {
149 return typeof x === "symbol" ? x : "".concat(x);
150 };
151
152 function __setFunctionName(f, name, prefix) {
153 if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
154 return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
155 };
156
157 function __metadata(metadataKey, metadataValue) {
158 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
159 }
160
161 function __awaiter(thisArg, _arguments, P, generator) {
162 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
163 return new (P || (P = Promise))(function (resolve, reject) {
164 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
165 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
166 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
167 step((generator = generator.apply(thisArg, _arguments || [])).next());
168 });
169 }
170
171 function __generator(thisArg, body) {
172 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
173 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
174 function verb(n) { return function (v) { return step([n, v]); }; }
175 function step(op) {
176 if (f) throw new TypeError("Generator is already executing.");
177 while (g && (g = 0, op[0] && (_ = 0)), _) try {
178 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
179 if (y = 0, t) op = [op[0] & 2, t.value];
180 switch (op[0]) {
181 case 0: case 1: t = op; break;
182 case 4: _.label++; return { value: op[1], done: false };
183 case 5: _.label++; y = op[1]; op = [0]; continue;
184 case 7: op = _.ops.pop(); _.trys.pop(); continue;
185 default:
186 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
187 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
188 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
189 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
190 if (t[2]) _.ops.pop();
191 _.trys.pop(); continue;
192 }
193 op = body.call(thisArg, _);
194 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
195 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
196 }
197 }
198
199 var __createBinding = Object.create ? (function(o, m, k, k2) {
200 if (k2 === undefined) k2 = k;
201 var desc = Object.getOwnPropertyDescriptor(m, k);
202 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
203 desc = { enumerable: true, get: function() { return m[k]; } };
204 }
205 Object.defineProperty(o, k2, desc);
206 }) : (function(o, m, k, k2) {
207 if (k2 === undefined) k2 = k;
208 o[k2] = m[k];
209 });
210
211 function __exportStar(m, o) {
212 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
213 }
214
215 function __values(o) {
216 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
217 if (m) return m.call(o);
218 if (o && typeof o.length === "number") return {
219 next: function () {
220 if (o && i >= o.length) o = void 0;
221 return { value: o && o[i++], done: !o };
222 }
223 };
224 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
225 }
226
227 function __read(o, n) {
228 var m = typeof Symbol === "function" && o[Symbol.iterator];
229 if (!m) return o;
230 var i = m.call(o), r, ar = [], e;
231 try {
232 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
233 }
234 catch (error) { e = { error: error }; }
235 finally {
236 try {
237 if (r && !r.done && (m = i["return"])) m.call(i);
238 }
239 finally { if (e) throw e.error; }
240 }
241 return ar;
242 }
243
244 /** @deprecated */
245 function __spread() {
246 for (var ar = [], i = 0; i < arguments.length; i++)
247 ar = ar.concat(__read(arguments[i]));
248 return ar;
249 }
250
251 /** @deprecated */
252 function __spreadArrays() {
253 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
254 for (var r = Array(s), k = 0, i = 0; i < il; i++)
255 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
256 r[k] = a[j];
257 return r;
258 }
259
260 function __spreadArray(to, from, pack) {
261 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
262 if (ar || !(i in from)) {
263 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
264 ar[i] = from[i];
265 }
266 }
267 return to.concat(ar || Array.prototype.slice.call(from));
268 }
269
270 function __await(v) {
271 return this instanceof __await ? (this.v = v, this) : new __await(v);
272 }
273
274 function __asyncGenerator(thisArg, _arguments, generator) {
275 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
276 var g = generator.apply(thisArg, _arguments || []), i, q = [];
277 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
278 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
279 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
280 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
281 function fulfill(value) { resume("next", value); }
282 function reject(value) { resume("throw", value); }
283 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
284 }
285
286 function __asyncDelegator(o) {
287 var i, p;
288 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
289 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
290 }
291
292 function __asyncValues(o) {
293 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
294 var m = o[Symbol.asyncIterator], i;
295 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
296 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
297 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
298 }
299
300 function __makeTemplateObject(cooked, raw) {
301 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
302 return cooked;
303 };
304
305 var __setModuleDefault = Object.create ? (function(o, v) {
306 Object.defineProperty(o, "default", { enumerable: true, value: v });
307 }) : function(o, v) {
308 o["default"] = v;
309 };
310
311 function __importStar(mod) {
312 if (mod && mod.__esModule) return mod;
313 var result = {};
314 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
315 __setModuleDefault(result, mod);
316 return result;
317 }
318
319 function __importDefault(mod) {
320 return (mod && mod.__esModule) ? mod : { default: mod };
321 }
322
323 function __classPrivateFieldGet(receiver, state, kind, f) {
324 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
325 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
326 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
327 }
328
329 function __classPrivateFieldSet(receiver, state, value, kind, f) {
330 if (kind === "m") throw new TypeError("Private method is not writable");
331 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
332 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
333 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
334 }
335
336 function __classPrivateFieldIn(state, receiver) {
337 if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
338 return typeof state === "function" ? receiver === state : state.has(receiver);
339 }
340
341 function __addDisposableResource(env, value, async) {
342 if (value !== null && value !== void 0) {
343 if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
344 var dispose;
345 if (async) {
346 if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
347 dispose = value[Symbol.asyncDispose];
348 }
349 if (dispose === void 0) {
350 if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
351 dispose = value[Symbol.dispose];
352 }
353 if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
354 env.stack.push({ value: value, dispose: dispose, async: async });
355 }
356 else if (async) {
357 env.stack.push({ async: true });
358 }
359 return value;
360 }
361
362 var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
363 var e = new Error(message);
364 return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
365 };
366
367 function __disposeResources(env) {
368 function fail(e) {
369 env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
370 env.hasError = true;
371 }
372 function next() {
373 while (env.stack.length) {
374 var rec = env.stack.pop();
375 try {
376 var result = rec.dispose && rec.dispose.call(rec.value);
377 if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
378 }
379 catch (e) {
380 fail(e);
381 }
382 }
383 if (env.hasError) throw env.error;
384 }
385 return next();
386 }
387
388 /* harmony default export */ const tslib_es6 = ({
389 __extends,
390 __assign,
391 __rest,
392 __decorate,
393 __param,
394 __metadata,
395 __awaiter,
396 __generator,
397 __createBinding,
398 __exportStar,
399 __values,
400 __read,
401 __spread,
402 __spreadArrays,
403 __spreadArray,
404 __await,
405 __asyncGenerator,
406 __asyncDelegator,
407 __asyncValues,
408 __makeTemplateObject,
409 __importStar,
410 __importDefault,
411 __classPrivateFieldGet,
412 __classPrivateFieldSet,
413 __classPrivateFieldIn,
414 __addDisposableResource,
415 __disposeResources,
416 });
417
418 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
419 /**
420 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
421 */
422 var SUPPORTED_LOCALE = {
423 tr: {
424 regexp: /\u0130|\u0049|\u0049\u0307/g,
425 map: {
426 İ: "\u0069",
427 I: "\u0131",
428 İ: "\u0069",
429 },
430 },
431 az: {
432 regexp: /\u0130/g,
433 map: {
434 İ: "\u0069",
435 I: "\u0131",
436 İ: "\u0069",
437 },
438 },
439 lt: {
440 regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
441 map: {
442 I: "\u0069\u0307",
443 J: "\u006A\u0307",
444 Į: "\u012F\u0307",
445 Ì: "\u0069\u0307\u0300",
446 Í: "\u0069\u0307\u0301",
447 Ĩ: "\u0069\u0307\u0303",
448 },
449 },
450 };
451 /**
452 * Localized lower case.
453 */
454 function localeLowerCase(str, locale) {
455 var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
456 if (lang)
457 return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
458 return lowerCase(str);
459 }
460 /**
461 * Lower case as a function.
462 */
463 function lowerCase(str) {
464 return str.toLowerCase();
465 }
466
467 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
468
469 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
470 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
471 // Remove all non-word characters.
472 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
473 /**
474 * Normalize the string into something other libraries can manipulate easier.
475 */
476 function noCase(input, options) {
477 if (options === void 0) { options = {}; }
478 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
479 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
480 var start = 0;
481 var end = result.length;
482 // Trim the delimiter from around the output string.
483 while (result.charAt(start) === "\0")
484 start++;
485 while (result.charAt(end - 1) === "\0")
486 end--;
487 // Transform each token independently.
488 return result.slice(start, end).split("\0").map(transform).join(delimiter);
489 }
490 /**
491 * Replace `re` in the input string with the replacement value.
492 */
493 function replace(input, re, value) {
494 if (re instanceof RegExp)
495 return input.replace(re, value);
496 return re.reduce(function (input, re) { return input.replace(re, value); }, input);
497 }
498
499 ;// CONCATENATED MODULE: ./node_modules/dot-case/dist.es2015/index.js
500
501
502 function dotCase(input, options) {
503 if (options === void 0) { options = {}; }
504 return noCase(input, __assign({ delimiter: "." }, options));
505 }
506
507 ;// CONCATENATED MODULE: ./node_modules/param-case/dist.es2015/index.js
508
509
510 function paramCase(input, options) {
511 if (options === void 0) { options = {}; }
512 return dotCase(input, __assign({ delimiter: "-" }, options));
513 }
514
515 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/constants.js
516 const VARIABLE_REFERENCE_PREFIX = 'var:';
517 const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
518 const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
519
520 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/utils.js
521 /**
522 * External dependencies
523 */
524
525
526 /**
527 * Internal dependencies
528 */
529
530
531
532 /**
533 * Helper util to return a value from a certain path of the object.
534 * Path is specified as an array of properties, like `[ 'x', 'y' ]`.
535 *
536 * @param object Input object.
537 * @param path Path to the object property.
538 * @return Value of the object property at the specified path.
539 */
540 const getStyleValueByPath = (object, path) => {
541 let value = object;
542 path.forEach(fieldName => {
543 value = value?.[fieldName];
544 });
545 return value;
546 };
547
548 /**
549 * Returns a JSON representation of the generated CSS rules.
550 *
551 * @param style Style object.
552 * @param options Options object with settings to adjust how the styles are generated.
553 * @param path An array of strings representing the path to the style value in the style object.
554 * @param ruleKey A CSS property key.
555 *
556 * @return GeneratedCSSRule[] CSS rules.
557 */
558 function generateRule(style, options, path, ruleKey) {
559 const styleValue = getStyleValueByPath(style, path);
560 return styleValue ? [{
561 selector: options?.selector,
562 key: ruleKey,
563 value: getCSSVarFromStyleValue(styleValue)
564 }] : [];
565 }
566
567 /**
568 * Returns a JSON representation of the generated CSS rules taking into account box model properties, top, right, bottom, left.
569 *
570 * @param style Style object.
571 * @param options Options object with settings to adjust how the styles are generated.
572 * @param path An array of strings representing the path to the style value in the style object.
573 * @param ruleKeys An array of CSS property keys and patterns.
574 * @param individualProperties The "sides" or individual properties for which to generate rules.
575 *
576 * @return GeneratedCSSRule[] CSS rules.
577 */
578 function generateBoxRules(style, options, path, ruleKeys, individualProperties = ['top', 'right', 'bottom', 'left']) {
579 const boxStyle = getStyleValueByPath(style, path);
580 if (!boxStyle) {
581 return [];
582 }
583 const rules = [];
584 if (typeof boxStyle === 'string') {
585 rules.push({
586 selector: options?.selector,
587 key: ruleKeys.default,
588 value: boxStyle
589 });
590 } else {
591 const sideRules = individualProperties.reduce((acc, side) => {
592 const value = getCSSVarFromStyleValue(getStyleValueByPath(boxStyle, [side]));
593 if (value) {
594 acc.push({
595 selector: options?.selector,
596 key: ruleKeys?.individual.replace('%s', upperFirst(side)),
597 value
598 });
599 }
600 return acc;
601 }, []);
602 rules.push(...sideRules);
603 }
604 return rules;
605 }
606
607 /**
608 * Returns a CSS var value from incoming style value following the pattern `var:description|context|slug`.
609 *
610 * @param styleValue A raw style value.
611 *
612 * @return string A CSS var value.
613 */
614 function getCSSVarFromStyleValue(styleValue) {
615 if (typeof styleValue === 'string' && styleValue.startsWith(VARIABLE_REFERENCE_PREFIX)) {
616 const variable = styleValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).map(presetVariable => paramCase(presetVariable, {
617 splitRegexp: [/([a-z0-9])([A-Z])/g,
618 // fooBar => foo-bar, 3Bar => 3-bar
619 /([0-9])([a-z])/g,
620 // 3bar => 3-bar
621 /([A-Za-z])([0-9])/g,
622 // Foo3 => foo-3, foo3 => foo-3
623 /([A-Z])([A-Z][a-z])/g // FOOBar => foo-bar
624 ]
625 })).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
626 return `var(--wp--${variable})`;
627 }
628 return styleValue;
629 }
630
631 /**
632 * Capitalizes the first letter in a string.
633 *
634 * @param string The string whose first letter the function will capitalize.
635 *
636 * @return String with the first letter capitalized.
637 */
638 function upperFirst(string) {
639 const [firstLetter, ...rest] = string;
640 return firstLetter.toUpperCase() + rest.join('');
641 }
642
643 /**
644 * Converts an array of strings into a camelCase string.
645 *
646 * @param strings The strings to join into a camelCase string.
647 *
648 * @return camelCase string.
649 */
650 function camelCaseJoin(strings) {
651 const [firstItem, ...rest] = strings;
652 return firstItem.toLowerCase() + rest.map(upperFirst).join('');
653 }
654
655 /**
656 * Safely decodes a URI with `decodeURI`. Returns the URI unmodified if
657 * `decodeURI` throws an error.
658 *
659 * @param {string} uri URI to decode.
660 *
661 * @example
662 * ```js
663 * const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z'
664 * ```
665 *
666 * @return {string} Decoded URI if possible.
667 */
668 function safeDecodeURI(uri) {
669 try {
670 return decodeURI(uri);
671 } catch (uriError) {
672 return uri;
673 }
674 }
675
676 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/border/index.js
677 /**
678 * Internal dependencies
679 */
680
681
682
683 /**
684 * Creates a function for generating CSS rules when the style path is the same as the camelCase CSS property used in React.
685 *
686 * @param path An array of strings representing the path to the style value in the style object.
687 *
688 * @return A function that generates CSS rules.
689 */
690 function createBorderGenerateFunction(path) {
691 return (style, options) => generateRule(style, options, path, camelCaseJoin(path));
692 }
693
694 /**
695 * Creates a function for generating border-{top,bottom,left,right}-{color,style,width} CSS rules.
696 *
697 * @param edge The edge to create CSS rules for.
698 *
699 * @return A function that generates CSS rules.
700 */
701 function createBorderEdgeGenerateFunction(edge) {
702 return (style, options) => {
703 return ['color', 'style', 'width'].flatMap(key => {
704 const path = ['border', edge, key];
705 return createBorderGenerateFunction(path)(style, options);
706 });
707 };
708 }
709 const color = {
710 name: 'color',
711 generate: createBorderGenerateFunction(['border', 'color'])
712 };
713 const radius = {
714 name: 'radius',
715 generate: (style, options) => {
716 return generateBoxRules(style, options, ['border', 'radius'], {
717 default: 'borderRadius',
718 individual: 'border%sRadius'
719 }, ['topLeft', 'topRight', 'bottomLeft', 'bottomRight']);
720 }
721 };
722 const borderStyle = {
723 name: 'style',
724 generate: createBorderGenerateFunction(['border', 'style'])
725 };
726 const width = {
727 name: 'width',
728 generate: createBorderGenerateFunction(['border', 'width'])
729 };
730 const borderTop = {
731 name: 'borderTop',
732 generate: createBorderEdgeGenerateFunction('top')
733 };
734 const borderRight = {
735 name: 'borderRight',
736 generate: createBorderEdgeGenerateFunction('right')
737 };
738 const borderBottom = {
739 name: 'borderBottom',
740 generate: createBorderEdgeGenerateFunction('bottom')
741 };
742 const borderLeft = {
743 name: 'borderLeft',
744 generate: createBorderEdgeGenerateFunction('left')
745 };
746 /* harmony default export */ const border = ([color, borderStyle, width, radius, borderTop, borderRight, borderBottom, borderLeft]);
747
748 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/color/background.js
749 /**
750 * Internal dependencies
751 */
752
753
754 const background = {
755 name: 'background',
756 generate: (style, options) => {
757 return generateRule(style, options, ['color', 'background'], 'backgroundColor');
758 }
759 };
760 /* harmony default export */ const color_background = (background);
761
762 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/color/gradient.js
763 /**
764 * Internal dependencies
765 */
766
767
768 const gradient = {
769 name: 'gradient',
770 generate: (style, options) => {
771 return generateRule(style, options, ['color', 'gradient'], 'background');
772 }
773 };
774 /* harmony default export */ const color_gradient = (gradient);
775
776 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/color/text.js
777 /**
778 * Internal dependencies
779 */
780
781
782 const text_text = {
783 name: 'text',
784 generate: (style, options) => {
785 return generateRule(style, options, ['color', 'text'], 'color');
786 }
787 };
788 /* harmony default export */ const color_text = (text_text);
789
790 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/color/index.js
791 /**
792 * Internal dependencies
793 */
794
795
796
797 /* harmony default export */ const styles_color = ([color_text, color_gradient, color_background]);
798
799 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/dimensions/index.js
800 /**
801 * Internal dependencies
802 */
803
804
805 const minHeight = {
806 name: 'minHeight',
807 generate: (style, options) => {
808 return generateRule(style, options, ['dimensions', 'minHeight'], 'minHeight');
809 }
810 };
811 const aspectRatio = {
812 name: 'aspectRatio',
813 generate: (style, options) => {
814 return generateRule(style, options, ['dimensions', 'aspectRatio'], 'aspectRatio');
815 }
816 };
817 /* harmony default export */ const dimensions = ([minHeight, aspectRatio]);
818
819 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/background/index.js
820 /**
821 * Internal dependencies
822 */
823
824
825 const backgroundImage = {
826 name: 'backgroundImage',
827 generate: (style, options) => {
828 const _backgroundImage = style?.background?.backgroundImage;
829 const _backgroundSize = style?.background?.backgroundSize;
830 const styleRules = [];
831 if (!_backgroundImage) {
832 return styleRules;
833 }
834 if (_backgroundImage?.source === 'file' && _backgroundImage?.url) {
835 styleRules.push({
836 selector: options.selector,
837 key: 'backgroundImage',
838 // Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string.
839 value: `url( '${encodeURI(safeDecodeURI(_backgroundImage.url))}' )`
840 });
841 }
842
843 // If no background size is set, but an image is, default to cover.
844 if (_backgroundSize === undefined) {
845 styleRules.push({
846 selector: options.selector,
847 key: 'backgroundSize',
848 value: 'cover'
849 });
850 }
851 return styleRules;
852 }
853 };
854 const backgroundRepeat = {
855 name: 'backgroundRepeat',
856 generate: (style, options) => {
857 return generateRule(style, options, ['background', 'backgroundRepeat'], 'backgroundRepeat');
858 }
859 };
860 const backgroundSize = {
861 name: 'backgroundSize',
862 generate: (style, options) => {
863 const _backgroundSize = style?.background?.backgroundSize;
864 const _backgroundPosition = style?.background?.backgroundPosition;
865 const styleRules = [];
866 if (_backgroundSize === undefined) {
867 return styleRules;
868 }
869 styleRules.push(...generateRule(style, options, ['background', 'backgroundSize'], 'backgroundSize'));
870
871 // If background size is set to contain, but no position is set, default to center.
872 if (_backgroundSize === 'contain' && _backgroundPosition === undefined) {
873 styleRules.push({
874 selector: options.selector,
875 key: 'backgroundPosition',
876 value: 'center'
877 });
878 }
879 return styleRules;
880 }
881 };
882 /* harmony default export */ const styles_background = ([backgroundImage, backgroundRepeat, backgroundSize]);
883
884 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/shadow/index.js
885 /**
886 * Internal dependencies
887 */
888
889
890 const shadow = {
891 name: 'shadow',
892 generate: (style, options) => {
893 return generateRule(style, options, ['shadow'], 'boxShadow');
894 }
895 };
896 /* harmony default export */ const styles_shadow = ([shadow]);
897
898 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/outline/index.js
899 /**
900 * Internal dependencies
901 */
902
903
904 const outline_color = {
905 name: 'color',
906 generate: (style, options, path = ['outline', 'color'], ruleKey = 'outlineColor') => {
907 return generateRule(style, options, path, ruleKey);
908 }
909 };
910 const offset = {
911 name: 'offset',
912 generate: (style, options, path = ['outline', 'offset'], ruleKey = 'outlineOffset') => {
913 return generateRule(style, options, path, ruleKey);
914 }
915 };
916 const outlineStyle = {
917 name: 'style',
918 generate: (style, options, path = ['outline', 'style'], ruleKey = 'outlineStyle') => {
919 return generateRule(style, options, path, ruleKey);
920 }
921 };
922 const outline_width = {
923 name: 'width',
924 generate: (style, options, path = ['outline', 'width'], ruleKey = 'outlineWidth') => {
925 return generateRule(style, options, path, ruleKey);
926 }
927 };
928 /* harmony default export */ const outline = ([outline_color, outlineStyle, offset, outline_width]);
929
930 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/spacing/padding.js
931 /**
932 * Internal dependencies
933 */
934
935
936 const padding = {
937 name: 'padding',
938 generate: (style, options) => {
939 return generateBoxRules(style, options, ['spacing', 'padding'], {
940 default: 'padding',
941 individual: 'padding%s'
942 });
943 }
944 };
945 /* harmony default export */ const spacing_padding = (padding);
946
947 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/spacing/margin.js
948 /**
949 * Internal dependencies
950 */
951
952
953 const margin = {
954 name: 'margin',
955 generate: (style, options) => {
956 return generateBoxRules(style, options, ['spacing', 'margin'], {
957 default: 'margin',
958 individual: 'margin%s'
959 });
960 }
961 };
962 /* harmony default export */ const spacing_margin = (margin);
963
964 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/spacing/index.js
965 /**
966 * Internal dependencies
967 */
968
969
970 /* harmony default export */ const spacing = ([spacing_margin, spacing_padding]);
971
972 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/typography/index.js
973 /**
974 * Internal dependencies
975 */
976
977
978 const fontSize = {
979 name: 'fontSize',
980 generate: (style, options) => {
981 return generateRule(style, options, ['typography', 'fontSize'], 'fontSize');
982 }
983 };
984 const fontStyle = {
985 name: 'fontStyle',
986 generate: (style, options) => {
987 return generateRule(style, options, ['typography', 'fontStyle'], 'fontStyle');
988 }
989 };
990 const fontWeight = {
991 name: 'fontWeight',
992 generate: (style, options) => {
993 return generateRule(style, options, ['typography', 'fontWeight'], 'fontWeight');
994 }
995 };
996 const fontFamily = {
997 name: 'fontFamily',
998 generate: (style, options) => {
999 return generateRule(style, options, ['typography', 'fontFamily'], 'fontFamily');
1000 }
1001 };
1002 const letterSpacing = {
1003 name: 'letterSpacing',
1004 generate: (style, options) => {
1005 return generateRule(style, options, ['typography', 'letterSpacing'], 'letterSpacing');
1006 }
1007 };
1008 const lineHeight = {
1009 name: 'lineHeight',
1010 generate: (style, options) => {
1011 return generateRule(style, options, ['typography', 'lineHeight'], 'lineHeight');
1012 }
1013 };
1014 const textColumns = {
1015 name: 'textColumns',
1016 generate: (style, options) => {
1017 return generateRule(style, options, ['typography', 'textColumns'], 'columnCount');
1018 }
1019 };
1020 const textDecoration = {
1021 name: 'textDecoration',
1022 generate: (style, options) => {
1023 return generateRule(style, options, ['typography', 'textDecoration'], 'textDecoration');
1024 }
1025 };
1026 const textTransform = {
1027 name: 'textTransform',
1028 generate: (style, options) => {
1029 return generateRule(style, options, ['typography', 'textTransform'], 'textTransform');
1030 }
1031 };
1032 const writingMode = {
1033 name: 'writingMode',
1034 generate: (style, options) => {
1035 return generateRule(style, options, ['typography', 'writingMode'], 'writingMode');
1036 }
1037 };
1038 /* harmony default export */ const typography = ([fontFamily, fontSize, fontStyle, fontWeight, letterSpacing, lineHeight, textColumns, textDecoration, textTransform, writingMode]);
1039
1040 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/styles/index.js
1041 /**
1042 * Internal dependencies
1043 */
1044
1045
1046
1047
1048
1049
1050
1051
1052 const styleDefinitions = [...border, ...styles_color, ...dimensions, ...outline, ...spacing, ...typography, ...styles_shadow, ...styles_background];
1053
1054 ;// CONCATENATED MODULE: ./packages/style-engine/build-module/index.js
1055 /**
1056 * External dependencies
1057 */
1058
1059
1060 /**
1061 * Internal dependencies
1062 */
1063
1064
1065
1066 /**
1067 * Generates a stylesheet for a given style object and selector.
1068 *
1069 * @since 6.1.0 Introduced in WordPress core.
1070 *
1071 * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
1072 * @param options Options object with settings to adjust how the styles are generated.
1073 *
1074 * @return A generated stylesheet or inline style declarations.
1075 */
1076 function compileCSS(style, options = {}) {
1077 const rules = getCSSRules(style, options);
1078
1079 // If no selector is provided, treat generated rules as inline styles to be returned as a single string.
1080 if (!options?.selector) {
1081 const inlineRules = [];
1082 rules.forEach(rule => {
1083 inlineRules.push(`${paramCase(rule.key)}: ${rule.value};`);
1084 });
1085 return inlineRules.join(' ');
1086 }
1087 const groupedRules = rules.reduce((acc, rule) => {
1088 const {
1089 selector
1090 } = rule;
1091 if (!selector) {
1092 return acc;
1093 }
1094 if (!acc[selector]) {
1095 acc[selector] = [];
1096 }
1097 acc[selector].push(rule);
1098 return acc;
1099 }, {});
1100 const selectorRules = Object.keys(groupedRules).reduce((acc, subSelector) => {
1101 acc.push(`${subSelector} { ${groupedRules[subSelector].map(rule => `${paramCase(rule.key)}: ${rule.value};`).join(' ')} }`);
1102 return acc;
1103 }, []);
1104 return selectorRules.join('\n');
1105 }
1106
1107 /**
1108 * Returns a JSON representation of the generated CSS rules.
1109 *
1110 * @since 6.1.0 Introduced in WordPress core.
1111 *
1112 * @param style Style object, for example, the value of a block's attributes.style object or the top level styles in theme.json
1113 * @param options Options object with settings to adjust how the styles are generated.
1114 *
1115 * @return A collection of objects containing the selector, if any, the CSS property key (camelcase) and parsed CSS value.
1116 */
1117 function getCSSRules(style, options = {}) {
1118 const rules = [];
1119 styleDefinitions.forEach(definition => {
1120 if (typeof definition.generate === 'function') {
1121 rules.push(...definition.generate(style, options));
1122 }
1123 });
1124 return rules;
1125 }
1126
1127 (window.wp = window.wp || {}).styleEngine = __webpack_exports__;
1128 /******/ })()
1129 ;