@qt-test/apex-dsl-compiler 0.1.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/README.md +272 -0
- package/bin/apexc.js +308 -0
- package/dist/acss/index.d.mts +67 -0
- package/dist/acss/index.d.ts +67 -0
- package/dist/acss/index.js +632 -0
- package/dist/acss/index.mjs +8 -0
- package/dist/ast-DEVgojMx.d.mts +135 -0
- package/dist/ast-DEVgojMx.d.ts +135 -0
- package/dist/axml/index.d.mts +59 -0
- package/dist/axml/index.d.ts +59 -0
- package/dist/axml/index.js +863 -0
- package/dist/axml/index.mjs +8 -0
- package/dist/chunk-7LDI6MFY.mjs +605 -0
- package/dist/chunk-B7VE6TVQ.mjs +605 -0
- package/dist/chunk-GQ3PJZ2P.mjs +836 -0
- package/dist/chunk-IRS3J3N7.mjs +836 -0
- package/dist/index.d.mts +237 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +2050 -0
- package/dist/index.mjs +587 -0
- package/package.json +71 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/acss/index.ts
|
|
21
|
+
var acss_exports = {};
|
|
22
|
+
__export(acss_exports, {
|
|
23
|
+
compileACSS: () => compileACSS,
|
|
24
|
+
parseACSS: () => parseACSS
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(acss_exports);
|
|
27
|
+
|
|
28
|
+
// src/acss/parser.ts
|
|
29
|
+
function createPosition(state) {
|
|
30
|
+
return {
|
|
31
|
+
line: state.line,
|
|
32
|
+
column: state.column,
|
|
33
|
+
offset: state.pos
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createLoc(start, end, source) {
|
|
37
|
+
return { start, end, source };
|
|
38
|
+
}
|
|
39
|
+
function parseACSS(source) {
|
|
40
|
+
const state = {
|
|
41
|
+
source,
|
|
42
|
+
pos: 0,
|
|
43
|
+
line: 1,
|
|
44
|
+
column: 0,
|
|
45
|
+
errors: []
|
|
46
|
+
};
|
|
47
|
+
const start = createPosition(state);
|
|
48
|
+
const rules = [];
|
|
49
|
+
const imports = [];
|
|
50
|
+
while (state.pos < state.source.length) {
|
|
51
|
+
skipWhitespaceAndComments(state);
|
|
52
|
+
if (state.pos >= state.source.length) break;
|
|
53
|
+
if (lookAhead(state, "@import")) {
|
|
54
|
+
const importRule = parseImport(state);
|
|
55
|
+
if (importRule) {
|
|
56
|
+
imports.push(importRule);
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (lookAhead(state, "@media")) {
|
|
61
|
+
const mediaRule = parseMediaRule(state);
|
|
62
|
+
if (mediaRule) {
|
|
63
|
+
rules.push(mediaRule);
|
|
64
|
+
}
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (lookAhead(state, "@keyframes") || lookAhead(state, "@-webkit-keyframes")) {
|
|
68
|
+
const keyframesRule = parseKeyframesRule(state);
|
|
69
|
+
if (keyframesRule) {
|
|
70
|
+
rules.push(keyframesRule);
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const rule = parseStyleRule(state);
|
|
75
|
+
if (rule) {
|
|
76
|
+
rules.push(rule);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const end = createPosition(state);
|
|
80
|
+
return {
|
|
81
|
+
ast: {
|
|
82
|
+
type: "Stylesheet",
|
|
83
|
+
rules,
|
|
84
|
+
imports,
|
|
85
|
+
start: start.offset,
|
|
86
|
+
end: end.offset,
|
|
87
|
+
loc: createLoc(start, end)
|
|
88
|
+
},
|
|
89
|
+
errors: state.errors
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function parseImport(state) {
|
|
93
|
+
const start = createPosition(state);
|
|
94
|
+
advance(state, 7);
|
|
95
|
+
skipWhitespace(state);
|
|
96
|
+
let path = "";
|
|
97
|
+
const quote = state.source[state.pos];
|
|
98
|
+
if (quote === '"' || quote === "'") {
|
|
99
|
+
advance(state);
|
|
100
|
+
while (state.pos < state.source.length && state.source[state.pos] !== quote) {
|
|
101
|
+
path += state.source[state.pos];
|
|
102
|
+
advance(state);
|
|
103
|
+
}
|
|
104
|
+
advance(state);
|
|
105
|
+
} else {
|
|
106
|
+
state.errors.push(`Expected quoted string at line ${state.line}`);
|
|
107
|
+
skipToSemicolon(state);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
skipWhitespace(state);
|
|
111
|
+
consume(state, ";");
|
|
112
|
+
const end = createPosition(state);
|
|
113
|
+
return {
|
|
114
|
+
type: "Import",
|
|
115
|
+
path,
|
|
116
|
+
start: start.offset,
|
|
117
|
+
end: end.offset,
|
|
118
|
+
loc: createLoc(start, end)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function parseMediaRule(state) {
|
|
122
|
+
const start = createPosition(state);
|
|
123
|
+
advance(state, 6);
|
|
124
|
+
skipWhitespace(state);
|
|
125
|
+
let query = "";
|
|
126
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "{") {
|
|
127
|
+
query += state.source[state.pos];
|
|
128
|
+
advance(state);
|
|
129
|
+
}
|
|
130
|
+
query = query.trim();
|
|
131
|
+
if (!consume(state, "{")) {
|
|
132
|
+
state.errors.push(`Expected '{' at line ${state.line}`);
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const rules = [];
|
|
136
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "}") {
|
|
137
|
+
skipWhitespaceAndComments(state);
|
|
138
|
+
if (state.source[state.pos] === "}") break;
|
|
139
|
+
const rule = parseStyleRule(state);
|
|
140
|
+
if (rule) {
|
|
141
|
+
rules.push(rule);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
consume(state, "}");
|
|
145
|
+
const end = createPosition(state);
|
|
146
|
+
return {
|
|
147
|
+
type: "MediaRule",
|
|
148
|
+
query,
|
|
149
|
+
rules,
|
|
150
|
+
start: start.offset,
|
|
151
|
+
end: end.offset,
|
|
152
|
+
loc: createLoc(start, end)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function parseKeyframesRule(state) {
|
|
156
|
+
const start = createPosition(state);
|
|
157
|
+
if (lookAhead(state, "@-webkit-keyframes")) {
|
|
158
|
+
advance(state, 18);
|
|
159
|
+
} else {
|
|
160
|
+
advance(state, 10);
|
|
161
|
+
}
|
|
162
|
+
skipWhitespace(state);
|
|
163
|
+
let name = "";
|
|
164
|
+
while (state.pos < state.source.length && !/[\s{]/.test(state.source[state.pos])) {
|
|
165
|
+
name += state.source[state.pos];
|
|
166
|
+
advance(state);
|
|
167
|
+
}
|
|
168
|
+
skipWhitespace(state);
|
|
169
|
+
if (!consume(state, "{")) {
|
|
170
|
+
state.errors.push(`Expected '{' at line ${state.line}`);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const keyframes = [];
|
|
174
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "}") {
|
|
175
|
+
skipWhitespaceAndComments(state);
|
|
176
|
+
if (state.source[state.pos] === "}") break;
|
|
177
|
+
const keyframe = parseKeyframe(state);
|
|
178
|
+
if (keyframe) {
|
|
179
|
+
keyframes.push(keyframe);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
consume(state, "}");
|
|
183
|
+
const end = createPosition(state);
|
|
184
|
+
return {
|
|
185
|
+
type: "KeyframesRule",
|
|
186
|
+
name,
|
|
187
|
+
keyframes,
|
|
188
|
+
start: start.offset,
|
|
189
|
+
end: end.offset,
|
|
190
|
+
loc: createLoc(start, end)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function parseKeyframe(state) {
|
|
194
|
+
const start = createPosition(state);
|
|
195
|
+
let selector = "";
|
|
196
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "{") {
|
|
197
|
+
selector += state.source[state.pos];
|
|
198
|
+
advance(state);
|
|
199
|
+
}
|
|
200
|
+
selector = selector.trim();
|
|
201
|
+
if (!consume(state, "{")) {
|
|
202
|
+
state.errors.push(`Expected '{' at line ${state.line}`);
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const declarations = parseDeclarations(state);
|
|
206
|
+
consume(state, "}");
|
|
207
|
+
const end = createPosition(state);
|
|
208
|
+
return {
|
|
209
|
+
type: "Keyframe",
|
|
210
|
+
selector,
|
|
211
|
+
declarations,
|
|
212
|
+
start: start.offset,
|
|
213
|
+
end: end.offset,
|
|
214
|
+
loc: createLoc(start, end)
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function parseStyleRule(state) {
|
|
218
|
+
const start = createPosition(state);
|
|
219
|
+
const selectors = parseSelectors(state);
|
|
220
|
+
if (selectors.length === 0) {
|
|
221
|
+
skipToCloseBrace(state);
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
skipWhitespace(state);
|
|
225
|
+
if (!consume(state, "{")) {
|
|
226
|
+
state.errors.push(`Expected '{' at line ${state.line}`);
|
|
227
|
+
skipToCloseBrace(state);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const declarations = parseDeclarations(state);
|
|
231
|
+
consume(state, "}");
|
|
232
|
+
const end = createPosition(state);
|
|
233
|
+
return {
|
|
234
|
+
type: "StyleRule",
|
|
235
|
+
selectors,
|
|
236
|
+
declarations,
|
|
237
|
+
start: start.offset,
|
|
238
|
+
end: end.offset,
|
|
239
|
+
loc: createLoc(start, end)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function parseSelectors(state) {
|
|
243
|
+
const selectors = [];
|
|
244
|
+
let current = "";
|
|
245
|
+
const start = createPosition(state);
|
|
246
|
+
while (state.pos < state.source.length) {
|
|
247
|
+
const char = state.source[state.pos];
|
|
248
|
+
if (char === "{") break;
|
|
249
|
+
if (char === ",") {
|
|
250
|
+
const trimmed2 = current.trim();
|
|
251
|
+
if (trimmed2) {
|
|
252
|
+
const end = createPosition(state);
|
|
253
|
+
selectors.push({
|
|
254
|
+
type: "Selector",
|
|
255
|
+
value: trimmed2,
|
|
256
|
+
specificity: calculateSpecificity(trimmed2),
|
|
257
|
+
start: start.offset,
|
|
258
|
+
end: end.offset,
|
|
259
|
+
loc: createLoc(start, end)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
advance(state);
|
|
263
|
+
current = "";
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
current += char;
|
|
267
|
+
advance(state);
|
|
268
|
+
}
|
|
269
|
+
const trimmed = current.trim();
|
|
270
|
+
if (trimmed) {
|
|
271
|
+
const end = createPosition(state);
|
|
272
|
+
selectors.push({
|
|
273
|
+
type: "Selector",
|
|
274
|
+
value: trimmed,
|
|
275
|
+
specificity: calculateSpecificity(trimmed),
|
|
276
|
+
start: start.offset,
|
|
277
|
+
end: end.offset,
|
|
278
|
+
loc: createLoc(start, end)
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return selectors;
|
|
282
|
+
}
|
|
283
|
+
function calculateSpecificity(selector) {
|
|
284
|
+
let ids = 0;
|
|
285
|
+
let classes = 0;
|
|
286
|
+
let elements = 0;
|
|
287
|
+
ids = (selector.match(/#[a-zA-Z_-][a-zA-Z0-9_-]*/g) || []).length;
|
|
288
|
+
classes = (selector.match(/\.[a-zA-Z_-][a-zA-Z0-9_-]*/g) || []).length;
|
|
289
|
+
classes += (selector.match(/\[[^\]]+\]/g) || []).length;
|
|
290
|
+
classes += (selector.match(/:[a-zA-Z-]+(?:\([^)]*\))?/g) || []).filter(
|
|
291
|
+
(p) => !p.startsWith("::")
|
|
292
|
+
).length;
|
|
293
|
+
const withoutIds = selector.replace(/#[a-zA-Z_-][a-zA-Z0-9_-]*/g, "");
|
|
294
|
+
const withoutClasses = withoutIds.replace(/\.[a-zA-Z_-][a-zA-Z0-9_-]*/g, "");
|
|
295
|
+
const withoutAttrs = withoutClasses.replace(/\[[^\]]+\]/g, "");
|
|
296
|
+
const withoutPseudo = withoutAttrs.replace(/:[a-zA-Z-]+(?:\([^)]*\))?/g, "");
|
|
297
|
+
const tagMatches = withoutPseudo.match(/[a-zA-Z][a-zA-Z0-9-]*/g) || [];
|
|
298
|
+
elements = tagMatches.filter((t) => !["not", "is", "where", "has"].includes(t)).length;
|
|
299
|
+
elements += (selector.match(/::[a-zA-Z-]+/g) || []).length;
|
|
300
|
+
return [ids, classes, elements];
|
|
301
|
+
}
|
|
302
|
+
function parseDeclarations(state) {
|
|
303
|
+
const declarations = [];
|
|
304
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "}") {
|
|
305
|
+
skipWhitespaceAndComments(state);
|
|
306
|
+
if (state.source[state.pos] === "}") break;
|
|
307
|
+
const declaration = parseDeclaration(state);
|
|
308
|
+
if (declaration) {
|
|
309
|
+
declarations.push(declaration);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return declarations;
|
|
313
|
+
}
|
|
314
|
+
function parseDeclaration(state) {
|
|
315
|
+
const start = createPosition(state);
|
|
316
|
+
let property = "";
|
|
317
|
+
while (state.pos < state.source.length && state.source[state.pos] !== ":" && state.source[state.pos] !== "}") {
|
|
318
|
+
property += state.source[state.pos];
|
|
319
|
+
advance(state);
|
|
320
|
+
}
|
|
321
|
+
property = property.trim();
|
|
322
|
+
if (!property || !consume(state, ":")) {
|
|
323
|
+
skipToSemicolon(state);
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
skipWhitespace(state);
|
|
327
|
+
let value = "";
|
|
328
|
+
let important = false;
|
|
329
|
+
let parenDepth = 0;
|
|
330
|
+
while (state.pos < state.source.length) {
|
|
331
|
+
const char = state.source[state.pos];
|
|
332
|
+
if (char === "(") parenDepth++;
|
|
333
|
+
if (char === ")") parenDepth--;
|
|
334
|
+
if (parenDepth === 0 && (char === ";" || char === "}")) {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
value += char;
|
|
338
|
+
advance(state);
|
|
339
|
+
}
|
|
340
|
+
value = value.trim();
|
|
341
|
+
if (value.endsWith("!important")) {
|
|
342
|
+
important = true;
|
|
343
|
+
value = value.slice(0, -10).trim();
|
|
344
|
+
}
|
|
345
|
+
consume(state, ";");
|
|
346
|
+
const end = createPosition(state);
|
|
347
|
+
if (!/^[a-zA-Z-]+$/.test(property)) {
|
|
348
|
+
state.errors.push(`Invalid property name "${property}" at line ${start.line}`);
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
type: "Declaration",
|
|
353
|
+
property,
|
|
354
|
+
value,
|
|
355
|
+
important,
|
|
356
|
+
start: start.offset,
|
|
357
|
+
end: end.offset,
|
|
358
|
+
loc: createLoc(start, end)
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function advance(state, count = 1) {
|
|
362
|
+
for (let i = 0; i < count && state.pos < state.source.length; i++) {
|
|
363
|
+
if (state.source[state.pos] === "\n") {
|
|
364
|
+
state.line++;
|
|
365
|
+
state.column = 0;
|
|
366
|
+
} else {
|
|
367
|
+
state.column++;
|
|
368
|
+
}
|
|
369
|
+
state.pos++;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function lookAhead(state, str) {
|
|
373
|
+
return state.source.slice(state.pos, state.pos + str.length) === str;
|
|
374
|
+
}
|
|
375
|
+
function consume(state, str) {
|
|
376
|
+
if (lookAhead(state, str)) {
|
|
377
|
+
advance(state, str.length);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
function skipWhitespace(state) {
|
|
383
|
+
while (state.pos < state.source.length && /\s/.test(state.source[state.pos])) {
|
|
384
|
+
advance(state);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function skipWhitespaceAndComments(state) {
|
|
388
|
+
while (state.pos < state.source.length) {
|
|
389
|
+
skipWhitespace(state);
|
|
390
|
+
if (lookAhead(state, "/*")) {
|
|
391
|
+
advance(state, 2);
|
|
392
|
+
while (state.pos < state.source.length && !lookAhead(state, "*/")) {
|
|
393
|
+
advance(state);
|
|
394
|
+
}
|
|
395
|
+
advance(state, 2);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (lookAhead(state, "//")) {
|
|
399
|
+
while (state.pos < state.source.length && state.source[state.pos] !== "\n") {
|
|
400
|
+
advance(state);
|
|
401
|
+
}
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
function skipToSemicolon(state) {
|
|
408
|
+
while (state.pos < state.source.length && state.source[state.pos] !== ";" && state.source[state.pos] !== "}") {
|
|
409
|
+
advance(state);
|
|
410
|
+
}
|
|
411
|
+
consume(state, ";");
|
|
412
|
+
}
|
|
413
|
+
function skipToCloseBrace(state) {
|
|
414
|
+
let depth = 0;
|
|
415
|
+
while (state.pos < state.source.length) {
|
|
416
|
+
if (state.source[state.pos] === "{") depth++;
|
|
417
|
+
if (state.source[state.pos] === "}") {
|
|
418
|
+
if (depth === 0) {
|
|
419
|
+
advance(state);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
depth--;
|
|
423
|
+
}
|
|
424
|
+
advance(state);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/acss/compiler.ts
|
|
429
|
+
var PREFIXED_PROPERTIES = {
|
|
430
|
+
"transform": ["-webkit-transform"],
|
|
431
|
+
"transform-origin": ["-webkit-transform-origin"],
|
|
432
|
+
"transition": ["-webkit-transition"],
|
|
433
|
+
"animation": ["-webkit-animation"],
|
|
434
|
+
"animation-name": ["-webkit-animation-name"],
|
|
435
|
+
"animation-duration": ["-webkit-animation-duration"],
|
|
436
|
+
"animation-timing-function": ["-webkit-animation-timing-function"],
|
|
437
|
+
"animation-delay": ["-webkit-animation-delay"],
|
|
438
|
+
"animation-iteration-count": ["-webkit-animation-iteration-count"],
|
|
439
|
+
"animation-direction": ["-webkit-animation-direction"],
|
|
440
|
+
"animation-fill-mode": ["-webkit-animation-fill-mode"],
|
|
441
|
+
"animation-play-state": ["-webkit-animation-play-state"],
|
|
442
|
+
"flex": ["-webkit-flex"],
|
|
443
|
+
"flex-direction": ["-webkit-flex-direction"],
|
|
444
|
+
"flex-wrap": ["-webkit-flex-wrap"],
|
|
445
|
+
"flex-flow": ["-webkit-flex-flow"],
|
|
446
|
+
"justify-content": ["-webkit-justify-content"],
|
|
447
|
+
"align-items": ["-webkit-align-items"],
|
|
448
|
+
"align-content": ["-webkit-align-content"],
|
|
449
|
+
"align-self": ["-webkit-align-self"],
|
|
450
|
+
"order": ["-webkit-order"],
|
|
451
|
+
"flex-grow": ["-webkit-flex-grow"],
|
|
452
|
+
"flex-shrink": ["-webkit-flex-shrink"],
|
|
453
|
+
"flex-basis": ["-webkit-flex-basis"],
|
|
454
|
+
"user-select": ["-webkit-user-select", "-moz-user-select"],
|
|
455
|
+
"appearance": ["-webkit-appearance", "-moz-appearance"],
|
|
456
|
+
"backdrop-filter": ["-webkit-backdrop-filter"],
|
|
457
|
+
"background-clip": ["-webkit-background-clip"]
|
|
458
|
+
};
|
|
459
|
+
function compileACSS(source, options = {}) {
|
|
460
|
+
const { ast, errors: parseErrors } = parseACSS(source);
|
|
461
|
+
const warnings = [];
|
|
462
|
+
const errors = [...parseErrors];
|
|
463
|
+
const animations = /* @__PURE__ */ new Set();
|
|
464
|
+
const imports = ast.imports.map((i) => i.path);
|
|
465
|
+
const processedRules = ast.rules.map((rule) => processRule(rule, options, animations, warnings));
|
|
466
|
+
const css = generateCSS(processedRules, options, warnings);
|
|
467
|
+
return {
|
|
468
|
+
css,
|
|
469
|
+
ast,
|
|
470
|
+
warnings,
|
|
471
|
+
errors,
|
|
472
|
+
imports,
|
|
473
|
+
animations
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function processRule(rule, options, animations, warnings) {
|
|
477
|
+
switch (rule.type) {
|
|
478
|
+
case "StyleRule":
|
|
479
|
+
return processStyleRule(rule, options, animations, warnings);
|
|
480
|
+
case "MediaRule":
|
|
481
|
+
return {
|
|
482
|
+
...rule,
|
|
483
|
+
rules: rule.rules.map((r) => processStyleRule(r, options, animations, warnings))
|
|
484
|
+
};
|
|
485
|
+
case "KeyframesRule":
|
|
486
|
+
animations.add(rule.name);
|
|
487
|
+
return processKeyframesRule(rule, options, warnings);
|
|
488
|
+
default:
|
|
489
|
+
return rule;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function processStyleRule(rule, options, animations, warnings) {
|
|
493
|
+
let selectors = rule.selectors;
|
|
494
|
+
if (options.scoped && options.scopeId) {
|
|
495
|
+
selectors = selectors.map((s) => ({
|
|
496
|
+
...s,
|
|
497
|
+
value: scopeSelector(s.value, options.scopeId)
|
|
498
|
+
}));
|
|
499
|
+
}
|
|
500
|
+
let declarations = rule.declarations.map((d) => processDeclaration(d, options, warnings));
|
|
501
|
+
if (options.autoprefixer) {
|
|
502
|
+
declarations = addVendorPrefixes(declarations);
|
|
503
|
+
}
|
|
504
|
+
declarations.forEach((d) => {
|
|
505
|
+
if (d.property === "animation" || d.property === "animation-name") {
|
|
506
|
+
const animName = d.value.split(/\s+/)[0];
|
|
507
|
+
if (animName && !animName.startsWith("var(")) {
|
|
508
|
+
animations.add(animName);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
return {
|
|
513
|
+
...rule,
|
|
514
|
+
selectors,
|
|
515
|
+
declarations
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
function processKeyframesRule(rule, options, warnings) {
|
|
519
|
+
return {
|
|
520
|
+
...rule,
|
|
521
|
+
keyframes: rule.keyframes.map((kf) => ({
|
|
522
|
+
...kf,
|
|
523
|
+
declarations: kf.declarations.map((d) => processDeclaration(d, options, warnings))
|
|
524
|
+
}))
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function processDeclaration(decl, options, warnings) {
|
|
528
|
+
let { value } = decl;
|
|
529
|
+
if (options.rpxToRem) {
|
|
530
|
+
value = convertRpxToRem(value, options);
|
|
531
|
+
}
|
|
532
|
+
if (!value) {
|
|
533
|
+
warnings.push(`Empty value for property "${decl.property}"`);
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
...decl,
|
|
537
|
+
value
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function convertRpxToRem(value, options) {
|
|
541
|
+
const designWidth = options.designWidth ?? 750;
|
|
542
|
+
const baseFontSize = options.baseFontSize ?? 16;
|
|
543
|
+
return value.replace(/(\d+(?:\.\d+)?)\s*rpx/gi, (_, num) => {
|
|
544
|
+
const px = parseFloat(num) / designWidth * 375;
|
|
545
|
+
const rem = px / baseFontSize;
|
|
546
|
+
return `${rem.toFixed(6).replace(/\.?0+$/, "")}rem`;
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
function scopeSelector(selector, scopeId) {
|
|
550
|
+
const scopeAttr = `[data-v-${scopeId}]`;
|
|
551
|
+
return selector.split(/\s*([>+~])\s*/).map((part, i) => {
|
|
552
|
+
if (i % 2 === 1) return part;
|
|
553
|
+
if (/^(html|body|:root)$/i.test(part)) return part;
|
|
554
|
+
const pseudoMatch = part.match(/^(.+?)(::[\w-]+)$/);
|
|
555
|
+
if (pseudoMatch) {
|
|
556
|
+
return `${pseudoMatch[1]}${scopeAttr}${pseudoMatch[2]}`;
|
|
557
|
+
}
|
|
558
|
+
const pseudoClassMatch = part.match(/^(.+?)(:[\w-]+(?:\([^)]*\))?)$/);
|
|
559
|
+
if (pseudoClassMatch) {
|
|
560
|
+
return `${pseudoClassMatch[1]}${scopeAttr}${pseudoClassMatch[2]}`;
|
|
561
|
+
}
|
|
562
|
+
return `${part}${scopeAttr}`;
|
|
563
|
+
}).join(" ");
|
|
564
|
+
}
|
|
565
|
+
function addVendorPrefixes(declarations) {
|
|
566
|
+
const result = [];
|
|
567
|
+
for (const decl of declarations) {
|
|
568
|
+
const prefixes = PREFIXED_PROPERTIES[decl.property];
|
|
569
|
+
if (prefixes) {
|
|
570
|
+
for (const prefix of prefixes) {
|
|
571
|
+
result.push({
|
|
572
|
+
...decl,
|
|
573
|
+
property: prefix
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
result.push(decl);
|
|
578
|
+
}
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
function generateCSS(rules, options, _warnings) {
|
|
582
|
+
const minify = options.minify ?? false;
|
|
583
|
+
const indent = minify ? "" : " ";
|
|
584
|
+
const newline = minify ? "" : "\n";
|
|
585
|
+
const space = minify ? "" : " ";
|
|
586
|
+
const parts = [];
|
|
587
|
+
for (const rule of rules) {
|
|
588
|
+
parts.push(generateRule(rule, indent, newline, space));
|
|
589
|
+
}
|
|
590
|
+
return parts.join(minify ? "" : "\n\n");
|
|
591
|
+
}
|
|
592
|
+
function generateRule(rule, indent, newline, space) {
|
|
593
|
+
switch (rule.type) {
|
|
594
|
+
case "StyleRule":
|
|
595
|
+
return generateStyleRule(rule, indent, newline, space);
|
|
596
|
+
case "MediaRule":
|
|
597
|
+
return generateMediaRule(rule, indent, newline, space);
|
|
598
|
+
case "KeyframesRule":
|
|
599
|
+
return generateKeyframesRule(rule, indent, newline, space);
|
|
600
|
+
default:
|
|
601
|
+
return "";
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function generateStyleRule(rule, indent, newline, space, baseIndent = "") {
|
|
605
|
+
const selectors = rule.selectors.map((s) => s.value).join(`,${space}`);
|
|
606
|
+
const declarations = rule.declarations.map((d) => {
|
|
607
|
+
const important = d.important ? `${space}!important` : "";
|
|
608
|
+
return `${baseIndent}${indent}${d.property}:${space}${d.value}${important};`;
|
|
609
|
+
}).join(newline);
|
|
610
|
+
return `${baseIndent}${selectors}${space}{${newline}${declarations}${newline}${baseIndent}}`;
|
|
611
|
+
}
|
|
612
|
+
function generateMediaRule(rule, indent, newline, space) {
|
|
613
|
+
const rules = rule.rules.map((r) => generateStyleRule(r, indent, newline, space, indent)).join(newline + newline);
|
|
614
|
+
return `@media${space}${rule.query}${space}{${newline}${rules}${newline}}`;
|
|
615
|
+
}
|
|
616
|
+
function generateKeyframesRule(rule, indent, newline, space) {
|
|
617
|
+
const keyframes = rule.keyframes.map((kf) => {
|
|
618
|
+
const declarations = kf.declarations.map((d) => {
|
|
619
|
+
const important = d.important ? `${space}!important` : "";
|
|
620
|
+
return `${indent}${indent}${d.property}:${space}${d.value}${important};`;
|
|
621
|
+
}).join(newline);
|
|
622
|
+
return `${indent}${kf.selector}${space}{${newline}${declarations}${newline}${indent}}`;
|
|
623
|
+
}).join(newline);
|
|
624
|
+
const standard = `@keyframes${space}${rule.name}${space}{${newline}${keyframes}${newline}}`;
|
|
625
|
+
const webkit = `@-webkit-keyframes${space}${rule.name}${space}{${newline}${keyframes}${newline}}`;
|
|
626
|
+
return `${webkit}${newline}${standard}`;
|
|
627
|
+
}
|
|
628
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
629
|
+
0 && (module.exports = {
|
|
630
|
+
compileACSS,
|
|
631
|
+
parseACSS
|
|
632
|
+
});
|