hono 4.0.10 → 4.1.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 (109) hide show
  1. package/dist/adapter/aws-lambda/handler.js +1 -1
  2. package/dist/adapter/bun/index.js +2 -0
  3. package/dist/adapter/bun/websocket.js +77 -0
  4. package/dist/adapter/cloudflare-workers/index.js +3 -1
  5. package/dist/adapter/cloudflare-workers/websocket.js +57 -0
  6. package/dist/adapter/deno/index.js +3 -1
  7. package/dist/adapter/deno/websocket.js +29 -0
  8. package/dist/adapter/lambda-edge/handler.js +1 -1
  9. package/dist/cjs/adapter/aws-lambda/handler.js +1 -1
  10. package/dist/cjs/adapter/bun/index.js +3 -0
  11. package/dist/cjs/adapter/bun/websocket.js +98 -0
  12. package/dist/cjs/adapter/cloudflare-workers/index.js +5 -2
  13. package/dist/cjs/adapter/cloudflare-workers/websocket.js +80 -0
  14. package/dist/cjs/adapter/deno/index.js +5 -2
  15. package/dist/cjs/adapter/deno/websocket.js +52 -0
  16. package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
  17. package/dist/cjs/client/client.js +68 -61
  18. package/dist/cjs/context.js +164 -188
  19. package/dist/cjs/helper/adapter/index.js +1 -1
  20. package/dist/cjs/helper/cookie/index.js +48 -8
  21. package/dist/cjs/helper/dev/index.js +3 -4
  22. package/dist/cjs/helper/factory/index.js +1 -3
  23. package/dist/cjs/helper/ssg/index.js +9 -159
  24. package/dist/cjs/helper/ssg/middleware.js +57 -0
  25. package/dist/cjs/helper/ssg/ssg.js +212 -0
  26. package/dist/cjs/helper/websocket/index.js +32 -0
  27. package/dist/cjs/helper.js +1 -0
  28. package/dist/cjs/hono-base.js +46 -65
  29. package/dist/cjs/http-exception.js +3 -1
  30. package/dist/cjs/jsx/base.js +7 -2
  31. package/dist/cjs/jsx/components.js +1 -1
  32. package/dist/cjs/jsx/dom/index.js +45 -3
  33. package/dist/cjs/jsx/dom/render.js +6 -6
  34. package/dist/cjs/jsx/hooks/index.js +25 -16
  35. package/dist/cjs/jsx/index.js +34 -2
  36. package/dist/cjs/middleware/body-limit/index.js +80 -0
  37. package/dist/cjs/middleware/logger/index.js +9 -7
  38. package/dist/cjs/request.js +29 -48
  39. package/dist/cjs/router/linear-router/router.js +3 -5
  40. package/dist/cjs/router/pattern-router/router.js +2 -4
  41. package/dist/cjs/router/reg-exp-router/node.js +3 -3
  42. package/dist/cjs/router/reg-exp-router/router.js +11 -12
  43. package/dist/cjs/router/reg-exp-router/trie.js +2 -4
  44. package/dist/cjs/router/smart-router/router.js +3 -3
  45. package/dist/cjs/router/trie-router/node.js +6 -2
  46. package/dist/cjs/router/trie-router/router.js +2 -1
  47. package/dist/cjs/test-utils/setup-vitest.js +2 -0
  48. package/dist/cjs/utils/color.js +32 -0
  49. package/dist/cjs/utils/concurrent.js +62 -0
  50. package/dist/cjs/utils/cookie.js +28 -1
  51. package/dist/cjs/utils/stream.js +5 -1
  52. package/dist/cjs/utils/url.js +2 -2
  53. package/dist/client/client.js +68 -61
  54. package/dist/context.js +164 -189
  55. package/dist/helper/adapter/index.js +1 -1
  56. package/dist/helper/cookie/index.js +48 -8
  57. package/dist/helper/dev/index.js +3 -4
  58. package/dist/helper/factory/index.js +1 -3
  59. package/dist/helper/ssg/index.js +3 -151
  60. package/dist/helper/ssg/middleware.js +29 -0
  61. package/dist/helper/ssg/ssg.js +187 -0
  62. package/dist/helper/websocket/index.js +9 -0
  63. package/dist/helper.js +1 -0
  64. package/dist/hono-base.js +45 -65
  65. package/dist/http-exception.js +3 -1
  66. package/dist/jsx/base.js +7 -2
  67. package/dist/jsx/components.js +1 -1
  68. package/dist/jsx/dom/index.js +44 -4
  69. package/dist/jsx/dom/render.js +6 -6
  70. package/dist/jsx/hooks/index.js +23 -16
  71. package/dist/jsx/index.js +34 -3
  72. package/dist/middleware/body-limit/index.js +57 -0
  73. package/dist/middleware/logger/index.js +9 -7
  74. package/dist/request.js +29 -49
  75. package/dist/router/linear-router/router.js +3 -5
  76. package/dist/router/pattern-router/router.js +2 -4
  77. package/dist/router/reg-exp-router/node.js +3 -3
  78. package/dist/router/reg-exp-router/router.js +11 -12
  79. package/dist/router/reg-exp-router/trie.js +2 -4
  80. package/dist/router/smart-router/router.js +3 -3
  81. package/dist/router/trie-router/node.js +6 -2
  82. package/dist/router/trie-router/router.js +2 -1
  83. package/dist/test-utils/setup-vitest.js +2 -0
  84. package/dist/types/adapter/bun/index.d.ts +1 -0
  85. package/dist/types/adapter/bun/websocket.d.ts +26 -0
  86. package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
  87. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -0
  88. package/dist/types/adapter/deno/index.d.ts +1 -0
  89. package/dist/types/adapter/deno/websocket.d.ts +2 -0
  90. package/dist/types/client/types.d.ts +9 -0
  91. package/dist/types/helper/cookie/index.d.ts +3 -1
  92. package/dist/types/helper/ssg/index.d.ts +2 -105
  93. package/dist/types/helper/ssg/middleware.d.ts +38 -0
  94. package/dist/types/helper/ssg/ssg.d.ts +70 -0
  95. package/dist/types/helper/websocket/index.d.ts +34 -0
  96. package/dist/types/http-exception.d.ts +1 -0
  97. package/dist/types/jsx/dom/index.d.ts +40 -7
  98. package/dist/types/jsx/hooks/index.d.ts +2 -0
  99. package/dist/types/jsx/index.d.ts +41 -5
  100. package/dist/types/middleware/body-limit/index.d.ts +28 -0
  101. package/dist/types/utils/color.d.ts +1 -0
  102. package/dist/types/utils/concurrent.d.ts +7 -0
  103. package/dist/types/utils/cookie.d.ts +2 -0
  104. package/dist/utils/color.js +9 -0
  105. package/dist/utils/concurrent.js +39 -0
  106. package/dist/utils/cookie.js +28 -1
  107. package/dist/utils/stream.js +5 -1
  108. package/dist/utils/url.js +2 -2
  109. package/package.json +18 -2
