selparsecss-selector 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +874 -0
- package/CHANGELOG.md +573 -0
- package/LICENSE-MIT +22 -0
- package/README.md +87 -0
- package/dist/index.js +45 -0
- package/dist/parser.js +1116 -0
- package/dist/processor.js +153 -0
- package/dist/selectors/attribute.js +440 -0
- package/dist/selectors/className.js +59 -0
- package/dist/selectors/combinator.js +33 -0
- package/dist/selectors/comment.js +33 -0
- package/dist/selectors/constructors.js +43 -0
- package/dist/selectors/container.js +433 -0
- package/dist/selectors/fragment.js +13 -0
- package/dist/selectors/guards.js +61 -0
- package/dist/selectors/id.js +36 -0
- package/dist/selectors/index.js +20 -0
- package/dist/selectors/namespace.js +96 -0
- package/dist/selectors/nesting.js +34 -0
- package/dist/selectors/node.js +195 -0
- package/dist/selectors/pseudo.js +45 -0
- package/dist/selectors/root.js +56 -0
- package/dist/selectors/selector.js +33 -0
- package/dist/selectors/string.js +33 -0
- package/dist/selectors/tag.js +33 -0
- package/dist/selectors/types.js +16 -0
- package/dist/selectors/universal.js +34 -0
- package/dist/selectors/wrapper.js +14 -0
- package/dist/sortAscending.js +7 -0
- package/dist/tokenTypes.js +37 -0
- package/dist/tokenize.js +301 -0
- package/dist/util/ensureObject.js +17 -0
- package/dist/util/getProp.js +18 -0
- package/dist/util/index.js +18 -0
- package/dist/util/maxNestingDepth.js +25 -0
- package/dist/util/propAssemble.js +5 -0
- package/dist/util/propBind.js +9 -0
- package/dist/util/propCache.js +9 -0
- package/dist/util/propPaths.js +8 -0
- package/dist/util/propSync.js +11 -0
- package/dist/util/stripComments.js +20 -0
- package/dist/util/unesc.js +71 -0
- package/dist/util/webpack.min.js +1 -0
- package/package.json +62 -0
- package/selparsecss-selector.d.ts +570 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var node_1 = __importDefault(require("./node"));
|
|
22
|
+
var types_1 = require("./types");
|
|
23
|
+
var Comment = /** @class */ (function (_super) {
|
|
24
|
+
__extends(Comment, _super);
|
|
25
|
+
function Comment(opts) {
|
|
26
|
+
var _this = _super.call(this, opts) || this;
|
|
27
|
+
_this.type = types_1.COMMENT;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
return Comment;
|
|
31
|
+
}(node_1.default));
|
|
32
|
+
exports.default = Comment;
|
|
33
|
+
//# sourceMappingURL=comment.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.universal = exports.tag = exports.string = exports.selector = exports.root = exports.pseudo = exports.nesting = exports.id = exports.comment = exports.combinator = exports.className = exports.attribute = void 0;
|
|
7
|
+
var attribute_1 = __importDefault(require("./attribute"));
|
|
8
|
+
var className_1 = __importDefault(require("./className"));
|
|
9
|
+
var combinator_1 = __importDefault(require("./combinator"));
|
|
10
|
+
var comment_1 = __importDefault(require("./comment"));
|
|
11
|
+
var id_1 = __importDefault(require("./id"));
|
|
12
|
+
var nesting_1 = __importDefault(require("./nesting"));
|
|
13
|
+
var pseudo_1 = __importDefault(require("./pseudo"));
|
|
14
|
+
var root_1 = __importDefault(require("./root"));
|
|
15
|
+
var selector_1 = __importDefault(require("./selector"));
|
|
16
|
+
var string_1 = __importDefault(require("./string"));
|
|
17
|
+
var tag_1 = __importDefault(require("./tag"));
|
|
18
|
+
var universal_1 = __importDefault(require("./universal"));
|
|
19
|
+
var attribute = function (opts) { return new attribute_1.default(opts); };
|
|
20
|
+
exports.attribute = attribute;
|
|
21
|
+
var className = function (opts) { return new className_1.default(opts); };
|
|
22
|
+
exports.className = className;
|
|
23
|
+
var combinator = function (opts) { return new combinator_1.default(opts); };
|
|
24
|
+
exports.combinator = combinator;
|
|
25
|
+
var comment = function (opts) { return new comment_1.default(opts); };
|
|
26
|
+
exports.comment = comment;
|
|
27
|
+
var id = function (opts) { return new id_1.default(opts); };
|
|
28
|
+
exports.id = id;
|
|
29
|
+
var nesting = function (opts) { return new nesting_1.default(opts); };
|
|
30
|
+
exports.nesting = nesting;
|
|
31
|
+
var pseudo = function (opts) { return new pseudo_1.default(opts); };
|
|
32
|
+
exports.pseudo = pseudo;
|
|
33
|
+
var root = function (opts) { return new root_1.default(opts); };
|
|
34
|
+
exports.root = root;
|
|
35
|
+
var selector = function (opts) { return new selector_1.default(opts); };
|
|
36
|
+
exports.selector = selector;
|
|
37
|
+
var string = function (opts) { return new string_1.default(opts); };
|
|
38
|
+
exports.string = string;
|
|
39
|
+
var tag = function (opts) { return new tag_1.default(opts); };
|
|
40
|
+
exports.tag = tag;
|
|
41
|
+
var universal = function (opts) { return new universal_1.default(opts); };
|
|
42
|
+
exports.universal = universal;
|
|
43
|
+
//# sourceMappingURL=constructors.js.map
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __values = (this && this.__values) || function(o) {
|
|
51
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
52
|
+
if (m) return m.call(o);
|
|
53
|
+
if (o && typeof o.length === "number") return {
|
|
54
|
+
next: function () {
|
|
55
|
+
if (o && i >= o.length) o = void 0;
|
|
56
|
+
return { value: o && o[i++], done: !o };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
60
|
+
};
|
|
61
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
62
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
63
|
+
if (!m) return o;
|
|
64
|
+
var i = m.call(o), r, ar = [], e;
|
|
65
|
+
try {
|
|
66
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
67
|
+
}
|
|
68
|
+
catch (error) { e = { error: error }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e) throw e.error; }
|
|
74
|
+
}
|
|
75
|
+
return ar;
|
|
76
|
+
};
|
|
77
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
78
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
79
|
+
if (ar || !(i in from)) {
|
|
80
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
81
|
+
ar[i] = from[i];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
|
+
};
|
|
86
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
+
};
|
|
89
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
+
var util_1 = require("../util");
|
|
91
|
+
var node_1 = __importDefault(require("./node"));
|
|
92
|
+
var types = __importStar(require("./types"));
|
|
93
|
+
var Container = /** @class */ (function (_super) {
|
|
94
|
+
__extends(Container, _super);
|
|
95
|
+
function Container(opts) {
|
|
96
|
+
var _this = _super.call(this, opts) || this;
|
|
97
|
+
if (!_this.nodes) {
|
|
98
|
+
_this.nodes = [];
|
|
99
|
+
}
|
|
100
|
+
return _this;
|
|
101
|
+
}
|
|
102
|
+
Container.prototype.append = function (selector) {
|
|
103
|
+
selector.parent = this;
|
|
104
|
+
this.nodes.push(selector);
|
|
105
|
+
return this;
|
|
106
|
+
};
|
|
107
|
+
Container.prototype.prepend = function (selector) {
|
|
108
|
+
selector.parent = this;
|
|
109
|
+
this.nodes.unshift(selector);
|
|
110
|
+
for (var id in this.indexes) {
|
|
111
|
+
this.indexes[id]++;
|
|
112
|
+
}
|
|
113
|
+
return this;
|
|
114
|
+
};
|
|
115
|
+
Container.prototype.at = function (index) {
|
|
116
|
+
return this.nodes[index];
|
|
117
|
+
};
|
|
118
|
+
Container.prototype.index = function (child) {
|
|
119
|
+
if (typeof child === "number") {
|
|
120
|
+
return child;
|
|
121
|
+
}
|
|
122
|
+
return this.nodes.indexOf(child);
|
|
123
|
+
};
|
|
124
|
+
Object.defineProperty(Container.prototype, "first", {
|
|
125
|
+
get: function () {
|
|
126
|
+
return this.at(0);
|
|
127
|
+
},
|
|
128
|
+
enumerable: false,
|
|
129
|
+
configurable: true
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(Container.prototype, "last", {
|
|
132
|
+
get: function () {
|
|
133
|
+
return this.at(this.length - 1);
|
|
134
|
+
},
|
|
135
|
+
enumerable: false,
|
|
136
|
+
configurable: true
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(Container.prototype, "length", {
|
|
139
|
+
get: function () {
|
|
140
|
+
return this.nodes.length;
|
|
141
|
+
},
|
|
142
|
+
enumerable: false,
|
|
143
|
+
configurable: true
|
|
144
|
+
});
|
|
145
|
+
Container.prototype.removeChild = function (child) {
|
|
146
|
+
child = this.index(child);
|
|
147
|
+
this.at(child).parent = undefined;
|
|
148
|
+
this.nodes.splice(child, 1);
|
|
149
|
+
var index;
|
|
150
|
+
for (var id in this.indexes) {
|
|
151
|
+
index = this.indexes[id];
|
|
152
|
+
if (index >= child) {
|
|
153
|
+
this.indexes[id] = index - 1;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return this;
|
|
157
|
+
};
|
|
158
|
+
Container.prototype.removeAll = function () {
|
|
159
|
+
var e_1, _a;
|
|
160
|
+
try {
|
|
161
|
+
for (var _b = __values(this.nodes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
162
|
+
var node = _c.value;
|
|
163
|
+
node.parent = undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
167
|
+
finally {
|
|
168
|
+
try {
|
|
169
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
170
|
+
}
|
|
171
|
+
finally { if (e_1) throw e_1.error; }
|
|
172
|
+
}
|
|
173
|
+
this.nodes = [];
|
|
174
|
+
return this;
|
|
175
|
+
};
|
|
176
|
+
Container.prototype.empty = function () {
|
|
177
|
+
return this.removeAll();
|
|
178
|
+
};
|
|
179
|
+
Container.prototype.insertAfter = function (oldNode, newNode) {
|
|
180
|
+
var _a;
|
|
181
|
+
newNode.parent = this;
|
|
182
|
+
var oldIndex = this.index(oldNode);
|
|
183
|
+
var resetNode = [];
|
|
184
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
185
|
+
resetNode.push(arguments[i]);
|
|
186
|
+
}
|
|
187
|
+
(_a = this.nodes).splice.apply(_a, __spreadArray([oldIndex + 1, 0, newNode], __read(resetNode), false));
|
|
188
|
+
newNode.parent = this;
|
|
189
|
+
var index;
|
|
190
|
+
for (var id in this.indexes) {
|
|
191
|
+
index = this.indexes[id];
|
|
192
|
+
if (oldIndex < index) {
|
|
193
|
+
this.indexes[id] = index + arguments.length - 1;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return this;
|
|
197
|
+
};
|
|
198
|
+
Container.prototype.insertBefore = function (oldNode, newNode) {
|
|
199
|
+
var _a;
|
|
200
|
+
newNode.parent = this;
|
|
201
|
+
var oldIndex = this.index(oldNode);
|
|
202
|
+
var resetNode = [];
|
|
203
|
+
for (var i = 2; i < arguments.length; i++) {
|
|
204
|
+
resetNode.push(arguments[i]);
|
|
205
|
+
}
|
|
206
|
+
(_a = this.nodes).splice.apply(_a, __spreadArray([oldIndex, 0, newNode], __read(resetNode), false));
|
|
207
|
+
newNode.parent = this;
|
|
208
|
+
var index;
|
|
209
|
+
for (var id in this.indexes) {
|
|
210
|
+
index = this.indexes[id];
|
|
211
|
+
if (index >= oldIndex) {
|
|
212
|
+
this.indexes[id] = index + arguments.length - 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return this;
|
|
216
|
+
};
|
|
217
|
+
Container.prototype._findChildAtPosition = function (line, col) {
|
|
218
|
+
var found = undefined;
|
|
219
|
+
this.each(function (node) {
|
|
220
|
+
if (node.atPosition) {
|
|
221
|
+
var foundChild = node.atPosition(line, col);
|
|
222
|
+
if (foundChild) {
|
|
223
|
+
found = foundChild;
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (node.isAtPosition(line, col)) {
|
|
228
|
+
found = node;
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return found;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Return the most specific node at the line and column number given.
|
|
236
|
+
* The source location is based on the original parsed location, locations aren't
|
|
237
|
+
* updated as selector nodes are mutated.
|
|
238
|
+
*
|
|
239
|
+
* Note that this location is relative to the location of the first character
|
|
240
|
+
* of the selector, and not the location of the selector in the overall document
|
|
241
|
+
* when used in conjunction with postcss.
|
|
242
|
+
*
|
|
243
|
+
* If not found, returns undefined.
|
|
244
|
+
* @param {number} line The line number of the node to find. (1-based index)
|
|
245
|
+
* @param {number} col The column number of the node to find. (1-based index)
|
|
246
|
+
*/
|
|
247
|
+
Container.prototype.atPosition = function (line, col) {
|
|
248
|
+
if (this.isAtPosition(line, col)) {
|
|
249
|
+
return this._findChildAtPosition(line, col) || this;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
Container.prototype._inferEndPosition = function () {
|
|
256
|
+
if (this.last && this.last.source && this.last.source.end) {
|
|
257
|
+
this.source = this.source || {};
|
|
258
|
+
this.source.end = this.source.end || {};
|
|
259
|
+
Object.assign(this.source.end, this.last.source.end);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
Container.prototype.each = function (callback) {
|
|
263
|
+
if (!this.lastEach) {
|
|
264
|
+
this.lastEach = 0;
|
|
265
|
+
}
|
|
266
|
+
if (!this.indexes) {
|
|
267
|
+
this.indexes = {};
|
|
268
|
+
}
|
|
269
|
+
this.lastEach++;
|
|
270
|
+
var id = this.lastEach;
|
|
271
|
+
this.indexes[id] = 0;
|
|
272
|
+
if (!this.length) {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
var index, result;
|
|
276
|
+
while (this.indexes[id] < this.length) {
|
|
277
|
+
index = this.indexes[id];
|
|
278
|
+
result = callback(this.at(index), index);
|
|
279
|
+
if (result === false) {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
this.indexes[id] += 1;
|
|
283
|
+
}
|
|
284
|
+
delete this.indexes[id];
|
|
285
|
+
if (result === false) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
Container.prototype.walk = function (callback, depth) {
|
|
290
|
+
if (depth === void 0) { depth = 0; }
|
|
291
|
+
// Bound recursion so a pathologically deep node tree raises a catchable
|
|
292
|
+
// error instead of overflowing the call stack (CVE-2026-9358 / CWE-674).
|
|
293
|
+
if (depth > util_1.MAX_NESTING_DEPTH) {
|
|
294
|
+
throw new Error("Cannot walk selector: nesting depth exceeds the maximum of ".concat(util_1.MAX_NESTING_DEPTH, "."));
|
|
295
|
+
}
|
|
296
|
+
return this.each(function (node, i) {
|
|
297
|
+
var result = callback(node, i);
|
|
298
|
+
if (result !== false && node.length) {
|
|
299
|
+
result = node.walk(callback, depth + 1);
|
|
300
|
+
}
|
|
301
|
+
if (result === false) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
Container.prototype.walkAttributes = function (callback) {
|
|
307
|
+
var _this = this;
|
|
308
|
+
return this.walk(function (selector) {
|
|
309
|
+
if (selector.type === types.ATTRIBUTE) {
|
|
310
|
+
return callback.call(_this, selector);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
Container.prototype.walkClasses = function (callback) {
|
|
315
|
+
var _this = this;
|
|
316
|
+
return this.walk(function (selector) {
|
|
317
|
+
if (selector.type === types.CLASS) {
|
|
318
|
+
return callback.call(_this, selector);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
Container.prototype.walkCombinators = function (callback) {
|
|
323
|
+
var _this = this;
|
|
324
|
+
return this.walk(function (selector) {
|
|
325
|
+
if (selector.type === types.COMBINATOR) {
|
|
326
|
+
return callback.call(_this, selector);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
Container.prototype.walkComments = function (callback) {
|
|
331
|
+
var _this = this;
|
|
332
|
+
return this.walk(function (selector) {
|
|
333
|
+
if (selector.type === types.COMMENT) {
|
|
334
|
+
return callback.call(_this, selector);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
Container.prototype.walkIds = function (callback) {
|
|
339
|
+
var _this = this;
|
|
340
|
+
return this.walk(function (selector) {
|
|
341
|
+
if (selector.type === types.ID) {
|
|
342
|
+
return callback.call(_this, selector);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
Container.prototype.walkNesting = function (callback) {
|
|
347
|
+
var _this = this;
|
|
348
|
+
return this.walk(function (selector) {
|
|
349
|
+
if (selector.type === types.NESTING) {
|
|
350
|
+
return callback.call(_this, selector);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
Container.prototype.walkPseudos = function (callback) {
|
|
355
|
+
var _this = this;
|
|
356
|
+
return this.walk(function (selector) {
|
|
357
|
+
if (selector.type === types.PSEUDO) {
|
|
358
|
+
return callback.call(_this, selector);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
Container.prototype.walkTags = function (callback) {
|
|
363
|
+
var _this = this;
|
|
364
|
+
return this.walk(function (selector) {
|
|
365
|
+
if (selector.type === types.TAG) {
|
|
366
|
+
return callback.call(_this, selector);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
Container.prototype.walkUniversals = function (callback) {
|
|
371
|
+
var _this = this;
|
|
372
|
+
return this.walk(function (selector) {
|
|
373
|
+
if (selector.type === types.UNIVERSAL) {
|
|
374
|
+
return callback.call(_this, selector);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
Container.prototype.split = function (callback) {
|
|
379
|
+
var _this = this;
|
|
380
|
+
var current = [];
|
|
381
|
+
return this.reduce(function (memo, node, index) {
|
|
382
|
+
var split = callback.call(_this, node);
|
|
383
|
+
current.push(node);
|
|
384
|
+
if (split) {
|
|
385
|
+
memo.push(current);
|
|
386
|
+
current = [];
|
|
387
|
+
}
|
|
388
|
+
else if (index === _this.length - 1) {
|
|
389
|
+
memo.push(current);
|
|
390
|
+
}
|
|
391
|
+
return memo;
|
|
392
|
+
}, []);
|
|
393
|
+
};
|
|
394
|
+
Container.prototype.map = function (callback) {
|
|
395
|
+
return this.nodes.map(callback);
|
|
396
|
+
};
|
|
397
|
+
Container.prototype.reduce = function (callback, memo) {
|
|
398
|
+
return this.nodes.reduce(callback, memo);
|
|
399
|
+
};
|
|
400
|
+
Container.prototype.every = function (callback) {
|
|
401
|
+
return this.nodes.every(callback);
|
|
402
|
+
};
|
|
403
|
+
Container.prototype.some = function (callback) {
|
|
404
|
+
return this.nodes.some(callback);
|
|
405
|
+
};
|
|
406
|
+
Container.prototype.filter = function (callback) {
|
|
407
|
+
return this.nodes.filter(callback);
|
|
408
|
+
};
|
|
409
|
+
Container.prototype.sort = function (callback) {
|
|
410
|
+
return this.nodes.sort(callback);
|
|
411
|
+
};
|
|
412
|
+
Container.prototype.toString = function (options) {
|
|
413
|
+
if (options === void 0) { options = {}; }
|
|
414
|
+
return this._stringify(options, 0, (0, util_1.resolveMaxNestingDepth)(options.maxNestingDepth));
|
|
415
|
+
};
|
|
416
|
+
Container.prototype._stringify = function (options, depth, max) {
|
|
417
|
+
var _this = this;
|
|
418
|
+
return this.map(function (child) { return _this._stringifyChild(child, options, depth, max); }).join("");
|
|
419
|
+
};
|
|
420
|
+
// Serialize a child node. Historically `toString` used `this.map(String)`,
|
|
421
|
+
// which leniently coerced anything — including raw arrays inserted via
|
|
422
|
+
// `replaceWith(array)` / `insertBefore` / `insertAfter` (e.g. Tailwind's
|
|
423
|
+
// `:merge()` expansion). Fall back to `String(child)` for values that are not
|
|
424
|
+
// parser nodes so that behaviour is preserved.
|
|
425
|
+
Container.prototype._stringifyChild = function (child, options, depth, max) {
|
|
426
|
+
return typeof child._stringify === "function"
|
|
427
|
+
? child._stringify(options, depth, max)
|
|
428
|
+
: String(child);
|
|
429
|
+
};
|
|
430
|
+
return Container;
|
|
431
|
+
}(node_1.default));
|
|
432
|
+
exports.default = Container;
|
|
433
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Node from "./node";
|
|
2
|
+
import { ID as fragmentType } from "./types";
|
|
3
|
+
|
|
4
|
+
export default class Fragment extends Node {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
super(opts);
|
|
7
|
+
this.type = fragmentType;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
valueToString() {
|
|
11
|
+
return "#" + super.valueToString();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isUniversal = exports.isTag = exports.isString = exports.isSelector = exports.isRoot = exports.isPseudo = exports.isNesting = exports.isIdentifier = exports.isComment = exports.isCombinator = exports.isClassName = exports.isAttribute = void 0;
|
|
5
|
+
exports.isNode = isNode;
|
|
6
|
+
exports.isPseudoElement = isPseudoElement;
|
|
7
|
+
exports.isPseudoClass = isPseudoClass;
|
|
8
|
+
exports.isContainer = isContainer;
|
|
9
|
+
exports.isNamespace = isNamespace;
|
|
10
|
+
var types_1 = require("./types");
|
|
11
|
+
var IS_TYPE = (_a = {},
|
|
12
|
+
_a[types_1.ATTRIBUTE] = true,
|
|
13
|
+
_a[types_1.CLASS] = true,
|
|
14
|
+
_a[types_1.COMBINATOR] = true,
|
|
15
|
+
_a[types_1.COMMENT] = true,
|
|
16
|
+
_a[types_1.ID] = true,
|
|
17
|
+
_a[types_1.NESTING] = true,
|
|
18
|
+
_a[types_1.PSEUDO] = true,
|
|
19
|
+
_a[types_1.ROOT] = true,
|
|
20
|
+
_a[types_1.SELECTOR] = true,
|
|
21
|
+
_a[types_1.STRING] = true,
|
|
22
|
+
_a[types_1.TAG] = true,
|
|
23
|
+
_a[types_1.UNIVERSAL] = true,
|
|
24
|
+
_a);
|
|
25
|
+
function isNode(node) {
|
|
26
|
+
return typeof node === "object" && IS_TYPE[node.type];
|
|
27
|
+
}
|
|
28
|
+
function isNodeType(type, node) {
|
|
29
|
+
return isNode(node) && node.type === type;
|
|
30
|
+
}
|
|
31
|
+
exports.isAttribute = isNodeType.bind(null, types_1.ATTRIBUTE);
|
|
32
|
+
exports.isClassName = isNodeType.bind(null, types_1.CLASS);
|
|
33
|
+
exports.isCombinator = isNodeType.bind(null, types_1.COMBINATOR);
|
|
34
|
+
exports.isComment = isNodeType.bind(null, types_1.COMMENT);
|
|
35
|
+
exports.isIdentifier = isNodeType.bind(null, types_1.ID);
|
|
36
|
+
exports.isNesting = isNodeType.bind(null, types_1.NESTING);
|
|
37
|
+
exports.isPseudo = isNodeType.bind(null, types_1.PSEUDO);
|
|
38
|
+
exports.isRoot = isNodeType.bind(null, types_1.ROOT);
|
|
39
|
+
exports.isSelector = isNodeType.bind(null, types_1.SELECTOR);
|
|
40
|
+
exports.isString = isNodeType.bind(null, types_1.STRING);
|
|
41
|
+
exports.isTag = isNodeType.bind(null, types_1.TAG);
|
|
42
|
+
exports.isUniversal = isNodeType.bind(null, types_1.UNIVERSAL);
|
|
43
|
+
function isPseudoElement(node) {
|
|
44
|
+
return ((0, exports.isPseudo)(node) &&
|
|
45
|
+
node.value &&
|
|
46
|
+
(node.value.startsWith("::") ||
|
|
47
|
+
node.value.toLowerCase() === ":before" ||
|
|
48
|
+
node.value.toLowerCase() === ":after" ||
|
|
49
|
+
node.value.toLowerCase() === ":first-letter" ||
|
|
50
|
+
node.value.toLowerCase() === ":first-line"));
|
|
51
|
+
}
|
|
52
|
+
function isPseudoClass(node) {
|
|
53
|
+
return (0, exports.isPseudo)(node) && !isPseudoElement(node);
|
|
54
|
+
}
|
|
55
|
+
function isContainer(node) {
|
|
56
|
+
return !!(isNode(node) && node.walk);
|
|
57
|
+
}
|
|
58
|
+
function isNamespace(node) {
|
|
59
|
+
return (0, exports.isAttribute)(node) || (0, exports.isTag)(node);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var node_1 = __importDefault(require("./node"));
|
|
22
|
+
var types_1 = require("./types");
|
|
23
|
+
var ID = /** @class */ (function (_super) {
|
|
24
|
+
__extends(ID, _super);
|
|
25
|
+
function ID(opts) {
|
|
26
|
+
var _this = _super.call(this, opts) || this;
|
|
27
|
+
_this.type = types_1.ID;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
ID.prototype.valueToString = function () {
|
|
31
|
+
return "#" + _super.prototype.valueToString.call(this);
|
|
32
|
+
};
|
|
33
|
+
return ID;
|
|
34
|
+
}(node_1.default));
|
|
35
|
+
exports.default = ID;
|
|
36
|
+
//# sourceMappingURL=id.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./constructors"), exports);
|
|
19
|
+
__exportStar(require("./guards"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|