hono 4.2.9 → 4.3.1

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 (72) hide show
  1. package/README.md +0 -13
  2. package/dist/adapter/deno/serve-static.js +1 -1
  3. package/dist/cjs/adapter/deno/serve-static.js +1 -1
  4. package/dist/cjs/client/client.js +2 -1
  5. package/dist/cjs/helper/cookie/index.js +2 -0
  6. package/dist/cjs/helper/factory/index.js +13 -1
  7. package/dist/cjs/jsx/base.js +26 -14
  8. package/dist/cjs/jsx/children.js +45 -0
  9. package/dist/cjs/jsx/constants.js +3 -0
  10. package/dist/cjs/jsx/dom/context.js +22 -11
  11. package/dist/cjs/jsx/dom/css.js +6 -4
  12. package/dist/cjs/jsx/dom/index.js +35 -4
  13. package/dist/cjs/jsx/dom/jsx-dev-runtime.js +20 -13
  14. package/dist/cjs/jsx/dom/render.js +110 -48
  15. package/dist/cjs/jsx/dom/utils.js +33 -0
  16. package/dist/cjs/jsx/hooks/index.js +41 -1
  17. package/dist/cjs/jsx/index.js +17 -1
  18. package/dist/cjs/jsx/jsx-dev-runtime.js +0 -1
  19. package/dist/cjs/jsx/utils.js +12 -2
  20. package/dist/cjs/middleware/bearer-auth/index.js +2 -1
  21. package/dist/cjs/middleware/secure-headers/index.js +58 -8
  22. package/dist/cjs/middleware/serve-static/index.js +5 -2
  23. package/dist/cjs/middleware/timing/index.js +3 -2
  24. package/dist/cjs/utils/mime.js +4 -2
  25. package/dist/client/client.js +2 -1
  26. package/dist/helper/cookie/index.js +2 -0
  27. package/dist/helper/factory/index.js +13 -1
  28. package/dist/jsx/base.js +27 -15
  29. package/dist/jsx/children.js +21 -0
  30. package/dist/jsx/constants.js +2 -0
  31. package/dist/jsx/dom/context.js +22 -11
  32. package/dist/jsx/dom/css.js +6 -4
  33. package/dist/jsx/dom/index.js +31 -5
  34. package/dist/jsx/dom/jsx-dev-runtime.js +20 -13
  35. package/dist/jsx/dom/render.js +109 -49
  36. package/dist/jsx/dom/utils.js +10 -0
  37. package/dist/jsx/hooks/index.js +37 -1
  38. package/dist/jsx/index.js +17 -2
  39. package/dist/jsx/jsx-dev-runtime.js +0 -1
  40. package/dist/jsx/utils.js +10 -1
  41. package/dist/middleware/bearer-auth/index.js +2 -1
  42. package/dist/middleware/secure-headers/index.js +57 -8
  43. package/dist/middleware/serve-static/index.js +5 -2
  44. package/dist/middleware/timing/index.js +3 -2
  45. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +6 -0
  46. package/dist/types/client/types.d.ts +44 -20
  47. package/dist/types/context.d.ts +6 -6
  48. package/dist/types/helper/cookie/index.d.ts +1 -1
  49. package/dist/types/helper/factory/index.d.ts +15 -1
  50. package/dist/types/helper/websocket/index.d.ts +1 -4
  51. package/dist/types/jsx/base.d.ts +10 -3
  52. package/dist/types/jsx/children.d.ts +9 -0
  53. package/dist/types/jsx/constants.d.ts +1 -0
  54. package/dist/types/jsx/dom/context.d.ts +1 -10
  55. package/dist/types/jsx/dom/index.d.ts +31 -11
  56. package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +3 -13
  57. package/dist/types/jsx/dom/render.d.ts +6 -4
  58. package/dist/types/jsx/dom/utils.d.ts +1 -0
  59. package/dist/types/jsx/hooks/index.d.ts +6 -0
  60. package/dist/types/jsx/index.d.ts +18 -3
  61. package/dist/types/jsx/types.d.ts +24 -1
  62. package/dist/types/jsx/utils.d.ts +1 -0
  63. package/dist/types/middleware/bearer-auth/index.d.ts +2 -0
  64. package/dist/types/middleware/secure-headers/index.d.ts +30 -21
  65. package/dist/types/middleware/serve-static/index.d.ts +2 -2
  66. package/dist/types/middleware/timing/index.d.ts +1 -1
  67. package/dist/types/request.d.ts +3 -2
  68. package/dist/types/types.d.ts +88 -63
  69. package/dist/types/utils/mime.d.ts +2 -0
  70. package/dist/types/utils/types.d.ts +3 -0
  71. package/dist/utils/mime.js +2 -1
  72. package/package.json +9 -1
