@yannosay/sinth 5.3.1 → 5.3.3

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.
@@ -0,0 +1,174 @@
1
+ # Sinth language reference (condensed)
2
+
3
+ Complete docs: https://sinth.yannosay.com/llms-full.txt
4
+
5
+ ## Declarations
6
+
7
+ ```sinth
8
+ var num count = 0 -- reactive state; assigning updates the UI
9
+ const str API = "/api" -- cannot be reassigned
10
+ computed num double = count * 2 -- derived, read-only
11
+ persist var str theme = "dark" -- saved in localStorage
12
+ var str? nickname -- nullable, starts as null
13
+ ```
14
+
15
+ Types: `str`, `num`, `bool`, `obj`, `any`, arrays with `[]` (`str[]`, `obj[]`), nullable with `?`. The type may be omitted when there is an initial value.
16
+
17
+ ## Expressions
18
+
19
+ JavaScript expressions with `and`/`or`/`not`, strict `==`, `f"Hello {name}"` strings, `range(1, 6)`, arrow functions `(x) => x * 2`, and everything in the JS standard library (`fetch`, `Math`, `JSON`, `Intl`, array methods). `$fn(x)` memoizes a call.
20
+
21
+ ## Functions
22
+
23
+ ```sinth
24
+ function greet(str name, str greeting = "Hello") -> str {
25
+ return greeting + ", " + name + "!"
26
+ }
27
+
28
+ async function load() {
29
+ try {
30
+ const res = await fetch("/api/items")
31
+ items = await res.json()
32
+ } catch (e) {
33
+ error = e.message
34
+ }
35
+ }
36
+ ```
37
+
38
+ Calls are checked: missing or extra arguments are compile errors. Named arguments work: `greet(name: "Ada")`.
39
+
40
+ ## Markup
41
+
42
+ ```sinth
43
+ Main {
44
+ Heading(level: 1) { "Welcome" }
45
+ Paragraph(class: "lead") { "Hello, " + name }
46
+ Link(href: "/about") { "About" }
47
+ Img(src: "/logo.png", alt: "Logo")
48
+ }
49
+ ```
50
+
51
+ Attributes: `class` accepts a string, a list or `{ active: on }`; `style` a string or object; CSS properties can be attributes (`color: "gray"`). Special: `model`/`bind`, `ref: el`, `show: cond`, `hide: cond`, `html: trusted`, `key`.
52
+
53
+ ## Events
54
+
55
+ `onClick: count += 1`, `onClick: save()`, `onClick: (e) => log(e)`, `onInput: q = e.target.value`. Modifiers: `.prevent .stop .once .self .passive .capture`, keys `.enter .esc .space .tab .up .down .left .right .delete`, system keys `.ctrl .shift .alt .meta`.
56
+
57
+ ## Conditionals and loops
58
+
59
+ ```sinth
60
+ if loggedIn { Paragraph { "Hi" } } elif loading { Spinner() } else { LoginButton() }
61
+ if open persist { Settings() } -- keep state while hidden
62
+ if visible transition("fade") { Toast() } -- fade-enter / fade-leave classes
63
+
64
+ for item, i in items key item.id { Li { (i + 1) + ". " + item.name } }
65
+ for item in items if item.visible { Card(title: item.title) } else { Paragraph { "Nothing here." } }
66
+ for n in range(1, 11) { Span { n } }
67
+ for value, i, key in settings { Dt { key } Dd { value } }
68
+ ```
69
+
70
+ Use `key` when list items are replaced by new objects (for example after a fetch).
71
+
72
+ ## Forms
73
+
74
+ ```sinth
75
+ Input(model: name)
76
+ Input(type: "number", model: age)
77
+ Textarea(model: bio)
78
+ Checkbox(model: agree)
79
+ Checkbox(value: "cheese", model: toppings) -- str[] of checked values
80
+ Radio(name: "plan", value: "pro", model: plan)
81
+ Select(model: plan) { Option(value: "free") { "Free" } Option(value: "pro") { "Pro" } }
82
+ ```
83
+
84
+ ## Components
85
+
86
+ ```sinth
87
+ -- components/Card.sinth
88
+ component Card(str title, str? subtitle, str accent = "#7c3aed") {
89
+ Article(class: "card") {
90
+ Heading(level: 3) { title }
91
+ if subtitle { Paragraph { subtitle } }
92
+ $slot
93
+ }
94
+ style {
95
+ .card { borderLeft: "4px solid " + accent; padding: "1rem" }
96
+ }
97
+ }
98
+
99
+ component Toggle(bind checked, str label = "") { -- bind: writes back to the caller
100
+ Label { Checkbox(model: checked) " " + label }
101
+ }
102
+ ```
103
+
104
+ Use: `Card(title: "Hello") { Paragraph { "Body" } }`, `Toggle(checked: dark, label: "Dark")`. Parameters are read-only inside the component; copy into a `var` for local state. Named slots: `$slot(name: "footer")` in the component (fallback in braces after it, or `fallback: "..."`), `slot(name: "footer") { ... }` at the call site.
105
+
106
+ ## Lifecycle and watchers
107
+
108
+ ```sinth
109
+ onMount {
110
+ const id = setInterval(() => { seconds += 1 }, 1000)
111
+ return () => clearInterval(id) -- runs when the component is removed
112
+ }
113
+ onDestroy { console.log("gone") }
114
+ watch query { results = search(value) } -- `value` and `previous`
115
+ ```
116
+
117
+ ## Shared state (stores)
118
+
119
+ Top-level `var`s and functions in a module file are shared by everything that imports them:
120
+
121
+ ```sinth
122
+ -- stores/cart.sinth
123
+ var obj[] items = []
124
+ computed num count = items.length
125
+ function add(obj product) { items.push(product) }
126
+ ```
127
+
128
+ ## Imports
129
+
130
+ ```sinth
131
+ import { Card } from "../components/Card.sinth"
132
+ import Card from "/components/Card.sinth" -- "/" = the source folder (project root or app/)
133
+ import { Button, Modal } from "sinth:ui" -- built-in component library
134
+ import confetti from "canvas-confetti" -- npm packages are bundled
135
+ import data from "./data.json" -- inlined at build time
136
+ import "./styles/reset.css"
137
+ import font "Inter:400,600" -- Google Fonts
138
+ extern Chart -- a global from an external script
139
+ ```
140
+
141
+ ## Styles
142
+
143
+ ```sinth
144
+ style {
145
+ main { maxWidth: "960px"; margin: "0 auto" }
146
+ .card {
147
+ padding: "1rem"
148
+ onHover { transform: "translateY(-2px)" }
149
+ .title { fontWeight: 700 }
150
+ }
151
+ media(maxWidth: "640px") { main { padding: "1rem" } }
152
+ dark { body { background: "#0a0a0b" } }
153
+ .box { background: "hsl(" + hue + ", 80%, 60%)" } -- reactive values work
154
+ }
155
+ ```
156
+
157
+ ## Metadata
158
+
159
+ `title`, `descr`, `favicon`, `lang`, `canonical`, `ogImage`, `themeColor`, `robots`, `jsonLd`, ... as `key = value` at the top of a page. Evaluated at build time.
160
+
161
+ ## Routing
162
+
163
+ Every `.sinth` file in `pages/` is a page: `pages/about.sinth` is `/about`, `pages/blog/index.sinth` is `/blog`, `pages/404.sinth` is the 404 page. Files and folders starting with `_` are not pages. Dynamic routes use brackets and list their values:
164
+
165
+ ```sinth
166
+ -- pages/blog/[slug].sinth
167
+ import posts from "../../content/posts.json"
168
+ paths = posts.map((p) => p.slug)
169
+ const post = posts.find((p) => p.slug == slug)
170
+ title = post.title
171
+ Main { Heading(level: 1) { post.title } }
172
+ ```
173
+
174
+ Links between pages navigate instantly (no full reload). Add `dataReload: true` to a link to opt out.
@@ -0,0 +1,71 @@
1
+ # Sinth projects, configuration and deployment
2
+
3
+ ## Layout
4
+
5
+ ```
6
+ my-site/
7
+ ├─ pages/ every .sinth file is a page (index.sinth is /)
8
+ ├─ components/ reusable components
9
+ ├─ assets/ copied to dist/assets/
10
+ ├─ public/ copied to the output root (robots.txt, favicon.ico)
11
+ ├─ functions/ server routes (Cloudflare Pages Functions conventions)
12
+ ├─ sinth.config.json optional
13
+ └─ package.json
14
+ ```
15
+
16
+ **Nuxt-style `app/` folder.** When `app/` exists and the root has no `pages/` folder and no `.sinth` files, Sinth reads pages, components, libraries and assets from `app/` (`app/pages/`, `app/components/`, ...). `public/` and `functions/` stay in the project root (`app/public/` also works). Set `"srcDir"` in `sinth.config.json` to choose the folder explicitly. In imports, `/components/Card.sinth` means the source folder.
17
+
18
+ Without a `pages/` folder, every `.sinth` file with markup in the source folder is a page.
19
+
20
+ ## CLI
21
+
22
+ ```
23
+ npx sinth dev dev server with hot reload (http://localhost:3000)
24
+ npx sinth check [--json] type-check everything, no output files
25
+ npx sinth build [--platform name]
26
+ npx sinth preview serve the production build locally
27
+ npx sinth deploy [--platform name] [--preview] [--create] [--project name]
28
+ npx sinth new page blog/first-post
29
+ npx sinth new component ProductCard
30
+ npx sinth info
31
+ ```
32
+
33
+ ## sinth.config.json
34
+
35
+ ```json
36
+ {
37
+ "platform": "cloudflare",
38
+ "site": "https://example.com",
39
+ "cloudflare": { "projectName": "my-site" }
40
+ }
41
+ ```
42
+
43
+ Other options: `srcDir`, `outDir` (default `dist`), `pagesDir`, `publicDir`, `staticDirs`, `base`, `minify`, `router`, `security.headers`, `security.csp`. Full list: https://sinth.yannosay.com/docs/tooling/configuration
44
+
45
+ ## Platforms
46
+
47
+ | `platform` | Build output | `sinth deploy` | Server functions |
48
+ |---|---|---|---|
49
+ | `cloudflare` (default) | `dist/` with `_headers` | Cloudflare Pages via Wrangler | yes (Pages Functions) |
50
+ | `cloudflare-workers` | `dist/` plus `.sinth/deploy/wrangler.json` (and a Worker when `functions/` exists) | `wrangler deploy` | yes (bundled into the Worker) |
51
+ | `vercel` | `.vercel/output/` (Build Output API: clean URLs, headers, 404) | `vercel deploy --prebuilt` | no |
52
+ | `netlify` | `dist/` with `_headers` | `netlify deploy` | no |
53
+ | `github-pages` | `dist/` with `.nojekyll` | none: publish with GitHub Actions | no |
54
+ | `static` | `dist/` | none: upload `dist/` anywhere | no |
55
+
56
+ - Deploying needs the user's own login for the host (`npx wrangler@4 login`, `npx vercel login`, `npx netlify-cli login`) or a CI token (`CLOUDFLARE_API_TOKEN` plus `CLOUDFLARE_ACCOUNT_ID`, `VERCEL_TOKEN`, `NETLIFY_AUTH_TOKEN` plus `NETLIFY_SITE_ID`). Never ask the user to paste tokens into the chat.
57
+ - `sinth deploy --preview` makes a preview deployment instead of production.
58
+ - On GitHub Pages under a repository path, set `"base": "/repo-name/"`.
59
+ - With your own `wrangler.json`/`wrangler.jsonc`/`wrangler.toml` in the root, `sinth deploy` uses it. Point `assets.directory` at `dist`, and for functions set `"main": ".sinth/deploy/worker.js"` and `"assets": { "binding": "ASSETS" }`.
60
+
61
+ ## Server functions
62
+
63
+ ```ts
64
+ // functions/api/hello.ts -> /api/hello
65
+ export const onRequestGet = ({ request, env }) => {
66
+ const name = new URL(request.url).searchParams.get("name") ?? "world";
67
+ return Response.json({ message: `Hello, ${name}!` });
68
+ };
69
+ ```
70
+
71
+ `[id].ts` gives `params.id`, `[[path]].ts` catches the rest as an array, `_middleware.ts` runs before routes below its folder and calls `next()`. Secrets for local development go in `.dev.vars`. Functions run in `sinth dev` and `sinth preview` too.