UNPKG

scriptable-testlab

Version:

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

197 lines 5.67 kB
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 image_exports = {}; __export(image_exports, { MockWidgetImage: () => MockWidgetImage }); module.exports = __toCommonJS(image_exports); var import_scriptable_abstract = require("scriptable-abstract"); var import_data = require("../../data"); var import_image = require("../../media/image"); var import_color = require("../color"); var import_size = require("../size"); const DEFAULT_STATE = { image: import_image.MockImage.fromData(import_data.MockData.fromString("")), resizable: true, imageSize: new import_size.MockSize(100, 100), imageOpacity: 1, cornerRadius: 0, borderWidth: 0, borderColor: new import_color.MockColor("#000000"), containerRelativeShape: false, tintColor: new import_color.MockColor("#000000"), url: "", contentMode: "fitting", alignment: "center" }; class MockWidgetImage extends import_scriptable_abstract.AbsWidgetImage { /** * Creates a new widget image element with the specified image. */ constructor(image) { super({ ...DEFAULT_STATE, ...image ? { image } : {} }); } /** * Creates a new widget image instance. * @param image - The image to display in the widget. * @returns A new widget image instance. */ static create(image) { return new MockWidgetImage(image); } // Property accessors get image() { return this.state.image; } set image(value) { this.setState({ image: value }); } get resizable() { return this.state.resizable; } set resizable(value) { this.setState({ resizable: value }); } get imageSize() { return this.state.imageSize; } set imageSize(value) { this.setState({ imageSize: value }); } /** * Gets or sets the opacity of the image. * Value should be between 0 (fully transparent) and 1 (fully opaque). */ get imageOpacity() { return this.state.imageOpacity; } set imageOpacity(value) { const numValue = Number(value); const clampedValue = isNaN(numValue) ? 0 : Math.max(0, Math.min(1, numValue)); this.setState({ imageOpacity: clampedValue }); } /** * Gets or sets the corner radius of the image. * Negative values will be converted to 0. */ get cornerRadius() { return this.state.cornerRadius; } set cornerRadius(value) { const numValue = Number(value); const validValue = isNaN(numValue) || numValue < 0 ? 0 : numValue; this.setState({ cornerRadius: validValue }); } /** * Gets or sets the border width of the image. * Negative values will be converted to 0. */ get borderWidth() { return this.state.borderWidth; } set borderWidth(value) { const numValue = isNaN(Number(value)) ? 0 : Number(value); this.setState({ borderWidth: Math.max(0, numValue) }); } get borderColor() { return this.state.borderColor; } set borderColor(value) { this.setState({ borderColor: value }); } get containerRelativeShape() { return this.state.containerRelativeShape; } set containerRelativeShape(value) { this.setState({ containerRelativeShape: value }); } get tintColor() { return this.state.tintColor; } set tintColor(value) { this.setState({ tintColor: value }); } get url() { return this.state.url; } set url(value) { this.setState({ url: value }); } /** * Aligns the image to the left of its container. * @returns this for method chaining */ leftAlignImage() { this.setState({ alignment: "left" }); return this; } /** * Centers the image in its container. * @returns this for method chaining */ centerAlignImage() { this.setState({ alignment: "center" }); return this; } /** * Aligns the image to the right of its container. * @returns this for method chaining */ rightAlignImage() { this.setState({ alignment: "right" }); return this; } /** * Sets the content mode to fitting, which scales the image to fit within its container while maintaining aspect ratio. * @returns this for method chaining */ applyFittingContentMode() { this.setState({ contentMode: "fitting" }); return this; } /** * Sets the content mode to filling, which scales the image to fill its container while maintaining aspect ratio. * @returns this for method chaining */ applyFillingContentMode() { this.setState({ contentMode: "filling" }); return this; } /** * Gets the current alignment of the image. * @returns The current alignment ('left', 'center', or 'right'). */ getAlignment() { return this.state.alignment; } /** * Gets the current content mode of the image. * @returns The current content mode ('fitting' or 'filling'). */ getContentMode() { return this.state.contentMode; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockWidgetImage }); //# sourceMappingURL=image.js.map