hono 4.0.4 → 4.0.5

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.
@@ -35,11 +35,10 @@ var import_utils2 = require("./utils");
35
35
  const SSG_CONTEXT = "HONO_SSG_CONTEXT";
36
36
  const SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
37
37
  const generateFilePath = (routePath, outDir, mimeType) => {
38
- const hasExtension = /\.[^\/]+$/.test(routePath);
39
- if (hasExtension) {
38
+ const extension = determineExtension(mimeType);
39
+ if (routePath.endsWith(`.${extension}`)) {
40
40
  return (0, import_utils2.joinPaths)(outDir, routePath);
41
41
  }
42
- const extension = determineExtension(mimeType);
43
42
  if (routePath === "/") {
44
43
  return (0, import_utils2.joinPaths)(outDir, `index.${extension}`);
45
44
  }
@@ -27,11 +27,17 @@ module.exports = __toCommonJS(render_exports);
27
27
  var import_constants = require("../constants");
28
28
  var import_context = require("../context");
29
29
  var import_hooks = require("../hooks");
30
+ var import__ = require(".");
30
31
  const eventAliasMap = {
31
32
  Change: "Input",
32
33
  DoubleClick: "DblClick"
33
34
  };
35
+ const nameSpaceMap = {
36
+ svg: "http://www.w3.org/2000/svg",
37
+ math: "http://www.w3.org/1998/Math/MathML"
38
+ };
34
39
  const buildDataStack = [];
40
+ let nameSpaceContext = void 0;
35
41
  const isNodeString = (node) => Array.isArray(node);
36
42
  const getEventSpec = (key) => {
37
43
  const match = key.match(/^on([A-Z][a-zA-Z]+?)((?<!Pointer)Capture)?$/);
@@ -205,7 +211,7 @@ const applyNodeObject = (node, container) => {
205
211
  }
206
212
  el = child.e || (child.e = document.createTextNode(child[0]));
207
213
  } else {
208
- el = child.e || (child.e = document.createElement(child.tag));
214
+ el = child.e || (child.e = child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag));
209
215
  applyProps(el, child.props, child.pP);
210
216
  applyNode(child, el);
211
217
  }
@@ -266,6 +272,11 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
266
272
  oldChild.children = child.children;
267
273
  child = oldChild;
268
274
  }
275
+ } else if (!isNodeString(child) && nameSpaceContext) {
276
+ const ns = (0, import__.useContext)(nameSpaceContext);
277
+ if (ns) {
278
+ child.n = ns;
279
+ }
269
280
  }
