@weapp-tailwindcss/postcss 3.3.5 → 3.3.7
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/README.md +10 -0
- package/README.zh-CN.md +6 -0
- package/dist/compat/index.d.ts +57 -0
- package/dist/compat/legacy-css/source-cleanup.d.ts +2 -0
- package/dist/compat/mini-program-css/output-import-shell.d.ts +8 -0
- package/dist/compat/native/compile.d.ts +2 -0
- package/dist/compat/native/properties.d.ts +15 -0
- package/dist/compat/native/selectors.d.ts +8 -0
- package/dist/compat/native/types.d.ts +23 -0
- package/dist/compat/processed-css/cleanup.d.ts +4 -0
- package/dist/compat/processed-css/composition.d.ts +6 -0
- package/dist/compat/processed-css/entry-directives.d.ts +1 -0
- package/dist/compat/processed-css/imports.d.ts +8 -0
- package/dist/compat/scoped-css/cleanup.d.ts +4 -0
- package/dist/compat/scoped-css/coverage.d.ts +10 -0
- package/dist/compat/scoped-css/covered-rules.d.ts +4 -0
- package/dist/compat/scoped-css/predicates.d.ts +13 -0
- package/dist/compat/tailwind-directive-injection.d.ts +8 -0
- package/dist/compat/tailwindcss-v4/generated-output.d.ts +5 -0
- package/dist/compat/tailwindcss-v4/package-import-statements.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/preflight-imports.d.ts +3 -0
- package/dist/compat/tailwindcss-v4/rpx-candidates.d.ts +6 -0
- package/dist/compat/tailwindcss-v4/theme-injection.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/theme-source.d.ts +5 -0
- package/dist/compat/tailwindcss-v4/user-css/apply-only.d.ts +6 -0
- package/dist/compat/tailwindcss-v4/user-css/apply-reference.d.ts +4 -0
- package/dist/compat/tailwindcss-v4/user-css/at-rules.d.ts +3 -0
- package/dist/compat/tailwindcss-v4/user-css/class-selectors.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/entry-source.d.ts +9 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/fallback.d.ts +11 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/index.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/directives/shared.d.ts +26 -0
- package/dist/compat/tailwindcss-v4/user-css/framework-composition.d.ts +2 -0
- package/dist/compat/tailwindcss-v4/user-css/framework-source.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/generated-cleanup.d.ts +7 -0
- package/dist/compat/tailwindcss-v4/user-css/identity.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/markers.d.ts +32 -0
- package/dist/compat/tailwindcss-v4/user-css/rule-deduplication.d.ts +1 -0
- package/dist/compat/tailwindcss-v4/user-css/scoped-rules.d.ts +4 -0
- package/dist/compat/tailwindcss-v4/user-css/source-fragments.d.ts +15 -0
- package/dist/compat/tailwindcss-v4/user-css/transform.d.ts +14 -0
- package/dist/compat/tailwindcss-v4/user-css/user-layer-order.d.ts +10 -0
- package/dist/compat/tailwindcss-v4/user-css/user-layers.d.ts +15 -0
- package/dist/compat/uni-app-x/apply-source.d.ts +2 -0
- package/dist/compat/uni-app-x/harmony-apply.d.ts +2 -0
- package/dist/compat/uni-app-x/reference-paths.d.ts +2 -0
- package/dist/compat/uni-app-x-style-value.d.ts +2 -0
- package/dist/compat/webpack-css/bare-selectors.d.ts +1 -0
- package/dist/compat/webpack-css/generated-cleanup.d.ts +4 -0
- package/dist/compat/webpack-css/identity.d.ts +5 -0
- package/dist/compat/webpack-css/preflight.d.ts +5 -0
- package/dist/compat/webpack-css/user-source.d.ts +6 -0
- package/dist/diagnostics/rpx-theme.d.ts +9 -0
- package/dist/directives-C7XTve1w.js +8263 -0
- package/dist/experimental/lightningcss/index.cjs +256 -0
- package/dist/experimental/lightningcss/index.d.ts +3 -0
- package/dist/experimental/lightningcss/index.js +245 -0
- package/dist/experimental/lightningcss/options.d.ts +3 -0
- package/dist/experimental/lightningcss/selector-transform.d.ts +10 -0
- package/dist/experimental/lightningcss/selector-utils.d.ts +10 -0
- package/dist/generator-plugin/config-directive.d.ts +5 -0
- package/dist/generator-plugin/source-files.d.ts +5 -5
- package/dist/generator-plugin/types.d.ts +5 -0
- package/dist/index.cjs +383 -9089
- package/dist/index.d.ts +2 -43
- package/dist/index.js +10 -8935
- package/dist/native.cjs +425 -0
- package/dist/native.d.ts +3 -0
- package/dist/native.js +419 -0
- package/dist/plugin-CRzZbcEf.js +185 -0
- package/dist/plugin-DwoAGHyN.cjs +194 -0
- package/dist/plugin.cjs +3 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +2 -0
- package/dist/postcss-runtime-i5rHe_mj.js +2 -0
- package/dist/preflight-BTZL2nvC.cjs +21 -0
- package/dist/preflight-DVg4eehD.js +16 -0
- package/dist/resolve-BFphwPip.cjs +9987 -0
- package/dist/resolve-D-FbFBpF.js +1139 -0
- package/dist/rewrite-imports-Dk9TKKSF.js +145 -0
- package/dist/shared-CELzerNo.cjs +34 -0
- package/dist/shared-CfQUwapA.js +23 -0
- package/dist/source-scan/candidates.d.ts +4 -0
- package/dist/source-scan/description.d.ts +15 -0
- package/dist/source-scan/params.d.ts +5 -0
- package/dist/source-scan/resolve.d.ts +30 -0
- package/dist/source-scan/tailwind-v4/entry-source.d.ts +16 -0
- package/dist/source-scan/tailwind-v4/fingerprint.d.ts +5 -0
- package/dist/source-scan.d.ts +3 -24
- package/dist/syntax/index.d.ts +1 -0
- package/dist/syntax/location-dependencies.d.ts +2 -0
- package/dist/syntax/rewrite-imports.d.ts +5 -0
- package/dist/syntax/runtime-signature.d.ts +2 -0
- package/dist/syntax/source-style.d.ts +1 -0
- package/dist/syntax.cjs +1167 -0
- package/dist/syntax.d.ts +6 -0
- package/dist/syntax.js +3 -0
- package/dist/transform-BGYgGeQj.js +9239 -0
- package/dist/transform-DpFypcaN.cjs +10956 -0
- package/dist/transform.cjs +421 -0
- package/dist/transform.d.ts +40 -0
- package/dist/transform.js +10 -0
- package/dist/utils/apply-source.d.ts +11 -0
- package/dist/utils/css-source-trace.d.ts +6 -0
- package/dist/utils/custom-property-values.d.ts +4 -0
- package/dist/utils/generated-css-marker.d.ts +12 -0
- package/package.json +49 -9
package/dist/syntax.cjs
ADDED
|
@@ -0,0 +1,1167 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _weapp_tailwindcss_engine = require("@weapp-tailwindcss/engine");
|
|
25
|
+
let _weapp_tailwindcss_source_scan = require("@weapp-tailwindcss/source-scan");
|
|
26
|
+
let node_path = require("node:path");
|
|
27
|
+
node_path = __toESM(node_path, 1);
|
|
28
|
+
let node_module = require("node:module");
|
|
29
|
+
let tailwindcss_config = require("tailwindcss-config");
|
|
30
|
+
let postcss = require("postcss");
|
|
31
|
+
postcss = __toESM(postcss, 1);
|
|
32
|
+
let postcss_scss = require("postcss-scss");
|
|
33
|
+
postcss_scss = __toESM(postcss_scss, 1);
|
|
34
|
+
//#region src/source-scan/params.ts
|
|
35
|
+
function parseConfigParam(params) {
|
|
36
|
+
const value = params.trim();
|
|
37
|
+
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
38
|
+
}
|
|
39
|
+
function parseSourceFileParam(params) {
|
|
40
|
+
const value = params.trim();
|
|
41
|
+
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
42
|
+
const negated = value.startsWith("not ");
|
|
43
|
+
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
44
|
+
if (sourceValue.startsWith("inline(")) return;
|
|
45
|
+
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
46
|
+
return match?.[2] ? {
|
|
47
|
+
negated,
|
|
48
|
+
sourcePath: match[2]
|
|
49
|
+
} : void 0;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/source-scan/inline-source.ts
|
|
53
|
+
const NUMERICAL_RANGE_RE = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/;
|
|
54
|
+
function segmentTopLevel(input, separator, options = {}) {
|
|
55
|
+
const parts = [];
|
|
56
|
+
const stack = [];
|
|
57
|
+
let lastPos = 0;
|
|
58
|
+
let quote;
|
|
59
|
+
for (let index = 0; index < input.length; index++) {
|
|
60
|
+
const char = input[index];
|
|
61
|
+
if (char === "\\") {
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (quote) {
|
|
66
|
+
if (char === quote) quote = void 0;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (char === "\"" || char === "'") {
|
|
70
|
+
quote = char;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(") {
|
|
74
|
+
stack.push(")");
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (char === "[") {
|
|
78
|
+
stack.push("]");
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (char === "{") {
|
|
82
|
+
stack.push("}");
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (stack.length > 0 && char === stack[stack.length - 1]) {
|
|
86
|
+
stack.pop();
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (stack.length === 0 && char === separator) {
|
|
90
|
+
const part = input.slice(lastPos, index);
|
|
91
|
+
if (part || options.keepEmpty) parts.push(part);
|
|
92
|
+
lastPos = index + 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const part = input.slice(lastPos);
|
|
96
|
+
if (part || options.keepEmpty) parts.push(part);
|
|
97
|
+
return parts;
|
|
98
|
+
}
|
|
99
|
+
function isSequence(value) {
|
|
100
|
+
return NUMERICAL_RANGE_RE.test(value);
|
|
101
|
+
}
|
|
102
|
+
function expandSequence(value) {
|
|
103
|
+
const match = value.match(NUMERICAL_RANGE_RE);
|
|
104
|
+
if (!match) return [value];
|
|
105
|
+
const [, start, end, stepValue] = match;
|
|
106
|
+
if (start === void 0 || end === void 0) return [value];
|
|
107
|
+
let step = stepValue ? Number.parseInt(stepValue, 10) : void 0;
|
|
108
|
+
const startNumber = Number.parseInt(start, 10);
|
|
109
|
+
const endNumber = Number.parseInt(end, 10);
|
|
110
|
+
const increasing = startNumber < endNumber;
|
|
111
|
+
if (step === void 0) step = increasing ? 1 : -1;
|
|
112
|
+
if (step === 0) return [];
|
|
113
|
+
if (increasing && step < 0) step = -step;
|
|
114
|
+
if (!increasing && step > 0) step = -step;
|
|
115
|
+
const result = [];
|
|
116
|
+
for (let value = startNumber; increasing ? value <= endNumber : value >= endNumber; value += step) result.push(String(value));
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function expandInlineSourceCandidatePattern(pattern) {
|
|
120
|
+
const index = pattern.indexOf("{");
|
|
121
|
+
if (index === -1) return [pattern];
|
|
122
|
+
const prefix = pattern.slice(0, index);
|
|
123
|
+
const rest = pattern.slice(index);
|
|
124
|
+
let depth = 0;
|
|
125
|
+
let endIndex = -1;
|
|
126
|
+
for (let index = 0; index < rest.length; index++) {
|
|
127
|
+
const char = rest[index];
|
|
128
|
+
if (char === "{") depth += 1;
|
|
129
|
+
else if (char === "}") {
|
|
130
|
+
depth -= 1;
|
|
131
|
+
if (depth === 0) {
|
|
132
|
+
endIndex = index;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (endIndex === -1) return [pattern];
|
|
138
|
+
const inner = rest.slice(1, endIndex);
|
|
139
|
+
const suffix = rest.slice(endIndex + 1);
|
|
140
|
+
const parts = (isSequence(inner) ? expandSequence(inner) : segmentTopLevel(inner, ",", { keepEmpty: true })).flatMap((part) => expandInlineSourceCandidatePattern(part));
|
|
141
|
+
return expandInlineSourceCandidatePattern(suffix).flatMap((suffix) => parts.map((part) => `${prefix}${part}${suffix}`));
|
|
142
|
+
}
|
|
143
|
+
function parseSourceInlineParam(params) {
|
|
144
|
+
let value = params.trim();
|
|
145
|
+
const negated = value.startsWith("not ");
|
|
146
|
+
if (negated) value = value.slice(4).trim();
|
|
147
|
+
if (!value.startsWith("inline(") || !value.endsWith(")")) return;
|
|
148
|
+
const inlineValue = value.slice(7, -1).trim();
|
|
149
|
+
const match = /^(['"])([\s\S]*)\1$/.exec(inlineValue);
|
|
150
|
+
if (!match) return;
|
|
151
|
+
const source = match[2];
|
|
152
|
+
if (source === void 0) return;
|
|
153
|
+
return {
|
|
154
|
+
negated,
|
|
155
|
+
source
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function collectCssInlineSourceCandidates(root) {
|
|
159
|
+
const included = /* @__PURE__ */ new Set();
|
|
160
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
161
|
+
root.walkAtRules("source", (rule) => {
|
|
162
|
+
const parsed = parseSourceInlineParam(rule.params);
|
|
163
|
+
if (!parsed) return;
|
|
164
|
+
const target = parsed.negated ? excluded : included;
|
|
165
|
+
for (const source of segmentTopLevel(parsed.source, " ")) {
|
|
166
|
+
const trimmed = source.trim();
|
|
167
|
+
if (!trimmed) continue;
|
|
168
|
+
for (const candidate of expandInlineSourceCandidatePattern(trimmed)) {
|
|
169
|
+
const normalized = candidate.trim();
|
|
170
|
+
if (normalized) target.add(normalized);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
for (const candidate of excluded) included.delete(candidate);
|
|
175
|
+
return {
|
|
176
|
+
included,
|
|
177
|
+
excluded
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/source-scan.ts
|
|
182
|
+
async function resolveCssSourceEntries(root, base, defaultPattern = (0, _weapp_tailwindcss_source_scan.createSourceScanPattern)()) {
|
|
183
|
+
const entries = [];
|
|
184
|
+
const tasks = [];
|
|
185
|
+
root.walkAtRules("source", (rule) => {
|
|
186
|
+
const parsed = parseSourceFileParam(rule.params);
|
|
187
|
+
if (!parsed) return;
|
|
188
|
+
tasks.push((0, _weapp_tailwindcss_source_scan.resolveTailwindSourceEntry)(parsed.sourcePath, base, parsed.negated, defaultPattern));
|
|
189
|
+
});
|
|
190
|
+
entries.push(...await Promise.all(tasks));
|
|
191
|
+
return entries;
|
|
192
|
+
}
|
|
193
|
+
async function expandTailwindSourceEntries(entries, options = {}) {
|
|
194
|
+
return (0, _weapp_tailwindcss_source_scan.expandSourceEntries)(entries, ({ cwd, sources }) => (0, _weapp_tailwindcss_engine.resolveProjectSourceFiles)({
|
|
195
|
+
cwd,
|
|
196
|
+
sources,
|
|
197
|
+
...options.ignore ? { ignoredSources: options.ignore.map((pattern) => ({
|
|
198
|
+
base: cwd,
|
|
199
|
+
pattern: (0, _weapp_tailwindcss_source_scan.normalizeGlobPattern)(pattern),
|
|
200
|
+
negated: true
|
|
201
|
+
})) } : {}
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region ../../node_modules/.pnpm/@csstools+css-tokenizer@4.0.1/node_modules/@csstools/css-tokenizer/dist/index.mjs
|
|
206
|
+
var ParseError = class extends Error {
|
|
207
|
+
sourceStart;
|
|
208
|
+
sourceEnd;
|
|
209
|
+
parserState;
|
|
210
|
+
constructor(e, n, t, o) {
|
|
211
|
+
super(e), this.name = "ParseError", this.sourceStart = n, this.sourceEnd = t, this.parserState = o;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var ParseErrorWithToken = class extends ParseError {
|
|
215
|
+
token;
|
|
216
|
+
constructor(e, n, t, o, r) {
|
|
217
|
+
super(e, n, t, o), this.token = r;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const e = {
|
|
221
|
+
UnexpectedNewLineInString: "Unexpected newline while consuming a string token.",
|
|
222
|
+
UnexpectedEOFInString: "Unexpected EOF while consuming a string token.",
|
|
223
|
+
UnexpectedEOFInComment: "Unexpected EOF while consuming a comment.",
|
|
224
|
+
UnexpectedEOFInURL: "Unexpected EOF while consuming a url token.",
|
|
225
|
+
UnexpectedEOFInEscapedCodePoint: "Unexpected EOF while consuming an escaped code point.",
|
|
226
|
+
UnexpectedCharacterInURL: "Unexpected character while consuming a url token.",
|
|
227
|
+
InvalidEscapeSequenceInURL: "Invalid escape sequence while consuming a url token.",
|
|
228
|
+
InvalidEscapeSequenceAfterBackslash: "Invalid escape sequence after \"\\\""
|
|
229
|
+
};
|
|
230
|
+
"undefined" != typeof globalThis && "structuredClone" in globalThis;
|
|
231
|
+
const t = 13;
|
|
232
|
+
const o = 45;
|
|
233
|
+
const r = 10;
|
|
234
|
+
const i = 43;
|
|
235
|
+
const c = 65533;
|
|
236
|
+
const s = 92;
|
|
237
|
+
var u;
|
|
238
|
+
var a;
|
|
239
|
+
var d;
|
|
240
|
+
function isHexDigitCodePoint(e) {
|
|
241
|
+
return e >= 48 && e <= 57 || e >= 97 && e <= 102 || e >= 65 && e <= 70;
|
|
242
|
+
}
|
|
243
|
+
function isIdentStartCodePoint(e) {
|
|
244
|
+
return e >= 97 && e <= 122 || e >= 65 && e <= 90 || 95 === e || isNonASCII_IdentCodePoint(e);
|
|
245
|
+
}
|
|
246
|
+
function isNonASCII_IdentCodePoint(e) {
|
|
247
|
+
return e < 183 ? 0 === e : 183 === e || 8204 === e || 8205 === e || 8255 === e || 8256 === e || 8204 === e || 192 <= e && e <= 214 || 216 <= e && e <= 246 || 248 <= e && e <= 893 || 895 <= e && e <= 8191 || 8304 <= e && e <= 8591 || 11264 <= e && e <= 12271 || 12289 <= e && e <= 55295 || 63744 <= e && e <= 64975 || 65008 <= e && e <= 65533 || 0 === e || e >= 55296 && e <= 57343 || e >= 65536;
|
|
248
|
+
}
|
|
249
|
+
function isNonPrintableCodePoint(e) {
|
|
250
|
+
return 11 === e || 127 === e || 0 <= e && e <= 8 || 14 <= e && e <= 31;
|
|
251
|
+
}
|
|
252
|
+
function isNewLine(e) {
|
|
253
|
+
return e === r || e === t || 12 === e;
|
|
254
|
+
}
|
|
255
|
+
function isWhitespace(e) {
|
|
256
|
+
return 32 === e || e === r || 9 === e || e === t || 12 === e;
|
|
257
|
+
}
|
|
258
|
+
function isSurrogate(e) {
|
|
259
|
+
return e >= 55296 && e <= 57343;
|
|
260
|
+
}
|
|
261
|
+
function tokenize(e, n) {
|
|
262
|
+
const t = tokenizer(e, n), o = [];
|
|
263
|
+
for (; !t.endOfFile();) o.push(t.nextToken());
|
|
264
|
+
return o.push(t.nextToken()), o;
|
|
265
|
+
}
|
|
266
|
+
function tokenizer(n, C) {
|
|
267
|
+
const l = n.css.valueOf(), f = n.unicodeRangesAllowed ?? !1;
|
|
268
|
+
let m = 0, h = 0, k = -1, P = !1;
|
|
269
|
+
const p = C?.onParseError ?? noop;
|
|
270
|
+
function consumeIdentSequence() {
|
|
271
|
+
const e = m;
|
|
272
|
+
for (;;) {
|
|
273
|
+
const e = l.charCodeAt(m);
|
|
274
|
+
if (e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === o || 95 === e) {
|
|
275
|
+
m += 1;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const n = l.codePointAt(m) ?? -1;
|
|
279
|
+
if (0 === n || n >= 55296 && n <= 57343 || n === s && !isNewLine(l.codePointAt(m + 1) ?? -1)) break;
|
|
280
|
+
if (!isNonASCII_IdentCodePoint(n)) break;
|
|
281
|
+
m += +(n > 65535) + 1;
|
|
282
|
+
}
|
|
283
|
+
const n = l.codePointAt(m) ?? -1;
|
|
284
|
+
if (0 !== n && !(n >= 55296 && n <= 57343) && (n !== s || isNewLine(l.codePointAt(m + 1) ?? -1))) return P = !0, k = m - 1, l.slice(e, m);
|
|
285
|
+
P = !1, m = e, k = -1;
|
|
286
|
+
let t = "";
|
|
287
|
+
for (;;) {
|
|
288
|
+
const e = l.codePointAt(m) ?? -1;
|
|
289
|
+
if (0 === e || isSurrogate(e)) t += String.fromCharCode(c), m += +(e > 65535) + 1, k = m - 1;
|
|
290
|
+
else if (e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === o || 95 === e || isNonASCII_IdentCodePoint(e)) t += e > 65535 ? String.fromCodePoint(e) : String.fromCharCode(e), m += +(e > 65535) + 1, k = m - 1;
|
|
291
|
+
else {
|
|
292
|
+
if (l.codePointAt(m) !== s || isNewLine(l.codePointAt(m + 1) ?? -1)) return t;
|
|
293
|
+
m += 1, k = m - 1, t += String.fromCodePoint(consumeEscapedCodePoint());
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function consumeEscapedCodePoint() {
|
|
298
|
+
const n = l.codePointAt(m);
|
|
299
|
+
if (void 0 === n) return p(new ParseError(e.UnexpectedEOFInEscapedCodePoint, h, k, ["4.3.7. Consume an escaped code point", "Unexpected EOF"])), c;
|
|
300
|
+
if (m += +(n > 65535) + 1, k = m - 1, isHexDigitCodePoint(n)) {
|
|
301
|
+
const e = [n];
|
|
302
|
+
let o;
|
|
303
|
+
for (; void 0 !== (o = l.codePointAt(m)) && isHexDigitCodePoint(o) && e.length < 6;) e.push(o), m += 1, k = m - 1;
|
|
304
|
+
isWhitespace(l.codePointAt(m) ?? -1) && (l.codePointAt(m) === t && l.codePointAt(m + 1) === r && (m += 1), m += 1, k = m - 1);
|
|
305
|
+
const i = parseInt(String.fromCodePoint(...e), 16);
|
|
306
|
+
return 0 === i || isSurrogate(i) || i > 1114111 ? c : i;
|
|
307
|
+
}
|
|
308
|
+
return 0 === n || isSurrogate(n) ? c : n;
|
|
309
|
+
}
|
|
310
|
+
function consumeBadURL() {
|
|
311
|
+
for (;;) {
|
|
312
|
+
const e = l.codePointAt(m);
|
|
313
|
+
if (void 0 === e) return;
|
|
314
|
+
if (41 === e) return m += 1, void (k = m - 1);
|
|
315
|
+
e !== s || isNewLine(l.codePointAt(m + 1) ?? -1) ? (m += 1, k = m - 1) : (m += 1, k = m - 1, consumeEscapedCodePoint());
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function consumeComment() {
|
|
319
|
+
for (m += 2, k = m - 1;;) {
|
|
320
|
+
const n = l.codePointAt(m);
|
|
321
|
+
if (void 0 === n) {
|
|
322
|
+
const n = [
|
|
323
|
+
u.Comment,
|
|
324
|
+
l.slice(h, k + 1),
|
|
325
|
+
h,
|
|
326
|
+
k,
|
|
327
|
+
void 0
|
|
328
|
+
];
|
|
329
|
+
return p(new ParseErrorWithToken(e.UnexpectedEOFInComment, h, k, ["4.3.2. Consume comments", "Unexpected EOF"], n)), n;
|
|
330
|
+
}
|
|
331
|
+
if (m += 1, k = m - 1, 42 === n && void 0 !== l.codePointAt(m) && 47 === l.codePointAt(m)) {
|
|
332
|
+
m += 1, k = m - 1;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return [
|
|
337
|
+
u.Comment,
|
|
338
|
+
l.slice(h, k + 1),
|
|
339
|
+
h,
|
|
340
|
+
k,
|
|
341
|
+
void 0
|
|
342
|
+
];
|
|
343
|
+
}
|
|
344
|
+
function consumeStringToken() {
|
|
345
|
+
let n = "";
|
|
346
|
+
const o = l.codePointAt(m);
|
|
347
|
+
for (m += 1, k = m - 1;;) {
|
|
348
|
+
const i = l.charCodeAt(m);
|
|
349
|
+
if (m >= l.length) {
|
|
350
|
+
const t = [
|
|
351
|
+
u.String,
|
|
352
|
+
l.slice(h, k + 1),
|
|
353
|
+
h,
|
|
354
|
+
k,
|
|
355
|
+
{ value: n }
|
|
356
|
+
];
|
|
357
|
+
return p(new ParseErrorWithToken(e.UnexpectedEOFInString, h, k, ["4.3.5. Consume a string token", "Unexpected EOF"], t)), t;
|
|
358
|
+
}
|
|
359
|
+
if (m += 1, k = m - 1, isNewLine(i)) {
|
|
360
|
+
m -= 1, k = m - 1;
|
|
361
|
+
const n = [
|
|
362
|
+
u.BadString,
|
|
363
|
+
l.slice(h, k + 1),
|
|
364
|
+
h,
|
|
365
|
+
k,
|
|
366
|
+
void 0
|
|
367
|
+
];
|
|
368
|
+
return p(new ParseErrorWithToken(e.UnexpectedNewLineInString, h, l.codePointAt(m) === t && l.codePointAt(m + 1) === r ? k + 2 : k + 1, ["4.3.5. Consume a string token", "Unexpected newline"], n)), n;
|
|
369
|
+
}
|
|
370
|
+
if (i === o) return [
|
|
371
|
+
u.String,
|
|
372
|
+
l.slice(h, k + 1),
|
|
373
|
+
h,
|
|
374
|
+
k,
|
|
375
|
+
{ value: n }
|
|
376
|
+
];
|
|
377
|
+
if (i !== s) if (0 !== i) if (i < 128) n += String.fromCharCode(i);
|
|
378
|
+
else {
|
|
379
|
+
if (i >= 55296 && i <= 57343) {
|
|
380
|
+
const e = l.codePointAt(m - 1) ?? -1;
|
|
381
|
+
e >= 65536 ? (n += String.fromCodePoint(e), m += 1, k = m - 1) : n += String.fromCharCode(c);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
n += String.fromCharCode(i);
|
|
385
|
+
}
|
|
386
|
+
else n += String.fromCharCode(c);
|
|
387
|
+
else {
|
|
388
|
+
if (void 0 === l.codePointAt(m)) continue;
|
|
389
|
+
if (isNewLine(l.codePointAt(m) ?? -1)) {
|
|
390
|
+
l.codePointAt(m) === t && l.codePointAt(m + 1) === r && (m += 1), m += 1, k = m - 1;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
n += String.fromCodePoint(consumeEscapedCodePoint());
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function consumeUnicodeRangeToken() {
|
|
398
|
+
m += 2, k = m - 1;
|
|
399
|
+
const e = [], n = [];
|
|
400
|
+
let t;
|
|
401
|
+
for (; void 0 !== (t = l.codePointAt(m)) && e.length < 6 && isHexDigitCodePoint(t);) e.push(t), m += 1, k = m - 1;
|
|
402
|
+
for (; void 0 !== (t = l.codePointAt(m)) && e.length < 6 && 63 === t;) 0 === n.length && n.push(...e), e.push(48), n.push(70), m += 1, k = m - 1;
|
|
403
|
+
if (!n.length && l.codePointAt(m) === o && isHexDigitCodePoint(l.codePointAt(m + 1) ?? -1)) for (m += 1, k = m - 1; void 0 !== (t = l.codePointAt(m)) && n.length < 6 && isHexDigitCodePoint(t);) n.push(t), m += 1, k = m - 1;
|
|
404
|
+
if (!n.length) {
|
|
405
|
+
const n = parseInt(String.fromCodePoint(...e), 16);
|
|
406
|
+
return [
|
|
407
|
+
u.UnicodeRange,
|
|
408
|
+
l.slice(h, k + 1),
|
|
409
|
+
h,
|
|
410
|
+
k,
|
|
411
|
+
{
|
|
412
|
+
startOfRange: n,
|
|
413
|
+
endOfRange: n
|
|
414
|
+
}
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
const r = parseInt(String.fromCodePoint(...e), 16), i = parseInt(String.fromCodePoint(...n), 16);
|
|
418
|
+
return [
|
|
419
|
+
u.UnicodeRange,
|
|
420
|
+
l.slice(h, k + 1),
|
|
421
|
+
h,
|
|
422
|
+
k,
|
|
423
|
+
{
|
|
424
|
+
startOfRange: r,
|
|
425
|
+
endOfRange: i
|
|
426
|
+
}
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
function consumeUrlToken() {
|
|
430
|
+
for (; isWhitespace(l.codePointAt(m) ?? -1);) m += 1, k = m - 1;
|
|
431
|
+
let n = "";
|
|
432
|
+
for (;;) {
|
|
433
|
+
if (void 0 === l.codePointAt(m)) {
|
|
434
|
+
const t = [
|
|
435
|
+
u.URL,
|
|
436
|
+
l.slice(h, k + 1),
|
|
437
|
+
h,
|
|
438
|
+
k,
|
|
439
|
+
{ value: n }
|
|
440
|
+
];
|
|
441
|
+
return p(new ParseErrorWithToken(e.UnexpectedEOFInURL, h, k, ["4.3.6. Consume a url token", "Unexpected EOF"], t)), t;
|
|
442
|
+
}
|
|
443
|
+
if (41 === l.codePointAt(m)) return m += 1, k = m - 1, [
|
|
444
|
+
u.URL,
|
|
445
|
+
l.slice(h, k + 1),
|
|
446
|
+
h,
|
|
447
|
+
k,
|
|
448
|
+
{ value: n }
|
|
449
|
+
];
|
|
450
|
+
if (isWhitespace(l.codePointAt(m) ?? -1)) {
|
|
451
|
+
for (m += 1, k = m - 1; isWhitespace(l.codePointAt(m) ?? -1);) m += 1, k = m - 1;
|
|
452
|
+
if (void 0 === l.codePointAt(m)) {
|
|
453
|
+
const t = [
|
|
454
|
+
u.URL,
|
|
455
|
+
l.slice(h, k + 1),
|
|
456
|
+
h,
|
|
457
|
+
k,
|
|
458
|
+
{ value: n }
|
|
459
|
+
];
|
|
460
|
+
return p(new ParseErrorWithToken(e.UnexpectedEOFInURL, h, k, [
|
|
461
|
+
"4.3.6. Consume a url token",
|
|
462
|
+
"Consume as much whitespace as possible",
|
|
463
|
+
"Unexpected EOF"
|
|
464
|
+
], t)), t;
|
|
465
|
+
}
|
|
466
|
+
return 41 === l.codePointAt(m) ? (m += 1, k = m - 1, [
|
|
467
|
+
u.URL,
|
|
468
|
+
l.slice(h, k + 1),
|
|
469
|
+
h,
|
|
470
|
+
k,
|
|
471
|
+
{ value: n }
|
|
472
|
+
]) : (consumeBadURL(), [
|
|
473
|
+
u.BadURL,
|
|
474
|
+
l.slice(h, k + 1),
|
|
475
|
+
h,
|
|
476
|
+
k,
|
|
477
|
+
void 0
|
|
478
|
+
]);
|
|
479
|
+
}
|
|
480
|
+
const t = l.codePointAt(m);
|
|
481
|
+
if (34 === t || 39 === t || 40 === t || isNonPrintableCodePoint(t ?? -1)) {
|
|
482
|
+
consumeBadURL();
|
|
483
|
+
const n = [
|
|
484
|
+
u.BadURL,
|
|
485
|
+
l.slice(h, k + 1),
|
|
486
|
+
h,
|
|
487
|
+
k,
|
|
488
|
+
void 0
|
|
489
|
+
];
|
|
490
|
+
return p(new ParseErrorWithToken(e.UnexpectedCharacterInURL, h, k, ["4.3.6. Consume a url token", "Unexpected U+0022 QUOTATION MARK (\"), U+0027 APOSTROPHE ('), U+0028 LEFT PARENTHESIS (() or non-printable code point"], n)), n;
|
|
491
|
+
}
|
|
492
|
+
if (t === s) {
|
|
493
|
+
if (t === s && !isNewLine(l.codePointAt(m + 1) ?? -1)) {
|
|
494
|
+
m += 1, k = m - 1, n += String.fromCodePoint(consumeEscapedCodePoint());
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
consumeBadURL();
|
|
498
|
+
const o = [
|
|
499
|
+
u.BadURL,
|
|
500
|
+
l.slice(h, k + 1),
|
|
501
|
+
h,
|
|
502
|
+
k,
|
|
503
|
+
void 0
|
|
504
|
+
];
|
|
505
|
+
return p(new ParseErrorWithToken(e.InvalidEscapeSequenceInURL, h, k, [
|
|
506
|
+
"4.3.6. Consume a url token",
|
|
507
|
+
"U+005C REVERSE SOLIDUS (\\)",
|
|
508
|
+
"The input stream does not start with a valid escape sequence"
|
|
509
|
+
], o)), o;
|
|
510
|
+
}
|
|
511
|
+
0 === t || isSurrogate(t ?? -1) ? (n += String.fromCharCode(c), m += 1, k = m - 1) : (n += String.fromCodePoint(t ?? c), m += +((t ?? -1) > 65535) + 1, k = m - 1);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function consumeNumericToken() {
|
|
515
|
+
let e;
|
|
516
|
+
{
|
|
517
|
+
const n = l.charCodeAt(m);
|
|
518
|
+
n === o ? e = "-" : n === i && (e = "+");
|
|
519
|
+
}
|
|
520
|
+
let n = a.Integer;
|
|
521
|
+
const t = l.charCodeAt(m);
|
|
522
|
+
t !== i && t !== o || (m += 1);
|
|
523
|
+
let r = l.charCodeAt(m);
|
|
524
|
+
for (; r >= 48 && r <= 57;) m += 1, r = l.charCodeAt(m);
|
|
525
|
+
if (46 === l.charCodeAt(m) && l.charCodeAt(m + 1) >= 48 && l.charCodeAt(m + 1) <= 57) for (m += 2, n = a.Number, r = l.charCodeAt(m); r >= 48 && r <= 57;) m += 1, r = l.charCodeAt(m);
|
|
526
|
+
const c = l.charCodeAt(m);
|
|
527
|
+
if (101 === c || 69 === c) {
|
|
528
|
+
const e = l.charCodeAt(m + 1);
|
|
529
|
+
if (e >= 48 && e <= 57) for (m += 2, n = a.Number, r = l.charCodeAt(m); r >= 48 && r <= 57;) m += 1, r = l.charCodeAt(m);
|
|
530
|
+
else if ((e === o || e === i) && l.charCodeAt(m + 2) >= 48 && l.charCodeAt(m + 2) <= 57) for (m += 3, n = a.Number, r = l.charCodeAt(m); r >= 48 && r <= 57;) m += 1, r = l.charCodeAt(m);
|
|
531
|
+
}
|
|
532
|
+
k = m - 1;
|
|
533
|
+
const s = parseFloat(l.slice(h, k + 1));
|
|
534
|
+
if (checkIfThreeCodePointsWouldStartAnIdentSequence()) {
|
|
535
|
+
const t = consumeIdentSequence();
|
|
536
|
+
return [
|
|
537
|
+
u.Dimension,
|
|
538
|
+
l.slice(h, k + 1),
|
|
539
|
+
h,
|
|
540
|
+
k,
|
|
541
|
+
{
|
|
542
|
+
value: s,
|
|
543
|
+
signCharacter: e,
|
|
544
|
+
type: n,
|
|
545
|
+
unit: t
|
|
546
|
+
}
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
return 37 === l.charCodeAt(m) ? (m += 1, k = m - 1, [
|
|
550
|
+
u.Percentage,
|
|
551
|
+
l.slice(h, k + 1),
|
|
552
|
+
h,
|
|
553
|
+
k,
|
|
554
|
+
{
|
|
555
|
+
value: s,
|
|
556
|
+
signCharacter: e
|
|
557
|
+
}
|
|
558
|
+
]) : [
|
|
559
|
+
u.Number,
|
|
560
|
+
l.slice(h, k + 1),
|
|
561
|
+
h,
|
|
562
|
+
k,
|
|
563
|
+
{
|
|
564
|
+
value: s,
|
|
565
|
+
signCharacter: e,
|
|
566
|
+
type: n
|
|
567
|
+
}
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
function consumeIdentLikeToken() {
|
|
571
|
+
const e = consumeIdentSequence();
|
|
572
|
+
if (40 !== l.charCodeAt(m)) return [
|
|
573
|
+
u.Ident,
|
|
574
|
+
P ? e : l.slice(h, k + 1),
|
|
575
|
+
h,
|
|
576
|
+
k,
|
|
577
|
+
{ value: e }
|
|
578
|
+
];
|
|
579
|
+
if (!(3 !== e.length || 117 !== e.charCodeAt(0) && 85 !== e.charCodeAt(0) || 114 !== e.charCodeAt(1) && 82 !== e.charCodeAt(1) || 108 !== e.charCodeAt(2) && 76 !== e.charCodeAt(2))) {
|
|
580
|
+
m += 1, k = m - 1;
|
|
581
|
+
let n = 0;
|
|
582
|
+
for (; isWhitespace(l.charCodeAt(m));) n += 1, m += 1, k = m - 1;
|
|
583
|
+
const t = l.charCodeAt(m);
|
|
584
|
+
return 34 === t || 39 === t ? (n > 0 && (m -= n, k = m - 1), [
|
|
585
|
+
u.Function,
|
|
586
|
+
l.slice(h, k + 1),
|
|
587
|
+
h,
|
|
588
|
+
k,
|
|
589
|
+
{ value: e }
|
|
590
|
+
]) : consumeUrlToken();
|
|
591
|
+
}
|
|
592
|
+
return m += 1, k = m - 1, [
|
|
593
|
+
u.Function,
|
|
594
|
+
l.slice(h, k + 1),
|
|
595
|
+
h,
|
|
596
|
+
k,
|
|
597
|
+
{ value: e }
|
|
598
|
+
];
|
|
599
|
+
}
|
|
600
|
+
function consumeHashToken() {
|
|
601
|
+
m += 1, k = m - 1;
|
|
602
|
+
const e = l.charCodeAt(m);
|
|
603
|
+
if (e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === o || 95 === e || isNonASCII_IdentCodePoint(e) || e === s && !isNewLine(l.codePointAt(m + 1) ?? -1)) {
|
|
604
|
+
let e = d.Unrestricted;
|
|
605
|
+
checkIfThreeCodePointsWouldStartAnIdentSequence() && (e = d.ID);
|
|
606
|
+
const n = consumeIdentSequence();
|
|
607
|
+
return [
|
|
608
|
+
u.Hash,
|
|
609
|
+
l.slice(h, k + 1),
|
|
610
|
+
h,
|
|
611
|
+
k,
|
|
612
|
+
{
|
|
613
|
+
value: n,
|
|
614
|
+
type: e
|
|
615
|
+
}
|
|
616
|
+
];
|
|
617
|
+
}
|
|
618
|
+
return [
|
|
619
|
+
u.Delim,
|
|
620
|
+
"#",
|
|
621
|
+
h,
|
|
622
|
+
k,
|
|
623
|
+
{ value: "#" }
|
|
624
|
+
];
|
|
625
|
+
}
|
|
626
|
+
function consumeAtKeywordToken() {
|
|
627
|
+
if (m += 1, k = m - 1, checkIfThreeCodePointsWouldStartAnIdentSequence()) {
|
|
628
|
+
const e = consumeIdentSequence();
|
|
629
|
+
return [
|
|
630
|
+
u.AtKeyword,
|
|
631
|
+
l.slice(h, k + 1),
|
|
632
|
+
h,
|
|
633
|
+
k,
|
|
634
|
+
{ value: e }
|
|
635
|
+
];
|
|
636
|
+
}
|
|
637
|
+
return [
|
|
638
|
+
u.Delim,
|
|
639
|
+
"@",
|
|
640
|
+
h,
|
|
641
|
+
k,
|
|
642
|
+
{ value: "@" }
|
|
643
|
+
];
|
|
644
|
+
}
|
|
645
|
+
function consumeInvalidEscapeToken() {
|
|
646
|
+
m += 1, k = m - 1;
|
|
647
|
+
const n = [
|
|
648
|
+
u.Delim,
|
|
649
|
+
"\\",
|
|
650
|
+
h,
|
|
651
|
+
k,
|
|
652
|
+
{ value: "\\" }
|
|
653
|
+
];
|
|
654
|
+
return p(new ParseErrorWithToken(e.InvalidEscapeSequenceAfterBackslash, h, k, [
|
|
655
|
+
"4.3.1. Consume a token",
|
|
656
|
+
"U+005C REVERSE SOLIDUS (\\)",
|
|
657
|
+
"The input stream does not start with a valid escape sequence"
|
|
658
|
+
], n)), n;
|
|
659
|
+
}
|
|
660
|
+
function checkIfThreeCodePointsWouldStartAnIdentSequence(e) {
|
|
661
|
+
const n = void 0 === e ? l.charCodeAt(m) : e;
|
|
662
|
+
return n === o ? l.charCodeAt(m + 1) === o || !!isIdentStartCodePoint(l.charCodeAt(m + 1)) || l.charCodeAt(m + 1) === s && !isNewLine(l.charCodeAt(m + 2)) : !!isIdentStartCodePoint(n) || l.charCodeAt(m) === s && !isNewLine(l.charCodeAt(m + 1));
|
|
663
|
+
}
|
|
664
|
+
function checkIfThreeCodePointsWouldStartANumber(e) {
|
|
665
|
+
return e === i || e === o ? l.charCodeAt(m + 1) >= 48 && l.charCodeAt(m + 1) <= 57 || 46 === l.charCodeAt(m + 1) && l.charCodeAt(m + 2) >= 48 && l.charCodeAt(m + 2) <= 57 : 46 === e ? l.charCodeAt(m + 1) >= 48 && l.charCodeAt(m + 1) <= 57 : e >= 48 && e <= 57;
|
|
666
|
+
}
|
|
667
|
+
return {
|
|
668
|
+
nextToken: function nextToken() {
|
|
669
|
+
if (h = m, k = -1, m >= l.length) return [
|
|
670
|
+
u.EOF,
|
|
671
|
+
"",
|
|
672
|
+
-1,
|
|
673
|
+
-1,
|
|
674
|
+
void 0
|
|
675
|
+
];
|
|
676
|
+
const e = l.charCodeAt(m);
|
|
677
|
+
if (47 === e && 42 === l.charCodeAt(m + 1)) return consumeComment();
|
|
678
|
+
if (f && (117 === e || 85 === e) && l.codePointAt(m + 1) === i && (63 === l.codePointAt(m + 2) || isHexDigitCodePoint(l.codePointAt(m + 2) ?? -1))) return consumeUnicodeRangeToken();
|
|
679
|
+
if (isIdentStartCodePoint(e)) return consumeIdentLikeToken();
|
|
680
|
+
if ((n = e) >= 48 && n <= 57) return consumeNumericToken();
|
|
681
|
+
switch (e) {
|
|
682
|
+
case 44: return m += 1, k = m - 1, [
|
|
683
|
+
u.Comma,
|
|
684
|
+
",",
|
|
685
|
+
h,
|
|
686
|
+
k,
|
|
687
|
+
void 0
|
|
688
|
+
];
|
|
689
|
+
case 58: return m += 1, k = m - 1, [
|
|
690
|
+
u.Colon,
|
|
691
|
+
":",
|
|
692
|
+
h,
|
|
693
|
+
k,
|
|
694
|
+
void 0
|
|
695
|
+
];
|
|
696
|
+
case 59: return m += 1, k = m - 1, [
|
|
697
|
+
u.Semicolon,
|
|
698
|
+
";",
|
|
699
|
+
h,
|
|
700
|
+
k,
|
|
701
|
+
void 0
|
|
702
|
+
];
|
|
703
|
+
case 40: return m += 1, k = m - 1, [
|
|
704
|
+
u.OpenParen,
|
|
705
|
+
"(",
|
|
706
|
+
h,
|
|
707
|
+
k,
|
|
708
|
+
void 0
|
|
709
|
+
];
|
|
710
|
+
case 41: return m += 1, k = m - 1, [
|
|
711
|
+
u.CloseParen,
|
|
712
|
+
")",
|
|
713
|
+
h,
|
|
714
|
+
k,
|
|
715
|
+
void 0
|
|
716
|
+
];
|
|
717
|
+
case 91: return m += 1, k = m - 1, [
|
|
718
|
+
u.OpenSquare,
|
|
719
|
+
"[",
|
|
720
|
+
h,
|
|
721
|
+
k,
|
|
722
|
+
void 0
|
|
723
|
+
];
|
|
724
|
+
case 93: return m += 1, k = m - 1, [
|
|
725
|
+
u.CloseSquare,
|
|
726
|
+
"]",
|
|
727
|
+
h,
|
|
728
|
+
k,
|
|
729
|
+
void 0
|
|
730
|
+
];
|
|
731
|
+
case 123: return m += 1, k = m - 1, [
|
|
732
|
+
u.OpenCurly,
|
|
733
|
+
"{",
|
|
734
|
+
h,
|
|
735
|
+
k,
|
|
736
|
+
void 0
|
|
737
|
+
];
|
|
738
|
+
case 125: return m += 1, k = m - 1, [
|
|
739
|
+
u.CloseCurly,
|
|
740
|
+
"}",
|
|
741
|
+
h,
|
|
742
|
+
k,
|
|
743
|
+
void 0
|
|
744
|
+
];
|
|
745
|
+
case 39:
|
|
746
|
+
case 34: return consumeStringToken();
|
|
747
|
+
case 35: return consumeHashToken();
|
|
748
|
+
case i:
|
|
749
|
+
case 46: return checkIfThreeCodePointsWouldStartANumber(e) ? consumeNumericToken() : (m += 1, k = m - 1, [
|
|
750
|
+
u.Delim,
|
|
751
|
+
l[h],
|
|
752
|
+
h,
|
|
753
|
+
k,
|
|
754
|
+
{ value: l[h] }
|
|
755
|
+
]);
|
|
756
|
+
case r:
|
|
757
|
+
case t:
|
|
758
|
+
case 12:
|
|
759
|
+
case 9:
|
|
760
|
+
case 32:
|
|
761
|
+
{
|
|
762
|
+
let e = l.charCodeAt(m);
|
|
763
|
+
for (; 32 === e || e === r || 9 === e || e === t || 12 === e;) m += 1, e = l.charCodeAt(m);
|
|
764
|
+
k = m - 1;
|
|
765
|
+
}
|
|
766
|
+
return [
|
|
767
|
+
u.Whitespace,
|
|
768
|
+
l.slice(h, k + 1),
|
|
769
|
+
h,
|
|
770
|
+
k,
|
|
771
|
+
void 0
|
|
772
|
+
];
|
|
773
|
+
case o: return checkIfThreeCodePointsWouldStartANumber(e) ? consumeNumericToken() : l.charCodeAt(m + 1) === o && 62 === l.charCodeAt(m + 2) ? (m += 3, k = m - 1, [
|
|
774
|
+
u.CDC,
|
|
775
|
+
"-->",
|
|
776
|
+
h,
|
|
777
|
+
k,
|
|
778
|
+
void 0
|
|
779
|
+
]) : checkIfThreeCodePointsWouldStartAnIdentSequence(e) ? consumeIdentLikeToken() : (m += 1, k = m - 1, [
|
|
780
|
+
u.Delim,
|
|
781
|
+
"-",
|
|
782
|
+
h,
|
|
783
|
+
k,
|
|
784
|
+
{ value: "-" }
|
|
785
|
+
]);
|
|
786
|
+
case 60: return 33 === l.charCodeAt(m + 1) && l.charCodeAt(m + 2) === o && l.charCodeAt(m + 3) === o ? (m += 4, k = m - 1, [
|
|
787
|
+
u.CDO,
|
|
788
|
+
"<!--",
|
|
789
|
+
h,
|
|
790
|
+
k,
|
|
791
|
+
void 0
|
|
792
|
+
]) : (m += 1, k = m - 1, [
|
|
793
|
+
u.Delim,
|
|
794
|
+
"<",
|
|
795
|
+
h,
|
|
796
|
+
k,
|
|
797
|
+
{ value: "<" }
|
|
798
|
+
]);
|
|
799
|
+
case 64: return consumeAtKeywordToken();
|
|
800
|
+
case s: return e !== s || isNewLine(l.charCodeAt(m + 1)) ? consumeInvalidEscapeToken() : consumeIdentLikeToken();
|
|
801
|
+
default: return m += 1, k = m - 1, [
|
|
802
|
+
u.Delim,
|
|
803
|
+
l[h],
|
|
804
|
+
h,
|
|
805
|
+
k,
|
|
806
|
+
{ value: l[h] }
|
|
807
|
+
];
|
|
808
|
+
}
|
|
809
|
+
var n;
|
|
810
|
+
},
|
|
811
|
+
endOfFile: function endOfFile() {
|
|
812
|
+
return m >= l.length;
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
function noop() {}
|
|
817
|
+
(function(e) {
|
|
818
|
+
e.Comment = "comment", e.AtKeyword = "at-keyword-token", e.BadString = "bad-string-token", e.BadURL = "bad-url-token", e.CDC = "CDC-token", e.CDO = "CDO-token", e.Colon = "colon-token", e.Comma = "comma-token", e.Delim = "delim-token", e.Dimension = "dimension-token", e.EOF = "EOF-token", e.Function = "function-token", e.Hash = "hash-token", e.Ident = "ident-token", e.Number = "number-token", e.Percentage = "percentage-token", e.Semicolon = "semicolon-token", e.String = "string-token", e.URL = "url-token", e.Whitespace = "whitespace-token", e.OpenParen = "(-token", e.CloseParen = ")-token", e.OpenSquare = "[-token", e.CloseSquare = "]-token", e.OpenCurly = "{-token", e.CloseCurly = "}-token", e.UnicodeRange = "unicode-range-token";
|
|
819
|
+
})(u || (u = {})), function(e) {
|
|
820
|
+
e.Integer = "integer", e.Number = "number";
|
|
821
|
+
}(a || (a = {})), function(e) {
|
|
822
|
+
e.Unrestricted = "unrestricted", e.ID = "id";
|
|
823
|
+
}(d || (d = {}));
|
|
824
|
+
Object.values(u);
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/syntax/css-import.ts
|
|
827
|
+
function significantTokens(params) {
|
|
828
|
+
return tokenize({ css: params }).filter((token) => token[0] !== u.Whitespace && token[0] !== u.Comment);
|
|
829
|
+
}
|
|
830
|
+
function isCssWhitespace(char) {
|
|
831
|
+
return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f";
|
|
832
|
+
}
|
|
833
|
+
function skipCssWhitespace(params, index) {
|
|
834
|
+
while (index < params.length && isCssWhitespace(params[index])) index++;
|
|
835
|
+
return index;
|
|
836
|
+
}
|
|
837
|
+
function parseSimpleQuotedSpecifier(params, start) {
|
|
838
|
+
const quote = params[start];
|
|
839
|
+
if (quote !== "\"" && quote !== "'") return;
|
|
840
|
+
let index = start + 1;
|
|
841
|
+
while (index < params.length) {
|
|
842
|
+
const char = params[index];
|
|
843
|
+
if (char === "\\" || char === "\n" || char === "\r") return;
|
|
844
|
+
if (char === quote) return {
|
|
845
|
+
specifier: params.slice(start + 1, index),
|
|
846
|
+
raw: params.slice(start, index + 1),
|
|
847
|
+
quote
|
|
848
|
+
};
|
|
849
|
+
index++;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function parseSimpleImportSpecifier(params) {
|
|
853
|
+
let index = skipCssWhitespace(params, 0);
|
|
854
|
+
const quoted = parseSimpleQuotedSpecifier(params, index);
|
|
855
|
+
if (quoted) return quoted;
|
|
856
|
+
if (params.slice(index, index + 4).toLowerCase() !== "url(") return;
|
|
857
|
+
const urlStart = index;
|
|
858
|
+
index = skipCssWhitespace(params, index + 4);
|
|
859
|
+
const inner = parseSimpleQuotedSpecifier(params, index);
|
|
860
|
+
if (!inner) return;
|
|
861
|
+
index = skipCssWhitespace(params, index + inner.raw.length);
|
|
862
|
+
if (params[index] !== ")") return;
|
|
863
|
+
return {
|
|
864
|
+
specifier: inner.specifier,
|
|
865
|
+
raw: params.slice(urlStart, index + 1),
|
|
866
|
+
quote: inner.quote
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* 解析 `@import` / `@use` / `@forward` 参数中的请求串。
|
|
871
|
+
* 无 escape/注释的引号和 `url("...")` 走快路径;复杂输入才使用 CSS tokenizer。
|
|
872
|
+
*/
|
|
873
|
+
function parseCssImportSpecifier(params) {
|
|
874
|
+
const simple = parseSimpleImportSpecifier(params);
|
|
875
|
+
if (simple) return simple;
|
|
876
|
+
const tokens = significantTokens(params);
|
|
877
|
+
const first = tokens[0];
|
|
878
|
+
if (!first || first[0] === u.EOF) return;
|
|
879
|
+
if (first[0] === u.String || first[0] === u.URL || first[0] === u.Ident) return {
|
|
880
|
+
specifier: first[4].value,
|
|
881
|
+
raw: first[1],
|
|
882
|
+
quote: first[0] === u.String ? first[1][0] : void 0
|
|
883
|
+
};
|
|
884
|
+
if (first[0] === u.Function && first[4].value.toLowerCase() === "url" && (tokens[1]?.[0] === u.String || tokens[1]?.[0] === u.Ident) && tokens[2]?.[0] === u.CloseParen) return {
|
|
885
|
+
specifier: tokens[1][4].value,
|
|
886
|
+
raw: params.slice(first[2], tokens[2][3] + 1),
|
|
887
|
+
quote: tokens[1][0] === u.String ? tokens[1][1][0] : void 0
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
/** 把文件系统路径写成 CSS 请求串;缓存和读文件仍使用原始路径。 */
|
|
891
|
+
function quoteCssImportSpecifier(file, quote = "\"") {
|
|
892
|
+
return `${quote}${(node_path.default.sep === "\\" || /^[a-z]:[\\/]|^\\\\/i.test(file) ? file.replaceAll("\\", "/") : file).replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`).replaceAll("\n", "\\a ").replaceAll("\r", "\\d ")}${quote}`;
|
|
893
|
+
}
|
|
894
|
+
/** 判断 import 参数是否指向 Tailwind CSS 包入口。 */
|
|
895
|
+
function isTailwindCssImport(params) {
|
|
896
|
+
const specifier = parseCssImportSpecifier(params)?.specifier;
|
|
897
|
+
if (!specifier) return false;
|
|
898
|
+
if (specifier === "tailwindcss" || specifier.startsWith("tailwindcss/")) return true;
|
|
899
|
+
const paths = specifier.includes("\\") ? node_path.default.win32 : node_path.default.posix;
|
|
900
|
+
return paths.basename(specifier) === "index.css" && paths.basename(paths.dirname(specifier)) === "tailwindcss";
|
|
901
|
+
}
|
|
902
|
+
/** 解析 `@import "..." source(...)` 中的 source 参数。 */
|
|
903
|
+
function parseImportSourceParam(params) {
|
|
904
|
+
const tokens = significantTokens(params);
|
|
905
|
+
const index = tokens.findIndex((token) => token[0] === u.Function && token[4].value === "source");
|
|
906
|
+
const value = tokens[index + 1];
|
|
907
|
+
if (index < 0 || tokens[index + 2]?.[0] !== u.CloseParen) return;
|
|
908
|
+
if (value?.[0] === u.Ident && value[4].value === "none") return {
|
|
909
|
+
none: true,
|
|
910
|
+
sourcePath: void 0
|
|
911
|
+
};
|
|
912
|
+
return value?.[0] === u.String ? {
|
|
913
|
+
none: false,
|
|
914
|
+
sourcePath: value[4].value
|
|
915
|
+
} : void 0;
|
|
916
|
+
}
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region src/source-scan/description.ts
|
|
919
|
+
/** 只提取来源指令;默认扫描策略与配置加载由调用层决定。 */
|
|
920
|
+
function describeCssSources(root, isSourceImport = isTailwindCssImport) {
|
|
921
|
+
const imports = [];
|
|
922
|
+
const sources = [];
|
|
923
|
+
const configs = [];
|
|
924
|
+
root.walkAtRules((rule) => {
|
|
925
|
+
if (rule.name === "import" && isSourceImport(rule.params)) imports.push(parseImportSourceParam(rule.params) ?? {});
|
|
926
|
+
else if (rule.name === "source") {
|
|
927
|
+
const source = parseSourceFileParam(rule.params);
|
|
928
|
+
if (source) sources.push(source);
|
|
929
|
+
} else if (rule.name === "config") {
|
|
930
|
+
const config = parseConfigParam(rule.params);
|
|
931
|
+
if (config) configs.push(config);
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
return {
|
|
935
|
+
imports,
|
|
936
|
+
sources,
|
|
937
|
+
configs,
|
|
938
|
+
inlineCandidates: collectCssInlineSourceCandidates(root)
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
//#endregion
|
|
942
|
+
//#region src/source-scan/resolve.ts
|
|
943
|
+
/** 将 AST 描述与配置 content 合并,再交给共享扫描策略生成执行计划。 */
|
|
944
|
+
async function resolveCssScanSources(definitions, policy) {
|
|
945
|
+
const entries = [];
|
|
946
|
+
const configEntries = [];
|
|
947
|
+
const configGroups = [];
|
|
948
|
+
const configPaths = /* @__PURE__ */ new Set();
|
|
949
|
+
const included = /* @__PURE__ */ new Set();
|
|
950
|
+
const excluded = /* @__PURE__ */ new Set();
|
|
951
|
+
let automaticBase;
|
|
952
|
+
let sourceNone = false;
|
|
953
|
+
let hasImport = false;
|
|
954
|
+
for (const { root, base } of definitions) {
|
|
955
|
+
const descriptor = describeCssSources(root);
|
|
956
|
+
hasImport ||= descriptor.imports.length > 0;
|
|
957
|
+
sourceNone ||= descriptor.imports.some((item) => item.none);
|
|
958
|
+
for (const item of descriptor.imports) if (item.sourcePath) automaticBase = (0, _weapp_tailwindcss_source_scan.sourcePathApi)(base, item.sourcePath).resolve(base, item.sourcePath);
|
|
959
|
+
for (const source of descriptor.sources) entries.push(await (0, _weapp_tailwindcss_source_scan.resolveTailwindSourceEntry)(source.sourcePath, base, source.negated, policy.pattern));
|
|
960
|
+
for (const value of descriptor.inlineCandidates.included) included.add(value);
|
|
961
|
+
for (const value of descriptor.inlineCandidates.excluded) excluded.add(value);
|
|
962
|
+
for (const request of descriptor.configs) configPaths.add(policy.configResolution === "module" ? (0, node_module.createRequire)(node_path.default.join(base, "package.json")).resolve(request) : (0, _weapp_tailwindcss_source_scan.sourcePathApi)(base, request).resolve(base, request));
|
|
963
|
+
}
|
|
964
|
+
if (policy.config) configPaths.add((0, _weapp_tailwindcss_source_scan.sourcePathApi)(policy.base, policy.config).resolve(policy.base, policy.config));
|
|
965
|
+
for (const config of policy.loadConfigContent === false ? [] : configPaths) {
|
|
966
|
+
const base = node_path.default.dirname(config);
|
|
967
|
+
const loaded = await (0, tailwindcss_config.loadConfig)({
|
|
968
|
+
config,
|
|
969
|
+
cwd: base
|
|
970
|
+
});
|
|
971
|
+
const group = (0, _weapp_tailwindcss_source_scan.normalizeLegacyContentEntries)(loaded?.config.content, base, { relativeBase: base });
|
|
972
|
+
configGroups.push(group);
|
|
973
|
+
configEntries.push(...group);
|
|
974
|
+
}
|
|
975
|
+
const explicitEntries = policy.sourceEntries ?? entries;
|
|
976
|
+
const combinedEntries = [...explicitEntries, ...configEntries];
|
|
977
|
+
let mode = policy.automatic;
|
|
978
|
+
if (mode !== "disabled") {
|
|
979
|
+
if (automaticBase) mode = "auto";
|
|
980
|
+
else if (sourceNone || policy.requireImport && !hasImport && combinedEntries.length === 0) mode = "disabled";
|
|
981
|
+
}
|
|
982
|
+
const base = automaticBase ?? (combinedEntries.length > 0 ? policy.base : policy.defaultBase ?? policy.base);
|
|
983
|
+
return {
|
|
984
|
+
entries: (0, _weapp_tailwindcss_source_scan.createSourceScanPlan)({
|
|
985
|
+
base,
|
|
986
|
+
mode,
|
|
987
|
+
entries: combinedEntries,
|
|
988
|
+
pattern: policy.pattern,
|
|
989
|
+
...policy.ignoredPatterns ? { ignoredPatterns: policy.ignoredPatterns } : {}
|
|
990
|
+
}),
|
|
991
|
+
explicitEntries,
|
|
992
|
+
configEntries,
|
|
993
|
+
configGroups,
|
|
994
|
+
configPaths: [...configPaths],
|
|
995
|
+
inlineCandidates: {
|
|
996
|
+
included,
|
|
997
|
+
excluded
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
//#endregion
|
|
1002
|
+
//#region src/syntax/parse.ts
|
|
1003
|
+
/** 解析标准 CSS;调用方负责处理非法输入。 */
|
|
1004
|
+
function parseCssSource(source, from) {
|
|
1005
|
+
return postcss.default.parse(source, { from });
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* 解析 SCSS/Sass 风格源码。
|
|
1009
|
+
* `postcss.parse` 不读取 syntax 选项,行注释和插值必须走 SCSS parser。
|
|
1010
|
+
*/
|
|
1011
|
+
function parseScssSource(source, from) {
|
|
1012
|
+
return postcss_scss.default.parse(source, { from });
|
|
1013
|
+
}
|
|
1014
|
+
function stringifyScssSource(root) {
|
|
1015
|
+
return root.toString(postcss_scss.default.stringify);
|
|
1016
|
+
}
|
|
1017
|
+
/** Harmony 在 Sass 预处理前读取局部样式;必须识别行注释,避免将其并入选择器。 */
|
|
1018
|
+
function parseUniAppXStyleSource(source) {
|
|
1019
|
+
return parseScssSource(source);
|
|
1020
|
+
}
|
|
1021
|
+
function isUniAppXStyleSourceEmpty(source) {
|
|
1022
|
+
try {
|
|
1023
|
+
return parseUniAppXStyleSource(source).nodes.every((node) => node.type === "comment");
|
|
1024
|
+
} catch {
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/syntax/runtime-signature.ts
|
|
1030
|
+
function rawField(node, field, value) {
|
|
1031
|
+
const raw = node.raws[field];
|
|
1032
|
+
return raw?.value === value ? raw.raw : value;
|
|
1033
|
+
}
|
|
1034
|
+
function signatureNodes(nodes) {
|
|
1035
|
+
const result = [];
|
|
1036
|
+
for (const node of nodes) {
|
|
1037
|
+
if (node.type === "comment") continue;
|
|
1038
|
+
const before = node.raws.before?.trim() ?? "";
|
|
1039
|
+
const between = node.raws.between?.trim() ?? "";
|
|
1040
|
+
if (node.type === "decl") result.push([
|
|
1041
|
+
"decl",
|
|
1042
|
+
before,
|
|
1043
|
+
node.prop,
|
|
1044
|
+
between,
|
|
1045
|
+
rawField(node, "value", node.value),
|
|
1046
|
+
Boolean(node.important)
|
|
1047
|
+
]);
|
|
1048
|
+
else {
|
|
1049
|
+
const after = node.raws.after?.trim() ?? "";
|
|
1050
|
+
if (node.type === "rule") result.push([
|
|
1051
|
+
"rule",
|
|
1052
|
+
before,
|
|
1053
|
+
rawField(node, "selector", node.selector),
|
|
1054
|
+
between,
|
|
1055
|
+
signatureNodes(node.nodes),
|
|
1056
|
+
after
|
|
1057
|
+
]);
|
|
1058
|
+
else result.push([
|
|
1059
|
+
"atrule",
|
|
1060
|
+
before,
|
|
1061
|
+
node.name,
|
|
1062
|
+
node.raws.afterName?.trim() ?? "",
|
|
1063
|
+
rawField(node, "params", node.params),
|
|
1064
|
+
between,
|
|
1065
|
+
Boolean(node.nodes),
|
|
1066
|
+
signatureNodes(node.nodes ?? []),
|
|
1067
|
+
after
|
|
1068
|
+
]);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
return result;
|
|
1072
|
+
}
|
|
1073
|
+
/** 忽略结构性排版,保留值、选择器和 token 边界;不追求合并所有等价 CSS。 */
|
|
1074
|
+
function createCssRuntimeAffectingSignature(source) {
|
|
1075
|
+
try {
|
|
1076
|
+
const root = parseCssSource(source);
|
|
1077
|
+
return JSON.stringify([
|
|
1078
|
+
"css",
|
|
1079
|
+
signatureNodes(root.nodes),
|
|
1080
|
+
root.raws.after?.trim() ?? ""
|
|
1081
|
+
]);
|
|
1082
|
+
} catch {
|
|
1083
|
+
return JSON.stringify(["raw", source]);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
//#endregion
|
|
1087
|
+
//#region src/syntax/location-dependencies.ts
|
|
1088
|
+
const LOCATION_SYNTAX_HINT_RE = /[@\\]|url\(/i;
|
|
1089
|
+
const ABSOLUTE_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/|#)/i;
|
|
1090
|
+
function isIndependentUrl(value) {
|
|
1091
|
+
return ABSOLUTE_URL_RE.test(value.trim());
|
|
1092
|
+
}
|
|
1093
|
+
/** 判断 CSS 转换是否依赖资源位置;路径解析和缓存范围仍由调用方负责。 */
|
|
1094
|
+
function hasCssLocationDependencies(source) {
|
|
1095
|
+
if (!LOCATION_SYNTAX_HINT_RE.test(source)) return false;
|
|
1096
|
+
let malformed = false;
|
|
1097
|
+
const stream = tokenizer({ css: source }, { onParseError() {
|
|
1098
|
+
malformed = true;
|
|
1099
|
+
} });
|
|
1100
|
+
const nextSignificant = () => {
|
|
1101
|
+
let token = stream.nextToken();
|
|
1102
|
+
while (token[0] === u.Whitespace || token[0] === u.Comment) token = stream.nextToken();
|
|
1103
|
+
return token;
|
|
1104
|
+
};
|
|
1105
|
+
while (!stream.endOfFile()) {
|
|
1106
|
+
const token = stream.nextToken();
|
|
1107
|
+
if (token[0] === u.AtKeyword && token[4].value.toLowerCase() === "import") return true;
|
|
1108
|
+
if (token[0] === u.URL && !isIndependentUrl(token[4].value)) return true;
|
|
1109
|
+
if (token[0] === u.Function && token[4].value.toLowerCase() === "url") {
|
|
1110
|
+
const value = nextSignificant();
|
|
1111
|
+
if (value[0] !== u.String || !isIndependentUrl(value[4].value)) return true;
|
|
1112
|
+
if (nextSignificant()[0] !== u.CloseParen) return true;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return malformed;
|
|
1116
|
+
}
|
|
1117
|
+
//#endregion
|
|
1118
|
+
//#region src/syntax/rewrite-imports.ts
|
|
1119
|
+
/** 改写请求串;文件查找、包解析与路径规则由调用方提供。 */
|
|
1120
|
+
function rewriteCssImportSpecifiers(css, resolve, options = {}) {
|
|
1121
|
+
let root;
|
|
1122
|
+
try {
|
|
1123
|
+
root = postcss.default.parse(css);
|
|
1124
|
+
} catch (error) {
|
|
1125
|
+
if (options.tolerateInvalidCss) return css;
|
|
1126
|
+
throw error;
|
|
1127
|
+
}
|
|
1128
|
+
const names = new Set(options.atRuleNames ?? ["import"]);
|
|
1129
|
+
let changed = false;
|
|
1130
|
+
root.walkAtRules((rule) => {
|
|
1131
|
+
if (!names.has(rule.name)) return;
|
|
1132
|
+
const parsed = parseCssImportSpecifier(rule.params);
|
|
1133
|
+
if (!parsed) return;
|
|
1134
|
+
const replacement = resolve(parsed.specifier);
|
|
1135
|
+
if (!replacement) return;
|
|
1136
|
+
rule.params = rule.params.replace(parsed.raw, () => quoteCssImportSpecifier(replacement, parsed.quote));
|
|
1137
|
+
changed = true;
|
|
1138
|
+
});
|
|
1139
|
+
return changed ? root.toString() : css;
|
|
1140
|
+
}
|
|
1141
|
+
//#endregion
|
|
1142
|
+
exports.collectCssInlineSourceCandidates = collectCssInlineSourceCandidates;
|
|
1143
|
+
exports.createCssRuntimeAffectingSignature = createCssRuntimeAffectingSignature;
|
|
1144
|
+
exports.describeCssSources = describeCssSources;
|
|
1145
|
+
exports.expandInlineSourceCandidatePattern = expandInlineSourceCandidatePattern;
|
|
1146
|
+
exports.expandTailwindSourceEntries = expandTailwindSourceEntries;
|
|
1147
|
+
exports.hasCssLocationDependencies = hasCssLocationDependencies;
|
|
1148
|
+
exports.isTailwindCssImport = isTailwindCssImport;
|
|
1149
|
+
exports.isUniAppXStyleSourceEmpty = isUniAppXStyleSourceEmpty;
|
|
1150
|
+
exports.parseConfigParam = parseConfigParam;
|
|
1151
|
+
exports.parseCssImportSpecifier = parseCssImportSpecifier;
|
|
1152
|
+
exports.parseCssSource = parseCssSource;
|
|
1153
|
+
exports.parseImportSourceParam = parseImportSourceParam;
|
|
1154
|
+
exports.parseScssSource = parseScssSource;
|
|
1155
|
+
exports.parseSourceFileParam = parseSourceFileParam;
|
|
1156
|
+
exports.parseUniAppXStyleSource = parseUniAppXStyleSource;
|
|
1157
|
+
exports.quoteCssImportSpecifier = quoteCssImportSpecifier;
|
|
1158
|
+
exports.resolveCssScanSources = resolveCssScanSources;
|
|
1159
|
+
exports.resolveCssSourceEntries = resolveCssSourceEntries;
|
|
1160
|
+
exports.rewriteCssImportSpecifiers = rewriteCssImportSpecifiers;
|
|
1161
|
+
Object.defineProperty(exports, "scss", {
|
|
1162
|
+
enumerable: true,
|
|
1163
|
+
get: function() {
|
|
1164
|
+
return postcss_scss.default;
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
exports.stringifyScssSource = stringifyScssSource;
|