@yannosay/sinth 5.3.0 → 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 +5 -0
- package/README.md +21 -39
- package/RUNTIME-EXCEPTION.md +25 -0
- package/dist/browser/sinth.js +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.3.1
|
|
4
|
+
|
|
5
|
+
- **Runtime exception.** Sinth is now licensed under the AGPL-3.0 with an additional permission ([RUNTIME-EXCEPTION.md](./RUNTIME-EXCEPTION.md)): sites built with Sinth, including the runtime code bundled into them, can be licensed however you like. Sinth itself stays under the AGPL. The exception covers all versions of Sinth.
|
|
6
|
+
- README and docs state measured output sizes instead of approximations.
|
|
7
|
+
|
|
3
8
|
## 5.3.0
|
|
4
9
|
|
|
5
10
|
### Instant navigation
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@yannosay/sinth) [](https://www.npmjs.com/package/@yannosay/sinth) [](https://github.com/Yannosay/sinth/actions) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Sinth is a language for building websites. A `.sinth` file holds a page's markup, state, functions and styles. The compiler checks the project, prerenders every page to HTML and bundles the interactive parts into plain JavaScript.
|
|
6
6
|
|
|
7
7
|
```sinth
|
|
8
8
|
title = "Counter"
|
|
@@ -15,7 +15,9 @@ Main {
|
|
|
15
15
|
}
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
This page builds to a 0.5 kB HTML file and 3.5 kB of gzipped JavaScript (runtime and router included).
|
|
19
|
+
|
|
20
|
+
[Playground](https://sinth.yannosay.com/playground) · [Documentation](https://sinth.yannosay.com/docs) · [Tutorial](https://sinth.yannosay.com/docs/getting-started/tutorial)
|
|
19
21
|
|
|
20
22
|
## Get started
|
|
21
23
|
|
|
@@ -28,17 +30,15 @@ npm run dev
|
|
|
28
30
|
|
|
29
31
|
Requires Node.js 18.17 or newer.
|
|
30
32
|
|
|
31
|
-
##
|
|
33
|
+
## Features
|
|
32
34
|
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **Works with everything else.** npm packages, TypeScript files, CSS and SCSS, JSON, Google Fonts, and components exported as standard web components for any HTML page.
|
|
41
|
-
- **Secure by default.** No `eval`, escaped output, no inline handlers, a strict Content Security Policy and security headers.
|
|
35
|
+
- **Reactive state.** Assigning to a `var`, or changing an array or object in place, updates the parts of the page that use it.
|
|
36
|
+
- **Compile-time checks.** Unknown names, wrong argument counts, missing component parameters and type mismatches the compiler can detect are errors with a code frame and a suggestion.
|
|
37
|
+
- **Prerendered pages.** Every page is rendered to HTML at build time. Interactive pages then load their code: the runtime is 5.4 kB gzipped at most and only the parts a page uses are bundled.
|
|
38
|
+
- **Routing.** Files in `pages/` are routes, `pages/blog/[slug].sinth` generates one page per item, and links between pages load without a full reload (2 kB gzipped; `"router": false` turns it off).
|
|
39
|
+
- **API routes.** Files in `functions/` handle requests with the standard Fetch API in `sinth dev` and `sinth preview`, and deploy to Cloudflare Pages Functions.
|
|
40
|
+
- **Components.** Parameters, two-way bindings, slots and scoped styles, plus a built-in component library (`sinth:ui`). Components can be exported as web components for use on other sites.
|
|
41
|
+
- **Tooling.** Hot reload that keeps state, npm packages, TypeScript and SCSS imports, security headers and a Content Security Policy without inline scripts, and `sinth deploy` for Cloudflare Pages. The output is static files, so other hosts work too.
|
|
42
42
|
|
|
43
43
|
## A component
|
|
44
44
|
|
|
@@ -57,7 +57,7 @@ component TodoList(str title = "Todos") {
|
|
|
57
57
|
draft = ""
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
Section
|
|
60
|
+
Section {
|
|
61
61
|
Heading(level: 2) { title + " (" + left + " left)" }
|
|
62
62
|
Form(onSubmit.prevent: add()) {
|
|
63
63
|
Field(label: "New todo", value: draft)
|
|
@@ -81,45 +81,27 @@ component TodoList(str title = "Todos") {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
## An API route
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
// functions/api/hello.ts
|
|
88
|
-
export const onRequestGet = () => Response.json({ message: "Hello from the server" });
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
```sinth
|
|
92
|
-
var str message = ""
|
|
93
|
-
onMount { message = (await (await fetch("/api/hello")).json()).message }
|
|
94
|
-
Main { Paragraph { message } }
|
|
95
|
-
```
|
|
96
|
-
|
|
97
84
|
## Commands
|
|
98
85
|
|
|
99
86
|
| Command | |
|
|
100
87
|
|---|---|
|
|
101
88
|
| `sinth create [name]` | Scaffold a project |
|
|
102
|
-
| `sinth dev` | Dev server with hot reload
|
|
89
|
+
| `sinth dev` | Dev server with hot reload |
|
|
103
90
|
| `sinth build` | Production build in `dist/` |
|
|
104
91
|
| `sinth preview` | Serve the build and `functions/` locally |
|
|
105
92
|
| `sinth deploy` | Deploy to Cloudflare Pages |
|
|
106
|
-
| `sinth check` |
|
|
93
|
+
| `sinth check` | Check the project without building (`--json` for tools) |
|
|
107
94
|
| `sinth new page/component` | Add files |
|
|
108
95
|
|
|
109
|
-
##
|
|
110
|
-
|
|
111
|
-
- [VS Code extension](https://github.com/Yannosay/sinth/releases/latest): download `sinth-vscode-*.vsix` from the latest release and run **Extensions: Install from VSIX**
|
|
112
|
-
- [Sinth IDE](https://github.com/Yannosay/sinth-ide/releases/latest): a desktop editor for Sinth (Windows, macOS, Linux)
|
|
113
|
-
- [Playground](https://sinth.yannosay.com/playground): the real compiler, in your browser
|
|
114
|
-
|
|
115
|
-
## Documentation
|
|
96
|
+
## Editors
|
|
116
97
|
|
|
117
|
-
|
|
98
|
+
- VS Code: download `sinth-vscode-*.vsix` from the [latest release](https://github.com/Yannosay/sinth/releases/latest) and run **Extensions: Install from VSIX**.
|
|
99
|
+
- [Sinth IDE](https://github.com/Yannosay/sinth-ide/releases/latest): a desktop editor for Sinth (Windows, macOS, Linux). Early development.
|
|
118
100
|
|
|
119
|
-
##
|
|
101
|
+
## Links
|
|
120
102
|
|
|
121
|
-
|
|
103
|
+
Documentation source: [docs/](./docs) · [Changelog](./CHANGELOG.md) · [Discord](https://discord.gg/SUvcrafTQm) · [Issues](https://github.com/Yannosay/sinth/issues) · [Security](./SECURITY.md) · [Contributing](./CONTRIBUTING.md)
|
|
122
104
|
|
|
123
105
|
## License
|
|
124
106
|
|
|
125
|
-
[AGPL-3.0](./LICENSE).
|
|
107
|
+
Sinth is licensed under the [AGPL-3.0](./LICENSE) with a [runtime exception](./RUNTIME-EXCEPTION.md): the sites you build with it, including the Sinth runtime code they contain, are yours to license however you like. The AGPL applies to Sinth itself.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Sinth Runtime Exception
|
|
2
|
+
|
|
3
|
+
Copyright (c) Yannosay Productions
|
|
4
|
+
|
|
5
|
+
This is an additional permission under section 7 of the GNU Affero General Public License, version 3 (the "AGPL"), which covers Sinth. It applies to every version of Sinth published by Yannosay Productions.
|
|
6
|
+
|
|
7
|
+
## Definitions
|
|
8
|
+
|
|
9
|
+
- **"Runtime Code"** means the files in `src/runtime/` and `lib/` of Sinth, in source or compiled form, including copies that the Sinth compiler places in its output, and any code that the Sinth compiler generates from your input.
|
|
10
|
+
- **"Output"** means the files written by the Sinth compiler and its commands (for example `sinth build`, `sinth dev`, `sinth preview` and `sinth deploy`, or the `compileFiles` API): HTML, CSS, JavaScript and other assets, together with any Runtime Code they contain.
|
|
11
|
+
- **"Your Input"** means the `.sinth` files, components, styles, scripts and other files that the compiler processes, other than Sinth itself.
|
|
12
|
+
|
|
13
|
+
## Permission
|
|
14
|
+
|
|
15
|
+
You may use, copy, modify, distribute, sublicense and sell Output produced from Your Input, including the Runtime Code it contains, under terms of your choice. You are not required to apply the AGPL to the Output, to provide its source code, or to include the AGPL with it.
|
|
16
|
+
|
|
17
|
+
This holds whether the Output was produced by an unmodified or a modified version of the Sinth compiler, provided the Runtime Code in the Output has not been modified in a way that turns the Output into a copy or substantial portion of the Sinth compiler, command-line tools, dev server or editor tooling.
|
|
18
|
+
|
|
19
|
+
## Scope
|
|
20
|
+
|
|
21
|
+
This exception does not change the license of Sinth itself. The compiler, command-line tools, dev server, browser build of the compiler, editor extensions and all other parts of Sinth remain under the AGPL when you use, modify or distribute them.
|
|
22
|
+
|
|
23
|
+
Your Input remains yours, under whatever license you choose.
|
|
24
|
+
|
|
25
|
+
If you modify Sinth, you may extend this exception to your modified version, or remove it.
|
package/dist/browser/sinth.js
CHANGED
|
@@ -125,7 +125,7 @@ ${R(this.stmts(e.body,i))}
|
|
|
125
125
|
`).map(e=>e&&" "+e).join(`
|
|
126
126
|
`)}function ys(t,e){return ye.fromTokens(ge(t,e.file,e),e.file).parseExpr()}function Zn(t,e,n){return new At(t,e,n).compile()}var v=Symbol("unknown"),Lt=class{constructor(e){this.value=e}},q=class{constructor(e){this.parent=e;E(this,"vars",new Map)}define(e,n){this.vars.set(e,new Lt(n))}find(e){return this.vars.get(e)??this.parent?.find(e)}},le=class{constructor(e){this.value=e}},Be=class{},je=class{},Rt=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__"]),ks=2e6,Ot=class{constructor(e){this.host=e;E(this,"complete",!0);E(this,"steps",0);E(this,"moduleEnvs",new Map);E(this,"componentTables",new Map);E(this,"depth",0)}renderPage(e,n){let i=this.moduleEnv(e,n);return this.renderNodes(e.body,{env:new q(i),file:e})}evalMeta(e,n){let i=this.moduleEnv(e,n);return e.meta.filter(s=>s.key!=="paths").map(s=>{let r;try{r=this.eval(s.value,i,e)}catch{r=v}return{key:s.key,value:r===v?void 0:r,known:r!==v,loc:s.loc}})}evalPaths(e,n){let i=e.meta.find(o=>o.key==="paths");if(!i)return{value:void 0,known:!0};let s={},r=this.moduleEnv(e,s,n),a;try{a=this.eval(i.value,r,e)}catch{a=v}return{value:a===v?void 0:a,known:a!==v}}tick(){if(++this.steps>ks)throw new Error("Prerender step limit exceeded")}moduleEnv(e,n,i=[]){let s=this.moduleEnvs.get(e.path);if(s)return s;let r=new q(null);this.moduleEnvs.set(e.path,r);for(let a of i)r.define(a,v);if(n)for(let[a,o]of Object.entries(n))r.define(a,o);for(let a of this.host.getImports(e)){let o=a.decl;if(a.kind==="json"){o.defaultName&&r.define(o.defaultName,a.json);for(let c of o.named)r.define(c.alias,a.json?.[c.name])}else if(a.kind==="sinth"&&a.exports){let c=this.host.getFile(a.specifier),h=this.moduleEnv(c);for(let u of o.named){let f=h.find(u.name);f&&r.define(u.alias,f.value)}}else for(let c of[o.defaultName,o.namespace,...o.named.map(h=>h.alias)])c&&r.define(c,v)}for(let a of e.externs)r.define(a.name,v);for(let a of e.functions)r.define(a.name,this.makeFunction(a,r,e));e.scripts.length&&(this.complete=!1);for(let a of e.vars)try{this.declare(a,r,e)}catch{r.define(a.name,v)}return r}declare(e,n,i){if(e.kind==="computed"&&e.init){let s=e.init;n.define(e.name,v);let r=n.find(e.name);Object.defineProperty(r,"value",{get:()=>this.eval(s,n,i),configurable:!0});return}n.define(e.name,e.init?this.eval(e.init,n,i):ws(e))}makeFunction(e,n,i){return e.view?v:(...s)=>{let r=new q(n);e.params.forEach((a,o)=>{let c=s[o];c===void 0&&a.defaultValue&&(c=this.eval(a.defaultValue,r,i)),r.define(a.name,c)});try{this.execAll(e.body,r,i)}catch(a){if(a instanceof le)return a.value;throw a}}}execAll(e,n,i){for(let s of e)this.exec(s,n,i)}exec(e,n,i){switch(this.tick(),e.k){case"expr":this.eval(e.expr,n,i);return;case"var":this.declare(e.decl,n,i);return;case"if":{let s=this.eval(e.test,n,i);if(s===v)throw new le(v);s?this.execAll(e.then,new q(n),i):e.else&&this.execAll(e.else,new q(n),i);return}case"for":{let s=this.eval(e.iter,n,i);if(s===v)throw new le(v);for(let[r,a,o]of Qn(s)){let c=new q(n);if([r,a,o].slice(0,e.names.length).forEach((h,u)=>c.define(e.names[u],h)),!(e.filter&&!this.eval(e.filter,c,i)))try{this.execAll(e.body,c,i)}catch(h){if(h instanceof Be)break;if(h instanceof je)continue;throw h}}return}case"while":{for(;;){let s=this.eval(e.test,n,i);if(s===v)throw new le(v);if(!s)break;try{this.execAll(e.body,new q(n),i)}catch(r){if(r instanceof Be)break;if(r instanceof je)continue;throw r}}return}case"try":case"throw":throw new le(v);case"return":throw new le(e.value?this.eval(e.value,n,i):void 0);case"break":throw new Be;case"continue":throw new je}}eval(e,n,i){switch(this.tick(),e.k){case"lit":return e.value;case"tpl":{let s="";for(let r of e.parts)if(typeof r=="string")s+=r;else{let a=this.eval(r,n,i);if(a===v)return v;s+=be(a)}return s}case"id":{let s=n.find(e.name);return s?s.value:Ss[e.name]??v}case"member":{let s=this.eval(e.object,n,i);return s===v?v:s==null?e.optional?void 0:v:Tt(s,e.prop)}case"index":{let s=this.eval(e.object,n,i),r=this.eval(e.index,n,i);return s===v||r===v?v:s==null?e.optional?void 0:v:Tt(s,String(r))}case"call":{let s,r;if(e.callee.k==="member"){if(s=this.eval(e.callee.object,n,i),s===v)return v;if(s==null)return e.optional||e.callee.optional?void 0:v;r=Tt(s,e.callee.prop)}else r=this.eval(e.callee,n,i);if(typeof r!="function")return v;let a=[];for(let o of e.args){let c=this.eval(o.value,n,i);if(c===v)return v;o.spread&&Array.isArray(c)?a.push(...c):a.push(c)}if(!Es(r,s))return v;try{let o=r.apply(s,a);return o instanceof Promise?v:o}catch(o){return o instanceof le?o.value:v}}case"new":{if(e.callee.k==="id"&&e.callee.name==="Date"){let s=e.args.map(r=>this.eval(r.value,n,i));return s.includes(v)?v:new Date(...s)}return v}case"unary":{if(e.op==="await")return v;let s=this.eval(e.arg,n,i);if(s===v)return v;switch(e.op){case"!":return!s;case"-":return-s;case"+":return+s;case"~":return~s;case"typeof":return typeof s}return v}case"binary":{let s=this.eval(e.left,n,i);if(s===v)return v;if(e.op==="&&")return s&&this.eval(e.right,n,i);if(e.op==="||")return s||this.eval(e.right,n,i);if(e.op==="??")return s??this.eval(e.right,n,i);let r=this.eval(e.right,n,i);return r===v?v:Pt(e.op,s,r)}case"cond":{let s=this.eval(e.test,n,i);return s===v?v:s?this.eval(e.then,n,i):this.eval(e.else,n,i)}case"assign":{let s=this.eval(e.value,n,i);if(e.target.k==="id"){let r=n.find(e.target.name);if(!r)return v;let a=r.value;return r.value=e.op==="="?s:s===v||a===v?v:Pt(e.op.slice(0,-1),a,s),r.value}if(e.target.k==="member"||e.target.k==="index"){let r=this.eval(e.target.object,n,i),a=e.target.k==="member"?e.target.prop:this.eval(e.target.index,n,i);if(r&&typeof r=="object"&&a!==v&&!Rt.has(String(a))){let o=r;return o[String(a)]=e.op==="="?s:Pt(e.op.slice(0,-1),o[String(a)],s),o[String(a)]}}return v}case"update":{if(e.target.k!=="id")return v;let s=n.find(e.target.name);if(!s||typeof s.value!="number")return v;let r=s.value;return s.value=r+1,e.prefix?s.value:r}case"array":{let s=[];for(let r of e.items){let a=this.eval(r.value,n,i);if(a===v)return v;r.spread&&Array.isArray(a)?s.push(...a):s.push(a)}return s}case"object":{let s={};for(let r of e.props){let a=this.eval(r.value,n,i);if(a===v)return v;if(r.spread)Object.assign(s,a);else{let o=r.computedKey?String(this.eval(r.computedKey,n,i)):r.key;Rt.has(o)||(s[o]=a)}}return s}case"arrow":{let s=e.body,r=e.params;return e.async?v:(...a)=>{let o=new q(n);if(r.forEach((c,h)=>o.define(c.name,a[h]===void 0&&c.defaultValue?this.eval(c.defaultValue,o,i):a[h])),!Array.isArray(s))return this.eval(s,o,i);try{this.execAll(s,o,i)}catch(c){if(c instanceof le)return c.value;throw c}}}case"range":return v}}components(e){let n=this.componentTables.get(e.path);if(n)return n;let i=new Map;this.componentTables.set(e.path,i);for(let s of this.host.getImports(e)){if(s.kind!=="sinth"||!s.exports)continue;let r=this.host.getFile(s.specifier),a=s.decl,o=c=>{let h=r.components.find(u=>u.name===c);return h?{decl:h,file:r}:void 0};if(a.sideEffect||!a.named.length&&!a.defaultName&&!a.namespace)for(let c of r.components)i.set(c.name,{decl:c,file:r});if(a.defaultName&&s.exports.defaultComponent){let c=o(s.exports.defaultComponent);c&&i.set(a.defaultName,c)}if(a.namespace)for(let c of r.components)i.set(`${a.namespace}.${c.name}`,{decl:c,file:r});for(let c of a.named){let h=o(c.name);h&&i.set(c.alias,h)}}for(let s of e.components)i.set(s.name,{decl:s,file:e});return i}renderNodes(e,n){let i="";for(let s of e)i+=this.renderNode(s,n);return i}renderNode(e,n){switch(this.tick(),e.k){case"text":{if(e.expr.k==="call"&&e.expr.callee.k==="id"){let s=n.file.functions.find(r=>r.name===e.expr.callee.name&&r.view);if(s&&s.view)return this.renderUiFunction(s,e.expr.args.map(r=>this.eval(r.value,n.env,n.file)),n)}let i=this.eval(e.expr,n.env,n.file);return i===v?(this.complete=!1,""):Ne(be(i))}case"element":return this.renderElement(e,n);case"if":{for(let i of e.branches){let s=i.test?this.eval(i.test,n.env,n.file):!0;if(s===v)return this.complete=!1,"";if(s)return this.renderNodes(i.body,{...n,env:new q(n.env)})}return""}case"for":{let i=this.eval(e.iter,n.env,n.file);if(i===v)return this.complete=!1,"";let s="",r=0;for(let[a,o,c]of Qn(i)){let h=new q(n.env);if([a,r,c].slice(0,e.names.length).forEach((u,f)=>h.define(e.names[f],u)),e.filter){let u=this.eval(e.filter,h,n.file);if(u===v&&(this.complete=!1),!u||u===v)continue}r++,s+=this.renderNodes(e.body,{...n,env:h})}return r===0&&e.empty&&(s+=this.renderNodes(e.empty,n)),s}case"slot":{let i=n.slots?.[e.name];return i?i():this.renderNodes(e.fallback,n)}case"stmt":try{this.exec(e.stmt,n.env,n.file)}catch{this.complete=!1}return"";case"var":return this.declare(e.decl,n.env,n.file),""}}renderUiFunction(e,n,i){let s=new q(this.moduleEnv(i.file));e.params.forEach((r,a)=>s.define(r.name,n[a]===void 0&&r.defaultValue?this.eval(r.defaultValue,s,i.file):n[a]));for(let r of e.body)r.k==="var"&&this.declare(r.decl,s,i.file);return this.renderNodes(e.view??[],{...i,env:s})}attrValue(e,n){return e.value===null?!0:this.eval(e.value,n.env,n.file)}renderElement(e,n){let i=n.compName===e.name&&J[e.name]?void 0:this.components(n.file).get(e.name);if(i)return this.renderComponent(e,i,n);if(e.name==="Fragment")return this.renderNodes(e.children,n);if(e.name==="RawHTML"||e.name==="Html"){let d=e.attrs.find(m=>m.name==="content"||m.name==="html"),g=d?this.attrValue(d,n):"";return g===v?(this.complete=!1,""):be(g)}let s=J[e.name];if(!s)return"";let r=s.tag,a=new Map(Object.entries(s.attrs??{})),o=[];s.className&&o.push(s.className),n.scopeClass&&o.push(n.scopeClass);let c=[],h;for(let d of e.attrs){if(d.handler||d.name==="ref"||d.name==="key"||d.name==="...")continue;if(d.name==="level"&&e.name==="Heading"){let C=this.attrValue(d,n);typeof C=="number"&&(r=`h${Math.min(6,Math.max(1,C))}`);continue}let g=this.attrValue(d,n);if(g===v){this.complete=!1;continue}switch(d.name){case"class":o.push(Vt(g));continue;case"style":if(g&&typeof g=="object")for(let[C,A]of Object.entries(g))A!=null&&A!==!1&&c.push(`${Yn(C)}: ${String(A)}`);else typeof g=="string"&&c.push(g);continue;case"model":case"bind":a.get("type")==="checkbox"||e.name==="Checkbox"?g===!0&&a.set("checked",""):r==="textarea"?h=Ne(be(g)):r!=="select"&&a.set("value",be(g));continue;case"hide":g&&c.push("display: none");continue;case"show":g||c.push("display: none");continue;case"delay":c.push("display: none");continue;case"html":h=be(g);continue;default:break}if(Me.has(d.name)&&!((d.name==="width"||d.name==="height")&&["img","video","canvas","iframe","svg","input","rect","embed","object","source"].includes(r))){g!=null&&g!==!1&&c.push(`${Yn(d.name)}: ${String(g)}`);continue}if(g==null||g===!1)continue;let m=ce(d.name);if(/^on/i.test(m))continue;let k=g===!0?"":typeof g=="object"?JSON.stringify(g):String(g);a.set(m,/^(href|src|action|formaction|poster)$/.test(m)&&/^\s*(javascript|vbscript):/i.test(k)?"about:blank#blocked":k)}let u=o.filter(Boolean).join(" ");u&&a.set("class",u),c.length&&a.set("style",[a.get("style"),...c].filter(Boolean).join("; "));let f=[...a].map(([d,g])=>g===""&&Ue.has(d)?` ${d}`:` ${d}="${T(g)}"`).join("");if(Pe.has(r))return`<${r}${f}>`;let x=h??this.renderNodes(e.children,n);return`<${r}${f}>${x}</${r}>`}renderComponent(e,n,i){if(++this.depth>64)throw this.depth--,new Error(`Component nesting is deeper than 64 levels at '${e.name}' (recursive component without a stop condition?)`);try{let s=n.decl,r=this.moduleEnv(n.file),a=new q(r),o=[];for(let m of s.params){let k=e.attrs.find(C=>C.name===m.name);k&&!k.handler?a.define(m.name,this.attrValue(k,i)):k?.handler?a.define(m.name,v):a.define(m.name,m.defaultValue?this.eval(m.defaultValue,a,n.file):void 0)}for(let m of e.attrs)!s.params.some(k=>k.name===m.name)&&!m.handler&&o.push(m);for(let m of s.vars)this.declare(m,a,n.file);s.scripts.length&&(this.complete=!1);let c={};e.children.length&&(c.default=()=>this.renderNodes(e.children,i));for(let m of e.slots)c[m.name]=()=>this.renderNodes(m.children,i);let h=`s-${Ce(n.file.path.replace(/\\/g,"/")+"#"+s.name).slice(0,7)}`,u={env:a,file:n.file,scopeClass:h,slots:c,compName:s.name},f=this.renderNodes(s.body,u),x=this.styleVars(s,n.file,a),d=o.filter(m=>m.name==="class").map(m=>Vt(this.attrValue(m,i))).join(" "),g=o.filter(m=>m.name!=="class"&&m.name!=="style"&&m.name!=="model"&&m.name!=="bind"&&m.name!=="ref").map(m=>[ce(m.name),this.attrValue(m,i)]).filter(([,m])=>m!==v&&m!==null&&m!==void 0&&m!==!1);return(x||d||g.length)&&(f=f.replace(/^<([a-zA-Z][\w-]*)((?:\s[^>]*)?)>/,(m,k,C)=>{let A=C;d&&(A=/\sclass="/.test(A)?A.replace(/\sclass="([^"]*)"/,(ie,de)=>` class="${de} ${T(d)}"`):`${A} class="${T(d)}"`),x&&(A=/\sstyle="/.test(A)?A.replace(/\sstyle="([^"]*)"/,(ie,de)=>` style="${de}; ${T(x)}"`):`${A} style="${T(x)}"`);for(let[ie,de]of g)new RegExp(`\\s${ie}=`).test(A)||(A+=de===!0?` ${ie}`:` ${ie}="${T(String(de))}"`);return`<${k}${A}>`})),f}finally{this.depth--}}styleVars(e,n,i){let s=new Set([...e.params.map(a=>a.name),...e.vars.map(a=>a.name)]),r=[];for(let a of e.styles){if(a.global)continue;let o=`--sv-${Ce(n.path+e.name).slice(0,5)}-`;try{let c=it(a.raw,a.lang==="scss"?"css":a.lang,{reactiveNames:s,varPrefix:o,loc:a.loc,sinthSyntax:a.lang==="sinth"});for(let h of c.expressions){let u=ye.fromTokens(ge(h.source,n.path,a.loc),n.path).parseExpr(),f=this.eval(u,i,n);f!==v&&f!==null&&f!==void 0&&r.push(`${h.cssVar}: ${be(f)}`)}}catch{continue}}return r.join("; ")}};function ws(t){let e=t.type;return!e||e.nullable?null:e.array?[]:e.base==="str"?"":e.base==="num"||e.base==="int"?0:e.base==="bool"?!1:null}function Pt(t,e,n){let i=e,s=n;switch(t){case"+":return e+n;case"-":return i-s;case"*":return i*s;case"/":return i/s;case"%":return i%s;case"**":return i**s;case"==":return e===n;case"!=":return e!==n;case"<":return i<s;case">":return i>s;case"<=":return i<=s;case">=":return i>=s;default:return v}}function Tt(t,e){if(Rt.has(e))return v;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean"){let n=Object(t)[e];return n===void 0?void 0:n}return t&&(typeof t=="object"||typeof t=="function")?t[e]:v}var Ss={Math,JSON,Number,String,Boolean,Array,Object,Date,parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI,Infinity:1/0,NaN:NaN,range:(t,e,n=1)=>{let i=e===void 0?0:t,s=e===void 0?t:e,r=[];if(n>0)for(let a=i;a<s&&r.length<1e5;a+=n)r.push(a);else if(n<0)for(let a=i;a>s&&r.length<1e5;a+=n)r.push(a);return r}},Cs=new Set([Function,Object.defineProperty,Object.defineProperties,Object.setPrototypeOf,Object.assign]);function Es(t,e){return!(Cs.has(t)||t===Function.prototype.call||t===Function.prototype.apply||t===Function.prototype.bind)}function Qn(t){return t==null||t===!1?[]:typeof t=="number"?Array.from({length:Math.max(0,Math.floor(t))},(e,n)=>[n,n,n]):Array.isArray(t)?t.map((e,n)=>[e,n,n]):t instanceof Map?Array.from(t.entries()).map(([e,n],i)=>[n,i,e]):typeof t=="string"?Array.from(t).map((e,n)=>[e,n,n]):typeof t=="object"?Object.entries(t).map(([e,n],i)=>[n,i,e]):[]}function be(t){if(t==null||t===!1||t===v)return"";if(typeof t=="string")return t;if(typeof t=="number")return String(t);if(Array.isArray(t))return t.map(be).join(", ");if(t instanceof Date)return t.toLocaleString("en-US");if(typeof t=="object")try{return JSON.stringify(t)}catch{return""}return String(t)}function Vt(t){return!t||t===v?"":typeof t=="string"?t:Array.isArray(t)?t.map(Vt).filter(Boolean).join(" "):typeof t=="object"?Object.entries(t).filter(([,e])=>!!e).map(([e])=>e).join(" "):String(t)}function Yn(t){return t.startsWith("--")?t:t.replace(/^(Webkit|Moz|Ms)/,e=>"-"+e.toLowerCase()).replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}function Xn(t,e,n){let i=new Ot(e),s;try{s=i.renderPage(t,n)}catch{s=void 0}let r=s!==void 0&&i.complete;return{html:s??"",complete:r,meta:i.evalMeta(t,n)}}function _s(t){let e=t.lastIndexOf("/");return e<=0?"/":t.slice(0,e)}function Bt(t){let e=[];for(let n of t.split("/"))!n||n==="."||(n===".."?e.pop():e.push(n));return"/"+e.join("/")}var jt=/^(https?:)?\/\//;function ei(t,e={}){let n=Bt(e.entry??"/pages/index.sinth"),i=e.builtins??{},s=e.resolvePackage??(S=>`https://esm.sh/${S}`),r=new Map,a=new Map,o=new Map,c=[],h=[],u=[],f=[],x=S=>S.startsWith("sinth:")?i[S]:t[S],d=S=>{let H=r.get(S);if(H)return H;let L=x(S);if(L===void 0)throw new P("E0600",`File not found: ${S}`);let K=Jt(L,S);return K.isPage=S===n,r.set(S,K),K},g=(S,H)=>[S,...H.map(L=>S+L),...H.map(L=>S+"/index"+L)].find(L=>x(L)!==void 0),m=S=>{let H=a.get(S.path);if(H)return H;let L=[];for(let K of S.imports){let B=K;B.kind==="library"&&(B={...B,kind:"sinth",source:"sinth:ui",sideEffect:!0});let N=B.source,Ee=N.startsWith("/")&&!N.startsWith("//")?Bt(N):Bt(_s(S.path)+"/"+N),ii=N.startsWith(".")||N.startsWith("/")&&!N.startsWith("//"),Dt=()=>{throw new P("E0601",`Cannot find '${N}'`,B.loc)},Ft=re=>{let De=d(re);if(De.isPage)throw new P("E0608",`Cannot import page '${N}'; pages are entry points`,B.loc);return{decl:{...B,kind:"sinth"},kind:"sinth",specifier:re,exports:Nt(De)}};if(N.startsWith("sinth:")){if(i[N]===void 0)throw new P("E0605",`Unknown built-in library '${N}'`,B.loc);L.push(Ft(N));continue}switch(B.kind){case"style":{if(jt.test(N)){f.push(N),L.push({decl:B,kind:"style",specifier:N});break}let re=g(Ee,[".css"])??Dt();h.push(x(re)??""),L.push({decl:B,kind:"style",specifier:N});break}case"font":L.push({decl:B,kind:"font",specifier:N});break;case"json":{let re=g(Ee,[])??Dt();try{L.push({decl:B,kind:"json",specifier:re,json:JSON.parse(x(re)??"")})}catch(De){throw new P("E0606",`Invalid JSON in '${N}': ${De.message}`,B.loc)}break}case"script":if(!jt.test(N))throw new P("E0607",`Only URL scripts can be imported here: '${N}'`,B.loc);u.push(N),L.push({decl:B,kind:"script",specifier:N});break;default:{if(jt.test(N)){L.push({decl:{...B,kind:"module"},kind:"module",specifier:N});break}if(ii){let re=g(Ee,[".sinth"]);if(re?.endsWith(".sinth")){L.push(Ft(re));break}throw new P("E0601",`Cannot find '${N}'`,B.loc,"Only .sinth, .css and .json files can be imported here")}L.push({decl:{...B,kind:"module"},kind:"module",specifier:s(N)})}}}return a.set(S.path,L),L},k=(S,H)=>{let L=o.get(S);if(L)return L;if(H.includes(S))throw new P("E0609",`Circular import: ${[...H.slice(H.indexOf(S)),S].join(" -> ")}`);let K=d(S),B=m(K);for(let Ee of B)Ee.kind==="sinth"&&k(Ee.specifier,[...H,S]);let N=Zn(K,B,{runtime:"sinth-runtime",dev:!!e.dev,persistPrefix:"sinth:"+S.replace(/^\//,"").replace(/\.sinth$/,"")});return o.set(S,N),c.push(S),N};k(n,[]);let C={getFile:d,getImports:m},A=Xn(d(n),C),ie=Kn(A.meta.map(S=>S.known?S:{...S,known:!0,value:void 0}),S=>S),de=c.map(S=>{let H=o.get(S),L=m(d(S)).filter(K=>K.kind==="sinth").map(K=>K.specifier);return{id:S,js:H.js.replace(/^import "sinth-css:[^"]*";\n/gm,""),deps:L}}),ti=[...h,...c.map(S=>o.get(S)?.css??"").filter(Boolean)].join(`
|
|
127
127
|
|
|
128
|
-
`),ni=c.flatMap(S=>o.get(S)?.diagnostics.warnings??[]);return{modules:de,entry:n,css:ti,externalScripts:u,externalStyles:f,warnings:ni,html:Gn(ie,A.html,{styles:[],scripts:[],preloads:[],inlineHead:[]})}}var sa="5.3.
|
|
128
|
+
`),ni=c.flatMap(S=>o.get(S)?.diagnostics.warnings??[]);return{modules:de,entry:n,css:ti,externalScripts:u,externalStyles:f,warnings:ni,html:Gn(ie,A.html,{styles:[],scripts:[],preloads:[],inlineHead:[]})}}var sa="5.3.1",ra=`const SVG_NS = "http://www.w3.org/2000/svg";
|
|
129
129
|
const BLOCKED_URL = /^\\s*(javascript|vbscript|data:(?!image\\/(png|gif|jpe?g|webp|avif|svg\\+xml)|video\\/|audio\\/))/i;
|
|
130
130
|
let rootOwner = createOwner(null);
|
|
131
131
|
let current = rootOwner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yannosay/sinth",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "A compiled, type-checked language for websites and web apps: reactive components, file-based routing with instant navigation, prerendered pages, API routes and one-command deploys.",
|
|
5
5
|
"author": "Yannosay Productions",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"schema/",
|
|
48
48
|
"README.md",
|
|
49
49
|
"CHANGELOG.md",
|
|
50
|
-
"LICENSE"
|
|
50
|
+
"LICENSE",
|
|
51
|
+
"RUNTIME-EXCEPTION.md"
|
|
51
52
|
],
|
|
52
53
|
"scripts": {
|
|
53
54
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.runtime.json && node scripts/build-browser.js",
|