@swipt/api 0.1.0-nightly.9 → 0.1.0-nightly.90
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/LICENSE +1 -1
- package/accessibility.d.ts +97 -29
- package/accessibility.mjs +5 -2
- package/app-intents.d.ts +127 -0
- package/app-intents.mjs +11 -0
- package/device.d.ts +38 -8
- package/device.mjs +5 -3
- package/file-system.d.ts +14 -1
- package/file-system.mjs +1 -0
- package/http.d.ts +46 -0
- package/http.mjs +8 -0
- package/image.d.ts +61 -17
- package/image.mjs +3 -1
- package/index.d.ts +30 -9
- package/index.mjs +7 -1
- package/input.d.ts +41 -9
- package/input.mjs +3 -1
- package/localization.d.ts +3 -0
- package/localization.mjs +7 -0
- package/maps.d.ts +6 -0
- package/maps.mjs +7 -0
- package/package.json +43 -4
- package/process.d.ts +190 -0
- package/process.mjs +9 -0
- package/repl.d.ts +5 -2
- package/screen.d.ts +27 -53
- package/screen.mjs +4 -7
- package/swift-ui.d.ts +323 -0
- package/swift-ui.mjs +9 -0
- package/swiplet.d.ts +77 -53
- package/swiplet.mjs +4 -1
package/LICENSE
CHANGED
package/accessibility.d.ts
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import type { CallOptions, Point, Rect } from "./index";
|
|
2
|
-
import type { TapOptions } from "./input";
|
|
3
2
|
|
|
4
|
-
export type AccessibilityTrait =
|
|
5
|
-
| "
|
|
6
|
-
| "
|
|
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";
|
|
7
21
|
|
|
8
|
-
export type AccessibilityAction =
|
|
9
|
-
| "
|
|
22
|
+
export type AccessibilityAction =
|
|
23
|
+
| "press"
|
|
24
|
+
| "increment"
|
|
25
|
+
| "decrement"
|
|
26
|
+
| "escape"
|
|
27
|
+
| "menu"
|
|
28
|
+
| "scrollUp"
|
|
29
|
+
| "scrollDown"
|
|
30
|
+
| "scrollLeft"
|
|
31
|
+
| "scrollRight"
|
|
32
|
+
| "scrollToVisible";
|
|
10
33
|
|
|
11
34
|
export interface AccessibilityElement {
|
|
12
35
|
readonly role: string;
|
|
@@ -31,6 +54,7 @@ export interface AccessibilityElement {
|
|
|
31
54
|
readonly secure?: true;
|
|
32
55
|
readonly selection?: [location: number, length: number];
|
|
33
56
|
readonly actions?: readonly string[];
|
|
57
|
+
readonly truncated?: true;
|
|
34
58
|
readonly children: readonly AccessibilityElement[];
|
|
35
59
|
readonly parent?: AccessibilityElement;
|
|
36
60
|
find(selector: AccessibilitySelector): AccessibilityElement | null;
|
|
@@ -42,42 +66,86 @@ export interface AccessibilitySnapshot {
|
|
|
42
66
|
readonly time: number;
|
|
43
67
|
readonly root: AccessibilityElement;
|
|
44
68
|
readonly system?: AccessibilityElement;
|
|
69
|
+
readonly truncated?: true;
|
|
45
70
|
find(selector: AccessibilitySelector): AccessibilityElement | null;
|
|
46
71
|
findAll(selector: AccessibilitySelector): AccessibilityElement[];
|
|
47
72
|
}
|
|
48
73
|
|
|
49
|
-
type TextField =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
74
|
+
type TextField =
|
|
75
|
+
| "role"
|
|
76
|
+
| "class"
|
|
77
|
+
| "label"
|
|
78
|
+
| "value"
|
|
79
|
+
| "identifier"
|
|
80
|
+
| "placeholder"
|
|
81
|
+
| "hint"
|
|
82
|
+
| "url"
|
|
83
|
+
| "app";
|
|
84
|
+
type Flag =
|
|
85
|
+
| "disabled"
|
|
86
|
+
| "focused"
|
|
87
|
+
| "selected"
|
|
88
|
+
| "expanded"
|
|
89
|
+
| "secure"
|
|
90
|
+
| "partial"
|
|
91
|
+
| "offScreen"
|
|
92
|
+
| "inert"
|
|
93
|
+
| "remote"
|
|
94
|
+
| "truncated";
|
|
55
95
|
|
|
56
96
|
export type AccessibilitySelector =
|
|
57
|
-
| ({
|
|
58
|
-
|
|
59
|
-
|
|
97
|
+
| ({
|
|
98
|
+
traits?: AccessibilityTrait[];
|
|
99
|
+
within?: AccessibilitySelector | AccessibilityElement;
|
|
100
|
+
parent?: AccessibilitySelector | AccessibilityElement;
|
|
101
|
+
has?: AccessibilitySelector | AccessibilityElement;
|
|
102
|
+
not?: AccessibilitySelector | AccessibilityElement;
|
|
103
|
+
index?: number;
|
|
104
|
+
} & { [field in TextField]?: string | RegExp } & {
|
|
105
|
+
[field in Flag]?: boolean;
|
|
106
|
+
})
|
|
60
107
|
| ((element: AccessibilityElement) => boolean);
|
|
61
108
|
|
|
62
|
-
export interface
|
|
63
|
-
readonly
|
|
109
|
+
export interface ReadOptions extends CallOptions {
|
|
110
|
+
readonly depth?: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SnapshotOptions extends ReadOptions {
|
|
114
|
+
readonly scope?: "frontApp" | "springBoard" | "fullScreen";
|
|
115
|
+
readonly within?: AccessibilityElement;
|
|
64
116
|
readonly full?: boolean;
|
|
65
117
|
}
|
|
66
118
|
|
|
67
|
-
export interface
|
|
68
|
-
/**
|
|
119
|
+
export interface FindOptions extends ReadOptions {
|
|
120
|
+
/** Omitted or 0 reads once; a positive number or Infinity reads until a match, and answers null at the limit. */
|
|
69
121
|
readonly timeoutMs?: number;
|
|
122
|
+
/** Reads again as soon as a read ends. Without it, a read waits for the device's next screen push, which comes 0.75 s after a change at the soonest and not at all for a change that adds or removes no element. */
|
|
123
|
+
readonly poll?: boolean;
|
|
124
|
+
readonly pollTimeoutMs?: number;
|
|
70
125
|
}
|
|
71
126
|
|
|
72
|
-
export
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
127
|
+
export declare function snapshot(
|
|
128
|
+
options?: SnapshotOptions,
|
|
129
|
+
): Promise<AccessibilitySnapshot>;
|
|
130
|
+
export declare function find(
|
|
131
|
+
selector: AccessibilitySelector | readonly AccessibilitySelector[],
|
|
132
|
+
options?: FindOptions,
|
|
133
|
+
): Promise<AccessibilityElement | null>;
|
|
134
|
+
export interface ElementOptions extends CallOptions {
|
|
135
|
+
readonly timeoutMs?: number;
|
|
78
136
|
}
|
|
79
137
|
|
|
80
|
-
export declare function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
138
|
+
export declare function tap(
|
|
139
|
+
element: AccessibilityElement,
|
|
140
|
+
options?: ElementOptions,
|
|
141
|
+
): Promise<void>;
|
|
142
|
+
export declare function setText(
|
|
143
|
+
element: AccessibilityElement,
|
|
144
|
+
text: string,
|
|
145
|
+
options?: ElementOptions,
|
|
146
|
+
): Promise<void>;
|
|
147
|
+
export declare function perform(
|
|
148
|
+
element: AccessibilityElement,
|
|
149
|
+
action: AccessibilityAction | (string & {}),
|
|
150
|
+
options?: CallOptions,
|
|
151
|
+
): Promise<void>;
|
package/accessibility.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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
|
-
export const locator = outside;
|
|
6
7
|
export const snapshot = outside;
|
|
7
8
|
export const find = outside;
|
|
8
9
|
export const tap = outside;
|
|
10
|
+
export const setText = outside;
|
|
11
|
+
export const perform = outside;
|
package/app-intents.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This package is designed to provide the same headless interactions as Shortcuts or App Intents.
|
|
3
|
+
*
|
|
4
|
+
* When Shortcuts runs an action, iOS presents these interactions itself, except requestValue.
|
|
5
|
+
* In every other case Swipt presents them. If another app is in front, Swipt takes a screenshot
|
|
6
|
+
* of it, comes to the front with the interaction over that screenshot, and returns to that app
|
|
7
|
+
* when the interaction ends. Cancelling an interaction rejects it with AbortError.
|
|
8
|
+
*
|
|
9
|
+
* It works in every environment, including the REPL, but should not be used in place of native
|
|
10
|
+
* UI interactions in a swiplet.
|
|
11
|
+
*/
|
|
12
|
+
import type { CallOptions } from "./index";
|
|
13
|
+
|
|
14
|
+
export type IntentChoiceStyle = "default" | "destructive" | "cancel";
|
|
15
|
+
|
|
16
|
+
export type ConfirmationActionName =
|
|
17
|
+
| "add"
|
|
18
|
+
| "addData"
|
|
19
|
+
| "book"
|
|
20
|
+
| "buy"
|
|
21
|
+
| "call"
|
|
22
|
+
| "checkIn"
|
|
23
|
+
| "continue"
|
|
24
|
+
| "create"
|
|
25
|
+
| "do"
|
|
26
|
+
| "download"
|
|
27
|
+
| "filter"
|
|
28
|
+
| "find"
|
|
29
|
+
| "get"
|
|
30
|
+
| "go"
|
|
31
|
+
| "log"
|
|
32
|
+
| "open"
|
|
33
|
+
| "order"
|
|
34
|
+
| "pay"
|
|
35
|
+
| "play"
|
|
36
|
+
| "playSound"
|
|
37
|
+
| "post"
|
|
38
|
+
| "request"
|
|
39
|
+
| "run"
|
|
40
|
+
| "search"
|
|
41
|
+
| "send"
|
|
42
|
+
| "set"
|
|
43
|
+
| "share"
|
|
44
|
+
| "start"
|
|
45
|
+
| "startNavigation"
|
|
46
|
+
| "toggle"
|
|
47
|
+
| "turnOff"
|
|
48
|
+
| "turnOn"
|
|
49
|
+
| "view";
|
|
50
|
+
|
|
51
|
+
export interface Person {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly handle?: { type: "phoneNumber" | "emailAddress"; value: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface Placemark {
|
|
57
|
+
readonly name?: string;
|
|
58
|
+
readonly coordinate?: [latitude: number, longitude: number];
|
|
59
|
+
readonly address?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A choice of style cancel rejects with AbortError. Swiping the request away answers
|
|
64
|
+
* the first choice, so the first choice is the one that is safe to take unasked.
|
|
65
|
+
* @available iOS 26
|
|
66
|
+
*/
|
|
67
|
+
export declare function requestChoice<
|
|
68
|
+
T extends string | { title: string; style?: IntentChoiceStyle },
|
|
69
|
+
>(choices: T[], prompt: string, options?: CallOptions): Promise<T>;
|
|
70
|
+
/** The deny button rejects with AbortError. */
|
|
71
|
+
export declare function requestConfirmation(
|
|
72
|
+
prompt: string,
|
|
73
|
+
options?: CallOptions & {
|
|
74
|
+
actionName?:
|
|
75
|
+
| ConfirmationActionName
|
|
76
|
+
| { accept: string; deny: string; destructive?: boolean };
|
|
77
|
+
},
|
|
78
|
+
): Promise<void>;
|
|
79
|
+
export declare function requestValue(
|
|
80
|
+
type: "text",
|
|
81
|
+
prompt?: string,
|
|
82
|
+
options?: CallOptions & {
|
|
83
|
+
multiline?: boolean;
|
|
84
|
+
/** Turns off autocapitalization, autocorrection, spell checking and smart punctuation. */
|
|
85
|
+
literal?: boolean;
|
|
86
|
+
},
|
|
87
|
+
): Promise<string>;
|
|
88
|
+
export declare function requestValue(
|
|
89
|
+
type: "integer",
|
|
90
|
+
prompt?: string,
|
|
91
|
+
options?: CallOptions & { stepper?: boolean; min?: number; max?: number },
|
|
92
|
+
): Promise<number>;
|
|
93
|
+
export declare function requestValue(
|
|
94
|
+
type: "number",
|
|
95
|
+
prompt?: string,
|
|
96
|
+
options?: CallOptions & { min?: number; max?: number },
|
|
97
|
+
): Promise<number>;
|
|
98
|
+
export declare function requestValue(
|
|
99
|
+
type: "date" | "time" | "dateTime",
|
|
100
|
+
prompt?: string,
|
|
101
|
+
options?: CallOptions,
|
|
102
|
+
): Promise<Date>;
|
|
103
|
+
export declare function requestValue(
|
|
104
|
+
type: "file",
|
|
105
|
+
prompt?: string,
|
|
106
|
+
options?: CallOptions,
|
|
107
|
+
): Promise<{ name: string; type: string; bytes: Uint8Array }>;
|
|
108
|
+
export declare function requestValue(
|
|
109
|
+
type: "person",
|
|
110
|
+
prompt?: string,
|
|
111
|
+
options?: CallOptions,
|
|
112
|
+
): Promise<Person>;
|
|
113
|
+
export declare function requestValue(
|
|
114
|
+
type: "placemark",
|
|
115
|
+
prompt?: string,
|
|
116
|
+
options?: CallOptions,
|
|
117
|
+
): Promise<Placemark>;
|
|
118
|
+
export declare function requestDisambiguation(
|
|
119
|
+
values: string[],
|
|
120
|
+
prompt: string,
|
|
121
|
+
options?: CallOptions,
|
|
122
|
+
): Promise<string>;
|
|
123
|
+
export declare function requestValueConfirmation(
|
|
124
|
+
value: string,
|
|
125
|
+
prompt: string,
|
|
126
|
+
options?: CallOptions,
|
|
127
|
+
): Promise<boolean>;
|
package/app-intents.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const outside = () => {
|
|
2
|
+
throw new Error(
|
|
3
|
+
"@swipt/api/app-intents runs inside Swipt; build the swiplet with `swipt project build`",
|
|
4
|
+
);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const requestChoice = outside;
|
|
8
|
+
export const requestConfirmation = outside;
|
|
9
|
+
export const requestValue = outside;
|
|
10
|
+
export const requestDisambiguation = outside;
|
|
11
|
+
export const requestValueConfirmation = outside;
|
package/device.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CallOptions, ObservableState } from "./index";
|
|
2
2
|
import type { FileHandle } from "./file-system";
|
|
3
|
+
import type { RasterImage } from "./image";
|
|
3
4
|
|
|
4
5
|
export type DisplayState = "off" | "dimmed" | "inactiveOn" | "activeOn";
|
|
5
6
|
|
|
@@ -31,19 +32,48 @@ export interface ApplicationStateEvent {
|
|
|
31
32
|
readonly time: number;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
export interface SimulatedLocation {
|
|
36
|
+
readonly latitude: number;
|
|
37
|
+
readonly longitude: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
export declare function info(options?: CallOptions): Promise<DeviceInfo>;
|
|
41
|
+
export declare function screenshot(options?: CallOptions): Promise<RasterImage>;
|
|
35
42
|
export declare const foregroundApplication: ObservableState<string>;
|
|
36
43
|
export declare const locked: ObservableState<boolean>;
|
|
37
44
|
export declare const displayState: ObservableState<DisplayState>;
|
|
38
45
|
export declare function unlock(options?: CallOptions): Promise<void>;
|
|
39
46
|
|
|
40
|
-
export declare function applicationEvents(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export declare function
|
|
47
|
+
export declare function applicationEvents(
|
|
48
|
+
options?: CallOptions,
|
|
49
|
+
): AsyncIterable<ApplicationStateEvent>;
|
|
50
|
+
export declare function installedApplications(
|
|
51
|
+
options?: CallOptions,
|
|
52
|
+
): Promise<InstalledApplication[]>;
|
|
53
|
+
/** Answers a PNG file in cacheDirectory. */
|
|
54
|
+
export declare function applicationIcon(
|
|
55
|
+
bundleId: string,
|
|
56
|
+
options?: CallOptions,
|
|
57
|
+
): Promise<FileHandle>;
|
|
58
|
+
export declare function launchApplication(
|
|
59
|
+
bundleId: string,
|
|
60
|
+
options?: CallOptions & { url?: string; restart?: boolean },
|
|
61
|
+
): Promise<void>;
|
|
44
62
|
|
|
45
|
-
export declare function pasteboard(
|
|
46
|
-
|
|
63
|
+
export declare function pasteboard(
|
|
64
|
+
options?: CallOptions,
|
|
65
|
+
): Promise<string | null>;
|
|
66
|
+
export declare function setPasteboard(
|
|
67
|
+
text: string | null,
|
|
68
|
+
options?: CallOptions,
|
|
69
|
+
): Promise<void>;
|
|
47
70
|
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The WGS-84 location Swipt simulates, kept across restarts of Swipt until it is
|
|
73
|
+
* set to null or the swiplet that set it is removed. iOS reports the real location
|
|
74
|
+
* while Swipt is not connected to the device, and has no call that reads the
|
|
75
|
+
* simulated location back, so get answers what Swipt last set.
|
|
76
|
+
*/
|
|
77
|
+
export declare const simulatedLocation: ObservableState<SimulatedLocation | null> & {
|
|
78
|
+
set(location: SimulatedLocation | null, options?: CallOptions): Promise<void>;
|
|
79
|
+
};
|
package/device.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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;
|
|
8
|
+
export const screenshot = outside;
|
|
6
9
|
export const foregroundApplication = undefined;
|
|
7
10
|
export const locked = undefined;
|
|
8
11
|
export const displayState = undefined;
|
|
@@ -13,5 +16,4 @@ export const applicationIcon = outside;
|
|
|
13
16
|
export const launchApplication = outside;
|
|
14
17
|
export const pasteboard = outside;
|
|
15
18
|
export const setPasteboard = outside;
|
|
16
|
-
export const
|
|
17
|
-
export const clearSimulatedLocation = outside;
|
|
19
|
+
export const simulatedLocation = undefined;
|
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/http.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FileHandle } from "./file-system";
|
|
2
|
+
|
|
3
|
+
export interface Cookie {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly value: string;
|
|
6
|
+
readonly domain: string;
|
|
7
|
+
readonly hostOnly: boolean;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly expires: number | null;
|
|
10
|
+
readonly secure: boolean;
|
|
11
|
+
readonly httpOnly: boolean;
|
|
12
|
+
readonly sameSite: "strict" | "lax" | "none" | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare class CookieJar {
|
|
16
|
+
constructor(file?: FileHandle);
|
|
17
|
+
getAll(url?: string | URL): Promise<Cookie[]>;
|
|
18
|
+
set(url: string | URL, setCookie: string): Promise<void>;
|
|
19
|
+
clear(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ClientOptions {
|
|
23
|
+
readonly cookies?: CookieJar;
|
|
24
|
+
readonly headers?: Headers | Record<string, string> | [string, string][];
|
|
25
|
+
readonly proxy?: string;
|
|
26
|
+
readonly tls?: {
|
|
27
|
+
readonly ca?: string | readonly string[];
|
|
28
|
+
readonly rejectUnauthorized?: boolean;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare class Client {
|
|
33
|
+
constructor(options?: ClientOptions);
|
|
34
|
+
readonly fetch: (
|
|
35
|
+
input: string | URL | Request,
|
|
36
|
+
init?: RequestInit,
|
|
37
|
+
) => Promise<Response>;
|
|
38
|
+
readonly webSocket: (
|
|
39
|
+
url: string | URL,
|
|
40
|
+
protocols?: string | string[],
|
|
41
|
+
) => WebSocket;
|
|
42
|
+
readonly eventSource: (
|
|
43
|
+
url: string | URL,
|
|
44
|
+
init?: EventSourceInit,
|
|
45
|
+
) => EventSource;
|
|
46
|
+
}
|
package/http.mjs
ADDED
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
|
|
|
@@ -81,10 +83,14 @@ export interface RasterImage {
|
|
|
81
83
|
readonly scale: number;
|
|
82
84
|
readonly frame: Rect;
|
|
83
85
|
readonly time: number | null;
|
|
86
|
+
readonly timestamp: number | null;
|
|
84
87
|
|
|
85
88
|
crop(rect: Rect): RasterImage;
|
|
86
89
|
resize(scale: number): RasterImage;
|
|
87
|
-
resize(size: {
|
|
90
|
+
resize(size: {
|
|
91
|
+
readonly width?: number;
|
|
92
|
+
readonly height?: number;
|
|
93
|
+
}): RasterImage;
|
|
88
94
|
rotate(degrees: number): RasterImage;
|
|
89
95
|
grayscale(): RasterImage;
|
|
90
96
|
threshold(level?: number | "otsu"): RasterImage;
|
|
@@ -94,21 +100,59 @@ export interface RasterImage {
|
|
|
94
100
|
dilate(radius?: number): RasterImage;
|
|
95
101
|
erode(radius?: number): RasterImage;
|
|
96
102
|
|
|
97
|
-
encode(
|
|
98
|
-
|
|
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,
|
|
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,
|
|
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,15 +9,36 @@ 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;
|
|
36
|
+
|
|
37
|
+
export declare function available(requirements: {
|
|
38
|
+
readonly apiLevel?: number;
|
|
39
|
+
readonly iOS?: number;
|
|
40
|
+
}): boolean;
|
|
41
|
+
|
|
42
|
+
declare global {
|
|
43
|
+
function sleep(ms: number, options?: CallOptions): Promise<void>;
|
|
44
|
+
}
|