@yannosay/sinth 4.1.0 → 5.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/DOCS.md +1359 -0
  3. package/README.md +83 -74
  4. package/bin/sinth.js +2 -1
  5. package/dist/cli/args.d.ts +11 -0
  6. package/dist/cli/args.js +74 -0
  7. package/dist/cli/index.d.ts +1 -0
  8. package/dist/cli/index.js +437 -0
  9. package/dist/cli/templates.d.ts +10 -0
  10. package/dist/cli/templates.js +193 -0
  11. package/dist/cli/ui.d.ts +28 -0
  12. package/dist/cli/ui.js +61 -0
  13. package/dist/cli/update-check.d.ts +2 -0
  14. package/dist/cli/update-check.js +124 -0
  15. package/dist/compiler/ast.d.ts +315 -0
  16. package/dist/compiler/ast.js +4 -0
  17. package/dist/compiler/codegen.d.ts +143 -0
  18. package/dist/compiler/codegen.js +1326 -0
  19. package/dist/compiler/diagnostics.d.ts +36 -0
  20. package/dist/compiler/diagnostics.js +142 -0
  21. package/dist/compiler/elements.d.ts +14 -0
  22. package/dist/compiler/elements.js +78 -0
  23. package/dist/compiler/globals.d.ts +2 -0
  24. package/dist/compiler/globals.js +27 -0
  25. package/dist/compiler/html.d.ts +37 -0
  26. package/dist/compiler/html.js +152 -0
  27. package/dist/compiler/lexer.d.ts +42 -0
  28. package/dist/compiler/lexer.js +404 -0
  29. package/dist/compiler/parser.d.ts +95 -0
  30. package/dist/compiler/parser.js +1374 -0
  31. package/dist/compiler/prerender.d.ts +72 -0
  32. package/dist/compiler/prerender.js +910 -0
  33. package/dist/compiler/script-analysis.d.ts +6 -0
  34. package/dist/compiler/script-analysis.js +106 -0
  35. package/dist/compiler/style.d.ts +39 -0
  36. package/dist/compiler/style.js +463 -0
  37. package/dist/deploy/cloudflare.d.ts +9 -0
  38. package/dist/deploy/cloudflare.js +111 -0
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.js +23 -0
  41. package/dist/project/build.d.ts +31 -0
  42. package/dist/project/build.js +425 -0
  43. package/dist/project/config.d.ts +33 -0
  44. package/dist/project/config.js +142 -0
  45. package/dist/project/project.d.ts +74 -0
  46. package/dist/project/project.js +535 -0
  47. package/dist/runtime/index.d.ts +68 -0
  48. package/dist/runtime/index.js +912 -0
  49. package/dist/server/client.d.ts +1 -0
  50. package/dist/server/client.js +112 -0
  51. package/dist/server/dev.d.ts +8 -0
  52. package/dist/server/dev.js +244 -0
  53. package/dist/server/preview.d.ts +6 -0
  54. package/dist/server/preview.js +106 -0
  55. package/dist/server/static.d.ts +10 -0
  56. package/dist/server/static.js +136 -0
  57. package/lib/ui/index.sinth +436 -0
  58. package/package.json +33 -15
  59. package/schema/sinth.config.schema.json +54 -0
  60. package/dist/browser/compile.js +0 -63
  61. package/dist/cli.js +0 -509
  62. package/dist/core/builtins.js +0 -117
  63. package/dist/core/cli-compiler.js +0 -705
  64. package/dist/core/compiler.js +0 -1489
  65. package/dist/core/expr.js +0 -129
  66. package/dist/core/head-builder.js +0 -130
  67. package/dist/core/lexer.js +0 -410
  68. package/dist/core/parser.js +0 -1646
  69. package/dist/core/runtime/custom-element.js +0 -81
  70. package/dist/core/runtime/functions.js +0 -99
  71. package/dist/core/runtime/helpers.js +0 -347
  72. package/dist/core/runtime/render.js +0 -136
  73. package/dist/core/style-processor.js +0 -317
  74. package/dist/core/types.js +0 -93
  75. package/dist/resolver.js +0 -175
  76. package/dist/server.js +0 -174
  77. package/dist/update-check.js +0 -109
  78. package/dist/utils.js +0 -80
