@popclip/types 1.4604.1 → 1.4624.1

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.
Files changed (2) hide show
  1. package/package.json +6 -2
  2. package/popclip.d.ts +1032 -958
package/popclip.d.ts CHANGED
@@ -6,44 +6,44 @@ This is a TypeScript definitions file for PopClip's JavaScript interface.
6
6
  * An object giving strings for the different languages PopClip supports. See {@link LocalizableString}.
7
7
  */
8
8
  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;
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
47
  }
48
48
 
49
49
  /**
@@ -70,14 +70,14 @@ type LocalizableString = string | StringTable;
70
70
  * See {@link PopClip.modifiers}.
71
71
  */
72
72
  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;
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
81
  }
82
82
 
83
83
  /**
@@ -89,16 +89,16 @@ interface Modifiers {
89
89
  * ```
90
90
  */
91
91
  type Requirement =
92
- | "text"
93
- | "cut"
94
- | "paste"
95
- | "formatting"
96
- | "url"
97
- | "urls"
98
- | "email"
99
- | "emails"
100
- | "path"
101
- | `option-${string}=${string}`;
92
+ | "text"
93
+ | "cut"
94
+ | "paste"
95
+ | "formatting"
96
+ | "url"
97
+ | "urls"
98
+ | "email"
99
+ | "emails"
100
+ | "path"
101
+ | `option-${string}=${string}`;
102
102
 
103
103
  /** Negated form of {@link Requirement}. */
104
104
  type NegatedRequirement = `!${Requirement}`;
@@ -112,37 +112,37 @@ type BeforeStep = "cut" | "copy" | "paste" | "paste-plain";
112
112
  * Strings which can be used to specify the {@link Action.after} action.
113
113
  */
114
114
  type AfterStep =
115
- | BeforeStep
116
- | "popclip-appear"
117
- | "show-status"
118
- | "copy-result"
119
- | "paste-result"
120
- | "show-result"
121
- | "preview-result";
115
+ | BeforeStep
116
+ | "popclip-appear"
117
+ | "show-status"
118
+ | "copy-result"
119
+ | "paste-result"
120
+ | "show-result"
121
+ | "preview-result";
122
122
 
123
123
  /**
124
124
  * Declares information about an app or website that this extension interacts with.
125
125
  */
126
126
  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[];
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
146
  }
147
147
 
148
148
  /**
@@ -153,37 +153,37 @@ interface AssociatedApp {
153
153
  * @returns A single action, an array of actions.
154
154
  */
155
155
  type PopulationFunction<CustomOptions = Options> = (
156
- input: Input,
157
- options: CustomOptions,
158
- context: Context,
156
+ input: Input,
157
+ options: CustomOptions,
158
+ context: Context,
159
159
  ) => (Action | ActionFunction)[] | Action | ActionFunction | void;
160
160
 
161
161
  /**
162
162
  * Object returned by {@link Extension.auth} when there is an authentication flow to kick off
163
163
  */
164
164
  type AuthFlowFunction = (
165
- url: string,
166
- params?: { [key: string]: string | undefined },
167
- expect?: string[],
165
+ url: string,
166
+ params?: { [key: string]: string | undefined },
167
+ expect?: string[],
168
168
  ) => Promise<any>;
169
169
 
170
170
  /**
171
171
  * Credentials used in auth function
172
172
  * */
173
173
  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;
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
187
  }
188
188
 
189
189
  /**
@@ -195,215 +195,215 @@ type AuthFunction = (info: AuthInfo, flow: AuthFlowFunction) => Promise<string>;
195
195
  * Properties that define how an icon is interpreted.
196
196
  */
197
197
  interface IconProperties {
198
- /**
199
- * If true, the supplied icon will be displayed with its original color instead of being filled in white/black. Default is false.
200
- */
201
- preserveColor?: boolean;
202
- /**
203
- * If true, the supplied icon will be displayed with its original aspect ratio instead of being scaled to fit a square. Default is false.
204
- */
205
- preserveAspect?: boolean;
206
- /**
207
- * If true, the supplied icon will be drawn horizontally flipped. Default is false.
208
- */
209
- flipX?: boolean;
210
- /**
211
- * If true, the supplied icon will be drawn vertically flipped. Default is false.
212
- */
213
- flipY?: boolean;
214
-
215
- /**
216
- * Move the icon horizontally by the specified distance, expressed as percentage of the icon's width.
217
- */
218
- moveX?: number;
219
-
220
- /**
221
- * Move the icon vertically by the specified distance, expressed as percentage of the icon's height.
222
- */
223
- moveY?: number;
224
-
225
- /**
226
- * Scale the icon by the specified factor, expressed as a percentage of the original size.
227
- */
228
- scale?: number;
229
-
230
- /**
231
- * Rotate the icon anticlockwise by the specified angle, expressed in degrees.
232
- */
233
- rotate?: number;
234
-
235
- /**
198
+ /**
199
+ * If true, the supplied icon will be displayed with its original color instead of being filled in white/black. Default is false.
200
+ */
201
+ preserveColor?: boolean;
202
+ /**
203
+ * If true, the supplied icon will be displayed with its original aspect ratio instead of being scaled to fit a square. Default is false.
204
+ */
205
+ preserveAspect?: boolean;
206
+ /**
207
+ * If true, the supplied icon will be drawn horizontally flipped. Default is false.
208
+ */
209
+ flipX?: boolean;
210
+ /**
211
+ * If true, the supplied icon will be drawn vertically flipped. Default is false.
212
+ */
213
+ flipY?: boolean;
214
+
215
+ /**
216
+ * Move the icon horizontally by the specified distance, expressed as percentage of the icon's width.
217
+ */
218
+ moveX?: number;
219
+
220
+ /**
221
+ * Move the icon vertically by the specified distance, expressed as percentage of the icon's height.
222
+ */
223
+ moveY?: number;
224
+
225
+ /**
226
+ * Scale the icon by the specified factor, expressed as a percentage of the original size.
227
+ */
228
+ scale?: number;
229
+
230
+ /**
231
+ * Rotate the icon anticlockwise by the specified angle, expressed in degrees.
232
+ */
233
+ rotate?: number;
234
+
235
+ /**
236
236
  Draw the icon inside a square.
237
237
  */
238
- square?: boolean;
239
-
240
- /**
241
- * Draw the icon inside a circle.
242
- */
243
- circle?: boolean;
244
-
245
- /**
246
- * Draw the icon inside a magnifying glass shape.
247
- */
248
- search?: boolean;
249
-
250
- /**
251
- * Draw a strike-through line over the icon.
252
- */
253
- strike?: boolean;
254
-
255
- /**
256
- * Draw the enclosing shape as a solid shape.
257
- */
258
- filled?: boolean;
259
-
260
- /**
261
- * For text icons only. Draw the text using a monospaced font.
262
- */
263
- monospaced?: boolean;
238
+ square?: boolean;
239
+
240
+ /**
241
+ * Draw the icon inside a circle.
242
+ */
243
+ circle?: boolean;
244
+
245
+ /**
246
+ * Draw the icon inside a magnifying glass shape.
247
+ */
248
+ search?: boolean;
249
+
250
+ /**
251
+ * Draw a strike-through line over the icon.
252
+ */
253
+ strike?: boolean;
254
+
255
+ /**
256
+ * Draw the enclosing shape as a solid shape.
257
+ */
258
+ filled?: boolean;
259
+
260
+ /**
261
+ * For text icons only. Draw the text using a monospaced font.
262
+ */
263
+ monospaced?: boolean;
264
264
  }
265
265
 
266
266
  /**
267
267
  * Properties common to Action and Extension
268
268
  */
