@yannosay/sinth 0.13.4 → 0.13.6

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
@@ -45,7 +45,7 @@ No JSX ternaries. No v-if. No separate script tags. Mixed logic. Clean.
45
45
  ```ts
46
46
  page
47
47
 
48
- title = "Full Test"
48
+ title = "Functions"
49
49
 
50
50
  var str userName = "Sinths User"
51
51
 
@@ -92,6 +92,45 @@ Paragraph {
92
92
  "Admin mode is " + (getStatus()) + "! :D"
93
93
  }
94
94
  ```
95
+ #### NEW (0.13.5): Fullscreen activation + if-else inside Component
96
+
97
+ ```ts
98
+ page
99
+ title = "Fullscreen"
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 == "Sinth" {
115
+ "Oh, welcome back!"
116
+ } else {
117
+ "Hello, " + userName + "!"
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ #### Fullscreen Sync (0.13.6)
124
+
125
+ Opt-in Escape key handling. `fullscreenSync` keeps your variable in sync with the browser's fullscreen state.
126
+
127
+ ```ts
128
+ Button(onClick: isFullscreen = !isFullscreen, fullscreen: isFullscreen, fullscreenSync: isFullscreen) {
129
+ if isFullscreen { "Exit Fullscreen" } else { "Enter Fullscreen" }
130
+ }
131
+ ```
132
+ Without fullscreenSync, pressing Escape exits fullscreen but the variable stays true.
133
+ With it, Escape resets the variable to false — button text updates automatically.
95
134
 
96
135
 
97
136
  #### Animations that make sense.
@@ -118,7 +157,23 @@ Delete elements for good. No virtual DOM diffing.
118
157
 
119
158
  Compiles to pure HTML.
120
159
 
121
- #### Ready to upload wherever you want.
160
+ #### Reactivity at its finest
161
+ ```ts
162
+ page
163
+ title = "Reactivity but easy"
164
+
165
+ var str begForFullscreen = ""
166
+ var bool doFullscreen = false
167
+
168
+ Main {
169
+ Input(bind: begForFullscreen, fullscreen: doFullscreen)
170
+ if begForFullscreen == "do fullscreen pls!!" {
171
+ doFullscreen = true
172
+ } else {
173
+ doFullscreen = false
174
+ }
175
+ }
176
+ ```
122
177
 
123
178
 
124
179
  # Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.13.4",
3
+ "version": "0.13.6",
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,36 @@ 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
+
140
+ if (name === "fullscreenSync") {
141
+ if (value?.kind === "str") {
142
+ const raw = value.value;
143
+ if (raw.startsWith("__EXPR__")) {
144
+ try {
145
+ const expr: Expression = JSON.parse(raw.substring(8));
146
+ if (expr.kind === "variable" && expr.name) {
147
+ return `data-sinth-fullscreen-sync="${escAttr(expr.name)}"`;
148
+ }
149
+ } catch {}
150
+ }
151
+ return `data-sinth-fullscreen-sync="${escAttr(raw)}"`;
152
+ }
153
+ return "";
154
+ }
155
+
126
156
  if (name === "checked") {
127
157
  return (value as any)?.kind === "bool" && (value as any).value ? "checked" : "";
128
158
  }
@@ -730,15 +760,17 @@ export function buildRuntime(opts: {
730
760
  sharedRuntime: boolean;
731
761
  functionsJS: string;
732
762
  }): string | { page: string; shared: string } {
763
+
733
764
  const { varDecls, bodyHTML, logicBlocks, mixedBlocks, assignedVars, exprRegistry, functionsJS } = opts;
734
-
735
- const needsExpr = bodyHTML.includes("sinth-expr");
736
- const needsIf = bodyHTML.includes("data-sinth-if");
765
+ const needsMixed = mixedBlocks.length > 0;
766
+ const needsExpr = bodyHTML.includes("sinth-expr") || needsMixed;
767
+ const needsIf = bodyHTML.includes("data-sinth-if") || needsMixed;
737
768
  const needsFor = bodyHTML.includes("data-sinth-for");
738
769
  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
770
  const needsLogic = logicBlocks.length > 0;
741
- const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide");
771
+ const needsFullscreen = bodyHTML.includes("data-sinth-fullscreen");
772
+ const needsFullscreenSync = bodyHTML.includes("data-sinth-fullscreen-sync");
773
+ const needsRender = needsExpr || needsIf || needsFor || needsMixed || needsLogic || bodyHTML.includes("data-sinth-hide") || needsFullscreen || needsFullscreenSync;
742
774
 
743
775
  const varLines = varDecls.map(v => {
744
776
  if (!v.value) {
@@ -782,7 +814,24 @@ export function buildRuntime(opts: {
782
814
  ? `var __X = [${exprRegistry.map((js) => `function(_ctx){ return ${js}; }`).join(",")}];\n`
783
815
  : "";
784
816
 
785
- const renderFunc = needsRender ? `function sinthRender() {\n${renderBody}}\nsinthRender();` : "";
817
+ let renderFunc = needsRender ? `function sinthRender() {\n${renderBody}}\nsinthRender();` : "";
818
+
819
+ if (needsFullscreenSync) {
820
+ renderFunc += `
821
+ (function() {
822
+ var syncedEls = document.querySelectorAll('[data-sinth-fullscreen-sync]');
823
+ if (syncedEls.length > 0) {
824
+ var vars = [];
825
+ syncedEls.forEach(function(el) { vars.push(el.dataset.sinthFullscreenSync); });
826
+ document.addEventListener('fullscreenchange', function() {
827
+ if (!document.fullscreenElement) {
828
+ vars.forEach(function(v) { window[v] = false; });
829
+ sinthRender();
830
+ }
831
+ });
832
+ }
833
+ })();`;
834
+ }
786
835
 
787
836
  const pageCode = `// Sinth page runtime
788
837
  ${varLines}
@@ -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);