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