@timber-js/app 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/timber.mjs +5 -0
- package/dist/_chunks/error-boundary-dj-WO5uq.js +121 -0
- package/dist/_chunks/error-boundary-dj-WO5uq.js.map +1 -0
- package/dist/_chunks/format-DNt20Kt8.js +163 -0
- package/dist/_chunks/format-DNt20Kt8.js.map +1 -0
- package/dist/_chunks/interception-DIaZN1bF.js +669 -0
- package/dist/_chunks/interception-DIaZN1bF.js.map +1 -0
- package/dist/_chunks/metadata-routes-BDnswgRO.js +141 -0
- package/dist/_chunks/metadata-routes-BDnswgRO.js.map +1 -0
- package/dist/_chunks/registry-DUIpYD_x.js +20 -0
- package/dist/_chunks/registry-DUIpYD_x.js.map +1 -0
- package/dist/_chunks/request-context-D6XHINkR.js +330 -0
- package/dist/_chunks/request-context-D6XHINkR.js.map +1 -0
- package/dist/_chunks/tracing-BtOwb8O6.js +174 -0
- package/dist/_chunks/tracing-BtOwb8O6.js.map +1 -0
- package/dist/_chunks/use-cookie-8ZlA0rr3.js +125 -0
- package/dist/_chunks/use-cookie-8ZlA0rr3.js.map +1 -0
- package/dist/adapters/cloudflare.d.ts +92 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +188 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/nitro.d.ts +72 -0
- package/dist/adapters/nitro.d.ts.map +1 -0
- package/dist/adapters/nitro.js +217 -0
- package/dist/adapters/nitro.js.map +1 -0
- package/dist/adapters/types.d.ts +53 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/cache/index.d.ts +52 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +283 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/redis-handler.d.ts +45 -0
- package/dist/cache/redis-handler.d.ts.map +1 -0
- package/dist/cache/register-cached-function.d.ts +17 -0
- package/dist/cache/register-cached-function.d.ts.map +1 -0
- package/dist/cache/singleflight.d.ts +11 -0
- package/dist/cache/singleflight.d.ts.map +1 -0
- package/dist/cache/stable-stringify.d.ts +7 -0
- package/dist/cache/stable-stringify.d.ts.map +1 -0
- package/dist/cache/timber-cache.d.ts +21 -0
- package/dist/cache/timber-cache.d.ts.map +1 -0
- package/dist/cli.d.ts +44 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +135 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/browser-entry.d.ts +22 -0
- package/dist/client/browser-entry.d.ts.map +1 -0
- package/dist/client/error-boundary.d.ts +42 -0
- package/dist/client/error-boundary.d.ts.map +1 -0
- package/dist/client/form.d.ts +115 -0
- package/dist/client/form.d.ts.map +1 -0
- package/dist/client/head.d.ts +16 -0
- package/dist/client/head.d.ts.map +1 -0
- package/dist/client/history.d.ts +29 -0
- package/dist/client/history.d.ts.map +1 -0
- package/dist/client/index.d.ts +32 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1218 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/link-navigate-interceptor.d.ts +28 -0
- package/dist/client/link-navigate-interceptor.d.ts.map +1 -0
- package/dist/client/link-status-provider.d.ts +11 -0
- package/dist/client/link-status-provider.d.ts.map +1 -0
- package/dist/client/link.d.ts +119 -0
- package/dist/client/link.d.ts.map +1 -0
- package/dist/client/nuqs-adapter.d.ts +11 -0
- package/dist/client/nuqs-adapter.d.ts.map +1 -0
- package/dist/client/router-ref.d.ts +11 -0
- package/dist/client/router-ref.d.ts.map +1 -0
- package/dist/client/router.d.ts +85 -0
- package/dist/client/router.d.ts.map +1 -0
- package/dist/client/segment-cache.d.ts +88 -0
- package/dist/client/segment-cache.d.ts.map +1 -0
- package/dist/client/segment-context.d.ts +32 -0
- package/dist/client/segment-context.d.ts.map +1 -0
- package/dist/client/ssr-data.d.ts +64 -0
- package/dist/client/ssr-data.d.ts.map +1 -0
- package/dist/client/types.d.ts +5 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/unload-guard.d.ts +18 -0
- package/dist/client/unload-guard.d.ts.map +1 -0
- package/dist/client/use-cookie.d.ts +37 -0
- package/dist/client/use-cookie.d.ts.map +1 -0
- package/dist/client/use-link-status.d.ts +35 -0
- package/dist/client/use-link-status.d.ts.map +1 -0
- package/dist/client/use-navigation-pending.d.ts +26 -0
- package/dist/client/use-navigation-pending.d.ts.map +1 -0
- package/dist/client/use-params.d.ts +50 -0
- package/dist/client/use-params.d.ts.map +1 -0
- package/dist/client/use-pathname.d.ts +20 -0
- package/dist/client/use-pathname.d.ts.map +1 -0
- package/dist/client/use-query-states.d.ts +36 -0
- package/dist/client/use-query-states.d.ts.map +1 -0
- package/dist/client/use-router.d.ts +39 -0
- package/dist/client/use-router.d.ts.map +1 -0
- package/dist/client/use-search-params.d.ts +24 -0
- package/dist/client/use-search-params.d.ts.map +1 -0
- package/dist/client/use-selected-layout-segment.d.ts +68 -0
- package/dist/client/use-selected-layout-segment.d.ts.map +1 -0
- package/dist/content/index.d.ts +11 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +2 -0
- package/dist/cookies/define-cookie.d.ts +61 -0
- package/dist/cookies/define-cookie.d.ts.map +1 -0
- package/dist/cookies/index.d.ts +3 -0
- package/dist/cookies/index.d.ts.map +1 -0
- package/dist/cookies/index.js +82 -0
- package/dist/cookies/index.js.map +1 -0
- package/dist/fonts/ast.d.ts +38 -0
- package/dist/fonts/ast.d.ts.map +1 -0
- package/dist/fonts/css.d.ts +43 -0
- package/dist/fonts/css.d.ts.map +1 -0
- package/dist/fonts/fallbacks.d.ts +36 -0
- package/dist/fonts/fallbacks.d.ts.map +1 -0
- package/dist/fonts/google.d.ts +122 -0
- package/dist/fonts/google.d.ts.map +1 -0
- package/dist/fonts/local.d.ts +76 -0
- package/dist/fonts/local.d.ts.map +1 -0
- package/dist/fonts/types.d.ts +85 -0
- package/dist/fonts/types.d.ts.map +1 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14701 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/adapter-build.d.ts +18 -0
- package/dist/plugins/adapter-build.d.ts.map +1 -0
- package/dist/plugins/build-manifest.d.ts +79 -0
- package/dist/plugins/build-manifest.d.ts.map +1 -0
- package/dist/plugins/build-report.d.ts +63 -0
- package/dist/plugins/build-report.d.ts.map +1 -0
- package/dist/plugins/cache-transform.d.ts +36 -0
- package/dist/plugins/cache-transform.d.ts.map +1 -0
- package/dist/plugins/chunks.d.ts +45 -0
- package/dist/plugins/chunks.d.ts.map +1 -0
- package/dist/plugins/content.d.ts +19 -0
- package/dist/plugins/content.d.ts.map +1 -0
- package/dist/plugins/dev-error-overlay.d.ts +60 -0
- package/dist/plugins/dev-error-overlay.d.ts.map +1 -0
- package/dist/plugins/dev-logs.d.ts +46 -0
- package/dist/plugins/dev-logs.d.ts.map +1 -0
- package/dist/plugins/dev-server.d.ts +22 -0
- package/dist/plugins/dev-server.d.ts.map +1 -0
- package/dist/plugins/dynamic-transform.d.ts +72 -0
- package/dist/plugins/dynamic-transform.d.ts.map +1 -0
- package/dist/plugins/entries.d.ts +21 -0
- package/dist/plugins/entries.d.ts.map +1 -0
- package/dist/plugins/fonts.d.ts +77 -0
- package/dist/plugins/fonts.d.ts.map +1 -0
- package/dist/plugins/mdx.d.ts +21 -0
- package/dist/plugins/mdx.d.ts.map +1 -0
- package/dist/plugins/react-prod.d.ts +18 -0
- package/dist/plugins/react-prod.d.ts.map +1 -0
- package/dist/plugins/routing.d.ts +13 -0
- package/dist/plugins/routing.d.ts.map +1 -0
- package/dist/plugins/server-action-exports.d.ts +26 -0
- package/dist/plugins/server-action-exports.d.ts.map +1 -0
- package/dist/plugins/server-bundle.d.ts +15 -0
- package/dist/plugins/server-bundle.d.ts.map +1 -0
- package/dist/plugins/shims.d.ts +18 -0
- package/dist/plugins/shims.d.ts.map +1 -0
- package/dist/plugins/static-build.d.ts +55 -0
- package/dist/plugins/static-build.d.ts.map +1 -0
- package/dist/routing/codegen.d.ts +29 -0
- package/dist/routing/codegen.d.ts.map +1 -0
- package/dist/routing/index.d.ts +8 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +2 -0
- package/dist/routing/interception.d.ts +46 -0
- package/dist/routing/interception.d.ts.map +1 -0
- package/dist/routing/scanner.d.ts +28 -0
- package/dist/routing/scanner.d.ts.map +1 -0
- package/dist/routing/status-file-lint.d.ts +33 -0
- package/dist/routing/status-file-lint.d.ts.map +1 -0
- package/dist/routing/types.d.ts +81 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/search-params/analyze.d.ts +54 -0
- package/dist/search-params/analyze.d.ts.map +1 -0
- package/dist/search-params/codecs.d.ts +53 -0
- package/dist/search-params/codecs.d.ts.map +1 -0
- package/dist/search-params/create.d.ts +106 -0
- package/dist/search-params/create.d.ts.map +1 -0
- package/dist/search-params/index.d.ts +7 -0
- package/dist/search-params/index.d.ts.map +1 -0
- package/dist/search-params/index.js +300 -0
- package/dist/search-params/index.js.map +1 -0
- package/dist/search-params/registry.d.ts +20 -0
- package/dist/search-params/registry.d.ts.map +1 -0
- package/dist/server/access-gate.d.ts +42 -0
- package/dist/server/access-gate.d.ts.map +1 -0
- package/dist/server/action-client.d.ts +190 -0
- package/dist/server/action-client.d.ts.map +1 -0
- package/dist/server/action-handler.d.ts +48 -0
- package/dist/server/action-handler.d.ts.map +1 -0
- package/dist/server/actions.d.ts +108 -0
- package/dist/server/actions.d.ts.map +1 -0
- package/dist/server/asset-headers.d.ts +42 -0
- package/dist/server/asset-headers.d.ts.map +1 -0
- package/dist/server/body-limits.d.ts +30 -0
- package/dist/server/body-limits.d.ts.map +1 -0
- package/dist/server/build-manifest.d.ts +120 -0
- package/dist/server/build-manifest.d.ts.map +1 -0
- package/dist/server/canonicalize.d.ts +30 -0
- package/dist/server/canonicalize.d.ts.map +1 -0
- package/dist/server/client-module-map.d.ts +47 -0
- package/dist/server/client-module-map.d.ts.map +1 -0
- package/dist/server/csrf.d.ts +34 -0
- package/dist/server/csrf.d.ts.map +1 -0
- package/dist/server/deny-renderer.d.ts +49 -0
- package/dist/server/deny-renderer.d.ts.map +1 -0
- package/dist/server/dev-logger.d.ts +44 -0
- package/dist/server/dev-logger.d.ts.map +1 -0
- package/dist/server/dev-span-processor.d.ts +29 -0
- package/dist/server/dev-span-processor.d.ts.map +1 -0
- package/dist/server/dev-warnings.d.ts +129 -0
- package/dist/server/dev-warnings.d.ts.map +1 -0
- package/dist/server/early-hints-sender.d.ts +38 -0
- package/dist/server/early-hints-sender.d.ts.map +1 -0
- package/dist/server/early-hints.d.ts +83 -0
- package/dist/server/early-hints.d.ts.map +1 -0
- package/dist/server/error-boundary-wrapper.d.ts +17 -0
- package/dist/server/error-boundary-wrapper.d.ts.map +1 -0
- package/dist/server/error-formatter.d.ts +17 -0
- package/dist/server/error-formatter.d.ts.map +1 -0
- package/dist/server/flush.d.ts +74 -0
- package/dist/server/flush.d.ts.map +1 -0
- package/dist/server/form-data.d.ts +60 -0
- package/dist/server/form-data.d.ts.map +1 -0
- package/dist/server/form-flash.d.ts +78 -0
- package/dist/server/form-flash.d.ts.map +1 -0
- package/dist/server/html-injectors.d.ts +101 -0
- package/dist/server/html-injectors.d.ts.map +1 -0
- package/dist/server/index.d.ts +54 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2925 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/instrumentation.d.ts +61 -0
- package/dist/server/instrumentation.d.ts.map +1 -0
- package/dist/server/logger.d.ts +83 -0
- package/dist/server/logger.d.ts.map +1 -0
- package/dist/server/manifest-status-resolver.d.ts +58 -0
- package/dist/server/manifest-status-resolver.d.ts.map +1 -0
- package/dist/server/metadata-render.d.ts +20 -0
- package/dist/server/metadata-render.d.ts.map +1 -0
- package/dist/server/metadata-routes.d.ts +67 -0
- package/dist/server/metadata-routes.d.ts.map +1 -0
- package/dist/server/metadata.d.ts +67 -0
- package/dist/server/metadata.d.ts.map +1 -0
- package/dist/server/middleware-runner.d.ts +21 -0
- package/dist/server/middleware-runner.d.ts.map +1 -0
- package/dist/server/nuqs-ssr-provider.d.ts +28 -0
- package/dist/server/nuqs-ssr-provider.d.ts.map +1 -0
- package/dist/server/pipeline.d.ts +81 -0
- package/dist/server/pipeline.d.ts.map +1 -0
- package/dist/server/prerender.d.ts +77 -0
- package/dist/server/prerender.d.ts.map +1 -0
- package/dist/server/primitives.d.ts +131 -0
- package/dist/server/primitives.d.ts.map +1 -0
- package/dist/server/proxy.d.ts +23 -0
- package/dist/server/proxy.d.ts.map +1 -0
- package/dist/server/request-context.d.ts +175 -0
- package/dist/server/request-context.d.ts.map +1 -0
- package/dist/server/route-element-builder.d.ts +66 -0
- package/dist/server/route-element-builder.d.ts.map +1 -0
- package/dist/server/route-handler.d.ts +35 -0
- package/dist/server/route-handler.d.ts.map +1 -0
- package/dist/server/route-matcher.d.ts +78 -0
- package/dist/server/route-matcher.d.ts.map +1 -0
- package/dist/server/rsc-entry/api-handler.d.ts +11 -0
- package/dist/server/rsc-entry/api-handler.d.ts.map +1 -0
- package/dist/server/rsc-entry/error-renderer.d.ts +30 -0
- package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -0
- package/dist/server/rsc-entry/helpers.d.ts +73 -0
- package/dist/server/rsc-entry/helpers.d.ts.map +1 -0
- package/dist/server/rsc-entry/index.d.ts +11 -0
- package/dist/server/rsc-entry/index.d.ts.map +1 -0
- package/dist/server/rsc-entry/ssr-bridge.d.ts +6 -0
- package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -0
- package/dist/server/slot-resolver.d.ts +34 -0
- package/dist/server/slot-resolver.d.ts.map +1 -0
- package/dist/server/ssr-entry.d.ts +73 -0
- package/dist/server/ssr-entry.d.ts.map +1 -0
- package/dist/server/ssr-render.d.ts +67 -0
- package/dist/server/ssr-render.d.ts.map +1 -0
- package/dist/server/status-code-resolver.d.ts +77 -0
- package/dist/server/status-code-resolver.d.ts.map +1 -0
- package/dist/server/tracing.d.ts +99 -0
- package/dist/server/tracing.d.ts.map +1 -0
- package/dist/server/tree-builder.d.ts +116 -0
- package/dist/server/tree-builder.d.ts.map +1 -0
- package/dist/server/types.d.ts +231 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/shims/font-google.d.ts +41 -0
- package/dist/shims/font-google.d.ts.map +1 -0
- package/dist/shims/headers.d.ts +11 -0
- package/dist/shims/headers.d.ts.map +1 -0
- package/dist/shims/image.d.ts +328 -0
- package/dist/shims/image.d.ts.map +1 -0
- package/dist/shims/link.d.ts +9 -0
- package/dist/shims/link.d.ts.map +1 -0
- package/dist/shims/navigation-client.d.ts +25 -0
- package/dist/shims/navigation-client.d.ts.map +1 -0
- package/dist/shims/navigation.d.ts +25 -0
- package/dist/shims/navigation.d.ts.map +1 -0
- package/dist/utils/directive-parser.d.ts +70 -0
- package/dist/utils/directive-parser.d.ts.map +1 -0
- package/dist/utils/format.d.ts +6 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/startup-timer.d.ts +34 -0
- package/dist/utils/startup-timer.d.ts.map +1 -0
- package/package.json +140 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { n as cookies } from "../_chunks/request-context-D6XHINkR.js";
|
|
2
|
+
import { t as useCookie } from "../_chunks/use-cookie-8ZlA0rr3.js";
|
|
3
|
+
//#region src/cookies/define-cookie.ts
|
|
4
|
+
/**
|
|
5
|
+
* defineCookie — typed cookie definitions.
|
|
6
|
+
*
|
|
7
|
+
* Bundles name + codec + options into a reusable CookieDefinition<T>
|
|
8
|
+
* with .get(), .set(), .delete() server methods and a .useCookie() client hook.
|
|
9
|
+
*
|
|
10
|
+
* Reuses the SearchParamCodec protocol via fromSchema() bridge.
|
|
11
|
+
* Validation on read returns the codec default (never throws).
|
|
12
|
+
*
|
|
13
|
+
* See design/29-cookies.md §"Typed Cookies with Schema Validation"
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Define a typed cookie.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineCookie } from '@timber/app/cookies';
|
|
20
|
+
* import { fromSchema } from '@timber/app/search-params';
|
|
21
|
+
* import { z } from 'zod/v4';
|
|
22
|
+
*
|
|
23
|
+
* export const themeCookie = defineCookie('theme', {
|
|
24
|
+
* codec: fromSchema(z.enum(['light', 'dark', 'system']).default('system')),
|
|
25
|
+
* httpOnly: false,
|
|
26
|
+
* maxAge: 60 * 60 * 24 * 365,
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function defineCookie(name, options) {
|
|
31
|
+
const { codec, ...cookieOpts } = options;
|
|
32
|
+
const resolvedOptions = { ...cookieOpts };
|
|
33
|
+
return {
|
|
34
|
+
name,
|
|
35
|
+
options: resolvedOptions,
|
|
36
|
+
codec,
|
|
37
|
+
get() {
|
|
38
|
+
const jar = cookies();
|
|
39
|
+
const raw = resolvedOptions.signed ? jar.getSigned(name) : jar.get(name);
|
|
40
|
+
return codec.parse(raw);
|
|
41
|
+
},
|
|
42
|
+
set(value) {
|
|
43
|
+
const serialized = codec.serialize(value);
|
|
44
|
+
if (serialized === null) cookies().delete(name, {
|
|
45
|
+
path: resolvedOptions.path,
|
|
46
|
+
domain: resolvedOptions.domain
|
|
47
|
+
});
|
|
48
|
+
else cookies().set(name, serialized, resolvedOptions);
|
|
49
|
+
},
|
|
50
|
+
delete() {
|
|
51
|
+
cookies().delete(name, {
|
|
52
|
+
path: resolvedOptions.path,
|
|
53
|
+
domain: resolvedOptions.domain
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
useCookie() {
|
|
57
|
+
const [raw, setRaw, deleteRaw] = useCookie(name, {
|
|
58
|
+
path: resolvedOptions.path,
|
|
59
|
+
domain: resolvedOptions.domain,
|
|
60
|
+
maxAge: resolvedOptions.maxAge,
|
|
61
|
+
expires: resolvedOptions.expires,
|
|
62
|
+
sameSite: resolvedOptions.sameSite,
|
|
63
|
+
secure: resolvedOptions.secure
|
|
64
|
+
});
|
|
65
|
+
const parsed = codec.parse(raw);
|
|
66
|
+
const setTyped = (value) => {
|
|
67
|
+
const serialized = codec.serialize(value);
|
|
68
|
+
if (serialized === null) deleteRaw();
|
|
69
|
+
else setRaw(serialized);
|
|
70
|
+
};
|
|
71
|
+
return [
|
|
72
|
+
parsed,
|
|
73
|
+
setTyped,
|
|
74
|
+
deleteRaw
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { defineCookie };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/cookies/define-cookie.ts"],"sourcesContent":["/**\n * defineCookie — typed cookie definitions.\n *\n * Bundles name + codec + options into a reusable CookieDefinition<T>\n * with .get(), .set(), .delete() server methods and a .useCookie() client hook.\n *\n * Reuses the SearchParamCodec protocol via fromSchema() bridge.\n * Validation on read returns the codec default (never throws).\n *\n * See design/29-cookies.md §\"Typed Cookies with Schema Validation\"\n */\n\nimport { cookies } from '#/server/request-context.js';\nimport type { CookieOptions } from '#/server/request-context.js';\nimport { useCookie as useRawCookie } from '#/client/use-cookie.js';\nimport type { ClientCookieOptions } from '#/client/use-cookie.js';\n\n// ─── Types ────────────────────────────────────────────────────────────────\n\n/**\n * A codec that converts between string cookie values and typed values.\n * Intentionally identical to SearchParamCodec<T>.\n */\nexport interface CookieCodec<T> {\n parse(value: string | string[] | undefined): T;\n serialize(value: T): string | null;\n}\n\n/** Options for defineCookie: codec + CookieOptions merged. */\nexport interface DefineCookieOptions<T> extends Omit<CookieOptions, 'signed'> {\n /** Codec for parsing/serializing the cookie value. */\n codec: CookieCodec<T>;\n /** Sign the cookie with HMAC-SHA256. */\n signed?: boolean;\n}\n\n/** A fully typed cookie definition with server and client methods. */\nexport interface CookieDefinition<T> {\n /** The cookie name. */\n readonly name: string;\n /** The resolved cookie options (without codec). */\n readonly options: CookieOptions;\n /** The codec used for parsing/serializing. */\n readonly codec: CookieCodec<T>;\n\n /** Server: read the typed value from the current request. */\n get(): T;\n /** Server: set the typed value on the response. */\n set(value: T): void;\n /** Server: delete the cookie. */\n delete(): void;\n\n /** Client: React hook for reading/writing this cookie. Returns [value, setter, deleter]. */\n useCookie(): [T, (value: T) => void, () => void];\n}\n\n// ─── Factory ──────────────────────────────────────────────────────────────\n\n/**\n * Define a typed cookie.\n *\n * ```ts\n * import { defineCookie } from '@timber/app/cookies';\n * import { fromSchema } from '@timber/app/search-params';\n * import { z } from 'zod/v4';\n *\n * export const themeCookie = defineCookie('theme', {\n * codec: fromSchema(z.enum(['light', 'dark', 'system']).default('system')),\n * httpOnly: false,\n * maxAge: 60 * 60 * 24 * 365,\n * });\n * ```\n */\nexport function defineCookie<T>(\n name: string,\n options: DefineCookieOptions<T>\n): CookieDefinition<T> {\n const { codec, ...cookieOpts } = options;\n const resolvedOptions: CookieOptions = { ...cookieOpts };\n\n return {\n name,\n options: resolvedOptions,\n codec,\n\n get(): T {\n const jar = cookies();\n const raw = resolvedOptions.signed ? jar.getSigned(name) : jar.get(name);\n return codec.parse(raw);\n },\n\n set(value: T): void {\n const serialized = codec.serialize(value);\n if (serialized === null) {\n cookies().delete(name, {\n path: resolvedOptions.path,\n domain: resolvedOptions.domain,\n });\n } else {\n cookies().set(name, serialized, resolvedOptions);\n }\n },\n\n delete(): void {\n cookies().delete(name, {\n path: resolvedOptions.path,\n domain: resolvedOptions.domain,\n });\n },\n\n useCookie(): [T, (value: T) => void, () => void] {\n // Extract client-safe options (no httpOnly — client cookies can't be httpOnly)\n const clientOpts: ClientCookieOptions = {\n path: resolvedOptions.path,\n domain: resolvedOptions.domain,\n maxAge: resolvedOptions.maxAge,\n expires: resolvedOptions.expires,\n sameSite: resolvedOptions.sameSite,\n secure: resolvedOptions.secure,\n };\n\n const [raw, setRaw, deleteRaw] = useRawCookie(name, clientOpts);\n const parsed = codec.parse(raw);\n\n const setTyped = (value: T): void => {\n const serialized = codec.serialize(value);\n if (serialized === null) {\n deleteRaw();\n } else {\n setRaw(serialized);\n }\n };\n\n return [parsed, setTyped, deleteRaw];\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,aACd,MACA,SACqB;CACrB,MAAM,EAAE,OAAO,GAAG,eAAe;CACjC,MAAM,kBAAiC,EAAE,GAAG,YAAY;AAExD,QAAO;EACL;EACA,SAAS;EACT;EAEA,MAAS;GACP,MAAM,MAAM,SAAS;GACrB,MAAM,MAAM,gBAAgB,SAAS,IAAI,UAAU,KAAK,GAAG,IAAI,IAAI,KAAK;AACxE,UAAO,MAAM,MAAM,IAAI;;EAGzB,IAAI,OAAgB;GAClB,MAAM,aAAa,MAAM,UAAU,MAAM;AACzC,OAAI,eAAe,KACjB,UAAS,CAAC,OAAO,MAAM;IACrB,MAAM,gBAAgB;IACtB,QAAQ,gBAAgB;IACzB,CAAC;OAEF,UAAS,CAAC,IAAI,MAAM,YAAY,gBAAgB;;EAIpD,SAAe;AACb,YAAS,CAAC,OAAO,MAAM;IACrB,MAAM,gBAAgB;IACtB,QAAQ,gBAAgB;IACzB,CAAC;;EAGJ,YAAiD;GAW/C,MAAM,CAAC,KAAK,QAAQ,aAAa,UAAa,MATN;IACtC,MAAM,gBAAgB;IACtB,QAAQ,gBAAgB;IACxB,QAAQ,gBAAgB;IACxB,SAAS,gBAAgB;IACzB,UAAU,gBAAgB;IAC1B,QAAQ,gBAAgB;IACzB,CAE8D;GAC/D,MAAM,SAAS,MAAM,MAAM,IAAI;GAE/B,MAAM,YAAY,UAAmB;IACnC,MAAM,aAAa,MAAM,UAAU,MAAM;AACzC,QAAI,eAAe,KACjB,YAAW;QAEX,QAAO,WAAW;;AAItB,UAAO;IAAC;IAAQ;IAAU;IAAU;;EAEvC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acorn-based AST utilities for extracting static font configs from source code.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the fragile regex-based extraction in fonts.ts and local.ts.
|
|
5
|
+
* Uses acorn (already a Vite dependency) for robust parsing that handles
|
|
6
|
+
* comments, trailing commas, multi-line configs, and other edge cases
|
|
7
|
+
* the regex approach missed.
|
|
8
|
+
*
|
|
9
|
+
* Design doc: 24-fonts.md §"Step 1: Static Analysis"
|
|
10
|
+
*/
|
|
11
|
+
import type { GoogleFontConfig } from './types.js';
|
|
12
|
+
import type { LocalFontConfig } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Extract a GoogleFontConfig from the source text of a font function call's
|
|
15
|
+
* object argument.
|
|
16
|
+
*
|
|
17
|
+
* The `callSource` should be the text of the call's argument list including
|
|
18
|
+
* parens, e.g. `({ subsets: ['latin'], weight: '400' })`.
|
|
19
|
+
*
|
|
20
|
+
* Returns null if parsing or extraction fails.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractFontConfigAst(callSource: string): GoogleFontConfig | null;
|
|
23
|
+
/**
|
|
24
|
+
* Extract a LocalFontConfig from the source text of a localFont() call's
|
|
25
|
+
* object argument.
|
|
26
|
+
*
|
|
27
|
+
* Returns null if parsing or extraction fails.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractLocalFontConfigAst(callSource: string): LocalFontConfig | null;
|
|
30
|
+
/**
|
|
31
|
+
* Detect if source code contains dynamic/computed font function calls
|
|
32
|
+
* that cannot be statically analyzed.
|
|
33
|
+
*
|
|
34
|
+
* Uses acorn to parse the full source and inspect CallExpression nodes.
|
|
35
|
+
* Returns the offending expression string if found, null if all calls are static.
|
|
36
|
+
*/
|
|
37
|
+
export declare function detectDynamicFontCallAst(source: string, importedNames: string[]): string | null;
|
|
38
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/fonts/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AA0HhE;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CA4DhF;AAiCD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA4CpF;AAID;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAiB/F"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @font-face CSS generation.
|
|
3
|
+
*
|
|
4
|
+
* Generates CSS strings from font face descriptors. Used by both
|
|
5
|
+
* Google and local font providers.
|
|
6
|
+
*
|
|
7
|
+
* Design doc: 24-fonts.md §"Step 3: @font-face Generation"
|
|
8
|
+
*/
|
|
9
|
+
import type { FontFaceDescriptor } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Generate a single `@font-face` CSS rule from a descriptor.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateFontFace(desc: FontFaceDescriptor): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate multiple `@font-face` rules from an array of descriptors.
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateFontFaces(descriptors: FontFaceDescriptor[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generate a scoped CSS class that sets a CSS custom property for the font.
|
|
20
|
+
*
|
|
21
|
+
* Example output:
|
|
22
|
+
* ```css
|
|
23
|
+
* .timber-font-inter {
|
|
24
|
+
* --font-sans: 'Inter', 'Inter Fallback', system-ui, sans-serif;
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateVariableClass(className: string, variable: string, fontFamily: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a scoped CSS class that applies font-family directly.
|
|
31
|
+
*
|
|
32
|
+
* Used when no `variable` is specified — the className applies
|
|
33
|
+
* the font-family inline instead of through a CSS custom property.
|
|
34
|
+
*
|
|
35
|
+
* Example output:
|
|
36
|
+
* ```css
|
|
37
|
+
* .timber-font-inter {
|
|
38
|
+
* font-family: 'Inter', 'Inter Fallback', system-ui, sans-serif;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateFontFamilyClass(className: string, fontFamily: string): string;
|
|
43
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/fonts/css.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAWjE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAE3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAErF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size-adjusted fallback font generation.
|
|
3
|
+
*
|
|
4
|
+
* Generates `@font-face` declarations for fallback fonts with
|
|
5
|
+
* `size-adjust`, `ascent-override`, `descent-override`, and
|
|
6
|
+
* `line-gap-override` to match custom font metrics and eliminate CLS.
|
|
7
|
+
*
|
|
8
|
+
* Design doc: 24-fonts.md §"Step 4: Size-Adjusted Fallbacks"
|
|
9
|
+
*/
|
|
10
|
+
import type { FontFaceDescriptor } from './types.js';
|
|
11
|
+
export declare function getGenericFamily(family: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Generate a size-adjusted fallback @font-face for a given font family.
|
|
14
|
+
*
|
|
15
|
+
* Returns null if no metrics are available (unknown font — no fallback generated).
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateFallbackFontFace(family: string): FontFaceDescriptor | null;
|
|
18
|
+
/**
|
|
19
|
+
* Generate the full CSS for a size-adjusted fallback font.
|
|
20
|
+
*
|
|
21
|
+
* This produces a complete @font-face block with override descriptors
|
|
22
|
+
* that FontFaceDescriptor doesn't natively support.
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateFallbackCss(family: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Check whether fallback metrics are available for a font family.
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasFallbackMetrics(family: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Build the full font stack string for a font, including its
|
|
31
|
+
* size-adjusted fallback and a generic family.
|
|
32
|
+
*
|
|
33
|
+
* Example: `'Inter', 'Inter Fallback', system-ui, sans-serif`
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildFontStack(family: string): string;
|
|
36
|
+
//# sourceMappingURL=fallbacks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../../src/fonts/fallbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAwJrD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOvD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAclF;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBjE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAgBrD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Fonts download, caching, and dev CDN fallback.
|
|
3
|
+
*
|
|
4
|
+
* At build time (production only):
|
|
5
|
+
* 1. Queries Google Fonts CSS API v2 for font metadata and file URLs
|
|
6
|
+
* 2. Downloads woff2 font files
|
|
7
|
+
* 3. Caches them in node_modules/.cache/timber-fonts/
|
|
8
|
+
* 4. Content-hashes filenames for cache busting
|
|
9
|
+
* 5. Emits font files into the build output via generateBundle
|
|
10
|
+
*
|
|
11
|
+
* In dev mode:
|
|
12
|
+
* - Generates @font-face rules pointing to Google Fonts CDN
|
|
13
|
+
* - No downloads, no caching
|
|
14
|
+
*
|
|
15
|
+
* Design doc: 24-fonts.md §"Step 2: Font Download & Subsetting"
|
|
16
|
+
*/
|
|
17
|
+
import type { ExtractedFont, FontFaceDescriptor } from './types.js';
|
|
18
|
+
/** A parsed @font-face block from the Google Fonts CSS response. */
|
|
19
|
+
export interface GoogleFontFace {
|
|
20
|
+
family: string;
|
|
21
|
+
weight: string;
|
|
22
|
+
style: string;
|
|
23
|
+
/** The remote URL to the font file. */
|
|
24
|
+
url: string;
|
|
25
|
+
/** The unicode-range from the CSS (e.g. `U+0000-00FF, U+0131`). */
|
|
26
|
+
unicodeRange: string;
|
|
27
|
+
/** Subset label extracted from the CSS comment (e.g. `latin`, `cyrillic`). */
|
|
28
|
+
subset: string;
|
|
29
|
+
}
|
|
30
|
+
/** A downloaded and cached font file, ready for build output. */
|
|
31
|
+
export interface CachedFont {
|
|
32
|
+
/** The original parsed face data. */
|
|
33
|
+
face: GoogleFontFace;
|
|
34
|
+
/** Content-hashed filename (e.g. `inter-latin-400-normal-abc123.woff2`). */
|
|
35
|
+
hashedFilename: string;
|
|
36
|
+
/** Absolute path to the cached file. */
|
|
37
|
+
cachePath: string;
|
|
38
|
+
/** Raw font file bytes. */
|
|
39
|
+
data: Buffer;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the Google Fonts CSS API v2 URL for a given font config.
|
|
43
|
+
*
|
|
44
|
+
* Example output:
|
|
45
|
+
* https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap&subset=latin
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildGoogleFontsUrl(font: ExtractedFont): string;
|
|
48
|
+
/**
|
|
49
|
+
* Fetch the CSS from Google Fonts API and parse out @font-face blocks.
|
|
50
|
+
*
|
|
51
|
+
* The API returns CSS with subset comments like:
|
|
52
|
+
* ```
|
|
53
|
+
* /* latin * /
|
|
54
|
+
* @font-face { ... }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* We parse each block to extract the font URL, unicode-range, and subset label.
|
|
58
|
+
*/
|
|
59
|
+
export declare function fetchGoogleFontsCss(url: string): Promise<GoogleFontFace[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Parse the CSS response from Google Fonts API into structured font face data.
|
|
62
|
+
*
|
|
63
|
+
* Handles the Google Fonts CSS format with subset comments and @font-face blocks.
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseGoogleFontsCss(css: string): GoogleFontFace[];
|
|
66
|
+
/**
|
|
67
|
+
* Filter parsed font faces to only the requested subsets.
|
|
68
|
+
*/
|
|
69
|
+
export declare function filterBySubsets(faces: GoogleFontFace[], subsets: string[]): GoogleFontFace[];
|
|
70
|
+
/**
|
|
71
|
+
* Generate a content hash for font data.
|
|
72
|
+
* Returns the first 8 hex chars of the SHA-256 hash.
|
|
73
|
+
*/
|
|
74
|
+
export declare function contentHash(data: Buffer): string;
|
|
75
|
+
/**
|
|
76
|
+
* Generate a content-hashed filename for a font face.
|
|
77
|
+
*
|
|
78
|
+
* Format: `<family>-<subset>-<weight>-<style>-<hash>.woff2`
|
|
79
|
+
* Example: `inter-latin-400-normal-abc12345.woff2`
|
|
80
|
+
*/
|
|
81
|
+
export declare function hashedFontFilename(face: GoogleFontFace, data: Buffer): string;
|
|
82
|
+
/**
|
|
83
|
+
* Build the cache key for a font face.
|
|
84
|
+
* Used to check if a font has already been downloaded.
|
|
85
|
+
*/
|
|
86
|
+
export declare function cacheKey(face: GoogleFontFace): string;
|
|
87
|
+
/**
|
|
88
|
+
* Download a single font file from its URL.
|
|
89
|
+
*/
|
|
90
|
+
export declare function downloadFontFile(url: string): Promise<Buffer>;
|
|
91
|
+
/**
|
|
92
|
+
* Download and cache all font files for a set of extracted Google fonts.
|
|
93
|
+
*
|
|
94
|
+
* - Checks the local cache first (node_modules/.cache/timber-fonts/)
|
|
95
|
+
* - Downloads missing fonts from Google Fonts CDN
|
|
96
|
+
* - Writes downloaded fonts to cache
|
|
97
|
+
* - Returns CachedFont entries with content-hashed filenames
|
|
98
|
+
*/
|
|
99
|
+
export declare function downloadAndCacheFonts(fonts: ExtractedFont[], projectRoot: string): Promise<CachedFont[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Generate @font-face descriptors for cached (production) Google Fonts.
|
|
102
|
+
*
|
|
103
|
+
* Each CachedFont gets a FontFaceDescriptor pointing to the
|
|
104
|
+
* content-hashed URL under `/_timber/fonts/`.
|
|
105
|
+
*/
|
|
106
|
+
export declare function generateProductionFontFaces(cachedFonts: CachedFont[], display: string): FontFaceDescriptor[];
|
|
107
|
+
/**
|
|
108
|
+
* Generate @font-face descriptors for dev mode (CDN-pointing).
|
|
109
|
+
*
|
|
110
|
+
* In dev mode, we query the Google Fonts API but use the CDN URLs
|
|
111
|
+
* directly instead of downloading. This avoids the download/cache
|
|
112
|
+
* step during `vite dev`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function generateDevFontFaces(faces: GoogleFontFace[], display: string): FontFaceDescriptor[];
|
|
115
|
+
/**
|
|
116
|
+
* Resolve dev-mode font faces for an extracted font.
|
|
117
|
+
*
|
|
118
|
+
* Fetches the CSS from Google Fonts API and returns FontFaceDescriptors
|
|
119
|
+
* pointing to CDN URLs. No files are downloaded.
|
|
120
|
+
*/
|
|
121
|
+
export declare function resolveDevFontFaces(font: ExtractedFont): Promise<FontFaceDescriptor[]>;
|
|
122
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/fonts/google.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAepE,oEAAoE;AACpE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,iEAAiE;AACjE,MAAM,WAAW,UAAU;IACzB,qCAAqC;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,4EAA4E;IAC5E,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAiC/D;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAahF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,EAAE,CA8BjE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,CAI5F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7E;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAGrD;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMnE;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,aAAa,EAAE,EACtB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,EAAE,CAAC,CAwCvB;AAeD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,UAAU,EAAE,EACzB,OAAO,EAAE,MAAM,GACd,kBAAkB,EAAE,CAStB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EAAE,EACvB,OAAO,EAAE,MAAM,GACd,kBAAkB,EAAE,CAStB;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAK5F"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local font processing for the timber-fonts pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Resolving font file paths relative to the importing module
|
|
6
|
+
* - Normalizing single-string `src` to array form
|
|
7
|
+
* - Generating @font-face descriptors for each weight/style variant
|
|
8
|
+
*
|
|
9
|
+
* Does NOT handle:
|
|
10
|
+
* - Font format conversion (serve whatever the user provides)
|
|
11
|
+
* - Font subsetting (user's responsibility for local fonts)
|
|
12
|
+
*
|
|
13
|
+
* Design doc: 24-fonts.md §"Local Fonts"
|
|
14
|
+
*/
|
|
15
|
+
import type { LocalFontConfig, LocalFontSrc, FontFaceDescriptor, ExtractedFont } from './types.js';
|
|
16
|
+
/**
|
|
17
|
+
* Infer the font format from a file extension.
|
|
18
|
+
*
|
|
19
|
+
* Returns the CSS `format()` value for `@font-face` src descriptors.
|
|
20
|
+
*/
|
|
21
|
+
export declare function inferFontFormat(filePath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Normalize `src` config to an array of LocalFontSrc entries.
|
|
24
|
+
*
|
|
25
|
+
* When `src` is a single string, it becomes a single entry with
|
|
26
|
+
* default weight '400' and style 'normal'.
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeSrc(src: string | LocalFontSrc[]): LocalFontSrc[];
|
|
29
|
+
/**
|
|
30
|
+
* Resolve font file paths relative to the importing module's directory.
|
|
31
|
+
*
|
|
32
|
+
* Takes the importer's file path and the normalized src entries,
|
|
33
|
+
* returns new entries with absolute resolved paths.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveLocalFontPaths(importerPath: string, sources: LocalFontSrc[]): LocalFontSrc[];
|
|
36
|
+
/**
|
|
37
|
+
* Generate a deterministic font family name from the file path
|
|
38
|
+
* when no explicit `family` is provided.
|
|
39
|
+
*
|
|
40
|
+
* Uses the filename without extension, e.g. "MyFont-Regular.woff2" → "MyFont-Regular".
|
|
41
|
+
* For multi-weight sources, uses the first file's name stem.
|
|
42
|
+
*/
|
|
43
|
+
export declare function generateFamilyName(sources: LocalFontSrc[]): string;
|
|
44
|
+
/**
|
|
45
|
+
* Generate @font-face descriptors for local font sources.
|
|
46
|
+
*
|
|
47
|
+
* Each source entry produces one @font-face rule. The `src` descriptor
|
|
48
|
+
* uses a `url()` pointing to the resolved file path with the inferred format.
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateLocalFontFaces(family: string, sources: LocalFontSrc[], display: string): FontFaceDescriptor[];
|
|
51
|
+
/**
|
|
52
|
+
* Build the className for a local font, following the same convention
|
|
53
|
+
* as Google fonts: `timber-font-<lowercase-hyphenated-family>`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function localFontClassName(family: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Process a local font config into an ExtractedFont.
|
|
58
|
+
*
|
|
59
|
+
* This is the main entry point called by the fonts plugin's transform hook
|
|
60
|
+
* when it encounters a `localFont()` call.
|
|
61
|
+
*/
|
|
62
|
+
export declare function processLocalFont(config: LocalFontConfig, importerPath: string): ExtractedFont;
|
|
63
|
+
/**
|
|
64
|
+
* Extract a LocalFontConfig from a static `localFont()` call source.
|
|
65
|
+
*
|
|
66
|
+
* Parses patterns like:
|
|
67
|
+
* localFont({ src: './fonts/MyFont.woff2', display: 'swap', variable: '--font-custom' })
|
|
68
|
+
* localFont({ src: [{ path: './a.woff2', weight: '400' }, { path: './b.woff2', weight: '700' }] })
|
|
69
|
+
*
|
|
70
|
+
* Returns null if the call cannot be statically analyzed.
|
|
71
|
+
*
|
|
72
|
+
* Uses acorn AST parsing for robust handling of comments, trailing commas,
|
|
73
|
+
* and multi-line configs.
|
|
74
|
+
*/
|
|
75
|
+
export declare function extractLocalFontConfig(callSource: string): LocalFontConfig | null;
|
|
76
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/fonts/local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAInG;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgBxD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,GAAG,YAAY,EAAE,CASzE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,YAAY,EAAE,GACtB,YAAY,EAAE,CAMhB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAYlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,MAAM,GACd,kBAAkB,EAAE,CAWtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAyB7F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAEjF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the timber-fonts pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Used by the fonts plugin, CSS generator, fallback generator,
|
|
5
|
+
* and the Google/local font providers.
|
|
6
|
+
*
|
|
7
|
+
* Design doc: 24-fonts.md
|
|
8
|
+
*/
|
|
9
|
+
/** Configuration passed to a Google font function (e.g. `Inter({ ... })`). */
|
|
10
|
+
export interface GoogleFontConfig {
|
|
11
|
+
weight?: string | string[];
|
|
12
|
+
subsets?: string[];
|
|
13
|
+
display?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
|
|
14
|
+
variable?: string;
|
|
15
|
+
style?: string | string[];
|
|
16
|
+
preload?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A single local font source entry (multi-weight). */
|
|
19
|
+
export interface LocalFontSrc {
|
|
20
|
+
path: string;
|
|
21
|
+
weight?: string;
|
|
22
|
+
style?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Configuration passed to `localFont()`. */
|
|
25
|
+
export interface LocalFontConfig {
|
|
26
|
+
src: string | LocalFontSrc[];
|
|
27
|
+
display?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
|
|
28
|
+
variable?: string;
|
|
29
|
+
/** Override the font family name. Defaults to a generated name. */
|
|
30
|
+
family?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The return value of a font function call.
|
|
34
|
+
*
|
|
35
|
+
* Matches the Next.js `next/font` return shape for compatibility.
|
|
36
|
+
*/
|
|
37
|
+
export interface FontResult {
|
|
38
|
+
/** Scoped CSS class that applies font-family (e.g. `timber-font-inter`). */
|
|
39
|
+
className: string;
|
|
40
|
+
/** Inline style with the full font stack including fallbacks. */
|
|
41
|
+
style: {
|
|
42
|
+
fontFamily: string;
|
|
43
|
+
};
|
|
44
|
+
/** CSS custom property name when `variable` is specified (e.g. `--font-sans`). */
|
|
45
|
+
variable?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Internal representation of a font extracted during static analysis. */
|
|
48
|
+
export interface ExtractedFont {
|
|
49
|
+
/** Unique identifier for this font instance (e.g. `inter-400-normal-latin`). */
|
|
50
|
+
id: string;
|
|
51
|
+
/** The font family name (e.g. `Inter`). */
|
|
52
|
+
family: string;
|
|
53
|
+
/** Provider: 'google' or 'local'. */
|
|
54
|
+
provider: 'google' | 'local';
|
|
55
|
+
/** Weights requested (e.g. ['400', '700']). */
|
|
56
|
+
weights: string[];
|
|
57
|
+
/** Styles requested (e.g. ['normal', 'italic']). */
|
|
58
|
+
styles: string[];
|
|
59
|
+
/** Subsets requested (e.g. ['latin']). Google fonts only. */
|
|
60
|
+
subsets: string[];
|
|
61
|
+
/** font-display value. */
|
|
62
|
+
display: string;
|
|
63
|
+
/** CSS variable name (e.g. `--font-sans`). */
|
|
64
|
+
variable?: string;
|
|
65
|
+
/** Source file paths for local fonts. */
|
|
66
|
+
localSources?: LocalFontSrc[];
|
|
67
|
+
/** The module that imported this font (for segment association). */
|
|
68
|
+
importer: string;
|
|
69
|
+
/** Generated scoped class name. */
|
|
70
|
+
className: string;
|
|
71
|
+
/** Full font stack including fallback. */
|
|
72
|
+
fontFamily: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A single @font-face declaration's data (before CSS serialization).
|
|
76
|
+
*/
|
|
77
|
+
export interface FontFaceDescriptor {
|
|
78
|
+
family: string;
|
|
79
|
+
src: string;
|
|
80
|
+
weight?: string;
|
|
81
|
+
style?: string;
|
|
82
|
+
display?: string;
|
|
83
|
+
unicodeRange?: string;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fonts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC7B,+CAA+C;IAC/C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,oDAAoD;IACpD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9B,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
|