@classic-homes/theme-tailwind-preset 0.4.0 → 0.4.2

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 +57 -9
  2. package/package.json +7 -2
package/index.js CHANGED
@@ -20,6 +20,61 @@
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
+ // 2.75rem leading: a 2rem line on 40px type made wrapped titles overlap
46
+ h1: ['2.5rem', { lineHeight: '2.75rem', fontWeight: '500' }], // 40px
47
+ h2: ['1.75rem', { lineHeight: '2.25rem', fontWeight: '600' }], // 28px
48
+ h3: ['1.5rem', { lineHeight: '2rem', fontWeight: '600' }], // 24px
49
+ h4: ['1.25rem', { lineHeight: '1.75rem', fontWeight: '600' }], // 20px
50
+ h5: ['1.125rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 18px
51
+ h6: ['1rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 16px
52
+ };
53
+
54
+ function headingBase({ addBase, theme }) {
55
+ // Not theme('fontSize.h1'): Tailwind 3 resolves that to the size string alone
56
+ const heading = (level) => {
57
+ const [fontSize, { lineHeight, fontWeight }] = headingScale[level];
58
+ return { fontSize, lineHeight, fontWeight };
59
+ };
60
+ // theme() hands fontFamily back as a joined string in Tailwind 3, an array in 4
61
+ const stack = (key) => [].concat(theme(key)).join(', ');
62
+ const serif = stack('fontFamily.serif');
63
+ const sans = stack('fontFamily.sans');
64
+ addBase({
65
+ h1: {
66
+ fontFamily: `var(--font-serif, ${serif})`,
67
+ fontStyle: 'italic',
68
+ ...heading('h1'),
69
+ },
70
+ h2: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h2') },
71
+ h3: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h3') },
72
+ h4: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h4') },
73
+ h5: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h5') },
74
+ h6: { fontFamily: `var(--font-sans, ${sans})`, ...heading('h6') },
75
+ });
76
+ }
77
+
23
78
  /** @type {import('tailwindcss').Config} */
24
79
  module.exports = {
25
80
  // Enable dark mode via class on <html> element
@@ -194,14 +249,7 @@ module.exports = {
194
249
 
195
250
  fontSize: {
196
251
  ...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
252
+ ...headingScale,
205
253
  },
206
254
 
207
255
  fontWeight: tokens.fontWeight,
@@ -390,5 +438,5 @@ module.exports = {
390
438
  },
391
439
  },
392
440
  },
393
- plugins: [],
441
+ plugins: [headingBase],
394
442
  };
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.2",
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
  }