source: trip-planner-front/node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1"use strict";
2
3var stylesInDom = [];
4
5function getIndexByIdentifier(identifier) {
6 var result = -1;
7
8 for (var i = 0; i < stylesInDom.length; i++) {
9 if (stylesInDom[i].identifier === identifier) {
10 result = i;
11 break;
12 }
13 }
14
15 return result;
16}
17
18function modulesToDom(list, options) {
19 var idCountMap = {};
20 var identifiers = [];
21
22 for (var i = 0; i < list.length; i++) {
23 var item = list[i];
24 var id = options.base ? item[0] + options.base : item[0];
25 var count = idCountMap[id] || 0;
26 var identifier = "".concat(id, " ").concat(count);
27 idCountMap[id] = count + 1;
28 var index = getIndexByIdentifier(identifier);
29 var obj = {
30 css: item[1],
31 media: item[2],
32 sourceMap: item[3]
33 };
34
35 if (index !== -1) {
36 stylesInDom[index].references++;
37 stylesInDom[index].updater(obj);
38 } else {
39 stylesInDom.push({
40 identifier: identifier,
41 updater: addStyle(obj, options),
42 references: 1
43 });
44 }
45
46 identifiers.push(identifier);
47 }
48
49 return identifiers;
50}
51
52function addStyle(obj, options) {
53 var api = options.domAPI(options);
54 api.update(obj);
55 return function updateStyle(newObj) {
56 if (newObj) {
57 if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) {
58 return;
59 }
60
61 api.update(obj = newObj);
62 } else {
63 api.remove();
64 }
65 };
66}
67
68module.exports = function (list, options) {
69 options = options || {};
70 list = list || [];
71 var lastIdentifiers = modulesToDom(list, options);
72 return function update(newList) {
73 newList = newList || [];
74
75 for (var i = 0; i < lastIdentifiers.length; i++) {
76 var identifier = lastIdentifiers[i];
77 var index = getIndexByIdentifier(identifier);
78 stylesInDom[index].references--;
79 }
80
81 var newLastIdentifiers = modulesToDom(newList, options);
82
83 for (var _i = 0; _i < lastIdentifiers.length; _i++) {
84 var _identifier = lastIdentifiers[_i];
85
86 var _index = getIndexByIdentifier(_identifier);
87
88 if (stylesInDom[_index].references === 0) {
89 stylesInDom[_index].updater();
90
91 stylesInDom.splice(_index, 1);
92 }
93 }
94
95 lastIdentifiers = newLastIdentifiers;
96 };
97};
Note: See TracBrowser for help on using the repository browser.