52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
|
|
// Global configuration and project defaults for Imhotep
|
||
|
|
// Uses dependency injection patterns: configure() sets runtime globals,
|
||
|
|
// project() sets persistent project-level metadata.
|
||
|
|
|
||
|
|
export interface ImhotepConfig {
|
||
|
|
defaultTolerance?: { value: number; unit: 'px' | 'jnd' }
|
||
|
|
defaultFrame?: string
|
||
|
|
perceptualModel?: string
|
||
|
|
[key: string]: unknown
|
||
|
|
}
|
||
|
|
|
||
|
|
let globalConfig: ImhotepConfig = {}
|
||
|
|
|
||
|
|
/** Sets or updates global Imhotep runtime configuration. */
|
||
|
|
export function configure(config: ImhotepConfig): void {
|
||
|
|
globalConfig = { ...globalConfig, ...config }
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Returns a shallow copy of the current global config. */
|
||
|
|
export function getConfig(): ImhotepConfig {
|
||
|
|
return { ...globalConfig }
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ProjectConfig {
|
||
|
|
name?: string
|
||
|
|
fontCorpus?: string
|
||
|
|
adapters?: string[]
|
||
|
|
environments?: unknown[]
|
||
|
|
[key: string]: unknown
|
||
|
|
}
|
||
|
|
|
||
|
|
let projectConfig: ProjectConfig = {}
|
||
|
|
|
||
|
|
/** Sets or updates project-level defaults, font corpora, and adapters. */
|
||
|
|
export function project(config: ProjectConfig): void {
|
||
|
|
projectConfig = { ...projectConfig, ...config }
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Returns a shallow copy of the current project config. */
|
||
|
|
export function getProjectConfig(): ProjectConfig {
|
||
|
|
return { ...projectConfig }
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Environment guard for responsive contracts.
|
||
|
|
* Only executes the callback when the condition is truthy.
|
||
|
|
*/
|
||
|
|
export function when(condition: unknown, fn: () => void): void {
|
||
|
|
if (condition) {
|
||
|
|
fn()
|
||
|
|
}
|
||
|
|
}
|