@yannosay/sinth 0.14.4 → 0.14.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/package.json +1 -1
- package/src/core/compiler.ts +13 -13
- package/src/core/runtime/helpers.ts +72 -72
- package/src/core/runtime/render.ts +12 -12
package/package.json
CHANGED
package/src/core/compiler.ts
CHANGED
|
@@ -984,20 +984,20 @@ export function buildRuntime(opts: {
|
|
|
984
984
|
);
|
|
985
985
|
}
|
|
986
986
|
const defaults: Record<string, string> = { str: '""', int: "0", bool: "false", "str[]": "[]" };
|
|
987
|
-
return `
|
|
987
|
+
return `let ${v.name} = ${defaults[v.varType] ?? "undefined"};`;
|
|
988
988
|
}
|
|
989
989
|
const val = litToString(v.value);
|
|
990
|
-
if (val.startsWith("__VAR__")) return `
|
|
991
|
-
if (val.startsWith("__ARR__")) return `
|
|
992
|
-
if (v.varType === "obj") return `
|
|
993
|
-
if (v.varType === "str") return `
|
|
990
|
+
if (val.startsWith("__VAR__")) return `let ${v.name} = ${val.slice(7)};`;
|
|
991
|
+
if (val.startsWith("__ARR__")) return `let ${v.name} = ${val.slice(7)};`;
|
|
992
|
+
if (v.varType === "obj") return `let ${v.name} = ${val};`;
|
|
993
|
+
if (v.varType === "str") return `let ${v.name} = ${JSON.stringify(val)};`;
|
|
994
994
|
if (v.varType === "str[]" && typeof val === 'string' && val.startsWith("__ARR__")) {
|
|
995
995
|
try {
|
|
996
996
|
const arr = JSON.parse(val.slice(7));
|
|
997
|
-
return `
|
|
998
|
-
} catch { return `
|
|
997
|
+
return `let ${v.name} = ${JSON.stringify(arr)};`;
|
|
998
|
+
} catch { return `let ${v.name} = ${val.slice(7)};`; }
|
|
999
999
|
}
|
|
1000
|
-
return `
|
|
1000
|
+
return `let ${v.name} = ${val};`;
|
|
1001
1001
|
}).join("\n");
|
|
1002
1002
|
|
|
1003
1003
|
if (!needsRender && !needsDelay) {
|
|
@@ -1013,7 +1013,7 @@ export function buildRuntime(opts: {
|
|
|
1013
1013
|
});
|
|
1014
1014
|
|
|
1015
1015
|
const exprArrayJS = exprRegistry.length > 0
|
|
1016
|
-
? `
|
|
1016
|
+
? `let __X = [${exprRegistry.map((js) => `function(_ctx){ return ${js}; }`).join(",")}];\n`
|
|
1017
1017
|
: "";
|
|
1018
1018
|
|
|
1019
1019
|
let renderFunc = needsRender ? `function sinthRender() {\n${renderBody}}\nsinthRender();` : "";
|
|
@@ -1021,9 +1021,9 @@ export function buildRuntime(opts: {
|
|
|
1021
1021
|
if (needsFullscreenSync) {
|
|
1022
1022
|
renderFunc += `
|
|
1023
1023
|
(function() {
|
|
1024
|
-
|
|
1024
|
+
let syncedEls = document.querySelectorAll('[data-sinth-fullscreen-sync]');
|
|
1025
1025
|
if (syncedEls.length > 0) {
|
|
1026
|
-
|
|
1026
|
+
let vars = [];
|
|
1027
1027
|
syncedEls.forEach(function(el) { vars.push(el.dataset.sinthFullscreenSync); });
|
|
1028
1028
|
document.addEventListener('fullscreenchange', function() {
|
|
1029
1029
|
if (!document.fullscreenElement) {
|
|
@@ -1035,7 +1035,7 @@ export function buildRuntime(opts: {
|
|
|
1035
1035
|
})();`;
|
|
1036
1036
|
}
|
|
1037
1037
|
|
|
1038
|
-
const pageCode = `// Sinth
|
|
1038
|
+
const pageCode = `// Sinth Page Runtime
|
|
1039
1039
|
${varLines}
|
|
1040
1040
|
${exprArrayJS}
|
|
1041
1041
|
${renderFunc}`;
|
|
@@ -1227,7 +1227,7 @@ export function compileFile(filePath: string, opts: CompileOptions): { html: str
|
|
|
1227
1227
|
const extra = Object.entries(s.attrs)
|
|
1228
1228
|
.map(([k, v]) => v === "true" ? k : `${k}="${escAttr(v)}"`)
|
|
1229
1229
|
.join(" ");
|
|
1230
|
-
const globalised = s.raw.replace(/\b(let|const)\b/g, "
|
|
1230
|
+
const globalised = s.raw.replace(/\b(let|const)\b/g, "let");
|
|
1231
1231
|
scriptTags.push(`<script${extra ? " " + extra : ""}>\n${globalised}\n</script>`);
|
|
1232
1232
|
}
|
|
1233
1233
|
|
|
@@ -12,7 +12,7 @@ export function generateHelpers(opts: {
|
|
|
12
12
|
helpers += `
|
|
13
13
|
function sinthExpr(el) {
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
let exprFn = __X[el.dataset.exprId];
|
|
16
16
|
if (exprFn) el.textContent = exprFn({});
|
|
17
17
|
} catch(e) {}
|
|
18
18
|
}
|
|
@@ -23,15 +23,15 @@ function sinthExpr(el) {
|
|
|
23
23
|
helpers += `
|
|
24
24
|
function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
25
25
|
if (anchor) {
|
|
26
|
-
|
|
27
|
-
while (cur && cur !== t) {
|
|
26
|
+
let cur = anchor.nextSibling;
|
|
27
|
+
while (cur && cur !== t) { let nx = cur.nextSibling; cur.remove(); cur = nx; }
|
|
28
28
|
} else {
|
|
29
29
|
anchor = document.createElement('span');
|
|
30
30
|
anchor.style.display = 'none';
|
|
31
31
|
anchor.dataset.sinthIfAnchor = ifId;
|
|
32
32
|
t.parentNode.insertBefore(anchor, t);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
let _rp = null, _rpParent = null, _rpNext = null;
|
|
35
35
|
if (replaceId) {
|
|
36
36
|
_rp = document.getElementById(replaceId);
|
|
37
37
|
if (_rp) {
|
|
@@ -43,14 +43,14 @@ function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
|
43
43
|
anchor._sinthReplacedNext = _rpNext;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
let frag = document.createRange().createContextualFragment(t.innerHTML);
|
|
47
47
|
frag.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
48
48
|
if (${needsDelay}) {
|
|
49
49
|
frag.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
50
50
|
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let fragFirst = frag.firstChild;
|
|
53
|
+
let fragLast = frag.lastChild;
|
|
54
54
|
if (_rpParent && _rpNext) {
|
|
55
55
|
_rpParent.insertBefore(frag, _rpNext);
|
|
56
56
|
} else if (_rpParent) {
|
|
@@ -72,9 +72,9 @@ function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
|
72
72
|
function sinthDelay(el) {
|
|
73
73
|
if (el.dataset.sinthDelayDone) { return; }
|
|
74
74
|
el.dataset.sinthDelayDone = '1';
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
let ms = parseInt(el.dataset.sinthDelay) || 0;
|
|
76
|
+
let hideEl = el.dataset.sinthDelayHide !== 'false';
|
|
77
|
+
let show = function() {
|
|
78
78
|
if (hideEl) el.style.display = '';
|
|
79
79
|
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
80
80
|
};
|
|
@@ -90,9 +90,9 @@ function sinthDelay(el) {
|
|
|
90
90
|
function sinthDelayExpr(el, _ctx) {
|
|
91
91
|
_ctx = _ctx || {};
|
|
92
92
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
let fn = __X[el.dataset.sinthDelayExprId];
|
|
94
|
+
let ms = fn ? parseInt(fn(_ctx)) || 0 : 0;
|
|
95
|
+
let show = function() {
|
|
96
96
|
el.style.display = '';
|
|
97
97
|
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
98
98
|
};
|
|
@@ -106,21 +106,21 @@ function sinthDelayExpr(el, _ctx) {
|
|
|
106
106
|
if (needsIf) {
|
|
107
107
|
helpers += `
|
|
108
108
|
function sinthIfBlock(t) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
let ifId = t.dataset.sinthIfId;
|
|
110
|
+
let anchor = t.parentNode.querySelector('[data-sinth-if-anchor="' + ifId + '"]');
|
|
111
|
+
let condFn = __X[t.dataset.sinthIfExpr];
|
|
112
|
+
let cond = condFn ? condFn() : false;
|
|
113
113
|
if (cond) {
|
|
114
|
-
|
|
114
|
+
let elseA = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
115
115
|
if (elseA) {
|
|
116
|
-
|
|
117
|
-
while (c && c !== t) {
|
|
116
|
+
let c = elseA.nextSibling;
|
|
117
|
+
while (c && c !== t) { let n = c.nextSibling; c.remove(); c = n; }
|
|
118
118
|
elseA.remove();
|
|
119
119
|
}
|
|
120
120
|
if (t.dataset.sinthIfPersist === "true" && anchor) return;
|
|
121
|
-
|
|
121
|
+
let _hasContent = anchor || t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
122
122
|
if (t.dataset.sinthIfDelayHide === 'false' && t.dataset.sinthIfDelay && _hasContent) {
|
|
123
|
-
|
|
123
|
+
let dms = parseInt(t.dataset.sinthIfDelay) || 0;
|
|
124
124
|
setTimeout(function() {
|
|
125
125
|
sinthReplaceInsert(t, anchor, ifId, t.dataset.sinthIfReplace);
|
|
126
126
|
}, dms);
|
|
@@ -128,18 +128,18 @@ function sinthIfBlock(t) {
|
|
|
128
128
|
anchor = sinthReplaceInsert(t, anchor, ifId, t.dataset.sinthIfReplace);
|
|
129
129
|
}
|
|
130
130
|
} else {
|
|
131
|
-
|
|
131
|
+
let runElse = function() {
|
|
132
132
|
if (t.dataset.sinthIfPersist === "true") return;
|
|
133
133
|
if (anchor) {
|
|
134
134
|
if (anchor._sinthReplaced) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
let insFirst = anchor._sinthInsertedFirst;
|
|
136
|
+
let insLast = anchor._sinthInsertedLast;
|
|
137
|
+
let rpParent = anchor._sinthReplacedParent;
|
|
138
|
+
let rpNext = anchor._sinthReplacedNext;
|
|
139
139
|
if (insFirst && insLast) {
|
|
140
|
-
|
|
140
|
+
let cur = insFirst;
|
|
141
141
|
while (cur && cur !== insLast) {
|
|
142
|
-
|
|
142
|
+
let next = cur.nextSibling;
|
|
143
143
|
cur.remove();
|
|
144
144
|
cur = next;
|
|
145
145
|
}
|
|
@@ -155,53 +155,53 @@ function sinthIfBlock(t) {
|
|
|
155
155
|
sinthDelay(anchor._sinthReplaced);
|
|
156
156
|
}
|
|
157
157
|
} else {
|
|
158
|
-
|
|
159
|
-
while (cur2 && cur2 !== t) {
|
|
158
|
+
let cur2 = anchor.nextSibling;
|
|
159
|
+
while (cur2 && cur2 !== t) { let nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
160
160
|
}
|
|
161
161
|
anchor.remove();
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
let elseT = t.nextElementSibling;
|
|
164
164
|
if (elseT && elseT.hasAttribute('data-sinth-else')) {
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
let elseIfId = elseT.dataset.sinthIfId;
|
|
166
|
+
let ea = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + elseIfId + '"]');
|
|
167
167
|
if (ea) {
|
|
168
|
-
|
|
169
|
-
while (cur3 && cur3 !== t) {
|
|
168
|
+
let cur3 = ea.nextSibling;
|
|
169
|
+
while (cur3 && cur3 !== t) { let nx3 = cur3.nextSibling; cur3.remove(); cur3 = nx3; }
|
|
170
170
|
} else {
|
|
171
171
|
ea = document.createElement('span');
|
|
172
172
|
ea.style.display = 'none';
|
|
173
173
|
ea.dataset.sinthIfAnchor = '__else__' + elseIfId;
|
|
174
174
|
t.parentNode.insertBefore(ea, t);
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
let ef = document.createRange().createContextualFragment(elseT.innerHTML);
|
|
177
177
|
ef.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
178
178
|
if (${needsDelay}) {
|
|
179
179
|
ef.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
180
180
|
ef.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
let innerTemplates = ef.querySelectorAll('template[data-sinth-if-expr]');
|
|
183
183
|
t.parentNode.insertBefore(ef, t);
|
|
184
|
-
for (
|
|
184
|
+
for (let i = 0; i < innerTemplates.length; i++) sinthIfBlock(innerTemplates[i]);
|
|
185
185
|
ef.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
|
|
186
186
|
delete el.dataset.sinthDelayDone;
|
|
187
187
|
sinthDelay(el);
|
|
188
188
|
});
|
|
189
189
|
} else {
|
|
190
|
-
|
|
190
|
+
let ea2 = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
191
191
|
if (ea2) {
|
|
192
|
-
|
|
193
|
-
while (ec && ec !== t) {
|
|
192
|
+
let ec = ea2.nextSibling;
|
|
193
|
+
while (ec && ec !== t) { let en = ec.nextSibling; ec.remove(); ec = en; }
|
|
194
194
|
ea2.remove();
|
|
195
195
|
}
|
|
196
196
|
if (anchor) {
|
|
197
|
-
|
|
198
|
-
while (ac && ac !== t) {
|
|
197
|
+
let ac = anchor.nextSibling;
|
|
198
|
+
while (ac && ac !== t) { let an = ac.nextSibling; ac.remove(); ac = an; }
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
};
|
|
202
|
-
|
|
202
|
+
let elseT = t.nextElementSibling;
|
|
203
203
|
if (elseT && elseT.hasAttribute('data-sinth-else') && elseT.dataset.sinthIfDelayHide === 'false' && elseT.dataset.sinthIfDelay && anchor) {
|
|
204
|
-
|
|
204
|
+
let edms = parseInt(elseT.dataset.sinthIfDelay) || 0;
|
|
205
205
|
setTimeout(runElse, edms);
|
|
206
206
|
} else {
|
|
207
207
|
runElse();
|
|
@@ -214,7 +214,7 @@ function sinthIfBlock(t) {
|
|
|
214
214
|
if (needsFor) {
|
|
215
215
|
helpers += `
|
|
216
216
|
function hashString(str) {
|
|
217
|
-
|
|
217
|
+
let hash = 0, i, chr;
|
|
218
218
|
for (i = 0; i < str.length; i++) {
|
|
219
219
|
chr = str.charCodeAt(i);
|
|
220
220
|
hash = ((hash << 5) - hash) + chr;
|
|
@@ -223,76 +223,76 @@ function hashString(str) {
|
|
|
223
223
|
return String(hash);
|
|
224
224
|
}
|
|
225
225
|
function sinthForBlock(t) {
|
|
226
|
-
|
|
226
|
+
let source = window[t.dataset.sinthFor];
|
|
227
227
|
if (source === undefined) source = [];
|
|
228
|
-
|
|
228
|
+
let newHash = '';
|
|
229
229
|
try { newHash = hashString(JSON.stringify(source)); } catch(e) { newHash = ''; }
|
|
230
230
|
if (t.dataset.sinthForHash && t.dataset.sinthForHash === newHash) {
|
|
231
231
|
return;
|
|
232
232
|
}
|
|
233
233
|
t.dataset.sinthForHash = newHash;
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
let isObj = (typeof source === 'object' && source !== null && !Array.isArray(source));
|
|
235
|
+
let entries;
|
|
236
236
|
if (isObj) {
|
|
237
237
|
entries = Object.entries(source);
|
|
238
238
|
} else {
|
|
239
239
|
if (!Array.isArray(source)) source = [];
|
|
240
240
|
entries = source.map(function(item, index) { return [index, item]; });
|
|
241
241
|
}
|
|
242
|
-
|
|
242
|
+
let anchor = t.parentNode ? t.parentNode.querySelector('[data-sinth-for-anchor="' + t.dataset.sinthFor + '"]') : null;
|
|
243
243
|
if (anchor) {
|
|
244
|
-
|
|
245
|
-
while (cur2 && cur2 !== t) {
|
|
244
|
+
let cur2 = anchor.nextSibling;
|
|
245
|
+
while (cur2 && cur2 !== t) { let nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
246
246
|
anchor.remove();
|
|
247
247
|
}
|
|
248
|
-
|
|
248
|
+
let fa = document.createElement('span');
|
|
249
249
|
fa.style.display = 'none';
|
|
250
250
|
fa.dataset.sinthForAnchor = t.dataset.sinthFor;
|
|
251
251
|
t.parentNode && t.parentNode.insertBefore(fa, t);
|
|
252
|
-
|
|
252
|
+
let _loopIdx = 0;
|
|
253
253
|
entries.forEach(function(entry) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
254
|
+
let _k = entry[0];
|
|
255
|
+
let _v = entry[1];
|
|
256
|
+
let _item = (t.dataset && t.dataset.sinthItem) ? t.dataset.sinthItem : '__item__';
|
|
257
|
+
let _key = t.dataset && t.dataset.sinthKey ? t.dataset.sinthKey : null;
|
|
258
|
+
let _idx = t.dataset && t.dataset.sinthIndex ? t.dataset.sinthIndex : null;
|
|
259
259
|
_loopIdx++;
|
|
260
260
|
if (t.dataset.sinthIfReplace) {
|
|
261
|
-
|
|
261
|
+
let _rp = document.getElementById(t.dataset.sinthIfReplace);
|
|
262
262
|
if (_rp) _rp.parentNode.removeChild(_rp);
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
let loopCtx = {};
|
|
265
265
|
if (_item) loopCtx[_item] = _v;
|
|
266
266
|
if (_key) loopCtx[_key] = _k;
|
|
267
267
|
if (_idx) loopCtx[_idx] = _loopIdx - 1;
|
|
268
|
-
|
|
268
|
+
let frag = document.createRange().createContextualFragment(t.innerHTML);
|
|
269
269
|
frag.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
270
270
|
try {
|
|
271
|
-
|
|
271
|
+
let exprFn = __X[el.dataset.exprId];
|
|
272
272
|
if (exprFn) el.textContent = exprFn(loopCtx);
|
|
273
273
|
} catch(e) {}
|
|
274
274
|
el.classList.remove('sinth-expr');
|
|
275
275
|
});
|
|
276
276
|
frag.querySelectorAll('template[data-sinth-if-expr]').forEach(function(ifT) {
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
let condFn = __X[ifT.dataset.sinthIfExpr];
|
|
278
|
+
let cond = false;
|
|
279
279
|
try { if (condFn) cond = condFn(loopCtx); } catch(e) {}
|
|
280
280
|
if (cond) {
|
|
281
|
-
|
|
281
|
+
let ifContent = document.createRange().createContextualFragment(ifT.innerHTML);
|
|
282
282
|
ifContent.querySelectorAll('.sinth-expr').forEach(function(el2) {
|
|
283
283
|
try {
|
|
284
|
-
|
|
284
|
+
let exprFn2 = __X[el2.dataset.exprId];
|
|
285
285
|
if (exprFn2) el2.textContent = exprFn2(loopCtx);
|
|
286
286
|
} catch(e) {}
|
|
287
287
|
});
|
|
288
288
|
ifT.parentNode.insertBefore(ifContent, ifT);
|
|
289
289
|
} else {
|
|
290
|
-
|
|
290
|
+
let elseT = ifT.nextElementSibling;
|
|
291
291
|
if (elseT && elseT.hasAttribute('data-sinth-else')) {
|
|
292
|
-
|
|
292
|
+
let elseContent = document.createRange().createContextualFragment(elseT.innerHTML);
|
|
293
293
|
elseContent.querySelectorAll('.sinth-expr').forEach(function(el2) {
|
|
294
294
|
try {
|
|
295
|
-
|
|
295
|
+
let exprFn2 = __X[el2.dataset.exprId];
|
|
296
296
|
if (exprFn2) el2.textContent = exprFn2(loopCtx);
|
|
297
297
|
} catch(e) {}
|
|
298
298
|
});
|
|
@@ -13,7 +13,7 @@ export function buildRenderBody(opts: {
|
|
|
13
13
|
}): string {
|
|
14
14
|
const { bodyHTML, logicBlocks, mixedBlocks, needsLogic, needsMixed, needsIf, needsFor, needsExpr, needsDelay } = opts;
|
|
15
15
|
let renderBody = "";
|
|
16
|
-
renderBody += `
|
|
16
|
+
renderBody += ` let _sx = window.scrollX, _sy = window.scrollY;\n`;
|
|
17
17
|
|
|
18
18
|
if (needsLogic) {
|
|
19
19
|
renderBody += logicBlocks.map(b => b.replace(/^/gm, " ")).join("\n") + "\n";
|
|
@@ -24,9 +24,9 @@ export function buildRenderBody(opts: {
|
|
|
24
24
|
const ifJS = mb.ifJS ? mb.ifJS.trim() : "";
|
|
25
25
|
const elseJS = mb.elseJS ? mb.elseJS.trim() : "";
|
|
26
26
|
renderBody += ` (function() {
|
|
27
|
-
|
|
27
|
+
let __el = document.getElementById(${JSON.stringify(mb.replaceId || mb.id)});
|
|
28
28
|
if (__el) {
|
|
29
|
-
|
|
29
|
+
let __condFn = __X[${mb.conditionJS}];
|
|
30
30
|
if (__condFn ? __condFn() : false) {
|
|
31
31
|
${ifJS}
|
|
32
32
|
__el.innerHTML = ${JSON.stringify(mb.ifHTML)};
|
|
@@ -47,7 +47,7 @@ export function buildRenderBody(opts: {
|
|
|
47
47
|
renderBody += ` document.querySelectorAll('template[data-sinth-if-expr]').forEach(sinthIfBlock);\n`;
|
|
48
48
|
}
|
|
49
49
|
renderBody += ` document.querySelectorAll('[data-sinth-remove]').forEach(function(el) {
|
|
50
|
-
|
|
50
|
+
let target = document.getElementById(el.dataset.sinthRemove);
|
|
51
51
|
if (target) target.remove();
|
|
52
52
|
});\n`;
|
|
53
53
|
if (needsFor) {
|
|
@@ -65,16 +65,16 @@ export function buildRenderBody(opts: {
|
|
|
65
65
|
if (bodyHTML.includes("data-sinth-checked-expr")) {
|
|
66
66
|
renderBody += ` document.querySelectorAll('[data-sinth-checked-expr]').forEach(function(el) {
|
|
67
67
|
try {
|
|
68
|
-
|
|
68
|
+
let exprFn = __X[el.dataset.sinthCheckedExpr];
|
|
69
69
|
if (exprFn) el.checked = !!exprFn({});
|
|
70
70
|
} catch(e) {}
|
|
71
71
|
});\n`;
|
|
72
72
|
}
|
|
73
73
|
if (needsDelay) {
|
|
74
74
|
renderBody += ` document.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
|
|
75
|
-
|
|
75
|
+
let newContent = '';
|
|
76
76
|
el.querySelectorAll('.sinth-expr').forEach(function(exprEl) {
|
|
77
|
-
|
|
77
|
+
let exprFn = __X[exprEl.dataset.exprId];
|
|
78
78
|
if (exprFn) newContent += exprFn({});
|
|
79
79
|
});
|
|
80
80
|
if (el._sinthLastContent === undefined) {
|
|
@@ -87,17 +87,17 @@ export function buildRenderBody(opts: {
|
|
|
87
87
|
}
|
|
88
88
|
if (needsExpr) {
|
|
89
89
|
renderBody += ` document.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
90
|
-
|
|
90
|
+
let delayParent = el.closest('[data-sinth-delay]');
|
|
91
91
|
if (!delayParent || delayParent.dataset.sinthDelayDone) {
|
|
92
92
|
sinthExpr(el);
|
|
93
93
|
}
|
|
94
94
|
});\n`;
|
|
95
95
|
}
|
|
96
96
|
renderBody += ` document.querySelectorAll('[data-sinth-hide]').forEach(function(el) {
|
|
97
|
-
|
|
97
|
+
let exprId = el.dataset.sinthHide;
|
|
98
98
|
if (exprId) {
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
let exprFn = __X[exprId];
|
|
101
101
|
if (exprFn) el.style.display = exprFn({}) ? 'none' : '';
|
|
102
102
|
} catch(e) {}
|
|
103
103
|
} else {
|
|
@@ -105,10 +105,10 @@ export function buildRenderBody(opts: {
|
|
|
105
105
|
}
|
|
106
106
|
});\n`;
|
|
107
107
|
renderBody += ` document.querySelectorAll('[data-sinth-fullscreen]').forEach(function(el) {
|
|
108
|
-
|
|
108
|
+
let exprId = el.dataset.sinthFullscreen;
|
|
109
109
|
if (exprId) {
|
|
110
110
|
try {
|
|
111
|
-
|
|
111
|
+
let exprFn = __X[exprId];
|
|
112
112
|
if (exprFn) {
|
|
113
113
|
if (exprFn({})) {
|
|
114
114
|
if (document.documentElement.requestFullscreen) document.documentElement.requestFullscreen();
|