zeplin-extension-style-kit
Version:
Models and utilities to generate CSS-like style code in Zeplin extensions.
28 lines (21 loc) • 698 B
text/typescript
import { StyleValue } from "../common.js";
import { Scalar } from "./scalar.js";
type AngleUnit = "deg" | "rad" | "grad" | "turn";
export class Angle implements StyleValue {
value: number;
unit: AngleUnit;
constructor(value: number, unit: AngleUnit = "deg") {
this.value = value;
this.unit = unit;
}
valueOf(): string {
const { value, unit } = this;
return `angle::v:${value}:u:${unit}`;
}
equals(other: Angle): boolean {
return this.value === other.value && this.unit === other.unit;
}
toStyleValue(): string {
return this.value === 0 ? "0" : `${new Scalar(this.value).toStyleValue()}${this.unit}`;
}
}