269
269
  interface ActionProperties extends IconProperties {
270
- /**
271
- * A unique identifying string. An identifier for an action can be any string of your choosing.
272
- */
273
- identifier?: string;
274
-
275
- /**
276
- * The action's title.
277
- *
278
- * If no title is defined here, the extension's [`[name]] will be used, if any.
279
- */
280
- title?: LocalizableString;
281
-
282
- /**
283
- * A string to define the action's icon.
284
- *
285
- * If no icon is defined here, the extension's {@link Extension.icon | icon} will be used, if any.
286
- * Setting to `null` explicitly sets the action to have no icon.
287
- */
288
- icon?: string | null;
289
-
290
- /**
291
- * An array of conditions which must be met for this action to appear — see {@link Requirement}.
292
- *
293
- * * If no array is specified here, the action takes the value of {@link Extension.requirements}.
294
- * * If no array is specified there either, the action takes the default value `["text"]`.
295
- *
296
- * #### Notes
297
- *
298
- * When multiple conditions are specified, all of them must be satisfied.
299
- *
300
- * An empty array (`[]`) indicates no requirements at all, meaning the action will always appear.
301
- *
302
- * This property has no effect on dynamically generated actions.
303
- */
304
- requirements?: Array<Requirement | NegatedRequirement>;
305
-
306
- /**
307
- * Array of bundle identifiers for which the extension should appear. The action will only
308
- * appear if PopCLip is used in one of the specified apps.
309
- *
310
- * This property has no effect on dynamically generated actions.
311
- */
312
- requiredApps?: string[];
313
-
314
- /**
315
- * Array of bundle identifiers for which the extension should not appear. The action will not
316
- * appear if PopClip is used in any of the specified apps.
317
- *
318
- * This property has no effect on dynamically generated actions.
319
- */
320
- excludedApps?: string[];
321
-
322
- /**
323
- * A regular expression to decide whether this action appears in the popup.
324
- *
325
- * * If no regex is specified here, the action takes the value of {@link Extension.regex}.
326
- * * If no regex is specified there either, the action will match any input.
327
- *
328
- * #### Notes
329
- *
330
- * You may express the value either as a
331
- * [JavaScript regular expression literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
332
- * (or otherwise constructed `RegExp` object), or as a string.
333
- *
334
- * * If you supply a `RegExp` it will be evaluated in the JavaScript engine.
335
- * * If you supply a string it will be evaluated by macOS natively using the `NSRegularExpression` API (same as for 'classic' PopClip extensions).
336
- *
337
- * If the regex matches the selected text, the action will be shown in the popup and
338
- * the first occurrence of the matched text is accessible later via {@link Input.matchedText | matchedText}.
339
- *
340
- * If there is no match, the action is excluded from the popup.
341
- *
342
- * The regex's `lastIndex` is reset before and after each invocation, so the `g` (global) and `y` (sticky) flags have no effect.
343
- *
344
- * This property has no effect on dynamically generated actions.
345
- *
346
- * #### Example
347
- * ```js
348
- * regex = /abc/i // Example regex 'abc' with 'i' (case insensitive) flag
349
- * // Matches abc, ABC, Abc, etc.
350
- * ```
351
- */
352
- regex?: RegExp | string;
353
-
354
- /**
355
- * Declares the application or website associated with this action, if any.
356
- */
357
- app?: AssociatedApp;
358
- apps?: AssociatedApp[];
359
-
360
- /**
361
- * An optional step to peform before the main action.
362
- */
363
- before?: BeforeStep;
364
-
365
- /**
366
- * An optional step to peform after the main action.
367
- */
368
- after?: AfterStep;
369
-
370
- /**
371
- * Whether PopClip will capture HTML and Markdown content for the selection. Default is no.
372
- */
373
- captureHtml?: boolean;
374
-
375
- /**
376
- * Whether PopClip will capture RTF (Rich Text Format) content for the selection. Default is no.
377
- */
378
- captureRtf?: boolean;
379
-
380
- /**
381
- * Whether PopClip's popup should stay on screen after clicking this action's button. Default is no.
382
- */
383
- stayVisible?: boolean;
384
-
385
- /**
386
- * Whether the pasteboard should be restored to its original state after `paste-result`.
387
- */
388
- restorePasteboard?: boolean;
389
-
390
- // static properties for benefit of JSON Schema
391
- shortcutName?: string;
392
- serviceName?: string;
393
- url?: string;
394
- keyCombo?: string | number;
395
- keyCombos?: Array<string | number>;
396
- applescript?: string;
397
- applescriptFile?: string;
398
- applescriptCall?: {
399
- handler: string;
400
- parameters?: string[];
401
- };
402
- shellScript?: string;
403
- shellScriptFile?: string;
404
- interpreter?: string;
405
- javascript?: string;
406
- javascriptFile?: string;
270
+ /**
271
+ * A unique identifying string. An identifier for an action can be any string of your choosing.
272
+ */
273
+ identifier?: string;
274
+
275
+ /**
276
+ * The action's title.
277
+ *
278
+ * If no title is defined here, the extension's [`[name]] will be used, if any.
279
+ */
280
+ title?: LocalizableString;
281
+
282
+ /**
283
+ * A string to define the action's icon.
284
+ *
285
+ * If no icon is defined here, the extension's {@link Extension.icon | icon} will be used, if any.
286
+ * Setting to `null` explicitly sets the action to have no icon.
287
+ */
288
+ icon?: string | null;
289
+
290
+ /**
291
+ * An array of conditions which must be met for this action to appear — see {@link Requirement}.
292
+ *
293
+ * * If no array is specified here, the action takes the value of {@link Extension.requirements}.
294
+ * * If no array is specified there either, the action takes the default value `["text"]`.
295
+ *
296
+ * #### Notes
297
+ *
298
+ * When multiple conditions are specified, all of them must be satisfied.
299
+ *
300
+ * An empty array (`[]`) indicates no requirements at all, meaning the action will always appear.
301
+ *
302
+ * This property has no effect on dynamically generated actions.
303
+ */
304
+ requirements?: Array<Requirement | NegatedRequirement>;
305
+
306
+ /**
307
+ * Array of bundle identifiers for which the extension should appear. The action will only
308
+ * appear if PopCLip is used in one of the specified apps.
309
+ *
310
+ * This property has no effect on dynamically generated actions.
311
+ */
312
+ requiredApps?: string[];
313
+
314
+ /**
315
+ * Array of bundle identifiers for which the extension should not appear. The action will not
316
+ * appear if PopClip is used in any of the specified apps.
317
+ *
318
+ * This property has no effect on dynamically generated actions.
319
+ */
320
+ excludedApps?: string[];
321
+
322
+ /**
323
+ * A regular expression to decide whether this action appears in the popup.
324
+ *
325
+ * * If no regex is specified here, the action takes the value of {@link Extension.regex}.
326
+ * * If no regex is specified there either, the action will match any input.
327
+ *
328
+ * #### Notes
329
+ *
330
+ * You may express the value either as a
331
+ * [JavaScript regular expression literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
332
+ * (or otherwise constructed `RegExp` object), or as a string.
333
+ *
334
+ * * If you supply a `RegExp` it will be evaluated in the JavaScript engine.
335
+ * * If you supply a string it will be evaluated by macOS natively using the `NSRegularExpression` API (same as for 'classic' PopClip extensions).
336
+ *
337
+ * If the regex matches the selected text, the action will be shown in the popup and
338
+ * the first occurrence of the matched text is accessible later via {@link Input.matchedText | matchedText}.
339
+ *
340
+ * If there is no match, the action is excluded from the popup.
341
+ *
342
+ * The regex's `lastIndex` is reset before and after each invocation, so the `g` (global) and `y` (sticky) flags have no effect.
343
+ *
344
+ * This property has no effect on dynamically generated actions.
345
+ *
346
+ * #### Example
347
+ * ```js
348
+ * regex = /abc/i // Example regex 'abc' with 'i' (case insensitive) flag
349
+ * // Matches abc, ABC, Abc, etc.
350
+ * ```
351
+ */
352
+ regex?: RegExp | string;
353
+
354
+ /**
355
+ * Declares the application or website associated with this action, if any.
356
+ */
357
+ app?: AssociatedApp;
358
+ apps?: AssociatedApp[];
359
+
360
+ /**
361
+ * An optional step to peform before the main action.
362
+ */
363
+ before?: BeforeStep;
364
+
365
+ /**
366
+ * An optional step to peform after the main action.
367
+ */
368
+ after?: AfterStep;
369
+
370
+ /**
371
+ * Whether PopClip will capture HTML and Markdown content for the selection. Default is no.
372
+ */
373
+ captureHtml?: boolean;
374
+
375
+ /**
376
+ * Whether PopClip will capture RTF (Rich Text Format) content for the selection. Default is no.
377
+ */
378
+ captureRtf?: boolean;
379
+
380
+ /**
381
+ * Whether PopClip's popup should stay on screen after clicking this action's button. Default is no.
382
+ */
383
+ stayVisible?: boolean;
384
+
385
+ /**
386
+ * Whether the pasteboard should be restored to its original state after `paste-result`.
387
+ */
388
+ restorePasteboard?: boolean;
389
+
390
+ // static properties for benefit of JSON Schema
391
+ shortcutName?: string;
392
+ serviceName?: string;
393
+ url?: string;
394
+ keyCombo?: string | number;
395
+ keyCombos?: Array<string | number>;
396
+ applescript?: string;
397
+ applescriptFile?: string;
398
+ applescriptCall?: {
399
+ handler: string;
400
+ parameters?: string[];
401
+ };
402
+ shellScript?: string;
403
+ shellScriptFile?: string;
404
+ interpreter?: string;
405
+ javascript?: string;
406
+ javascriptFile?: string;
407
407
  }
