From a2562195210e220e63eeea853d022e9ace97aa6e Mon Sep 17 00:00:00 2001 From: "Samuel M. Bednarz" Date: Sat, 30 Dec 2023 01:38:06 +0100 Subject: [PATCH] output input seperation --- packages/core/engine/generator.ts | 6 +----- packages/core/engine/index.ts | 18 ++++++++---------- packages/core/engine/primitives/format.ts | 8 ++++---- packages/core/package.json | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/core/engine/generator.ts b/packages/core/engine/generator.ts index 3b775c7..18bf8bb 100644 --- a/packages/core/engine/generator.ts +++ b/packages/core/engine/generator.ts @@ -88,9 +88,5 @@ function base(input: UmbraInput, adjusted: UmbraAdjusted) { } export function umbraGenerate(input: UmbraInput, adjusted: UmbraAdjusted) { - return { - input, - adjusted, - generated: [base(input, adjusted), ...accents(input, adjusted)] - } + return [base(input, adjusted), ...accents(input, adjusted)] } diff --git a/packages/core/engine/index.ts b/packages/core/engine/index.ts index 08f4676..e5a45e4 100644 --- a/packages/core/engine/index.ts +++ b/packages/core/engine/index.ts @@ -1,6 +1,6 @@ import { colord } from 'colord' import { defaultSettings, defaultScheme } from './defaults' -import type { UmbraOutput, UmbraScheme, UmbraSettings, UmbraInput } from './types' +import type { UmbraOutput, UmbraScheme, UmbraSettings, UmbraInput, RawRange } from './types' import { format, Format, Formater, UmbraOutputs } from './primitives/format' import { inverse, isDark } from './primitives/scheme' @@ -28,9 +28,9 @@ interface RootSettings extends UmbraSettings { export function umbra(scheme = defaultScheme, settings?: RootSettings) { const input = umbraInput({ scheme, settings }) - const adjusted = umbraAdjust(input.settings, scheme) - const generated = umbraGenerate(input, adjusted) - return umbraHydrate(generated) + const adjustment = umbraAdjust(input.settings, scheme) + const output = umbraGenerate(input, adjustment) + return umbraHydrate(input, output) } function umbraInput({ @@ -66,14 +66,12 @@ function umbraAdjust(settings: UmbraSettings, scheme = defaultScheme) { } } -export function umbraHydrate(output: UmbraOutput) { - const input = output.input - function apply({ element, formater, alias }: ApplyProps = {}) { - return format({ output, formater }).attach(element, alias) - } - +export function umbraHydrate(input: UmbraInput, output: RawRange[]) { + const apply = ({ element, formater, alias }: ApplyProps = {}) => + format({ output, formater }).attach(element, alias) return { apply, + input, output, isDark: () => isDark(input.scheme), format: (formater?: Formater) => format({ output, formater }), diff --git a/packages/core/engine/primitives/format.ts b/packages/core/engine/primitives/format.ts index 056efc2..8e58280 100644 --- a/packages/core/engine/primitives/format.ts +++ b/packages/core/engine/primitives/format.ts @@ -1,12 +1,12 @@ import { Colord } from 'colord' import { umbra } from '../..' -import { UmbraOutput, RawRange, FormatedRange } from '../types' +import { RawRange, FormatedRange } from '../types' import { attach, Alias } from './attach' export type Formater = (color: Colord) => string interface FormatProps { - output: UmbraOutput + output: RawRange[] formater?: Formater element?: HTMLElement } @@ -18,7 +18,7 @@ export interface Format extends UmbraOutputs { export interface UmbraOutputs { flattened: FlattenColor[] formated: FormatedRange[] - output: UmbraOutput + output: RawRange[] } export const format = ({ output = umbra().output, formater = defaultFormater }: FormatProps) => { @@ -39,7 +39,7 @@ export const format = ({ output = umbra().output, formater = defaultFormater }: } } - const formated = output.generated.map((c) => getColors(c, formater)) + const formated = output.map((c) => getColors(c, formater)) const flattened = flattenColors({ prefix: '--', formated diff --git a/packages/core/package.json b/packages/core/package.json index d066107..fae1e9c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@umbrajs/core", - "version": "0.0.33", + "version": "0.0.332", "description": "Umbra is a theme managment library that allows you to create semantic color themes that are easy to dynamically customize, change retroactively and scale progressively", "author": "Samuel M. Bednarz", "repository": {