hono 3.12.0 → 4.0.0-rc.0

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.
Files changed (59) hide show
  1. package/dist/adapter/cloudflare-pages/handler.js +1 -3
  2. package/dist/cjs/adapter/cloudflare-pages/handler.js +1 -3
  3. package/dist/cjs/client/client.js +1 -9
  4. package/dist/cjs/context.js +0 -47
  5. package/dist/cjs/helper/css/index.js +15 -1
  6. package/dist/cjs/helper/streaming/sse.js +5 -17
  7. package/dist/cjs/hono-base.js +8 -24
  8. package/dist/cjs/jsx/dom/index.js +355 -0
  9. package/dist/cjs/jsx/hooks/index.js +111 -0
  10. package/dist/cjs/jsx/index.js +29 -0
  11. package/dist/cjs/jsx/jsx-dev-runtime.js +10 -6
  12. package/dist/cjs/middleware/basic-auth/index.js +1 -1
  13. package/dist/cjs/middleware/compress/index.js +1 -1
  14. package/dist/cjs/middleware/jwt/index.js +3 -2
  15. package/dist/cjs/request.js +0 -34
  16. package/dist/cjs/utils/body.js +3 -1
  17. package/dist/cjs/utils/html.js +2 -1
  18. package/dist/cjs/utils/jwt/types.js +0 -3
  19. package/dist/cjs/validator/validator.js +0 -4
  20. package/dist/client/client.js +1 -9
  21. package/dist/context.js +0 -47
  22. package/dist/helper/css/index.js +15 -1
  23. package/dist/helper/streaming/sse.js +5 -17
  24. package/dist/hono-base.js +8 -24
  25. package/dist/jsx/dom/index.js +326 -0
  26. package/dist/jsx/hooks/index.js +85 -0
  27. package/dist/jsx/index.js +27 -0
  28. package/dist/jsx/jsx-dev-runtime.js +10 -6
  29. package/dist/middleware/basic-auth/index.js +1 -1
  30. package/dist/middleware/compress/index.js +1 -1
  31. package/dist/middleware/jwt/index.js +3 -2
  32. package/dist/request.js +0 -34
  33. package/dist/types/adapter/aws-lambda/custom-context.d.ts +0 -4
  34. package/dist/types/adapter/aws-lambda/index.d.ts +1 -1
  35. package/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -7
  36. package/dist/types/context.d.ts +0 -44
  37. package/dist/types/helper.d.ts +8 -0
  38. package/dist/types/hono-base.d.ts +1 -29
  39. package/dist/types/jsx/dom/index.d.ts +20 -0
  40. package/dist/types/jsx/hooks/index.d.ts +7 -0
  41. package/dist/types/jsx/index.d.ts +4 -1
  42. package/dist/types/jsx/jsx-dev-runtime.d.ts +1 -1
  43. package/dist/types/request.d.ts +0 -56
  44. package/dist/types/types.d.ts +1 -1
  45. package/dist/types/utils/body.d.ts +1 -1
  46. package/dist/types/utils/html.d.ts +1 -0
  47. package/dist/types/utils/jwt/types.d.ts +0 -5
  48. package/dist/types/validator/validator.d.ts +4 -3
  49. package/dist/utils/body.js +3 -1
  50. package/dist/utils/html.js +2 -1
  51. package/dist/utils/jwt/types.js +0 -2
  52. package/dist/validator/validator.js +0 -4
  53. package/package.json +25 -6
  54. package/dist/adapter/nextjs/handler.js +0 -9
  55. package/dist/adapter/nextjs/index.js +0 -5
  56. package/dist/cjs/adapter/nextjs/handler.js +0 -32
  57. package/dist/cjs/adapter/nextjs/index.js +0 -28
  58. package/dist/types/adapter/nextjs/handler.d.ts +0 -16
  59. package/dist/types/adapter/nextjs/index.d.ts +0 -1
@@ -1,7 +1,5 @@
1
1
  // src/adapter/cloudflare-pages/handler.ts
