@wsxjs/wsx-core 0.0.26 → 0.0.28
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/dist/chunk-34PNC5CJ.mjs +1307 -0
- package/dist/chunk-DYG2LIOG.mjs +1315 -0
- package/dist/chunk-HWJ7GZD6.mjs +1327 -0
- package/dist/chunk-VCL7OXC6.mjs +1282 -0
- package/dist/chunk-WDQYPG2N.mjs +1315 -0
- package/dist/chunk-ZY36MEHX.mjs +1306 -0
- package/dist/index.js +185 -135
- package/dist/index.mjs +3 -3
- package/dist/jsx-runtime.js +183 -133
- package/dist/jsx-runtime.mjs +1 -1
- package/dist/jsx.js +183 -133
- package/dist/jsx.mjs +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/jsx-factory.ts +3 -1
- package/src/utils/dom-utils.ts +19 -0
- package/src/utils/element-creation.ts +35 -2
- package/src/utils/element-marking.ts +4 -2
- package/src/utils/element-update.ts +131 -107
- package/src/utils/update-children-helpers.ts +95 -55
- package/src/web-component.ts +6 -5
package/dist/index.js
CHANGED
|
@@ -97,6 +97,17 @@ function flattenChildren(children, skipHTMLDetection = false, depth = 0) {
|
|
|
97
97
|
} else {
|
|
98
98
|
result.push(child);
|
|
99
99
|
}
|
|
100
|
+
} else if (child instanceof DocumentFragment) {
|
|
101
|
+
const fragmentChildren = Array.from(child.childNodes);
|
|
102
|
+
for (const fragChild of fragmentChildren) {
|
|
103
|
+
if (fragChild instanceof HTMLElement || fragChild instanceof SVGElement) {
|
|
104
|
+
result.push(fragChild);
|
|
105
|
+
} else if (fragChild.nodeType === Node.TEXT_NODE) {
|
|
106
|
+
result.push(fragChild.textContent || "");
|
|
107
|
+
} else if (fragChild instanceof DocumentFragment) {
|
|
108
|
+
result.push(...flattenChildren([fragChild], skipHTMLDetection, depth + 1));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
} else {
|
|
101
112
|
result.push(child);
|
|
102
113
|
}
|
|
@@ -197,7 +208,7 @@ function isCreatedByH(element) {
|
|
|
197
208
|
}
|
|
198
209
|
function shouldPreserveElement(element) {
|
|
199
210
|
if (!(element instanceof HTMLElement || element instanceof SVGElement)) {
|
|
200
|
-
return
|
|
211
|
+
return false;
|
|
201
212
|
}
|
|
202
213
|
if (!isCreatedByH(element)) {
|
|
203
214
|
return true;
|
|
@@ -561,7 +572,7 @@ function setSmartProperty(element, key, value, tag) {
|
|
|
561
572
|
|
|
562
573
|
// src/utils/element-creation.ts
|
|
563
574
|
function applySingleProp(element, key, value, tag, isSVG) {
|
|
564
|
-
if (value === null || value === void 0
|
|
575
|
+
if (value === null || value === void 0) {
|
|
565
576
|
return;
|
|
566
577
|
}
|
|
567
578
|
if (key === "ref" && typeof value === "function") {
|
|
@@ -590,6 +601,31 @@ function applySingleProp(element, key, value, tag, isSVG) {
|
|
|
590
601
|
if (typeof value === "boolean") {
|
|
591
602
|
if (value) {
|
|
592
603
|
element.setAttribute(key, "");
|
|
604
|
+
if (element instanceof HTMLInputElement) {
|
|
605
|
+
if (key === "checked") {
|
|
606
|
+
element.checked = true;
|
|
607
|
+
} else if (key === "disabled") {
|
|
608
|
+
element.disabled = true;
|
|
609
|
+
} else if (key === "readonly") {
|
|
610
|
+
element.readOnly = true;
|
|
611
|
+
}
|
|
612
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
613
|
+
element.selected = true;
|
|
614
|
+
}
|
|
615
|
+
} else {
|
|
616
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
617
|
+
element.removeAttribute(attributeName);
|
|
618
|
+
if (element instanceof HTMLInputElement) {
|
|
619
|
+
if (key === "checked") {
|
|
620
|
+
element.checked = false;
|
|
621
|
+
} else if (key === "disabled") {
|
|
622
|
+
element.disabled = false;
|
|
623
|
+
} else if (key === "readonly") {
|
|
624
|
+
element.readOnly = false;
|
|
625
|
+
}
|
|
626
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
627
|
+
element.selected = false;
|
|
628
|
+
}
|
|
593
629
|
}
|
|
594
630
|
return;
|
|
595
631
|
}
|
|
@@ -623,7 +659,9 @@ function appendChildrenToElement(element, children) {
|
|
|
623
659
|
return;
|
|
624
660
|
}
|
|
625
661
|
if (typeof child === "string" || typeof child === "number") {
|
|
626
|
-
|
|
662
|
+
const textNode = document.createTextNode(String(child));
|
|
663
|
+
textNode.__wsxManaged = true;
|
|
664
|
+
element.appendChild(textNode);
|
|
627
665
|
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
628
666
|
element.appendChild(child);
|
|
629
667
|
} else if (child instanceof DocumentFragment) {
|
|
@@ -643,6 +681,9 @@ function collectPreservedElements(element) {
|
|
|
643
681
|
const preserved = [];
|
|
644
682
|
for (let i = 0; i < element.childNodes.length; i++) {
|
|
645
683
|
const child = element.childNodes[i];
|
|
684
|
+
if (child.nodeType === Node.TEXT_NODE) {
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
646
687
|
if (shouldPreserveElement(child)) {
|
|
647
688
|
preserved.push(child);
|
|
648
689
|
}
|
|
@@ -676,38 +717,40 @@ function findElementNode(oldChild, parent) {
|
|
|
676
717
|
}
|
|
677
718
|
return null;
|
|
678
719
|
}
|
|
679
|
-
function findTextNode(parent, domIndex) {
|
|
680
|
-
|
|
681
|
-
const node = parent.childNodes[
|
|
682
|
-
if (node.nodeType === Node.TEXT_NODE && node.
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
return textNode;
|
|
720
|
+
function findTextNode(parent, domIndex, processedNodes) {
|
|
721
|
+
for (let i = domIndex.value; i < parent.childNodes.length; i++) {
|
|
722
|
+
const node = parent.childNodes[i];
|
|
723
|
+
if (node.nodeType === Node.TEXT_NODE && node.__wsxManaged === true && !processedNodes.has(node)) {
|
|
724
|
+
domIndex.value = i + 1;
|
|
725
|
+
return node;
|
|
686
726
|
}
|
|
687
|
-
domIndex.value++;
|
|
688
727
|
}
|
|
689
728
|
return null;
|
|
690
729
|
}
|
|
691
|
-
function updateOrCreateTextNode(parent, oldNode, newText) {
|
|
730
|
+
function updateOrCreateTextNode(parent, oldNode, newText, insertBeforeNode) {
|
|
731
|
+
if (shouldPreserveElement(parent)) {
|
|
732
|
+
if (oldNode && oldNode.nodeType === Node.TEXT_NODE) {
|
|
733
|
+
return oldNode;
|
|
734
|
+
}
|
|
735
|
+
return document.createTextNode(newText);
|
|
736
|
+
}
|
|
692
737
|
if (oldNode && oldNode.nodeType === Node.TEXT_NODE) {
|
|
693
738
|
if (oldNode.textContent !== newText) {
|
|
694
739
|
oldNode.textContent = newText;
|
|
695
740
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
for (let i = 0; i < parent.childNodes.length; i++) {
|
|
700
|
-
const node = parent.childNodes[i];
|
|
701
|
-
if (node.nodeType === Node.TEXT_NODE && node.parentNode === parent && node.textContent === newText) {
|
|
702
|
-
return node;
|
|
703
|
-
}
|
|
741
|
+
if (insertBeforeNode !== void 0) {
|
|
742
|
+
if (oldNode !== insertBeforeNode && oldNode.nextSibling !== insertBeforeNode) {
|
|
743
|
+
parent.insertBefore(oldNode, insertBeforeNode);
|
|
704
744
|
}
|
|
705
745
|
}
|
|
746
|
+
return oldNode;
|
|
747
|
+
} else {
|
|
706
748
|
const newTextNode = document.createTextNode(newText);
|
|
749
|
+
newTextNode.__wsxManaged = true;
|
|
707
750
|
if (oldNode && !shouldPreserveElement(oldNode)) {
|
|
708
751
|
parent.replaceChild(newTextNode, oldNode);
|
|
709
752
|
} else {
|
|
710
|
-
parent.insertBefore(newTextNode,
|
|
753
|
+
parent.insertBefore(newTextNode, insertBeforeNode ?? null);
|
|
711
754
|
}
|
|
712
755
|
return newTextNode;
|
|
713
756
|
}
|
|
@@ -717,53 +760,13 @@ function removeNodeIfNotPreserved(parent, node) {
|
|
|
717
760
|
parent.removeChild(node);
|
|
718
761
|
}
|
|
719
762
|
}
|
|
720
|
-
function replaceOrInsertElement(parent, newChild, oldNode) {
|
|
721
|
-
const targetNextSibling = oldNode && shouldPreserveElement(oldNode) ? oldNode : oldNode?.nextSibling || null;
|
|
722
|
-
replaceOrInsertElementAtPosition(parent, newChild, oldNode, targetNextSibling);
|
|
723
|
-
}
|
|
724
|
-
function replaceOrInsertElementAtPosition(parent, newChild, oldNode, targetNextSibling) {
|
|
725
|
-
if (newChild.parentNode && newChild.parentNode !== parent) {
|
|
726
|
-
newChild.parentNode.removeChild(newChild);
|
|
727
|
-
}
|
|
728
|
-
const isInCorrectPosition = newChild.parentNode === parent && newChild.nextSibling === targetNextSibling;
|
|
729
|
-
if (isInCorrectPosition) {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
if (newChild.parentNode === parent) {
|
|
733
|
-
parent.insertBefore(newChild, targetNextSibling);
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
if (oldNode && oldNode.parentNode === parent && !shouldPreserveElement(oldNode)) {
|
|
737
|
-
if (oldNode !== newChild) {
|
|
738
|
-
parent.replaceChild(newChild, oldNode);
|
|
739
|
-
}
|
|
740
|
-
} else {
|
|
741
|
-
if (newChild.parentNode === parent) {
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
const newChildCacheKey = getElementCacheKey(newChild);
|
|
745
|
-
if (!newChildCacheKey) {
|
|
746
|
-
const newChildContent = newChild.textContent || "";
|
|
747
|
-
const newChildTag = newChild.tagName.toLowerCase();
|
|
748
|
-
for (let i = 0; i < parent.childNodes.length; i++) {
|
|
749
|
-
const existingNode = parent.childNodes[i];
|
|
750
|
-
if (existingNode instanceof HTMLElement || existingNode instanceof SVGElement) {
|
|
751
|
-
const existingCacheKey = getElementCacheKey(existingNode);
|
|
752
|
-
if (!existingCacheKey && existingNode.tagName.toLowerCase() === newChildTag && existingNode.textContent === newChildContent && existingNode !== newChild) {
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
parent.insertBefore(newChild, targetNextSibling);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
763
|
function appendNewChild(parent, child, processedNodes) {
|
|
762
764
|
if (child === null || child === void 0 || child === false) {
|
|
763
765
|
return;
|
|
764
766
|
}
|
|
765
767
|
if (typeof child === "string" || typeof child === "number") {
|
|
766
768
|
const newTextNode = document.createTextNode(String(child));
|
|
769
|
+
newTextNode.__wsxManaged = true;
|
|
767
770
|
parent.appendChild(newTextNode);
|
|
768
771
|
if (processedNodes) {
|
|
769
772
|
processedNodes.add(newTextNode);
|
|
@@ -780,6 +783,11 @@ function appendNewChild(parent, child, processedNodes) {
|
|
|
780
783
|
processedNodes.add(child);
|
|
781
784
|
}
|
|
782
785
|
} else if (child instanceof DocumentFragment) {
|
|
786
|
+
if (processedNodes) {
|
|
787
|
+
for (let i = 0; i < child.childNodes.length; i++) {
|
|
788
|
+
processedNodes.add(child.childNodes[i]);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
783
791
|
parent.appendChild(child);
|
|
784
792
|
}
|
|
785
793
|
}
|
|
@@ -800,21 +808,32 @@ function buildNewChildrenMaps(flatNew) {
|
|
|
800
808
|
return { elementSet, cacheKeyMap };
|
|
801
809
|
}
|
|
802
810
|
function shouldRemoveNode(node, elementSet, cacheKeyMap, processedNodes) {
|
|
811
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
812
|
+
if (node.__wsxManaged === true) {
|
|
813
|
+
if (processedNodes && processedNodes.has(node)) {
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
const parent = node.parentNode;
|
|
819
|
+
if (parent && (parent instanceof HTMLElement || parent instanceof SVGElement)) {
|
|
820
|
+
if (shouldPreserveElement(parent)) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return true;
|
|
825
|
+
} else {
|
|
826
|
+
if (shouldPreserveElement(node)) {
|
|
827
|
+
return false;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const isProcessed = processedNodes && processedNodes.has(node);
|
|
803
831
|
if (shouldPreserveElement(node)) {
|
|
804
832
|
return false;
|
|
805
833
|
}
|
|
806
|
-
if (node.nodeType === Node.TEXT_NODE &&
|
|
834
|
+
if (node.nodeType === Node.TEXT_NODE && isProcessed) {
|
|
807
835
|
return false;
|
|
808
836
|
}
|
|
809
|
-
if (node.nodeType === Node.TEXT_NODE && processedNodes) {
|
|
810
|
-
let parent = node.parentNode;
|
|
811
|
-
while (parent) {
|
|
812
|
-
if (processedNodes.has(parent) && parent.parentNode) {
|
|
813
|
-
return false;
|
|
814
|
-
}
|
|
815
|
-
parent = parent.parentNode;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
837
|
if (node instanceof HTMLElement || node instanceof SVGElement || node instanceof DocumentFragment) {
|
|
819
838
|
if (elementSet.has(node)) {
|
|
820
839
|
return false;
|
|
@@ -856,7 +875,8 @@ function collectNodesToRemove(parent, elementSet, cacheKeyMap, processedNodes) {
|
|
|
856
875
|
const nodesToRemove = [];
|
|
857
876
|
for (let i = 0; i < parent.childNodes.length; i++) {
|
|
858
877
|
const node = parent.childNodes[i];
|
|
859
|
-
|
|
878
|
+
const removed = shouldRemoveNode(node, elementSet, cacheKeyMap, processedNodes);
|
|
879
|
+
if (removed) {
|
|
860
880
|
nodesToRemove.push(node);
|
|
861
881
|
}
|
|
862
882
|
}
|
|
@@ -945,7 +965,7 @@ function removeProp(element, key, oldValue, tag) {
|
|
|
945
965
|
}
|
|
946
966
|
}
|
|
947
967
|
function applySingleProp2(element, key, value, tag, isSVG) {
|
|
948
|
-
if (value === null || value === void 0
|
|
968
|
+
if (value === null || value === void 0) {
|
|
949
969
|
return;
|
|
950
970
|
}
|
|
951
971
|
if (key === "ref" && typeof value === "function") {
|
|
@@ -978,6 +998,31 @@ function applySingleProp2(element, key, value, tag, isSVG) {
|
|
|
978
998
|
if (typeof value === "boolean") {
|
|
979
999
|
if (value) {
|
|
980
1000
|
element.setAttribute(key, "");
|
|
1001
|
+
if (element instanceof HTMLInputElement) {
|
|
1002
|
+
if (key === "checked") {
|
|
1003
|
+
element.checked = true;
|
|
1004
|
+
} else if (key === "disabled") {
|
|
1005
|
+
element.disabled = true;
|
|
1006
|
+
} else if (key === "readonly") {
|
|
1007
|
+
element.readOnly = true;
|
|
1008
|
+
}
|
|
1009
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
1010
|
+
element.selected = true;
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
const attributeName = isSVG ? getSVGAttributeName(key) : key;
|
|
1014
|
+
element.removeAttribute(attributeName);
|
|
1015
|
+
if (element instanceof HTMLInputElement) {
|
|
1016
|
+
if (key === "checked") {
|
|
1017
|
+
element.checked = false;
|
|
1018
|
+
} else if (key === "disabled") {
|
|
1019
|
+
element.disabled = false;
|
|
1020
|
+
} else if (key === "readonly") {
|
|
1021
|
+
element.readOnly = false;
|
|
1022
|
+
}
|
|
1023
|
+
} else if (element instanceof HTMLOptionElement && key === "selected") {
|
|
1024
|
+
element.selected = false;
|
|
1025
|
+
}
|
|
981
1026
|
}
|
|
982
1027
|
return;
|
|
983
1028
|
}
|
|
@@ -1033,6 +1078,7 @@ function updateChildren(element, oldChildren, newChildren, _cacheManager) {
|
|
|
1033
1078
|
const preservedElements = collectPreservedElements(element);
|
|
1034
1079
|
const minLength = Math.min(flatOld.length, flatNew.length);
|
|
1035
1080
|
const domIndex = { value: 0 };
|
|
1081
|
+
const insertionIndex = { value: 0 };
|
|
1036
1082
|
const processedNodes = /* @__PURE__ */ new Set();
|
|
1037
1083
|
for (let i = 0; i < minLength; i++) {
|
|
1038
1084
|
const oldChild = flatOld[i];
|
|
@@ -1047,40 +1093,54 @@ function updateChildren(element, oldChildren, newChildren, _cacheManager) {
|
|
|
1047
1093
|
}
|
|
1048
1094
|
}
|
|
1049
1095
|
} else if (typeof oldChild === "string" || typeof oldChild === "number") {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
domIndex.value =
|
|
1058
|
-
break;
|
|
1096
|
+
if (shouldPreserveElement(element)) {
|
|
1097
|
+
oldNode = null;
|
|
1098
|
+
} else {
|
|
1099
|
+
oldNode = findTextNode(element, domIndex, processedNodes);
|
|
1100
|
+
if (oldNode) {
|
|
1101
|
+
const nodeIndex = Array.from(element.childNodes).indexOf(oldNode);
|
|
1102
|
+
if (nodeIndex !== -1 && nodeIndex >= domIndex.value) {
|
|
1103
|
+
domIndex.value = nodeIndex + 1;
|
|
1059
1104
|
}
|
|
1060
1105
|
}
|
|
1061
1106
|
}
|
|
1062
1107
|
}
|
|
1063
1108
|
if (typeof oldChild === "string" || typeof oldChild === "number") {
|
|
1064
1109
|
if (typeof newChild === "string" || typeof newChild === "number") {
|
|
1065
|
-
const oldText = String(oldChild);
|
|
1066
1110
|
const newText = String(newChild);
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1111
|
+
if (shouldPreserveElement(element)) {
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
const insertBeforeNode = insertionIndex.value < element.childNodes.length ? element.childNodes[insertionIndex.value] : null;
|
|
1115
|
+
const updatedNode = updateOrCreateTextNode(
|
|
1116
|
+
element,
|
|
1117
|
+
oldNode,
|
|
1118
|
+
newText,
|
|
1119
|
+
insertBeforeNode
|
|
1120
|
+
);
|
|
1121
|
+
if (updatedNode) {
|
|
1122
|
+
processedNodes.add(updatedNode);
|
|
1123
|
+
insertionIndex.value++;
|
|
1077
1124
|
}
|
|
1078
1125
|
} else {
|
|
1079
|
-
|
|
1126
|
+
const targetNode = insertionIndex.value < element.childNodes.length ? element.childNodes[insertionIndex.value] : null;
|
|
1080
1127
|
if (newChild instanceof HTMLElement || newChild instanceof SVGElement) {
|
|
1081
|
-
|
|
1128
|
+
if (oldNode && oldNode === targetNode && oldNode.parentNode === element) {
|
|
1129
|
+
element.replaceChild(newChild, oldNode);
|
|
1130
|
+
} else {
|
|
1131
|
+
element.insertBefore(newChild, targetNode);
|
|
1132
|
+
removeNodeIfNotPreserved(element, oldNode);
|
|
1133
|
+
}
|
|
1134
|
+
processedNodes.add(newChild);
|
|
1135
|
+
insertionIndex.value++;
|
|
1082
1136
|
} else if (newChild instanceof DocumentFragment) {
|
|
1083
|
-
|
|
1137
|
+
if (processedNodes) {
|
|
1138
|
+
for (let i2 = 0; i2 < newChild.childNodes.length; i2++) {
|
|
1139
|
+
processedNodes.add(newChild.childNodes[i2]);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
element.insertBefore(newChild, targetNode);
|
|
1143
|
+
removeNodeIfNotPreserved(element, oldNode);
|
|
1084
1144
|
}
|
|
1085
1145
|
}
|
|
1086
1146
|
} else if (oldChild instanceof HTMLElement || oldChild instanceof SVGElement) {
|
|
@@ -1088,49 +1148,37 @@ function updateChildren(element, oldChildren, newChildren, _cacheManager) {
|
|
|
1088
1148
|
continue;
|
|
1089
1149
|
}
|
|
1090
1150
|
if (newChild instanceof HTMLElement || newChild instanceof SVGElement) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
if (prevChild instanceof HTMLElement || prevChild instanceof SVGElement) {
|
|
1096
|
-
if (prevChild.parentNode === element) {
|
|
1097
|
-
targetNextSibling = prevChild.nextSibling;
|
|
1098
|
-
foundPreviousElement = true;
|
|
1099
|
-
break;
|
|
1100
|
-
}
|
|
1151
|
+
const insertBeforeNode = insertionIndex.value < element.childNodes.length ? element.childNodes[insertionIndex.value] : null;
|
|
1152
|
+
if (newChild === oldNode) {
|
|
1153
|
+
if (newChild.nextSibling !== insertBeforeNode) {
|
|
1154
|
+
element.insertBefore(newChild, insertBeforeNode);
|
|
1101
1155
|
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
const firstChild = Array.from(element.childNodes).find(
|
|
1105
|
-
(node) => !shouldPreserveElement(node) && !processedNodes.has(node)
|
|
1106
|
-
);
|
|
1107
|
-
targetNextSibling = firstChild || null;
|
|
1108
|
-
}
|
|
1109
|
-
const isInCorrectPosition = newChild.parentNode === element && newChild.nextSibling === targetNextSibling;
|
|
1110
|
-
if (newChild === oldChild && isInCorrectPosition) {
|
|
1111
|
-
if (oldNode) processedNodes.add(oldNode);
|
|
1112
|
-
processedNodes.add(newChild);
|
|
1113
|
-
continue;
|
|
1114
|
-
}
|
|
1115
|
-
const referenceNode = oldNode && oldNode.parentNode === element ? oldNode : null;
|
|
1116
|
-
replaceOrInsertElementAtPosition(
|
|
1117
|
-
element,
|
|
1118
|
-
newChild,
|
|
1119
|
-
referenceNode,
|
|
1120
|
-
targetNextSibling
|
|
1121
|
-
);
|
|
1122
|
-
if (oldNode && oldNode !== newChild) {
|
|
1123
|
-
processedNodes.delete(oldNode);
|
|
1156
|
+
} else {
|
|
1157
|
+
element.insertBefore(newChild, insertBeforeNode);
|
|
1124
1158
|
}
|
|
1125
1159
|
processedNodes.add(newChild);
|
|
1160
|
+
insertionIndex.value++;
|
|
1126
1161
|
} else {
|
|
1127
|
-
|
|
1162
|
+
const targetNode = insertionIndex.value < element.childNodes.length ? element.childNodes[insertionIndex.value] : null;
|
|
1128
1163
|
if (typeof newChild === "string" || typeof newChild === "number") {
|
|
1129
1164
|
const newTextNode = document.createTextNode(String(newChild));
|
|
1130
|
-
|
|
1165
|
+
newTextNode.__wsxManaged = true;
|
|
1166
|
+
if (oldNode && oldNode === targetNode && oldNode.parentNode === element) {
|
|
1167
|
+
element.replaceChild(newTextNode, oldNode);
|
|
1168
|
+
} else {
|
|
1169
|
+
element.insertBefore(newTextNode, targetNode);
|
|
1170
|
+
removeNodeIfNotPreserved(element, oldNode);
|
|
1171
|
+
}
|
|
1131
1172
|
processedNodes.add(newTextNode);
|
|
1173
|
+
insertionIndex.value++;
|
|
1132
1174
|
} else if (newChild instanceof DocumentFragment) {
|
|
1133
|
-
|
|
1175
|
+
if (processedNodes) {
|
|
1176
|
+
for (let i2 = 0; i2 < newChild.childNodes.length; i2++) {
|
|
1177
|
+
processedNodes.add(newChild.childNodes[i2]);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
element.insertBefore(newChild, targetNode);
|
|
1181
|
+
removeNodeIfNotPreserved(element, oldNode);
|
|
1134
1182
|
}
|
|
1135
1183
|
}
|
|
1136
1184
|
}
|
|
@@ -1252,7 +1300,9 @@ function Fragment(_props, children) {
|
|
|
1252
1300
|
return;
|
|
1253
1301
|
}
|
|
1254
1302
|
if (typeof child === "string" || typeof child === "number") {
|
|
1255
|
-
|
|
1303
|
+
const textNode = document.createTextNode(String(child));
|
|
1304
|
+
textNode.__wsxManaged = true;
|
|
1305
|
+
fragment.appendChild(textNode);
|
|
1256
1306
|
} else if (child instanceof HTMLElement || child instanceof SVGElement) {
|
|
1257
1307
|
fragment.appendChild(child);
|
|
1258
1308
|
} else if (child instanceof DocumentFragment) {
|
|
@@ -2153,7 +2203,7 @@ var WebComponent = class extends BaseComponent {
|
|
|
2153
2203
|
if (!isContentAlreadyInShadowRoot) {
|
|
2154
2204
|
this.shadowRoot.appendChild(content);
|
|
2155
2205
|
}
|
|
2156
|
-
const
|
|
2206
|
+
const oldNodes = Array.from(this.shadowRoot.childNodes).filter((child) => {
|
|
2157
2207
|
if (child === content) {
|
|
2158
2208
|
return false;
|
|
2159
2209
|
}
|
|
@@ -2165,7 +2215,7 @@ var WebComponent = class extends BaseComponent {
|
|
|
2165
2215
|
}
|
|
2166
2216
|
return true;
|
|
2167
2217
|
});
|
|
2168
|
-
|
|
2218
|
+
oldNodes.forEach((node) => node.remove());
|
|
2169
2219
|
const hasStylesAfterDOM = this.shadowRoot.adoptedStyleSheets && this.shadowRoot.adoptedStyleSheets.length > 0;
|
|
2170
2220
|
const hasStyleElementAfterDOM = Array.from(this.shadowRoot.children).some(
|
|
2171
2221
|
(child) => child instanceof HTMLStyleElement
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
createLogger,
|
|
5
5
|
h,
|
|
6
6
|
shouldPreserveElement
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-34PNC5CJ.mjs";
|
|
8
8
|
|
|
9
9
|
// src/styles/style-manager.ts
|
|
10
10
|
var StyleManager = class {
|
|
@@ -897,7 +897,7 @@ var WebComponent = class extends BaseComponent {
|
|
|
897
897
|
if (!isContentAlreadyInShadowRoot) {
|
|
898
898
|
this.shadowRoot.appendChild(content);
|
|
899
899
|
}
|
|
900
|
-
const
|
|
900
|
+
const oldNodes = Array.from(this.shadowRoot.childNodes).filter((child) => {
|
|
901
901
|
if (child === content) {
|
|
902
902
|
return false;
|
|
903
903
|
}
|
|
@@ -909,7 +909,7 @@ var WebComponent = class extends BaseComponent {
|
|
|
909
909
|
}
|
|
910
910
|
return true;
|
|
911
911
|
});
|
|
912
|
-
|
|
912
|
+
oldNodes.forEach((node) => node.remove());
|
|
913
913
|
const hasStylesAfterDOM = this.shadowRoot.adoptedStyleSheets && this.shadowRoot.adoptedStyleSheets.length > 0;
|
|
914
914
|
const hasStyleElementAfterDOM = Array.from(this.shadowRoot.children).some(
|
|
915
915
|
(child) => child instanceof HTMLStyleElement
|