@popclip/types 1.4586.0
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/README.md +5 -0
- package/package.json +14 -0
- package/popclip.d.ts +1325 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@popclip/types",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "1.4586.0",
|
|
5
|
+
"types": "./popclip.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"check": "tsc --noEmit",
|
|
8
|
+
"docs": "typedoc"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"typedoc": "0.25.13",
|
|
12
|
+
"typescript": "5.4.5"
|
|
13
|
+
}
|
|
14
|
+
}
|
package/popclip.d.ts
ADDED
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This is a TypeScript definitions file for PopClip's JavaScript interface.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object giving strings for the different languages PopClip supports. See {@link LocalizableString}.
|
|
7
|
+
*/
|
|
8
|
+
declare interface StringTable {
|
|
9
|
+
/** English (US) language string. */
|
|
10
|
+
en: string;
|
|
11
|
+
/** English (UK) language string. */
|
|
12
|
+
"en-GB"?: string;
|
|
13
|
+
/** Danish language string. */
|
|
14
|
+
da?: string;
|
|
15
|
+
/** German language string. */
|
|
16
|
+
de?: string;
|
|
17
|
+
/** Spanish language string. */
|
|
18
|
+
es?: string;
|
|
19
|
+
/** French language string. */
|
|
20
|
+
fr?: string;
|
|
21
|
+
/** Italian language string. */
|
|
22
|
+
it?: string;
|
|
23
|
+
/** Japanese language string. */
|
|
24
|
+
ja?: string;
|
|
25
|
+
/** Korean language string. */
|
|
26
|
+
ko?: string;
|
|
27
|
+
/** Dutch language string. */
|
|
28
|
+
nl?: string;
|
|
29
|
+
/** Polish language string. */
|
|
30
|
+
pl?: string;
|
|
31
|
+
/** Brazilian Portuguese language string. */
|
|
32
|
+
"pt-BR"?: string;
|
|
33
|
+
/** Russian language string. */
|
|
34
|
+
ru?: string;
|
|
35
|
+
/** Slovak language string. */
|
|
36
|
+
sk?: string;
|
|
37
|
+
/** Turkish language string. */
|
|
38
|
+
tr?: string;
|
|
39
|
+
/** Vietnamese language string. */
|
|
40
|
+
vi?: string;
|
|
41
|
+
/** Simplified Chinese language string. */
|
|
42
|
+
"zh-Hans"?: string;
|
|
43
|
+
/** Traditional Chinese language string. */
|
|
44
|
+
"zh-Hant"?: string;
|
|
45
|
+
/** Any other strings. */
|
|
46
|
+
[code: string]: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A type to represent a localizable string.
|
|
51
|
+
*
|
|
52
|
+
* #### Notes
|
|
53
|
+
*
|
|
54
|
+
* The value may be either a string or an object.
|
|
55
|
+
* If you supply a string, that string is used.
|
|
56
|
+
* If you supply a {@link StringTable} object, PopClip will
|
|
57
|
+
* display the string for the user's preferred language if possible, with fallback to the `en` string.
|
|
58
|
+
*
|
|
59
|
+
* #### Example
|
|
60
|
+
* ```js
|
|
61
|
+
* option.label = "Color" // just use this string
|
|
62
|
+
* option.label = { en: "Color", "en-GB": "Colour", fr: "Couleur", "zh-Hans": "颜色" }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare type LocalizableString = string | StringTable;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Represents the state of the four modifier keys. The value is true when the key is held down
|
|
69
|
+
* at the time the action is invoked.
|
|
70
|
+
* See {@link PopClip.modifiers}.
|
|
71
|
+
*/
|
|
72
|
+
declare interface Modifiers {
|
|
73
|
+
/** Shift (⇧) key state. */
|
|
74
|
+
shift: boolean;
|
|
75
|
+
/** Control (⌃) key state. */
|
|
76
|
+
control: boolean;
|
|
77
|
+
/** Option (⌥) key state. */
|
|
78
|
+
option: boolean;
|
|
79
|
+
/** Command (⌘) key state. */
|
|
80
|
+
command: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A requirement is specified in the {@link Action.requirements} array as a string.
|
|
85
|
+
*
|
|
86
|
+
* #### Example
|
|
87
|
+
* ```js
|
|
88
|
+
* ["paste", "!urls", "option-goFishing=1"]
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare type Requirement =
|
|
92
|
+
| "text"
|
|
93
|
+
| "cut"
|
|
94
|
+
| "paste"
|
|
95
|
+
| "formatting"
|
|
96
|
+
| "url"
|
|
97
|
+
| "urls"
|
|
98
|
+
| "email"
|
|
99
|
+
| "emails"
|
|
100
|
+
| "path"
|
|
101
|
+
| `option-${string}=${string}`;
|
|
102
|
+
|
|
103
|
+
/** Negated form of {@link Requirement}. */
|
|
104
|
+
declare type NegatedRequirement = `!${Requirement}`;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Strings which can be used to specify the {@link Action.before} action.
|
|
108
|
+
*/
|
|
109
|
+
declare type BeforeStep = "cut" | "copy" | "paste" | "paste-plain";
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Strings which can be used to specify the {@link Action.after} action.
|
|
113
|
+
*/
|
|
114
|
+
declare type AfterStep =
|
|
115
|
+
| BeforeStep
|
|
116
|
+
| "popclip-appear"
|
|
117
|
+
| "show-status"
|
|
118
|
+
| "copy-result"
|
|
119
|
+
| "paste-result"
|
|
120
|
+
| "show-result"
|
|
121
|
+
| "preview-result";
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Declares information about an app or website that this extension interacts with.
|
|
125
|
+
*/
|
|
126
|
+
declare interface AssociatedApp {
|
|
127
|
+
/**
|
|
128
|
+
* Name of the app. For example "Scrivener"
|
|
129
|
+
*/
|
|
130
|
+
name: string;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Web page where user can obtain the app, e.g. "https://www.literatureandlatte.com/scrivener".
|
|
134
|
+
*/
|
|
135
|
+
link: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Indicates whether PopClip should check for the presence of the app on the computer. Default is false.
|
|
139
|
+
*/
|
|
140
|
+
checkInstalled?: boolean;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* List of possible bundle identifiers of this app.
|
|
144
|
+
*/
|
|
145
|
+
bundleIdentifiers?: string[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A population function dynamically generates the actions for the extension. See {@link Extension.actions}.
|
|
150
|
+
* @param input The selected text and related properties. (Same object as {@link PopClip.input}.)
|
|
151
|
+
* @param options Current values of the options for this extension. (Same object as {@link PopClip.options}.)
|
|
152
|
+
* @param context Information about the context surrounding the selection. (Same object as {@link PopClip.context}.)
|
|
153
|
+
* @returns A single action, an array of actions.
|
|
154
|
+
*/
|
|
155
|
+
declare type PopulationFunction<CustomOptions extends Options = Options> = (
|
|
156
|
+
input: Input,
|
|
157
|
+
options: CustomOptions,
|
|
158
|
+
context: Context,
|
|
159
|
+
) => (Action | ActionFunction)[] | Action | ActionFunction | void;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Object returned by {@link Extension.auth} when there is an authentication flow to kick off
|
|
163
|
+
*/
|
|
164
|
+
declare type AuthFlowFunction = (
|
|
165
|
+
url: string,
|
|
166
|
+
params?: { [key: string]: string | undefined },
|
|
167
|
+
expect?: string[],
|
|
168
|
+
) => Promise<any>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Credentials used in auth function
|
|
172
|
+
* */
|
|
173
|
+
declare interface AuthInfo {
|
|
174
|
+
/** Value of `username` option (will be empty string if none defined) */
|
|
175
|
+
username: string;
|
|
176
|
+
/** Value of `password` option (will be empty string if none defined) */
|
|
177
|
+
password: string;
|
|
178
|
+
/** An appropriate value to use as the redirection URL in authorization flows for this extension.
|
|
179
|
+
* Example output:
|
|
180
|
+
* `http://localhost:58906/callback/com.pilotmoon.popclip.extension.todoist/auth`
|
|
181
|
+
*/
|
|
182
|
+
redirect: string;
|
|
183
|
+
/** Extension display name */
|
|
184
|
+
name: string;
|
|
185
|
+
/** Extension identifier */
|
|
186
|
+
identifier: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Function signature of the {@link Extension.auth} method.
|
|
191
|
+
*/
|
|
192
|
+
declare type AuthFunction = (
|
|
193
|
+
info: AuthInfo,
|
|
194
|
+
flow: AuthFlowFunction,
|
|
195
|
+
) => Promise<string>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Properties that define how an icon is interpreted.
|
|
199
|
+
*/
|
|
200
|
+
declare interface IconProperties {
|
|
201
|
+
/**
|
|
202
|
+
* If true, the supplied icon will be displayed with its original color instead of being filled in white/black. Default is false.
|
|
203
|
+
*/
|
|
204
|
+
preserveColor?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* If true, the supplied icon will be displayed with its original aspect ratio instead of being scaled to fit a square. Default is false.
|
|
207
|
+
*/
|
|
208
|
+
preserveAspect?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* If true, the supplied icon will be drawn horizontally flipped. Default is false.
|
|
211
|
+
*/
|
|
212
|
+
flipX?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* If true, the supplied icon will be drawn vertically flipped. Default is false.
|
|
215
|
+
*/
|
|
216
|
+
flipY?: boolean;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Move the icon horizontally by the specified distance, expressed as percentage of the icon's width.
|
|
220
|
+
*/
|
|
221
|
+
moveX?: number;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Move the icon vertically by the specified distance, expressed as percentage of the icon's height.
|
|
225
|
+
*/
|
|
226
|
+
moveY?: number;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Scale the icon by the specified factor, expressed as a percentage of the original size.
|
|
230
|
+
*/
|
|
231
|
+
scale?: number;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Rotate the icon anticlockwise by the specified angle, expressed in degrees.
|
|
235
|
+
*/
|
|
236
|
+
rotate?: number;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
Draw the icon inside a square.
|
|
240
|
+
*/
|
|
241
|
+
square?: boolean;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Draw the icon inside a circle.
|
|
245
|
+
*/
|
|
246
|
+
circle?: boolean;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Draw the icon inside a magnifying glass shape.
|
|
250
|
+
*/
|
|
251
|
+
search?: boolean;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Draw a strike-through line over the icon.
|
|
255
|
+
*/
|
|
256
|
+
strike?: boolean;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Draw the enclosing shape as a solid shape.
|
|
260
|
+
*/
|
|
261
|
+
filled?: boolean;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* For text icons only. Draw the text using a monospaced font.
|
|
265
|
+
*/
|
|
266
|
+
monospaced?: boolean;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Properties common to Action and Extension
|
|
271
|
+
*/
|
|
272
|
+
declare interface ActionProperties extends IconProperties {
|
|
273
|
+
/**
|
|
274
|
+
* A unique identifying string. An identifier for an action can be any string of your choosing.
|
|
275
|
+
*/
|
|
276
|
+
identifier?: string;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The action's title.
|
|
280
|
+
*
|
|
281
|
+
* If no title is defined here, the extension's [`[name]] will be used, if any.
|
|
282
|
+
*/
|
|
283
|
+
title?: LocalizableString;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* A string to define the action's icon.
|
|
287
|
+
*
|
|
288
|
+
* If no icon is defined here, the extension's {@link Extension.icon | icon} will be used, if any.
|
|
289
|
+
* Setting to `null` explicitly sets the action to have no icon.
|
|
290
|
+
*/
|
|
291
|
+
icon?: string | null;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* An array of conditions which must be met for this action to appear — see {@link Requirement}.
|
|
295
|
+
*
|
|
296
|
+
* * If no array is specified here, the action takes the value of {@link Extension.requirements}.
|
|
297
|
+
* * If no array is specified there either, the action takes the default value `["text"]`.
|
|
298
|
+
*
|
|
299
|
+
* #### Notes
|
|
300
|
+
*
|
|
301
|
+
* When multiple conditions are specified, all of them must be satisfied.
|
|
302
|
+
*
|
|
303
|
+
* An empty array (`[]`) indicates no requirements at all, meaning the action will always appear.
|
|
304
|
+
*
|
|
305
|
+
* This property has no effect on dynamically generated actions.
|
|
306
|
+
*/
|
|
307
|
+
requirements?: Array<Requirement | NegatedRequirement>;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Array of bundle identifiers for which the extension should appear. The action will only
|
|
311
|
+
* appear if PopCLip is used in one of the specified apps.
|
|
312
|
+
*
|
|
313
|
+
* This property has no effect on dynamically generated actions.
|
|
314
|
+
*/
|
|
315
|
+
requiredApps?: string[];
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Array of bundle identifiers for which the extension should not appear. The action will not
|
|
319
|
+
* appear if PopClip is used in any of the specified apps.
|
|
320
|
+
*
|
|
321
|
+
* This property has no effect on dynamically generated actions.
|
|
322
|
+
*/
|
|
323
|
+
excludedApps?: string[];
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* A regular expression to decide whether this action appears in the popup.
|
|
327
|
+
*
|
|
328
|
+
* * If no regex is specified here, the action takes the value of {@link Extension.regex}.
|
|
329
|
+
* * If no regex is specified there either, the action will match any input.
|
|
330
|
+
*
|
|
331
|
+
* #### Notes
|
|
332
|
+
*
|
|
333
|
+
* You may express the value either as a
|
|
334
|
+
* [JavaScript regular expression literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
|
|
335
|
+
* (or otherwise constructed `RegExp` object), or as a string.
|
|
336
|
+
*
|
|
337
|
+
* * If you supply a `RegExp` it will be evaluated in the JavaScript engine.
|
|
338
|
+
* * If you supply a string it will be evaluated by macOS natively using the `NSRegularExpression` API (same as for 'classic' PopClip extensions).
|
|
339
|
+
*
|
|
340
|
+
* If the regex matches the selected text, the action will be shown in the popup and
|
|
341
|
+
* the first occurrence of the matched text is accessible later via {@link Input.matchedText | matchedText}.
|
|
342
|
+
*
|
|
343
|
+
* If there is no match, the action is excluded from the popup.
|
|
344
|
+
*
|
|
345
|
+
* The regex's `lastIndex` is reset before and after each invocation, so the `g` (global) and `y` (sticky) flags have no effect.
|
|
346
|
+
*
|
|
347
|
+
* This property has no effect on dynamically generated actions.
|
|
348
|
+
*
|
|
349
|
+
* #### Example
|
|
350
|
+
* ```js
|
|
351
|
+
* regex = /abc/i // Example regex 'abc' with 'i' (case insensitive) flag
|
|
352
|
+
* // Matches abc, ABC, Abc, etc.
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
regex?: RegExp | string;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Declares the application or website associated with this action, if any.
|
|
359
|
+
*/
|
|
360
|
+
app?: AssociatedApp;
|
|
361
|
+
apps?: AssociatedApp[];
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* An optional step to peform before the main action.
|
|
365
|
+
*/
|
|
366
|
+
before?: BeforeStep;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* An optional step to peform after the main action.
|
|
370
|
+
*/
|
|
371
|
+
after?: AfterStep;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Whether PopClip will capture HTML and Markdown content for the selection. Default is no.
|
|
375
|
+
*/
|
|
376
|
+
captureHtml?: boolean;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Whether PopClip will capture RTF (Rich Text Format) content for the selection. Default is no.
|
|
380
|
+
*/
|
|
381
|
+
captureRtf?: boolean;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Whether PopClip's popup should stay on screen after clicking this action's button. Default is no.
|
|
385
|
+
*/
|
|
386
|
+
stayVisible?: boolean;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Whether the pasteboard should be restored to its original state after `paste-result`.
|
|
390
|
+
*/
|
|
391
|
+
restorePasteboard?: boolean;
|
|
392
|
+
|
|
393
|
+
// static properties for benefit of JSON Schema
|
|
394
|
+
shortcutName?: string;
|
|
395
|
+
serviceName?: string;
|
|
396
|
+
url?: string;
|
|
397
|
+
keyCombo?: string | number;
|
|
398
|
+
keyCombos?: Array<string | number>;
|
|
399
|
+
applescript?: string;
|
|
400
|
+
applescriptFile?: string;
|
|
401
|
+
applescriptCall?: {
|
|
402
|
+
handler: string;
|
|
403
|
+
parameters?: string[];
|
|
404
|
+
};
|
|
405
|
+
shellScript?: string;
|
|
406
|
+
shellScriptFile?: string;
|
|
407
|
+
interpreter?: string;
|
|
408
|
+
javascript?: string;
|
|
409
|
+
javascriptFile?: string;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* An action function is called when the user clicks the action button in PopClip. This is where
|
|
414
|
+
* the extension does its main work.
|
|
415
|
+
* @param input The selected text and related properties. (Same object as {@link PopClip.input}.)
|
|
416
|
+
* @param options Current values of the options for this extension. (Same object as {@link PopClip.options}.)
|
|
417
|
+
* @param context Information about the context surrounding the selection. (Same object as {@link PopClip.context}.)
|
|
418
|
+
*/
|
|
419
|
+
declare type ActionFunction<CustomOptions extends Options = Options> = (
|
|
420
|
+
input: Input,
|
|
421
|
+
options: CustomOptions & AuthOptions,
|
|
422
|
+
context: Context,
|
|
423
|
+
) => Promise<string | void> | string | void;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* **Action** represents the properties of a single action.
|
|
427
|
+
* If `code` is omitted, the action displays a disabled title/icon only.
|
|
428
|
+
*/
|
|
429
|
+
declare interface Action<CustomOptions extends Options = Options>
|
|
430
|
+
extends ActionProperties {
|
|
431
|
+
code?: ActionFunction<CustomOptions>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// included for JSON Schema
|
|
435
|
+
declare type Entitlement = "network" | "dynamic";
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* The Extension object defines the PopClip extension.
|
|
439
|
+
*/
|
|
440
|
+
declare interface Extension<CustomOptions extends Options = Options>
|
|
441
|
+
extends ActionProperties {
|
|
442
|
+
/**
|
|
443
|
+
* The display name of this extension.
|
|
444
|
+
*/
|
|
445
|
+
name?: LocalizableString;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Defines the user-configurable options for this extension.
|
|
449
|
+
*/
|
|
450
|
+
options?: Option[];
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* If you define this function then PopClip will display a 'sign in' button in the options UI. When the user clicks the button,
|
|
454
|
+
* PopClip will call this function with an `info` object and an `flow` callback.
|
|
455
|
+
*
|
|
456
|
+
* If the sign in needs a username and password, you'll also need to define `username` and `password` options. PopClip will then pass the values
|
|
457
|
+
* of those options in the info parameter. */
|
|
458
|
+
auth?: AuthFunction;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Define the actions to go in PopClip's popup. This can be an array or a function.
|
|
462
|
+
*
|
|
463
|
+
* - If it's an array, the supplied actions are used in the popup, subject to meeting the
|
|
464
|
+
* requirements and regex conditions.
|
|
465
|
+
*
|
|
466
|
+
* - If it's a population function, it is called by PopClip to dynamically populate the popup with actions from this extension.
|
|
467
|
+
* Setting requirements and regex keys has no effect on dynamic actions — the function itself is responsible for deciding what actions to show.
|
|
468
|
+
* Population function requires the `dynamic` entitlement.
|
|
469
|
+
*/
|
|
470
|
+
actions?:
|
|
471
|
+
| (Action<CustomOptions> | ActionFunction<CustomOptions>)[]
|
|
472
|
+
| PopulationFunction<CustomOptions>;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Simplified property to define a single action.
|
|
476
|
+
*/
|
|
477
|
+
action?: Action<CustomOptions> | ActionFunction<CustomOptions>;
|
|
478
|
+
|
|
479
|
+
// the following are static properties, included for the benefit of the JSON Scheme generation
|
|
480
|
+
popclipVersion?: number;
|
|
481
|
+
macosVersion?: string;
|
|
482
|
+
entitlements?: Entitlement[];
|
|
483
|
+
module?: string;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Defines a single extension option.
|
|
488
|
+
*/
|
|
489
|
+
declare interface Option {
|
|
490
|
+
/**
|
|
491
|
+
* An identifying string for this option.
|
|
492
|
+
*/
|
|
493
|
+
identifier: string;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The kind of option, one of:
|
|
497
|
+
* * `string`: a text box for free text entry,
|
|
498
|
+
* * `boolean`: a check box,
|
|
499
|
+
* * `multiple`: multiple-choice drop-down with predefined options,
|
|
500
|
+
* * `secret`: concealed text entry field (persisted in user's keychain),
|
|
501
|
+
* * `password`: concealed text entry field (not persisted, only passed to auth function),
|
|
502
|
+
* * `heading`: adds a heading in the user interface, but does not actually define an option
|
|
503
|
+
*/
|
|
504
|
+
type: "string" | "boolean" | "multiple" | "password" | "heading" | "secret";
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* A short label for this option.
|
|
508
|
+
*/
|
|
509
|
+
label?: LocalizableString;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* An optional longer explanantion of this option, to be shown in the UI.
|
|
513
|
+
*/
|
|
514
|
+
description?: LocalizableString;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* The default value of the option. If ommitted, `string` options default to the empty string,
|
|
518
|
+
* `boolean` options default to true, and `multiple` options default to the top item in the list.
|
|
519
|
+
* A `password` field may not have a default value.
|
|
520
|
+
*/
|
|
521
|
+
defaultValue?: string | boolean;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The possible values for a `multiple` option.
|
|
525
|
+
*/
|
|
526
|
+
values?: string[];
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Display names corresponding to the entries in the {@link values} array. These are shown in the option UI.
|
|
530
|
+
* If ommitted, the raw value strings are shown instead.
|
|
531
|
+
*/
|
|
532
|
+
valueLabels?: LocalizableString[];
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* An icon for this option. It is only displayed for boolean options, next to the check box.
|
|
536
|
+
*/
|
|
537
|
+
icon?: string;
|
|
538
|
+
|
|
539
|
+
/*
|
|
540
|
+
* If true, this option will be hidden in the prefs window. Default is false.
|
|
541
|
+
*/
|
|
542
|
+
hidden?: boolean;
|
|
543
|
+
|
|
544
|
+
/*
|
|
545
|
+
* If true, this option will be be inset to the right of its label, instead of below it. Default is false.
|
|
546
|
+
*/
|
|
547
|
+
inset?: boolean;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Represents a generic range, as a location and length
|
|
552
|
+
*/
|
|
553
|
+
declare interface Range {
|
|
554
|
+
location: number;
|
|
555
|
+
length: number;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* An array of strings with an addiontal `ranges` property defining the source of the data in the orignal string.
|
|
560
|
+
*/
|
|
561
|
+
declare interface RangedStrings extends Array<string> {
|
|
562
|
+
ranges: Range[];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Input defines properties to access the input text contents.
|
|
567
|
+
*/
|
|
568
|
+
declare interface Input {
|
|
569
|
+
/**
|
|
570
|
+
* The plain text selected by the user. If there is no selected text, this will be the empty string.
|
|
571
|
+
*/
|
|
572
|
+
text: string;
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* If the action specified {@link Action.requirements} or a {@link Action.regex} to match the input, this will be the matching part of the text.
|
|
576
|
+
* Otherwise, it will be the same string as {@link text}.
|
|
577
|
+
*/
|
|
578
|
+
matchedText: string;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* If the action specified a {@link Action.regex | regex} to match the input, this will be the result of the the match.
|
|
582
|
+
*
|
|
583
|
+
* You can use this to access any capture groups from the regex.
|
|
584
|
+
*
|
|
585
|
+
* If the regex was specified as a JavaScript regex, the value is a return value from JavaScript's
|
|
586
|
+
* [RegExp.prototype.exec()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method.
|
|
587
|
+
*
|
|
588
|
+
* If the regex was specified as an ICU regex in the static config, the value is the array of capture components.
|
|
589
|
+
*
|
|
590
|
+
* #### Example
|
|
591
|
+
* ```js
|
|
592
|
+
* // text: "apple", regex: /.(.)/
|
|
593
|
+
* selection.regexResult[0] // "ap" (full match)
|
|
594
|
+
* selection.regexResult[1] // "p" (capture group 1)
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
regexResult?: RegExpMatchArray | string[] | null;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* HTML content (if `captureHtml` is true).
|
|
601
|
+
*/
|
|
602
|
+
html: string;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* XHTML content (if `captureHtml` is true).
|
|
606
|
+
*/
|
|
607
|
+
xhtml: string;
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Markdown content (if `captureHtml` is true).
|
|
611
|
+
*/
|
|
612
|
+
markdown: string;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* RTF content (if `captureRtf` is true).
|
|
616
|
+
*/
|
|
617
|
+
rtf: string;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Data of various kinds, that PopClip detected in the selected text.
|
|
621
|
+
*/
|
|
622
|
+
data: {
|
|
623
|
+
/**
|
|
624
|
+
* HTTP ot HTTPS urls.
|
|
625
|
+
*/
|
|
626
|
+
urls: RangedStrings;
|
|
627
|
+
/**
|
|
628
|
+
* Other protocols or app urls e.g. `ftp:`, `omnifocus:`, `craftdocs:` etc. (PopClip has a pre-defined allowlist
|
|
629
|
+
* for custom URL schemes.)
|
|
630
|
+
*/
|
|
631
|
+
nonHttpUrls: RangedStrings;
|
|
632
|
+
/**
|
|
633
|
+
* Email addresses.
|
|
634
|
+
*/
|
|
635
|
+
emails: RangedStrings;
|
|
636
|
+
/**
|
|
637
|
+
* Local file paths.
|
|
638
|
+
* */
|
|
639
|
+
paths: RangedStrings;
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Unprocessed selection contents indexed by UTI.
|
|
644
|
+
*/
|
|
645
|
+
content: PasteboardContent;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
Indicate if the text content is *just* a web URL (or URL-like string
|
|
649
|
+
such as `popclip.app`), allowing for leading and trailing whitespace.
|
|
650
|
+
*/
|
|
651
|
+
isUrl: boolean;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Properties relating the context surrounding the selected text.
|
|
656
|
+
*/
|
|
657
|
+
declare interface Context {
|
|
658
|
+
/**
|
|
659
|
+
* Indicates whether the text area supports formatting.
|
|
660
|
+
*/
|
|
661
|
+
hasFormatting: boolean;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* This property is true iff the Paste command is enabled in the current app.
|
|
665
|
+
*/
|
|
666
|
+
canPaste: boolean;
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* This property is true iff text was selected.
|
|
670
|
+
*/
|
|
671
|
+
canCopy: boolean;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* This property is true iff text was selected and the app's Cut command is enabled.
|
|
675
|
+
*/
|
|
676
|
+
canCut: boolean;
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* If the current app is a compatible browser, this will be the page URL.
|
|
680
|
+
*/
|
|
681
|
+
browserUrl: string;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* If the current app is a compatible browser, this will be the page title.
|
|
685
|
+
*/
|
|
686
|
+
browserTitle: string;
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* The name of the current app, for example `Drafts`.
|
|
690
|
+
*/
|
|
691
|
+
appName: string;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The bundle identitifier of the current app, for example `com.agiletortoise.Drafts-OSX`.
|
|
695
|
+
*/
|
|
696
|
+
appIdentifier: string;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Represents the current values of the extension's settings.
|
|
701
|
+
*/
|
|
702
|
+
declare interface Options {
|
|
703
|
+
readonly [identifier: string]: string | boolean;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* The `authsecret` property has the special behaviour of throwing an `Error` with the message 'Not signed in' if it is accessed while either
|
|
708
|
+
* undefined or holding an empty string.
|
|
709
|
+
*/
|
|
710
|
+
declare interface AuthOptions {
|
|
711
|
+
/**
|
|
712
|
+
* The stored value that was returned from the `auth()` function.
|
|
713
|
+
*/
|
|
714
|
+
authsecret: string;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* This interface describes the methods and properties of the global {@link popclip} object.
|
|
719
|
+
*
|
|
720
|
+
*/
|
|
721
|
+
declare interface PopClip {
|
|
722
|
+
/**
|
|
723
|
+
* The state of the modifier keys when the action was invoked in PopClip.
|
|
724
|
+
*
|
|
725
|
+
* #### Notes
|
|
726
|
+
* During the execution of the population function, all the modifiers will read as false.
|
|
727
|
+
*/
|
|
728
|
+
readonly modifiers: Modifiers;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* The current selection.
|
|
732
|
+
*/
|
|
733
|
+
readonly input: Input;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* The current context.
|
|
737
|
+
*/
|
|
738
|
+
readonly context: Context;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* The current values of the options.
|
|
742
|
+
*/
|
|
743
|
+
readonly options: Options & AuthOptions;
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* If the target app's Paste command is available, this method places the given string on the pasteboard
|
|
747
|
+
* and then invokes the target app's Paste comand. If the `restore` flag is set in the options, it will
|
|
748
|
+
* then restore the original pasteboard contents.
|
|
749
|
+
*
|
|
750
|
+
* If the target app's Paste command is not available, it behaves as {@link copyText} instead.
|
|
751
|
+
*
|
|
752
|
+
* #### Example
|
|
753
|
+
*
|
|
754
|
+
* ```js
|
|
755
|
+
* // place "Hello" on the clipboard and invoke Paste
|
|
756
|
+
* popclip.pasteText("Hello");
|
|
757
|
+
* // place "Hello", then restore the original pasteboard contents
|
|
758
|
+
* popclip.pasteText("Hello", {restore: true});
|
|
759
|
+
* ```
|
|
760
|
+
* @param text The plain text string to paste
|
|
761
|
+
* @param options
|
|
762
|
+
*/
|
|
763
|
+
pasteText: (text: string, options?: PasteOptions) => void;
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Paste arbitrary pasteboard content.
|
|
767
|
+
*/
|
|
768
|
+
pasteContent: (content: PasteboardContent, options?: PasteOptions) => void;
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Places the given string on the pasteboard, and shows "Copied" notificaction to the user.
|
|
772
|
+
* @param text The plain text string to copy
|
|
773
|
+
*/
|
|
774
|
+
copyText: (text: string) => void;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Copy arbitrary pasteboard content.
|
|
778
|
+
*/
|
|
779
|
+
copyContent: (content: PasteboardContent) => void;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Invokes a command in the target app.
|
|
783
|
+
* @param command Either `cut`, `copy` or `paste`.
|
|
784
|
+
* @param options Options for the command.
|
|
785
|
+
*/
|
|
786
|
+
performCommand: (
|
|
787
|
+
command: "cut" | "copy" | "paste",
|
|
788
|
+
options?: {
|
|
789
|
+
/** Transformation to apply to the pasteboard contents. (Default: `none`)
|
|
790
|
+
* - `none`: regular pasteboard operation
|
|
791
|
+
* - `plain`: strips away everything but plain text
|
|
792
|
+
*/
|
|
793
|
+
transform?: "none" | "plain";
|
|
794
|
+
},
|
|
795
|
+
) => void;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Display text inside PopClip's popup, with option to make the display a clickable button to
|
|
799
|
+
* paste the text.
|
|
800
|
+
* @param text The text to display. It will be truncated to 160 characters when shown.
|
|
801
|
+
* @param options
|
|
802
|
+
*/
|
|
803
|
+
showText: (
|
|
804
|
+
text: string,
|
|
805
|
+
options?: {
|
|
806
|
+
/**
|
|
807
|
+
* If `true`, and the app's Paste command is available, the displayed text will be in a cickable button,
|
|
808
|
+
* which clicked, pastes the full text.
|
|
809
|
+
*/
|
|
810
|
+
preview?: boolean;
|
|
811
|
+
},
|
|
812
|
+
) => void;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* PopClip will show a checkmark symbol to indicate success.
|
|
816
|
+
*/
|
|
817
|
+
showSuccess: () => void;
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* PopClip will show an "X" symbol to indicate failure.
|
|
821
|
+
*/
|
|
822
|
+
showFailure: () => void;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* PopClip will open the settings UI for this extension.
|
|
826
|
+
*
|
|
827
|
+
* #### Notes
|
|
828
|
+
* If the extension has no settings, this method does nothing.
|
|
829
|
+
*/
|
|
830
|
+
showSettings: () => void;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Trigger PopClip to appear again with the current selection.
|
|
834
|
+
*/
|
|
835
|
+
appear: () => void;
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Simulate a key press by the user.
|
|
839
|
+
*
|
|
840
|
+
* #### Examples
|
|
841
|
+
*
|
|
842
|
+
* ```js
|
|
843
|
+
* // press the key combo ⌘B
|
|
844
|
+
* popclip.pressKey('command B');
|
|
845
|
+
* // press the key combo ⌥⌘H
|
|
846
|
+
* popclip.pressKey('option command H');
|
|
847
|
+
* // press the return key
|
|
848
|
+
* popclip.pressKey('return');
|
|
849
|
+
* popclip.pressKey(util.constant.KEY_RETURN); // equivalent
|
|
850
|
+
* * // press option and the page down key
|
|
851
|
+
* popclip.pressKey('option 0x79');
|
|
852
|
+
* popclip.pressKey(0x79, util.constant.MODIFIER_OPTION); // equivalent
|
|
853
|
+
* ```
|
|
854
|
+
*
|
|
855
|
+
* #### Notes
|
|
856
|
+
*
|
|
857
|
+
* Some key code and modifier constants are available in {@link Util.constant | util.constant}.
|
|
858
|
+
*
|
|
859
|
+
* @param key The key to press. When this parameter is a string, PopClip will interpret it as in
|
|
860
|
+
* [Key Press actions](https://www.popclip.app/dev/key-press-actions).
|
|
861
|
+
* When this parameter is a number, PopClip will use that exact key code.
|
|
862
|
+
*
|
|
863
|
+
* @param modifiers An optional bit mask specifiying additional modifier keys, if any.
|
|
864
|
+
*/
|
|
865
|
+
pressKey: (key: string | number, modifiers?: number) => void;
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Open a URL in an application.
|
|
869
|
+
*
|
|
870
|
+
* #### Choice of application
|
|
871
|
+
*
|
|
872
|
+
* If a target application bundle identifier is specified via the `app` option, PopClip will ask that app to open the URL.
|
|
873
|
+
*
|
|
874
|
+
* If no target app is specified:
|
|
875
|
+
*
|
|
876
|
+
* - If the URL has the http or https scheme, and the current app is a browser, the URL is opened in the current app.
|
|
877
|
+
* - Otherwise, PopClip asks macOS to open the URL in the default handler for that URL type.
|
|
878
|
+
*
|
|
879
|
+
* #### URL encoding
|
|
880
|
+
*
|
|
881
|
+
* Any parameters etc. in the URL must be appropriately percent-encoded. JavaScript provides the
|
|
882
|
+
* [encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
|
|
883
|
+
* function for this.
|
|
884
|
+
*
|
|
885
|
+
* #### Example
|
|
886
|
+
* ```js
|
|
887
|
+
* popclip.openUrl("https://xkcd.com"); // open xckd.com in current/default browser
|
|
888
|
+
* popclip.openUrl("https://xkcd.com", {app: "com.brave.Browser"}); // open xkcd.com in Brave browser
|
|
889
|
+
* popclip.openUrl(`mailto:support@pilotmoon.com?subject=${encodeURIComponent("What's up?")}`); // open mailto link in the default mail application
|
|
890
|
+
* ```
|
|
891
|
+
*
|
|
892
|
+
* @param url A well-formed URL
|
|
893
|
+
* @param options Options.
|
|
894
|
+
*/
|
|
895
|
+
openUrl: (
|
|
896
|
+
url: string,
|
|
897
|
+
options?: {
|
|
898
|
+
/**
|
|
899
|
+
* Bundle identifier of the app to open the URL with. For example `"com.google.Chrome"`.
|
|
900
|
+
*/
|
|
901
|
+
app?: string;
|
|
902
|
+
},
|
|
903
|
+
) => void;
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Share items with a named macOS sharing service.
|
|
907
|
+
*
|
|
908
|
+
* #### Example
|
|
909
|
+
* ```js
|
|
910
|
+
* // share a string with the Messages service
|
|
911
|
+
* popclip.share("com.apple.share.Messages.window", ["Hello, world!"]);
|
|
912
|
+
* // share a URL with the Safari Reading List service
|
|
913
|
+
* popclip.share("com.apple.share.System.add-to-safari-reading-list", [{ url: "https://example.com" }]);
|
|
914
|
+
* // share a an html string with the Notes service
|
|
915
|
+
* const item = new RichString("Some <b>simple</b> html", { format: html })
|
|
916
|
+
* popclip.share("com.apple.Notes.SharingExtension", [item]);
|
|
917
|
+
* ```
|
|
918
|
+
*
|
|
919
|
+
* #### Notes
|
|
920
|
+
*
|
|
921
|
+
* The list of available sharing services is determined by the user's system configuration.
|
|
922
|
+
*
|
|
923
|
+
* @param serviceName The name of the sharing service to use.
|
|
924
|
+
* @param items An array of items to share. Each item can be a string, a {@link RichString} object, or an object with a `url` property.
|
|
925
|
+
* @throws If the service name is not recognized, or if the service cannot handle the supplied items, an error is thrown.
|
|
926
|
+
*/
|
|
927
|
+
share: (
|
|
928
|
+
serviceName: string,
|
|
929
|
+
items: (string | RichString | { url: string })[],
|
|
930
|
+
) => void;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* The global `popclip` object encapsulates the user's current interaction with PopClip, and provides methods
|
|
935
|
+
* for performing various actions. It implements {@link PopClip}.
|
|
936
|
+
*/
|
|
937
|
+
declare const popclip: PopClip;
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Represents a formatted text string. The underlying implementation uses a macOS Attributed String (`NSAttributedString`) object.
|
|
941
|
+
* Can be constructed from a plain string in RTF, HTML, or Markdown format.
|
|
942
|
+
*
|
|
943
|
+
* #### Example
|
|
944
|
+
* ```js
|
|
945
|
+
* // create a RichString object from a html string
|
|
946
|
+
* const item = new RichString("<b>bold</b> and <i>italic</i>.", {format: 'html'});
|
|
947
|
+
* // create a RichString object from a markdown string
|
|
948
|
+
* const item = new RichString("# Title\n\nBody.", {format: 'markdown'});
|
|
949
|
+
* ```
|
|
950
|
+
*/
|
|
951
|
+
declare class RichString {
|
|
952
|
+
/**
|
|
953
|
+
* Create a new RichString object from a string.
|
|
954
|
+
*
|
|
955
|
+
* @param source The string to convert to a RichString object.
|
|
956
|
+
* @param options Options for the conversion.
|
|
957
|
+
*/
|
|
958
|
+
constructor(
|
|
959
|
+
source: string,
|
|
960
|
+
options?: {
|
|
961
|
+
/**
|
|
962
|
+
Format of the source string. Default is 'rtf'.
|
|
963
|
+
*/
|
|
964
|
+
format?: "rtf" | "html" | "markdown";
|
|
965
|
+
},
|
|
966
|
+
);
|
|
967
|
+
/**
|
|
968
|
+
* An RTF representation of the content.
|
|
969
|
+
*/
|
|
970
|
+
readonly rtf: string;
|
|
971
|
+
/**
|
|
972
|
+
* An HTML representation of the content.
|
|
973
|
+
*/
|
|
974
|
+
readonly html: string;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* A container for various utility functions and constants {@link util} object.
|
|
979
|
+
*/
|
|
980
|
+
declare interface Util {
|
|
981
|
+
/**
|
|
982
|
+
* Localize an English string into the current user interface language, if possible.
|
|
983
|
+
* This will work for strings which match an existing string in PopClip's user interface.
|
|
984
|
+
*
|
|
985
|
+
* @param string The string to localize.
|
|
986
|
+
* @return The localized string, or the original string if no localized version was avaiable.
|
|
987
|
+
*/
|
|
988
|
+
localize: (string: string) => string;
|
|
989
|
+
|
|
990
|
+
localeInfo: {
|
|
991
|
+
localeIdentifier: string;
|
|
992
|
+
regionCode: string;
|
|
993
|
+
languageCode: string;
|
|
994
|
+
decimalSeparator: string;
|
|
995
|
+
groupingSeparator: string;
|
|
996
|
+
currencyCode: string;
|
|
997
|
+
currencySymbol: string;
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
timeZoneInfo: {
|
|
1001
|
+
identifier: string;
|
|
1002
|
+
abbreviation: string;
|
|
1003
|
+
secondsOffset: number;
|
|
1004
|
+
daylightSaving: boolean;
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
htmlToRtf: (html: string) => string | undefined;
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Encode a string as UTF-8 then Base-64 encode the result.
|
|
1011
|
+
*
|
|
1012
|
+
* @param string The string to encode.
|
|
1013
|
+
* @param options
|
|
1014
|
+
*/
|
|
1015
|
+
base64Encode: (
|
|
1016
|
+
string: string,
|
|
1017
|
+
options?: {
|
|
1018
|
+
/**
|
|
1019
|
+
* Whether to encode using the URL-safe variant, with `-` and `_` substituted for `+` and `/`. Default is no.
|
|
1020
|
+
*/
|
|
1021
|
+
urlSafe?: boolean;
|
|
1022
|
+
/**
|
|
1023
|
+
* Whether to trim the `=`/`==` padding from the string. Default is no.
|
|
1024
|
+
*/
|
|
1025
|
+
trimmed?: boolean;
|
|
1026
|
+
},
|
|
1027
|
+
) => string;
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Decode a Base-64 string and interpret the result as a UTF-8 string.
|
|
1031
|
+
*
|
|
1032
|
+
* Accepts both standard and URL-safe variants as input. Also accepts input with or without the `=`/`==` end padding.
|
|
1033
|
+
* Throws an error if the input cannot be decoded as a UTF-8 string.
|
|
1034
|
+
*
|
|
1035
|
+
* @param string
|
|
1036
|
+
* @returns The decoded string
|
|
1037
|
+
*/
|
|
1038
|
+
base64Decode: (string: string) => string;
|
|
1039
|
+
|
|
1040
|
+
/** Build a URL from a base URL and additional query parameters */
|
|
1041
|
+
buildQueryUrl: (baseUrl: string, params: { [key: string]: string }) => string;
|
|
1042
|
+
|
|
1043
|
+
/** Build a query from params object */
|
|
1044
|
+
buildQuery: (params: { [key: string]: string }) => string;
|
|
1045
|
+
|
|
1046
|
+
/** Parse a query into params object */
|
|
1047
|
+
parseQuery: (query: string) => any;
|
|
1048
|
+
|
|
1049
|
+
/** Decipher a JSON object that has been lightly obscured to prevent constants such as
|
|
1050
|
+
* API keys appearing in plaintext in the source files.
|
|
1051
|
+
*
|
|
1052
|
+
* This function will ROT13 decipher the text, apply Base64 decoding, and parse the result as JSON. */
|
|
1053
|
+
clarify: (obscuredString: string) => any;
|
|
1054
|
+
|
|
1055
|
+
// same as global sleep()
|
|
1056
|
+
sleep: (durationMilliseconds: number) => Promise<void>;
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* The `constant` property is a container for pre-defined constants.
|
|
1060
|
+
*/
|
|
1061
|
+
readonly constant: {
|
|
1062
|
+
/**
|
|
1063
|
+
* Bit mask for the Shift (⇧) key.
|
|
1064
|
+
*/
|
|
1065
|
+
readonly MODIFIER_SHIFT: 131072;
|
|
1066
|
+
/**
|
|
1067
|
+
* Bit mask for the Control (⌃) key.
|
|
1068
|
+
*/
|
|
1069
|
+
readonly MODIFIER_CONTROL: 262144;
|
|
1070
|
+
/**
|
|
1071
|
+
* Bit mask for the Option (⌥) key.
|
|
1072
|
+
*/
|
|
1073
|
+
readonly MODIFIER_OPTION: 524288;
|
|
1074
|
+
/**
|
|
1075
|
+
* Bit mask for the Command (⌘) key.
|
|
1076
|
+
*/
|
|
1077
|
+
readonly MODIFIER_COMMAND: 1048576;
|
|
1078
|
+
/**
|
|
1079
|
+
* Key code for the Return (↵) key.
|
|
1080
|
+
*/
|
|
1081
|
+
readonly KEY_RETURN: 0x24;
|
|
1082
|
+
/**
|
|
1083
|
+
* Key code for the Tab (⇥) key.
|
|
1084
|
+
*/
|
|
1085
|
+
readonly KEY_TAB: 0x30;
|
|
1086
|
+
/**
|
|
1087
|
+
* Key code for the space bar.
|
|
1088
|
+
*/
|
|
1089
|
+
readonly KEY_SPACE: 0x31;
|
|
1090
|
+
/**
|
|
1091
|
+
* Key code for the Delete (⌫) key.
|
|
1092
|
+
*/
|
|
1093
|
+
readonly KEY_DELETE: 0x33;
|
|
1094
|
+
/**
|
|
1095
|
+
* Key code for the Escape key.
|
|
1096
|
+
*/
|
|
1097
|
+
readonly KEY_ESCAPE: 0x35;
|
|
1098
|
+
/**
|
|
1099
|
+
* Key code for the Left Arrow key.
|
|
1100
|
+
*/
|
|
1101
|
+
readonly KEY_LEFTARROW: 0x7b;
|
|
1102
|
+
/**
|
|
1103
|
+
* Key code for the Right Arrow key.
|
|
1104
|
+
*/
|
|
1105
|
+
readonly KEY_RIGHTARROW: 0x7c;
|
|
1106
|
+
/**
|
|
1107
|
+
* Key code for the Down Arrow key.
|
|
1108
|
+
*/
|
|
1109
|
+
readonly KEY_DOWNARROW: 0x7d;
|
|
1110
|
+
/**
|
|
1111
|
+
* Key code for the Up Arrow key.
|
|
1112
|
+
*/
|
|
1113
|
+
readonly KEY_UPARROW: 0x7e;
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* The global `util` object acts as a container for various utility functions and constants. It implements {@link Util}.
|
|
1119
|
+
*/
|
|
1120
|
+
declare const util: Util;
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Represents the raw pasteboard content, indexed by UTI. Supports string data only.
|
|
1124
|
+
*/
|
|
1125
|
+
declare interface PasteboardContent {
|
|
1126
|
+
"public.utf8-plain-text"?: string;
|
|
1127
|
+
"public.html"?: string;
|
|
1128
|
+
"public.rtf"?: string;
|
|
1129
|
+
[key: string]: string | undefined;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Options for Paste operations.
|
|
1134
|
+
*/
|
|
1135
|
+
declare interface PasteOptions {
|
|
1136
|
+
/**
|
|
1137
|
+
* Whether to restore the original contents of the pasteboard after the paste
|
|
1138
|
+
* operation. Default is `false`.
|
|
1139
|
+
*/
|
|
1140
|
+
restore?: boolean;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* A simplified interface to the macOS pasteboard. Implemented by the global object, {@link pasteboard}.
|
|
1145
|
+
*/
|
|
1146
|
+
declare interface Pasteboard {
|
|
1147
|
+
/**
|
|
1148
|
+
* Get and set the plain text content of the pasteboard.
|
|
1149
|
+
*
|
|
1150
|
+
* #### Notes
|
|
1151
|
+
* This property corresponds with the pasteboard type `public.utf8-plain-text`.
|
|
1152
|
+
*
|
|
1153
|
+
* When placing text on the pasteboard this way, PopClip's "Copied" notification will not appear.
|
|
1154
|
+
* (Typically, scripts should use {@link PopClip.copyText} instead, so that the user gets the "Copied" notification.)
|
|
1155
|
+
*
|
|
1156
|
+
* The value of this property will always be a string. If there is no plain text value on the
|
|
1157
|
+
* pasteboard, reading this property will give an empty string (`""`).
|
|
1158
|
+
*
|
|
1159
|
+
* #### Example
|
|
1160
|
+
* ```js
|
|
1161
|
+
* let x = pasteboard.text;
|
|
1162
|
+
* pasteboard.text = "new text";
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
text: string;
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Get and set the content of the pasteboard, of the specified types
|
|
1169
|
+
*/
|
|
1170
|
+
content: PasteboardContent;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* The global `pasteboard` object provides access to the contents of the macOS general pasteboard (i.e. the system clipboard). It implements {@link Pasteboard}.
|
|
1175
|
+
*/
|
|
1176
|
+
declare const pasteboard: Pasteboard;
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* Output a string for debugging purposes. By default it is not output anywhere, but
|
|
1180
|
+
* you can configure PopClip to output to the Console app by running the following command in Terminal:
|
|
1181
|
+
*
|
|
1182
|
+
* `defaults write com.pilotmoon.popclip EnableExtensionDebug -bool YES`
|
|
1183
|
+
*
|
|
1184
|
+
* then Quit and restart PopClip.
|
|
1185
|
+
*
|
|
1186
|
+
* #### Example
|
|
1187
|
+
* ```js
|
|
1188
|
+
* print("Hello, world!")
|
|
1189
|
+
* // print: Hello, world!
|
|
1190
|
+
* print(1, Math.PI, 2/3, ['a','b','c'])
|
|
1191
|
+
* // print: 1 3.141592653589793 0.6666666666666666 a,b,c
|
|
1192
|
+
* ```
|
|
1193
|
+
*
|
|
1194
|
+
* @param args One or more values, which will be coerced to strings. Multiple parameters will be separated by a space.
|
|
1195
|
+
*/
|
|
1196
|
+
declare function print(...args: any[]): void;
|
|
1197
|
+
|
|
1198
|
+
/*
|
|
1199
|
+
* Export an object for use by another file.
|
|
1200
|
+
*
|
|
1201
|
+
* #### Notes
|
|
1202
|
+
*
|
|
1203
|
+
* The _define_ function family exports an arbitrary object, which other files can import using {@link require}.
|
|
1204
|
+
*
|
|
1205
|
+
* It should be called only once in any file; if it is called more than once, only the
|
|
1206
|
+
* final call will have any effect.
|
|
1207
|
+
*
|
|
1208
|
+
* Partially implements AMD spec: https://github.com/amdjs/amdjs-api/wiki/AMD
|
|
1209
|
+
*
|
|
1210
|
+
* Recommendation: instead of this, use {@link defineExtension} or `module.exports = ...`.
|
|
1211
|
+
*/
|
|
1212
|
+
declare function define(object: object): void;
|
|
1213
|
+
declare function define(factory: () => object): void;
|
|
1214
|
+
declare function define(dependencies: string[], factory: () => object): void;
|
|
1215
|
+
declare function define(id: string, factory: () => object): void;
|
|
1216
|
+
declare function define(
|
|
1217
|
+
id: string,
|
|
1218
|
+
dependencies: string[],
|
|
1219
|
+
factory: () => object,
|
|
1220
|
+
): void;
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* This global function may be called as an alternative to setting `module.exports` directly.
|
|
1224
|
+
* The advantage of using `defineExtension()` is that you will automatically get type checking
|
|
1225
|
+
* and autocomplete for your extension object.
|
|
1226
|
+
*
|
|
1227
|
+
* You may define the shape of the extensions's options object by specifying the
|
|
1228
|
+
* `CustomOptions` generic type parameter. This will enable type checking and autocomplete for
|
|
1229
|
+
* the `options` parameter in action functions and the population function.
|
|
1230
|
+
*
|
|
1231
|
+
* @param extension The extension object to export.
|
|
1232
|
+
*/
|
|
1233
|
+
declare function defineExtension<CustomOptions extends Options = Options>(
|
|
1234
|
+
extension: Extension<CustomOptions>,
|
|
1235
|
+
): void;
|
|
1236
|
+
|
|
1237
|
+
/* Declare ambient module + exports for CommonJS-style exporting */
|
|
1238
|
+
declare const module: { exports: any };
|
|
1239
|
+
declare const exports: any;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Import an object from another file.
|
|
1243
|
+
*
|
|
1244
|
+
* #### Notes
|
|
1245
|
+
*
|
|
1246
|
+
* PopClip's `require()` implementation attempts to import from the following module formats:
|
|
1247
|
+
*
|
|
1248
|
+
* - AMD modules, which use `define(...)`.
|
|
1249
|
+
* - CommonJS modules, which use `module.exports = ...` or `exports.name = ...`
|
|
1250
|
+
* - TypeScript-compiled ES modules, which use `exports.default = ...`
|
|
1251
|
+
*
|
|
1252
|
+
* #### Notes
|
|
1253
|
+
*
|
|
1254
|
+
* Paths beginning with `./` or `../` are resolved relative to the the location of the current file.
|
|
1255
|
+
*
|
|
1256
|
+
* Otherwise, the path is resolved relative to the extensions's package root.
|
|
1257
|
+
* If there is no file in the extension, PopClip will look in its internal module repository.
|
|
1258
|
+
*
|
|
1259
|
+
* If no file extension is given, PopCLip will try adding the extensions `.js`, `.ts`, `.json` in that order.
|
|
1260
|
+
*
|
|
1261
|
+
* TypeScript files are transpiled to JavaScript on the fly.
|
|
1262
|
+
*
|
|
1263
|
+
* JSON files are parsed and returned as an object.å
|
|
1264
|
+
*
|
|
1265
|
+
* @param file Path to the file to import.
|
|
1266
|
+
* @return The imported object.
|
|
1267
|
+
*/
|
|
1268
|
+
declare function require(file: string): object;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* A promise-based sleep function. Included as a more convenient alternative
|
|
1272
|
+
* to {@link setTimeout} for performing simple delays. Call as `await sleep(1000)`.
|
|
1273
|
+
* @param durationMilliseconds How long to sleep in milliseconds
|
|
1274
|
+
*/
|
|
1275
|
+
declare function sleep(durationMilliseconds: number): Promise<void>;
|
|
1276
|
+
|
|
1277
|
+
/* WebAPI and Node.js Globals
|
|
1278
|
+
* The following functions and objects are available in PopClip via polyfills.
|
|
1279
|
+
*/
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Call a function after a specified time interval.
|
|
1283
|
+
*
|
|
1284
|
+
* #### Notes
|
|
1285
|
+
*
|
|
1286
|
+
* This is PopClip's own implementation of the standard
|
|
1287
|
+
* [setTimeout](http://developer.mozilla.org/en-US/docs/Web/API/SetTimeout) function,
|
|
1288
|
+
* as found in browsers.
|
|
1289
|
+
* Ordinarily you shouldn't need to use this. It is is mainly included for
|
|
1290
|
+
* compatibility with libraries that might need it.
|
|
1291
|
+
*
|
|
1292
|
+
* @param callback A function to be called after the timer expires.
|
|
1293
|
+
* @param timeout Timeout in milliseconds. If this parameter is omitted, a value of 0 is used,
|
|
1294
|
+
* @param args Additional arguments to be passed to the callback function.
|
|
1295
|
+
* @returns Numeric identifier for the timer which can be passed to {@link clearTimeout} to cancel it.
|
|
1296
|
+
*/
|
|
1297
|
+
declare function setTimeout(
|
|
1298
|
+
callback: (...args: any) => void,
|
|
1299
|
+
timeout?: number,
|
|
1300
|
+
...args: any
|
|
1301
|
+
): number;
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Cancels a timeout prevouly created with {@link setTimeout}.
|
|
1305
|
+
* @param timeoutId Identifier of the timeout to cancel.
|
|
1306
|
+
*/
|
|
1307
|
+
declare function clearTimeout(timeoutId: number): void;
|
|
1308
|
+
|
|
1309
|
+
// these are from WebAPI, and are implemented in PopClip with polyfills from `core-js` library
|
|
1310
|
+
declare function btoa(string: string): string;
|
|
1311
|
+
declare function atob(string: string): string;
|
|
1312
|
+
declare function structuredClone<T>(value: T): T;
|
|
1313
|
+
declare const URL: any;
|
|
1314
|
+
declare const URLSearchParams: any;
|
|
1315
|
+
|
|
1316
|
+
// XMLHttpRequest is implemented natively in PopClip
|
|
1317
|
+
declare const XMLHttpRequest: any;
|
|
1318
|
+
|
|
1319
|
+
// Blob is is a WebAPI object, implemented in PopClip with 'node-blob` library
|
|
1320
|
+
declare const Blob: any;
|
|
1321
|
+
|
|
1322
|
+
// Buffer is a node.js object, implemented in PopClip with 'buffer' library
|
|
1323
|
+
declare const Buffer: any;
|
|
1324
|
+
|
|
1325
|
+
// TODO: Not sure how to improve typings for these imported globals?
|