scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
157 lines • 4.24 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var color_exports = {};
__export(color_exports, {
MockColor: () => MockColor
});
module.exports = __toCommonJS(color_exports);
var import_scriptable_abstract = require("scriptable-abstract");
const DEFAULT_STATE = {
hex: "#000000",
red: 0,
green: 0,
blue: 0,
alpha: 1
};
class MockColor extends import_scriptable_abstract.AbsColor {
constructor(hex = "#000000", alpha = 1) {
super(DEFAULT_STATE);
this.hex = hex;
if (alpha !== void 0) {
this.alpha = alpha;
}
}
get hex() {
const r = Math.round(this.state.red).toString(16).padStart(2, "0");
const g = Math.round(this.state.green).toString(16).padStart(2, "0");
const b = Math.round(this.state.blue).toString(16).padStart(2, "0");
return `#${r}${g}${b}`.toUpperCase();
}
set hex(value) {
const normalizedHex = value.startsWith("#") ? value : `#${value}`;
if (!/^#[0-9A-Fa-f]{6}$/i.test(normalizedHex)) {
throw new Error("Invalid hex color format. Expected format: #RRGGBB");
}
const r = parseInt(normalizedHex.slice(1, 3), 16);
const g = parseInt(normalizedHex.slice(3, 5), 16);
const b = parseInt(normalizedHex.slice(5, 7), 16);
this.setState({
hex: normalizedHex.toUpperCase(),
red: r,
green: g,
blue: b,
alpha: this.alpha
});
}
get red() {
return this.state.red;
}
set red(value) {
if (value < 0 || value > 255) {
throw new Error("Red value must be between 0 and 255");
}
const hex = this.hex;
this.setState({ red: value, hex });
}
get green() {
return this.state.green;
}
set green(value) {
if (value < 0 || value > 255) {
throw new Error("Green value must be between 0 and 255");
}
const hex = this.hex;
this.setState({ green: value, hex });
}
get blue() {
return this.state.blue;
}
set blue(value) {
if (value < 0 || value > 255) {
throw new Error("Blue value must be between 0 and 255");
}
const hex = this.hex;
this.setState({ blue: value, hex });
}
get alpha() {
return this.state.alpha;
}
set alpha(value) {
if (value < 0 || value > 1) {
throw new Error("Alpha value must be between 0 and 1");
}
const hex = this.hex;
this.setState({ alpha: value, hex });
}
// Static factory methods
static black() {
return new MockColor("#000000");
}
static darkGray() {
return new MockColor("#555555");
}
static lightGray() {
return new MockColor("#AAAAAA");
}
static white() {
return new MockColor("#FFFFFF");
}
static gray() {
return new MockColor("#808080");
}
static red() {
return new MockColor("#FF0000");
}
static green() {
return new MockColor("#00FF00");
}
static blue() {
return new MockColor("#0000FF");
}
static cyan() {
return new MockColor("#00FFFF");
}
static yellow() {
return new MockColor("#FFFF00");
}
static magenta() {
return new MockColor("#FF00FF");
}
static orange() {
return new MockColor("#FFA500");
}
static purple() {
return new MockColor("#800080");
}
static brown() {
return new MockColor("#A52A2A");
}
static clear() {
const color = new MockColor("#000000");
color.alpha = 0;
return color;
}
static dynamic(dark, _light) {
return dark;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockColor
});
//# sourceMappingURL=color.js.map