@kithinji/orca 1.0.6 → 1.0.7

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.
@@ -930,15 +930,22 @@ var kithinjiorca = (() => {
930
930
  return this.renderClassComponent(vnode, injector);
931
931
  }
932
932
  if (isIntrinsicElement(vnode)) {
933
- const hasDangerousHTML = vnode.props?.dangerouslySetInnerHTML;
933
+ const dangerousHTML = vnode.props?.dangerouslySetInnerHTML;
934
+ let children;
935
+ if (dangerousHTML && dangerousHTML.__html) {
936
+ children = this.parseHTMLToJSX(dangerousHTML.__html, injector);
937
+ } else {
938
+ children = this.mapChildren(vnode.props?.children, injector);
939
+ }
934
940
  return {
935
- $$typeof: ORCA_ELEMENT_TYPE,
941
+ $typeof: ORCA_ELEMENT_TYPE,
936
942
  type: vnode.type,
937
943
  id: vnode.id,
938
944
  props: {
939
945
  ...vnode.props,
940
- // Only process children if dangerouslySetInnerHTML is not present
941
- children: hasDangerousHTML ? void 0 : this.mapChildren(vnode.props?.children, injector)
946
+ dangerouslySetInnerHTML: void 0,
947
+ // Remove after processing
948
+ children
942
949
  },
943
950
  key: vnode.key ?? null
944
951
  };
@@ -989,6 +996,59 @@ var kithinjiorca = (() => {
989
996
  }
990
997
  return this.buildSyncTree(children, injector);
991
998
  }
999
+ parseHTMLToJSX(html, injector) {
1000
+ const parser = new DOMParser();
1001
+ const doc = parser.parseFromString(html, "text/html");
1002
+ const convertNode = (node) => {
1003
+ if (node.nodeType === Node.TEXT_NODE) {
1004
+ return node.textContent;
1005
+ }
1006
+ if (node.nodeType === Node.ELEMENT_NODE) {
1007
+ const element = node;
1008
+ const tagName = element.tagName.toLowerCase();
1009
+ const props = {};
1010
+ for (let i = 0; i < element.attributes.length; i++) {
1011
+ const attr = element.attributes[i];
1012
+ let propName = attr.name;
1013
+ if (propName === "class")
1014
+ propName = "className";
1015
+ if (propName === "for")
1016
+ propName = "htmlFor";
1017
+ props[propName] = attr.value;
1018
+ }
1019
+ const children = [];
1020
+ for (let i = 0; i < element.childNodes.length; i++) {
1021
+ const child = convertNode(element.childNodes[i]);
1022
+ if (child !== null && child !== "") {
1023
+ children.push(child);
1024
+ }
1025
+ }
1026
+ const jsxElement = {
1027
+ $$typeof: ORCA_ELEMENT_TYPE,
1028
+ type: tagName,
1029
+ id: this.generateId(),
1030
+ props: {
1031
+ ...props,
1032
+ children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
1033
+ },
1034
+ key: null
1035
+ };
1036
+ return this.buildSyncTree(jsxElement, injector);
1037
+ }
1038
+ return null;
1039
+ };
1040
+ const bodyChildren = [];
1041
+ for (let i = 0; i < doc.body.childNodes.length; i++) {
1042
+ const child = convertNode(doc.body.childNodes[i]);
1043
+ if (child !== null && child !== "") {
1044
+ bodyChildren.push(child);
1045
+ }
1046
+ }
1047
+ return bodyChildren.length === 0 ? void 0 : bodyChildren.length === 1 ? bodyChildren[0] : bodyChildren;
1048
+ }
1049
+ generateId() {
1050
+ return `jsx_${Math.random().toString(36).substr(2, 9)}`;
1051
+ }
992
1052
  createPendingReference(vnode, promise, injector) {
993
1053
  const id = vnode.id;
994
1054
  const abortController = new AbortController();