@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/DOCS.md +1359 -0
  3. package/README.md +83 -74
  4. package/bin/sinth.js +2 -1
  5. package/dist/cli/args.d.ts +11 -0
  6. package/dist/cli/args.js +74 -0
  7. package/dist/cli/index.d.ts +1 -0
  8. package/dist/cli/index.js +437 -0
  9. package/dist/cli/templates.d.ts +10 -0
  10. package/dist/cli/templates.js +193 -0
  11. package/dist/cli/ui.d.ts +28 -0
  12. package/dist/cli/ui.js +61 -0
  13. package/dist/cli/update-check.d.ts +2 -0
  14. package/dist/cli/update-check.js +124 -0
  15. package/dist/compiler/ast.d.ts +315 -0
  16. package/dist/compiler/ast.js +4 -0
  17. package/dist/compiler/codegen.d.ts +143 -0
  18. package/dist/compiler/codegen.js +1326 -0
  19. package/dist/compiler/diagnostics.d.ts +36 -0
  20. package/dist/compiler/diagnostics.js +142 -0
  21. package/dist/compiler/elements.d.ts +14 -0
  22. package/dist/compiler/elements.js +78 -0
  23. package/dist/compiler/globals.d.ts +2 -0
  24. package/dist/compiler/globals.js +27 -0
  25. package/dist/compiler/html.d.ts +37 -0
  26. package/dist/compiler/html.js +152 -0
  27. package/dist/compiler/lexer.d.ts +42 -0
  28. package/dist/compiler/lexer.js +404 -0
  29. package/dist/compiler/parser.d.ts +95 -0
  30. package/dist/compiler/parser.js +1374 -0
  31. package/dist/compiler/prerender.d.ts +72 -0
  32. package/dist/compiler/prerender.js +910 -0
  33. package/dist/compiler/script-analysis.d.ts +6 -0
  34. package/dist/compiler/script-analysis.js +106 -0
  35. package/dist/compiler/style.d.ts +39 -0
  36. package/dist/compiler/style.js +463 -0
  37. package/dist/deploy/cloudflare.d.ts +9 -0
  38. package/dist/deploy/cloudflare.js +111 -0
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.js +23 -0
  41. package/dist/project/build.d.ts +31 -0
  42. package/dist/project/build.js +425 -0
  43. package/dist/project/config.d.ts +33 -0
  44. package/dist/project/config.js +142 -0
  45. package/dist/project/project.d.ts +74 -0
  46. package/dist/project/project.js +535 -0
  47. package/dist/runtime/index.d.ts +68 -0
  48. package/dist/runtime/index.js +912 -0
  49. package/dist/server/client.d.ts +1 -0
  50. package/dist/server/client.js +112 -0
  51. package/dist/server/dev.d.ts +8 -0
  52. package/dist/server/dev.js +244 -0
  53. package/dist/server/preview.d.ts +6 -0
  54. package/dist/server/preview.js +106 -0
  55. package/dist/server/static.d.ts +10 -0
  56. package/dist/server/static.js +136 -0
  57. package/lib/ui/index.sinth +436 -0
  58. package/package.json +33 -15
  59. package/schema/sinth.config.schema.json +54 -0
  60. package/dist/browser/compile.js +0 -62
  61. package/dist/cli.js +0 -509
  62. package/dist/core/builtins.js +0 -117
  63. package/dist/core/cli-compiler.js +0 -683
  64. package/dist/core/compiler.js +0 -1428
  65. package/dist/core/expr.js +0 -125
  66. package/dist/core/head-builder.js +0 -130
  67. package/dist/core/lexer.js +0 -414
  68. package/dist/core/parser.js +0 -1665
  69. package/dist/core/runtime/custom-element.js +0 -81
  70. package/dist/core/runtime/functions.js +0 -99
  71. package/dist/core/runtime/helpers.js +0 -347
  72. package/dist/core/runtime/render.js +0 -136
  73. package/dist/core/style-processor.js +0 -317
  74. package/dist/core/types.js +0 -93
  75. package/dist/resolver.js +0 -175
  76. package/dist/server.js +0 -174
  77. package/dist/update-check.js +0 -109
  78. package/dist/utils.js +0 -80
