hono 3.12.5 → 4.0.0-rc.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 (127) hide show
  1. package/README.md +2 -2
  2. package/dist/adapter/bun/index.js +4 -1
  3. package/dist/adapter/bun/ssg.js +18 -0
  4. package/dist/adapter/cloudflare-pages/handler.js +1 -3
  5. package/dist/adapter/cloudflare-workers/serve-static-module.js +1 -3
  6. package/dist/adapter/cloudflare-workers/serve-static.js +1 -1
  7. package/dist/adapter/deno/deno.d.js +0 -0
  8. package/dist/adapter/deno/index.js +4 -1
  9. package/dist/adapter/deno/ssg.js +18 -0
  10. package/dist/cjs/adapter/bun/index.js +7 -2
  11. package/dist/cjs/adapter/bun/ssg.js +42 -0
  12. package/dist/cjs/adapter/cloudflare-pages/handler.js +1 -3
  13. package/dist/cjs/adapter/cloudflare-workers/serve-static-module.js +1 -9
  14. package/dist/cjs/adapter/cloudflare-workers/serve-static.js +1 -1
  15. package/dist/cjs/adapter/deno/deno.d.js +1 -0
  16. package/dist/cjs/adapter/deno/index.js +7 -2
  17. package/dist/cjs/adapter/deno/ssg.js +42 -0
  18. package/dist/cjs/client/client.js +0 -8
  19. package/dist/cjs/context.js +3 -47
  20. package/dist/cjs/helper/css/index.js +55 -19
  21. package/dist/cjs/helper/ssg/index.js +130 -0
  22. package/dist/cjs/helper/ssg/utils.js +64 -0
  23. package/dist/cjs/helper.js +1 -0
  24. package/dist/cjs/hono-base.js +8 -24
  25. package/dist/cjs/jsx/components.js +3 -0
  26. package/dist/cjs/jsx/context.js +60 -0
  27. package/dist/cjs/jsx/dom/components.js +53 -0
  28. package/dist/cjs/jsx/dom/context.js +60 -0
  29. package/dist/cjs/jsx/dom/index.js +39 -0
  30. package/dist/cjs/{adapter/nextjs/index.js → jsx/dom/jsx-dev-runtime.js} +18 -6
  31. package/dist/cjs/{adapter/nextjs/handler.js → jsx/dom/jsx-runtime.js} +11 -10
  32. package/dist/cjs/jsx/dom/render.js +317 -0
  33. package/dist/cjs/jsx/hooks/index.js +212 -0
  34. package/dist/cjs/jsx/index.js +77 -32
  35. package/dist/cjs/jsx/jsx-dev-runtime.js +9 -5
  36. package/dist/cjs/jsx/streaming.js +19 -1
  37. package/dist/cjs/middleware/basic-auth/index.js +5 -11
  38. package/dist/cjs/middleware/cache/index.js +12 -13
  39. package/dist/cjs/middleware/compress/index.js +1 -1
  40. package/dist/cjs/middleware/cors/index.js +2 -3
  41. package/dist/cjs/middleware/jsx-renderer/index.js +12 -1
  42. package/dist/cjs/middleware/jwt/index.js +31 -21
  43. package/dist/cjs/request.js +0 -34
  44. package/dist/cjs/router/linear-router/router.js +3 -3
  45. package/dist/cjs/utils/body.js +3 -1
  46. package/dist/cjs/utils/cookie.js +1 -1
  47. package/dist/cjs/utils/encode.js +1 -1
  48. package/dist/cjs/utils/html.js +2 -1
  49. package/dist/cjs/utils/jwt/types.js +0 -3
  50. package/dist/cjs/utils/mime.js +5 -0
  51. package/dist/cjs/validator/validator.js +0 -4
  52. package/dist/client/client.js +0 -8
  53. package/dist/context.js +3 -47
  54. package/dist/helper/css/index.js +55 -19
  55. package/dist/helper/ssg/index.js +104 -0
  56. package/dist/helper/ssg/utils.js +40 -0
  57. package/dist/helper.js +1 -0
  58. package/dist/hono-base.js +8 -24
  59. package/dist/jsx/components.js +4 -4
  60. package/dist/jsx/context.js +36 -0
  61. package/dist/jsx/dom/components.js +29 -0
  62. package/dist/jsx/dom/context.js +36 -0
  63. package/dist/jsx/dom/index.js +12 -0
  64. package/dist/jsx/dom/jsx-dev-runtime.js +16 -0
  65. package/dist/jsx/dom/jsx-runtime.js +8 -0
  66. package/dist/jsx/dom/render.js +288 -0
  67. package/dist/jsx/hooks/index.js +181 -0
  68. package/dist/jsx/index.js +71 -30
  69. package/dist/jsx/jsx-dev-runtime.js +10 -6
  70. package/dist/jsx/streaming.js +19 -1
  71. package/dist/middleware/basic-auth/index.js +5 -11
  72. package/dist/middleware/cache/index.js +12 -13
  73. package/dist/middleware/compress/index.js +1 -1
  74. package/dist/middleware/cors/index.js +2 -3
  75. package/dist/middleware/jsx-renderer/index.js +13 -2
  76. package/dist/middleware/jwt/index.js +31 -21
  77. package/dist/request.js +0 -34
  78. package/dist/router/linear-router/router.js +3 -3
  79. package/dist/types/adapter/aws-lambda/custom-context.d.ts +0 -4
  80. package/dist/types/adapter/aws-lambda/index.d.ts +1 -1
  81. package/dist/types/adapter/bun/index.d.ts +1 -0
  82. package/dist/types/adapter/bun/ssg.d.ts +13 -0
  83. package/dist/types/adapter/cloudflare-pages/handler.d.ts +2 -7
  84. package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +1 -1
  85. package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +2 -2
  86. package/dist/types/adapter/deno/index.d.ts +1 -0
  87. package/dist/types/adapter/deno/ssg.d.ts +13 -0
  88. package/dist/types/adapter/lambda-edge/handler.d.ts +15 -3
  89. package/dist/types/context.d.ts +11 -44
  90. package/dist/types/helper/css/index.d.ts +6 -2
  91. package/dist/types/helper/factory/index.d.ts +0 -60
  92. package/dist/types/helper/ssg/index.d.ts +82 -0
  93. package/dist/types/helper/ssg/utils.d.ts +7 -0
  94. package/dist/types/helper.d.ts +9 -0
  95. package/dist/types/hono-base.d.ts +1 -29
  96. package/dist/types/jsx/components.d.ts +4 -5
  97. package/dist/types/jsx/context.d.ts +9 -0
  98. package/dist/types/jsx/dom/components.d.ts +10 -0
  99. package/dist/types/jsx/dom/context.d.ts +12 -0
  100. package/dist/types/jsx/dom/index.d.ts +5 -0
  101. package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +13 -0
  102. package/dist/types/jsx/dom/jsx-runtime.d.ts +2 -0
  103. package/dist/types/jsx/dom/render.d.ts +41 -0
  104. package/dist/types/jsx/hooks/index.d.ts +19 -0
  105. package/dist/types/jsx/index.d.ts +17 -14
  106. package/dist/types/jsx/jsx-dev-runtime.d.ts +1 -1
  107. package/dist/types/jsx/streaming.d.ts +1 -1
  108. package/dist/types/middleware/jsx-renderer/index.d.ts +4 -2
  109. package/dist/types/request.d.ts +0 -56
  110. package/dist/types/types.d.ts +4 -2
  111. package/dist/types/utils/body.d.ts +1 -1
  112. package/dist/types/utils/html.d.ts +1 -0
  113. package/dist/types/utils/jwt/types.d.ts +0 -5
  114. package/dist/types/utils/mime.d.ts +1 -0
  115. package/dist/types/utils/types.d.ts +0 -1
  116. package/dist/utils/body.js +3 -1
  117. package/dist/utils/cookie.js +1 -1
  118. package/dist/utils/encode.js +1 -1
  119. package/dist/utils/html.js +2 -1
  120. package/dist/utils/jwt/types.js +0 -2
  121. package/dist/utils/mime.js +4 -0
  122. package/dist/validator/validator.js +0 -4
  123. package/package.json +35 -16
  124. package/dist/adapter/nextjs/handler.js +0 -9
  125. package/dist/adapter/nextjs/index.js +0 -5
  126. package/dist/types/adapter/nextjs/handler.d.ts +0 -16
  127. package/dist/types/adapter/nextjs/index.d.ts +0 -1
