@swipt/api 0.1.0-nightly.42 → 0.1.0-nightly.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,35 @@
1
1
  import type { CallOptions, Point, Rect } from "./index";
2
2
 
3
- export type AccessibilityTrait = "button" | "link" | "image" | "playsSound" | "keyboardKey" | "staticText" | "summaryElement"
4
- | "updatesFrequently" | "searchField" | "startsMediaSession" | "adjustable" | "allowsDirectInteraction"
5
- | "causesPageTurn" | "tabBar" | "header" | "webContent" | "textEntry";
3
+ export type AccessibilityTrait =
4
+ | "button"
5
+ | "link"
6
+ | "image"
7
+ | "playsSound"
8
+ | "keyboardKey"
9
+ | "staticText"
10
+ | "summaryElement"
11
+ | "updatesFrequently"
12
+ | "searchField"
13
+ | "startsMediaSession"
14
+ | "adjustable"
15
+ | "allowsDirectInteraction"
16
+ | "causesPageTurn"
17
+ | "tabBar"
18
+ | "header"
19
+ | "webContent"
20
+ | "textEntry";
6
21
 
7
- export type AccessibilityAction = "press" | "increment" | "decrement" | "escape" | "menu"
8
- | "scrollUp" | "scrollDown" | "scrollLeft" | "scrollRight" | "scrollToVisible";
22
+ export type AccessibilityAction =
23
+ | "press"
24
+ | "increment"
25
+ | "decrement"
26
+ | "escape"
27
+ | "menu"
28
+ | "scrollUp"
29
+ | "scrollDown"
30
+ | "scrollLeft"
31
+ | "scrollRight"
32
+ | "scrollToVisible";
9
33
 
