@typestyles/next 0.0.0-unstable.bad151c39628 → 0.0.0-unstable.c467888a22b7

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/README.md CHANGED
@@ -150,6 +150,23 @@ To ship a static `typestyles.css` and avoid client-side `<style>` injection (use
150
150
 
151
151
  `withTypestylesExtract` sets **`NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED`** via `next.config` `env` (works with **webpack and Turbopack**) and adds webpack **`DefinePlugin`** for `__TYPESTYLES_RUNTIME_DISABLED__` on client bundles when webpack runs. Example app: `examples/next-app`.
152
152
 
153
+ ### Runtime in development, zero-runtime in production
154
+
155
+ During `next dev`, keeping the client runtime **enabled** avoids tying every style tweak to a pre-build extraction step. In production, disable injection so the browser loads one cacheable stylesheet.
156
+
157
+ ```js
158
+ // next.config.mjs
159
+ import { withTypestylesExtract } from '@typestyles/next/build';
160
+
161
+ const base = {
162
+ /* your config */
163
+ };
164
+
165
+ export default process.env.NODE_ENV === 'production' ? withTypestylesExtract(base) : base;
166
+ ```
167
+
168
+ You still typically generate `typestyles.css` before production builds (CI or `prebuild`). The example app uses this pattern.
169
+
153
170
  ## API Reference
154
171
 
155
172
  ### getRegisteredCss
@@ -204,7 +221,7 @@ import { TypestylesStylesheet } from '@typestyles/next';
204
221
  // app/page.tsx
205
222
  import { styles } from 'typestyles';
206
223
 
207
- const button = styles.create('button', {
224
+ const button = styles.component('button', {
208
225
  base: {
209
226
  padding: '12px 24px',
210
227
  backgroundColor: '#0066ff',
@@ -218,7 +235,7 @@ const button = styles.create('button', {
218
235
  export default function Home() {
219
236
  return (
220
237
  <main>
221
- <button className={button('base')}>Click me</button>
238
+ <button className={button()}>Click me</button>
222
239
  </main>
223
240
  );
224
241
  }
@@ -245,7 +262,7 @@ export const spacing = tokens.create('space', {
245
262
  import { styles } from 'typestyles';
246
263
  import { colors, spacing } from './tokens';
247
264
 
248
- const card = styles.create('card', {
265
+ const card = styles.component('card', {
249
266
  base: {
250
267
  padding: spacing.md,
251
268
  backgroundColor: colors.primary,
@@ -254,7 +271,7 @@ const card = styles.create('card', {
254
271
  });
255
272
 
256
273
  export default function Page() {
257
- return <div className={card('base')}>Hello World</div>;
274
+ return <div className={card()}>Hello World</div>;
258
275
  }
259
276
  ```
260
277
 
@@ -266,9 +283,11 @@ import { tokens } from 'typestyles';
266
283
  import { getRegisteredCss } from '@typestyles/next';
267
284
 
268
285
  const darkTheme = tokens.createTheme('dark', {
269
- color: {
270
- background: '#1a1a1a',
271
- text: '#ffffff',
286
+ base: {
287
+ color: {
288
+ background: '#1a1a1a',
289
+ text: '#ffffff',
290
+ },
272
291
  },
273
292
  });
274
293
 
@@ -276,7 +295,7 @@ export default function RootLayout({ children }) {
276
295
  const css = getRegisteredCss();
277
296
 
278
297
  return (
279
- <html className={darkTheme}>
298
+ <html className={darkTheme.className}>
280
299
  <head>{css && <style dangerouslySetInnerHTML={{ __html: css }} />}</head>
281
300
  <body>{children}</body>
282
301
  </html>
@@ -284,6 +303,14 @@ export default function RootLayout({ children }) {
284
303
  }
285
304
  ```
286
305
 
306
+ ## Fonts and local files
307
+
308
+ `global.fontFace()` registers `@font-face` like any other TypeStyles global. For **Next’s pre-build extraction** (`buildTypestylesForNext`), prefer fonts under **`public/fonts/`** and a root-relative `url('/fonts/…')` in `src` so Node does not need to resolve binary imports.
309
+
310
+ For **Vite**, you can use `import file from './font.woff2?url'` and `url(\`${file}\`) format('woff2')` so production CSS points at hashed assets.
311
+
312
+ See the **Fonts** guide in the TypeStyles docs (`docs/content/docs/fonts.md`, route `/docs/fonts` on the docs site).
313
+
287
314
  ## Troubleshooting
288
315
 
289
316
  ### Flash of Unstyled Content (FOUC)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/next",
3
- "version": "0.0.0-unstable.bad151c39628",
3
+ "version": "0.0.0-unstable.c467888a22b7",
4
4
  "description": "Next.js integration for typestyles SSR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -68,6 +68,7 @@
68
68
  }
69
69
  },
70
70
  "devDependencies": {
71
+ "eslint": "^9.39.2",
71
72
  "vitest": "^3.0.0",
72
73
  "@types/node": "^25.2.1",
73
74
  "@types/react": "^18.3.12",
@@ -76,13 +77,14 @@
76
77
  "react": "^18.0.0",
77
78
  "react-dom": "^18.0.0",
78
79
  "tsup": "^8.0.0",
79
- "typestyles": "0.0.0-unstable.bad151c39628",
80
+ "typestyles": "0.0.0-unstable.c467888a22b7",
80
81
  "typescript": "^5.4.0",
81
82
  "webpack": "^5.97.1"
82
83
  },
83
84
  "scripts": {
84
85
  "build": "tsup",
85
86
  "test": "vitest run",
87
+ "lint": "eslint .",
86
88
  "typecheck": "tsc --noEmit"
87
89
  }
88
90
  }
package/src/build.test.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import type { NextConfig } from 'next';
3
3
  import type { Configuration } from 'webpack';
4
- import { withTypestylesExtract } from './build.js';
4
+ import { withTypestylesExtract } from './build';
5
5
 
6
6
  type WebpackContext = Parameters<NonNullable<NextConfig['webpack']>>[1];
7
7
 
8
8
  describe('withTypestylesExtract', () => {
9
9
  it('merges NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED into env for Turbopack + webpack', () => {
10
- const merged = withTypestylesExtract(
11
- { env: { CUSTOM: 'x' } },
12
- { disableClientRuntime: true },
13
- );
10
+ const merged = withTypestylesExtract({ env: { CUSTOM: 'x' } }, { disableClientRuntime: true });
14
11
  expect(merged.env).toEqual({
15
12
  CUSTOM: 'x',
16
13
  NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED: 'true',
@@ -18,10 +15,7 @@ describe('withTypestylesExtract', () => {
18
15
  });
19
16
 
20
17
  it('does not override env when disableClientRuntime is false', () => {
21
- const merged = withTypestylesExtract(
22
- { env: { CUSTOM: 'x' } },
23
- { disableClientRuntime: false },
24
- );
18
+ const merged = withTypestylesExtract({ env: { CUSTOM: 'x' } }, { disableClientRuntime: false });
25
19
  expect(merged.env).toEqual({ CUSTOM: 'x' });
26
20
  });
27
21
 
@@ -33,9 +27,12 @@ describe('withTypestylesExtract', () => {
33
27
  });
34
28
  const merged = withTypestylesExtract({ webpack: userWebpack });
35
29
  const config = { plugins: [] as unknown[] };
36
- const result = merged.webpack!(config as Configuration, {
37
- isServer: false,
38
- } as WebpackContext);
30
+ const result = merged.webpack!(
31
+ config as Configuration,
32
+ {
33
+ isServer: false,
34
+ } as WebpackContext,
35
+ );
39
36
  expect(userWebpack).toHaveBeenCalled();
40
37
  const hasDefine = result.plugins?.some(
41
38
  (p: unknown) => p instanceof webpackMod.default.DefinePlugin,
@@ -47,9 +44,12 @@ describe('withTypestylesExtract', () => {
47
44
  const webpackMod = await import('webpack');
48
45
  const merged = withTypestylesExtract({});
49
46
  const config = { plugins: [] as unknown[] };
50
- const result = merged.webpack!(config as Configuration, {
51
- isServer: true,
52
- } as WebpackContext);
47
+ const result = merged.webpack!(
48
+ config as Configuration,
49
+ {
50
+ isServer: true,
51
+ } as WebpackContext,
52
+ );
53
53
  const hasDefine = result.plugins?.some(
54
54
  (p: unknown) => p instanceof webpackMod.default.DefinePlugin,
55
55
  );
package/src/build.ts CHANGED
@@ -28,7 +28,9 @@ export interface BuildTypestylesForNextOptions {
28
28
  * Extract TypeStyles CSS for a Next.js app (run from a script before `next build`, or in CI).
29
29
  * Loads each module path (relative to `root`) so side-effect registrations run, then writes CSS.
30
30
  */
31
- export async function buildTypestylesForNext(options: BuildTypestylesForNextOptions): Promise<void> {
31
+ export async function buildTypestylesForNext(
32
+ options: BuildTypestylesForNextOptions,
33
+ ): Promise<void> {
32
34
  const { root, modules, cssOutFile, manifestOutFile, manifestCssPath } = options;
33
35
  const loaders = modules.map((mod) => {
34
36
  const abs = resolve(root, mod);
package/src/client.d.ts CHANGED
@@ -11,9 +11,7 @@ export function useTypestyles(): ReturnType<typeof useSyncExternalStore<string>>
11
11
  * Re-export of React’s `useServerInsertedHTML` (App Router / streaming SSR).
12
12
  * Declared here so consumers get a stable signature even when their `@types/react` predates the hook.
13
13
  */
14
- export function useServerInsertedHTML(
15
- callback: () => React.ReactNode | null,
16
- ): void;
14
+ export function useServerInsertedHTML(callback: () => React.ReactNode | null): void;
17
15
 
18
16
  /**
19
17
  * Props for the TypestylesStylesheet component.
@@ -25,9 +23,7 @@ export interface TypestylesStylesheetProps {
25
23
  /**
26
24
  * A React component that renders typestyles CSS.
27
25
  */
28
- export function TypestylesStylesheet(
29
- props: TypestylesStylesheetProps,
30
- ): React.JSX.Element | null;
26
+ export function TypestylesStylesheet(props: TypestylesStylesheetProps): React.JSX.Element | null;
31
27
 
32
28
  /**
33
29
  * Create a Next.js layout export that includes typestyles.