@yannosay/sinth 0.13.4 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.13.4",
3
+ "version": "0.13.5",
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",
@@ -123,6 +123,20 @@ if (name === "delay") {
123
123
  return "";
124
124
  }
125
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 ""; }
135
+ }
136
+ }
137
+ return "";
138
+ }
139
+
126
140
  if (name === "checked") {
127
141
  return (value as any)?.kind === "bool" && (value as any).value ? "checked" : "";
128
142
  }
@@ -732,13 +746,14 @@ export function buildRuntime(opts: {
732
746
  }): string | { page: string; shared: string } {
733
747
  const { varDecls, bodyHTML, logicBlocks, mixedBlocks, assignedVars, exprRegistry, functionsJS } = opts;
734
748
 
735
- const needsExpr = bodyHTML.includes("sinth-expr");
736
- const needsIf = bodyHTML.includes("data-sinth-if");
749
+ const needsMixed = mixedBlocks.length > 0;
750
+ const needsExpr = bodyHTML.includes("sinth-expr") || needsMixed;
751
+ const needsIf = bodyHTML.includes("data-sinth-if") || needsMixed;
737
752
  const needsFor = bodyHTML.includes("data-sinth-for");
738
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"));
739
- const needsMixed = mixedBlocks.length > 0;
740
754
  const needsLogic = logicBlocks.length > 0;
741
- const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide");
755
+ const needsFullscreen = bodyHTML.includes("data-sinth-fullscreen");
756
+ const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide") || needsFullscreen;
742
757
 
743
758
  const varLines = varDecls.map(v => {
744
759
  if (!v.value) {
@@ -564,7 +564,30 @@ private parseArrayLiteral(): Literal {
564
564
  }
565
565
  if (this.check(TT.STRING)) {
566
566
  const loc = this.peek().loc;
567
- children.push({ kind: "text", value: this.consume(TT.STRING).value, loc });
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
 
@@ -1,4 +1,4 @@
1
- import { CompileCtx, FunctionDef } from "../types.ts";
1
+ import { CompileCtx, FunctionDef, IfBlock } from "../types.ts";
2
2
  import { compileExprToJS, compileIfToJS } from "../expr.ts";
3
3
 
4
4
  export function compileFunctionDef(fn: FunctionDef, ctx: CompileCtx): string {
@@ -82,6 +82,21 @@ export function buildRenderBody(opts: {
82
82
  el.style.display = 'none';
83
83
  }
84
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`;
85
100
  if (needsDelay) {
86
101
  renderBody += ` setTimeout(function() {
87
102
  document.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);