scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
216 lines • 5.82 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 date_exports = {};
__export(date_exports, {
MockWidgetDate: () => MockWidgetDate
});
module.exports = __toCommonJS(date_exports);
var import_scriptable_abstract = require("scriptable-abstract");
var import_color = require("../color");
var import_font = require("../font");
const DEFAULT_STATE = {
date: /* @__PURE__ */ new Date(),
textColor: new import_color.MockColor("#000000"),
font: import_font.MockFont.systemFont(16),
textOpacity: 1,
lineLimit: 0,
minimumScaleFactor: 1,
shadowColor: new import_color.MockColor("#000000"),
shadowRadius: 0,
shadowOffset: { x: 0, y: 0 },
url: "",
dateFormat: "date",
textAlignment: "left",
appliedStyles: []
};
class MockWidgetDate extends import_scriptable_abstract.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: import_font.MockFont.systemFont(16),
dateFormat: "time",
appliedStyles: [...this.state.appliedStyles, "time"]
});
}
/**
* Applies the date style to the date element.
*/
applyDateStyle() {
this.setState({
font: import_font.MockFont.systemFont(16),
dateFormat: "date",
appliedStyles: [...this.state.appliedStyles, "date"]
});
}
/**
* Applies the relative style to the date element.
*/
applyRelativeStyle() {
this.setState({
font: import_font.MockFont.systemFont(16),
dateFormat: "relative",
appliedStyles: [...this.state.appliedStyles, "relative"]
});
}
/**
* Applies the offset style to the date element.
*/
applyOffsetStyle() {
this.setState({
font: import_font.MockFont.systemFont(16),
dateFormat: "offset",
appliedStyles: [...this.state.appliedStyles, "offset"]
});
}
/**
* Applies the timer style to the date element.
*/
applyTimerStyle() {
this.setState({
font: import_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;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockWidgetDate
});
//# sourceMappingURL=date.js.map