UNPKG

3.15 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var concatStyleSets_1 = require("./concatStyleSets");
4var extractStyleParts_1 = require("./extractStyleParts");
5var StyleOptionsState_1 = require("./StyleOptionsState");
6var styleToClassName_1 = require("./styleToClassName");
7/**
8 * Takes in one or more style set objects, each consisting of a set of areas,
9 * each which will produce a class name. Using this is analogous to calling
10 * `mergeStyles` for each property in the object, but ensures we maintain the
11 * set ordering when multiple style sets are merged.
12 *
13 * @param styleSets - One or more style sets to be merged.
14 */
15function mergeStyleSets() {
16 var styleSets = [];
17 for (var _i = 0; _i < arguments.length; _i++) {
18 styleSets[_i] = arguments[_i];
19 }
20 return mergeCssSets(styleSets, StyleOptionsState_1.getStyleOptions());
21}
22exports.mergeStyleSets = mergeStyleSets;
23/**
24 * Takes in one or more style set objects, each1consisting of a set of areas,
25 * each which will produce a class name. Using this is analogous to calling
26 * `mergeCss` for each property in the object, but ensures the
27 * set ordering when multiple style sets are merged.
28 *
29 * @param styleSets - One or more style sets to be merged.
30 * @param options - (optional) Options to use when creating rules.
31 */
32function mergeCssSets(styleSets, options) {
33 var _a, _b;
34 var classNameSet = { subComponentStyles: {} };
35 var styleSet = styleSets[0];
36 if (!styleSet && styleSets.length <= 1) {
37 return { subComponentStyles: {} };
38 }
39 var concatenatedStyleSet = concatStyleSets_1.concatStyleSets.apply(void 0, styleSets);
40 var registrations = [];
41 for (var styleSetArea in concatenatedStyleSet) {
42 if (concatenatedStyleSet.hasOwnProperty(styleSetArea)) {
43 if (styleSetArea === 'subComponentStyles') {
44 classNameSet.subComponentStyles = concatenatedStyleSet.subComponentStyles || {};
45 continue;
46 }
47 var styles = concatenatedStyleSet[styleSetArea];
48 var _c = extractStyleParts_1.extractStyleParts(styles), classes = _c.classes, objects = _c.objects;
49 if ((_a = objects) === null || _a === void 0 ? void 0 : _a.length) {
50 var registration = styleToClassName_1.styleToRegistration(options || {}, { displayName: styleSetArea }, objects);
51 if (registration) {
52 registrations.push(registration);
53 classNameSet[styleSetArea] = classes.concat([registration.className]).join(' ');
54 }
55 }
56 else {
57 classNameSet[styleSetArea] = classes.join(' ');
58 }
59 }
60 }
61 for (var _i = 0, registrations_1 = registrations; _i < registrations_1.length; _i++) {
62 var registration = registrations_1[_i];
63 if (registration) {
64 styleToClassName_1.applyRegistration(registration, (_b = options) === null || _b === void 0 ? void 0 : _b.specificityMultiplier);
65 }
66 }
67 return classNameSet;
68}
69exports.mergeCssSets = mergeCssSets;
70//# sourceMappingURL=mergeStyleSets.js.map
\No newline at end of file