@kithinji/orca 1.0.6 → 1.0.8
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/browser/index.iife.js +90 -16
- package/dist/browser/index.iife.js.map +3 -3
- package/dist/browser/index.mjs +90 -16
- package/dist/browser/index.mjs.map +3 -3
- package/dist/node/index.cjs +90 -16
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.mjs +90 -16
- package/dist/node/index.mjs.map +3 -3
- package/dist/types/shared/renderers/stream.d.ts +4 -1
- package/dist/types/shared/renderers/stream.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -883,13 +883,14 @@ var kithinjiorca = (() => {
|
|
|
883
883
|
};
|
|
884
884
|
|
|
885
885
|
// src/shared/renderers/stream.ts
|
|
886
|
+
var import_jsdom = __require("jsdom");
|
|
886
887
|
var StreamRenderer = class {
|
|
887
888
|
constructor(rootInjector, options = {}) {
|
|
888
889
|
this.rootInjector = rootInjector;
|
|
889
890
|
this.pending = /* @__PURE__ */ new Map();
|
|
890
891
|
this.processedIds = /* @__PURE__ */ new Set();
|
|
891
892
|
this.queueResolvers = [];
|
|
892
|
-
this.
|
|
893
|
+
this.idCounter = 0;
|
|
893
894
|
this.options = {
|
|
894
895
|
timeout: options.timeout ?? 3e4
|
|
895
896
|
};
|
|
@@ -930,18 +931,7 @@ var kithinjiorca = (() => {
|
|
|
930
931
|
return this.renderClassComponent(vnode, injector);
|
|
931
932
|
}
|
|
932
933
|
if (isIntrinsicElement(vnode)) {
|
|
933
|
-
|
|
934
|
-
return {
|
|
935
|
-
$$typeof: ORCA_ELEMENT_TYPE,
|
|
936
|
-
type: vnode.type,
|
|
937
|
-
id: vnode.id,
|
|
938
|
-
props: {
|
|
939
|
-
...vnode.props,
|
|
940
|
-
// Only process children if dangerouslySetInnerHTML is not present
|
|
941
|
-
children: hasDangerousHTML ? void 0 : this.mapChildren(vnode.props?.children, injector)
|
|
942
|
-
},
|
|
943
|
-
key: vnode.key ?? null
|
|
944
|
-
};
|
|
934
|
+
return this.renderIntrinsicElement(vnode, injector);
|
|
945
935
|
}
|
|
946
936
|
if (isFragment(vnode)) {
|
|
947
937
|
return {
|
|
@@ -959,6 +949,28 @@ var kithinjiorca = (() => {
|
|
|
959
949
|
this.renderingNodes.delete(vnode);
|
|
960
950
|
}
|
|
961
951
|
}
|
|
952
|
+
renderIntrinsicElement(vnode, injector) {
|
|
953
|
+
const { dangerouslySetInnerHTML, children, ...restProps } = vnode.props || {};
|
|
954
|
+
let processedChildren;
|
|
955
|
+
if (dangerouslySetInnerHTML?.__html) {
|
|
956
|
+
processedChildren = this.parseHTMLToJSX(
|
|
957
|
+
dangerouslySetInnerHTML.__html,
|
|
958
|
+
injector
|
|
959
|
+
);
|
|
960
|
+
} else {
|
|
961
|
+
processedChildren = this.mapChildren(children, injector);
|
|
962
|
+
}
|
|
963
|
+
return {
|
|
964
|
+
$$typeof: ORCA_ELEMENT_TYPE,
|
|
965
|
+
type: vnode.type,
|
|
966
|
+
id: vnode.id,
|
|
967
|
+
props: {
|
|
968
|
+
...restProps,
|
|
969
|
+
children: processedChildren
|
|
970
|
+
},
|
|
971
|
+
key: vnode.key ?? null
|
|
972
|
+
};
|
|
973
|
+
}
|
|
962
974
|
renderClassComponent(vnode, injector) {
|
|
963
975
|
const ComponentClass = vnode.type;
|
|
964
976
|
const isComponent = Reflect.getMetadata(COMPONENT, ComponentClass);
|
|
@@ -981,7 +993,9 @@ var kithinjiorca = (() => {
|
|
|
981
993
|
return this.buildSyncTree(childVNode, componentInjector);
|
|
982
994
|
}
|
|
983
995
|
mapChildren(children, injector) {
|
|
984
|
-
if (children == null
|
|
996
|
+
if (children == null)
|
|
997
|
+
return void 0;
|
|
998
|
+
if (typeof children === "string" || typeof children === "number") {
|
|
985
999
|
return children;
|
|
986
1000
|
}
|
|
987
1001
|
if (Array.isArray(children)) {
|
|
@@ -989,6 +1003,63 @@ var kithinjiorca = (() => {
|
|
|
989
1003
|
}
|
|
990
1004
|
return this.buildSyncTree(children, injector);
|
|
991
1005
|
}
|
|
1006
|
+
parseHTMLToJSX(html, injector) {
|
|
1007
|
+
const dom = new import_jsdom.JSDOM(html);
|
|
1008
|
+
const document2 = dom.window.document;
|
|
1009
|
+
const convertNode = (node) => {
|
|
1010
|
+
if (node.nodeType === 3) {
|
|
1011
|
+
const text = node.textContent || "";
|
|
1012
|
+
return text.trim() ? text : null;
|
|
1013
|
+
}
|
|
1014
|
+
if (node.nodeType === 1) {
|
|
1015
|
+
const element = node;
|
|
1016
|
+
const tagName = element.tagName.toLowerCase();
|
|
1017
|
+
const props = {};
|
|
1018
|
+
Array.from(element.attributes).forEach((attr) => {
|
|
1019
|
+
let name = attr.name;
|
|
1020
|
+
if (name === "class")
|
|
1021
|
+
name = "className";
|
|
1022
|
+
else if (name === "for")
|
|
1023
|
+
name = "htmlFor";
|
|
1024
|
+
else if (name.startsWith("data-") || name.startsWith("aria-")) {
|
|
1025
|
+
} else if (name.includes("-")) {
|
|
1026
|
+
name = name.replace(
|
|
1027
|
+
/-([a-z])/g,
|
|
1028
|
+
(_, letter) => letter.toUpperCase()
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
props[name] = attr.value;
|
|
1032
|
+
});
|
|
1033
|
+
const children = [];
|
|
1034
|
+
element.childNodes.forEach((child) => {
|
|
1035
|
+
const converted = convertNode(child);
|
|
1036
|
+
if (converted != null) {
|
|
1037
|
+
children.push(converted);
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
const jsxElement = {
|
|
1041
|
+
$$typeof: ORCA_ELEMENT_TYPE,
|
|
1042
|
+
type: tagName,
|
|
1043
|
+
id: this.generateId(),
|
|
1044
|
+
props: {
|
|
1045
|
+
...props,
|
|
1046
|
+
children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
|
|
1047
|
+
},
|
|
1048
|
+
key: null
|
|
1049
|
+
};
|
|
1050
|
+
return this.buildSyncTree(jsxElement, injector);
|
|
1051
|
+
}
|
|
1052
|
+
return null;
|
|
1053
|
+
};
|
|
1054
|
+
const result = [];
|
|
1055
|
+
document2.body.childNodes.forEach((node) => {
|
|
1056
|
+
const converted = convertNode(node);
|
|
1057
|
+
if (converted != null) {
|
|
1058
|
+
result.push(converted);
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
return result.length === 0 ? void 0 : result.length === 1 ? result[0] : result;
|
|
1062
|
+
}
|
|
992
1063
|
createPendingReference(vnode, promise, injector) {
|
|
993
1064
|
const id = vnode.id;
|
|
994
1065
|
const abortController = new AbortController();
|
|
@@ -1014,13 +1085,13 @@ var kithinjiorca = (() => {
|
|
|
1014
1085
|
if (this.processedIds.has(id))
|
|
1015
1086
|
return;
|
|
1016
1087
|
this.processedIds.add(id);
|
|
1017
|
-
this.
|
|
1088
|
+
this.queueResolvers.shift()?.({
|
|
1018
1089
|
...resolved,
|
|
1019
1090
|
action: "update"
|
|
1020
1091
|
});
|
|
1021
1092
|
this.pending.delete(id);
|
|
1022
1093
|
}).catch((e) => {
|
|
1023
|
-
this.
|
|
1094
|
+
this.queueResolvers.shift()?.({
|
|
1024
1095
|
$$typeof: ERROR_ELEMENT,
|
|
1025
1096
|
type: "error",
|
|
1026
1097
|
action: "error",
|
|
@@ -1040,6 +1111,9 @@ var kithinjiorca = (() => {
|
|
|
1040
1111
|
key: vnode.key ?? null
|
|
1041
1112
|
};
|
|
1042
1113
|
}
|
|
1114
|
+
generateId() {
|
|
1115
|
+
return `jsx_${++this.idCounter}`;
|
|
1116
|
+
}
|
|
1043
1117
|
cleanup() {
|
|
1044
1118
|
for (const { abortController } of this.pending.values()) {
|
|
1045
1119
|
abortController.abort();
|