UNPKG

scriptable-testlab

Version:

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

193 lines 4.68 kB
import { AbsWidgetDate } from "scriptable-abstract"; import { MockColor } from "../color"; import { MockFont } from "../font"; const DEFAULT_STATE = { date: /* @__PURE__ */ new Date(), textColor: new MockColor("#000000"), font: MockFont.systemFont(16), textOpacity: 1, lineLimit: 0, minimumScaleFactor: 1, shadowColor: new MockColor("#000000"), shadowRadius: 0, shadowOffset: { x: 0, y: 0 }, url: "", dateFormat: "date", textAlignment: "left", appliedStyles: [] }; class MockWidgetDate extends AbsWidgetDate { /** * Creates a new widget date element with the specified date. */ constructor(date) { super({ ...DEFAULT_STATE, date }); } // Property accessors get date() { return new Date(this.state.date); } set date(value) { this.setState({ date: new Date(value) }); } get textColor() { return this.state.textColor; } set textColor(value) { this.setState({ textColor: value }); } get font() { return this.state.font; } set font(value) { this.setState({ font: value }); } get textOpacity() { return this.state.textOpacity; } set textOpacity(value) { const numValue = Number(value); const clampedValue = isNaN(numValue) ? 0 : Math.max(0, Math.min(1, numValue)); this.setState({ textOpacity: clampedValue }); } get lineLimit() { return this.state.lineLimit; } set lineLimit(value) { const numValue = Number(value); const validValue = isNaN(numValue) || numValue < 0 ? 0 : numValue; this.setState({ lineLimit: validValue }); } get minimumScaleFactor() { return this.state.minimumScaleFactor; } set minimumScaleFactor(value) { const numValue = Number(value); const clampedValue = isNaN(numValue) ? 0 : Math.max(0, Math.min(1, numValue)); this.setState({ minimumScaleFactor: clampedValue }); } get shadowColor() { return this.state.shadowColor; } set shadowColor(value) { this.setState({ shadowColor: value }); } get shadowRadius() { return this.state.shadowRadius; } set shadowRadius(value) { const numValue = Number(value); const validValue = isNaN(numValue) || numValue < 0 ? 0 : numValue; this.setState({ shadowRadius: validValue }); } get shadowOffset() { return { ...this.state.shadowOffset }; } set shadowOffset(value) { this.setState({ shadowOffset: { ...value } }); } get url() { return this.state.url; } set url(value) { this.setState({ url: value }); } // Style methods /** * Applies the time style to the date element. */ applyTimeStyle() { this.setState({ font: MockFont.systemFont(16), dateFormat: "time", appliedStyles: [...this.state.appliedStyles, "time"] }); } /** * Applies the date style to the date element. */ applyDateStyle() { this.setState({ font: MockFont.systemFont(16), dateFormat: "date", appliedStyles: [...this.state.appliedStyles, "date"] }); } /** * Applies the relative style to the date element. */ applyRelativeStyle() { this.setState({ font: MockFont.systemFont(16), dateFormat: "relative", appliedStyles: [...this.state.appliedStyles, "relative"] }); } /** * Applies the offset style to the date element. */ applyOffsetStyle() { this.setState({ font: MockFont.systemFont(16), dateFormat: "offset", appliedStyles: [...this.state.appliedStyles, "offset"] }); } /** * Applies the timer style to the date element. */ applyTimerStyle() { this.setState({ font: MockFont.systemFont(16), dateFormat: "timer", appliedStyles: [...this.state.appliedStyles, "timer"] }); } // Alignment methods /** * Centers the text in its container. */ centerAlignText() { this.setState({ textAlignment: "center" }); } /** * Aligns the text to the left of its container. */ leftAlignText() { this.setState({ textAlignment: "left" }); } /** * Aligns the text to the right of its container. */ rightAlignText() { this.setState({ textAlignment: "right" }); } /** * Gets the current date format. * @returns The current date format. */ getDateFormat() { return this.state.dateFormat; } /** * Gets the current text alignment. * @returns The current text alignment. */ getTextAlignment() { return this.state.textAlignment; } /** * Gets the list of applied styles. * @returns A copy of the applied styles array. */ getAppliedStyles() { return this.state.appliedStyles; } } export { MockWidgetDate }; //# sourceMappingURL=date.js.map