@yannosay/sinth 1.4.0 → 1.5.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/README.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  The language that makes HTML feel SO easy. Declarative. Reactive. Compiles to pure HTML.
4
4
 
5
+ **I need YOUR Help to improve Sinth, please consider joining the Discord so Sinth can be optimized more easy, currently I am doing this alone!**
6
+
5
7
  * Introduction: https://www.youtube.com/watch?v=W0tOMTiIF0Q
6
8
  * Discord: [Join here!](https://discord.gg/SUvcrafTQm)
7
- * Documentation: [sinth.yannosay.com/docs](https://sinth.yannosay.com/docs)
9
+ * Documentation: [sinth.yannosay.com/docs](https://sinth.yannosay.com/docs) (HIGHLY WIP, not yet finished at all!)
8
10
 
9
11
 
10
12
  [![npm version](https://img.shields.io/npm/v/@yannosay/sinth)](https://www.npmjs.com/package/@yannosay/sinth)
@@ -19,7 +21,7 @@ Input(bind: userName, placeholder: "Enter your name")
19
21
  Paragraph { "Hello, " + userName }
20
22
  ```
21
23
 
22
- No useState. No onChange. No e.target.value.
24
+ No useState, onChange or e.target.value!
23
25
 
24
26
  ```ts
25
27
  page
@@ -56,7 +58,42 @@ Button(onClick: "deletePost()") { "Delete" }
56
58
  }
57
59
  ```
58
60
 
59
- No JSX ternaries. No v-if. No separate script tags. Mixed logic. Clean.
61
+ No JSX ternaries or v-if. No separate script tags. Mixed logic there where you need it.
62
+
63
+ #### Sinth Language Syntax Reference
64
+
65
+ | Syntax | Description |
66
+ |-------------------------------------------------|------------------------------------------------|
67
+ | `--` or --[Hello]-- | Comment |
68
+ | `page` | Declares a full Sinth page |
69
+ | `title = "..."` | Sets the page title |
70
+ | `function myFunction` | Creates a reusable & reactive function |
71
+ | `var str myVar = ""` | Declares a string variable |
72
+ | `var int myVar` | Declares an integer variable |
73
+ | `var bool myVar` | Declares a boolean variable |
74
+ | `var str[] myVar` | Declares a string array |
75
+ | `var obj myVar` | Declares an object variable |
76
+ | `import "./file.sinth"` | Imports another Sinth file |
77
+ | `import css "./file.css"` | Imports a CSS file |
78
+ | `import js "./file.js"` | Imports a JS file |
79
+ | `Heading(level: 1) { "..." }` | Renders a heading (h1-h6) |
80
+ | `Paragraph { "..." }` | Renders a paragraph |
81
+ | `Button(onClick: fn) { "..." }` | Renders a clickable button |
82
+ | `Input(bind: myVar)` | Renders a bound input field |
83
+ | `Checkbox(checked: myBool)` | Renders a checkbox |
84
+ | `if condition { ... }` | Conditional rendering |
85
+ | `if condition { ... } else { ... }` | Conditional with else branch |
86
+ | `for item in array { ... }` | Loops over an array |
87
+ | `for item, index in array { ... }` | Loops with index |
88
+ | `delay: ms` | Delays rendering of an element |
89
+ | `hide: bool` | Conditionally hides an element |
90
+ | `style { ... }` | Defines scoped CSS styles |
91
+ | `script { ... }` | Defines page-level JavaScript |
92
+ | `component MyComp { ... }` | Defines a reusable component |
93
+ | `custom el "my-tag" { ... }` | Defines a custom element |
94
+ | `custom MyCounter(export: <awesome-counter />)` | Exports a custom element tag |
95
+
96
+
60
97
 
61
98
  #### Functions - easy as you know it
62
99
  ```ts
@@ -83,8 +120,6 @@ Div {
83
120
  renderHeading(userName)
84
121
  renderHeading("This renders!")
85
122
  ```
86
- or
87
-
88
123
  ```ts
89
124
  page
90
125
 
@@ -109,7 +144,56 @@ Paragraph {
109
144
  "Admin mode is " + getStatus() + "!"
110
145
  }
111
146
  ```
112
- #### NEW (0.13.5): Fullscreen activation + if-else inside Component
147
+ #### Code what you need
148
+ ```ts
149
+ page
150
+ title = "For Loop Variable Test"
151
+
152
+ var obj historyList = []
153
+ var int kickCount = 0
154
+ var str userName = ""
155
+ var obj newList = []
156
+ var int i = 0
157
+
158
+ function kickUser() {
159
+ if userName != "" {
160
+ historyList.push(userName)
161
+ kickCount = kickCount + 1
162
+ userName = ""
163
+ }
164
+ }
165
+
166
+ function removeUser(index) {
167
+ newList = []
168
+ i = 0
169
+ for user in historyList {
170
+ if i != index {
171
+ newList.push(user)
172
+ }
173
+ i = i + 1
174
+ }
175
+ historyList = newList
176
+ kickCount = kickCount - 1
177
+ }
178
+
179
+ Main {
180
+ Heading(level: 1) { "For Loop Test" }
181
+
182
+ Input(bind: userName, placeholder: "Enter username to kick")
183
+ Button(onClick: kickUser()) { "Add User" }
184
+
185
+ Paragraph { "Count: " + kickCount }
186
+
187
+ Heading(level: 2) { "Users:" }
188
+ for kickedUser, index in historyList {
189
+ Paragraph { kickedUser }
190
+ Button(onClick: removeUser(index)) { "Remove" }
191
+ }
192
+ }
193
+ ```
194
+
195
+
196
+ #### Fullscreen activation + if-else inside Component
113
197
 
114
198
  ```ts
115
199
  page
@@ -137,7 +221,7 @@ Main {
137
221
  }
138
222
  ```
139
223
 
140
- #### Fullscreen Sync (0.13.6)
224
+ #### Fullscreen Sync
141
225
 
142
226
  Opt-in Escape key handling. `fullscreenSync` keeps your variable in sync with the browser's fullscreen state.
143
227
 
@@ -147,11 +231,11 @@ Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen, fullscre
147
231
  }
148
232
  ```
149
233
  Without fullscreenSync, pressing Escape exits fullscreen but the variable stays true.
150
- With it, Escape resets the variable to false — button text updates automatically.
234
+ With it, Escape resets the variable to false and the button text updates automatically.
151
235
 
152
236
  #### Opt-in DOM Diffing
153
237
 
154
- Skip re-executing expressions when their variables haven't changed. Perfect for expensive calculations or side effects you only want to fire once.
238
+ 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
155
239
 
156
240
  ```ts
157
241
  page
@@ -169,8 +253,12 @@ Count updates every click because count changed. The alert fires only on page lo
169
253
 
170
254
  #### Animations that make sense.
171
255
  ```ts
256
+ page
257
+
258
+ var str[] items = ["First", "Second", "Third", "Fourth", "Fifth"]
259
+
172
260
  for item, index in items {
173
- Paragraph(delay: index * 300) { item.name }
261
+ Paragraph(delay: (index + 1) * 1000) { item }
174
262
  }
175
263
  ```
176
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "A declarative & reactive language that compiles to pure HTML, CSS, and JavaScript.",
5
5
  "author": "Yannosay Productions",
6
6
  "license": "AGPL-3.0",
@@ -1087,7 +1087,7 @@ export function buildRuntime(opts: {
1087
1087
  const needsLogic = logicBlocks.length > 0;
1088
1088
  const needsFullscreen = bodyHTML.includes("data-sinth-fullscreen");
1089
1089
  const needsFullscreenSync = bodyHTML.includes("data-sinth-fullscreen-sync");
1090
- const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide") || needsFullscreen || needsFullscreenSync;
1090
+ const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide") || needsFullscreen || needsFullscreenSync || needsDelay;
1091
1091
 
1092
1092
  const varLines = varDecls.map(v => {
1093
1093
  if (!v.value) {
@@ -1115,7 +1115,7 @@ export function buildRuntime(opts: {
1115
1115
  return `let ${v.name} = ${val};`;
1116
1116
  }).join("\n");
1117
1117
 
1118
- if (!needsRender && !needsDelay) {
1118
+ if (!needsRender) {
1119
1119
  return varLines ? `// Sinth compiled runtime\n${varLines}` : "";
1120
1120
  }
1121
1121
 
@@ -95,16 +95,25 @@ function sinthDelay(el) {
95
95
  }
96
96
  }
97
97
  function sinthDelayExpr(el, _ctx) {
98
+ if (el.dataset.sinthDelayDone) return;
99
+ el.dataset.sinthDelayDone = '1';
98
100
  _ctx = _ctx || {};
99
101
  try {
100
102
  let fn = __X[el.dataset.sinthDelayExprId];
101
103
  let ms = fn ? parseInt(fn(_ctx)) || 0 : 0;
104
+ let hideEl = el.dataset.sinthDelayHide !== 'false';
102
105
  let show = function() {
103
- el.style.display = '';
106
+ if (hideEl) el.style.display = '';
104
107
  el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
105
108
  };
106
- if (ms > 0) setTimeout(show, ms);
107
- else show();
109
+ if (hideEl) {
110
+ el.style.display = 'none';
111
+ if (ms > 0) setTimeout(show, ms);
112
+ else show();
113
+ } else {
114
+ if (ms > 0) setTimeout(show, ms);
115
+ else show();
116
+ }
108
117
  } catch(e) {}
109
118
  }
110
119
  `;
@@ -290,6 +299,9 @@ function sinthForBlock(t) {
290
299
  try { let fn = __X[el.dataset.exprId]; if (fn) el.textContent = fn(loopCtx); } catch(e) {}
291
300
  el.classList.remove('sinth-expr');
292
301
  });
302
+ frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) {
303
+ sinthDelayExpr(el, loopCtx);
304
+ });
293
305
  frag.querySelectorAll('[onclick*="_ctx."]').forEach(function(el) {
294
306
  var onclick = el.getAttribute('onclick');
295
307
  for (var key in loopCtx) {
@@ -84,7 +84,8 @@ export function buildRenderBody(opts: {
84
84
  el._sinthLastContent = newContent;
85
85
  delete el.dataset.sinthDelayDone;
86
86
  }
87
- });\n`;
87
+ });
88
+ document.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });\n`;
88
89
  }
89
90
  if (needsExpr) {
90
91
  renderBody += ` document.querySelectorAll('.sinth-expr').forEach(function(el) {
@@ -123,6 +124,7 @@ export function buildRenderBody(opts: {
123
124
  if (needsDelay) {
124
125
  renderBody += ` setTimeout(function() {
125
126
  document.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
127
+ document.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
126
128
  }, 0);\n`;
127
129
  }
128
130
  renderBody += ` window.scrollTo(_sx, _sy);\n`;