@yannosay/sinth 4.1.0 → 5.1.0
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/CHANGELOG.md +83 -0
- package/DOCS.md +1359 -0
- package/README.md +83 -74
- package/bin/sinth.js +2 -1
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.js +74 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +437 -0
- package/dist/cli/templates.d.ts +10 -0
- package/dist/cli/templates.js +193 -0
- package/dist/cli/ui.d.ts +28 -0
- package/dist/cli/ui.js +61 -0
- package/dist/cli/update-check.d.ts +2 -0
- package/dist/cli/update-check.js +124 -0
- package/dist/compiler/ast.d.ts +315 -0
- package/dist/compiler/ast.js +4 -0
- package/dist/compiler/codegen.d.ts +143 -0
- package/dist/compiler/codegen.js +1326 -0
- package/dist/compiler/diagnostics.d.ts +36 -0
- package/dist/compiler/diagnostics.js +142 -0
- package/dist/compiler/elements.d.ts +14 -0
- package/dist/compiler/elements.js +78 -0
- package/dist/compiler/globals.d.ts +2 -0
- package/dist/compiler/globals.js +27 -0
- package/dist/compiler/html.d.ts +37 -0
- package/dist/compiler/html.js +152 -0
- package/dist/compiler/lexer.d.ts +42 -0
- package/dist/compiler/lexer.js +404 -0
- package/dist/compiler/parser.d.ts +95 -0
- package/dist/compiler/parser.js +1374 -0
- package/dist/compiler/prerender.d.ts +72 -0
- package/dist/compiler/prerender.js +910 -0
- package/dist/compiler/script-analysis.d.ts +6 -0
- package/dist/compiler/script-analysis.js +106 -0
- package/dist/compiler/style.d.ts +39 -0
- package/dist/compiler/style.js +463 -0
- package/dist/deploy/cloudflare.d.ts +9 -0
- package/dist/deploy/cloudflare.js +111 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +23 -0
- package/dist/project/build.d.ts +31 -0
- package/dist/project/build.js +425 -0
- package/dist/project/config.d.ts +33 -0
- package/dist/project/config.js +142 -0
- package/dist/project/project.d.ts +74 -0
- package/dist/project/project.js +535 -0
- package/dist/runtime/index.d.ts +68 -0
- package/dist/runtime/index.js +912 -0
- package/dist/server/client.d.ts +1 -0
- package/dist/server/client.js +112 -0
- package/dist/server/dev.d.ts +8 -0
- package/dist/server/dev.js +244 -0
- package/dist/server/preview.d.ts +6 -0
- package/dist/server/preview.js +106 -0
- package/dist/server/static.d.ts +10 -0
- package/dist/server/static.js +136 -0
- package/lib/ui/index.sinth +436 -0
- package/package.json +33 -15
- package/schema/sinth.config.schema.json +54 -0
- package/dist/browser/compile.js +0 -63
- package/dist/cli.js +0 -509
- package/dist/core/builtins.js +0 -117
- package/dist/core/cli-compiler.js +0 -705
- package/dist/core/compiler.js +0 -1489
- package/dist/core/expr.js +0 -129
- package/dist/core/head-builder.js +0 -130
- package/dist/core/lexer.js +0 -410
- package/dist/core/parser.js +0 -1646
- package/dist/core/runtime/custom-element.js +0 -81
- package/dist/core/runtime/functions.js +0 -99
- package/dist/core/runtime/helpers.js +0 -347
- package/dist/core/runtime/render.js +0 -136
- package/dist/core/style-processor.js +0 -317
- package/dist/core/types.js +0 -93
- package/dist/resolver.js +0 -175
- package/dist/server.js +0 -174
- package/dist/update-check.js +0 -109
- package/dist/utils.js +0 -80
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileCustomElement = compileCustomElement;
|
|
4
|
-
const compiler_1 = require("../compiler");
|
|
5
|
-
const utils_1 = require("../../utils");
|
|
6
|
-
function compileCustomElement(cel, opts, hash, ctx) {
|
|
7
|
-
const componentId = `${cel.sinthName}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
8
|
-
const exportTag = cel.exportTag ?? `sinth-el-${componentId.slice(-8)}`;
|
|
9
|
-
const varDecls = cel.varDecls;
|
|
10
|
-
const varLines = varDecls.map(v => {
|
|
11
|
-
if (v.value) {
|
|
12
|
-
const val = (0, utils_1.litToString)(v.value);
|
|
13
|
-
if (v.varType === "int")
|
|
14
|
-
return `this._${v.name} = ${parseFloat(val) || 0};`;
|
|
15
|
-
if (v.varType === "bool")
|
|
16
|
-
return `this._${v.name} = ${val === "true" ? "true" : "false"};`;
|
|
17
|
-
return `this._${v.name} = ${JSON.stringify(val)};`;
|
|
18
|
-
}
|
|
19
|
-
const defaults = { str: '""', int: "0", bool: "false", "str[]": "[]" };
|
|
20
|
-
return `this._${v.name} = ${defaults[v.varType ?? "str"] ?? "undefined"};`;
|
|
21
|
-
}).join("\n ");
|
|
22
|
-
const childCtx = {
|
|
23
|
-
...ctx,
|
|
24
|
-
exprRegistry: [],
|
|
25
|
-
exprMap: new Map(),
|
|
26
|
-
logicBlocks: [],
|
|
27
|
-
mixedBlocks: [],
|
|
28
|
-
customEls: new Map(),
|
|
29
|
-
scopePrefix: 'this._',
|
|
30
|
-
scopeVar: 'this',
|
|
31
|
-
ceActionHandlers: [],
|
|
32
|
-
varDecls: varDecls,
|
|
33
|
-
scopeHash: componentId,
|
|
34
|
-
};
|
|
35
|
-
const customVarMap = new Map();
|
|
36
|
-
for (const v of varDecls) {
|
|
37
|
-
customVarMap.set(v.name, v.name);
|
|
38
|
-
}
|
|
39
|
-
const bodyHTML = cel.body.map(c => (0, compiler_1.renderChild)(c, childCtx, customVarMap, 0)).join("\n");
|
|
40
|
-
const className = `CE_${componentId.replace(/[^a-zA-Z0-9]/g, '_')}`;
|
|
41
|
-
const escapedHTML = bodyHTML.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
42
|
-
return `(function(){
|
|
43
|
-
const tagName='${exportTag}';
|
|
44
|
-
if(customElements.get(tagName))return;
|
|
45
|
-
class ${className} extends HTMLElement{
|
|
46
|
-
constructor(){
|
|
47
|
-
super();
|
|
48
|
-
this.attachShadow({mode:'open'});
|
|
49
|
-
${varLines}
|
|
50
|
-
}
|
|
51
|
-
connectedCallback(){
|
|
52
|
-
this.shadowRoot.innerHTML=\`${escapedHTML}\`;
|
|
53
|
-
const btns=this.shadowRoot.querySelectorAll('button');
|
|
54
|
-
for(let i=0;i<btns.length;i++){
|
|
55
|
-
btns[i].onclick=()=>{
|
|
56
|
-
if(this._count!==undefined){
|
|
57
|
-
this._count++;
|
|
58
|
-
const spans=this.shadowRoot.querySelectorAll('[data-expr-id]');
|
|
59
|
-
for(let j=0;j<spans.length;j++){
|
|
60
|
-
const s=spans[j];
|
|
61
|
-
const id=s.getAttribute('data-expr-id');
|
|
62
|
-
if(id==='0'){
|
|
63
|
-
s.textContent=this._count;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const spans=this.shadowRoot.querySelectorAll('[data-expr-id]');
|
|
70
|
-
for(let i=0;i<spans.length;i++){
|
|
71
|
-
const s=spans[i];
|
|
72
|
-
const id=s.getAttribute('data-expr-id');
|
|
73
|
-
if(id==='0'){
|
|
74
|
-
s.textContent=this._count;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
customElements.define(tagName,${className});
|
|
80
|
-
})();`;
|
|
81
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileFunctionDef = compileFunctionDef;
|
|
4
|
-
const expr_1 = require("../expr");
|
|
5
|
-
function compileFunctionDef(fn, ctx) {
|
|
6
|
-
const paramsJS = fn.params.map(p => p.name).join(", ");
|
|
7
|
-
if (fn.returnType === "ui") {
|
|
8
|
-
return "";
|
|
9
|
-
}
|
|
10
|
-
const bodyStatements = [];
|
|
11
|
-
for (const child of fn.body) {
|
|
12
|
-
switch (child.kind) {
|
|
13
|
-
case "text":
|
|
14
|
-
break;
|
|
15
|
-
case "expr":
|
|
16
|
-
bodyStatements.push(`${(0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars)};`);
|
|
17
|
-
break;
|
|
18
|
-
case "assign_stmt":
|
|
19
|
-
bodyStatements.push(`${(0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars)};`);
|
|
20
|
-
break;
|
|
21
|
-
case "if":
|
|
22
|
-
bodyStatements.push((0, expr_1.compileIfToJS)(child, undefined, ctx.namespace, ctx.declaredVars));
|
|
23
|
-
break;
|
|
24
|
-
case "for": {
|
|
25
|
-
const fl = child;
|
|
26
|
-
const itemVar = fl.itemVar;
|
|
27
|
-
const arrayVar = (ctx.namespace && ctx.declaredVars && ctx.declaredVars.has(fl.arrayVar)) ? ctx.namespace + "_" + fl.arrayVar : fl.arrayVar;
|
|
28
|
-
const bodyJS = fl.body.map((c) => {
|
|
29
|
-
if (c.kind === "assign_stmt")
|
|
30
|
-
return `${(0, expr_1.compileExprToJS)(c.expression, undefined, ctx.namespace, ctx.declaredVars)};`;
|
|
31
|
-
if (c.kind === "if")
|
|
32
|
-
return (0, expr_1.compileIfToJS)(c, undefined, ctx.namespace, ctx.declaredVars);
|
|
33
|
-
if (c.kind === "expr")
|
|
34
|
-
return `${(0, expr_1.compileExprToJS)(c.expression, undefined, ctx.namespace, ctx.declaredVars)};`;
|
|
35
|
-
return "";
|
|
36
|
-
}).filter(Boolean).join("\n");
|
|
37
|
-
const bodyLines = bodyJS.split("\n");
|
|
38
|
-
const indentedBody = bodyLines.map((line) => ` ${line}`).join("\n");
|
|
39
|
-
if (fl.indexVar) {
|
|
40
|
-
const alreadyDeclared = fn.body.some((bc) => bc.kind === "var" && bc.name === fl.indexVar);
|
|
41
|
-
if (!alreadyDeclared) {
|
|
42
|
-
bodyStatements.push(`let ${fl.indexVar} = 0;`);
|
|
43
|
-
}
|
|
44
|
-
bodyStatements.push(`for (let ${itemVar} of ${arrayVar}) {\n${indentedBody}\n ${fl.indexVar} = ${fl.indexVar} + 1;\n }`);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
bodyStatements.push(`for (let ${itemVar} of ${arrayVar}) {\n${indentedBody}\n }`);
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case "var": {
|
|
52
|
-
const vd = child;
|
|
53
|
-
let initJS;
|
|
54
|
-
if (vd.value) {
|
|
55
|
-
const lit = vd.value;
|
|
56
|
-
if (lit.kind === "str") {
|
|
57
|
-
if (lit.value.startsWith("__ARR__")) {
|
|
58
|
-
initJS = lit.value.slice(7);
|
|
59
|
-
}
|
|
60
|
-
else if (lit.value.startsWith("__EXPR__")) {
|
|
61
|
-
try {
|
|
62
|
-
const innerExpr = JSON.parse(lit.value.substring(8));
|
|
63
|
-
initJS = (0, expr_1.compileExprToJS)(innerExpr, undefined, ctx.namespace, ctx.declaredVars);
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
initJS = JSON.stringify(lit.value);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
initJS = JSON.stringify(lit.value);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (lit.kind === "num") {
|
|
74
|
-
initJS = String(lit.value);
|
|
75
|
-
}
|
|
76
|
-
else if (lit.kind === "bool") {
|
|
77
|
-
initJS = String(lit.value);
|
|
78
|
-
}
|
|
79
|
-
else if (lit.kind === "null") {
|
|
80
|
-
initJS = "null";
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
initJS = "null";
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const defaults = { str: '""', int: "0", bool: "false", "str[]": "[]", obj: "{}" };
|
|
88
|
-
initJS = defaults[vd.varType] ?? "undefined";
|
|
89
|
-
}
|
|
90
|
-
bodyStatements.push(`let ${vd.name} = ${initJS};`);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
case "return":
|
|
94
|
-
bodyStatements.push(`return ${child.expression ? (0, expr_1.compileExprToJS)(child.expression, undefined, ctx.namespace, ctx.declaredVars) : ""};`);
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return `function ${fn.name}(${paramsJS}) {\n${bodyStatements.map(s => ` ${s}`).join("\n")}\n}`;
|
|
99
|
-
}
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateHelpers = generateHelpers;
|
|
4
|
-
function generateHelpers(opts) {
|
|
5
|
-
const { needsExpr, needsIf, needsFor, needsDelay, needsMixed, ns } = opts;
|
|
6
|
-
const X = ns ? "__X" + ns : "__X";
|
|
7
|
-
let helpers = "";
|
|
8
|
-
if (needsExpr || needsIf || needsFor) {
|
|
9
|
-
helpers += `
|
|
10
|
-
var sinthExpr = function(el) {
|
|
11
|
-
try {
|
|
12
|
-
let exprFn = ${X}[el.dataset.exprId];
|
|
13
|
-
if (exprFn) el.textContent = exprFn({});
|
|
14
|
-
} catch(e) {}
|
|
15
|
-
};
|
|
16
|
-
`;
|
|
17
|
-
}
|
|
18
|
-
if (needsIf || needsMixed) {
|
|
19
|
-
helpers += `
|
|
20
|
-
function sinthReplaceInsert(t, anchor, ifId, replaceId) {
|
|
21
|
-
if (anchor) {
|
|
22
|
-
let cur = anchor.nextSibling;
|
|
23
|
-
while (cur && cur !== t) { let nx = cur.nextSibling; cur.remove(); cur = nx; }
|
|
24
|
-
} else {
|
|
25
|
-
anchor = document.createElement('span');
|
|
26
|
-
anchor.style.display = 'none';
|
|
27
|
-
anchor.dataset.sinthIfAnchor = ifId;
|
|
28
|
-
t.parentNode.insertBefore(anchor, t);
|
|
29
|
-
}
|
|
30
|
-
let _rp = null, _rpParent = null, _rpNext = null;
|
|
31
|
-
if (replaceId) {
|
|
32
|
-
if (anchor._sinthReplaced) {
|
|
33
|
-
_rp = anchor._sinthReplaced;
|
|
34
|
-
_rpParent = anchor._sinthReplacedParent;
|
|
35
|
-
_rpNext = anchor._sinthReplacedNext;
|
|
36
|
-
if (_rp.parentNode) _rp.parentNode.removeChild(_rp);
|
|
37
|
-
} else {
|
|
38
|
-
_rp = document.getElementById(replaceId);
|
|
39
|
-
if (_rp) {
|
|
40
|
-
_rpParent = _rp.parentNode;
|
|
41
|
-
_rpNext = _rp.nextSibling;
|
|
42
|
-
_rp.parentNode.removeChild(_rp);
|
|
43
|
-
let src = _rp.previousSibling;
|
|
44
|
-
while (src && src !== _rp.parentNode.firstChild) {
|
|
45
|
-
if (src.dataset && src.dataset.sinthIfAnchor) {
|
|
46
|
-
anchor._sinthReplaceSourceIfId = src.dataset.sinthIfAnchor;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
src = src.previousSibling;
|
|
50
|
-
}
|
|
51
|
-
anchor._sinthReplaced = _rp;
|
|
52
|
-
anchor._sinthReplacedParent = _rpParent;
|
|
53
|
-
anchor._sinthReplacedNext = _rpNext;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
let frag = document.createRange().createContextualFragment(t.innerHTML);
|
|
58
|
-
frag.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
59
|
-
if (${needsDelay}) {
|
|
60
|
-
frag.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
61
|
-
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
62
|
-
}
|
|
63
|
-
let fragFirst = frag.firstChild;
|
|
64
|
-
let fragLast = frag.lastChild;
|
|
65
|
-
if (_rpParent && _rpNext) {
|
|
66
|
-
_rpParent.insertBefore(frag, _rpNext);
|
|
67
|
-
} else if (_rpParent) {
|
|
68
|
-
_rpParent.appendChild(frag);
|
|
69
|
-
} else {
|
|
70
|
-
t.parentNode.insertBefore(frag, t);
|
|
71
|
-
}
|
|
72
|
-
if (replaceId && anchor) {
|
|
73
|
-
anchor._sinthInsertedFirst = fragFirst;
|
|
74
|
-
anchor._sinthInsertedLast = fragLast;
|
|
75
|
-
}
|
|
76
|
-
return anchor;
|
|
77
|
-
}
|
|
78
|
-
`;
|
|
79
|
-
}
|
|
80
|
-
if (needsDelay) {
|
|
81
|
-
helpers += `
|
|
82
|
-
function sinthDelay(el) {
|
|
83
|
-
if (el.dataset.sinthDelayDone) { return; }
|
|
84
|
-
el.dataset.sinthDelayDone = '1';
|
|
85
|
-
let ms = parseInt(el.dataset.sinthDelay) || 0;
|
|
86
|
-
let hideEl = el.dataset.sinthDelayHide !== 'false';
|
|
87
|
-
let show = function() {
|
|
88
|
-
if (hideEl) el.style.display = '';
|
|
89
|
-
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
90
|
-
};
|
|
91
|
-
if (hideEl) {
|
|
92
|
-
el.style.display = 'none';
|
|
93
|
-
if (ms > 0) setTimeout(show, ms);
|
|
94
|
-
else show();
|
|
95
|
-
} else {
|
|
96
|
-
if (ms > 0) setTimeout(show, ms);
|
|
97
|
-
else show();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function sinthDelayExpr(el, _ctx) {
|
|
101
|
-
if (el.dataset.sinthDelayDone) return;
|
|
102
|
-
el.dataset.sinthDelayDone = '1';
|
|
103
|
-
_ctx = _ctx || {};
|
|
104
|
-
try {
|
|
105
|
-
let fn = ${X}[el.dataset.sinthDelayExprId];
|
|
106
|
-
let ms = fn ? parseInt(fn(_ctx)) || 0 : 0;
|
|
107
|
-
let hideEl = el.dataset.sinthDelayHide !== 'false';
|
|
108
|
-
let show = function() {
|
|
109
|
-
if (hideEl) el.style.display = '';
|
|
110
|
-
el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
111
|
-
};
|
|
112
|
-
if (hideEl) {
|
|
113
|
-
el.style.display = 'none';
|
|
114
|
-
if (ms > 0) setTimeout(show, ms);
|
|
115
|
-
else show();
|
|
116
|
-
} else {
|
|
117
|
-
if (ms > 0) setTimeout(show, ms);
|
|
118
|
-
else show();
|
|
119
|
-
}
|
|
120
|
-
} catch(e) {}
|
|
121
|
-
}
|
|
122
|
-
`;
|
|
123
|
-
}
|
|
124
|
-
if (needsIf) {
|
|
125
|
-
helpers += `
|
|
126
|
-
function sinthIfBlock(t) {
|
|
127
|
-
let ifId = t.dataset.sinthIfId;
|
|
128
|
-
let replaceId = t.dataset.sinthIfReplace || null;
|
|
129
|
-
let anchorKey = replaceId ? '__replace__' + replaceId : ifId;
|
|
130
|
-
let anchor = t.parentNode.querySelector('[data-sinth-if-anchor="' + anchorKey + '"]');
|
|
131
|
-
let condFn = ${X}[t.dataset.sinthIfExpr];
|
|
132
|
-
let cond = condFn ? condFn() : false;
|
|
133
|
-
if (cond) {
|
|
134
|
-
let elseA = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
135
|
-
if (elseA) {
|
|
136
|
-
let c = elseA.nextSibling;
|
|
137
|
-
while (c && c !== t) { let n = c.nextSibling; c.remove(); c = n; }
|
|
138
|
-
elseA.remove();
|
|
139
|
-
}
|
|
140
|
-
if (t.dataset.sinthIfPersist === "true" && anchor) return;
|
|
141
|
-
if (anchor && anchor._sinthReplaced && !t.dataset.sinthIfDelayHide) return;
|
|
142
|
-
let _hasContent = anchor || t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
143
|
-
if (t.dataset.sinthIfDelayHide === 'false' && t.dataset.sinthIfDelay && _hasContent) {
|
|
144
|
-
let dms = parseInt(t.dataset.sinthIfDelay) || 0;
|
|
145
|
-
setTimeout(function() {
|
|
146
|
-
sinthReplaceInsert(t, anchor, anchorKey, replaceId);
|
|
147
|
-
}, dms);
|
|
148
|
-
} else {
|
|
149
|
-
anchor = sinthReplaceInsert(t, anchor, anchorKey, replaceId);
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
let runElse = function() {
|
|
153
|
-
if (t.dataset.sinthIfPersist === "true") {
|
|
154
|
-
if (anchor) {
|
|
155
|
-
let cur2 = anchor.nextSibling;
|
|
156
|
-
while (cur2 && cur2 !== t) { let nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
157
|
-
anchor.remove();
|
|
158
|
-
}
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (anchor) {
|
|
162
|
-
if (anchor._sinthReplaced) {
|
|
163
|
-
var restored = anchor._sinthReplaced;
|
|
164
|
-
let insFirst = anchor._sinthInsertedFirst;
|
|
165
|
-
let insLast = anchor._sinthInsertedLast;
|
|
166
|
-
let rpParent = anchor._sinthReplacedParent;
|
|
167
|
-
let rpNext = anchor._sinthReplacedNext;
|
|
168
|
-
if (insFirst && insLast) {
|
|
169
|
-
let cur = insFirst;
|
|
170
|
-
while (cur && cur !== insLast) {
|
|
171
|
-
let next = cur.nextSibling;
|
|
172
|
-
cur.remove();
|
|
173
|
-
cur = next;
|
|
174
|
-
}
|
|
175
|
-
if (insLast) insLast.remove();
|
|
176
|
-
}
|
|
177
|
-
if (rpParent && rpNext) {
|
|
178
|
-
rpParent.insertBefore(restored, rpNext);
|
|
179
|
-
} else if (rpParent) {
|
|
180
|
-
rpParent.appendChild(restored);
|
|
181
|
-
}
|
|
182
|
-
if (restored.id) {
|
|
183
|
-
var allDup = t.parentNode.querySelectorAll('[id="' + restored.id + '"]');
|
|
184
|
-
for (var di = 0; di < allDup.length; di++) {
|
|
185
|
-
if (allDup[di] !== restored) allDup[di].remove();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
restored.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
189
|
-
if (restored.dataset.sinthDelay) {
|
|
190
|
-
delete restored.dataset.sinthDelayDone;
|
|
191
|
-
sinthDelay(restored);
|
|
192
|
-
}
|
|
193
|
-
anchor._sinthReplaced = null;
|
|
194
|
-
anchor._sinthReplacedParent = null;
|
|
195
|
-
anchor._sinthReplacedNext = null;
|
|
196
|
-
anchor._sinthInsertedFirst = null;
|
|
197
|
-
anchor._sinthInsertedLast = null;
|
|
198
|
-
anchor._sinthReplaceSourceIfId = null;
|
|
199
|
-
} else {
|
|
200
|
-
let cur2 = anchor.nextSibling;
|
|
201
|
-
while (cur2 && cur2 !== t) { let nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
202
|
-
}
|
|
203
|
-
anchor.remove();
|
|
204
|
-
}
|
|
205
|
-
let elseT = t.nextElementSibling;
|
|
206
|
-
if (elseT && elseT.hasAttribute('data-sinth-else')) {
|
|
207
|
-
let elseIfId = elseT.dataset.sinthIfId;
|
|
208
|
-
let ea = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + elseIfId + '"]');
|
|
209
|
-
if (ea) {
|
|
210
|
-
let cur3 = ea.nextSibling;
|
|
211
|
-
while (cur3 && cur3 !== t) { let nx3 = cur3.nextSibling; cur3.remove(); cur3 = nx3; }
|
|
212
|
-
} else {
|
|
213
|
-
ea = document.createElement('span');
|
|
214
|
-
ea.style.display = 'none';
|
|
215
|
-
ea.dataset.sinthIfAnchor = '__else__' + elseIfId;
|
|
216
|
-
t.parentNode.insertBefore(ea, t);
|
|
217
|
-
}
|
|
218
|
-
let ef = document.createRange().createContextualFragment(elseT.innerHTML);
|
|
219
|
-
ef.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
220
|
-
if (${needsDelay}) {
|
|
221
|
-
ef.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
222
|
-
ef.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
223
|
-
}
|
|
224
|
-
let innerTemplates = ef.querySelectorAll('template[data-sinth-if-expr]');
|
|
225
|
-
t.parentNode.insertBefore(ef, t);
|
|
226
|
-
for (let i = 0; i < innerTemplates.length; i++) sinthIfBlock(innerTemplates[i]);
|
|
227
|
-
ef.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
|
|
228
|
-
delete el.dataset.sinthDelayDone;
|
|
229
|
-
sinthDelay(el);
|
|
230
|
-
});
|
|
231
|
-
} else {
|
|
232
|
-
let ea2 = t.parentNode.querySelector('[data-sinth-if-anchor="__else__' + ifId + '"]');
|
|
233
|
-
if (ea2) {
|
|
234
|
-
let ec = ea2.nextSibling;
|
|
235
|
-
while (ec && ec !== t) { let en = ec.nextSibling; ec.remove(); ec = en; }
|
|
236
|
-
ea2.remove();
|
|
237
|
-
}
|
|
238
|
-
if (anchor) {
|
|
239
|
-
let ac = anchor.nextSibling;
|
|
240
|
-
while (ac && ac !== t) { let an = ac.nextSibling; ac.remove(); ac = an; }
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
let elseT = t.nextElementSibling;
|
|
245
|
-
if (elseT && elseT.hasAttribute('data-sinth-else') && elseT.dataset.sinthIfDelayHide === 'false' && elseT.dataset.sinthIfDelay && anchor) {
|
|
246
|
-
let edms = parseInt(elseT.dataset.sinthIfDelay) || 0;
|
|
247
|
-
setTimeout(runElse, edms);
|
|
248
|
-
} else {
|
|
249
|
-
runElse();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
`;
|
|
254
|
-
}
|
|
255
|
-
if (needsFor) {
|
|
256
|
-
helpers += `
|
|
257
|
-
function hashString(str) {
|
|
258
|
-
let hash = 0, i, chr;
|
|
259
|
-
for (i = 0; i < str.length; i++) {
|
|
260
|
-
chr = str.charCodeAt(i);
|
|
261
|
-
hash = ((hash << 5) - hash) + chr;
|
|
262
|
-
hash |= 0;
|
|
263
|
-
}
|
|
264
|
-
return String(hash);
|
|
265
|
-
}
|
|
266
|
-
function sinthForBlock(t) {
|
|
267
|
-
t.querySelectorAll('template[data-sinth-if-expr]').forEach(function(innerT) {
|
|
268
|
-
innerT.dataset.sinthForHandled = '1';
|
|
269
|
-
});
|
|
270
|
-
let source = _sinthForData[t.dataset.sinthFor];
|
|
271
|
-
if (source === undefined) source = [];
|
|
272
|
-
let newHash = '';
|
|
273
|
-
try { newHash = hashString(JSON.stringify(source)); } catch(e) { newHash = ''; }
|
|
274
|
-
if (t.dataset.sinthForHash && t.dataset.sinthForHash === newHash) return;
|
|
275
|
-
t.dataset.sinthForHash = newHash;
|
|
276
|
-
let isObj = (typeof source === 'object' && source !== null && !Array.isArray(source));
|
|
277
|
-
let entries;
|
|
278
|
-
if (isObj) {
|
|
279
|
-
entries = Object.entries(source);
|
|
280
|
-
} else {
|
|
281
|
-
if (!Array.isArray(source)) source = [];
|
|
282
|
-
entries = source.map(function(item, index) { return [index, item]; });
|
|
283
|
-
}
|
|
284
|
-
let anchorId = t.dataset.sinthForExpr || t.dataset.sinthFor;
|
|
285
|
-
let anchor = null;
|
|
286
|
-
if (t.parentNode) {
|
|
287
|
-
let all = t.parentNode.querySelectorAll('[data-sinth-for-anchor]');
|
|
288
|
-
for (let i = 0; i < all.length; i++) {
|
|
289
|
-
if (all[i].dataset.sinthForAnchor === anchorId) { anchor = all[i]; break; }
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (anchor) {
|
|
293
|
-
let cur2 = anchor.nextSibling;
|
|
294
|
-
while (cur2 && cur2 !== t) { let nx2 = cur2.nextSibling; cur2.remove(); cur2 = nx2; }
|
|
295
|
-
anchor.remove();
|
|
296
|
-
}
|
|
297
|
-
let fa = document.createElement('span');
|
|
298
|
-
fa.style.display = 'none';
|
|
299
|
-
fa.dataset.sinthForAnchor = anchorId;
|
|
300
|
-
t.parentNode && t.parentNode.insertBefore(fa, t);
|
|
301
|
-
let _loopIdx = 0;
|
|
302
|
-
let tplContent = t.innerHTML;
|
|
303
|
-
entries.forEach(function(entry) {
|
|
304
|
-
let _k = entry[0], _v = entry[1];
|
|
305
|
-
let _item = t.dataset.sinthItem || '__item__';
|
|
306
|
-
let _key = t.dataset.sinthKey || null;
|
|
307
|
-
let _idx = t.dataset.sinthIndex || null;
|
|
308
|
-
_loopIdx++;
|
|
309
|
-
let loopCtx = {};
|
|
310
|
-
if (_item) loopCtx[_item] = _v;
|
|
311
|
-
if (_key) loopCtx[_key] = _k;
|
|
312
|
-
if (_idx) loopCtx[_idx] = _loopIdx - 1;
|
|
313
|
-
let frag = document.createRange().createContextualFragment(tplContent);
|
|
314
|
-
frag.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
315
|
-
try { let fn = ${X}[el.dataset.exprId]; if (fn) el.textContent = fn(loopCtx); } catch(e) {}
|
|
316
|
-
el.classList.remove('sinth-expr');
|
|
317
|
-
});
|
|
318
|
-
frag.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) {
|
|
319
|
-
sinthDelayExpr(el, loopCtx);
|
|
320
|
-
});
|
|
321
|
-
frag.querySelectorAll('[onclick*="_ctx."]').forEach(function(el) {
|
|
322
|
-
var onclick = el.getAttribute('onclick');
|
|
323
|
-
for (var key in loopCtx) {
|
|
324
|
-
onclick = onclick.split('_ctx.' + key).join(JSON.stringify(loopCtx[key]));
|
|
325
|
-
}
|
|
326
|
-
el.setAttribute('onclick', onclick);
|
|
327
|
-
});
|
|
328
|
-
frag.querySelectorAll('template[data-sinth-if-expr]').forEach(function(ifT) {
|
|
329
|
-
let condFn = ${X}[ifT.dataset.sinthIfExpr];
|
|
330
|
-
let cond = condFn ? condFn(loopCtx) : false;
|
|
331
|
-
if (cond) {
|
|
332
|
-
let ifFrag = document.createRange().createContextualFragment(ifT.innerHTML);
|
|
333
|
-
ifFrag.querySelectorAll('.sinth-expr').forEach(function(el2) {
|
|
334
|
-
try { let fn2 = ${X}[el2.dataset.exprId]; if (fn2) el2.textContent = fn2(loopCtx); } catch(e) {} el2.classList.remove('sinth-expr');
|
|
335
|
-
});
|
|
336
|
-
ifT.replaceWith(ifFrag);
|
|
337
|
-
} else {
|
|
338
|
-
ifT.remove();
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
t.parentNode && t.parentNode.insertBefore(frag, t);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
`;
|
|
345
|
-
}
|
|
346
|
-
return helpers;
|
|
347
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildRenderBody = buildRenderBody;
|
|
4
|
-
function buildRenderBody(opts) {
|
|
5
|
-
const { bodyHTML, logicBlocks, mixedBlocks, needsLogic, needsMixed, needsIf, needsFor, needsExpr, needsDelay, exprVarUpdates, ns } = opts;
|
|
6
|
-
const X = ns ? "__X" + ns : "__X";
|
|
7
|
-
let renderBody = "";
|
|
8
|
-
renderBody += ` let _sx = window.scrollX, _sy = window.scrollY;\n`;
|
|
9
|
-
if (needsLogic) {
|
|
10
|
-
renderBody += logicBlocks.map(b => b.replace(/^/gm, " ")).join("\n") + "\n";
|
|
11
|
-
}
|
|
12
|
-
if (needsMixed) {
|
|
13
|
-
for (const mb of mixedBlocks) {
|
|
14
|
-
const ifJS = mb.ifJS ? mb.ifJS.trim() : "";
|
|
15
|
-
const elseJS = mb.elseJS ? mb.elseJS.trim() : "";
|
|
16
|
-
renderBody += ` (function() {
|
|
17
|
-
let __el = document.getElementById(${JSON.stringify(mb.replaceId || mb.id)});
|
|
18
|
-
if (__el) {
|
|
19
|
-
let __condFn = ${X}[${mb.conditionJS}];
|
|
20
|
-
if (__condFn ? __condFn() : false) {
|
|
21
|
-
${ifJS}
|
|
22
|
-
__el.innerHTML = ${JSON.stringify(mb.ifHTML)};
|
|
23
|
-
} else {
|
|
24
|
-
${elseJS}
|
|
25
|
-
__el.innerHTML = ${JSON.stringify(mb.elseHTML)};
|
|
26
|
-
}
|
|
27
|
-
__el.querySelectorAll('.sinth-expr').forEach(sinthExpr);
|
|
28
|
-
__el.querySelectorAll('.sinth-expr').forEach(function(el) { el.classList.remove('sinth-expr'); });
|
|
29
|
-
__el.querySelectorAll('template[data-sinth-if-expr]').forEach(sinthIfBlock);
|
|
30
|
-
${needsDelay ? `__el.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
31
|
-
__el.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });` : ""}
|
|
32
|
-
}
|
|
33
|
-
})();\n`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
renderBody += ` document.querySelectorAll('[data-sinth-remove]').forEach(function(el) {
|
|
37
|
-
let target = document.getElementById(el.dataset.sinthRemove);
|
|
38
|
-
if (target) target.remove();
|
|
39
|
-
});\n`;
|
|
40
|
-
if (needsFor) {
|
|
41
|
-
renderBody += ` document.querySelectorAll('template[data-sinth-for], template[data-sinth-for-expr]').forEach(sinthForBlock);\n`;
|
|
42
|
-
}
|
|
43
|
-
if (needsIf) {
|
|
44
|
-
renderBody += ` document.querySelectorAll('template[data-sinth-if-expr]').forEach(function(t) { var p = t.parentElement; while(p && p.tagName !== 'TEMPLATE') p = p.parentElement; if (!p || (!p.hasAttribute('data-sinth-for') && !p.hasAttribute('data-sinth-for-expr'))) sinthIfBlock(t); });\n`;
|
|
45
|
-
}
|
|
46
|
-
renderBody += ` document.querySelectorAll('[data-sinth-value]').forEach(function(el) {
|
|
47
|
-
try { let v=el.dataset.sinthValue; el.value = ${X}[v] ? ${X}[v]({}) : ''; } catch(e) {}
|
|
48
|
-
});\n`;
|
|
49
|
-
renderBody += ` document.querySelectorAll('[data-sinth-step]').forEach(function(el) {
|
|
50
|
-
try { let s=el.dataset.sinthStep; el.step = ${X}[s] ? ${X}[s]({}) : 1; } catch(e) {}
|
|
51
|
-
});\n`;
|
|
52
|
-
renderBody += ` document.querySelectorAll('[data-sinth-checked]').forEach(function(el) {
|
|
53
|
-
try { let c=el.dataset.sinthChecked; el.checked = ${X}[c] ? !!${X}[c]({}) : false; } catch(e) {}
|
|
54
|
-
});\n`;
|
|
55
|
-
if (exprVarUpdates) {
|
|
56
|
-
renderBody += ` ${exprVarUpdates}\n`;
|
|
57
|
-
}
|
|
58
|
-
if (bodyHTML.includes("data-sinth-checked-expr")) {
|
|
59
|
-
renderBody += ` document.querySelectorAll('[data-sinth-checked-expr]').forEach(function(el) {
|
|
60
|
-
try {
|
|
61
|
-
let exprFn = ${X}[el.dataset.sinthCheckedExpr];
|
|
62
|
-
if (exprFn) el.checked = !!exprFn({});
|
|
63
|
-
} catch(e) {}
|
|
64
|
-
});\n`;
|
|
65
|
-
}
|
|
66
|
-
if (needsDelay) {
|
|
67
|
-
renderBody += ` document.querySelectorAll('[data-sinth-delay]').forEach(function(el) {
|
|
68
|
-
let newContent = '';
|
|
69
|
-
el.querySelectorAll('.sinth-expr').forEach(function(exprEl) {
|
|
70
|
-
let exprFn = ${X}[exprEl.dataset.exprId];
|
|
71
|
-
if (exprFn) newContent += exprFn({});
|
|
72
|
-
});
|
|
73
|
-
if (el._sinthLastContent === undefined) {
|
|
74
|
-
el._sinthLastContent = newContent;
|
|
75
|
-
} else if (el._sinthLastContent !== newContent) {
|
|
76
|
-
el._sinthLastContent = newContent;
|
|
77
|
-
delete el.dataset.sinthDelayDone;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
document.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });\n`;
|
|
81
|
-
}
|
|
82
|
-
if (needsExpr) {
|
|
83
|
-
renderBody += ` document.querySelectorAll('.sinth-expr').forEach(function(el) {
|
|
84
|
-
let delayParent = el.closest('[data-sinth-delay]');
|
|
85
|
-
if (!delayParent || delayParent.dataset.sinthDelayDone) {
|
|
86
|
-
sinthExpr(el);
|
|
87
|
-
}
|
|
88
|
-
});\n`;
|
|
89
|
-
}
|
|
90
|
-
renderBody += ` document.querySelectorAll('[data-sinth-style]').forEach(function(el) {
|
|
91
|
-
try {
|
|
92
|
-
let d = el.dataset.sinthStyle.split(';');
|
|
93
|
-
for (let i = 0; i < d.length; i++) {
|
|
94
|
-
let p = d[i].split(':');
|
|
95
|
-
if (p.length === 2) {
|
|
96
|
-
let fn = ${X}[p[1]];
|
|
97
|
-
if (fn) el.style[p[0]] = fn({});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
} catch(e) {}
|
|
101
|
-
});\n`;
|
|
102
|
-
renderBody += ` document.querySelectorAll('[data-sinth-hide]').forEach(function(el) {
|
|
103
|
-
let exprId = el.dataset.sinthHide;
|
|
104
|
-
if (exprId) {
|
|
105
|
-
try {
|
|
106
|
-
let exprFn = ${X}[exprId];
|
|
107
|
-
if (exprFn) el.style.display = exprFn({}) ? 'none' : '';
|
|
108
|
-
} catch(e) {}
|
|
109
|
-
} else {
|
|
110
|
-
el.style.display = 'none';
|
|
111
|
-
}
|
|
112
|
-
});\n`;
|
|
113
|
-
renderBody += ` document.querySelectorAll('[data-sinth-fullscreen]').forEach(function(el) {
|
|
114
|
-
let exprId = el.dataset.sinthFullscreen;
|
|
115
|
-
if (exprId) {
|
|
116
|
-
try {
|
|
117
|
-
let exprFn = ${X}[exprId];
|
|
118
|
-
if (exprFn) {
|
|
119
|
-
if (exprFn({})) {
|
|
120
|
-
if (document.documentElement.requestFullscreen) document.documentElement.requestFullscreen();
|
|
121
|
-
} else {
|
|
122
|
-
if (document.fullscreenElement && document.exitFullscreen) document.exitFullscreen();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
} catch(e) {}
|
|
126
|
-
}
|
|
127
|
-
});\n`;
|
|
128
|
-
if (needsDelay) {
|
|
129
|
-
renderBody += ` setTimeout(function() {
|
|
130
|
-
document.querySelectorAll('[data-sinth-delay]').forEach(sinthDelay);
|
|
131
|
-
document.querySelectorAll('[data-sinth-delay-expr-id]').forEach(function(el) { sinthDelayExpr(el, {}); });
|
|
132
|
-
}, 0);\n`;
|
|
133
|
-
}
|
|
134
|
-
renderBody += ` window.scrollTo(_sx, _sy);\n`;
|
|
135
|
-
return renderBody;
|
|
136
|
-
}
|