@vigla/svelte 0.0.0-stage → 5.57.4
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/action.d.ts +2 -0
- package/animate.d.ts +2 -0
- package/compiler/index.js +43266 -0
- package/compiler/index.js.map +1 -0
- package/compiler/package.json +3 -0
- package/compiler.d.ts +2 -0
- package/dist/compiler/diagnostics.d.ts +70 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +166 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/index.d.ts +72 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +178 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/options.d.ts +7 -0
- package/dist/compiler/options.d.ts.map +1 -0
- package/dist/compiler/options.js +126 -0
- package/dist/compiler/options.js.map +1 -0
- package/dist/compiler/preprocess/decode.d.ts +3 -0
- package/dist/compiler/preprocess/decode.d.ts.map +1 -0
- package/dist/compiler/preprocess/decode.js +60 -0
- package/dist/compiler/preprocess/decode.js.map +1 -0
- package/dist/compiler/preprocess/index.d.ts +27 -0
- package/dist/compiler/preprocess/index.d.ts.map +1 -0
- package/dist/compiler/preprocess/index.js +208 -0
- package/dist/compiler/preprocess/index.js.map +1 -0
- package/dist/compiler/preprocess/mapped.d.ts +25 -0
- package/dist/compiler/preprocess/mapped.d.ts.map +1 -0
- package/dist/compiler/preprocess/mapped.js +129 -0
- package/dist/compiler/preprocess/mapped.js.map +1 -0
- package/dist/compiler/proxy.d.ts +3 -0
- package/dist/compiler/proxy.d.ts.map +1 -0
- package/dist/compiler/proxy.js +133 -0
- package/dist/compiler/proxy.js.map +1 -0
- package/dist/entries/action.d.ts +2 -0
- package/dist/entries/action.d.ts.map +1 -0
- package/dist/entries/action.js +1 -0
- package/dist/entries/action.js.map +1 -0
- package/dist/entries/animate.d.ts +2 -0
- package/dist/entries/animate.d.ts.map +1 -0
- package/dist/entries/animate.js +2 -0
- package/dist/entries/animate.js.map +1 -0
- package/dist/entries/attachments.d.ts +2 -0
- package/dist/entries/attachments.d.ts.map +1 -0
- package/dist/entries/attachments.js +2 -0
- package/dist/entries/attachments.js.map +1 -0
- package/dist/entries/context.d.ts +15 -0
- package/dist/entries/context.d.ts.map +1 -0
- package/dist/entries/context.js +32 -0
- package/dist/entries/context.js.map +1 -0
- package/dist/entries/easing.d.ts +2 -0
- package/dist/entries/easing.d.ts.map +1 -0
- package/dist/entries/easing.js +2 -0
- package/dist/entries/easing.js.map +1 -0
- package/dist/entries/events.d.ts +2 -0
- package/dist/entries/events.d.ts.map +1 -0
- package/dist/entries/events.js +2 -0
- package/dist/entries/events.js.map +1 -0
- package/dist/entries/index-server.d.ts +4 -0
- package/dist/entries/index-server.d.ts.map +1 -0
- package/dist/entries/index-server.js +11 -0
- package/dist/entries/index-server.js.map +1 -0
- package/dist/entries/index.d.ts +10 -0
- package/dist/entries/index.d.ts.map +1 -0
- package/dist/entries/index.js +24 -0
- package/dist/entries/index.js.map +1 -0
- package/dist/entries/internal/client.d.ts +4 -0
- package/dist/entries/internal/client.d.ts.map +1 -0
- package/dist/entries/internal/client.js +9 -0
- package/dist/entries/internal/client.js.map +1 -0
- package/dist/entries/internal/disclose-version.d.ts +2 -0
- package/dist/entries/internal/disclose-version.d.ts.map +1 -0
- package/dist/entries/internal/disclose-version.js +4 -0
- package/dist/entries/internal/disclose-version.js.map +1 -0
- package/dist/entries/internal/index.d.ts +2 -0
- package/dist/entries/internal/index.d.ts.map +1 -0
- package/dist/entries/internal/index.js +2 -0
- package/dist/entries/internal/index.js.map +1 -0
- package/dist/entries/internal/server.d.ts +2 -0
- package/dist/entries/internal/server.d.ts.map +1 -0
- package/dist/entries/internal/server.js +7 -0
- package/dist/entries/internal/server.js.map +1 -0
- package/dist/entries/internal/tracing.d.ts +2 -0
- package/dist/entries/internal/tracing.d.ts.map +1 -0
- package/dist/entries/internal/tracing.js +2 -0
- package/dist/entries/internal/tracing.js.map +1 -0
- package/dist/entries/motion-server.d.ts +2 -0
- package/dist/entries/motion-server.d.ts.map +1 -0
- package/dist/entries/motion-server.js +2 -0
- package/dist/entries/motion-server.js.map +1 -0
- package/dist/entries/motion.d.ts +2 -0
- package/dist/entries/motion.d.ts.map +1 -0
- package/dist/entries/motion.js +2 -0
- package/dist/entries/motion.js.map +1 -0
- package/dist/entries/proxy.d.ts +6 -0
- package/dist/entries/proxy.d.ts.map +1 -0
- package/dist/entries/proxy.js +77 -0
- package/dist/entries/proxy.js.map +1 -0
- package/dist/entries/reactivity-server.d.ts +2 -0
- package/dist/entries/reactivity-server.d.ts.map +1 -0
- package/dist/entries/reactivity-server.js +2 -0
- package/dist/entries/reactivity-server.js.map +1 -0
- package/dist/entries/reactivity.d.ts +2 -0
- package/dist/entries/reactivity.d.ts.map +1 -0
- package/dist/entries/reactivity.js +2 -0
- package/dist/entries/reactivity.js.map +1 -0
- package/dist/entries/report.d.ts +3 -0
- package/dist/entries/report.d.ts.map +1 -0
- package/dist/entries/report.js +66 -0
- package/dist/entries/report.js.map +1 -0
- package/dist/entries/server.d.ts +8 -0
- package/dist/entries/server.d.ts.map +1 -0
- package/dist/entries/server.js +48 -0
- package/dist/entries/server.js.map +1 -0
- package/dist/entries/store-client.d.ts +12 -0
- package/dist/entries/store-client.d.ts.map +1 -0
- package/dist/entries/store-client.js +63 -0
- package/dist/entries/store-client.js.map +1 -0
- package/dist/entries/store-server.d.ts +12 -0
- package/dist/entries/store-server.d.ts.map +1 -0
- package/dist/entries/store-server.js +30 -0
- package/dist/entries/store-server.js.map +1 -0
- package/dist/entries/store.d.ts +25 -0
- package/dist/entries/store.d.ts.map +1 -0
- package/dist/entries/store.js +139 -0
- package/dist/entries/store.js.map +1 -0
- package/dist/entries/transition.d.ts +2 -0
- package/dist/entries/transition.d.ts.map +1 -0
- package/dist/entries/transition.js +2 -0
- package/dist/entries/transition.js.map +1 -0
- package/dist/entries/window-server.d.ts +2 -0
- package/dist/entries/window-server.d.ts.map +1 -0
- package/dist/entries/window-server.js +2 -0
- package/dist/entries/window-server.js.map +1 -0
- package/dist/entries/window.d.ts +2 -0
- package/dist/entries/window.d.ts.map +1 -0
- package/dist/entries/window.js +2 -0
- package/dist/entries/window.js.map +1 -0
- package/dist/front/ast.d.ts +290 -0
- package/dist/front/ast.d.ts.map +1 -0
- package/dist/front/ast.js +1 -0
- package/dist/front/ast.js.map +1 -0
- package/dist/front/diagnostics.d.ts +13 -0
- package/dist/front/diagnostics.d.ts.map +1 -0
- package/dist/front/diagnostics.js +38 -0
- package/dist/front/diagnostics.js.map +1 -0
- package/dist/front/ignores.d.ts +12 -0
- package/dist/front/ignores.d.ts.map +1 -0
- package/dist/front/ignores.js +75 -0
- package/dist/front/ignores.js.map +1 -0
- package/dist/front/index.d.ts +17 -0
- package/dist/front/index.d.ts.map +1 -0
- package/dist/front/index.js +65 -0
- package/dist/front/index.js.map +1 -0
- package/dist/front/legacy.d.ts +5 -0
- package/dist/front/legacy.d.ts.map +1 -0
- package/dist/front/legacy.js +408 -0
- package/dist/front/legacy.js.map +1 -0
- package/dist/front/locate.d.ts +4 -0
- package/dist/front/locate.d.ts.map +1 -0
- package/dist/front/locate.js +19 -0
- package/dist/front/locate.js.map +1 -0
- package/dist/front/lower.d.ts +39 -0
- package/dist/front/lower.d.ts.map +1 -0
- package/dist/front/lower.js +470 -0
- package/dist/front/lower.js.map +1 -0
- package/dist/front/parse/attribute.d.ts +12 -0
- package/dist/front/parse/attribute.d.ts.map +1 -0
- package/dist/front/parse/attribute.js +288 -0
- package/dist/front/parse/attribute.js.map +1 -0
- package/dist/front/parse/bracket.d.ts +3 -0
- package/dist/front/parse/bracket.d.ts.map +1 -0
- package/dist/front/parse/bracket.js +102 -0
- package/dist/front/parse/bracket.js.map +1 -0
- package/dist/front/parse/characters.d.ts +4 -0
- package/dist/front/parse/characters.d.ts.map +1 -0
- package/dist/front/parse/characters.js +6 -0
- package/dist/front/parse/characters.js.map +1 -0
- package/dist/front/parse/decode.d.ts +2 -0
- package/dist/front/parse/decode.d.ts.map +1 -0
- package/dist/front/parse/decode.js +89 -0
- package/dist/front/parse/decode.js.map +1 -0
- package/dist/front/parse/element.d.ts +3 -0
- package/dist/front/parse/element.d.ts.map +1 -0
- package/dist/front/parse/element.js +311 -0
- package/dist/front/parse/element.js.map +1 -0
- package/dist/front/parse/entities.d.ts +2 -0
- package/dist/front/parse/entities.d.ts.map +1 -0
- package/dist/front/parse/entities.js +2234 -0
- package/dist/front/parse/entities.js.map +1 -0
- package/dist/front/parse/expression.d.ts +5 -0
- package/dist/front/parse/expression.d.ts.map +1 -0
- package/dist/front/parse/expression.js +86 -0
- package/dist/front/parse/expression.js.map +1 -0
- package/dist/front/parse/html.d.ts +8 -0
- package/dist/front/parse/html.d.ts.map +1 -0
- package/dist/front/parse/html.js +146 -0
- package/dist/front/parse/html.js.map +1 -0
- package/dist/front/parse/identifier.d.ts +4 -0
- package/dist/front/parse/identifier.d.ts.map +1 -0
- package/dist/front/parse/identifier.js +24 -0
- package/dist/front/parse/identifier.js.map +1 -0
- package/dist/front/parse/index.d.ts +13 -0
- package/dist/front/parse/index.d.ts.map +1 -0
- package/dist/front/parse/index.js +74 -0
- package/dist/front/parse/index.js.map +1 -0
- package/dist/front/parse/js.d.ts +27 -0
- package/dist/front/parse/js.d.ts.map +1 -0
- package/dist/front/parse/js.js +241 -0
- package/dist/front/parse/js.js.map +1 -0
- package/dist/front/parse/options.d.ts +3 -0
- package/dist/front/parse/options.d.ts.map +1 -0
- package/dist/front/parse/options.js +198 -0
- package/dist/front/parse/options.js.map +1 -0
- package/dist/front/parse/parser.d.ts +50 -0
- package/dist/front/parse/parser.d.ts.map +1 -0
- package/dist/front/parse/parser.js +157 -0
- package/dist/front/parse/parser.js.map +1 -0
- package/dist/front/parse/pattern.d.ts +4 -0
- package/dist/front/parse/pattern.d.ts.map +1 -0
- package/dist/front/parse/pattern.js +53 -0
- package/dist/front/parse/pattern.js.map +1 -0
- package/dist/front/parse/script.d.ts +4 -0
- package/dist/front/parse/script.d.ts.map +1 -0
- package/dist/front/parse/script.js +60 -0
- package/dist/front/parse/script.js.map +1 -0
- package/dist/front/parse/style.d.ts +7 -0
- package/dist/front/parse/style.d.ts.map +1 -0
- package/dist/front/parse/style.js +397 -0
- package/dist/front/parse/style.js.map +1 -0
- package/dist/front/parse/tag.d.ts +3 -0
- package/dist/front/parse/tag.d.ts.map +1 -0
- package/dist/front/parse/tag.js +591 -0
- package/dist/front/parse/tag.js.map +1 -0
- package/dist/front/print/css.d.ts +5 -0
- package/dist/front/print/css.d.ts.map +1 -0
- package/dist/front/print/css.js +234 -0
- package/dist/front/print/css.js.map +1 -0
- package/dist/front/print/index.d.ts +18 -0
- package/dist/front/print/index.d.ts.map +1 -0
- package/dist/front/print/index.js +24 -0
- package/dist/front/print/index.js.map +1 -0
- package/dist/front/print/layout.d.ts +11 -0
- package/dist/front/print/layout.d.ts.map +1 -0
- package/dist/front/print/layout.js +73 -0
- package/dist/front/print/layout.js.map +1 -0
- package/dist/front/print/template.d.ts +5 -0
- package/dist/front/print/template.d.ts.map +1 -0
- package/dist/front/print/template.js +455 -0
- package/dist/front/print/template.js.map +1 -0
- package/dist/front/runes.d.ts +13 -0
- package/dist/front/runes.d.ts.map +1 -0
- package/dist/front/runes.js +253 -0
- package/dist/front/runes.js.map +1 -0
- package/dist/front/stores.d.ts +5 -0
- package/dist/front/stores.d.ts.map +1 -0
- package/dist/front/stores.js +84 -0
- package/dist/front/stores.js.map +1 -0
- package/dist/front/typescript.d.ts +2 -0
- package/dist/front/typescript.d.ts.map +1 -0
- package/dist/front/typescript.js +182 -0
- package/dist/front/typescript.js.map +1 -0
- package/dist/front/validate/anchors.d.ts +15 -0
- package/dist/front/validate/anchors.d.ts.map +1 -0
- package/dist/front/validate/anchors.js +43 -0
- package/dist/front/validate/anchors.js.map +1 -0
- package/dist/front/validate/index.d.ts +16 -0
- package/dist/front/validate/index.d.ts.map +1 -0
- package/dist/front/validate/index.js +139 -0
- package/dist/front/validate/index.js.map +1 -0
- package/dist/front/validate/legacy.d.ts +9 -0
- package/dist/front/validate/legacy.d.ts.map +1 -0
- package/dist/front/validate/legacy.js +102 -0
- package/dist/front/validate/legacy.js.map +1 -0
- package/dist/front/validate/report.d.ts +14 -0
- package/dist/front/validate/report.d.ts.map +1 -0
- package/dist/front/validate/report.js +29 -0
- package/dist/front/validate/report.js.map +1 -0
- package/dist/front/validate/template.d.ts +31 -0
- package/dist/front/validate/template.d.ts.map +1 -0
- package/dist/front/validate/template.js +507 -0
- package/dist/front/validate/template.js.map +1 -0
- package/dist/front/wording.d.ts +4 -0
- package/dist/front/wording.d.ts.map +1 -0
- package/dist/front/wording.js +110 -0
- package/dist/front/wording.js.map +1 -0
- package/dist/shared/format.d.ts +3 -0
- package/dist/shared/format.d.ts.map +1 -0
- package/dist/shared/format.js +7 -0
- package/dist/shared/format.js.map +1 -0
- package/easing.d.ts +2 -0
- package/elements.d.ts +1220 -0
- package/index.d.ts +2 -0
- package/motion.d.ts +2 -0
- package/package.json +128 -5
- package/src/compiler/diagnostics.ts +233 -0
- package/src/compiler/index.ts +292 -0
- package/src/compiler/options.ts +140 -0
- package/src/compiler/preprocess/decode.ts +85 -0
- package/src/compiler/preprocess/index.ts +299 -0
- package/src/compiler/preprocess/mapped.ts +146 -0
- package/src/compiler/proxy.ts +154 -0
- package/src/entries/action.ts +1 -0
- package/src/entries/animate.ts +1 -0
- package/src/entries/attachments.ts +1 -0
- package/src/entries/context.ts +50 -0
- package/src/entries/easing.ts +1 -0
- package/src/entries/events.ts +1 -0
- package/src/entries/index-server.ts +17 -0
- package/src/entries/index.ts +41 -0
- package/src/entries/internal/client.ts +15 -0
- package/src/entries/internal/disclose-version.ts +4 -0
- package/src/entries/internal/index.ts +3 -0
- package/src/entries/internal/server.ts +8 -0
- package/src/entries/internal/tracing.ts +1 -0
- package/src/entries/motion-server.ts +1 -0
- package/src/entries/motion.ts +1 -0
- package/src/entries/proxy.ts +86 -0
- package/src/entries/reactivity-server.ts +9 -0
- package/src/entries/reactivity.ts +9 -0
- package/src/entries/report.ts +81 -0
- package/src/entries/server.ts +76 -0
- package/src/entries/store-client.ts +80 -0
- package/src/entries/store-server.ts +44 -0
- package/src/entries/store.ts +201 -0
- package/src/entries/transition.ts +1 -0
- package/src/entries/window-server.ts +1 -0
- package/src/entries/window.ts +1 -0
- package/src/front/ast.ts +369 -0
- package/src/front/diagnostics.ts +53 -0
- package/src/front/ignores.ts +84 -0
- package/src/front/index.ts +86 -0
- package/src/front/legacy.ts +414 -0
- package/src/front/locate.ts +20 -0
- package/src/front/lower.ts +509 -0
- package/src/front/parse/attribute.ts +319 -0
- package/src/front/parse/bracket.ts +99 -0
- package/src/front/parse/characters.ts +19 -0
- package/src/front/parse/decode.ts +87 -0
- package/src/front/parse/element.ts +354 -0
- package/src/front/parse/entities.ts +2233 -0
- package/src/front/parse/expression.ts +85 -0
- package/src/front/parse/html.ts +158 -0
- package/src/front/parse/identifier.ts +29 -0
- package/src/front/parse/index.ts +88 -0
- package/src/front/parse/js.ts +284 -0
- package/src/front/parse/options.ts +194 -0
- package/src/front/parse/parser.ts +189 -0
- package/src/front/parse/pattern.ts +57 -0
- package/src/front/parse/script.ts +74 -0
- package/src/front/parse/style.ts +399 -0
- package/src/front/parse/tag.ts +601 -0
- package/src/front/print/css.ts +239 -0
- package/src/front/print/index.ts +40 -0
- package/src/front/print/layout.ts +87 -0
- package/src/front/print/template.ts +448 -0
- package/src/front/runes.ts +267 -0
- package/src/front/stores.ts +98 -0
- package/src/front/typescript.ts +178 -0
- package/src/front/validate/anchors.ts +54 -0
- package/src/front/validate/index.ts +174 -0
- package/src/front/validate/legacy.ts +119 -0
- package/src/front/validate/report.ts +38 -0
- package/src/front/validate/template.ts +549 -0
- package/src/front/wording.ts +112 -0
- package/src/shared/format.ts +8 -0
- package/store.d.ts +2 -0
- package/svelte-html.d.ts +53 -0
- package/transition.d.ts +2 -0
- package/types/compiler/interfaces.d.ts +2 -0
- package/types/compiler/preprocess.d.ts +2 -0
- package/types/index.d.ts +1453 -0
- package/README.md +0 -3
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import type { Context, Visitors } from 'esrap';
|
|
2
|
+
import type * as AST from '../ast.ts';
|
|
3
|
+
import { attributes } from './layout.ts';
|
|
4
|
+
|
|
5
|
+
type Item = AST.Css.Rule | AST.Css.Atrule | AST.Css.Declaration;
|
|
6
|
+
|
|
7
|
+
const identifierChar = /^[a-zA-Z0-9_-]$/;
|
|
8
|
+
const hexDigit = /[0-9a-fA-F]/;
|
|
9
|
+
|
|
10
|
+
function isDigit(char: string): boolean {
|
|
11
|
+
return char >= '0' && char <= '9';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function escapeIdentifier(name: string): string {
|
|
15
|
+
let escaped = '';
|
|
16
|
+
let index = 0;
|
|
17
|
+
while (index < name.length) {
|
|
18
|
+
const char = name[index] as string;
|
|
19
|
+
if (char === '\\') {
|
|
20
|
+
const next = name.charAt(index + 1);
|
|
21
|
+
if (next === '' || hexDigit.test(next)) {
|
|
22
|
+
escaped += '\\5c ';
|
|
23
|
+
index += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
escaped += `\\${next}`;
|
|
27
|
+
index += 2;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const code = char.codePointAt(0) as number;
|
|
31
|
+
const leadingDigit = index === 0 && isDigit(char);
|
|
32
|
+
const leadingHyphenDigit = index === 0 && char === '-' && isDigit(name.charAt(index + 1));
|
|
33
|
+
if (leadingDigit || leadingHyphenDigit || !(identifierChar.test(char) || code >= 160)) {
|
|
34
|
+
escaped += `\\${code.toString(16)} `;
|
|
35
|
+
} else {
|
|
36
|
+
escaped += char;
|
|
37
|
+
}
|
|
38
|
+
index += 1;
|
|
39
|
+
}
|
|
40
|
+
return escaped;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function cssVisitors(
|
|
44
|
+
comments: readonly AST.Css.Comment[],
|
|
45
|
+
scriptComments: readonly AST.JSComment[]
|
|
46
|
+
): Visitors {
|
|
47
|
+
let next = 0;
|
|
48
|
+
const before = (end: number): boolean => {
|
|
49
|
+
const comment = comments[next];
|
|
50
|
+
return comment !== undefined && comment.start < end;
|
|
51
|
+
};
|
|
52
|
+
const writeComment = (context: Context, comment: AST.Css.Comment): void => {
|
|
53
|
+
context.write(`/*${comment.value}*/`);
|
|
54
|
+
};
|
|
55
|
+
const inline = (context: Context, end: number): boolean => {
|
|
56
|
+
let written = false;
|
|
57
|
+
while (before(end)) {
|
|
58
|
+
if (written) context.write(' ');
|
|
59
|
+
writeComment(context, comments[next++] as AST.Css.Comment);
|
|
60
|
+
written = true;
|
|
61
|
+
}
|
|
62
|
+
return written;
|
|
63
|
+
};
|
|
64
|
+
const value = (context: Context, text: string, end: number): void => {
|
|
65
|
+
let offset = 0;
|
|
66
|
+
while (before(end)) {
|
|
67
|
+
const comment = comments[next++] as AST.Css.Comment;
|
|
68
|
+
const position = Math.max(offset, Math.min(comment.position ?? 0, text.length));
|
|
69
|
+
context.write(text.slice(offset, position));
|
|
70
|
+
writeComment(context, comment);
|
|
71
|
+
offset = position;
|
|
72
|
+
}
|
|
73
|
+
context.write(text.slice(offset));
|
|
74
|
+
};
|
|
75
|
+
const children = (
|
|
76
|
+
context: Context,
|
|
77
|
+
items: readonly Item[],
|
|
78
|
+
end: number,
|
|
79
|
+
margins: boolean
|
|
80
|
+
): void => {
|
|
81
|
+
let started = false;
|
|
82
|
+
const separate = (): void => {
|
|
83
|
+
if (!started) return;
|
|
84
|
+
if (margins) context.margin();
|
|
85
|
+
context.newline();
|
|
86
|
+
};
|
|
87
|
+
for (const child of items) {
|
|
88
|
+
while (before(child.start)) {
|
|
89
|
+
separate();
|
|
90
|
+
writeComment(context, comments[next++] as AST.Css.Comment);
|
|
91
|
+
started = true;
|
|
92
|
+
}
|
|
93
|
+
separate();
|
|
94
|
+
context.visit(child);
|
|
95
|
+
started = true;
|
|
96
|
+
}
|
|
97
|
+
while (before(end)) {
|
|
98
|
+
separate();
|
|
99
|
+
writeComment(context, comments[next++] as AST.Css.Comment);
|
|
100
|
+
started = true;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const selectors = (node: AST.Css.SelectorList, context: Context, multiline: boolean): void => {
|
|
104
|
+
let separated = false;
|
|
105
|
+
let remaining = node.children.length;
|
|
106
|
+
for (const selector of node.children) {
|
|
107
|
+
while (before(selector.start)) {
|
|
108
|
+
if (separated) context.write(' ');
|
|
109
|
+
writeComment(context, comments[next++] as AST.Css.Comment);
|
|
110
|
+
separated = true;
|
|
111
|
+
}
|
|
112
|
+
if (separated) {
|
|
113
|
+
if (multiline) context.newline();
|
|
114
|
+
else context.write(' ');
|
|
115
|
+
}
|
|
116
|
+
context.visit(selector);
|
|
117
|
+
separated = true;
|
|
118
|
+
remaining -= 1;
|
|
119
|
+
if (remaining > 0) context.write(',');
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const args = (
|
|
123
|
+
node: AST.Css.PseudoClassSelector | AST.Css.PseudoElementSelector,
|
|
124
|
+
context: Context
|
|
125
|
+
): void => {
|
|
126
|
+
if (!node.args) return;
|
|
127
|
+
context.write('(');
|
|
128
|
+
context.visit(node.args);
|
|
129
|
+
if (before(node.end)) {
|
|
130
|
+
context.write(' ');
|
|
131
|
+
inline(context, node.end);
|
|
132
|
+
}
|
|
133
|
+
context.write(')');
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const visitors: Record<string, (node: never, context: Context) => void> = {
|
|
137
|
+
Atrule(node: AST.Css.Atrule, context: Context) {
|
|
138
|
+
context.write(`@${escapeIdentifier(node.name)}`);
|
|
139
|
+
const preludeEnd = node.block?.start ?? node.end;
|
|
140
|
+
if (node.prelude || before(preludeEnd)) {
|
|
141
|
+
context.write(' ');
|
|
142
|
+
value(context, node.prelude, preludeEnd);
|
|
143
|
+
}
|
|
144
|
+
if (node.block) {
|
|
145
|
+
context.write(' ');
|
|
146
|
+
context.visit(node.block);
|
|
147
|
+
} else {
|
|
148
|
+
context.write(';');
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
AttributeSelector(node: AST.Css.AttributeSelector, context: Context) {
|
|
152
|
+
context.write(`[${escapeIdentifier(node.name)}`);
|
|
153
|
+
if (node.matcher) {
|
|
154
|
+
context.write(node.matcher);
|
|
155
|
+
context.write(`"${node.value}"`);
|
|
156
|
+
if (node.flags) context.write(` ${node.flags}`);
|
|
157
|
+
}
|
|
158
|
+
context.write(']');
|
|
159
|
+
},
|
|
160
|
+
Block(node: AST.Css.Block, context: Context) {
|
|
161
|
+
context.write('{');
|
|
162
|
+
if (node.children.length > 0 || before(node.end)) {
|
|
163
|
+
context.indent();
|
|
164
|
+
context.newline();
|
|
165
|
+
children(context, node.children, node.end, false);
|
|
166
|
+
context.dedent();
|
|
167
|
+
context.newline();
|
|
168
|
+
}
|
|
169
|
+
context.write('}');
|
|
170
|
+
},
|
|
171
|
+
ClassSelector(node: AST.Css.ClassSelector, context: Context) {
|
|
172
|
+
context.write(`.${escapeIdentifier(node.name)}`);
|
|
173
|
+
},
|
|
174
|
+
ComplexSelector(node: AST.Css.ComplexSelector, context: Context) {
|
|
175
|
+
for (const selector of node.children) context.visit(selector);
|
|
176
|
+
},
|
|
177
|
+
Declaration(node: AST.Css.Declaration, context: Context) {
|
|
178
|
+
context.write(`${node.property}: `);
|
|
179
|
+
value(context, node.value, node.end);
|
|
180
|
+
context.write(';');
|
|
181
|
+
},
|
|
182
|
+
IdSelector(node: AST.Css.IdSelector, context: Context) {
|
|
183
|
+
context.write(`#${escapeIdentifier(node.name)}`);
|
|
184
|
+
},
|
|
185
|
+
NestingSelector(_: AST.Css.NestingSelector, context: Context) {
|
|
186
|
+
context.write('&');
|
|
187
|
+
},
|
|
188
|
+
Nth(node: AST.Css.Nth, context: Context) {
|
|
189
|
+
context.write(node.value);
|
|
190
|
+
},
|
|
191
|
+
Percentage(node: AST.Css.Percentage, context: Context) {
|
|
192
|
+
context.write(node.value);
|
|
193
|
+
},
|
|
194
|
+
PseudoClassSelector(node: AST.Css.PseudoClassSelector, context: Context) {
|
|
195
|
+
context.write(`:${escapeIdentifier(node.name)}`);
|
|
196
|
+
args(node, context);
|
|
197
|
+
},
|
|
198
|
+
PseudoElementSelector(node: AST.Css.PseudoElementSelector, context: Context) {
|
|
199
|
+
context.write(`::${escapeIdentifier(node.name)}`);
|
|
200
|
+
args(node, context);
|
|
201
|
+
},
|
|
202
|
+
RelativeSelector(node: AST.Css.RelativeSelector, context: Context) {
|
|
203
|
+
if (node.combinator) {
|
|
204
|
+
context.write(node.combinator.name === ' ' ? ' ' : ` ${node.combinator.name} `);
|
|
205
|
+
}
|
|
206
|
+
for (const selector of node.selectors) context.visit(selector);
|
|
207
|
+
},
|
|
208
|
+
Rule(node: AST.Css.Rule, context: Context) {
|
|
209
|
+
selectors(node.prelude, context, true);
|
|
210
|
+
context.write(' ');
|
|
211
|
+
if (inline(context, node.block.start)) context.write(' ');
|
|
212
|
+
context.visit(node.block);
|
|
213
|
+
},
|
|
214
|
+
SelectorList(node: AST.Css.SelectorList, context: Context) {
|
|
215
|
+
selectors(node, context, false);
|
|
216
|
+
},
|
|
217
|
+
StyleSheet(node: AST.Css.StyleSheet, context: Context) {
|
|
218
|
+
context.write('<style');
|
|
219
|
+
attributes(node, node.attributes, context, scriptComments);
|
|
220
|
+
context.write('>');
|
|
221
|
+
if (node.children.length > 0 || node.comments.length > 0) {
|
|
222
|
+
context.indent();
|
|
223
|
+
context.newline();
|
|
224
|
+
children(context, node.children, node.content.end, true);
|
|
225
|
+
context.dedent();
|
|
226
|
+
context.newline();
|
|
227
|
+
}
|
|
228
|
+
context.write('</style>');
|
|
229
|
+
},
|
|
230
|
+
TypeSelector(node: AST.Css.TypeSelector, context: Context) {
|
|
231
|
+
if (node.namespace !== undefined) {
|
|
232
|
+
context.write(node.namespace === '*' ? '*' : escapeIdentifier(node.namespace));
|
|
233
|
+
context.write('|');
|
|
234
|
+
}
|
|
235
|
+
context.write(node.name === '*' ? node.name : escapeIdentifier(node.name));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
return visitors as unknown as Visitors;
|
|
239
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { print as render, type Visitors } from 'esrap';
|
|
2
|
+
import ts from 'esrap/languages/ts';
|
|
3
|
+
import type * as AST from '../ast.ts';
|
|
4
|
+
import { cssVisitors } from './css.ts';
|
|
5
|
+
import type { State } from './layout.ts';
|
|
6
|
+
import { templateVisitors } from './template.ts';
|
|
7
|
+
|
|
8
|
+
export interface PrintOptions {
|
|
9
|
+
indent?: string;
|
|
10
|
+
getLeadingComments?: (node: unknown) => unknown[] | undefined;
|
|
11
|
+
getTrailingComments?: (node: unknown) => unknown[] | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Printed {
|
|
15
|
+
code: string;
|
|
16
|
+
map: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Printable = { type: string; comments?: AST.JSComment[]; css?: AST.Css.StyleSheet | null };
|
|
20
|
+
|
|
21
|
+
export function print(ast: Printable, options?: PrintOptions): Printed {
|
|
22
|
+
const comments = (ast.type === 'Root' && ast.comments) || [];
|
|
23
|
+
const css =
|
|
24
|
+
(ast.type === 'Root'
|
|
25
|
+
? ast.css?.comments
|
|
26
|
+
: ast.type === 'StyleSheet'
|
|
27
|
+
? (ast as unknown as AST.Css.StyleSheet).comments
|
|
28
|
+
: null) ?? [];
|
|
29
|
+
const state: State = { preserve: 0 };
|
|
30
|
+
const visitors = {
|
|
31
|
+
...ts({
|
|
32
|
+
comments,
|
|
33
|
+
getLeadingComments: options?.getLeadingComments,
|
|
34
|
+
getTrailingComments: options?.getTrailingComments
|
|
35
|
+
} as Parameters<typeof ts>[0]),
|
|
36
|
+
...templateVisitors(comments, state),
|
|
37
|
+
...cssVisitors(css, comments)
|
|
38
|
+
} as Visitors;
|
|
39
|
+
return render(ast, visitors, { indent: options?.indent });
|
|
40
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Context } from 'esrap';
|
|
2
|
+
import type * as AST from '../ast.ts';
|
|
3
|
+
|
|
4
|
+
export const lineBreak = 50;
|
|
5
|
+
|
|
6
|
+
export interface State {
|
|
7
|
+
preserve: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function block(
|
|
11
|
+
context: Context,
|
|
12
|
+
node: { type: string },
|
|
13
|
+
preserve = false,
|
|
14
|
+
inline = false
|
|
15
|
+
): void {
|
|
16
|
+
if (preserve) {
|
|
17
|
+
context.visit(node);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const child = context.new();
|
|
21
|
+
child.visit(node);
|
|
22
|
+
if (child.empty()) return;
|
|
23
|
+
if (inline && !child.multiline) {
|
|
24
|
+
context.append(child);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
context.indent();
|
|
28
|
+
context.newline();
|
|
29
|
+
context.append(child);
|
|
30
|
+
context.dedent();
|
|
31
|
+
context.newline();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function attributes(
|
|
35
|
+
node: AST.Located,
|
|
36
|
+
list: readonly AST.AttributeLike[],
|
|
37
|
+
context: Context,
|
|
38
|
+
comments: readonly AST.JSComment[]
|
|
39
|
+
): boolean {
|
|
40
|
+
if (list.length === 0) return false;
|
|
41
|
+
let length = -1;
|
|
42
|
+
let index = comments.findIndex((comment) => comment.start > node.start);
|
|
43
|
+
if (index === -1) index = comments.length;
|
|
44
|
+
const separator = context.new();
|
|
45
|
+
let previousEnd = node.start;
|
|
46
|
+
|
|
47
|
+
const children = list.map((attribute) => {
|
|
48
|
+
const child = context.new();
|
|
49
|
+
while (index < comments.length) {
|
|
50
|
+
const comment = comments[index] as AST.JSComment;
|
|
51
|
+
if (comment.start >= attribute.start) break;
|
|
52
|
+
if (comment.start >= previousEnd) {
|
|
53
|
+
if (comment.type === 'Line') {
|
|
54
|
+
child.write(`//${comment.value}`);
|
|
55
|
+
child.newline();
|
|
56
|
+
} else {
|
|
57
|
+
child.write(`/*${comment.value}*/`);
|
|
58
|
+
child.append(separator);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
index += 1;
|
|
62
|
+
}
|
|
63
|
+
child.visit(attribute);
|
|
64
|
+
previousEnd = attribute.end;
|
|
65
|
+
length += child.measure() + 1;
|
|
66
|
+
return child;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const multiline = context.multiline || length > lineBreak;
|
|
70
|
+
if (multiline) {
|
|
71
|
+
separator.newline();
|
|
72
|
+
context.indent();
|
|
73
|
+
for (const child of children) {
|
|
74
|
+
context.newline();
|
|
75
|
+
context.append(child);
|
|
76
|
+
}
|
|
77
|
+
context.dedent();
|
|
78
|
+
context.newline();
|
|
79
|
+
} else {
|
|
80
|
+
separator.write(' ');
|
|
81
|
+
for (const child of children) {
|
|
82
|
+
context.write(' ');
|
|
83
|
+
context.append(child);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return multiline;
|
|
87
|
+
}
|