UNPKG

@synergy-design-system/components

Version:
96 lines (93 loc) 2.93 kB
import { ChartPresets } from "./chunk.FVE47CHN.js"; import { mergeConfigs } from "./chunk.T3OQKYCT.js"; import { __privateAdd, __privateGet, __privateMethod, __privateSet } from "./chunk.VK2FVWOF.js"; // src/components/chart/configs/config.ts var _config, _ChartConfigBuilder_instances, with_fn, registerPresetHandleMethod_fn, registerPresetHandleMethods_fn; var ChartConfigBuilder = class { /** * Creates a new handle seeded with an empty chart configuration. * * @param base The initial config to extend. */ constructor(base = {}) { __privateAdd(this, _ChartConfigBuilder_instances); __privateAdd(this, _config); __privateSet(this, _config, base); __privateMethod(this, _ChartConfigBuilder_instances, registerPresetHandleMethods_fn).call(this); } /** * Sets the base chart config that subsequent preset calls extend. * * Calling `baseConfig()` again replaces the previous base config. */ baseConfig(config) { __privateSet(this, _config, mergeConfigs(config)); return this; } /** * Returns the composed chart configuration. * * @returns The final merged ECConfig. */ build() { return __privateGet(this, _config); } }; _config = new WeakMap(); _ChartConfigBuilder_instances = new WeakSet(); /** * Applies a modifier to the current config and stores the merged result. * * @param modifier The modifier to apply to the current config. * @returns The current builder instance for chaining. */ with_fn = function(modifier) { __privateSet(this, _config, mergeConfigs(__privateGet(this, _config), modifier(__privateGet(this, _config)))); return this; }; /** * Installs a single preset method on this builder. */ registerPresetHandleMethod_fn = function(modifierName) { const modifier = ChartPresets[modifierName]; const typedModifier = modifier; Object.defineProperty(this, modifierName, { configurable: true, enumerable: false, value: (options) => __privateMethod(this, _ChartConfigBuilder_instances, with_fn).call(this, typedModifier(options)), writable: false }); }; /** * Registers all preset functions from the `ChartPresets` namespace as methods on this builder instance. * * Each method is named after the preset and accepts the same options as the preset function. * Calling a method applies the corresponding preset to the current config. */ registerPresetHandleMethods_fn = function() { const presetNames = Object.keys(ChartPresets); presetNames.forEach((presetName) => __privateMethod(this, _ChartConfigBuilder_instances, registerPresetHandleMethod_fn).call(this, presetName)); return this; }; var resolveConfigInput = (input) => { if (typeof input === "function") { const builder = new ChartConfigBuilder(); input(builder); return builder.build(); } return input; }; export { ChartConfigBuilder, resolveConfigInput }; //# sourceMappingURL=chunk.UOCJ2U5N.js.map