UNPKG

scriptable-testlab

Version:

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

177 lines 4.2 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 photos_exports = {}; __export(photos_exports, { MockPhotos: () => MockPhotos }); module.exports = __toCommonJS(photos_exports); var import_scriptable_abstract = require("scriptable-abstract"); var import_image = require("../media/image"); class MockPhotos extends import_scriptable_abstract.AbsPhotos { constructor() { super({ library: { photos: [], screenshots: [] } }); } /** * @inheritdoc */ async fromLibrary() { if (this.state.library.photos.length === 0) { throw new Error("No photos in library"); } return this.state.library.photos[0]; } /** * @inheritdoc */ async fromCamera() { const image = new import_image.MockImage(); this.setState((state) => ({ library: { ...state.library, photos: [image, ...state.library.photos] } })); return image; } /** * @inheritdoc */ async latestPhoto() { if (this.state.library.photos.length === 0) { throw new Error("No photos in library"); } return this.state.library.photos[0]; } /** * @inheritdoc */ async latestPhotos(count) { return this.state.library.photos.slice(0, count); } /** * @inheritdoc */ async latestScreenshot() { if (this.state.library.screenshots.length === 0) { throw new Error("No screenshots in library"); } return this.state.library.screenshots[0]; } /** * @inheritdoc */ async latestScreenshots(count) { return this.state.library.screenshots.slice(0, count); } /** * @inheritdoc */ removeLatestPhoto() { if (this.state.library.photos.length === 0) { throw new Error("No photos in library"); } this.setState((state) => ({ library: { ...state.library, photos: state.library.photos.slice(1) } })); } /** * @inheritdoc */ removeLatestPhotos(count) { this.setState((state) => ({ library: { ...state.library, photos: state.library.photos.slice(count) } })); } /** * @inheritdoc */ removeLatestScreenshot() { if (this.state.library.screenshots.length === 0) { throw new Error("No screenshots in library"); } this.setState((state) => ({ library: { ...state.library, screenshots: state.library.screenshots.slice(1) } })); } /** * @inheritdoc */ removeLatestScreenshots(count) { this.setState((state) => ({ library: { ...state.library, screenshots: state.library.screenshots.slice(count) } })); } /** * @inheritdoc */ save(image) { this.setState((state) => ({ library: { ...state.library, photos: [image, ...state.library.photos] } })); } /** * @additional * Add a screenshot to the library * @param image The screenshot image to add */ addScreenshot(image) { this.setState((state) => ({ library: { ...state.library, screenshots: [image, ...state.library.screenshots] } })); } /** * @additional * Clear all photos and screenshots from the library */ clear() { this.setState({ library: { photos: [], screenshots: [] } }); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockPhotos }); //# sourceMappingURL=photos.js.map