-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_config.go
More file actions
227 lines (184 loc) · 6.49 KB
/
app_config.go
File metadata and controls
227 lines (184 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package forgeui
import (
"io/fs"
"github.com/xraph/forgeui/bridge"
"github.com/xraph/forgeui/theme"
)
// AppConfig holds enhanced ForgeUI application configuration
type AppConfig struct {
// Debug enables debug/development mode
Debug bool
// Theme is the active theme name (legacy support)
Theme string
// AssetPublicDir is the source directory for static assets
AssetPublicDir string
// AssetOutputDir is the output directory for processed assets
AssetOutputDir string
// AssetManifest is the path to a manifest file for production builds
AssetManifest string
// AssetFileSystem is an optional custom filesystem for assets (e.g., embed.FS)
AssetFileSystem fs.FS
// Bridge configuration (optional)
BridgeConfig *bridge.Config
EnableBridge bool
// Theme configuration (enhanced)
LightTheme *theme.Theme
DarkTheme *theme.Theme
// FontConfig holds typography configuration (fonts, preloading, etc.)
FontConfig *theme.FontConfig
// DefaultLayout is the default layout name for all pages
DefaultLayout string
// InputCSS is an optional path to a custom Tailwind v4 input CSS file.
// When set, this is used instead of auto-generating one from themes.
InputCSS string
// Verbose enables detailed logging for asset processing and other subsystems.
Verbose bool
// BasePath is the base URL path for all ForgeUI routes (static, bridge, etc.)
// Example: "/api/identity/ui" results in:
// - Static: /api/identity/ui/static/...
// - Bridge: /api/identity/ui/bridge/...
BasePath string
// StaticPath is the URL path for static assets (relative to BasePath if set)
// Default: "/static"
StaticPath string
// Component defaults (from legacy Config)
DefaultSize Size
DefaultVariant Variant
DefaultRadius Radius
}
// DefaultAppConfig returns sensible defaults for ForgeUI application
func DefaultAppConfig() *AppConfig {
return &AppConfig{
Debug: false,
Theme: "default",
AssetPublicDir: "public",
AssetOutputDir: "dist",
AssetManifest: "",
EnableBridge: false,
BridgeConfig: nil,
LightTheme: nil,
DarkTheme: nil,
DefaultLayout: "",
BasePath: "",
StaticPath: "/static",
DefaultSize: SizeMD,
DefaultVariant: VariantDefault,
DefaultRadius: RadiusMD,
}
}
// AppOption is a functional option for configuring the App
type AppOption func(*AppConfig)
// WithDev enables or disables development mode
func WithDev(dev bool) AppOption {
return func(c *AppConfig) { c.Debug = dev }
}
// WithDebug enables or disables debug mode (alias for WithDev)
func WithDebug(debug bool) AppOption {
return func(c *AppConfig) { c.Debug = debug }
}
// WithAssets sets the asset directories
func WithAssets(publicDir string, opts ...string) AppOption {
return func(c *AppConfig) {
c.AssetPublicDir = publicDir
if len(opts) > 0 {
c.AssetOutputDir = opts[0]
}
}
}
// WithAssetPublicDir sets the source directory for static assets
func WithAssetPublicDir(dir string) AppOption {
return func(c *AppConfig) { c.AssetPublicDir = dir }
}
// WithAssetOutputDir sets the output directory for processed assets
func WithAssetOutputDir(dir string) AppOption {
return func(c *AppConfig) { c.AssetOutputDir = dir }
}
// WithAssetManifest sets the path to a manifest file for production builds
func WithAssetManifest(path string) AppOption {
return func(c *AppConfig) { c.AssetManifest = path }
}
// WithAssetFileSystem sets a custom filesystem for serving assets (e.g., embed.FS)
// This is useful when embedding assets in the binary or using custom filesystem implementations
func WithAssetFileSystem(fsys fs.FS) AppOption {
return func(c *AppConfig) { c.AssetFileSystem = fsys }
}
// WithEmbedFS is an alias for WithAssetFileSystem for better discoverability
func WithEmbedFS(fsys fs.FS) AppOption {
return func(c *AppConfig) { c.AssetFileSystem = fsys }
}
// WithBridge enables and configures the bridge system
func WithBridge(opts ...bridge.ConfigOption) AppOption {
return func(c *AppConfig) {
c.EnableBridge = true
bridgeConfig := bridge.DefaultConfig()
for _, opt := range opts {
opt(bridgeConfig)
}
c.BridgeConfig = bridgeConfig
}
}
// WithThemes sets the light and dark themes
func WithThemes(light, dark *theme.Theme) AppOption {
return func(c *AppConfig) {
c.LightTheme = light
c.DarkTheme = dark
}
}
// WithFonts sets the font configuration for the application.
// This enables font preloading and @font-face generation.
func WithFonts(fc *theme.FontConfig) AppOption {
return func(c *AppConfig) { c.FontConfig = fc }
}
// WithDefaultLayout sets the default layout for all pages
func WithDefaultLayout(layout string) AppOption {
return func(c *AppConfig) {
c.DefaultLayout = layout
}
}
// WithAppStaticPath sets the URL path for static assets
func WithAppStaticPath(path string) AppOption {
return func(c *AppConfig) {
c.StaticPath = path
}
}
// WithStaticPath sets the static assets path (alias for WithAppStaticPath)
func WithStaticPath(path string) AppOption {
return func(c *AppConfig) { c.StaticPath = path }
}
// WithBasePath sets the base URL path for all ForgeUI routes
// This prefixes static, bridge, and other ForgeUI endpoints
// Example: WithBasePath("/api/identity/ui") results in:
// - Static: /api/identity/ui/static/...
// - Bridge: /api/identity/ui/bridge/...
func WithBasePath(path string) AppOption {
return func(c *AppConfig) { c.BasePath = path }
}
// WithInputCSS sets a custom Tailwind v4 input CSS file.
// When set, this is used instead of auto-generating one from themes.
func WithInputCSS(path string) AppOption {
return func(c *AppConfig) { c.InputCSS = path }
}
// WithVerbose enables verbose logging for asset processing
func WithVerbose(verbose bool) AppOption {
return func(c *AppConfig) { c.Verbose = verbose }
}
// WithThemeName sets the theme name (legacy support)
func WithThemeName(theme string) AppOption {
return func(c *AppConfig) { c.Theme = theme }
}
// WithDefaultSize sets the default component size
func WithDefaultSize(size Size) AppOption {
return func(c *AppConfig) { c.DefaultSize = size }
}
// WithDefaultVariant sets the default component variant
func WithDefaultVariant(variant Variant) AppOption {
return func(c *AppConfig) { c.DefaultVariant = variant }
}
// WithDefaultRadius sets the default border radius
func WithDefaultRadius(radius Radius) AppOption {
return func(c *AppConfig) { c.DefaultRadius = radius }
}
// WithAssetsPath sets the filesystem assets path (deprecated, use WithAssetPublicDir)
func WithAssetsPath(path string) AppOption {
return func(c *AppConfig) { c.AssetPublicDir = path }
}