@torpor/view 0.4.13 → 0.4.15
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 +16 -0
- package/dist/{Cleanup-BGQ5zaxE.d.cts → Cleanup-CYsytTEc.d.cts} +1 -1
- package/dist/Cleanup-CYsytTEc.d.cts.map +1 -0
- package/dist/{Cleanup-Ca8IspaG.d.ts → Cleanup-CgjyN0lW.d.mts} +1 -1
- package/dist/Cleanup-CgjyN0lW.d.mts.map +1 -0
- package/dist/{Component-BDUCwkBQ.d.cts → Component-DmWGMgak.d.mts} +1 -1
- package/dist/{Component-BDUCwkBQ.d.cts.map → Component-DmWGMgak.d.mts.map} +1 -1
- package/dist/{Component-JVwSemf-.d.ts → Component-kGLRFYg2.d.cts} +1 -1
- package/dist/Component-kGLRFYg2.d.cts.map +1 -0
- package/dist/{Region-BrsZLZUe.d.ts → Region-Bb6HAb-F.d.cts} +2 -2
- package/dist/{Region-Cf7OeBIQ.d.cts.map → Region-Bb6HAb-F.d.cts.map} +1 -1
- package/dist/{Region-Cf7OeBIQ.d.cts → Region-CTchywkr.d.mts} +2 -2
- package/dist/Region-CTchywkr.d.mts.map +1 -0
- package/dist/compile.cjs +238 -68
- package/dist/compile.d.cts +1 -1
- package/dist/{compile.d.ts → compile.d.mts} +2 -2
- package/dist/compile.d.mts.map +1 -0
- package/dist/{compile.js → compile.mjs} +238 -67
- package/dist/compile.mjs.map +1 -0
- package/dist/dev.cjs +1 -2
- package/dist/dev.d.cts +2 -2
- package/dist/{dev.d.ts → dev.d.mts} +3 -3
- package/dist/dev.d.mts.map +1 -0
- package/dist/{dev.js → dev.mjs} +2 -2
- package/dist/{dev.cjs.map → dev.mjs.map} +1 -1
- package/dist/devContext-B3yskfhA.cjs +1 -2
- package/dist/{devContext-CevrTlUO.js → devContext-CQ8RhBX-.mjs} +1 -1
- package/dist/{devContext-B3yskfhA.cjs.map → devContext-CQ8RhBX-.mjs.map} +1 -1
- package/dist/{formatText-Ck04q8_X.cjs → formatText--9zsK5Nq.cjs} +4 -4
- package/dist/{formatText-OyD8MNAM.js → formatText-B8u71S_K.mjs} +4 -3
- package/dist/formatText-B8u71S_K.mjs.map +1 -0
- package/dist/{formatText-BlLF3PPm.d.ts → formatText-BNP3P38F.d.cts} +3 -3
- package/dist/formatText-BNP3P38F.d.cts.map +1 -0
- package/dist/{formatText-Bcb1JvW5.d.cts → formatText-D6Ov8Ub0.d.mts} +3 -3
- package/dist/formatText-D6Ov8Ub0.d.mts.map +1 -0
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +4 -4
- package/dist/{index.d.ts → index.d.mts} +5 -5
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +3 -3
- package/dist/{index.cjs.map → index.mjs.map} +1 -1
- package/dist/ssr.cjs +2 -3
- package/dist/ssr.d.cts +2 -2
- package/dist/{ssr.d.ts → ssr.d.mts} +3 -3
- package/dist/ssr.d.mts.map +1 -0
- package/dist/{ssr.js → ssr.mjs} +2 -2
- package/dist/{ssr.cjs.map → ssr.mjs.map} +1 -1
- package/package.json +17 -17
- package/scripts/copyToRepl.ts +6 -6
- package/src/compile/build/client/addMappedTextWithOffsets.ts +31 -0
- package/src/compile/build/client/buildAddFragment.ts +11 -11
- package/src/compile/build/client/buildComponentNode.ts +126 -29
- package/src/compile/build/client/buildElementNode.ts +65 -8
- package/src/compile/build/client/buildIfNode.ts +1 -1
- package/src/compile/build/client/buildSwitchNode.ts +1 -1
- package/src/compile/build/client/buildTextNode.ts +13 -6
- package/src/compile/build/client/getAttributeOffsets.ts +90 -0
- package/src/compile/build/client/stashRunWithOffsets.ts +7 -1
- package/src/compile/build/server/buildServerElementNode.ts +1 -1
- package/src/compile/parse/parseTag.ts +1 -7
- package/src/compile/parse/parseText.ts +1 -1
- package/src/render/buildClasses.ts +1 -1
- package/src/render/buildStyles.ts +3 -1
- package/src/types/ClassValue.ts +6 -1
- package/src/types/StyleValue.ts +6 -1
- package/test/class/class.test.ts +31 -12
- package/test/class/components/output/Class-client.ts +62 -17
- package/test/class/components/output/Class-server.ts +40 -6
- package/test/class/components/temp/Class-client-c100fef7474dd892108c52b2cfed5825a3412e8b.ts +123 -0
- package/test/class/components/temp/Class-server-f42d0611a27002b493da55392baf7244d31e0d39.ts +78 -0
- package/test/source-maps/interpolated.test.ts +88 -0
- package/test/source-maps/parse.test.ts +1 -1
- package/tsdown.config.ts +2 -9
- package/vitest.config.ts +3 -3
- package/dist/Cleanup-BGQ5zaxE.d.cts.map +0 -1
- package/dist/Cleanup-Ca8IspaG.d.ts.map +0 -1
- package/dist/Component-JVwSemf-.d.ts.map +0 -1
- package/dist/Region-BrsZLZUe.d.ts.map +0 -1
- package/dist/compile.cjs.map +0 -1
- package/dist/compile.d.ts.map +0 -1
- package/dist/compile.js.map +0 -1
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js.map +0 -1
- package/dist/devContext-CevrTlUO.js.map +0 -1
- package/dist/formatText-Bcb1JvW5.d.cts.map +0 -1
- package/dist/formatText-BlLF3PPm.d.ts.map +0 -1
- package/dist/formatText-Ck04q8_X.cjs.map +0 -1
- package/dist/formatText-OyD8MNAM.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ssr.d.ts.map +0 -1
- package/dist/ssr.js.map +0 -1
- package/test/class/components/temp/Class-client-d17977d356d8c8f964eaa1ac5a381814b33c22ba.ts +0 -78
- package/test/class/components/temp/Class-server-e4adcf242d5620acfcfa31c57b9b35c323a15664.ts +0 -44
|
@@ -299,6 +299,28 @@ function nextVarName(name, status) {
|
|
|
299
299
|
return varName;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region src/compile/build/client/addMappedTextWithOffsets.ts
|
|
304
|
+
function addMappedTextWithOffsets(preText, text, postText, spans, offsets, lengths, status, b) {
|
|
305
|
+
if (status.options.mapped === true) {
|
|
306
|
+
let mappedStart = b.toString().length + preText.length;
|
|
307
|
+
let functionBody = preText + text + postText;
|
|
308
|
+
b.append(functionBody);
|
|
309
|
+
for (let i = 0; i < spans.length; i++) {
|
|
310
|
+
let start = mappedStart + offsets[i];
|
|
311
|
+
let end = start + lengths[i];
|
|
312
|
+
status.map.push({
|
|
313
|
+
script: functionBody,
|
|
314
|
+
source: spans[i],
|
|
315
|
+
compiled: {
|
|
316
|
+
start,
|
|
317
|
+
end
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
} else b.append(preText + text + postText);
|
|
322
|
+
}
|
|
323
|
+
|
|
302
324
|
//#endregion
|
|
303
325
|
//#region src/compile/build/client/buildAddFragment.ts
|
|
304
326
|
function buildAddFragment(node, status, b, parentName, anchorName) {
|
|
@@ -309,19 +331,7 @@ function buildAddFragment(node, status, b, parentName, anchorName) {
|
|
|
309
331
|
if (fragment.effects.length > 0) {
|
|
310
332
|
status.imports.add("$run");
|
|
311
333
|
b.append("$run(() => {");
|
|
312
|
-
if (status.options.mapped === true) for (let effect of fragment.effects)
|
|
313
|
-
let start = b.toString().length + effect.offsets[i];
|
|
314
|
-
b.append(effect.functionBody);
|
|
315
|
-
let end = start + effect.lengths[i];
|
|
316
|
-
status.map.push({
|
|
317
|
-
script: effect.functionBody,
|
|
318
|
-
source: effect.spans[i],
|
|
319
|
-
compiled: {
|
|
320
|
-
start,
|
|
321
|
-
end
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
}
|
|
334
|
+
if (status.options.mapped === true) for (let effect of fragment.effects) addMappedTextWithOffsets("", effect.functionBody, "", effect.spans, effect.offsets, effect.lengths, status, b);
|
|
325
335
|
else b.append(fragment.effects.map((e) => e.functionBody).join("\n"));
|
|
326
336
|
b.append(`}${status.options.dev === true ? `, "setAttributes"` : ""});`);
|
|
327
337
|
}
|
|
@@ -704,6 +714,81 @@ function buildRun(functionName, functionBody, status, b) {
|
|
|
704
714
|
addPopDevBoundary(status, b);
|
|
705
715
|
}
|
|
706
716
|
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/compile/utils/endOfString.ts
|
|
719
|
+
function endOfString(char, content, start) {
|
|
720
|
+
for (let j = start + 1; j < content.length; j++) if (content[j] === char && content[j - 1] !== "\\") return j;
|
|
721
|
+
return content.length;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/compile/build/client/getAttributeOffsets.ts
|
|
726
|
+
function getAttributeOffsets(value, span) {
|
|
727
|
+
value = trimQuotes(value);
|
|
728
|
+
let spans = [];
|
|
729
|
+
let offsets = [];
|
|
730
|
+
let lengths = [];
|
|
731
|
+
let textContent = "";
|
|
732
|
+
let reactiveStart = 0;
|
|
733
|
+
let level = 0;
|
|
734
|
+
for (let i = 0; i < value.length; i++) {
|
|
735
|
+
const char = value[i];
|
|
736
|
+
const nextChar = value[i + 1];
|
|
737
|
+
if (char === "{") {
|
|
738
|
+
level++;
|
|
739
|
+
if (level === 1) {
|
|
740
|
+
textContent += "${";
|
|
741
|
+
reactiveStart = textContent.length;
|
|
742
|
+
spans.push({
|
|
743
|
+
start: span.start + i + 2,
|
|
744
|
+
end: -1
|
|
745
|
+
});
|
|
746
|
+
offsets.push(reactiveStart + 1);
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
} else if (char === "}") {
|
|
750
|
+
level--;
|
|
751
|
+
if (level === 0) {
|
|
752
|
+
spans.at(-1).end = span.start + i + 2;
|
|
753
|
+
lengths.push(textContent.length - reactiveStart);
|
|
754
|
+
textContent += "}";
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
} else if (char === "`" && level === 0) textContent += "\\";
|
|
758
|
+
else if (level > 0) {
|
|
759
|
+
if (char === "/" && nextChar === "/") {
|
|
760
|
+
let start = i;
|
|
761
|
+
i = value.indexOf("\n", i);
|
|
762
|
+
textContent += value.substring(start, i + 1);
|
|
763
|
+
continue;
|
|
764
|
+
} else if (char === "/" && nextChar === "*") {
|
|
765
|
+
let start = i;
|
|
766
|
+
i = value.indexOf("*/", i) + 1;
|
|
767
|
+
textContent += value.substring(start, i + 1);
|
|
768
|
+
continue;
|
|
769
|
+
} else if (char === "\"" || char === "'") {
|
|
770
|
+
let start = i;
|
|
771
|
+
i = endOfString(char, value, i);
|
|
772
|
+
textContent += value.substring(start, i + 1);
|
|
773
|
+
continue;
|
|
774
|
+
} else if (char === "`") {
|
|
775
|
+
let start = i;
|
|
776
|
+
i = endOfTemplateString(value, i);
|
|
777
|
+
textContent += value.substring(start, i + 1);
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
textContent += value[i];
|
|
782
|
+
}
|
|
783
|
+
value = `\`${textContent}\``;
|
|
784
|
+
return {
|
|
785
|
+
newValue: value,
|
|
786
|
+
spans,
|
|
787
|
+
offsets,
|
|
788
|
+
lengths
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
707
792
|
//#endregion
|
|
708
793
|
//#region src/compile/build/client/buildComponentNode.ts
|
|
709
794
|
function buildComponentNode(node, status, b, root = false) {
|
|
@@ -716,51 +801,125 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
716
801
|
let props = [];
|
|
717
802
|
let runs = [];
|
|
718
803
|
let bindingRuns = [];
|
|
719
|
-
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (
|
|
804
|
+
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (value != null && fullyReactive) if (name.startsWith("&")) {
|
|
720
805
|
name = name.substring(1);
|
|
721
806
|
props.push({
|
|
722
807
|
name,
|
|
808
|
+
preText: "",
|
|
723
809
|
value,
|
|
724
|
-
|
|
810
|
+
postText: "",
|
|
811
|
+
spans: [span],
|
|
812
|
+
offsets: [],
|
|
813
|
+
lengths: []
|
|
725
814
|
});
|
|
726
815
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
727
816
|
bindingRuns.push(`${value} = ${propsName}["${name}"];`);
|
|
728
|
-
} else if (name === "class"
|
|
817
|
+
} else if (name === "class") {
|
|
729
818
|
status.imports.add("t_class");
|
|
730
819
|
const params = [value];
|
|
731
820
|
if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
|
|
732
|
-
value =
|
|
821
|
+
value = params.join(", ");
|
|
733
822
|
props.push({
|
|
734
823
|
name,
|
|
824
|
+
preText: "t_class(",
|
|
735
825
|
value,
|
|
736
|
-
|
|
826
|
+
postText: ")",
|
|
827
|
+
spans: [span],
|
|
828
|
+
offsets: [],
|
|
829
|
+
lengths: []
|
|
737
830
|
});
|
|
738
|
-
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
739
|
-
} else if (name === "style"
|
|
831
|
+
runs.push(`${propsName}["${name}"] = t_class(${value});`);
|
|
832
|
+
} else if (name === "style") {
|
|
740
833
|
status.imports.add("t_style");
|
|
741
|
-
value = `t_style(${value})`;
|
|
742
834
|
props.push({
|
|
743
835
|
name,
|
|
836
|
+
preText: "t_style(",
|
|
744
837
|
value,
|
|
745
|
-
|
|
838
|
+
postText: ")",
|
|
839
|
+
spans: [span],
|
|
840
|
+
offsets: [],
|
|
841
|
+
lengths: []
|
|
842
|
+
});
|
|
843
|
+
runs.push(`${propsName}["${name}"] = t_style(${value});`);
|
|
844
|
+
} else {
|
|
845
|
+
props.push({
|
|
846
|
+
name,
|
|
847
|
+
preText: "",
|
|
848
|
+
value,
|
|
849
|
+
postText: "",
|
|
850
|
+
spans: [span],
|
|
851
|
+
offsets: [],
|
|
852
|
+
lengths: []
|
|
746
853
|
});
|
|
747
854
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
855
|
+
}
|
|
856
|
+
else if (value != null && reactive) {
|
|
857
|
+
const { newValue, spans, offsets, lengths } = getAttributeOffsets(value, span);
|
|
858
|
+
value = newValue;
|
|
859
|
+
if (name === "class") {
|
|
860
|
+
status.imports.add("t_class");
|
|
861
|
+
const params = [value];
|
|
862
|
+
if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
|
|
863
|
+
value = params.join(", ");
|
|
864
|
+
props.push({
|
|
865
|
+
name,
|
|
866
|
+
preText: "t_class(",
|
|
867
|
+
value,
|
|
868
|
+
postText: ")",
|
|
869
|
+
spans,
|
|
870
|
+
offsets,
|
|
871
|
+
lengths
|
|
872
|
+
});
|
|
873
|
+
runs.push(`${propsName}["${name}"] = t_class(${value});`);
|
|
874
|
+
} else if (name === "style") {
|
|
875
|
+
status.imports.add("t_style");
|
|
876
|
+
props.push({
|
|
877
|
+
name,
|
|
878
|
+
preText: "t_style(",
|
|
879
|
+
value,
|
|
880
|
+
postText: ")",
|
|
881
|
+
spans,
|
|
882
|
+
offsets,
|
|
883
|
+
lengths
|
|
884
|
+
});
|
|
885
|
+
runs.push(`${propsName}["${name}"] = t_style(${value});`);
|
|
886
|
+
} else {
|
|
887
|
+
props.push({
|
|
888
|
+
name,
|
|
889
|
+
preText: "",
|
|
890
|
+
value,
|
|
891
|
+
postText: "",
|
|
892
|
+
spans,
|
|
893
|
+
offsets,
|
|
894
|
+
lengths
|
|
895
|
+
});
|
|
896
|
+
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
897
|
+
}
|
|
748
898
|
} else if (value != null) {
|
|
899
|
+
if (name === "class" && node.scopeStyles) value = `"${trimQuotes(value)} torp-${status.styleHash}"`;
|
|
749
900
|
props.push({
|
|
750
901
|
name,
|
|
902
|
+
preText: "",
|
|
751
903
|
value,
|
|
752
|
-
|
|
904
|
+
postText: "",
|
|
905
|
+
spans: [span],
|
|
906
|
+
offsets: [],
|
|
907
|
+
lengths: []
|
|
753
908
|
});
|
|
754
|
-
if (reactive) runs.push(`${propsName}["${name}"] = ${value};`);
|
|
755
909
|
} else props.push({
|
|
756
910
|
name,
|
|
911
|
+
preText: "",
|
|
757
912
|
value: "true",
|
|
758
|
-
|
|
913
|
+
postText: "",
|
|
914
|
+
spans: [span],
|
|
915
|
+
offsets: [],
|
|
916
|
+
lengths: []
|
|
759
917
|
});
|
|
760
918
|
b.append(`const ${propsName} = $watch({`);
|
|
761
919
|
for (let p of props) {
|
|
762
920
|
let value = replaceForVarNames(p.value, status);
|
|
763
|
-
addMappedText(`${p.name}:
|
|
921
|
+
if (p.spans.length === 1) addMappedText(`${p.name}: ` + p.preText, value, p.postText + ",", p.spans[0], status, b);
|
|
922
|
+
else addMappedTextWithOffsets(`${p.name}: ` + p.preText, value, p.postText + ",", p.spans, p.offsets, p.lengths, status, b);
|
|
764
923
|
}
|
|
765
924
|
b.append("});");
|
|
766
925
|
if (runs.length) buildRun("setProps", replaceForVarNames(runs.join("\n"), status), status, b);
|
|
@@ -1099,7 +1258,7 @@ function buildIfNode(node, status, b) {
|
|
|
1099
1258
|
b.append(`
|
|
1100
1259
|
const ${regionName} = t_region(${status.options.dev === true ? `"if"` : ""});
|
|
1101
1260
|
let ${indexName} = -1;
|
|
1102
|
-
t_run_control(${regionName}, ${anchorName}, (t_before) => {`);
|
|
1261
|
+
t_run_control(${regionName}, ${anchorName}, (${status.inHead ? "" : "t_before"}) => {`);
|
|
1103
1262
|
let index = 0;
|
|
1104
1263
|
for (let branch of branches) buildIfBranch(branch, status, b, parentName, regionName, indexName, index++);
|
|
1105
1264
|
b.append(`}${status.options.dev === true ? `, "runIf"` : ""});`);
|
|
@@ -1208,7 +1367,7 @@ function buildSwitchNode(node, status, b) {
|
|
|
1208
1367
|
b.append(`
|
|
1209
1368
|
const ${regionName} = t_region(${status.options.dev === true ? `"switch"` : ""});
|
|
1210
1369
|
let ${indexName} = -1;
|
|
1211
|
-
t_run_control(${regionName}, ${anchorName}, (t_before) => {`);
|
|
1370
|
+
t_run_control(${regionName}, ${anchorName}, (${status.inHead ? "" : "t_before"}) => {`);
|
|
1212
1371
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1213
1372
|
let index = 0;
|
|
1214
1373
|
for (let branch of branches) buildSwitchBranch(branch, status, b, parentName, regionName, indexName, index++);
|
|
@@ -1330,6 +1489,26 @@ function stashRun(fragment, functionStart, value, functionEnd, span, status) {
|
|
|
1330
1489
|
});
|
|
1331
1490
|
}
|
|
1332
1491
|
|
|
1492
|
+
//#endregion
|
|
1493
|
+
//#region src/compile/build/client/stashRunWithOffsets.ts
|
|
1494
|
+
function stashRunWithOffsets(fragment, functionStart, value, functionEnd, spans, offsets, lengths, status) {
|
|
1495
|
+
let functionBody = functionStart + value + functionEnd;
|
|
1496
|
+
for (let i = 0; i < offsets.length; i++) {
|
|
1497
|
+
offsets[i] += functionStart.length;
|
|
1498
|
+
const oldLength = functionBody.length;
|
|
1499
|
+
functionBody = functionBody.substring(0, offsets[i]) + replaceForVarNames(functionBody.substring(offsets[i], offsets[i] + lengths[i]), status) + functionBody.substring(offsets[i] + lengths[i]);
|
|
1500
|
+
const changedLength = functionBody.length - oldLength;
|
|
1501
|
+
lengths[i] += changedLength;
|
|
1502
|
+
for (let j = i + 1; j < offsets.length; j++) offsets[j] += changedLength;
|
|
1503
|
+
}
|
|
1504
|
+
fragment.effects.push({
|
|
1505
|
+
functionBody,
|
|
1506
|
+
spans,
|
|
1507
|
+
offsets,
|
|
1508
|
+
lengths
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1333
1512
|
//#endregion
|
|
1334
1513
|
//#region src/compile/build/client/buildElementNode.ts
|
|
1335
1514
|
function buildElementNode(node, status, b, parentName, root = false) {
|
|
@@ -1419,26 +1598,46 @@ function buildElementAttributes$1(node, varName, status, b) {
|
|
|
1419
1598
|
let { value, fullyReactive } = refAttribute;
|
|
1420
1599
|
if (value != null && fullyReactive) b.append(`${value} = ${varName};`);
|
|
1421
1600
|
}
|
|
1422
|
-
for (let { name, value, reactive, span
|
|
1601
|
+
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@element") {} else if (name === "&ref") {} else if (value != null && fullyReactive) if (name === "&group") buildBindGroupAttribute(node, varName, value, status, b);
|
|
1423
1602
|
else if (name === "&value" || name === "&checked") buildBindAttribute(node, varName, name, value, status, b);
|
|
1424
1603
|
else if (name === "onmount") buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
|
|
1425
|
-
else if (name.startsWith("on")) buildEventAttribute(varName, name, value,
|
|
1604
|
+
else if (name.startsWith("on")) buildEventAttribute(varName, name, value, span, status, b);
|
|
1426
1605
|
else if (name.startsWith("transition")) buildTransitionAttribute(node, varName, name, value, status, b);
|
|
1427
1606
|
else if (name === "class") {
|
|
1428
1607
|
status.imports.add("t_class");
|
|
1429
1608
|
const params = [value];
|
|
1430
1609
|
if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
|
|
1431
1610
|
const propName = status.ns ? "className.baseVal" : "className";
|
|
1432
|
-
stashRun(fragment, `${status.ns ? "// @ts-ignore\n" : ""}${varName}.${propName} = t_class(`, params.join(", "), ");",
|
|
1611
|
+
stashRun(fragment, `${status.ns ? "// @ts-ignore\n" : ""}${varName}.${propName} = t_class(`, params.join(", "), ");", span, status);
|
|
1433
1612
|
} else if (name === "style") {
|
|
1434
1613
|
status.imports.add("t_style");
|
|
1435
|
-
stashRun(fragment, `${varName}.setAttribute("style", t_style(`, value, "));",
|
|
1614
|
+
stashRun(fragment, `${varName}.setAttribute("style", t_style(`, value, "));", span, status);
|
|
1436
1615
|
} else if (name.includes("-")) {
|
|
1437
1616
|
status.imports.add("t_attribute");
|
|
1438
|
-
stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");",
|
|
1617
|
+
stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");", span, status);
|
|
1439
1618
|
} else {
|
|
1440
1619
|
status.imports.add("t_attribute");
|
|
1441
|
-
stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");",
|
|
1620
|
+
stashRun(fragment, `t_attribute(${varName}, "${name}", `, value, ");", span, status);
|
|
1621
|
+
}
|
|
1622
|
+
else if (value != null && reactive) {
|
|
1623
|
+
const { newValue, spans, offsets, lengths } = getAttributeOffsets(value, span);
|
|
1624
|
+
value = newValue;
|
|
1625
|
+
if (name === "class") {
|
|
1626
|
+
status.imports.add("t_class");
|
|
1627
|
+
const params = [value];
|
|
1628
|
+
if (node.scopeStyles) params.push(`"torp-${status.styleHash}"`);
|
|
1629
|
+
const propName = status.ns ? "className.baseVal" : "className";
|
|
1630
|
+
stashRunWithOffsets(fragment, `${status.ns ? "// @ts-ignore\n" : ""}${varName}.${propName} = t_class(`, params.join(", "), ");", spans, offsets, lengths, status);
|
|
1631
|
+
} else if (name === "style") {
|
|
1632
|
+
status.imports.add("t_style");
|
|
1633
|
+
stashRunWithOffsets(fragment, `${varName}.setAttribute("style", t_style(`, value, "));", spans, offsets, lengths, status);
|
|
1634
|
+
} else if (name.includes("-")) {
|
|
1635
|
+
status.imports.add("t_attribute");
|
|
1636
|
+
stashRunWithOffsets(fragment, `t_attribute(${varName}, "${name}", `, value, ");", spans, offsets, lengths, status);
|
|
1637
|
+
} else {
|
|
1638
|
+
status.imports.add("t_attribute");
|
|
1639
|
+
stashRunWithOffsets(fragment, `t_attribute(${varName}, "${name}", `, value, ");", spans, offsets, lengths, status);
|
|
1640
|
+
}
|
|
1442
1641
|
}
|
|
1443
1642
|
}
|
|
1444
1643
|
function buildBindGroupAttribute(node, varName, value, status, b) {
|
|
@@ -1602,31 +1801,6 @@ function buildSpecialNode(node, status, b, parentName, root = false) {
|
|
|
1602
1801
|
return "";
|
|
1603
1802
|
}
|
|
1604
1803
|
|
|
1605
|
-
//#endregion
|
|
1606
|
-
//#region src/compile/utils/endOfString.ts
|
|
1607
|
-
function endOfString(char, content, start) {
|
|
1608
|
-
for (let j = start + 1; j < content.length; j++) if (content[j] === char && content[j - 1] !== "\\") return j;
|
|
1609
|
-
return content.length;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
//#endregion
|
|
1613
|
-
//#region src/compile/build/client/stashRunWithOffsets.ts
|
|
1614
|
-
function stashRunWithOffsets(fragment, functionBody, spans, offsets, lengths, status) {
|
|
1615
|
-
for (let i = 0; i < offsets.length; i++) {
|
|
1616
|
-
const oldLength = functionBody.length;
|
|
1617
|
-
functionBody = functionBody.substring(0, offsets[i]) + replaceForVarNames(functionBody.substring(offsets[i], offsets[i] + lengths[i]), status) + functionBody.substring(offsets[i] + lengths[i]);
|
|
1618
|
-
const changedLength = functionBody.length - oldLength;
|
|
1619
|
-
lengths[i] += changedLength;
|
|
1620
|
-
for (let j = i + 1; j < offsets.length; j++) offsets[j] += changedLength;
|
|
1621
|
-
}
|
|
1622
|
-
fragment.effects.push({
|
|
1623
|
-
functionBody,
|
|
1624
|
-
spans,
|
|
1625
|
-
offsets,
|
|
1626
|
-
lengths
|
|
1627
|
-
});
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
1804
|
//#endregion
|
|
1631
1805
|
//#region src/compile/build/client/buildTextNode.ts
|
|
1632
1806
|
function buildTextNode(node, status) {
|
|
@@ -1696,11 +1870,8 @@ function buildTextNode(node, status) {
|
|
|
1696
1870
|
offsetChange = 1;
|
|
1697
1871
|
}
|
|
1698
1872
|
status.imports.add("t_fmt");
|
|
1699
|
-
let functionBody = `${node.varName}.textContent = `;
|
|
1700
|
-
offsetChange += functionBody.length;
|
|
1701
1873
|
offsets.map((_, i) => offsets[i] += offsetChange);
|
|
1702
|
-
|
|
1703
|
-
stashRunWithOffsets(fragment, functionBody, node.spans, offsets, lengths, status);
|
|
1874
|
+
stashRunWithOffsets(fragment, `${node.varName}.textContent = `, textContent, ";", node.spans, offsets, lengths, status);
|
|
1704
1875
|
}
|
|
1705
1876
|
}
|
|
1706
1877
|
|
|
@@ -2268,7 +2439,7 @@ function buildElementAttributes(node, status) {
|
|
|
2268
2439
|
}
|
|
2269
2440
|
else if (value != null && reactive) {
|
|
2270
2441
|
status.imports.add("t_attr");
|
|
2271
|
-
attributes.push(`${name}="${trimQuotes(value).replaceAll("
|
|
2442
|
+
attributes.push(`${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`);
|
|
2272
2443
|
} else if (name === "class" && node.scopeStyles) {
|
|
2273
2444
|
value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
2274
2445
|
attributes.push(`${name}="${trimQuotes(value).replaceAll("\"", """)}"`);
|
|
@@ -2718,7 +2889,7 @@ function parseTag(status) {
|
|
|
2718
2889
|
accept("<", status);
|
|
2719
2890
|
let closeTag = accept("/", status);
|
|
2720
2891
|
consumeSpace(status);
|
|
2721
|
-
let tagStart = status.i;
|
|
2892
|
+
let tagStart = status.i + 1;
|
|
2722
2893
|
let snailed = accept("@", status);
|
|
2723
2894
|
let tagName = consumeAlphaNumeric(status);
|
|
2724
2895
|
let tagEnd = status.i;
|
|
@@ -2782,7 +2953,7 @@ function parseAttribute(status) {
|
|
|
2782
2953
|
value = value.substring(1, value.length - 1);
|
|
2783
2954
|
valueStart++;
|
|
2784
2955
|
valueEnd--;
|
|
2785
|
-
}
|
|
2956
|
+
}
|
|
2786
2957
|
} else if (name.startsWith("{") && name.endsWith("}")) {
|
|
2787
2958
|
value = name.substring(1, name.length - 1);
|
|
2788
2959
|
valueStart++;
|
|
@@ -3799,4 +3970,4 @@ function parse(source) {
|
|
|
3799
3970
|
|
|
3800
3971
|
//#endregion
|
|
3801
3972
|
export { build, buildType, parse };
|
|
3802
|
-
//# sourceMappingURL=compile.
|
|
3973
|
+
//# sourceMappingURL=compile.mjs.map
|