@yannosay/sinth 5.2.3 → 5.3.1
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 +48 -0
- package/README.md +24 -23
- package/RUNTIME-EXCEPTION.md +25 -0
- package/dist/browser/compile.d.ts +35 -0
- package/dist/browser/compile.js +158 -0
- package/dist/browser/sinth.js +1492 -0
- package/dist/cli/index.js +3 -1
- package/dist/cli/templates.js +2 -2
- package/dist/cli/ui.d.ts +0 -1
- package/dist/cli/ui.js +1 -2
- package/dist/compiler/ast.d.ts +11 -0
- package/dist/compiler/codegen.d.ts +2 -87
- package/dist/compiler/codegen.js +49 -6
- package/dist/compiler/diagnostics.d.ts +0 -1
- package/dist/compiler/diagnostics.js +0 -4
- package/dist/compiler/html.d.ts +2 -0
- package/dist/compiler/html.js +11 -1
- package/dist/compiler/lexer.js +3 -0
- package/dist/compiler/parser.js +27 -1
- package/dist/compiler/prerender.js +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/project/build.d.ts +6 -0
- package/dist/project/build.js +69 -41
- package/dist/project/config.d.ts +1 -0
- package/dist/project/config.js +3 -2
- package/dist/project/project.d.ts +1 -0
- package/dist/project/project.js +2 -1
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.js +18 -2
- package/dist/runtime/router.d.ts +36 -0
- package/dist/runtime/router.js +215 -0
- package/dist/server/client.js +3 -1
- package/dist/server/dev.js +65 -25
- package/dist/server/functions.d.ts +49 -0
- package/dist/server/functions.js +309 -0
- package/dist/server/preview.d.ts +2 -0
- package/dist/server/preview.js +41 -18
- package/dist/server/static.d.ts +10 -0
- package/dist/server/static.js +25 -0
- package/package.json +22 -13
- package/schema/sinth.config.schema.json +2 -1
- package/DOCS.md +0 -1360
package/DOCS.md
DELETED
|
@@ -1,1360 +0,0 @@
|
|
|
1
|
-
# Sinth 5 Reference
|
|
2
|
-
|
|
3
|
-
The complete guide to the Sinth language, compiler, CLI and tooling. For a quick overview see the [README](./README.md).
|
|
4
|
-
|
|
5
|
-
- [1. Getting started](#1-getting-started)
|
|
6
|
-
- [2. Project structure](#2-project-structure)
|
|
7
|
-
- [3. Files, pages and components](#3-files-pages-and-components)
|
|
8
|
-
- [4. Comments](#4-comments)
|
|
9
|
-
- [5. Page metadata](#5-page-metadata)
|
|
10
|
-
- [6. Variables and types](#6-variables-and-types)
|
|
11
|
-
- [7. Expressions](#7-expressions)
|
|
12
|
-
- [8. Markup](#8-markup)
|
|
13
|
-
- [9. Built-in elements](#9-built-in-elements)
|
|
14
|
-
- [10. Attributes](#10-attributes)
|
|
15
|
-
- [11. Events](#11-events)
|
|
16
|
-
- [12. Binding forms](#12-binding-forms)
|
|
17
|
-
- [13. Conditionals](#13-conditionals)
|
|
18
|
-
- [14. Loops](#14-loops)
|
|
19
|
-
- [15. Functions](#15-functions)
|
|
20
|
-
- [16. Components](#16-components)
|
|
21
|
-
- [17. Slots](#17-slots)
|
|
22
|
-
- [18. Lifecycle and watchers](#18-lifecycle-and-watchers)
|
|
23
|
-
- [19. Styling](#19-styling)
|
|
24
|
-
- [20. Script blocks](#20-script-blocks)
|
|
25
|
-
- [21. Imports](#21-imports)
|
|
26
|
-
- [22. Shared state (stores)](#22-shared-state-stores)
|
|
27
|
-
- [23. The sinth:ui library](#23-the-sinthui-library)
|
|
28
|
-
- [24. Custom elements](#24-custom-elements)
|
|
29
|
-
- [25. Rendering model and performance](#25-rendering-model-and-performance)
|
|
30
|
-
- [26. Security](#26-security)
|
|
31
|
-
- [27. The CLI](#27-the-cli)
|
|
32
|
-
- [28. Configuration](#28-configuration)
|
|
33
|
-
- [29. Dev server](#29-dev-server)
|
|
34
|
-
- [30. Building and output](#30-building-and-output)
|
|
35
|
-
- [31. Deploying](#31-deploying)
|
|
36
|
-
- [32. Editor support](#32-editor-support)
|
|
37
|
-
- [33. Programmatic API](#33-programmatic-api)
|
|
38
|
-
- [34. Error reference](#34-error-reference)
|
|
39
|
-
- [35. Migrating from Sinth 4](#35-migrating-from-sinth-4)
|
|
40
|
-
- [36. FAQ](#36-faq)
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## 1. Getting started
|
|
45
|
-
|
|
46
|
-
Requirements: Node.js 18.17 or newer.
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
npx @yannosay/sinth create my-site
|
|
50
|
-
cd my-site
|
|
51
|
-
npm install
|
|
52
|
-
npm run dev
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Or install the CLI globally:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
npm install -g @yannosay/sinth
|
|
59
|
-
sinth create my-site
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Open `http://localhost:3000`. Edit `pages/index.sinth` and save; the page updates instantly and keeps its state.
|
|
63
|
-
|
|
64
|
-
A complete page:
|
|
65
|
-
|
|
66
|
-
```sinth
|
|
67
|
-
title = "Counter"
|
|
68
|
-
|
|
69
|
-
var num count = 0
|
|
70
|
-
|
|
71
|
-
Main {
|
|
72
|
-
Heading(level: 1) { "Count: " + count }
|
|
73
|
-
Button(onClick: count += 1) { "Increment" }
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
When you are ready:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
npm run build # optimized production build in dist/
|
|
81
|
-
npm run preview # serve dist/ locally with production headers
|
|
82
|
-
npm run deploy # deploy to Cloudflare Pages
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## 2. Project structure
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
my-site/
|
|
89
|
-
├─ pages/ every .sinth file in here is a page
|
|
90
|
-
│ ├─ index.sinth → /
|
|
91
|
-
│ ├─ about.sinth → /about
|
|
92
|
-
│ ├─ 404.sinth → 404.html (used by Cloudflare Pages and `sinth preview`)
|
|
93
|
-
│ ├─ blog/index.sinth → /blog
|
|
94
|
-
│ └─ blog/[slug].sinth → /blog/hello-world, /blog/second-post, ... (dynamic route)
|
|
95
|
-
├─ components/ reusable components (any folder name works)
|
|
96
|
-
├─ public/ copied to the output root as-is (robots.txt, favicon.ico, ...)
|
|
97
|
-
├─ assets/ copied to dist/assets/
|
|
98
|
-
├─ sinth.config.json optional configuration
|
|
99
|
-
└─ package.json
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Rules:
|
|
103
|
-
|
|
104
|
-
- Every `.sinth` file in `pages/` is a page. No keyword or boilerplate is needed.
|
|
105
|
-
- Files and folders whose names start with `_` are not pages (use them for drafts and page-local components: `pages/_partials/Hero.sinth`).
|
|
106
|
-
- A file in `pages/` that only declares components or functions (no markup, no metadata) is treated as a module, so older projects keep working.
|
|
107
|
-
- If there is no `pages/` folder, every `.sinth` file in the project root that contains markup or metadata is a page; `components/`, `lib/`, `styles/`, `assets/` and `public/` are skipped.
|
|
108
|
-
- File and folder names in `[brackets]` are [dynamic routes](#dynamic-routes).
|
|
109
|
-
|
|
110
|
-
## 3. Files, pages and components
|
|
111
|
-
|
|
112
|
-
There are two kinds of `.sinth` files.
|
|
113
|
-
|
|
114
|
-
**Pages** are the files in `pages/`. They contain metadata, state, markup and styles, and are compiled to one HTML file each (or one per path, for dynamic routes).
|
|
115
|
-
|
|
116
|
-
**Modules** (files outside `pages/`, usually in `components/`) contain components, functions and shared variables that pages import.
|
|
117
|
-
|
|
118
|
-
> Sinth 4 required pages to start with the keyword `page`. That keyword has been removed: a file that still starts with it fails with E0104. Delete the line; where a file lives decides whether it is a page.
|
|
119
|
-
|
|
120
|
-
Order inside a page is flexible, but the usual layout is:
|
|
121
|
-
|
|
122
|
-
```sinth
|
|
123
|
-
import { Card } from "../components/Card.sinth" -- 1. imports
|
|
124
|
-
|
|
125
|
-
title = "Home" -- 2. metadata
|
|
126
|
-
|
|
127
|
-
var str name = "World" -- 3. state
|
|
128
|
-
|
|
129
|
-
function greet(str who) -> str { -- 4. functions
|
|
130
|
-
return "Hello, " + who + "!"
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Main { -- 5. markup
|
|
134
|
-
Heading(level: 1) { greet(name) }
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
style { -- 6. styles
|
|
138
|
-
main { padding: "2rem" }
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Dynamic routes
|
|
143
|
-
|
|
144
|
-
Put a parameter name in brackets in a file or folder name to generate many pages from one file. List the values in `paths`; the parameter is then available as a `str` constant:
|
|
145
|
-
|
|
146
|
-
```sinth
|
|
147
|
-
-- pages/blog/[slug].sinth
|
|
148
|
-
import posts from "../../content/posts.json"
|
|
149
|
-
|
|
150
|
-
paths = posts.map((p) => p.slug)
|
|
151
|
-
const post = posts.find((p) => p.slug == slug)
|
|
152
|
-
|
|
153
|
-
title = post.title + " | Blog"
|
|
154
|
-
descr = post.summary
|
|
155
|
-
|
|
156
|
-
Main {
|
|
157
|
-
Heading(level: 1) { post.title }
|
|
158
|
-
Paragraph { post.body }
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
With `content/posts.json` holding two posts, the build writes `blog/hello-world.html` and `blog/second-post.html`, each prerendered with its own title and description, and both listed in the sitemap.
|
|
163
|
-
|
|
164
|
-
Several parameters work too. Then `paths` lists objects:
|
|
165
|
-
|
|
166
|
-
```sinth
|
|
167
|
-
-- pages/[lang]/docs/[page].sinth
|
|
168
|
-
paths = [
|
|
169
|
-
{ lang: "en", page: "intro" }
|
|
170
|
-
{ lang: "de", page: "intro" }
|
|
171
|
-
]
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Rules:
|
|
175
|
-
|
|
176
|
-
- `paths` is evaluated at build time from literals, constants, imported JSON and functions. Each value must be a non-empty string or number without `/`, `\`, `?` or `#`, and every combination must be unique.
|
|
177
|
-
- Interactive dynamic pages share one JavaScript bundle; the current params are embedded as JSON and read at startup, so `slug` works in event handlers too.
|
|
178
|
-
- In the dev server every generated page is served at its URL and updates on save.
|
|
179
|
-
|
|
180
|
-
## 4. Comments
|
|
181
|
-
|
|
182
|
-
```sinth
|
|
183
|
-
-- line comment
|
|
184
|
-
--[
|
|
185
|
-
block comment
|
|
186
|
-
--[ block comments nest ]--
|
|
187
|
-
]--
|
|
188
|
-
// JavaScript-style line comments also work
|
|
189
|
-
/* and block comments */
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## 5. Page metadata
|
|
193
|
-
|
|
194
|
-
Metadata is written as `key = value` at the top level of a page. Values are evaluated at build time, so they can use literals, constants, imported JSON and [route params](#dynamic-routes):
|
|
195
|
-
|
|
196
|
-
```sinth
|
|
197
|
-
const str site = "Acme"
|
|
198
|
-
title = "Pricing | " + site
|
|
199
|
-
descr = f"Plans for teams of every size at {site}"
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
Values that only exist in the browser (`fetch`, `localStorage`, user input) cannot be used in metadata (E0700). A value of `null` or `false` leaves the tag out.
|
|
203
|
-
|
|
204
|
-
| Key | Output |
|
|
205
|
-
|---|---|
|
|
206
|
-
| `title` | `<title>`, and `og:title` if not set |
|
|
207
|
-
| `descr` / `description` | `<meta name="description">`, and `og:description` if not set |
|
|
208
|
-
| `fav` / `favicon` | `<link rel="icon">` (type detected from the extension) |
|
|
209
|
-
| `lang` | `<html lang>` (default `en`) |
|
|
210
|
-
| `charset` | default `utf-8` |
|
|
211
|
-
| `viewport` | default `width=device-width, initial-scale=1` |
|
|
212
|
-
| `author`, `keywords`, `robots`, `generator` | `<meta name="...">` |
|
|
213
|
-
| `themeColor` | `<meta name="theme-color">` |
|
|
214
|
-
| `colorScheme` | `<meta name="color-scheme">` |
|
|
215
|
-
| `canonical` | `<link rel="canonical">` |
|
|
216
|
-
| `manifest` | `<link rel="manifest">` |
|
|
217
|
-
| `appleTouchIcon` | `<link rel="apple-touch-icon">` |
|
|
218
|
-
| `base` | `<base href>` |
|
|
219
|
-
| `bodyClass`, `htmlClass` | class on `<body>` / `<html>` |
|
|
220
|
-
| `ogImage`, `ogUrl`, `ogType`, `ogSiteName`, ... | `<meta property="og:...">` |
|
|
221
|
-
| `twitterCard`, `twitterSite`, `twitterImage`, ... | `<meta name="twitter:...">` |
|
|
222
|
-
|
|
223
|
-
Asset paths (`fav`, `ogImage`, `manifest`, `appleTouchIcon`) are resolved for you: `fav = "assets/logo.png"` or `fav = "./favicon.svg"` become correct root-relative URLs if the file exists in `public/` or a static folder. `twitter:card` defaults to `summary_large_image` when an `ogImage` is present.
|
|
224
|
-
|
|
225
|
-
## 6. Variables and types
|
|
226
|
-
|
|
227
|
-
```sinth
|
|
228
|
-
var str name = "Sinth"
|
|
229
|
-
var num count = 0
|
|
230
|
-
var bool open = false
|
|
231
|
-
var str[] tags = ["web", "ui"]
|
|
232
|
-
var num[] scores = [1, 2, 3]
|
|
233
|
-
var obj user = { name: "Ada", age: 36 }
|
|
234
|
-
var obj[] todos = [{ text: "Write docs", done: false }]
|
|
235
|
-
var str? nickname -- nullable, starts as null
|
|
236
|
-
var any data = null
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
Types: `str`, `num`, `bool`, `obj`, `any`, plus `[]` for arrays and `?` for nullable. `int` still works but is deprecated (use `num`). `ui`, `void` and `fn` are used in function signatures.
|
|
240
|
-
|
|
241
|
-
The type can be omitted when there is an initial value:
|
|
242
|
-
|
|
243
|
-
```sinth
|
|
244
|
-
var count = 0 -- inferred as num
|
|
245
|
-
var name: str = "x" -- colon syntax also works
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
Uninitialized variables get a default: `""` for `str`, `0` for `num`, `false` for `bool`, `[]` for arrays, `null` for everything else.
|
|
249
|
-
|
|
250
|
-
### Kinds of declarations
|
|
251
|
-
|
|
252
|
-
```sinth
|
|
253
|
-
var num count = 0 -- reactive state
|
|
254
|
-
const str API = "https://api.example.com" -- cannot be reassigned
|
|
255
|
-
computed num double = count * 2 -- recalculated from other values
|
|
256
|
-
persist var str theme = "dark" -- saved in localStorage
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
- **`var`**: assigning to it updates every place in the UI that uses it.
|
|
260
|
-
- **`const`**: assigning to it is a compile error.
|
|
261
|
-
- **`computed`**: an expression that stays up to date. It cannot be assigned.
|
|
262
|
-
- **`persist var`**: survives reloads (stored in `localStorage` under `sinth:<file>:<name>`).
|
|
263
|
-
|
|
264
|
-
### Type checking
|
|
265
|
-
|
|
266
|
-
The compiler catches clear mistakes:
|
|
267
|
-
|
|
268
|
-
```sinth
|
|
269
|
-
var num count = "zero" -- error E0403: cannot assign str to num
|
|
270
|
-
count = "1" -- error E0403
|
|
271
|
-
if count == "1" { ... } -- error E0401: cannot compare num and str
|
|
272
|
-
count += "1" -- error E0400
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
Unknown names are errors with suggestions:
|
|
276
|
-
|
|
277
|
-
```
|
|
278
|
-
error[E0302]: Unknown name 'cuont'
|
|
279
|
-
--> pages/index.sinth:12:20
|
|
280
|
-
> 12 | Paragraph { "Count: " + cuont }
|
|
281
|
-
| ^^^^^
|
|
282
|
-
hint: Did you mean 'count'?
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Reserved words
|
|
286
|
-
|
|
287
|
-
JavaScript keywords (`class`, `new`, `default`, ...) and Sinth operators (`and`, `or`, `not`) cannot be used as names. Names starting with `$$` are reserved for the runtime.
|
|
288
|
-
|
|
289
|
-
## 7. Expressions
|
|
290
|
-
|
|
291
|
-
Sinth expressions are a safe subset of JavaScript with a few additions.
|
|
292
|
-
|
|
293
|
-
| Category | Operators |
|
|
294
|
-
|---|---|
|
|
295
|
-
| Arithmetic | `+ - * / % **` |
|
|
296
|
-
| Comparison | `== != < > <= >=` (always strict: `==` compiles to `===`) |
|
|
297
|
-
| Logic | `and`, `or`, `not` (also `&&`, `\|\|`, `!`) |
|
|
298
|
-
| Nullish | `??`, optional chaining `a?.b`, `a?.[0]`, `f?.()` |
|
|
299
|
-
| Conditional | `cond ? a : b` |
|
|
300
|
-
| Assignment | `= += -= *= /= %= **= ??= &&= \|\|=`, `x++`, `++x` |
|
|
301
|
-
| Other | `typeof`, `await`, `new Date()`, spread `...xs` |
|
|
302
|
-
|
|
303
|
-
Precedence follows mathematics and JavaScript: `2 + 3 * 4` is `14`, `(2 + 3) * 4` is `20`.
|
|
304
|
-
|
|
305
|
-
### Strings
|
|
306
|
-
|
|
307
|
-
```sinth
|
|
308
|
-
"double" 'single'
|
|
309
|
-
"escapes: \n \t é \u{1F600}"
|
|
310
|
-
f"Hello {name}, you have {items.length} items"
|
|
311
|
-
`template ${name} literal`
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
`f"..."` strings interpolate any expression in `{...}`. Escape literal braces as `\{` and `\}`.
|
|
315
|
-
|
|
316
|
-
### Collections
|
|
317
|
-
|
|
318
|
-
```sinth
|
|
319
|
-
[1, 2, 3]
|
|
320
|
-
{ name: "Ada", "data-id": 7, [key]: value, ...other }
|
|
321
|
-
{ name } -- shorthand for { name: name }
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
Objects and arrays may also be separated by newlines instead of commas.
|
|
325
|
-
|
|
326
|
-
### Calling functions
|
|
327
|
-
|
|
328
|
-
Everything from JavaScript's standard library is available: `Math.max(a, b)`, `JSON.stringify(x)`, `items.filter((t) => t.done)`, `Date.now()`, `fetch(url)`, `localStorage`, `Intl.NumberFormat`, and so on.
|
|
329
|
-
|
|
330
|
-
Arrow functions:
|
|
331
|
-
|
|
332
|
-
```sinth
|
|
333
|
-
(x) => x * 2
|
|
334
|
-
(a, b) => { return a + b }
|
|
335
|
-
async (url) => await fetch(url)
|
|
336
|
-
(num x) -> num { return x * 2 } -- typed form
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
`range()` is built in:
|
|
340
|
-
|
|
341
|
-
```sinth
|
|
342
|
-
range(5) -- [0, 1, 2, 3, 4]
|
|
343
|
-
range(1, 6) -- [1, 2, 3, 4, 5]
|
|
344
|
-
range(10, 0, -2) -- [10, 8, 6, 4, 2]
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### Memoized calls
|
|
348
|
-
|
|
349
|
-
Prefix a call with `$` to cache its result for the same arguments:
|
|
350
|
-
|
|
351
|
-
```sinth
|
|
352
|
-
Paragraph { "fib(30) = " + $fib(30) }
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
## 8. Markup
|
|
356
|
-
|
|
357
|
-
Markup is a tree of elements. An element is a capitalized name, optional attributes in parentheses and optional children in braces:
|
|
358
|
-
|
|
359
|
-
```sinth
|
|
360
|
-
Main {
|
|
361
|
-
Heading(level: 1) { "Welcome" }
|
|
362
|
-
Paragraph(class: "lead") { "Hello, " + name }
|
|
363
|
-
Hr
|
|
364
|
-
Img(src: "/logo.png", alt: "Logo")
|
|
365
|
-
}
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
Children can be:
|
|
369
|
-
|
|
370
|
-
- **Text**: any expression. Strings, numbers and variables are rendered as text. `null`, `undefined` and `false` render nothing; arrays render as `a, b, c`.
|
|
371
|
-
- **Elements and components.**
|
|
372
|
-
- **`if`, `for`, `$slot`, local `var` declarations.**
|
|
373
|
-
- **Statements** such as assignments (`count = 5`) and `console.log(...)`, which run once when that part of the page is created.
|
|
374
|
-
|
|
375
|
-
Text is always escaped. To render HTML, see `RawHTML` below.
|
|
376
|
-
|
|
377
|
-
Several text children on the same line must be joined with `+`:
|
|
378
|
-
|
|
379
|
-
```sinth
|
|
380
|
-
Paragraph { "Hello " + name } -- good
|
|
381
|
-
Paragraph { "Hello " name } -- error: use '+' to join values
|
|
382
|
-
Paragraph {
|
|
383
|
-
"Hello " -- good: one child per line
|
|
384
|
-
Strong { name }
|
|
385
|
-
}
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
## 9. Built-in elements
|
|
389
|
-
|
|
390
|
-
Every built-in element maps to an HTML tag.
|
|
391
|
-
|
|
392
|
-
| Group | Elements |
|
|
393
|
-
|---|---|
|
|
394
|
-
| Layout | `Main Header Footer Nav Section Article Aside Div Span Search Hgroup` |
|
|
395
|
-
| Layout with class | `Hero` (section.hero), `Container`, `Grid`, `Flex`, `Stack`, `Row`, `Column` (div.col), `CardGrid` |
|
|
396
|
-
| Text | `Heading`(h1–h6 via `level`), `H1`…`H6`, `Paragraph`/`P`, `Lead`, `SubHeading`, `Small`, `Strong`, `Bold`, `Em`, `Italic`, `Underline`, `Code`, `Pre`, `Blockquote`, `Quote`, `Mark`, `Label`, `Abbr`, `Del`, `Ins`, `Sub`, `Sup`, `Time`, `Kbd`, `Samp`, `Var`, `Cite`, `Dfn`, `Address`, `Data`, `S`, `Ruby`, `Rt`, `Rp`, `Bdi`, `Bdo` |
|
|
397
|
-
| Interactive | `Button` (type="button"), `SubmitButton` (type="submit"), `Link`/`A`, `NavLink` (a.nav-link), `Form`, `Input`, `Textarea`, `Select`, `Option`, `Optgroup`, `Checkbox`, `Radio`, `Fieldset`, `Legend`, `Datalist`, `Details`, `Summary`, `Dialog`, `Progress`, `Meter`, `Output`, `Menu` |
|
|
398
|
-
| Media | `Img`/`Image`, `Logo`, `Picture`, `Source`, `Track`, `Video`, `Audio`, `Figure`, `Figcaption`, `Canvas`, `IFrame`, `Embed`, `Object`, `Map`, `Area` |
|
|
399
|
-
| Lists | `Ul`, `Ol`, `Li`, `List` (ul), `ListItem` (li), `Dl`, `Dt`, `Dd` |
|
|
400
|
-
| Tables | `Table`, `Caption`, `Thead`, `Tbody`, `Tfoot`, `Tr`, `Th`, `Td`, `Colgroup`, `Col` |
|
|
401
|
-
| SVG | `Svg`, `Path`, `Circle`, `Rect`, `Line`, `Polyline`, `Polygon`, `Ellipse`, `G`, `Use`, `Defs`, `Text`, `TSpan`, `LinearGradient`, `RadialGradient`, `Stop`, `Symbol`, `ClipPath`, `Mask` |
|
|
402
|
-
| Other | `Hr`, `Br`, `Wbr`, `Template`, `Slot`, `NoScript` |
|
|
403
|
-
| Special | `Fragment` (children without a wrapper), `RawHTML`/`Html` (trusted HTML) |
|
|
404
|
-
|
|
405
|
-
```sinth
|
|
406
|
-
RawHTML(content: "<em>trusted</em>")
|
|
407
|
-
Div(html: markdownToHtml(post.body)) -- same, on an element
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
`RawHTML` and `html:` insert unescaped HTML. The compiler warns (W0301) when the content is not a literal. Only use them with content you trust.
|
|
411
|
-
|
|
412
|
-
## 10. Attributes
|
|
413
|
-
|
|
414
|
-
```sinth
|
|
415
|
-
Link(href: "/about", target: "_blank", rel: "noopener") { "About" }
|
|
416
|
-
Input(type: "email", required, placeholder: "you@example.com")
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
- Values are expressions: `disabled: not valid`, `href: "/users/" + user.id`.
|
|
420
|
-
- An attribute without a value is `true`: `Input(required)`.
|
|
421
|
-
- `false`, `null` and `undefined` remove the attribute.
|
|
422
|
-
- Commas between attributes are optional when each is on its own line.
|
|
423
|
-
- `ariaLabel` becomes `aria-label`, `dataId` becomes `data-id`; `"aria-label": ...` also works.
|
|
424
|
-
- `className` → `class`, `htmlFor` → `for`, `tabIndex` → `tabindex`, and similar React-style names are converted.
|
|
425
|
-
|
|
426
|
-
### class
|
|
427
|
-
|
|
428
|
-
```sinth
|
|
429
|
-
Div(class: "card") -- string
|
|
430
|
-
Div(class: ["card", selected ? "active" : ""]) -- list
|
|
431
|
-
Div(class: { card: true, active: selected }) -- object toggles
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
### style
|
|
435
|
-
|
|
436
|
-
```sinth
|
|
437
|
-
Div(style: "color: red")
|
|
438
|
-
Div(style: { backgroundColor: color, padding: "1rem", opacity: 0.8 })
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
Common CSS properties can also be written directly as attributes:
|
|
442
|
-
|
|
443
|
-
```sinth
|
|
444
|
-
Paragraph(color: "gray", fontSize: "1.2rem", marginTop: "0") { "..." }
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
(`width` and `height` stay real attributes on `Img`, `Video`, `Canvas`, `IFrame`, `Svg` and `Input`.)
|
|
448
|
-
|
|
449
|
-
### Special attributes
|
|
450
|
-
|
|
451
|
-
| Attribute | Meaning |
|
|
452
|
-
|---|---|
|
|
453
|
-
| `model: x` / `bind: x` | two-way binding (see [12](#12-binding-forms)) |
|
|
454
|
-
| `value: x` | one-way value |
|
|
455
|
-
| `ref: el` | stores the DOM element in variable `el` |
|
|
456
|
-
| `hide: cond` | `display: none` while `cond` is true |
|
|
457
|
-
| `show: cond` | `display: none` while `cond` is false |
|
|
458
|
-
| `delay: ms` | reveals the element after `ms` milliseconds |
|
|
459
|
-
| `html: str` | sets trusted inner HTML |
|
|
460
|
-
| `level: 1..6` | heading level for `Heading` |
|
|
461
|
-
| `key` | reserved for loops |
|
|
462
|
-
|
|
463
|
-
Lowercase inline handlers like `onclick: "..."` are rejected (E0334); use `onClick:` with a Sinth handler.
|
|
464
|
-
|
|
465
|
-
## 11. Events
|
|
466
|
-
|
|
467
|
-
Any attribute named `on` + capital letter is an event handler: `onClick`, `onInput`, `onChange`, `onSubmit`, `onKeyDown`, `onMouseEnter`, `onScroll`, `onPointerDown`, and so on (`onDoubleClick` maps to `dblclick`).
|
|
468
|
-
|
|
469
|
-
A handler can be:
|
|
470
|
-
|
|
471
|
-
```sinth
|
|
472
|
-
Button(onClick: count += 1) -- a statement
|
|
473
|
-
Button(onClick: count += 1; message = "Clicked") -- several, separated by ;
|
|
474
|
-
Button(onClick: reset) -- a function name
|
|
475
|
-
Button(onClick: addItem(draft)) -- a call
|
|
476
|
-
Button(onClick: (e) => console.log(e.clientX)) -- an arrow function
|
|
477
|
-
Input(onInput: query = e.target.value) -- `e` / `event` is the DOM event
|
|
478
|
-
Button(onClick: if open { open = false } else { open = true })
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
After every handler the UI updates automatically. If the handler returns a promise (an `async` function or `await`), the UI updates again when it settles.
|
|
482
|
-
|
|
483
|
-
### Modifiers
|
|
484
|
-
|
|
485
|
-
```sinth
|
|
486
|
-
Form(onSubmit.prevent: save()) -- preventDefault()
|
|
487
|
-
Button(onClick.stop: select(item)) -- stopPropagation()
|
|
488
|
-
Button(onClick.once: init()) -- runs once
|
|
489
|
-
Div(onClick.self: close()) -- only when the element itself is clicked
|
|
490
|
-
Div(onScroll.passive: track()) -- passive listener
|
|
491
|
-
Div(onClick.capture: log()) -- capture phase
|
|
492
|
-
Input(onKeyDown.enter: submit()) -- key filters: enter esc space tab up down left right delete
|
|
493
|
-
Input(onKeyDown.ctrl.enter: send()) -- system keys: ctrl shift alt meta
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
Modifiers can be combined: `onClick.prevent.stop`.
|
|
497
|
-
|
|
498
|
-
## 12. Binding forms
|
|
499
|
-
|
|
500
|
-
`model:` (or its alias `bind:`) keeps a variable and an input in sync:
|
|
501
|
-
|
|
502
|
-
```sinth
|
|
503
|
-
var str name = ""
|
|
504
|
-
var num age = 18
|
|
505
|
-
var bool agree = false
|
|
506
|
-
var str plan = "free"
|
|
507
|
-
var str[] toppings = []
|
|
508
|
-
|
|
509
|
-
Input(model: name, placeholder: "Name")
|
|
510
|
-
Input(type: "number", model: age) -- numbers stay numbers
|
|
511
|
-
Input(type: "range", model: age, min: 0, max: 120)
|
|
512
|
-
Textarea(model: bio)
|
|
513
|
-
Checkbox(model: agree)
|
|
514
|
-
Radio(name: "plan", value: "free", model: plan)
|
|
515
|
-
Radio(name: "plan", value: "pro", model: plan)
|
|
516
|
-
Select(model: plan) {
|
|
517
|
-
Option(value: "free") { "Free" }
|
|
518
|
-
Option(value: "pro") { "Pro" }
|
|
519
|
-
}
|
|
520
|
-
Checkbox(value: "cheese", model: toppings) -- array of checked values
|
|
521
|
-
Select(multiple: true, model: toppings) { ... }
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
Bindings also work on object fields and array items: `Checkbox(model: todo.done)`, `Input(model: rows[i].name)`.
|
|
525
|
-
|
|
526
|
-
## 13. Conditionals
|
|
527
|
-
|
|
528
|
-
```sinth
|
|
529
|
-
if loggedIn {
|
|
530
|
-
Paragraph { "Welcome back, " + user.name }
|
|
531
|
-
} elif loading {
|
|
532
|
-
Paragraph { "Loading..." }
|
|
533
|
-
} else {
|
|
534
|
-
Button(onClick: login()) { "Log in" }
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
Parentheses around the condition are optional. `else if` and `elif` are equivalent. Only the active branch exists in the DOM.
|
|
539
|
-
|
|
540
|
-
Modifiers go between the condition and the block:
|
|
541
|
-
|
|
542
|
-
```sinth
|
|
543
|
-
if open persist { Settings } -- keep the branch alive while hidden (state, scroll, focus)
|
|
544
|
-
if visible delay(300) { Toast } -- remove it 300ms later (exit animations)
|
|
545
|
-
if visible transition("fade") { Toast } -- adds fade-enter / fade-leave classes
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
With `transition("fade")`, the element gets `fade-enter` when it appears (removed on the next frame) and `fade-leave` before it is removed (after 200ms, or `delay`):
|
|
549
|
-
|
|
550
|
-
```sinth
|
|
551
|
-
style global {
|
|
552
|
-
.fade-enter, .fade-leave { opacity: 0 }
|
|
553
|
-
.toast { transition: "opacity 0.2s" }
|
|
554
|
-
}
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
Inline conditionals: `Paragraph { done ? "Done" : "Pending" }`.
|
|
558
|
-
|
|
559
|
-
## 14. Loops
|
|
560
|
-
|
|
561
|
-
```sinth
|
|
562
|
-
for fruit in fruits {
|
|
563
|
-
Li { fruit }
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
for (todo, i in todos) key todo.id {
|
|
567
|
-
Li { (i + 1) + ". " + todo.text }
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
for item in items if item.visible { -- inline filter
|
|
571
|
-
Card(title: item.title)
|
|
572
|
-
} else { -- shown when nothing is rendered
|
|
573
|
-
Paragraph { "Nothing here yet." }
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
for n in range(1, 11) { Span { n } }
|
|
577
|
-
for value, i, key in settings { Dt { key } Dd { value } } -- objects and Maps
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
A loop declares up to three names: **item**, **index** and **key**. For arrays the key equals the index; for objects it is the property name; for `Map`s it is the map key.
|
|
581
|
-
|
|
582
|
-
### Keys
|
|
583
|
-
|
|
584
|
-
Sinth reuses DOM nodes when a list changes. By default object items are matched by identity and primitive items by position. Use `key` when items are replaced by new objects (for example after `fetch`):
|
|
585
|
-
|
|
586
|
-
```sinth
|
|
587
|
-
for user in users key user.id { UserRow(user: user) }
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
In-place changes like `items.push(x)`, `items.splice(i, 1)` or `todo.done = true` update the UI automatically.
|
|
591
|
-
|
|
592
|
-
## 15. Functions
|
|
593
|
-
|
|
594
|
-
```sinth
|
|
595
|
-
function add(num a, num b) -> num {
|
|
596
|
-
return a + b
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function greet(str name, str greeting = "Hello") -> str {
|
|
600
|
-
return greeting + ", " + name + "!"
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
async function loadUser(num id) -> obj {
|
|
604
|
-
const res = await fetch("/api/users/" + id)
|
|
605
|
-
return await res.json()
|
|
606
|
-
}
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
- Parameters may have types and defaults. Parameter syntax `name: type` also works.
|
|
610
|
-
- `-> type` declares the return type; returning the wrong type is an error.
|
|
611
|
-
- Calling with missing or too many arguments is a compile error (E0315 / E0314).
|
|
612
|
-
- Arguments can be named and given in any order: `greet(greeting: "Hi", name: "Ada")`.
|
|
613
|
-
- Function bodies support `var`, `const`, `if`/`elif`/`else`, `for ... in`, `while`, `return`, `break`, `continue`, and single-line `if cond return x`.
|
|
614
|
-
|
|
615
|
-
Functions can change page state:
|
|
616
|
-
|
|
617
|
-
```sinth
|
|
618
|
-
function addTodo() {
|
|
619
|
-
if draft.trim() == "" { return }
|
|
620
|
-
todos.push({ text: draft.trim(), done: false })
|
|
621
|
-
draft = ""
|
|
622
|
-
}
|
|
623
|
-
```
|
|
624
|
-
|
|
625
|
-
### UI functions
|
|
626
|
-
|
|
627
|
-
A function returning `ui` renders markup and can be called inside markup:
|
|
628
|
-
|
|
629
|
-
```sinth
|
|
630
|
-
function badge(str label, str tone = "info") -> ui {
|
|
631
|
-
Span(class: "badge " + tone) { label }
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
Main {
|
|
635
|
-
badge("New")
|
|
636
|
-
badge("Sale", tone: "danger")
|
|
637
|
-
}
|
|
638
|
-
```
|
|
639
|
-
|
|
640
|
-
## 16. Components
|
|
641
|
-
|
|
642
|
-
```sinth
|
|
643
|
-
-- components/Card.sinth
|
|
644
|
-
component Card(str title, str? subtitle, str accent = "#7c3aed") {
|
|
645
|
-
Article(class: "card") {
|
|
646
|
-
Heading(level: 3) { title }
|
|
647
|
-
if subtitle { Paragraph(class: "sub") { subtitle } }
|
|
648
|
-
$slot
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
style {
|
|
652
|
-
.card {
|
|
653
|
-
borderLeft: "4px solid " + accent
|
|
654
|
-
padding: "1rem"
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
```
|
|
659
|
-
|
|
660
|
-
```sinth
|
|
661
|
-
-- pages/index.sinth
|
|
662
|
-
import { Card } from "../components/Card.sinth"
|
|
663
|
-
|
|
664
|
-
Main {
|
|
665
|
-
Card(title: "Hello", accent: "teal") {
|
|
666
|
-
Paragraph { "Card body" }
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
### Parameters
|
|
672
|
-
|
|
673
|
-
- `str title`: required. Leaving it out is a compile error (E0360).
|
|
674
|
-
- `str? subtitle`: optional, `undefined` when omitted.
|
|
675
|
-
- `str accent = "#7c3aed"`: optional with a default.
|
|
676
|
-
- Parameters are reactive: when the parent passes `title: user.name` and `user.name` changes, the card updates.
|
|
677
|
-
- Parameters are read-only inside the component (E0390). Copy them into a `var` if you need local state: `var num value = start`.
|
|
678
|
-
|
|
679
|
-
### Two-way parameters
|
|
680
|
-
|
|
681
|
-
Declare a parameter with `bind` to let the component write back to the caller's variable:
|
|
682
|
-
|
|
683
|
-
```sinth
|
|
684
|
-
component Toggle(bind checked, str label = "") {
|
|
685
|
-
Label {
|
|
686
|
-
Checkbox(model: checked)
|
|
687
|
-
label
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
var bool dark = false
|
|
692
|
-
Toggle(checked: dark, label: "Dark mode")
|
|
693
|
-
```
|
|
694
|
-
|
|
695
|
-
### Callback parameters
|
|
696
|
-
|
|
697
|
-
Pass functions down to let children notify parents:
|
|
698
|
-
|
|
699
|
-
```sinth
|
|
700
|
-
component TodoItem(obj todo, onRemove) {
|
|
701
|
-
Li {
|
|
702
|
-
Span { todo.text }
|
|
703
|
-
Button(onClick: onRemove(todo)) { "Remove" }
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
TodoItem(todo: t, onRemove: (x) => remove(x))
|
|
708
|
-
```
|
|
709
|
-
|
|
710
|
-
### Attribute fallthrough
|
|
711
|
-
|
|
712
|
-
Attributes that are not parameters (like `class`, `id`, `style`, `ariaLabel` or event handlers) are applied to the component's first root element:
|
|
713
|
-
|
|
714
|
-
```sinth
|
|
715
|
-
Card(title: "Hi", id: "intro", class: "wide", onClick: open = true)
|
|
716
|
-
```
|
|
717
|
-
|
|
718
|
-
### Local state, functions and scripts
|
|
719
|
-
|
|
720
|
-
Each instance has its own state:
|
|
721
|
-
|
|
722
|
-
```sinth
|
|
723
|
-
component Counter(num start = 0) {
|
|
724
|
-
var num n = start
|
|
725
|
-
|
|
726
|
-
function reset() {
|
|
727
|
-
n = start
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
Button(onClick: n += 1) { "Clicked " + n }
|
|
731
|
-
Button(onClick: reset()) { "Reset" }
|
|
732
|
-
}
|
|
733
|
-
```
|
|
734
|
-
|
|
735
|
-
### Recursion
|
|
736
|
-
|
|
737
|
-
Components can render themselves (for trees). Prerendering stops at 64 levels to protect against infinite recursion.
|
|
738
|
-
|
|
739
|
-
### Wrapping built-ins
|
|
740
|
-
|
|
741
|
-
A component may share a name with a built-in element. Inside its own body, the name refers to the HTML element, so you can wrap it:
|
|
742
|
-
|
|
743
|
-
```sinth
|
|
744
|
-
component Button(str variant = "primary") {
|
|
745
|
-
Button(class: "btn btn-" + variant) { $slot }
|
|
746
|
-
}
|
|
747
|
-
```
|
|
748
|
-
|
|
749
|
-
## 17. Slots
|
|
750
|
-
|
|
751
|
-
```sinth
|
|
752
|
-
component Panel(str title) {
|
|
753
|
-
Section(class: "panel") {
|
|
754
|
-
Header { $slot(name: "header") { Strong { title } } }
|
|
755
|
-
$slot
|
|
756
|
-
Footer { $slot(name: "footer", fallback: "No footer") }
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
Panel(title: "Settings") {
|
|
761
|
-
Paragraph { "Main content goes to $slot" }
|
|
762
|
-
slot(name: "footer") {
|
|
763
|
-
Button { "Save" }
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
```
|
|
767
|
-
|
|
768
|
-
- `$slot` renders the default slot (all children that are not inside a `slot(...)` block).
|
|
769
|
-
- `$slot(name: "x")` renders a named slot.
|
|
770
|
-
- Fallback content is given in braces after `$slot` or with `fallback:`.
|
|
771
|
-
- Slot content uses the caller's variables and styles.
|
|
772
|
-
|
|
773
|
-
## 18. Lifecycle and watchers
|
|
774
|
-
|
|
775
|
-
```sinth
|
|
776
|
-
onMount {
|
|
777
|
-
const res = await fetch("/api/posts")
|
|
778
|
-
posts = await res.json()
|
|
779
|
-
loading = false
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
onDestroy {
|
|
783
|
-
clearInterval(timer)
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
watch query {
|
|
787
|
-
results = search(value) -- `value` is the new value, `previous` the old one
|
|
788
|
-
}
|
|
789
|
-
```
|
|
790
|
-
|
|
791
|
-
These work at page level and inside components. `onMount` runs once after the page or component is in the DOM. `watch` runs whenever the expression's value changes (arrays and objects are compared by content).
|
|
792
|
-
|
|
793
|
-
## 19. Styling
|
|
794
|
-
|
|
795
|
-
### Style blocks
|
|
796
|
-
|
|
797
|
-
```sinth
|
|
798
|
-
style {
|
|
799
|
-
main {
|
|
800
|
-
maxWidth: "960px"
|
|
801
|
-
margin: "0 auto"
|
|
802
|
-
padding: "2rem"
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
Paragraph { -- element names become tags: p
|
|
806
|
-
lineHeight: 1.7
|
|
807
|
-
color: "#333"
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
.card {
|
|
811
|
-
padding: "1rem"
|
|
812
|
-
onHover { transform: "translateY(-2px)" } -- &:hover
|
|
813
|
-
before { content: "'→'" } -- &::before
|
|
814
|
-
& + & { marginTop: "1rem" } -- nesting with &
|
|
815
|
-
.title { fontWeight: 700 } -- descendant
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
media(maxWidth: "640px") {
|
|
819
|
-
main { padding: "1rem" }
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
dark { -- @media (prefers-color-scheme: dark)
|
|
823
|
-
body { background: "#0a0a0b"; color: "#f5f5f6" }
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
```
|
|
827
|
-
|
|
828
|
-
Rules:
|
|
829
|
-
|
|
830
|
-
- Property names are camelCase (`backgroundColor` → `background-color`, `WebkitUserSelect` → `-webkit-user-select`). Plain CSS names also work.
|
|
831
|
-
- Values in quotes are unquoted (`padding: "1rem"` → `padding: 1rem`). For `content`, write the CSS string inside the quotes: `content: "'→'"`.
|
|
832
|
-
- Declarations end at a newline or `;`.
|
|
833
|
-
- `--` starts a comment, but `--name:` is a CSS custom property.
|
|
834
|
-
- Pseudo shorthands: `onHover onFocus onActive onVisited onChecked onDisabled onEnabled onRequired onOptional onValid onInvalid onPlaceholderShown onFocusWithin onFocusVisible onFirst onLast onFirstOfType onLastOfType onEmpty onTarget onLink onOpen`.
|
|
835
|
-
- Pseudo-element shorthands: `before after placeholder selection firstLine firstLetter marker backdrop`.
|
|
836
|
-
- Media shorthands: `dark light reducedMotion print mobile tablet desktop`, and `media(minWidth: "800px", orientation: "landscape")`.
|
|
837
|
-
- All CSS at-rules work: `@keyframes`, `@font-face`, `@supports`, `@container`, `@layer`.
|
|
838
|
-
|
|
839
|
-
### Scoping
|
|
840
|
-
|
|
841
|
-
- **Page styles** apply to the whole page.
|
|
842
|
-
- **Component styles** are scoped: they only match elements rendered by that component. `.card` inside `Card` cannot leak into other components.
|
|
843
|
-
- `style global { ... }` inside a component opts out of scoping.
|
|
844
|
-
- `:global(.selector)` escapes scoping for one selector.
|
|
845
|
-
- `html`, `body` and `:root` are never scoped.
|
|
846
|
-
|
|
847
|
-
### Reactive styles
|
|
848
|
-
|
|
849
|
-
A style value that uses a parameter or variable updates automatically (it compiles to a CSS custom property):
|
|
850
|
-
|
|
851
|
-
```sinth
|
|
852
|
-
component Bar(num percent, str color = "teal") {
|
|
853
|
-
Div(class: "bar") { Div(class: "fill") }
|
|
854
|
-
style {
|
|
855
|
-
.fill {
|
|
856
|
-
width: percent + "%"
|
|
857
|
-
background: color
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
```
|
|
862
|
-
|
|
863
|
-
### CSS and SCSS
|
|
864
|
-
|
|
865
|
-
```sinth
|
|
866
|
-
style lang="css" { .a { color: red; } } -- plain CSS
|
|
867
|
-
style lang="scss" { $gap: 1rem; .a { margin: $gap } } -- needs: npm install -D sass
|
|
868
|
-
import "./styles/theme.scss" -- SCSS files too
|
|
869
|
-
```
|
|
870
|
-
|
|
871
|
-
## 20. Script blocks
|
|
872
|
-
|
|
873
|
-
Script blocks contain plain JavaScript that shares the page's (or component's) variables:
|
|
874
|
-
|
|
875
|
-
```sinth
|
|
876
|
-
var num ticks = 0
|
|
877
|
-
|
|
878
|
-
script {
|
|
879
|
-
const timer = setInterval(() => {
|
|
880
|
-
ticks += 1
|
|
881
|
-
sinthRender()
|
|
882
|
-
}, 1000)
|
|
883
|
-
|
|
884
|
-
function formatDate(d) {
|
|
885
|
-
return new Intl.DateTimeFormat("en", { dateStyle: "medium" }).format(d)
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
Paragraph { "Ticks: " + ticks + " · " + formatDate(new Date()) }
|
|
890
|
-
```
|
|
891
|
-
|
|
892
|
-
- Functions and variables declared in a script block can be used from Sinth code.
|
|
893
|
-
- Changes made from Sinth handlers update the UI automatically. Changes from timers, callbacks or third-party code need `sinthRender()` (or `sinth.update()`).
|
|
894
|
-
- Script syntax errors are reported with the correct `.sinth` line number (E0500).
|
|
895
|
-
- `import` statements belong at the top of the `.sinth` file, not inside component scripts.
|
|
896
|
-
|
|
897
|
-
## 21. Imports
|
|
898
|
-
|
|
899
|
-
```sinth
|
|
900
|
-
-- Sinth modules
|
|
901
|
-
import { Card, Badge } from "./components/ui.sinth" -- named
|
|
902
|
-
import { Card as Tile } from "./components/ui.sinth" -- renamed
|
|
903
|
-
import Card from "./components/Card.sinth" -- default: the component named like the file
|
|
904
|
-
import * as UI from "./components/ui.sinth" -- namespace: UI.Card { ... }
|
|
905
|
-
import "./components/Navbar.sinth" -- all components of the file
|
|
906
|
-
import { Button } from "sinth:ui" -- built-in library
|
|
907
|
-
import { Chart } from "charts/Chart" -- from a library folder (libraryPaths)
|
|
908
|
-
import { Map } from "sinth-maps" -- npm package with a "sinth" field
|
|
909
|
-
|
|
910
|
-
-- JavaScript and npm
|
|
911
|
-
import confetti from "canvas-confetti" -- bundled from node_modules
|
|
912
|
-
import { format } from "date-fns"
|
|
913
|
-
import * as utils from "./utils.js" -- .js, .mjs, .ts, .tsx, .jsx
|
|
914
|
-
import "./analytics.js" -- side effects only
|
|
915
|
-
|
|
916
|
-
-- Styles
|
|
917
|
-
import "./styles/reset.css"
|
|
918
|
-
import css "./styles/theme.scss"
|
|
919
|
-
import "https://cdn.example.com/lib.css" -- external stylesheet link
|
|
920
|
-
|
|
921
|
-
-- Data and fonts
|
|
922
|
-
import data from "./data.json" -- inlined at build time
|
|
923
|
-
import { posts, site } from "./content.json"
|
|
924
|
-
import font "Inter:400,600,800" -- Google Fonts (with preconnect)
|
|
925
|
-
|
|
926
|
-
-- External scripts
|
|
927
|
-
import "https://cdn.example.com/widget.js" { defer: true }
|
|
928
|
-
extern Widget -- declare the global it creates
|
|
929
|
-
```
|
|
930
|
-
|
|
931
|
-
Rules:
|
|
932
|
-
|
|
933
|
-
- Extensions are optional for `.sinth` files (`./components/Card`).
|
|
934
|
-
- Paths starting with `/` are relative to the project root.
|
|
935
|
-
- Missing npm packages produce a clear error with the `npm install` command to run.
|
|
936
|
-
- Circular imports between `.sinth` files are an error (E0609).
|
|
937
|
-
- Importing a name that does not exist lists the available exports (E0602).
|
|
938
|
-
|
|
939
|
-
### Publishing Sinth components on npm
|
|
940
|
-
|
|
941
|
-
Add a `sinth` field pointing to your entry file:
|
|
942
|
-
|
|
943
|
-
```json
|
|
944
|
-
{ "name": "sinth-charts", "sinth": "index.sinth" }
|
|
945
|
-
```
|
|
946
|
-
|
|
947
|
-
Users can then write `import { BarChart } from "sinth-charts"`.
|
|
948
|
-
|
|
949
|
-
## 22. Shared state (stores)
|
|
950
|
-
|
|
951
|
-
Top-level variables and functions in a module file are shared by every page and component that imports them:
|
|
952
|
-
|
|
953
|
-
```sinth
|
|
954
|
-
-- stores/cart.sinth
|
|
955
|
-
var obj[] items = []
|
|
956
|
-
computed num count = items.length
|
|
957
|
-
|
|
958
|
-
function add(obj product) {
|
|
959
|
-
items.push(product)
|
|
960
|
-
}
|
|
961
|
-
```
|
|
962
|
-
|
|
963
|
-
```sinth
|
|
964
|
-
import { items, count, add } from "../stores/cart.sinth"
|
|
965
|
-
|
|
966
|
-
Button(onClick: add({ name: "Shirt" })) { "Add (" + count + ")" }
|
|
967
|
-
```
|
|
968
|
-
|
|
969
|
-
Assignments like `items = []` from the importing file work too.
|
|
970
|
-
|
|
971
|
-
## 23. The sinth:ui library
|
|
972
|
-
|
|
973
|
-
A small, accessible component library that ships with Sinth. It supports light and dark mode automatically.
|
|
974
|
-
|
|
975
|
-
```sinth
|
|
976
|
-
import { Button, Card, Field, Modal } from "sinth:ui"
|
|
977
|
-
```
|
|
978
|
-
|
|
979
|
-
| Component | Parameters |
|
|
980
|
-
|---|---|
|
|
981
|
-
| `Button` | `variant` (`primary` `secondary` `ghost` `danger`), `size` (`sm` `md` `lg`), `href` (renders a link), `disabled`, `type`, `block` |
|
|
982
|
-
| `Card` | `title`, `subtitle`, `interactive`; slot `footer` |
|
|
983
|
-
| `Badge` | `tone` (`neutral` `accent` `success` `warning` `danger`) |
|
|
984
|
-
| `Alert` | `tone` (`info` `success` `warning` `danger`), `title` |
|
|
985
|
-
| `Content` | `width` (`sm` `md` `lg` `full`): centered page column |
|
|
986
|
-
| `Columns` | `min` (minimum column width), `gap`: responsive grid |
|
|
987
|
-
| `Inline` | `gap`, `align`, `justify`, `wrap`: horizontal row |
|
|
988
|
-
| `VStack` | `gap`, `align`: vertical stack |
|
|
989
|
-
| `Field` | `label`, `bind value`, `type` (any input type or `textarea`), `placeholder`, `hint`, `error`, `required`, `name` |
|
|
990
|
-
| `Toggle` | `bind checked`, `label` |
|
|
991
|
-
| `Modal` | `bind open`, `title`, `width`; slot `footer`. Closes on backdrop click and Escape |
|
|
992
|
-
| `Avatar` | `name`, `src`, `size`; shows initials without `src` |
|
|
993
|
-
| `Spinner` | `size`, `label` |
|
|
994
|
-
| `Navbar` | `brand`, `brandHref`; links as children |
|
|
995
|
-
| `Divider` | `label` |
|
|
996
|
-
|
|
997
|
-
Theme it by overriding custom properties:
|
|
998
|
-
|
|
999
|
-
```sinth
|
|
1000
|
-
style {
|
|
1001
|
-
:root {
|
|
1002
|
-
--ui-accent: "#0ea5e9"
|
|
1003
|
-
--ui-radius: "6px"
|
|
1004
|
-
--ui-font: "'Inter', system-ui, sans-serif"
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
```
|
|
1008
|
-
|
|
1009
|
-
Variables: `--ui-bg --ui-surface --ui-surface-2 --ui-text --ui-muted --ui-border --ui-accent --ui-accent-hover --ui-accent-text --ui-success --ui-warning --ui-danger --ui-info --ui-radius --ui-radius-lg --ui-shadow --ui-font --ui-mono`.
|
|
1010
|
-
|
|
1011
|
-
The library also sets a light base style for `body`, links and focus rings. The legacy `import SinthUI` imports the whole library.
|
|
1012
|
-
|
|
1013
|
-
## 24. Custom elements
|
|
1014
|
-
|
|
1015
|
-
Any component can be exported as a standard web component that works in any HTML page, framework or CMS:
|
|
1016
|
-
|
|
1017
|
-
```sinth
|
|
1018
|
-
-- components/Counter.sinth
|
|
1019
|
-
component Counter(num start = 0, str label = "Count") as <sinth-counter> {
|
|
1020
|
-
var num n = start
|
|
1021
|
-
Button(onClick: n += 1) { label + ": " + n }
|
|
1022
|
-
}
|
|
1023
|
-
```
|
|
1024
|
-
|
|
1025
|
-
`sinth build` writes `dist/elements/sinth-counter.js`, a standalone file with the runtime and the component's CSS:
|
|
1026
|
-
|
|
1027
|
-
```html
|
|
1028
|
-
<script type="module" src="/elements/sinth-counter.js"></script>
|
|
1029
|
-
<sinth-counter start="5" label="Clicks"></sinth-counter>
|
|
1030
|
-
```
|
|
1031
|
-
|
|
1032
|
-
- Attributes are converted to the parameter types (`num`, `bool`, and `obj`/arrays as JSON).
|
|
1033
|
-
- Changing an attribute or a property (`el.label = "x"`) updates the element.
|
|
1034
|
-
- Children of the custom element become its default slot.
|
|
1035
|
-
- Tag names must be lowercase and contain a dash.
|
|
1036
|
-
- The Sinth 4 syntax `custom-element Counter(export: <sinth-counter/>) { ... }` still works.
|
|
1037
|
-
|
|
1038
|
-
## 25. Rendering model and performance
|
|
1039
|
-
|
|
1040
|
-
- **Prerendering**: every page is rendered to static HTML at build time, so content is visible immediately and indexable by search engines.
|
|
1041
|
-
- **No JavaScript when none is needed**: if a page has no events, bindings, scripts, watchers or values that can only be known in the browser, Sinth ships no JavaScript at all for it.
|
|
1042
|
-
- **Fine-grained updates**: interactive pages mount a ~5 kB runtime. Each binding is updated only when its value actually changes. Text, attributes and keyed lists are patched in place; nothing is re-rendered with `innerHTML`.
|
|
1043
|
-
- **Code splitting**: shared code across pages is split into cached chunks, and `<link rel="modulepreload">` tags are added automatically.
|
|
1044
|
-
- **Static subtrees**: purely static markup inside interactive pages is created from cached templates.
|
|
1045
|
-
- **Hashed assets**: files in `dist/_sinth/` have content hashes and are served with long-lived caching headers.
|
|
1046
|
-
|
|
1047
|
-
The browser runtime is exposed for interop as `window.sinth` (`sinth.update()`, `sinth.schedule()`) and `window.sinthRender()`.
|
|
1048
|
-
|
|
1049
|
-
## 26. Security
|
|
1050
|
-
|
|
1051
|
-
Sinth is designed to be safe by default.
|
|
1052
|
-
|
|
1053
|
-
- **No `eval`**: neither the compiler nor the runtime evaluates strings as code. Build-time prerendering uses an AST interpreter.
|
|
1054
|
-
- **Escaped output**: all text and attribute values are escaped. Only `RawHTML`/`html:` insert HTML, and the compiler warns when that content is dynamic.
|
|
1055
|
-
- **No inline handlers**: event handlers are attached with `addEventListener`, so pages work under a strict Content Security Policy without `'unsafe-inline'` scripts. `onclick: "..."` strings are compile errors.
|
|
1056
|
-
- **URL sanitizing**: dynamic `href`, `src`, `action` and similar attributes that resolve to `javascript:`, `vbscript:` or HTML `data:` URLs are blocked.
|
|
1057
|
-
- **Security headers**: builds include a `_headers` file (Cloudflare Pages and Netlify format) with a Content Security Policy, `X-Content-Type-Options`, `Referrer-Policy`, `X-Frame-Options` and `Cross-Origin-Opener-Policy`. External scripts, styles and fonts you import are added to the CSP automatically.
|
|
1058
|
-
- **Safe dev server**: binds to `127.0.0.1` by default, rejects path traversal and only serves your project's public and static folders.
|
|
1059
|
-
- **Safe builds**: `sinth build` refuses to empty an output folder it did not create.
|
|
1060
|
-
- **Safe deploys**: deployment arguments are validated and passed to Wrangler without shell interpolation.
|
|
1061
|
-
|
|
1062
|
-
Configure the CSP in `sinth.config.json`:
|
|
1063
|
-
|
|
1064
|
-
```json
|
|
1065
|
-
{ "security": { "csp": "default-src 'self'; img-src * data:" } }
|
|
1066
|
-
```
|
|
1067
|
-
|
|
1068
|
-
Set `"csp": false` to omit it, or `"headers": false` to skip the `_headers` file.
|
|
1069
|
-
|
|
1070
|
-
Report vulnerabilities privately as described in [SECURITY.md](./SECURITY.md).
|
|
1071
|
-
|
|
1072
|
-
## 27. The CLI
|
|
1073
|
-
|
|
1074
|
-
```
|
|
1075
|
-
sinth create [name] [--template starter|minimal|blank] [--yes] [--force]
|
|
1076
|
-
sinth dev [--port 3000] [--host [address]] [--open]
|
|
1077
|
-
sinth build [--out dist] [--no-minify] [--sourcemap]
|
|
1078
|
-
sinth preview [--port 4000] [--host [address]] [--open]
|
|
1079
|
-
sinth deploy [--preview] [--branch name] [--project name] [--create] [--skip-build]
|
|
1080
|
-
sinth check [--json]
|
|
1081
|
-
sinth new page <path> | sinth new component <Name>
|
|
1082
|
-
sinth info
|
|
1083
|
-
sinth version
|
|
1084
|
-
sinth help [command]
|
|
1085
|
-
```
|
|
1086
|
-
|
|
1087
|
-
Every command accepts `--root <dir>` to run against another folder. Aliases: `init` = `create`, `start` = `dev`, `serve` = `preview`.
|
|
1088
|
-
|
|
1089
|
-
| Command | What it does |
|
|
1090
|
-
|---|---|
|
|
1091
|
-
| `create` | Scaffolds a project. Templates: `starter` (layout, two pages, 404, sinth:ui), `minimal` (one page), `blank` (config only). |
|
|
1092
|
-
| `dev` | Dev server with hot reload, state preservation and an error overlay. |
|
|
1093
|
-
| `build` | Production build: prerendering, minification, code splitting, hashed assets, headers, sitemap. |
|
|
1094
|
-
| `preview` | Serves the build with clean URLs, `_headers` and `404.html`, like Cloudflare Pages. |
|
|
1095
|
-
| `deploy` | Builds and deploys to Cloudflare Pages through Wrangler. |
|
|
1096
|
-
| `check` | Type-checks every page and module without writing files. `--json` prints machine-readable diagnostics. |
|
|
1097
|
-
| `new` | Creates a page (`sinth new page blog/first-post`) or component (`sinth new component ProductCard`). |
|
|
1098
|
-
| `info` | Prints versions and project settings, useful for bug reports. |
|
|
1099
|
-
|
|
1100
|
-
The CLI checks for updates at most once a day (never in CI). Disable with `SINTH_NO_UPDATE_CHECK=1`. Disable colors with `NO_COLOR=1`.
|
|
1101
|
-
|
|
1102
|
-
## 28. Configuration
|
|
1103
|
-
|
|
1104
|
-
`sinth.config.json` is optional. All options:
|
|
1105
|
-
|
|
1106
|
-
```json
|
|
1107
|
-
{
|
|
1108
|
-
"$schema": "./node_modules/@yannosay/sinth/schema/sinth.config.schema.json",
|
|
1109
|
-
"outDir": "dist",
|
|
1110
|
-
"pagesDir": "pages",
|
|
1111
|
-
"publicDir": "public",
|
|
1112
|
-
"staticDirs": ["assets"],
|
|
1113
|
-
"libraryPaths": ["libraries"],
|
|
1114
|
-
"site": "https://example.com",
|
|
1115
|
-
"base": "/",
|
|
1116
|
-
"minify": true,
|
|
1117
|
-
"sourcemap": false,
|
|
1118
|
-
"port": 3000,
|
|
1119
|
-
"host": "127.0.0.1",
|
|
1120
|
-
"previewPort": 4000,
|
|
1121
|
-
"target": ["es2020", "chrome90", "firefox90", "safari15", "edge90"],
|
|
1122
|
-
"security": { "headers": true, "csp": true },
|
|
1123
|
-
"cloudflare": { "projectName": "my-site", "accountId": "…", "productionBranch": "main" },
|
|
1124
|
-
"development": { "sourcemap": true },
|
|
1125
|
-
"production": { "minify": true }
|
|
1126
|
-
}
|
|
1127
|
-
```
|
|
1128
|
-
|
|
1129
|
-
| Option | Default | Description |
|
|
1130
|
-
|---|---|---|
|
|
1131
|
-
| `outDir` | `dist` | Build output folder |
|
|
1132
|
-
| `pagesDir` | `pages` | Folder containing pages |
|
|
1133
|
-
| `publicDir` | `public` | Copied to the output root |
|
|
1134
|
-
| `staticDirs` | `["assets"]` | Copied to `<outDir>/<name>` |
|
|
1135
|
-
| `libraryPaths` | `["libraries"]` | Folders searched for bare imports like `"ui/Button"` |
|
|
1136
|
-
| `site` | none | Public URL; enables `sitemap.xml` and `robots.txt` |
|
|
1137
|
-
| `base` | `/` | URL prefix when hosting in a subfolder |
|
|
1138
|
-
| `minify` | `true` in build | Minify JS and CSS |
|
|
1139
|
-
| `sourcemap` | `true` in dev | Emit source maps |
|
|
1140
|
-
| `port` / `host` | `3000` / `127.0.0.1` | Dev server address |
|
|
1141
|
-
| `previewPort` | `4000` | Preview server port |
|
|
1142
|
-
| `target` | modern browsers | esbuild targets for JS and CSS |
|
|
1143
|
-
| `security.headers` | `true` | Write `_headers` |
|
|
1144
|
-
| `security.csp` | `true` | `true` (generated), `false`, or a custom policy string |
|
|
1145
|
-
| `cloudflare` | `{}` | Deployment settings (see [31](#31-deploying)) |
|
|
1146
|
-
| `development` / `production` | none | Overrides per mode |
|
|
1147
|
-
|
|
1148
|
-
Command-line flags override the config file. Unknown keys produce a warning; wrong types produce an error. The Sinth 4 options `sharedRuntime`, `inlineJS` and `inlineCSS` are accepted and ignored, since splitting and bundling are automatic.
|
|
1149
|
-
|
|
1150
|
-
## 29. Dev server
|
|
1151
|
-
|
|
1152
|
-
`sinth dev` builds in memory and serves your site:
|
|
1153
|
-
|
|
1154
|
-
- **Hot module replacement**: saving a `.sinth` file swaps the page's code without a reload and **keeps your state** (variables, form inputs). CSS-only changes are applied without touching the page. Changes to metadata reload the page.
|
|
1155
|
-
- **Error overlay**: compile errors appear in the browser with the code frame and a hint, and disappear when fixed. Runtime errors are shown too.
|
|
1156
|
-
- **Clean URLs**: `/about`, `/about.html` and `/blog/` all work.
|
|
1157
|
-
- **Static files** from `public/` and your static folders are served directly; changing them reloads the page.
|
|
1158
|
-
- If the port is busy, the next free port is used.
|
|
1159
|
-
- `--host` exposes the server on your network (e.g. to test on a phone).
|
|
1160
|
-
|
|
1161
|
-
Editor temp files and folders like `node_modules`, `dist` and `.git` are ignored.
|
|
1162
|
-
|
|
1163
|
-
## 30. Building and output
|
|
1164
|
-
|
|
1165
|
-
`sinth build` produces:
|
|
1166
|
-
|
|
1167
|
-
```
|
|
1168
|
-
dist/
|
|
1169
|
-
├─ index.html, about.html, blog/index.html, 404.html
|
|
1170
|
-
├─ _sinth/
|
|
1171
|
-
│ ├─ index-HASH.js page entry (only for interactive pages)
|
|
1172
|
-
│ ├─ index-HASH.css page styles
|
|
1173
|
-
│ ├─ chunks/… shared code
|
|
1174
|
-
│ └─ assets/… images and fonts referenced from CSS
|
|
1175
|
-
├─ elements/… standalone custom elements
|
|
1176
|
-
├─ _headers security and caching headers
|
|
1177
|
-
├─ sitemap.xml, robots.txt (when "site" is set)
|
|
1178
|
-
└─ contents of public/ and static folders
|
|
1179
|
-
```
|
|
1180
|
-
|
|
1181
|
-
The output is standard HTML, CSS and JavaScript with no server runtime, so it runs on Cloudflare Pages, Netlify, Vercel, GitHub Pages, S3, nginx or any static host. Pages are written as `about.html`; most hosts serve them at `/about` (on GitHub Pages and nginx, links to `/about.html` or a rewrite rule may be needed).
|
|
1182
|
-
|
|
1183
|
-
The build prints every page with its size and whether it ships JavaScript:
|
|
1184
|
-
|
|
1185
|
-
```
|
|
1186
|
-
/ index.html 2.3 kB js 5.1 kB css 8.3 kB
|
|
1187
|
-
/about about.html 1.2 kB no js css 8.2 kB
|
|
1188
|
-
```
|
|
1189
|
-
|
|
1190
|
-
## 31. Deploying
|
|
1191
|
-
|
|
1192
|
-
### Cloudflare Pages
|
|
1193
|
-
|
|
1194
|
-
```bash
|
|
1195
|
-
npx wrangler@4 login # once
|
|
1196
|
-
sinth deploy --create # first deploy: creates the project
|
|
1197
|
-
sinth deploy # production
|
|
1198
|
-
sinth deploy --preview # preview URL
|
|
1199
|
-
```
|
|
1200
|
-
|
|
1201
|
-
Configuration:
|
|
1202
|
-
|
|
1203
|
-
```json
|
|
1204
|
-
{
|
|
1205
|
-
"cloudflare": {
|
|
1206
|
-
"projectName": "my-site",
|
|
1207
|
-
"productionBranch": "main",
|
|
1208
|
-
"accountId": "0123456789abcdef0123456789abcdef"
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
```
|
|
1212
|
-
|
|
1213
|
-
- `projectName` defaults to your `package.json` name (lowercase letters, numbers and dashes).
|
|
1214
|
-
- In CI, set `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` instead of logging in.
|
|
1215
|
-
|
|
1216
|
-
Example GitHub Actions workflow:
|
|
1217
|
-
|
|
1218
|
-
```yaml
|
|
1219
|
-
name: Deploy
|
|
1220
|
-
on: { push: { branches: [main] } }
|
|
1221
|
-
jobs:
|
|
1222
|
-
deploy:
|
|
1223
|
-
runs-on: ubuntu-latest
|
|
1224
|
-
steps:
|
|
1225
|
-
- uses: actions/checkout@v4
|
|
1226
|
-
- uses: actions/setup-node@v4
|
|
1227
|
-
with: { node-version: 22 }
|
|
1228
|
-
- run: npm ci
|
|
1229
|
-
- run: npx sinth deploy
|
|
1230
|
-
env:
|
|
1231
|
-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
1232
|
-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
1233
|
-
```
|
|
1234
|
-
|
|
1235
|
-
### Other hosts
|
|
1236
|
-
|
|
1237
|
-
Run `sinth build` and upload `dist/`. On Netlify the `_headers` file is used automatically. Other hosts ignore it, so configure the headers there if you want them.
|
|
1238
|
-
|
|
1239
|
-
## 32. Editor support
|
|
1240
|
-
|
|
1241
|
-
- **VS Code**: the official extension provides syntax highlighting, completions for elements, attributes, events, modifiers, metadata keys, your own components and sinth:ui (with auto-import), hover documentation, go to definition, snippets, error checking with `sinth check`, and commands to run the dev server, build, preview and deploy. Download `sinth-vscode-*.vsix` from the [latest release](https://github.com/Yannosay/sinth/releases/latest) and run **Extensions: Install from VSIX**.
|
|
1242
|
-
- **Sinth IDE**: a desktop editor for Windows, macOS and Linux with Sinth highlighting, completions, inline diagnostics on save, a Problems list, an integrated terminal, one-click Run/Build/Preview/Deploy and automatic updates. Download it from [Sinth IDE releases](https://github.com/Yannosay/sinth-ide/releases/latest).
|
|
1243
|
-
- **Other editors**: run `sinth check --json` for diagnostics in any tool.
|
|
1244
|
-
|
|
1245
|
-
## 33. Programmatic API
|
|
1246
|
-
|
|
1247
|
-
```js
|
|
1248
|
-
const { loadConfig, Project, buildProject, checkProject, parseSinth } = require("@yannosay/sinth");
|
|
1249
|
-
|
|
1250
|
-
const root = process.cwd();
|
|
1251
|
-
const { config } = loadConfig(root, "production");
|
|
1252
|
-
const project = new Project(root, config, false);
|
|
1253
|
-
|
|
1254
|
-
const result = await buildProject(project, { write: true });
|
|
1255
|
-
console.log(result.pages.map(p => p.page.route));
|
|
1256
|
-
|
|
1257
|
-
const { errors, warnings } = checkProject(project);
|
|
1258
|
-
const ast = parseSinth(source, "file.sinth");
|
|
1259
|
-
```
|
|
1260
|
-
|
|
1261
|
-
Errors are `SinthError` instances with `code`, `loc` and `diagnostic`; `formatDiagnostic(diagnostic, color)` renders them like the CLI does.
|
|
1262
|
-
|
|
1263
|
-
## 34. Error reference
|
|
1264
|
-
|
|
1265
|
-
| Code | Meaning |
|
|
1266
|
-
|---|---|
|
|
1267
|
-
| E0001 | Invalid character, string or number |
|
|
1268
|
-
| E0100 | Syntax error |
|
|
1269
|
-
| E0102 | Reserved word used as a name |
|
|
1270
|
-
| E0103 | Invalid assignment target |
|
|
1271
|
-
| E0104 | The removed `page` keyword (delete the line) |
|
|
1272
|
-
| E0201 | Unknown type |
|
|
1273
|
-
| E0202 | Name declared twice in the same scope |
|
|
1274
|
-
| E0210 | `persist` outside page or component state |
|
|
1275
|
-
| E0301 | Unknown component or element |
|
|
1276
|
-
| E0302 | Unknown name |
|
|
1277
|
-
| E0310 | `$slot` outside a component |
|
|
1278
|
-
| E0311–E0316 | Wrong function or slot arguments (unknown, duplicated, too many, missing, misordered) |
|
|
1279
|
-
| E0320 | Invalid heading level |
|
|
1280
|
-
| E0330–E0334 | Invalid element content or attribute (children on void elements, inline `on*` strings, ...) |
|
|
1281
|
-
| E0340, E0341 | `model`/`ref` without a variable |
|
|
1282
|
-
| E0350, E0351 | A non-function or a string used as event handler |
|
|
1283
|
-
| E0360 | Missing required component parameter |
|
|
1284
|
-
| E0370, E0371 | UI function or component used as a value |
|
|
1285
|
-
| E0380 | Returning a value from a `void` function |
|
|
1286
|
-
| E0390–E0394 | Assigning to a parameter, constant, computed value, function or loop variable |
|
|
1287
|
-
| E0400–E0403 | Type errors |
|
|
1288
|
-
| E0400 (in a style block) | Invalid style syntax |
|
|
1289
|
-
| E0402 | SCSS compile error |
|
|
1290
|
-
| E0500, E0501 | Script block syntax error / `import` inside a component script |
|
|
1291
|
-
| E0600–E0609 | Import errors (file not found, unknown export, circular import, ...) |
|
|
1292
|
-
| E0700 | Metadata value can't be computed at build time |
|
|
1293
|
-
| E0701 | Metadata value is an object or array |
|
|
1294
|
-
| E0710 | Dynamic route without `paths` |
|
|
1295
|
-
| E0711 | `paths` is not an array computable at build time |
|
|
1296
|
-
| E0712 | Invalid, missing or duplicate value in `paths` |
|
|
1297
|
-
| E0713 | `paths` in a page that is not a dynamic route |
|
|
1298
|
-
| E0714 | Invalid route parameter name |
|
|
1299
|
-
| E0800 | Bundling error (e.g. missing npm package) |
|
|
1300
|
-
| E0801 | Output folder not created by Sinth |
|
|
1301
|
-
| E0802 | No pages found |
|
|
1302
|
-
| E0899 | Internal compiler error (please report it) |
|
|
1303
|
-
| E0900–E0902 | Invalid configuration |
|
|
1304
|
-
| E1000 | No build to preview |
|
|
1305
|
-
| E1100–E1105 | Deployment errors |
|
|
1306
|
-
| E1200–E1202 | Invalid command-line options |
|
|
1307
|
-
| E1300–E1305 | `new`/`create` errors |
|
|
1308
|
-
| W0101 | Markup outside a component in a module file |
|
|
1309
|
-
| W0201 | `int` is deprecated |
|
|
1310
|
-
| W0301 | Unescaped dynamic HTML |
|
|
1311
|
-
| W0310 | Unknown component parameter passed to the root element (likely typo) |
|
|
1312
|
-
| W0401 | `null` assigned to a non-nullable variable |
|
|
1313
|
-
| W0800 | Bundler warning |
|
|
1314
|
-
|
|
1315
|
-
## 35. Migrating from Sinth 4
|
|
1316
|
-
|
|
1317
|
-
Most Sinth 4 code compiles unchanged. Things to check:
|
|
1318
|
-
|
|
1319
|
-
| Sinth 4 | Sinth 5 |
|
|
1320
|
-
|---|---|
|
|
1321
|
-
| `page` at the top of every page | removed: delete the line (E0104). Every file in `pages/` is a page; move pages that lived elsewhere into `pages/` |
|
|
1322
|
-
| `dist/pages/index.html` | `dist/index.html`: pages are now relative to `pages/` |
|
|
1323
|
-
| `var int x` | `var num x` (`int` still works with a warning) |
|
|
1324
|
-
| `==` was loose | `==` is strict: `1 == "1"` is a compile error |
|
|
1325
|
-
| `"$title"` inside component strings | use the parameter directly: `{ title }` or `f"{title}"` |
|
|
1326
|
-
| event handler strings like `onClick: "handler"` | `onClick: handler` or `onClick: handler()` (strings are now a compile error, E0351) |
|
|
1327
|
-
| `for k, v in obj` (key, value) | `for value, index, key in obj` |
|
|
1328
|
-
| `sharedRuntime`, `inlineJS`, `inlineCSS` | removed: splitting and bundling are automatic |
|
|
1329
|
-
| `import SinthUI` (CSS only) | still works; it now also provides real components (`sinth:ui`) |
|
|
1330
|
-
| `sinthRender()` in scripts | still works; usually unnecessary in Sinth handlers |
|
|
1331
|
-
| `RawHTML(content: ...)` | unchanged; warns when the content is dynamic |
|
|
1332
|
-
| `fullscreen:` attribute | removed; use `document.documentElement.requestFullscreen()` |
|
|
1333
|
-
|
|
1334
|
-
Run `sinth check` after upgrading. It reports every incompatibility with its location.
|
|
1335
|
-
|
|
1336
|
-
## 36. FAQ
|
|
1337
|
-
|
|
1338
|
-
**Does Sinth need a framework or runtime on the server?**
|
|
1339
|
-
No. The output is HTML, CSS and JavaScript that any web host can serve.
|
|
1340
|
-
|
|
1341
|
-
**Can I use npm packages?**
|
|
1342
|
-
Yes. Install them and import them. They are bundled and tree-shaken.
|
|
1343
|
-
|
|
1344
|
-
**Can I use TypeScript?**
|
|
1345
|
-
Import `.ts` files directly; they are compiled during bundling. Sinth itself has its own type annotations.
|
|
1346
|
-
|
|
1347
|
-
**How do I fetch data?**
|
|
1348
|
-
In `onMount`, an event handler or an `async function`. The UI updates when the promise settles.
|
|
1349
|
-
|
|
1350
|
-
**How do I share layouts?**
|
|
1351
|
-
Make a `Layout` component with `$slot` and wrap each page in it. The starter template does this.
|
|
1352
|
-
|
|
1353
|
-
**Why is my page shipping JavaScript?**
|
|
1354
|
-
It has an event, binding, script, watcher, lifecycle hook, persisted variable, JS import, or a value that can only be computed in the browser. Pages without these ship none.
|
|
1355
|
-
|
|
1356
|
-
**Can I host under a subfolder?**
|
|
1357
|
-
Set `"base": "/docs/"`.
|
|
1358
|
-
|
|
1359
|
-
**Where do I report bugs?**
|
|
1360
|
-
[github.com/Yannosay/sinth/issues](https://github.com/Yannosay/sinth/issues). Include the output of `sinth info`.
|