@swipt/api 0.1.0-nightly.9 → 0.1.0-nightly.91

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2026 by nekohasekai <contact-sagernet@sekai.icu>
1
+ Copyright (C) 2026 by nekohasekai <i@sekai.icu>
2
2
 
3
3
  This program is free software: you can redistribute it and/or modify
4
4
  it under the terms of the GNU General Public License as published by
@@ -1,12 +1,36 @@
1
+ /** @available iOS 26 */
1
2
  import type { CallOptions, Point, Rect } from "./index";
2
- import type { TapOptions } from "./input";
3
3
 
4
- export type AccessibilityTrait = "button" | "link" | "image" | "playsSound" | "keyboardKey" | "staticText" | "summaryElement"
5
- | "updatesFrequently" | "searchField" | "startsMediaSession" | "adjustable" | "allowsDirectInteraction"
6
- | "causesPageTurn" | "tabBar" | "header" | "webContent" | "textEntry";
4
+ export type AccessibilityTrait =
5
+ | "button"
6
+ | "link"
7
+ | "image"
8
+ | "playsSound"
9
+ | "keyboardKey"
10
+ | "staticText"
11
+ | "summaryElement"
12
+ | "updatesFrequently"
13
+ | "searchField"
14
+ | "startsMediaSession"
15
+ | "adjustable"
16
+ | "allowsDirectInteraction"
17
+ | "causesPageTurn"
18
+ | "tabBar"
19
+ | "header"
20
+ | "webContent"
21
+ | "textEntry";
7
22
 
8
- export type AccessibilityAction = "press" | "increment" | "decrement" | "escape" | "menu"
9
- | "scrollUp" | "scrollDown" | "scrollLeft" | "scrollRight" | "scrollToVisible";
23
+ export type AccessibilityAction =
24
+ | "press"
25
+ | "increment"
26
+ | "decrement"
27
+ | "escape"
28
+ | "menu"
29
+ | "scrollUp"
30
+ | "scrollDown"
31
+ | "scrollLeft"
32
+ | "scrollRight"
33
+ | "scrollToVisible";
10
34
 
