@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.
- package/accessibility.d.ts +80 -15
- package/accessibility.mjs +3 -1
- package/device.d.ts +30 -8
- package/device.mjs +3 -1
- package/file-system.d.ts +14 -1
- package/file-system.mjs +1 -0
- package/image.d.ts +60 -16
- package/image.mjs +3 -1
- package/index.d.ts +21 -9
- package/input.d.ts +41 -8
- package/input.mjs +3 -1
- package/package.json +1 -1
- package/repl.d.ts +3 -1
- package/screen.d.ts +94 -23
- package/screen.mjs +3 -1
- package/swiplet.d.ts +149 -33
- package/swiplet.mjs +3 -1
package/accessibility.d.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import type { CallOptions, Point, Rect } from "./index";
|
|
2
2
|
|
|
3
|
-
export type AccessibilityTrait =
|
|
4
|
-
| "
|
|
5
|
-
| "
|
|
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 =
|
|
8
|
-
| "
|
|
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 =
|
|
49
|
-
|
|
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
|
-
| ({
|
|
53
|
-
|
|
54
|
-
|
|
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(
|
|
71
|
-
|
|
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(
|
|
78
|
-
|
|
79
|
-
|
|
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(
|
|
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(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export declare function
|
|
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(
|
|
46
|
-
|
|
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(
|
|
49
|
-
|
|
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(
|
|
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
|
-
|
|
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
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 =
|
|
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
|
|
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: {
|
|
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(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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 = [
|
|
12
|
+
export type Quad = [
|
|
13
|
+
topLeft: Point,
|
|
14
|
+
topRight: Point,
|
|
15
|
+
bottomRight: Point,
|
|
16
|
+
bottomLeft: Point,
|
|
17
|
+
];
|
|
13
18
|
|
|
14
|
-
export type ErrorName =
|
|
19
|
+
export type ErrorName =
|
|
20
|
+
"AbortError" | "TimeoutError" | "NotFoundError" | "UnavailableError";
|
|
15
21
|
|
|
16
|
-
export type 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
|
|
19
|
-
|
|
20
|
-
: T extends
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 =
|
|
8
|
-
| "
|
|
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 =
|
|
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(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
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
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
|
-
|
|
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
|
-
| {
|
|
22
|
-
|
|
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
|
-
| {
|
|
25
|
-
|
|
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(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
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(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export declare function
|
|
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(
|
|
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 {
|
|
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 =
|
|
8
|
-
| "
|
|
9
|
-
| "
|
|
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<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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<
|
|
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<
|
|
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<
|
|
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(
|
|
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<
|
|
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<
|
|
83
|
-
|
|
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> =
|
|
89
|
-
|
|
90
|
-
?
|
|
91
|
-
|
|
92
|
-
|
|
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>> = {
|
|
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<
|
|
212
|
+
export declare function actions<
|
|
213
|
+
E extends Extension<any, any>,
|
|
214
|
+
>(): ActionCalls<E>;
|
|
105
215
|
|
|
106
|
-
export declare function useService<
|
|
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(
|
|
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(
|
|
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;
|