create-vexcms 0.0.9 → 0.0.10
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.
- package/package.json +1 -1
- package/templates/base-nextjs/package.json +7 -7
- package/templates/marketing-site/src/components/admin/ThemeImport.tsx +174 -0
- package/templates/marketing-site/src/components/admin/ThemeImportField.tsx +33 -0
- package/templates/marketing-site/src/components/ui/accordion.tsx +74 -0
- package/templates/marketing-site/src/lib/colorConvert.ts +171 -0
package/package.json
CHANGED
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"@t3-oss/env-nextjs": "^0.13.10",
|
|
23
23
|
"@tanstack/react-form": "^1.27.7",
|
|
24
24
|
"@tanstack/react-query": "^5.90.17",
|
|
25
|
-
"@vexcms/admin-next": "~0.0.
|
|
26
|
-
"@vexcms/better-auth": "~0.0.
|
|
27
|
-
"@vexcms/core": "~0.0.
|
|
28
|
-
"@vexcms/richtext": "~0.0.
|
|
29
|
-
"@vexcms/ui": "~0.0.
|
|
30
|
-
"@vexcms/file-storage-convex": "~0.0.
|
|
25
|
+
"@vexcms/admin-next": "~0.0.10",
|
|
26
|
+
"@vexcms/better-auth": "~0.0.10",
|
|
27
|
+
"@vexcms/core": "~0.0.10",
|
|
28
|
+
"@vexcms/richtext": "~0.0.10",
|
|
29
|
+
"@vexcms/ui": "~0.0.10",
|
|
30
|
+
"@vexcms/file-storage-convex": "~0.0.10",
|
|
31
31
|
"better-auth": ">=1.4.9 <1.5.0",
|
|
32
32
|
"class-variance-authority": "^0.7.1",
|
|
33
33
|
"clsx": "^2.1.1",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/node": "^20",
|
|
53
53
|
"@types/react": "^19",
|
|
54
54
|
"@types/react-dom": "^19",
|
|
55
|
-
"@vexcms/cli": "~0.0.
|
|
55
|
+
"@vexcms/cli": "~0.0.10",
|
|
56
56
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
57
57
|
"eslint": "^9",
|
|
58
58
|
"eslint-config-next": "15.5.9",
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
|
|
5
|
+
import { parseThemeCSS } from "~/lib/colorConvert"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CSS variable name → form field path mapping.
|
|
9
|
+
* Maps CSS custom property names (from :root / .dark blocks)
|
|
10
|
+
* to the field paths in the themes collection form.
|
|
11
|
+
*
|
|
12
|
+
* Tabs with slugs create nested paths: "light.background", "dark.background"
|
|
13
|
+
* This maps the CSS var name to the camelCase field name used in themeColorFields().
|
|
14
|
+
*/
|
|
15
|
+
const CSS_VAR_TO_FIELD: Record<string, string> = {
|
|
16
|
+
background: "background",
|
|
17
|
+
foreground: "foreground",
|
|
18
|
+
card: "card",
|
|
19
|
+
"card-foreground": "cardForeground",
|
|
20
|
+
popover: "popover",
|
|
21
|
+
"popover-foreground": "popoverForeground",
|
|
22
|
+
primary: "primary",
|
|
23
|
+
"primary-foreground": "primaryForeground",
|
|
24
|
+
secondary: "secondary",
|
|
25
|
+
"secondary-foreground": "secondaryForeground",
|
|
26
|
+
muted: "muted",
|
|
27
|
+
"muted-foreground": "mutedForeground",
|
|
28
|
+
accent: "accent",
|
|
29
|
+
"accent-foreground": "accentForeground",
|
|
30
|
+
destructive: "destructive",
|
|
31
|
+
"destructive-foreground": "destructiveForeground",
|
|
32
|
+
border: "border",
|
|
33
|
+
input: "input",
|
|
34
|
+
ring: "ring",
|
|
35
|
+
"chart-1": "chart1",
|
|
36
|
+
"chart-2": "chart2",
|
|
37
|
+
"chart-3": "chart3",
|
|
38
|
+
"chart-4": "chart4",
|
|
39
|
+
"chart-5": "chart5",
|
|
40
|
+
sidebar: "sidebar",
|
|
41
|
+
"sidebar-foreground": "sidebarForeground",
|
|
42
|
+
"sidebar-primary": "sidebarPrimary",
|
|
43
|
+
"sidebar-primary-foreground": "sidebarPrimaryForeground",
|
|
44
|
+
"sidebar-accent": "sidebarAccent",
|
|
45
|
+
"sidebar-accent-foreground": "sidebarAccentForeground",
|
|
46
|
+
"sidebar-border": "sidebarBorder",
|
|
47
|
+
"sidebar-ring": "sidebarRing",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ThemeImportProps {
|
|
51
|
+
/** Callback to set a form field value by path. e.g., setFieldValue("light.background", "#fff") */
|
|
52
|
+
onImport: (updates: Record<string, string>) => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Theme import component — paste CSS from tweakcn/shadcn to populate color fields.
|
|
57
|
+
*
|
|
58
|
+
* Parses :root { } and .dark { } blocks from the CSS, maps variable names to
|
|
59
|
+
* form field paths, and calls onImport with all matched field updates.
|
|
60
|
+
*
|
|
61
|
+
* Designed to work with any CSS file — only updates fields that match known
|
|
62
|
+
* CSS variable names. Unmatched variables are silently ignored.
|
|
63
|
+
*/
|
|
64
|
+
export function ThemeImport({ onImport }: ThemeImportProps) {
|
|
65
|
+
const [css, setCss] = useState("")
|
|
66
|
+
const [isExpanded, setIsExpanded] = useState(false)
|
|
67
|
+
const [importResult, setImportResult] = useState<string | null>(null)
|
|
68
|
+
|
|
69
|
+
const handleImport = () => {
|
|
70
|
+
if (!css.trim()) return
|
|
71
|
+
|
|
72
|
+
const parsed = parseThemeCSS({ css })
|
|
73
|
+
const updates: Record<string, string> = {}
|
|
74
|
+
let count = 0
|
|
75
|
+
|
|
76
|
+
// Map light colors to light.{fieldName} paths
|
|
77
|
+
for (const [cssVar, value] of Object.entries(parsed.light)) {
|
|
78
|
+
const fieldName = CSS_VAR_TO_FIELD[cssVar]
|
|
79
|
+
if (fieldName) {
|
|
80
|
+
updates[`light.${fieldName}`] = value
|
|
81
|
+
count++
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Map dark colors to dark.{fieldName} paths
|
|
86
|
+
for (const [cssVar, value] of Object.entries(parsed.dark)) {
|
|
87
|
+
const fieldName = CSS_VAR_TO_FIELD[cssVar]
|
|
88
|
+
if (fieldName) {
|
|
89
|
+
updates[`dark.${fieldName}`] = value
|
|
90
|
+
count++
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (count > 0) {
|
|
95
|
+
onImport(updates)
|
|
96
|
+
setImportResult(`Imported ${count} color values`)
|
|
97
|
+
setCss("")
|
|
98
|
+
setTimeout(() => setImportResult(null), 3000)
|
|
99
|
+
} else {
|
|
100
|
+
setImportResult("No matching CSS variables found")
|
|
101
|
+
setTimeout(() => setImportResult(null), 3000)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className="rounded-lg border bg-card p-4 mb-6">
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
onClick={() => setIsExpanded(!isExpanded)}
|
|
110
|
+
className="flex items-center gap-2 text-sm font-medium w-full text-left"
|
|
111
|
+
>
|
|
112
|
+
<span className={`transition-transform ${isExpanded ? "rotate-90" : ""}`}>▶</span>
|
|
113
|
+
Import Theme from CSS
|
|
114
|
+
</button>
|
|
115
|
+
|
|
116
|
+
{isExpanded && (
|
|
117
|
+
<div className="mt-3 space-y-3">
|
|
118
|
+
<p className="text-xs text-muted-foreground">
|
|
119
|
+
Paste CSS from{" "}
|
|
120
|
+
<a
|
|
121
|
+
href="https://tweakcn.com"
|
|
122
|
+
target="_blank"
|
|
123
|
+
rel="noopener noreferrer"
|
|
124
|
+
className="underline"
|
|
125
|
+
>
|
|
126
|
+
tweakcn
|
|
127
|
+
</a>
|
|
128
|
+
{" "}or{" "}
|
|
129
|
+
<a
|
|
130
|
+
href="https://ui.shadcn.com/themes"
|
|
131
|
+
target="_blank"
|
|
132
|
+
rel="noopener noreferrer"
|
|
133
|
+
className="underline"
|
|
134
|
+
>
|
|
135
|
+
shadcn/ui themes
|
|
136
|
+
</a>
|
|
137
|
+
. The importer will match CSS variable names to color fields and fill them in.
|
|
138
|
+
</p>
|
|
139
|
+
|
|
140
|
+
<textarea
|
|
141
|
+
value={css}
|
|
142
|
+
onChange={(e) => setCss(e.target.value)}
|
|
143
|
+
placeholder={`:root {
|
|
144
|
+
--background: #ffffff;
|
|
145
|
+
--foreground: #0a0a0a;
|
|
146
|
+
--primary: #171717;
|
|
147
|
+
...
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.dark {
|
|
151
|
+
--background: #0a0a0a;
|
|
152
|
+
...
|
|
153
|
+
}`}
|
|
154
|
+
className="w-full h-40 rounded-md border bg-background px-3 py-2 text-xs font-mono resize-y"
|
|
155
|
+
/>
|
|
156
|
+
|
|
157
|
+
<div className="flex items-center gap-3">
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
onClick={handleImport}
|
|
161
|
+
disabled={!css.trim()}
|
|
162
|
+
className="inline-flex items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50"
|
|
163
|
+
>
|
|
164
|
+
Import
|
|
165
|
+
</button>
|
|
166
|
+
{importResult && (
|
|
167
|
+
<span className="text-xs text-muted-foreground">{importResult}</span>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useVexFormContext } from "@vexcms/ui"
|
|
4
|
+
|
|
5
|
+
import { ThemeImport } from "./ThemeImport"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom admin field component that renders the theme CSS import UI.
|
|
9
|
+
* Uses the VexForm context to programmatically set color field values
|
|
10
|
+
* when CSS is imported.
|
|
11
|
+
*
|
|
12
|
+
* Register on a ui() field in the themes collection:
|
|
13
|
+
* ```ts
|
|
14
|
+
* importTheme: ui({ admin: { components: { Field: ThemeImportField } } })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export default function ThemeImportField() {
|
|
18
|
+
const { form } = useVexFormContext()
|
|
19
|
+
|
|
20
|
+
const handleImport = (updates: Record<string, string>) => {
|
|
21
|
+
for (const [path, value] of Object.entries(updates)) {
|
|
22
|
+
// Path is like "light.background" or "dark.foreground"
|
|
23
|
+
// Tabs expand to top-level keys, so the form field path is just the path directly
|
|
24
|
+
try {
|
|
25
|
+
form.setFieldValue(path as any, value)
|
|
26
|
+
} catch {
|
|
27
|
+
// Field might not exist in this form — silently skip
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return <ThemeImport onImport={handleImport} />
|
|
33
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { Accordion as AccordionPrimitive } from "@base-ui/react/accordion"
|
|
4
|
+
|
|
5
|
+
import { cn } from "~/lib/utils"
|
|
6
|
+
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
|
7
|
+
|
|
8
|
+
function Accordion({ className, ...props }: AccordionPrimitive.Root.Props) {
|
|
9
|
+
return (
|
|
10
|
+
<AccordionPrimitive.Root
|
|
11
|
+
data-slot="accordion"
|
|
12
|
+
className={cn("flex w-full flex-col", className)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function AccordionItem({ className, ...props }: AccordionPrimitive.Item.Props) {
|
|
19
|
+
return (
|
|
20
|
+
<AccordionPrimitive.Item
|
|
21
|
+
data-slot="accordion-item"
|
|
22
|
+
className={cn("not-last:border-b", className)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function AccordionTrigger({
|
|
29
|
+
className,
|
|
30
|
+
children,
|
|
31
|
+
...props
|
|
32
|
+
}: AccordionPrimitive.Trigger.Props) {
|
|
33
|
+
return (
|
|
34
|
+
<AccordionPrimitive.Header className="flex">
|
|
35
|
+
<AccordionPrimitive.Trigger
|
|
36
|
+
data-slot="accordion-trigger"
|
|
37
|
+
className={cn(
|
|
38
|
+
"group/accordion-trigger relative flex flex-1 items-start justify-between rounded-md border border-transparent py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:after:border-ring aria-disabled:pointer-events-none aria-disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
|
|
39
|
+
className
|
|
40
|
+
)}
|
|
41
|
+
{...props}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
<ChevronDownIcon data-slot="accordion-trigger-icon" className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden" />
|
|
45
|
+
<ChevronUpIcon data-slot="accordion-trigger-icon" className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline" />
|
|
46
|
+
</AccordionPrimitive.Trigger>
|
|
47
|
+
</AccordionPrimitive.Header>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function AccordionContent({
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
...props
|
|
55
|
+
}: AccordionPrimitive.Panel.Props) {
|
|
56
|
+
return (
|
|
57
|
+
<AccordionPrimitive.Panel
|
|
58
|
+
data-slot="accordion-content"
|
|
59
|
+
className="overflow-hidden text-sm data-open:animate-accordion-down data-closed:animate-accordion-up"
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
<div
|
|
63
|
+
className={cn(
|
|
64
|
+
"h-(--accordion-panel-height) pt-0 pb-4 data-ending-style:h-0 data-starting-style:h-0 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
|
65
|
+
className
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
</div>
|
|
70
|
+
</AccordionPrimitive.Panel>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// @ts-expect-error culori/fn lacks type declarations in v4
|
|
2
|
+
import { parse, formatHex, formatHsl, converter } from "culori/fn"
|
|
3
|
+
|
|
4
|
+
const toOklch = converter("oklch")
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convert a color string to the specified format.
|
|
8
|
+
*
|
|
9
|
+
* @param props.color - Input color in any CSS-parseable format
|
|
10
|
+
* @param props.format - Target format: "hex", "hsl", or "oklch"
|
|
11
|
+
* @returns Formatted color string, or the original if parsing fails
|
|
12
|
+
*/
|
|
13
|
+
export function convertColor(props: {
|
|
14
|
+
color: string
|
|
15
|
+
format: "hex" | "hsl" | "oklch"
|
|
16
|
+
}): string {
|
|
17
|
+
if (!props.color || props.color.startsWith("var(")) return props.color
|
|
18
|
+
|
|
19
|
+
const parsed = parse(props.color)
|
|
20
|
+
if (!parsed) return props.color
|
|
21
|
+
|
|
22
|
+
switch (props.format) {
|
|
23
|
+
case "hex":
|
|
24
|
+
return formatHex(parsed) ?? props.color
|
|
25
|
+
case "hsl":
|
|
26
|
+
return formatHsl(parsed) ?? props.color
|
|
27
|
+
case "oklch": {
|
|
28
|
+
const oklch = toOklch(parsed)
|
|
29
|
+
if (!oklch) return props.color
|
|
30
|
+
const l = (oklch.l ?? 0).toFixed(3)
|
|
31
|
+
const c = (oklch.c ?? 0).toFixed(3)
|
|
32
|
+
const h = (oklch.h ?? 0).toFixed(1)
|
|
33
|
+
return `oklch(${l} ${c} ${h})`
|
|
34
|
+
}
|
|
35
|
+
default:
|
|
36
|
+
return props.color
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Known CSS custom property names that represent colors.
|
|
42
|
+
* These are the standard shadcn/Tailwind CSS variables.
|
|
43
|
+
*/
|
|
44
|
+
const COLOR_VAR_NAMES = [
|
|
45
|
+
"background",
|
|
46
|
+
"foreground",
|
|
47
|
+
"card",
|
|
48
|
+
"card-foreground",
|
|
49
|
+
"popover",
|
|
50
|
+
"popover-foreground",
|
|
51
|
+
"primary",
|
|
52
|
+
"primary-foreground",
|
|
53
|
+
"secondary",
|
|
54
|
+
"secondary-foreground",
|
|
55
|
+
"muted",
|
|
56
|
+
"muted-foreground",
|
|
57
|
+
"accent",
|
|
58
|
+
"accent-foreground",
|
|
59
|
+
"destructive",
|
|
60
|
+
"destructive-foreground",
|
|
61
|
+
"border",
|
|
62
|
+
"input",
|
|
63
|
+
"ring",
|
|
64
|
+
"chart-1",
|
|
65
|
+
"chart-2",
|
|
66
|
+
"chart-3",
|
|
67
|
+
"chart-4",
|
|
68
|
+
"chart-5",
|
|
69
|
+
"sidebar",
|
|
70
|
+
"sidebar-foreground",
|
|
71
|
+
"sidebar-primary",
|
|
72
|
+
"sidebar-primary-foreground",
|
|
73
|
+
"sidebar-accent",
|
|
74
|
+
"sidebar-accent-foreground",
|
|
75
|
+
"sidebar-border",
|
|
76
|
+
"sidebar-ring",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Extract color CSS custom properties from the document's stylesheets.
|
|
81
|
+
* Returns light and dark values for each known color variable.
|
|
82
|
+
*/
|
|
83
|
+
export function getThemeColorsFromDOM(): {
|
|
84
|
+
name: string
|
|
85
|
+
lightValue: string
|
|
86
|
+
darkValue: string | null
|
|
87
|
+
}[] {
|
|
88
|
+
if (typeof document === "undefined") return []
|
|
89
|
+
|
|
90
|
+
const results: { name: string; lightValue: string; darkValue: string | null }[] = []
|
|
91
|
+
|
|
92
|
+
// Get computed styles for :root (light mode)
|
|
93
|
+
const rootStyles = getComputedStyle(document.documentElement)
|
|
94
|
+
|
|
95
|
+
// Try to get dark mode values by reading stylesheets
|
|
96
|
+
const darkValues = new Map<string, string>()
|
|
97
|
+
try {
|
|
98
|
+
for (const sheet of document.styleSheets) {
|
|
99
|
+
try {
|
|
100
|
+
for (const rule of sheet.cssRules) {
|
|
101
|
+
if (rule instanceof CSSStyleRule && rule.selectorText?.includes(".dark")) {
|
|
102
|
+
for (const varName of COLOR_VAR_NAMES) {
|
|
103
|
+
const value = rule.style.getPropertyValue(`--${varName}`).trim()
|
|
104
|
+
if (value) darkValues.set(varName, value)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
// Cross-origin stylesheet — skip
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
// No stylesheet access
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const varName of COLOR_VAR_NAMES) {
|
|
117
|
+
const lightValue = rootStyles.getPropertyValue(`--${varName}`).trim()
|
|
118
|
+
if (!lightValue) continue
|
|
119
|
+
|
|
120
|
+
results.push({
|
|
121
|
+
name: varName,
|
|
122
|
+
lightValue,
|
|
123
|
+
darkValue: darkValues.get(varName) ?? null,
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return results
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Parse CSS text containing :root and .dark variable declarations.
|
|
132
|
+
* Used by the theme import feature to extract color values from pasted CSS.
|
|
133
|
+
*
|
|
134
|
+
* @param props.css - Raw CSS text containing :root { } and optionally .dark { }
|
|
135
|
+
* @returns Parsed light and dark color maps
|
|
136
|
+
*/
|
|
137
|
+
export function parseThemeCSS(props: { css: string }): {
|
|
138
|
+
light: Record<string, string>
|
|
139
|
+
dark: Record<string, string>
|
|
140
|
+
} {
|
|
141
|
+
const light: Record<string, string> = {}
|
|
142
|
+
const dark: Record<string, string> = {}
|
|
143
|
+
|
|
144
|
+
// Match :root { ... } block
|
|
145
|
+
const rootMatch = props.css.match(/:root\s*\{([\s\S]+?)\}/)
|
|
146
|
+
if (rootMatch) {
|
|
147
|
+
const vars = rootMatch[1].matchAll(/--([a-z-]+)\s*:\s*([^;]+)/g)
|
|
148
|
+
for (const match of vars) {
|
|
149
|
+
const name = match[1].trim()
|
|
150
|
+
const value = match[2].trim()
|
|
151
|
+
if (COLOR_VAR_NAMES.includes(name)) {
|
|
152
|
+
light[name] = value
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Match .dark { ... } block
|
|
158
|
+
const darkMatch = props.css.match(/\.dark\s*\{([\s\S]+?)\}/)
|
|
159
|
+
if (darkMatch) {
|
|
160
|
+
const vars = darkMatch[1].matchAll(/--([a-z-]+)\s*:\s*([^;]+)/g)
|
|
161
|
+
for (const match of vars) {
|
|
162
|
+
const name = match[1].trim()
|
|
163
|
+
const value = match[2].trim()
|
|
164
|
+
if (COLOR_VAR_NAMES.includes(name)) {
|
|
165
|
+
dark[name] = value
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { light, dark }
|
|
171
|
+
}
|