@kithinji/orca 1.0.7 → 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.
@@ -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.pushQueue = (u) => this.queueResolvers.shift()?.(u);
893
+ this.idCounter = 0;
893
894
  this.options = {
894
895
  timeout: options.timeout ?? 3e4
895
896
  };
@@ -930,25 +931,7 @@ var kithinjiorca = (() => {
930
931
  return this.renderClassComponent(vnode, injector);
931
932
  }
932
933
  if (isIntrinsicElement(vnode)) {
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
- }
940
- return {
941
- $typeof: ORCA_ELEMENT_TYPE,
942
- type: vnode.type,
943
- id: vnode.id,
944
- props: {
945
- ...vnode.props,
946
- dangerouslySetInnerHTML: void 0,
947
- // Remove after processing
948
- children
949
- },
950
- key: vnode.key ?? null
951
- };
934
+ return this.renderIntrinsicElement(vnode, injector);
952
935
  }
953
936
  if (isFragment(vnode)) {
954
937
  return {
@@ -966,6 +949,28 @@ var kithinjiorca = (() => {
966
949
  this.renderingNodes.delete(vnode);
967
950
  }
968
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
+ }
969
974
  renderClassComponent(vnode, injector) {
970
975
  const ComponentClass = vnode.type;
971
976
  const isComponent = Reflect.getMetadata(COMPONENT, ComponentClass);
@@ -988,7 +993,9 @@ var kithinjiorca = (() => {
988
993
  return this.buildSyncTree(childVNode, componentInjector);
989
994
  }
990
995
  mapChildren(children, injector) {
991
- if (children == null || typeof children === "string" || typeof children === "number") {
996
+ if (children == null)
997
+ return void 0;
998
+ if (typeof children === "string" || typeof children === "number") {
992
999
  return children;
993
1000
  }
994
1001
  if (Array.isArray(children)) {
@@ -997,32 +1004,39 @@ var kithinjiorca = (() => {
997
1004
  return this.buildSyncTree(children, injector);
998
1005
  }
999
1006
  parseHTMLToJSX(html, injector) {
1000
- const parser = new DOMParser();
1001
- const doc = parser.parseFromString(html, "text/html");
1007
+ const dom = new import_jsdom.JSDOM(html);
1008
+ const document2 = dom.window.document;
1002
1009
  const convertNode = (node) => {
1003
- if (node.nodeType === Node.TEXT_NODE) {
1004
- return node.textContent;
1010
+ if (node.nodeType === 3) {
1011
+ const text = node.textContent || "";
1012
+ return text.trim() ? text : null;
1005
1013
  }
1006
- if (node.nodeType === Node.ELEMENT_NODE) {
1014
+ if (node.nodeType === 1) {
1007
1015
  const element = node;
1008
1016
  const tagName = element.tagName.toLowerCase();
1009
1017
  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
- }
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
+ });
1019
1033
  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);
1034
+ element.childNodes.forEach((child) => {
1035
+ const converted = convertNode(child);
1036
+ if (converted != null) {
1037
+ children.push(converted);
1024
1038
  }
1025
- }
1039
+ });
1026
1040
  const jsxElement = {
1027
1041
  $$typeof: ORCA_ELEMENT_TYPE,
1028
1042
  type: tagName,
@@ -1037,17 +1051,14 @@ var kithinjiorca = (() => {
1037
1051
  }
1038
1052
  return null;
1039
1053
  };
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);
1054
+ const result = [];
1055
+ document2.body.childNodes.forEach((node) => {
1056
+ const converted = convertNode(node);
1057
+ if (converted != null) {
1058
+ result.push(converted);
1045
1059
  }
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)}`;
1060
+ });
1061
+ return result.length === 0 ? void 0 : result.length === 1 ? result[0] : result;
1051
1062
  }
1052
1063
  createPendingReference(vnode, promise, injector) {
1053
1064
  const id = vnode.id;
@@ -1074,13 +1085,13 @@ var kithinjiorca = (() => {
1074
1085
  if (this.processedIds.has(id))
1075
1086
  return;
1076
1087
  this.processedIds.add(id);
1077
- this.pushQueue({
1088
+ this.queueResolvers.shift()?.({
1078
1089
  ...resolved,
1079
1090
  action: "update"
1080
1091
  });
1081
1092
  this.pending.delete(id);
1082
1093
  }).catch((e) => {
1083
- this.pushQueue({
1094
+ this.queueResolvers.shift()?.({
1084
1095
  $$typeof: ERROR_ELEMENT,
1085
1096
  type: "error",
1086
1097
  action: "error",
@@ -1100,6 +1111,9 @@ var kithinjiorca = (() => {
1100
1111
  key: vnode.key ?? null
1101
1112
  };
1102
1113
  }
1114
+ generateId() {
1115
+ return `jsx_${++this.idCounter}`;
1116
+ }
1103
1117
  cleanup() {
1104
1118
  for (const { abortController } of this.pending.values()) {
1105
1119
  abortController.abort();