11
35
  export interface AccessibilityElement {
12
36
  readonly role: string;
@@ -31,6 +55,7 @@ export interface AccessibilityElement {
31
55
  readonly secure?: true;
32
56
  readonly selection?: [location: number, length: number];
33
57
  readonly actions?: readonly string[];
58
+ readonly truncated?: true;
34
59
  readonly children: readonly AccessibilityElement[];
35
60
  readonly parent?: AccessibilityElement;
36
61
  find(selector: AccessibilitySelector): AccessibilityElement | null;
@@ -42,42 +67,86 @@ export interface AccessibilitySnapshot {
42
67
  readonly time: number;
43
68
  readonly root: AccessibilityElement;
44
69
  readonly system?: AccessibilityElement;
70
+ readonly truncated?: true;
45
71
  find(selector: AccessibilitySelector): AccessibilityElement | null;
46
72
  findAll(selector: AccessibilitySelector): AccessibilityElement[];
47
73
  }
48
74
 
49
- type TextField = "role" | "class" | "label" | "value" | "identifier" | "placeholder" | "hint" | "url" | "app";
50
- type Flag = "disabled" | "focused" | "selected" | "expanded" | "secure" | "partial" | "offScreen" | "inert" | "remote";
51
-
52
- export type AccessibilityQuery = { traits?: AccessibilityTrait[]; within?: AccessibilityQuery; parent?: AccessibilityQuery; has?: AccessibilityQuery; not?: AccessibilityQuery; index?: number }
53
- & { [field in TextField]?: string | RegExp }
54
- & { [field in Flag]?: boolean };
75
+ type TextField =
76
+ | "role"
77
+ | "class"
78
+ | "label"
79
+ | "value"
80
+ | "identifier"
81
+ | "placeholder"
82
+ | "hint"
83
+ | "url"
84
+ | "app";
85
+ type Flag =
86
+ | "disabled"
87
+ | "focused"
88
+ | "selected"
89
+ | "expanded"
90
+ | "secure"
91
+ | "partial"
92
+ | "offScreen"
93
+ | "inert"
94
+ | "remote"
95
+ | "truncated";
55
96
 
56
97
  export type AccessibilitySelector =
57
- | ({ traits?: AccessibilityTrait[]; within?: AccessibilitySelector | AccessibilityElement; parent?: AccessibilitySelector | AccessibilityElement; has?: AccessibilitySelector | AccessibilityElement; not?: AccessibilitySelector | AccessibilityElement; index?: number }
58
- & { [field in TextField]?: string | RegExp }
59
- & { [field in Flag]?: boolean })
98
+ | ({
99
+ traits?: AccessibilityTrait[];
100
+ within?: AccessibilitySelector | AccessibilityElement;
101
+ parent?: AccessibilitySelector | AccessibilityElement;
102
+ has?: AccessibilitySelector | AccessibilityElement;
103
+ not?: AccessibilitySelector | AccessibilityElement;
104
+ index?: number;
105
+ } & { [field in TextField]?: string | RegExp } & {
106
+ [field in Flag]?: boolean;
107
+ })
60
108
  | ((element: AccessibilityElement) => boolean);
61
109
 
62
- export interface SnapshotOptions extends CallOptions {
63
- readonly scope?: "screen" | "frontApp";
110
+ export interface ReadOptions extends CallOptions {
111
+ readonly depth?: number;
112
+ }
113
+
114
+ export interface SnapshotOptions extends ReadOptions {
115
+ readonly scope?: "frontApp" | "springBoard" | "fullScreen";
116
+ readonly within?: AccessibilityElement;
64
117
  readonly full?: boolean;
65
118
  }
66
119
 
67
- export interface LocatorOptions extends CallOptions {
68
- /** 10000 when omitted; Infinity waits without a limit. */
120
+ export interface FindOptions extends ReadOptions {
121
+ /** Omitted or 0 reads once; a positive number or Infinity reads until a match, and answers null at the limit. */
69
122
  readonly timeoutMs?: number;
123
+ /** 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. */
124
+ readonly poll?: boolean;
125
+ readonly pollTimeoutMs?: number;
70
126
  }
71
127
 
72
- export interface AccessibilityLocator {
73
- tap(options?: LocatorOptions & TapOptions): Promise<void>;
74
- /** Taps each element as it comes to match, once while it stays matched, and resolves when the app in front at the call leaves the front, at once if the query names only other apps. */
75
- tapEach(options?: TapOptions): Promise<void>;
76
- setText(text: string, options?: LocatorOptions): Promise<void>;
77
- perform(action: AccessibilityAction | (string & {}), options?: LocatorOptions): Promise<void>;
128
+ export declare function snapshot(
129
+ options?: SnapshotOptions,
130
+ ): Promise<AccessibilitySnapshot>;
131
+ export declare function find(
132
+ selector: AccessibilitySelector | readonly AccessibilitySelector[],
133
+ options?: FindOptions,
134
+ ): Promise<AccessibilityElement | null>;
135
+ export interface ElementOptions extends CallOptions {
136
+ readonly timeoutMs?: number;
78
137
  }
79
138
 
80
- export declare function locator(query: AccessibilityQuery | readonly AccessibilityQuery[]): AccessibilityLocator;
81
- export declare function snapshot(options?: SnapshotOptions): Promise<AccessibilitySnapshot>;
82
- export declare function find(selector: AccessibilitySelector, options?: CallOptions): Promise<AccessibilityElement | null>;
83
- export declare function tap(element: AccessibilityElement, options?: TapOptions): Promise<void>;
139
+ export declare function tap(
140
+ element: AccessibilityElement,
141
+ options?: ElementOptions,
142
+ ): Promise<void>;
143
+ export declare function setText(
144
+ element: AccessibilityElement,
145
+ text: string,
146
+ options?: ElementOptions,
147
+ ): Promise<void>;
148
+ export declare function perform(
149
+ element: AccessibilityElement,
150
+ action: AccessibilityAction | (string & {}),
151
+ options?: CallOptions,
152
+ ): Promise<void>;
package/accessibility.mjs CHANGED
@@ -1,8 +1,11 @@
1
1
  const outside = () => {
2
- throw new Error("@swipt/api/accessibility runs inside Swipt; build the swiplet with `swiplet 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
- 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;
@@ -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>;
@@ -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(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>;
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(options?: CallOptions): Promise<string | null>;
46
- export declare function setPasteboard(text: string | null, options?: CallOptions): Promise<void>;
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
- export declare function simulateLocation(latitude: number, longitude: number, options?: CallOptions): Promise<void>;
49
- export declare function clearSimulatedLocation(options?: CallOptions): Promise<void>;
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("@swipt/api/device runs inside Swipt; build the swiplet with `swiplet 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;
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 simulateLocation = outside;
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
- write(data: string | Uint8Array | Blob): 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/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
@@ -0,0 +1,8 @@
1
+ const outside = () => {
2
+ throw new Error(
3
+ "@swipt/api/http runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
5
+ };
6
+
7
+ export const Client = outside;
8
+ export const CookieJar = outside;
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
 
@@ -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: { readonly width?: number; readonly height?: number }): RasterImage;
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(format?: ImageFormat, options?: CallOptions & { readonly quality?: number }): Promise<Uint8Array>;
98
- save(file: FileHandle | string, options?: CallOptions & { readonly format?: ImageFormat; readonly quality?: number }): Promise<FileHandle>;
99
- pixel(point: Point, options?: CallOptions): Promise<[red: number, green: number, blue: number, alpha: number]>;
100
- stats(options?: CallOptions & { readonly region?: Rect }): Promise<ImageStats>;
101
- release(): void;
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,
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,
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 `swiplet 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,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 = [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;
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
+ }
package/index.mjs CHANGED
@@ -1 +1,7 @@
1
- export {};
1
+ const outside = () => {
2
+ throw new Error(
3
+ "@swipt/api runs inside Swipt; build the swiplet with `swipt project build`",
4
+ );
5
+ };
6
+
7
+ export const available = outside;