UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

164 lines 4 kB
import { AbsWidgetStack } from "scriptable-abstract"; import { MockImage } from "../../media/image"; import { MockColor } from "../color"; import { MockLinearGradient } from "../gradient"; import { MockWidgetDate } from "./date"; import { MockWidgetImage } from "./image"; import { MockWidgetText } from "./text"; const DEFAULT_STATE = { alignment: "leading", spacing: 0, size: { width: 0, height: 0 }, backgroundColor: new MockColor("#000000"), backgroundImage: MockImage.fromFile(""), backgroundGradient: new MockLinearGradient(), cornerRadius: 0, borderWidth: 0, borderColor: new MockColor("#000000"), url: "", padding: { top: 0, leading: 0, bottom: 0, trailing: 0 }, items: [], layout: "vertical" }; class MockWidgetStack extends AbsWidgetStack { constructor() { super(DEFAULT_STATE); } /** * Creates a new widget stack instance. */ static create() { return new MockWidgetStack(); } // Property accessors get alignment() { return this.state.alignment; } set alignment(value) { this.setState({ alignment: value }); } get spacing() { return this.state.spacing; } set spacing(value) { this.setState({ spacing: value }); } get size() { return { ...this.state.size }; } set size(value) { this.setState({ size: { ...value } }); } get backgroundColor() { return this.state.backgroundColor; } set backgroundColor(value) { this.setState({ backgroundColor: value }); } get backgroundImage() { return this.state.backgroundImage; } set backgroundImage(value) { this.setState({ backgroundImage: value }); } get backgroundGradient() { return this.state.backgroundGradient; } set backgroundGradient(value) { this.setState({ backgroundGradient: value }); } get cornerRadius() { return this.state.cornerRadius; } set cornerRadius(value) { this.setState({ cornerRadius: value }); } get borderWidth() { return this.state.borderWidth; } set borderWidth(value) { this.setState({ borderWidth: value }); } get borderColor() { return this.state.borderColor; } set borderColor(value) { this.setState({ borderColor: value }); } get url() { return this.state.url; } set url(value) { this.setState({ url: value }); } // Widget element management methods addText(text) { const textItem = new MockWidgetText(text); this.setState((prevState) => ({ items: [...prevState.items, textItem] })); return textItem; } addDate(date) { const dateItem = new MockWidgetDate(date); this.setState((prevState) => ({ items: [...prevState.items, dateItem] })); return dateItem; } addImage(image) { const imageItem = MockWidgetImage.create(image); this.setState((prevState) => ({ items: [...prevState.items, imageItem] })); return imageItem; } addSpacer(length) { const spacer = { type: "spacer", length: length ?? 0 }; this.setState((prevState) => ({ items: [...prevState.items, spacer] })); return spacer; } addStack() { const stack = MockWidgetStack.create(); this.setState((prevState) => ({ items: [...prevState.items, stack] })); return stack; } // Layout methods setPadding(top, leading, bottom, trailing) { this.setState({ padding: { top, leading, bottom, trailing } }); } getPadding() { return { ...this.state.padding }; } getItems() { return [...this.state.items]; } useDefaultPadding() { this.setPadding(8, 8, 8, 8); } topAlignContent() { this.setState({ alignment: "leading" }); } centerAlignContent() { this.setState({ alignment: "center" }); } bottomAlignContent() { this.setState({ alignment: "trailing" }); } layoutHorizontally() { this.setState({ layout: "horizontal" }); } layoutVertically() { this.setState({ layout: "vertical" }); } } export { MockWidgetStack }; //# sourceMappingURL=stack.js.map