Skip to content

Commit

Permalink
output input seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
CarelessCourage committed Dec 30, 2023
1 parent ef19372 commit a256219
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
6 changes: 1 addition & 5 deletions packages/core/engine/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
18 changes: 8 additions & 10 deletions packages/core/engine/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 }),
Expand Down
8 changes: 4 additions & 4 deletions packages/core/engine/primitives/format.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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) => {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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<https://github.com/CarelessCourage>",
"repository": {
Expand Down

0 comments on commit a256219

Please sign in to comment.