@yannosay/sinth 0.14.0 → 0.14.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yannosay/sinth",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
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",
@@ -617,6 +617,18 @@ export function renderCompUse(
617
617
  if (classes) attrParts.push(`class="${escAttr(classes)}"`);
618
618
  if (inlineStyleParts.length > 0) attrParts.push(`style="${escAttr(inlineStyleParts.join("; "))}"`);
619
619
  if (tag === "button" && !use.attrs.some(a => a.name === "type")) attrParts.push(`type="button"`);
620
+ if (use.attrs.some(a => a.name === "delay") && use.attrs.some(a => a.name === "hide")) {
621
+ const hideAttr = use.attrs.find(a => a.name === "hide")!;
622
+ const hideVal = hideAttr.value;
623
+ const isHidden = (hideVal === null) ||
624
+ (hideVal?.kind === "bool" && hideVal.value) ||
625
+ (hideVal?.kind === "str" && hideVal.value !== "false");
626
+ attrParts.push(`data-sinth-delay-hide="${isHidden ? "true" : "false"}"`);
627
+ if (!isHidden) {
628
+ // hide: false → show initial content immediately, delay only on updates
629
+ attrParts.push(`data-sinth-delay-done="1"`);
630
+ }
631
+ }
620
632
  if (use.name === "Input") {
621
633
  const bindAttr = use.attrs.find(a => a.name === "bind");
622
634
  const modelAttr = use.attrs.find(a => a.name === "model");
@@ -73,15 +73,19 @@ function sinthDelay(el) {
73
73
  if (el.dataset.sinthDelayDone) { return; }
74
74
  el.dataset.sinthDelayDone = '1';
75
75
  var ms = parseInt(el.dataset.sinthDelay) || 0;
76
- if (el.dataset.sinthDelayHide !== 'false') {
77
- el.style.display = 'none';
78
- }
76
+ var hideEl = el.dataset.sinthDelayHide !== 'false';
79
77
  var show = function() {
80
- el.style.display = '';
78
+ if (hideEl) el.style.display = '';
81
79
  el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
82
80
  };
83
- if (ms > 0) setTimeout(show, ms);
84
- else show();
81
+ if (hideEl) {
82
+ el.style.display = 'none';
83
+ if (ms > 0) setTimeout(show, ms);
84
+ else show();
85
+ } else {
86
+ if (ms > 0) setTimeout(show, ms);
87
+ else show();
88
+ }
85
89
  }
86
90
  function sinthDelayExpr(el, _ctx) {
87
91
  _ctx = _ctx || {};
@@ -70,8 +70,28 @@ export function buildRenderBody(opts: {
70
70
  } catch(e) {}
71
71
  });\n`;
72
72
  }
73
+ if (needsDelay) {
74
+ renderBody += ` document.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
75
+ var newContent = '';
76
+ el.querySelectorAll('.sinth-expr').forEach(function(exprEl) {
77
+ var exprFn = __X[exprEl.dataset.exprId];
78
+ if (exprFn) newContent += exprFn({});
79
+ });
80
+ if (el._sinthLastContent === undefined) {
81
+ el._sinthLastContent = newContent;
82
+ } else if (el._sinthLastContent !== newContent) {
83
+ el._sinthLastContent = newContent;
84
+ delete el.dataset.sinthDelayDone;
85
+ }
86
+ });\n`;
87
+ }
73
88
  if (needsExpr) {
74
- renderBody += ` document.querySelectorAll('.sinth-expr').forEach(sinthExpr);\n`;
89
+ renderBody += ` document.querySelectorAll('.sinth-expr').forEach(function(el) {
90
+ var delayParent = el.closest('[data-sinth-delay]');
91
+ if (!delayParent || delayParent.dataset.sinthDelayDone) {
92
+ sinthExpr(el);
93
+ }
94
+ });\n`;
75
95
  }
76
96
  renderBody += ` document.querySelectorAll('[data-sinth-hide]').forEach(function(el) {
77
97
  var exprId = el.dataset.sinthHide;