@classic-homes/theme-tailwind-preset 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/index.js +56 -9
  2. package/package.json +7 -2
package/index.js CHANGED
@@ -20,6 +20,60 @@
20
20
 
21
21
  const tokens = require('@classic-homes/theme-tokens');
22
22
 
23
+ /**
24
+ * Base heading typography, emitted through `addBase`.
25
+ *
26
+ * theme-styles/base.css sets the same scale inside `@layer classic-theme.base`,
27
+ * but any consumer that runs `@tailwind base` also gets Tailwind preflight's
28
+ * `h1..h6 { font-size: inherit; font-weight: inherit }`. Preflight is
29
+ * unlayered, so it outranks the theme's layered rule by cascade semantics -
30
+ * and @csstools/postcss-cascade-layers (postcss-config) keeps that ordering
31
+ * with specificity boosts. Bare headings therefore rendered at body size with
32
+ * the inherited weight in every Tailwind app, including our own example apps.
33
+ *
34
+ * `addBase` output lands inside Tailwind's base output *after* preflight, so
35
+ * it wins on source order. Sizes and weights come from the `fontSize.h1..h6`
36
+ * scale below, so the utilities (`text-h1`) and the bare elements agree.
37
+ * Color and margins are left to base.css/preflight on purpose: this only
38
+ * restores what preflight resets.
39
+ */
40
+ // Heading sizes for the typography scale (mirrors theme-styles base.css).
41
+ // h1 pairs with `font-serif italic` (Spectral 500); h2-h6 are Figtree 600.
42
+ // Exposed as `text-h1`..`text-h6` and emitted on the bare elements by
43
+ // `headingBase` below, so the two never drift.
44
+ const headingScale = {
45
+ h1: ['2.5rem', { lineHeight: '2rem', fontWeight: '500' }], // 40px
46
+ h2: ['1.75rem', { lineHeight: '2.25rem', fontWeight: '600' }], // 28px
47
+ h3: ['1.5rem', { lineHeight: '2rem', fontWeight: '600' }], // 24px
48
+ h4: ['1.25rem', { lineHeight: '1.75rem', fontWeight: '600' }], // 20px
49
+ h5: ['1.125rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 18px
50
+ h6: ['1rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 16px
51
+ };
52
+
53
+ function headingBase({ addBase, theme }) {
54
+ // Not theme('fontSize.h1'): Tailwind 3 resolves that to the size string alone
55
+ const heading = (level) => {
56
+ const [fontSize, { lineHeight, fontWeight }] = headingScale[level];
57
+ return { fontSize, lineHeight, fontWeight };
58
+ };
59
+ // theme() hands fontFamily back as a joined string in Tailwind 3, an array in 4
60
+ const stack = (key) => [].concat(theme(key)).join(', ');
61
+ const serif = stack('fontFamily.serif');
62
+ const sans = stack('fontFamily.sans');
63
+ addBase({
64
+ h1: {
65
+ fontFamily: `var(--font-serif, ${serif})`,
66
+ fontStyle: 'italic',
67
+ ...heading('h1'),
68
+ },
69
+ h2: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h2') },
70
+ h3: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h3') },
71
+ h4: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h4') },
72
+ h5: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h5') },
73
+ h6: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h6') },
74
+ });
75
+ }
76
+
23
77
  /** @type {import('tailwindcss').Config} */
24
78
  module.exports = {
25
79
  // Enable dark mode via class on <html> element
@@ -194,14 +248,7 @@ module.exports = {
194
248
 
195
249
  fontSize: {
196
250
  ...tokens.fontSize,
197
- // Heading sizes for typography scale (mirrors theme-styles base.css).
198
- // h1 pairs with `font-serif italic` (Spectral 500); h2-h6 are Figtree 600.
199
- h1: ['2.5rem', { lineHeight: '2rem', fontWeight: '500' }], // 40px
200
- h2: ['1.75rem', { lineHeight: '2.25rem', fontWeight: '600' }], // 28px
201
- h3: ['1.5rem', { lineHeight: '2rem', fontWeight: '600' }], // 24px
202
- h4: ['1.25rem', { lineHeight: '1.75rem', fontWeight: '600' }], // 20px
203
- h5: ['1.125rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 18px
204
- h6: ['1rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 16px
251
+ ...headingScale,
205
252
  },
206
253
 
207
254
  fontWeight: tokens.fontWeight,
@@ -390,5 +437,5 @@ module.exports = {
390
437
  },
391
438
  },
392
439
  },
393
- plugins: [],
440
+ plugins: [headingBase],
394
441
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/theme-tailwind-preset",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Tailwind CSS preset for the Classic theme system",
5
5
  "main": "index.js",
6
6
  "sideEffects": false,
@@ -8,7 +8,8 @@
8
8
  "index.js"
9
9
  ],
10
10
  "scripts": {
11
- "build": "echo 'No build needed for tailwind-preset'"
11
+ "build": "echo 'No build needed for tailwind-preset'",
12
+ "test": "vitest run"
12
13
  },
13
14
  "keywords": [
14
15
  "tailwindcss",
@@ -29,5 +30,9 @@
29
30
  },
30
31
  "dependencies": {
31
32
  "@classic-homes/theme-tokens": "*"
33
+ },
34
+ "devDependencies": {
35
+ "tailwindcss": "^3.4.0",
36
+ "vitest": "^4.0.0"
32
37
  }
33
38
  }