🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

postcss-selector-parser

Package Overview
Dependencies
Maintainers
5
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-selector-parser - npm Package Compare versions

Comparing version
7.1.2
to
7.1.3
+4
-0
CHANGELOG.md

@@ -0,1 +1,5 @@

# 7.1.3 - 2026-06-11
- Improve fix CVE-2026-9358 (NVD) / SNYK-JS-POSTCSSSELECTORPARSER-16873882 (clone/walk)
# 7.1.2 - 2026-06-09

@@ -2,0 +6,0 @@

+40
-11
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _processor = _interopRequireDefault(require("./processor"));
var selectors = _interopRequireWildcard(require("./selectors"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var parser = function parser(processor) {
return new _processor["default"](processor);
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var processor_1 = __importDefault(require("./processor"));
var selectors = __importStar(require("./selectors"));
var parser = function (processor) { return new processor_1.default(processor); };
Object.assign(parser, selectors);
delete parser.__esModule;
var _default = exports["default"] = parser;
module.exports = exports.default;
module.exports = parser;
//# sourceMappingURL=index.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _root = _interopRequireDefault(require("./selectors/root"));
var _selector = _interopRequireDefault(require("./selectors/selector"));
var _className = _interopRequireDefault(require("./selectors/className"));
var _comment = _interopRequireDefault(require("./selectors/comment"));
var _id = _interopRequireDefault(require("./selectors/id"));
var _tag = _interopRequireDefault(require("./selectors/tag"));
var _string = _interopRequireDefault(require("./selectors/string"));
var _pseudo = _interopRequireDefault(require("./selectors/pseudo"));
var _attribute = _interopRequireWildcard(require("./selectors/attribute"));
var _universal = _interopRequireDefault(require("./selectors/universal"));
var _combinator = _interopRequireDefault(require("./selectors/combinator"));
var _nesting = _interopRequireDefault(require("./selectors/nesting"));
var _sortAscending = _interopRequireDefault(require("./sortAscending"));
var _tokenize = _interopRequireWildcard(require("./tokenize"));
var tokens = _interopRequireWildcard(require("./tokenTypes"));
var types = _interopRequireWildcard(require("./selectors/types"));
var _util = require("./util");
var _WHITESPACE_TOKENS, _Object$assign;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var WHITESPACE_TOKENS = (_WHITESPACE_TOKENS = {}, _WHITESPACE_TOKENS[tokens.space] = true, _WHITESPACE_TOKENS[tokens.cr] = true, _WHITESPACE_TOKENS[tokens.feed] = true, _WHITESPACE_TOKENS[tokens.newline] = true, _WHITESPACE_TOKENS[tokens.tab] = true, _WHITESPACE_TOKENS);
var WHITESPACE_EQUIV_TOKENS = Object.assign({}, WHITESPACE_TOKENS, (_Object$assign = {}, _Object$assign[tokens.comment] = true, _Object$assign));
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
var root_1 = __importDefault(require("./selectors/root"));
var selector_1 = __importDefault(require("./selectors/selector"));
var className_1 = __importDefault(require("./selectors/className"));
var comment_1 = __importDefault(require("./selectors/comment"));
var id_1 = __importDefault(require("./selectors/id"));
var tag_1 = __importDefault(require("./selectors/tag"));
var string_1 = __importDefault(require("./selectors/string"));
var pseudo_1 = __importDefault(require("./selectors/pseudo"));
var attribute_1 = __importStar(require("./selectors/attribute"));
var universal_1 = __importDefault(require("./selectors/universal"));
var combinator_1 = __importDefault(require("./selectors/combinator"));
var nesting_1 = __importDefault(require("./selectors/nesting"));
var sortAscending_1 = __importDefault(require("./sortAscending"));
var tokenize_1 = __importStar(require("./tokenize"));
var tokens = __importStar(require("./tokenTypes"));
var types = __importStar(require("./selectors/types"));
var util_1 = require("./util");
var WHITESPACE_TOKENS = (_a = {},
_a[tokens.space] = true,
_a[tokens.cr] = true,
_a[tokens.feed] = true,
_a[tokens.newline] = true,
_a[tokens.tab] = true,
_a);
var WHITESPACE_EQUIV_TOKENS = __assign(__assign({}, WHITESPACE_TOKENS), (_b = {}, _b[tokens.comment] = true, _b));
function tokenStart(token) {
return {
line: token[_tokenize.FIELDS.START_LINE],
column: token[_tokenize.FIELDS.START_COL]
};
return {
line: token[tokenize_1.FIELDS.START_LINE],
column: token[tokenize_1.FIELDS.START_COL],
};
}
function tokenEnd(token) {
return {
line: token[_tokenize.FIELDS.END_LINE],
column: token[_tokenize.FIELDS.END_COL]
};
return {
line: token[tokenize_1.FIELDS.END_LINE],
column: token[tokenize_1.FIELDS.END_COL],
};
}
function getSource(startLine, startColumn, endLine, endColumn) {
return {
start: {
line: startLine,
column: startColumn
},
end: {
line: endLine,
column: endColumn
}
};
return {
start: {
line: startLine,
column: startColumn,
},
end: {
line: endLine,
column: endColumn,
},
};
}
function getTokenSource(token) {
return getSource(token[_tokenize.FIELDS.START_LINE], token[_tokenize.FIELDS.START_COL], token[_tokenize.FIELDS.END_LINE], token[_tokenize.FIELDS.END_COL]);
return getSource(token[tokenize_1.FIELDS.START_LINE], token[tokenize_1.FIELDS.START_COL], token[tokenize_1.FIELDS.END_LINE], token[tokenize_1.FIELDS.END_COL]);
}
function getTokenSourceSpan(startToken, endToken) {
if (!startToken) {
return undefined;
}
return getSource(startToken[_tokenize.FIELDS.START_LINE], startToken[_tokenize.FIELDS.START_COL], endToken[_tokenize.FIELDS.END_LINE], endToken[_tokenize.FIELDS.END_COL]);
if (!startToken) {
return undefined;
}
return getSource(startToken[tokenize_1.FIELDS.START_LINE], startToken[tokenize_1.FIELDS.START_COL], endToken[tokenize_1.FIELDS.END_LINE], endToken[tokenize_1.FIELDS.END_COL]);
}
function unescapeProp(node, prop) {
var value = node[prop];
if (typeof value !== "string") {
return;
}
if (value.indexOf("\\") !== -1) {
(0, _util.ensureObject)(node, 'raws');
node[prop] = (0, _util.unesc)(value);
if (node.raws[prop] === undefined) {
node.raws[prop] = value;
var value = node[prop];
if (typeof value !== "string") {
return;
}
}
return node;
if (value.indexOf("\\") !== -1) {
(0, util_1.ensureObject)(node, "raws");
node[prop] = (0, util_1.unesc)(value);
if (node.raws[prop] === undefined) {
node.raws[prop] = value;
}
}
return node;
}
function indexesOf(array, item) {
var i = -1;
var indexes = [];
while ((i = array.indexOf(item, i + 1)) !== -1) {
indexes.push(i);
}
return indexes;
var i = -1;
var indexes = [];
while ((i = array.indexOf(item, i + 1)) !== -1) {
indexes.push(i);
}
return indexes;
}
function uniqs() {
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function (item, i) {
return i === list.indexOf(item);
});
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function (item, i) { return i === list.indexOf(item); });
}
var Parser = exports["default"] = /*#__PURE__*/function () {
function Parser(rule, options) {
if (options === void 0) {
options = {};
var Parser = /** @class */ (function () {
function Parser(rule, options) {
if (options === void 0) { options = {}; }
this.rule = rule;
this.options = Object.assign({ lossy: false, safe: false }, options);
this.position = 0;
this.nestingDepth = 0;
this.maxNestingDepth = (0, util_1.resolveMaxNestingDepth)(this.options.maxNestingDepth);
this.css = typeof this.rule === "string" ? this.rule : this.rule.selector;
this.tokens = (0, tokenize_1.default)({
css: this.css,
error: this._errorGenerator(),
safe: this.options.safe,
});
var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
this.root = new root_1.default({ source: rootSource });
this.root.errorGenerator = this._errorGenerator();
var selector = new selector_1.default({
source: { start: { line: 1, column: 1 } },
sourceIndex: 0,
});
this.root.append(selector);
this.current = selector;
this.loop();
}
this.rule = rule;
this.options = Object.assign({
lossy: false,
safe: false
}, options);
this.position = 0;
this.nestingDepth = 0;
this.maxNestingDepth = (0, _util.resolveMaxNestingDepth)(this.options.maxNestingDepth);
this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
this.tokens = (0, _tokenize["default"])({
css: this.css,
error: this._errorGenerator(),
safe: this.options.safe
});
var rootSource = getTokenSourceSpan(this.tokens[0], this.tokens[this.tokens.length - 1]);
this.root = new _root["default"]({
source: rootSource
});
this.root.errorGenerator = this._errorGenerator();
var selector = new _selector["default"]({
source: {
start: {
line: 1,
column: 1
Parser.prototype._errorGenerator = function () {
var _this = this;
return function (message, errorOptions) {
if (typeof _this.rule === "string") {
return new Error(message);
}
return _this.rule.error(message, errorOptions);
};
};
Parser.prototype.attribute = function () {
var attr = [];
var startingToken = this.currToken;
this.position++;
while (this.position < this.tokens.length &&
this.currToken[tokenize_1.FIELDS.TYPE] !== tokens.closeSquare) {
attr.push(this.currToken);
this.position++;
}
},
sourceIndex: 0
});
this.root.append(selector);
this.current = selector;
this.loop();
}
var _proto = Parser.prototype;
_proto._errorGenerator = function _errorGenerator() {
var _this = this;
return function (message, errorOptions) {
if (typeof _this.rule === 'string') {
return new Error(message);
}
return _this.rule.error(message, errorOptions);
if (this.currToken[tokenize_1.FIELDS.TYPE] !== tokens.closeSquare) {
return this.expected("closing square bracket", this.currToken[tokenize_1.FIELDS.START_POS]);
}
var len = attr.length;
var node = {
source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
sourceIndex: startingToken[tokenize_1.FIELDS.START_POS],
};
if (len === 1 && !~[tokens.word].indexOf(attr[0][tokenize_1.FIELDS.TYPE])) {
return this.expected("attribute", attr[0][tokenize_1.FIELDS.START_POS]);
}
var pos = 0;
var spaceBefore = "";
var commentBefore = "";
var lastAdded = null;
var spaceAfterMeaningfulToken = false;
while (pos < len) {
var token = attr[pos];
var content = this.content(token);
var next = attr[pos + 1];
switch (token[tokenize_1.FIELDS.TYPE]) {
case tokens.space:
// if (
// len === 1 ||
// pos === 0 && this.content(next) === '|'
// ) {
// return this.expected('attribute', token[TOKEN.START_POS], content);
// }
spaceAfterMeaningfulToken = true;
if (this.options.lossy) {
break;
}
if (lastAdded) {
(0, util_1.ensureObject)(node, "spaces", lastAdded);
var prevContent = node.spaces[lastAdded].after || "";
node.spaces[lastAdded].after = prevContent + content;
var existingComment = (0, util_1.getProp)(node, "raws", "spaces", lastAdded, "after") || null;
if (existingComment) {
node.raws.spaces[lastAdded].after = existingComment + content;
}
}
else {
spaceBefore = spaceBefore + content;
commentBefore = commentBefore + content;
}
break;
case tokens.asterisk:
if (next[tokenize_1.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = "operator";
}
else if ((!node.namespace || (lastAdded === "namespace" && !spaceAfterMeaningfulToken)) &&
next) {
if (spaceBefore) {
(0, util_1.ensureObject)(node, "spaces", "attribute");
node.spaces.attribute.before = spaceBefore;
spaceBefore = "";
}
if (commentBefore) {
(0, util_1.ensureObject)(node, "raws", "spaces", "attribute");
node.raws.spaces.attribute.before = spaceBefore;
commentBefore = "";
}
node.namespace = (node.namespace || "") + content;
var rawValue = (0, util_1.getProp)(node, "raws", "namespace") || null;
if (rawValue) {
node.raws.namespace += content;
}
lastAdded = "namespace";
}
spaceAfterMeaningfulToken = false;
break;
case tokens.dollar:
if (lastAdded === "value") {
var oldRawValue = (0, util_1.getProp)(node, "raws", "value");
node.value += "$";
if (oldRawValue) {
node.raws.value = oldRawValue + "$";
}
break;
}
// Falls through
case tokens.caret:
if (next[tokenize_1.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = "operator";
}
spaceAfterMeaningfulToken = false;
break;
case tokens.combinator:
if (content === "~" && next[tokenize_1.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = "operator";
}
if (content !== "|") {
spaceAfterMeaningfulToken = false;
break;
}
if (next[tokenize_1.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = "operator";
}
else if (!node.namespace && !node.attribute) {
node.namespace = true;
}
spaceAfterMeaningfulToken = false;
break;
case tokens.word:
if (next &&
this.content(next) === "|" &&
attr[pos + 2] &&
attr[pos + 2][tokenize_1.FIELDS.TYPE] !== tokens.equals && // this look-ahead probably fails with comment nodes involved.
!node.operator &&
!node.namespace) {
node.namespace = content;
lastAdded = "namespace";
}
else if (!node.attribute || (lastAdded === "attribute" && !spaceAfterMeaningfulToken)) {
if (spaceBefore) {
(0, util_1.ensureObject)(node, "spaces", "attribute");
node.spaces.attribute.before = spaceBefore;
spaceBefore = "";
}
if (commentBefore) {
(0, util_1.ensureObject)(node, "raws", "spaces", "attribute");
node.raws.spaces.attribute.before = commentBefore;
commentBefore = "";
}
node.attribute = (node.attribute || "") + content;
var rawValue = (0, util_1.getProp)(node, "raws", "attribute") || null;
if (rawValue) {
node.raws.attribute += content;
}
lastAdded = "attribute";
}
else if ((!node.value && node.value !== "") ||
(lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark))) {
var unescaped_1 = (0, util_1.unesc)(content);
var oldRawValue = (0, util_1.getProp)(node, "raws", "value") || "";
var oldValue = node.value || "";
node.value = oldValue + unescaped_1;
node.quoteMark = null;
if (unescaped_1 !== content || oldRawValue) {
(0, util_1.ensureObject)(node, "raws");
node.raws.value = (oldRawValue || oldValue) + content;
}
lastAdded = "value";
}
else {
var insensitive = content === "i" || content === "I";
if ((node.value || node.value === "") &&
(node.quoteMark || spaceAfterMeaningfulToken)) {
node.insensitive = insensitive;
if (!insensitive || content === "I") {
(0, util_1.ensureObject)(node, "raws");
node.raws.insensitiveFlag = content;
}
lastAdded = "insensitive";
if (spaceBefore) {
(0, util_1.ensureObject)(node, "spaces", "insensitive");
node.spaces.insensitive.before = spaceBefore;
spaceBefore = "";
}
if (commentBefore) {
(0, util_1.ensureObject)(node, "raws", "spaces", "insensitive");
node.raws.spaces.insensitive.before = commentBefore;
commentBefore = "";
}
}
else if (node.value || node.value === "") {
lastAdded = "value";
node.value += content;
if (node.raws.value) {
node.raws.value += content;
}
}
}
spaceAfterMeaningfulToken = false;
break;
case tokens.str:
if (!node.attribute || !node.operator) {
return this.error("Expected an attribute followed by an operator preceding the string.", {
index: token[tokenize_1.FIELDS.START_POS],
});
}
var _a = (0, attribute_1.unescapeValue)(content), unescaped = _a.unescaped, quoteMark = _a.quoteMark;
node.value = unescaped;
node.quoteMark = quoteMark;
lastAdded = "value";
(0, util_1.ensureObject)(node, "raws");
node.raws.value = content;
spaceAfterMeaningfulToken = false;
break;
case tokens.equals:
if (!node.attribute) {
return this.expected("attribute", token[tokenize_1.FIELDS.START_POS], content);
}
if (node.value) {
return this.error('Unexpected "=" found; an operator was already defined.', {
index: token[tokenize_1.FIELDS.START_POS],
});
}
node.operator = node.operator ? node.operator + content : content;
lastAdded = "operator";
spaceAfterMeaningfulToken = false;
break;
case tokens.comment:
if (lastAdded) {
if (spaceAfterMeaningfulToken ||
(next && next[tokenize_1.FIELDS.TYPE] === tokens.space) ||
lastAdded === "insensitive") {
var lastComment = (0, util_1.getProp)(node, "spaces", lastAdded, "after") || "";
var rawLastComment = (0, util_1.getProp)(node, "raws", "spaces", lastAdded, "after") || lastComment;
(0, util_1.ensureObject)(node, "raws", "spaces", lastAdded);
node.raws.spaces[lastAdded].after = rawLastComment + content;
}
else {
var lastValue = node[lastAdded] || "";
var rawLastValue = (0, util_1.getProp)(node, "raws", lastAdded) || lastValue;
(0, util_1.ensureObject)(node, "raws");
node.raws[lastAdded] = rawLastValue + content;
}
}
else {
commentBefore = commentBefore + content;
}
break;
default:
return this.error("Unexpected \"".concat(content, "\" found."), { index: token[tokenize_1.FIELDS.START_POS] });
}
pos++;
}
unescapeProp(node, "attribute");
unescapeProp(node, "namespace");
this.newNode(new attribute_1.default(node));
this.position++;
};
};
_proto.attribute = function attribute() {
var attr = [];
var startingToken = this.currToken;
this.position++;
while (this.position < this.tokens.length && this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
attr.push(this.currToken);
this.position++;
}
if (this.currToken[_tokenize.FIELDS.TYPE] !== tokens.closeSquare) {
return this.expected('closing square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
}
var len = attr.length;
var node = {
source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
};
if (len === 1 && !~[tokens.word].indexOf(attr[0][_tokenize.FIELDS.TYPE])) {
return this.expected('attribute', attr[0][_tokenize.FIELDS.START_POS]);
}
var pos = 0;
var spaceBefore = '';
var commentBefore = '';
var lastAdded = null;
var spaceAfterMeaningfulToken = false;
while (pos < len) {
var token = attr[pos];
var content = this.content(token);
var next = attr[pos + 1];
switch (token[_tokenize.FIELDS.TYPE]) {
case tokens.space:
// if (
// len === 1 ||
// pos === 0 && this.content(next) === '|'
// ) {
// return this.expected('attribute', token[TOKEN.START_POS], content);
// }
spaceAfterMeaningfulToken = true;
if (this.options.lossy) {
break;
}
if (lastAdded) {
(0, _util.ensureObject)(node, 'spaces', lastAdded);
var prevContent = node.spaces[lastAdded].after || '';
node.spaces[lastAdded].after = prevContent + content;
var existingComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || null;
if (existingComment) {
node.raws.spaces[lastAdded].after = existingComment + content;
/**
* return a node containing meaningless garbage up to (but not including) the specified token position.
* if the token position is negative, all remaining tokens are consumed.
*
* This returns an array containing a single string node if all whitespace,
* otherwise an array of comment nodes with space before and after.
*
* These tokens are not added to the current selector, the caller can add them or use them to amend
* a previous node's space metadata.
*
* In lossy mode, this returns only comments.
*/
Parser.prototype.parseWhitespaceEquivalentTokens = function (stopPosition) {
if (stopPosition < 0) {
stopPosition = this.tokens.length;
}
var startPosition = this.position;
var nodes = [];
var space = "";
var lastComment = undefined;
do {
if (WHITESPACE_TOKENS[this.currToken[tokenize_1.FIELDS.TYPE]]) {
if (!this.options.lossy) {
space += this.content();
}
}
} else {
spaceBefore = spaceBefore + content;
commentBefore = commentBefore + content;
}
break;
case tokens.asterisk:
if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = 'operator';
} else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
if (spaceBefore) {
(0, _util.ensureObject)(node, 'spaces', 'attribute');
node.spaces.attribute.before = spaceBefore;
spaceBefore = '';
else if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.comment) {
var spaces = {};
if (space) {
spaces.before = space;
space = "";
}
lastComment = new comment_1.default({
value: this.content(),
source: getTokenSource(this.currToken),
sourceIndex: this.currToken[tokenize_1.FIELDS.START_POS],
spaces: spaces,
});
nodes.push(lastComment);
}
if (commentBefore) {
(0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
node.raws.spaces.attribute.before = spaceBefore;
commentBefore = '';
} while (++this.position < stopPosition);
if (space) {
if (lastComment) {
lastComment.spaces.after = space;
}
node.namespace = (node.namespace || "") + content;
var rawValue = (0, _util.getProp)(node, 'raws', 'namespace') || null;
if (rawValue) {
node.raws.namespace += content;
else if (!this.options.lossy) {
var firstToken = this.tokens[startPosition];
var lastToken = this.tokens[this.position - 1];
nodes.push(new string_1.default({
value: "",
source: getSource(firstToken[tokenize_1.FIELDS.START_LINE], firstToken[tokenize_1.FIELDS.START_COL], lastToken[tokenize_1.FIELDS.END_LINE], lastToken[tokenize_1.FIELDS.END_COL]),
sourceIndex: firstToken[tokenize_1.FIELDS.START_POS],
spaces: { before: space, after: "" },
}));
}
lastAdded = 'namespace';
}
spaceAfterMeaningfulToken = false;
break;
case tokens.dollar:
if (lastAdded === "value") {
var oldRawValue = (0, _util.getProp)(node, 'raws', 'value');
node.value += "$";
if (oldRawValue) {
node.raws.value = oldRawValue + "$";
}
return nodes;
};
/**
*
* @param {*} nodes
*/
Parser.prototype.convertWhitespaceNodesToSpace = function (nodes, requiredSpace) {
var _this = this;
if (requiredSpace === void 0) { requiredSpace = false; }
var space = "";
var rawSpace = "";
nodes.forEach(function (n) {
var spaceBefore = _this.lossySpace(n.spaces.before, requiredSpace);
var rawSpaceBefore = _this.lossySpace(n.rawSpaceBefore, requiredSpace);
space +=
spaceBefore + _this.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
rawSpace +=
spaceBefore +
n.value +
_this.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
});
if (rawSpace === space) {
rawSpace = undefined;
}
var result = { space: space, rawSpace: rawSpace };
return result;
};
Parser.prototype.isNamedCombinator = function (position) {
if (position === void 0) { position = this.position; }
return (this.tokens[position + 0] &&
this.tokens[position + 0][tokenize_1.FIELDS.TYPE] === tokens.slash &&
this.tokens[position + 1] &&
this.tokens[position + 1][tokenize_1.FIELDS.TYPE] === tokens.word &&
this.tokens[position + 2] &&
this.tokens[position + 2][tokenize_1.FIELDS.TYPE] === tokens.slash);
};
Parser.prototype.namedCombinator = function () {
if (this.isNamedCombinator()) {
var nameRaw = this.content(this.tokens[this.position + 1]);
var name = (0, util_1.unesc)(nameRaw).toLowerCase();
var raws = {};
if (name !== nameRaw) {
raws.value = "/".concat(nameRaw, "/");
}
break;
}
// Falls through
case tokens.caret:
if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = 'operator';
}
spaceAfterMeaningfulToken = false;
break;
case tokens.combinator:
if (content === '~' && next[_tokenize.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = 'operator';
}
if (content !== '|') {
spaceAfterMeaningfulToken = false;
break;
}
if (next[_tokenize.FIELDS.TYPE] === tokens.equals) {
node.operator = content;
lastAdded = 'operator';
} else if (!node.namespace && !node.attribute) {
node.namespace = true;
}
spaceAfterMeaningfulToken = false;
break;
case tokens.word:
if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][_tokenize.FIELDS.TYPE] !== tokens.equals &&
// this look-ahead probably fails with comment nodes involved.
!node.operator && !node.namespace) {
node.namespace = content;
lastAdded = 'namespace';
} else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
if (spaceBefore) {
(0, _util.ensureObject)(node, 'spaces', 'attribute');
node.spaces.attribute.before = spaceBefore;
spaceBefore = '';
var node = new combinator_1.default({
value: "/".concat(name, "/"),
source: getSource(this.currToken[tokenize_1.FIELDS.START_LINE], this.currToken[tokenize_1.FIELDS.START_COL], this.tokens[this.position + 2][tokenize_1.FIELDS.END_LINE], this.tokens[this.position + 2][tokenize_1.FIELDS.END_COL]),
sourceIndex: this.currToken[tokenize_1.FIELDS.START_POS],
raws: raws,
});
this.position = this.position + 3;
return node;
}
else {
this.unexpected();
}
};
Parser.prototype.combinator = function () {
var _this = this;
if (this.content() === "|") {
return this.namespace();
}
// We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
if (nextSigTokenPos < 0 ||
this.tokens[nextSigTokenPos][tokenize_1.FIELDS.TYPE] === tokens.comma ||
this.tokens[nextSigTokenPos][tokenize_1.FIELDS.TYPE] === tokens.closeParenthesis) {
var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
if (nodes.length > 0) {
var last = this.current.last;
if (last) {
var _a = this.convertWhitespaceNodesToSpace(nodes), space = _a.space, rawSpace = _a.rawSpace;
if (rawSpace !== undefined) {
last.rawSpaceAfter += rawSpace;
}
last.spaces.after += space;
}
else {
nodes.forEach(function (n) { return _this.newNode(n); });
}
}
if (commentBefore) {
(0, _util.ensureObject)(node, 'raws', 'spaces', 'attribute');
node.raws.spaces.attribute.before = commentBefore;
commentBefore = '';
return;
}
var firstToken = this.currToken;
var spaceOrDescendantSelectorNodes = undefined;
if (nextSigTokenPos > this.position) {
spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
}
var node;
if (this.isNamedCombinator()) {
node = this.namedCombinator();
}
else if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.combinator) {
node = new combinator_1.default({
value: this.content(),
source: getTokenSource(this.currToken),
sourceIndex: this.currToken[tokenize_1.FIELDS.START_POS],
});
this.position++;
}
else if (WHITESPACE_TOKENS[this.currToken[tokenize_1.FIELDS.TYPE]]) {
// pass
}
else if (!spaceOrDescendantSelectorNodes) {
this.unexpected();
}
if (node) {
if (spaceOrDescendantSelectorNodes) {
var _b = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes), space = _b.space, rawSpace = _b.rawSpace;
node.spaces.before = space;
node.rawSpaceBefore = rawSpace;
}
node.attribute = (node.attribute || "") + content;
var _rawValue = (0, _util.getProp)(node, 'raws', 'attribute') || null;
if (_rawValue) {
node.raws.attribute += content;
}
else {
// descendant combinator
var _c = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true), space = _c.space, rawSpace = _c.rawSpace;
if (!rawSpace) {
rawSpace = space;
}
lastAdded = 'attribute';
} else if (!node.value && node.value !== "" || lastAdded === "value" && !(spaceAfterMeaningfulToken || node.quoteMark)) {
var _unescaped = (0, _util.unesc)(content);
var _oldRawValue = (0, _util.getProp)(node, 'raws', 'value') || '';
var oldValue = node.value || '';
node.value = oldValue + _unescaped;
node.quoteMark = null;
if (_unescaped !== content || _oldRawValue) {
(0, _util.ensureObject)(node, 'raws');
node.raws.value = (_oldRawValue || oldValue) + content;
var spaces = {};
var raws = { spaces: {} };
if (space.endsWith(" ") && rawSpace.endsWith(" ")) {
spaces.before = space.slice(0, space.length - 1);
raws.spaces.before = rawSpace.slice(0, rawSpace.length - 1);
}
lastAdded = 'value';
} else {
var insensitive = content === 'i' || content === "I";
if ((node.value || node.value === '') && (node.quoteMark || spaceAfterMeaningfulToken)) {
node.insensitive = insensitive;
if (!insensitive || content === "I") {
(0, _util.ensureObject)(node, 'raws');
node.raws.insensitiveFlag = content;
}
lastAdded = 'insensitive';
if (spaceBefore) {
(0, _util.ensureObject)(node, 'spaces', 'insensitive');
node.spaces.insensitive.before = spaceBefore;
spaceBefore = '';
}
if (commentBefore) {
(0, _util.ensureObject)(node, 'raws', 'spaces', 'insensitive');
node.raws.spaces.insensitive.before = commentBefore;
commentBefore = '';
}
} else if (node.value || node.value === '') {
lastAdded = 'value';
node.value += content;
if (node.raws.value) {
node.raws.value += content;
}
else if (space[0] === " " && rawSpace[0] === " ") {
spaces.after = space.slice(1);
raws.spaces.after = rawSpace.slice(1);
}
}
spaceAfterMeaningfulToken = false;
break;
case tokens.str:
if (!node.attribute || !node.operator) {
return this.error("Expected an attribute followed by an operator preceding the string.", {
index: token[_tokenize.FIELDS.START_POS]
else {
raws.value = rawSpace;
}
node = new combinator_1.default({
value: " ",
source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
sourceIndex: firstToken[tokenize_1.FIELDS.START_POS],
spaces: spaces,
raws: raws,
});
}
var _unescapeValue = (0, _attribute.unescapeValue)(content),
unescaped = _unescapeValue.unescaped,
quoteMark = _unescapeValue.quoteMark;
node.value = unescaped;
node.quoteMark = quoteMark;
lastAdded = 'value';
(0, _util.ensureObject)(node, 'raws');
node.raws.value = content;
spaceAfterMeaningfulToken = false;
break;
case tokens.equals:
if (!node.attribute) {
return this.expected('attribute', token[_tokenize.FIELDS.START_POS], content);
}
if (node.value) {
return this.error('Unexpected "=" found; an operator was already defined.', {
index: token[_tokenize.FIELDS.START_POS]
});
}
node.operator = node.operator ? node.operator + content : content;
lastAdded = 'operator';
spaceAfterMeaningfulToken = false;
break;
case tokens.comment:
if (lastAdded) {
if (spaceAfterMeaningfulToken || next && next[_tokenize.FIELDS.TYPE] === tokens.space || lastAdded === 'insensitive') {
var lastComment = (0, _util.getProp)(node, 'spaces', lastAdded, 'after') || '';
var rawLastComment = (0, _util.getProp)(node, 'raws', 'spaces', lastAdded, 'after') || lastComment;
(0, _util.ensureObject)(node, 'raws', 'spaces', lastAdded);
node.raws.spaces[lastAdded].after = rawLastComment + content;
} else {
var lastValue = node[lastAdded] || '';
var rawLastValue = (0, _util.getProp)(node, 'raws', lastAdded) || lastValue;
(0, _util.ensureObject)(node, 'raws');
node.raws[lastAdded] = rawLastValue + content;
}
} else {
commentBefore = commentBefore + content;
}
break;
default:
return this.error("Unexpected \"" + content + "\" found.", {
index: token[_tokenize.FIELDS.START_POS]
});
}
pos++;
}
unescapeProp(node, "attribute");
unescapeProp(node, "namespace");
this.newNode(new _attribute["default"](node));
this.position++;
}
/**
* return a node containing meaningless garbage up to (but not including) the specified token position.
* if the token position is negative, all remaining tokens are consumed.
*
* This returns an array containing a single string node if all whitespace,
* otherwise an array of comment nodes with space before and after.
*
* These tokens are not added to the current selector, the caller can add them or use them to amend
* a previous node's space metadata.
*
* In lossy mode, this returns only comments.
*/;
_proto.parseWhitespaceEquivalentTokens = function parseWhitespaceEquivalentTokens(stopPosition) {
if (stopPosition < 0) {
stopPosition = this.tokens.length;
}
var startPosition = this.position;
var nodes = [];
var space = "";
var lastComment = undefined;
do {
if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
if (!this.options.lossy) {
space += this.content();
}
} else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.comment) {
var spaces = {};
if (space) {
spaces.before = space;
space = "";
if (this.currToken && this.currToken[tokenize_1.FIELDS.TYPE] === tokens.space) {
node.spaces.after = this.optionalSpace(this.content());
this.position++;
}
lastComment = new _comment["default"]({
value: this.content(),
source: getTokenSource(this.currToken),
sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
spaces: spaces
return this.newNode(node);
};
Parser.prototype.comma = function () {
if (this.position === this.tokens.length - 1) {
this.root.trailingComma = true;
this.position++;
return;
}
this.current._inferEndPosition();
var selector = new selector_1.default({
source: {
start: tokenStart(this.tokens[this.position + 1]),
},
sourceIndex: this.tokens[this.position + 1][tokenize_1.FIELDS.START_POS],
});
nodes.push(lastComment);
}
} while (++this.position < stopPosition);
if (space) {
if (lastComment) {
lastComment.spaces.after = space;
} else if (!this.options.lossy) {
var firstToken = this.tokens[startPosition];
var lastToken = this.tokens[this.position - 1];
nodes.push(new _string["default"]({
value: '',
source: getSource(firstToken[_tokenize.FIELDS.START_LINE], firstToken[_tokenize.FIELDS.START_COL], lastToken[_tokenize.FIELDS.END_LINE], lastToken[_tokenize.FIELDS.END_COL]),
sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
spaces: {
before: space,
after: ''
}
this.current.parent.append(selector);
this.current = selector;
this.position++;
};
Parser.prototype.comment = function () {
var current = this.currToken;
this.newNode(new comment_1.default({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[tokenize_1.FIELDS.START_POS],
}));
}
}
return nodes;
}
/**
*
* @param {*} nodes
*/;
_proto.convertWhitespaceNodesToSpace = function convertWhitespaceNodesToSpace(nodes, requiredSpace) {
var _this2 = this;
if (requiredSpace === void 0) {
requiredSpace = false;
}
var space = "";
var rawSpace = "";
nodes.forEach(function (n) {
var spaceBefore = _this2.lossySpace(n.spaces.before, requiredSpace);
var rawSpaceBefore = _this2.lossySpace(n.rawSpaceBefore, requiredSpace);
space += spaceBefore + _this2.lossySpace(n.spaces.after, requiredSpace && spaceBefore.length === 0);
rawSpace += spaceBefore + n.value + _this2.lossySpace(n.rawSpaceAfter, requiredSpace && rawSpaceBefore.length === 0);
});
if (rawSpace === space) {
rawSpace = undefined;
}
var result = {
space: space,
rawSpace: rawSpace
this.position++;
};
return result;
};
_proto.isNamedCombinator = function isNamedCombinator(position) {
if (position === void 0) {
position = this.position;
}
return this.tokens[position + 0] && this.tokens[position + 0][_tokenize.FIELDS.TYPE] === tokens.slash && this.tokens[position + 1] && this.tokens[position + 1][_tokenize.FIELDS.TYPE] === tokens.word && this.tokens[position + 2] && this.tokens[position + 2][_tokenize.FIELDS.TYPE] === tokens.slash;
};
_proto.namedCombinator = function namedCombinator() {
if (this.isNamedCombinator()) {
var nameRaw = this.content(this.tokens[this.position + 1]);
var name = (0, _util.unesc)(nameRaw).toLowerCase();
var raws = {};
if (name !== nameRaw) {
raws.value = "/" + nameRaw + "/";
}
var node = new _combinator["default"]({
value: "/" + name + "/",
source: getSource(this.currToken[_tokenize.FIELDS.START_LINE], this.currToken[_tokenize.FIELDS.START_COL], this.tokens[this.position + 2][_tokenize.FIELDS.END_LINE], this.tokens[this.position + 2][_tokenize.FIELDS.END_COL]),
sourceIndex: this.currToken[_tokenize.FIELDS.START_POS],
raws: raws
});
this.position = this.position + 3;
return node;
} else {
this.unexpected();
}
};
_proto.combinator = function combinator() {
var _this3 = this;
if (this.content() === '|') {
return this.namespace();
}
// We need to decide between a space that's a descendant combinator and meaningless whitespace at the end of a selector.
var nextSigTokenPos = this.locateNextMeaningfulToken(this.position);
if (nextSigTokenPos < 0 || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.comma || this.tokens[nextSigTokenPos][_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
var nodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
if (nodes.length > 0) {
var last = this.current.last;
if (last) {
var _this$convertWhitespa = this.convertWhitespaceNodesToSpace(nodes),
space = _this$convertWhitespa.space,
rawSpace = _this$convertWhitespa.rawSpace;
if (rawSpace !== undefined) {
last.rawSpaceAfter += rawSpace;
}
last.spaces.after += space;
} else {
nodes.forEach(function (n) {
return _this3.newNode(n);
});
Parser.prototype.error = function (message, opts) {
throw this.root.error(message, opts);
};
Parser.prototype.missingBackslash = function () {
return this.error("Expected a backslash preceding the semicolon.", {
index: this.currToken[tokenize_1.FIELDS.START_POS],
});
};
Parser.prototype.missingParenthesis = function () {
return this.expected("opening parenthesis", this.currToken[tokenize_1.FIELDS.START_POS]);
};
Parser.prototype.missingSquareBracket = function () {
return this.expected("opening square bracket", this.currToken[tokenize_1.FIELDS.START_POS]);
};
Parser.prototype.unexpected = function () {
return this.error("Unexpected '".concat(this.content(), "'. Escaping special characters with \\ may help."), this.currToken[tokenize_1.FIELDS.START_POS]);
};
Parser.prototype.unexpectedPipe = function () {
return this.error("Unexpected '|'.", this.currToken[tokenize_1.FIELDS.START_POS]);
};
Parser.prototype.namespace = function () {
var before = (this.prevToken && this.content(this.prevToken)) || true;
if (this.nextToken[tokenize_1.FIELDS.TYPE] === tokens.word) {
this.position++;
return this.word(before);
}
}
return;
}
var firstToken = this.currToken;
var spaceOrDescendantSelectorNodes = undefined;
if (nextSigTokenPos > this.position) {
spaceOrDescendantSelectorNodes = this.parseWhitespaceEquivalentTokens(nextSigTokenPos);
}
var node;
if (this.isNamedCombinator()) {
node = this.namedCombinator();
} else if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.combinator) {
node = new _combinator["default"]({
value: this.content(),
source: getTokenSource(this.currToken),
sourceIndex: this.currToken[_tokenize.FIELDS.START_POS]
});
this.position++;
} else if (WHITESPACE_TOKENS[this.currToken[_tokenize.FIELDS.TYPE]]) {
// pass
} else if (!spaceOrDescendantSelectorNodes) {
this.unexpected();
}
if (node) {
if (spaceOrDescendantSelectorNodes) {
var _this$convertWhitespa2 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes),
_space = _this$convertWhitespa2.space,
_rawSpace = _this$convertWhitespa2.rawSpace;
node.spaces.before = _space;
node.rawSpaceBefore = _rawSpace;
}
} else {
// descendant combinator
var _this$convertWhitespa3 = this.convertWhitespaceNodesToSpace(spaceOrDescendantSelectorNodes, true),
_space2 = _this$convertWhitespa3.space,
_rawSpace2 = _this$convertWhitespa3.rawSpace;
if (!_rawSpace2) {
_rawSpace2 = _space2;
}
var spaces = {};
var raws = {
spaces: {}
};
if (_space2.endsWith(' ') && _rawSpace2.endsWith(' ')) {
spaces.before = _space2.slice(0, _space2.length - 1);
raws.spaces.before = _rawSpace2.slice(0, _rawSpace2.length - 1);
} else if (_space2[0] === ' ' && _rawSpace2[0] === ' ') {
spaces.after = _space2.slice(1);
raws.spaces.after = _rawSpace2.slice(1);
} else {
raws.value = _rawSpace2;
}
node = new _combinator["default"]({
value: ' ',
source: getTokenSourceSpan(firstToken, this.tokens[this.position - 1]),
sourceIndex: firstToken[_tokenize.FIELDS.START_POS],
spaces: spaces,
raws: raws
});
}
if (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.space) {
node.spaces.after = this.optionalSpace(this.content());
this.position++;
}
return this.newNode(node);
};
_proto.comma = function comma() {
if (this.position === this.tokens.length - 1) {
this.root.trailingComma = true;
this.position++;
return;
}
this.current._inferEndPosition();
var selector = new _selector["default"]({
source: {
start: tokenStart(this.tokens[this.position + 1])
},
sourceIndex: this.tokens[this.position + 1][_tokenize.FIELDS.START_POS]
});
this.current.parent.append(selector);
this.current = selector;
this.position++;
};
_proto.comment = function comment() {
var current = this.currToken;
this.newNode(new _comment["default"]({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[_tokenize.FIELDS.START_POS]
}));
this.position++;
};
_proto.error = function error(message, opts) {
throw this.root.error(message, opts);
};
_proto.missingBackslash = function missingBackslash() {
return this.error('Expected a backslash preceding the semicolon.', {
index: this.currToken[_tokenize.FIELDS.START_POS]
});
};
_proto.missingParenthesis = function missingParenthesis() {
return this.expected('opening parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
};
_proto.missingSquareBracket = function missingSquareBracket() {
return this.expected('opening square bracket', this.currToken[_tokenize.FIELDS.START_POS]);
};
_proto.unexpected = function unexpected() {
return this.error("Unexpected '" + this.content() + "'. Escaping special characters with \\ may help.", this.currToken[_tokenize.FIELDS.START_POS]);
};
_proto.unexpectedPipe = function unexpectedPipe() {
return this.error("Unexpected '|'.", this.currToken[_tokenize.FIELDS.START_POS]);
};
_proto.namespace = function namespace() {
var before = this.prevToken && this.content(this.prevToken) || true;
if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.word) {
this.position++;
return this.word(before);
} else if (this.nextToken[_tokenize.FIELDS.TYPE] === tokens.asterisk) {
this.position++;
return this.universal(before);
}
this.unexpectedPipe();
};
_proto.nesting = function nesting() {
if (this.nextToken) {
var nextContent = this.content(this.nextToken);
if (nextContent === "|") {
else if (this.nextToken[tokenize_1.FIELDS.TYPE] === tokens.asterisk) {
this.position++;
return this.universal(before);
}
this.unexpectedPipe();
};
Parser.prototype.nesting = function () {
if (this.nextToken) {
var nextContent = this.content(this.nextToken);
if (nextContent === "|") {
this.position++;
return;
}
}
var current = this.currToken;
this.newNode(new nesting_1.default({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[tokenize_1.FIELDS.START_POS],
}));
this.position++;
return;
}
}
var current = this.currToken;
this.newNode(new _nesting["default"]({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[_tokenize.FIELDS.START_POS]
}));
this.position++;
};
_proto.parentheses = function parentheses() {
var last = this.current.last;
var unbalanced = 1;
this.position++;
if (last && last.type === types.PSEUDO) {
var selector = new _selector["default"]({
source: {
start: tokenStart(this.tokens[this.position])
},
sourceIndex: this.tokens[this.position][_tokenize.FIELDS.START_POS]
});
var cache = this.current;
last.append(selector);
this.current = selector;
// Track nesting depth so deeply nested pseudo selectors raise a
// catchable error instead of overflowing the call stack. The
// counter is restored in `finally` so the parser is never left in
// an inconsistent state, even on the error path.
this.nestingDepth++;
try {
if (this.nestingDepth > this.maxNestingDepth) {
this.error("Cannot parse selector: nesting depth exceeds the maximum of " + this.maxNestingDepth + ".", {
index: this.currToken[_tokenize.FIELDS.START_POS]
});
};
Parser.prototype.parentheses = function () {
var last = this.current.last;
var unbalanced = 1;
this.position++;
if (last && last.type === types.PSEUDO) {
var selector = new selector_1.default({
source: { start: tokenStart(this.tokens[this.position]) },
sourceIndex: this.tokens[this.position][tokenize_1.FIELDS.START_POS],
});
var cache = this.current;
last.append(selector);
this.current = selector;
// Track nesting depth so deeply nested pseudo selectors raise a
// catchable error instead of overflowing the call stack. The
// counter is restored in `finally` so the parser is never left in
// an inconsistent state, even on the error path.
this.nestingDepth++;
try {
if (this.nestingDepth > this.maxNestingDepth) {
this.error("Cannot parse selector: nesting depth exceeds the maximum of ".concat(this.maxNestingDepth, "."), { index: this.currToken[tokenize_1.FIELDS.START_POS] });
}
while (this.position < this.tokens.length && unbalanced) {
if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.openParenthesis) {
unbalanced++;
}
if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.closeParenthesis) {
unbalanced--;
}
if (unbalanced) {
this.parse();
}
else {
this.current.source.end = tokenEnd(this.currToken);
this.current.parent.source.end = tokenEnd(this.currToken);
this.position++;
}
}
}
finally {
this.nestingDepth--;
}
this.current = cache;
}
while (this.position < this.tokens.length && unbalanced) {
if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
unbalanced++;
}
if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
unbalanced--;
}
if (unbalanced) {
this.parse();
} else {
this.current.source.end = tokenEnd(this.currToken);
this.current.parent.source.end = tokenEnd(this.currToken);
else {
// I think this case should be an error. It's used to implement a basic parse of media queries
// but I don't think it's a good idea.
var parenStart = this.currToken;
var parenValue = "(";
var parenEnd = void 0;
while (this.position < this.tokens.length && unbalanced) {
if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.openParenthesis) {
unbalanced++;
}
if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.closeParenthesis) {
unbalanced--;
}
parenEnd = this.currToken;
parenValue += this.parseParenthesisToken(this.currToken);
this.position++;
}
if (last) {
last.appendToPropertyAndEscape("value", parenValue, parenValue);
}
else {
this.newNode(new string_1.default({
value: parenValue,
source: getSource(parenStart[tokenize_1.FIELDS.START_LINE], parenStart[tokenize_1.FIELDS.START_COL], parenEnd[tokenize_1.FIELDS.END_LINE], parenEnd[tokenize_1.FIELDS.END_COL]),
sourceIndex: parenStart[tokenize_1.FIELDS.START_POS],
}));
}
}
if (unbalanced) {
return this.expected("closing parenthesis", this.currToken[tokenize_1.FIELDS.START_POS]);
}
};
Parser.prototype.pseudo = function () {
var _this = this;
var pseudoStr = "";
var startingToken = this.currToken;
while (this.currToken && this.currToken[tokenize_1.FIELDS.TYPE] === tokens.colon) {
pseudoStr += this.content();
this.position++;
}
}
} finally {
this.nestingDepth--;
}
this.current = cache;
} else {
// I think this case should be an error. It's used to implement a basic parse of media queries
// but I don't think it's a good idea.
var parenStart = this.currToken;
var parenValue = "(";
var parenEnd;
while (this.position < this.tokens.length && unbalanced) {
if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
unbalanced++;
if (!this.currToken) {
return this.expected(["pseudo-class", "pseudo-element"], this.position - 1);
}
if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
unbalanced--;
if (this.currToken[tokenize_1.FIELDS.TYPE] === tokens.word) {
this.splitWord(false, function (first, length) {
pseudoStr += first;
_this.newNode(new pseudo_1.default({
value: pseudoStr,
source: getTokenSourceSpan(startingToken, _this.currToken),
sourceIndex: startingToken[tokenize_1.FIELDS.START_POS],
}));
if (length > 1 && _this.nextToken && _this.nextToken[tokenize_1.FIELDS.TYPE] === tokens.openParenthesis) {
_this.error("Misplaced parenthesis.", {
index: _this.nextToken[tokenize_1.FIELDS.START_POS],
});
}
});
}
parenEnd = this.currToken;
parenValue += this.parseParenthesisToken(this.currToken);
else {
return this.expected(["pseudo-class", "pseudo-element"], this.currToken[tokenize_1.FIELDS.START_POS]);
}
};
Parser.prototype.space = function () {
var content = this.content();
// Handle space before and after the selector
if (this.position === 0 ||
this.prevToken[tokenize_1.FIELDS.TYPE] === tokens.comma ||
this.prevToken[tokenize_1.FIELDS.TYPE] === tokens.openParenthesis ||
this.current.nodes.every(function (node) { return node.type === "comment"; })) {
this.spaces = this.optionalSpace(content);
this.position++;
}
else if (this.position === this.tokens.length - 1 ||
this.nextToken[tokenize_1.FIELDS.TYPE] === tokens.comma ||
this.nextToken[tokenize_1.FIELDS.TYPE] === tokens.closeParenthesis) {
this.current.last.spaces.after = this.optionalSpace(content);
this.position++;
}
else {
this.combinator();
}
};
Parser.prototype.string = function () {
var current = this.currToken;
this.newNode(new string_1.default({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[tokenize_1.FIELDS.START_POS],
}));
this.position++;
}
if (last) {
last.appendToPropertyAndEscape("value", parenValue, parenValue);
} else {
this.newNode(new _string["default"]({
value: parenValue,
source: getSource(parenStart[_tokenize.FIELDS.START_LINE], parenStart[_tokenize.FIELDS.START_COL], parenEnd[_tokenize.FIELDS.END_LINE], parenEnd[_tokenize.FIELDS.END_COL]),
sourceIndex: parenStart[_tokenize.FIELDS.START_POS]
}));
}
}
if (unbalanced) {
return this.expected('closing parenthesis', this.currToken[_tokenize.FIELDS.START_POS]);
}
};
_proto.pseudo = function pseudo() {
var _this4 = this;
var pseudoStr = '';
var startingToken = this.currToken;
while (this.currToken && this.currToken[_tokenize.FIELDS.TYPE] === tokens.colon) {
pseudoStr += this.content();
this.position++;
}
if (!this.currToken) {
return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
}
if (this.currToken[_tokenize.FIELDS.TYPE] === tokens.word) {
this.splitWord(false, function (first, length) {
pseudoStr += first;
_this4.newNode(new _pseudo["default"]({
value: pseudoStr,
source: getTokenSourceSpan(startingToken, _this4.currToken),
sourceIndex: startingToken[_tokenize.FIELDS.START_POS]
}));
if (length > 1 && _this4.nextToken && _this4.nextToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis) {
_this4.error('Misplaced parenthesis.', {
index: _this4.nextToken[_tokenize.FIELDS.START_POS]
});
};
Parser.prototype.universal = function (namespace) {
var nextToken = this.nextToken;
if (nextToken && this.content(nextToken) === "|") {
this.position++;
return this.namespace();
}
});
} else {
return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[_tokenize.FIELDS.START_POS]);
}
};
_proto.space = function space() {
var content = this.content();
// Handle space before and after the selector
if (this.position === 0 || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.prevToken[_tokenize.FIELDS.TYPE] === tokens.openParenthesis || this.current.nodes.every(function (node) {
return node.type === 'comment';
})) {
this.spaces = this.optionalSpace(content);
this.position++;
} else if (this.position === this.tokens.length - 1 || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.comma || this.nextToken[_tokenize.FIELDS.TYPE] === tokens.closeParenthesis) {
this.current.last.spaces.after = this.optionalSpace(content);
this.position++;
} else {
this.combinator();
}
};
_proto.string = function string() {
var current = this.currToken;
this.newNode(new _string["default"]({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[_tokenize.FIELDS.START_POS]
}));
this.position++;
};
_proto.universal = function universal(namespace) {
var nextToken = this.nextToken;
if (nextToken && this.content(nextToken) === '|') {
this.position++;
return this.namespace();
}
var current = this.currToken;
this.newNode(new _universal["default"]({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[_tokenize.FIELDS.START_POS]
}), namespace);
this.position++;
};
_proto.splitWord = function splitWord(namespace, firstCallback) {
var _this5 = this;
var nextToken = this.nextToken;
var word = this.content();
while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[_tokenize.FIELDS.TYPE])) {
this.position++;
var current = this.content();
word += current;
if (current.lastIndexOf('\\') === current.length - 1) {
var next = this.nextToken;
if (next && next[_tokenize.FIELDS.TYPE] === tokens.space) {
word += this.requiredSpace(this.content(next));
this.position++;
var current = this.currToken;
this.newNode(new universal_1.default({
value: this.content(),
source: getTokenSource(current),
sourceIndex: current[tokenize_1.FIELDS.START_POS],
}), namespace);
this.position++;
};
Parser.prototype.splitWord = function (namespace, firstCallback) {
var _this = this;
var nextToken = this.nextToken;
var word = this.content();
while (nextToken &&
~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[tokenize_1.FIELDS.TYPE])) {
this.position++;
var current = this.content();
word += current;
if (current.lastIndexOf("\\") === current.length - 1) {
var next = this.nextToken;
if (next && next[tokenize_1.FIELDS.TYPE] === tokens.space) {
word += this.requiredSpace(this.content(next));
this.position++;
}
}
nextToken = this.nextToken;
}
}
nextToken = this.nextToken;
}
var hasClass = indexesOf(word, '.').filter(function (i) {
// Allow escaped dot within class name
var escapedDot = word[i - 1] === '\\';
// Allow decimal numbers percent in @keyframes
var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
return !escapedDot && !isKeyframesPercent;
var hasClass = indexesOf(word, ".").filter(function (i) {
// Allow escaped dot within class name
var escapedDot = word[i - 1] === "\\";
// Allow decimal numbers percent in @keyframes
var isKeyframesPercent = /^\d+\.\d+%$/.test(word);
return !escapedDot && !isKeyframesPercent;
});
var hasId = indexesOf(word, "#").filter(function (i) { return word[i - 1] !== "\\"; });
// Eliminate Sass interpolations from the list of id indexes
var interpolations = indexesOf(word, "#{");
if (interpolations.length) {
hasId = hasId.filter(function (hashIndex) { return !~interpolations.indexOf(hashIndex); });
}
var indices = (0, sortAscending_1.default)(uniqs(__spreadArray(__spreadArray([0], __read(hasClass), false), __read(hasId), false)));
indices.forEach(function (ind, i) {
var index = indices[i + 1] || word.length;
var value = word.slice(ind, index);
if (i === 0 && firstCallback) {
return firstCallback.call(_this, value, indices.length);
}
var node;
var current = _this.currToken;
var sourceIndex = current[tokenize_1.FIELDS.START_POS] + indices[i];
var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
if (~hasClass.indexOf(ind)) {
var classNameOpts = {
value: value.slice(1),
source: source,
sourceIndex: sourceIndex,
};
node = new className_1.default(unescapeProp(classNameOpts, "value"));
}
else if (~hasId.indexOf(ind)) {
var idOpts = {
value: value.slice(1),
source: source,
sourceIndex: sourceIndex,
};
node = new id_1.default(unescapeProp(idOpts, "value"));
}
else {
var tagOpts = {
value: value,
source: source,
sourceIndex: sourceIndex,
};
unescapeProp(tagOpts, "value");
node = new tag_1.default(tagOpts);
}
_this.newNode(node, namespace);
// Ensure that the namespace is used only once
namespace = null;
});
this.position++;
};
Parser.prototype.word = function (namespace) {
var nextToken = this.nextToken;
if (nextToken && this.content(nextToken) === "|") {
this.position++;
return this.namespace();
}
return this.splitWord(namespace);
};
Parser.prototype.loop = function () {
while (this.position < this.tokens.length) {
this.parse(true);
}
this.current._inferEndPosition();
return this.root;
};
Parser.prototype.parse = function (throwOnParenthesis) {
switch (this.currToken[tokenize_1.FIELDS.TYPE]) {
case tokens.space:
this.space();
break;
case tokens.comment:
this.comment();
break;
case tokens.openParenthesis:
this.parentheses();
break;
case tokens.closeParenthesis:
if (throwOnParenthesis) {
this.missingParenthesis();
}
break;
case tokens.openSquare:
this.attribute();
break;
case tokens.dollar:
case tokens.caret:
case tokens.equals:
case tokens.word:
this.word();
break;
case tokens.colon:
this.pseudo();
break;
case tokens.comma:
this.comma();
break;
case tokens.asterisk:
this.universal();
break;
case tokens.ampersand:
this.nesting();
break;
case tokens.slash:
case tokens.combinator:
this.combinator();
break;
case tokens.str:
this.string();
break;
// These cases throw; no break needed.
case tokens.closeSquare:
this.missingSquareBracket();
case tokens.semicolon:
this.missingBackslash();
default:
this.unexpected();
}
};
/**
* Helpers
*/
Parser.prototype.expected = function (description, index, found) {
if (Array.isArray(description)) {
var last = description.pop();
description = "".concat(description.join(", "), " or ").concat(last);
}
var an = /^[aeiou]/.test(description[0]) ? "an" : "a";
if (!found) {
return this.error("Expected ".concat(an, " ").concat(description, "."), { index: index });
}
return this.error("Expected ".concat(an, " ").concat(description, ", found \"").concat(found, "\" instead."), { index: index });
};
Parser.prototype.requiredSpace = function (space) {
return this.options.lossy ? " " : space;
};
Parser.prototype.optionalSpace = function (space) {
return this.options.lossy ? "" : space;
};
Parser.prototype.lossySpace = function (space, required) {
if (this.options.lossy) {
return required ? " " : "";
}
else {
return space;
}
};
Parser.prototype.parseParenthesisToken = function (token) {
var content = this.content(token);
if (token[tokenize_1.FIELDS.TYPE] === tokens.space) {
return this.requiredSpace(content);
}
else {
return content;
}
};
Parser.prototype.newNode = function (node, namespace) {
if (namespace) {
if (/^ +$/.test(namespace)) {
if (!this.options.lossy) {
this.spaces = (this.spaces || "") + namespace;
}
namespace = true;
}
node.namespace = namespace;
unescapeProp(node, "namespace");
}
if (this.spaces) {
node.spaces.before = this.spaces;
this.spaces = "";
}
return this.current.append(node);
};
Parser.prototype.content = function (token) {
if (token === void 0) { token = this.currToken; }
return this.css.slice(token[tokenize_1.FIELDS.START_POS], token[tokenize_1.FIELDS.END_POS]);
};
Object.defineProperty(Parser.prototype, "currToken", {
get: function () {
return this.tokens[this.position];
},
enumerable: false,
configurable: true
});
var hasId = indexesOf(word, '#').filter(function (i) {
return word[i - 1] !== '\\';
Object.defineProperty(Parser.prototype, "nextToken", {
get: function () {
return this.tokens[this.position + 1];
},
enumerable: false,
configurable: true
});
// Eliminate Sass interpolations from the list of id indexes
var interpolations = indexesOf(word, '#{');
if (interpolations.length) {
hasId = hasId.filter(function (hashIndex) {
return !~interpolations.indexOf(hashIndex);
});
}
var indices = (0, _sortAscending["default"])(uniqs([0].concat(hasClass, hasId)));
indices.forEach(function (ind, i) {
var index = indices[i + 1] || word.length;
var value = word.slice(ind, index);
if (i === 0 && firstCallback) {
return firstCallback.call(_this5, value, indices.length);
}
var node;
var current = _this5.currToken;
var sourceIndex = current[_tokenize.FIELDS.START_POS] + indices[i];
var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
if (~hasClass.indexOf(ind)) {
var classNameOpts = {
value: value.slice(1),
source: source,
sourceIndex: sourceIndex
};
node = new _className["default"](unescapeProp(classNameOpts, "value"));
} else if (~hasId.indexOf(ind)) {
var idOpts = {
value: value.slice(1),
source: source,
sourceIndex: sourceIndex
};
node = new _id["default"](unescapeProp(idOpts, "value"));
} else {
var tagOpts = {
value: value,
source: source,
sourceIndex: sourceIndex
};
unescapeProp(tagOpts, "value");
node = new _tag["default"](tagOpts);
}
_this5.newNode(node, namespace);
// Ensure that the namespace is used only once
namespace = null;
Object.defineProperty(Parser.prototype, "prevToken", {
get: function () {
return this.tokens[this.position - 1];
},
enumerable: false,
configurable: true
});
this.position++;
};
_proto.word = function word(namespace) {
var nextToken = this.nextToken;
if (nextToken && this.content(nextToken) === '|') {
this.position++;
return this.namespace();
}
return this.splitWord(namespace);
};
_proto.loop = function loop() {
while (this.position < this.tokens.length) {
this.parse(true);
}
this.current._inferEndPosition();
return this.root;
};
_proto.parse = function parse(throwOnParenthesis) {
switch (this.currToken[_tokenize.FIELDS.TYPE]) {
case tokens.space:
this.space();
break;
case tokens.comment:
this.comment();
break;
case tokens.openParenthesis:
this.parentheses();
break;
case tokens.closeParenthesis:
if (throwOnParenthesis) {
this.missingParenthesis();
/**
* returns the index of the next non-whitespace, non-comment token.
* returns -1 if no meaningful token is found.
*/
Parser.prototype.locateNextMeaningfulToken = function (startPosition) {
if (startPosition === void 0) { startPosition = this.position + 1; }
var searchPosition = startPosition;
while (searchPosition < this.tokens.length) {
if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][tokenize_1.FIELDS.TYPE]]) {
searchPosition++;
continue;
}
else {
return searchPosition;
}
}
break;
case tokens.openSquare:
this.attribute();
break;
case tokens.dollar:
case tokens.caret:
case tokens.equals:
case tokens.word:
this.word();
break;
case tokens.colon:
this.pseudo();
break;
case tokens.comma:
this.comma();
break;
case tokens.asterisk:
this.universal();
break;
case tokens.ampersand:
this.nesting();
break;
case tokens.slash:
case tokens.combinator:
this.combinator();
break;
case tokens.str:
this.string();
break;
// These cases throw; no break needed.
case tokens.closeSquare:
this.missingSquareBracket();
case tokens.semicolon:
this.missingBackslash();
default:
this.unexpected();
}
}
/**
* Helpers
*/;
_proto.expected = function expected(description, index, found) {
if (Array.isArray(description)) {
var last = description.pop();
description = description.join(', ') + " or " + last;
}
var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
if (!found) {
return this.error("Expected " + an + " " + description + ".", {
index: index
});
}
return this.error("Expected " + an + " " + description + ", found \"" + found + "\" instead.", {
index: index
});
};
_proto.requiredSpace = function requiredSpace(space) {
return this.options.lossy ? ' ' : space;
};
_proto.optionalSpace = function optionalSpace(space) {
return this.options.lossy ? '' : space;
};
_proto.lossySpace = function lossySpace(space, required) {
if (this.options.lossy) {
return required ? ' ' : '';
} else {
return space;
}
};
_proto.parseParenthesisToken = function parseParenthesisToken(token) {
var content = this.content(token);
if (token[_tokenize.FIELDS.TYPE] === tokens.space) {
return this.requiredSpace(content);
} else {
return content;
}
};
_proto.newNode = function newNode(node, namespace) {
if (namespace) {
if (/^ +$/.test(namespace)) {
if (!this.options.lossy) {
this.spaces = (this.spaces || '') + namespace;
}
namespace = true;
}
node.namespace = namespace;
unescapeProp(node, "namespace");
}
if (this.spaces) {
node.spaces.before = this.spaces;
this.spaces = '';
}
return this.current.append(node);
};
_proto.content = function content(token) {
if (token === void 0) {
token = this.currToken;
}
return this.css.slice(token[_tokenize.FIELDS.START_POS], token[_tokenize.FIELDS.END_POS]);
};
/**
* returns the index of the next non-whitespace, non-comment token.
* returns -1 if no meaningful token is found.
*/
_proto.locateNextMeaningfulToken = function locateNextMeaningfulToken(startPosition) {
if (startPosition === void 0) {
startPosition = this.position + 1;
}
var searchPosition = startPosition;
while (searchPosition < this.tokens.length) {
if (WHITESPACE_EQUIV_TOKENS[this.tokens[searchPosition][_tokenize.FIELDS.TYPE]]) {
searchPosition++;
continue;
} else {
return searchPosition;
}
}
return -1;
};
_createClass(Parser, [{
key: "currToken",
get: function get() {
return this.tokens[this.position];
}
}, {
key: "nextToken",
get: function get() {
return this.tokens[this.position + 1];
}
}, {
key: "prevToken",
get: function get() {
return this.tokens[this.position - 1];
}
}]);
return Parser;
}();
module.exports = exports.default;
return -1;
};
return Parser;
}());
exports.default = Parser;
//# sourceMappingURL=parser.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _parser = _interopRequireDefault(require("./parser"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var Processor = exports["default"] = /*#__PURE__*/function () {
function Processor(func, options) {
this.func = func || function noop() {};
this.funcRes = null;
this.options = options;
}
var _proto = Processor.prototype;
_proto._shouldUpdateSelector = function _shouldUpdateSelector(rule, options) {
if (options === void 0) {
options = {};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var parser_1 = __importDefault(require("./parser"));
var Processor = /** @class */ (function () {
function Processor(func, options) {
this.func = func || function noop() { };
this.funcRes = null;
this.options = options;
}
var merged = Object.assign({}, this.options, options);
if (merged.updateSelector === false) {
return false;
} else {
return typeof rule !== "string";
}
};
_proto._isLossy = function _isLossy(options) {
if (options === void 0) {
options = {};
}
var merged = Object.assign({}, this.options, options);
if (merged.lossless === false) {
return true;
} else {
return false;
}
};
_proto._root = function _root(rule, options) {
if (options === void 0) {
options = {};
}
var parser = new _parser["default"](rule, this._parseOptions(options));
return parser.root;
};
_proto._parseOptions = function _parseOptions(options) {
var merged = Object.assign({}, this.options, options);
return {
lossy: this._isLossy(merged),
maxNestingDepth: merged.maxNestingDepth
Processor.prototype._shouldUpdateSelector = function (rule, options) {
if (options === void 0) { options = {}; }
var merged = Object.assign({}, this.options, options);
if (merged.updateSelector === false) {
return false;
}
else {
return typeof rule !== "string";
}
};
};
_proto._stringifyOptions = function _stringifyOptions(options) {
var merged = Object.assign({}, this.options, options);
return {
maxNestingDepth: merged.maxNestingDepth
Processor.prototype._isLossy = function (options) {
if (options === void 0) { options = {}; }
var merged = Object.assign({}, this.options, options);
if (merged.lossless === false) {
return true;
}
else {
return false;
}
};
};
_proto._run = function _run(rule, options) {
var _this = this;
if (options === void 0) {
options = {};
}
return new Promise(function (resolve, reject) {
try {
var root = _this._root(rule, options);
Promise.resolve(_this.func(root)).then(function (transform) {
var string = undefined;
if (_this._shouldUpdateSelector(rule, options)) {
string = root.toString(_this._stringifyOptions(options));
Processor.prototype._root = function (rule, options) {
if (options === void 0) { options = {}; }
var parser = new parser_1.default(rule, this._parseOptions(options));
return parser.root;
};
Processor.prototype._parseOptions = function (options) {
var merged = Object.assign({}, this.options, options);
return {
lossy: this._isLossy(merged),
maxNestingDepth: merged.maxNestingDepth,
};
};
Processor.prototype._stringifyOptions = function (options) {
var merged = Object.assign({}, this.options, options);
return {
maxNestingDepth: merged.maxNestingDepth,
};
};
Processor.prototype._run = function (rule, options) {
var _this = this;
if (options === void 0) { options = {}; }
return new Promise(function (resolve, reject) {
try {
var root_1 = _this._root(rule, options);
Promise.resolve(_this.func(root_1))
.then(function (transform) {
var string = undefined;
if (_this._shouldUpdateSelector(rule, options)) {
string = root_1.toString(_this._stringifyOptions(options));
rule.selector = string;
}
return { transform: transform, root: root_1, string: string };
})
.then(resolve, reject);
}
catch (e) {
reject(e);
return;
}
});
};
Processor.prototype._runSync = function (rule, options) {
if (options === void 0) { options = {}; }
var root = this._root(rule, options);
var transform = this.func(root);
if (transform && typeof transform.then === "function") {
throw new Error("Selector processor returned a promise to a synchronous call.");
}
var string = undefined;
if (options.updateSelector && typeof rule !== "string") {
string = root.toString(this._stringifyOptions(options));
rule.selector = string;
}
return {
transform: transform,
root: root,
string: string
};
}).then(resolve, reject);
} catch (e) {
reject(e);
return;
}
});
};
_proto._runSync = function _runSync(rule, options) {
if (options === void 0) {
options = {};
}
var root = this._root(rule, options);
var transform = this.func(root);
if (transform && typeof transform.then === "function") {
throw new Error("Selector processor returned a promise to a synchronous call.");
}
var string = undefined;
if (options.updateSelector && typeof rule !== "string") {
string = root.toString(this._stringifyOptions(options));
rule.selector = string;
}
return {
transform: transform,
root: root,
string: string
}
return { transform: transform, root: root, string: string };
};
}
/**
* Process rule into a selector AST.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<parser.Root>} The AST of the selector after processing it.
*/;
_proto.ast = function ast(rule, options) {
return this._run(rule, options).then(function (result) {
return result.root;
});
}
/**
* Process rule into a selector AST synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {parser.Root} The AST of the selector after processing it.
*/;
_proto.astSync = function astSync(rule, options) {
return this._runSync(rule, options).root;
}
/**
* Process a selector into a transformed value asynchronously
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<any>} The value returned by the processor.
*/;
_proto.transform = function transform(rule, options) {
return this._run(rule, options).then(function (result) {
return result.transform;
});
}
/**
* Process a selector into a transformed value synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {any} The value returned by the processor.
*/;
_proto.transformSync = function transformSync(rule, options) {
return this._runSync(rule, options).transform;
}
/**
* Process a selector into a new selector string asynchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/;
_proto.process = function process(rule, options) {
var _this2 = this;
return this._run(rule, options).then(function (result) {
return result.string || result.root.toString(_this2._stringifyOptions(options));
});
}
/**
* Process a selector into a new selector string synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/;
_proto.processSync = function processSync(rule, options) {
var result = this._runSync(rule, options);
return result.string || result.root.toString(this._stringifyOptions(options));
};
return Processor;
}();
module.exports = exports.default;
/**
* Process rule into a selector AST.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<parser.Root>} The AST of the selector after processing it.
*/
Processor.prototype.ast = function (rule, options) {
return this._run(rule, options).then(function (result) { return result.root; });
};
/**
* Process rule into a selector AST synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {parser.Root} The AST of the selector after processing it.
*/
Processor.prototype.astSync = function (rule, options) {
return this._runSync(rule, options).root;
};
/**
* Process a selector into a transformed value asynchronously
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<any>} The value returned by the processor.
*/
Processor.prototype.transform = function (rule, options) {
return this._run(rule, options).then(function (result) { return result.transform; });
};
/**
* Process a selector into a transformed value synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {any} The value returned by the processor.
*/
Processor.prototype.transformSync = function (rule, options) {
return this._runSync(rule, options).transform;
};
/**
* Process a selector into a new selector string asynchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/
Processor.prototype.process = function (rule, options) {
var _this = this;
return this._run(rule, options).then(function (result) { return result.string || result.root.toString(_this._stringifyOptions(options)); });
};
/**
* Process a selector into a new selector string synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/
Processor.prototype.processSync = function (rule, options) {
var result = this._runSync(rule, options);
return result.string || result.root.toString(this._stringifyOptions(options));
};
return Processor;
}());
exports.default = Processor;
//# sourceMappingURL=processor.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unescapeValue = unescapeValue;
var _cssesc = _interopRequireDefault(require("cssesc"));
var _unesc = _interopRequireDefault(require("../util/unesc"));
var _namespace = _interopRequireDefault(require("./namespace"));
var _types = require("./types");
var _CSSESC_QUOTE_OPTIONS;
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var cssesc_1 = __importDefault(require("cssesc"));
var unesc_1 = __importDefault(require("../util/unesc"));
var namespace_1 = __importDefault(require("./namespace"));
var types_1 = require("./types");
var deprecate = require("util-deprecate");
var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
var warnOfDeprecatedValueAssignment = deprecate(function () { }, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " +
"Call attribute.setValue() instead.");
var warnOfDeprecatedQuotedAssignment = deprecate(function () { }, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
var warnOfDeprecatedConstructor = deprecate(function () { }, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
function unescapeValue(value) {
var deprecatedUsage = false;
var quoteMark = null;
var unescaped = value;
var m = unescaped.match(WRAPPED_IN_QUOTES);
if (m) {
quoteMark = m[1];
unescaped = m[2];
}
unescaped = (0, _unesc["default"])(unescaped);
if (unescaped !== value) {
deprecatedUsage = true;
}
return {
deprecatedUsage: deprecatedUsage,
unescaped: unescaped,
quoteMark: quoteMark
};
}
function handleDeprecatedContructorOpts(opts) {
if (opts.quoteMark !== undefined) {
return opts;
}
if (opts.value === undefined) {
return opts;
}
warnOfDeprecatedConstructor();
var _unescapeValue = unescapeValue(opts.value),
quoteMark = _unescapeValue.quoteMark,
unescaped = _unescapeValue.unescaped;
if (!opts.raws) {
opts.raws = {};
}
if (opts.raws.value === undefined) {
opts.raws.value = opts.value;
}
opts.value = unescaped;
opts.quoteMark = quoteMark;
return opts;
}
var Attribute = exports["default"] = /*#__PURE__*/function (_Namespace) {
_inheritsLoose(Attribute, _Namespace);
function Attribute(opts) {
var _this;
if (opts === void 0) {
opts = {};
var deprecatedUsage = false;
var quoteMark = null;
var unescaped = value;
var m = unescaped.match(WRAPPED_IN_QUOTES);
if (m) {
quoteMark = m[1];
unescaped = m[2];
}
_this = _Namespace.call(this, handleDeprecatedContructorOpts(opts)) || this;
_this.type = _types.ATTRIBUTE;
_this.raws = _this.raws || {};
Object.defineProperty(_this.raws, 'unquoted', {
get: deprecate(function () {
return _this.value;
}, "attr.raws.unquoted is deprecated. Call attr.value instead."),
set: deprecate(function () {
return _this.value;
}, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
});
_this._constructed = true;
return _this;
}
/**
* Returns the Attribute's value quoted such that it would be legal to use
* in the value of a css file. The original value's quotation setting
* used for stringification is left unchanged. See `setValue(value, options)`
* if you want to control the quote settings of a new value for the attribute.
*
* You can also change the quotation used for the current value by setting quoteMark.
*
* Options:
* * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
* option is not set, the original value for quoteMark will be used. If
* indeterminate, a double quote is used. The legal values are:
* * `null` - the value will be unquoted and characters will be escaped as necessary.
* * `'` - the value will be quoted with a single quote and single quotes are escaped.
* * `"` - the value will be quoted with a double quote and double quotes are escaped.
* * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
* over the quoteMark option value.
* * smart {boolean} - if true, will select a quote mark based on the value
* and the other options specified here. See the `smartQuoteMark()`
* method.
**/
var _proto = Attribute.prototype;
_proto.getQuotedValue = function getQuotedValue(options) {
if (options === void 0) {
options = {};
unescaped = (0, unesc_1.default)(unescaped);
if (unescaped !== value) {
deprecatedUsage = true;
}
var quoteMark = this._determineQuoteMark(options);
var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
var escaped = (0, _cssesc["default"])(this._value, cssescopts);
return escaped;
};
_proto._determineQuoteMark = function _determineQuoteMark(options) {
return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
}
/**
* Set the unescaped value with the specified quotation options. The value
* provided must not include any wrapping quote marks -- those quotes will
* be interpreted as part of the value and escaped accordingly.
*/;
_proto.setValue = function setValue(value, options) {
if (options === void 0) {
options = {};
}
this._value = value;
this._quoteMark = this._determineQuoteMark(options);
this._syncRawValue();
}
/**
* Intelligently select a quoteMark value based on the value's contents. If
* the value is a legal CSS ident, it will not be quoted. Otherwise a quote
* mark will be picked that minimizes the number of escapes.
*
* If there's no clear winner, the quote mark from these options is used,
* then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
* true). If the quoteMark is unspecified, a double quote is used.
*
* @param options This takes the quoteMark and preferCurrentQuoteMark options
* from the quoteValue method.
*/;
_proto.smartQuoteMark = function smartQuoteMark(options) {
var v = this.value;
var numSingleQuotes = v.replace(/[^']/g, '').length;
var numDoubleQuotes = v.replace(/[^"]/g, '').length;
if (numSingleQuotes + numDoubleQuotes === 0) {
var escaped = (0, _cssesc["default"])(v, {
isIdentifier: true
});
if (escaped === v) {
return Attribute.NO_QUOTE;
} else {
var pref = this.preferredQuoteMark(options);
if (pref === Attribute.NO_QUOTE) {
// pick a quote mark that isn't none and see if it's smaller
var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
var opts = CSSESC_QUOTE_OPTIONS[quote];
var quoteValue = (0, _cssesc["default"])(v, opts);
if (quoteValue.length < escaped.length) {
return quote;
}
}
return pref;
}
} else if (numDoubleQuotes === numSingleQuotes) {
return this.preferredQuoteMark(options);
} else if (numDoubleQuotes < numSingleQuotes) {
return Attribute.DOUBLE_QUOTE;
} else {
return Attribute.SINGLE_QUOTE;
}
}
/**
* Selects the preferred quote mark based on the options and the current quote mark value.
* If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
* instead.
*/;
_proto.preferredQuoteMark = function preferredQuoteMark(options) {
var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
if (quoteMark === undefined) {
quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
}
if (quoteMark === undefined) {
quoteMark = Attribute.DOUBLE_QUOTE;
}
return quoteMark;
};
_proto._syncRawValue = function _syncRawValue() {
var rawValue = (0, _cssesc["default"])(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
if (rawValue === this._value) {
if (this.raws) {
delete this.raws.value;
}
} else {
this.raws.value = rawValue;
}
};
_proto._handleEscapes = function _handleEscapes(prop, value) {
if (this._constructed) {
var escaped = (0, _cssesc["default"])(value, {
isIdentifier: true
});
if (escaped !== value) {
this.raws[prop] = escaped;
} else {
delete this.raws[prop];
}
}
};
_proto._spacesFor = function _spacesFor(name) {
var attrSpaces = {
before: '',
after: ''
return {
deprecatedUsage: deprecatedUsage,
unescaped: unescaped,
quoteMark: quoteMark,
};
var spaces = this.spaces[name] || {};
var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
return Object.assign(attrSpaces, spaces, rawSpaces);
};
_proto._stringFor = function _stringFor(name, spaceName, concat) {
if (spaceName === void 0) {
spaceName = name;
}
function handleDeprecatedContructorOpts(opts) {
if (opts.quoteMark !== undefined) {
return opts;
}
if (concat === void 0) {
concat = defaultAttrConcat;
if (opts.value === undefined) {
return opts;
}
var attrSpaces = this._spacesFor(spaceName);
return concat(this.stringifyProperty(name), attrSpaces);
}
/**
* returns the offset of the attribute part specified relative to the
* start of the node of the output string.
*
* * "ns" - alias for "namespace"
* * "namespace" - the namespace if it exists.
* * "attribute" - the attribute name
* * "attributeNS" - the start of the attribute or its namespace
* * "operator" - the match operator of the attribute
* * "value" - The value (string or identifier)
* * "insensitive" - the case insensitivity flag;
* @param part One of the possible values inside an attribute.
* @returns -1 if the name is invalid or the value doesn't exist in this attribute.
*/;
_proto.offsetOf = function offsetOf(name) {
var count = 1;
var attributeSpaces = this._spacesFor("attribute");
count += attributeSpaces.before.length;
if (name === "namespace" || name === "ns") {
return this.namespace ? count : -1;
warnOfDeprecatedConstructor();
var _a = unescapeValue(opts.value), quoteMark = _a.quoteMark, unescaped = _a.unescaped;
if (!opts.raws) {
opts.raws = {};
}
if (name === "attributeNS") {
return count;
if (opts.raws.value === undefined) {
opts.raws.value = opts.value;
}
count += this.namespaceString.length;
if (this.namespace) {
count += 1;
opts.value = unescaped;
opts.quoteMark = quoteMark;
return opts;
}
var Attribute = /** @class */ (function (_super) {
__extends(Attribute, _super);
function Attribute(opts) {
if (opts === void 0) { opts = {}; }
var _this = _super.call(this, handleDeprecatedContructorOpts(opts)) || this;
_this.type = types_1.ATTRIBUTE;
_this.raws = _this.raws || {};
Object.defineProperty(_this.raws, "unquoted", {
get: deprecate(function () { return _this.value; }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
set: deprecate(function () { return _this.value; }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now."),
});
_this._constructed = true;
return _this;
}
if (name === "attribute") {
return count;
}
count += this.stringifyProperty("attribute").length;
count += attributeSpaces.after.length;
var operatorSpaces = this._spacesFor("operator");
count += operatorSpaces.before.length;
var operator = this.stringifyProperty("operator");
if (name === "operator") {
return operator ? count : -1;
}
count += operator.length;
count += operatorSpaces.after.length;
var valueSpaces = this._spacesFor("value");
count += valueSpaces.before.length;
var value = this.stringifyProperty("value");
if (name === "value") {
return value ? count : -1;
}
count += value.length;
count += valueSpaces.after.length;
var insensitiveSpaces = this._spacesFor("insensitive");
count += insensitiveSpaces.before.length;
if (name === "insensitive") {
return this.insensitive ? count : -1;
}
return -1;
};
_proto.toString = function toString() {
var _this2 = this;
var selector = [this.rawSpaceBefore, '['];
selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
if (this.operator && (this.value || this.value === '')) {
selector.push(this._stringFor('operator'));
selector.push(this._stringFor('value'));
selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
attrSpaces.before = " ";
}
return defaultAttrConcat(attrValue, attrSpaces);
}));
}
selector.push(']');
selector.push(this.rawSpaceAfter);
return selector.join('');
};
_createClass(Attribute, [{
key: "quoted",
get: function get() {
var qm = this.quoteMark;
return qm === "'" || qm === '"';
},
set: function set(value) {
warnOfDeprecatedQuotedAssignment();
}
/**
* returns a single (`'`) or double (`"`) quote character if the value is quoted.
* returns `null` if the value is not quoted.
* returns `undefined` if the quotation state is unknown (this can happen when
* the attribute is constructed without specifying a quote mark.)
* Returns the Attribute's value quoted such that it would be legal to use
* in the value of a css file. The original value's quotation setting
* used for stringification is left unchanged. See `setValue(value, options)`
* if you want to control the quote settings of a new value for the attribute.
*
* You can also change the quotation used for the current value by setting quoteMark.
*
* Options:
* * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
* option is not set, the original value for quoteMark will be used. If
* indeterminate, a double quote is used. The legal values are:
* * `null` - the value will be unquoted and characters will be escaped as necessary.
* * `'` - the value will be quoted with a single quote and single quotes are escaped.
* * `"` - the value will be quoted with a double quote and double quotes are escaped.
* * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
* over the quoteMark option value.
* * smart {boolean} - if true, will select a quote mark based on the value
* and the other options specified here. See the `smartQuoteMark()`
* method.
**/
Attribute.prototype.getQuotedValue = function (options) {
if (options === void 0) { options = {}; }
var quoteMark = this._determineQuoteMark(options);
var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
var escaped = (0, cssesc_1.default)(this._value, cssescopts);
return escaped;
};
Attribute.prototype._determineQuoteMark = function (options) {
return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
};
/**
* Set the unescaped value with the specified quotation options. The value
* provided must not include any wrapping quote marks -- those quotes will
* be interpreted as part of the value and escaped accordingly.
*/
}, {
key: "quoteMark",
get: function get() {
return this._quoteMark;
}
/**
* Set the quote mark to be used by this attribute's value.
* If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
* value is updated accordingly.
*
* @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
*/,
set: function set(quoteMark) {
if (!this._constructed) {
this._quoteMark = quoteMark;
return;
}
if (this._quoteMark !== quoteMark) {
this._quoteMark = quoteMark;
Attribute.prototype.setValue = function (value, options) {
if (options === void 0) { options = {}; }
this._value = value;
this._quoteMark = this._determineQuoteMark(options);
this._syncRawValue();
}
}
}, {
key: "qualifiedAttribute",
get: function get() {
return this.qualifiedName(this.raws.attribute || this.attribute);
}
}, {
key: "insensitiveFlag",
get: function get() {
return this.insensitive ? 'i' : '';
}
}, {
key: "value",
get: function get() {
return this._value;
},
set:
};
/**
* Before 3.0, the value had to be set to an escaped value including any wrapped
* quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
* is unescaped during parsing and any quote marks are removed.
* Intelligently select a quoteMark value based on the value's contents. If
* the value is a legal CSS ident, it will not be quoted. Otherwise a quote
* mark will be picked that minimizes the number of escapes.
*
* Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
* a deprecation warning is raised when the new value contains any characters that would
* require escaping (including if it contains wrapped quotes).
* If there's no clear winner, the quote mark from these options is used,
* then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
* true). If the quoteMark is unspecified, a double quote is used.
*
* Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
* how the new value is quoted.
* @param options This takes the quoteMark and preferCurrentQuoteMark options
* from the quoteValue method.
*/
function set(v) {
if (this._constructed) {
var _unescapeValue2 = unescapeValue(v),
deprecatedUsage = _unescapeValue2.deprecatedUsage,
unescaped = _unescapeValue2.unescaped,
quoteMark = _unescapeValue2.quoteMark;
if (deprecatedUsage) {
warnOfDeprecatedValueAssignment();
Attribute.prototype.smartQuoteMark = function (options) {
var v = this.value;
var numSingleQuotes = v.replace(/[^']/g, "").length;
var numDoubleQuotes = v.replace(/[^"]/g, "").length;
if (numSingleQuotes + numDoubleQuotes === 0) {
var escaped = (0, cssesc_1.default)(v, { isIdentifier: true });
if (escaped === v) {
return Attribute.NO_QUOTE;
}
else {
var pref = this.preferredQuoteMark(options);
if (pref === Attribute.NO_QUOTE) {
// pick a quote mark that isn't none and see if it's smaller
var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
var opts = CSSESC_QUOTE_OPTIONS[quote];
var quoteValue = (0, cssesc_1.default)(v, opts);
if (quoteValue.length < escaped.length) {
return quote;
}
}
return pref;
}
}
if (unescaped === this._value && quoteMark === this._quoteMark) {
return;
else if (numDoubleQuotes === numSingleQuotes) {
return this.preferredQuoteMark(options);
}
this._value = unescaped;
this._quoteMark = quoteMark;
this._syncRawValue();
} else {
this._value = v;
}
}
}, {
key: "insensitive",
get: function get() {
return this._insensitive;
}
else if (numDoubleQuotes < numSingleQuotes) {
return Attribute.DOUBLE_QUOTE;
}
else {
return Attribute.SINGLE_QUOTE;
}
};
/**
* Set the case insensitive flag.
* If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
* of the attribute is updated accordingly.
* Selects the preferred quote mark based on the options and the current quote mark value.
* If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
* instead.
*/
Attribute.prototype.preferredQuoteMark = function (options) {
var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
if (quoteMark === undefined) {
quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
}
if (quoteMark === undefined) {
quoteMark = Attribute.DOUBLE_QUOTE;
}
return quoteMark;
};
Object.defineProperty(Attribute.prototype, "quoted", {
get: function () {
var qm = this.quoteMark;
return qm === "'" || qm === '"';
},
set: function (value) {
warnOfDeprecatedQuotedAssignment();
},
enumerable: false,
configurable: true
});
Object.defineProperty(Attribute.prototype, "quoteMark", {
/**
* returns a single (`'`) or double (`"`) quote character if the value is quoted.
* returns `null` if the value is not quoted.
* returns `undefined` if the quotation state is unknown (this can happen when
* the attribute is constructed without specifying a quote mark.)
*/
get: function () {
return this._quoteMark;
},
/**
* Set the quote mark to be used by this attribute's value.
* If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
* value is updated accordingly.
*
* @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
*/
set: function (quoteMark) {
if (!this._constructed) {
this._quoteMark = quoteMark;
return;
}
if (this._quoteMark !== quoteMark) {
this._quoteMark = quoteMark;
this._syncRawValue();
}
},
enumerable: false,
configurable: true
});
Attribute.prototype._syncRawValue = function () {
var rawValue = (0, cssesc_1.default)(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
if (rawValue === this._value) {
if (this.raws) {
delete this.raws.value;
}
}
else {
this.raws.value = rawValue;
}
};
Object.defineProperty(Attribute.prototype, "qualifiedAttribute", {
get: function () {
return this.qualifiedName(this.raws.attribute || this.attribute);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Attribute.prototype, "insensitiveFlag", {
get: function () {
return this.insensitive ? "i" : "";
},
enumerable: false,
configurable: true
});
Object.defineProperty(Attribute.prototype, "value", {
get: function () {
return this._value;
},
/**
* Before 3.0, the value had to be set to an escaped value including any wrapped
* quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
* is unescaped during parsing and any quote marks are removed.
*
* Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
* a deprecation warning is raised when the new value contains any characters that would
* require escaping (including if it contains wrapped quotes).
*
* Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
* how the new value is quoted.
*/
set: function (v) {
if (this._constructed) {
var _a = unescapeValue(v), deprecatedUsage = _a.deprecatedUsage, unescaped = _a.unescaped, quoteMark = _a.quoteMark;
if (deprecatedUsage) {
warnOfDeprecatedValueAssignment();
}
if (unescaped === this._value && quoteMark === this._quoteMark) {
return;
}
this._value = unescaped;
this._quoteMark = quoteMark;
this._syncRawValue();
}
else {
this._value = v;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Attribute.prototype, "insensitive", {
get: function () {
return this._insensitive;
},
/**
* Set the case insensitive flag.
* If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
* of the attribute is updated accordingly.
*
* @param {true | false} insensitive true if the attribute should match case-insensitively.
*/
set: function (insensitive) {
if (!insensitive) {
this._insensitive = false;
// "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
// When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
if (this.raws && (this.raws.insensitiveFlag === "I" || this.raws.insensitiveFlag === "i")) {
this.raws.insensitiveFlag = undefined;
}
}
this._insensitive = insensitive;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Attribute.prototype, "attribute", {
get: function () {
return this._attribute;
},
set: function (name) {
this._handleEscapes("attribute", name);
this._attribute = name;
},
enumerable: false,
configurable: true
});
Attribute.prototype._handleEscapes = function (prop, value) {
if (this._constructed) {
var escaped = (0, cssesc_1.default)(value, { isIdentifier: true });
if (escaped !== value) {
this.raws[prop] = escaped;
}
else {
delete this.raws[prop];
}
}
};
Attribute.prototype._spacesFor = function (name) {
var attrSpaces = { before: "", after: "" };
var spaces = this.spaces[name] || {};
var rawSpaces = (this.raws.spaces && this.raws.spaces[name]) || {};
return Object.assign(attrSpaces, spaces, rawSpaces);
};
Attribute.prototype._stringFor = function (name, spaceName, concat) {
if (spaceName === void 0) { spaceName = name; }
if (concat === void 0) { concat = defaultAttrConcat; }
var attrSpaces = this._spacesFor(spaceName);
return concat(this.stringifyProperty(name), attrSpaces);
};
/**
* returns the offset of the attribute part specified relative to the
* start of the node of the output string.
*
* @param {true | false} insensitive true if the attribute should match case-insensitively.
*/,
set: function set(insensitive) {
if (!insensitive) {
this._insensitive = false;
// "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
// When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
if (this.raws && (this.raws.insensitiveFlag === 'I' || this.raws.insensitiveFlag === 'i')) {
this.raws.insensitiveFlag = undefined;
* * "ns" - alias for "namespace"
* * "namespace" - the namespace if it exists.
* * "attribute" - the attribute name
* * "attributeNS" - the start of the attribute or its namespace
* * "operator" - the match operator of the attribute
* * "value" - The value (string or identifier)
* * "insensitive" - the case insensitivity flag;
* @param part One of the possible values inside an attribute.
* @returns -1 if the name is invalid or the value doesn't exist in this attribute.
*/
Attribute.prototype.offsetOf = function (name) {
var count = 1;
var attributeSpaces = this._spacesFor("attribute");
count += attributeSpaces.before.length;
if (name === "namespace" || name === "ns") {
return this.namespace ? count : -1;
}
}
this._insensitive = insensitive;
}
}, {
key: "attribute",
get: function get() {
return this._attribute;
if (name === "attributeNS") {
return count;
}
count += this.namespaceString.length;
if (this.namespace) {
count += 1;
}
if (name === "attribute") {
return count;
}
count += this.stringifyProperty("attribute").length;
count += attributeSpaces.after.length;
var operatorSpaces = this._spacesFor("operator");
count += operatorSpaces.before.length;
var operator = this.stringifyProperty("operator");
if (name === "operator") {
return operator ? count : -1;
}
count += operator.length;
count += operatorSpaces.after.length;
var valueSpaces = this._spacesFor("value");
count += valueSpaces.before.length;
var value = this.stringifyProperty("value");
if (name === "value") {
return value ? count : -1;
}
count += value.length;
count += valueSpaces.after.length;
var insensitiveSpaces = this._spacesFor("insensitive");
count += insensitiveSpaces.before.length;
if (name === "insensitive") {
return this.insensitive ? count : -1;
}
return -1;
};
Attribute.prototype.toString = function () {
var _this = this;
var selector = [this.rawSpaceBefore, "["];
selector.push(this._stringFor("qualifiedAttribute", "attribute"));
if (this.operator && (this.value || this.value === "")) {
selector.push(this._stringFor("operator"));
selector.push(this._stringFor("value"));
selector.push(this._stringFor("insensitiveFlag", "insensitive", function (attrValue, attrSpaces) {
if (attrValue.length > 0 &&
!_this.quoted &&
attrSpaces.before.length === 0 &&
!(_this.spaces.value && _this.spaces.value.after)) {
attrSpaces.before = " ";
}
return defaultAttrConcat(attrValue, attrSpaces);
}));
}
selector.push("]");
selector.push(this.rawSpaceAfter);
return selector.join("");
};
Attribute.NO_QUOTE = null;
Attribute.SINGLE_QUOTE = "'";
Attribute.DOUBLE_QUOTE = '"';
return Attribute;
}(namespace_1.default));
exports.default = Attribute;
var CSSESC_QUOTE_OPTIONS = (_a = {
"'": { quotes: "single", wrap: true },
'"': { quotes: "double", wrap: true }
},
set: function set(name) {
this._handleEscapes("attribute", name);
this._attribute = name;
}
}]);
return Attribute;
}(_namespace["default"]);
Attribute.NO_QUOTE = null;
Attribute.SINGLE_QUOTE = "'";
Attribute.DOUBLE_QUOTE = '"';
var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
"'": {
quotes: 'single',
wrap: true
},
'"': {
quotes: 'double',
wrap: true
}
}, _CSSESC_QUOTE_OPTIONS[null] = {
isIdentifier: true
}, _CSSESC_QUOTE_OPTIONS);
_a[null] = { isIdentifier: true },
_a);
function defaultAttrConcat(attrValue, attrSpaces) {
return "" + attrSpaces.before + attrValue + attrSpaces.after;
}
return "".concat(attrSpaces.before).concat(attrValue).concat(attrSpaces.after);
}
//# sourceMappingURL=attribute.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _cssesc = _interopRequireDefault(require("cssesc"));
var _util = require("../util");
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var ClassName = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(ClassName, _Node);
function ClassName(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.CLASS;
_this._constructed = true;
return _this;
}
var _proto = ClassName.prototype;
_proto.valueToString = function valueToString() {
return '.' + _Node.prototype.valueToString.call(this);
};
_createClass(ClassName, [{
key: "value",
get: function get() {
return this._value;
},
set: function set(v) {
if (this._constructed) {
var escaped = (0, _cssesc["default"])(v, {
isIdentifier: true
});
if (escaped !== v) {
(0, _util.ensureObject)(this, "raws");
this.raws.value = escaped;
} else if (this.raws) {
delete this.raws.value;
}
}
this._value = v;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var cssesc_1 = __importDefault(require("cssesc"));
var util_1 = require("../util");
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var ClassName = /** @class */ (function (_super) {
__extends(ClassName, _super);
function ClassName(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.CLASS;
_this._constructed = true;
return _this;
}
}]);
return ClassName;
}(_node["default"]);
module.exports = exports.default;
Object.defineProperty(ClassName.prototype, "value", {
get: function () {
return this._value;
},
set: function (v) {
if (this._constructed) {
var escaped = (0, cssesc_1.default)(v, { isIdentifier: true });
if (escaped !== v) {
(0, util_1.ensureObject)(this, "raws");
this.raws.value = escaped;
}
else if (this.raws) {
delete this.raws.value;
}
}
this._value = v;
},
enumerable: false,
configurable: true
});
ClassName.prototype.valueToString = function () {
return "." + _super.prototype.valueToString.call(this);
};
return ClassName;
}(node_1.default));
exports.default = ClassName;
//# sourceMappingURL=className.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Combinator = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(Combinator, _Node);
function Combinator(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.COMBINATOR;
return _this;
}
return Combinator;
}(_node["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var Combinator = /** @class */ (function (_super) {
__extends(Combinator, _super);
function Combinator(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.COMBINATOR;
return _this;
}
return Combinator;
}(node_1.default));
exports.default = Combinator;
//# sourceMappingURL=combinator.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Comment = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(Comment, _Node);
function Comment(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.COMMENT;
return _this;
}
return Comment;
}(_node["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var Comment = /** @class */ (function (_super) {
__extends(Comment, _super);
function Comment(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.COMMENT;
return _this;
}
return Comment;
}(node_1.default));
exports.default = Comment;
//# sourceMappingURL=comment.js.map
"use strict";
exports.__esModule = true;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
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;
var _attribute = _interopRequireDefault(require("./attribute"));
var _className = _interopRequireDefault(require("./className"));
var _combinator = _interopRequireDefault(require("./combinator"));
var _comment = _interopRequireDefault(require("./comment"));
var _id = _interopRequireDefault(require("./id"));
var _nesting = _interopRequireDefault(require("./nesting"));
var _pseudo = _interopRequireDefault(require("./pseudo"));
var _root = _interopRequireDefault(require("./root"));
var _selector = _interopRequireDefault(require("./selector"));
var _string = _interopRequireDefault(require("./string"));
var _tag = _interopRequireDefault(require("./tag"));
var _universal = _interopRequireDefault(require("./universal"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var attribute = exports.attribute = function attribute(opts) {
return new _attribute["default"](opts);
};
var className = exports.className = function className(opts) {
return new _className["default"](opts);
};
var combinator = exports.combinator = function combinator(opts) {
return new _combinator["default"](opts);
};
var comment = exports.comment = function comment(opts) {
return new _comment["default"](opts);
};
var id = exports.id = function id(opts) {
return new _id["default"](opts);
};
var nesting = exports.nesting = function nesting(opts) {
return new _nesting["default"](opts);
};
var pseudo = exports.pseudo = function pseudo(opts) {
return new _pseudo["default"](opts);
};
var root = exports.root = function root(opts) {
return new _root["default"](opts);
};
var selector = exports.selector = function selector(opts) {
return new _selector["default"](opts);
};
var string = exports.string = function string(opts) {
return new _string["default"](opts);
};
var tag = exports.tag = function tag(opts) {
return new _tag["default"](opts);
};
var universal = exports.universal = function universal(opts) {
return new _universal["default"](opts);
};
var attribute_1 = __importDefault(require("./attribute"));
var className_1 = __importDefault(require("./className"));
var combinator_1 = __importDefault(require("./combinator"));
var comment_1 = __importDefault(require("./comment"));
var id_1 = __importDefault(require("./id"));
var nesting_1 = __importDefault(require("./nesting"));
var pseudo_1 = __importDefault(require("./pseudo"));
var root_1 = __importDefault(require("./root"));
var selector_1 = __importDefault(require("./selector"));
var string_1 = __importDefault(require("./string"));
var tag_1 = __importDefault(require("./tag"));
var universal_1 = __importDefault(require("./universal"));
var attribute = function (opts) { return new attribute_1.default(opts); };
exports.attribute = attribute;
var className = function (opts) { return new className_1.default(opts); };
exports.className = className;
var combinator = function (opts) { return new combinator_1.default(opts); };
exports.combinator = combinator;
var comment = function (opts) { return new comment_1.default(opts); };
exports.comment = comment;
var id = function (opts) { return new id_1.default(opts); };
exports.id = id;
var nesting = function (opts) { return new nesting_1.default(opts); };
exports.nesting = nesting;
var pseudo = function (opts) { return new pseudo_1.default(opts); };
exports.pseudo = pseudo;
var root = function (opts) { return new root_1.default(opts); };
exports.root = root;
var selector = function (opts) { return new selector_1.default(opts); };
exports.selector = selector;
var string = function (opts) { return new string_1.default(opts); };
exports.string = string;
var tag = function (opts) { return new tag_1.default(opts); };
exports.tag = tag;
var universal = function (opts) { return new universal_1.default(opts); };
exports.universal = universal;
//# sourceMappingURL=constructors.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _util = require("../util");
var _node = _interopRequireDefault(require("./node"));
var types = _interopRequireWildcard(require("./types"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Container = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(Container, _Node);
function Container(opts) {
var _this;
_this = _Node.call(this, opts) || this;
if (!_this.nodes) {
_this.nodes = [];
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
return _this;
}
var _proto = Container.prototype;
_proto.append = function append(selector) {
selector.parent = this;
this.nodes.push(selector);
return this;
};
_proto.prepend = function prepend(selector) {
selector.parent = this;
this.nodes.unshift(selector);
for (var id in this.indexes) {
this.indexes[id]++;
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
return this;
};
_proto.at = function at(index) {
return this.nodes[index];
};
_proto.index = function index(child) {
if (typeof child === 'number') {
return child;
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return this.nodes.indexOf(child);
};
_proto.removeChild = function removeChild(child) {
child = this.index(child);
this.at(child).parent = undefined;
this.nodes.splice(child, 1);
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (index >= child) {
this.indexes[id] = index - 1;
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return this;
};
_proto.removeAll = function removeAll() {
for (var _iterator = _createForOfIteratorHelperLoose(this.nodes), _step; !(_step = _iterator()).done;) {
var node = _step.value;
node.parent = undefined;
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("../util");
var node_1 = __importDefault(require("./node"));
var types = __importStar(require("./types"));
var Container = /** @class */ (function (_super) {
__extends(Container, _super);
function Container(opts) {
var _this = _super.call(this, opts) || this;
if (!_this.nodes) {
_this.nodes = [];
}
return _this;
}
this.nodes = [];
return this;
};
_proto.empty = function empty() {
return this.removeAll();
};
_proto.insertAfter = function insertAfter(oldNode, newNode) {
var _this$nodes;
newNode.parent = this;
var oldIndex = this.index(oldNode);
var resetNode = [];
for (var i = 2; i < arguments.length; i++) {
resetNode.push(arguments[i]);
}
(_this$nodes = this.nodes).splice.apply(_this$nodes, [oldIndex + 1, 0, newNode].concat(resetNode));
newNode.parent = this;
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (oldIndex < index) {
this.indexes[id] = index + arguments.length - 1;
}
}
return this;
};
_proto.insertBefore = function insertBefore(oldNode, newNode) {
var _this$nodes2;
newNode.parent = this;
var oldIndex = this.index(oldNode);
var resetNode = [];
for (var i = 2; i < arguments.length; i++) {
resetNode.push(arguments[i]);
}
(_this$nodes2 = this.nodes).splice.apply(_this$nodes2, [oldIndex, 0, newNode].concat(resetNode));
newNode.parent = this;
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (index >= oldIndex) {
this.indexes[id] = index + arguments.length - 1;
}
}
return this;
};
_proto._findChildAtPosition = function _findChildAtPosition(line, col) {
var found = undefined;
this.each(function (node) {
if (node.atPosition) {
var foundChild = node.atPosition(line, col);
if (foundChild) {
found = foundChild;
return false;
Container.prototype.append = function (selector) {
selector.parent = this;
this.nodes.push(selector);
return this;
};
Container.prototype.prepend = function (selector) {
selector.parent = this;
this.nodes.unshift(selector);
for (var id in this.indexes) {
this.indexes[id]++;
}
} else if (node.isAtPosition(line, col)) {
found = node;
return false;
}
return this;
};
Container.prototype.at = function (index) {
return this.nodes[index];
};
Container.prototype.index = function (child) {
if (typeof child === "number") {
return child;
}
return this.nodes.indexOf(child);
};
Object.defineProperty(Container.prototype, "first", {
get: function () {
return this.at(0);
},
enumerable: false,
configurable: true
});
return found;
}
/**
* Return the most specific node at the line and column number given.
* The source location is based on the original parsed location, locations aren't
* updated as selector nodes are mutated.
*
* Note that this location is relative to the location of the first character
* of the selector, and not the location of the selector in the overall document
* when used in conjunction with postcss.
*
* If not found, returns undefined.
* @param {number} line The line number of the node to find. (1-based index)
* @param {number} col The column number of the node to find. (1-based index)
*/;
_proto.atPosition = function atPosition(line, col) {
if (this.isAtPosition(line, col)) {
return this._findChildAtPosition(line, col) || this;
} else {
return undefined;
}
};
_proto._inferEndPosition = function _inferEndPosition() {
if (this.last && this.last.source && this.last.source.end) {
this.source = this.source || {};
this.source.end = this.source.end || {};
Object.assign(this.source.end, this.last.source.end);
}
};
_proto.each = function each(callback) {
if (!this.lastEach) {
this.lastEach = 0;
}
if (!this.indexes) {
this.indexes = {};
}
this.lastEach++;
var id = this.lastEach;
this.indexes[id] = 0;
if (!this.length) {
return undefined;
}
var index, result;
while (this.indexes[id] < this.length) {
index = this.indexes[id];
result = callback(this.at(index), index);
if (result === false) {
break;
}
this.indexes[id] += 1;
}
delete this.indexes[id];
if (result === false) {
return false;
}
};
_proto.walk = function walk(callback) {
return this.each(function (node, i) {
var result = callback(node, i);
if (result !== false && node.length) {
result = node.walk(callback);
}
if (result === false) {
return false;
}
Object.defineProperty(Container.prototype, "last", {
get: function () {
return this.at(this.length - 1);
},
enumerable: false,
configurable: true
});
};
_proto.walkAttributes = function walkAttributes(callback) {
var _this2 = this;
return this.walk(function (selector) {
if (selector.type === types.ATTRIBUTE) {
return callback.call(_this2, selector);
}
Object.defineProperty(Container.prototype, "length", {
get: function () {
return this.nodes.length;
},
enumerable: false,
configurable: true
});
};
_proto.walkClasses = function walkClasses(callback) {
var _this3 = this;
return this.walk(function (selector) {
if (selector.type === types.CLASS) {
return callback.call(_this3, selector);
}
});
};
_proto.walkCombinators = function walkCombinators(callback) {
var _this4 = this;
return this.walk(function (selector) {
if (selector.type === types.COMBINATOR) {
return callback.call(_this4, selector);
}
});
};
_proto.walkComments = function walkComments(callback) {
var _this5 = this;
return this.walk(function (selector) {
if (selector.type === types.COMMENT) {
return callback.call(_this5, selector);
}
});
};
_proto.walkIds = function walkIds(callback) {
var _this6 = this;
return this.walk(function (selector) {
if (selector.type === types.ID) {
return callback.call(_this6, selector);
}
});
};
_proto.walkNesting = function walkNesting(callback) {
var _this7 = this;
return this.walk(function (selector) {
if (selector.type === types.NESTING) {
return callback.call(_this7, selector);
}
});
};
_proto.walkPseudos = function walkPseudos(callback) {
var _this8 = this;
return this.walk(function (selector) {
if (selector.type === types.PSEUDO) {
return callback.call(_this8, selector);
}
});
};
_proto.walkTags = function walkTags(callback) {
var _this9 = this;
return this.walk(function (selector) {
if (selector.type === types.TAG) {
return callback.call(_this9, selector);
}
});
};
_proto.walkUniversals = function walkUniversals(callback) {
var _this0 = this;
return this.walk(function (selector) {
if (selector.type === types.UNIVERSAL) {
return callback.call(_this0, selector);
}
});
};
_proto.split = function split(callback) {
var _this1 = this;
var current = [];
return this.reduce(function (memo, node, index) {
var split = callback.call(_this1, node);
current.push(node);
if (split) {
memo.push(current);
current = [];
} else if (index === _this1.length - 1) {
memo.push(current);
}
return memo;
}, []);
};
_proto.map = function map(callback) {
return this.nodes.map(callback);
};
_proto.reduce = function reduce(callback, memo) {
return this.nodes.reduce(callback, memo);
};
_proto.every = function every(callback) {
return this.nodes.every(callback);
};
_proto.some = function some(callback) {
return this.nodes.some(callback);
};
_proto.filter = function filter(callback) {
return this.nodes.filter(callback);
};
_proto.sort = function sort(callback) {
return this.nodes.sort(callback);
};
_proto.toString = function toString(options) {
if (options === void 0) {
options = {};
}
return this._stringify(options, 0, (0, _util.resolveMaxNestingDepth)(options.maxNestingDepth));
};
_proto._stringify = function _stringify(options, depth, max) {
return this.map(function (child) {
return child._stringify(options, depth, max);
}).join('');
};
_createClass(Container, [{
key: "first",
get: function get() {
return this.at(0);
}
}, {
key: "last",
get: function get() {
return this.at(this.length - 1);
}
}, {
key: "length",
get: function get() {
return this.nodes.length;
}
}]);
return Container;
}(_node["default"]);
module.exports = exports.default;
Container.prototype.removeChild = function (child) {
child = this.index(child);
this.at(child).parent = undefined;
this.nodes.splice(child, 1);
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (index >= child) {
this.indexes[id] = index - 1;
}
}
return this;
};
Container.prototype.removeAll = function () {
var e_1, _a;
try {
for (var _b = __values(this.nodes), _c = _b.next(); !_c.done; _c = _b.next()) {
var node = _c.value;
node.parent = undefined;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
this.nodes = [];
return this;
};
Container.prototype.empty = function () {
return this.removeAll();
};
Container.prototype.insertAfter = function (oldNode, newNode) {
var _a;
newNode.parent = this;
var oldIndex = this.index(oldNode);
var resetNode = [];
for (var i = 2; i < arguments.length; i++) {
resetNode.push(arguments[i]);
}
(_a = this.nodes).splice.apply(_a, __spreadArray([oldIndex + 1, 0, newNode], __read(resetNode), false));
newNode.parent = this;
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (oldIndex < index) {
this.indexes[id] = index + arguments.length - 1;
}
}
return this;
};
Container.prototype.insertBefore = function (oldNode, newNode) {
var _a;
newNode.parent = this;
var oldIndex = this.index(oldNode);
var resetNode = [];
for (var i = 2; i < arguments.length; i++) {
resetNode.push(arguments[i]);
}
(_a = this.nodes).splice.apply(_a, __spreadArray([oldIndex, 0, newNode], __read(resetNode), false));
newNode.parent = this;
var index;
for (var id in this.indexes) {
index = this.indexes[id];
if (index >= oldIndex) {
this.indexes[id] = index + arguments.length - 1;
}
}
return this;
};
Container.prototype._findChildAtPosition = function (line, col) {
var found = undefined;
this.each(function (node) {
if (node.atPosition) {
var foundChild = node.atPosition(line, col);
if (foundChild) {
found = foundChild;
return false;
}
}
else if (node.isAtPosition(line, col)) {
found = node;
return false;
}
});
return found;
};
/**
* Return the most specific node at the line and column number given.
* The source location is based on the original parsed location, locations aren't
* updated as selector nodes are mutated.
*
* Note that this location is relative to the location of the first character
* of the selector, and not the location of the selector in the overall document
* when used in conjunction with postcss.
*
* If not found, returns undefined.
* @param {number} line The line number of the node to find. (1-based index)
* @param {number} col The column number of the node to find. (1-based index)
*/
Container.prototype.atPosition = function (line, col) {
if (this.isAtPosition(line, col)) {
return this._findChildAtPosition(line, col) || this;
}
else {
return undefined;
}
};
Container.prototype._inferEndPosition = function () {
if (this.last && this.last.source && this.last.source.end) {
this.source = this.source || {};
this.source.end = this.source.end || {};
Object.assign(this.source.end, this.last.source.end);
}
};
Container.prototype.each = function (callback) {
if (!this.lastEach) {
this.lastEach = 0;
}
if (!this.indexes) {
this.indexes = {};
}
this.lastEach++;
var id = this.lastEach;
this.indexes[id] = 0;
if (!this.length) {
return undefined;
}
var index, result;
while (this.indexes[id] < this.length) {
index = this.indexes[id];
result = callback(this.at(index), index);
if (result === false) {
break;
}
this.indexes[id] += 1;
}
delete this.indexes[id];
if (result === false) {
return false;
}
};
Container.prototype.walk = function (callback, depth) {
if (depth === void 0) { depth = 0; }
// Bound recursion so a pathologically deep node tree raises a catchable
// error instead of overflowing the call stack (CVE-2026-9358 / CWE-674).
if (depth > util_1.MAX_NESTING_DEPTH) {
throw new Error("Cannot walk selector: nesting depth exceeds the maximum of ".concat(util_1.MAX_NESTING_DEPTH, "."));
}
return this.each(function (node, i) {
var result = callback(node, i);
if (result !== false && node.length) {
result = node.walk(callback, depth + 1);
}
if (result === false) {
return false;
}
});
};
Container.prototype.walkAttributes = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.ATTRIBUTE) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkClasses = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.CLASS) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkCombinators = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.COMBINATOR) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkComments = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.COMMENT) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkIds = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.ID) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkNesting = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.NESTING) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkPseudos = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.PSEUDO) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkTags = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.TAG) {
return callback.call(_this, selector);
}
});
};
Container.prototype.walkUniversals = function (callback) {
var _this = this;
return this.walk(function (selector) {
if (selector.type === types.UNIVERSAL) {
return callback.call(_this, selector);
}
});
};
Container.prototype.split = function (callback) {
var _this = this;
var current = [];
return this.reduce(function (memo, node, index) {
var split = callback.call(_this, node);
current.push(node);
if (split) {
memo.push(current);
current = [];
}
else if (index === _this.length - 1) {
memo.push(current);
}
return memo;
}, []);
};
Container.prototype.map = function (callback) {
return this.nodes.map(callback);
};
Container.prototype.reduce = function (callback, memo) {
return this.nodes.reduce(callback, memo);
};
Container.prototype.every = function (callback) {
return this.nodes.every(callback);
};
Container.prototype.some = function (callback) {
return this.nodes.some(callback);
};
Container.prototype.filter = function (callback) {
return this.nodes.filter(callback);
};
Container.prototype.sort = function (callback) {
return this.nodes.sort(callback);
};
Container.prototype.toString = function (options) {
if (options === void 0) { options = {}; }
return this._stringify(options, 0, (0, util_1.resolveMaxNestingDepth)(options.maxNestingDepth));
};
Container.prototype._stringify = function (options, depth, max) {
return this.map(function (child) { return child._stringify(options, depth, max); }).join("");
};
return Container;
}(node_1.default));
exports.default = Container;
//# sourceMappingURL=container.js.map
"use strict";
exports.__esModule = true;
exports.isComment = exports.isCombinator = exports.isClassName = exports.isAttribute = void 0;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
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;
exports.isNode = isNode;
exports.isPseudoElement = isPseudoElement;
exports.isPseudoClass = isPseudoClass;
exports.isContainer = isContainer;
exports.isIdentifier = void 0;
exports.isNamespace = isNamespace;
exports.isNesting = void 0;
exports.isNode = isNode;
exports.isPseudo = void 0;
exports.isPseudoClass = isPseudoClass;
exports.isPseudoElement = isPseudoElement;
exports.isUniversal = exports.isTag = exports.isString = exports.isSelector = exports.isRoot = void 0;
var _types = require("./types");
var _IS_TYPE;
var IS_TYPE = (_IS_TYPE = {}, _IS_TYPE[_types.ATTRIBUTE] = true, _IS_TYPE[_types.CLASS] = true, _IS_TYPE[_types.COMBINATOR] = true, _IS_TYPE[_types.COMMENT] = true, _IS_TYPE[_types.ID] = true, _IS_TYPE[_types.NESTING] = true, _IS_TYPE[_types.PSEUDO] = true, _IS_TYPE[_types.ROOT] = true, _IS_TYPE[_types.SELECTOR] = true, _IS_TYPE[_types.STRING] = true, _IS_TYPE[_types.TAG] = true, _IS_TYPE[_types.UNIVERSAL] = true, _IS_TYPE);
var types_1 = require("./types");
var IS_TYPE = (_a = {},
_a[types_1.ATTRIBUTE] = true,
_a[types_1.CLASS] = true,
_a[types_1.COMBINATOR] = true,
_a[types_1.COMMENT] = true,
_a[types_1.ID] = true,
_a[types_1.NESTING] = true,
_a[types_1.PSEUDO] = true,
_a[types_1.ROOT] = true,
_a[types_1.SELECTOR] = true,
_a[types_1.STRING] = true,
_a[types_1.TAG] = true,
_a[types_1.UNIVERSAL] = true,
_a);
function isNode(node) {
return typeof node === "object" && IS_TYPE[node.type];
return typeof node === "object" && IS_TYPE[node.type];
}
function isNodeType(type, node) {
return isNode(node) && node.type === type;
return isNode(node) && node.type === type;
}
var isAttribute = exports.isAttribute = isNodeType.bind(null, _types.ATTRIBUTE);
var isClassName = exports.isClassName = isNodeType.bind(null, _types.CLASS);
var isCombinator = exports.isCombinator = isNodeType.bind(null, _types.COMBINATOR);
var isComment = exports.isComment = isNodeType.bind(null, _types.COMMENT);
var isIdentifier = exports.isIdentifier = isNodeType.bind(null, _types.ID);
var isNesting = exports.isNesting = isNodeType.bind(null, _types.NESTING);
var isPseudo = exports.isPseudo = isNodeType.bind(null, _types.PSEUDO);
var isRoot = exports.isRoot = isNodeType.bind(null, _types.ROOT);
var isSelector = exports.isSelector = isNodeType.bind(null, _types.SELECTOR);
var isString = exports.isString = isNodeType.bind(null, _types.STRING);
var isTag = exports.isTag = isNodeType.bind(null, _types.TAG);
var isUniversal = exports.isUniversal = isNodeType.bind(null, _types.UNIVERSAL);
exports.isAttribute = isNodeType.bind(null, types_1.ATTRIBUTE);
exports.isClassName = isNodeType.bind(null, types_1.CLASS);
exports.isCombinator = isNodeType.bind(null, types_1.COMBINATOR);
exports.isComment = isNodeType.bind(null, types_1.COMMENT);
exports.isIdentifier = isNodeType.bind(null, types_1.ID);
exports.isNesting = isNodeType.bind(null, types_1.NESTING);
exports.isPseudo = isNodeType.bind(null, types_1.PSEUDO);
exports.isRoot = isNodeType.bind(null, types_1.ROOT);
exports.isSelector = isNodeType.bind(null, types_1.SELECTOR);
exports.isString = isNodeType.bind(null, types_1.STRING);
exports.isTag = isNodeType.bind(null, types_1.TAG);
exports.isUniversal = isNodeType.bind(null, types_1.UNIVERSAL);
function isPseudoElement(node) {
return isPseudo(node) && node.value && (node.value.startsWith("::") || node.value.toLowerCase() === ":before" || node.value.toLowerCase() === ":after" || node.value.toLowerCase() === ":first-letter" || node.value.toLowerCase() === ":first-line");
return ((0, exports.isPseudo)(node) &&
node.value &&
(node.value.startsWith("::") ||
node.value.toLowerCase() === ":before" ||
node.value.toLowerCase() === ":after" ||
node.value.toLowerCase() === ":first-letter" ||
node.value.toLowerCase() === ":first-line"));
}
function isPseudoClass(node) {
return isPseudo(node) && !isPseudoElement(node);
return (0, exports.isPseudo)(node) && !isPseudoElement(node);
}
function isContainer(node) {
return !!(isNode(node) && node.walk);
return !!(isNode(node) && node.walk);
}
function isNamespace(node) {
return isAttribute(node) || isTag(node);
}
return (0, exports.isAttribute)(node) || (0, exports.isTag)(node);
}
//# sourceMappingURL=guards.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var ID = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(ID, _Node);
function ID(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.ID;
return _this;
}
var _proto = ID.prototype;
_proto.valueToString = function valueToString() {
return '#' + _Node.prototype.valueToString.call(this);
};
return ID;
}(_node["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var ID = /** @class */ (function (_super) {
__extends(ID, _super);
function ID(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.ID;
return _this;
}
ID.prototype.valueToString = function () {
return "#" + _super.prototype.valueToString.call(this);
};
return ID;
}(node_1.default));
exports.default = ID;
//# sourceMappingURL=id.js.map
"use strict";
exports.__esModule = true;
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _types[key]) return;
exports[key] = _types[key];
});
var _constructors = require("./constructors");
Object.keys(_constructors).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _constructors[key]) return;
exports[key] = _constructors[key];
});
var _guards = require("./guards");
Object.keys(_guards).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _guards[key]) return;
exports[key] = _guards[key];
});
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types"), exports);
__exportStar(require("./constructors"), exports);
__exportStar(require("./guards"), exports);
//# sourceMappingURL=index.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _cssesc = _interopRequireDefault(require("cssesc"));
var _util = require("../util");
var _node = _interopRequireDefault(require("./node"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Namespace = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(Namespace, _Node);
function Namespace() {
return _Node.apply(this, arguments) || this;
}
var _proto = Namespace.prototype;
_proto.qualifiedName = function qualifiedName(value) {
if (this.namespace) {
return this.namespaceString + "|" + value;
} else {
return value;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var cssesc_1 = __importDefault(require("cssesc"));
var util_1 = require("../util");
var node_1 = __importDefault(require("./node"));
var Namespace = /** @class */ (function (_super) {
__extends(Namespace, _super);
function Namespace() {
return _super !== null && _super.apply(this, arguments) || this;
}
};
_proto.valueToString = function valueToString() {
return this.qualifiedName(_Node.prototype.valueToString.call(this));
};
_createClass(Namespace, [{
key: "namespace",
get: function get() {
return this._namespace;
},
set: function set(namespace) {
if (namespace === true || namespace === "*" || namespace === "&") {
this._namespace = namespace;
if (this.raws) {
delete this.raws.namespace;
Object.defineProperty(Namespace.prototype, "namespace", {
get: function () {
return this._namespace;
},
set: function (namespace) {
if (namespace === true || namespace === "*" || namespace === "&") {
this._namespace = namespace;
if (this.raws) {
delete this.raws.namespace;
}
return;
}
var escaped = (0, cssesc_1.default)(namespace, { isIdentifier: true });
this._namespace = namespace;
if (escaped !== namespace) {
(0, util_1.ensureObject)(this, "raws");
this.raws.namespace = escaped;
}
else if (this.raws) {
delete this.raws.namespace;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Namespace.prototype, "ns", {
get: function () {
return this._namespace;
},
set: function (namespace) {
this.namespace = namespace;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Namespace.prototype, "namespaceString", {
get: function () {
if (this.namespace) {
var ns = this.stringifyProperty("namespace");
if (ns === true) {
return "";
}
else {
return ns;
}
}
else {
return "";
}
},
enumerable: false,
configurable: true
});
Namespace.prototype.qualifiedName = function (value) {
if (this.namespace) {
return "".concat(this.namespaceString, "|").concat(value);
}
return;
}
var escaped = (0, _cssesc["default"])(namespace, {
isIdentifier: true
});
this._namespace = namespace;
if (escaped !== namespace) {
(0, _util.ensureObject)(this, "raws");
this.raws.namespace = escaped;
} else if (this.raws) {
delete this.raws.namespace;
}
}
}, {
key: "ns",
get: function get() {
return this._namespace;
},
set: function set(namespace) {
this.namespace = namespace;
}
}, {
key: "namespaceString",
get: function get() {
if (this.namespace) {
var ns = this.stringifyProperty("namespace");
if (ns === true) {
return '';
} else {
return ns;
else {
return value;
}
} else {
return '';
}
}
}]);
return Namespace;
}(_node["default"]);
;
module.exports = exports.default;
};
Namespace.prototype.valueToString = function () {
return this.qualifiedName(_super.prototype.valueToString.call(this));
};
return Namespace;
}(node_1.default));
exports.default = Namespace;
//# sourceMappingURL=namespace.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Nesting = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(Nesting, _Node);
function Nesting(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.NESTING;
_this.value = '&';
return _this;
}
return Nesting;
}(_node["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var Nesting = /** @class */ (function (_super) {
__extends(Nesting, _super);
function Nesting(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.NESTING;
_this.value = "&";
return _this;
}
return Nesting;
}(node_1.default));
exports.default = Nesting;
//# sourceMappingURL=nesting.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _util = require("../util");
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var cloneNode = function cloneNode(obj, parent) {
if (typeof obj !== 'object' || obj === null) {
return obj;
}
var cloned = new obj.constructor();
for (var i in obj) {
if (!obj.hasOwnProperty(i)) {
continue;
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("../util");
var cloneNode = function (obj, parent, depth) {
if (depth === void 0) { depth = 0; }
// Bound recursion so a pathologically deep node tree raises a catchable
// error instead of overflowing the call stack (CVE-2026-9358 / CWE-674).
if (depth > util_1.MAX_NESTING_DEPTH) {
throw new Error("Cannot clone selector: nesting depth exceeds the maximum of ".concat(util_1.MAX_NESTING_DEPTH, "."));
}
var value = obj[i];
var type = typeof value;
if (i === 'parent' && type === 'object') {
if (parent) {
cloned[i] = parent;
}
} else if (value instanceof Array) {
cloned[i] = value.map(function (j) {
return cloneNode(j, cloned);
});
} else {
cloned[i] = cloneNode(value, cloned);
if (typeof obj !== "object" || obj === null) {
return obj;
}
}
return cloned;
};
var Node = exports["default"] = /*#__PURE__*/function () {
function Node(opts) {
if (opts === void 0) {
opts = {};
var cloned = new obj.constructor();
for (var i in obj) {
if (!obj.hasOwnProperty(i)) {
continue;
}
var value = obj[i];
var type = typeof value;
if (i === "parent" && type === "object") {
if (parent) {
cloned[i] = parent;
}
}
else if (value instanceof Array) {
cloned[i] = value.map(function (j) { return cloneNode(j, cloned, depth + 1); });
}
else {
cloned[i] = cloneNode(value, cloned, depth + 1);
}
}
Object.assign(this, opts);
this.spaces = this.spaces || {};
this.spaces.before = this.spaces.before || '';
this.spaces.after = this.spaces.after || '';
}
var _proto = Node.prototype;
_proto.remove = function remove() {
if (this.parent) {
this.parent.removeChild(this);
}
this.parent = undefined;
return this;
};
_proto.replaceWith = function replaceWith() {
if (this.parent) {
for (var index in arguments) {
this.parent.insertBefore(this, arguments[index]);
}
this.remove();
}
return this;
};
_proto.next = function next() {
return this.parent.at(this.parent.index(this) + 1);
};
_proto.prev = function prev() {
return this.parent.at(this.parent.index(this) - 1);
};
_proto.clone = function clone(overrides) {
if (overrides === void 0) {
overrides = {};
}
var cloned = cloneNode(this);
for (var name in overrides) {
cloned[name] = overrides[name];
}
return cloned;
}
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows non standard syntax to be appended to an existing property
* by specifying the escaped value. By specifying the escaped value,
* illegal characters are allowed to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped optional. the escaped value of the property.
*/;
_proto.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
};
var Node = /** @class */ (function () {
function Node(opts) {
if (opts === void 0) { opts = {}; }
Object.assign(this, opts);
this.spaces = this.spaces || {};
this.spaces.before = this.spaces.before || "";
this.spaces.after = this.spaces.after || "";
}
var originalValue = this[name];
var originalEscaped = this.raws[name];
this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
if (originalEscaped || valueEscaped !== value) {
this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
} else {
delete this.raws[name]; // delete any escaped value that was created by the setter.
}
}
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows the escaped value to be specified directly, allowing illegal
* characters to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped the escaped value of the property.
*/;
_proto.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
}
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
this.raws[name] = valueEscaped;
}
/**
* When you want a value to passed through to CSS directly. This method
* deletes the corresponding raw value causing the stringifier to fallback
* to the unescaped value.
* @param {string} name the property to set.
* @param {any} value The value that is both escaped and unescaped.
*/;
_proto.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
if (this.raws) {
delete this.raws[name];
}
}
/**
*
* @param {number} line The number (starting with 1)
* @param {number} column The column number (starting with 1)
*/;
_proto.isAtPosition = function isAtPosition(line, column) {
if (this.source && this.source.start && this.source.end) {
if (this.source.start.line > line) {
return false;
}
if (this.source.end.line < line) {
return false;
}
if (this.source.start.line === line && this.source.start.column > column) {
return false;
}
if (this.source.end.line === line && this.source.end.column < column) {
return false;
}
return true;
}
return undefined;
};
_proto.stringifyProperty = function stringifyProperty(name) {
return this.raws && this.raws[name] || this[name];
};
_proto.valueToString = function valueToString() {
return String(this.stringifyProperty("value"));
};
_proto.toString = function toString() {
return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join('');
}
// Internal recursion entry point used by Container serialization. Leaf
// nodes don't recurse, so they ignore the depth/limit and stringify
// themselves. Containers override this to thread the nesting depth.
;
_proto._stringify = function _stringify() {
return this.toString();
};
_createClass(Node, [{
key: "rawSpaceBefore",
get: function get() {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
if (rawSpace === undefined) {
rawSpace = this.spaces && this.spaces.before;
}
return rawSpace || "";
},
set: function set(raw) {
(0, _util.ensureObject)(this, "raws", "spaces");
this.raws.spaces.before = raw;
}
}, {
key: "rawSpaceAfter",
get: function get() {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
if (rawSpace === undefined) {
rawSpace = this.spaces.after;
}
return rawSpace || "";
},
set: function set(raw) {
(0, _util.ensureObject)(this, "raws", "spaces");
this.raws.spaces.after = raw;
}
}]);
return Node;
}();
module.exports = exports.default;
Node.prototype.remove = function () {
if (this.parent) {
this.parent.removeChild(this);
}
this.parent = undefined;
return this;
};
Node.prototype.replaceWith = function () {
if (this.parent) {
for (var index in arguments) {
this.parent.insertBefore(this, arguments[index]);
}
this.remove();
}
return this;
};
Node.prototype.next = function () {
return this.parent.at(this.parent.index(this) + 1);
};
Node.prototype.prev = function () {
return this.parent.at(this.parent.index(this) - 1);
};
Node.prototype.clone = function (overrides) {
if (overrides === void 0) { overrides = {}; }
var cloned = cloneNode(this);
for (var name in overrides) {
cloned[name] = overrides[name];
}
return cloned;
};
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows non standard syntax to be appended to an existing property
* by specifying the escaped value. By specifying the escaped value,
* illegal characters are allowed to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped optional. the escaped value of the property.
*/
Node.prototype.appendToPropertyAndEscape = function (name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
}
var originalValue = this[name];
var originalEscaped = this.raws[name];
this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
if (originalEscaped || valueEscaped !== value) {
this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
}
else {
delete this.raws[name]; // delete any escaped value that was created by the setter.
}
};
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows the escaped value to be specified directly, allowing illegal
* characters to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped the escaped value of the property.
*/
Node.prototype.setPropertyAndEscape = function (name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
}
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
this.raws[name] = valueEscaped;
};
/**
* When you want a value to passed through to CSS directly. This method
* deletes the corresponding raw value causing the stringifier to fallback
* to the unescaped value.
* @param {string} name the property to set.
* @param {any} value The value that is both escaped and unescaped.
*/
Node.prototype.setPropertyWithoutEscape = function (name, value) {
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
if (this.raws) {
delete this.raws[name];
}
};
/**
*
* @param {number} line The number (starting with 1)
* @param {number} column The column number (starting with 1)
*/
Node.prototype.isAtPosition = function (line, column) {
if (this.source && this.source.start && this.source.end) {
if (this.source.start.line > line) {
return false;
}
if (this.source.end.line < line) {
return false;
}
if (this.source.start.line === line && this.source.start.column > column) {
return false;
}
if (this.source.end.line === line && this.source.end.column < column) {
return false;
}
return true;
}
return undefined;
};
Node.prototype.stringifyProperty = function (name) {
return (this.raws && this.raws[name]) || this[name];
};
Object.defineProperty(Node.prototype, "rawSpaceBefore", {
get: function () {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
if (rawSpace === undefined) {
rawSpace = this.spaces && this.spaces.before;
}
return rawSpace || "";
},
set: function (raw) {
(0, util_1.ensureObject)(this, "raws", "spaces");
this.raws.spaces.before = raw;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "rawSpaceAfter", {
get: function () {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
if (rawSpace === undefined) {
rawSpace = this.spaces.after;
}
return rawSpace || "";
},
set: function (raw) {
(0, util_1.ensureObject)(this, "raws", "spaces");
this.raws.spaces.after = raw;
},
enumerable: false,
configurable: true
});
Node.prototype.valueToString = function () {
return String(this.stringifyProperty("value"));
};
Node.prototype.toString = function () {
return [this.rawSpaceBefore, this.valueToString(), this.rawSpaceAfter].join("");
};
// Internal recursion entry point used by Container serialization. Leaf
// nodes don't recurse, so they ignore the depth/limit and stringify
// themselves. Containers override this to thread the nesting depth.
Node.prototype._stringify = function () {
return this.toString();
};
return Node;
}());
exports.default = Node;
//# sourceMappingURL=node.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _container = _interopRequireDefault(require("./container"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Pseudo = exports["default"] = /*#__PURE__*/function (_Container) {
_inheritsLoose(Pseudo, _Container);
function Pseudo(opts) {
var _this;
_this = _Container.call(this, opts) || this;
_this.type = _types.PSEUDO;
return _this;
}
var _proto = Pseudo.prototype;
_proto._stringify = function _stringify(options, depth, max) {
if (depth >= max) {
throw new Error("Cannot serialize selector: nesting depth exceeds the maximum of " + max + ".");
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var container_1 = __importDefault(require("./container"));
var types_1 = require("./types");
var Pseudo = /** @class */ (function (_super) {
__extends(Pseudo, _super);
function Pseudo(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.PSEUDO;
return _this;
}
var params = this.length ? '(' + this.map(function (child) {
return child._stringify(options, depth + 1, max);
}).join(',') + ')' : '';
return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
};
return Pseudo;
}(_container["default"]);
module.exports = exports.default;
Pseudo.prototype._stringify = function (options, depth, max) {
if (depth >= max) {
throw new Error("Cannot serialize selector: nesting depth exceeds the maximum of ".concat(max, "."));
}
var params = this.length
? "(" + this.map(function (child) { return child._stringify(options, depth + 1, max); }).join(",") + ")"
: "";
return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join("");
};
return Pseudo;
}(container_1.default));
exports.default = Pseudo;
//# sourceMappingURL=pseudo.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _container = _interopRequireDefault(require("./container"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Root = exports["default"] = /*#__PURE__*/function (_Container) {
_inheritsLoose(Root, _Container);
function Root(opts) {
var _this;
_this = _Container.call(this, opts) || this;
_this.type = _types.ROOT;
return _this;
}
var _proto = Root.prototype;
_proto._stringify = function _stringify(options, depth, max) {
var str = this.reduce(function (memo, selector) {
memo.push(selector._stringify(options, depth, max));
return memo;
}, []).join(',');
return this.trailingComma ? str + ',' : str;
};
_proto.error = function error(message, options) {
if (this._error) {
return this._error(message, options);
} else {
return new Error(message);
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var container_1 = __importDefault(require("./container"));
var types_1 = require("./types");
var Root = /** @class */ (function (_super) {
__extends(Root, _super);
function Root(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.ROOT;
return _this;
}
};
_createClass(Root, [{
key: "errorGenerator",
set: function set(handler) {
this._error = handler;
}
}]);
return Root;
}(_container["default"]);
module.exports = exports.default;
Root.prototype._stringify = function (options, depth, max) {
var str = this.reduce(function (memo, selector) {
memo.push(selector._stringify(options, depth, max));
return memo;
}, []).join(",");
return this.trailingComma ? str + "," : str;
};
Root.prototype.error = function (message, options) {
if (this._error) {
return this._error(message, options);
}
else {
return new Error(message);
}
};
Object.defineProperty(Root.prototype, "errorGenerator", {
set: function (handler) {
this._error = handler;
},
enumerable: false,
configurable: true
});
return Root;
}(container_1.default));
exports.default = Root;
//# sourceMappingURL=root.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _container = _interopRequireDefault(require("./container"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Selector = exports["default"] = /*#__PURE__*/function (_Container) {
_inheritsLoose(Selector, _Container);
function Selector(opts) {
var _this;
_this = _Container.call(this, opts) || this;
_this.type = _types.SELECTOR;
return _this;
}
return Selector;
}(_container["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var container_1 = __importDefault(require("./container"));
var types_1 = require("./types");
var Selector = /** @class */ (function (_super) {
__extends(Selector, _super);
function Selector(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.SELECTOR;
return _this;
}
return Selector;
}(container_1.default));
exports.default = Selector;
//# sourceMappingURL=selector.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _node = _interopRequireDefault(require("./node"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var String = exports["default"] = /*#__PURE__*/function (_Node) {
_inheritsLoose(String, _Node);
function String(opts) {
var _this;
_this = _Node.call(this, opts) || this;
_this.type = _types.STRING;
return _this;
}
return String;
}(_node["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var node_1 = __importDefault(require("./node"));
var types_1 = require("./types");
var String = /** @class */ (function (_super) {
__extends(String, _super);
function String(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.STRING;
return _this;
}
return String;
}(node_1.default));
exports.default = String;
//# sourceMappingURL=string.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _namespace = _interopRequireDefault(require("./namespace"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Tag = exports["default"] = /*#__PURE__*/function (_Namespace) {
_inheritsLoose(Tag, _Namespace);
function Tag(opts) {
var _this;
_this = _Namespace.call(this, opts) || this;
_this.type = _types.TAG;
return _this;
}
return Tag;
}(_namespace["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var namespace_1 = __importDefault(require("./namespace"));
var types_1 = require("./types");
var Tag = /** @class */ (function (_super) {
__extends(Tag, _super);
function Tag(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.TAG;
return _this;
}
return Tag;
}(namespace_1.default));
exports.default = Tag;
//# sourceMappingURL=tag.js.map
"use strict";
exports.__esModule = true;
exports.UNIVERSAL = exports.TAG = exports.STRING = exports.SELECTOR = exports.ROOT = exports.PSEUDO = exports.NESTING = exports.ID = exports.COMMENT = exports.COMBINATOR = exports.CLASS = exports.ATTRIBUTE = void 0;
var TAG = exports.TAG = 'tag';
var STRING = exports.STRING = 'string';
var SELECTOR = exports.SELECTOR = 'selector';
var ROOT = exports.ROOT = 'root';
var PSEUDO = exports.PSEUDO = 'pseudo';
var NESTING = exports.NESTING = 'nesting';
var ID = exports.ID = 'id';
var COMMENT = exports.COMMENT = 'comment';
var COMBINATOR = exports.COMBINATOR = 'combinator';
var CLASS = exports.CLASS = 'class';
var ATTRIBUTE = exports.ATTRIBUTE = 'attribute';
var UNIVERSAL = exports.UNIVERSAL = 'universal';
Object.defineProperty(exports, "__esModule", { value: true });
exports.UNIVERSAL = exports.ATTRIBUTE = exports.CLASS = exports.COMBINATOR = exports.COMMENT = exports.ID = exports.NESTING = exports.PSEUDO = exports.ROOT = exports.SELECTOR = exports.STRING = exports.TAG = void 0;
exports.TAG = "tag";
exports.STRING = "string";
exports.SELECTOR = "selector";
exports.ROOT = "root";
exports.PSEUDO = "pseudo";
exports.NESTING = "nesting";
exports.ID = "id";
exports.COMMENT = "comment";
exports.COMBINATOR = "combinator";
exports.CLASS = "class";
exports.ATTRIBUTE = "attribute";
exports.UNIVERSAL = "universal";
//# sourceMappingURL=types.js.map
"use strict";
exports.__esModule = true;
exports["default"] = void 0;
var _namespace = _interopRequireDefault(require("./namespace"));
var _types = require("./types");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var Universal = exports["default"] = /*#__PURE__*/function (_Namespace) {
_inheritsLoose(Universal, _Namespace);
function Universal(opts) {
var _this;
_this = _Namespace.call(this, opts) || this;
_this.type = _types.UNIVERSAL;
_this.value = '*';
return _this;
}
return Universal;
}(_namespace["default"]);
module.exports = exports.default;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var namespace_1 = __importDefault(require("./namespace"));
var types_1 = require("./types");
var Universal = /** @class */ (function (_super) {
__extends(Universal, _super);
function Universal(opts) {
var _this = _super.call(this, opts) || this;
_this.type = types_1.UNIVERSAL;
_this.value = "*";
return _this;
}
return Universal;
}(namespace_1.default));
exports.default = Universal;
//# sourceMappingURL=universal.js.map
"use strict";
exports.__esModule = true;
exports["default"] = sortAscending;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = sortAscending;
function sortAscending(list) {
return list.sort(function (a, b) {
return a - b;
});
return list.sort(function (a, b) { return a - b; });
}
;
module.exports = exports.default;
//# sourceMappingURL=sortAscending.js.map
"use strict";
exports.__esModule = true;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FIELDS = void 0;
exports["default"] = tokenize;
var t = _interopRequireWildcard(require("./tokenTypes"));
var _unescapable, _wordDelimiters;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
var wordDelimiters = (_wordDelimiters = {}, _wordDelimiters[t.space] = true, _wordDelimiters[t.tab] = true, _wordDelimiters[t.newline] = true, _wordDelimiters[t.cr] = true, _wordDelimiters[t.feed] = true, _wordDelimiters[t.ampersand] = true, _wordDelimiters[t.asterisk] = true, _wordDelimiters[t.bang] = true, _wordDelimiters[t.comma] = true, _wordDelimiters[t.colon] = true, _wordDelimiters[t.semicolon] = true, _wordDelimiters[t.openParenthesis] = true, _wordDelimiters[t.closeParenthesis] = true, _wordDelimiters[t.openSquare] = true, _wordDelimiters[t.closeSquare] = true, _wordDelimiters[t.singleQuote] = true, _wordDelimiters[t.doubleQuote] = true, _wordDelimiters[t.plus] = true, _wordDelimiters[t.pipe] = true, _wordDelimiters[t.tilde] = true, _wordDelimiters[t.greaterThan] = true, _wordDelimiters[t.equals] = true, _wordDelimiters[t.dollar] = true, _wordDelimiters[t.caret] = true, _wordDelimiters[t.slash] = true, _wordDelimiters);
exports.default = tokenize;
var t = __importStar(require("./tokenTypes"));
var unescapable = (_a = {},
_a[t.tab] = true,
_a[t.newline] = true,
_a[t.cr] = true,
_a[t.feed] = true,
_a);
var wordDelimiters = (_b = {},
_b[t.space] = true,
_b[t.tab] = true,
_b[t.newline] = true,
_b[t.cr] = true,
_b[t.feed] = true,
_b[t.ampersand] = true,
_b[t.asterisk] = true,
_b[t.bang] = true,
_b[t.comma] = true,
_b[t.colon] = true,
_b[t.semicolon] = true,
_b[t.openParenthesis] = true,
_b[t.closeParenthesis] = true,
_b[t.openSquare] = true,
_b[t.closeSquare] = true,
_b[t.singleQuote] = true,
_b[t.doubleQuote] = true,
_b[t.plus] = true,
_b[t.pipe] = true,
_b[t.tilde] = true,
_b[t.greaterThan] = true,
_b[t.equals] = true,
_b[t.dollar] = true,
_b[t.caret] = true,
_b[t.slash] = true,
_b);
var hex = {};
var hexChars = "0123456789abcdefABCDEF";
for (var i = 0; i < hexChars.length; i++) {
hex[hexChars.charCodeAt(i)] = true;
hex[hexChars.charCodeAt(i)] = true;
}
/**

@@ -23,18 +84,19 @@ * Returns the last index of the bar css word

function consumeWord(css, start) {
var next = start;
var code;
do {
code = css.charCodeAt(next);
if (wordDelimiters[code]) {
return next - 1;
} else if (code === t.backslash) {
next = consumeEscape(css, next) + 1;
} else {
// All other characters are part of the word
next++;
}
} while (next < css.length);
return next - 1;
var next = start;
var code;
do {
code = css.charCodeAt(next);
if (wordDelimiters[code]) {
return next - 1;
}
else if (code === t.backslash) {
next = consumeEscape(css, next) + 1;
}
else {
// All other characters are part of the word
next++;
}
} while (next < css.length);
return next - 1;
}
/**

@@ -46,194 +108,196 @@ * Returns the last index of the escape sequence

function consumeEscape(css, start) {
var next = start;
var code = css.charCodeAt(next + 1);
if (unescapable[code]) {
// just consume the escape char
} else if (hex[code]) {
var hexDigits = 0;
// consume up to 6 hex chars
do {
next++;
hexDigits++;
code = css.charCodeAt(next + 1);
} while (hex[code] && hexDigits < 6);
// if fewer than 6 hex chars, a trailing space ends the escape
if (hexDigits < 6 && code === t.space) {
next++;
var next = start;
var code = css.charCodeAt(next + 1);
if (unescapable[code]) {
// just consume the escape char
}
} else {
// the next char is part of the current word
next++;
}
return next;
else if (hex[code]) {
var hexDigits = 0;
// consume up to 6 hex chars
do {
next++;
hexDigits++;
code = css.charCodeAt(next + 1);
} while (hex[code] && hexDigits < 6);
// if fewer than 6 hex chars, a trailing space ends the escape
if (hexDigits < 6 && code === t.space) {
next++;
}
}
else {
// the next char is part of the current word
next++;
}
return next;
}
var FIELDS = exports.FIELDS = {
TYPE: 0,
START_LINE: 1,
START_COL: 2,
END_LINE: 3,
END_COL: 4,
START_POS: 5,
END_POS: 6
exports.FIELDS = {
TYPE: 0,
START_LINE: 1,
START_COL: 2,
END_LINE: 3,
END_COL: 4,
START_POS: 5,
END_POS: 6,
};
function tokenize(input) {
var tokens = [];
var css = input.css.valueOf();
var _css = css,
length = _css.length;
var offset = -1;
var line = 1;
var start = 0;
var end = 0;
var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
function unclosed(what, fix) {
if (input.safe) {
// fyi: this is never set to true.
css += fix;
next = css.length - 1;
} else {
throw input.error('Unclosed ' + what, line, start - offset, start);
var tokens = [];
var css = input.css.valueOf();
var length = css.length;
var offset = -1;
var line = 1;
var start = 0;
var end = 0;
var code, content, endColumn, endLine, escaped, escapePos, last, lines, next, nextLine, nextOffset, quote, tokenType;
function unclosed(what, fix) {
if (input.safe) {
// fyi: this is never set to true.
css += fix;
next = css.length - 1;
}
else {
throw input.error("Unclosed " + what, line, start - offset, start);
}
}
}
while (start < length) {
code = css.charCodeAt(start);
if (code === t.newline) {
offset = start;
line += 1;
}
switch (code) {
case t.space:
case t.tab:
case t.newline:
case t.cr:
case t.feed:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
if (code === t.newline) {
offset = next;
while (start < length) {
code = css.charCodeAt(start);
if (code === t.newline) {
offset = start;
line += 1;
}
} while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
tokenType = t.space;
endLine = line;
endColumn = next - offset - 1;
end = next;
break;
case t.plus:
case t.greaterThan:
case t.tilde:
case t.pipe:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
} while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
tokenType = t.combinator;
endLine = line;
endColumn = start - offset;
end = next;
break;
// Consume these characters as single tokens.
case t.asterisk:
case t.ampersand:
case t.bang:
case t.comma:
case t.equals:
case t.dollar:
case t.caret:
case t.openSquare:
case t.closeSquare:
case t.colon:
case t.semicolon:
case t.openParenthesis:
case t.closeParenthesis:
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
case t.singleQuote:
case t.doubleQuote:
quote = code === t.singleQuote ? "'" : '"';
next = start;
do {
escaped = false;
next = css.indexOf(quote, next + 1);
if (next === -1) {
unclosed('quote', quote);
}
escapePos = next;
while (css.charCodeAt(escapePos - 1) === t.backslash) {
escapePos -= 1;
escaped = !escaped;
}
} while (escaped);
tokenType = t.str;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
default:
if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
next = css.indexOf('*/', start + 2) + 1;
if (next === 0) {
unclosed('comment', '*/');
}
content = css.slice(start, next + 1);
lines = content.split('\n');
last = lines.length - 1;
if (last > 0) {
nextLine = line + last;
nextOffset = next - lines[last].length;
} else {
nextLine = line;
nextOffset = offset;
}
tokenType = t.comment;
line = nextLine;
endLine = nextLine;
endColumn = next - nextOffset;
} else if (code === t.slash) {
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
} else {
next = consumeWord(css, start);
tokenType = t.word;
endLine = line;
endColumn = next - offset;
}
end = next + 1;
break;
switch (code) {
case t.space:
case t.tab:
case t.newline:
case t.cr:
case t.feed:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
if (code === t.newline) {
offset = next;
line += 1;
}
} while (code === t.space ||
code === t.newline ||
code === t.tab ||
code === t.cr ||
code === t.feed);
tokenType = t.space;
endLine = line;
endColumn = next - offset - 1;
end = next;
break;
case t.plus:
case t.greaterThan:
case t.tilde:
case t.pipe:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
} while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
tokenType = t.combinator;
endLine = line;
endColumn = start - offset;
end = next;
break;
// Consume these characters as single tokens.
case t.asterisk:
case t.ampersand:
case t.bang:
case t.comma:
case t.equals:
case t.dollar:
case t.caret:
case t.openSquare:
case t.closeSquare:
case t.colon:
case t.semicolon:
case t.openParenthesis:
case t.closeParenthesis:
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
case t.singleQuote:
case t.doubleQuote:
quote = code === t.singleQuote ? "'" : '"';
next = start;
do {
escaped = false;
next = css.indexOf(quote, next + 1);
if (next === -1) {
unclosed("quote", quote);
}
escapePos = next;
while (css.charCodeAt(escapePos - 1) === t.backslash) {
escapePos -= 1;
escaped = !escaped;
}
} while (escaped);
tokenType = t.str;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
default:
if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
next = css.indexOf("*/", start + 2) + 1;
if (next === 0) {
unclosed("comment", "*/");
}
content = css.slice(start, next + 1);
lines = content.split("\n");
last = lines.length - 1;
if (last > 0) {
nextLine = line + last;
nextOffset = next - lines[last].length;
}
else {
nextLine = line;
nextOffset = offset;
}
tokenType = t.comment;
line = nextLine;
endLine = nextLine;
endColumn = next - nextOffset;
}
else if (code === t.slash) {
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
}
else {
next = consumeWord(css, start);
tokenType = t.word;
endLine = line;
endColumn = next - offset;
}
end = next + 1;
break;
}
// Ensure that the token structure remains consistent
tokens.push([
tokenType, // [0] Token type
line, // [1] Starting line
start - offset, // [2] Starting column
endLine, // [3] Ending line
endColumn, // [4] Ending column
start, // [5] Start position / Source index
end, // [6] End position
]);
// Reset offset for the next token
if (nextOffset) {
offset = nextOffset;
nextOffset = null;
}
start = end;
}
// Ensure that the token structure remains consistent
tokens.push([tokenType,
// [0] Token type
line,
// [1] Starting line
start - offset,
// [2] Starting column
endLine,
// [3] Ending line
endColumn,
// [4] Ending column
start,
// [5] Start position / Source index
end // [6] End position
]);
// Reset offset for the next token
if (nextOffset) {
offset = nextOffset;
nextOffset = null;
}
start = end;
}
return tokens;
}
return tokens;
}
//# sourceMappingURL=tokenize.js.map
"use strict";
exports.__esModule = true;
exports.word = exports.tilde = exports.tab = exports.str = exports.space = exports.slash = exports.singleQuote = exports.semicolon = exports.plus = exports.pipe = exports.openSquare = exports.openParenthesis = exports.newline = exports.greaterThan = exports.feed = exports.equals = exports.doubleQuote = exports.dollar = exports.cr = exports.comment = exports.comma = exports.combinator = exports.colon = exports.closeSquare = exports.closeParenthesis = exports.caret = exports.bang = exports.backslash = exports.at = exports.asterisk = exports.ampersand = void 0;
var ampersand = exports.ampersand = 38; // `&`.charCodeAt(0);
var asterisk = exports.asterisk = 42; // `*`.charCodeAt(0);
var at = exports.at = 64; // `@`.charCodeAt(0);
var comma = exports.comma = 44; // `,`.charCodeAt(0);
var colon = exports.colon = 58; // `:`.charCodeAt(0);
var semicolon = exports.semicolon = 59; // `;`.charCodeAt(0);
var openParenthesis = exports.openParenthesis = 40; // `(`.charCodeAt(0);
var closeParenthesis = exports.closeParenthesis = 41; // `)`.charCodeAt(0);
var openSquare = exports.openSquare = 91; // `[`.charCodeAt(0);
var closeSquare = exports.closeSquare = 93; // `]`.charCodeAt(0);
var dollar = exports.dollar = 36; // `$`.charCodeAt(0);
var tilde = exports.tilde = 126; // `~`.charCodeAt(0);
var caret = exports.caret = 94; // `^`.charCodeAt(0);
var plus = exports.plus = 43; // `+`.charCodeAt(0);
var equals = exports.equals = 61; // `=`.charCodeAt(0);
var pipe = exports.pipe = 124; // `|`.charCodeAt(0);
var greaterThan = exports.greaterThan = 62; // `>`.charCodeAt(0);
var space = exports.space = 32; // ` `.charCodeAt(0);
var singleQuote = exports.singleQuote = 39; // `'`.charCodeAt(0);
var doubleQuote = exports.doubleQuote = 34; // `"`.charCodeAt(0);
var slash = exports.slash = 47; // `/`.charCodeAt(0);
var bang = exports.bang = 33; // `!`.charCodeAt(0);
var backslash = exports.backslash = 92; // '\\'.charCodeAt(0);
var cr = exports.cr = 13; // '\r'.charCodeAt(0);
var feed = exports.feed = 12; // '\f'.charCodeAt(0);
var newline = exports.newline = 10; // '\n'.charCodeAt(0);
var tab = exports.tab = 9; // '\t'.charCodeAt(0);
Object.defineProperty(exports, "__esModule", { value: true });
exports.combinator = exports.word = exports.comment = exports.str = exports.tab = exports.newline = exports.feed = exports.cr = exports.backslash = exports.bang = exports.slash = exports.doubleQuote = exports.singleQuote = exports.space = exports.greaterThan = exports.pipe = exports.equals = exports.plus = exports.caret = exports.tilde = exports.dollar = exports.closeSquare = exports.openSquare = exports.closeParenthesis = exports.openParenthesis = exports.semicolon = exports.colon = exports.comma = exports.at = exports.asterisk = exports.ampersand = void 0;
exports.ampersand = 38; // `&`.charCodeAt(0);
exports.asterisk = 42; // `*`.charCodeAt(0);
exports.at = 64; // `@`.charCodeAt(0);
exports.comma = 44; // `,`.charCodeAt(0);
exports.colon = 58; // `:`.charCodeAt(0);
exports.semicolon = 59; // `;`.charCodeAt(0);
exports.openParenthesis = 40; // `(`.charCodeAt(0);
exports.closeParenthesis = 41; // `)`.charCodeAt(0);
exports.openSquare = 91; // `[`.charCodeAt(0);
exports.closeSquare = 93; // `]`.charCodeAt(0);
exports.dollar = 36; // `$`.charCodeAt(0);
exports.tilde = 126; // `~`.charCodeAt(0);
exports.caret = 94; // `^`.charCodeAt(0);
exports.plus = 43; // `+`.charCodeAt(0);
exports.equals = 61; // `=`.charCodeAt(0);
exports.pipe = 124; // `|`.charCodeAt(0);
exports.greaterThan = 62; // `>`.charCodeAt(0);
exports.space = 32; // ` `.charCodeAt(0);
exports.singleQuote = 39; // `'`.charCodeAt(0);
exports.doubleQuote = 34; // `"`.charCodeAt(0);
exports.slash = 47; // `/`.charCodeAt(0);
exports.bang = 33; // `!`.charCodeAt(0);
exports.backslash = 92; // '\\'.charCodeAt(0);
exports.cr = 13; // '\r'.charCodeAt(0);
exports.feed = 12; // '\f'.charCodeAt(0);
exports.newline = 10; // '\n'.charCodeAt(0);
exports.tab = 9; // '\t'.charCodeAt(0);
// Expose aliases primarily for readability.
var str = exports.str = singleQuote;
exports.str = exports.singleQuote;
// No good single character representation!
var comment = exports.comment = -1;
var word = exports.word = -2;
var combinator = exports.combinator = -3;
exports.comment = -1;
exports.word = -2;
exports.combinator = -3;
//# sourceMappingURL=tokenTypes.js.map
"use strict";
exports.__esModule = true;
exports["default"] = ensureObject;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ensureObject;
function ensureObject(obj) {
for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
props[_key - 1] = arguments[_key];
}
while (props.length > 0) {
var prop = props.shift();
if (!obj[prop]) {
obj[prop] = {};
var props = [];
for (var _i = 1; _i < arguments.length; _i++) {
props[_i - 1] = arguments[_i];
}
obj = obj[prop];
}
while (props.length > 0) {
var prop = props.shift();
if (!obj[prop]) {
obj[prop] = {};
}
obj = obj[prop];
}
}
module.exports = exports.default;
//# sourceMappingURL=ensureObject.js.map
"use strict";
exports.__esModule = true;
exports["default"] = getProp;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getProp;
function getProp(obj) {
for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
props[_key - 1] = arguments[_key];
}
while (props.length > 0) {
var prop = props.shift();
if (!obj[prop]) {
return undefined;
var props = [];
for (var _i = 1; _i < arguments.length; _i++) {
props[_i - 1] = arguments[_i];
}
obj = obj[prop];
}
return obj;
while (props.length > 0) {
var prop = props.shift();
if (!obj[prop]) {
return undefined;
}
obj = obj[prop];
}
return obj;
}
module.exports = exports.default;
//# sourceMappingURL=getProp.js.map
"use strict";
exports.__esModule = true;
exports.unesc = exports.stripComments = exports.resolveMaxNestingDepth = exports.getProp = exports.ensureObject = exports.MAX_NESTING_DEPTH = void 0;
var _unesc = _interopRequireDefault(require("./unesc"));
exports.unesc = _unesc["default"];
var _getProp = _interopRequireDefault(require("./getProp"));
exports.getProp = _getProp["default"];
var _ensureObject = _interopRequireDefault(require("./ensureObject"));
exports.ensureObject = _ensureObject["default"];
var _stripComments = _interopRequireDefault(require("./stripComments"));
exports.stripComments = _stripComments["default"];
var _maxNestingDepth = _interopRequireWildcard(require("./maxNestingDepth"));
exports.resolveMaxNestingDepth = _maxNestingDepth["default"];
exports.MAX_NESTING_DEPTH = _maxNestingDepth.MAX_NESTING_DEPTH;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) { "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); } return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_NESTING_DEPTH = exports.resolveMaxNestingDepth = exports.stripComments = exports.ensureObject = exports.getProp = exports.unesc = void 0;
var unesc_1 = require("./unesc");
Object.defineProperty(exports, "unesc", { enumerable: true, get: function () { return __importDefault(unesc_1).default; } });
var getProp_1 = require("./getProp");
Object.defineProperty(exports, "getProp", { enumerable: true, get: function () { return __importDefault(getProp_1).default; } });
var ensureObject_1 = require("./ensureObject");
Object.defineProperty(exports, "ensureObject", { enumerable: true, get: function () { return __importDefault(ensureObject_1).default; } });
var stripComments_1 = require("./stripComments");
Object.defineProperty(exports, "stripComments", { enumerable: true, get: function () { return __importDefault(stripComments_1).default; } });
var maxNestingDepth_1 = require("./maxNestingDepth");
Object.defineProperty(exports, "resolveMaxNestingDepth", { enumerable: true, get: function () { return __importDefault(maxNestingDepth_1).default; } });
Object.defineProperty(exports, "MAX_NESTING_DEPTH", { enumerable: true, get: function () { return maxNestingDepth_1.MAX_NESTING_DEPTH; } });
//# sourceMappingURL=index.js.map
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_NESTING_DEPTH = void 0;
exports["default"] = resolveMaxNestingDepth;
exports.default = resolveMaxNestingDepth;
/**

@@ -13,4 +12,3 @@ * The default maximum selector nesting depth allowed when parsing or

*/
var MAX_NESTING_DEPTH = exports.MAX_NESTING_DEPTH = 256;
exports.MAX_NESTING_DEPTH = 256;
/**

@@ -26,3 +24,4 @@ * Coerce a user-supplied nesting-depth limit into a safe value. Anything that

function resolveMaxNestingDepth(value) {
return Number.isSafeInteger(value) && value >= 0 ? value : MAX_NESTING_DEPTH;
}
return Number.isSafeInteger(value) && value >= 0 ? value : exports.MAX_NESTING_DEPTH;
}
//# sourceMappingURL=maxNestingDepth.js.map
"use strict";
exports.__esModule = true;
exports["default"] = stripComments;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = stripComments;
function stripComments(str) {
var s = "";
var commentStart = str.indexOf("/*");
var lastEnd = 0;
while (commentStart >= 0) {
s = s + str.slice(lastEnd, commentStart);
var commentEnd = str.indexOf("*/", commentStart + 2);
if (commentEnd < 0) {
return s;
var s = "";
var commentStart = str.indexOf("/*");
var lastEnd = 0;
while (commentStart >= 0) {
s = s + str.slice(lastEnd, commentStart);
var commentEnd = str.indexOf("*/", commentStart + 2);
if (commentEnd < 0) {
return s;
}
lastEnd = commentEnd + 2;
commentStart = str.indexOf("/*", lastEnd);
}
lastEnd = commentEnd + 2;
commentStart = str.indexOf("/*", lastEnd);
}
s = s + str.slice(lastEnd);
return s;
s = s + str.slice(lastEnd);
return s;
}
module.exports = exports.default;
//# sourceMappingURL=stripComments.js.map
"use strict";
exports.__esModule = true;
exports["default"] = unesc;
// Many thanks for this post which made this migration much easier.
// https://mathiasbynens.be/notes/css-escapes
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = unesc;
/**
*
* @param {string} str
*
* @param {string} str
* @returns {[string, number]|undefined}
*/
function gobbleHex(str) {
var lower = str.toLowerCase();
var hex = '';
var spaceTerminated = false;
for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
var code = lower.charCodeAt(i);
// check to see if we are dealing with a valid hex char [a-f|0-9]
var valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
// https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
spaceTerminated = code === 32;
if (!valid) {
break;
var lower = str.toLowerCase();
var hex = "";
var spaceTerminated = false;
for (var i = 0; i < 6 && lower[i] !== undefined; i++) {
var code = lower.charCodeAt(i);
// check to see if we are dealing with a valid hex char [a-f|0-9]
var valid = (code >= 97 && code <= 102) || (code >= 48 && code <= 57);
// https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
spaceTerminated = code === 32;
if (!valid) {
break;
}
hex += lower[i];
}
hex += lower[i];
}
if (hex.length === 0) {
return undefined;
}
var codePoint = parseInt(hex, 16);
var isSurrogate = codePoint >= 0xD800 && codePoint <= 0xDFFF;
// Add special case for
// "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
// https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10FFFF) {
return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
}
return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
if (hex.length === 0) {
return undefined;
}
var codePoint = parseInt(hex, 16);
var isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff;
// Add special case for
// "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
// https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
}
return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
}
var CONTAINS_ESCAPE = /\\/;
function unesc(str) {
var needToProcess = CONTAINS_ESCAPE.test(str);
if (!needToProcess) {
return str;
}
var ret = "";
for (var i = 0; i < str.length; i++) {
if (str[i] === "\\") {
var gobbled = gobbleHex(str.slice(i + 1, i + 7));
if (gobbled !== undefined) {
ret += gobbled[0];
i += gobbled[1];
continue;
}
// Retain a pair of \\ if double escaped `\\\\`
// https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
if (str[i + 1] === "\\") {
ret += "\\";
i++;
continue;
}
// if \\ is at the end of the string retain it
// https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
if (str.length === i + 1) {
var needToProcess = CONTAINS_ESCAPE.test(str);
if (!needToProcess) {
return str;
}
var ret = "";
for (var i = 0; i < str.length; i++) {
if (str[i] === "\\") {
var gobbled = gobbleHex(str.slice(i + 1, i + 7));
if (gobbled !== undefined) {
ret += gobbled[0];
i += gobbled[1];
continue;
}
// Retain a pair of \\ if double escaped `\\\\`
// https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
if (str[i + 1] === "\\") {
ret += "\\";
i++;
continue;
}
// if \\ is at the end of the string retain it
// https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
if (str.length === i + 1) {
ret += str[i];
}
continue;
}
ret += str[i];
}
continue;
}
ret += str[i];
}
return ret;
return ret;
}
module.exports = exports.default;
//# sourceMappingURL=unesc.js.map
{
"name": "postcss-selector-parser",
"version": "7.1.2",
"description": "Selector parser with built in methods for working with selector strings.",
"version": "7.1.3",
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/eslint-parser": "^7.11.5",
"@babel/eslint-plugin": "^7.11.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"ava": "^5.1.0",
"babel-plugin-add-module-exports": "^1.0.4",
"coveralls-next": "^4.2.1",
"del-cli": "^5.0.0",
"eslint": "^8.28.0",
"eslint-plugin-import": "^2.26.0",
"glob": "^8.0.3",
"minimist": "^1.2.5",
"nyc": "^15.1.0",
"oxfmt": "^0.54.0",
"oxlint": "^1.69.0",
"postcss": "^8.4.31",
"semver": "^7.3.2",
"typescript": "^4.0.3"
"typescript": "^5.4.0"
},

@@ -33,13 +19,19 @@ "main": "dist/index.js",

"postcss-selector-parser.d.ts",
"!**/__tests__"
"!**/__tests__",
"!dist/**/*.map"
],
"scripts": {
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
"build": "npm run clean && tsc",
"typecheck": "tsc --noEmit --strict postcss-selector-parser.d.ts postcss-selector-parser.test.ts",
"pretest": "eslint src && npm run typecheck",
"prepare": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"lintfix": "eslint --fix src",
"report": "nyc report --reporter=html",
"test:node-lt-20": "nyc ava src/__tests__/*.mjs",
"test": "nyc ava src/__tests__/*.mjs --node-arguments=--no-experimental-detect-module",
"testone": "ava",
"lint": "oxlint",
"lint:fix": "oxlint --fix",
"format": "oxfmt src",
"format:check": "oxfmt --check src",
"pretests": "npm run build",
"tests": "node --test src/__tests__/*.mjs",
"precoverage": "npm run build",
"coverage": "node --enable-source-maps --test --experimental-test-coverage --test-coverage-exclude=\"**/__tests__/**\" --test-coverage-lines=94 --test-coverage-branches=94 --test-coverage-functions=96 --test-reporter=spec src/__tests__/*.mjs",
"test": "npm run lint && npm run typecheck && npm run coverage",
"prepare": "npm run build",
"release": "npx npmpub"

@@ -68,17 +60,6 @@ },

],
"repository": "postcss/postcss-selector-parser",
"ava": {
"require": [
"@babel/register"
],
"concurrency": 5,
"timeout": "25s",
"nodeArguments": []
},
"nyc": {
"exclude": [
"node_modules",
"**/__tests__"
]
"repository": {
"type": "git",
"url": "https://github.com/postcss/postcss-selector-parser.git"
}
}