@yannosay/sinth 1.8.5 → 1.11.4
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/README.md +56 -485
- package/bin/sinth.js +1 -1
- package/package.json +1 -1
- package/src/browser/compile.ts +72 -0
- package/src/cli.ts +1 -1
- package/src/core/cli-compiler.ts +481 -0
- package/src/core/compiler.ts +134 -547
- package/src/core/expr.ts +16 -11
- package/src/core/runtime/helpers.ts +9 -8
- package/src/core/runtime/render.ts +23 -9
- package/src/core/types.ts +4 -0
- package/src/server.ts +1 -1
package/README.md
CHANGED
|
@@ -1,529 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
# 
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@yannosay/sinth)
|
|
4
4
|
[](https://www.npmjs.com/package/@yannosay/sinth)
|
|
5
|
-
[](https://github.com/yannosay/sinth/blob/main/LICENSE)
|
|
5
|
+
[](https://github.com/yannosay/sinth/blob/main/LICENSE)
|
|
6
6
|
[](https://github.com/yannosay/sinth/commits)
|
|
7
7
|
[](https://github.com/yannosay/sinth/pulls)
|
|
8
8
|
|
|
9
|
-
* Introduction: https://www.youtube.com/watch?v=W0tOMTiIF0Q
|
|
10
|
-
* Discord: [Join here!](https://discord.gg/SUvcrafTQm)
|
|
11
|
-
<!-- * Documentation: [sinth.yannosay.com/docs](https://sinth.yannosay.com/docs) -->
|
|
12
|
-
|
|
13
9
|
## Sinth Compiler
|
|
14
|
-
Welcome to Sinth Compiler! Sinth enables faster, easier and reactive HTML coding.
|
|
15
|
-
|
|
16
|
-
## Overview
|
|
17
|
-
#### Reactive forms in one line.
|
|
18
|
-
```ts
|
|
19
|
-
Input(bind: userName, placeholder: "Enter your name")
|
|
20
|
-
Paragraph { "Hello, " + userName }
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
No useState, onChange or e.target.value.
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
page
|
|
27
|
-
title = "Counter"
|
|
28
|
-
|
|
29
|
-
var int count = 0
|
|
30
|
-
|
|
31
|
-
Main {
|
|
32
|
-
Heading(level: 1) {count}
|
|
33
|
-
Button(onClick: count += 1) {"Increment"}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
#### Declare your own HTML tags
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
custom MyCounter(export: <awesome-counter />) {
|
|
41
|
-
var int count = 0
|
|
42
|
-
Button(onClick: count += 1) { count }
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
then you can use it in non-sinth HTML projects
|
|
47
|
-
|
|
48
|
-
```html
|
|
49
|
-
<awesome-counter />
|
|
50
|
-
<script src="awesome-counter.js"></script>
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
#### Logic and UI live together.
|
|
54
|
-
```ts
|
|
55
|
-
if user.isAdmin {
|
|
56
|
-
Button(onClick: "deletePost()") { "Delete" }
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
No JSX ternaries or v-if or separate script tags. Mixed logic there where you need it.
|
|
61
|
-
|
|
62
|
-
#### Sinth Language Syntax Reference
|
|
63
|
-
|
|
64
|
-
| Syntax | Description |
|
|
65
|
-
|-------------------------------------------------|------------------------------------------------|
|
|
66
|
-
| `--` or --[Hello]-- | Comment |
|
|
67
|
-
| `page` | Declares a full Sinth page |
|
|
68
|
-
| `title = "..."` | Sets the page title |
|
|
69
|
-
| `function myFunction` | Creates a reusable & reactive function |
|
|
70
|
-
| `var str myVar = ""` | Declares a string variable |
|
|
71
|
-
| `var int myVar` | Declares an integer variable |
|
|
72
|
-
| `var bool myVar` | Declares a boolean variable |
|
|
73
|
-
| `var str[] myVar` | Declares a string array |
|
|
74
|
-
| `var obj myVar` | Declares an object variable |
|
|
75
|
-
| `import "./file.sinth"` | Imports another Sinth file |
|
|
76
|
-
| `import css "./file.css"` | Imports a CSS file |
|
|
77
|
-
| `import js "./file.js"` | Imports a JS file |
|
|
78
|
-
| `Heading(level: 1) { "..." }` | Renders a heading (h1-h6) |
|
|
79
|
-
| `Paragraph { "..." }` | Renders a paragraph |
|
|
80
|
-
| `Button(onClick: fn) { "..." }` | Renders a clickable button |
|
|
81
|
-
| `Input(bind: myVar)` | Renders a bound input field |
|
|
82
|
-
| `Checkbox(checked: myBool)` | Renders a checkbox |
|
|
83
|
-
| `if condition { ... }` | Conditional rendering |
|
|
84
|
-
| `if condition { ... } else { ... }` | Conditional with else branch |
|
|
85
|
-
| `for item in array { ... }` | Loops over an array |
|
|
86
|
-
| `for item, index in array { ... }` | Loops with index |
|
|
87
|
-
| `delay: ms` | Delays rendering of an element |
|
|
88
|
-
| `hide: bool` | Conditionally hides an element |
|
|
89
|
-
| `style { ... }` | Defines scoped CSS styles |
|
|
90
|
-
| `script { ... }` | Defines page-level JavaScript |
|
|
91
|
-
| `component MyComp { ... }` | Defines a reusable component |
|
|
92
|
-
| `custom el "my-tag" { ... }` | Defines a custom element |
|
|
93
|
-
| `custom MyCounter(export: <awesome-counter />)` | Exports a custom element tag |
|
|
94
|
-
| `$myFunction()` (e.g. `$alert("displayed once")`)| Indicator for Memorization - Useful for functions that should only show once |
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
#### Functions - easy as you know it
|
|
98
|
-
```ts
|
|
99
|
-
page
|
|
100
|
-
|
|
101
|
-
title = "Functions"
|
|
102
|
-
|
|
103
|
-
var str userName = "Sinth User"
|
|
104
|
-
|
|
105
|
-
function greet(str name) -> str {
|
|
106
|
-
"Hello, " + name
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function renderHeading(str label) -> ui {
|
|
110
|
-
Heading(level: 2) {
|
|
111
|
-
(label)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
Div {
|
|
116
|
-
greet(userName) + " - welcome back!"
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
renderHeading(userName)
|
|
120
|
-
renderHeading("This renders!")
|
|
121
|
-
```
|
|
122
|
-
```ts
|
|
123
|
-
page
|
|
124
|
-
|
|
125
|
-
title = "Checkbox Test"
|
|
126
|
-
|
|
127
|
-
var bool isAdmin = false
|
|
128
|
-
|
|
129
|
-
function toggleAdmin() {
|
|
130
|
-
isAdmin = not isAdmin
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getStatus() -> str {
|
|
134
|
-
if (isAdmin) {
|
|
135
|
-
return "ON"
|
|
136
|
-
}
|
|
137
|
-
return "OFF"
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
Checkbox(checked: isAdmin label: "Admin mode?")
|
|
141
|
-
|
|
142
|
-
Paragraph {
|
|
143
|
-
"Admin mode is " + getStatus() + "!"
|
|
144
|
-
}
|
|
145
|
-
```
|
|
146
|
-
#### Code what you need
|
|
147
|
-
```ts
|
|
148
|
-
page
|
|
149
|
-
title = "For Loop Variable Test"
|
|
150
|
-
|
|
151
|
-
var obj historyList = []
|
|
152
|
-
var int kickCount = 0
|
|
153
|
-
var str userName = ""
|
|
154
|
-
var obj newList = []
|
|
155
|
-
var int i = 0
|
|
156
|
-
|
|
157
|
-
function kickUser() {
|
|
158
|
-
if userName != "" {
|
|
159
|
-
historyList.push(userName)
|
|
160
|
-
kickCount = kickCount + 1
|
|
161
|
-
userName = ""
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function removeUser(index) {
|
|
166
|
-
newList = []
|
|
167
|
-
i = 0
|
|
168
|
-
for user in historyList {
|
|
169
|
-
if i != index {
|
|
170
|
-
newList.push(user)
|
|
171
|
-
}
|
|
172
|
-
i = i + 1
|
|
173
|
-
}
|
|
174
|
-
historyList = newList
|
|
175
|
-
kickCount = kickCount - 1
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
Main {
|
|
179
|
-
Heading(level: 1) { "For Loop Test" }
|
|
180
|
-
|
|
181
|
-
Input(bind: userName, placeholder: "Enter username to kick")
|
|
182
|
-
Button(onClick: kickUser()) { "Add User" }
|
|
183
|
-
|
|
184
|
-
Paragraph { "Count: " + kickCount }
|
|
185
|
-
|
|
186
|
-
Heading(level: 2) { "Users:" }
|
|
187
|
-
for kickedUser, index in historyList {
|
|
188
|
-
Paragraph { kickedUser }
|
|
189
|
-
Button(onClick: removeUser(index)) { "Remove" }
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
#### Fullscreen activation + if-else inside Component
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
page
|
|
199
|
-
title = "Fullscreen"
|
|
200
|
-
|
|
201
|
-
var bool isFullscreen = false
|
|
202
|
-
var str userName = ""
|
|
203
|
-
|
|
204
|
-
Main {
|
|
205
|
-
Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen) {
|
|
206
|
-
if isFullscreen {
|
|
207
|
-
"Exit Fullscreen"
|
|
208
|
-
} else {
|
|
209
|
-
"Enter Fullscreen"
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
Input(bind: userName)
|
|
213
|
-
Paragraph {
|
|
214
|
-
if userName == "Sinth" {
|
|
215
|
-
"Oh, welcome back!"
|
|
216
|
-
} else {
|
|
217
|
-
"Hello, " + userName + "!"
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
#### Fullscreen Sync
|
|
224
|
-
|
|
225
|
-
Opt-in Escape key handling. `fullscreenSync` keeps your variable in sync with the browser's fullscreen state.
|
|
226
|
-
|
|
227
|
-
```ts
|
|
228
|
-
Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen, fullscreenSync: isFullscreen) {
|
|
229
|
-
if isFullscreen { "Exit Fullscreen" } else { "Enter Fullscreen" }
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
Without fullscreenSync, pressing Escape exits fullscreen but the variable stays true.
|
|
233
|
-
With it, Escape resets the variable to false and the button text updates automatically.
|
|
234
|
-
|
|
235
|
-
#### Opt-in DOM Diffing
|
|
236
|
-
|
|
237
|
-
Skip re-executing expressions when their variables haven't changed. Perfect for expensive calculations or side effects you only want to fire once. No one
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
page
|
|
241
|
-
domdiffing = true -- enables expression memoization
|
|
242
|
-
|
|
243
|
-
var int count = 0
|
|
244
|
-
|
|
245
|
-
Main {
|
|
246
|
-
Heading(level: 1) { count }
|
|
247
|
-
(alert("Fires only once!")) -- no dependencies, runs once and never again
|
|
248
|
-
Button(onClick: count += 1) { "Increment" }
|
|
249
|
-
}
|
|
250
|
-
```
|
|
251
|
-
Count updates every click because count changed. The alert fires only on page load — zero dependencies means it's cached forever. Just a meta flag.
|
|
252
|
-
|
|
253
|
-
#### Animations that make sense.
|
|
254
|
-
```ts
|
|
255
|
-
page
|
|
256
|
-
|
|
257
|
-
var str[] items = ["First", "Second", "Third", "Fourth", "Fifth"]
|
|
258
10
|
|
|
259
|
-
|
|
260
|
-
Paragraph(delay: (index + 1) * 1000) { item }
|
|
261
|
-
}
|
|
262
|
-
```
|
|
11
|
+
Sinth enables faster, easier and reactive HTML coding.
|
|
263
12
|
|
|
264
|
-
|
|
13
|
+
* **Declarative:** Sinth makes it super easy to create reactive code. Declarative code helps you understand your code more easily and simplifies debugging.
|
|
14
|
+
* **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.
|
|
265
15
|
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
Button(onClick: show = not show; deleted = true) { "Toggle & Delete" }
|
|
269
|
-
Chain statements with ;. No wrapper functions. No script blocks.
|
|
270
|
-
```
|
|
16
|
+
## Install
|
|
271
17
|
|
|
272
|
-
|
|
273
|
-
|
|
18
|
+
* To install Sinth, use this command:
|
|
19
|
+
* `npm install -g @yannosay/sinth`
|
|
274
20
|
|
|
275
|
-
|
|
21
|
+
The Sinth compiler is designed as a CLI tool that should work from anywhere. Therefore, it is best installed globally.
|
|
276
22
|
|
|
277
|
-
|
|
278
|
-
var bool deleted = false
|
|
23
|
+
## Init
|
|
279
24
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Button(onClick: remove("my-box"); deleted = true) {
|
|
286
|
-
"Delete Box Forever"
|
|
287
|
-
}
|
|
25
|
+
* You can initialize your Sinth project via your CLI:
|
|
26
|
+
* `sinth init my-sinth-project`
|
|
27
|
+
* `cd my-sinth-project`
|
|
28
|
+
* After that's done, you can start a Dev Server to preview your change:
|
|
29
|
+
* `sinth dev pages/index.sinth`
|
|
288
30
|
|
|
289
|
-
|
|
290
|
-
Div(id: "my-box") {
|
|
291
|
-
Paragraph { "I'm a box!" }
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
31
|
+
## Documentation
|
|
295
32
|
|
|
296
|
-
|
|
297
|
-
Delete elements. Easy.
|
|
33
|
+
You can find the complete documentation, including all notes and tips [here](https://sinth.yannosay.com).
|
|
298
34
|
|
|
299
|
-
|
|
35
|
+
## Usage
|
|
300
36
|
|
|
301
|
-
#### Reactivity at its finest
|
|
302
37
|
```ts
|
|
303
38
|
page
|
|
304
|
-
title = "Reactivity but easy"
|
|
305
|
-
|
|
306
|
-
var str begForFullscreen = ""
|
|
307
|
-
var bool doFullscreen = false
|
|
308
|
-
|
|
309
|
-
Main {
|
|
310
|
-
Input(bind: begForFullscreen, fullscreen: doFullscreen)
|
|
311
|
-
if begForFullscreen == "do fullscreen pls!!" {
|
|
312
|
-
doFullscreen = true
|
|
313
|
-
} else {
|
|
314
|
-
doFullscreen = false
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
39
|
|
|
40
|
+
title = "Increment Showcase"
|
|
41
|
+
fav = "./assets/fav.ico"
|
|
319
42
|
|
|
320
|
-
|
|
321
|
-
```ts
|
|
322
|
-
page
|
|
323
|
-
title = "Counter Demo"
|
|
324
|
-
|
|
43
|
+
var str userName = "User"
|
|
325
44
|
var int count = 0
|
|
326
|
-
var int addVar = 1
|
|
327
|
-
var int stepSize = 1
|
|
328
|
-
|
|
329
|
-
Main {
|
|
330
|
-
Heading(level: 1) {count}
|
|
331
|
-
|
|
332
|
-
Paragraph {"Increment by:"}
|
|
333
|
-
Input(bind: addVar, step: stepSize)
|
|
334
|
-
|
|
335
|
-
Br()
|
|
336
|
-
Button(onClick: count = count + addVar) {"Increment"}
|
|
337
|
-
|
|
338
|
-
Br()
|
|
339
|
-
Br()
|
|
340
|
-
Paragraph {"Step size for arrows:"}
|
|
341
|
-
Input(bind: stepSize, step: 1)
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
##### NEW! (0.14.0):
|
|
345
|
-
Sinth now supports Reactivity in Functions!
|
|
346
|
-
```ts
|
|
347
|
-
page
|
|
348
|
-
title = "Reactive Counter"
|
|
349
|
-
|
|
350
|
-
var int apples = 1
|
|
351
|
-
var int bananas = 2
|
|
352
|
-
var int oranges = -6
|
|
353
|
-
|
|
354
|
-
function Counter(int value) -> ui {
|
|
355
|
-
Heading(level: 1) {"Count is at: " + (value) + "!"}
|
|
356
|
-
Button(onClick: value = value + 1) {"Increment"}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
Main {
|
|
360
|
-
Counter(apples)
|
|
361
|
-
Counter(bananas)
|
|
362
|
-
Counter(oranges)
|
|
363
|
-
}
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
## Use in real life
|
|
367
|
-
```ts
|
|
368
|
-
page
|
|
369
|
-
|
|
370
|
-
title = "Kick Users Admin Panel"
|
|
371
|
-
|
|
372
|
-
var str userName = "test username"
|
|
373
|
-
var int count = 0
|
|
374
|
-
|
|
375
|
-
style lang= "scss"{
|
|
376
|
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
|
|
377
|
-
|
|
378
|
-
* {
|
|
379
|
-
font-family: 'Inter', sans-serif;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
Main {
|
|
384
|
-
Div(display: "flex", flexDirection: "column", gap: "16px", alignItems: "center", padding: "40px", fontFamily: "Inter") {
|
|
385
|
-
Heading(level: 1, fontSize: "28px", color: "#000000", fontWeight: "700") {
|
|
386
|
-
"Kick Counter: " + count
|
|
387
|
-
}
|
|
388
|
-
Div(display: "flex", gap: "12px", alignItems: "center") {
|
|
389
|
-
Input(
|
|
390
|
-
bind: userName,
|
|
391
|
-
padding: "10px 14px",
|
|
392
|
-
fontSize: "16px",
|
|
393
|
-
borderRadius: "8px",
|
|
394
|
-
border: "2px solid #6366f1",
|
|
395
|
-
outline: "none",
|
|
396
|
-
width: "250px",
|
|
397
|
-
backgroundColor: "#1e1b4b",
|
|
398
|
-
color: "#e0e7ff",
|
|
399
|
-
fontWeight: "400"
|
|
400
|
-
)
|
|
401
|
-
Button(
|
|
402
|
-
onClick: alert("Kicked: " + userName); console.log("User kicked"); count += 1,
|
|
403
|
-
padding: "10px 20px",
|
|
404
|
-
fontSize: "16px",
|
|
405
|
-
fontWeight: "600",
|
|
406
|
-
borderRadius: "8px",
|
|
407
|
-
border: "none",
|
|
408
|
-
backgroundColor: "#6366f1",
|
|
409
|
-
color: "#ffffff",
|
|
410
|
-
cursor: "pointer",
|
|
411
|
-
minWidth: "180px",
|
|
412
|
-
textAlign: "left"
|
|
413
|
-
) {
|
|
414
|
-
"Kick " + userName
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
Paragraph(fontSize: "14px", color: "#a5b4fc", fontWeight: "400") {
|
|
418
|
-
"Total kicks: " + count
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
# Install
|
|
425
|
-
npm install -g @yannosay/sinth
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
## Quick Start
|
|
432
|
-
`sinth init`
|
|
433
|
-
|
|
434
|
-
`sinth dev pages/index.sinth`
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Open your browser. Edit your .sinth file. Watch it update live.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
## Your First Sinth File
|
|
442
|
-
```ts
|
|
443
|
-
page
|
|
444
|
-
title = "My Sinth Project"
|
|
445
|
-
|
|
446
|
-
|
|
447
45
|
Main {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
46
|
+
Heading(level: 1) { count }
|
|
47
|
+
Button(onClick: count += 1) { "Increment" }
|
|
48
|
+
Input(bind: userName, placeholder: "Type in your username")
|
|
49
|
+
Paragraph() { userName + " has reached Count " + count + "!" }
|
|
451
50
|
}
|
|
452
51
|
```
|
|
453
52
|
|
|
53
|
+
## Feature Overview
|
|
454
54
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
## Features
|
|
459
|
-
|
|
460
|
-
- Mixed logic — if, for, and expressions right in your UI
|
|
461
|
-
- Two-way binding — Input(bind: variable) in one line
|
|
462
|
-
- Reactivity
|
|
55
|
+
- Mixed logic
|
|
56
|
+
- Two-way binding
|
|
57
|
+
- Reactive Sinth variables
|
|
463
58
|
- Import own Components
|
|
464
|
-
- Expression-based delays
|
|
465
|
-
- Object support
|
|
466
|
-
- Object iteration
|
|
467
|
-
- SCSS support
|
|
468
|
-
- Tree-shaken output
|
|
469
|
-
- VS Code extension
|
|
470
|
-
- Live reload dev server
|
|
59
|
+
- Expression-based delays
|
|
60
|
+
- Object support
|
|
61
|
+
- Object iteration
|
|
62
|
+
- SCSS support
|
|
63
|
+
- Tree-shaken output
|
|
64
|
+
- VS Code extension
|
|
65
|
+
- Live reload dev server
|
|
471
66
|
- Self-contained HTML
|
|
472
|
-
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
## Shared Runtime
|
|
477
|
-
|
|
478
|
-
For multi-page projects, extract helpers into a cached file:
|
|
479
|
-
`sinth build --shared-runtime`
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
This creates a `sinth-runtime.js` file shared across all pages. Each page shrinks to ~25 lines of render logic. The browser caches the helpers once.
|
|
483
|
-
|
|
484
|
-
Helpful when working on big projects.
|
|
67
|
+
- Reactive Sinth variables affecting CSS
|
|
68
|
+
- Reactivity in functions
|
|
69
|
+
- Exporting custom HTML Tags to use in non-sinth HTML Projects
|
|
485
70
|
|
|
486
71
|
## Security
|
|
487
72
|
|
|
488
|
-
Sinth's reactive runtime does not use eval()
|
|
489
|
-
|
|
490
|
-
###### Don't trust? -> Ctrl+F "eval(" returns nothing!
|
|
491
|
-
|
|
492
|
-
## Commands
|
|
73
|
+
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.
|
|
493
74
|
|
|
494
|
-
|
|
495
|
-
- sinth dev [file] — start dev server with live reload
|
|
496
|
-
- sinth build — compile to static files
|
|
497
|
-
- sinth build --shared-runtime — build with shared runtime (useful when using a heavier runtime)
|
|
498
|
-
- sinth check — lint without output
|
|
499
|
-
- sinth version — print version
|
|
75
|
+
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).
|
|
500
76
|
|
|
501
|
-
##
|
|
77
|
+
## Support
|
|
502
78
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
```ts
|
|
506
|
-
page
|
|
507
|
-
|
|
508
|
-
import components/MyComponent.sinth as Navbar
|
|
79
|
+
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.
|
|
509
80
|
|
|
81
|
+
## Commands
|
|
510
82
|
|
|
511
|
-
|
|
83
|
+
- `sinth init [name]`
|
|
84
|
+
- `sinth dev [file]`
|
|
85
|
+
- `sinth build [file] [--shared-runtime]`
|
|
86
|
+
- `sinth check [file]`
|
|
87
|
+
- `sinth version`
|
|
512
88
|
|
|
513
|
-
|
|
89
|
+
## Additional Links
|
|
514
90
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
## Links
|
|
519
|
-
|
|
520
|
-
- GitHub: [Official Sinth Repo](https://github.com/yannosay/sinth)
|
|
521
|
-
- Website: [Sinth](https://sinth.yannosay.com) (Note: Deep in development; documentation and various other aspects are not yet finalized.)
|
|
522
|
-
- Discord: [Join here!](https://discord.gg/SUvcrafTQm)
|
|
91
|
+
- Official Sinth Repo: [Visit on GitHub](https://github.com/yannosay/sinth)
|
|
92
|
+
- Website: [Yannosay Production Website](https://yannosay.com/)
|
|
93
|
+
- Discord: [Join here](https://discord.gg/SUvcrafTQm)
|
|
523
94
|
- VS Code Extension: [Download here](https://marketplace.visualstudio.com/items?itemName=YannosayProductions.sinth-vscode)
|
|
524
95
|
|
|
525
|
-
|
|
526
|
-
|
|
527
96
|
## License
|
|
528
97
|
|
|
529
|
-
AGPL-3.0
|
|
98
|
+
[AGPL-3.0](https://github.com/Yannosay/sinth/blob/main/LICENSE)
|
|
99
|
+
|
|
100
|
+
Notice: All generated output you made with Sinth is entirely your intellectual property and free of any license obligations of Sinth.
|
package/bin/sinth.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Lexer } from "../core/lexer.ts";
|
|
2
|
+
import { Parser } from "../core/parser.ts";
|
|
3
|
+
import { SinthFile, CompileCtx } from "../core/types.ts";
|
|
4
|
+
import { buildRuntime, renderCompUse } from "../core/compiler.ts";
|
|
5
|
+
import { fnv1a } from "../utils.ts";
|
|
6
|
+
import { processStyleBlock } from "../core/style-processor.ts";
|
|
7
|
+
|
|
8
|
+
export interface BrowserCompileResult {
|
|
9
|
+
html: string;
|
|
10
|
+
js: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function compileSinth(source: string): BrowserCompileResult | null {
|
|
14
|
+
const tokens = new Lexer(source, "<script>").tokenize();
|
|
15
|
+
const parser = new Parser(tokens, "<script>");
|
|
16
|
+
const file: SinthFile = parser.parse();
|
|
17
|
+
|
|
18
|
+
if (!file.isPage) return null;
|
|
19
|
+
|
|
20
|
+
const hash = fnv1a("<script>" + Math.random().toString(36));
|
|
21
|
+
const instanceId = "s" + Math.random().toString(36).slice(2, 8);
|
|
22
|
+
|
|
23
|
+
const ctx: CompileCtx = {
|
|
24
|
+
allDefs: new Map(),
|
|
25
|
+
functionDefs: file.functions,
|
|
26
|
+
customEls: new Map(),
|
|
27
|
+
cssLinks: [],
|
|
28
|
+
jsLinks: [],
|
|
29
|
+
scopeHash: hash,
|
|
30
|
+
pageFile: "<script>",
|
|
31
|
+
extraCSS: [],
|
|
32
|
+
mixedBlocks: [],
|
|
33
|
+
mixedCounter: 0,
|
|
34
|
+
logicBlocks: [],
|
|
35
|
+
ifIdCounter: 0,
|
|
36
|
+
exprRegistry: [],
|
|
37
|
+
exprMap: new Map(),
|
|
38
|
+
varDecls: file.varDecls,
|
|
39
|
+
actionButtons: [],
|
|
40
|
+
diffingEnabled: false,
|
|
41
|
+
declaredVars: new Set(file.varDecls.map(v => v.name)),
|
|
42
|
+
namespace: instanceId,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const bodyHTML = file.uses.map(u => renderCompUse(u, ctx, new Map(), 0)).join("\n");
|
|
46
|
+
const pageCSS = file.styles.map(s => processStyleBlock(s, hash, new Map())).join("\n");
|
|
47
|
+
|
|
48
|
+
const assignedVars = new Set<string>();
|
|
49
|
+
for (const v of file.varDecls) {
|
|
50
|
+
if (v.value) assignedVars.add(v.name);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const runtime = buildRuntime({
|
|
54
|
+
varDecls: file.varDecls,
|
|
55
|
+
bodyHTML,
|
|
56
|
+
logicBlocks: ctx.logicBlocks,
|
|
57
|
+
mixedBlocks: ctx.mixedBlocks,
|
|
58
|
+
assignedVars,
|
|
59
|
+
exprRegistry: ctx.exprRegistry,
|
|
60
|
+
sharedRuntime: false,
|
|
61
|
+
functionsJS: "",
|
|
62
|
+
namespace: instanceId,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const js = typeof runtime === 'string' ? runtime : runtime.page;
|
|
66
|
+
const scopedJs = js;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
html: `<div data-s="${hash}">${bodyHTML}</div><style>${pageCSS}</style>`,
|
|
70
|
+
js: scopedJs,
|
|
71
|
+
};
|
|
72
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { SinthWarning } from "./core/types.ts";
|
|
5
|
-
import { compileFile, CompileOptions, findSinthPages, copyDir } from "./core/compiler.ts";
|
|
5
|
+
import { compileFile, CompileOptions, findSinthPages, copyDir } from "./core/cli-compiler.ts";
|
|
6
6
|
import { startDevServer } from "./server.ts";
|
|
7
7
|
|
|
8
8
|
|