@yannosay/sinth 5.3.1 → 5.3.2
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 +5 -0
- package/dist/browser/sinth.js +39 -43
- package/dist/compiler/codegen.js +9 -8
- package/dist/compiler/prerender.d.ts +1 -0
- package/dist/compiler/prerender.js +12 -5
- package/dist/runtime/index.js +14 -18
- package/package.json +1 -1
package/dist/compiler/codegen.js
CHANGED
|
@@ -154,7 +154,15 @@ class ModuleCompiler {
|
|
|
154
154
|
body.push(this.genComponent(c));
|
|
155
155
|
this.componentInfo[c.name] = { interactive: this.interactive, uses: [...this.uses] };
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
// Page styles are compiled before render() so their reactive values (pageCssVars) get wired up there.
|
|
158
|
+
let moduleBase = base;
|
|
159
|
+
for (const s of file.styles) {
|
|
160
|
+
this.interactive = false;
|
|
161
|
+
this.addStyle(s, undefined, this.moduleScope, file.isPage ? "page" : "module");
|
|
162
|
+
if (this.interactive)
|
|
163
|
+
moduleBase = true;
|
|
164
|
+
}
|
|
165
|
+
this.interactive = this.pageCssVars.length > 0 && file.isPage;
|
|
158
166
|
this.uses = new Set();
|
|
159
167
|
const stateVars = file.vars.filter(v => v.kind === "var");
|
|
160
168
|
if (file.vars.length) {
|
|
@@ -194,13 +202,6 @@ class ModuleCompiler {
|
|
|
194
202
|
this.interactive = true;
|
|
195
203
|
}
|
|
196
204
|
const pageInfo = file.isPage ? { interactive: this.interactive, uses: [...this.uses] } : undefined;
|
|
197
|
-
let moduleBase = base;
|
|
198
|
-
for (const s of file.styles) {
|
|
199
|
-
this.interactive = false;
|
|
200
|
-
this.addStyle(s, undefined, this.moduleScope, file.isPage ? "page" : "module");
|
|
201
|
-
if (this.interactive)
|
|
202
|
-
moduleBase = true;
|
|
203
|
-
}
|
|
204
205
|
if (file.components.some(c => c.customTag))
|
|
205
206
|
moduleBase = true;
|
|
206
207
|
if (this.css.length)
|
|
@@ -53,7 +53,11 @@ class Prerenderer {
|
|
|
53
53
|
}
|
|
54
54
|
renderPage(file, params) {
|
|
55
55
|
const env = this.moduleEnv(file, params);
|
|
56
|
-
|
|
56
|
+
const body = this.renderNodes(file.body, { env: new Env(env), file });
|
|
57
|
+
// Initial values of reactive page styles, so the page looks right before the script takes over.
|
|
58
|
+
const names = new Set(file.vars.map(v => v.name));
|
|
59
|
+
const vars = this.evalStyleVars(file.styles, names, `--sv-${(0, html_1.hashString)(file.path + "page").slice(0, 5)}-`, file, env);
|
|
60
|
+
return vars ? `<style>:root{${escapeStyleText(vars)}}</style>${body}` : body;
|
|
57
61
|
}
|
|
58
62
|
/** Evaluates metadata in the page's module scope. Values that need the browser come back as `undefined` with `known: false`. */
|
|
59
63
|
evalMeta(file, params) {
|
|
@@ -754,11 +758,11 @@ class Prerenderer {
|
|
|
754
758
|
}
|
|
755
759
|
styleVars(decl, file, env) {
|
|
756
760
|
const names = new Set([...decl.params.map(p => p.name), ...decl.vars.map(v => v.name)]);
|
|
761
|
+
return this.evalStyleVars(decl.styles.filter(st => !st.global), names, `--sv-${(0, html_1.hashString)(file.path + decl.name).slice(0, 5)}-`, file, env);
|
|
762
|
+
}
|
|
763
|
+
evalStyleVars(styles, names, varPrefix, file, env) {
|
|
757
764
|
const parts = [];
|
|
758
|
-
for (const s of
|
|
759
|
-
if (s.global)
|
|
760
|
-
continue;
|
|
761
|
-
const varPrefix = `--sv-${(0, html_1.hashString)(file.path + decl.name).slice(0, 5)}-`;
|
|
765
|
+
for (const s of styles) {
|
|
762
766
|
try {
|
|
763
767
|
const res = (0, style_1.compileStyle)(s.raw, s.lang === "scss" ? "css" : s.lang, { reactiveNames: names, varPrefix, loc: s.loc, sinthSyntax: s.lang === "sinth" });
|
|
764
768
|
for (const e of res.expressions) {
|
|
@@ -776,6 +780,9 @@ class Prerenderer {
|
|
|
776
780
|
}
|
|
777
781
|
}
|
|
778
782
|
exports.Prerenderer = Prerenderer;
|
|
783
|
+
function escapeStyleText(css) {
|
|
784
|
+
return css.replace(/<\//gi, "<\\/");
|
|
785
|
+
}
|
|
779
786
|
function defaultValue(v) {
|
|
780
787
|
const t = v.type;
|
|
781
788
|
if (!t || t.nullable)
|
package/dist/runtime/index.js
CHANGED
|
@@ -558,7 +558,7 @@ export function each(parent, list, render, keyOf, filter, empty) {
|
|
|
558
558
|
const [start, end] = makeRange(parent, "for");
|
|
559
559
|
const owner = current;
|
|
560
560
|
let rows = new Map();
|
|
561
|
-
let
|
|
561
|
+
let empty$ = null;
|
|
562
562
|
effect(() => {
|
|
563
563
|
let entries = iterate(list());
|
|
564
564
|
if (filter)
|
|
@@ -622,30 +622,26 @@ export function each(parent, list, render, keyOf, filter, empty) {
|
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
if (empty) {
|
|
625
|
-
if (order.length === 0 && !
|
|
626
|
-
emptyOwner = createOwner(owner);
|
|
625
|
+
if (order.length === 0 && !empty$) {
|
|
626
|
+
const emptyOwner = createOwner(owner);
|
|
627
627
|
const frag = renderInto(emptyOwner, empty);
|
|
628
|
+
const emptyStart = document.createComment("");
|
|
629
|
+
const emptyEnd = document.createComment("");
|
|
630
|
+
frag.insertBefore(emptyStart, frag.firstChild);
|
|
631
|
+
frag.appendChild(emptyEnd);
|
|
628
632
|
end.parentNode?.insertBefore(frag, end);
|
|
633
|
+
empty$ = { owner: emptyOwner, start: emptyStart, end: emptyEnd };
|
|
629
634
|
}
|
|
630
|
-
else if (order.length > 0 &&
|
|
631
|
-
disposeOwner(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
n.parentNode?.removeChild(n);
|
|
637
|
-
n = following;
|
|
638
|
-
}
|
|
635
|
+
else if (order.length > 0 && empty$) {
|
|
636
|
+
disposeOwner(empty$.owner);
|
|
637
|
+
clearRange(empty$.start, empty$.end);
|
|
638
|
+
empty$.start.remove();
|
|
639
|
+
empty$.end.remove();
|
|
640
|
+
empty$ = null;
|
|
639
641
|
}
|
|
640
642
|
}
|
|
641
643
|
});
|
|
642
644
|
}
|
|
643
|
-
function rowsHasStart(rows, node) {
|
|
644
|
-
for (const row of rows.values())
|
|
645
|
-
if (row.start === node)
|
|
646
|
-
return true;
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
645
|
export function html(parent, get) {
|
|
650
646
|
const [start, end] = makeRange(parent, "html");
|
|
651
647
|
let last;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yannosay/sinth",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "A compiled, type-checked language for websites and web apps: reactive components, file-based routing with instant navigation, prerendered pages, API routes and one-command deploys.",
|
|
5
5
|
"author": "Yannosay Productions",
|
|
6
6
|
"license": "AGPL-3.0",
|