@typestyles/next 0.5.3 → 0.5.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.
package/README.md CHANGED
@@ -227,16 +227,21 @@ import { TypestylesStylesheet } from '@typestyles/next';
227
227
 
228
228
  ```tsx
229
229
  // app/page.tsx
230
- import { styles } from 'typestyles';
231
-
232
- const button = styles.component('button', {
233
- base: {
234
- padding: '12px 24px',
235
- backgroundColor: '#0066ff',
236
- color: 'white',
237
- border: 'none',
238
- borderRadius: '6px',
239
- cursor: 'pointer',
230
+ import { createTypeStyles } from 'typestyles';
231
+
232
+ const { recipe } = createTypeStyles({ scopeId: 'app' });
233
+
234
+ const button = recipe({
235
+ name: 'button',
236
+ styles: {
237
+ base: {
238
+ padding: '12px 24px',
239
+ backgroundColor: '#0066ff',
240
+ color: 'white',
241
+ border: 'none',
242
+ borderRadius: '6px',
243
+ cursor: 'pointer',
244
+ },
240
245
  },
241
246
  });
242
247
 
@@ -252,8 +257,10 @@ export default function Home() {
252
257
  ### With Design Tokens
253
258
 
254
259
  ```tsx
255
- // app/tokens.ts
256
- import { tokens } from 'typestyles';
260
+ // app/styles.ts
261
+ import { createTypeStyles } from 'typestyles';
262
+
263
+ export const { recipe, tokens } = createTypeStyles({ scopeId: 'app' });
257
264
 