10
34
  export interface AccessibilityElement {
11
35
  readonly role: string;
@@ -45,13 +69,38 @@ export interface AccessibilitySnapshot {
45
69
  findAll(selector: AccessibilitySelector): AccessibilityElement[];
46
70
  }
47
71
 
48
- type TextField = "role" | "class" | "label" | "value" | "identifier" | "placeholder" | "hint" | "url" | "app";
49
- type Flag = "disabled" | "focused" | "selected" | "expanded" | "secure" | "partial" | "offScreen" | "inert" | "remote";
72
+ type TextField =
73
+ | "role"
74
+ | "class"
75
+ | "label"
76
+ | "value"
77
+ | "identifier"
78
+ | "placeholder"
79
+ | "hint"
80
+ | "url"
81
+ | "app";
82
+ type Flag =
83
+ | "disabled"
84
+ | "focused"
85
+ | "selected"
86
+ | "expanded"
87
+ | "secure"
88
+ | "partial"
89
+ | "offScreen"
90
+ | "inert"
91
+ | "remote";
50
92
 
51
93
  export type AccessibilitySelector =
52
- | ({ traits?: AccessibilityTrait[]; within?: AccessibilitySelector | AccessibilityElement; parent?: AccessibilitySelector | AccessibilityElement; has?: AccessibilitySelector | AccessibilityElement; not?: AccessibilitySelector | AccessibilityElement; index?: number }
53
- & { [field in TextField]?: string | RegExp }
54
- & { [field in Flag]?: boolean })
94
+ | ({
95
+ traits?: AccessibilityTrait[];
96
+ within?: AccessibilitySelector | AccessibilityElement;
97
+ parent?: AccessibilitySelector | AccessibilityElement;
98
+ has?: AccessibilitySelector | AccessibilityElement;
99
+ not?: AccessibilitySelector | AccessibilityElement;
100
+ index?: number;
101
+ } & { [field in TextField]?: string | RegExp } & {
102
+ [field in Flag]?: boolean;
103
+ })
55
104
  | ((element: AccessibilityElement) => boolean);
56
105
 
57
106
  export interface SnapshotOptions extends CallOptions {
@@ -67,13 +116,29 @@ export interface FindOptions extends CallOptions {
67
116
  readonly pollTimeoutMs?: number;
68
117
  }
69
118
 
70
- export declare function snapshot(options?: SnapshotOptions): Promise<AccessibilitySnapshot>;
71
- export declare function find(selector: AccessibilitySelector | readonly AccessibilitySelector[], options?: FindOptions): Promise<AccessibilityElement | null>;
119
+ export declare function snapshot(
120
+ options?: SnapshotOptions,
121
+ ): Promise<AccessibilitySnapshot>;
122
+ export declare function find(
123
+ selector: AccessibilitySelector | readonly AccessibilitySelector[],
124
+ options?: FindOptions,
125
+ ): Promise<AccessibilityElement | null>;
72
126
  export interface ElementOptions extends CallOptions {
73
127
  /** Omitted or 0 tries once; a positive number or Infinity keeps checking until a tap would reach the element, and fails at the limit. */
74
128
  readonly timeoutMs?: number;
75
129
  }
76
130
 
77
- export declare function tap(element: AccessibilityElement, options?: ElementOptions): Promise<void>;
78
- export declare function setText(element: AccessibilityElement, text: string, options?: ElementOptions): Promise<void>;
79
- export declare function perform(element: AccessibilityElement, action: AccessibilityAction | (string & {}), options?: CallOptions): Promise<void>;
131
+ export declare function tap(
132
+ element: AccessibilityElement,
133
+ options?: ElementOptions,
134
+ ): Promise<void>;
135
+ export declare function setText(
136
+ element: AccessibilityElement,
137
+ text: string,
138
+ options?: ElementOptions,
139
+ ): Promise<void>;
140
+ export declare function perform(
141
+ element: AccessibilityElement,
142
+ action: AccessibilityAction | (string & {}),
143
+ options?: CallOptions,
144
+ ): Promise<void>;
package/accessibility.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/accessibility runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/accessibility runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const snapshot = outside;
package/device.d.ts CHANGED
@@ -37,13 +37,35 @@ export declare const locked: ObservableState<boolean>;
37
37
  export declare const displayState: ObservableState<DisplayState>;
38
38
  export declare function unlock(options?: CallOptions): Promise<void>;
39
39
 
40
- export declare function applicationEvents(options?: CallOptions): AsyncIterable<ApplicationStateEvent>;
41
- export declare function installedApplications(options?: CallOptions): Promise<InstalledApplication[]>;
42
- export declare function applicationIcon(bundleId: string, options?: CallOptions): Promise<FileHandle>;
43
- export declare function launchApplication(bundleId: string, options?: CallOptions & { url?: string; restart?: boolean }): Promise<void>;
40
+ export declare function applicationEvents(
41
+ options?: CallOptions,
42
+ ): AsyncIterable<ApplicationStateEvent>;
43
+ export declare function installedApplications(
44
+ options?: CallOptions,
45
+ ): Promise<InstalledApplication[]>;
46
+ /** Answers a PNG file in cacheDirectory. */
47
+ export declare function applicationIcon(
48
+ bundleId: string,
49
+ options?: CallOptions,
50
+ ): Promise<FileHandle>;
51
+ export declare function launchApplication(
52
+ bundleId: string,
53
+ options?: CallOptions & { url?: string; restart?: boolean },
54
+ ): Promise<void>;
44
55
 
45
- export declare function pasteboard(options?: CallOptions): Promise<string | null>;
46
- export declare function setPasteboard(text: string | null, options?: CallOptions): Promise<void>;
56
+ export declare function pasteboard(
57
+ options?: CallOptions,
58
+ ): Promise<string | null>;
59
+ export declare function setPasteboard(
60
+ text: string | null,
61
+ options?: CallOptions,
62
+ ): Promise<void>;
47
63
 
48
- export declare function simulateLocation(latitude: number, longitude: number, options?: CallOptions): Promise<void>;
49
- export declare function clearSimulatedLocation(options?: CallOptions): Promise<void>;
64
+ export declare function simulateLocation(
65
+ latitude: number,
66
+ longitude: number,
67
+ options?: CallOptions,
68
+ ): Promise<void>;
69
+ export declare function clearSimulatedLocation(
70
+ options?: CallOptions,
71
+ ): Promise<void>;
package/device.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/device runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/device runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const info = outside;
package/file-system.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  export declare const dataDirectory: DirectoryHandle;
2
+ /**
3
+ * Holds the files Swipt keeps for the Swiplet by default: screen recordings and their exports, and application icons.
4
+ * The system may delete its contents when storage runs low; clearing the Swiplet's data or deleting the Swiplet removes it.
5
+ */
6
+ export declare const cacheDirectory: DirectoryHandle;
2
7
  export declare const assets: DirectoryHandle;
3
8
 
4
9
  export interface FileStat {
@@ -23,7 +28,15 @@ export interface FileHandle {
23
28
  stat(): Promise<FileStat | null>;
24
29
  text(): Promise<string>;
25
30
  bytes(): Promise<Uint8Array>;
26
- write(data: string | Uint8Array | Blob | ReadableStream<Uint8Array>): Promise<void>;
31
+ stream(): ReadableStream<Uint8Array>;
32
+ write(
33
+ data:
34
+ | string
35
+ | ArrayBuffer
36
+ | ArrayBufferView
37
+ | Blob
38
+ | ReadableStream<ArrayBuffer | ArrayBufferView>,
39
+ ): Promise<void>;
27
40
  copy(to: FileHandle): Promise<void>;
28
41
  move(to: FileHandle): Promise<void>;
29
42
  delete(): Promise<void>;
package/file-system.mjs CHANGED
@@ -1,2 +1,3 @@
1
1
  export const dataDirectory = undefined;
2
+ export const cacheDirectory = undefined;
2
3
  export const assets = undefined;
package/image.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { CallOptions, Point, Quad, Rect } from "./index";
2
2
  import type { FileHandle } from "./file-system";
3
3
 
4
- export type Color = `#${string}` | readonly [red: number, green: number, blue: number];
4
+ export type Color =
5
+ `#${string}` | readonly [red: number, green: number, blue: number];
5
6
  export type ImageFormat = "png" | "jpeg" | "heic";
6
7
 
7
8
  export interface TemplateMatch {
@@ -58,7 +59,8 @@ export interface RecognizedTextCandidate {
58
59
  boundingBox(start: number, end: number): RecognizedTextBox | null;
59
60
  }
60
61
 
61
- export interface RecognizedTextLine extends RecognizedTextCandidate, RecognizedTextBox {
62
+ export interface RecognizedTextLine
63
+ extends RecognizedTextCandidate, RecognizedTextBox {
62
64
  readonly candidates: readonly RecognizedTextCandidate[];
63
65
  }
64
66
 
@@ -85,7 +87,10 @@ export interface RasterImage {
85
87
 
86
88
  crop(rect: Rect): RasterImage;
87
89
  resize(scale: number): RasterImage;
88
- resize(size: { readonly width?: number; readonly height?: number }): RasterImage;
90
+ resize(size: {
91
+ readonly width?: number;
92
+ readonly height?: number;
93
+ }): RasterImage;
89
94
  rotate(degrees: number): RasterImage;
90
95
  grayscale(): RasterImage;
91
96
  threshold(level?: number | "otsu"): RasterImage;
@@ -95,20 +100,59 @@ export interface RasterImage {
95
100
  dilate(radius?: number): RasterImage;
96
101
  erode(radius?: number): RasterImage;
97
102
 
98
- encode(format?: ImageFormat, options?: CallOptions & { readonly quality?: number }): Promise<Uint8Array>;
99
- save(file: FileHandle | string, options?: CallOptions & { readonly format?: ImageFormat; readonly quality?: number }): Promise<FileHandle>;
100
- pixel(point: Point, options?: CallOptions): Promise<[red: number, green: number, blue: number, alpha: number]>;
101
- stats(options?: CallOptions & { readonly region?: Rect }): Promise<ImageStats>;
102
-
103
- find(template: RasterImage, options?: TemplateMatchOptions): Promise<TemplateMatch | null>;
104
- findAll(template: RasterImage, options?: TemplateMatchOptions & { readonly limit?: number; readonly overlap?: number }): Promise<TemplateMatch[]>;
105
- matchColors(checks: readonly ColorCheck[], options?: CallOptions): Promise<boolean[]>;
106
- components(options?: CallOptions & { readonly minimumPixels?: number }): Promise<ConnectedComponent[]>;
107
- recognizeText(options?: TextRecognitionOptions): Promise<RecognizedTextLine[]>;
108
- diff(other: RasterImage, options?: CallOptions & { readonly threshold?: number }): Promise<ImageDifference>;
103
+ encode(
104
+ format?: ImageFormat,
105
+ options?: CallOptions & { readonly quality?: number },
106
+ ): Promise<Uint8Array>;
107
+ save(
108
+ file: FileHandle | string,
109
+ options?: CallOptions & {
110
+ readonly format?: ImageFormat;
111
+ readonly quality?: number;
112
+ },
113
+ ): Promise<FileHandle>;
114
+ pixel(
115
+ point: Point,
116
+ options?: CallOptions,
117
+ ): Promise<[red: number, green: number, blue: number, alpha: number]>;
118
+ stats(
119
+ options?: CallOptions & { readonly region?: Rect },
120
+ ): Promise<ImageStats>;
121
+
122
+ find(
123
+ template: RasterImage,
124
+ options?: TemplateMatchOptions,
125
+ ): Promise<TemplateMatch | null>;
126
+ findAll(
127
+ template: RasterImage,
128
+ options?: TemplateMatchOptions & {
129
+ readonly limit?: number;
130
+ readonly overlap?: number;
131
+ },
132
+ ): Promise<TemplateMatch[]>;
133
+ matchColors(
134
+ checks: readonly ColorCheck[],
135
+ options?: CallOptions,
136
+ ): Promise<boolean[]>;
137
+ components(
138
+ options?: CallOptions & { readonly minimumPixels?: number },
139
+ ): Promise<ConnectedComponent[]>;
140
+ recognizeText(
141
+ options?: TextRecognitionOptions,
142
+ ): Promise<RecognizedTextLine[]>;
143
+ diff(
144
+ other: RasterImage,
145
+ options?: CallOptions & { readonly threshold?: number },
146
+ ): Promise<ImageDifference>;
109
147
  distance(other: RasterImage, options?: CallOptions): Promise<number>;
110
- nearest(candidates: readonly RasterImage[], options?: CallOptions): Promise<{ readonly index: number; readonly distance: number }>;
148
+ nearest(
149
+ candidates: readonly RasterImage[],
150
+ options?: CallOptions,
151
+ ): Promise<{ readonly index: number; readonly distance: number }>;
111
152
  detectBarcodes(options?: CallOptions): Promise<DetectedBarcode[]>;
112
153
  }
113
154
 
114
- export declare function decode(data: Uint8Array | FileHandle | string, options?: CallOptions & { readonly scale?: number }): Promise<RasterImage>;
155
+ export declare function decode(
156
+ data: Uint8Array | FileHandle | string,
157
+ options?: CallOptions & { readonly scale?: number },
158
+ ): Promise<RasterImage>;
package/image.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/image runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/image runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const decode = outside;
package/index.d.ts CHANGED
@@ -9,18 +9,30 @@ export interface ObservableState<T> {
9
9
 
10
10
  export type Point = [x: number, y: number];
11
11
  export type Rect = [x: number, y: number, width: number, height: number];
12
- export type Quad = [topLeft: Point, topRight: Point, bottomRight: Point, bottomLeft: Point];
12
+ export type Quad = [
13
+ topLeft: Point,
14
+ topRight: Point,
15
+ bottomRight: Point,
16
+ bottomLeft: Point,
17
+ ];
13
18
 
14
- export type ErrorName = "AbortError" | "TimeoutError" | "NotFoundError" | "UnavailableError";
19
+ export type ErrorName =
20
+ "AbortError" | "TimeoutError" | "NotFoundError" | "UnavailableError";
15
21
 
16
- export type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
22
+ export type JSONValue =
23
+ string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
17
24
 
18
- export type Jsonify<T> = T extends string | number | boolean | null ? T
19
- : T extends undefined | symbol | ((...args: any[]) => unknown) ? never
20
- : T extends { toJSON(): infer J } ? Jsonify<J>
21
- : T extends readonly (infer U)[] ? Jsonify<U>[]
22
- : T extends object ? { [K in keyof T]: Jsonify<Exclude<T[K], undefined>> }
23
- : never;
25
+ export type Jsonify<T> = T extends string | number | boolean | null
26
+ ? T
27
+ : T extends undefined | symbol | ((...args: any[]) => unknown)
28
+ ? never
29
+ : T extends { toJSON(): infer J }
30
+ ? Jsonify<J>
31
+ : T extends readonly (infer U)[]
32
+ ? Jsonify<U>[]
33
+ : T extends object
34
+ ? { [K in keyof T]: Jsonify<Exclude<T[K], undefined>> }
35
+ : never;
24
36
 
25
37
  declare global {
26
38
  function sleep(ms: number, options?: CallOptions): Promise<void>;
package/input.d.ts CHANGED
@@ -4,18 +4,51 @@ export interface TapOptions extends CallOptions {
4
4
  readonly count?: number;
5
5
  }
6
6
 
7
- export type KeyboardKey = "return" | "backspace" | "forwardDelete" | "tab" | "escape" | "space" | "left" | "right" | "up" | "down"
8
- | "home" | "end" | "pageUp" | "pageDown" | `f${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}`;
7
+ export type KeyboardKey =
8
+ | "return"
9
+ | "backspace"
10
+ | "forwardDelete"
11
+ | "tab"
12
+ | "escape"
13
+ | "space"
14
+ | "left"
15
+ | "right"
16
+ | "up"
17
+ | "down"
18
+ | "home"
19
+ | "end"
20
+ | "pageUp"
21
+ | "pageDown"
22
+ | `f${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}`;
9
23
  export type KeyboardModifier = "cmd" | "shift" | "ctrl" | "alt";
10
- export type KeyCombination = KeyboardKey | `${KeyboardModifier}+${KeyboardKey}` | (string & {});
24
+ export type KeyCombination =
25
+ KeyboardKey | `${KeyboardModifier}+${KeyboardKey}` | (string & {});
11
26
  export type TouchSample = [x: number, y: number, ms: number];
12
27
 
13
28
  export declare function tap(point: Point, options?: TapOptions): Promise<void>;
14
- export declare function swipe(from: Point, to: Point, options?: CallOptions & { durationMs?: number }): Promise<void>;
15
- export declare function drag(from: Point, to: Point, options?: CallOptions & { durationMs?: number; pressMs?: number }): Promise<void>;
16
- export declare function pinch(center: Point, scale: number, options?: CallOptions & { durationMs?: number }): Promise<void>;
17
- export declare function touch(fingers: readonly (readonly TouchSample[])[], options?: CallOptions): Promise<void>;
18
- export declare function pressKey(combination: KeyCombination, options?: CallOptions): Promise<void>;
29
+ export declare function swipe(
30
+ from: Point,
31
+ to: Point,
32
+ options?: CallOptions & { durationMs?: number },
33
+ ): Promise<void>;
34
+ export declare function drag(
35
+ from: Point,
36
+ to: Point,
37
+ options?: CallOptions & { durationMs?: number; pressMs?: number },
38
+ ): Promise<void>;
39
+ export declare function pinch(
40
+ center: Point,
41
+ scale: number,
42
+ options?: CallOptions & { durationMs?: number },
43
+ ): Promise<void>;
44
+ export declare function touch(
45
+ fingers: readonly (readonly TouchSample[])[],
46
+ options?: CallOptions,
47
+ ): Promise<void>;
48
+ export declare function pressKey(
49
+ combination: KeyCombination,
50
+ options?: CallOptions,
51
+ ): Promise<void>;
19
52
  export declare function pressHome(options?: CallOptions): Promise<void>;
20
53
  export declare function openAppSwitcher(options?: CallOptions): Promise<void>;
21
54
  export declare function pressPower(options?: CallOptions): Promise<void>;
package/input.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/input runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/input runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const tap = outside;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swipt/api",
3
- "version": "0.1.0-nightly.42",
3
+ "version": "0.1.0-nightly.44",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "repository": {
6
6
  "type": "git",
package/repl.d.ts CHANGED
@@ -2,8 +2,10 @@ declare global {
2
2
  const accessibility: typeof import("@swipt/api/accessibility");
3
3
  const input: typeof import("@swipt/api/input");
4
4
  const device: typeof import("@swipt/api/device");
5
- const screen: typeof import("@swipt/api/screen");
5
+ var screen: Screen;
6
+ interface Screen extends Readonly<typeof import("@swipt/api/screen")> {}
6
7
  const image: typeof import("@swipt/api/image");
8
+ const dataDirectory: import("@swipt/api/file-system").DirectoryHandle;
7
9
  const dialog: import("@swipt/api/swiplet").IntentDialog;
8
10
  const args: readonly string[];
9
11
 
package/screen.d.ts CHANGED
@@ -18,11 +18,37 @@ export interface ScreenChange {
18
18
  }
19
19
 
20
20
  export type TimelineEvent =
21
- | { readonly time: number; readonly type: "operation"; readonly name: string; readonly arguments?: readonly unknown[]; readonly durationMs?: number; readonly error?: string; readonly message?: string; readonly swiplet?: string }
22
- | { readonly time: number; readonly type: "action"; readonly swiplet: string; readonly action: string; readonly caller: "app" | "shortcuts" | "api" }
21
+ | {
22
+ readonly time: number;
23
+ readonly type: "operation";
24
+ readonly name: string;
25
+ readonly arguments?: readonly unknown[];
26
+ readonly durationMs?: number;
27
+ readonly error?: string;
28
+ readonly message?: string;
29
+ readonly swiplet?: string;
30
+ }
31
+ | {
32
+ readonly time: number;
33
+ readonly type: "action";
34
+ readonly swiplet: string;
35
+ readonly action: string;
36
+ readonly caller: "app" | "shortcuts" | "api";
37
+ }
23
38
  | { readonly time: number; readonly type: "foreground"; readonly app: string }
24
- | { readonly time: number; readonly type: "log"; readonly swiplet: string; readonly level: "error" | "warn" | "info" | "debug"; readonly message: string }
25
- | { readonly time: number; readonly type: "feed"; readonly frames: number; readonly decodedMs: number };
39
+ | {
40
+ readonly time: number;
41
+ readonly type: "log";
42
+ readonly swiplet: string;
43
+ readonly level: "error" | "warn" | "info" | "debug";
44
+ readonly message: string;
45
+ }
46
+ | {
47
+ readonly time: number;
48
+ readonly type: "feed";
49
+ readonly frames: number;
50
+ readonly decodedMs: number;
51
+ };
26
52
 
27
53
  export interface ScreenRecording {
28
54
  readonly file: FileHandle;
@@ -35,19 +61,46 @@ export interface ScreenRecording {
35
61
  readonly events: readonly TimelineEvent[];
36
62
 
37
63
  frame(time: number): RasterImage;
38
- frames(times: readonly number[] | { readonly everyMs: number; readonly from?: number; readonly to?: number }): RasterImage[];
39
- grid(options?: CallOptions & { readonly times?: readonly number[]; readonly columns?: number; readonly width?: number }): Promise<RasterImage>;
40
- diff(from: number, to: number, options?: CallOptions & { readonly threshold?: number }): Promise<ImageDifference>;
41
- find(target: ScreenTarget | readonly ScreenTarget[], options?: Omit<ScreenFindOptions, "timeoutMs"> & { readonly from?: number; readonly to?: number }): Promise<(ScreenMatch & { readonly time: number }) | null>;
42
- export(options?: CallOptions & {
43
- readonly file?: FileHandle | string;
44
- readonly from?: number;
45
- readonly to?: number;
46
- readonly region?: Rect;
47
- readonly scale?: number;
48
- readonly format?: "mov" | "mp4" | "gif";
49
- readonly frameRate?: number;
50
- }): Promise<FileHandle>;
64
+ frames(
65
+ times:
66
+ | readonly number[]
67
+ | {
68
+ readonly everyMs: number;
69
+ readonly from?: number;
70
+ readonly to?: number;
71
+ },
72
+ ): RasterImage[];
73
+ grid(
74
+ options?: CallOptions & {
75
+ readonly times?: readonly number[];
76
+ readonly columns?: number;
77
+ readonly width?: number;
78
+ },
79
+ ): Promise<RasterImage>;
80
+ diff(
81
+ from: number,
82
+ to: number,
83
+ options?: CallOptions & { readonly threshold?: number },
84
+ ): Promise<ImageDifference>;
85
+ find(
86
+ target: ScreenTarget | readonly ScreenTarget[],
87
+ options?: Omit<ScreenFindOptions, "timeoutMs"> & {
88
+ readonly from?: number;
89
+ readonly to?: number;
90
+ },
91
+ ): Promise<(ScreenMatch & { readonly time: number }) | null>;
92
+ export(
93
+ options?: CallOptions & {
94
+ /** Omitted, the export goes to a new file in cacheDirectory. */
95
+ readonly file?: FileHandle | string;
96
+ readonly from?: number;
97
+ readonly to?: number;
98
+ readonly region?: Rect;
99
+ readonly scale?: number;
100
+ readonly format?: "mov" | "mp4" | "gif";
101
+ readonly frameRate?: number;
102
+ },
103
+ ): Promise<FileHandle>;
51
104
  }
52
105
 
53
106
  export interface RecordingSession {
@@ -80,10 +133,28 @@ export interface ScreenMatch {
80
133
  }
81
134
 
82
135
  export declare function screenshot(options?: CallOptions): Promise<RasterImage>;
83
- export declare function find(target: ScreenTarget | readonly ScreenTarget[], options?: ScreenFindOptions): Promise<ScreenMatch | null>;
136
+ export declare function find(
137
+ target: ScreenTarget | readonly ScreenTarget[],
138
+ options?: ScreenFindOptions,
139
+ ): Promise<ScreenMatch | null>;
84
140
  export declare const frames: ObservableState<RasterImage>;
85
- export declare function waitFor(predicate: (frame: RasterImage) => boolean | Promise<boolean>, options?: CallOptions & { readonly timeoutMs?: number }): Promise<RasterImage>;
86
- export declare function waitForChange(options?: WaitOptions & { readonly from?: RasterImage }): Promise<RasterImage>;
87
- export declare function waitForStable(options?: WaitOptions & { readonly durationMs?: number }): Promise<RasterImage>;
88
- export declare function record(options?: CallOptions & { readonly file?: FileHandle | string }): Promise<RecordingSession>;
89
- export declare function openRecording(file: FileHandle | string, options?: CallOptions): Promise<ScreenRecording>;
141
+ export declare function waitFor(
142
+ predicate: (frame: RasterImage) => boolean | Promise<boolean>,
143
+ options?: CallOptions & { readonly timeoutMs?: number },
144
+ ): Promise<RasterImage>;
145
+ export declare function waitForChange(
146
+ options?: WaitOptions & { readonly from?: RasterImage },
147
+ ): Promise<RasterImage>;
148
+ export declare function waitForStable(
149
+ options?: WaitOptions & { readonly durationMs?: number },
150
+ ): Promise<RasterImage>;
151
+ export declare function record(
152
+ options?: CallOptions & {
153
+ /** Omitted, the recording goes to a new file in cacheDirectory. */
154
+ readonly file?: FileHandle | string;
155
+ },
156
+ ): Promise<RecordingSession>;
157
+ export declare function openRecording(
158
+ file: FileHandle | string,
159
+ options?: CallOptions,
160
+ ): Promise<ScreenRecording>;
package/screen.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/screen runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/screen runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const screenshot = outside;
package/swiplet.d.ts CHANGED
@@ -1,12 +1,46 @@
1
- import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
1
+ import type {
2
+ StandardJSONSchemaV1,
3
+ StandardSchemaV1,
4
+ } from "@standard-schema/spec";
2
5
 
3
6
  import type { CallOptions, Jsonify } from "./index";
4
7
 
5
8
  export type IntentChoiceStyle = "default" | "destructive" | "cancel";
6
9
 
7
- export type ConfirmationActionName = "add" | "addData" | "book" | "buy" | "call" | "checkIn" | "continue" | "create" | "do" | "download"
8
- | "filter" | "find" | "get" | "go" | "log" | "open" | "order" | "pay" | "play" | "playSound" | "post" | "request" | "run"
9
- | "search" | "send" | "set" | "share" | "start" | "startNavigation" | "toggle" | "turnOff" | "turnOn" | "view";
10
+ export type ConfirmationActionName =
11
+ | "add"
12
+ | "addData"
13
+ | "book"
14
+ | "buy"
15
+ | "call"
16
+ | "checkIn"
17
+ | "continue"
18
+ | "create"
19
+ | "do"
20
+ | "download"
21
+ | "filter"
22
+ | "find"
23
+ | "get"
24
+ | "go"
25
+ | "log"
26
+ | "open"
27
+ | "order"
28
+ | "pay"
29
+ | "play"
30
+ | "playSound"
31
+ | "post"
32
+ | "request"
33
+ | "run"
34
+ | "search"
35
+ | "send"
36
+ | "set"
37
+ | "share"
38
+ | "start"
39
+ | "startNavigation"
40
+ | "toggle"
41
+ | "turnOff"
42
+ | "turnOn"
43
+ | "view";
10
44
 
11
45
  export interface Person {
12
46
  readonly name: string;
@@ -20,23 +54,79 @@ export interface Placemark {
20
54
  }
21
55
 
22
56
  export interface IntentDialog {
23
- requestChoice<T extends string | { title: string; style?: IntentChoiceStyle }>(choices: T[], prompt: string, options?: CallOptions): Promise<T>;
24
- requestConfirmation(prompt: string, options?: CallOptions & { actionName?: ConfirmationActionName | { accept: string; deny: string; destructive?: boolean } }): Promise<void>;
25
- requestValue(type: "text", prompt?: string, options?: CallOptions & { multiline?: boolean; literal?: boolean }): Promise<string>;
26
- requestValue(type: "integer", prompt?: string, options?: CallOptions & { stepper?: boolean; min?: number; max?: number }): Promise<number>;
27
- requestValue(type: "number", prompt?: string, options?: CallOptions & { min?: number; max?: number }): Promise<number>;
28
- requestValue(type: "date" | "time" | "dateTime", prompt?: string, options?: CallOptions): Promise<Date>;
29
- requestValue(type: "file", prompt?: string, options?: CallOptions): Promise<{ name: string; type: string; bytes: Uint8Array }>;
30
- requestValue(type: "person", prompt?: string, options?: CallOptions): Promise<Person>;
31
- requestValue(type: "placemark", prompt?: string, options?: CallOptions): Promise<Placemark>;
32
- requestDisambiguation(values: string[], prompt: string, options?: CallOptions): Promise<string>;
33
- requestValueConfirmation(value: string, prompt: string, options?: CallOptions): Promise<boolean>;
34
- continueInForeground(prompt?: string, options?: CallOptions & { alwaysConfirm?: boolean }): Promise<void>;
57
+ requestChoice<
58
+ T extends string | { title: string; style?: IntentChoiceStyle },
59
+ >(
60
+ choices: T[],
61
+ prompt: string,
62
+ options?: CallOptions,
63
+ ): Promise<T>;
64
+ requestConfirmation(
65
+ prompt: string,
66
+ options?: CallOptions & {
67
+ actionName?:
68
+ | ConfirmationActionName
69
+ | { accept: string; deny: string; destructive?: boolean };
70
+ },
71
+ ): Promise<void>;
72
+ requestValue(
73
+ type: "text",
74
+ prompt?: string,
75
+ options?: CallOptions & { multiline?: boolean; literal?: boolean },
76
+ ): Promise<string>;
77
+ requestValue(
78
+ type: "integer",
79
+ prompt?: string,
80
+ options?: CallOptions & { stepper?: boolean; min?: number; max?: number },
81
+ ): Promise<number>;
82
+ requestValue(
83
+ type: "number",
84
+ prompt?: string,
85
+ options?: CallOptions & { min?: number; max?: number },
86
+ ): Promise<number>;
87
+ requestValue(
88
+ type: "date" | "time" | "dateTime",
89
+ prompt?: string,
90
+ options?: CallOptions,
91
+ ): Promise<Date>;
92
+ requestValue(
93
+ type: "file",
94
+ prompt?: string,
95
+ options?: CallOptions,
96
+ ): Promise<{ name: string; type: string; bytes: Uint8Array }>;
97
+ requestValue(
98
+ type: "person",
99
+ prompt?: string,
100
+ options?: CallOptions,
101
+ ): Promise<Person>;
102
+ requestValue(
103
+ type: "placemark",
104
+ prompt?: string,
105
+ options?: CallOptions,
106
+ ): Promise<Placemark>;
107
+ requestDisambiguation(
108
+ values: string[],
109
+ prompt: string,
110
+ options?: CallOptions,
111
+ ): Promise<string>;
112
+ requestValueConfirmation(
113
+ value: string,
114
+ prompt: string,
115
+ options?: CallOptions,
116
+ ): Promise<boolean>;
117
+ continueInForeground(
118
+ prompt?: string,
119
+ options?: CallOptions & { alwaysConfirm?: boolean },
120
+ ): Promise<void>;
35
121
  }
36
122
 
37
123
  export type ActionCaller = "app" | "shortcuts" | "api";
38
124
 
39
- export type Schema<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output> & StandardJSONSchemaV1<Input, Output>;
125
+ export type Schema<Input = unknown, Output = Input> = StandardSchemaV1<
126
+ Input,
127
+ Output
128
+ > &
129
+ StandardJSONSchemaV1<Input, Output>;
40
130
 
41
131
  declare const types: unique symbol;
42
132
 
@@ -47,7 +137,10 @@ export interface Action<Input = void, Output = void> {
47
137
  readonly expose: readonly "shortcuts"[];
48
138
  }
49
139
 
50
- export interface Extension<Actions extends Record<string, Action<any, any>> = {}, HasRun extends boolean = boolean> {
140
+ export interface Extension<
141
+ Actions extends Record<string, Action<any, any>> = {},
142
+ HasRun extends boolean = boolean,
143
+ > {
51
144
  readonly [types]: { hasRun: HasRun };
52
145
  readonly actions: Actions;
53
146
  }
@@ -66,32 +159,47 @@ type Sent<S> = S extends Schema ? StandardSchemaV1.InferInput<S> : void;
66
159
  type Returned<S, R> = S extends Schema ? StandardSchemaV1.InferInput<S> : R;
67
160
  type Delivered<S, R> = S extends Schema ? StandardSchemaV1.InferOutput<S> : R;
68
161
 
69
- export declare function defineAction<I extends Schema | undefined = undefined, O extends Schema | undefined = undefined, R = void>(definition: {
162
+ export declare function defineAction<
163
+ I extends Schema | undefined = undefined,
164
+ O extends Schema | undefined = undefined,
165
+ R = void,
166
+ >(definition: {
70
167
  readonly title: string;
71
168
  readonly description?: string;
72
169
  readonly input?: I;
73
170
  readonly output?: O;
74
171
  readonly expose?: readonly "shortcuts"[];
75
- run(input: Received<I>, context: ActionContext): Returned<O, R> | Promise<Returned<O, R>>;
172
+ run(
173
+ input: Received<I>,
174
+ context: ActionContext,
175
+ ): Returned<O, R> | Promise<Returned<O, R>>;
76
176
  }): Action<Sent<I>, Jsonify<Awaited<Delivered<O, R>>>>;
77
177
 
78
- export declare function defineExtension<Actions extends Record<string, Action<any, any>> = {}>(definition: {
178
+ export declare function defineExtension<
179
+ Actions extends Record<string, Action<any, any>> = {},
180
+ >(definition: {
79
181
  run(context: RunContext): Promise<void>;
80
182
  readonly actions?: Actions;
81
183
  }): Extension<Actions, true>;
82
- export declare function defineExtension<Actions extends Record<string, Action<any, any>> = {}>(definition: {
83
- readonly actions?: Actions;
84
- }): Extension<Actions, false>;
184
+ export declare function defineExtension<
185
+ Actions extends Record<string, Action<any, any>> = {},
186
+ >(definition: { readonly actions?: Actions }): Extension<Actions, false>;
85
187
 
86
188
  export type ServiceStatus = "starting" | "running" | "stopped" | "failed";
87
189
 
88
- type ActionCall<A> = A extends Action<infer Input, infer Output>
89
- ? [Input] extends [void]
90
- ? (input?: undefined, options?: { signal?: AbortSignal }) => Promise<Output>
91
- : (input: Input, options?: { signal?: AbortSignal }) => Promise<Output>
92
- : never;
190
+ type ActionCall<A> =
191
+ A extends Action<infer Input, infer Output>
192
+ ? [Input] extends [void]
193
+ ? (
194
+ input?: undefined,
195
+ options?: { signal?: AbortSignal },
196
+ ) => Promise<Output>
197
+ : (input: Input, options?: { signal?: AbortSignal }) => Promise<Output>
198
+ : never;
93
199
 
94
- export type ActionCalls<E extends Extension<any, any>> = { readonly [K in keyof E["actions"]]: ActionCall<E["actions"][K]> };
200
+ export type ActionCalls<E extends Extension<any, any>> = {
201
+ readonly [K in keyof E["actions"]]: ActionCall<E["actions"][K]>;
202
+ };
95
203
 
96
204
  export interface ServiceHandle {
97
205
  readonly enabled: boolean;
@@ -101,10 +209,18 @@ export interface ServiceHandle {
101
209
  setEnabled(enabled: boolean): Promise<void>;
102
210
  }
103
211
 
104
- export declare function actions<E extends Extension<any, any>>(): ActionCalls<E>;
212
+ export declare function actions<
213
+ E extends Extension<any, any>,
214
+ >(): ActionCalls<E>;
105
215
 
106
- export declare function useService<E extends Extension<any, true>>(): ServiceHandle;
216
+ export declare function useService<
217
+ E extends Extension<any, true>,
218
+ >(): ServiceHandle;
107
219
 
108
220
  export declare function exit(): void;
109
221
 
110
- export declare function preferredLocalizations(localizations: readonly string[]): string[];
222
+ export declare function preferredLocalizations(
223
+ localizations: readonly string[],
224
+ ): string[];
225
+
226
+ export {};
package/swiplet.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/swiplet runs inside Swipt; build the swiplet with `swipt project build`");
2
+ throw new Error(
3
+ "@swipt/api/swiplet runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
3
5
  };
4
6
 
5
7
  export const defineExtension = outside;