@yannosay/sinth 1.0.0 → 1.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.
- package/README.md +58 -1
- package/package.json +1 -1
- package/src/core/compiler.ts +9 -5
- package/src/core/runtime/render.ts +3 -3
package/README.md
CHANGED
|
@@ -262,6 +262,63 @@ Main {
|
|
|
262
262
|
}
|
|
263
263
|
```
|
|
264
264
|
|
|
265
|
+
## Use in real life
|
|
266
|
+
```ts
|
|
267
|
+
page
|
|
268
|
+
|
|
269
|
+
title = "Kick Users Admin Panel"
|
|
270
|
+
|
|
271
|
+
var str userName = "test username"
|
|
272
|
+
var int count = 0
|
|
273
|
+
|
|
274
|
+
style lang= "scss"{
|
|
275
|
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
|
|
276
|
+
|
|
277
|
+
* {
|
|
278
|
+
font-family: 'Inter', sans-serif;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
Main {
|
|
283
|
+
Div(display: "flex", flexDirection: "column", gap: "16px", alignItems: "center", padding: "40px", fontFamily: "Inter") {
|
|
284
|
+
Heading(level: 1, fontSize: "28px", color: "#000000", fontWeight: "700") {
|
|
285
|
+
"Kick Counter: " + count
|
|
286
|
+
}
|
|
287
|
+
Div(display: "flex", gap: "12px", alignItems: "center") {
|
|
288
|
+
Input(
|
|
289
|
+
bind: userName,
|
|
290
|
+
padding: "10px 14px",
|
|
291
|
+
fontSize: "16px",
|
|
292
|
+
borderRadius: "8px",
|
|
293
|
+
border: "2px solid #6366f1",
|
|
294
|
+
outline: "none",
|
|
295
|
+
width: "250px",
|
|
296
|
+
backgroundColor: "#1e1b4b",
|
|
297
|
+
color: "#e0e7ff",
|
|
298
|
+
fontWeight: "400"
|
|
299
|
+
)
|
|
300
|
+
Button(
|
|
301
|
+
onClick: alert("Kicked: " + userName); console.log("User kicked"); count += 1,
|
|
302
|
+
padding: "10px 20px",
|
|
303
|
+
fontSize: "16px",
|
|
304
|
+
fontWeight: "600",
|
|
305
|
+
borderRadius: "8px",
|
|
306
|
+
border: "none",
|
|
307
|
+
backgroundColor: "#6366f1",
|
|
308
|
+
color: "#ffffff",
|
|
309
|
+
cursor: "pointer",
|
|
310
|
+
minWidth: "180px",
|
|
311
|
+
textAlign: "left"
|
|
312
|
+
) {
|
|
313
|
+
"Kick " + userName
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
Paragraph(fontSize: "14px", color: "#a5b4fc", fontWeight: "400") {
|
|
317
|
+
"Total kicks: " + count
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
```
|
|
265
322
|
|
|
266
323
|
# Install
|
|
267
324
|
npm install -g @yannosay/sinth
|
|
@@ -368,4 +425,4 @@ Main {
|
|
|
368
425
|
|
|
369
426
|
## License
|
|
370
427
|
|
|
371
|
-
AGPL-3.0
|
|
428
|
+
AGPL-3.0 (Just the compiler, the generated Output is 100% yours)
|
package/package.json
CHANGED
package/src/core/compiler.ts
CHANGED
|
@@ -159,7 +159,8 @@ if (name === "step" && value?.kind === "str") {
|
|
|
159
159
|
try {
|
|
160
160
|
const expr: Expression = JSON.parse(raw.substring(8));
|
|
161
161
|
if (expr.kind === "variable" && expr.name) {
|
|
162
|
-
|
|
162
|
+
const stepExprId = registerExpr(ctx, expr);
|
|
163
|
+
return `data-sinth-step="${stepExprId}"`;
|
|
163
164
|
}
|
|
164
165
|
} catch {}
|
|
165
166
|
}
|
|
@@ -835,7 +836,8 @@ export function renderCompUse(
|
|
|
835
836
|
const initialVal = varDecl?.value ? litToString(varDecl.value).replace(/"/g, '"') : "";
|
|
836
837
|
attrParts.push(`oninput="(function(e){ ${vName} = ${rhs}; sinthRender(); })(event)"`);
|
|
837
838
|
attrParts.push(`value="${escAttr(initialVal)}"`);
|
|
838
|
-
|
|
839
|
+
const valueExprId = registerExpr(ctx, { kind: "variable", name: vName });
|
|
840
|
+
attrParts.push(`data-sinth-value="${valueExprId}"`);
|
|
839
841
|
}
|
|
840
842
|
}
|
|
841
843
|
if (use.name === "Checkbox") {
|
|
@@ -851,14 +853,16 @@ export function renderCompUse(
|
|
|
851
853
|
try {
|
|
852
854
|
const expr: Expression = JSON.parse(raw.substring(8));
|
|
853
855
|
if (expr.kind === "variable" && expr.name) {
|
|
854
|
-
|
|
856
|
+
const checkedExprId = registerExpr(ctx, { kind: "variable", name: expr.name });
|
|
857
|
+
attrParts.push(`data-sinth-checked="${checkedExprId}"`);
|
|
855
858
|
} else {
|
|
856
859
|
const exprId = registerExpr(ctx, expr);
|
|
857
860
|
attrParts.push(`data-sinth-checked-expr="${exprId}"`);
|
|
858
861
|
}
|
|
859
862
|
} catch {}
|
|
860
863
|
} else {
|
|
861
|
-
|
|
864
|
+
const checkedExprId = registerExpr(ctx, { kind: "variable", name: raw });
|
|
865
|
+
attrParts.push(`data-sinth-checked="${checkedExprId}"`);
|
|
862
866
|
}
|
|
863
867
|
}
|
|
864
868
|
}
|
|
@@ -1067,7 +1071,7 @@ export function buildRuntime(opts: {
|
|
|
1067
1071
|
? `let __X = [${exprRegistry.map((js) => `function(_ctx){ return ${js}; }`).join(",")}];\n`
|
|
1068
1072
|
: "";
|
|
1069
1073
|
|
|
1070
|
-
let renderFunc = needsRender ? `
|
|
1074
|
+
let renderFunc = needsRender ? `var _sinthRenderPending = false;\nfunction sinthRender() {\n if (_sinthRenderPending) return;\n _sinthRenderPending = true;\n requestAnimationFrame(function() {\n _sinthRenderPending = false;\n${renderBody.replace(/^/gm, " ")}\n });\n}\nsinthRender();` : "";
|
|
1071
1075
|
|
|
1072
1076
|
if (needsFullscreenSync) {
|
|
1073
1077
|
renderFunc += `
|
|
@@ -55,13 +55,13 @@ export function buildRenderBody(opts: {
|
|
|
55
55
|
renderBody += ` document.querySelectorAll('template[data-sinth-for]').forEach(sinthForBlock);\n`;
|
|
56
56
|
}
|
|
57
57
|
renderBody += ` document.querySelectorAll('[data-sinth-value]').forEach(function(el) {
|
|
58
|
-
try { if (document.activeElement !== el) { el.value =
|
|
58
|
+
try { if (document.activeElement !== el) { let v=el.dataset.sinthValue; el.value = __X[v] ? __X[v]({}) : ''; } } catch(e) {}
|
|
59
59
|
});\n`;
|
|
60
60
|
renderBody += ` document.querySelectorAll('[data-sinth-step]').forEach(function(el) {
|
|
61
|
-
try {
|
|
61
|
+
try { let s=el.dataset.sinthStep; el.step = __X[s] ? __X[s]({}) : 1; } catch(e) {}
|
|
62
62
|
});\n`;
|
|
63
63
|
renderBody += ` document.querySelectorAll('[data-sinth-checked]').forEach(function(el) {
|
|
64
|
-
try { el.checked =
|
|
64
|
+
try { let c=el.dataset.sinthChecked; el.checked = __X[c] ? !!__X[c]({}) : false; } catch(e) {}
|
|
65
65
|
});\n`;
|
|
66
66
|
if (bodyHTML.includes("data-sinth-checked-expr")) {
|
|
67
67
|
renderBody += ` document.querySelectorAll('[data-sinth-checked-expr]').forEach(function(el) {
|