1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _SimpleMap = require('./SimpleMap');
|
8 |
|
9 | var _SimpleMap2 = _interopRequireDefault(_SimpleMap);
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12 |
|
13 | var CustomMap = typeof Map === 'undefined' ? _SimpleMap2.default : Map;
|
14 |
|
15 | var stylesIndex = new CustomMap();
|
16 |
|
17 | exports.default = function (styles, styleNames, handleNotFoundStyleName) {
|
18 | var appendClassName = void 0;
|
19 | var stylesIndexMap = void 0;
|
20 |
|
21 | stylesIndexMap = stylesIndex.get(styles);
|
22 |
|
23 | if (stylesIndexMap) {
|
24 | var styleNameIndex = stylesIndexMap.get(styleNames);
|
25 |
|
26 | if (styleNameIndex) {
|
27 | return styleNameIndex;
|
28 | }
|
29 | } else {
|
30 | stylesIndexMap = new CustomMap();
|
31 | stylesIndex.set(styles, new CustomMap());
|
32 | }
|
33 |
|
34 | appendClassName = '';
|
35 |
|
36 | for (var styleName in styleNames) {
|
37 | if (styleNames.hasOwnProperty(styleName)) {
|
38 | var className = styles[styleNames[styleName]];
|
39 |
|
40 | if (className) {
|
41 | appendClassName += ' ' + className;
|
42 | } else {
|
43 | if (handleNotFoundStyleName === 'throw') {
|
44 | throw new Error('"' + styleNames[styleName] + '" CSS module is undefined.');
|
45 | }
|
46 | if (handleNotFoundStyleName === 'log') {
|
47 |
|
48 | console.warn('"' + styleNames[styleName] + '" CSS module is undefined.');
|
49 | }
|
50 | }
|
51 | }
|
52 | }
|
53 |
|
54 | appendClassName = appendClassName.trim();
|
55 |
|
56 | stylesIndexMap.set(styleNames, appendClassName);
|
57 |
|
58 | return appendClassName;
|
59 | };
|
60 |
|
61 | module.exports = exports['default']; |
\ | No newline at end of file |