@yannosay/sinth 0.12.0 → 0.13.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 +2 -2
- package/src/core/compiler.ts +199 -93
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yannosay/sinth",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A declarative language that compiles to pure HTML, CSS, and JavaScript.",
|
|
3
|
+
"version": "0.13.1",
|
|
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",
|
|
7
7
|
"homepage": "https://sinth.yannosay.com",
|
package/src/core/compiler.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import * as fs from "fs";
|
|
3
|
-
import { Loc, Literal, Expression, Child, Attr, CompUse, IfBlock, ForLoop, RemoveStmt, StyleBlock, CompDef, ParamDecl, VarDeclaration, SinthFile, CompileCtx, MixedBlockEntry, SinthError, SinthWarning, TT, AssignStmt, MetaEntry } from "./types.ts";
|
|
3
|
+
import { Loc, Literal, Expression, Child, Attr, CompUse, IfBlock, ForLoop, RemoveStmt, ReturnStmt, StyleBlock, CompDef, ParamDecl, VarDeclaration, SinthFile, CompileCtx, MixedBlockEntry, SinthError, SinthWarning, TT, AssignStmt, MetaEntry } from "./types.ts";
|
|
4
4
|
import { Parser } from "./parser.ts";
|
|
5
5
|
import { fnv1a, camelToKebab, esc, escAttr, litToString, tagNameToPascal } from "../utils.ts";
|
|
6
6
|
import { compileExprToJS, compileIfToJS, bodyToJS } from "./expr.ts";
|
|
@@ -505,20 +505,29 @@ if (name === "model" && value?.kind === "str") {
|
|
|
505
505
|
|
|
506
506
|
if (name === "delay") {
|
|
507
507
|
if (value.kind === "num") {
|
|
508
|
-
return `data-sinth-delay="${value.value}"
|
|
508
|
+
return `data-sinth-delay="${value.value}"`;
|
|
509
509
|
}
|
|
510
510
|
const v = litToString(value);
|
|
511
|
-
if (/^\d+$/.test(v)) return `data-sinth-delay="${escAttr(v)}"
|
|
511
|
+
if (/^\d+$/.test(v)) return `data-sinth-delay="${escAttr(v)}"`;
|
|
512
512
|
if (v.startsWith("__EXPR__")) {
|
|
513
513
|
try {
|
|
514
514
|
const expr: Expression = JSON.parse(v.substring(8));
|
|
515
515
|
const id = registerExpr(ctx, expr);
|
|
516
|
-
return `data-sinth-delay-expr-id="${id}"
|
|
516
|
+
return `data-sinth-delay-expr-id="${id}"`;
|
|
517
517
|
} catch {}
|
|
518
518
|
}
|
|
519
|
-
// plain variable name – register as expression
|
|
520
519
|
const id = registerExpr(ctx, { kind: "variable", name: v });
|
|
521
|
-
return `data-sinth-delay-expr-id="${id}"
|
|
520
|
+
return `data-sinth-delay-expr-id="${id}"`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (name === "hide") {
|
|
524
|
+
if (value && (value as any).kind === "bool") {
|
|
525
|
+
if (!(value as any).value) {
|
|
526
|
+
return `data-sinth-delay-hide="false"`;
|
|
527
|
+
}
|
|
528
|
+
return "";
|
|
529
|
+
}
|
|
530
|
+
return "";
|
|
522
531
|
}
|
|
523
532
|
|
|
524
533
|
if (name === "checked") {
|
|
@@ -637,15 +646,49 @@ export function renderChild(
|
|
|
637
646
|
localParams.set(fnDef.params[i].name, "__VAR__" + arg.name);
|
|
638
647
|
}
|
|
639
648
|
}
|
|
640
|
-
|
|
641
|
-
if (
|
|
642
|
-
|
|
649
|
+
const substituteExpr = (expr: Expression, pm: Map<string, string>): Expression => {
|
|
650
|
+
if (expr.kind === "variable" && pm.has(expr.name!)) {
|
|
651
|
+
const pv = pm.get(expr.name!)!;
|
|
652
|
+
if (pv.startsWith("__LIT__")) return { kind: "literal", value: { kind: "str", value: pv.slice(7) } };
|
|
653
|
+
return { kind: "variable", name: pv.slice(7) };
|
|
654
|
+
}
|
|
655
|
+
if (expr.kind === "binary") return { ...expr, left: substituteExpr(expr.left!, pm), right: substituteExpr(expr.right!, pm) };
|
|
656
|
+
if (expr.kind === "unary") return { ...expr, operand: substituteExpr(expr.operand!, pm) };
|
|
657
|
+
if (expr.kind === "call") return { ...expr, callee: substituteExpr(expr.callee!, pm), args: expr.args?.map(a => substituteExpr(a, pm)) };
|
|
658
|
+
if (expr.kind === "index") return { ...expr, object: substituteExpr(expr.object!, pm), key: substituteExpr(expr.key!, pm) };
|
|
659
|
+
if (expr.kind === "assign") return { ...expr, right: expr.right ? substituteExpr(expr.right, pm) : undefined };
|
|
660
|
+
return expr;
|
|
661
|
+
};
|
|
662
|
+
const substituteChild = (c: Child, pm: Map<string, string>): Child => {
|
|
663
|
+
if (c.kind === "expr") return { ...c, expression: substituteExpr(c.expression, pm) };
|
|
664
|
+
if (c.kind === "assign_stmt") return { ...c, expression: substituteExpr(c.expression, pm) as Expression };
|
|
665
|
+
if (c.kind === "return" && (c as ReturnStmt).expression) return { ...c, expression: substituteExpr((c as ReturnStmt).expression!, pm) } as Child;
|
|
666
|
+
if (c.kind === "if") {
|
|
667
|
+
const ib = c as IfBlock;
|
|
668
|
+
return { ...ib, condition: substituteExpr(ib.condition, pm), body: ib.body.map(bc => substituteChild(bc, pm)), elseBody: ib.elseBody?.map(bc => substituteChild(bc, pm)) };
|
|
669
|
+
}
|
|
670
|
+
if (c.kind === "for") {
|
|
671
|
+
const fl = c as ForLoop;
|
|
672
|
+
return { ...fl, body: fl.body.map(bc => substituteChild(bc, pm)) };
|
|
643
673
|
}
|
|
644
674
|
if (c.kind === "use") {
|
|
645
|
-
|
|
675
|
+
const u = c as CompUse;
|
|
676
|
+
const sa: Attr[] = u.attrs.map(a => {
|
|
677
|
+
if (a.value?.kind === "str") {
|
|
678
|
+
let raw = a.value.value;
|
|
679
|
+
for (const [pn, pv] of pm) {
|
|
680
|
+
if (pv.startsWith("__LIT__")) raw = raw.replace(new RegExp(`\\b${pn}\\b`, 'g'), pv.slice(7));
|
|
681
|
+
if (pv.startsWith("__VAR__")) raw = raw.replace(new RegExp(`\\b${pn}\\b`, 'g'), pv.slice(7));
|
|
682
|
+
}
|
|
683
|
+
return { ...a, value: { kind: "str" as const, value: raw } };
|
|
684
|
+
}
|
|
685
|
+
return a;
|
|
686
|
+
});
|
|
687
|
+
return { ...u, attrs: sa, children: u.children.map(cc => substituteChild(cc, pm)) };
|
|
646
688
|
}
|
|
647
|
-
return
|
|
648
|
-
}
|
|
689
|
+
return c;
|
|
690
|
+
};
|
|
691
|
+
return fnDef.body.map(c => renderChild(substituteChild(c, localParams), ctx, localParams, depth + 1)).join("");
|
|
649
692
|
}
|
|
650
693
|
}
|
|
651
694
|
if (child.expression.kind === "literal" && child.expression.value) {
|
|
@@ -677,16 +720,14 @@ export function renderChild(
|
|
|
677
720
|
return renderIfBlock(child, ctx, params, depth);
|
|
678
721
|
|
|
679
722
|
case "for": {
|
|
680
|
-
// collect loop‑variable names
|
|
681
723
|
const loopVars = new Set<string>();
|
|
682
724
|
loopVars.add(child.itemVar);
|
|
683
725
|
if (child.keyVar) loopVars.add(child.keyVar);
|
|
684
726
|
if (child.indexVar) loopVars.add(child.indexVar);
|
|
685
|
-
// set them on ctx for compilation of the body
|
|
686
727
|
const prev = ctx.loopVars;
|
|
687
728
|
ctx.loopVars = loopVars;
|
|
688
729
|
const bodyHTML = child.body.map(c => renderChild(c, ctx, params, depth + 1)).join("");
|
|
689
|
-
ctx.loopVars = prev;
|
|
730
|
+
ctx.loopVars = prev;
|
|
690
731
|
const keyAttr = child.keyVar ? ` data-sinth-key="${escAttr(child.keyVar)}"` : "";
|
|
691
732
|
const idxAttr = child.indexVar ? ` data-sinth-index="${escAttr(child.indexVar)}"` : "";
|
|
692
733
|
return (
|
|
@@ -737,9 +778,40 @@ depth: number,
|
|
|
737
778
|
replaceAttr = ` data-sinth-if-replace="${escAttr(idAttr.value.value)}"`;
|
|
738
779
|
}
|
|
739
780
|
}
|
|
781
|
+
let delayAttr = "";
|
|
782
|
+
let delayHideAttr = "";
|
|
783
|
+
if (firstComp) {
|
|
784
|
+
const delayA = firstComp.attrs.find(a => a.name === "delay");
|
|
785
|
+
const hideA = firstComp.attrs.find(a => a.name === "hide");
|
|
786
|
+
if (delayA && hideA && hideA.value && (hideA.value as any).kind === "bool" && !(hideA.value as any).value) {
|
|
787
|
+
if (delayA.value?.kind === "num") {
|
|
788
|
+
delayAttr = ` data-sinth-if-delay="${delayA.value.value}"`;
|
|
789
|
+
} else if (delayA.value?.kind === "str") {
|
|
790
|
+
const v = litToString(delayA.value);
|
|
791
|
+
if (/^\d+$/.test(v)) delayAttr = ` data-sinth-if-delay="${v}"`;
|
|
792
|
+
}
|
|
793
|
+
delayHideAttr = ` data-sinth-if-delay-hide="false"`;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
let elseDelayAttr = "";
|
|
797
|
+
let elseDelayHideAttr = "";
|
|
798
|
+
const elseFirstComp = (ifBlock.elseBody ?? []).find(c => c.kind === "use") as CompUse | undefined;
|
|
799
|
+
if (elseFirstComp) {
|
|
800
|
+
const delayA = elseFirstComp.attrs.find(a => a.name === "delay");
|
|
801
|
+
const hideA = elseFirstComp.attrs.find(a => a.name === "hide");
|
|
802
|
+
if (delayA && hideA && hideA.value && (hideA.value as any).kind === "bool" && !(hideA.value as any).value) {
|
|
803
|
+
if (delayA.value?.kind === "num") {
|
|
804
|
+
elseDelayAttr = ` data-sinth-if-delay="${delayA.value.value}"`;
|
|
805
|
+
} else if (delayA.value?.kind === "str") {
|
|
806
|
+
const v = litToString(delayA.value);
|
|
807
|
+
if (/^\d+$/.test(v)) elseDelayAttr = ` data-sinth-if-delay="${v}"`;
|
|
808
|
+
}
|
|
809
|
+
elseDelayHideAttr = ` data-sinth-if-delay-hide="false"`;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
740
812
|
return (
|
|
741
|
-
`<template data-sinth-if-id="${tplId}" data-sinth-if-expr="${condId}"${replaceAttr}>${bodyHTML}</template>` +
|
|
742
|
-
(elseHTML ? `<template data-sinth-else data-sinth-if-id="${tplId}">${elseHTML}</template>` : "")
|
|
813
|
+
`<template data-sinth-if-id="${tplId}" data-sinth-if-expr="${condId}"${replaceAttr}${delayAttr}${delayHideAttr}>${bodyHTML}</template>` +
|
|
814
|
+
(elseHTML ? `<template data-sinth-else data-sinth-if-id="${tplId}"${elseDelayAttr}${elseDelayHideAttr}>${elseHTML}</template>` : "")
|
|
743
815
|
);
|
|
744
816
|
}
|
|
745
817
|
|
|
@@ -801,7 +873,6 @@ export function renderCompUse(
|
|
|
801
873
|
params: Map<string, string>,
|
|
802
874
|
depth: number,
|
|
803
875
|
): string {
|
|
804
|
-
// transparent wrapper inserted by flattenIfToUses()
|
|
805
876
|
if (use.name === "__IF_ROOT__") {
|
|
806
877
|
return use.children.map(c => renderChild(c, ctx, params, depth)).join("");
|
|
807
878
|
}
|
|
@@ -853,6 +924,12 @@ export function renderCompUse(
|
|
|
853
924
|
continue;
|
|
854
925
|
}
|
|
855
926
|
if (use.name === "Checkbox" && (attr.name === "checked" || attr.name === "onChange" || attr.name === "label")) continue;
|
|
927
|
+
if (attr.name === "hide") {
|
|
928
|
+
if (attr.value && (attr.value as any).kind === "bool" && !(attr.value as any).value) {
|
|
929
|
+
attrParts.push(`data-sinth-delay-hide="false"`);
|
|
930
|
+
}
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
856
933
|
const rendered = renderAttr(attr, params, ctx);
|
|
857
934
|
if (rendered) attrParts.push(rendered);
|
|
858
935
|
}
|
|
@@ -1124,8 +1201,7 @@ function compileFunctionDef(fn: FunctionDef, ctx: CompileCtx): string {
|
|
|
1124
1201
|
const paramsJS = fn.params.map(p => p.name).join(", ");
|
|
1125
1202
|
|
|
1126
1203
|
if (fn.returnType === "ui") {
|
|
1127
|
-
|
|
1128
|
-
return `function ${fn.name}(${paramsJS}) {\n return [${childHTMLs.map(h => JSON.stringify(h)).join(", ")}];\n}`;
|
|
1204
|
+
return "";
|
|
1129
1205
|
}
|
|
1130
1206
|
|
|
1131
1207
|
const bodyStatements: string[] = [];
|
|
@@ -1243,7 +1319,7 @@ function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
|
1243
1319
|
frag.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1244
1320
|
if (${needsDelay}) {
|
|
1245
1321
|
frag.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1246
|
-
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(sinthDelayExpr);
|
|
1322
|
+
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
1247
1323
|
}
|
|
1248
1324
|
var fragFirst = frag.firstChild;
|
|
1249
1325
|
var fragLast = frag.lastChild;
|
|
@@ -1266,19 +1342,30 @@ function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
|
1266
1342
|
if (needsDelay) {
|
|
1267
1343
|
helpers += `
|
|
1268
1344
|
function sinthDelay(el) {
|
|
1269
|
-
if (el.dataset.sinthDelayDone) {
|
|
1345
|
+
if (el.dataset.sinthDelayDone) { return; }
|
|
1270
1346
|
el.dataset.sinthDelayDone = '1';
|
|
1271
1347
|
var ms = parseInt(el.dataset.sinthDelay) || 0;
|
|
1272
|
-
el.
|
|
1273
|
-
|
|
1274
|
-
|
|
1348
|
+
if (el.dataset.sinthDelayHide !== 'false') {
|
|
1349
|
+
el.style.display = 'none';
|
|
1350
|
+
}
|
|
1351
|
+
var show = function() {
|
|
1352
|
+
el.style.display = '';
|
|
1353
|
+
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1354
|
+
};
|
|
1355
|
+
if (ms > 0) setTimeout(show, ms);
|
|
1356
|
+
else show();
|
|
1275
1357
|
}
|
|
1276
|
-
function sinthDelayExpr(el) {
|
|
1358
|
+
function sinthDelayExpr(el, _ctx) {
|
|
1359
|
+
_ctx = _ctx || {};
|
|
1277
1360
|
try {
|
|
1278
1361
|
var fn = __X[el.dataset.sinthDelayExprId];
|
|
1279
|
-
var ms = fn ? parseInt(fn()) || 0 : 0;
|
|
1280
|
-
|
|
1281
|
-
|
|
1362
|
+
var ms = fn ? parseInt(fn(_ctx)) || 0 : 0;
|
|
1363
|
+
var show = function() {
|
|
1364
|
+
el.style.display = '';
|
|
1365
|
+
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1366
|
+
};
|
|
1367
|
+
if (ms > 0) setTimeout(show, ms);
|
|
1368
|
+
else show();
|
|
1282
1369
|
} catch(e) {}
|
|
1283
1370
|
}
|
|
1284
1371
|
`;
|
|
@@ -1292,61 +1379,86 @@ function sinthIfBlock(t) {
|
|
|
1292
1379
|
var condFn = __X[t.dataset.sinthIfExpr];
|
|
1293
1380
|
var cond = condFn ? condFn() : false;
|
|
1294
1381
|
if (cond) {
|
|
1295
|
-
|
|
1382
|
+
var _hasContent = anchor || t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
1383
|
+
if (t.dataset.sinthIfDelayHide === 'false' && t.dataset.sinthIfDelay && _hasContent) {
|
|
1384
|
+
var dms = parseInt(t.dataset.sinthIfDelay) || 0;
|
|
1385
|
+
setTimeout(function() {
|
|
1386
|
+
sinthReplaceInsert(t, anchor, ifId, t.dataset.sinthIfReplace);
|
|
1387
|
+
}, dms);
|
|
1388
|
+
} else {
|
|
1389
|
+
anchor = sinthReplaceInsert(t, anchor, ifId, t.dataset.sinthIfReplace);
|
|
1390
|
+
}
|
|
1296
1391
|
} else {
|
|
1297
|
-
|
|
1298
|
-
if (anchor
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1392
|
+
var runElse = function() {
|
|
1393
|
+
if (anchor) {
|
|
1394
|
+
if (anchor._sinthReplaced) {
|
|
1395
|
+
var insFirst = anchor._sinthInsertedFirst;
|
|
1396
|
+
var insLast = anchor._sinthInsertedLast;
|
|
1397
|
+
var rpParent = anchor._sinthReplacedParent;
|
|
1398
|
+
var rpNext = anchor._sinthReplacedNext;
|
|
1399
|
+
if (insFirst && insLast) {
|
|
1400
|
+
var cur = insFirst;
|
|
1401
|
+
while (cur && cur !== insLast) {
|
|
1402
|
+
var next = cur.nextSibling;
|
|
1403
|
+
cur.remove();
|
|
1404
|
+
cur = next;
|
|
1405
|
+
}
|
|
1406
|
+
if (insLast) insLast.remove();
|
|
1407
|
+
}
|
|
1408
|
+
if (rpParent && rpNext) {
|
|
1409
|
+
rpParent.insertBefore(anchor._sinthReplaced, rpNext);
|
|
1410
|
+
} else if (rpParent) {
|
|
1411
|
+
rpParent.appendChild(anchor._sinthReplaced);
|
|
1412
|
+
}
|
|
1413
|
+
if (anchor._sinthReplaced && anchor._sinthReplaced.dataset.sinthDelay) {
|
|
1414
|
+
delete anchor._sinthReplaced.dataset.sinthDelayDone;
|
|
1415
|
+
sinthDelay(anchor._sinthReplaced);
|
|
1309
1416
|
}
|
|
1310
|
-
|
|
1417
|
+
} else {
|
|
1418
|
+
var cur2 = anchor.nextSibling;
|
|
1419
|
+
while (cur2 && cur2 !== t) { var nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
1311
1420
|
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1421
|
+
anchor.remove();
|
|
1422
|
+
}
|
|
1423
|
+
var elseT = t.nextElementSibling;
|
|
1424
|
+
if (elseT && elseT.hasAttribute('data-sinth-else')) {
|
|
1425
|
+
var elseIfId = elseT.dataset.sinthIfId;
|
|
1426
|
+
var ea = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + elseIfId + '"]');
|
|
1427
|
+
if (ea) {
|
|
1428
|
+
var cur3 = ea.nextSibling;
|
|
1429
|
+
while (cur3 && cur3 !== t) { var nx3 = cur3.nextSibling; cur3.remove(); cur3 = nx3; }
|
|
1430
|
+
} else {
|
|
1431
|
+
ea = document.createElement('span');
|
|
1432
|
+
ea.style.display = 'none';
|
|
1433
|
+
ea.dataset.sinthIfAnchor = '__else__' + elseIfId;
|
|
1434
|
+
t.parentNode.insertBefore(ea, t);
|
|
1435
|
+
}
|
|
1436
|
+
var ef = document.createRange().createContextualFragment(elseT.innerHTML);
|
|
1437
|
+
ef.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1438
|
+
if (${needsDelay}) {
|
|
1439
|
+
ef.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1440
|
+
ef.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
1316
1441
|
}
|
|
1442
|
+
t.parentNode.insertBefore(ef, t);
|
|
1443
|
+
ef.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
|
|
1444
|
+
delete el.dataset.sinthDelayDone;
|
|
1445
|
+
sinthDelay(el);
|
|
1446
|
+
});
|
|
1317
1447
|
} else {
|
|
1318
|
-
var
|
|
1319
|
-
|
|
1448
|
+
var ea2 = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
1449
|
+
if (ea2) {
|
|
1450
|
+
var ec = ea2.nextSibling;
|
|
1451
|
+
while (ec && ec !== t) { var en = ec.nextSibling; ec.remove(); ec = en; }
|
|
1452
|
+
ea2.remove();
|
|
1453
|
+
}
|
|
1320
1454
|
}
|
|
1321
|
-
|
|
1322
|
-
}
|
|
1455
|
+
};
|
|
1323
1456
|
var elseT = t.nextElementSibling;
|
|
1324
|
-
if (elseT && elseT.hasAttribute('data-sinth-else')) {
|
|
1325
|
-
var
|
|
1326
|
-
|
|
1327
|
-
if (ea) {
|
|
1328
|
-
var cur3 = ea.nextSibling;
|
|
1329
|
-
while (cur3 && cur3 !== t) { var nx3 = cur3.nextSibling; cur3.remove(); cur3 = nx3; }
|
|
1330
|
-
} else {
|
|
1331
|
-
ea = document.createElement('span');
|
|
1332
|
-
ea.style.display = 'none';
|
|
1333
|
-
ea.dataset.sinthIfAnchor = '__else__' + elseIfId;
|
|
1334
|
-
t.parentNode.insertBefore(ea, t);
|
|
1335
|
-
}
|
|
1336
|
-
var ef = document.createRange().createContextualFragment(elseT.innerHTML);
|
|
1337
|
-
ef.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1338
|
-
if (${needsDelay}) {
|
|
1339
|
-
ef.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1340
|
-
ef.querySelectorAll('[data-sinth-delay-expr-id]').forEach(sinthDelayExpr);
|
|
1341
|
-
}
|
|
1342
|
-
t.parentNode.insertBefore(ef, t);
|
|
1457
|
+
if (elseT && elseT.hasAttribute('data-sinth-else') && elseT.dataset.sinthIfDelayHide === 'false' && elseT.dataset.sinthIfDelay && anchor) {
|
|
1458
|
+
var edms = parseInt(elseT.dataset.sinthIfDelay) || 0;
|
|
1459
|
+
setTimeout(runElse, edms);
|
|
1343
1460
|
} else {
|
|
1344
|
-
|
|
1345
|
-
if (ea2) {
|
|
1346
|
-
var ec = ea2.nextSibling;
|
|
1347
|
-
while (ec && ec !== t) { var en = ec.nextSibling; ec.remove(); ec = en; }
|
|
1348
|
-
ea2.remove();
|
|
1349
|
-
}
|
|
1461
|
+
runElse();
|
|
1350
1462
|
}
|
|
1351
1463
|
}
|
|
1352
1464
|
}
|
|
@@ -1403,33 +1515,28 @@ function sinthForBlock(t) {
|
|
|
1403
1515
|
var _rp = document.getElementById(t.dataset.sinthIfReplace);
|
|
1404
1516
|
if (_rp) _rp.parentNode.removeChild(_rp);
|
|
1405
1517
|
}
|
|
1518
|
+
var loopCtx = {};
|
|
1519
|
+
if (_item) loopCtx[_item] = _v;
|
|
1520
|
+
if (_key) loopCtx[_key] = _k;
|
|
1521
|
+
if (_idx) loopCtx[_idx] = _loopIdx - 1;
|
|
1406
1522
|
var frag = document.createRange().createContextualFragment(t.innerHTML);
|
|
1407
1523
|
frag.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
1408
1524
|
try {
|
|
1409
1525
|
var exprFn = __X[el.dataset.exprId];
|
|
1410
|
-
if (
|
|
1411
|
-
var _ctx = {};
|
|
1412
|
-
if (_item) _ctx[_item] = _v;
|
|
1413
|
-
if (_key) _ctx[_key] = _k;
|
|
1414
|
-
if (_idx) _ctx[_idx] = _loopIdx - 1;
|
|
1415
|
-
el.textContent = exprFn(_ctx);
|
|
1416
|
-
el.classList.remove('sinth-expr');
|
|
1526
|
+
if (exprFn) el.textContent = exprFn(loopCtx);
|
|
1417
1527
|
} catch(e) {}
|
|
1528
|
+
el.classList.remove('sinth-expr');
|
|
1418
1529
|
});
|
|
1419
1530
|
frag.querySelectorAll('template[data-sinth-if-expr]').forEach(function(ifT) {
|
|
1420
1531
|
var condFn = __X[ifT.dataset.sinthIfExpr];
|
|
1421
|
-
var _ctx = {};
|
|
1422
|
-
if (_item) _ctx[_item] = _v;
|
|
1423
|
-
if (_key) _ctx[_key] = _k;
|
|
1424
|
-
if (_idx) _ctx[_idx] = _loopIdx - 1;
|
|
1425
1532
|
var cond = false;
|
|
1426
|
-
try { if (condFn) cond = condFn(
|
|
1533
|
+
try { if (condFn) cond = condFn(loopCtx); } catch(e) {}
|
|
1427
1534
|
if (cond) {
|
|
1428
1535
|
var ifContent = document.createRange().createContextualFragment(ifT.innerHTML);
|
|
1429
1536
|
ifContent.querySelectorAll('.sinth-expr').forEach(function(el2) {
|
|
1430
1537
|
try {
|
|
1431
1538
|
var exprFn2 = __X[el2.dataset.exprId];
|
|
1432
|
-
if (exprFn2) el2.textContent = exprFn2(
|
|
1539
|
+
if (exprFn2) el2.textContent = exprFn2(loopCtx);
|
|
1433
1540
|
} catch(e) {}
|
|
1434
1541
|
});
|
|
1435
1542
|
ifT.parentNode.insertBefore(ifContent, ifT);
|
|
@@ -1440,7 +1547,7 @@ function sinthForBlock(t) {
|
|
|
1440
1547
|
elseContent.querySelectorAll('.sinth-expr').forEach(function(el2) {
|
|
1441
1548
|
try {
|
|
1442
1549
|
var exprFn2 = __X[el2.dataset.exprId];
|
|
1443
|
-
if (exprFn2) el2.textContent = exprFn2(
|
|
1550
|
+
if (exprFn2) el2.textContent = exprFn2(loopCtx);
|
|
1444
1551
|
} catch(e) {}
|
|
1445
1552
|
});
|
|
1446
1553
|
ifT.parentNode.insertBefore(elseContent, ifT);
|
|
@@ -1449,7 +1556,7 @@ function sinthForBlock(t) {
|
|
|
1449
1556
|
});
|
|
1450
1557
|
if (${needsDelay}) {
|
|
1451
1558
|
frag.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1452
|
-
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(sinthDelayExpr);
|
|
1559
|
+
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, loopCtx); });
|
|
1453
1560
|
}
|
|
1454
1561
|
t.parentNode && t.parentNode.insertBefore(frag, t);
|
|
1455
1562
|
});
|
|
@@ -1488,7 +1595,7 @@ function sinthForBlock(t) {
|
|
|
1488
1595
|
__el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
1489
1596
|
__el.querySelectorAll('template[data-sinth-if-expr]').forEach(sinthIfBlock);
|
|
1490
1597
|
${needsDelay ? `__el.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1491
|
-
__el.querySelectorAll('[data-sinth-delay-expr-id]').forEach(sinthDelayExpr);` : ""}
|
|
1598
|
+
__el.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });` : ""}
|
|
1492
1599
|
}
|
|
1493
1600
|
})();\n`;
|
|
1494
1601
|
}
|
|
@@ -1525,7 +1632,6 @@ function sinthForBlock(t) {
|
|
|
1525
1632
|
if (needsDelay) {
|
|
1526
1633
|
renderBody += ` setTimeout(function() {
|
|
1527
1634
|
document.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
1528
|
-
document.querySelectorAll('[data-sinth-delay-expr-id]').forEach(sinthDelayExpr);
|
|
1529
1635
|
}, 0);\n`;
|
|
1530
1636
|
}
|
|
1531
1637
|
renderBody += ` window.scrollTo(_sx, _sy);\n`;
|