selparsecss-selector 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +874 -0
- package/CHANGELOG.md +573 -0
- package/LICENSE-MIT +22 -0
- package/README.md +87 -0
- package/dist/index.js +45 -0
- package/dist/parser.js +1116 -0
- package/dist/processor.js +153 -0
- package/dist/selectors/attribute.js +440 -0
- package/dist/selectors/className.js +59 -0
- package/dist/selectors/combinator.js +33 -0
- package/dist/selectors/comment.js +33 -0
- package/dist/selectors/constructors.js +43 -0
- package/dist/selectors/container.js +433 -0
- package/dist/selectors/fragment.js +13 -0
- package/dist/selectors/guards.js +61 -0
- package/dist/selectors/id.js +36 -0
- package/dist/selectors/index.js +20 -0
- package/dist/selectors/namespace.js +96 -0
- package/dist/selectors/nesting.js +34 -0
- package/dist/selectors/node.js +195 -0
- package/dist/selectors/pseudo.js +45 -0
- package/dist/selectors/root.js +56 -0
- package/dist/selectors/selector.js +33 -0
- package/dist/selectors/string.js +33 -0
- package/dist/selectors/tag.js +33 -0
- package/dist/selectors/types.js +16 -0
- package/dist/selectors/universal.js +34 -0
- package/dist/selectors/wrapper.js +14 -0
- package/dist/sortAscending.js +7 -0
- package/dist/tokenTypes.js +37 -0
- package/dist/tokenize.js +301 -0
- package/dist/util/ensureObject.js +17 -0
- package/dist/util/getProp.js +18 -0
- package/dist/util/index.js +18 -0
- package/dist/util/maxNestingDepth.js +25 -0
- package/dist/util/propAssemble.js +5 -0
- package/dist/util/propBind.js +9 -0
- package/dist/util/propCache.js +9 -0
- package/dist/util/propPaths.js +8 -0
- package/dist/util/propSync.js +11 -0
- package/dist/util/stripComments.js +20 -0
- package/dist/util/unesc.js +71 -0
- package/dist/util/webpack.min.js +1 -0
- package/package.json +62 -0
- package/selparsecss-selector.d.ts +570 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var parser_1 = __importDefault(require("./parser"));
|
|
7
|
+
var Processor = /** @class */ (function () {
|
|
8
|
+
function Processor(func, options) {
|
|
9
|
+
this.func = func || function noop() { };
|
|
10
|
+
this.funcRes = null;
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
Processor.prototype._shouldUpdateSelector = function (rule, options) {
|
|
14
|
+
if (options === void 0) { options = {}; }
|
|
15
|
+
var merged = Object.assign({}, this.options, options);
|
|
16
|
+
if (merged.updateSelector === false) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return typeof rule !== "string";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
Processor.prototype._isLossy = function (options) {
|
|
24
|
+
if (options === void 0) { options = {}; }
|
|
25
|
+
var merged = Object.assign({}, this.options, options);
|
|
26
|
+
if (merged.lossless === false) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
Processor.prototype._root = function (rule, options) {
|
|
34
|
+
if (options === void 0) { options = {}; }
|
|
35
|
+
var parser = new parser_1.default(rule, this._parseOptions(options));
|
|
36
|
+
return parser.root;
|
|
37
|
+
};
|
|
38
|
+
Processor.prototype._parseOptions = function (options) {
|
|
39
|
+
var merged = Object.assign({}, this.options, options);
|
|
40
|
+
return {
|
|
41
|
+
lossy: this._isLossy(merged),
|
|
42
|
+
maxNestingDepth: merged.maxNestingDepth,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
Processor.prototype._stringifyOptions = function (options) {
|
|
46
|
+
var merged = Object.assign({}, this.options, options);
|
|
47
|
+
return {
|
|
48
|
+
maxNestingDepth: merged.maxNestingDepth,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
Processor.prototype._run = function (rule, options) {
|
|
52
|
+
var _this = this;
|
|
53
|
+
if (options === void 0) { options = {}; }
|
|
54
|
+
return new Promise(function (resolve, reject) {
|
|
55
|
+
try {
|
|
56
|
+
var root_1 = _this._root(rule, options);
|
|
57
|
+
Promise.resolve(_this.func(root_1))
|
|
58
|
+
.then(function (transform) {
|
|
59
|
+
var string = undefined;
|
|
60
|
+
if (_this._shouldUpdateSelector(rule, options)) {
|
|
61
|
+
string = root_1.toString(_this._stringifyOptions(options));
|
|
62
|
+
rule.selector = string;
|
|
63
|
+
}
|
|
64
|
+
return { transform: transform, root: root_1, string: string };
|
|
65
|
+
})
|
|
66
|
+
.then(resolve, reject);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
reject(e);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
Processor.prototype._runSync = function (rule, options) {
|
|
75
|
+
if (options === void 0) { options = {}; }
|
|
76
|
+
var root = this._root(rule, options);
|
|
77
|
+
var transform = this.func(root);
|
|
78
|
+
if (transform && typeof transform.then === "function") {
|
|
79
|
+
throw new Error("Selector processor returned a promise to a synchronous call.");
|
|
80
|
+
}
|
|
81
|
+
var string = undefined;
|
|
82
|
+
if (options.updateSelector && typeof rule !== "string") {
|
|
83
|
+
string = root.toString(this._stringifyOptions(options));
|
|
84
|
+
rule.selector = string;
|
|
85
|
+
}
|
|
86
|
+
return { transform: transform, root: root, string: string };
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Process rule into a selector AST.
|
|
90
|
+
*
|
|
91
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
92
|
+
* @param options The options for processing
|
|
93
|
+
* @returns {Promise<parser.Root>} The AST of the selector after processing it.
|
|
94
|
+
*/
|
|
95
|
+
Processor.prototype.ast = function (rule, options) {
|
|
96
|
+
return this._run(rule, options).then(function (result) { return result.root; });
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Process rule into a selector AST synchronously.
|
|
100
|
+
*
|
|
101
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
102
|
+
* @param options The options for processing
|
|
103
|
+
* @returns {parser.Root} The AST of the selector after processing it.
|
|
104
|
+
*/
|
|
105
|
+
Processor.prototype.astSync = function (rule, options) {
|
|
106
|
+
return this._runSync(rule, options).root;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Process a selector into a transformed value asynchronously
|
|
110
|
+
*
|
|
111
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
112
|
+
* @param options The options for processing
|
|
113
|
+
* @returns {Promise<any>} The value returned by the processor.
|
|
114
|
+
*/
|
|
115
|
+
Processor.prototype.transform = function (rule, options) {
|
|
116
|
+
return this._run(rule, options).then(function (result) { return result.transform; });
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Process a selector into a transformed value synchronously.
|
|
120
|
+
*
|
|
121
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
122
|
+
* @param options The options for processing
|
|
123
|
+
* @returns {any} The value returned by the processor.
|
|
124
|
+
*/
|
|
125
|
+
Processor.prototype.transformSync = function (rule, options) {
|
|
126
|
+
return this._runSync(rule, options).transform;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Process a selector into a new selector string asynchronously.
|
|
130
|
+
*
|
|
131
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
132
|
+
* @param options The options for processing
|
|
133
|
+
* @returns {string} the selector after processing.
|
|
134
|
+
*/
|
|
135
|
+
Processor.prototype.process = function (rule, options) {
|
|
136
|
+
var _this = this;
|
|
137
|
+
return this._run(rule, options).then(function (result) { return result.string || result.root.toString(_this._stringifyOptions(options)); });
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Process a selector into a new selector string synchronously.
|
|
141
|
+
*
|
|
142
|
+
* @param rule {postcss.Rule | string} The css selector to be processed
|
|
143
|
+
* @param options The options for processing
|
|
144
|
+
* @returns {string} the selector after processing.
|
|
145
|
+
*/
|
|
146
|
+
Processor.prototype.processSync = function (rule, options) {
|
|
147
|
+
var result = this._runSync(rule, options);
|
|
148
|
+
return result.string || result.root.toString(this._stringifyOptions(options));
|
|
149
|
+
};
|
|
150
|
+
return Processor;
|
|
151
|
+
}());
|
|
152
|
+
exports.default = Processor;
|
|
153
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
var _a;
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.unescapeValue = unescapeValue;
|
|
23
|
+
var cssesc_1 = __importDefault(require("cssesc"));
|
|
24
|
+
var unesc_1 = __importDefault(require("../util/unesc"));
|
|
25
|
+
var namespace_1 = __importDefault(require("./namespace"));
|
|
26
|
+
var types_1 = require("./types");
|
|
27
|
+
var deprecate = require("util-deprecate");
|
|
28
|
+
var WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/;
|
|
29
|
+
var warnOfDeprecatedValueAssignment = deprecate(function () { }, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " +
|
|
30
|
+
"Call attribute.setValue() instead.");
|
|
31
|
+
var warnOfDeprecatedQuotedAssignment = deprecate(function () { }, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
|
|
32
|
+
var warnOfDeprecatedConstructor = deprecate(function () { }, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
|
|
33
|
+
function unescapeValue(value) {
|
|
34
|
+
var deprecatedUsage = false;
|
|
35
|
+
var quoteMark = null;
|
|
36
|
+
var unescaped = value;
|
|
37
|
+
var m = unescaped.match(WRAPPED_IN_QUOTES);
|
|
38
|
+
if (m) {
|
|
39
|
+
quoteMark = m[1];
|
|
40
|
+
unescaped = m[2];
|
|
41
|
+
}
|
|
42
|
+
unescaped = (0, unesc_1.default)(unescaped);
|
|
43
|
+
if (unescaped !== value) {
|
|
44
|
+
deprecatedUsage = true;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
deprecatedUsage: deprecatedUsage,
|
|
48
|
+
unescaped: unescaped,
|
|
49
|
+
quoteMark: quoteMark,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function handleDeprecatedContructorOpts(opts) {
|
|
53
|
+
if (opts.quoteMark !== undefined) {
|
|
54
|
+
return opts;
|
|
55
|
+
}
|
|
56
|
+
if (opts.value === undefined) {
|
|
57
|
+
return opts;
|
|
58
|
+
}
|
|
59
|
+
warnOfDeprecatedConstructor();
|
|
60
|
+
var _a = unescapeValue(opts.value), quoteMark = _a.quoteMark, unescaped = _a.unescaped;
|
|
61
|
+
if (!opts.raws) {
|
|
62
|
+
opts.raws = {};
|
|
63
|
+
}
|
|
64
|
+
if (opts.raws.value === undefined) {
|
|
65
|
+
opts.raws.value = opts.value;
|
|
66
|
+
}
|
|
67
|
+
opts.value = unescaped;
|
|
68
|
+
opts.quoteMark = quoteMark;
|
|
69
|
+
return opts;
|
|
70
|
+
}
|
|
71
|
+
var Attribute = /** @class */ (function (_super) {
|
|
72
|
+
__extends(Attribute, _super);
|
|
73
|
+
function Attribute(opts) {
|
|
74
|
+
if (opts === void 0) { opts = {}; }
|
|
75
|
+
var _this = _super.call(this, handleDeprecatedContructorOpts(opts)) || this;
|
|
76
|
+
_this.type = types_1.ATTRIBUTE;
|
|
77
|
+
_this.raws = _this.raws || {};
|
|
78
|
+
Object.defineProperty(_this.raws, "unquoted", {
|
|
79
|
+
get: deprecate(function () { return _this.value; }, "attr.raws.unquoted is deprecated. Call attr.value instead."),
|
|
80
|
+
set: deprecate(function () { return _this.value; }, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now."),
|
|
81
|
+
});
|
|
82
|
+
_this._constructed = true;
|
|
83
|
+
return _this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns the Attribute's value quoted such that it would be legal to use
|
|
87
|
+
* in the value of a css file. The original value's quotation setting
|
|
88
|
+
* used for stringification is left unchanged. See `setValue(value, options)`
|
|
89
|
+
* if you want to control the quote settings of a new value for the attribute.
|
|
90
|
+
*
|
|
91
|
+
* You can also change the quotation used for the current value by setting quoteMark.
|
|
92
|
+
*
|
|
93
|
+
* Options:
|
|
94
|
+
* * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
|
|
95
|
+
* option is not set, the original value for quoteMark will be used. If
|
|
96
|
+
* indeterminate, a double quote is used. The legal values are:
|
|
97
|
+
* * `null` - the value will be unquoted and characters will be escaped as necessary.
|
|
98
|
+
* * `'` - the value will be quoted with a single quote and single quotes are escaped.
|
|
99
|
+
* * `"` - the value will be quoted with a double quote and double quotes are escaped.
|
|
100
|
+
* * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
|
|
101
|
+
* over the quoteMark option value.
|
|
102
|
+
* * smart {boolean} - if true, will select a quote mark based on the value
|
|
103
|
+
* and the other options specified here. See the `smartQuoteMark()`
|
|
104
|
+
* method.
|
|
105
|
+
**/
|
|
106
|
+
Attribute.prototype.getQuotedValue = function (options) {
|
|
107
|
+
if (options === void 0) { options = {}; }
|
|
108
|
+
var quoteMark = this._determineQuoteMark(options);
|
|
109
|
+
var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
|
|
110
|
+
var escaped = (0, cssesc_1.default)(this._value, cssescopts);
|
|
111
|
+
return escaped;
|
|
112
|
+
};
|
|
113
|
+
Attribute.prototype._determineQuoteMark = function (options) {
|
|
114
|
+
return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Set the unescaped value with the specified quotation options. The value
|
|
118
|
+
* provided must not include any wrapping quote marks -- those quotes will
|
|
119
|
+
* be interpreted as part of the value and escaped accordingly.
|
|
120
|
+
*/
|
|
121
|
+
Attribute.prototype.setValue = function (value, options) {
|
|
122
|
+
if (options === void 0) { options = {}; }
|
|
123
|
+
this._value = value;
|
|
124
|
+
this._quoteMark = this._determineQuoteMark(options);
|
|
125
|
+
this._syncRawValue();
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Intelligently select a quoteMark value based on the value's contents. If
|
|
129
|
+
* the value is a legal CSS ident, it will not be quoted. Otherwise a quote
|
|
130
|
+
* mark will be picked that minimizes the number of escapes.
|
|
131
|
+
*
|
|
132
|
+
* If there's no clear winner, the quote mark from these options is used,
|
|
133
|
+
* then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
|
|
134
|
+
* true). If the quoteMark is unspecified, a double quote is used.
|
|
135
|
+
*
|
|
136
|
+
* @param options This takes the quoteMark and preferCurrentQuoteMark options
|
|
137
|
+
* from the quoteValue method.
|
|
138
|
+
*/
|
|
139
|
+
Attribute.prototype.smartQuoteMark = function (options) {
|
|
140
|
+
var v = this.value;
|
|
141
|
+
var numSingleQuotes = v.replace(/[^']/g, "").length;
|
|
142
|
+
var numDoubleQuotes = v.replace(/[^"]/g, "").length;
|
|
143
|
+
if (numSingleQuotes + numDoubleQuotes === 0) {
|
|
144
|
+
var escaped = (0, cssesc_1.default)(v, { isIdentifier: true });
|
|
145
|
+
if (escaped === v) {
|
|
146
|
+
return Attribute.NO_QUOTE;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
var pref = this.preferredQuoteMark(options);
|
|
150
|
+
if (pref === Attribute.NO_QUOTE) {
|
|
151
|
+
// pick a quote mark that isn't none and see if it's smaller
|
|
152
|
+
var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
|
|
153
|
+
var opts = CSSESC_QUOTE_OPTIONS[quote];
|
|
154
|
+
var quoteValue = (0, cssesc_1.default)(v, opts);
|
|
155
|
+
if (quoteValue.length < escaped.length) {
|
|
156
|
+
return quote;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return pref;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (numDoubleQuotes === numSingleQuotes) {
|
|
163
|
+
return this.preferredQuoteMark(options);
|
|
164
|
+
}
|
|
165
|
+
else if (numDoubleQuotes < numSingleQuotes) {
|
|
166
|
+
return Attribute.DOUBLE_QUOTE;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return Attribute.SINGLE_QUOTE;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Selects the preferred quote mark based on the options and the current quote mark value.
|
|
174
|
+
* If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
|
|
175
|
+
* instead.
|
|
176
|
+
*/
|
|
177
|
+
Attribute.prototype.preferredQuoteMark = function (options) {
|
|
178
|
+
var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
|
|
179
|
+
if (quoteMark === undefined) {
|
|
180
|
+
quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
|
|
181
|
+
}
|
|
182
|
+
if (quoteMark === undefined) {
|
|
183
|
+
quoteMark = Attribute.DOUBLE_QUOTE;
|
|
184
|
+
}
|
|
185
|
+
return quoteMark;
|
|
186
|
+
};
|
|
187
|
+
Object.defineProperty(Attribute.prototype, "quoted", {
|
|
188
|
+
get: function () {
|
|
189
|
+
var qm = this.quoteMark;
|
|
190
|
+
return qm === "'" || qm === '"';
|
|
191
|
+
},
|
|
192
|
+
set: function (value) {
|
|
193
|
+
warnOfDeprecatedQuotedAssignment();
|
|
194
|
+
},
|
|
195
|
+
enumerable: false,
|
|
196
|
+
configurable: true
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(Attribute.prototype, "quoteMark", {
|
|
199
|
+
/**
|
|
200
|
+
* returns a single (`'`) or double (`"`) quote character if the value is quoted.
|
|
201
|
+
* returns `null` if the value is not quoted.
|
|
202
|
+
* returns `undefined` if the quotation state is unknown (this can happen when
|
|
203
|
+
* the attribute is constructed without specifying a quote mark.)
|
|
204
|
+
*/
|
|
205
|
+
get: function () {
|
|
206
|
+
return this._quoteMark;
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Set the quote mark to be used by this attribute's value.
|
|
210
|
+
* If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
|
|
211
|
+
* value is updated accordingly.
|
|
212
|
+
*
|
|
213
|
+
* @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
|
|
214
|
+
*/
|
|
215
|
+
set: function (quoteMark) {
|
|
216
|
+
if (!this._constructed) {
|
|
217
|
+
this._quoteMark = quoteMark;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (this._quoteMark !== quoteMark) {
|
|
221
|
+
this._quoteMark = quoteMark;
|
|
222
|
+
this._syncRawValue();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
enumerable: false,
|
|
226
|
+
configurable: true
|
|
227
|
+
});
|
|
228
|
+
Attribute.prototype._syncRawValue = function () {
|
|
229
|
+
var rawValue = (0, cssesc_1.default)(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
|
|
230
|
+
if (rawValue === this._value) {
|
|
231
|
+
if (this.raws) {
|
|
232
|
+
delete this.raws.value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.raws.value = rawValue;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
Object.defineProperty(Attribute.prototype, "qualifiedAttribute", {
|
|
240
|
+
get: function () {
|
|
241
|
+
return this.qualifiedName(this.raws.attribute || this.attribute);
|
|
242
|
+
},
|
|
243
|
+
enumerable: false,
|
|
244
|
+
configurable: true
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(Attribute.prototype, "insensitiveFlag", {
|
|
247
|
+
get: function () {
|
|
248
|
+
return this.insensitive ? "i" : "";
|
|
249
|
+
},
|
|
250
|
+
enumerable: false,
|
|
251
|
+
configurable: true
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(Attribute.prototype, "value", {
|
|
254
|
+
get: function () {
|
|
255
|
+
return this._value;
|
|
256
|
+
},
|
|
257
|
+
/**
|
|
258
|
+
* Before 3.0, the value had to be set to an escaped value including any wrapped
|
|
259
|
+
* quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
|
|
260
|
+
* is unescaped during parsing and any quote marks are removed.
|
|
261
|
+
*
|
|
262
|
+
* Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
|
|
263
|
+
* a deprecation warning is raised when the new value contains any characters that would
|
|
264
|
+
* require escaping (including if it contains wrapped quotes).
|
|
265
|
+
*
|
|
266
|
+
* Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
|
|
267
|
+
* how the new value is quoted.
|
|
268
|
+
*/
|
|
269
|
+
set: function (v) {
|
|
270
|
+
if (this._constructed) {
|
|
271
|
+
var _a = unescapeValue(v), deprecatedUsage = _a.deprecatedUsage, unescaped = _a.unescaped, quoteMark = _a.quoteMark;
|
|
272
|
+
if (deprecatedUsage) {
|
|
273
|
+
warnOfDeprecatedValueAssignment();
|
|
274
|
+
}
|
|
275
|
+
if (unescaped === this._value && quoteMark === this._quoteMark) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
this._value = unescaped;
|
|
279
|
+
this._quoteMark = quoteMark;
|
|
280
|
+
this._syncRawValue();
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
this._value = v;
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
enumerable: false,
|
|
287
|
+
configurable: true
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(Attribute.prototype, "insensitive", {
|
|
290
|
+
get: function () {
|
|
291
|
+
return this._insensitive;
|
|
292
|
+
},
|
|
293
|
+
/**
|
|
294
|
+
* Set the case insensitive flag.
|
|
295
|
+
* If the case insensitive flag changes, the raw (escaped) value at `attr.raws.insensitiveFlag`
|
|
296
|
+
* of the attribute is updated accordingly.
|
|
297
|
+
*
|
|
298
|
+
* @param {true | false} insensitive true if the attribute should match case-insensitively.
|
|
299
|
+
*/
|
|
300
|
+
set: function (insensitive) {
|
|
301
|
+
if (!insensitive) {
|
|
302
|
+
this._insensitive = false;
|
|
303
|
+
// "i" and "I" can be used in "this.raws.insensitiveFlag" to store the original notation.
|
|
304
|
+
// When setting `attr.insensitive = false` both should be erased to ensure correct serialization.
|
|
305
|
+
if (this.raws && (this.raws.insensitiveFlag === "I" || this.raws.insensitiveFlag === "i")) {
|
|
306
|
+
this.raws.insensitiveFlag = undefined;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
this._insensitive = insensitive;
|
|
310
|
+
},
|
|
311
|
+
enumerable: false,
|
|
312
|
+
configurable: true
|
|
313
|
+
});
|
|
314
|
+
Object.defineProperty(Attribute.prototype, "attribute", {
|
|
315
|
+
get: function () {
|
|
316
|
+
return this._attribute;
|
|
317
|
+
},
|
|
318
|
+
set: function (name) {
|
|
319
|
+
this._handleEscapes("attribute", name);
|
|
320
|
+
this._attribute = name;
|
|
321
|
+
},
|
|
322
|
+
enumerable: false,
|
|
323
|
+
configurable: true
|
|
324
|
+
});
|
|
325
|
+
Attribute.prototype._handleEscapes = function (prop, value) {
|
|
326
|
+
if (this._constructed) {
|
|
327
|
+
var escaped = (0, cssesc_1.default)(value, { isIdentifier: true });
|
|
328
|
+
if (escaped !== value) {
|
|
329
|
+
this.raws[prop] = escaped;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
delete this.raws[prop];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
Attribute.prototype._spacesFor = function (name) {
|
|
337
|
+
var attrSpaces = { before: "", after: "" };
|
|
338
|
+
var spaces = this.spaces[name] || {};
|
|
339
|
+
var rawSpaces = (this.raws.spaces && this.raws.spaces[name]) || {};
|
|
340
|
+
return Object.assign(attrSpaces, spaces, rawSpaces);
|
|
341
|
+
};
|
|
342
|
+
Attribute.prototype._stringFor = function (name, spaceName, concat) {
|
|
343
|
+
if (spaceName === void 0) { spaceName = name; }
|
|
344
|
+
if (concat === void 0) { concat = defaultAttrConcat; }
|
|
345
|
+
var attrSpaces = this._spacesFor(spaceName);
|
|
346
|
+
return concat(this.stringifyProperty(name), attrSpaces);
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* returns the offset of the attribute part specified relative to the
|
|
350
|
+
* start of the node of the output string.
|
|
351
|
+
*
|
|
352
|
+
* * "ns" - alias for "namespace"
|
|
353
|
+
* * "namespace" - the namespace if it exists.
|
|
354
|
+
* * "attribute" - the attribute name
|
|
355
|
+
* * "attributeNS" - the start of the attribute or its namespace
|
|
356
|
+
* * "operator" - the match operator of the attribute
|
|
357
|
+
* * "value" - The value (string or identifier)
|
|
358
|
+
* * "insensitive" - the case insensitivity flag;
|
|
359
|
+
* @param part One of the possible values inside an attribute.
|
|
360
|
+
* @returns -1 if the name is invalid or the value doesn't exist in this attribute.
|
|
361
|
+
*/
|
|
362
|
+
Attribute.prototype.offsetOf = function (name) {
|
|
363
|
+
var count = 1;
|
|
364
|
+
var attributeSpaces = this._spacesFor("attribute");
|
|
365
|
+
count += attributeSpaces.before.length;
|
|
366
|
+
if (name === "namespace" || name === "ns") {
|
|
367
|
+
return this.namespace ? count : -1;
|
|
368
|
+
}
|
|
369
|
+
if (name === "attributeNS") {
|
|
370
|
+
return count;
|
|
371
|
+
}
|
|
372
|
+
count += this.namespaceString.length;
|
|
373
|
+
if (this.namespace) {
|
|
374
|
+
count += 1;
|
|
375
|
+
}
|
|
376
|
+
if (name === "attribute") {
|
|
377
|
+
return count;
|
|
378
|
+
}
|
|
379
|
+
count += this.stringifyProperty("attribute").length;
|
|
380
|
+
count += attributeSpaces.after.length;
|
|
381
|
+
var operatorSpaces = this._spacesFor("operator");
|
|
382
|
+
count += operatorSpaces.before.length;
|
|
383
|
+
var operator = this.stringifyProperty("operator");
|
|
384
|
+
if (name === "operator") {
|
|
385
|
+
return operator ? count : -1;
|
|
386
|
+
}
|
|
387
|
+
count += operator.length;
|
|
388
|
+
count += operatorSpaces.after.length;
|
|
389
|
+
var valueSpaces = this._spacesFor("value");
|
|
390
|
+
count += valueSpaces.before.length;
|
|
391
|
+
var value = this.stringifyProperty("value");
|
|
392
|
+
if (name === "value") {
|
|
393
|
+
return value ? count : -1;
|
|
394
|
+
}
|
|
395
|
+
count += value.length;
|
|
396
|
+
count += valueSpaces.after.length;
|
|
397
|
+
var insensitiveSpaces = this._spacesFor("insensitive");
|
|
398
|
+
count += insensitiveSpaces.before.length;
|
|
399
|
+
if (name === "insensitive") {
|
|
400
|
+
return this.insensitive ? count : -1;
|
|
401
|
+
}
|
|
402
|
+
return -1;
|
|
403
|
+
};
|
|
404
|
+
Attribute.prototype.toString = function () {
|
|
405
|
+
var _this = this;
|
|
406
|
+
var selector = [this.rawSpaceBefore, "["];
|
|
407
|
+
selector.push(this._stringFor("qualifiedAttribute", "attribute"));
|
|
408
|
+
if (this.operator && (this.value || this.value === "")) {
|
|
409
|
+
selector.push(this._stringFor("operator"));
|
|
410
|
+
selector.push(this._stringFor("value"));
|
|
411
|
+
selector.push(this._stringFor("insensitiveFlag", "insensitive", function (attrValue, attrSpaces) {
|
|
412
|
+
if (attrValue.length > 0 &&
|
|
413
|
+
!_this.quoted &&
|
|
414
|
+
attrSpaces.before.length === 0 &&
|
|
415
|
+
!(_this.spaces.value && _this.spaces.value.after)) {
|
|
416
|
+
attrSpaces.before = " ";
|
|
417
|
+
}
|
|
418
|
+
return defaultAttrConcat(attrValue, attrSpaces);
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
selector.push("]");
|
|
422
|
+
selector.push(this.rawSpaceAfter);
|
|
423
|
+
return selector.join("");
|
|
424
|
+
};
|
|
425
|
+
Attribute.NO_QUOTE = null;
|
|
426
|
+
Attribute.SINGLE_QUOTE = "'";
|
|
427
|
+
Attribute.DOUBLE_QUOTE = '"';
|
|
428
|
+
return Attribute;
|
|
429
|
+
}(namespace_1.default));
|
|
430
|
+
exports.default = Attribute;
|
|
431
|
+
var CSSESC_QUOTE_OPTIONS = (_a = {
|
|
432
|
+
"'": { quotes: "single", wrap: true },
|
|
433
|
+
'"': { quotes: "double", wrap: true }
|
|
434
|
+
},
|
|
435
|
+
_a[null] = { isIdentifier: true },
|
|
436
|
+
_a);
|
|
437
|
+
function defaultAttrConcat(attrValue, attrSpaces) {
|
|
438
|
+
return "".concat(attrSpaces.before).concat(attrValue).concat(attrSpaces.after);
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=attribute.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var cssesc_1 = __importDefault(require("cssesc"));
|
|
22
|
+
var util_1 = require("../util");
|
|
23
|
+
var node_1 = __importDefault(require("./node"));
|
|
24
|
+
var types_1 = require("./types");
|
|
25
|
+
var ClassName = /** @class */ (function (_super) {
|
|
26
|
+
__extends(ClassName, _super);
|
|
27
|
+
function ClassName(opts) {
|
|
28
|
+
var _this = _super.call(this, opts) || this;
|
|
29
|
+
_this.type = types_1.CLASS;
|
|
30
|
+
_this._constructed = true;
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(ClassName.prototype, "value", {
|
|
34
|
+
get: function () {
|
|
35
|
+
return this._value;
|
|
36
|
+
},
|
|
37
|
+
set: function (v) {
|
|
38
|
+
if (this._constructed) {
|
|
39
|
+
var escaped = (0, cssesc_1.default)(v, { isIdentifier: true });
|
|
40
|
+
if (escaped !== v) {
|
|
41
|
+
(0, util_1.ensureObject)(this, "raws");
|
|
42
|
+
this.raws.value = escaped;
|
|
43
|
+
}
|
|
44
|
+
else if (this.raws) {
|
|
45
|
+
delete this.raws.value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this._value = v;
|
|
49
|
+
},
|
|
50
|
+
enumerable: false,
|
|
51
|
+
configurable: true
|
|
52
|
+
});
|
|
53
|
+
ClassName.prototype.valueToString = function () {
|
|
54
|
+
return "." + _super.prototype.valueToString.call(this);
|
|
55
|
+
};
|
|
56
|
+
return ClassName;
|
|
57
|
+
}(node_1.default));
|
|
58
|
+
exports.default = ClassName;
|
|
59
|
+
//# sourceMappingURL=className.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var node_1 = __importDefault(require("./node"));
|
|
22
|
+
var types_1 = require("./types");
|
|
23
|
+
var Combinator = /** @class */ (function (_super) {
|
|
24
|
+
__extends(Combinator, _super);
|
|
25
|
+
function Combinator(opts) {
|
|
26
|
+
var _this = _super.call(this, opts) || this;
|
|
27
|
+
_this.type = types_1.COMBINATOR;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
return Combinator;
|
|
31
|
+
}(node_1.default));
|
|
32
|
+
exports.default = Combinator;
|
|
33
|
+
//# sourceMappingURL=combinator.js.map
|