@@ -0,0 +1,29 @@
1
+ // src/helper/ssg/middleware.ts
2
+ var SSG_CONTEXT = "HONO_SSG_CONTEXT";
3
+ var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
4
+ var ssgParams = (params) => async (c, next) => {
5
+ ;
6
+ c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
7
+ await next();
8
+ };
9
+ var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
10
+ var disableSSG = () => async function disableSSG2(c, next) {
11
+ if (isSSGContext(c)) {
12
+ return SSG_DISABLED_RESPONSE;
13
+ }
14
+ await next();
15
+ };
16
+ var onlySSG = () => async function onlySSG2(c, next) {
17
+ if (!isSSGContext(c)) {
18
+ return c.notFound();
19
+ }
20
+ await next();
21
+ };
22
+ export {
23
+ SSG_CONTEXT,
24
+ SSG_DISABLED_RESPONSE,
25
+ disableSSG,
26
+ isSSGContext,
27
+ onlySSG,
28
+ ssgParams
29
+ };
@@ -0,0 +1,187 @@
1
+ // src/helper/ssg/ssg.ts
2
+ import { replaceUrlParam } from "../../client/utils.js";
3
+ import { createPool } from "../../utils/concurrent.js";
4
+ import { getExtension } from "../../utils/mime.js";
5
+ import { SSG_DISABLED_RESPONSE, SSG_CONTEXT } from "./middleware.js";
6
+ import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
7
+ var DEFAULT_CONCURRENCY = 2;
8
+ var generateFilePath = (routePath, outDir, mimeType) => {
9
+ const extension = determineExtension(mimeType);
10
+ if (routePath.endsWith(`.${extension}`)) {
11
+ return joinPaths(outDir, routePath);
12
+ }
13
+ if (routePath === "/") {
14
+ return joinPaths(outDir, `index.${extension}`);
15
+ }
16
+ if (routePath.endsWith("/")) {
17
+ return joinPaths(outDir, routePath, `index.${extension}`);
18
+ }
19
+ return joinPaths(outDir, `${routePath}.${extension}`);
20
+ };
21
+ var parseResponseContent = async (response) => {
22
+ const contentType = response.headers.get("Content-Type");
23
+ try {
24
+ if (contentType?.includes("text") || contentType?.includes("json")) {
25
+ return await response.text();
26
+ } else {
27
+ return await response.arrayBuffer();
28
+ }
29
+ } catch (error) {
30
+ throw new Error(
31
+ `Error processing response: ${error instanceof Error ? error.message : "Unknown error"}`
32
+ );
33
+ }
34
+ };
35
+ var determineExtension = (mimeType) => {
36
+ switch (mimeType) {
37
+ case "text/html":
38
+ return "html";
39
+ case "text/xml":
40
+ case "application/xml":
41
+ return "xml";
42
+ default: {
43
+ return getExtension(mimeType) || "html";
44
+ }
45
+ }
46
+ };
47
+ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, concurrency) {
48
+ const baseURL = "http://localhost";
49
+ const pool = createPool({ concurrency });
50
+ for (const route of filterStaticGenerateRoutes(app)) {
51
+ const thisRouteBaseURL = new URL(route.path, baseURL).toString();
52
+ let forGetInfoURLRequest = new Request(thisRouteBaseURL);
53
+ if (beforeRequestHook) {
54
+ const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
55
+ if (!maybeRequest) {
56
+ continue;
57
+ }
58
+ forGetInfoURLRequest = maybeRequest;
59
+ }
60
+ yield new Promise(async (resolveGetInfo, rejectGetInfo) => {
61
+ try {
62
+ await pool.run(() => app.fetch(forGetInfoURLRequest));
63
+ if (!forGetInfoURLRequest.ssgParams) {
64
+ if (isDynamicRoute(route.path)) {
65
+ resolveGetInfo(void 0);
66
+ return;
67
+ }
68
+ forGetInfoURLRequest.ssgParams = [{}];
69
+ }
70
+ const requestInit = {
71
+ method: forGetInfoURLRequest.method,
72
+ headers: forGetInfoURLRequest.headers
73
+ };
74
+ resolveGetInfo(
75
+ function* () {
76
+ for (const param of forGetInfoURLRequest.ssgParams) {
77
+ yield new Promise(async (resolveReq, rejectReq) => {
78
+ try {
79
+ const replacedUrlParam = replaceUrlParam(route.path, param);
80
+ let response = await pool.run(
81
+ () => app.request(replacedUrlParam, requestInit, {
82
+ [SSG_CONTEXT]: true
83
+ })
84
+ );
85
+ if (response === SSG_DISABLED_RESPONSE) {
86
+ resolveReq(void 0);
87
+ return;
88
+ }
89
+ if (afterResponseHook) {
90
+ const maybeResponse = afterResponseHook(response);
91
+ if (!maybeResponse) {
92
+ resolveReq(void 0);
93
+ return;
94
+ }
95
+ response = maybeResponse;
96
+ }
97
+ const mimeType = response.headers.get("Content-Type")?.split(";")[0] || "text/plain";
98
+ const content = await parseResponseContent(response);
99
+ resolveReq({
100
+ routePath: replacedUrlParam,
101
+ mimeType,
102
+ content
103
+ });
104
+ } catch (error) {
105
+ rejectReq(error);
106
+ }
107
+ });
108
+ }
109
+ }()
110
+ );
111
+ } catch (error) {
112
+ rejectGetInfo(error);
113
+ }
114
+ });
115
+ }
116
+ };
117
+ var isDynamicRoute = (path) => {
118
+ return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
119
+ };
120
+ var createdDirs = /* @__PURE__ */ new Set();
121
+ var saveContentToFile = async (data, fsModule, outDir) => {
122
+ const awaitedData = await data;
123
+ if (!awaitedData) {
124
+ return;
125
+ }
126
+ const { routePath, content, mimeType } = awaitedData;
127
+ const filePath = generateFilePath(routePath, outDir, mimeType);
128
+ const dirPath = dirname(filePath);
129
+ if (!createdDirs.has(dirPath)) {
130
+ await fsModule.mkdir(dirPath, { recursive: true });
131
+ createdDirs.add(dirPath);
132
+ }
133
+ if (typeof content === "string") {
134
+ await fsModule.writeFile(filePath, content);
135
+ } else if (content instanceof ArrayBuffer) {
136
+ await fsModule.writeFile(filePath, new Uint8Array(content));
137
+ }
138
+ return filePath;
139
+ };
140
+ var toSSG = async (app, fs, options) => {
141
+ let result = void 0;
142
+ const getInfoPromises = [];
143
+ const savePromises = [];
144
+ try {
145
+ const outputDir = options?.dir ?? "./static";
146
+ const concurrency = options?.concurrency ?? DEFAULT_CONCURRENCY;
147
+ const getInfoGen = fetchRoutesContent(
148
+ app,
149
+ options?.beforeRequestHook,
150
+ options?.afterResponseHook,
151
+ concurrency
152
+ );
153
+ for (const getInfo of getInfoGen) {
154
+ getInfoPromises.push(
155
+ getInfo.then((getContentGen) => {
156
+ if (!getContentGen) {
157
+ return;
158
+ }
159
+ for (const content of getContentGen) {
160
+ savePromises.push(saveContentToFile(content, fs, outputDir).catch((e) => e));
161
+ }
162
+ })
163
+ );
164
+ }
165
+ await Promise.all(getInfoPromises);
166
+ const files = [];
167
+ for (const savePromise of savePromises) {
168
+ const fileOrError = await savePromise;
169
+ if (typeof fileOrError === "string") {
170
+ files.push(fileOrError);
171
+ } else if (fileOrError) {
172
+ throw fileOrError;
173
+ }
174
+ }
175
+ result = { success: true, files };
176
+ } catch (error) {
177
+ const errorObj = error instanceof Error ? error : new Error(String(error));
178
+ result = { success: false, files: [], error: errorObj };
179
+ }
180
+ await options?.afterGenerateHook?.(result);
181
+ return result;
182
+ };
183
+ export {
184
+ fetchRoutesContent,
185
+ saveContentToFile,
186
+ toSSG
187
+ };
@@ -0,0 +1,9 @@
1
+ // src/helper/websocket/index.ts
2
+ var createWSMessageEvent = (source) => {
3
+ return new MessageEvent("message", {
4
+ data: source
5
+ });
6
+ };
7
+ export {
8
+ createWSMessageEvent
9
+ };
package/dist/helper.js CHANGED
@@ -9,3 +9,4 @@ export * from "./helper/streaming/index.js";
9
9
  export * from "./helper/testing/index.js";
