Skip to content

Commit

Permalink
imrpove formating pass
Browse files Browse the repository at this point in the history
  • Loading branch information
CarelessCourage committed Jan 9, 2024
1 parent f87b6a8 commit 22b889c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
21 changes: 15 additions & 6 deletions packages/core/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Umbra {

interface DefaultSettings extends UmbraSettings {
callback?: (props: UmbraOutputs) => void
formater?: Formater
}

export function umbra(scheme = defaultScheme, settings?: DefaultSettings): Umbra {
Expand All @@ -39,7 +40,8 @@ export function umbra(scheme = defaultScheme, settings?: DefaultSettings): Umbra
input,
output: umbraGenerate(input, adjustment),
inversed: scheme.inversed ? insertFallbacks(scheme.inversed, settings) : undefined,
callback: settings?.callback
callback: settings?.callback,
defaultFormater: settings?.formater
})
}

Expand Down Expand Up @@ -101,23 +103,30 @@ export function umbraHydrate({
input,
output,
inversed,
callback
callback,
defaultFormater
}: {
input: UmbraInput
output: UmbraRange[]
inversed?: UmbraInput
callback?: (props: any) => void
callback?: (props: UmbraOutputs) => void
defaultFormater?: Formater
}) {
function getFormat(passedFormater?: Formater) {
const formater = passedFormater || defaultFormater
return format({ output, formater, input, callback })
}

return {
input,
output,
isDark: () => isDark(input),
format: (formater?: Formater) => format({ output, formater, input, callback }),
inverse: () => umbra(inverse(input, inversed)),
format: (formater?: Formater) => getFormat(formater),
inverse: () => umbra(inverse(input, inversed)) as Umbra,
apply: (props?: ApplyProps) => {
const { alias, formater } = props || {}
const target = getTarget(props?.target)
const formated = format({ output, formater, input })
const formated = getFormat(formater)
const outputs = formated.attach({ alias, target })
callback && callback(outputs)
return outputs
Expand Down
15 changes: 3 additions & 12 deletions packages/core/engine/primitives/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,17 @@ export const format = ({
}
}

export const defaultFormater = hexFormat
export const defaultFormater = hex

export function strippedRGBFormat(color: Colord) {
const rgb = color.toRgb()
return `${rgb.r} ${rgb.g} ${rgb.b}`
}

export function hexFormat(color: Colord) {
export function hex(color: Colord) {
return color.toHex()
}

export function rgbStrippedFormat(color: Colord) {
export function rgb(color: Colord) {
const rgba = color.toRgb()
return `${rgba.r} ${rgba.g} ${rgba.b}`
}

export function hslFormat(color: Colord) {
return color.toHslString()
}

export interface FlattenColor {
name: string
color: string
Expand Down
15 changes: 3 additions & 12 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { umbra, umbraHydrate, Umbra } from './engine/index'
import { umbraGenerate } from './engine/generator'
import { randomScheme } from './engine/primitives/utils'
import {
format,
FlattenColor,
Formater,
UmbraOutputs,
hexFormat,
rgbStrippedFormat,
hslFormat
} from './engine/primitives/format'
import { format, FlattenColor, Formater, UmbraOutputs, hex, rgb } from './engine/primitives/format'
import { attach } from './engine/primitives/attach'
import { mostReadable, colorMix } from './engine/primitives/color'
import type {
Expand All @@ -33,9 +25,8 @@ export {
findContrast,
attach,
format,
hexFormat,
rgbStrippedFormat,
hslFormat
hex,
rgb
}

export type {
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.447",
"version": "0.0.45",
"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 22b889c

Please sign in to comment.