408
408
 
409
409
  /**
@@ -414,9 +414,9 @@ interface ActionProperties extends IconProperties {
414
414
  * @param context Information about the context surrounding the selection. (Same object as {@link PopClip.context}.)
415
415
  */
416
416
  type ActionFunction<CustomOptions = Options> = (
417
- input: Input,
418
- options: CustomOptions & AuthOptions,
419
- context: Context,
417
+ input: Input,
418
+ options: CustomOptions & AuthOptions,
419
+ context: Context,
420
420
  ) => Promise<string | void> | string | void;
421
421
 
422
422
  /**
@@ -424,7 +424,7 @@ type ActionFunction<CustomOptions = Options> = (
424
424
  * If `code` is omitted, the action displays a disabled title/icon only.
425
425
  */
426
426
  interface Action<CustomOptions = Options> extends ActionProperties {
427
- code?: ActionFunction<CustomOptions>;
427
+ code?: ActionFunction<CustomOptions>;
428
428
  }
429
429
 
430
430
  // included for JSON Schema
@@ -433,309 +433,350 @@ type Entitlement = "network" | "dynamic";
433
433
  /**
434
434
  * The Extension object defines the PopClip extension.
435
435
  */
436
- interface Extension<CustomOptions extends Options = Options>
437
- extends ActionProperties {
438
- /**
439
- * The display name of this extension.
440
- */
441
- name?: LocalizableString;
442
-
443
- /**
444
- * Defines the user-configurable options for this extension.
445
- */
446
- options?: Option[];
447
-
448
- /**
449
- * If you define this function then PopClip will display a 'sign in' button in the options UI. When the user clicks the button,
450
- * PopClip will call this function with an `info` object and an `flow` callback.
451
- *
452
- * 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
453
- * of those options in the info parameter. */
454
- auth?: AuthFunction;
455
-
456
- /**
457
- * Define the actions to go in PopClip's popup. This can be an array or a function.
458
- *
459
- * - If it's an array, the supplied actions are used in the popup, subject to meeting the
460
- * requirements and regex conditions.
461
- *
462
- * - If it's a population function, it is called by PopClip to dynamically populate the popup with actions from this extension.
463
- * Setting requirements and regex keys has no effect on dynamic actions — the function itself is responsible for deciding what actions to show.
464
- * Population function requires the `dynamic` entitlement.
465
- */
466
- actions?:
467
- | (Action<CustomOptions> | ActionFunction<CustomOptions>)[]
468
- | PopulationFunction<CustomOptions>;
469
-
470
- /**
471
- * Simplified property to define a single action.
472
- */
473
- action?: Action<CustomOptions> | ActionFunction<CustomOptions>;
474
-
475
- // the following are static properties, included for the benefit of the JSON Scheme generation
476
- popclipVersion?: number;
477
- macosVersion?: string;
478
- entitlements?: Entitlement[];
479
- module?: string;
436
+ interface Extension<CustomOptions = Options> extends ActionProperties {
437
+ /**
438
+ * The display name of this extension.
439
+ */
440
+ name?: LocalizableString;
441
+
442
+ /**
443
+ * Defines the user-configurable options for this extension.
444
+ */
445
+ options?: Option[];
446
+
447
+ /**
448
+ * If you define this function then PopClip will display a 'sign in' button in the options UI. When the user clicks the button,
449
+ * PopClip will call this function with an `info` object and an `flow` callback.
450
+ *
451
+ * 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
452
+ * of those options in the info parameter. */
453
+ auth?: AuthFunction;
454
+
455
+ /**
456
+ * Define the actions to go in PopClip's popup. This can be an array or a function.
457
+ *
458
+ * - If it's an array, the supplied actions are used in the popup, subject to meeting the
459
+ * requirements and regex conditions.
460
+ *
461
+ * - If it's a population function, it is called by PopClip to dynamically populate the popup with actions from this extension.
462
+ * Setting requirements and regex keys has no effect on dynamic actions the function itself is responsible for deciding what actions to show.
463
+ * Population function requires the `dynamic` entitlement.
464
+ */
465
+ actions?:
466
+ | (Action<CustomOptions> | ActionFunction<CustomOptions>)[]
467
+ | PopulationFunction<CustomOptions>;
468
+
469
+ /**
470
+ * Simplified property to define a single action.
471
+ */
472
+ action?: Action<CustomOptions> | ActionFunction<CustomOptions>;
473
+
474
+ // the following are static properties, included for the benefit of the JSON Scheme generation
475
+ popclipVersion?: number;
476
+ macosVersion?: string;
477
+ entitlements?: Entitlement[];
478
+ module?: string;
480
479
  }
481
480
 
481
+ /**
482
+ * The possible values for `type` of {@link Option}.
483
+ */
482
484
  type OptionType =
483
- | "string"
484
- | "boolean"
485
- | "multiple"
486
- | "password"
487
- | "heading"
488
- | "secret";
485
+ | "string"
486
+ | "boolean"
487
+ | "multiple"
488
+ | "password"
489
+ | "heading"
490
+ | "secret";
489
491
 
490
492
  /**
491
493
  * Defines a single extension option.
492
494
  */
493
495
  interface OptionBase {
494
- /**
495
- * An identifying string for this option.
496
- */
497
- identifier: string;
498
-
499
- /**
500
- * The kind of option, one of:
501
- * * `string`: a text box for free text entry,
502
- * * `boolean`: a check box,
503
- * * `multiple`: multiple-choice drop-down with predefined options,
504
- * * `secret`: concealed text entry field (persisted in user's keychain),
505
- * * `password`: concealed text entry field (not persisted, only passed to auth function),
506
- * * `heading`: adds a heading in the user interface, but does not actually define an option
507
- */
508
- type: OptionType;
509
-
510
- /**
511
- * A short label for this option.
512
- */
513
- label?: LocalizableString;
514
-
515
- /**
516
- * An optional longer explanantion of this option, to be shown in the UI.
517
- */
518
- description?: LocalizableString;
519
-
520
- /*
521
- * If true, this option will be hidden in the prefs window. Default is false.
522
- */
523
- hidden?: boolean;
524
-
525
- /*
526
- * If true, this option will be be inset to the right of its label, instead of below it. Default is false.
527
- */
528
- inset?: boolean;
496
+ /**
497
+ * An identifying string for this option.
498
+ */
499
+ readonly identifier: string;
500
+
501
+ /**
502
+ * The kind of option, one of:
503
+ * * `string`: a text box for free text entry,
504
+ * * `boolean`: a check box,
505
+ * * `multiple`: multiple-choice drop-down with predefined options,
506
+ * * `secret`: concealed text entry field (persisted in user's keychain),
507
+ * * `password`: concealed text entry field (not persisted, only passed to auth function),
508
+ * * `heading`: adds a heading in the user interface, but does not actually define an option
509
+ */
510
+ readonly type: OptionType;
511
+
512
+ /**
513
+ * A short label for this option.
514
+ */
515
+ readonly label?: LocalizableString;
516
+
517
+ /**
518
+ * An optional longer explanantion of this option, to be shown in the UI.
519
+ */
520
+ readonly description?: LocalizableString;
521
+
522
+ /*
523
+ * If true, this option will be hidden in the prefs window. Default is false.
524
+ */
525
+ readonly hidden?: boolean;
526
+
527
+ /*
528
+ * If true, this option will be be inset to the right of its label, instead of below it. Default is false.
529
+ */
530
+ readonly inset?: boolean;
529
531
  }
530
532
 
533
+ /**
534
+ A string-valued option.
535
+ */
531
536
  interface StringOption extends OptionBase {
532
- type: "string";
533
- /**
534
- * The default value of the option. If omitted, `string` options default to the empty string.
535
- */
536
- defaultValue?: string;
537
+ readonly type: "string";
538
+ /**
539
+ * The default value of the option. If omitted, `string` options default to the empty string.
540
+ */
541
+ readonly defaultValue?: string;
537
542
  }
538
543
 
544
+ /**
545
+ * A multiple-choice option.
546
+ */
539
547
  interface MultipleOption extends OptionBase {
540
- type: "multiple";
541
- /**
542
- * The default value of the option. If omitted, `multiple` options default to the top item in the list.
543
- */
544
- defaultValue?: string | boolean;
545
-
546
- /**
547
- * The possible values for a `multiple` option.
548
- */
549
- values?: string[];
550
-
551
- /**
552
- * Display names corresponding to the entries in the {@link values} array. These are shown in the option UI.
553
- * If ommitted, the raw value strings are shown instead.
554
- */
555
- valueLabels?: LocalizableString[];
548
+ readonly type: "multiple";
549
+ /**
550
+ * The default value of the option. If omitted, `multiple` options default to the top item in the list.
551
+ */
552
+ readonly defaultValue?: string;
553
+
554
+ /**
555
+ * The possible values for a `multiple` option.
556
+ */
557
+ readonly values?: string[];
558
+
559
+ /**
560
+ * Display names corresponding to the entries in the {@link values} array. These are shown in the option UI.
561
+ * If ommitted, the raw value strings are shown instead.
562
+ */
563
+ readonly valueLabels?: LocalizableString[];
556
564
  }
557
565
 
566
+ /**
567
+ * A boolean option.
568
+ */
558
569
  interface BooleanOption extends OptionBase {
559
- type: "boolean";
560
- /**
561
- * The default value of the option. If omitted, `boolean` options default to true.
562
- */
563
- defaultValue?: boolean;
564
- /**
565
- * An icon for this option. It is only displayed for boolean options, next to the check box.
566
- */
567
- icon?: string;
570
+ readonly type: "boolean";
571
+ /**
572
+ * The default value of the option. If omitted, `boolean` options default to true.
573
+ */
574
+ readonly defaultValue?: boolean;
575
+ /**
576
+ * An icon for this option. It is only displayed for boolean options, next to the check box.
577
+ */
578
+ readonly icon?: string;
568
579
  }
569
580
 
581
+ /**
582
+ * A concealed string option.
583
+ */
570
584
  interface PasswordOption extends OptionBase {
571
- type: "password" | "secret";
585
+ readonly type: "password" | "secret";
572
586
  }
573
587
 
588
+ /**
589
+ * A heading option, which does not define an actual option, but adds a heading in the preferences window.
590
+ */
574
591
  interface HeadingOption extends OptionBase {
575
- type: "heading";
592
+ readonly type: "heading";
576
593
  }
577
594
 
595
+ /**
596
+ Represents a single option in the extension's preferences.
597
+ */
578
598
  type Option =
579
- | StringOption
580
- | MultipleOption
581
- | BooleanOption
582
- | PasswordOption
583
- | HeadingOption;
599
+ | StringOption
600
+ | MultipleOption
601
+ | BooleanOption
602
+ | PasswordOption
603
+ | HeadingOption;
604
+
605
+ // Create a type mapping from Option Type to TypeScript types
606
+ type OptionTypeMapping = {
607
+ secret: string;
608
+ password: string;
609
+ string: string;
610
+ multiple: string;
611
+ boolean: boolean;
612
+ };
613
+
614
+ // Helper type to extract the type for each option
615
+ type ExtractType<T extends Option> = T["type"] extends keyof OptionTypeMapping
616
+ ? OptionTypeMapping[T["type"]]
617
+ : never;
618
+
619
+ // Create a utility type to infer the OmnivoreOptions type
620
+ type InferOptions<T extends readonly Option[]> = {
621
+ readonly [K in T[number]["identifier"]]: ExtractType<
622
+ Extract<T[number], { identifier: K }>
623
+ >;
624
+ } & AuthOptions;
584
625
 
585
626
  /**
586
627
  * Represents a generic range, as a location and length
587
628
  */
588
629
  interface Range {
589
- location: number;
590
- length: number;
630
+ location: number;
631
+ length: number;
591
632
  }
592
633
 
593
634
  /**
594
635
  * An array of strings with an addiontal `ranges` property defining the source of the data in the orignal string.
595
636
  */
596
637
  interface RangedStrings extends Array<string> {
597
- ranges: Range[];
638
+ ranges: Range[];
598
639
  }
599
640
 
600
641
  /**
601
642
  * Input defines properties to access the input text contents.
602
643
  */
603
644
  interface Input {
604
- /**
605
- * The plain text selected by the user. If there is no selected text, this will be the empty string.
606
- */
607
- text: string;
608
-
609
- /**
610
- * 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.
611
- * Otherwise, it will be the same string as {@link text}.
612
- */
613
- matchedText: string;
614
-
615
- /**
616
- * If the action specified a {@link Action.regex | regex} to match the input, this will be the result of the the match.
617
- *
618
- * You can use this to access any capture groups from the regex.
619
- *
620
- * If the regex was specified as a JavaScript regex, the value is a return value from JavaScript's
621
- * [RegExp.prototype.exec()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method.
622
- *
623
- * If the regex was specified as an ICU regex in the static config, the value is the array of capture components.
624
- *
625
- * #### Example
626
- * ```js
627
- * // text: "apple", regex: /.(.)/
628
- * selection.regexResult[0] // "ap" (full match)
629
- * selection.regexResult[1] // "p" (capture group 1)
630
- * ```
631
- */
632
- regexResult?: RegExpMatchArray | string[] | null;
633
-
634
- /**
635
- * HTML content (if `captureHtml` is true).
636
- */
637
- html: string;
638
-
639
- /**
640
- * XHTML content (if `captureHtml` is true).
641
- */
642
- xhtml: string;
643
-
644
- /**
645
- * Markdown content (if `captureHtml` is true).
646
- */
647
- markdown: string;
648
-
649
- /**
650
- * RTF content (if `captureRtf` is true).
651
- */
652
- rtf: string;
653
-
654
- /**
655
- * Data of various kinds, that PopClip detected in the selected text.
656
- */
657
- data: {
658
- /**
659
- * HTTP ot HTTPS urls.
660
- */
661
- urls: RangedStrings;
662
- /**
663
- * Other protocols or app urls e.g. `ftp:`, `omnifocus:`, `craftdocs:` etc. (PopClip has a pre-defined allowlist
664
- * for custom URL schemes.)
665
- */
666
- nonHttpUrls: RangedStrings;
667
- /**
668
- * Email addresses.
669
- */
670
- emails: RangedStrings;
671
- /**
672
- * Local file paths.
673
- * */
674
- paths: RangedStrings;
675
- };
676
-
677
- /**
678
- * Unprocessed selection contents indexed by UTI.
679
- */
680
- content: PasteboardContent;
681
-
682
- /**
645
+ /**
646
+ * The plain text selected by the user. If there is no selected text, this will be the empty string.
647
+ */
648
+ text: string;
649
+
650
+ /**
651
+ * 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.
652
+ * Otherwise, it will be the same string as {@link text}.
653
+ */
654
+ matchedText: string;
655
+
656
+ /**
657
+ * If the action specified a {@link Action.regex | regex} to match the input, this will be the result of the the match.
658
+ *
659
+ * You can use this to access any capture groups from the regex.
660
+ *
661
+ * If the regex was specified as a JavaScript regex, the value is a return value from JavaScript's
662
+ * [RegExp.prototype.exec()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) method.
663
+ *
664
+ * If the regex was specified as an ICU regex in the static config, the value is the array of capture components.
665
+ *
666
+ * #### Example
667
+ * ```js
668
+ * // text: "apple", regex: /.(.)/
669
+ * selection.regexResult[0] // "ap" (full match)
670
+ * selection.regexResult[1] // "p" (capture group 1)
671
+ * ```
672
+ */
673
+ regexResult?: RegExpMatchArray | string[] | null;
674
+
675
+ /**
676
+ * HTML content (if `captureHtml` is true).
677
+ */
678
+ html: string;
679
+
680
+ /**
681
+ * XHTML content (if `captureHtml` is true).
682
+ */
683
+ xhtml: string;
684
+
685
+ /**
686
+ * Markdown content (if `captureHtml` is true).
687
+ */
688
+ markdown: string;
689
+
690
+ /**
691
+ * RTF content (if `captureRtf` is true).
692
+ */
693
+ rtf: string;
694
+
695
+ /**
696
+ * Data of various kinds, that PopClip detected in the selected text.
697
+ */
698
+ data: {
699
+ /**
700
+ * HTTP ot HTTPS urls.
701
+ */
702
+ urls: RangedStrings;
703
+ /**
704
+ * Other protocols or app urls e.g. `ftp:`, `omnifocus:`, `craftdocs:` etc. (PopClip has a pre-defined allowlist
705
+ * for custom URL schemes.)
706
+ */
707
+ nonHttpUrls: RangedStrings;
708
+ /**
709
+ * Email addresses.
710
+ */
711
+ emails: RangedStrings;
712
+ /**
713
+ * Local file paths.
714
+ * */
715
+ paths: RangedStrings;
716
+ };
717
+
718
+ /**
719
+ * Unprocessed selection contents indexed by UTI.
720
+ */
721
+ content: PasteboardContent;
722
+
723
+ /**
683
724
  Indicate if the text content is *just* a web URL (or URL-like string
684
725
  such as `popclip.app`), allowing for leading and trailing whitespace.
685
726
  */
686
- isUrl: boolean;
727
+ isUrl: boolean;
687
728
  }
688
729
 
689
730
  /**
690
731
  * Properties relating the context surrounding the selected text.
691
732
  */
692
733
  interface Context {
693
- /**
694
- * Indicates whether the text area supports formatting.
695
- */
696
- hasFormatting: boolean;
697
-
698
- /**
699
- * This property is true iff the Paste command is enabled in the current app.
700
- */
701
- canPaste: boolean;
702
-
703
- /**
704
- * This property is true iff text was selected.
705
- */
706
- canCopy: boolean;
707
-
708
- /**
709
- * This property is true iff text was selected and the app's Cut command is enabled.
710
- */
711
- canCut: boolean;
712
-
713
- /**
714
- * If the current app is a compatible browser, this will be the page URL.
715
- */
716
- browserUrl: string;
717
-
718
- /**
719
- * If the current app is a compatible browser, this will be the page title.
720
- */
721
- browserTitle: string;
722
-
723
- /**
724
- * The name of the current app, for example `Drafts`.
725
- */
726
- appName: string;
727
-
728
- /**
729
- * The bundle identitifier of the current app, for example `com.agiletortoise.Drafts-OSX`.
730
- */
731
- appIdentifier: string;
734
+ /**
735
+ * Indicates whether the text area supports formatting.
736
+ */
737
+ hasFormatting: boolean;
738
+
739
+ /**
740
+ * This property is true iff the Paste command is enabled in the current app.
741
+ */
742
+ canPaste: boolean;
743
+
744
+ /**
745
+ * This property is true iff text was selected.
746
+ */
747
+ canCopy: boolean;
748
+
749
+ /**
750
+ * This property is true iff text was selected and the app's Cut command is enabled.
751
+ */
752
+ canCut: boolean;
753
+
754
+ /**
755
+ * If the current app is a compatible browser, this will be the page URL.
756
+ */
757
+ browserUrl: string;
758
+
759
+ /**
760
+ * If the current app is a compatible browser, this will be the page title.
761
+ */
762
+ browserTitle: string;
763
+
764
+ /**
765
+ * The name of the current app, for example `Drafts`.
766
+ */
767
+ appName: string;
768
+
769
+ /**
770
+ * The bundle identitifier of the current app, for example `com.agiletortoise.Drafts-OSX`.
771
+ */
772
+ appIdentifier: string;
732
773
  }
733
774
 
734
775
  /**
735
776
  * Represents the current values of the extension's settings.
736
777
  */
737
778
  interface Options {
738
- readonly [identifier: string]: string | boolean;
779
+ readonly [identifier: string]: string | boolean;
739
780
  }
740
781
 
741
782
  /**
@@ -743,10 +784,10 @@ interface Options {
743
784
  * undefined or holding an empty string.
744
785
  */
745
786
  interface AuthOptions {
746
- /**
747
- * The stored value that was returned from the `auth()` function.
748
- */
749
- authsecret: string;
787
+ /**
788
+ * The stored value that was returned from the `auth()` function.
789
+ */
790
+ authsecret: string;
750
791
  }
751
792
 
752
793
  /**
@@ -754,411 +795,444 @@ interface AuthOptions {
754
795
  *
755
796
  */
756
797
  interface PopClip {
757
- /**
758
- * The state of the modifier keys when the action was invoked in PopClip.
759
- *
760
- * #### Notes
761
- * During the execution of the population function, all the modifiers will read as false.
762
- */
763
- readonly modifiers: Modifiers;
764
-
765
- /**
766
- * The current selection.
767
- */
768
- readonly input: Input;
769
-
770
- /**
771
- * The current context.
772
- */
773
- readonly context: Context;
774
-
775
- /**
776
- * The current values of the options.
777
- */
778
- readonly options: Options & AuthOptions;
779
-
780
- /**
781
- * If the target app's Paste command is available, this method places the given string on the pasteboard
782
- * and then invokes the target app's Paste comand. If the `restore` flag is set in the options, it will
783
- * then restore the original pasteboard contents.
784
- *
785
- * If the target app's Paste command is not available, it behaves as {@link copyText} instead.
786
- *
787
- * #### Example
788
- *
789
- * ```js
790
- * // place "Hello" on the clipboard and invoke Paste
791
- * popclip.pasteText("Hello");
792
- * // place "Hello", then restore the original pasteboard contents
793
- * popclip.pasteText("Hello", {restore: true});
794
- * ```
795
- * @param text The plain text string to paste
796
- * @param options
797
- */
798
- pasteText: (text: string, options?: PasteOptions) => void;
799
-
800
- /**
801
- * Paste arbitrary pasteboard content.
802
- */
803
- pasteContent: (content: PasteboardContent, options?: PasteOptions) => void;
804
-
805
- /**
806
- * Places the given string on the pasteboard, and shows "Copied" notificaction to the user.
807
- * @param text The plain text string to copy
808
- */
809
- copyText: (text: string) => void;
810
-
811
- /**
812
- * Copy arbitrary pasteboard content.
813
- */
814
- copyContent: (content: PasteboardContent) => void;
815
-
816
- /**
817
- * Invokes a command in the target app.
818
- * @param command Either `cut`, `copy` or `paste`.
819
- * @param options Options for the command.
820
- */
821
- performCommand: (
822
- command: "cut" | "copy" | "paste",
823
- options?: {
824
- /** Transformation to apply to the pasteboard contents. (Default: `none`)
825
- * - `none`: regular pasteboard operation
826
- * - `plain`: strips away everything but plain text
827
- */
828
- transform?: "none" | "plain";
829
- },
830
- ) => void;
831
-
832
- /**
833
- * Display text to the user.
834
- * @param text The text to display.
835
- * @param options Options.
836
- */
837
- showText: (
838
- text: string,
839
- options?: {
840
- /**
841
- * Display style:
842
- * - `compact` (default): Show the text inside PopClip's popup. It will be truncated to 160 characters when shown.
843
- * - `large`: Show as "Large Type" in full screen.
844
- */
845
- style?: "compact" | "large";
846
- /**
847
- * Applies to `compact` display mode only. If `true`, and the app's Paste command is available,
848
- * the displayed text will be in a clickable button, which clicked, pastes the full text.
849
- */
850
- preview?: boolean;
851
- },
852
- ) => void;
853
-
854
- /**
855
- * PopClip will show a checkmark symbol to indicate success.
856
- */
857
- showSuccess: () => void;
858
-
859
- /**
860
- * PopClip will show an "X" symbol to indicate failure.
861
- */
862
- showFailure: () => void;
863
-
864
- /**
865
- * PopClip will open the settings UI for this extension.
866
- *
867
- * #### Notes
868
- * If the extension has no settings, this method does nothing.
869
- */
870
- showSettings: () => void;
871
-
872
- /**
873
- * Trigger PopClip to appear again with the current selection.
874
- */
875
- appear: () => void;
876
-
877
- /**
878
- * Simulate a key press by the user.
879
- *
880
- * #### Examples
881
- *
882
- * ```js
883
- * // press the key combo ⌘B
884
- * popclip.pressKey('command B');
885
- * // press the key combo ⌥⌘H
886
- * popclip.pressKey('option command H');
887
- * // press the return key
888
- * popclip.pressKey('return');
889
- * popclip.pressKey(util.constant.KEY_RETURN); // equivalent
890
- * * // press option and the page down key
891
- * popclip.pressKey('option 0x79');
892
- * popclip.pressKey(0x79, util.constant.MODIFIER_OPTION); // equivalent
893
- * ```
894
- *
895
- * #### Notes
896
- *
897
- * Some key code and modifier constants are available in {@link Util.constant | util.constant}.
898
- *
899
- * @param key The key to press. When this parameter is a string, PopClip will interpret it as in
900
- * [Key Press actions](https://www.popclip.app/dev/key-press-actions).
901
- * When this parameter is a number, PopClip will use that exact key code.
902
- *
903
- * @param modifiers An optional bit mask specifiying additional modifier keys, if any.
904
- */
905
- pressKey: (key: string | number, modifiers?: number) => void;
906
-
907
- /**
908
- * Open a URL in an application.
909
- *
910
- * #### Choice of application
911
- *
912
- * If a target application bundle identifier is specified via the `app` option, PopClip will ask that app to open the URL.
913
- *
914
- * If no target app is specified:
915
- *
916
- * - If the URL has the http or https scheme, and the current app is a browser, the URL is opened in the current app.
917
- * - Otherwise, PopClip asks macOS to open the URL in the default handler for that URL type.
918
- *
919
- * #### URL encoding
920
- *
921
- * Any parameters etc. in the URL must be appropriately percent-encoded. JavaScript provides the
922
- * [encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
923
- * function for this.
924
- *
925
- * #### Example
926
- * ```js
927
- * popclip.openUrl("https://xkcd.com"); // open xckd.com in current/default browser
928
- * popclip.openUrl("https://xkcd.com", {app: "com.brave.Browser"}); // open xkcd.com in Brave browser
929
- * popclip.openUrl(`mailto:support@pilotmoon.com?subject=${encodeURIComponent("What's up?")}`); // open mailto link in the default mail application
930
- * ```
931
- *
932
- * @param url A well-formed URL
933
- * @param options Options.
934
- */
935
- openUrl: (
936
- url: string,
937
- options?: {
938
- /**
939
- * Bundle identifier of the app to open the URL with. For example `"com.google.Chrome"`.
940
- */
941
- app?: string;
942
- },
943
- ) => void;
944
-
945
- /**
946
- * Share items with a named macOS sharing service.
947
- *
948
- * #### Example
949
- * ```js
950
- * // share a string with the Messages service
951
- * popclip.share("com.apple.share.Messages.window", ["Hello, world!"]);
952
- * // share a URL with the Safari Reading List service
953
- * popclip.share("com.apple.share.System.add-to-safari-reading-list", [{ url: "https://example.com" }]);
954
- * // share a an html string with the Notes service
955
- * const item = new RichString("Some <b>simple</b> html", { format: html })
956
- * popclip.share("com.apple.Notes.SharingExtension", [item]);
957
- * ```
958
- *
959
- * #### Notes
960
- *
961
- * The list of available sharing services is determined by the user's system configuration.
962
- *
963
- * @param serviceName The name of the sharing service to use.
964
- * @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.
965
- * @throws If the service name is not recognized, or if the service cannot handle the supplied items, an error is thrown.
966
- */
967
- share: (
968
- serviceName: string,
969
- items: (string | RichString | { url: string })[],
970
- ) => void;
798
+ /**
799
+ * The state of the modifier keys when the action was invoked in PopClip.
800
+ *
801
+ * #### Notes
802
+ * During the execution of the population function, all the modifiers will read as false.
803
+ */
804
+ readonly modifiers: Modifiers;
805
+
806
+ /**
807
+ * The current selection.
808
+ */
809
+ readonly input: Input;
810
+
811
+ /**
812
+ * The current context.
813
+ */
814
+ readonly context: Context;
815
+
816
+ /**
817
+ * The current values of the options.
818
+ */
819
+ readonly options: Options & AuthOptions;
820
+
821
+ /**
822
+ * If the target app's Paste command is available, this method places the given string on the pasteboard
823
+ * and then invokes the target app's Paste comand. If the `restore` flag is set in the options, it will
824
+ * then restore the original pasteboard contents.
825
+ *
826
+ * If the target app's Paste command is not available, it behaves as {@link copyText} instead.
827
+ *
828
+ * #### Example
829
+ *
830
+ * ```js
831
+ * // place "Hello" on the clipboard and invoke Paste
832
+ * popclip.pasteText("Hello");
833
+ * // place "Hello", then restore the original pasteboard contents
834
+ * popclip.pasteText("Hello", {restore: true});
835
+ * ```
836
+ * @param text The plain text string to paste
837
+ * @param options
838
+ */
839
+ pasteText: (text: string, options?: PasteOptions) => void;
840
+
841
+ /**
842
+ * Paste arbitrary pasteboard content.
843
+ */
844
+ pasteContent: (content: PasteboardContent, options?: PasteOptions) => void;
845
+
846
+ /**
847
+ * Places the given string on the pasteboard, and shows "Copied" notificaction to the user.
848
+ * @param text The plain text string to copy
849
+ */
850
+ copyText: (text: string) => void;
851
+
852
+ /**
853
+ * Copy arbitrary pasteboard content.
854
+ */
855
+ copyContent: (content: PasteboardContent) => void;
856
+
857
+ /**
858
+ * Invokes a command in the target app.
859
+ * @param command Either `cut`, `copy` or `paste`.
860
+ * @param options Options for the command.
861
+ */
862
+ performCommand: (
863
+ command: "cut" | "copy" | "paste",
864
+ options?: {
865
+ /** Transformation to apply to the pasteboard contents. (Default: `none`)
866
+ * - `none`: regular pasteboard operation
867
+ * - `plain`: strips away everything but plain text
868
+ */
869
+ transform?: "none" | "plain";
870
+ },
871
+ ) => void;
872
+
873
+ /**
874
+ * Display text to the user.
875
+ * @param text The text to display.
876
+ * @param options Options.
877
+ */
878
+ showText: (
879
+ text: string,
880
+ options?: {
881
+ /**
882
+ * Display style:
883
+ * - `compact` (default): Show the text inside PopClip's popup. It will be truncated to 160 characters when shown.
884
+ * - `large`: Show as "Large Type" in full screen.
885
+ */
886
+ style?: "compact" | "large";
887
+ /**
888
+ * Applies to `compact` display mode only. If `true`, and the app's Paste command is available,
889
+ * the displayed text will be in a clickable button, which clicked, pastes the full text.
890
+ */
891
+ preview?: boolean;
892
+ },
893
+ ) => void;
894
+
895
+ /**
896
+ * PopClip will show a checkmark symbol to indicate success.
897
+ */
898
+ showSuccess: () => void;
899
+
900
+ /**
901
+ * PopClip will show an "X" symbol to indicate failure.
902
+ */
903
+ showFailure: () => void;
904
+
905
+ /**
906
+ * PopClip will open the settings UI for this extension.
907
+ *
908
+ * #### Notes
909
+ * If the extension has no settings, this method does nothing.
910
+ */
911
+ showSettings: () => void;
912
+
913
+ /**
914
+ * Trigger PopClip to appear again with the current selection.
915
+ */
916
+ appear: () => void;
917
+
918
+ /**
919
+ * Simulate a key press by the user.
920
+ *
921
+ * #### Examples
922
+ *
923
+ * ```js
924
+ * // press the key combo ⌘B
925
+ * popclip.pressKey('command B');
926
+ * // press the key combo ⌥⌘H
927
+ * popclip.pressKey('option command H');
928
+ * // press the return key
929
+ * popclip.pressKey('return');
930
+ * popclip.pressKey(util.constant.KEY_RETURN); // equivalent
931
+ * * // press option and the page down key
932
+ * popclip.pressKey('option 0x79');
933
+ * popclip.pressKey(0x79, util.constant.MODIFIER_OPTION); // equivalent
934
+ * ```
935
+ *
936
+ * #### Notes
937
+ *
938
+ * Some key code and modifier constants are available in {@link Util.constant | util.constant}.
939
+ *
940
+ * @param key The key to press. When this parameter is a string, PopClip will interpret it as in
941
+ * [Key Press actions](https://www.popclip.app/dev/key-press-actions).
942
+ * When this parameter is a number, PopClip will use that exact key code.
943
+ *
944
+ * @param modifiers An optional bit mask specifiying additional modifier keys, if any.
945
+ */
946
+ pressKey: (key: string | number, modifiers?: number) => void;
947
+
948
+ /**
949
+ * Open a URL in an application.
950
+ *
951
+ * #### Choice of application
952
+ *
953
+ * If a target application bundle identifier is specified via the `app` option, PopClip will ask that app to open the URL.
954
+ *
955
+ * If no target app is specified:
956
+ *
957
+ * - If the URL has the http or https scheme, and the current app is a browser, the URL is opened in the current app.
958
+ * - Otherwise, PopClip asks macOS to open the URL in the default handler for that URL type.
959
+ *
960
+ * #### URL encoding
961
+ *
962
+ * Any parameters etc. in the URL must be appropriately percent-encoded. JavaScript provides the
963
+ * [encodeURIComponent()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
964
+ * function for this.
965
+ *
966
+ * #### Example
967
+ * ```js
968
+ * popclip.openUrl("https://xkcd.com"); // open xckd.com in current/default browser
969
+ * popclip.openUrl("https://xkcd.com", {app: "com.brave.Browser"}); // open xkcd.com in Brave browser
970
+ * popclip.openUrl(`mailto:support@pilotmoon.com?subject=${encodeURIComponent("What's up?")}`); // open mailto link in the default mail application
971
+ * ```
972
+ *
973
+ * @param url A well-formed URL
974
+ * @param options Options.
975
+ */
976
+ openUrl: (
977
+ url: string,
978
+ options?: {
979
+ /**
980
+ * Bundle identifier of the app to open the URL with. For example `"com.google.Chrome"`.
981
+ */
982
+ app?: string;
983
+ },
984
+ ) => void;
985
+
986
+ /**
987
+ * Share items with a named macOS sharing service.
988
+ *
989
+ * #### Example
990
+ * ```js
991
+ * // share a string with the Messages service
992
+ * popclip.share("com.apple.share.Messages.window", ["Hello, world!"]);
993
+ * // share a URL with the Safari Reading List service
994
+ * popclip.share("com.apple.share.System.add-to-safari-reading-list", [{ url: "https://example.com" }]);
995
+ * // share a an html string with the Notes service
996
+ * const item = new RichString("Some <b>simple</b> html", { format: html })
997
+ * popclip.share("com.apple.Notes.SharingExtension", [item]);
998
+ * ```
999
+ *
1000
+ * #### Notes
1001
+ *
1002
+ * The list of available sharing services is determined by the user's system configuration.
1003
+ *
1004
+ * @param serviceName The name of the sharing service to use.
1005
+ * @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.
1006
+ * @throws If the service name is not recognized, or if the service cannot handle the supplied items, an error is thrown.
1007
+ */
1008
+ share: (
1009
+ serviceName: string,
1010
+ items: (string | RichString | { url: string })[],
1011
+ ) => void;
971
1012
  }
972
1013
 
973
1014
  /**
974
1015
  * A container for various utility functions and constants {@link util} object.
975
1016
  */
976
1017
  interface Util {
977
- /**
978
- * Localize an English string into the current user interface language, if possible.
979
- * This will work for strings which match an existing string in PopClip's user interface.
980
- *
981
- * @param string The string to localize.
982
- * @return The localized string, or the original string if no localized version was avaiable.
983
- */
984
- localize: (string: string) => string;
985
-
986
- localeInfo: {
987
- localeIdentifier: string;
988
- regionCode: string;
989
- languageCode: string;
990
- decimalSeparator: string;
991
- groupingSeparator: string;
992
- currencyCode: string;
993
- currencySymbol: string;
994
- };
995
-
996
- timeZoneInfo: {
997
- identifier: string;
998
- abbreviation: string;
999
- secondsOffset: number;
1000
- daylightSaving: boolean;
1001
- };
1002
-
1003
- htmlToRtf: (html: string) => string | undefined;
1004
-
1005
- /**
1006
- * Encode a string as UTF-8 then Base-64 encode the result.
1007
- *
1008
- * @param string The string to encode.
1009
- * @param options
1010
- */
1011
- base64Encode: (
1012
- string: string,
1013
- options?: {
1014
- /**
1015
- * Whether to encode using the URL-safe variant, with `-` and `_` substituted for `+` and `/`. Default is no.
1016
- */
1017
- urlSafe?: boolean;
1018
- /**
1019
- * Whether to trim the `=`/`==` padding from the string. Default is no.
1020
- */
1021
- trimmed?: boolean;
1022
- },
1023
- ) => string;
1024
-
1025
- /**
1026
- * Decode a Base-64 string and interpret the result as a UTF-8 string.
1027
- *
1028
- * Accepts both standard and URL-safe variants as input. Also accepts input with or without the `=`/`==` end padding.
1029
- * Throws an error if the input cannot be decoded as a UTF-8 string.
1030
- *
1031
- * @param string
1032
- * @returns The decoded string
1033
- */
1034
- base64Decode: (string: string) => string;
1035
-
1036
- /** Build a URL from a base URL and additional query parameters */
1037
- buildQueryUrl: (baseUrl: string, params: { [key: string]: string }) => string;
1038
-
1039
- /** Build a query from params object */
1040
- buildQuery: (params: { [key: string]: string }) => string;
1041
-
1042
- /** Parse a query into params object */
1043
- parseQuery: (query: string) => any;
1044
-
1045
- /** Decipher a JSON object that has been lightly obscured to prevent constants such as
1046
- * API keys appearing in plaintext in the source files.
1047
- *
1048
- * This function will ROT13 decipher the text, apply Base64 decoding, and parse the result as JSON. */
1049
- clarify: (obscuredString: string) => any;
1050
-
1051
- // same as global sleep()
1052
- sleep: (durationMilliseconds: number) => Promise<void>;
1053
-
1054
- /**
1055
- * The `constant` property is a container for pre-defined constants.
1056
- */
1057
- readonly constant: {
1058
- /**
1059
- * Bit mask for the Shift (⇧) key.
1060
- */
1061
- readonly MODIFIER_SHIFT: 131072;
1062
- /**
1063
- * Bit mask for the Control (⌃) key.
1064
- */
1065
- readonly MODIFIER_CONTROL: 262144;
1066
- /**
1067
- * Bit mask for the Option (⌥) key.
1068
- */
1069
- readonly MODIFIER_OPTION: 524288;
1070
- /**
1071
- * Bit mask for the Command (⌘) key.
1072
- */
1073
- readonly MODIFIER_COMMAND: 1048576;
1074
- /**
1075
- * Key code for the Return (↵) key.
1076
- */
1077
- readonly KEY_RETURN: 0x24;
1078
- /**
1079
- * Key code for the Tab (⇥) key.
1080
- */
1081
- readonly KEY_TAB: 0x30;
1082
- /**
1083
- * Key code for the space bar.
1084
- */
1085
- readonly KEY_SPACE: 0x31;
1086
- /**
1087
- * Key code for the Delete (⌫) key.
1088
- */
1089
- readonly KEY_DELETE: 0x33;
1090
- /**
1091
- * Key code for the Escape key.
1092
- */
1093
- readonly KEY_ESCAPE: 0x35;
1094
- /**
1095
- * Key code for the Left Arrow key.
1096
- */
1097
- readonly KEY_LEFTARROW: 0x7b;
1098
- /**
1099
- * Key code for the Right Arrow key.
1100
- */
1101
- readonly KEY_RIGHTARROW: 0x7c;
1102
- /**
1103
- * Key code for the Down Arrow key.
1104
- */
1105
- readonly KEY_DOWNARROW: 0x7d;
1106
- /**
1107
- * Key code for the Up Arrow key.
1108
- */
1109
- readonly KEY_UPARROW: 0x7e;
1110
- };
1018
+ /**
1019
+ * Localize an English string into the current user interface language, if possible.
1020
+ * This will work for strings which match an existing string in PopClip's user interface.
1021
+ *
1022
+ * @param string The string to localize.
1023
+ * @return The localized string, or the original string if no localized version was avaiable.
1024
+ */
1025
+ localize: (string: string) => string;
1026
+
1027
+ /**
1028
+ Get information about the current locale as configures in macOS settings.
1029
+ */
1030
+ localeInfo: {
1031
+ localeIdentifier: string;
1032
+ regionCode: string;
1033
+ languageCode: string;
1034
+ decimalSeparator: string;
1035
+ groupingSeparator: string;
1036
+ currencyCode: string;
1037
+ currencySymbol: string;
1038
+ };
1039
+
1040
+ /**
1041
+ Get information about the current time zone as configured in macOS settings.
1042
+ */
1043
+ timeZoneInfo: {
1044
+ identifier: string;
1045
+ abbreviation: string;
1046
+ secondsOffset: number;
1047
+ daylightSaving: boolean;
1048
+ };
1049
+
1050
+ htmlToRtf: (html: string) => string | undefined;
1051
+
1052
+ /**
1053
+ * Encode a string as UTF-8 then Base-64 encode the result.
1054
+ *
1055
+ * @param string The string to encode.
1056
+ * @param options
1057
+ */
1058
+ base64Encode: (
1059
+ string: string,
1060
+ options?: {
1061
+ /**
1062
+ * Whether to encode using the URL-safe variant, with `-` and `_` substituted for `+` and `/`. Default is no.
1063
+ */
1064
+ urlSafe?: boolean;
1065
+ /**
1066
+ * Whether to trim the `=`/`==` padding from the string. Default is no.
1067
+ */
1068
+ trimmed?: boolean;
1069
+ },
1070
+ ) => string;
1071
+
1072
+ /**
1073
+ * Decode a Base-64 string and interpret the result as a UTF-8 string.
1074
+ *
1075
+ * Accepts both standard and URL-safe variants as input. Also accepts input with or without the `=`/`==` end padding.
1076
+ * Throws an error if the input cannot be decoded as a UTF-8 string.
1077
+ *
1078
+ * @param string
1079
+ * @returns The decoded string
1080
+ */
1081
+ base64Decode: (string: string) => string;
1082
+
1083
+ /* Build a URL from a base URL and additional query parameters */
1084
+ buildQueryUrl: (baseUrl: string, params: { [key: string]: string }) => string;
1085
+
1086
+ /* Build a query from params object */
1087
+ buildQuery: (params: { [key: string]: string }) => string;
1088
+
1089
+ /* Parse a query into params object */
1090
+ parseQuery: (query: string) => any;
1091
+
1092
+ /** Decipher a JSON object that has been lightly obscured to prevent constants such as
1093
+ * API keys appearing in plaintext in the source files.
1094
+ *
1095
+ * This function will ROT13 decipher the text, apply Base64 decoding, and parse the result as JSON. */
1096
+ clarify: (obscuredString: string) => any;
1097
+
1098
+ // same as global sleep()
1099
+ sleep: (durationMilliseconds: number) => Promise<void>;
1100
+
1101
+ /**
1102
+ * Fill the provided `TypedArray` with cryptographically secure random values.
1103
+ * This aims work like `crypto.getRandomValues()` from Web Crypto API.
1104
+ * Internally, it is implemented using Apple's `SecRandomCopyBytes`.
1105
+ *
1106
+ * #### Example
1107
+ *
1108
+ * ```js
1109
+ * const array = new Uint8Array(16); // array of 16 bytes
1110
+ * util.getRandomValues(array); // array is now filled with random bytes
1111
+ * ```
1112
+ *
1113
+ * @param typedArray The array to fill with random values. This will be modified in place.
1114
+ */
1115
+ getRandomValues(
1116
+ typedArray:
1117
+ | Int8Array
1118
+ | Uint8Array
1119
+ | Uint8ClampedArray
1120
+ | Int16Array
1121
+ | Uint16Array
1122
+ | Int32Array
1123
+ | Uint32Array
1124
+ | BigInt64Array
1125
+ | BigUint64Array,
1126
+ ): void;
1127
+
1128
+ /**
1129
+ * The `constant` property is a container for pre-defined constants.
1130
+ */
1131
+ readonly constant: {
1132
+ /**
1133
+ * Bit mask for the Shift (⇧) key.
1134
+ */
1135
+ readonly MODIFIER_SHIFT: 131072;
1136
+ /**
1137
+ * Bit mask for the Control (⌃) key.
1138
+ */
1139
+ readonly MODIFIER_CONTROL: 262144;
1140
+ /**
1141
+ * Bit mask for the Option (⌥) key.
1142
+ */
1143
+ readonly MODIFIER_OPTION: 524288;
1144
+ /**
1145
+ * Bit mask for the Command (⌘) key.
1146
+ */
1147
+ readonly MODIFIER_COMMAND: 1048576;
1148
+ /**
1149
+ * Key code for the Return (↵) key.
1150
+ */
1151
+ readonly KEY_RETURN: 0x24;
1152
+ /**
1153
+ * Key code for the Tab (⇥) key.
1154
+ */
1155
+ readonly KEY_TAB: 0x30;
1156
+ /**
1157
+ * Key code for the space bar.
1158
+ */
1159
+ readonly KEY_SPACE: 0x31;
1160
+ /**
1161
+ * Key code for the Delete (⌫) key.
1162
+ */
1163
+ readonly KEY_DELETE: 0x33;
1164
+ /**
1165
+ * Key code for the Escape key.
1166
+ */
1167
+ readonly KEY_ESCAPE: 0x35;
1168
+ /**
1169
+ * Key code for the Left Arrow key.
1170
+ */
1171
+ readonly KEY_LEFTARROW: 0x7b;
1172
+ /**
1173
+ * Key code for the Right Arrow key.
1174
+ */
1175
+ readonly KEY_RIGHTARROW: 0x7c;
1176
+ /**
1177
+ * Key code for the Down Arrow key.
1178
+ */
1179
+ readonly KEY_DOWNARROW: 0x7d;
1180
+ /**
1181
+ * Key code for the Up Arrow key.
1182
+ */
1183
+ readonly KEY_UPARROW: 0x7e;
1184
+ };
1111
1185
  }
1112
1186
 
1113
1187
  /**
1114
1188
  * Represents the raw pasteboard content, indexed by UTI. Supports string data only.
1115
1189
  */
1116
1190
  interface PasteboardContent {
1117
- "public.utf8-plain-text"?: string;
1118
- "public.html"?: string;
1119
- "public.rtf"?: string;
1120
- [key: string]: string | undefined;
1191
+ "public.utf8-plain-text"?: string;
1192
+ "public.html"?: string;
1193
+ "public.rtf"?: string;
1194
+ [key: string]: string | undefined;
1121
1195
  }
1122
1196
 
1123
1197
  /**
1124
1198
  * Options for Paste operations.
1125
1199
  */
1126
1200
  interface PasteOptions {
1127
- /**
1128
- * Whether to restore the original contents of the pasteboard after the paste
1129
- * operation. Default is `false`.
1130
- */
1131
- restore?: boolean;
1201
+ /**
1202
+ * Whether to restore the original contents of the pasteboard after the paste
1203
+ * operation. Default is `false`.
1204
+ */
1205
+ restore?: boolean;
1132
1206
  }
1133
1207
 
1134
1208
  /**
1135
1209
  * A simplified interface to the macOS pasteboard. Implemented by the global object, {@link pasteboard}.
1136
1210
  */
1137
1211
  interface Pasteboard {
1138
- /**
1139
- * Get and set the plain text content of the pasteboard.
1140
- *
1141
- * #### Notes
1142
- * This property corresponds with the pasteboard type `public.utf8-plain-text`.
1143
- *
1144
- * When placing text on the pasteboard this way, PopClip's "Copied" notification will not appear.
1145
- * (Typically, scripts should use {@link PopClip.copyText} instead, so that the user gets the "Copied" notification.)
1146
- *
1147
- * The value of this property will always be a string. If there is no plain text value on the
1148
- * pasteboard, reading this property will give an empty string (`""`).
1149
- *
1150
- * #### Example
1151
- * ```js
1152
- * let x = pasteboard.text;
1153
- * pasteboard.text = "new text";
1154
- * ```
1155
- */
1156
- text: string;
1157
-
1158
- /**
1159
- * Get and set the content of the pasteboard, of the specified types
1160
- */
1161
- content: PasteboardContent;
1212
+ /**
1213
+ * Get and set the plain text content of the pasteboard.
1214
+ *
1215
+ * #### Notes
1216
+ * This property corresponds with the pasteboard type `public.utf8-plain-text`.
1217
+ *
1218
+ * When placing text on the pasteboard this way, PopClip's "Copied" notification will not appear.
1219
+ * (Typically, scripts should use {@link PopClip.copyText} instead, so that the user gets the "Copied" notification.)
1220
+ *
1221
+ * The value of this property will always be a string. If there is no plain text value on the
1222
+ * pasteboard, reading this property will give an empty string (`""`).
1223
+ *
1224
+ * #### Example
1225
+ * ```js
1226
+ * let x = pasteboard.text;
1227
+ * pasteboard.text = "new text";
1228
+ * ```
1229
+ */
1230
+ text: string;
1231
+
1232
+ /**
1233
+ * Get and set the content of the pasteboard, of the specified types
1234
+ */
1235
+ content: PasteboardContent;
1162
1236
  }
1163
1237
 
1164
1238
  /**
@@ -1180,29 +1254,29 @@ declare const popclip: PopClip;
1180
1254
  * ```
1181
1255
  */
1182
1256
  declare class RichString {
1183
- /**
1184
- * Create a new RichString object from a string.
1185
- *
1186
- * @param source The string to convert to a RichString object.
1187
- * @param options Options for the conversion.
1188
- */
1189
- constructor(
1190
- source: string,
1191
- options?: {
1192
- /**
1257
+ /**
1258
+ * Create a new RichString object from a string.
1259
+ *
1260
+ * @param source The string to convert to a RichString object.
1261
+ * @param options Options for the conversion.
1262
+ */
1263
+ constructor(
1264
+ source: string,
1265
+ options?: {
1266
+ /**
1193
1267
  Format of the source string. Default is 'rtf'.
1194
1268
  */
1195
- format?: "rtf" | "html" | "markdown";
1196
- },
1197
- );
1198
- /**
1199
- * An RTF representation of the content.
1200
- */
1201
- readonly rtf: string;
1202
- /**
1203
- * An HTML representation of the content.
1204
- */
1205
- readonly html: string;
1269
+ format?: "rtf" | "html" | "markdown";
1270
+ },
1271
+ );
1272
+ /**
1273
+ * An RTF representation of the content.
1274
+ */
1275
+ readonly rtf: string;
1276
+ /**
1277
+ * An HTML representation of the content.
1278
+ */
1279
+ readonly html: string;
1206
1280
  }
1207
1281
 
1208
1282
  /**
@@ -1254,5 +1328,5 @@ declare function sleep(durationMilliseconds: number): Promise<void>;
1254
1328
  * @param extension The extension object to export.
1255
1329
  */
1256
1330
  declare function defineExtension<CustomOptions = Options>(
1257
- extension: Extension<CustomOptions>,
1331
+ extension: Extension<CustomOptions>,
1258
1332
  ): void;