@@ -5,7 +5,6 @@ import defaultTheme from "tailwindcss/defaultTheme";
5
5
import twForms from "@tailwindcss/forms" ;
6
6
import twTypography from "@tailwindcss/typography" ;
7
7
import twAspectRatio from "@tailwindcss/aspect-ratio" ;
8
- import twLineClamp from "@tailwindcss/line-clamp" ;
9
8
import { ChaiBlock } from "../core/types/ChaiBlock.ts" ;
10
9
import { addPrefixToClasses , ChaiPageData , getBrandingClasses } from "./functions.ts" ;
11
10
import { STYLES_KEY } from "../core/constants/CONTROLS.ts" ;
@@ -16,6 +15,7 @@ export async function getTailwindCSS(
16
15
markupString : string [ ] ,
17
16
safelist : string [ ] = [ ] ,
18
17
prefix : string = "c-" ,
18
+ includeBaseStyles : boolean = false ,
19
19
) {
20
20
const primary = get ( options , "primaryColor" , "#000" ) ;
21
21
const secondary = get ( options , "secondaryColor" , "#ccc" ) ;
@@ -31,7 +31,6 @@ export async function getTailwindCSS(
31
31
set ( colors , "secondary.DEFAULT" , secondary ) ;
32
32
const tailwind = createTailwindcss ( {
33
33
tailwindConfig : {
34
- prefix,
35
34
darkMode : "class" ,
36
35
safelist,
37
36
theme : {
@@ -46,19 +45,22 @@ export async function getTailwindCSS(
46
45
colors,
47
46
} ,
48
47
} ,
49
- plugins : [ twForms , twTypography , twAspectRatio , twLineClamp ] ,
50
- corePlugins : { preflight : false } ,
48
+ plugins : [ twForms , twTypography , twAspectRatio ] ,
49
+ corePlugins : { preflight : includeBaseStyles } ,
50
+ ...( prefix ? { prefix : `${ prefix } ` } : { } ) ,
51
51
} ,
52
52
} ) ;
53
53
54
54
const css = await tailwind . generateStylesFromContent (
55
- ` @tailwind components;
55
+ ` ${ includeBaseStyles ? "@tailwind base;" : "" }
56
+ @tailwind components;
56
57
@tailwind utilities;` ,
57
58
markupString ,
58
59
) ;
59
- return `${ css } .${ prefix } bg-clip-text{background-clip: text;-webkit-background-clip: text;} h1,h2,h3,h4,h5,h6{font-family: "${ headingFont } ",${ defaultTheme . fontFamily . sans . join (
60
- ", " ,
61
- ) } ;}`;
60
+ return `${ css }
61
+ .${ prefix } bg-clip-text{background-clip: text;-webkit-background-clip: text;} h1,h2,h3,h4,h5,h6{font-family: "${ headingFont } ",${ defaultTheme . fontFamily . sans . join (
62
+ ", " ,
63
+ ) } ;}`;
62
64
}
63
65
64
66
const addPrefixToBlockStyles = ( blocks : ChaiBlock [ ] , prefix : string ) => {
@@ -75,23 +77,37 @@ const addPrefixToBlockStyles = (blocks: ChaiBlock[], prefix: string) => {
75
77
} ) ;
76
78
} ;
77
79
78
- export const getBlocksTailwindCSS = ( blocks : ChaiBlock [ ] , brandingOptions : any , prefix : string = "c-" ) => {
80
+ export const getBlocksTailwindCSS = (
81
+ blocks : ChaiBlock [ ] ,
82
+ brandingOptions : any ,
83
+ prefix : string = "c-" ,
84
+ includeBaseStyles : boolean = false ,
85
+ ) => {
79
86
const brandingClasses = getBrandingClasses ( brandingOptions , prefix ) ;
80
87
return getTailwindCSS (
81
88
brandingOptions ,
82
89
[ replace ( JSON . stringify ( addPrefixToBlockStyles ( blocks , prefix ) ) , / # s t y l e s : / g, "" ) ] ,
83
90
brandingClasses . split ( " " ) . concat ( `${ prefix } inline-block` , `${ prefix } w-full` , `${ prefix } h-full` ) ,
91
+ prefix ,
92
+ includeBaseStyles ,
84
93
) ;
85
94
} ;
86
- export const getStylesForPageData = async ( pageData : ChaiPageData , classPrefix : string = "c-" ) : Promise < string > => {
95
+
96
+ export const getStylesForPageData = async (
97
+ pageData : ChaiPageData ,
98
+ classPrefix : string = "c-" ,
99
+ includeBaseStyles : boolean = false ,
100
+ ) : Promise < string > => {
87
101
//TODO: add support for subpages
88
102
const blocks = pageData . page . blocks ;
89
- return await getBlocksTailwindCSS ( blocks , pageData . project . brandingOptions , classPrefix ) ;
103
+ return await getBlocksTailwindCSS ( blocks , pageData . project . brandingOptions , classPrefix , includeBaseStyles ) ;
90
104
} ;
105
+
91
106
export const getStylesForBlocks = async (
92
107
blocks : ChaiBlock [ ] ,
93
108
brandingOptions : BrandingOptions ,
94
109
classPrefix : string = "c-" ,
110
+ includeBaseStyles : boolean = false ,
95
111
) : Promise < string > => {
96
- return await getBlocksTailwindCSS ( blocks , brandingOptions , classPrefix ) ;
112
+ return await getBlocksTailwindCSS ( blocks , brandingOptions , classPrefix , includeBaseStyles ) ;
97
113
} ;
0 commit comments