Skip to content

Commit

Permalink
refactor(hdom-canvas): update resolveColor to use resolveAsCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 21, 2019
1 parent f96ac92 commit 22ab80e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions packages/hdom-canvas/src/draw/color.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { isArrayLike, isNumber, isString } from "@thi.ng/checks";
import { asCSS, ColorMode, ReadonlyColor } from "@thi.ng/color";
import { isString } from "@thi.ng/checks";
import { resolveAsCSS } from "@thi.ng/color";
import { DrawState } from "../api";

const resolve = (v: any) =>
isArrayLike(v)
? isNumber((<any>v).mode)
? asCSS(<any>v)
: asCSS(<ReadonlyColor>v, ColorMode.RGBA)
: isNumber(v)
? asCSS(v, ColorMode.INT32)
: v;

export const resolveColor = (v: any) => (isString(v) ? v : resolve(v));
export const resolveColor = (v: any) => (isString(v) ? v : resolveAsCSS(v));

export const resolveGradientOrColor = (state: DrawState, v: any) =>
isString(v) ? (v[0] === "$" ? state.grads![v.substr(1)] : v) : resolve(v);
isString(v)
? v[0] === "$"
? state.grads![v.substr(1)]
: v
: resolveAsCSS(v);

export const defLinearGradient = (
ctx: CanvasRenderingContext2D,
Expand Down

0 comments on commit 22ab80e

Please sign in to comment.