File tree Expand file tree Collapse file tree 3 files changed +19
-1807
lines changed
packages/tailwind/src/lib Expand file tree Collapse file tree 3 files changed +19
-1807
lines changed Original file line number Diff line number Diff line change @@ -46,19 +46,29 @@ export function createThemeColors(colorSpace: SupportedColorSpace) {
4646}
4747
4848/**
49- * Get themes names split into light and dark collections determined by `color-scheme` property
49+ * Get themes names (`[data-theme="..."]`) split into light and dark collections determined by `color-scheme` property
5050 */
51- export function getThemeNames ( themes : Record < string , any > ) {
52- const light : string [ ] = [ ] ;
53- const dark : string [ ] = [ ] ;
51+ export function getThemeNames ( cssContent : string ) {
52+ const themeBlocks = cssContent . split ( / \[ d a t a - t h e m e = / ) ;
5453
55- entries ( themes ) . map ( ( [ themeName , props ] ) => {
56- if ( props [ 'color-scheme' ] === 'dark' ) {
54+ const light = [ ] ;
55+ const dark = [ ] ;
56+
57+ // Skip first element as it's content before first theme
58+ for ( let i = 1 ; i < themeBlocks . length ; i ++ ) {
59+ const block = themeBlocks [ i ] ;
60+
61+ // Extract theme name
62+ const nameMatch = block . match ( / ^ " ( [ ^ " ] + ) " / ) ;
63+ if ( ! nameMatch ) continue ;
64+ const themeName = nameMatch [ 1 ] ;
65+
66+ if ( block . includes ( 'color-scheme: dark' ) ) {
5767 dark . push ( themeName ) ;
5868 } else {
5969 light . push ( themeName ) ;
6070 }
61- } ) ;
71+ }
6272
6373 return { light, dark } ;
6474}
Original file line number Diff line number Diff line change 11import { env } from '$env/dynamic/private' ;
22
3- import themes from '../../themes.json' assert { type : 'json' } ;
43import { getThemeNames } from '@layerstack/tailwind' ;
4+ import themeCss from '@layerstack/tailwind/themes/all.css?raw' ;
55
66export async function load ( ) {
77 return {
8- themes : getThemeNames ( themes ) ,
8+ themes : getThemeNames ( themeCss ) ,
99 // themes: { light: ['light'], dark: ['dark'] },
1010 pr_id : env . VERCEL_GIT_PULL_REQUEST_ID ,
1111 } ;
You can’t perform that action at this time.
0 commit comments