@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.
@@ -1940,13 +1940,14 @@ var StringRenderer = class {
1940
1940
  };
1941
1941
 
1942
1942
  // src/shared/renderers/stream.ts
1943
+ import { JSDOM } from "jsdom";
1943
1944
  var StreamRenderer = class {
1944
1945
  constructor(rootInjector, options = {}) {
1945
1946
  this.rootInjector = rootInjector;
1946
1947
  this.pending = /* @__PURE__ */ new Map();
1947
1948
  this.processedIds = /* @__PURE__ */ new Set();
1948
1949
  this.queueResolvers = [];
1949
- this.pushQueue = (u) => this.queueResolvers.shift()?.(u);
1950
+ this.idCounter = 0;
1950
1951
  this.options = {
1951
1952
  timeout: options.timeout ?? 3e4
1952
1953
  };
@@ -1987,25 +1988,7 @@ var StreamRenderer = class {
1987
1988
  return this.renderClassComponent(vnode, injector);
1988
1989
  }
1989
1990
  if (isIntrinsicElement(vnode)) {
1990
- const dangerousHTML = vnode.props?.dangerouslySetInnerHTML;
1991
- let children;
1992
- if (dangerousHTML && dangerousHTML.__html) {
1993
- children = this.parseHTMLToJSX(dangerousHTML.__html, injector);
1994
- } else {
1995
- children = this.mapChildren(vnode.props?.children, injector);
1996
- }
1997
- return {
1998
- $typeof: ORCA_ELEMENT_TYPE,
1999
- type: vnode.type,
2000
- id: vnode.id,
2001
- props: {
2002
- ...vnode.props,
2003
- dangerouslySetInnerHTML: void 0,
2004
- // Remove after processing
2005
- children
2006
- },
2007
- key: vnode.key ?? null
2008
- };
1991
+ return this.renderIntrinsicElement(vnode, injector);
2009
1992
  }
2010
1993
  if (isFragment(vnode)) {
2011
1994
  return {
@@ -2023,6 +2006,28 @@ var StreamRenderer = class {
2023
2006
  this.renderingNodes.delete(vnode);
2024
2007
  }
2025
2008
  }
2009
+ renderIntrinsicElement(vnode, injector) {
2010
+ const { dangerouslySetInnerHTML, children, ...restProps } = vnode.props || {};
2011
+ let processedChildren;
2012
+ if (dangerouslySetInnerHTML?.__html) {
2013
+ processedChildren = this.parseHTMLToJSX(
2014
+ dangerouslySetInnerHTML.__html,
2015
+ injector
2016
+ );
2017
+ } else {
2018
+ processedChildren = this.mapChildren(children, injector);
2019
+ }
2020
+ return {
2021
+ $$typeof: ORCA_ELEMENT_TYPE,
2022
+ type: vnode.type,
2023
+ id: vnode.id,
2024
+ props: {
2025
+ ...restProps,
2026
+ children: processedChildren
2027
+ },
2028
+ key: vnode.key ?? null
2029
+ };
2030
+ }
2026
2031
  renderClassComponent(vnode, injector) {
2027
2032
  const ComponentClass = vnode.type;
2028
2033
  const isComponent = Reflect.getMetadata(COMPONENT, ComponentClass);
@@ -2045,7 +2050,9 @@ var StreamRenderer = class {
2045
2050
  return this.buildSyncTree(childVNode, componentInjector);
2046
2051
  }
2047
2052
  mapChildren(children, injector) {
2048
- if (children == null || typeof children === "string" || typeof children === "number") {
2053
+ if (children == null)
2054
+ return void 0;
2055
+ if (typeof children === "string" || typeof children === "number") {
2049
2056
  return children;
2050
2057
  }
2051
2058
  if (Array.isArray(children)) {
@@ -2054,32 +2061,39 @@ var StreamRenderer = class {
2054
2061
  return this.buildSyncTree(children, injector);
2055
2062
  }
2056
2063
  parseHTMLToJSX(html, injector) {
2057
- const parser = new DOMParser();
2058
- const doc = parser.parseFromString(html, "text/html");
2064
+ const dom = new JSDOM(html);
2065
+ const document2 = dom.window.document;
2059
2066
  const convertNode = (node) => {
2060
- if (node.nodeType === Node.TEXT_NODE) {
2061
- return node.textContent;
2067
+ if (node.nodeType === 3) {
2068
+ const text = node.textContent || "";
2069
+ return text.trim() ? text : null;
2062
2070
  }
2063
- if (node.nodeType === Node.ELEMENT_NODE) {
2071
+ if (node.nodeType === 1) {
2064
2072
  const element = node;
2065
2073
  const tagName = element.tagName.toLowerCase();
2066
2074
  const props = {};
2067
- for (let i = 0; i < element.attributes.length; i++) {
2068
- const attr = element.attributes[i];
2069
- let propName = attr.name;
2070
- if (propName === "class")
2071
- propName = "className";
2072
- if (propName === "for")
2073
- propName = "htmlFor";
2074
- props[propName] = attr.value;
2075
- }
2075
+ Array.from(element.attributes).forEach((attr) => {
2076
+ let name = attr.name;
2077
+ if (name === "class")
2078
+ name = "className";
2079
+ else if (name === "for")
2080
+ name = "htmlFor";
2081
+ else if (name.startsWith("data-") || name.startsWith("aria-")) {
2082
+ } else if (name.includes("-")) {
2083
+ name = name.replace(
2084
+ /-([a-z])/g,
2085
+ (_, letter) => letter.toUpperCase()
2086
+ );
2087
+ }
2088
+ props[name] = attr.value;
2089
+ });
2076
2090
  const children = [];
2077
- for (let i = 0; i < element.childNodes.length; i++) {
2078
- const child = convertNode(element.childNodes[i]);
2079
- if (child !== null && child !== "") {
2080
- children.push(child);
2091
+ element.childNodes.forEach((child) => {
2092
+ const converted = convertNode(child);
2093
+ if (converted != null) {
2094
+ children.push(converted);
2081
2095
  }
2082
- }
2096
+ });
2083
2097
  const jsxElement = {
2084
2098
  $$typeof: ORCA_ELEMENT_TYPE,
2085
2099
  type: tagName,
@@ -2094,17 +2108,14 @@ var StreamRenderer = class {
2094
2108
  }
2095
2109
  return null;
2096
2110
  };
2097
- const bodyChildren = [];
2098
- for (let i = 0; i < doc.body.childNodes.length; i++) {
2099
- const child = convertNode(doc.body.childNodes[i]);
2100
- if (child !== null && child !== "") {
2101
- bodyChildren.push(child);
2111
+ const result = [];
2112
+ document2.body.childNodes.forEach((node) => {
2113
+ const converted = convertNode(node);
2114
+ if (converted != null) {
2115
+ result.push(converted);
2102
2116
  }
2103
- }
2104
- return bodyChildren.length === 0 ? void 0 : bodyChildren.length === 1 ? bodyChildren[0] : bodyChildren;
2105
- }
2106
- generateId() {
2107
- return `jsx_${Math.random().toString(36).substr(2, 9)}`;
2117
+ });
2118
+ return result.length === 0 ? void 0 : result.length === 1 ? result[0] : result;
2108
2119
  }
2109
2120
  createPendingReference(vnode, promise, injector) {
2110
2121
  const id = vnode.id;
@@ -2131,13 +2142,13 @@ var StreamRenderer = class {
2131
2142
  if (this.processedIds.has(id))
2132
2143
  return;
2133
2144
  this.processedIds.add(id);
2134
- this.pushQueue({
2145
+ this.queueResolvers.shift()?.({
2135
2146
  ...resolved,
2136
2147
  action: "update"
2137
2148
  });
2138
2149
  this.pending.delete(id);
2139
2150
  }).catch((e) => {
2140
- this.pushQueue({
2151
+ this.queueResolvers.shift()?.({
2141
2152
  $$typeof: ERROR_ELEMENT,
2142
2153
  type: "error",
2143
2154
  action: "error",
@@ -2157,6 +2168,9 @@ var StreamRenderer = class {
2157
2168
  key: vnode.key ?? null
2158
2169
  };
2159
2170
  }
2171
+ generateId() {
2172
+ return `jsx_${++this.idCounter}`;
2173
+ }
2160
2174
  cleanup() {
2161
2175
  for (const { abortController } of this.pending.values()) {
2162
2176
  abortController.abort();