@yannosay/sinth 0.0.4 → 0.0.5
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/package.json +1 -1
- package/pages/index.sinth +1 -1
- package/prod-test/pages/index.html +38 -0
- package/public/components/Card.html +4 -0
- package/public/components/Navbar.html +4 -0
- package/public/pages/index.html +67 -0
- package/public/test-project/components/Card.html +4 -0
- package/public/test-project/components/Navbar.html +4 -0
- package/public/test-project/pages/index.html +67 -0
- package/src/sinth.ts +99 -44
package/package.json
CHANGED
package/pages/index.sinth
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>My Site</title><link rel="icon" href="assets/favicon.ico" type="image/x-icon"><meta name="description" content="Built with Sinth."><link rel="stylesheet" href="../styles/reset.css"><style>
|
|
2
|
+
[data-s="931b8d90"] Hero, Hero[data-s="931b8d90"] {
|
|
3
|
+
padding: 4rem 2rem;
|
|
4
|
+
text-align: center;
|
|
5
|
+
background-color: #f0f4ff;
|
|
6
|
+
}
|
|
7
|
+
[data-s="931b8d90"] Main, Main[data-s="931b8d90"] {
|
|
8
|
+
max-width: 1100px;
|
|
9
|
+
margin: 0 auto;
|
|
10
|
+
padding: 2rem;
|
|
11
|
+
}
|
|
12
|
+
[data-s="931b8d90"] Header, Header[data-s="931b8d90"] {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
padding: 1rem 2rem;
|
|
16
|
+
background-color: #1a1a2e;
|
|
17
|
+
color: white;
|
|
18
|
+
}
|
|
19
|
+
[data-s="931b8d90"] .logo, .logo[data-s="931b8d90"] {
|
|
20
|
+
font-size: 1.5rem;
|
|
21
|
+
font-weight: 700;
|
|
22
|
+
color: white;
|
|
23
|
+
text-decoration: none;
|
|
24
|
+
}
|
|
25
|
+
[data-s="931b8d90"] .nav-links, .nav-links[data-s="931b8d90"] {
|
|
26
|
+
margin-left: auto;
|
|
27
|
+
display: flex;
|
|
28
|
+
gap: 1.5rem;
|
|
29
|
+
}
|
|
30
|
+
[data-s="931b8d90"] .nav-links a, .nav-links a[data-s="931b8d90"] {
|
|
31
|
+
color: rgba(255,255,255,0.8);
|
|
32
|
+
text-decoration: none;
|
|
33
|
+
}
|
|
34
|
+
</style></head><body data-s="931b8d90"><header data-s="931b8d90"><nav data-s="931b8d90"><a data-s="931b8d90" href="/" class="logo">MySite</a><div data-s="931b8d90" class="nav-links"><a data-s="931b8d90" href="/">Home</a><a data-s="931b8d90" href="/about">About</a></div></nav></header><section data-s="931b8d90" class="hero"><h1 data-s="931b8d90">Welcome to Sinth</h1><p data-s="931b8d90">A declarative, component-based web UI language.</p><button data-s="931b8d90" onclick="handleCTA(event)" type="button">Get Stssssssssssssssarted</button></section><main data-s="931b8d90"><section data-s="931b8d90"><h2 data-s="931b8d90">Features</h2><div data-s="931b8d90" class="card-grid"></div></section></main><script>
|
|
35
|
+
function handleCTA() {
|
|
36
|
+
alert("Hello from Sinth!")
|
|
37
|
+
}
|
|
38
|
+
</script></body></html>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>My Site</title>
|
|
7
|
+
<link rel="icon" href="assets/favicon.ico" type="image/x-icon">
|
|
8
|
+
<meta name="description" content="Built with Sinth.">
|
|
9
|
+
<link rel="stylesheet" href="../styles/reset.css">
|
|
10
|
+
<style>
|
|
11
|
+
|
|
12
|
+
[data-s="931b8d90"] Hero, Hero[data-s="931b8d90"] {
|
|
13
|
+
padding: 4rem 2rem;
|
|
14
|
+
text-align: center;
|
|
15
|
+
background-color: #f0f4ff;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[data-s="931b8d90"] Main, Main[data-s="931b8d90"] {
|
|
19
|
+
max-width: 1100px;
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
padding: 2rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[data-s="931b8d90"] Header, Header[data-s="931b8d90"] {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
padding: 1rem 2rem;
|
|
30
|
+
background-color: #1a1a2e;
|
|
31
|
+
color: white;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-s="931b8d90"] .logo, .logo[data-s="931b8d90"] {
|
|
35
|
+
font-size: 1.5rem;
|
|
36
|
+
font-weight: 700;
|
|
37
|
+
color: white;
|
|
38
|
+
text-decoration: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[data-s="931b8d90"] .nav-links, .nav-links[data-s="931b8d90"] {
|
|
42
|
+
margin-left: auto;
|
|
43
|
+
display: flex;
|
|
44
|
+
gap: 1.5rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[data-s="931b8d90"] .nav-links a, .nav-links a[data-s="931b8d90"] {
|
|
48
|
+
color: rgba(255,255,255,0.8);
|
|
49
|
+
text-decoration: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body data-s="931b8d90">
|
|
56
|
+
<header data-s="931b8d90"><nav data-s="931b8d90"><a data-s="931b8d90" href="/" class="logo">MySite</a><div data-s="931b8d90" class="nav-links"><a data-s="931b8d90" href="/">Home</a><a data-s="931b8d90" href="/about">About</a></div></nav></header>
|
|
57
|
+
<section data-s="931b8d90" class="hero"><h1 data-s="931b8d90">Welcome to Sinth</h1><p data-s="931b8d90">A declarative, component-based web UI language.</p><button data-s="931b8d90" onclick="handleCTA(event)" type="button">Get Stssssssssssssssarted</button></section>
|
|
58
|
+
<main data-s="931b8d90"><section data-s="931b8d90"><h2 data-s="931b8d90">Features</h2><div data-s="931b8d90" class="card-grid"></div></section></main>
|
|
59
|
+
<script>
|
|
60
|
+
|
|
61
|
+
function handleCTA() {
|
|
62
|
+
alert("Hello from Sinth!")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
</script>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>My Site</title>
|
|
7
|
+
<link rel="icon" href="assets/favicon.ico" type="image/x-icon">
|
|
8
|
+
<meta name="description" content="Built with Sinth.">
|
|
9
|
+
<link rel="stylesheet" href="../styles/reset.css">
|
|
10
|
+
<style>
|
|
11
|
+
|
|
12
|
+
[data-s="8cfc97e4"] Hero, Hero[data-s="8cfc97e4"] {
|
|
13
|
+
padding: 4rem 2rem;
|
|
14
|
+
text-align: center;
|
|
15
|
+
background-color: #f0f4ff;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[data-s="8cfc97e4"] Main, Main[data-s="8cfc97e4"] {
|
|
19
|
+
max-width: 1100px;
|
|
20
|
+
margin: 0 auto;
|
|
21
|
+
padding: 2rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[data-s="8cfc97e4"] Header, Header[data-s="8cfc97e4"] {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
padding: 1rem 2rem;
|
|
30
|
+
background-color: #1a1a2e;
|
|
31
|
+
color: white;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-s="8cfc97e4"] .logo, .logo[data-s="8cfc97e4"] {
|
|
35
|
+
font-size: 1.5rem;
|
|
36
|
+
font-weight: 700;
|
|
37
|
+
color: white;
|
|
38
|
+
text-decoration: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[data-s="8cfc97e4"] .nav-links, .nav-links[data-s="8cfc97e4"] {
|
|
42
|
+
margin-left: auto;
|
|
43
|
+
display: flex;
|
|
44
|
+
gap: 1.5rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[data-s="8cfc97e4"] .nav-links a, .nav-links a[data-s="8cfc97e4"] {
|
|
48
|
+
color: rgba(255,255,255,0.8);
|
|
49
|
+
text-decoration: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body data-s="8cfc97e4">
|
|
56
|
+
<header data-s="8cfc97e4"><nav data-s="8cfc97e4"><a data-s="8cfc97e4" href="/" class="logo">MySite</a><div data-s="8cfc97e4" class="nav-links"><a data-s="8cfc97e4" href="/">Home</a><a data-s="8cfc97e4" href="/about">About</a></div></nav></header>
|
|
57
|
+
<section data-s="8cfc97e4" class="hero"><h1 data-s="8cfc97e4">Welcome to Sinth</h1><p data-s="8cfc97e4">A declarative, component-based web UI language.</p><button data-s="8cfc97e4" onclick="handleCTA(event)" type="button">Get Started</button></section>
|
|
58
|
+
<main data-s="8cfc97e4"><section data-s="8cfc97e4"><h2 data-s="8cfc97e4">Features</h2><div data-s="8cfc97e4" class="card-grid"></div></section></main>
|
|
59
|
+
<script>
|
|
60
|
+
|
|
61
|
+
function handleCTA() {
|
|
62
|
+
alert("Hello from Sinth!")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
</script>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
package/src/sinth.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Sinth Compiler v0.0.
|
|
2
|
+
// Sinth Compiler v0.0.5 — enum fix, raw-block detection, import resolution, CSS conversion, slot escaping, custom-elements, HTML5 map
|
|
3
3
|
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
@@ -11,7 +11,7 @@ import * as http from "http";
|
|
|
11
11
|
|
|
12
12
|
interface Loc { file: string; line: number; col: number }
|
|
13
13
|
|
|
14
|
-
// === v0.0.
|
|
14
|
+
// === v0.0.5: Must be plain `enum TT`, NOT `const enum TT` — const enum breaks TT[t] string indexing ===
|
|
15
15
|
enum TT {
|
|
16
16
|
LBRACE, RBRACE, LPAREN, RPAREN, COLON, COMMA, EQUALS, DOT,
|
|
17
17
|
STRING, NUMBER, BOOL_TRUE, BOOL_FALSE, NULL_LIT,
|
|
@@ -20,7 +20,7 @@ enum TT {
|
|
|
20
20
|
KW_IMPORT, KW_AS, KW_CSS,
|
|
21
21
|
KW_COMPONENT, KW_STYLE, KW_SCRIPT,
|
|
22
22
|
KW_GLOBAL, KW_PAGE, KW_LANG,
|
|
23
|
-
// === v0.0.
|
|
23
|
+
// === v0.0.5: KW_CUSTOM_EL and KW_CUSTOM ensured present ===
|
|
24
24
|
KW_CUSTOM_EL,
|
|
25
25
|
KW_CUSTOM,
|
|
26
26
|
EOF,
|
|
@@ -102,7 +102,7 @@ class SinthError extends Error {
|
|
|
102
102
|
return s;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// === v0.0.
|
|
105
|
+
// === v0.0.5: Attach source line to produce error preview ===
|
|
106
106
|
withSource(lines: string[]): SinthError {
|
|
107
107
|
if (!this.loc || this.sourceLine !== undefined) return this;
|
|
108
108
|
const line = lines[this.loc.line - 1] ?? "";
|
|
@@ -173,7 +173,7 @@ const KEYWORDS: Record<string, TT> = {
|
|
|
173
173
|
"true": TT.BOOL_TRUE,
|
|
174
174
|
"false": TT.BOOL_FALSE,
|
|
175
175
|
"null": TT.NULL_LIT,
|
|
176
|
-
// === v0.0.
|
|
176
|
+
// === v0.0.5: custom-element and custom lexed as hyphenated identifier ===
|
|
177
177
|
"custom-element": TT.KW_CUSTOM_EL,
|
|
178
178
|
"custom": TT.KW_CUSTOM,
|
|
179
179
|
};
|
|
@@ -221,7 +221,7 @@ export class Lexer {
|
|
|
221
221
|
|
|
222
222
|
if (this.isIdentStart(ch)) {
|
|
223
223
|
const tok = this.readIdent(loc);
|
|
224
|
-
// === v0.0.
|
|
224
|
+
// === v0.0.5: Also set rawBlockPending for component, custom-element, custom ===
|
|
225
225
|
if (
|
|
226
226
|
tok.type === TT.KW_STYLE ||
|
|
227
227
|
tok.type === TT.KW_SCRIPT ||
|
|
@@ -386,7 +386,7 @@ export class Lexer {
|
|
|
386
386
|
|
|
387
387
|
private readIdent(loc: Loc): Token {
|
|
388
388
|
let s = "";
|
|
389
|
-
// === v0.0.
|
|
389
|
+
// === v0.0.5: isIdentCont includes '-' so "custom-element" is read as one token ===
|
|
390
390
|
while (this.pos < this.src.length && this.isIdentCont(this.src[this.pos])) {
|
|
391
391
|
s += this.src[this.pos]; this.adv();
|
|
392
392
|
}
|
|
@@ -407,7 +407,7 @@ export class Lexer {
|
|
|
407
407
|
private loc(): Loc { return { file: this.file, line: this.line, col: this.col }; }
|
|
408
408
|
private isDigit(c: string) { return c >= "0" && c <= "9"; }
|
|
409
409
|
private isIdentStart(c: string) { return /[a-zA-Z_\u00C0-\uFFFF]/.test(c); }
|
|
410
|
-
// === v0.0.
|
|
410
|
+
// === v0.0.5: '-' allowed in identifiers so "custom-element" is a single token ===
|
|
411
411
|
private isIdentCont(c: string) { return /[a-zA-Z0-9_\-\u00C0-\uFFFF]/.test(c); }
|
|
412
412
|
}
|
|
413
413
|
|
|
@@ -503,14 +503,14 @@ export class Parser {
|
|
|
503
503
|
const loc = this.consume(TT.KW_COMPONENT).loc;
|
|
504
504
|
const name = this.consume(TT.IDENT).value;
|
|
505
505
|
const params = this.parseParamDecls();
|
|
506
|
-
// === v0.0.
|
|
506
|
+
// === v0.0.5: rawBlockPending was set by the lexer when KW_COMPONENT was read;
|
|
507
507
|
// the next token is therefore RAW_BLOCK, not LBRACE ===
|
|
508
508
|
const rawTok = this.consume(TT.RAW_BLOCK);
|
|
509
509
|
const { body, styles, scripts } = this.parseCompBody(rawTok.value, rawTok.loc);
|
|
510
510
|
return { name, params, body, styles, scripts, loc };
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
-
// === v0.0.
|
|
513
|
+
// === v0.0.5: Parse custom-element / custom declarations ===
|
|
514
514
|
private parseCustomEl(): CustomElDecl {
|
|
515
515
|
const loc = this.peek().loc;
|
|
516
516
|
if (this.check(TT.KW_CUSTOM_EL)) this.consume(TT.KW_CUSTOM_EL);
|
|
@@ -690,7 +690,7 @@ interface ResolvedImports {
|
|
|
690
690
|
// Module-level import stack for circular detection
|
|
691
691
|
const IMPORT_STACK: string[] = [];
|
|
692
692
|
|
|
693
|
-
// === v0.0.
|
|
693
|
+
// === v0.0.5: parseFile catches errors and attaches source line preview ===
|
|
694
694
|
function parseFile(filePath: string): SinthFile {
|
|
695
695
|
if (!fs.existsSync(filePath)) throw new SinthError(`File not found: ${filePath}`);
|
|
696
696
|
const src = fs.readFileSync(filePath, "utf-8");
|
|
@@ -744,7 +744,7 @@ function resolveImports(
|
|
|
744
744
|
const src = resolveLibrary(imp.name, cfg);
|
|
745
745
|
jsLinks.push({ src, attrs: {} });
|
|
746
746
|
|
|
747
|
-
// === v0.0.
|
|
747
|
+
// === v0.0.5: Auto-import companion .sinth for JS libraries (e.g. sinthui.sinth) ===
|
|
748
748
|
for (const libDir of cfg.libraryPaths) {
|
|
749
749
|
const companion = path.join(libDir, imp.name + ".sinth");
|
|
750
750
|
if (fs.existsSync(companion) && !visited.has(companion)) {
|
|
@@ -802,7 +802,7 @@ function resolveLibrary(name: string, cfg: ResolverConfig): string {
|
|
|
802
802
|
return `/libraries/${base}`;
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
-
// === v0.0.
|
|
805
|
+
// === v0.0.5: resolveSinthPath — first try relative to importing file, then library paths ===
|
|
806
806
|
function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): string {
|
|
807
807
|
// Explicit relative path
|
|
808
808
|
if (p.startsWith("./") || p.startsWith("../")) {
|
|
@@ -813,7 +813,7 @@ function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): str
|
|
|
813
813
|
throw new SinthError(`Cannot resolve import '${p}' from '${fromFile}'`);
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
-
// === v0.0.
|
|
816
|
+
// === v0.0.5: Non-relative paths (e.g. "components/Card.sinth"): try relative to importing
|
|
817
817
|
// file's directory FIRST, then fall back to library paths ===
|
|
818
818
|
const relToFile = path.resolve(path.dirname(fromFile), p);
|
|
819
819
|
if (fs.existsSync(relToFile)) return relToFile;
|
|
@@ -839,7 +839,7 @@ function resolveSinthPath(p: string, fromFile: string, cfg: ResolverConfig): str
|
|
|
839
839
|
|
|
840
840
|
interface BuiltinInfo { tag: string; defaultClass?: string; voidEl?: boolean }
|
|
841
841
|
|
|
842
|
-
// === v0.0.
|
|
842
|
+
// === v0.0.5: Complete HTML5 map; Col = void <col>; Column = grid div; added SubHeading, CardGrid ===
|
|
843
843
|
const BUILTIN_MAP: Record<string, BuiltinInfo> = {
|
|
844
844
|
// ── Structural ──────────────────────────────────────────
|
|
845
845
|
Main: { tag: "main" },
|
|
@@ -857,12 +857,12 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
|
|
|
857
857
|
Flex: { tag: "div", defaultClass: "flex" },
|
|
858
858
|
Stack: { tag: "div", defaultClass: "stack" },
|
|
859
859
|
Row: { tag: "div", defaultClass: "row" },
|
|
860
|
-
// === v0.0.
|
|
860
|
+
// === v0.0.5: Column = grid helper div; Col = HTML void table col ===
|
|
861
861
|
Column: { tag: "div", defaultClass: "col" },
|
|
862
862
|
// ── Typography ────────────────────────────────────────────
|
|
863
863
|
Heading: { tag: "h1" }, // resolved dynamically by level attr
|
|
864
864
|
Paragraph: { tag: "p" },
|
|
865
|
-
// === v0.0.
|
|
865
|
+
// === v0.0.5: SubHeading convenience component ===
|
|
866
866
|
SubHeading: { tag: "p", defaultClass: "subheading" },
|
|
867
867
|
Lead: { tag: "p", defaultClass: "lead" },
|
|
868
868
|
Small: { tag: "small" },
|
|
@@ -929,7 +929,7 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
|
|
|
929
929
|
Wbr: { tag: "wbr", voidEl: true },
|
|
930
930
|
Source: { tag: "source", voidEl: true },
|
|
931
931
|
Embed: { tag: "embed", voidEl: true },
|
|
932
|
-
// === v0.0.
|
|
932
|
+
// === v0.0.5: Col = HTML void table column (NOT the grid div) ===
|
|
933
933
|
Col: { tag: "col", voidEl: true },
|
|
934
934
|
Area: { tag: "area", voidEl: true },
|
|
935
935
|
// ── Lists ─────────────────────────────────────────────────
|
|
@@ -949,9 +949,9 @@ const BUILTIN_MAP: Record<string, BuiltinInfo> = {
|
|
|
949
949
|
Template: { tag: "template" },
|
|
950
950
|
Slot: { tag: "slot" },
|
|
951
951
|
NoScript: { tag: "noscript" },
|
|
952
|
-
// === v0.0.
|
|
952
|
+
// === v0.0.5: CardGrid convenience layout wrapper ===
|
|
953
953
|
CardGrid: { tag: "div", defaultClass: "card-grid" },
|
|
954
|
-
// === v0.0.
|
|
954
|
+
// === v0.0.5: RawHTML marker — handled specially in renderCompUse ===
|
|
955
955
|
RawHTML: { tag: "__RAW__" },
|
|
956
956
|
};
|
|
957
957
|
|
|
@@ -970,7 +970,7 @@ function eventAttrName(name: string): string | null {
|
|
|
970
970
|
// SECTION 7: STYLE PROCESSOR
|
|
971
971
|
// ═══════════════════════════════════════════════════════════
|
|
972
972
|
|
|
973
|
-
// === v0.0.
|
|
973
|
+
// === v0.0.5: Completely rewritten convertCSSProps — bulletproof line-by-line approach ===
|
|
974
974
|
// Rules:
|
|
975
975
|
// - Match lines of the form: [whitespace] camelCaseProp : "value" [;]
|
|
976
976
|
// - Convert property name camelCase → kebab-case
|
|
@@ -1022,7 +1022,7 @@ function convertCSSProps(css: string): string {
|
|
|
1022
1022
|
}).join("\n");
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
|
-
// === v0.0.
|
|
1025
|
+
// === v0.0.5: processStyleBlock — correct order: interpolate {param} → camelCase convert → SCSS → scope ===
|
|
1026
1026
|
function processStyleBlock(
|
|
1027
1027
|
block: StyleBlock,
|
|
1028
1028
|
hash: string,
|
|
@@ -1208,7 +1208,7 @@ function renderAttr(attr: Attr, paramMap: Map<string, string>): string {
|
|
|
1208
1208
|
return `${name}="${escAttr(raw)}"`;
|
|
1209
1209
|
}
|
|
1210
1210
|
|
|
1211
|
-
// === v0.0.
|
|
1211
|
+
// === v0.0.5: renderText — "$slot" protected from double-escaping via placeholder approach ===
|
|
1212
1212
|
function renderText(text: string, params: Map<string, string>): string {
|
|
1213
1213
|
// Map of placeholder → raw HTML for slot-like params
|
|
1214
1214
|
const rawSlots = new Map<string, string>();
|
|
@@ -1246,7 +1246,7 @@ function renderText(text: string, params: Map<string, string>): string {
|
|
|
1246
1246
|
// Step 5: Restore \$ → $
|
|
1247
1247
|
s = s.replace(/\x00DOLLAR\x00/g, "$");
|
|
1248
1248
|
|
|
1249
|
-
// === v0.0.
|
|
1249
|
+
// === v0.0.5: Warn about {identifier} patterns remaining after substitution ===
|
|
1250
1250
|
const braceRe = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
1251
1251
|
let m: RegExpExecArray | null;
|
|
1252
1252
|
while ((m = braceRe.exec(s)) !== null) {
|
|
@@ -1282,7 +1282,7 @@ function renderCompUse(
|
|
|
1282
1282
|
params: Map<string, string>,
|
|
1283
1283
|
depth: number,
|
|
1284
1284
|
): string {
|
|
1285
|
-
// === v0.0.
|
|
1285
|
+
// === v0.0.5: RawHTML — output content attribute verbatim, no wrapping tag, no scoping ===
|
|
1286
1286
|
if (use.name === "RawHTML") {
|
|
1287
1287
|
const ca = use.attrs.find(a => a.name === "content");
|
|
1288
1288
|
if (!ca || !ca.value) return "";
|
|
@@ -1327,7 +1327,7 @@ function renderCompUse(
|
|
|
1327
1327
|
const classes = [defaultClass, userClass].filter(Boolean).join(" ");
|
|
1328
1328
|
if (classes) attrParts.push(`class="${escAttr(classes)}"`);
|
|
1329
1329
|
|
|
1330
|
-
// === v0.0.
|
|
1330
|
+
// === v0.0.5: Default type="button" for <button> elements ===
|
|
1331
1331
|
if (tag === "button" && !use.attrs.some(a => a.name === "type")) {
|
|
1332
1332
|
attrParts.push(`type="button"`);
|
|
1333
1333
|
}
|
|
@@ -1389,7 +1389,7 @@ function expandUserComp(
|
|
|
1389
1389
|
const slotHTML = use.children.map(c => renderChild(c, ctx, params, depth)).join("");
|
|
1390
1390
|
local.set("slot", slotHTML);
|
|
1391
1391
|
|
|
1392
|
-
// === v0.0.
|
|
1392
|
+
// === v0.0.5: Process component style blocks with instance params and push to extraCSS ===
|
|
1393
1393
|
for (const block of def.styles) {
|
|
1394
1394
|
ctx.extraCSS.push(processStyleBlock(block, ctx.scopeHash, local));
|
|
1395
1395
|
}
|
|
@@ -1490,7 +1490,7 @@ function buildHeadData(meta: MetaEntry[]): HeadData {
|
|
|
1490
1490
|
return { title, fav, lang, charset, viewport, metaTags, metaProps };
|
|
1491
1491
|
}
|
|
1492
1492
|
|
|
1493
|
-
// === v0.0.
|
|
1493
|
+
// === v0.0.5: .jpg and .jpeg return "image/jpeg" ===
|
|
1494
1494
|
function faviconType(p: string): string {
|
|
1495
1495
|
const ext = path.extname(p).toLowerCase();
|
|
1496
1496
|
switch (ext) {
|
|
@@ -1553,7 +1553,7 @@ function compileFile(filePath: string, opts: CompileOptions): string | null {
|
|
|
1553
1553
|
const { allDefs, customEls, cssLinks, jsLinks } = resolveImports(file, cfg);
|
|
1554
1554
|
const hash = fnv1a(absPath);
|
|
1555
1555
|
|
|
1556
|
-
// === v0.0.
|
|
1556
|
+
// === v0.0.5: extraCSS collected during rendering (per-instance component styles) ===
|
|
1557
1557
|
const ctx: CompileCtx = {
|
|
1558
1558
|
allDefs, customEls, cssLinks, jsLinks,
|
|
1559
1559
|
scopeHash: hash, pageFile: absPath, extraCSS: [],
|
|
@@ -1583,7 +1583,13 @@ function compileFile(filePath: string, opts: CompileOptions): string | null {
|
|
|
1583
1583
|
return fs.existsSync(base) ? path.basename(base) : undefined;
|
|
1584
1584
|
})();
|
|
1585
1585
|
|
|
1586
|
-
|
|
1586
|
+
// Convert CSS absolute paths to relative paths from the HTML output
|
|
1587
|
+
const relativeCssLinks = cssLinks.map(css => {
|
|
1588
|
+
const rel = path.relative(path.dirname(absPath), css).replace(/\\/g, "/");
|
|
1589
|
+
return rel.startsWith(".") ? rel : "./" + rel;
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
const head = renderHead(headData, relativeCssLinks, jsLinks, scopedCSS, companionJS);
|
|
1587
1593
|
const scriptTags: string[] = [];
|
|
1588
1594
|
|
|
1589
1595
|
if (componentScripts.length > 0) {
|
|
@@ -1618,7 +1624,7 @@ function minifyHTML(html: string): string {
|
|
|
1618
1624
|
// SECTION 12: FILE DISCOVERY & ASSET COPY
|
|
1619
1625
|
// ═══════════════════════════════════════════════════════════
|
|
1620
1626
|
|
|
1621
|
-
// === v0.0.
|
|
1627
|
+
// === v0.0.5: findSinthPages skips outDir to prevent infinite watcher loops ===
|
|
1622
1628
|
function findSinthPages(dir: string, outDir?: string): string[] {
|
|
1623
1629
|
const results: string[] = [];
|
|
1624
1630
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -1634,7 +1640,7 @@ function findSinthPages(dir: string, outDir?: string): string[] {
|
|
|
1634
1640
|
return results;
|
|
1635
1641
|
}
|
|
1636
1642
|
|
|
1637
|
-
// === v0.0.
|
|
1643
|
+
// === v0.0.5: Recursive directory copy for assets/ ===
|
|
1638
1644
|
function copyDir(src: string, dest: string): void {
|
|
1639
1645
|
if (!fs.existsSync(src)) return;
|
|
1640
1646
|
fs.mkdirSync(dest, { recursive: true });
|
|
@@ -1658,7 +1664,7 @@ const LIVE_RELOAD_SCRIPT = `<script>
|
|
|
1658
1664
|
})();
|
|
1659
1665
|
</script>`;
|
|
1660
1666
|
|
|
1661
|
-
async function startDevServer(opts: CompileOptions & { port: number }) {
|
|
1667
|
+
async function startDevServer(opts: CompileOptions & { port: number, files?: string[] }) {
|
|
1662
1668
|
const clients: http.ServerResponse[] = [];
|
|
1663
1669
|
let debounce: ReturnType<typeof setTimeout> | null = null;
|
|
1664
1670
|
const cache = new Map<string, string>();
|
|
@@ -1669,7 +1675,9 @@ async function startDevServer(opts: CompileOptions & { port: number }) {
|
|
|
1669
1675
|
|
|
1670
1676
|
function compileAll(): void {
|
|
1671
1677
|
cache.clear();
|
|
1672
|
-
const pages =
|
|
1678
|
+
const pages = (opts.files && opts.files.length > 0)
|
|
1679
|
+
? opts.files.filter(f => fs.existsSync(f))
|
|
1680
|
+
: findSinthPages(opts.projectRoot, opts.outDir);
|
|
1673
1681
|
for (const p of pages) {
|
|
1674
1682
|
try {
|
|
1675
1683
|
const html = compileFile(p, { ...opts, checkOnly: false });
|
|
@@ -1691,19 +1699,43 @@ async function startDevServer(opts: CompileOptions & { port: number }) {
|
|
|
1691
1699
|
|
|
1692
1700
|
compileAll();
|
|
1693
1701
|
|
|
1694
|
-
// === v0.0.
|
|
1702
|
+
// === v0.0.5: Watch ignores changes whose absolute path is inside outDir ===
|
|
1695
1703
|
const resolvedOut = path.resolve(opts.outDir);
|
|
1704
|
+
// Use fs.watch with fs.watchFile fallback for Windows reliability
|
|
1705
|
+
let watchReady = false;
|
|
1696
1706
|
try {
|
|
1697
1707
|
fs.watch(opts.projectRoot, { recursive: true }, (_, filename) => {
|
|
1698
1708
|
if (!filename) return;
|
|
1699
1709
|
const abs = path.resolve(opts.projectRoot, filename);
|
|
1700
|
-
// Skip events from inside the output directory to prevent infinite loops
|
|
1701
1710
|
if (abs.startsWith(resolvedOut + path.sep) || abs === resolvedOut) return;
|
|
1702
|
-
|
|
1703
|
-
|
|
1711
|
+
process.stdout.write(`\x1b[36m[sinth]\x1b[0m Changed: ${filename}\n`);
|
|
1712
|
+
compileAll();
|
|
1713
|
+
notify();
|
|
1704
1714
|
});
|
|
1715
|
+
watchReady = true;
|
|
1705
1716
|
} catch {}
|
|
1706
1717
|
|
|
1718
|
+
if (!watchReady) {
|
|
1719
|
+
// Fallback: poll for changes every 500ms
|
|
1720
|
+
const poller = setInterval(() => {
|
|
1721
|
+
const pages = (opts.files && opts.files.length > 0)
|
|
1722
|
+
? opts.files
|
|
1723
|
+
: findSinthPages(opts.projectRoot, opts.outDir);
|
|
1724
|
+
for (const p of pages) {
|
|
1725
|
+
const stat = fs.statSync(p);
|
|
1726
|
+
const key = p + ":" + stat.mtimeMs;
|
|
1727
|
+
if (cache.get("__mtime__" + p) !== key) {
|
|
1728
|
+
cache.set("__mtime__" + p, key);
|
|
1729
|
+
process.stdout.write(`\x1b[36m[sinth]\x1b[0m Changed: ${path.relative(opts.projectRoot, p)}\n`);
|
|
1730
|
+
compileAll();
|
|
1731
|
+
notify();
|
|
1732
|
+
break;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}, 500);
|
|
1736
|
+
process.on("exit", () => clearInterval(poller));
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1707
1739
|
const EXT_TYPES: Record<string, string> = {
|
|
1708
1740
|
".css": "text/css", ".js": "application/javascript",
|
|
1709
1741
|
".png": "image/png", ".svg": "image/svg+xml",
|
|
@@ -1787,11 +1819,30 @@ async function main(): Promise<void> {
|
|
|
1787
1819
|
const minify = args.includes("--prod") || Boolean(cfg.minify);
|
|
1788
1820
|
const libraryPaths = (cfg.libraryPaths as string[] | undefined) ?? [path.join(cwd, "libraries")];
|
|
1789
1821
|
|
|
1822
|
+
// Remove flag values from args so they don't get treated as .sinth files
|
|
1823
|
+
const flagValues = new Set<string>();
|
|
1824
|
+
if (outDirIdx !== -1) flagValues.add(args[outDirIdx + 1]);
|
|
1825
|
+
if (portIdx !== -1) flagValues.add(args[portIdx + 1]);
|
|
1826
|
+
const cleanArgs = args.filter(a => !a.startsWith("--") && !flagValues.has(a));
|
|
1827
|
+
|
|
1790
1828
|
const opts: CompileOptions = { projectRoot: cwd, outDir, libraryPaths, minify, checkOnly: false };
|
|
1791
1829
|
|
|
1792
1830
|
switch (command) {
|
|
1793
1831
|
case "build": {
|
|
1794
|
-
const
|
|
1832
|
+
const nonSinth = cleanArgs.filter(a => !a.endsWith(".sinth"));
|
|
1833
|
+
if (nonSinth.length > 0) {
|
|
1834
|
+
process.stdout.write(`\x1b[33mSkipping non-.sinth files:\x1b[0m ${nonSinth.join(", ")}\n`);
|
|
1835
|
+
}
|
|
1836
|
+
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
1837
|
+
const pages = fileArgs.length > 0
|
|
1838
|
+
? fileArgs.map(f => path.resolve(cwd, f)).filter(f => fs.existsSync(f))
|
|
1839
|
+
: findSinthPages(cwd, outDir);
|
|
1840
|
+
|
|
1841
|
+
if (pages.length === 0) {
|
|
1842
|
+
process.stdout.write("No .sinth files found.\n");
|
|
1843
|
+
process.exit(0);
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1795
1846
|
let hadError = false, built = 0;
|
|
1796
1847
|
|
|
1797
1848
|
for (const p of pages) {
|
|
@@ -1810,7 +1861,7 @@ async function main(): Promise<void> {
|
|
|
1810
1861
|
}
|
|
1811
1862
|
}
|
|
1812
1863
|
|
|
1813
|
-
// === v0.0.
|
|
1864
|
+
// === v0.0.5: Copy assets/ to outDir/assets/ ===
|
|
1814
1865
|
const assetsIn = path.join(cwd, "assets");
|
|
1815
1866
|
const assetsOut = path.join(outDir, "assets");
|
|
1816
1867
|
if (fs.existsSync(assetsIn)) {
|
|
@@ -1824,7 +1875,11 @@ async function main(): Promise<void> {
|
|
|
1824
1875
|
}
|
|
1825
1876
|
|
|
1826
1877
|
case "dev": {
|
|
1827
|
-
|
|
1878
|
+
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
1879
|
+
const files = fileArgs.length > 0
|
|
1880
|
+
? fileArgs.map(f => path.resolve(cwd, f)).filter(f => fs.existsSync(f))
|
|
1881
|
+
: undefined;
|
|
1882
|
+
await startDevServer({ ...opts, port, files });
|
|
1828
1883
|
break;
|
|
1829
1884
|
}
|
|
1830
1885
|
|
|
@@ -1845,11 +1900,11 @@ async function main(): Promise<void> {
|
|
|
1845
1900
|
break;
|
|
1846
1901
|
}
|
|
1847
1902
|
|
|
1848
|
-
// === v0.0.
|
|
1903
|
+
// === v0.0.5: sinth version command ===
|
|
1849
1904
|
case "version":
|
|
1850
1905
|
case "--version":
|
|
1851
1906
|
case "-v": {
|
|
1852
|
-
process.stdout.write("Sinth Compiler v0.0.
|
|
1907
|
+
process.stdout.write("Sinth Compiler v0.0.5\n");
|
|
1853
1908
|
break;
|
|
1854
1909
|
}
|
|
1855
1910
|
|
|
@@ -1862,7 +1917,7 @@ async function main(): Promise<void> {
|
|
|
1862
1917
|
|
|
1863
1918
|
default: {
|
|
1864
1919
|
process.stdout.write(`
|
|
1865
|
-
\x1b[1mSinth Compiler v0.0.
|
|
1920
|
+
\x1b[1mSinth Compiler v0.0.5\x1b[0m
|
|
1866
1921
|
|
|
1867
1922
|
\x1b[1mCommands:\x1b[0m
|
|
1868
1923
|
sinth build [--out ./dist] [--prod] Compile all .sinth pages + copy assets/
|