source: trip-planner-front/node_modules/postcss-attribute-case-insensitive/dist/index.js@ 188ee53

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

initial commit

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _postcss = _interopRequireDefault(require("postcss"));
9
10var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14function nodeIsInsensitiveAttribute(node) {
15 return node.type === 'attribute' && node.insensitive;
16}
17
18function selectorHasInsensitiveAttribute(selector) {
19 return selector.some(nodeIsInsensitiveAttribute);
20}
21
22function transformString(strings, charPos, string) {
23 var char = string.charAt(charPos);
24
25 if (char === '') {
26 return strings;
27 }
28
29 var newStrings = strings.map(function (x) {
30 return x + char;
31 });
32 var upperChar = char.toLocaleUpperCase();
33
34 if (upperChar !== char) {
35 newStrings = newStrings.concat(strings.map(function (x) {
36 return x + upperChar;
37 }));
38 }
39
40 return transformString(newStrings, charPos + 1, string);
41}
42
43function createSensitiveAtributes(attribute) {
44 var attributes = transformString([''], 0, attribute.value);
45 return attributes.map(function (x) {
46 var newAttribute = attribute.clone({
47 spaces: {
48 after: attribute.spaces.after,
49 before: attribute.spaces.before
50 },
51 insensitive: false
52 });
53 newAttribute.setValue(x);
54 return newAttribute;
55 });
56}
57
58function createNewSelectors(selector) {
59 var newSelectors = [_postcssSelectorParser.default.selector()];
60 selector.walk(function (node) {
61 if (!nodeIsInsensitiveAttribute(node)) {
62 newSelectors.forEach(function (newSelector) {
63 newSelector.append(node.clone());
64 });
65 return;
66 }
67
68 var sensitiveAttributes = createSensitiveAtributes(node);
69 var newSelectorsWithSensitiveAttributes = [];
70 sensitiveAttributes.forEach(function (newNode) {
71 newSelectors.forEach(function (newSelector) {
72 var newSelectorWithNewNode = newSelector.clone();
73 newSelectorWithNewNode.append(newNode);
74 newSelectorsWithSensitiveAttributes.push(newSelectorWithNewNode);
75 });
76 });
77 newSelectors = newSelectorsWithSensitiveAttributes;
78 });
79 return newSelectors;
80}
81
82function transform(selectors) {
83 var newSelectors = [];
84 selectors.each(function (selector) {
85 if (selectorHasInsensitiveAttribute(selector)) {
86 newSelectors = newSelectors.concat(createNewSelectors(selector));
87 selector.remove();
88 }
89 });
90
91 if (newSelectors.length) {
92 newSelectors.forEach(function (newSelector) {
93 return selectors.append(newSelector);
94 });
95 }
96}
97
98var caseInsensitiveRegExp = /i(\s*\/\*[\W\w]*?\*\/)*\s*\]/;
99
100var _default = _postcss.default.plugin('postcss-attribute-case-insensitive', function () {
101 return function (css) {
102 css.walkRules(caseInsensitiveRegExp, function (rule) {
103 rule.selector = (0, _postcssSelectorParser.default)(transform).processSync(rule.selector);
104 });
105 };
106});
107
108exports.default = _default;
Note: See TracBrowser for help on using the repository browser.