@blinkk/root 2.2.1-alpha.0 → 2.2.1-alpha.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.
@@ -15,7 +15,7 @@ var Html = ({ children, ...attrs }) => {
15
15
  };
16
16
 
17
17
  // src/core/hooks/useI18nContext.ts
18
- import path from "node:path";
18
+ import path from "path";
19
19
  import { createContext as createContext2 } from "preact";
20
20
  import { useContext as useContext2 } from "preact/hooks";
21
21
  var I18N_CONTEXT = createContext2(null);
@@ -63,4 +63,4 @@ export {
63
63
  REQUEST_CONTEXT,
64
64
  useRequestContext
65
65
  };
66
- //# sourceMappingURL=chunk-FKTS7ME3.js.map
66
+ //# sourceMappingURL=chunk-6RLXVNIT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/components/Html.tsx","../src/core/hooks/useI18nContext.ts","../src/core/hooks/useRequestContext.ts"],"sourcesContent":["import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport interface HtmlContext {\n htmlAttrs: preact.JSX.HTMLAttributes<HTMLHtmlElement>;\n headAttrs: preact.JSX.HTMLAttributes<HTMLHeadElement>;\n headComponents: ComponentChildren[];\n bodyAttrs: preact.JSX.HTMLAttributes<HTMLBodyElement>;\n scriptDeps: Array<preact.JSX.ScriptHTMLAttributes<HTMLScriptElement>>;\n}\n\nexport const HTML_CONTEXT = createContext<HtmlContext | null>(null);\n\nexport type HtmlProps = preact.JSX.HTMLAttributes<HTMLHtmlElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The `<Html>` component can be used to update attrs in the `<html>` tag.\n *\n * Usage:\n *\n * ```tsx\n * <Html lang=\"en-US\">\n * <h1>Hello world</h1>\n * </Html>\n * ```\n */\nexport const Html: FunctionalComponent<HtmlProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Html> component'\n );\n }\n context.htmlAttrs = attrs;\n return <>{children}</>;\n};\n","import path from 'node:path';\nimport {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const I18N_CONTEXT = createContext<I18nContext | null>(null);\n\nexport interface I18nContext {\n locale: string;\n translations: Record<string, string>;\n}\n\n/**\n * A hook that returns information about the current i18n context, including the\n * locale for the given route and a map of translations for that locale.\n */\nexport function useI18nContext() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('I18N_CONTEXT not found');\n }\n return context;\n}\n\nexport function getTranslations(locale: string): Record<string, string> {\n const translations: Record<string, Record<string, string>> = {};\n const translationsFiles = import.meta.glob(['/translations/*.json'], {\n eager: true,\n }) as Record<string, {default?: Record<string, string>}>;\n Object.keys(translationsFiles).forEach((translationPath) => {\n const parts = path.parse(translationPath);\n const locale = parts.name;\n const module = translationsFiles[translationPath];\n if (module && module.default) {\n translations[locale] = module.default;\n }\n });\n return translations[locale] || {};\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {Route} from '../types.js';\n\nexport interface RequestContext {\n /**\n * The current request path, e.g. `/foo/bar` (default route path) or\n * `/{locale}/foo/bar` (localized route path).\n */\n currentPath: string;\n /** The route file. */\n route: Route;\n /**\n * Route param values. E.g. for a route like `routes/blog/[slug].tsx`,\n * visiting `/blog/foo` will pass {slug: 'foo'} here.\n */\n routeParams: Record<string, string>;\n /** Props passed to the route's server component. */\n props: any;\n /** The current locale. */\n locale: string;\n /** Translations map for the current locale. */\n translations: Record<string, string>;\n /** CSP nonce value. */\n nonce?: string;\n}\n\nexport const REQUEST_CONTEXT = createContext<RequestContext | null>(null);\n\n/**\n * A hook that returns information about the current route.\n *\n * Usage:\n *\n * ```ts\n * const ctx = useRequestContext();\n * ctx.route.src;\n * // => 'routes/index.tsx'\n * ```\n */\nexport function useRequestContext() {\n const context = useContext(REQUEST_CONTEXT);\n if (!context) {\n throw new Error('REQUEST_CONTEXT not found');\n }\n return context;\n}\n"],"mappings":";A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Context","useContext"]}
@@ -3,7 +3,7 @@ import {
3
3
  rootProjectMiddleware,
4
4
  sessionMiddleware,
5
5
  trailingSlashMiddleware
6
- } from "./chunk-DISVDCLA.js";
6
+ } from "./chunk-N677DHZI.js";
7
7
  import {
8
8
  bundleRootConfig,
9
9
  copyDir,
@@ -22,7 +22,7 @@ import {
22
22
  rmDir,
23
23
  writeFile,
24
24
  writeJson
25
- } from "./chunk-KN32BDF2.js";
25
+ } from "./chunk-ZCX5PVMF.js";
26
26
  import {
27
27
  configureServerPlugins,
28
28
  getVitePlugins
@@ -40,16 +40,16 @@ import { Command, InvalidArgumentError } from "commander";
40
40
  import { bgGreen, black } from "kleur/colors";
41
41
 
42
42
  // src/cli/build.ts
43
- import path3 from "node:path";
44
- import { fileURLToPath } from "node:url";
43
+ import path3 from "path";
44
+ import { fileURLToPath } from "url";
45
45
  import fsExtra from "fs-extra";
46
46
  import { dim, cyan } from "kleur/colors";
47
47
  import glob2 from "tiny-glob";
48
48
  import { build as viteBuild } from "vite";
49
49
 
50
50
  // src/node/element-graph.ts
51
- import fs from "node:fs";
52
- import path from "node:path";
51
+ import fs from "fs";
52
+ import path from "path";
53
53
  import glob from "tiny-glob";
54
54
  import { searchForWorkspaceRoot } from "vite";
55
55
  var ElementGraph = class _ElementGraph {
@@ -157,8 +157,8 @@ function getElementsDirs(rootConfig) {
157
157
  }
158
158
 
159
159
  // src/render/asset-map/build-asset-map.ts
160
- import fs2 from "node:fs";
161
- import path2 from "node:path";
160
+ import fs2 from "fs";
161
+ import path2 from "path";
162
162
  var BuildAssetMap = class _BuildAssetMap {
163
163
  rootConfig;
164
164
  srcToAsset;
@@ -798,9 +798,9 @@ function formatParams(params) {
798
798
  }
799
799
 
800
800
  // src/cli/codegen.ts
801
- import { promises as fs3 } from "node:fs";
802
- import path4 from "node:path";
803
- import { fileURLToPath as fileURLToPath2 } from "node:url";
801
+ import { promises as fs3 } from "fs";
802
+ import path4 from "path";
803
+ import { fileURLToPath as fileURLToPath2 } from "url";
804
804
  import glob3 from "tiny-glob";
805
805
  var __dirname2 = path4.dirname(fileURLToPath2(import.meta.url));
806
806
  async function codegen(type, name, options) {
@@ -878,8 +878,8 @@ function toTitleCase(str) {
878
878
  }
879
879
 
880
880
  // src/cli/create-package.ts
881
- import { promises as fs4 } from "node:fs";
882
- import path5 from "node:path";
881
+ import { promises as fs4 } from "fs";
882
+ import path5 from "path";
883
883
  import { build as esbuild } from "esbuild";
884
884
  async function createPackage(rootProjectDir, options) {
885
885
  const mode = options?.mode || "production";
@@ -1011,8 +1011,8 @@ async function bundleTsFile(srcPath, outPath) {
1011
1011
  }
1012
1012
 
1013
1013
  // src/cli/dev.ts
1014
- import path7 from "node:path";
1015
- import { fileURLToPath as fileURLToPath3 } from "node:url";
1014
+ import path7 from "path";
1015
+ import { fileURLToPath as fileURLToPath3 } from "url";
1016
1016
  import cookieParser from "cookie-parser";
1017
1017
  import { default as express } from "express";
1018
1018
  import { dim as dim2 } from "kleur/colors";
@@ -1101,7 +1101,7 @@ function testIsRedirectValid(url) {
1101
1101
  }
1102
1102
 
1103
1103
  // src/render/asset-map/dev-asset-map.ts
1104
- import path6 from "node:path";
1104
+ import path6 from "path";
1105
1105
  import { searchForWorkspaceRoot as searchForWorkspaceRoot2 } from "vite";
1106
1106
  var DevServerAssetMap = class {
1107
1107
  rootConfig;
@@ -1231,7 +1231,7 @@ var DevServerAsset = class _DevServerAsset {
1231
1231
  };
1232
1232
 
1233
1233
  // src/utils/ports.ts
1234
- import { createServer } from "node:net";
1234
+ import { createServer } from "net";
1235
1235
  function isPortOpen(port) {
1236
1236
  return new Promise((resolve, reject) => {
1237
1237
  const server = createServer();
@@ -1492,8 +1492,8 @@ function debounce(fn, timeout) {
1492
1492
  }
1493
1493
 
1494
1494
  // src/cli/gae-deploy.ts
1495
- import { execSync } from "node:child_process";
1496
- import fs5 from "node:fs";
1495
+ import { execSync } from "child_process";
1496
+ import fs5 from "fs";
1497
1497
  import yaml from "js-yaml";
1498
1498
  async function gaeDeploy(appDir, options) {
1499
1499
  if (!appDir) {
@@ -1661,7 +1661,7 @@ function testManagedVersion(service, appInfo, prefix) {
1661
1661
  }
1662
1662
 
1663
1663
  // src/cli/preview.ts
1664
- import path8 from "node:path";
1664
+ import path8 from "path";
1665
1665
  import compression from "compression";
1666
1666
  import cookieParser2 from "cookie-parser";
1667
1667
  import { default as express2 } from "express";
@@ -1807,7 +1807,7 @@ function rootPreviewServer500Middleware() {
1807
1807
  }
1808
1808
 
1809
1809
  // src/cli/start.ts
1810
- import path9 from "node:path";
1810
+ import path9 from "path";
1811
1811
  import compression2 from "compression";
1812
1812
  import cookieParser3 from "cookie-parser";
1813
1813
  import { default as express3 } from "express";
@@ -2042,4 +2042,4 @@ export {
2042
2042
  createProdServer,
2043
2043
  CliRunner
2044
2044
  };
2045
- //# sourceMappingURL=chunk-CGKBPWW5.js.map
2045
+ //# sourceMappingURL=chunk-DBLKWTDH.js.map
@@ -1,5 +1,5 @@
1
1
  // src/middleware/common.ts
2
- import path from "node:path";
2
+ import path from "path";
3
3
  import micromatch from "micromatch";
4
4
  function rootProjectMiddleware(options) {
5
5
  return (req, _, next) => {
@@ -209,4 +209,4 @@ export {
209
209
  sessionMiddleware,
210
210
  Session
211
211
  };
212
- //# sourceMappingURL=chunk-DISVDCLA.js.map
212
+ //# sourceMappingURL=chunk-N677DHZI.js.map
@@ -3,12 +3,12 @@ import {
3
3
  } from "./chunk-V2WNR3EX.js";
4
4
 
5
5
  // src/node/monorepo.ts
6
- import path2 from "node:path";
6
+ import path2 from "path";
7
7
  import { getWorkspaces, getWorkspaceRoot } from "workspace-tools";
8
8
 
9
9
  // src/utils/fsutils.ts
10
- import fs from "node:fs";
11
- import path from "node:path";
10
+ import fs from "fs";
11
+ import path from "path";
12
12
  import fsExtra from "fs-extra";
13
13
  import glob from "tiny-glob";
14
14
  function isJsFile(filename) {
@@ -176,7 +176,7 @@ function sortDeps(deps) {
176
176
  }
177
177
 
178
178
  // src/node/load-config.ts
179
- import path3 from "node:path";
179
+ import path3 from "path";
180
180
  import { bundleRequire } from "bundle-require";
181
181
  import { build } from "esbuild";
182
182
  async function loadRootConfig(rootDir, options) {
@@ -360,4 +360,4 @@ export {
360
360
  createViteServer,
361
361
  viteSsrLoadModule
362
362
  };
363
- //# sourceMappingURL=chunk-KN32BDF2.js.map
363
+ //# sourceMappingURL=chunk-ZCX5PVMF.js.map
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as Server } from './types-mA-Pt2Qw.js';
1
+ import { S as Server } from './types-Cme7hyzR.js';
2
2
  import 'express';
3
3
  import 'preact';
4
4
  import 'vite';
package/dist/cli.js CHANGED
@@ -8,9 +8,9 @@ import {
8
8
  dev,
9
9
  preview,
10
10
  start
11
- } from "./chunk-CGKBPWW5.js";
12
- import "./chunk-DISVDCLA.js";
13
- import "./chunk-KN32BDF2.js";
11
+ } from "./chunk-DBLKWTDH.js";
12
+ import "./chunk-N677DHZI.js";
13
+ import "./chunk-ZCX5PVMF.js";
14
14
  import "./chunk-V2WNR3EX.js";
15
15
  import "./chunk-3KGEENDW.js";
16
16
  export {
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Route } from './types-mA-Pt2Qw.js';
2
- export { j as ConfigureServerHook, k as ConfigureServerOptions, C as ContentSecurityPolicyConfig, v as GetStaticContent, p as GetStaticPaths, G as GetStaticProps, t as Handler, H as HandlerContext, y as HandlerRenderFn, x as HandlerRenderOptions, L as LocaleGroup, M as MultipartFile, N as NextFunction, l as Plugin, P as PluginHooks, r as Request, q as RequestMiddleware, s as Response, d as RootBuildConfig, b as RootConfig, f as RootHeaderConfig, c as RootI18nConfig, e as RootRedirectConfig, g as RootSecurityConfig, h as RootServerConfig, a as RootUserConfig, w as RouteModule, o as RouteParams, S as Server, z as Sitemap, A as SitemapItem, u as StaticContentResult, X as XFrameOptionsConfig, m as configureServerPlugins, i as defineConfig, n as getVitePlugins } from './types-mA-Pt2Qw.js';
1
+ import { R as Route } from './types-Cme7hyzR.js';
2
+ export { j as ConfigureServerHook, k as ConfigureServerOptions, C as ContentSecurityPolicyConfig, v as GetStaticContent, p as GetStaticPaths, G as GetStaticProps, t as Handler, H as HandlerContext, y as HandlerRenderFn, x as HandlerRenderOptions, L as LocaleGroup, M as MultipartFile, N as NextFunction, l as Plugin, P as PluginHooks, r as Request, q as RequestMiddleware, s as Response, d as RootBuildConfig, b as RootConfig, f as RootHeaderConfig, c as RootI18nConfig, e as RootRedirectConfig, g as RootSecurityConfig, h as RootServerConfig, a as RootUserConfig, w as RouteModule, o as RouteParams, S as Server, z as Sitemap, A as SitemapItem, u as StaticContentResult, X as XFrameOptionsConfig, m as configureServerPlugins, i as defineConfig, n as getVitePlugins } from './types-Cme7hyzR.js';
3
3
  import * as preact$1 from 'preact';
4
4
  import { FunctionalComponent, ComponentChildren } from 'preact';
5
5
  import 'express';
@@ -53,7 +53,7 @@ interface HtmlContext {
53
53
  headAttrs: preact$1.JSX.HTMLAttributes<HTMLHeadElement>;
54
54
  headComponents: ComponentChildren[];
55
55
  bodyAttrs: preact$1.JSX.HTMLAttributes<HTMLBodyElement>;
56
- scriptDeps: Array<preact$1.JSX.HTMLAttributes<HTMLScriptElement>>;
56
+ scriptDeps: Array<preact$1.JSX.ScriptHTMLAttributes<HTMLScriptElement>>;
57
57
  }
58
58
  declare const HTML_CONTEXT: preact$1.Context<HtmlContext | null>;
59
59
  type HtmlProps = preact$1.JSX.HTMLAttributes<HTMLHtmlElement> & {
package/dist/core.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  getTranslations,
9
9
  useI18nContext,
10
10
  useRequestContext
11
- } from "./chunk-FKTS7ME3.js";
11
+ } from "./chunk-6RLXVNIT.js";
12
12
 
13
13
  // src/core/config.ts
14
14
  function defineConfig(config) {
package/dist/functions.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  createPreviewServer,
3
3
  createProdServer
4
- } from "./chunk-CGKBPWW5.js";
5
- import "./chunk-DISVDCLA.js";
6
- import "./chunk-KN32BDF2.js";
4
+ } from "./chunk-DBLKWTDH.js";
5
+ import "./chunk-N677DHZI.js";
6
+ import "./chunk-ZCX5PVMF.js";
7
7
  import "./chunk-V2WNR3EX.js";
8
8
  import "./chunk-3KGEENDW.js";
9
9
 
10
10
  // src/functions/server.ts
11
- import path from "node:path";
11
+ import path from "path";
12
12
  import { onRequest } from "firebase-functions/v2/https";
13
13
  function server(options) {
14
14
  let rootServer;
@@ -1,5 +1,5 @@
1
- import { b as RootConfig, r as Request, s as Response, N as NextFunction } from './types-mA-Pt2Qw.js';
2
- export { B as SESSION_COOKIE, E as SaveSessionOptions, I as Session, D as SessionMiddlewareOptions, F as sessionMiddleware } from './types-mA-Pt2Qw.js';
1
+ import { b as RootConfig, r as Request, s as Response, N as NextFunction } from './types-Cme7hyzR.js';
2
+ export { B as SESSION_COOKIE, E as SaveSessionOptions, I as Session, D as SessionMiddlewareOptions, F as sessionMiddleware } from './types-Cme7hyzR.js';
3
3
  import { RequestHandler } from 'express';
4
4
  import 'preact';
5
5
  import 'vite';
@@ -6,7 +6,7 @@ import {
6
6
  rootProjectMiddleware,
7
7
  sessionMiddleware,
8
8
  trailingSlashMiddleware
9
- } from "./chunk-DISVDCLA.js";
9
+ } from "./chunk-N677DHZI.js";
10
10
  export {
11
11
  SESSION_COOKIE,
12
12
  Session,
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as RootConfig } from './types-mA-Pt2Qw.js';
1
+ import { b as RootConfig } from './types-Cme7hyzR.js';
2
2
  import { PackageInfo } from 'workspace-tools';
3
3
  import { ViteDevServer } from 'vite';
4
4
  import 'express';
package/dist/node.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  loadPackageJson,
8
8
  loadRootConfig,
9
9
  viteSsrLoadModule
10
- } from "./chunk-KN32BDF2.js";
10
+ } from "./chunk-ZCX5PVMF.js";
11
11
  import "./chunk-V2WNR3EX.js";
12
12
  export {
13
13
  bundleRootConfig,
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { J as Renderer } from './types-mA-Pt2Qw.js';
1
+ export { J as Renderer } from './types-Cme7hyzR.js';
2
2
  import 'express';
3
3
  import 'preact';
4
4
  import 'vite';
package/dist/render.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  I18N_CONTEXT,
4
4
  REQUEST_CONTEXT,
5
5
  getTranslations
6
- } from "./chunk-FKTS7ME3.js";
6
+ } from "./chunk-6RLXVNIT.js";
7
7
  import {
8
8
  RouteTrie,
9
9
  htmlMinify,
@@ -12,8 +12,8 @@ import {
12
12
  } from "./chunk-3KGEENDW.js";
13
13
 
14
14
  // src/render/render.tsx
15
- import crypto from "node:crypto";
16
- import path2 from "node:path";
15
+ import crypto from "crypto";
16
+ import path2 from "path";
17
17
  import {
18
18
  options as preactOptions
19
19
  } from "preact";
@@ -12871,7 +12871,7 @@ function test419Country(countryCode) {
12871
12871
  }
12872
12872
 
12873
12873
  // src/render/router.ts
12874
- import path from "node:path";
12874
+ import path from "path";
12875
12875
  var ROUTES_FILES = import.meta.glob(
12876
12876
  ["/routes/*.ts", "/routes/**/*.ts", "/routes/*.tsx", "/routes/**/*.tsx"],
12877
12877
  { eager: true }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkk/root",
3
- "version": "2.2.1-alpha.0",
3
+ "version": "2.2.1-alpha.1",
4
4
  "author": "s@blinkk.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -104,12 +104,12 @@
104
104
  "firebase-admin": "11.11.0",
105
105
  "firebase-functions": "4.8.0",
106
106
  "nodemon": "3.0.1",
107
- "preact": "10.19.3",
108
- "preact-custom-element": "4.3.0",
109
- "preact-render-to-string": "6.3.1",
110
- "tsup": "8.0.1",
111
- "typescript": "5.2.2",
112
- "vitest": "0.34.6"
107
+ "preact": "10.27.1",
108
+ "preact-custom-element": "4.5.0",
109
+ "preact-render-to-string": "6.6.1",
110
+ "tsup": "8.5.0",
111
+ "typescript": "5.9.2",
112
+ "vitest": "3.2.4"
113
113
  },
114
114
  "scripts": {
115
115
  "build": "rm -rf dist && tsup-node",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/components/Html.tsx","../src/core/hooks/useI18nContext.ts","../src/core/hooks/useRequestContext.ts"],"sourcesContent":["import {ComponentChildren, FunctionalComponent, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport interface HtmlContext {\n htmlAttrs: preact.JSX.HTMLAttributes<HTMLHtmlElement>;\n headAttrs: preact.JSX.HTMLAttributes<HTMLHeadElement>;\n headComponents: ComponentChildren[];\n bodyAttrs: preact.JSX.HTMLAttributes<HTMLBodyElement>;\n scriptDeps: Array<preact.JSX.HTMLAttributes<HTMLScriptElement>>;\n}\n\nexport const HTML_CONTEXT = createContext<HtmlContext | null>(null);\n\nexport type HtmlProps = preact.JSX.HTMLAttributes<HTMLHtmlElement> & {\n children?: ComponentChildren;\n};\n\n/**\n * The `<Html>` component can be used to update attrs in the `<html>` tag.\n *\n * Usage:\n *\n * ```tsx\n * <Html lang=\"en-US\">\n * <h1>Hello world</h1>\n * </Html>\n * ```\n */\nexport const Html: FunctionalComponent<HtmlProps> = ({children, ...attrs}) => {\n const context = useContext(HTML_CONTEXT);\n if (!context) {\n throw new Error(\n 'HTML_CONTEXT not found, double-check usage of the <Html> component'\n );\n }\n context.htmlAttrs = attrs;\n return <>{children}</>;\n};\n","import path from 'node:path';\nimport {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const I18N_CONTEXT = createContext<I18nContext | null>(null);\n\nexport interface I18nContext {\n locale: string;\n translations: Record<string, string>;\n}\n\n/**\n * A hook that returns information about the current i18n context, including the\n * locale for the given route and a map of translations for that locale.\n */\nexport function useI18nContext() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('I18N_CONTEXT not found');\n }\n return context;\n}\n\nexport function getTranslations(locale: string): Record<string, string> {\n const translations: Record<string, Record<string, string>> = {};\n const translationsFiles = import.meta.glob(['/translations/*.json'], {\n eager: true,\n }) as Record<string, {default?: Record<string, string>}>;\n Object.keys(translationsFiles).forEach((translationPath) => {\n const parts = path.parse(translationPath);\n const locale = parts.name;\n const module = translationsFiles[translationPath];\n if (module && module.default) {\n translations[locale] = module.default;\n }\n });\n return translations[locale] || {};\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\nimport {Route} from '../types.js';\n\nexport interface RequestContext {\n /**\n * The current request path, e.g. `/foo/bar` (default route path) or\n * `/{locale}/foo/bar` (localized route path).\n */\n currentPath: string;\n /** The route file. */\n route: Route;\n /**\n * Route param values. E.g. for a route like `routes/blog/[slug].tsx`,\n * visiting `/blog/foo` will pass {slug: 'foo'} here.\n */\n routeParams: Record<string, string>;\n /** Props passed to the route's server component. */\n props: any;\n /** The current locale. */\n locale: string;\n /** Translations map for the current locale. */\n translations: Record<string, string>;\n /** CSP nonce value. */\n nonce?: string;\n}\n\nexport const REQUEST_CONTEXT = createContext<RequestContext | null>(null);\n\n/**\n * A hook that returns information about the current route.\n *\n * Usage:\n *\n * ```ts\n * const ctx = useRequestContext();\n * ctx.route.src;\n * // => 'routes/index.tsx'\n * ```\n */\nexport function useRequestContext() {\n const context = useContext(REQUEST_CONTEXT);\n if (!context) {\n throw new Error('REQUEST_CONTEXT not found');\n }\n return context;\n}\n"],"mappings":";AAAA,SAAgD,qBAAoB;AACpE,SAAQ,kBAAiB;AAmChB;AAzBF,IAAM,eAAe,cAAkC,IAAI;AAiB3D,IAAM,OAAuC,CAAC,EAAC,UAAU,GAAG,MAAK,MAAM;AAC5E,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,UAAQ,YAAY;AACpB,SAAO,gCAAG,UAAS;AACrB;;;ACrCA,OAAO,UAAU;AACjB,SAAQ,iBAAAA,sBAAoB;AAC5B,SAAQ,cAAAC,mBAAiB;AAElB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