source: frontend/node_modules/stylehacks/src/plugins/leadingStar.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2const BasePlugin = require('../plugin');
3const { IE_5_5, IE_6, IE_7 } = require('../dictionary/browsers');
4const { PROPERTY } = require('../dictionary/identifiers');
5const { ATRULE, DECL } = require('../dictionary/postcss');
6
7const hacks = '!_$_&_*_)_=_%_+_,_._/_`_]_#_~_?_:_|'.split('_');
8
9module.exports = class LeadingStar extends BasePlugin {
10 /** @param {import('postcss').Result=} result */
11 constructor(result) {
12 super([IE_5_5, IE_6, IE_7], [ATRULE, DECL], result);
13 }
14
15 /**
16 * @param {import('postcss').Declaration | import('postcss').AtRule} node
17 * @return {void}
18 */
19 detect(node) {
20 if (node.type === DECL) {
21 // some values are not picked up by before, so ensure they are
22 // at the beginning of the value
23 hacks.forEach((hack) => {
24 if (!node.prop.indexOf(hack)) {
25 this.push(node, {
26 identifier: PROPERTY,
27 hack: node.prop,
28 });
29 }
30 });
31 const { before } = node.raws;
32 if (!before) {
33 return;
34 }
35 hacks.forEach((hack) => {
36 if (before.includes(hack)) {
37 this.push(node, {
38 identifier: PROPERTY,
39 hack: `${before.trim()}${node.prop}`,
40 });
41 }
42 });
43 } else {
44 // test for the @property: value; hack
45 const { name } = node;
46 const len = name.length - 1;
47 if (name.lastIndexOf(':') === len) {
48 this.push(node, {
49 identifier: PROPERTY,
50 hack: `@${name.substr(0, len)}`,
51 });
52 }
53 }
54 }
55};
Note: See TracBrowser for help on using the repository browser.