2026-01-07 16:53:17 +03:00
|
|
|
import {
|
|
|
|
|
type ControlModel,
|
2026-01-21 21:51:22 +03:00
|
|
|
type TypographyControl,
|
2026-01-07 16:53:17 +03:00
|
|
|
createTypographyControl,
|
|
|
|
|
} from '$shared/lib';
|
2026-01-21 21:51:22 +03:00
|
|
|
import { SvelteMap } from 'svelte/reactivity';
|
|
|
|
|
|
|
|
|
|
export interface Control {
|
|
|
|
|
id: string;
|
|
|
|
|
increaseLabel?: string;
|
|
|
|
|
decreaseLabel?: string;
|
|
|
|
|
controlLabel?: string;
|
|
|
|
|
instance: TypographyControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class TypographyControlManager {
|
|
|
|
|
#controls = new SvelteMap<string, Control>();
|
2026-02-06 14:20:32 +03:00
|
|
|
#sizeMultiplier = $state(1);
|
2026-01-21 21:51:22 +03:00
|
|
|
|
|
|
|
|
constructor(configs: ControlModel[]) {
|
|
|
|
|
configs.forEach(({ id, increaseLabel, decreaseLabel, controlLabel, ...config }) => {
|
|
|
|
|
this.#controls.set(id, {
|
|
|
|
|
id,
|
|
|
|
|
increaseLabel,
|
|
|
|
|
decreaseLabel,
|
|
|
|
|
controlLabel,
|
|
|
|
|
instance: createTypographyControl(config),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get controls() {
|
|
|
|
|
return this.#controls.values();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get weight() {
|
|
|
|
|
return this.#controls.get('font_weight')?.instance.value ?? 400;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get size() {
|
2026-02-06 14:20:32 +03:00
|
|
|
const size = this.#controls.get('font_size')?.instance.value;
|
|
|
|
|
return size === undefined ? undefined : size * this.#sizeMultiplier;
|
2026-01-21 21:51:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get height() {
|
|
|
|
|
return this.#controls.get('line_height')?.instance.value;
|
|
|
|
|
}
|
2026-01-30 00:48:29 +03:00
|
|
|
|
|
|
|
|
get spacing() {
|
|
|
|
|
return this.#controls.get('letter_spacing')?.instance.value;
|
|
|
|
|
}
|
2026-02-06 14:20:32 +03:00
|
|
|
|
|
|
|
|
set multiplier(value: number) {
|
|
|
|
|
this.#sizeMultiplier = value;
|
|
|
|
|
}
|
2026-01-21 21:51:22 +03:00
|
|
|
}
|
2026-01-07 16:53:17 +03:00
|
|
|
|
2026-01-18 15:55:07 +03:00
|
|
|
/**
|
|
|
|
|
* Creates a typography control manager that handles a collection of typography controls.
|
|
|
|
|
*
|
|
|
|
|
* @param configs - Array of control configurations.
|
|
|
|
|
* @returns - Typography control manager instance.
|
|
|
|
|
*/
|
2026-01-07 16:53:17 +03:00
|
|
|
export function createTypographyControlManager(configs: ControlModel[]) {
|
2026-01-21 21:51:22 +03:00
|
|
|
return new TypographyControlManager(configs);
|
2026-01-07 16:53:17 +03:00
|
|
|
}
|