@yannosay/sinth 4.0.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.
- package/CHANGELOG.md +83 -0
- package/DOCS.md +1359 -0
- package/README.md +83 -74
- package/bin/sinth.js +2 -1
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.js +74 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +437 -0
- package/dist/cli/templates.d.ts +10 -0
- package/dist/cli/templates.js +193 -0
- package/dist/cli/ui.d.ts +28 -0
- package/dist/cli/ui.js +61 -0
- package/dist/cli/update-check.d.ts +2 -0
- package/dist/cli/update-check.js +124 -0
- package/dist/compiler/ast.d.ts +315 -0
- package/dist/compiler/ast.js +4 -0
- package/dist/compiler/codegen.d.ts +143 -0
- package/dist/compiler/codegen.js +1326 -0
- package/dist/compiler/diagnostics.d.ts +36 -0
- package/dist/compiler/diagnostics.js +142 -0
- package/dist/compiler/elements.d.ts +14 -0
- package/dist/compiler/elements.js +78 -0
- package/dist/compiler/globals.d.ts +2 -0
- package/dist/compiler/globals.js +27 -0
- package/dist/compiler/html.d.ts +37 -0
- package/dist/compiler/html.js +152 -0
- package/dist/compiler/lexer.d.ts +42 -0
- package/dist/compiler/lexer.js +404 -0
- package/dist/compiler/parser.d.ts +95 -0
- package/dist/compiler/parser.js +1374 -0
- package/dist/compiler/prerender.d.ts +72 -0
- package/dist/compiler/prerender.js +910 -0
- package/dist/compiler/script-analysis.d.ts +6 -0
- package/dist/compiler/script-analysis.js +106 -0
- package/dist/compiler/style.d.ts +39 -0
- package/dist/compiler/style.js +463 -0
- package/dist/deploy/cloudflare.d.ts +9 -0
- package/dist/deploy/cloudflare.js +111 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +23 -0
- package/dist/project/build.d.ts +31 -0
- package/dist/project/build.js +425 -0
- package/dist/project/config.d.ts +33 -0
- package/dist/project/config.js +142 -0
- package/dist/project/project.d.ts +74 -0
- package/dist/project/project.js +535 -0
- package/dist/runtime/index.d.ts +68 -0
- package/dist/runtime/index.js +912 -0
- package/dist/server/client.d.ts +1 -0
- package/dist/server/client.js +112 -0
- package/dist/server/dev.d.ts +8 -0
- package/dist/server/dev.js +244 -0
- package/dist/server/preview.d.ts +6 -0
- package/dist/server/preview.js +106 -0
- package/dist/server/static.d.ts +10 -0
- package/dist/server/static.js +136 -0
- package/lib/ui/index.sinth +436 -0
- package/package.json +33 -15
- package/schema/sinth.config.schema.json +54 -0
- package/dist/browser/compile.js +0 -62
- package/dist/cli.js +0 -509
- package/dist/core/builtins.js +0 -117
- package/dist/core/cli-compiler.js +0 -683
- package/dist/core/compiler.js +0 -1428
- package/dist/core/expr.js +0 -125
- package/dist/core/head-builder.js +0 -130
- package/dist/core/lexer.js +0 -414
- package/dist/core/parser.js +0 -1665
- package/dist/core/runtime/custom-element.js +0 -81
- package/dist/core/runtime/functions.js +0 -99
- package/dist/core/runtime/helpers.js +0 -347
- package/dist/core/runtime/render.js +0 -136
- package/dist/core/style-processor.js +0 -317
- package/dist/core/types.js +0 -93
- package/dist/resolver.js +0 -175
- package/dist/server.js +0 -174
- package/dist/update-check.js +0 -109
- package/dist/utils.js +0 -80
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Loc {
|
|
2
|
+
file: string;
|
|
3
|
+
line: number;
|
|
4
|
+
col: number;
|
|
5
|
+
}
|
|
6
|
+
export interface Span extends Loc {
|
|
7
|
+
length?: number;
|
|
8
|
+
}
|
|
9
|
+
export type Severity = "error" | "warning";
|
|
10
|
+
export interface Diagnostic {
|
|
11
|
+
severity: Severity;
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
loc?: Span;
|
|
15
|
+
hint?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function registerSource(file: string, source: string): void;
|
|
18
|
+
export declare function getSource(file: string): string | undefined;
|
|
19
|
+
export declare class SinthError extends Error {
|
|
20
|
+
readonly diagnostic: Diagnostic;
|
|
21
|
+
constructor(code: string, message: string, loc?: Span, hint?: string);
|
|
22
|
+
get loc(): Span | undefined;
|
|
23
|
+
get code(): string;
|
|
24
|
+
format(color?: boolean): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class DiagnosticBag {
|
|
27
|
+
readonly items: Diagnostic[];
|
|
28
|
+
warn(code: string, message: string, loc?: Span, hint?: string): void;
|
|
29
|
+
error(code: string, message: string, loc?: Span, hint?: string): never;
|
|
30
|
+
get warnings(): Diagnostic[];
|
|
31
|
+
}
|
|
32
|
+
export declare function codeFrame(loc: Span, color?: boolean, context?: number): string;
|
|
33
|
+
export declare function setDisplayRoot(root: string | undefined): void;
|
|
34
|
+
export declare function formatDiagnostic(d: Diagnostic, color?: boolean): string;
|
|
35
|
+
export declare function levenshtein(a: string, b: string): number;
|
|
36
|
+
export declare function suggest(name: string, candidates: Iterable<string>): string | undefined;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiagnosticBag = exports.SinthError = void 0;
|
|
4
|
+
exports.registerSource = registerSource;
|
|
5
|
+
exports.getSource = getSource;
|
|
6
|
+
exports.codeFrame = codeFrame;
|
|
7
|
+
exports.setDisplayRoot = setDisplayRoot;
|
|
8
|
+
exports.formatDiagnostic = formatDiagnostic;
|
|
9
|
+
exports.levenshtein = levenshtein;
|
|
10
|
+
exports.suggest = suggest;
|
|
11
|
+
const sourceCache = new Map();
|
|
12
|
+
function registerSource(file, source) {
|
|
13
|
+
sourceCache.set(file, source);
|
|
14
|
+
}
|
|
15
|
+
function getSource(file) {
|
|
16
|
+
return sourceCache.get(file);
|
|
17
|
+
}
|
|
18
|
+
class SinthError extends Error {
|
|
19
|
+
diagnostic;
|
|
20
|
+
constructor(code, message, loc, hint) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "SinthError";
|
|
23
|
+
this.diagnostic = { severity: "error", code, message, loc, hint };
|
|
24
|
+
Object.setPrototypeOf(this, SinthError.prototype);
|
|
25
|
+
}
|
|
26
|
+
get loc() {
|
|
27
|
+
return this.diagnostic.loc;
|
|
28
|
+
}
|
|
29
|
+
get code() {
|
|
30
|
+
return this.diagnostic.code;
|
|
31
|
+
}
|
|
32
|
+
format(color = false) {
|
|
33
|
+
return formatDiagnostic(this.diagnostic, color);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.SinthError = SinthError;
|
|
37
|
+
class DiagnosticBag {
|
|
38
|
+
items = [];
|
|
39
|
+
warn(code, message, loc, hint) {
|
|
40
|
+
const key = `${code}|${message}|${loc?.file}|${loc?.line}|${loc?.col}`;
|
|
41
|
+
if (this.items.some(d => `${d.code}|${d.message}|${d.loc?.file}|${d.loc?.line}|${d.loc?.col}` === key))
|
|
42
|
+
return;
|
|
43
|
+
this.items.push({ severity: "warning", code, message, loc, hint });
|
|
44
|
+
}
|
|
45
|
+
error(code, message, loc, hint) {
|
|
46
|
+
throw new SinthError(code, message, loc, hint);
|
|
47
|
+
}
|
|
48
|
+
get warnings() {
|
|
49
|
+
return this.items.filter(d => d.severity === "warning");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.DiagnosticBag = DiagnosticBag;
|
|
53
|
+
const ANSI = {
|
|
54
|
+
reset: "\u001b[0m",
|
|
55
|
+
bold: "\u001b[1m",
|
|
56
|
+
dim: "\u001b[2m",
|
|
57
|
+
red: "\u001b[31m",
|
|
58
|
+
yellow: "\u001b[33m",
|
|
59
|
+
cyan: "\u001b[36m",
|
|
60
|
+
gray: "\u001b[90m",
|
|
61
|
+
};
|
|
62
|
+
function codeFrame(loc, color = false, context = 2) {
|
|
63
|
+
const source = sourceCache.get(loc.file);
|
|
64
|
+
if (source === undefined)
|
|
65
|
+
return "";
|
|
66
|
+
const lines = source.split(/\r?\n/);
|
|
67
|
+
const start = Math.max(1, loc.line - context);
|
|
68
|
+
const end = Math.min(lines.length, loc.line + context);
|
|
69
|
+
const width = String(end).length;
|
|
70
|
+
const paint = (code, s) => (color ? code + s + ANSI.reset : s);
|
|
71
|
+
const out = [];
|
|
72
|
+
for (let n = start; n <= end; n++) {
|
|
73
|
+
const marker = n === loc.line ? ">" : " ";
|
|
74
|
+
const gutter = `${marker} ${String(n).padStart(width)} | `;
|
|
75
|
+
const text = (lines[n - 1] ?? "").replace(/\t/g, " ");
|
|
76
|
+
out.push(n === loc.line ? paint(ANSI.bold, gutter) + text : paint(ANSI.gray, gutter + text));
|
|
77
|
+
if (n === loc.line) {
|
|
78
|
+
const raw = lines[n - 1] ?? "";
|
|
79
|
+
const prefix = raw.slice(0, Math.max(0, loc.col - 1)).replace(/\t/g, " ");
|
|
80
|
+
const caret = "^".repeat(Math.max(1, loc.length ?? 1));
|
|
81
|
+
out.push(" ".repeat(width + 2) + paint(ANSI.gray, "| ") + " ".repeat(prefix.length) + paint(ANSI.red, caret));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out.join("\n");
|
|
85
|
+
}
|
|
86
|
+
let displayRoot;
|
|
87
|
+
function setDisplayRoot(root) {
|
|
88
|
+
displayRoot = root;
|
|
89
|
+
}
|
|
90
|
+
function displayPath(file) {
|
|
91
|
+
if (!displayRoot)
|
|
92
|
+
return file;
|
|
93
|
+
const norm = (p) => p.replace(/\\/g, "/");
|
|
94
|
+
const f = norm(file);
|
|
95
|
+
const r = norm(displayRoot).replace(/\/$/, "") + "/";
|
|
96
|
+
return f.startsWith(r) ? f.slice(r.length) : file;
|
|
97
|
+
}
|
|
98
|
+
function formatDiagnostic(d, color = false) {
|
|
99
|
+
const paint = (code, s) => (color ? code + s + ANSI.reset : s);
|
|
100
|
+
const head = d.severity === "error" ? paint(ANSI.red + ANSI.bold, `error[${d.code}]`) : paint(ANSI.yellow + ANSI.bold, `warning[${d.code}]`);
|
|
101
|
+
const parts = [`${head}: ${d.message}`];
|
|
102
|
+
if (d.loc) {
|
|
103
|
+
parts.push(paint(ANSI.cyan, ` --> ${displayPath(d.loc.file)}:${d.loc.line}:${d.loc.col}`));
|
|
104
|
+
const frame = codeFrame(d.loc, color);
|
|
105
|
+
if (frame)
|
|
106
|
+
parts.push(frame);
|
|
107
|
+
}
|
|
108
|
+
if (d.hint)
|
|
109
|
+
parts.push(paint(ANSI.dim, ` hint: ${d.hint}`));
|
|
110
|
+
return parts.join("\n");
|
|
111
|
+
}
|
|
112
|
+
function levenshtein(a, b) {
|
|
113
|
+
if (a === b)
|
|
114
|
+
return 0;
|
|
115
|
+
if (!a.length)
|
|
116
|
+
return b.length;
|
|
117
|
+
if (!b.length)
|
|
118
|
+
return a.length;
|
|
119
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
120
|
+
for (let i = 1; i <= a.length; i++) {
|
|
121
|
+
const curr = [i];
|
|
122
|
+
for (let j = 1; j <= b.length; j++) {
|
|
123
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
124
|
+
curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
|
|
125
|
+
}
|
|
126
|
+
prev = curr;
|
|
127
|
+
}
|
|
128
|
+
return prev[b.length];
|
|
129
|
+
}
|
|
130
|
+
function suggest(name, candidates) {
|
|
131
|
+
let best;
|
|
132
|
+
let bestScore = Infinity;
|
|
133
|
+
const limit = Math.max(2, Math.floor(name.length / 3));
|
|
134
|
+
for (const c of candidates) {
|
|
135
|
+
const score = levenshtein(name.toLowerCase(), c.toLowerCase());
|
|
136
|
+
if (score < bestScore && score <= limit) {
|
|
137
|
+
best = c;
|
|
138
|
+
bestScore = score;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return best;
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ElementInfo {
|
|
2
|
+
tag: string;
|
|
3
|
+
className?: string;
|
|
4
|
+
attrs?: Record<string, string>;
|
|
5
|
+
void?: boolean;
|
|
6
|
+
svg?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const ELEMENTS: Record<string, ElementInfo>;
|
|
9
|
+
export declare const SPECIAL_ELEMENTS: ReadonlySet<string>;
|
|
10
|
+
export declare const VOID_TAGS: ReadonlySet<string>;
|
|
11
|
+
export declare const INLINE_STYLE_PROPS: ReadonlySet<string>;
|
|
12
|
+
export declare const URL_ATTRS: ReadonlySet<string>;
|
|
13
|
+
export declare const BOOLEAN_ATTRS: ReadonlySet<string>;
|
|
14
|
+
export declare function attrNameToHtml(name: string): string;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BOOLEAN_ATTRS = exports.URL_ATTRS = exports.INLINE_STYLE_PROPS = exports.VOID_TAGS = exports.SPECIAL_ELEMENTS = exports.ELEMENTS = void 0;
|
|
4
|
+
exports.attrNameToHtml = attrNameToHtml;
|
|
5
|
+
const e = (tag, extra = {}) => ({ tag, ...extra });
|
|
6
|
+
exports.ELEMENTS = {
|
|
7
|
+
Main: e("main"), Header: e("header"), Footer: e("footer"), Nav: e("nav"), Section: e("section"), Article: e("article"),
|
|
8
|
+
Aside: e("aside"), Div: e("div"), Span: e("span"), Search: e("search"), Hgroup: e("hgroup"),
|
|
9
|
+
Hero: e("section", { className: "hero" }), Container: e("div", { className: "container" }), Grid: e("div", { className: "grid" }),
|
|
10
|
+
Flex: e("div", { className: "flex" }), Stack: e("div", { className: "stack" }), Row: e("div", { className: "row" }),
|
|
11
|
+
Column: e("div", { className: "col" }), CardGrid: e("div", { className: "card-grid" }),
|
|
12
|
+
Heading: e("h1"), H1: e("h1"), H2: e("h2"), H3: e("h3"), H4: e("h4"), H5: e("h5"), H6: e("h6"),
|
|
13
|
+
SubHeading: e("p", { className: "subheading" }), Paragraph: e("p"), P: e("p"), Lead: e("p", { className: "lead" }),
|
|
14
|
+
Small: e("small"), Strong: e("strong"), Bold: e("b"), Em: e("em"), Italic: e("i"), Underline: e("u"), Code: e("code"),
|
|
15
|
+
Pre: e("pre"), Blockquote: e("blockquote"), Quote: e("q"), Mark: e("mark"), Label: e("label"), Abbr: e("abbr"),
|
|
16
|
+
Del: e("del"), Ins: e("ins"), Sub: e("sub"), Sup: e("sup"), Data: e("data"), Time: e("time"), Bdi: e("bdi"), Bdo: e("bdo"),
|
|
17
|
+
Cite: e("cite"), Dfn: e("dfn"), Kbd: e("kbd"), Samp: e("samp"), Var: e("var"), Address: e("address"), Ruby: e("ruby"),
|
|
18
|
+
Rt: e("rt"), Rp: e("rp"), S: e("s"),
|
|
19
|
+
Button: e("button", { attrs: { type: "button" } }), SubmitButton: e("button", { attrs: { type: "submit" } }),
|
|
20
|
+
Link: e("a"), NavLink: e("a", { className: "nav-link" }), A: e("a"),
|
|
21
|
+
Select: e("select"), Form: e("form"), Fieldset: e("fieldset"), Legend: e("legend"), Details: e("details"),
|
|
22
|
+
Summary: e("summary"), Dialog: e("dialog"), Textarea: e("textarea"), TextArea: e("textarea"), Datalist: e("datalist"),
|
|
23
|
+
Optgroup: e("optgroup"), Option: e("option"), Progress: e("progress"), Meter: e("meter"), Output: e("output"),
|
|
24
|
+
Menu: e("menu"),
|
|
25
|
+
Picture: e("picture"), Video: e("video"), Audio: e("audio"), Figure: e("figure"), Figcaption: e("figcaption"),
|
|
26
|
+
Canvas: e("canvas"), IFrame: e("iframe"), Iframe: e("iframe"), Object: e("object"), Map: e("map"),
|
|
27
|
+
Img: e("img", { void: true }), Image: e("img", { void: true }), Logo: e("img", { void: true, className: "logo" }),
|
|
28
|
+
Input: e("input", { void: true }), Checkbox: e("input", { void: true, attrs: { type: "checkbox" } }),
|
|
29
|
+
Radio: e("input", { void: true, attrs: { type: "radio" } }), Hr: e("hr", { void: true }), Br: e("br", { void: true }),
|
|
30
|
+
Wbr: e("wbr", { void: true }), Source: e("source", { void: true }), Track: e("track", { void: true }),
|
|
31
|
+
Embed: e("embed", { void: true }), Col: e("col", { void: true }), Area: e("area", { void: true }),
|
|
32
|
+
Ul: e("ul"), Ol: e("ol"), Li: e("li"), ListItem: e("li"), List: e("ul"), Dl: e("dl"), Dt: e("dt"), Dd: e("dd"),
|
|
33
|
+
Table: e("table"), Caption: e("caption"), Thead: e("thead"), Tbody: e("tbody"), Tfoot: e("tfoot"), Tr: e("tr"),
|
|
34
|
+
Th: e("th"), Td: e("td"), Colgroup: e("colgroup"),
|
|
35
|
+
Template: e("template"), Slot: e("slot"), NoScript: e("noscript"),
|
|
36
|
+
Svg: e("svg", { svg: true }), Path: e("path", { svg: true }), Circle: e("circle", { svg: true }),
|
|
37
|
+
Rect: e("rect", { svg: true }), Line: e("line", { svg: true }), Polyline: e("polyline", { svg: true }),
|
|
38
|
+
Polygon: e("polygon", { svg: true }), Ellipse: e("ellipse", { svg: true }), G: e("g", { svg: true }),
|
|
39
|
+
Use: e("use", { svg: true }), Defs: e("defs", { svg: true }), Text: e("text", { svg: true }),
|
|
40
|
+
LinearGradient: e("linearGradient", { svg: true }), RadialGradient: e("radialGradient", { svg: true }),
|
|
41
|
+
Stop: e("stop", { svg: true }), Symbol: e("symbol", { svg: true }), ClipPath: e("clipPath", { svg: true }),
|
|
42
|
+
Mask: e("mask", { svg: true }), TSpan: e("tspan", { svg: true }),
|
|
43
|
+
};
|
|
44
|
+
exports.SPECIAL_ELEMENTS = new Set(["RawHTML", "Html", "Fragment", "Head", "Portal"]);
|
|
45
|
+
exports.VOID_TAGS = new Set([
|
|
46
|
+
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr",
|
|
47
|
+
]);
|
|
48
|
+
exports.INLINE_STYLE_PROPS = new Set([
|
|
49
|
+
"color", "backgroundColor", "background", "backgroundImage", "backgroundSize", "backgroundPosition",
|
|
50
|
+
"fontSize", "fontWeight", "fontFamily", "fontStyle", "lineHeight", "letterSpacing", "textAlign", "textDecoration",
|
|
51
|
+
"textTransform", "whiteSpace", "wordBreak", "textOverflow", "margin", "marginTop", "marginBottom", "marginLeft",
|
|
52
|
+
"marginRight", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "width", "height", "minWidth",
|
|
53
|
+
"maxWidth", "minHeight", "maxHeight", "display", "flexDirection", "flexWrap", "flex", "flexGrow", "flexShrink",
|
|
54
|
+
"flexBasis", "justifyContent", "alignItems", "alignContent", "alignSelf", "gap", "rowGap", "columnGap",
|
|
55
|
+
"gridTemplateColumns", "gridTemplateRows", "gridColumn", "gridRow", "gridArea", "position", "top", "right", "bottom",
|
|
56
|
+
"left", "zIndex", "border", "borderTop", "borderBottom", "borderLeft", "borderRight", "borderWidth", "borderStyle",
|
|
57
|
+
"borderColor", "borderRadius", "outline", "boxShadow", "textShadow", "opacity", "visibility", "overflow", "overflowX",
|
|
58
|
+
"overflowY", "objectFit", "objectPosition", "cursor", "userSelect", "pointerEvents", "transform", "transition",
|
|
59
|
+
"animation", "aspectRatio", "inset", "filter", "backdropFilter",
|
|
60
|
+
]);
|
|
61
|
+
exports.URL_ATTRS = new Set(["href", "src", "action", "formaction", "poster", "data", "cite", "background", "xlink:href", "srcset"]);
|
|
62
|
+
exports.BOOLEAN_ATTRS = new Set([
|
|
63
|
+
"allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled",
|
|
64
|
+
"formnovalidate", "hidden", "inert", "ismap", "itemscope", "loop", "multiple", "muted", "nomodule", "novalidate", "open",
|
|
65
|
+
"playsinline", "readonly", "required", "reversed", "selected",
|
|
66
|
+
]);
|
|
67
|
+
function attrNameToHtml(name) {
|
|
68
|
+
if (/^(aria|data)[A-Z]/.test(name))
|
|
69
|
+
return name.replace(/[A-Z]/g, m => "-" + m.toLowerCase());
|
|
70
|
+
const map = {
|
|
71
|
+
className: "class", htmlFor: "for", tabIndex: "tabindex", readOnly: "readonly", maxLength: "maxlength",
|
|
72
|
+
minLength: "minlength", autoComplete: "autocomplete", autoFocus: "autofocus", autoPlay: "autoplay", colSpan: "colspan",
|
|
73
|
+
rowSpan: "rowspan", contentEditable: "contenteditable", crossOrigin: "crossorigin", spellCheck: "spellcheck",
|
|
74
|
+
srcSet: "srcset", inputMode: "inputmode", enterKeyHint: "enterkeyhint", noValidate: "novalidate",
|
|
75
|
+
playsInline: "playsinline", referrerPolicy: "referrerpolicy", fetchPriority: "fetchpriority", accessKey: "accesskey",
|
|
76
|
+
};
|
|
77
|
+
return map[name] ?? name;
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RUNTIME_GLOBALS = exports.JS_GLOBALS = void 0;
|
|
4
|
+
exports.JS_GLOBALS = new Set([
|
|
5
|
+
"globalThis", "window", "document", "navigator", "location", "history", "screen", "console", "performance",
|
|
6
|
+
"localStorage", "sessionStorage", "indexedDB", "crypto", "fetch", "Request", "Response", "Headers", "FormData",
|
|
7
|
+
"URL", "URLSearchParams", "AbortController", "AbortSignal", "Blob", "File", "FileReader", "WebSocket", "EventSource",
|
|
8
|
+
"Worker", "BroadcastChannel", "MessageChannel", "Notification", "IntersectionObserver", "ResizeObserver",
|
|
9
|
+
"MutationObserver", "matchMedia", "getComputedStyle", "requestAnimationFrame", "cancelAnimationFrame",
|
|
10
|
+
"requestIdleCallback", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "queueMicrotask",
|
|
11
|
+
"structuredClone", "alert", "confirm", "prompt", "open", "close", "print", "scrollTo", "scrollBy", "atob", "btoa",
|
|
12
|
+
"encodeURIComponent", "decodeURIComponent", "encodeURI", "decodeURI", "escape", "unescape", "isNaN", "isFinite",
|
|
13
|
+
"parseInt", "parseFloat", "Math", "JSON", "Date", "Number", "String", "Boolean", "BigInt", "Symbol", "Array", "Object",
|
|
14
|
+
"Map", "Set", "WeakMap", "WeakSet", "WeakRef", "Promise", "Proxy", "Reflect", "RegExp", "Error", "TypeError",
|
|
15
|
+
"RangeError", "SyntaxError", "Intl", "ArrayBuffer", "DataView", "Uint8Array", "Int8Array", "Uint16Array",
|
|
16
|
+
"Int16Array", "Uint32Array", "Int32Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "TextEncoder",
|
|
17
|
+
"TextDecoder", "Event", "CustomEvent", "KeyboardEvent", "MouseEvent", "EventTarget", "Element", "HTMLElement",
|
|
18
|
+
"Node", "NodeList", "DOMParser", "XMLHttpRequest", "Image", "Audio", "Option", "CSS", "customElements",
|
|
19
|
+
"visualViewport", "devicePixelRatio", "innerWidth", "innerHeight", "outerWidth", "outerHeight", "scrollX",
|
|
20
|
+
"scrollY", "origin", "isSecureContext", "caches", "clipboard", "Infinity", "NaN", "undefined", "Clipboard",
|
|
21
|
+
"AudioContext", "speechSynthesis", "SpeechSynthesisUtterance", "Intl", "sinthRender", "sinth",
|
|
22
|
+
]);
|
|
23
|
+
exports.RUNTIME_GLOBALS = new Map([
|
|
24
|
+
["range", "$$.range"],
|
|
25
|
+
["sinthRender", "$$.update"],
|
|
26
|
+
["render", "$$.update"],
|
|
27
|
+
]);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MetaEntry } from "./ast";
|
|
2
|
+
export declare function escapeHtml(s: string): string;
|
|
3
|
+
export declare function escapeAttr(s: string): string;
|
|
4
|
+
export declare function hashString(s: string): string;
|
|
5
|
+
export interface HeadData {
|
|
6
|
+
title?: string;
|
|
7
|
+
lang: string;
|
|
8
|
+
charset: string;
|
|
9
|
+
viewport: string;
|
|
10
|
+
favicon?: string;
|
|
11
|
+
canonical?: string;
|
|
12
|
+
manifest?: string;
|
|
13
|
+
appleTouchIcon?: string;
|
|
14
|
+
base?: string;
|
|
15
|
+
bodyClass?: string;
|
|
16
|
+
htmlClass?: string;
|
|
17
|
+
metaNames: [string, string][];
|
|
18
|
+
metaProps: [string, string][];
|
|
19
|
+
}
|
|
20
|
+
export interface MetaValue {
|
|
21
|
+
key: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
known: boolean;
|
|
24
|
+
loc: MetaEntry["loc"];
|
|
25
|
+
}
|
|
26
|
+
export declare function buildHead(meta: MetaValue[], resolveAsset: (value: string) => string): HeadData;
|
|
27
|
+
export interface DocumentAssets {
|
|
28
|
+
styles: string[];
|
|
29
|
+
scripts: {
|
|
30
|
+
src: string;
|
|
31
|
+
module: boolean;
|
|
32
|
+
attrs: Record<string, string | boolean>;
|
|
33
|
+
}[];
|
|
34
|
+
preloads: string[];
|
|
35
|
+
inlineHead: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare function renderDocument(head: HeadData, body: string, assets: DocumentAssets): string;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeHtml = escapeHtml;
|
|
4
|
+
exports.escapeAttr = escapeAttr;
|
|
5
|
+
exports.hashString = hashString;
|
|
6
|
+
exports.buildHead = buildHead;
|
|
7
|
+
exports.renderDocument = renderDocument;
|
|
8
|
+
const diagnostics_1 = require("./diagnostics");
|
|
9
|
+
function escapeHtml(s) {
|
|
10
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
11
|
+
}
|
|
12
|
+
function escapeAttr(s) {
|
|
13
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
14
|
+
}
|
|
15
|
+
function hashString(s) {
|
|
16
|
+
let h1 = 0x811c9dc5;
|
|
17
|
+
let h2 = 0x01000193;
|
|
18
|
+
for (let i = 0; i < s.length; i++) {
|
|
19
|
+
const c = s.charCodeAt(i);
|
|
20
|
+
h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
|
|
21
|
+
h2 = Math.imul(h2 ^ c, 0x5bd1e995) >>> 0;
|
|
22
|
+
}
|
|
23
|
+
return (h1.toString(36) + h2.toString(36)).padEnd(12, "0");
|
|
24
|
+
}
|
|
25
|
+
const NAME_MAP = {
|
|
26
|
+
descr: "description", description: "description", author: "author", keywords: "keywords", robots: "robots",
|
|
27
|
+
themeColor: "theme-color", colorScheme: "color-scheme", generator: "generator",
|
|
28
|
+
};
|
|
29
|
+
function buildHead(meta, resolveAsset) {
|
|
30
|
+
const head = {
|
|
31
|
+
lang: "en", charset: "utf-8", viewport: "width=device-width, initial-scale=1", metaNames: [], metaProps: [],
|
|
32
|
+
};
|
|
33
|
+
for (const m of meta) {
|
|
34
|
+
if (!m.known) {
|
|
35
|
+
throw new diagnostics_1.SinthError("E0700", `Metadata '${m.key}' must be computable at build time`, m.loc, "Use literals, imported JSON, constants and route params. Values that need the browser (fetch, localStorage, user input) can't go in the page head");
|
|
36
|
+
}
|
|
37
|
+
if (m.value === null || m.value === undefined || m.value === false)
|
|
38
|
+
continue;
|
|
39
|
+
if (typeof m.value === "object")
|
|
40
|
+
throw new diagnostics_1.SinthError("E0701", `Metadata '${m.key}' must be a string, number or boolean`, m.loc);
|
|
41
|
+
const value = String(m.value);
|
|
42
|
+
switch (m.key) {
|
|
43
|
+
case "title":
|
|
44
|
+
head.title = value;
|
|
45
|
+
break;
|
|
46
|
+
case "lang":
|
|
47
|
+
head.lang = value;
|
|
48
|
+
break;
|
|
49
|
+
case "charset":
|
|
50
|
+
head.charset = value;
|
|
51
|
+
break;
|
|
52
|
+
case "viewport":
|
|
53
|
+
head.viewport = value;
|
|
54
|
+
break;
|
|
55
|
+
case "fav":
|
|
56
|
+
case "favicon":
|
|
57
|
+
head.favicon = resolveAsset(value);
|
|
58
|
+
break;
|
|
59
|
+
case "canonical":
|
|
60
|
+
head.canonical = value;
|
|
61
|
+
break;
|
|
62
|
+
case "manifest":
|
|
63
|
+
head.manifest = resolveAsset(value);
|
|
64
|
+
break;
|
|
65
|
+
case "appleTouchIcon":
|
|
66
|
+
head.appleTouchIcon = resolveAsset(value);
|
|
67
|
+
break;
|
|
68
|
+
case "base":
|
|
69
|
+
head.base = value;
|
|
70
|
+
break;
|
|
71
|
+
case "bodyClass":
|
|
72
|
+
head.bodyClass = value;
|
|
73
|
+
break;
|
|
74
|
+
case "htmlClass":
|
|
75
|
+
head.htmlClass = value;
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
if (NAME_MAP[m.key])
|
|
79
|
+
head.metaNames.push([NAME_MAP[m.key], value]);
|
|
80
|
+
else if (/^og[A-Z]/.test(m.key)) {
|
|
81
|
+
const prop = "og:" + m.key.slice(2).replace(/[A-Z]/g, (c, i) => (i === 0 ? c.toLowerCase() : "_" + c.toLowerCase()));
|
|
82
|
+
head.metaProps.push([prop, /image|url$/i.test(m.key) ? resolveAsset(value) : value]);
|
|
83
|
+
}
|
|
84
|
+
else if (/^twitter[A-Z]/.test(m.key)) {
|
|
85
|
+
const name = "twitter:" + m.key.slice(7).replace(/[A-Z]/g, (c, i) => (i === 0 ? c.toLowerCase() : "_" + c.toLowerCase()));
|
|
86
|
+
head.metaNames.push([name, /image$/i.test(m.key) ? resolveAsset(value) : value]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const has = (list, key) => list.some(([k]) => k === key);
|
|
91
|
+
const description = head.metaNames.find(([k]) => k === "description")?.[1];
|
|
92
|
+
if (head.title && !has(head.metaProps, "og:title"))
|
|
93
|
+
head.metaProps.push(["og:title", head.title]);
|
|
94
|
+
if (description && !has(head.metaProps, "og:description"))
|
|
95
|
+
head.metaProps.push(["og:description", description]);
|
|
96
|
+
if (!has(head.metaProps, "og:type"))
|
|
97
|
+
head.metaProps.push(["og:type", "website"]);
|
|
98
|
+
if (!has(head.metaNames, "twitter:card"))
|
|
99
|
+
head.metaNames.push(["twitter:card", has(head.metaProps, "og:image") ? "summary_large_image" : "summary"]);
|
|
100
|
+
return head;
|
|
101
|
+
}
|
|
102
|
+
function faviconType(href) {
|
|
103
|
+
const ext = href.split(/[?#]/)[0].split(".").pop()?.toLowerCase();
|
|
104
|
+
switch (ext) {
|
|
105
|
+
case "ico": return "image/x-icon";
|
|
106
|
+
case "png": return "image/png";
|
|
107
|
+
case "svg": return "image/svg+xml";
|
|
108
|
+
case "gif": return "image/gif";
|
|
109
|
+
case "webp": return "image/webp";
|
|
110
|
+
case "jpg":
|
|
111
|
+
case "jpeg": return "image/jpeg";
|
|
112
|
+
default: return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function renderDocument(head, body, assets) {
|
|
116
|
+
const lines = [];
|
|
117
|
+
lines.push(`<meta charset="${escapeAttr(head.charset)}">`);
|
|
118
|
+
lines.push(`<meta name="viewport" content="${escapeAttr(head.viewport)}">`);
|
|
119
|
+
if (head.base)
|
|
120
|
+
lines.push(`<base href="${escapeAttr(head.base)}">`);
|
|
121
|
+
if (head.title !== undefined)
|
|
122
|
+
lines.push(`<title>${escapeHtml(head.title)}</title>`);
|
|
123
|
+
for (const [name, content] of head.metaNames)
|
|
124
|
+
lines.push(`<meta name="${escapeAttr(name)}" content="${escapeAttr(content)}">`);
|
|
125
|
+
for (const [prop, content] of head.metaProps)
|
|
126
|
+
lines.push(`<meta property="${escapeAttr(prop)}" content="${escapeAttr(content)}">`);
|
|
127
|
+
if (head.canonical)
|
|
128
|
+
lines.push(`<link rel="canonical" href="${escapeAttr(head.canonical)}">`);
|
|
129
|
+
if (head.favicon) {
|
|
130
|
+
const type = faviconType(head.favicon);
|
|
131
|
+
lines.push(`<link rel="icon" href="${escapeAttr(head.favicon)}"${type ? ` type="${type}"` : ""}>`);
|
|
132
|
+
}
|
|
133
|
+
if (head.appleTouchIcon)
|
|
134
|
+
lines.push(`<link rel="apple-touch-icon" href="${escapeAttr(head.appleTouchIcon)}">`);
|
|
135
|
+
if (head.manifest)
|
|
136
|
+
lines.push(`<link rel="manifest" href="${escapeAttr(head.manifest)}">`);
|
|
137
|
+
for (const href of assets.preloads)
|
|
138
|
+
lines.push(`<link rel="modulepreload" href="${escapeAttr(href)}">`);
|
|
139
|
+
for (const href of assets.styles)
|
|
140
|
+
lines.push(`<link rel="stylesheet" href="${escapeAttr(href)}">`);
|
|
141
|
+
for (const s of assets.scripts) {
|
|
142
|
+
const attrs = Object.entries(s.attrs)
|
|
143
|
+
.filter(([, v]) => v !== false)
|
|
144
|
+
.map(([k, v]) => (v === true ? ` ${k}` : ` ${k}="${escapeAttr(String(v))}"`))
|
|
145
|
+
.join("");
|
|
146
|
+
lines.push(`<script${s.module ? ' type="module"' : ""} src="${escapeAttr(s.src)}"${attrs}></script>`);
|
|
147
|
+
}
|
|
148
|
+
lines.push(...assets.inlineHead);
|
|
149
|
+
const htmlClass = head.htmlClass ? ` class="${escapeAttr(head.htmlClass)}"` : "";
|
|
150
|
+
const bodyClass = head.bodyClass ? ` class="${escapeAttr(head.bodyClass)}"` : "";
|
|
151
|
+
return `<!DOCTYPE html>\n<html lang="${escapeAttr(head.lang)}"${htmlClass}>\n<head>\n${lines.map(l => " " + l).join("\n")}\n</head>\n<body${bodyClass}>\n${body}\n</body>\n</html>\n`;
|
|
152
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Loc } from "./diagnostics";
|
|
2
|
+
export type TokenKind = "ident" | "number" | "string" | "template" | "punct" | "raw" | "eof";
|
|
3
|
+
export interface Token {
|
|
4
|
+
kind: TokenKind;
|
|
5
|
+
value: string;
|
|
6
|
+
loc: Loc;
|
|
7
|
+
end: number;
|
|
8
|
+
start: number;
|
|
9
|
+
newlineBefore: boolean;
|
|
10
|
+
quote?: string;
|
|
11
|
+
formatted?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class Lexer {
|
|
14
|
+
private readonly src;
|
|
15
|
+
private readonly file;
|
|
16
|
+
private readonly baseLoc?;
|
|
17
|
+
private pos;
|
|
18
|
+
private line;
|
|
19
|
+
private col;
|
|
20
|
+
private sawNewline;
|
|
21
|
+
private rawPending;
|
|
22
|
+
private readonly tokens;
|
|
23
|
+
constructor(src: string, file: string, baseLoc?: Loc | undefined);
|
|
24
|
+
tokenize(): Token[];
|
|
25
|
+
private here;
|
|
26
|
+
private make;
|
|
27
|
+
private advance;
|
|
28
|
+
private peekChar;
|
|
29
|
+
private fail;
|
|
30
|
+
private skipTrivia;
|
|
31
|
+
private skipBlockComment;
|
|
32
|
+
private next;
|
|
33
|
+
private readIdent;
|
|
34
|
+
private atStatementStart;
|
|
35
|
+
private readNumber;
|
|
36
|
+
private readEscape;
|
|
37
|
+
private readString;
|
|
38
|
+
private readTemplate;
|
|
39
|
+
private readRawBlock;
|
|
40
|
+
private skipQuoted;
|
|
41
|
+
}
|
|
42
|
+
export declare function tokenize(src: string, file: string, baseLoc?: Loc): Token[];
|