258
265
  export const colors = tokens.create('color', {
259
266
  primary: '#0066ff',
@@ -267,14 +274,16 @@ export const spacing = tokens.create('space', {
267
274
  });
268
275
 
269
276
  // app/page.tsx
270
- import { styles } from 'typestyles';
271
- import { colors, spacing } from './tokens';
272
-
273
- const card = styles.component('card', {
274
- base: {
275
- padding: spacing.md,
276
- backgroundColor: colors.primary,
277
- borderRadius: '8px',
277
+ import { recipe, colors, spacing } from './styles';
278
+
279
+ const card = recipe({
280
+ name: 'card',
281
+ styles: {
282
+ base: {
283
+ padding: spacing.md,
284
+ backgroundColor: colors.primary,
285
+ borderRadius: '8px',
286
+ },
278
287
  },
279
288
  });
280
289
 
@@ -287,9 +296,11 @@ export default function Page() {
287
296
 
288
297
  ```tsx
289
298
  // app/layout.tsx
290
- import { tokens } from 'typestyles';
299
+ import { createTypeStyles } from 'typestyles';
291
300
  import { getRegisteredCss } from '@typestyles/next';
292
301
 
302
+ const { tokens } = createTypeStyles({ scopeId: 'app' });
303
+
293
304
  const darkTheme = tokens.createTheme('dark', {
294
305
  base: {
295
306
  color: {
package/dist/build.cjs CHANGED
@@ -62,10 +62,11 @@ async function buildTypestylesForNext(options) {
62
62
  } = options;
63
63
  const resolvedModules = resolveExtractModulesForNext(root, modules);
64
64
  const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
65
+ let extractNonce = 0;
65
66
  const loaders = resolvedModules.map((mod) => {
66
67
  const abs = (0, import_node_path.resolve)(root, mod);
67
68
  const href = (0, import_node_url.pathToFileURL)(abs).href;
68
- return () => import(href);
69
+ return () => import(`${href}?typestyles-extract=${++extractNonce}`);
69
70
  });
70
71
  const css = await (0, import_build.collectStylesFromModules)(loaders);
71
72
  const outAbs = (0, import_node_path.resolve)(root, cssOutFile);
package/dist/build.js CHANGED
@@ -41,10 +41,11 @@ async function buildTypestylesForNext(options) {
41
41
  } = options;
42
42
  const resolvedModules = resolveExtractModulesForNext(root, modules);
43
43
  const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
44
+ let extractNonce = 0;
44
45
  const loaders = resolvedModules.map((mod) => {
45
46
  const abs = resolve(root, mod);
46
47
  const href = pathToFileURL(abs).href;
47
- return () => import(href);
48
+ return () => import(`${href}?typestyles-extract=${++extractNonce}`);
48
49
  });
49
50
  const css = await collectStylesFromModules(loaders);
50
51
  const outAbs = resolve(root, cssOutFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/next",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Next.js integration for typestyles SSR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -68,7 +68,7 @@
68
68
  }
69
69
  },
70
70
  "dependencies": {
71
- "@typestyles/build-runner": "0.5.3"
71
+ "@typestyles/build-runner": "0.6.1"
72
72
  },
73
73
  "devDependencies": {
74
74
  "eslint": "^9.39.2",
@@ -82,7 +82,7 @@
82
82
  "tsup": "^8.0.0",
83
83
  "typescript": "^5.4.0",
84
84
  "webpack": "^5.97.1",
85
- "typestyles": "0.25.0"
85
+ "typestyles": "0.32.0"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "tsup",
@@ -12,7 +12,7 @@ describe('buildTypestylesForNext route CSS', () => {
12
12
 
13
13
  writeFileSync(
14
14
  join(root, 'styles/typestyles-entry.ts'),
15
- `import { styles } from 'typestyles';\nstyles.class('shared', { margin: '0' });\n`,
15
+ `import { createTypeStyles } from 'typestyles';\nconst { style } = createTypeStyles();\nstyle('shared', { margin: '0' });\n`,
16
16
  );
17
17
  writeFileSync(
18
18
  join(root, 'app/layout.tsx'),
@@ -20,11 +20,11 @@ describe('buildTypestylesForNext route CSS', () => {
20
20
  );
21
21
  writeFileSync(
22
22
  join(root, 'app/page.tsx'),
23
- `import { styles } from 'typestyles';\nstyles.class('home', { color: 'red' });\nexport default function Home() { return null; }\n`,
23
+ `import { createStyles } from 'typestyles';\nconst styles = createStyles();\nstyles.class('home', { color: 'red' });\nexport default function Home() { return null; }\n`,
24
24
  );
25
25
  writeFileSync(
26
26
  join(root, 'app/about/page.tsx'),
27
- `import { styles } from 'typestyles';\nstyles.class('about', { color: 'blue' });\nexport default function About() { return null; }\n`,
27
+ `import { createStyles } from 'typestyles';\nconst styles = createStyles();\nstyles.class('about', { color: 'blue' });\nexport default function About() { return null; }\n`,
28
28
  );
29
29
 
30
30
  try {
@@ -11,7 +11,8 @@ describe('buildTypestylesForNext theme extraction', () => {
11
11
 
12
12
  writeFileSync(
13
13
  join(root, 'styles/typestyles-entry.ts'),
14
- `import { tokens, createTheme } from 'typestyles';
14
+ `import { createTokens, createTheme } from 'typestyles';
15
+ const tokens = createTokens();
15
16
  const color = tokens.create('next-color', { primary: '#0066ff' });
16
17
  createTheme('next-dark', { base: { 'next-color': { primary: '#66aaff' } } });
17
18
  `,
package/src/build.ts CHANGED
@@ -98,10 +98,13 @@ export async function buildTypestylesForNext(
98
98
  const resolvedModules = resolveExtractModulesForNext(root, modules);
99
99
  const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
100
100
 
101
+ let extractNonce = 0;
101
102
  const loaders = resolvedModules.map((mod) => {
102
103
  const abs = resolve(root, mod);
103
104
  const href = pathToFileURL(abs).href;
104
- return () => import(href);
105
+ // Cache-bust so a later route-CSS pass can re-import and re-register styles
106
+ // into an isolated sheet (Node ESM caches bare `import(href)` forever).
107
+ return () => import(`${href}?typestyles-extract=${++extractNonce}`);
105
108
  });
106
109
  const css = await collectStylesFromModules(loaders);
107
110
  const outAbs = resolve(root, cssOutFile);