@yannosay/sinth 0.13.3 → 0.13.5
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 +26 -0
- package/package.json +1 -1
- package/src/core/compiler.ts +34 -10
- package/src/core/parser.ts +24 -1
- package/src/core/runtime/functions.ts +1 -1
- package/src/core/runtime/render.ts +26 -0
package/README.md
CHANGED
|
@@ -92,7 +92,33 @@ Paragraph {
|
|
|
92
92
|
"Admin mode is " + (getStatus()) + "! :D"
|
|
93
93
|
}
|
|
94
94
|
```
|
|
95
|
+
#### NEW (0.13.5): Fullscreen activation + if-else inside Component
|
|
95
96
|
|
|
97
|
+
```ts
|
|
98
|
+
page
|
|
99
|
+
title = "Counter"
|
|
100
|
+
|
|
101
|
+
var bool isFullscreen = false
|
|
102
|
+
var str userName = ""
|
|
103
|
+
|
|
104
|
+
Main {
|
|
105
|
+
Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen) {
|
|
106
|
+
if isFullscreen {
|
|
107
|
+
"Exit Fullscreen"
|
|
108
|
+
} else {
|
|
109
|
+
"Enter Fullscreen"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
Input(bind: userName)
|
|
113
|
+
Paragraph {
|
|
114
|
+
if userName == "Yannosay" {
|
|
115
|
+
"YANNOSAY??? YOU?? :O"
|
|
116
|
+
} else {
|
|
117
|
+
"Hello, " + userName + "!"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
96
122
|
|
|
97
123
|
#### Animations that make sense.
|
|
98
124
|
```ts
|
package/package.json
CHANGED
package/src/core/compiler.ts
CHANGED
|
@@ -104,11 +104,35 @@ if (name === "delay") {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (name === "hide") {
|
|
107
|
+
if (value === null) return `data-sinth-hide=""`;
|
|
107
108
|
if (value && (value as any).kind === "bool") {
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
return (value as any).value ? `data-sinth-hide=""` : "";
|
|
110
|
+
}
|
|
111
|
+
if (value?.kind === "str") {
|
|
112
|
+
const v = value.value;
|
|
113
|
+
if (v === "true") return `data-sinth-hide=""`;
|
|
114
|
+
if (v === "false") return "";
|
|
115
|
+
if (v.startsWith("__EXPR__")) {
|
|
116
|
+
try {
|
|
117
|
+
const expr: Expression = JSON.parse(v.substring(8));
|
|
118
|
+
const id = registerExpr(ctx, expr);
|
|
119
|
+
return `data-sinth-hide="${id}"`;
|
|
120
|
+
} catch { return ""; }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (name === "fullscreen") {
|
|
127
|
+
if (value?.kind === "str") {
|
|
128
|
+
const v = value.value;
|
|
129
|
+
if (v.startsWith("__EXPR__")) {
|
|
130
|
+
try {
|
|
131
|
+
const expr: Expression = JSON.parse(v.substring(8));
|
|
132
|
+
const id = registerExpr(ctx, expr);
|
|
133
|
+
return `data-sinth-fullscreen="${id}"`;
|
|
134
|
+
} catch { return ""; }
|
|
110
135
|
}
|
|
111
|
-
return "";
|
|
112
136
|
}
|
|
113
137
|
return "";
|
|
114
138
|
}
|
|
@@ -516,9 +540,8 @@ export function renderCompUse(
|
|
|
516
540
|
}
|
|
517
541
|
if (use.name === "Checkbox" && (attr.name === "checked" || attr.name === "onChange" || attr.name === "label")) continue;
|
|
518
542
|
if (attr.name === "hide") {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
543
|
+
const rendered = renderAttr(attr, params, ctx);
|
|
544
|
+
if (rendered) attrParts.push(rendered);
|
|
522
545
|
continue;
|
|
523
546
|
}
|
|
524
547
|
const rendered = renderAttr(attr, params, ctx);
|
|
@@ -723,13 +746,14 @@ export function buildRuntime(opts: {
|
|
|
723
746
|
}): string | { page: string; shared: string } {
|
|
724
747
|
const { varDecls, bodyHTML, logicBlocks, mixedBlocks, assignedVars, exprRegistry, functionsJS } = opts;
|
|
725
748
|
|
|
726
|
-
const
|
|
727
|
-
const
|
|
749
|
+
const needsMixed = mixedBlocks.length > 0;
|
|
750
|
+
const needsExpr = bodyHTML.includes("sinth-expr") || needsMixed;
|
|
751
|
+
const needsIf = bodyHTML.includes("data-sinth-if") || needsMixed;
|
|
728
752
|
const needsFor = bodyHTML.includes("data-sinth-for");
|
|
729
753
|
const needsDelay = bodyHTML.includes("data-sinth-delay") || bodyHTML.includes("data-sinth-delay-expr-id") || mixedBlocks.some(mb => mb.ifHTML.includes("data-sinth-delay") || mb.ifHTML.includes("data-sinth-delay-expr-id") || mb.elseHTML.includes("data-sinth-delay") || mb.elseHTML.includes("data-sinth-delay-expr-id"));
|
|
730
|
-
const needsMixed = mixedBlocks.length > 0;
|
|
731
754
|
const needsLogic = logicBlocks.length > 0;
|
|
732
|
-
const
|
|
755
|
+
const needsFullscreen = bodyHTML.includes("data-sinth-fullscreen");
|
|
756
|
+
const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide") || needsFullscreen;
|
|
733
757
|
|
|
734
758
|
const varLines = varDecls.map(v => {
|
|
735
759
|
if (!v.value) {
|
package/src/core/parser.ts
CHANGED
|
@@ -564,7 +564,30 @@ private parseArrayLiteral(): Literal {
|
|
|
564
564
|
}
|
|
565
565
|
if (this.check(TT.STRING)) {
|
|
566
566
|
const loc = this.peek().loc;
|
|
567
|
-
|
|
567
|
+
let leftExpr: Expression = { kind: "literal", value: { kind: "str", value: this.consume(TT.STRING).value } };
|
|
568
|
+
while (this.check(TT.OP_PLUS)) {
|
|
569
|
+
this.consume(TT.OP_PLUS);
|
|
570
|
+
let rhs: Expression | null = null;
|
|
571
|
+
if (this.check(TT.STRING)) {
|
|
572
|
+
rhs = { kind: "literal", value: { kind: "str", value: this.consume(TT.STRING).value } };
|
|
573
|
+
} else if (this.check(TT.IDENT)) {
|
|
574
|
+
const rhsName = this.consume(TT.IDENT).value;
|
|
575
|
+
if (this.check(TT.DOT)) {
|
|
576
|
+
this.consume(TT.DOT);
|
|
577
|
+
rhs = { kind: "variable", name: rhsName + "." + this.consume(TT.IDENT).value };
|
|
578
|
+
} else if (this.check(TT.LBRACKET)) {
|
|
579
|
+
const rhsVar: Expression = { kind: "variable", name: rhsName };
|
|
580
|
+
rhs = this.parsePostfix(rhsVar);
|
|
581
|
+
} else {
|
|
582
|
+
rhs = { kind: "variable", name: rhsName };
|
|
583
|
+
}
|
|
584
|
+
} else {
|
|
585
|
+
rhs = this.parseExpression();
|
|
586
|
+
}
|
|
587
|
+
if (!rhs) throw new SinthError("Expected expression after +", this.peek().loc);
|
|
588
|
+
leftExpr = { kind: "binary", left: leftExpr, op: "+", right: rhs };
|
|
589
|
+
}
|
|
590
|
+
children.push({ kind: "expr", expression: leftExpr, loc });
|
|
568
591
|
continue;
|
|
569
592
|
}
|
|
570
593
|
|
|
@@ -71,6 +71,32 @@ export function buildRenderBody(opts: {
|
|
|
71
71
|
if (needsExpr) {
|
|
72
72
|
renderBody += ` document.querySelectorAll('.sinth-expr').forEach(sinthExpr);\n`;
|
|
73
73
|
}
|
|
74
|
+
renderBody += ` document.querySelectorAll('[data-sinth-hide]').forEach(function(el) {
|
|
75
|
+
var exprId = el.dataset.sinthHide;
|
|
76
|
+
if (exprId) {
|
|
77
|
+
try {
|
|
78
|
+
var exprFn = __X[exprId];
|
|
79
|
+
if (exprFn) el.style.display = exprFn({}) ? 'none' : '';
|
|
80
|
+
} catch(e) {}
|
|
81
|
+
} else {
|
|
82
|
+
el.style.display = 'none';
|
|
83
|
+
}
|
|
84
|
+
});\n`;
|
|
85
|
+
renderBody += ` document.querySelectorAll('[data-sinth-fullscreen]').forEach(function(el) {
|
|
86
|
+
var exprId = el.dataset.sinthFullscreen;
|
|
87
|
+
if (exprId) {
|
|
88
|
+
try {
|
|
89
|
+
var exprFn = __X[exprId];
|
|
90
|
+
if (exprFn) {
|
|
91
|
+
if (exprFn({})) {
|
|
92
|
+
if (document.documentElement.requestFullscreen) document.documentElement.requestFullscreen();
|
|
93
|
+
} else {
|
|
94
|
+
if (document.fullscreenElement && document.exitFullscreen) document.exitFullscreen();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch(e) {}
|
|
98
|
+
}
|
|
99
|
+
});\n`;
|
|
74
100
|
if (needsDelay) {
|
|
75
101
|
renderBody += ` setTimeout(function() {
|
|
76
102
|
document.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|