Fix typescript indent size
This commit is contained in:
+35
-35
@@ -4,49 +4,49 @@ import { ColorToken } from "../tokens";
|
||||
export type Color = string;
|
||||
export type ColorRampStep = { value: Color; type: "color"; step: number };
|
||||
export type ColorRamp = {
|
||||
[index: number]: ColorRampStep;
|
||||
[index: number]: ColorRampStep;
|
||||
};
|
||||
|
||||
export function colorRamp(
|
||||
color: Color | [Color, Color],
|
||||
options?: { steps?: number; increment?: number; }
|
||||
color: Color | [Color, Color],
|
||||
options?: { steps?: number; increment?: number; }
|
||||
): ColorRamp {
|
||||
let scale: Scale;
|
||||
if (Array.isArray(color)) {
|
||||
const [startColor, endColor] = color;
|
||||
scale = chroma.scale([startColor, endColor]);
|
||||
} else {
|
||||
let hue = Math.round(chroma(color).hsl()[0]);
|
||||
let startColor = chroma.hsl(hue, 0.88, 0.96);
|
||||
let endColor = chroma.hsl(hue, 0.68, 0.12);
|
||||
scale = chroma
|
||||
.scale([startColor, color, endColor])
|
||||
.domain([0, 0.5, 1])
|
||||
.mode("hsl")
|
||||
.gamma(1)
|
||||
// .correctLightness(true)
|
||||
.padding([0, 0]);
|
||||
}
|
||||
let scale: Scale;
|
||||
if (Array.isArray(color)) {
|
||||
const [startColor, endColor] = color;
|
||||
scale = chroma.scale([startColor, endColor]);
|
||||
} else {
|
||||
let hue = Math.round(chroma(color).hsl()[0]);
|
||||
let startColor = chroma.hsl(hue, 0.88, 0.96);
|
||||
let endColor = chroma.hsl(hue, 0.68, 0.12);
|
||||
scale = chroma
|
||||
.scale([startColor, color, endColor])
|
||||
.domain([0, 0.5, 1])
|
||||
.mode("hsl")
|
||||
.gamma(1)
|
||||
// .correctLightness(true)
|
||||
.padding([0, 0]);
|
||||
}
|
||||
|
||||
const ramp: ColorRamp = {};
|
||||
const steps = options?.steps || 10;
|
||||
const increment = options?.increment || 100;
|
||||
const ramp: ColorRamp = {};
|
||||
const steps = options?.steps || 10;
|
||||
const increment = options?.increment || 100;
|
||||
|
||||
scale.colors(steps, "hex").forEach((color, ix) => {
|
||||
const step = ix * increment;
|
||||
ramp[step] = {
|
||||
value: color,
|
||||
step,
|
||||
type: "color",
|
||||
};
|
||||
});
|
||||
scale.colors(steps, "hex").forEach((color, ix) => {
|
||||
const step = ix * increment;
|
||||
ramp[step] = {
|
||||
value: color,
|
||||
step,
|
||||
type: "color",
|
||||
};
|
||||
});
|
||||
|
||||
return ramp;
|
||||
return ramp;
|
||||
}
|
||||
|
||||
export function withOpacity(color: ColorToken, opacity: number): ColorToken {
|
||||
return {
|
||||
...color,
|
||||
value: chroma(color.value).alpha(opacity).hex()
|
||||
};
|
||||
return {
|
||||
...color,
|
||||
value: chroma(color.value).alpha(opacity).hex()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,32 +4,32 @@ import { snakeCase } from "case-anything";
|
||||
|
||||
// Typescript magic to convert any string from camelCase to snake_case at compile time
|
||||
type SnakeCase<S> =
|
||||
S extends string ?
|
||||
S extends `${infer T}${infer U}` ?
|
||||
`${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${SnakeCase<U>}` :
|
||||
S :
|
||||
S;
|
||||
S extends string ?
|
||||
S extends `${infer T}${infer U}` ?
|
||||
`${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${SnakeCase<U>}` :
|
||||
S :
|
||||
S;
|
||||
|
||||
type SnakeCased<Type> = {
|
||||
[Property in keyof Type as SnakeCase<Property>]: SnakeCased<Type[Property]>
|
||||
[Property in keyof Type as SnakeCase<Property>]: SnakeCased<Type[Property]>
|
||||
}
|
||||
|
||||
export default function snakeCaseTree<T>(object: T): SnakeCased<T> {
|
||||
const snakeObject: any = {};
|
||||
for (const key in object) {
|
||||
snakeObject[snakeCase(key)] = snakeCaseValue(object[key]);
|
||||
}
|
||||
return snakeObject;
|
||||
const snakeObject: any = {};
|
||||
for (const key in object) {
|
||||
snakeObject[snakeCase(key)] = snakeCaseValue(object[key]);
|
||||
}
|
||||
return snakeObject;
|
||||
}
|
||||
|
||||
function snakeCaseValue(value: any): any {
|
||||
if (typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(snakeCaseValue);
|
||||
} else {
|
||||
return snakeCaseTree(value);
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(snakeCaseValue);
|
||||
} else {
|
||||
return value;
|
||||
return snakeCaseTree(value);
|
||||
}
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user