source: trip-planner-front/node_modules/postcss-selector-parser/dist/selectors/node.js@ 59329aa

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

initial commit

  • Property mode set to 100644
File size: 6.5 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5
6var _util = require("../util");
7
8function _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); } }
9
10function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
11
12var cloneNode = function cloneNode(obj, parent) {
13 if (typeof obj !== 'object' || obj === null) {
14 return obj;
15 }
16
17 var cloned = new obj.constructor();
18
19 for (var i in obj) {
20 if (!obj.hasOwnProperty(i)) {
21 continue;
22 }
23
24 var value = obj[i];
25 var type = typeof value;
26
27 if (i === 'parent' && type === 'object') {
28 if (parent) {
29 cloned[i] = parent;
30 }
31 } else if (value instanceof Array) {
32 cloned[i] = value.map(function (j) {
33 return cloneNode(j, cloned);
34 });
35 } else {
36 cloned[i] = cloneNode(value, cloned);
37 }
38 }
39
40 return cloned;
41};
42
43var Node = /*#__PURE__*/function () {
44 function Node(opts) {
45 if (opts === void 0) {
46 opts = {};
47 }
48
49 Object.assign(this, opts);
50 this.spaces = this.spaces || {};
51 this.spaces.before = this.spaces.before || '';
52 this.spaces.after = this.spaces.after || '';
53 }
54
55 var _proto = Node.prototype;
56
57 _proto.remove = function remove() {
58 if (this.parent) {
59 this.parent.removeChild(this);
60 }
61
62 this.parent = undefined;
63 return this;
64 };
65
66 _proto.replaceWith = function replaceWith() {
67 if (this.parent) {
68 for (var index in arguments) {
69 this.parent.insertBefore(this, arguments[index]);
70 }
71
72 this.remove();
73 }
74
75 return this;
76 };
77
78 _proto.next = function next() {
79 return this.parent.at(this.parent.index(this) + 1);
80 };
81
82 _proto.prev = function prev() {
83 return this.parent.at(this.parent.index(this) - 1);
84 };
85
86 _proto.clone = function clone(overrides) {
87 if (overrides === void 0) {
88 overrides = {};
89 }
90
91 var cloned = cloneNode(this);
92
93 for (var name in overrides) {
94 cloned[name] = overrides[name];
95 }
96
97 return cloned;
98 }
99 /**
100 * Some non-standard syntax doesn't follow normal escaping rules for css.
101 * This allows non standard syntax to be appended to an existing property
102 * by specifying the escaped value. By specifying the escaped value,
103 * illegal characters are allowed to be directly inserted into css output.
104 * @param {string} name the property to set
105 * @param {any} value the unescaped value of the property
106 * @param {string} valueEscaped optional. the escaped value of the property.
107 */
108 ;
109
110 _proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
111 if (!this.raws) {
112 this.raws = {};
113 }
114
115 var originalValue = this[name];
116 var originalEscaped = this.raws[name];
117 this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
118
119 if (originalEscaped || valueEscaped !== value) {
120 this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
121 } else {
122 delete this.raws[name]; // delete any escaped value that was created by the setter.
123 }
124 }
125 /**
126 * Some non-standard syntax doesn't follow normal escaping rules for css.
127 * This allows the escaped value to be specified directly, allowing illegal
128 * characters to be directly inserted into css output.
129 * @param {string} name the property to set
130 * @param {any} value the unescaped value of the property
131 * @param {string} valueEscaped the escaped value of the property.
132 */
133 ;
134
135 _proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
136 if (!this.raws) {
137 this.raws = {};
138 }
139
140 this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
141
142 this.raws[name] = valueEscaped;
143 }
144 /**
145 * When you want a value to passed through to CSS directly. This method
146 * deletes the corresponding raw value causing the stringifier to fallback
147 * to the unescaped value.
148 * @param {string} name the property to set.
149 * @param {any} value The value that is both escaped and unescaped.
150 */
151 ;
152
153 _proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
154 this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
155
156 if (this.raws) {
157 delete this.raws[name];
158 }
159 }
160 /**
161 *
162 * @param {number} line The number (starting with 1)
163 * @param {number} column The column number (starting with 1)
164 */
165 ;
166
167 _proto.isAtPosition = function isAtPosition(line, column) {
168 if (this.source && this.source.start && this.source.end) {
169 if (this.source.start.line > line) {
170 return false;
171 }
172
173 if (this.source.end.line < line) {
174 return false;
175 }
176
177 if (this.source.start.line === line && this.source.start.column > column) {
178 return false;
179 }
180
181 if (this.source.end.line === line && this.source.end.column < column) {
182 return false;
183 }
184
185 return true;
186 }
187
188 return undefined;
189 };
190
191 _proto.stringifyProperty = function stringifyProperty(name) {
192 return this.raws && this.raws[name] || this[name];
193 };
194
195 _proto.valueToString = function valueToString() {
196 return String(this.stringifyProperty("value"));
197 };
198
199 _proto.toString = function toString() {
200 return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
201 };
202
203 _createClass(Node, [{
204 key: "rawSpaceBefore",
205 get: function get() {
206 var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
207
208 if (rawSpace === undefined) {
209 rawSpace = this.spaces && this.spaces.before;
210 }
211
212 return rawSpace || "";
213 },
214 set: function set(raw) {
215 (0, _util.ensureObject)(this, "raws", "spaces");
216 this.raws.spaces.before = raw;
217 }
218 }, {
219 key: "rawSpaceAfter",
220 get: function get() {
221 var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
222
223 if (rawSpace === undefined) {
224 rawSpace = this.spaces.after;
225 }
226
227 return rawSpace || "";
228 },
229 set: function set(raw) {
230 (0, _util.ensureObject)(this, "raws", "spaces");
231 this.raws.spaces.after = raw;
232 }
233 }]);
234
235 return Node;
236}();
237
238exports["default"] = Node;
239module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.