@@ -0,0 +1,6 @@
1
+ import { Loc } from "./diagnostics";
2
+ export interface ScriptInfo {
3
+ declared: string[];
4
+ hasImports: boolean;
5
+ }
6
+ export declare function analyzeScript(code: string, loc: Loc, inComponent: boolean): ScriptInfo;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.analyzeScript = analyzeScript;
37
+ const acorn = __importStar(require("acorn"));
38
+ const diagnostics_1 = require("./diagnostics");
39
+ function collectPattern(node, out) {
40
+ if (!node)
41
+ return;
42
+ switch (node.type) {
43
+ case "Identifier":
44
+ if (node.name)
45
+ out.push(node.name);
46
+ break;
47
+ case "ObjectPattern":
48
+ for (const p of node.properties ?? [])
49
+ collectPattern(p.type === "RestElement" ? p.argument : p.value, out);
50
+ break;
51
+ case "ArrayPattern":
52
+ for (const el of node.elements ?? [])
53
+ collectPattern(el, out);
54
+ break;
55
+ case "RestElement":
56
+ collectPattern(node.argument, out);
57
+ break;
58
+ case "AssignmentPattern":
59
+ collectPattern(node.left, out);
60
+ break;
61
+ default:
62
+ break;
63
+ }
64
+ }
65
+ function analyzeScript(code, loc, inComponent) {
66
+ let program;
67
+ try {
68
+ program = acorn.parse(code, {
69
+ ecmaVersion: "latest",
70
+ sourceType: inComponent ? "script" : "module",
71
+ allowReturnOutsideFunction: inComponent,
72
+ allowAwaitOutsideFunction: !inComponent,
73
+ locations: true,
74
+ });
75
+ }
76
+ catch (err) {
77
+ const e = err;
78
+ const line = e.loc ? loc.line + e.loc.line - 1 : loc.line;
79
+ const col = e.loc ? (e.loc.line === 1 ? loc.col + e.loc.column : e.loc.column + 1) : loc.col;
80
+ throw new diagnostics_1.SinthError("E0500", `JavaScript syntax error in script block: ${e.message.replace(/\s*\(\d+:\d+\)$/, "")}`, { file: loc.file, line, col });
81
+ }
82
+ const declared = [];
83
+ let hasImports = false;
84
+ for (const stmt of program.body ?? []) {
85
+ switch (stmt.type) {
86
+ case "FunctionDeclaration":
87
+ case "ClassDeclaration":
88
+ if (stmt.id?.name)
89
+ declared.push(stmt.id.name);
90
+ break;
91
+ case "VariableDeclaration":
92
+ for (const d of stmt.declarations ?? [])
93
+ collectPattern(d.id, declared);
94
+ break;
95
+ case "ImportDeclaration":
96
+ hasImports = true;
97
+ for (const s of stmt.specifiers ?? [])
98
+ if (s.local?.name)
99
+ declared.push(s.local.name);
100
+ break;
101
+ default:
102
+ break;
103
+ }
104
+ }
105
+ return { declared, hasImports };
106
+ }
@@ -0,0 +1,39 @@
1
+ import { Loc } from "./diagnostics";
2
+ export type CssNode = {
3
+ k: "decl";
4
+ prop: string;
5
+ value: string;
6
+ line: number;
7
+ } | {
8
+ k: "rule";
9
+ selector: string;
10
+ children: CssNode[];
11
+ } | {
12
+ k: "at";
13
+ name: string;
14
+ params: string;
15
+ children: CssNode[] | null;
16
+ };
17
+ export interface StyleExpression {
18
+ cssVar: string;
19
+ source: string;
20
+ line: number;
21
+ }
22
+ export interface StyleCompileOptions {
23
+ scope?: string;
24
+ reactiveNames?: ReadonlySet<string>;
25
+ varPrefix: string;
26
+ loc: Loc;
27
+ sinthSyntax: boolean;
28
+ }
29
+ export interface StyleCompileResult {
30
+ css: string;
31
+ expressions: StyleExpression[];
32
+ }
33
+ export declare function camelToKebab(s: string): string;
34
+ export declare function splitTopLevel(text: string, sep: string): string[];
35
+ export declare function parseCss(src: string, sinth: boolean, loc: Loc): CssNode[];
36
+ export declare function serializeNested(nodes: CssNode[], indent?: string): string;
37
+ export declare function flattenCss(nodes: CssNode[], scope?: string): string;
38
+ export type ScssCompiler = (source: string, file: string) => string;
39
+ export declare function compileStyle(raw: string, lang: "sinth" | "css" | "scss", opts: StyleCompileOptions, scss?: ScssCompiler): StyleCompileResult;
@@ -0,0 +1,463 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelToKebab = camelToKebab;
4
+ exports.splitTopLevel = splitTopLevel;
5
+ exports.parseCss = parseCss;
6
+ exports.serializeNested = serializeNested;
7
+ exports.flattenCss = flattenCss;
8
+ exports.compileStyle = compileStyle;
9
+ const diagnostics_1 = require("./diagnostics");
10
+ const elements_1 = require("./elements");
11
+ const PSEUDO_CLASS = {
12
+ onHover: ":hover", onFocus: ":focus", onActive: ":active", onVisited: ":visited", onChecked: ":checked",
13
+ onDisabled: ":disabled", onEnabled: ":enabled", onRequired: ":required", onOptional: ":optional", onValid: ":valid",
14
+ onInvalid: ":invalid", onPlaceholderShown: ":placeholder-shown", onFocusWithin: ":focus-within",
15
+ onFocusVisible: ":focus-visible", onFirst: ":first-child", onLast: ":last-child", onFirstOfType: ":first-of-type",
16
+ onLastOfType: ":last-of-type", onEmpty: ":empty", onTarget: ":target", onLink: ":link", onOpen: "[open]",
17
+ };
18
+ const PSEUDO_ELEMENT = {
19
+ before: "::before", after: "::after", placeholder: "::placeholder", selection: "::selection",
20
+ firstLine: "::first-line", firstLetter: "::first-letter", marker: "::marker", backdrop: "::backdrop",
21
+ };
22
+ const MEDIA_SHORTHAND = {
23
+ dark: "(prefers-color-scheme: dark)",
24
+ light: "(prefers-color-scheme: light)",
25
+ reducedMotion: "(prefers-reduced-motion: reduce)",
26
+ print: "print",
27
+ mobile: "(max-width: 640px)",
28
+ tablet: "(min-width: 641px) and (max-width: 1024px)",
29
+ desktop: "(min-width: 1025px)",
30
+ };
31
+ const QUOTED_CONTENT_PROPS = new Set(["content", "quotes"]);
32
+ function camelToKebab(s) {
33
+ if (s.startsWith("--"))
34
+ return s;
35
+ const vendor = s.match(/^(Webkit|Moz|Ms|O)([A-Z].*)$/);
36
+ if (vendor)
37
+ return `-${vendor[1].toLowerCase()}-${camelToKebab(vendor[2][0].toLowerCase() + vendor[2].slice(1))}`;
38
+ return s.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
39
+ }
40
+ class CssReader {
41
+ src;
42
+ sinth;
43
+ loc;
44
+ pos = 0;
45
+ line;
46
+ constructor(src, sinth, loc) {
47
+ this.src = src;
48
+ this.sinth = sinth;
49
+ this.loc = loc;
50
+ this.line = loc.line;
51
+ }
52
+ fail(message) {
53
+ throw new diagnostics_1.SinthError("E0400", message, { file: this.loc.file, line: this.line, col: 1 });
54
+ }
55
+ skipTrivia() {
56
+ while (this.pos < this.src.length) {
57
+ const c = this.src[this.pos];
58
+ if (c === "\n") {
59
+ this.line++;
60
+ this.pos++;
61
+ }
62
+ else if (c === " " || c === "\t" || c === "\r" || c === ";") {
63
+ this.pos++;
64
+ }
65
+ else if (c === "/" && this.src[this.pos + 1] === "*") {
66
+ const end = this.src.indexOf("*/", this.pos + 2);
67
+ const stop = end === -1 ? this.src.length : end + 2;
68
+ this.countLines(this.pos, stop);
69
+ this.pos = stop;
70
+ }
71
+ else if (this.sinth && c === "/" && this.src[this.pos + 1] === "/") {
72
+ while (this.pos < this.src.length && this.src[this.pos] !== "\n")
73
+ this.pos++;
74
+ }
75
+ else if (this.sinth && c === "-" && this.src[this.pos + 1] === "-" && this.src[this.pos + 2] === "[") {
76
+ const end = this.src.indexOf("]--", this.pos + 3);
77
+ const stop = end === -1 ? this.src.length : end + 3;
78
+ this.countLines(this.pos, stop);
79
+ this.pos = stop;
80
+ }
81
+ else if (this.sinth && c === "-" && this.src[this.pos + 1] === "-" && !/[A-Za-z0-9_]/.test(this.src[this.pos + 2] ?? "")) {
82
+ while (this.pos < this.src.length && this.src[this.pos] !== "\n")
83
+ this.pos++;
84
+ }
85
+ else {
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ countLines(from, to) {
91
+ for (let i = from; i < to; i++)
92
+ if (this.src[i] === "\n")
93
+ this.line++;
94
+ }
95
+ readBlock() {
96
+ const nodes = [];
97
+ for (;;) {
98
+ this.skipTrivia();
99
+ if (this.pos >= this.src.length)
100
+ return nodes;
101
+ if (this.src[this.pos] === "}")
102
+ return nodes;
103
+ nodes.push(this.readItem());
104
+ }
105
+ }
106
+ readItem() {
107
+ const startLine = this.line;
108
+ let text = "";
109
+ let depth = 0;
110
+ while (this.pos < this.src.length) {
111
+ const c = this.src[this.pos];
112
+ if (c === '"' || c === "'") {
113
+ text += this.readQuoted(c);
114
+ continue;
115
+ }
116
+ if (c === "#" && this.src[this.pos + 1] === "{") {
117
+ const close = this.src.indexOf("}", this.pos);
118
+ if (close === -1)
119
+ this.fail("Unterminated interpolation '#{'");
120
+ text += this.src.slice(this.pos, close + 1);
121
+ this.pos = close + 1;
122
+ continue;
123
+ }
124
+ if (c === "/" && this.src[this.pos + 1] === "*") {
125
+ const end = this.src.indexOf("*/", this.pos + 2);
126
+ const stop = end === -1 ? this.src.length : end + 2;
127
+ this.countLines(this.pos, stop);
128
+ this.pos = stop;
129
+ continue;
130
+ }
131
+ if (this.sinth && depth === 0 && c === "-" && this.src[this.pos + 1] === "-" && /\s/.test(this.src[this.pos - 1] ?? " ") && !/[A-Za-z0-9_]/.test(this.src[this.pos + 2] ?? "")) {
132
+ while (this.pos < this.src.length && this.src[this.pos] !== "\n")
133
+ this.pos++;
134
+ continue;
135
+ }
136
+ if (c === "(" || c === "[")
137
+ depth++;
138
+ if (c === ")" || c === "]")
139
+ depth--;
140
+ if (depth === 0) {
141
+ if (c === "{") {
142
+ this.pos++;
143
+ const children = this.readBlock();
144
+ if (this.src[this.pos] !== "}")
145
+ this.fail(`Missing '}' for '${text.trim()}'`);
146
+ this.pos++;
147
+ return this.makeBlock(text.trim(), children, startLine);
148
+ }
149
+ if (c === ";" || c === "}")
150
+ break;
151
+ if (c === "\n") {
152
+ const trimmed = text.trim();
153
+ const continues = trimmed.endsWith(",") || trimmed.endsWith(":") || this.nextLineStartsWithBrace();
154
+ if (this.sinth && trimmed && !continues)
155
+ break;
156
+ }
157
+ }
158
+ if (c === "\n")
159
+ this.line++;
160
+ text += c;
161
+ this.pos++;
162
+ }
163
+ if (this.src[this.pos] === ";")
164
+ this.pos++;
165
+ return this.makeStatement(text.trim(), startLine);
166
+ }
167
+ nextLineStartsWithBrace() {
168
+ let i = this.pos + 1;
169
+ while (i < this.src.length && /[ \t\r\n]/.test(this.src[i]))
170
+ i++;
171
+ return this.src[i] === "{";
172
+ }
173
+ readQuoted(q) {
174
+ const start = this.pos;
175
+ this.pos++;
176
+ while (this.pos < this.src.length && this.src[this.pos] !== q) {
177
+ if (this.src[this.pos] === "\\")
178
+ this.pos++;
179
+ if (this.src[this.pos] === "\n")
180
+ this.fail("Unterminated string in style block");
181
+ this.pos++;
182
+ }
183
+ this.pos++;
184
+ return this.src.slice(start, this.pos);
185
+ }
186
+ makeBlock(head, children, line) {
187
+ if (head.startsWith("@")) {
188
+ const m = head.match(/^@([\w-]+)\s*([\s\S]*)$/);
189
+ return { k: "at", name: m?.[1] ?? "", params: (m?.[2] ?? "").trim(), children };
190
+ }
191
+ if (this.sinth) {
192
+ const media = head.match(/^media\s*\(([\s\S]*)\)$/);
193
+ if (media)
194
+ return { k: "at", name: "media", params: convertMediaArgs(media[1]), children };
195
+ if (MEDIA_SHORTHAND[head])
196
+ return { k: "at", name: "media", params: MEDIA_SHORTHAND[head], children };
197
+ if (/^supports\s*\(/.test(head))
198
+ return { k: "at", name: "supports", params: head.slice(8).trim(), children };
199
+ }
200
+ if (!head)
201
+ this.fail(`Missing selector before '{' (line ${line})`);
202
+ return { k: "rule", selector: this.sinth ? convertSelector(head) : head, children };
203
+ }
204
+ makeStatement(text, line) {
205
+ if (text.startsWith("@")) {
206
+ const m = text.match(/^@([\w-]+)\s*([\s\S]*)$/);
207
+ return { k: "at", name: m?.[1] ?? "", params: (m?.[2] ?? "").trim(), children: null };
208
+ }
209
+ const colon = findTopLevelColon(text);
210
+ if (colon === -1) {
211
+ if (this.sinth && /^[A-Z][A-Za-z0-9]*$/.test(text))
212
+ this.fail(`Missing '{' after selector '${text}'`);
213
+ this.fail(`Invalid style declaration '${text}' (expected 'property: value')`);
214
+ }
215
+ const prop = text.slice(0, colon).trim();
216
+ const value = text.slice(colon + 1).trim();
217
+ if (!value)
218
+ this.fail(`Missing value for '${prop}'`);
219
+ return { k: "decl", prop, value, line };
220
+ }
221
+ }
222
+ function findTopLevelColon(text) {
223
+ let depth = 0;
224
+ let quote = "";
225
+ for (let i = 0; i < text.length; i++) {
226
+ const c = text[i];
227
+ if (quote) {
228
+ if (c === "\\")
229
+ i++;
230
+ else if (c === quote)
231
+ quote = "";
232
+ continue;
233
+ }
234
+ if (c === '"' || c === "'")
235
+ quote = c;
236
+ else if (c === "(" || c === "[")
237
+ depth++;
238
+ else if (c === ")" || c === "]")
239
+ depth--;
240
+ else if (c === ":" && depth === 0)
241
+ return i;
242
+ }
243
+ return -1;
244
+ }
245
+ function convertMediaArgs(args) {
246
+ const parts = splitTopLevel(args, ",");
247
+ return parts.map(p => {
248
+ const t = p.trim();
249
+ const colon = findTopLevelColon(t);
250
+ if (colon === -1)
251
+ return MEDIA_SHORTHAND[t] ?? unquote(t);
252
+ const key = camelToKebab(t.slice(0, colon).trim());
253
+ return `(${key}: ${unquote(t.slice(colon + 1).trim())})`;
254
+ }).join(" and ");
255
+ }
256
+ function unquote(v) {
257
+ const m = v.match(/^(["'])([\s\S]*)\1$/);
258
+ return m ? m[2] : v;
259
+ }
260
+ function splitTopLevel(text, sep) {
261
+ const out = [];
262
+ let depth = 0;
263
+ let quote = "";
264
+ let cur = "";
265
+ for (let i = 0; i < text.length; i++) {
266
+ const c = text[i];
267
+ if (quote) {
268
+ cur += c;
269
+ if (c === "\\")
270
+ cur += text[++i] ?? "";
271
+ else if (c === quote)
272
+ quote = "";
273
+ continue;
274
+ }
275
+ if (c === '"' || c === "'")
276
+ quote = c;
277
+ else if (c === "(" || c === "[")
278
+ depth++;
279
+ else if (c === ")" || c === "]")
280
+ depth--;
281
+ if (c === sep && depth === 0) {
282
+ out.push(cur);
283
+ cur = "";
284
+ continue;
285
+ }
286
+ cur += c;
287
+ }
288
+ out.push(cur);
289
+ return out;
290
+ }
291
+ function convertSelector(sel) {
292
+ if (PSEUDO_CLASS[sel])
293
+ return "&" + PSEUDO_CLASS[sel];
294
+ if (PSEUDO_ELEMENT[sel])
295
+ return "&" + PSEUDO_ELEMENT[sel];
296
+ return splitTopLevel(sel, ",").map(part => part.trim().replace(/(^|[\s>+~(])([A-Z][A-Za-z0-9]*)(?=$|[\s.:#[>+~,)])/g, (m, pre, name) => {
297
+ const info = elements_1.ELEMENTS[name];
298
+ if (!info)
299
+ return m;
300
+ return pre + info.tag + (info.className ? "." + info.className.split(" ").join(".") : "");
301
+ }).replace(/&?\b(on[A-Z][A-Za-z]+)\b/g, (m, name) => (PSEUDO_CLASS[name] ? "&" + PSEUDO_CLASS[name] : m))).join(", ");
302
+ }
303
+ class StyleConverter {
304
+ opts;
305
+ expressions = [];
306
+ constructor(opts) {
307
+ this.opts = opts;
308
+ }
309
+ convert(nodes) {
310
+ return nodes.map(n => {
311
+ if (n.k === "decl")
312
+ return this.convertDecl(n);
313
+ if (n.k === "rule")
314
+ return { ...n, children: this.convert(n.children) };
315
+ return { ...n, children: n.children ? this.convert(n.children) : null };
316
+ });
317
+ }
318
+ convertDecl(d) {
319
+ if (d.prop.startsWith("$"))
320
+ return d;
321
+ const prop = camelToKebab(d.prop);
322
+ let value = d.value;
323
+ let important = "";
324
+ const imp = value.match(/\s*!important$/);
325
+ if (imp) {
326
+ important = " !important";
327
+ value = value.slice(0, imp.index);
328
+ }
329
+ const reactive = this.reactiveExpression(value);
330
+ if (reactive !== undefined) {
331
+ const cssVar = `${this.opts.varPrefix}${this.expressions.length}`;
332
+ this.expressions.push({ cssVar, source: reactive, line: d.line });
333
+ return { k: "decl", prop, value: `var(${cssVar})${important}`, line: d.line };
334
+ }
335
+ const single = value.match(/^(["'])([\s\S]*)\1$/);
336
+ if (single && !QUOTED_CONTENT_PROPS.has(prop))
337
+ value = single[2];
338
+ else if (single && prop === "content" && (/^(attr|counter|counters|url|var)\(|^(none|normal|open-quote|close-quote)$/.test(single[2]) || /^(["'])[\s\S]*\1$/.test(single[2])))
339
+ value = single[2];
340
+ return { k: "decl", prop, value: value + important, line: d.line };
341
+ }
342
+ reactiveExpression(value) {
343
+ const names = this.opts.reactiveNames;
344
+ if (!names || names.size === 0)
345
+ return undefined;
346
+ const stripped = value.replace(/(["'])(?:\\.|(?!\1).)*\1/g, "\"\"");
347
+ const ids = stripped.match(/[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/g) ?? [];
348
+ const hit = ids.some(id => names.has(id.split(".")[0]));
349
+ if (!hit)
350
+ return undefined;
351
+ if (/^[A-Za-z_$][\w$.]*$/.test(value.trim()))
352
+ return value.trim();
353
+ if (/[+*/?]|\(|\)/.test(stripped) || /^["']/.test(value.trim()))
354
+ return value.trim();
355
+ return undefined;
356
+ }
357
+ }
358
+ function parseCss(src, sinth, loc) {
359
+ const reader = new CssReader(src, sinth, loc);
360
+ const nodes = reader.readBlock();
361
+ if (reader.pos < src.length)
362
+ reader.fail("Unexpected '}' in style block");
363
+ return nodes;
364
+ }
365
+ function serializeNested(nodes, indent = "") {
366
+ const out = [];
367
+ for (const n of nodes) {
368
+ if (n.k === "decl")
369
+ out.push(`${indent}${n.prop}: ${n.value};`);
370
+ else if (n.k === "rule")
371
+ out.push(`${indent}${n.selector} {\n${serializeNested(n.children, indent + " ")}\n${indent}}`);
372
+ else if (n.children === null)
373
+ out.push(`${indent}@${n.name}${n.params ? " " + n.params : ""};`);
374
+ else
375
+ out.push(`${indent}@${n.name}${n.params ? " " + n.params : ""} {\n${serializeNested(n.children, indent + " ")}\n${indent}}`);
376
+ }
377
+ return out.join("\n");
378
+ }
379
+ const UNSCOPED_ROOTS = /^(html|body|:root|:host)(?=$|[\s.:#[>+~])/;
380
+ function scopeComplexSelector(sel, scope) {
381
+ const trimmed = sel.trim();
382
+ if (/^:global\(/.test(trimmed) && trimmed.endsWith(")"))
383
+ return trimmed.slice(8, -1);
384
+ if (trimmed.includes(":global("))
385
+ return trimmed.replace(/:global\(([^)]*)\)/g, "$1");
386
+ if (UNSCOPED_ROOTS.test(trimmed) && !/[\s>+~]/.test(trimmed))
387
+ return trimmed;
388
+ const cls = `.${scope}`;
389
+ let depth = 0;
390
+ let lastCompoundStart = 0;
391
+ for (let i = 0; i < trimmed.length; i++) {
392
+ const c = trimmed[i];
393
+ if (c === "(" || c === "[")
394
+ depth++;
395
+ else if (c === ")" || c === "]")
396
+ depth--;
397
+ else if (depth === 0 && /[\s>+~]/.test(c))
398
+ lastCompoundStart = i + 1;
399
+ }
400
+ const head = trimmed.slice(0, lastCompoundStart);
401
+ const last = trimmed.slice(lastCompoundStart);
402
+ if (UNSCOPED_ROOTS.test(last))
403
+ return trimmed;
404
+ const pe = last.indexOf("::");
405
+ const scopedLast = pe === -1 ? last + cls : last.slice(0, pe) + cls + last.slice(pe);
406
+ return head + scopedLast;
407
+ }
408
+ function combineSelectors(parents, child) {
409
+ const out = [];
410
+ for (const c of splitTopLevel(child, ",")) {
411
+ const part = c.trim();
412
+ for (const p of parents)
413
+ out.push(part.includes("&") ? part.replace(/&/g, p) : p ? `${p} ${part}` : part);
414
+ }
415
+ return out;
416
+ }
417
+ function flatten(nodes, ctx, indent) {
418
+ const out = [];
419
+ const decls = nodes.filter((n) => n.k === "decl");
420
+ if (decls.length && ctx.selectors.length) {
421
+ const sel = ctx.inKeyframes ? ctx.selectors.join(", ") : ctx.selectors.map(s => (ctx.scope ? scopeComplexSelector(s, ctx.scope) : s)).join(",\n" + indent);
422
+ out.push(`${indent}${sel} {\n${decls.map(d => `${indent} ${d.prop}: ${d.value};`).join("\n")}\n${indent}}`);
423
+ }
424
+ else if (decls.length) {
425
+ out.push(...decls.map(d => `${indent}${d.prop}: ${d.value};`));
426
+ }
427
+ for (const n of nodes) {
428
+ if (n.k === "rule") {
429
+ const selectors = ctx.inKeyframes ? [n.selector] : combineSelectors(ctx.selectors.length ? ctx.selectors : [""], n.selector);
430
+ out.push(...flatten(n.children, { ...ctx, selectors }, indent));
431
+ }
432
+ else if (n.k === "at") {
433
+ if (n.children === null) {
434
+ out.push(`${indent}@${n.name}${n.params ? " " + n.params : ""};`);
435
+ continue;
436
+ }
437
+ const keyframes = /keyframes$/.test(n.name);
438
+ if (keyframes || n.name === "font-face" || n.name === "property" || n.name === "page" || n.name === "counter-style") {
439
+ const inner = flatten(n.children, { selectors: [], scope: undefined, inKeyframes: true }, indent + " ");
440
+ out.push(`${indent}@${n.name}${n.params ? " " + n.params : ""} {\n${inner.join("\n")}\n${indent}}`);
441
+ continue;
442
+ }
443
+ const inner = flatten(n.children, ctx, indent + " ");
444
+ if (inner.length)
445
+ out.push(`${indent}@${n.name}${n.params ? " " + n.params : ""} {\n${inner.join("\n")}\n${indent}}`);
446
+ }
447
+ }
448
+ return out;
449
+ }
450
+ function flattenCss(nodes, scope) {
451
+ return flatten(nodes, { selectors: [], scope, inKeyframes: false }, "").join("\n");
452
+ }
453
+ function compileStyle(raw, lang, opts, scss) {
454
+ const converter = new StyleConverter(opts);
455
+ const tree = converter.convert(parseCss(raw, lang !== "css", opts.loc));
456
+ if (lang === "scss") {
457
+ if (!scss)
458
+ throw new diagnostics_1.SinthError("E0401", "SCSS support requires the 'sass' package", opts.loc, "Install it in your project: npm install -D sass");
459
+ const compiled = scss(serializeNested(tree), opts.loc.file);
460
+ return { css: flattenCss(parseCss(compiled, false, opts.loc), opts.scope), expressions: converter.expressions };
461
+ }
462
+ return { css: flattenCss(tree, opts.scope), expressions: converter.expressions };
463
+ }
@@ -0,0 +1,9 @@
1
+ import { SinthConfig } from "../project/config";
2
+ export interface DeployOptions {
3
+ branch?: string;
4
+ preview: boolean;
5
+ create: boolean;
6
+ projectName?: string;
7
+ }
8
+ export declare function defaultProjectName(root: string): string;
9
+ export declare function deployToCloudflare(root: string, outDir: string, config: SinthConfig, opts: DeployOptions): Promise<void>;