Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Wanstrath
1e013287cf HMR support 2026-01-13 15:24:03 -08:00
Chris Wanstrath
e30f8c8a68 fix packaging 2026-01-13 15:23:56 -08:00
2 changed files with 17 additions and 2 deletions

View File

@ -1,7 +1,16 @@
{
"name": "forge",
"module": "src/index.ts",
"version": "0.1.0",
"type": "module",
"main": "src/index.tsx",
"module": "src/index.tsx",
"types": "src/index.tsx",
"exports": {
".": {
"import": "./src/index.tsx",
"types": "./src/index.tsx"
}
},
"scripts": {
"dev": "bun build:spa && bun run --hot server.tsx",
"test": "bun test",

View File

@ -10,6 +10,8 @@ let registeredThemeKeys: Set<string> = new Set()
// Clear all registered styles
export function clearStyles() {
for (const key in styles) delete styles[key]
for (const key in themes) delete themes[key]
registeredThemeKeys.clear()
}
// Register a theme with CSS custom properties
@ -286,7 +288,11 @@ export function define(nameOrDef: string | TagDef, defIfNamed?: TagDef) {
const def = defIfNamed ?? nameOrDef as TagDef
const name = defIfNamed ? (nameOrDef as string) : anonName(def)
if (styles[name]) throw `${name} is already defined! Must use unique names.`
// Clear any existing styles for this component (supports HMR/hot reload)
for (const key in styles) {
if (key === name || key.startsWith(`${name}_`) || key.startsWith(`${name}.`) || key.startsWith(`${name}:`))
delete styles[key]
}
registerStyles(name, def)
return (props: Record<string, any>) => {