@@ -20,14 +20,19 @@ var render_exports = {};
20
20
  __export(render_exports, {
21
21
  build: () => build,
22
22
  buildDataStack: () => buildDataStack,
23
+ createPortal: () => createPortal,
24
+ flushSync: () => flushSync,
23
25
  render: () => render,
24
26
  update: () => update
25
27
  });
26
28
  module.exports = __toCommonJS(render_exports);
29
+ var import_children = require("../children");
27
30
  var import_constants = require("../constants");
28
31
  var import_context = require("../context");
29
32
  var import_hooks = require("../hooks");
33
+ var import_utils = require("../utils");
30
34
  var import_context2 = require("./context");
35
+ const HONO_PORTAL_ELEMENT = "_hp";
31
36
  const eventAliasMap = {
32
37
  Change: "Input",
33
38
  DoubleClick: "DblClick"
@@ -36,9 +41,10 @@ const nameSpaceMap = {
36
41
  svg: "http://www.w3.org/2000/svg",
37
42
  math: "http://www.w3.org/1998/Math/MathML"
38
43
  };
44
+ const skipProps = /* @__PURE__ */ new Set(["children"]);
39
45
  const buildDataStack = [];
40
46
  let nameSpaceContext = void 0;
41
- const isNodeString = (node) => Array.isArray(node);
47
+ const isNodeString = (node) => "t" in node;
42
48
  const getEventSpec = (key) => {
43
49
  const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);
44
50
  if (match) {
@@ -50,30 +56,35 @@ const getEventSpec = (key) => {
50
56
  const applyProps = (container, attributes, oldAttributes) => {
51
57
  attributes ||= {};
52
58
  for (const [key, value] of Object.entries(attributes)) {
53
- if (!oldAttributes || oldAttributes[key] !== value) {
59
+ if (!skipProps.has(key) && (!oldAttributes || oldAttributes[key] !== value)) {
54
60
  const eventSpec = getEventSpec(key);
55
61
  if (eventSpec) {
56
- if (typeof value !== "function") {
57
- throw new Error(`Event handler for "${key}" is not a function`);
58
- }
59
62
  if (oldAttributes) {
60
63
  container.removeEventListener(eventSpec[0], oldAttributes[key], eventSpec[1]);
61
64
  }
62
- container.addEventListener(eventSpec[0], value, eventSpec[1]);
65
+ if (value != null) {
66
+ if (typeof value !== "function") {
67
+ throw new Error(`Event handler for "${key}" is not a function`);
68
+ }
69
+ container.addEventListener(eventSpec[0], value, eventSpec[1]);
70
+ }
63
71
  } else if (key === "dangerouslySetInnerHTML" && value) {
64
72
  container.innerHTML = value.__html;
65
73
  } else if (key === "ref") {
66
74
  if (typeof value === "function") {
67
75
  value(container);
68
- } else if ("current" in value) {
76
+ } else if (value && "current" in value) {
69
77
  value.current = container;
70
78
  }
71
79
  } else if (key === "style") {
80
+ const style = container.style;
72
81
  if (typeof value === "string") {
73
- container.style.cssText = value;
82
+ style.cssText = value;
74
83
  } else {
75
- container.style.cssText = "";
76
- Object.assign(container.style, value);
84
+ style.cssText = "";
85
+ if (value != null) {
86
+ (0, import_utils.styleObjectForEach)(value, style.setProperty.bind(style));
87
+ }
77
88
  }
78
89
  } else {
79
90
  const nodeName = container.nodeName;
@@ -110,7 +121,7 @@ const applyProps = (container, attributes, oldAttributes) => {
110
121
  }
111
122
  if (oldAttributes) {
112
123
  for (const [key, value] of Object.entries(oldAttributes)) {
113
- if (!(key in attributes)) {
124
+ if (!skipProps.has(key) && !(key in attributes)) {
114
125
  const eventSpec = getEventSpec(key);
115
126
  if (eventSpec) {
116
127
  container.removeEventListener(eventSpec[0], value, eventSpec[1]);
@@ -139,8 +150,8 @@ const invokeTag = (context, node) => {
139
150
  try {
140
151
  return [
141
152
  func.call(null, {
142
- ...node.props,
143
- children: node.children
153
+ ...func.defaultProps || {},
154
+ ...node.props
144
155
  })
145
156
  ];
146
157
  } finally {
@@ -185,21 +196,30 @@ const findInsertBefore = (node) => {
185
196
  const removeNode = (node) => {
186
197
  if (!isNodeString(node)) {
187
198
  node[import_constants.DOM_STASH]?.[1][import_hooks.STASH_EFFECT]?.forEach((data) => data[2]?.());
199
+ if (node.e && node.props?.ref) {
200
+ if (typeof node.props.ref === "function") {
201
+ node.props.ref(null);
202
+ } else {
203
+ node.props.ref.current = null;
204
+ }
205
+ }
188
206
  node.vC?.forEach(removeNode);
189
207
  }
190
- node.e?.remove();
191
- node.tag = void 0;
208
+ if (node.tag !== HONO_PORTAL_ELEMENT) {
209
+ node.e?.remove();
210
+ }
211
+ if (typeof node.tag === "function") {
212
+ updateMap.delete(node);
213
+ fallbackUpdateFnArrayMap.delete(node);
214
+ }
192
215
  };
193
216
  const apply = (node, container) => {
194
- if (node.tag === void 0) {
195
- return;
196
- }
197
217
  node.c = container;
198
218
  applyNodeObject(node, container);
199
219
  };
200
220
  const applyNode = (node, container) => {
201
221
  if (isNodeString(node)) {
202
- container.textContent = node[0];
222
+ container.textContent = node.t;
203
223
  } else {
204
224
  applyNodeObject(node, container);
205
225
  }
@@ -226,17 +246,17 @@ const applyNodeObject = (node, container) => {
226
246
  const child = next[i];
227
247
  let el;
228
248
  if (isNodeString(child)) {
229
- if (child.e && child[1]) {
230
- child.e.textContent = child[0];
249
+ if (child.e && child.d) {
250
+ child.e.textContent = child.t;
231
251
  }
232
- child[1] = false;
233
- el = child.e ||= document.createTextNode(child[0]);
252
+ child.d = false;
253
+ el = child.e ||= document.createTextNode(child.t);
234
254
  } else {
235
255
  el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
236
256
  applyProps(el, child.props, child.pP);
237
257
  applyNode(child, el);
238
258
  }
239
- if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
259
+ if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e && child.tag !== HONO_PORTAL_ELEMENT) {
240
260
  container.insertBefore(el, childNodes[offset] || null);
241
261
  }
242
262
  }
@@ -246,12 +266,10 @@ const applyNodeObject = (node, container) => {
246
266
  callbacks.forEach(([, , , cb]) => cb?.());
247
267
  });
248
268
  };
269
+ const fallbackUpdateFnArrayMap = /* @__PURE__ */ new WeakMap();
249
270
  const build = (context, node, topLevelErrorHandlerNode, children) => {
250
- if (node.tag === void 0) {
251
- return;
252
- }
253
271
  let errorHandler;
254
- children ||= typeof node.tag == "function" ? invokeTag(context, node) : node.children;
272
+ children ||= typeof node.tag == "function" ? invokeTag(context, node) : (0, import_children.toArray)(node.props.children);
255
273
  if (children[0]?.tag === "") {
256
274
  errorHandler = children[0][import_constants.DOM_ERROR_HANDLER];
257
275
  topLevelErrorHandlerNode ||= node;
@@ -268,7 +286,7 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
268
286
  prevNode.nN = child;
269
287
  }
270
288
  prevNode = child;
271
- if (typeof child.tag === "function" && import_context.globalContexts.length > 0) {
289
+ if (typeof child.tag === "function" && !child.tag[import_constants.DOM_INTERNAL_TAG] && import_context.globalContexts.length > 0) {
272
290
  child[import_constants.DOM_STASH][2] = import_context.globalContexts.map((c2) => [c2, c2.values.at(-1)]);
273
291
  }
274
292
  let oldChild;
@@ -282,9 +300,9 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
282
300
  if (!isNodeString(oldChild)) {
283
301
  vChildrenToRemove.push(oldChild);
284
302
  } else {
285
- if (oldChild[0] !== child[0]) {
286
- oldChild[0] = child[0];
287
- oldChild[1] = true;
303
+ if (oldChild.t !== child.t) {
304
+ oldChild.t = child.t;
305
+ oldChild.d = true;
288
306
  }
289
307
  child = oldChild;
290
308
  }
@@ -293,7 +311,9 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
293
311
  } else {
294
312
  oldChild.pP = oldChild.props;
295
313
  oldChild.props = child.props;
296
- oldChild.children = child.children;
314
+ if (typeof child.tag === "function") {
315
+ oldChild[import_constants.DOM_STASH][2] = child[import_constants.DOM_STASH][2] || [];
316
+ }
297
317
  child = oldChild;
298
318
  }
299
319
  } else if (!isNodeString(child) && nameSpaceContext) {
@@ -313,10 +333,20 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
313
333
  node.vR = vChildrenToRemove;
314
334
  } catch (e) {
315
335
  if (errorHandler) {
316
- const fallback = errorHandler(
317
- e,
318
- () => update([0, false, context[2]], topLevelErrorHandlerNode)
319
- );
336
+ const fallbackUpdateFn = () => update([0, false, context[2]], topLevelErrorHandlerNode);
337
+ const fallbackUpdateFnArray = fallbackUpdateFnArrayMap.get(topLevelErrorHandlerNode) || [];
338
+ fallbackUpdateFnArray.push(fallbackUpdateFn);
339
+ fallbackUpdateFnArrayMap.set(topLevelErrorHandlerNode, fallbackUpdateFnArray);
340
+ const fallback = errorHandler(e, () => {
341
+ const fnArray = fallbackUpdateFnArrayMap.get(topLevelErrorHandlerNode);
342
+ if (fnArray) {
343
+ const i = fnArray.indexOf(fallbackUpdateFn);
344
+ if (i !== -1) {
345
+ fnArray.splice(i, 1);
346
+ return fallbackUpdateFn();
347
+ }
348
+ }
349
+ });
320
350
  if (fallback) {
321
351
  if (context[0] === 1) {
322
352
  context[1] = true;
@@ -333,9 +363,12 @@ const buildNode = (node) => {
333
363
  if (node === void 0 || node === null || typeof node === "boolean") {
334
364
  return void 0;
335
365
  } else if (typeof node === "string" || typeof node === "number") {
336
- return [node.toString(), true];
366
+ return { t: node.toString(), d: true };
337
367
  } else {
338
368
  if (typeof node.tag === "function") {
369
+ if (node[import_constants.DOM_STASH]) {
370
+ node = { ...node };
371
+ }
339
372
  ;
340
373
  node[import_constants.DOM_STASH] = [0, []];
341
374
  } else {
@@ -344,13 +377,13 @@ const buildNode = (node) => {
344
377
  ;
345
378
  node.n = ns;
346
379
  nameSpaceContext ||= (0, import_context2.createContext)("");
347
- node.children = [
380
+ node.props.children = [
348
381
  {
349
382
  tag: nameSpaceContext.Provider,
350
383
  props: {
351
- value: ns
352
- },
353
- children: node.children
384
+ value: ns,
385
+ children: node.props.children
386
+ }
354
387
  }
355
388
  ];
356
389
  }
@@ -377,6 +410,7 @@ const updateSync = (context, node) => {
377
410
  }
378
411
  };
379
412
  const updateMap = /* @__PURE__ */ new WeakMap();
413
+ const currentUpdateSets = [];
380
414
  const update = async (context, node) => {
381
415
  const existing = updateMap.get(node);
382
416
  if (existing) {
@@ -397,26 +431,54 @@ const update = async (context, node) => {
397
431
  }
398
432
  }
399
433
  ]);
400
- await Promise.resolve();
401
- const latest = updateMap.get(node);
402
- if (latest) {
403
- updateMap.delete(node);
404
- latest[1]();
434
+ if (currentUpdateSets.length) {
435
+ ;
436
+ currentUpdateSets.at(-1).add(node);
437
+ } else {
438
+ await Promise.resolve();
439
+ const latest = updateMap.get(node);
440
+ if (latest) {
441
+ updateMap.delete(node);
442
+ latest[1]();
443
+ }
405
444
  }
406
445
  return promise;
407
446
  };
408
447
  const render = (jsxNode, container) => {
409
- const node = buildNode({ tag: "", children: [jsxNode] });
448
+ const node = buildNode({ tag: "", props: { children: jsxNode } });
410
449
  build([], node, void 0);
411
450
  const fragment = document.createDocumentFragment();
412
451
  apply(node, fragment);
413
452
  replaceContainer(node, fragment, container);
414
453
  container.replaceChildren(fragment);
415
454
  };
455
+ const flushSync = (callback) => {
456
+ const set = /* @__PURE__ */ new Set();
457
+ currentUpdateSets.push(set);
458
+ callback();
459
+ set.forEach((node) => {
460
+ const latest = updateMap.get(node);
461
+ if (latest) {
462
+ updateMap.delete(node);
463
+ latest[1]();
464
+ }
465
+ });
466
+ currentUpdateSets.pop();
467
+ };
468
+ const createPortal = (children, container, key) => ({
469
+ tag: HONO_PORTAL_ELEMENT,
470
+ props: {
471
+ children
472
+ },
473
+ key,
474
+ e: container
475
+ });
416
476
  // Annotate the CommonJS export names for ESM import in node:
417
477
  0 && (module.exports = {
418
478
  build,
419
479
  buildDataStack,
480
+ createPortal,
481
+ flushSync,
420
482
  render,
421
483
  update
422
484
  });
@@ -0,0 +1,33 @@
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 utils_exports = {};
20
+ __export(utils_exports, {
21
+ setInternalTagFlag: () => setInternalTagFlag
22
+ });
23
+ module.exports = __toCommonJS(utils_exports);
24
+ var import_constants = require("../constants");
25
+ const setInternalTagFlag = (fn) => {
26
+ ;
27
+ fn[import_constants.DOM_INTERNAL_TAG] = true;
28
+ return fn;
29
+ };
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ setInternalTagFlag
33
+ });
@@ -19,6 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var hooks_exports = {};
20
20
  __export(hooks_exports, {
21
21
  STASH_EFFECT: () => STASH_EFFECT,
22
+ createRef: () => createRef,
23
+ forwardRef: () => forwardRef,
22
24
  startTransition: () => startTransition,
23
25
  startViewTransition: () => startViewTransition,
24
26
  use: () => use,
@@ -27,11 +29,13 @@ __export(hooks_exports, {
27
29
  useDeferredValue: () => useDeferredValue,
28
30
  useEffect: () => useEffect,
29
31
  useId: () => useId,
32
+ useImperativeHandle: () => useImperativeHandle,
30
33
  useLayoutEffect: () => useLayoutEffect,
31
34
  useMemo: () => useMemo,
32
35
  useReducer: () => useReducer,
33
36
  useRef: () => useRef,
34
37
  useState: () => useState,
38
+ useSyncExternalStore: () => useSyncExternalStore,
35
39
  useTransition: () => useTransition,
36
40
  useViewTransition: () => useViewTransition
37
41
  });
@@ -151,7 +155,7 @@ const useState = (initialState) => {
151
155
  if (typeof newState === "function") {
152
156
  newState = newState(stateData[0]);
153
157
  }
154
- if (newState !== stateData[0]) {
158
+ if (!Object.is(newState, stateData[0])) {
155
159
  stateData[0] = newState;
156
160
  if (pendingStack.length) {
157
161
  const pendingType = pendingStack.at(-1);
@@ -299,9 +303,43 @@ let idCounter = 0;
299
303
  const useId = () => useMemo(() => `:r${(idCounter++).toString(32)}:`, []);
300
304
  const useDebugValue = (_value, _formatter) => {
301
305
  };
306
+ const createRef = () => {
307
+ return { current: null };
308
+ };
309
+ const forwardRef = (Component) => {
310
+ return (props) => {
311
+ const { ref, ...rest } = props;
312
+ return Component(rest, ref);
313
+ };
314
+ };
315
+ const useImperativeHandle = (ref, createHandle, deps) => {
316
+ useEffect(() => {
317
+ ref.current = createHandle();
318
+ return () => {
319
+ ref.current = null;
320
+ };
321
+ }, deps);
322
+ };
323
+ let useSyncExternalStoreGetServerSnapshotNotified = false;
324
+ const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
325
+ const [state, setState] = useState(getSnapshot());
326
+ useEffect(
327
+ () => subscribe(() => {
328
+ setState(getSnapshot());
329
+ }),
330
+ []
331
+ );
332
+ if (getServerSnapshot && !useSyncExternalStoreGetServerSnapshotNotified) {
333
+ useSyncExternalStoreGetServerSnapshotNotified = true;
334
+ console.info("`getServerSnapshot` is not supported yet.");
335
+ }
336
+ return state;
337
+ };
302
338
  // Annotate the CommonJS export names for ESM import in node:
303
339
  0 && (module.exports = {
304
340
  STASH_EFFECT,
341
+ createRef,
342
+ forwardRef,
305
343
  startTransition,
306
344
  startViewTransition,
307
345
  use,
@@ -310,11 +348,13 @@ const useDebugValue = (_value, _formatter) => {
310
348
  useDeferredValue,
311
349
  useEffect,
312
350
  useId,
351
+ useImperativeHandle,
313
352
  useLayoutEffect,
314
353
  useMemo,
315
354
  useReducer,
316
355
  useRef,
317
356
  useState,
357
+ useSyncExternalStore,
318
358
  useTransition,
319
359
  useViewTransition
320
360
  });
@@ -19,13 +19,16 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var jsx_exports = {};
21
21
  __export(jsx_exports, {
22
+ Children: () => import_children.Children,
22
23
  ErrorBoundary: () => import_components.ErrorBoundary,
23
24
  Fragment: () => import_base.Fragment,
24
25
  Suspense: () => import_streaming.Suspense,
25
26
  cloneElement: () => import_base.cloneElement,
26
27
  createContext: () => import_context.createContext,
27
28
  createElement: () => import_base.jsx,
29
+ createRef: () => import_hooks.createRef,
28
30
  default: () => jsx_default,
31
+ forwardRef: () => import_hooks.forwardRef,
29
32
  isValidElement: () => import_base.isValidElement,
30
33
  jsx: () => import_base.jsx,
31
34
  memo: () => import_base.memo,
@@ -38,16 +41,19 @@ __export(jsx_exports, {
38
41
  useDeferredValue: () => import_hooks.useDeferredValue,
39
42
  useEffect: () => import_hooks.useEffect,
40
43
  useId: () => import_hooks.useId,
44
+ useImperativeHandle: () => import_hooks.useImperativeHandle,
41
45
  useLayoutEffect: () => import_hooks.useLayoutEffect,
42
46
  useMemo: () => import_hooks.useMemo,
43
47
  useReducer: () => import_hooks.useReducer,
44
48
  useRef: () => import_hooks.useRef,
45
49
  useState: () => import_hooks.useState,
50
+ useSyncExternalStore: () => import_hooks.useSyncExternalStore,
46
51
  useTransition: () => import_hooks.useTransition,
47
52
  useViewTransition: () => import_hooks.useViewTransition
48
53
  });
49
54
  module.exports = __toCommonJS(jsx_exports);
50
55
  var import_base = require("./base");
56
+ var import_children = require("./children");
51
57
  var import_components = require("./components");
52
58
  var import_context = require("./context");
53
59
  var import_hooks = require("./hooks");
@@ -77,16 +83,24 @@ var jsx_default = {
77
83
  useViewTransition: import_hooks.useViewTransition,
78
84
  useMemo: import_hooks.useMemo,
79
85
  useLayoutEffect: import_hooks.useLayoutEffect,
80
- Suspense: import_streaming.Suspense
86
+ createRef: import_hooks.createRef,
87
+ forwardRef: import_hooks.forwardRef,
88
+ useImperativeHandle: import_hooks.useImperativeHandle,
89
+ useSyncExternalStore: import_hooks.useSyncExternalStore,
90
+ Suspense: import_streaming.Suspense,
91
+ Children: import_children.Children
81
92
  };
82
93
  // Annotate the CommonJS export names for ESM import in node:
83
94
  0 && (module.exports = {
95
+ Children,
84
96
  ErrorBoundary,
85
97
  Fragment,
86
98
  Suspense,
87
99
  cloneElement,
88
100
  createContext,
89
101
  createElement,
102
+ createRef,
103
+ forwardRef,
90
104
  isValidElement,
91
105
  jsx,
92
106
  memo,
@@ -99,11 +113,13 @@ var jsx_default = {
99
113
  useDeferredValue,
100
114
  useEffect,
101
115
  useId,
116
+ useImperativeHandle,
102
117
  useLayoutEffect,
103
118
  useMemo,
104
119
  useReducer,
105
120
  useRef,
106
121
  useState,
122
+ useSyncExternalStore,
107
123
  useTransition,
108
124
  useViewTransition
109
125
  });
@@ -30,7 +30,6 @@ function jsxDEV(tag, props, key) {
30
30
  node = (0, import_base.jsxFn)(tag, props, []);
31
31
  } else {
32
32
  const children = props.children;
33
- delete props["children"];
34
33
  node = Array.isArray(children) ? (0, import_base.jsxFn)(tag, props, children) : (0, import_base.jsxFn)(tag, props, [children]);
35
34
  }
36
35
  node.key = key;
@@ -18,7 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
- normalizeIntrinsicElementProps: () => normalizeIntrinsicElementProps
21
+ normalizeIntrinsicElementProps: () => normalizeIntrinsicElementProps,
22
+ styleObjectForEach: () => styleObjectForEach
22
23
  });
23
24
  module.exports = __toCommonJS(utils_exports);
24
25
  const normalizeIntrinsicElementProps = (props) => {
@@ -27,7 +28,16 @@ const normalizeIntrinsicElementProps = (props) => {
27
28
  delete props["className"];
28
29
  }
29
30
  };
31
+ const styleObjectForEach = (style, fn) => {
32
+ for (const [k, v] of Object.entries(style)) {
33
+ fn(
34
+ k[0] === "-" ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`),
35
+ v == null ? null : typeof v === "number" ? v + "px" : v
36
+ );
37
+ }
38
+ };
30
39
  // Annotate the CommonJS export names for ESM import in node:
31
40
  0 && (module.exports = {
32
- normalizeIntrinsicElementProps
41
+ normalizeIntrinsicElementProps,
42
+ styleObjectForEach
33
43
  });
@@ -25,6 +25,7 @@ var import_http_exception = require("../../http-exception");
25
25
  var import_buffer = require("../../utils/buffer");
26
26
  const TOKEN_STRINGS = "[A-Za-z0-9._~+/-]+=*";
27
27
  const PREFIX = "Bearer";
28
+ const HEADER = "Authorization";
28
29
  const bearerAuth = (options) => {
29
30
  if (!("token" in options || "verifyToken" in options)) {
30
31
  throw new Error('bearer auth middleware requires options for "token"');
@@ -37,7 +38,7 @@ const bearerAuth = (options) => {
37
38
  }
38
39
  const realm = options.realm?.replace(/"/g, '\\"');
39
40
  return async function bearerAuth2(c, next) {
40
- const headerToken = c.req.header("Authorization");
41
+ const headerToken = c.req.header(options.headerName || HEADER);
41
42
  if (!headerToken) {
42
43
  const res = new Response("Unauthorized", {
43
44
  status: 401,
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var secure_headers_exports = {};
20
20
  __export(secure_headers_exports, {
21
+ NONCE: () => NONCE,
21
22
  secureHeaders: () => secureHeaders
22
23
  });
23
24
  module.exports = __toCommonJS(secure_headers_exports);
@@ -49,11 +50,29 @@ const DEFAULT_OPTIONS = {
49
50
  xPermittedCrossDomainPolicies: true,
50
51
  xXssProtection: true
51
52
  };
53
+ const generateNonce = () => {
54
+ const buffer = new Uint8Array(16);
55
+ crypto.getRandomValues(buffer);
56
+ return Buffer.from(buffer).toString("base64");
57
+ };
58
+ const NONCE = (ctx) => {
59
+ const nonce = ctx.get("secureHeadersNonce") || (() => {
60
+ const newNonce = generateNonce();
61
+ ctx.set("secureHeadersNonce", newNonce);
62
+ return newNonce;
63
+ })();
64
+ return `'nonce-${nonce}'`;
65
+ };
52
66
  const secureHeaders = (customOptions) => {
53
67
  const options = { ...DEFAULT_OPTIONS, ...customOptions };
54
68
  const headersToSet = getFilteredHeaders(options);
69
+ const callbacks = [];
55
70
  if (options.contentSecurityPolicy) {
56
- headersToSet.push(["Content-Security-Policy", getCSPDirectives(options.contentSecurityPolicy)]);
71
+ const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
72
+ if (callback) {
73
+ callbacks.push(callback);
74
+ }
75
+ headersToSet.push(["Content-Security-Policy", value]);
57
76
  }
58
77
  if (options.reportingEndpoints) {
59
78
  headersToSet.push(["Reporting-Endpoints", getReportingEndpoints(options.reportingEndpoints)]);
@@ -62,8 +81,9 @@ const secureHeaders = (customOptions) => {
62
81
  headersToSet.push(["Report-To", getReportToOptions(options.reportTo)]);
63
82
  }
64
83
  return async function secureHeaders2(ctx, next) {
84
+ const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
65
85
  await next();
66
- setHeaders(ctx, headersToSet);
86
+ setHeaders(ctx, headersToSetForReq);
67
87
  ctx.res.headers.delete("X-Powered-By");
68
88
  };
69
89
  };
@@ -74,13 +94,42 @@ function getFilteredHeaders(options) {
74
94
  });
75
95
  }
76
96
  function getCSPDirectives(contentSecurityPolicy) {
77
- return Object.entries(contentSecurityPolicy || []).map(([directive, value]) => {
78
- const kebabCaseDirective = directive.replace(
79
- /[A-Z]+(?![a-z])|[A-Z]/g,
80
- (match, offset) => offset ? "-" + match.toLowerCase() : match.toLowerCase()
97
+ const callbacks = [];
98
+ const resultValues = [];
99
+ for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
100
+ const valueArray = Array.isArray(value) ? value : [value];
101
+ valueArray.forEach((value2, i) => {
102
+ if (typeof value2 === "function") {
103
+ const index = i * 2 + 2 + resultValues.length;
104
+ callbacks.push((ctx, values) => {
105
+ values[index] = value2(ctx, directive);
106
+ });
107
+ }
108
+ });
109
+ resultValues.push(
110
+ directive.replace(
111
+ /[A-Z]+(?![a-z])|[A-Z]/g,
112
+ (match, offset) => offset ? "-" + match.toLowerCase() : match.toLowerCase()
113
+ ),
114
+ ...valueArray.flatMap((value2) => [" ", value2]),
115
+ "; "
81
116
  );
82
- return `${kebabCaseDirective} ${Array.isArray(value) ? value.join(" ") : value}`;
83
- }).join("; ");
117
+ }
118
+ resultValues.pop();
119
+ return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
120
+ (ctx, headersToSet) => headersToSet.map((values) => {
121
+ if (values[0] === "Content-Security-Policy") {
122
+ const clone = values[1].slice();
123
+ callbacks.forEach((cb) => {
124
+ cb(ctx, clone);
125
+ });
126
+ return [values[0], clone.join("")];
127
+ } else {
128
+ return values;
129
+ }
130
+ }),
131
+ resultValues
132
+ ];
84
133
  }
85
134
  function getReportingEndpoints(reportingEndpoints = []) {
86
135
  return reportingEndpoints.map((endpoint) => `${endpoint.name}="${endpoint.url}"`).join(", ");
@@ -95,5 +144,6 @@ function setHeaders(ctx, headersToSet) {
95
144
  }
96
145
  // Annotate the CommonJS export names for ESM import in node:
97
146
  0 && (module.exports = {
147
+ NONCE,
98
148
  secureHeaders
99
149
  });