package/README.md CHANGED
@@ -1,96 +1,105 @@
1
- # ![Sinth Repo Cover](/.github/assets/repo_cover.png)
1
+ # ![Sinth](/.github/assets/repo_cover.png)
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@yannosay/sinth?color=6366f1&label=&style=for-the-badge)](https://www.npmjs.com/package/@yannosay/sinth) [![npm downloads](https://img.shields.io/npm/dt/@yannosay/sinth?color=818cf8&label=Downloads&style=for-the-badge)](https://www.npmjs.com/package/@yannosay/sinth) [![license](https://img.shields.io/npm/l/@yannosay/sinth?color=a78bfa&label=&style=for-the-badge)](https://github.com/yannosay/sinth/blob/main/LICENSE) [![Commits](https://img.shields.io/github/commit-activity/m/yannosay/sinth?color=a78bfa&style=for-the-badge)](https://github.com/yannosay/sinth/commits) [![PRs](https://img.shields.io/github/issues-pr-raw/yannosay/sinth?color=818cf8&style=for-the-badge)](https://github.com/yannosay/sinth/pulls)
3
+ [![npm version](https://img.shields.io/npm/v/@yannosay/sinth?color=a855f7&label=npm&style=for-the-badge)](https://www.npmjs.com/package/@yannosay/sinth) [![downloads](https://img.shields.io/npm/dt/@yannosay/sinth?color=c084fc&label=downloads&style=for-the-badge)](https://www.npmjs.com/package/@yannosay/sinth) [![CI](https://img.shields.io/github/actions/workflow/status/Yannosay/sinth/ci.yml?branch=main&label=CI&style=for-the-badge)](https://github.com/Yannosay/sinth/actions) [![license](https://img.shields.io/npm/l/@yannosay/sinth?color=a78bfa&style=for-the-badge)](./LICENSE)
4
4
 
5
- ## Sinth Compiler
5
+ **Sinth is a reactive language for building websites and web apps of any size, from a landing page to a large multi-page product.** Write pages and components in one readable syntax. The compiler type-checks your whole project and turns it into static-first HTML, CSS and JavaScript, with no framework to learn.
6
6
 
7
- Sinth enables faster, easier and reactive HTML coding.
7
+ ```sinth
8
+ title = "Counter"
8
9
 
9
- * **Declarative:** Sinth makes it super easy to create reactive code. Declarative code helps you understand your code more easily and simplifies debugging.
10
- * **Simple to setup:** You don't need to download 5 different packages. Download Sinth, create `.sinth` files, and easily transform them into usable HTML right in your CLI.
10
+ var num count = 0
11
11
 
12
- ## Install
13
-
14
- * To install Sinth, use this command:
15
- * `npm install -g @yannosay/sinth`
16
-
17
- The Sinth compiler is designed as a CLI tool that should work from anywhere. Therefore, it is best installed globally.
18
-
19
- ## Init
20
-
21
- * You can initialize your Sinth project via your CLI:
22
- * `sinth init my-sinth-project`
23
- * `cd my-sinth-project`
24
- * After that's done, you can start a Dev Server to preview your change:
25
- * `sinth dev pages/index.sinth`
26
-
27
- ## Documentation
28
-
29
- You can find the complete documentation, including all notes and tips [here](https://sinth.yannosay.com).
30
-
31
- ## Usage
32
-
33
- ```ts
34
- page
35
-
36
- title = "Increment Showcase"
37
- fav = "./assets/fav.ico"
38
-
39
- var str userName = "User"
40
- var int count = 0
41
12
  Main {
42
- Heading(level: 1) { count }
43
- Button(onClick: count += 1) { "Increment" }
44
- Input(bind: userName, placeholder: "Type in your username")
45
- Paragraph() { userName + " has reached Count " + count + "!" }
13
+ Heading(level: 1) { "Count: " + count }
14
+ Button(onClick: count += 1) { "Increment" }
46
15
  }
47
16
  ```
48
17
 
49
- ## Feature Overview
18
+ ## Why Sinth
50
19
 
51
- - Mixed logic
52
- - Two-way binding
53
- - Reactive Sinth variables
54
- - Import own Components
55
- - Expression-based delays
56
- - Object support
57
- - Object iteration
58
- - SCSS support
59
- - Tree-shaken output
60
- - VS Code extension
61
- - Live reload dev server
62
- - Self-contained HTML
63
- - Reactive Sinth variables affecting CSS
64
- - Reactivity in functions
65
- - Exporting custom HTML Tags to use in non-sinth HTML Projects
20
+ - **Easy to read, easy to learn.** Markup, state, logic and styles live together in one file with no boilerplate.
21
+ - **Reactive by default.** Change a variable and exactly the affected parts of the page update.
22
+ - **Built to scale.** File-based routing with dynamic routes (`pages/blog/[slug].sinth` generates one page per post), shared layouts and components, project-wide type checking, code splitting and cached chunks. Thousands of pages build in seconds.
23
+ - **Static first.** Every page is prerendered to HTML. Pages without interactivity ship zero JavaScript; interactive ones load a ~5 kB runtime.
24
+ - **Catches mistakes before the browser does.** Unknown names, missing arguments, wrong types and missing component props are compile errors with "did you mean" hints.
25
+ - **Secure by default.** No `eval`, escaped output, no inline handlers, strict CSP and security headers out of the box.
26
+ - **Batteries included.** Dev server with hot reload that keeps state, scoped CSS, a component library (`sinth:ui`), npm packages, SCSS, JSON imports, Google Fonts, custom elements, sitemaps and one-command Cloudflare deploys.
66
27
 
67
- ## Security
28
+ ## Get started
68
29
 
69
- Sinth's reactive runtime environment does not use `eval()`. Every expression is precompiled into optimized JavaScript functions at build time. This is intended to make using Sinth more secure.
30
+ ```bash
31
+ npx @yannosay/sinth create my-site
32
+ cd my-site
33
+ npm install
34
+ npm run dev
35
+ ```
70
36
 
71
- Should you nevertheless discover a security issue, you can help us by submitting a security vulnerabilities report. For more information, view our [Security policy](https://github.com/Yannosay/sinth/security/policy).
37
+ Requires Node.js 18.17 or newer.
38
+
39
+ ## A component
40
+
41
+ ```sinth
42
+ -- components/TodoList.sinth
43
+ import { Button, Field } from "sinth:ui"
44
+
45
+ component TodoList(str title = "Todos") {
46
+ var str draft = ""
47
+ var obj[] todos = []
48
+ computed num left = todos.filter((t) => not t.done).length
49
+
50
+ function add() {
51
+ if draft.trim() == "" return
52
+ todos.push({ text: draft.trim(), done: false })
53
+ draft = ""
54
+ }
55
+
56
+ Section(class: "todos") {
57
+ Heading(level: 2) { title + " (" + left + " left)" }
58
+ Form(onSubmit.prevent: add()) {
59
+ Field(label: "New todo", value: draft)
60
+ Button(type: "submit") { "Add" }
61
+ }
62
+ Ul {
63
+ for todo in todos {
64
+ Li(class: { done: todo.done }) {
65
+ Checkbox(model: todo.done)
66
+ " " + todo.text
67
+ }
68
+ } else {
69
+ Li { "Nothing to do." }
70
+ }
71
+ }
72
+ }
73
+
74
+ style {
75
+ .done { textDecoration: "line-through"; opacity: 0.6 }
76
+ }
77
+ }
78
+ ```
72
79
 
73
- ## Support
80
+ ## Commands
74
81
 
75
- If you have encountered a problem and need assistance, please open an issue in [our repository](https://github.com/Yannosay/sinth/issues) or join our [Discord server](https://discord.gg/SUvcrafTQm) for general support.
82
+ | Command | |
83
+ |---|---|
84
+ | `sinth create [name]` | Scaffold a project |
85
+ | `sinth dev` | Dev server with hot reload and error overlay |
86
+ | `sinth build` | Production build in `dist/` |
87
+ | `sinth preview` | Serve the build locally |
88
+ | `sinth deploy` | Deploy to Cloudflare Pages |
89
+ | `sinth check` | Type-check without building |
90
+ | `sinth new page/component` | Add files |
76
91
 
77
- ## Commands
92
+ ## Documentation
78
93
 
79
- - `sinth init [name]`
80
- - `sinth dev [file]`
81
- - `sinth build [file] [--shared-runtime]`
82
- - `sinth check [file]`
83
- - `sinth version`
94
+ - **[Full reference (DOCS.md)](./DOCS.md)**: every feature, option and error code
95
+ - [Website](https://sinth.yannosay.com)
96
+ - [Changelog](./CHANGELOG.md)
97
+ - [VS Code extension](https://marketplace.visualstudio.com/items?itemName=YannosayProductions.sinth-vscode)
84
98
 
85
- ## Additional Links
99
+ ## Community
86
100
 
87
- - Official Sinth Repo: [Visit on GitHub](https://github.com/yannosay/sinth)
88
- - Website: [Yannosay Production Website](https://yannosay.com/)
89
- - Discord: [Join here](https://discord.gg/SUvcrafTQm)
90
- - VS Code Extension: [Download here](https://marketplace.visualstudio.com/items?itemName=YannosayProductions.sinth-vscode)
101
+ Questions and ideas: [Discord](https://discord.gg/SUvcrafTQm) · Bugs: [GitHub issues](https://github.com/Yannosay/sinth/issues) · Security reports: [SECURITY.md](./SECURITY.md) · Contributing: [CONTRIBUTING.md](./CONTRIBUTING.md)
91
102
 
92
103
  ## License
93
104
 
94
- [AGPL-3.0](https://github.com/Yannosay/sinth/blob/main/LICENSE)
95
-
96
- **Notice**: All generated output you made with Sinth is entirely your intellectual property and free of any license obligations of Sinth.
105
+ [AGPL-3.0](./LICENSE). Everything you build with Sinth (the generated HTML, CSS and JavaScript) is yours, free of any license obligations.
package/bin/sinth.js CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- require('../dist/cli.js');
2
+ "use strict";
3
+ require("../dist/cli/index.js").main(process.argv.slice(2));
@@ -0,0 +1,11 @@
1
+ export interface FlagSpec {
2
+ type: "boolean" | "string" | "number";
3
+ alias?: string;
4
+ description: string;
5
+ optionalValue?: string;
6
+ }
7
+ export interface ParsedArgs {
8
+ positionals: string[];
9
+ flags: Record<string, string | number | boolean | undefined>;
10
+ }
11
+ export declare function parseArgs(argv: string[], spec: Record<string, FlagSpec>): ParsedArgs;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseArgs = parseArgs;
4
+ const diagnostics_1 = require("../compiler/diagnostics");
5
+ function parseArgs(argv, spec) {
6
+ const positionals = [];
7
+ const flags = {};
8
+ const aliases = new Map();
9
+ for (const [name, s] of Object.entries(spec))
10
+ if (s.alias)
11
+ aliases.set(s.alias, name);
12
+ for (let i = 0; i < argv.length; i++) {
13
+ const arg = argv[i];
14
+ if (arg === "--") {
15
+ positionals.push(...argv.slice(i + 1));
16
+ break;
17
+ }
18
+ if (!arg.startsWith("-") || arg === "-") {
19
+ positionals.push(arg);
20
+ continue;
21
+ }
22
+ let name;
23
+ let inline;
24
+ if (arg.startsWith("--")) {
25
+ const eq = arg.indexOf("=");
26
+ name = eq === -1 ? arg.slice(2) : arg.slice(2, eq);
27
+ inline = eq === -1 ? undefined : arg.slice(eq + 1);
28
+ }
29
+ else {
30
+ const alias = aliases.get(arg.slice(1));
31
+ if (!alias)
32
+ throw new diagnostics_1.SinthError("E1200", `Unknown option '${arg}'`);
33
+ name = alias;
34
+ }
35
+ let negated = false;
36
+ if (!spec[name] && name.startsWith("no-") && spec[name.slice(3)]?.type === "boolean") {
37
+ name = name.slice(3);
38
+ negated = true;
39
+ }
40
+ const s = spec[name];
41
+ if (!s) {
42
+ const near = (0, diagnostics_1.suggest)(name, Object.keys(spec));
43
+ throw new diagnostics_1.SinthError("E1200", `Unknown option '--${name}'`, undefined, near ? `Did you mean '--${near}'?` : "Run 'sinth help' to see all options");
44
+ }
45
+ if (s.type === "boolean") {
46
+ flags[name] = inline !== undefined ? inline !== "false" : !negated;
47
+ continue;
48
+ }
49
+ let value = inline;
50
+ if (value === undefined) {
51
+ const next = argv[i + 1];
52
+ if (next !== undefined && !next.startsWith("-")) {
53
+ value = next;
54
+ i++;
55
+ }
56
+ else if (s.optionalValue !== undefined) {
57
+ value = s.optionalValue;
58
+ }
59
+ else {
60
+ throw new diagnostics_1.SinthError("E1201", `Option '--${name}' needs a value`);
61
+ }
62
+ }
63
+ if (s.type === "number") {
64
+ const n = Number(value);
65
+ if (!Number.isFinite(n))
66
+ throw new diagnostics_1.SinthError("E1202", `Option '--${name}' expects a number, got '${value}'`);
67
+ flags[name] = n;
68
+ }
69
+ else {
70
+ flags[name] = value;
71
+ }
72
+ }
73
+ return { positionals, flags };
74
+ }
@@ -0,0 +1 @@
1
+ export declare function main(argv: string[]): Promise<void>;