@yannosay/sinth 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sinth.ts +41 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A declarative language that compiles to pure HTML, CSS, and JavaScript.",
5
5
  "author": "Yannosay Productions",
6
6
  "license": "AGPL-3.0",
package/src/sinth.ts CHANGED
@@ -872,10 +872,21 @@ private parseCompUse(): CompUse {
872
872
  }
873
873
  }
874
874
  } else {
875
- value = this.parseLiteral();
875
+ // Try literal first, then variable reference
876
+ if (this.check(TT.STRING) || this.check(TT.NUMBER) ||
877
+ this.check(TT.BOOL_TRUE) || this.check(TT.BOOL_FALSE) ||
878
+ this.check(TT.NULL_LIT) || this.check(TT.LBRACKET)) {
879
+ value = this.parseLiteral();
880
+ } else if (this.check(TT.IDENT)) {
881
+ const varName = this.consume(TT.IDENT).value;
882
+ value = { kind: "str", value: varName };
883
+ } else {
884
+ value = this.parseLiteral();
885
+ }
876
886
  }
877
887
  }
878
888
  attrs.push({ name: aname, value, loc: aloc });
889
+
879
890
  if (!this.check(TT.RPAREN)) this.consume(TT.COMMA);
880
891
  }
881
892
  this.consume(TT.RPAREN);
@@ -1602,11 +1613,20 @@ function renderAttr(attr: Attr, paramMap: Map<string, string>): string {
1602
1613
  if (value.kind === "null") return "";
1603
1614
  if (value.kind === "bool") return value.value ? name : "";
1604
1615
 
1605
- // --- delay handling (must be before generic number/string cases) ---
1606
- if (name === "delay") {
1607
- const delayVal = value.kind === "num" ? String(value.value) : litToString(value);
1616
+ if (name === "delay") {
1617
+ // Support both numbers and variable references
1618
+ let delayVal: string;
1619
+ if (value.kind === "num") {
1620
+ delayVal = String(value.value);
1621
+ } else {
1622
+ delayVal = litToString(value);
1623
+ // If it looks like a variable name (not a number), treat it as a JS expression
1624
+ if (!/^\d+$/.test(delayVal)) {
1625
+ return `data-sinth-delay-expr="${escAttr(delayVal)}" style="display:none"`;
1626
+ }
1627
+ }
1608
1628
  return `data-sinth-delay="${escAttr(delayVal)}" style="display:none"`;
1609
- }
1629
+ }
1610
1630
 
1611
1631
  if (value.kind === "num") return `${name}="${value.value}"`;
1612
1632
 
@@ -2177,14 +2197,24 @@ function sinthRender() {
2177
2197
  processTemplates(document.body);
2178
2198
 
2179
2199
  // Show delayed elements after DOM settles
2180
- setTimeout(() => {
2200
+ setTimeout(() => {
2201
+ // Handle static delays
2181
2202
  document.querySelectorAll('[data-sinth-delay]').forEach(el => {
2182
- const delayMs = parseInt(el.dataset.sinthDelay) || 0;
2183
- if (delayMs > 0) {
2184
- setTimeout(() => { el.style.display = ''; }, delayMs);
2185
- }
2203
+ const delayMs = parseInt(el.dataset.sinthDelay) || 0;
2204
+ if (delayMs > 0) {
2205
+ setTimeout(() => { el.style.display = ''; }, delayMs);
2206
+ }
2207
+ });
2208
+ // Handle expression-based delays (variables)
2209
+ document.querySelectorAll('[data-sinth-delay-expr]').forEach(el => {
2210
+ try {
2211
+ const delayMs = parseInt(eval(el.dataset.sinthDelayExpr)) || 0;
2212
+ if (delayMs > 0) {
2213
+ setTimeout(() => { el.style.display = ''; }, delayMs);
2214
+ }
2215
+ } catch(e) {}
2186
2216
  });
2187
- }, 0);
2217
+ }, 0);
2188
2218
 
2189
2219
  // Update any remaining expression spans (from initial render)
2190
2220
  document.querySelectorAll('.sinth-expr').forEach(el => {