2
- import { Hono } from "../../hono.js";
3
- var handle = (subApp, path) => (eventContext) => {
4
- const app = path ? new Hono().route(path, subApp) : subApp;
2
+ var handle = (app) => (eventContext) => {
5
3
  return app.fetch(
6
4
  eventContext.request,
7
5
  { ...eventContext.env, eventContext },
@@ -22,9 +22,7 @@ __export(handler_exports, {
22
22
  serveStatic: () => serveStatic
23
23
  });
24
24
  module.exports = __toCommonJS(handler_exports);
25
- var import_hono = require("../../hono");
26
- const handle = (subApp, path) => (eventContext) => {
27
- const app = path ? new import_hono.Hono().route(path, subApp) : subApp;
25
+ const handle = (app) => (eventContext) => {
28
26
  return app.fetch(
29
27
  eventContext.request,
30
28
  { ...eventContext.env, eventContext },
@@ -27,7 +27,7 @@ const createProxy = (callback, path) => {
27
27
  const proxy = new Proxy(() => {
28
28
  }, {
29
29
  get(_obj, key) {
30
- if (typeof key !== "string")
30
+ if (typeof key !== "string" || key === "then")
31
31
  return void 0;
32
32
  return createProxy(callback, [...path, key]);
33
33
  },
@@ -62,14 +62,6 @@ class ClientRequestImpl {
62
62
  }
63
63
  }
64
64
  }
65
- if (args.queries) {
66
- for (const [k, v] of Object.entries(args.queries)) {
67
- for (const v2 of v) {
68
- this.queryParams || (this.queryParams = new URLSearchParams());
69
- this.queryParams.append(k, v2);
70
- }
71
- }
72
- }
73
65
  if (args.form) {
74
66
  const form = new FormData();
75
67
  for (const [k, v] of Object.entries(args.form)) {
@@ -40,9 +40,7 @@ __export(context_exports, {
40
40
  TEXT_PLAIN: () => TEXT_PLAIN
41
41
  });
42
42
  module.exports = __toCommonJS(context_exports);
43
- var import_cookie = require("./utils/cookie");
44
43
  var import_html = require("./utils/html");
45
- var import_stream = require("./utils/stream");
46
44
  var _status, _executionCtx, _headers, _preparedHeaders, _res, _isFresh;
47
45
  const TEXT_PLAIN = "text/plain; charset=UTF-8";
48
46
  class Context {
@@ -167,9 +165,6 @@ class Context {
167
165
  __privateGet(this, _preparedHeaders)["content-type"] = "application/json; charset=UTF-8";
168
166
  return typeof arg === "number" ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
169
167
  };
170
- this.jsonT = (object, arg, headers) => {
171
- return this.json(object, arg, headers);
172
- };
173
168
  this.html = (html, arg, headers) => {
174
169
  __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
175
170
  __privateGet(this, _preparedHeaders)["content-type"] = "text/html; charset=UTF-8";
@@ -190,23 +185,6 @@ class Context {
190
185
  __privateGet(this, _headers).set("Location", location);
191
186
  return this.newResponse(null, status);
192
187
  };
193
- this.streamText = (cb, arg, headers) => {
194
- headers ?? (headers = {});
195
- this.header("content-type", TEXT_PLAIN);
196
- this.header("x-content-type-options", "nosniff");
197
- this.header("transfer-encoding", "chunked");
198
- return this.stream(cb, arg, headers);
199
- };
200
- this.stream = (cb, arg, headers) => {
201
- const { readable, writable } = new TransformStream();
202
- const stream = new import_stream.StreamingApi(writable, readable);
203
- cb(stream).finally(() => stream.close());
204
- return typeof arg === "number" ? this.newResponse(stream.responseReadable, arg, headers) : this.newResponse(stream.responseReadable, arg);
205
- };
206
- this.cookie = (name, value, opt) => {
207
- const cookie = (0, import_cookie.serialize)(name, value, opt);
208
- this.header("set-cookie", cookie, { append: true });
209
- };
210
188
  this.notFound = () => {
211
189
  return this.notFoundHandler(this);
212
190
  };
@@ -251,31 +229,6 @@ class Context {
251
229
  get var() {
252
230
  return { ...this._var };
253
231
  }
254
- get runtime() {
255
- const global = globalThis;
256
- if (global?.Deno !== void 0) {
257
- return "deno";
258
- }
259
- if (global?.Bun !== void 0) {
260
- return "bun";
261
- }
262
- if (typeof global?.WebSocketPair === "function") {
263
- return "workerd";
264
- }
265
- if (typeof global?.EdgeRuntime === "string") {
266
- return "edge-light";
267
- }
268
- if (global?.fastly !== void 0) {
269
- return "fastly";
270
- }
271
- if (global?.__lagon__ !== void 0) {
272
- return "lagon";
273
- }
274
- if (global?.process?.release?.name === "node") {
275
- return "node";
276
- }
277
- return "other";
278
- }
279
232
  }
280
233
  _status = new WeakMap();
281
234
  _executionCtx = new WeakMap();
@@ -27,6 +27,7 @@ __export(css_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(css_exports);
29
29
  var import_html = require("../../helper/html");
30
+ var import_html2 = require("../../utils/html");
30
31
  const IS_CSS_CLASS_NAME = Symbol("IS_CSS_CLASS_NAME");
31
32
  const STYLE_STRING = Symbol("STYLE_STRING");
32
33
  const SELECTORS = Symbol("SELECTORS");
@@ -141,7 +142,20 @@ const createCssContext = ({ id }) => {
141
142
  }
142
143
  return Promise.resolve(appendStyleScript);
143
144
  };
144
- const addClassNameToContext = ({ context }) => {
145
+ const addClassNameToContext = ({ context, phase }) => {
146
+ if (phase === import_html2.HtmlEscapedCallbackPhase.BeforeDom) {
147
+ const styleSheets = document.styleSheets;
148
+ for (let i = 0; i < styleSheets.length; i++) {
149
+ const sheet = styleSheets[i];
150
+ if (sheet.ownerNode?.id === id) {
151
+ if (!sheet.cssRules?.[0]?.cssText?.includes(thisSelector)) {
152
+ sheet.insertRule(`.${thisSelector}{${thisStyleString}}`);
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ return;
158
+ }
145
159
  if (!contextMap.get(context)) {
146
160
  contextMap.set(context, [{}, {}]);
147
161
  }
@@ -23,7 +23,6 @@ __export(sse_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(sse_exports);
25
25
  var import_stream = require("../../utils/stream");
26
- var import__ = require(".");
27
26
  class SSEStreamingApi extends import_stream.StreamingApi {
28
27
  constructor(writable, readable) {
29
28
  super(writable, readable);
@@ -43,22 +42,11 @@ const setSSEHeaders = (context) => {
43
42
  context.header("Connection", "keep-alive");
44
43
  };
45
44
  const streamSSE = (c, cb) => {
46
- return (0, import__.stream)(c, async (originalStream) => {
47
- const { readable, writable } = new TransformStream();
48
- const stream2 = new SSEStreamingApi(writable, readable);
49
- originalStream.pipe(stream2.responseReadable).catch((err) => {
50
- console.error("Error in stream piping: ", err);
51
- stream2.close();
52
- });
53
- setSSEHeaders(c);
54
- try {
55
- await cb(stream2);
56
- } catch (err) {
57
- console.error("Error during streaming: ", err);
58
- } finally {
59
- await stream2.close();
60
- }
61
- });
45
+ const { readable, writable } = new TransformStream();
46
+ const stream = new SSEStreamingApi(writable, readable);
47
+ cb(stream).finally(() => stream.close());
48
+ setSSEHeaders(c);
49
+ return c.newResponse(stream.responseReadable);
62
50
  };
63
51
  // Annotate the CommonJS export names for ESM import in node:
64
52
  0 && (module.exports = {
@@ -79,13 +79,6 @@ const _Hono = class extends defineDynamicClass() {
79
79
  this.notFoundHandler = handler;
80
80
  return this;
81
81
  };
82
- this.head = () => {
83
- console.warn("`app.head()` is no longer used. `app.get()` implicitly handles the HEAD method.");
84
- return this;
85
- };
86
- this.handleEvent = (event) => {
87
- return this.dispatch(event.request, event, void 0, event.request.method);
88
- };
89
82
  this.fetch = (request, Env, executionCtx) => {
90
83
  return this.dispatch(request, executionCtx, Env, request.method);
91
84
  };
@@ -125,11 +118,13 @@ const _Hono = class extends defineDynamicClass() {
125
118
  this.on = (method, path, ...handlers) => {
126
119
  if (!method)
127
120
  return this;
128
- __privateSet(this, _path, path);
129
- for (const m of [method].flat()) {
130
- handlers.map((handler) => {
131
- this.addRoute(m.toUpperCase(), __privateGet(this, _path), handler);
132
- });
121
+ for (const p of [path].flat()) {
122
+ __privateSet(this, _path, p);
123
+ for (const m of [method].flat()) {
124
+ handlers.map((handler) => {
125
+ this.addRoute(m.toUpperCase(), __privateGet(this, _path), handler);
126
+ });
127
+ }
133
128
  }
134
129
  return this;
135
130
  };
@@ -137,6 +132,7 @@ const _Hono = class extends defineDynamicClass() {
137
132
  if (typeof arg1 === "string") {
138
133
  __privateSet(this, _path, arg1);
139
134
  } else {
135
+ __privateSet(this, _path, "*");
140
136
  handlers.unshift(arg1);
141
137
  }
142
138
  handlers.map((handler) => {
@@ -179,14 +175,6 @@ const _Hono = class extends defineDynamicClass() {
179
175
  subApp._basePath = (0, import_url.mergePath)(this._basePath, path);
180
176
  return subApp;
181
177
  }
182
- showRoutes() {
183
- const length = 8;
184
- this.routes.map((route) => {
185
- console.log(
186
- `\x1B[32m${route.method}\x1B[0m ${" ".repeat(length - route.method.length)} ${route.path}`
187
- );
188
- });
189
- }
190
178
  mount(path, applicationHandler, optionHandler) {
191
179
  const mergedPath = (0, import_url.mergePath)(this._basePath, path);
192
180
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
@@ -213,10 +201,6 @@ const _Hono = class extends defineDynamicClass() {
213
201
  this.addRoute(import_router.METHOD_NAME_ALL, (0, import_url.mergePath)(path, "*"), handler);
214
202
  return this;
215
203
  }
216
- get routerName() {
217
- this.matchRoute("GET", "/");
218
- return this.router.name;
219
- }
220
204
  addRoute(method, path, handler) {
221
205
  method = method.toUpperCase();
222
206
  path = (0, import_url.mergePath)(this._basePath, path);
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var dom_exports = {};
20
+ __export(dom_exports, {
21
+ UpdatePhase: () => UpdatePhase,
22
+ invokeUpdate: () => invokeUpdate,
23
+ nodeMap: () => nodeMap,
24
+ render: () => render,
25
+ unloadCallbacks: () => unloadCallbacks,
26
+ updateCallbacks: () => updateCallbacks,
27
+ updateStack: () => updateStack
28
+ });
29
+ module.exports = __toCommonJS(dom_exports);
30
+ var import__ = require("..");
31
+ var import_html = require("../../utils/html");
32
+ const nodeMap = /* @__PURE__ */ new WeakMap();
33
+ const updateCallbacks = /* @__PURE__ */ new WeakMap();
34
+ const unloadCallbacks = /* @__PURE__ */ new WeakMap();
35
+ const UpdatePhase = {
36
+ Updating: 1,
37
+ UpdateAgain: 2,
38
+ Done: 3
39
+ };
40
+ const updateStack = [];
41
+ const getContextNode = (container, node, nth) => {
42
+ const nodes = nodeMap.get(container);
43
+ if (!nodes) {
44
+ return;
45
+ }
46
+ return (node.key ? nodes.find(([n]) => n.key === node.key) : nodes.find(([n]) => n === node)) || nodes.filter(([n]) => n.tag === node.tag)[nth];
47
+ };
48
+ const removeElement = (element) => {
49
+ if (!element) {
50
+ return;
51
+ }
52
+ for (const callback of unloadCallbacks.get(element) || []) {
53
+ callback();
54
+ }
55
+ element.remove();
56
+ };
57
+ const invokeUpdate = (updateData) => {
58
+ const [update, , , getContextNode2] = updateData;
59
+ updateData[2] = UpdatePhase.Updating;
60
+ updateStack.push(updateData);
61
+ do {
62
+ updateData[1] = 0;
63
+ update();
64
+ } while (updateData[2] === UpdatePhase.UpdateAgain);
65
+ updateData[2] = UpdatePhase.Done;
66
+ const callbacks = updateCallbacks.get(update);
67
+ if (callbacks) {
68
+ updateCallbacks.set(update, []);
69
+ for (const callback of callbacks) {
70
+ const unload = callback();
71
+ if (unload) {
72
+ const el = getContextNode2()?.[2];
73
+ if (el) {
74
+ unloadCallbacks.set(el, [...unloadCallbacks.get(el) || [], unload]);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ updateStack.pop();
80
+ };
81
+ const mount = (node, container, nth = 0, replaceElement) => {
82
+ if (typeof node === "boolean" || node === null || node === void 0) {
83
+ removeElement(replaceElement);
84
+ return;
85
+ }
86
+ if (Array.isArray(node)) {
87
+ const tagCounter2 = /* @__PURE__ */ new Map();
88
+ node.forEach((child) => {
89
+ const nth2 = tagCounter2.get(child.tag) || 0;
90
+ tagCounter2.set(child.tag, nth2 + 1);
91
+ mount(child, container, nth2);
92
+ });
93
+ return;
94
+ }
95
+ const { tag, props, children } = node;
96
+ let nodes = nodeMap.get(container);
97
+ if (typeof tag === "function") {
98
+ let contextNode = getContextNode(container, node, nth);
99
+ const update = () => {
100
+ const res = tag.call(null, {
101
+ ...props,
102
+ children: children.length <= 1 ? children[0] : children
103
+ });
104
+ if (res instanceof import__.JSXNode) {
105
+ if (contextNode) {
106
+ patch(contextNode[1], res, contextNode[2], nth);
107
+ contextNode[1] = res;
108
+ } else {
109
+ contextNode = [node, res, void 0];
110
+ if (!nodes) {
111
+ nodes = [];
112
+ nodeMap.set(container, nodes);
113
+ }
114
+ nodes.push(contextNode);
115
+ mount(res, container, nth, replaceElement);
116
+ }
117
+ return;
118
+ } else if (typeof res === "string") {
119
+ const el2 = document.createTextNode(res);
120
+ container.appendChild(el2);
121
+ return;
122
+ } else {
123
+ const wrap = document.createElement("div");
124
+ wrap.innerHTML = res;
125
+ wrap.childNodes.forEach((child) => {
126
+ container.appendChild(child);
127
+ });
128
+ }
129
+ };
130
+ const updateData = [update, 0, UpdatePhase.Updating, () => contextNode];
131
+ invokeUpdate(updateData);
132
+ return;
133
+ }
134
+ const el = document.createElement(tag);
135
+ for (const [key, value] of Object.entries(node.props)) {
136
+ if (key === "ref") {
137
+ if (typeof value === "function") {
138
+ value(el);
139
+ } else {
140
+ value.current = el;
141
+ }
142
+ } else if (key.startsWith("on")) {
143
+ const eventName = key.slice(2).toLowerCase();
144
+ el.addEventListener(eventName, value);
145
+ } else if (value instanceof Promise) {
146
+ value.then((v) => {
147
+ const callbacks = v.callbacks;
148
+ if (callbacks) {
149
+ callbacks.forEach(
150
+ (c) => c({
151
+ phase: import_html.HtmlEscapedCallbackPhase.BeforeDom,
152
+ context: {}
153
+ })
154
+ );
155
+ }
156
+ container.setAttribute(key, v);
157
+ });
158
+ } else {
159
+ el.setAttribute(key, value);
160
+ }
161
+ }
162
+ const tagCounter = /* @__PURE__ */ new Map();
163
+ for (const child of node.children) {
164
+ if (typeof child === "string" || typeof child === "number") {
165
+ el.appendChild(document.createTextNode(child.toString()));
166
+ } else if (child instanceof import__.JSXNode) {
167
+ const nth2 = tagCounter.get(child.tag) || 0;
168
+ tagCounter.set(child.tag, nth2 + 1);
169
+ mount(child, el, nth2);
170
+ } else {
171
+ mount(child, el, nth);
172
+ }
173
+ }
174
+ if (nodes) {
175
+ for (const node2 of nodes) {
176
+ node2[2] || (node2[2] = el);
177
+ }
178
+ }
179
+ if (replaceElement) {
180
+ if (nodes) {
181
+ nodes = nodes.filter(([, , oldReplaceElement]) => oldReplaceElement !== replaceElement);
182
+ nodeMap.set(container, nodes);
183
+ }
184
+ container.replaceChild(el, replaceElement);
185
+ } else {
186
+ container.appendChild(el);
187
+ }
188
+ };
189
+ const patchChildren = (oldChildren, newChildren, container) => {
190
+ oldChildren = oldChildren.flat();
191
+ newChildren = newChildren.flat();
192
+ if (newChildren.some((child) => child && child.key !== void 0)) {
193
+ newChildren.forEach((newChild, i) => {
194
+ const oldChild = oldChildren[i];
195
+ if (oldChild === void 0) {
196
+ return;
197
+ }
198
+ if (newChild instanceof import__.JSXNode) {
199
+ if (!newChild.key) {
200
+ return;
201
+ }
202
+ if (oldChild instanceof import__.JSXNode) {
203
+ if (!oldChild.key || newChild.key === oldChild.key) {
204
+ return;
205
+ }
206
+ const oldChildIndex = oldChildren.findIndex(
207
+ (child) => child.key === newChild.key
208
+ );
209
+ if (oldChildIndex !== -1) {
210
+ const oldChild2 = oldChildren[oldChildIndex];
211
+ oldChildren[oldChildIndex] = oldChildren[i];
212
+ oldChildren[i] = oldChild2;
213
+ const oldChildNode = container.childNodes[oldChildIndex];
214
+ container.insertBefore(oldChildNode, container.childNodes[i]);
215
+ return;
216
+ }
217
+ }
218
+ }
219
+ });
220
+ }
221
+ const length = Math.max(oldChildren.length, newChildren.length);
222
+ const tagCounter = /* @__PURE__ */ new Map();
223
+ for (let i = 0, j = 0; i < length; i++, j++) {
224
+ const newChild = newChildren[i];
225
+ if (typeof newChild === "boolean" || newChild === null || newChild === void 0) {
226
+ removeElement(container.childNodes[j]);
227
+ j--;
228
+ continue;
229
+ }
230
+ let nth = 0;
231
+ if (newChild instanceof import__.JSXNode) {
232
+ nth = tagCounter.get(newChild.tag) || 0;
233
+ tagCounter.set(newChild.tag, nth + 1);
234
+ }
235
+ if (oldChildren[i] === void 0) {
236
+ if (typeof newChildren[i] === "string" || typeof newChildren[i] === "number") {
237
+ container.appendChild(document.createTextNode(newChildren[i].toString()));
238
+ } else {
239
+ mount(newChildren[i], container, nth);
240
+ }
241
+ } else {
242
+ if (typeof newChildren[i] === "string" || typeof newChildren[i] === "number") {
243
+ container.replaceChild(
244
+ document.createTextNode(newChildren[i].toString()),
245
+ container.childNodes[i]
246
+ );
247
+ } else {
248
+ if (Array.isArray(oldChildren[i]) && Array.isArray(newChildren[i])) {
249
+ patchChildren(oldChildren[i], newChildren[i], container);
250
+ } else {
251
+ patch(
252
+ oldChildren[i],
253
+ newChildren[i],
254
+ container.childNodes[j],
255
+ nth
256
+ );
257
+ }
258
+ }
259
+ }
260
+ }
261
+ };
262
+ const patch = (oldNode, newNode, container, nth) => {
263
+ if (typeof oldNode.tag === "function") {
264
+ const contextNode = nodeMap.get(container.parentElement)?.find(([n]) => n === oldNode);
265
+ const replaceElement = contextNode?.[2];
266
+ if (typeof newNode.tag === "function") {
267
+ if (oldNode.tag !== newNode.tag) {
268
+ mount(newNode, container.parentElement, nth, replaceElement);
269
+ return;
270
+ }
271
+ if (contextNode) {
272
+ const { tag, props, children } = newNode;
273
+ const res = tag.call(null, {
274
+ ...props,
275
+ children: children.length <= 1 ? children[0] : children
276
+ });
277
+ patch(contextNode[1], res, contextNode[2], 0);
278
+ contextNode[1] = res;
279
+ } else {
280
+ mount(newNode, container.parentElement, nth, replaceElement);
281
+ }
282
+ return;
283
+ } else {
284
+ mount(newNode, container.parentElement, nth, replaceElement);
285
+ return;
286
+ }
287
+ }
288
+ if (oldNode.tag !== newNode.tag) {
289
+ mount(newNode, container.parentElement, nth, container);
290
+ return;
291
+ }
292
+ for (const [key, value] of Object.entries(newNode.props)) {
293
+ if (oldNode.props[key] !== value) {
294
+ if (key === "ref") {
295
+ if (typeof value === "function") {
296
+ value(container);
297
+ } else {
298
+ value.current = container;
299
+ }
300
+ } else if (key.startsWith("on")) {
301
+ const eventName = key.slice(2).toLowerCase();
302
+ container.removeEventListener(eventName, oldNode.props[key]);
303
+ container.addEventListener(eventName, value);
304
+ } else if (value instanceof Promise) {
305
+ value.then((v) => {
306
+ const callbacks = v.callbacks;
307
+ if (callbacks) {
308
+ callbacks.forEach(
309
+ (c) => c({
310
+ phase: import_html.HtmlEscapedCallbackPhase.BeforeDom,
311
+ context: {}
312
+ })
313
+ );
314
+ }
315
+ container.setAttribute(key, v);
316
+ });
317
+ } else {
318
+ container.setAttribute(key, value);
319
+ }
320
+ }
321
+ }
322
+ for (const [key, value] of Object.entries(oldNode.props)) {
323
+ if (!(key in newNode.props)) {
324
+ if (key === "ref") {
325
+ if (typeof value === "function") {
326
+ value(null);
327
+ } else {
328
+ value.current = null;
329
+ }
330
+ } else if (key.startsWith("on")) {
331
+ const eventName = key.slice(2).toLowerCase();
332
+ container.removeEventListener(eventName, value);
333
+ } else {
334
+ container.removeAttribute(key);
335
+ }
336
+ }
337
+ }
338
+ patchChildren(oldNode.children, newNode.children, container);
339
+ };
340
+ const render = (node, container) => {
341
+ if (!(node instanceof import__.JSXNode)) {
342
+ throw new Error("Invalid node");
343
+ }
344
+ mount(node, container);
345
+ };
346
+ // Annotate the CommonJS export names for ESM import in node:
347
+ 0 && (module.exports = {
348
+ UpdatePhase,
349
+ invokeUpdate,
350
+ nodeMap,
351
+ render,
352
+ unloadCallbacks,
353
+ updateCallbacks,
354
+ updateStack
355
+ });