10
10
  export * from "./helper/dev/index.js";
11
11
  export * from "./adapter/deno/ssg.js";
12
+ export * from "./adapter/deno/websocket.js";
package/dist/hono-base.js CHANGED
@@ -1,22 +1,3 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
-
20
1
  // src/hono-base.ts
21
2
  import { compose } from "./compose.js";
22
3
  import { Context } from "./context.js";
@@ -39,54 +20,25 @@ var errorHandler = (err, c) => {
39
20
  console.error(err);
40
21
  return c.text("Internal Server Error", 500);
41
22
  };
42
- var _path;
43
- var _Hono = class extends defineDynamicClass() {
23
+ var Hono = class extends defineDynamicClass() {
24
+ router;
25
+ getPath;
26
+ _basePath = "/";
27
+ #path = "/";
28
+ routes = [];
44
29
  constructor(options = {}) {
45
30
  super();
46
- this._basePath = "/";
47
- __privateAdd(this, _path, "/");
48
- this.routes = [];
49
- this.notFoundHandler = notFoundHandler;
50
- this.errorHandler = errorHandler;
51
- this.onError = (handler) => {
52
- this.errorHandler = handler;
53
- return this;
54
- };
55
- this.notFound = (handler) => {
56
- this.notFoundHandler = handler;
57
- return this;
58
- };
59
- this.fetch = (request, Env, executionCtx) => {
60
- return this.dispatch(request, executionCtx, Env, request.method);
61
- };
62
- this.request = (input, requestInit, Env, executionCtx) => {
63
- if (input instanceof Request) {
64
- if (requestInit !== void 0) {
65
- input = new Request(input, requestInit);
66
- }
67
- return this.fetch(input, Env, executionCtx);
68
- }
69
- input = input.toString();
70
- const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
71
- const req = new Request(path, requestInit);
72
- return this.fetch(req, Env, executionCtx);
73
- };
74
- this.fire = () => {
75
- addEventListener("fetch", (event) => {
76
- event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
77
- });
78
- };
79
31
  const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
80
32
  allMethods.map((method) => {
81
33
  this[method] = (args1, ...args) => {
82
34
  if (typeof args1 === "string") {
83
- __privateSet(this, _path, args1);
35
+ this.#path = args1;
84
36
  } else {
85
- this.addRoute(method, __privateGet(this, _path), args1);
37
+ this.addRoute(method, this.#path, args1);
86
38
  }
87
39
  args.map((handler) => {
88
40
  if (typeof handler !== "string") {
89
- this.addRoute(method, __privateGet(this, _path), handler);
41
+ this.addRoute(method, this.#path, handler);
90
42
  }
91
43
  });
92
44
  return this;
@@ -97,10 +49,10 @@ var _Hono = class extends defineDynamicClass() {
97
49
  return this;
98
50
  }
99
51
  for (const p of [path].flat()) {
100
- __privateSet(this, _path, p);
52
+ this.#path = p;
101
53
  for (const m of [method].flat()) {
102
54
  handlers.map((handler) => {
103
- this.addRoute(m.toUpperCase(), __privateGet(this, _path), handler);
55
+ this.addRoute(m.toUpperCase(), this.#path, handler);
104
56
  });
105
57
  }
106
58
  }
@@ -108,13 +60,13 @@ var _Hono = class extends defineDynamicClass() {
108
60
  };
109
61
  this.use = (arg1, ...handlers) => {
110
62
  if (typeof arg1 === "string") {
111
- __privateSet(this, _path, arg1);
63
+ this.#path = arg1;
112
64
  } else {
113
- __privateSet(this, _path, "*");
65
+ this.#path = "*";
114
66
  handlers.unshift(arg1);
115
67
  }
116
68
  handlers.map((handler) => {
117
- this.addRoute(METHOD_NAME_ALL, __privateGet(this, _path), handler);
69
+ this.addRoute(METHOD_NAME_ALL, this.#path, handler);
118
70
  });
119
71
  return this;
120
72
  };
@@ -124,13 +76,15 @@ var _Hono = class extends defineDynamicClass() {
124
76
  this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
125
77
  }
126
78
  clone() {
127
- const clone = new _Hono({
79
+ const clone = new Hono({
128
80
  router: this.router,
129
81
  getPath: this.getPath
130
82
  });
131
83
  clone.routes = this.routes;
132
84
  return clone;
133
85
  }
86
+ notFoundHandler = notFoundHandler;
87
+ errorHandler = errorHandler;
134
88
  route(path, app) {
135
89
  const subApp = this.basePath(path);
136
90
  if (!app) {
@@ -153,6 +107,14 @@ var _Hono = class extends defineDynamicClass() {
153
107
  subApp._basePath = mergePath(this._basePath, path);
154
108
  return subApp;
155
109
  }
110
+ onError = (handler) => {
111
+ this.errorHandler = handler;
112
+ return this;
113
+ };
114
+ notFound = (handler) => {
115
+ this.notFoundHandler = handler;
116
+ return this;
117
+ };
156
118
  mount(path, applicationHandler, optionHandler) {
157
119
  const mergedPath = mergePath(this._basePath, path);
158
120
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
@@ -235,9 +197,27 @@ var _Hono = class extends defineDynamicClass() {
235
197
  }
236
198
  })();
237
199
  }
200
+ fetch = (request, Env, executionCtx) => {
201
+ return this.dispatch(request, executionCtx, Env, request.method);
202
+ };
203
+ request = (input, requestInit, Env, executionCtx) => {
204
+ if (input instanceof Request) {
205
+ if (requestInit !== void 0) {
206
+ input = new Request(input, requestInit);
207
+ }
208
+ return this.fetch(input, Env, executionCtx);
209
+ }
210
+ input = input.toString();
211
+ const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
212
+ const req = new Request(path, requestInit);
213
+ return this.fetch(req, Env, executionCtx);
214
+ };
215
+ fire = () => {
216
+ addEventListener("fetch", (event) => {
217
+ event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
218
+ });
219
+ };
238
220
  };
239
- var Hono = _Hono;
240
- _path = new WeakMap();
241
221
  export {
242
222
  COMPOSED_HANDLER,
243
223
  Hono as HonoBase
@@ -1,7 +1,9 @@
1
1
  // src/http-exception.ts
2
2
  var HTTPException = class extends Error {
3
+ res;
4
+ status;
3
5
  constructor(status = 500, options) {
4
- super(options?.message);
6
+ super(options?.message, { cause: options?.cause });
5
7
  this.res = options?.res;
6
8
  this.status = status;
7
9
  }
package/dist/jsx/base.js CHANGED
@@ -67,8 +67,13 @@ var childrenToStringToBuffer = (children, buffer) => {
67
67
  }
68
68
  };
69
69
  var JSXNode = class {
70
+ tag;
71
+ props;
72
+ key;
73
+ children;
74
+ isEscaped = true;
75
+ localContexts;
70
76
  constructor(tag, props, children) {
71
- this.isEscaped = true;
72
77
  this.tag = tag;
73
78
  this.props = props;
74
79
  this.children = children;
@@ -220,7 +225,7 @@ var memo = (component, propsAreEqual = shallowEqual) => {
220
225
  computed = void 0;
221
226
  }
222
227
  prevProps = props;
223
- return computed || (computed = component(props));
228
+ return computed ||= component(props);
224
229
  };
225
230
  };
226
231
  var Fragment = ({
@@ -42,7 +42,7 @@ var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
42
42
  }
43
43
  }
44
44
  if (resArray.some((res) => res instanceof Promise)) {
45
- fallbackStr || (fallbackStr = await fallback?.toString());
45
+ fallbackStr ||= await fallback?.toString();
46
46
  const index = errorBoundaryCounter++;
47
47
  const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
48
48
  const caught = false;
@@ -1,4 +1,6 @@
1
1
  // src/jsx/dom/index.ts
2
+ import { memo, isValidElement } from "../base.js";
3
+ import { useContext } from "../context.js";
2
4
  import {
3
5
  useState,
4
6
  useEffect,
@@ -11,14 +13,23 @@ import {
11
13
  startViewTransition,
12
14
  useViewTransition,
13
15
  useMemo,
14
- useLayoutEffect
16
+ useLayoutEffect,
17
+ useReducer,
18
+ useDebugValue
15
19
  } from "../hooks/index.js";
16
- import { render } from "./render.js";
17
20
  import { Suspense, ErrorBoundary } from "./components.js";
18
- import { useContext } from "../context.js";
19
21
  import { createContext } from "./context.js";
20
- import { memo, isValidElement } from "../base.js";
21
22
  import { jsx } from "./jsx-runtime.js";
23
+ import { render } from "./render.js";
24
+ var createElement = (tag, props, ...children) => {
25
+ const jsxProps = { ...props, children };
26
+ let key = void 0;
27
+ if ("key" in jsxProps) {
28
+ key = jsxProps.key;
29
+ delete jsxProps.key;
30
+ }
31
+ return jsx(tag, jsxProps, key);
32
+ };
22
33
  var cloneElement = (element, props, ...children) => {
23
34
  return jsx(
24
35
  element.tag,
@@ -30,12 +41,39 @@ var cloneElement = (element, props, ...children) => {
30
41
  element.key
31
42
  );
32
43
  };
44
+ var dom_default = {
45
+ useState,
46
+ useEffect,
47
+ useRef,
48
+ useCallback,
49
+ use,
50
+ startTransition,
51
+ useTransition,
52
+ useDeferredValue,
53
+ startViewTransition,
54
+ useViewTransition,
55
+ useMemo,
56
+ useLayoutEffect,
57
+ useReducer,
58
+ useDebugValue,
59
+ Suspense,
60
+ ErrorBoundary,
61
+ createContext,
62
+ useContext,
63
+ memo,
64
+ isValidElement,
65
+ createElement,
66
+ cloneElement
67
+ };
33
68
  export {
34
69
  ErrorBoundary,
35
70
  Suspense,
36
71
  cloneElement,
37
72
  createContext,
73
+ createElement,
74
+ dom_default as default,
38
75
  isValidElement,
76
+ createElement as jsx,
39
77
  memo,
40
78
  render,
41
79
  startTransition,
@@ -43,10 +81,12 @@ export {
43
81
  use,
44
82
  useCallback,
45
83
  useContext,
84
+ useDebugValue,
46
85
  useDeferredValue,
47
86
  useEffect,
48
87
  useLayoutEffect,
49
88
  useMemo,
89
+ useReducer,
50
90
  useRef,
51
91
  useState,
52
92
  useTransition,
@@ -23,7 +23,7 @@ var getEventSpec = (key) => {
23
23
  return void 0;
24
24
  };
25
25
  var applyProps = (container, attributes, oldAttributes) => {
26
- attributes || (attributes = {});
26
+ attributes ||= {};
27
27
  for (const [key, value] of Object.entries(attributes)) {
28
28
  if (!oldAttributes || oldAttributes[key] !== value) {
29
29
  const eventSpec = getEventSpec(key);
@@ -205,9 +205,9 @@ var applyNodeObject = (node, container) => {
205
205
  child.e.textContent = child[0];
206
206
  }
207
207
  child[1] = false;
208
- el = child.e || (child.e = document.createTextNode(child[0]));
208
+ el = child.e ||= document.createTextNode(child[0]);
209
209
  } else {
210
- el = child.e || (child.e = child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag));
210
+ el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
211
211
  applyProps(el, child.props, child.pP);
212
212
  applyNode(child, el);
213
213
  }
@@ -226,10 +226,10 @@ var build = (context, node, topLevelErrorHandlerNode, children) => {
226
226
  return;
227
227
  }
228
228
  let errorHandler;
229
- children || (children = typeof node.tag == "function" ? invokeTag(context, node) : node.children);
229
+ children ||= typeof node.tag == "function" ? invokeTag(context, node) : node.children;
230
230
  if (children[0]?.tag === "") {
231
231
  errorHandler = children[0][DOM_ERROR_HANDLER];
232
- topLevelErrorHandlerNode || (topLevelErrorHandlerNode = node);
232
+ topLevelErrorHandlerNode ||= node;
233
233
  }
234
234
  const oldVChildren = node.vC ? [...node.vC] : [];
235
235
  const vChildren = [];
@@ -318,7 +318,7 @@ var buildNode = (node) => {
318
318
  if (ns) {
319
319
  ;
320
320
  node.n = ns;
321
- nameSpaceContext || (nameSpaceContext = createContext(""));
321
+ nameSpaceContext ||= createContext("");
322
322
  node.children = [
323
323
  {
324
324
  tag: nameSpaceContext.Provider,