@classic-homes/theme-tailwind-preset 0.3.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 +67 -8
  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
@@ -77,6 +131,15 @@ module.exports = {
77
131
  border: 'hsl(var(--border))',
78
132
  input: 'hsl(var(--input))',
79
133
  ring: 'hsl(var(--ring))',
134
+ outline: {
135
+ DEFAULT: 'hsl(var(--outline))',
136
+ hover: 'hsl(var(--outline-hover))',
137
+ },
138
+ toolbar: {
139
+ DEFAULT: 'hsl(var(--toolbar))',
140
+ foreground: 'hsl(var(--toolbar-foreground))',
141
+ border: 'hsl(var(--toolbar-border))',
142
+ },
80
143
  background: {
81
144
  DEFAULT: 'hsl(var(--background))',
82
145
  hover: 'hsl(var(--background-hover))',
@@ -92,6 +155,8 @@ module.exports = {
92
155
  DEFAULT: 'hsl(var(--secondary))',
93
156
  foreground: 'hsl(var(--secondary-foreground))',
94
157
  hover: 'hsl(var(--secondary-hover))',
158
+ border: 'hsl(var(--secondary-border))',
159
+ soft: 'hsl(var(--secondary-soft))',
95
160
  },
96
161
  destructive: {
97
162
  DEFAULT: 'hsl(var(--destructive))',
@@ -183,13 +248,7 @@ module.exports = {
183
248
 
184
249
  fontSize: {
185
250
  ...tokens.fontSize,
186
- // Heading sizes for typography scale
187
- h1: ['2.25rem', { lineHeight: '2.5rem', fontWeight: '600' }], // 36px
188
- h2: ['1.875rem', { lineHeight: '2.25rem', fontWeight: '600' }], // 30px
189
- h3: ['1.5rem', { lineHeight: '2rem', fontWeight: '600' }], // 24px
190
- h4: ['1.25rem', { lineHeight: '1.75rem', fontWeight: '600' }], // 20px
191
- h5: ['1.125rem', { lineHeight: '1.75rem', fontWeight: '600' }], // 18px
192
- h6: ['1rem', { lineHeight: '1.5rem', fontWeight: '600' }], // 16px
251
+ ...headingScale,
193
252
  },
194
253
 
195
254
  fontWeight: tokens.fontWeight,
@@ -378,5 +437,5 @@ module.exports = {
378
437
  },
379
438
  },
380
439
  },
381
- plugins: [],
440
+ plugins: [headingBase],
382
441
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/theme-tailwind-preset",
3
- "version": "0.3.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
  }