scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
218 lines • 6.59 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var device_exports = {};
__export(device_exports, {
MockDevice: () => MockDevice
});
module.exports = __toCommonJS(device_exports);
var import_assert = __toESM(require("assert"));
var import_scriptable_abstract = require("scriptable-abstract");
function isValidScreenDimension(value) {
return typeof value === "number" && value > 0;
}
function isValidPercentage(value) {
return typeof value === "number" && value >= 0 && value <= 1;
}
function isValidDeviceModel(value) {
return typeof value === "string" && ["iPhone", "iPad"].includes(value);
}
const DEFAULT_STATE = {
name: "iPhone Mock",
systemName: "iOS",
systemVersion: "16.0",
model: "iPhone",
screenSize: {
width: 390,
height: 844
},
screenResolution: {
width: 1170,
height: 2532
},
screenScale: 3,
screenBrightness: 1,
orientation: {
isInPortrait: true,
isInPortraitUpsideDown: false,
isInLandscapeLeft: false,
isInLandscapeRight: false,
isFaceUp: false,
isFaceDown: false
},
battery: {
level: 1,
isDischarging: false,
isCharging: false,
isFullyCharged: true
},
locale: {
preferredLanguages: ["en"],
locale: "en_US",
language: "en"
},
appearance: {
isUsingDarkAppearance: false
},
volume: 0.5
};
class MockDevice extends import_scriptable_abstract.AbsDevice {
static get instance() {
return super.instance;
}
constructor() {
super(DEFAULT_STATE);
}
// Device information methods
name() {
return this.state.name;
}
systemName() {
return this.state.systemName;
}
systemVersion() {
return this.state.systemVersion;
}
model() {
return this.state.model;
}
isPhone() {
return this.state.model.toLowerCase().includes("phone");
}
isPad() {
return this.state.model.toLowerCase().includes("pad");
}
// Screen methods
screenSize() {
return { ...this.state.screenSize };
}
screenResolution() {
return { ...this.state.screenResolution };
}
screenScale() {
return this.state.screenScale;
}
screenBrightness() {
return this.state.screenBrightness;
}
setScreenBrightness(value) {
(0, import_assert.default)(isValidPercentage(value), "Brightness must be between 0 and 1");
this.setState({ screenBrightness: value });
}
// Orientation methods
isInPortrait() {
return this.state.orientation.isInPortrait;
}
isInPortraitUpsideDown() {
return this.state.orientation.isInPortraitUpsideDown;
}
isInLandscapeLeft() {
return this.state.orientation.isInLandscapeLeft;
}
isInLandscapeRight() {
return this.state.orientation.isInLandscapeRight;
}
isFaceUp() {
return this.state.orientation.isFaceUp;
}
isFaceDown() {
return this.state.orientation.isFaceDown;
}
// Battery methods
batteryLevel() {
return this.state.battery.level;
}
isDischarging() {
return this.state.battery.isDischarging;
}
isCharging() {
return this.state.battery.isCharging;
}
isFullyCharged() {
return this.state.battery.isFullyCharged;
}
// Locale methods
preferredLanguages() {
return [...this.state.locale.preferredLanguages];
}
locale() {
return this.state.locale.locale;
}
language() {
return this.state.locale.language;
}
// Appearance methods
isUsingDarkAppearance() {
return this.state.appearance.isUsingDarkAppearance;
}
// Volume methods
volume() {
return this.state.volume;
}
setVolume(value) {
(0, import_assert.default)(isValidPercentage(value), "Volume must be between 0 and 1");
this.setState({ volume: value });
}
updateState(state) {
if (state.screenBrightness !== void 0) {
(0, import_assert.default)(isValidPercentage(state.screenBrightness), "Brightness must be between 0 and 1");
}
if (state.screenScale !== void 0) {
(0, import_assert.default)(isValidScreenDimension(state.screenScale), "Screen scale must be greater than 0");
}
if (state.screenResolution) {
const { width, height } = state.screenResolution;
if (width !== void 0) {
(0, import_assert.default)(isValidScreenDimension(width), "Screen resolution width must be greater than 0");
}
if (height !== void 0) {
(0, import_assert.default)(isValidScreenDimension(height), "Screen resolution height must be greater than 0");
}
}
if (state.screenSize) {
const { width, height } = state.screenSize;
if (width !== void 0) {
(0, import_assert.default)(isValidScreenDimension(width), "Screen size width must be greater than 0");
}
if (height !== void 0) {
(0, import_assert.default)(isValidScreenDimension(height), "Screen size height must be greater than 0");
}
}
if (state.model !== void 0) {
(0, import_assert.default)(isValidDeviceModel(state.model), "Model must be either iPhone or iPad");
}
if (state.volume !== void 0) {
(0, import_assert.default)(isValidPercentage(state.volume), "Volume must be between 0 and 1");
}
super.updateState(state);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockDevice
});
//# sourceMappingURL=device.js.map