package/README.md CHANGED
@@ -26,7 +26,7 @@
26
26
  [![Discord badge](https://img.shields.io/discord/1011308539819597844?label=Discord&logo=Discord)](https://discord.gg/KMh2eNSdxV)
27
27
 
28
28
  Hono - _**\[炎\] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for the Edges.
29
- It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Lagon, AWS Lambda, Lambda@Edge, and Node.js.
29
+ It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, AWS Lambda, Lambda@Edge, and Node.js.
30
30
 
31
31
  Fast, but not only fast.
32
32
 
@@ -49,7 +49,7 @@ npm create hono@latest my-app
49
49
 
50
50
  - **Ultrafast** 🚀 - The router `RegExpRouter` is really fast. Not using linear loops. Fast.
51
51
  - **Lightweight** 🪶 - The `hono/tiny` preset is under 14kB. Hono has zero dependencies and uses only the Web Standard API.
52
- - **Multi-runtime** 🌍 - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, Lagon, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
52
+ - **Multi-runtime** 🌍 - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, Lambda@Edge, or Node.js. The same code runs on all platforms.
53
53
  - **Batteries Included** 🔋 - Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included.
54
54
  - **Delightful DX** 😃 - Super clean APIs. First-class TypeScript support. Now, we've got "Types".
55
55
 
@@ -1,5 +1,8 @@
1
1
  // src/adapter/bun/index.ts
2
2
  import { serveStatic } from "./serve-static.js";
3
+ import { bunFileSystemModule, toSSG } from "./ssg.js";
3
4
  export {
4
- serveStatic
5
+ bunFileSystemModule,
6
+ serveStatic,
7
+ toSSG
5
8
  };
@@ -0,0 +1,18 @@
1
+ // src/adapter/bun/ssg.ts
2
+ import { mkdir, writeFile } from "fs/promises";
3
+ import { toSSG as baseToSSG } from "../../helper/ssg/index.js";
4
+ var bunFileSystemModule = {
5
+ writeFile: (path, data) => {
6
+ return writeFile(path, data);
7
+ },
8
+ mkdir: async (path, options) => {
9
+ await mkdir(path, options);
10
+ }
11
+ };
12
+ var toSSG = async (app, options) => {
13
+ return baseToSSG(app, bunFileSystemModule, options);
14
+ };
15
+ export {
16
+ bunFileSystemModule,
17
+ toSSG
18
+ };
@@ -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 },
@@ -1,8 +1,6 @@
1
1
  // src/adapter/cloudflare-workers/serve-static-module.ts
2
- import manifest from "__STATIC_CONTENT_MANIFEST";
3
2
  import { serveStatic } from "./serve-static.js";
4
- var module = (options = { root: "" }) => {
5
- options.manifest ?? (options.manifest = manifest);
3
+ var module = (options) => {
6
4
  return serveStatic(options);
7
5
  };
8
6
  export {
@@ -3,7 +3,7 @@ import { getFilePath } from "../../utils/filepath.js";
3
3
  import { getMimeType } from "../../utils/mime.js";
4
4
  import { getContentFromKVAsset } from "./utils.js";
5
5
  var DEFAULT_DOCUMENT = "index.html";
6
- var serveStatic = (options = { root: "" }) => {
6
+ var serveStatic = (options) => {
7
7
  return async (c, next) => {
8
8
  if (c.finalized) {
9
9
  await next();
File without changes
@@ -1,5 +1,8 @@
1
1
  // src/adapter/deno/index.ts
2
2
  import { serveStatic } from "./serve-static.js";
3
+ import { toSSG, denoFileSystemModule } from "./ssg.js";
3
4
  export {
4
- serveStatic
5
+ denoFileSystemModule,
6
+ serveStatic,
7
+ toSSG
5
8
  };
@@ -0,0 +1,18 @@
1
+ // src/adapter/deno/ssg.ts
2
+ import { toSSG as baseToSSG } from "../../helper/ssg/index.js";
3
+ var denoFileSystemModule = {
4
+ writeFile: async (path, data) => {
5
+ const uint8Data = typeof data === "string" ? new TextEncoder().encode(data) : data;
6
+ await Deno.writeFile(path, uint8Data);
7
+ },
8
+ mkdir: async (path, options) => {
9
+ return Deno.mkdir(path, { recursive: options?.recursive ?? false });
10
+ }
11
+ };
12
+ var toSSG = async (app, options) => {
13
+ return baseToSSG(app, denoFileSystemModule, options);
14
+ };
15
+ export {
16
+ denoFileSystemModule,
17
+ toSSG
18
+ };
@@ -18,11 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var bun_exports = {};
20
20
  __export(bun_exports, {
21
- serveStatic: () => import_serve_static.serveStatic
21
+ bunFileSystemModule: () => import_ssg.bunFileSystemModule,
22
+ serveStatic: () => import_serve_static.serveStatic,
23
+ toSSG: () => import_ssg.toSSG
22
24
  });
23
25
  module.exports = __toCommonJS(bun_exports);
24
26
  var import_serve_static = require("./serve-static");
27
+ var import_ssg = require("./ssg");
25
28
  // Annotate the CommonJS export names for ESM import in node:
26
29
  0 && (module.exports = {
27
- serveStatic
30
+ bunFileSystemModule,
31
+ serveStatic,
32
+ toSSG
28
33
  });
@@ -0,0 +1,42 @@
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 ssg_exports = {};
20
+ __export(ssg_exports, {
21
+ bunFileSystemModule: () => bunFileSystemModule,
22
+ toSSG: () => toSSG
23
+ });
24
+ module.exports = __toCommonJS(ssg_exports);
25
+ var import_promises = require("fs/promises");
26
+ var import_ssg = require("../../helper/ssg");
27
+ const bunFileSystemModule = {
28
+ writeFile: (path, data) => {
29
+ return (0, import_promises.writeFile)(path, data);
30
+ },
31
+ mkdir: async (path, options) => {
32
+ await (0, import_promises.mkdir)(path, options);
33
+ }
34
+ };
35
+ const toSSG = async (app, options) => {
36
+ return (0, import_ssg.toSSG)(app, bunFileSystemModule, options);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ bunFileSystemModule,
41
+ toSSG
42
+ });
@@ -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 },
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,20 +15,14 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
  var serve_static_module_exports = {};
26
20
  __export(serve_static_module_exports, {
27
21
  serveStatic: () => module2
28
22
  });
29
23
  module.exports = __toCommonJS(serve_static_module_exports);
30
- var import_STATIC_CONTENT_MANIFEST = __toESM(require("__STATIC_CONTENT_MANIFEST"), 1);
31
24
  var import_serve_static = require("./serve-static");
32
- const module2 = (options = { root: "" }) => {
33
- options.manifest ?? (options.manifest = import_STATIC_CONTENT_MANIFEST.default);
25
+ const module2 = (options) => {
34
26
  return (0, import_serve_static.serveStatic)(options);
35
27
  };
36
28
  // Annotate the CommonJS export names for ESM import in node:
@@ -25,7 +25,7 @@ var import_filepath = require("../../utils/filepath");
25
25
  var import_mime = require("../../utils/mime");
26
26
  var import_utils = require("./utils");
27
27
  const DEFAULT_DOCUMENT = "index.html";
28
- const serveStatic = (options = { root: "" }) => {
28
+ const serveStatic = (options) => {
29
29
  return async (c, next) => {
30
30
  if (c.finalized) {
31
31
  await next();
@@ -0,0 +1 @@
1
+ "use strict";
@@ -18,11 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var deno_exports = {};
20
20
  __export(deno_exports, {
21
- serveStatic: () => import_serve_static.serveStatic
21
+ denoFileSystemModule: () => import_ssg.denoFileSystemModule,
22
+ serveStatic: () => import_serve_static.serveStatic,
23
+ toSSG: () => import_ssg.toSSG
22
24
  });
23
25
  module.exports = __toCommonJS(deno_exports);
24
26
  var import_serve_static = require("./serve-static");
27
+ var import_ssg = require("./ssg");
25
28
  // Annotate the CommonJS export names for ESM import in node:
26
29
  0 && (module.exports = {
27
- serveStatic
30
+ denoFileSystemModule,
31
+ serveStatic,
32
+ toSSG
28
33
  });
@@ -0,0 +1,42 @@
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 ssg_exports = {};
20
+ __export(ssg_exports, {
21
+ denoFileSystemModule: () => denoFileSystemModule,
22
+ toSSG: () => toSSG
23
+ });
24
+ module.exports = __toCommonJS(ssg_exports);
25
+ var import_ssg = require("../../helper/ssg/index");
26
+ const denoFileSystemModule = {
27
+ writeFile: async (path, data) => {
28
+ const uint8Data = typeof data === "string" ? new TextEncoder().encode(data) : data;
29
+ await Deno.writeFile(path, uint8Data);
30
+ },
31
+ mkdir: async (path, options) => {
32
+ return Deno.mkdir(path, { recursive: options?.recursive ?? false });
33
+ }
34
+ };
35
+ const toSSG = async (app, options) => {
36
+ return (0, import_ssg.toSSG)(app, denoFileSystemModule, options);
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ denoFileSystemModule,
41
+ toSSG
42
+ });
@@ -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 {
@@ -57,9 +55,12 @@ class Context {
57
55
  __privateAdd(this, _preparedHeaders, void 0);
58
56
  __privateAdd(this, _res, void 0);
59
57
  __privateAdd(this, _isFresh, true);
58
+ this.layout = void 0;
60
59
  this.renderer = (content) => this.html(content);
61
60
  this.notFoundHandler = () => new Response();
62
61
  this.render = (...args) => this.renderer(...args);
62
+ this.setLayout = (layout) => this.layout = layout;
63
+ this.getLayout = () => this.layout;
63
64
  this.setRenderer = (renderer) => {
64
65
  this.renderer = renderer;
65
66
  };
@@ -167,9 +168,6 @@ class Context {
167
168
  __privateGet(this, _preparedHeaders)["content-type"] = "application/json; charset=UTF-8";
168
169
  return typeof arg === "number" ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
169
170
  };
170
- this.jsonT = (object, arg, headers) => {
171
- return this.json(object, arg, headers);
172
- };
173
171
  this.html = (html, arg, headers) => {
174
172
  __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
175
173
  __privateGet(this, _preparedHeaders)["content-type"] = "text/html; charset=UTF-8";
@@ -190,23 +188,6 @@ class Context {
190
188
  __privateGet(this, _headers).set("Location", location);
191
189
  return this.newResponse(null, status);
192
190
  };
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
191
  this.notFound = () => {
211
192
  return this.notFoundHandler(this);
212
193
  };
@@ -259,31 +240,6 @@ class Context {
259
240
  get var() {
260
241
  return { ...this._var };
261
242
  }
262
- get runtime() {
263
- const global = globalThis;
264
- if (global?.Deno !== void 0) {
265
- return "deno";
266
- }
267
- if (global?.Bun !== void 0) {
268
- return "bun";
269
- }
270
- if (typeof global?.WebSocketPair === "function") {
271
- return "workerd";
272
- }
273
- if (typeof global?.EdgeRuntime === "string") {
274
- return "edge-light";
275
- }
276
- if (global?.fastly !== void 0) {
277
- return "fastly";
278
- }
279
- if (global?.__lagon__ !== void 0) {
280
- return "lagon";
281
- }
282
- if (global?.process?.release?.name === "node") {
283
- return "node";
284
- }
285
- return "other";
286
- }
287
243
  }
288
244
  _status = new WeakMap();
289
245
  _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");
@@ -36,6 +37,8 @@ const rawCssString = (value) => {
36
37
  escapedString.isCssEscaped = true;
37
38
  return escapedString;
38
39
  };
40
+ const PSEUDO_GLOBAL_SELECTOR = ":-hono-global";
41
+ const isPseudoGlobalSelectorRe = new RegExp(`^${PSEUDO_GLOBAL_SELECTOR}{(.*)}$`);
39
42
  const DEFAULT_STYLE_ID = "hono-css";
40
43
  const toHash = (str) => {
41
44
  let i = 0, out = 11;
@@ -67,8 +70,9 @@ const minify = (css2) => {
67
70
  return css2.replace(minifyCssRe, (_, $1, $2, $3, $4) => $1 || $2 || $3 || $4 || "");
68
71
  };
69
72
  const buildStyleString = async (strings, values, selectors, externalClassNames) => {
73
+ const label = strings[0].match(/^\s*\/\*(.*?)\*\//)?.[1] || "";
70
74
  let styleString = "";
71
- for (let i = 0; i < strings.length; i++) {
75
+ for (let i = 0, len = strings.length; i < len; i++) {
72
76
  styleString += strings[i];
73
77
  let vArray = values[i];
74
78
  if (typeof vArray === "boolean" || vArray === null || vArray === void 0) {
@@ -77,7 +81,7 @@ const buildStyleString = async (strings, values, selectors, externalClassNames)
77
81
  if (!Array.isArray(vArray)) {
78
82
  vArray = [vArray];
79
83
  }
80
- for (let j = 0; j < vArray.length; j++) {
84
+ for (let j = 0, len2 = vArray.length; j < len2; j++) {
81
85
  let value = vArray[j] instanceof Promise ? await vArray[j] : vArray[j];
82
86
  if (typeof value === "boolean" || value === null || value === void 0) {
83
87
  continue;
@@ -89,13 +93,19 @@ const buildStyleString = async (strings, values, selectors, externalClassNames)
89
93
  styleString += ` ${value.substring(11)} `;
90
94
  } else {
91
95
  if (value[IS_CSS_CLASS_NAME]) {
92
- selectors.push(...value[SELECTORS]);
93
- externalClassNames.push(...value[EXTERNAL_CLASS_NAMES]);
94
- value = value[STYLE_STRING];
95
- if (value.length > 0) {
96
- const lastChar = value[value.length - 1];
97
- if (lastChar !== ";" && lastChar !== "}") {
98
- value += ";";
96
+ if (strings[i + 1]?.match(/^\s*{/)) {
97
+ selectors.push(value);
98
+ value = `.${value}`;
99
+ } else {
100
+ selectors.push(...value[SELECTORS]);
101
+ externalClassNames.push(...value[EXTERNAL_CLASS_NAMES]);
102
+ value = value[STYLE_STRING];
103
+ const valueLen = value.length;
104
+ if (valueLen > 0) {
105
+ const lastChar = value[valueLen - 1];
106
+ if (lastChar !== ";" && lastChar !== "}") {
107
+ value += ";";
108
+ }
99
109
  }
100
110
  }
101
111
  } else if (!value.isCssEscaped && /([\\"'\/])/.test(value)) {
@@ -105,7 +115,7 @@ const buildStyleString = async (strings, values, selectors, externalClassNames)
105
115
  }
106
116
  }
107
117
  }
108
- return minify(styleString);
118
+ return [label, minify(styleString)];
109
119
  };
110
120
  const createCssContext = ({ id }) => {
111
121
  const contextMap = /* @__PURE__ */ new WeakMap();
@@ -113,9 +123,20 @@ const createCssContext = ({ id }) => {
113
123
  const css2 = async (strings, ...values) => {
114
124
  const selectors = [];
115
125
  const externalClassNames = [];
116
- const thisStyleString = await buildStyleString(strings, values, selectors, externalClassNames);
117
- const thisSelector = toHash(thisStyleString);
118
- const className = new String([thisSelector, ...externalClassNames].join(" "));
126
+ let [label, thisStyleString] = await buildStyleString(
127
+ strings,
128
+ values,
129
+ selectors,
130
+ externalClassNames
131
+ );
132
+ const isPseudoGlobal = isPseudoGlobalSelectorRe.exec(thisStyleString);
133
+ if (isPseudoGlobal) {
134
+ thisStyleString = isPseudoGlobal[1];
135
+ }
136
+ const thisSelector = (isPseudoGlobal ? PSEUDO_GLOBAL_SELECTOR : "") + toHash(label + thisStyleString);
137
+ const className = new String(
138
+ (isPseudoGlobal ? selectors.map(String) : [thisSelector, ...externalClassNames]).join(" ")
139
+ );
119
140
  const appendStyle = ({ buffer, context }) => {
120
141
  const [toAdd, added] = contextMap.get(context);
121
142
  const names = Object.keys(toAdd);
@@ -125,7 +146,7 @@ const createCssContext = ({ id }) => {
125
146
  let stylesStr = "";
126
147
  names.forEach((className2) => {
127
148
  added[className2] = true;
128
- stylesStr += `${className2[0] === "@" ? "" : "."}${className2}{${toAdd[className2]}}`;
149
+ stylesStr += className2.startsWith(PSEUDO_GLOBAL_SELECTOR) ? toAdd[className2] : `${className2[0] === "@" ? "" : "."}${className2}{${toAdd[className2]}}`;
129
150
  });
130
151
  contextMap.set(context, [{}, added]);
131
152
  if (buffer && replaceStyleRe.test(buffer[0])) {
@@ -141,7 +162,20 @@ const createCssContext = ({ id }) => {
141
162
  }
142
163
  return Promise.resolve(appendStyleScript);
143
164
  };
144
- const addClassNameToContext = ({ context }) => {
165
+ const addClassNameToContext = ({ context, phase }) => {
166
+ if (phase === import_html2.HtmlEscapedCallbackPhase.BeforeDom) {
167
+ const styleSheets = document.styleSheets;
168
+ for (let i = 0, len = styleSheets.length; i < len; i++) {
169
+ const sheet = styleSheets[i];
170
+ if (sheet.ownerNode?.id === id) {
171
+ if (!sheet.cssRules?.[0]?.cssText?.includes(thisSelector)) {
172
+ sheet.insertRule(`.${thisSelector}{${thisStyleString}}`);
173
+ break;
174
+ }
175
+ }
176
+ }
177
+ return;
178
+ }
145
179
  if (!contextMap.get(context)) {
146
180
  contextMap.set(context, [{}, {}]);
147
181
  }
@@ -174,7 +208,7 @@ const createCssContext = ({ id }) => {
174
208
  };
175
209
  const cx2 = async (...args) => {
176
210
  const resolvedArgs = await Promise.all(args);
177
- for (let i = 0; i < resolvedArgs.length; i++) {
211
+ for (let i = 0, len = resolvedArgs.length; i < len; i++) {
178
212
  const arg = resolvedArgs[i];
179
213
  if (typeof arg === "string" && !arg[IS_CSS_CLASS_NAME]) {
180
214
  const externalClassName = new String(arg);
@@ -190,8 +224,8 @@ const createCssContext = ({ id }) => {
190
224
  return css2(Array(resolvedArgs.length).fill(""), ...resolvedArgs);
191
225
  };
192
226
  const keyframes2 = async (strings, ...values) => {
193
- const styleString = await buildStyleString(strings, values, [], []);
194
- const className = new String(`@keyframes ${toHash(styleString)}`);
227
+ const [label, styleString] = await buildStyleString(strings, values, [], []);
228
+ const className = new String(`@keyframes ${toHash(label + styleString)}`);
195
229
  Object.assign(className, {
196
230
  isEscaped: true,
197
231
  [IS_CSS_CLASS_NAME]: true,
@@ -201,7 +235,9 @@ const createCssContext = ({ id }) => {
201
235
  });
202
236
  return className;
203
237
  };
204
- const Style2 = () => (0, import_html.raw)(`<style id="${id}"></style>`);
238
+ const Style2 = ({ children } = {}) => children ? children.then(
239
+ (cssData) => (0, import_html.raw)(`<style id="${id}">${cssData[STYLE_STRING]}</style>`)
240
+ ) : (0, import_html.raw)(`<style id="${id}"></style>`);
205
241
  return {
206
242
  css: css2,
207
243
  cx: cx2,