270
281
  if (!isNodeString(child)) {
271
282
  build(context, child, topLevelErrorHandlerNode);
@@ -303,6 +314,22 @@ const buildNode = (node) => {
303
314
  if (typeof node.tag === "function") {
304
315
  ;
305
316
  node[import_constants.DOM_STASH] = [0, []];
317
+ } else {
318
+ const ns = nameSpaceMap[node.tag];
319
+ if (ns) {
320
+ ;
321
+ node.n = ns;
322
+ nameSpaceContext || (nameSpaceContext = (0, import__.createContext)(""));
323
+ node.children = [
324
+ {
325
+ tag: nameSpaceContext.Provider,
326
+ props: {
327
+ value: ns
328
+ },
329
+ children: node.children
330
+ }
331
+ ];
332
+ }
306
333
  }
307
334
  return node;
308
335
  }
@@ -6,11 +6,10 @@ import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
6
6
  var SSG_CONTEXT = "HONO_SSG_CONTEXT";
7
7
  var SSG_DISABLED_RESPONSE = new Response("SSG is disabled", { status: 404 });
8
8
  var generateFilePath = (routePath, outDir, mimeType) => {
9
- const hasExtension = /\.[^\/]+$/.test(routePath);
10
- if (hasExtension) {
9
+ const extension = determineExtension(mimeType);
10
+ if (routePath.endsWith(`.${extension}`)) {
11
11
  return joinPaths(outDir, routePath);
12
12
  }
13
- const extension = determineExtension(mimeType);
14
13
  if (routePath === "/") {
15
14
  return joinPaths(outDir, `index.${extension}`);
16
15
  }
@@ -2,11 +2,17 @@
2
2
  import { DOM_RENDERER, DOM_ERROR_HANDLER, DOM_STASH } from "../constants.js";
3
3
  import { globalContexts as globalJSXContexts } from "../context.js";
4
4
  import { STASH_EFFECT } from "../hooks/index.js";
5
+ import { useContext, createContext } from "./index.js";
5
6
  var eventAliasMap = {
6
7
  Change: "Input",
7
8
  DoubleClick: "DblClick"
8
9
  };
10
+ var nameSpaceMap = {
11
+ svg: "http://www.w3.org/2000/svg",
12
+ math: "http://www.w3.org/1998/Math/MathML"
13
+ };
9
14
  var buildDataStack = [];
15
+ var nameSpaceContext = void 0;
10
16
  var isNodeString = (node) => Array.isArray(node);
11
17
  var getEventSpec = (key) => {
12
18
  const match = key.match(/^on([A-Z][a-zA-Z]+?)((?<!Pointer)Capture)?$/);
@@ -180,7 +186,7 @@ var applyNodeObject = (node, container) => {
180
186
  }
181
187
  el = child.e || (child.e = document.createTextNode(child[0]));
182
188
  } else {
183
- el = child.e || (child.e = document.createElement(child.tag));
189
+ el = child.e || (child.e = child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag));
184
190
  applyProps(el, child.props, child.pP);
185
191
  applyNode(child, el);
186
192
  }
@@ -241,6 +247,11 @@ var build = (context, node, topLevelErrorHandlerNode, children) => {
241
247
  oldChild.children = child.children;
242
248
  child = oldChild;
243
249
  }
250
+ } else if (!isNodeString(child) && nameSpaceContext) {
251
+ const ns = useContext(nameSpaceContext);
252
+ if (ns) {
253
+ child.n = ns;
254
+ }
244
255
  }
245
256
  if (!isNodeString(child)) {
246
257
  build(context, child, topLevelErrorHandlerNode);
@@ -278,6 +289,22 @@ var buildNode = (node) => {
278
289
  if (typeof node.tag === "function") {
279
290
  ;
280
291
  node[DOM_STASH] = [0, []];
292
+ } else {
293
+ const ns = nameSpaceMap[node.tag];
294
+ if (ns) {
295
+ ;
296
+ node.n = ns;
297
+ nameSpaceContext || (nameSpaceContext = createContext(""));
298
+ node.children = [
299
+ {
300
+ tag: nameSpaceContext.Provider,
301
+ props: {
302
+ value: ns
303
+ },
304
+ children: node.children
305
+ }
306
+ ];
307
+ }
281
308
  }
282
309
  return node;
283
310
  }
@@ -1,5 +1,3 @@
1
- import type { FC } from './jsx';
2
- import type { PropsForRenderer } from './middleware/jsx-renderer';
3
1
  import type { HonoRequest } from './request';
4
2
  import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types';
5
3
  import type { RedirectStatusCode, StatusCode } from './utils/http-status';
@@ -18,6 +16,8 @@ interface DefaultRenderer {
18
16
  (content: string | Promise<string>): Response | Promise<Response>;
19
17
  }
20
18
  export type Renderer = ContextRenderer extends Function ? ContextRenderer : DefaultRenderer;
19
+ export type PropsForRenderer = [...Required<Parameters<Renderer>>] extends [unknown, infer Props] ? Props : unknown;
20
+ export type Layout<T = Record<string, any>> = (props: T) => any;
21
21
  interface Get<E extends Env> {
22
22
  <Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
23
23
  <Key extends keyof E['Variables']>(key: Key): E['Variables'][Key];
@@ -112,13 +112,13 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
112
112
  * @see https://hono.dev/api/context#render-setrenderer
113
113
  */
114
114
  render: Renderer;
115
- setLayout: (layout: FC<PropsForRenderer & {
116
- Layout: FC;
117
- }>) => FC<{
118
- Layout: FC;
115
+ setLayout: (layout: Layout<PropsForRenderer & {
116
+ Layout: Layout;
117
+ }>) => Layout<{
118
+ Layout: Layout;
119
119
  }>;
120
- getLayout: () => FC<{
121
- Layout: FC;
120
+ getLayout: () => Layout<{
121
+ Layout: Layout;
122
122
  }> | undefined;
123
123
  /**
124
124
  * `.setRenderer()` can set the layout in the custom middleware.
@@ -8,14 +8,16 @@ export type HasRenderToDom = FC<any> & {
8
8
  export type ErrorHandler = (error: any, retry: () => void) => Child | undefined;
9
9
  type Container = HTMLElement | DocumentFragment;
10
10
  type LocalJSXContexts = [JSXContext<unknown>, unknown][] | undefined;
11
+ type SupportedElement = HTMLElement | SVGElement | MathMLElement;
11
12
  export type NodeObject = {
12
13
  pP: Props | undefined;
13
14
  nN: Node | undefined;
14
15
  vC: Node[];
15
16
  vR: Node[];
16
17
  s?: Node[];
18
+ n?: string;
17
19
  c: Container | undefined;
18
- e: HTMLElement | Text | undefined;
20
+ e: SupportedElement | Text | undefined;
19
21
  [DOM_STASH]: [
20
22
  number,
21
23
  any[][],
@@ -1,8 +1,7 @@
1
- import type { Context, Renderer } from '../../context';
1
+ import type { Context, PropsForRenderer } from '../../context';
2
2
  import type { FC, PropsWithChildren } from '../../jsx';
3
3
  import type { Env, Input, MiddlewareHandler } from '../../types';
4
4
  export declare const RequestContext: import("../../jsx").Context<Context<any, any, {}> | null>;
5
- export type PropsForRenderer = [...Required<Parameters<Renderer>>] extends [unknown, infer Props] ? Props : unknown;
6
5
  type RendererOptions = {
7
6
  docType?: boolean | string;
8
7
  stream?: boolean | Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",