.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / postcss-selector-parser / dist / selectors / attribute.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6
7 var _namespace = require('./namespace');
8
9 var _namespace2 = _interopRequireDefault(_namespace);
10
11 var _types = require('./types');
12
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
17 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
18
19 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
20
21 var Attribute = function (_Namespace) {
22     _inherits(Attribute, _Namespace);
23
24     function Attribute() {
25         var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
27         _classCallCheck(this, Attribute);
28
29         var _this = _possibleConstructorReturn(this, _Namespace.call(this, opts));
30
31         _this.type = _types.ATTRIBUTE;
32         _this.raws = _this.raws || {};
33         _this._constructed = true;
34         return _this;
35     }
36
37     Attribute.prototype._spacesFor = function _spacesFor(name) {
38         var attrSpaces = { before: '', after: '' };
39         var spaces = this.spaces[name] || {};
40         var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
41         return Object.assign(attrSpaces, spaces, rawSpaces);
42     };
43
44     Attribute.prototype._valueFor = function _valueFor(name) {
45         return this.raws[name] || this[name];
46     };
47
48     Attribute.prototype._stringFor = function _stringFor(name) {
49         var spaceName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : name;
50         var concat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultAttrConcat;
51
52         var attrSpaces = this._spacesFor(spaceName);
53         return concat(this._valueFor(name), attrSpaces);
54     };
55
56     /**
57      * returns the offset of the attribute part specified relative to the
58      * start of the node of the output string.
59      *
60      * * "ns" - alias for "namespace"
61      * * "namespace" - the namespace if it exists.
62      * * "attribute" - the attribute name
63      * * "attributeNS" - the start of the attribute or its namespace
64      * * "operator" - the match operator of the attribute
65      * * "value" - The value (string or identifier)
66      * * "insensitive" - the case insensitivity flag;
67      * @param part One of the possible values inside an attribute.
68      * @returns -1 if the name is invalid or the value doesn't exist in this attribute.
69      */
70
71
72     Attribute.prototype.offsetOf = function offsetOf(name) {
73         var count = 1;
74         var attributeSpaces = this._spacesFor("attribute");
75         count += attributeSpaces.before.length;
76         if (name === "namespace" || name === "ns") {
77             return this.namespace ? count : -1;
78         }
79         if (name === "attributeNS") {
80             return count;
81         }
82
83         count += this.namespaceString.length;
84         if (this.namespace) {
85             count += 1;
86         }
87         if (name === "attribute") {
88             return count;
89         }
90
91         count += this._valueFor("attribute").length;
92         count += attributeSpaces.after.length;
93         var operatorSpaces = this._spacesFor("operator");
94         count += operatorSpaces.before.length;
95         var operator = this._valueFor("operator");
96         if (name === "operator") {
97             return operator ? count : -1;
98         }
99
100         count += operator.length;
101         count += operatorSpaces.after.length;
102         var valueSpaces = this._spacesFor("value");
103         count += valueSpaces.before.length;
104         var value = this._valueFor("value");
105         if (name === "value") {
106             return value ? count : -1;
107         }
108
109         count += value.length;
110         count += valueSpaces.after.length;
111         var insensitiveSpaces = this._spacesFor("insensitive");
112         count += insensitiveSpaces.before.length;
113         if (name === "insensitive") {
114             return this.insensitive ? count : -1;
115         }
116         return -1;
117     };
118
119     Attribute.prototype.toString = function toString() {
120         var _this2 = this;
121
122         var selector = [this.spaces.before, '['];
123
124         selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
125
126         if (this.operator && this.value) {
127             selector.push(this._stringFor('operator'));
128             selector.push(this._stringFor('value'));
129             selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
130                 if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
131                     attrSpaces.before = " ";
132                 }
133                 return defaultAttrConcat(attrValue, attrSpaces);
134             }));
135         }
136
137         selector.push(']');
138         selector.push(this.spaces.after);
139         return selector.join('');
140     };
141
142     _createClass(Attribute, [{
143         key: 'qualifiedAttribute',
144         get: function get() {
145             return this.qualifiedName(this.raws.attribute || this.attribute);
146         }
147     }, {
148         key: 'insensitiveFlag',
149         get: function get() {
150             return this.insensitive ? 'i' : '';
151         }
152     }, {
153         key: 'value',
154         get: function get() {
155             return this._value;
156         },
157         set: function set(v) {
158             this._value = v;
159             if (this._constructed) {
160                 delete this.raws.value;
161             }
162         }
163     }, {
164         key: 'namespace',
165         get: function get() {
166             return this._namespace;
167         },
168         set: function set(v) {
169             this._namespace = v;
170             if (this._constructed) {
171                 delete this.raws.namespace;
172             }
173         }
174     }, {
175         key: 'attribute',
176         get: function get() {
177             return this._attribute;
178         },
179         set: function set(v) {
180             this._attribute = v;
181             if (this._constructed) {
182                 delete this.raws.attibute;
183             }
184         }
185     }]);
186
187     return Attribute;
188 }(_namespace2.default);
189
190 exports.default = Attribute;
191
192
193 function defaultAttrConcat(attrValue, attrSpaces) {
194     return '' + attrSpaces.before + attrValue + attrSpaces.after;
195 }
196 module.exports = exports['default'];