@yannosay/sinth 1.8.1 → 1.8.2
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/LICENSE +660 -660
- package/README.md +548 -548
- package/package.json +45 -45
- package/src/cli.ts +338 -338
- package/src/core/builtins.ts +116 -116
- package/src/core/compiler.ts +1706 -1706
- package/src/core/expr.ts +88 -88
- package/src/core/head-builder.ts +86 -86
- package/src/core/lexer.ts +275 -275
- package/src/core/parser.ts +1523 -1523
- package/src/core/runtime/custom-element.ts +134 -134
- package/src/core/runtime/functions.ts +46 -46
- package/src/core/runtime/helpers.ts +332 -332
- package/src/core/runtime/render.ts +136 -136
- package/src/core/style-processor.ts +299 -299
- package/src/core/types.ts +192 -192
- package/src/resolver.ts +149 -149
- package/src/server.ts +128 -128
- package/src/utils.ts +76 -76
- package/tsconfig.json +26 -26
package/src/utils.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { Literal, SinthWarning } from "./core/types.ts";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function fnv1a(s: string): string {
|
|
5
|
-
let h = 0x811c9dc5;
|
|
6
|
-
for (let i = 0; i < s.length; i++) {
|
|
7
|
-
h ^= s.charCodeAt(i);
|
|
8
|
-
h = Math.imul(h, 0x01000193) >>> 0;
|
|
9
|
-
}
|
|
10
|
-
return h.toString(16).padStart(8, "0").slice(0, 8);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function camelToKebab(s: string): string {
|
|
14
|
-
const vp = s.match(/^(Webkit|Moz|Ms)(.+)$/);
|
|
15
|
-
if (vp) return `-${vp[1].toLowerCase()}-${camelToKebab(vp[2])}`;
|
|
16
|
-
return s.replace(/([A-Z])/g, m => `-${m.toLowerCase()}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function tagNameToPascal(tag: string): string {
|
|
20
|
-
return tag.split("-").map(p => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function esc(s: string): string {
|
|
24
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function escAttr(s: string): string {
|
|
28
|
-
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function litToString(lit: Literal): string {
|
|
32
|
-
switch (lit.kind) {
|
|
33
|
-
case "str": return lit.value;
|
|
34
|
-
case "num": return String(lit.value);
|
|
35
|
-
case "bool": return String(lit.value);
|
|
36
|
-
case "null": return "";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function interpolateAttr(text: string, params: Map<string, string>): string {
|
|
41
|
-
let s = text.replace(/\\\{/g, "\x00LB\x00");
|
|
42
|
-
s = s.replace(/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (_, n) => params.get(n) ?? `{${n}}`);
|
|
43
|
-
return s.replace(/\x00LB\x00/g, "{");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function renderText(text: string, params: Map<string, string>): string {
|
|
47
|
-
const rawSlots = new Map<string, string>();
|
|
48
|
-
let counter = 0;
|
|
49
|
-
|
|
50
|
-
let s = text.replace(/\\\$/g, "\x00DOLLAR\x00");
|
|
51
|
-
|
|
52
|
-
s = s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, n) => {
|
|
53
|
-
const val = params.get(n);
|
|
54
|
-
if (val === undefined) return `$${n}`;
|
|
55
|
-
if (n === "slot") {
|
|
56
|
-
const ph = `\x00RAW${counter++}\x00`;
|
|
57
|
-
rawSlots.set(ph, val);
|
|
58
|
-
return ph;
|
|
59
|
-
}
|
|
60
|
-
return val;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
s = esc(s);
|
|
64
|
-
|
|
65
|
-
for (const [ph, val] of rawSlots) s = s.replace(ph, val);
|
|
66
|
-
s = s.replace(/\x00DOLLAR\x00/g, "$");
|
|
67
|
-
|
|
68
|
-
const braceRe = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
69
|
-
let m: RegExpExecArray | null;
|
|
70
|
-
while ((m = braceRe.exec(s)) !== null) {
|
|
71
|
-
SinthWarning.emit(
|
|
72
|
-
`Use $param for text interpolation; {param} is for attributes. Found '${m[0]}' in text.`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return s;
|
|
1
|
+
import { Literal, SinthWarning } from "./core/types.ts";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function fnv1a(s: string): string {
|
|
5
|
+
let h = 0x811c9dc5;
|
|
6
|
+
for (let i = 0; i < s.length; i++) {
|
|
7
|
+
h ^= s.charCodeAt(i);
|
|
8
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
9
|
+
}
|
|
10
|
+
return h.toString(16).padStart(8, "0").slice(0, 8);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function camelToKebab(s: string): string {
|
|
14
|
+
const vp = s.match(/^(Webkit|Moz|Ms)(.+)$/);
|
|
15
|
+
if (vp) return `-${vp[1].toLowerCase()}-${camelToKebab(vp[2])}`;
|
|
16
|
+
return s.replace(/([A-Z])/g, m => `-${m.toLowerCase()}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function tagNameToPascal(tag: string): string {
|
|
20
|
+
return tag.split("-").map(p => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function esc(s: string): string {
|
|
24
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function escAttr(s: string): string {
|
|
28
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function litToString(lit: Literal): string {
|
|
32
|
+
switch (lit.kind) {
|
|
33
|
+
case "str": return lit.value;
|
|
34
|
+
case "num": return String(lit.value);
|
|
35
|
+
case "bool": return String(lit.value);
|
|
36
|
+
case "null": return "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function interpolateAttr(text: string, params: Map<string, string>): string {
|
|
41
|
+
let s = text.replace(/\\\{/g, "\x00LB\x00");
|
|
42
|
+
s = s.replace(/\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (_, n) => params.get(n) ?? `{${n}}`);
|
|
43
|
+
return s.replace(/\x00LB\x00/g, "{");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function renderText(text: string, params: Map<string, string>): string {
|
|
47
|
+
const rawSlots = new Map<string, string>();
|
|
48
|
+
let counter = 0;
|
|
49
|
+
|
|
50
|
+
let s = text.replace(/\\\$/g, "\x00DOLLAR\x00");
|
|
51
|
+
|
|
52
|
+
s = s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, n) => {
|
|
53
|
+
const val = params.get(n);
|
|
54
|
+
if (val === undefined) return `$${n}`;
|
|
55
|
+
if (n === "slot") {
|
|
56
|
+
const ph = `\x00RAW${counter++}\x00`;
|
|
57
|
+
rawSlots.set(ph, val);
|
|
58
|
+
return ph;
|
|
59
|
+
}
|
|
60
|
+
return val;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
s = esc(s);
|
|
64
|
+
|
|
65
|
+
for (const [ph, val] of rawSlots) s = s.replace(ph, val);
|
|
66
|
+
s = s.replace(/\x00DOLLAR\x00/g, "$");
|
|
67
|
+
|
|
68
|
+
const braceRe = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
|
|
69
|
+
let m: RegExpExecArray | null;
|
|
70
|
+
while ((m = braceRe.exec(s)) !== null) {
|
|
71
|
+
SinthWarning.emit(
|
|
72
|
+
`Use $param for text interpolation; {param} is for attributes. Found '${m[0]}' in text.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return s;
|
|
77
77
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"noImplicitAny": true,
|
|
12
|
-
"strictNullChecks": true,
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"types": ["node"],
|
|
16
|
-
"typeRoots": ["./node_modules/@types", "../node_modules/@types"]
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules", "dist"],
|
|
20
|
-
"ts-node": {
|
|
21
|
-
"compilerOptions": {
|
|
22
|
-
"module": "commonjs"
|
|
23
|
-
},
|
|
24
|
-
"esm": false,
|
|
25
|
-
"transpileOnly": true
|
|
26
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020"],
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"noImplicitAny": true,
|
|
12
|
+
"strictNullChecks": true,
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"types": ["node"],
|
|
16
|
+
"typeRoots": ["./node_modules/@types", "../node_modules/@types"]
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"],
|
|
19
|
+
"exclude": ["node_modules", "dist"],
|
|
20
|
+
"ts-node": {
|
|
21
|
+
"compilerOptions": {
|
|
22
|
+
"module": "commonjs"
|
|
23
|
+
},
|
|
24
|
+
"esm": false,
|
|
25
|
+
"transpileOnly": true
|
|
26
|
+
}
|
|
27
27
|
}
|