@vantail/api 0.1.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.
Files changed (109) hide show
  1. package/dist/app.d.ts +87 -0
  2. package/dist/app.d.ts.map +1 -0
  3. package/dist/app.js +79 -0
  4. package/dist/app.js.map +1 -0
  5. package/dist/autostart.d.ts +21 -0
  6. package/dist/autostart.d.ts.map +1 -0
  7. package/dist/autostart.js +28 -0
  8. package/dist/autostart.js.map +1 -0
  9. package/dist/binary.d.ts +13 -0
  10. package/dist/binary.d.ts.map +1 -0
  11. package/dist/binary.js +41 -0
  12. package/dist/binary.js.map +1 -0
  13. package/dist/clipboard.d.ts +36 -0
  14. package/dist/clipboard.d.ts.map +1 -0
  15. package/dist/clipboard.js +34 -0
  16. package/dist/clipboard.js.map +1 -0
  17. package/dist/deeplink.d.ts +36 -0
  18. package/dist/deeplink.d.ts.map +1 -0
  19. package/dist/deeplink.js +61 -0
  20. package/dist/deeplink.js.map +1 -0
  21. package/dist/dialog.d.ts +48 -0
  22. package/dist/dialog.d.ts.map +1 -0
  23. package/dist/dialog.js +25 -0
  24. package/dist/dialog.js.map +1 -0
  25. package/dist/drop.d.ts +37 -0
  26. package/dist/drop.d.ts.map +1 -0
  27. package/dist/drop.js +29 -0
  28. package/dist/drop.js.map +1 -0
  29. package/dist/error.d.ts +27 -0
  30. package/dist/error.d.ts.map +1 -0
  31. package/dist/error.js +39 -0
  32. package/dist/error.js.map +1 -0
  33. package/dist/filesystem.d.ts +99 -0
  34. package/dist/filesystem.d.ts.map +1 -0
  35. package/dist/filesystem.js +75 -0
  36. package/dist/filesystem.js.map +1 -0
  37. package/dist/hid.d.ts +69 -0
  38. package/dist/hid.d.ts.map +1 -0
  39. package/dist/hid.js +54 -0
  40. package/dist/hid.js.map +1 -0
  41. package/dist/index.d.ts +41 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +40 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/mdns.d.ts +65 -0
  46. package/dist/mdns.d.ts.map +1 -0
  47. package/dist/mdns.js +42 -0
  48. package/dist/mdns.js.map +1 -0
  49. package/dist/menu.d.ts +83 -0
  50. package/dist/menu.d.ts.map +1 -0
  51. package/dist/menu.js +55 -0
  52. package/dist/menu.js.map +1 -0
  53. package/dist/network.d.ts +61 -0
  54. package/dist/network.d.ts.map +1 -0
  55. package/dist/network.js +59 -0
  56. package/dist/network.js.map +1 -0
  57. package/dist/notification.d.ts +17 -0
  58. package/dist/notification.d.ts.map +1 -0
  59. package/dist/notification.js +13 -0
  60. package/dist/notification.js.map +1 -0
  61. package/dist/os.d.ts +22 -0
  62. package/dist/os.d.ts.map +1 -0
  63. package/dist/os.js +20 -0
  64. package/dist/os.js.map +1 -0
  65. package/dist/power.d.ts +29 -0
  66. package/dist/power.d.ts.map +1 -0
  67. package/dist/power.js +30 -0
  68. package/dist/power.js.map +1 -0
  69. package/dist/process.d.ts +69 -0
  70. package/dist/process.d.ts.map +1 -0
  71. package/dist/process.js +44 -0
  72. package/dist/process.js.map +1 -0
  73. package/dist/protocol.d.ts +66 -0
  74. package/dist/protocol.d.ts.map +1 -0
  75. package/dist/protocol.js +26 -0
  76. package/dist/protocol.js.map +1 -0
  77. package/dist/screen.d.ts +49 -0
  78. package/dist/screen.d.ts.map +1 -0
  79. package/dist/screen.js +38 -0
  80. package/dist/screen.js.map +1 -0
  81. package/dist/secrets.d.ts +31 -0
  82. package/dist/secrets.d.ts.map +1 -0
  83. package/dist/secrets.js +32 -0
  84. package/dist/secrets.js.map +1 -0
  85. package/dist/shell.d.ts +14 -0
  86. package/dist/shell.d.ts.map +1 -0
  87. package/dist/shell.js +13 -0
  88. package/dist/shell.js.map +1 -0
  89. package/dist/shortcut.d.ts +45 -0
  90. package/dist/shortcut.d.ts.map +1 -0
  91. package/dist/shortcut.js +45 -0
  92. package/dist/shortcut.js.map +1 -0
  93. package/dist/transport.d.ts +36 -0
  94. package/dist/transport.d.ts.map +1 -0
  95. package/dist/transport.js +141 -0
  96. package/dist/transport.js.map +1 -0
  97. package/dist/tray.d.ts +59 -0
  98. package/dist/tray.d.ts.map +1 -0
  99. package/dist/tray.js +30 -0
  100. package/dist/tray.js.map +1 -0
  101. package/dist/updater.d.ts +65 -0
  102. package/dist/updater.d.ts.map +1 -0
  103. package/dist/updater.js +48 -0
  104. package/dist/updater.js.map +1 -0
  105. package/dist/window.d.ts +156 -0
  106. package/dist/window.d.ts.map +1 -0
  107. package/dist/window.js +141 -0
  108. package/dist/window.js.map +1 -0
  109. package/package.json +27 -0
package/dist/app.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ export interface AppInfo {
2
+ name: string;
3
+ version: string;
4
+ identifier: string;
5
+ isDev: boolean;
6
+ }
7
+ /** Identity and lifecycle of the running application. */
8
+ export type ProgressState = "none" | "normal" | "indeterminate" | "paused" | "error";
9
+ export interface ProgressOptions {
10
+ /** 0 to 100. Leave it out to change only the state. */
11
+ value?: number;
12
+ state?: ProgressState;
13
+ }
14
+ export declare const app: {
15
+ name: () => Promise<string>;
16
+ version: () => Promise<string>;
17
+ identifier: () => Promise<string>;
18
+ info: () => Promise<AppInfo>;
19
+ /** Whether the app is running under `vantail dev`. */
20
+ isDev: () => Promise<boolean>;
21
+ /**
22
+ * The same facts as {@link app.info}, without awaiting.
23
+ *
24
+ * The runtime injects them before any application code runs, so this is
25
+ * safe to read during module evaluation. Returns `undefined` in a browser.
26
+ */
27
+ infoSync: () => AppInfo | undefined;
28
+ /**
29
+ * Send an application-defined event to another window, or to all of them.
30
+ *
31
+ * This is how two windows talk to each other: there is no shared memory
32
+ * between webviews, so a message goes out through the runtime and comes
33
+ * back in on the other side.
34
+ *
35
+ * ```ts
36
+ * // in the main window
37
+ * await app.emit("document-saved", { path }, { to: "preview" });
38
+ *
39
+ * // in the preview window
40
+ * app.listen<{ path: string }>("document-saved", ({ path }) => reload(path));
41
+ * ```
42
+ */
43
+ emit: (event: string, payload?: unknown, options?: {
44
+ to?: string;
45
+ }) => Promise<null>;
46
+ /**
47
+ * Listen for events sent with {@link app.emit}. Returns an unsubscribe
48
+ * function. The second argument tells you which window sent it.
49
+ */
50
+ listen: <T = unknown>(event: string, handler: (payload: T, meta: {
51
+ from: string;
52
+ }) => void) => (() => void);
53
+ /**
54
+ * Somebody started the application again while it was already running.
55
+ *
56
+ * Only fires when `singleInstance` is on, which is where the second launch
57
+ * hands over its arguments and exits instead of opening a second copy. The
58
+ * runtime has already brought the existing window to the front by the time
59
+ * this arrives.
60
+ */
61
+ onSecondInstance: (handler: (launch: {
62
+ args: string[];
63
+ cwd: string;
64
+ }) => void) => () => void;
65
+ /** Close the application. Does not resolve - the process is going away. */
66
+ /**
67
+ * The badge on the application's icon - an unread count, usually.
68
+ * `null` clears it.
69
+ *
70
+ * macOS shows any text. Linux shows a number, so a label that is not one is
71
+ * refused there. Windows has no text badge and answers `UNSUPPORTED`.
72
+ */
73
+ setBadge: (label: string | number | null) => Promise<null>;
74
+ /**
75
+ * The progress bar drawn across the application's icon or taskbar button.
76
+ *
77
+ * ```ts
78
+ * await app.setProgress({ value: 40, state: "normal" });
79
+ * await app.setProgress({ state: "none" }); // done
80
+ * ```
81
+ */
82
+ setProgress: (options: ProgressOptions) => Promise<null>;
83
+ quit: () => Promise<null>;
84
+ /** Relaunch the application with the same arguments. */
85
+ restart: () => Promise<null>;
86
+ };
87
+ //# sourceMappingURL=app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,yDAAyD;AACzD,MAAM,MAAM,aAAa,GACvB,MAAM,GAAG,QAAQ,GAAG,eAAe,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,eAAO,MAAM,GAAG;IACd,IAAI;IACJ,OAAO;IACP,UAAU;IACV,IAAI;IAEJ,sDAAsD;IACtD,KAAK;IAEL;;;;;OAKG;IACH,QAAQ,QAAM,OAAO,GAAG,SAAS;IAOjC;;;;;;;;;;;;;;OAcG;IACH,IAAI,UAAU,MAAM,YAAY,OAAO,YAAW;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE;IAGjE;;;OAGG;IACH,MAAM,GAAG,CAAC,GAAG,OAAO,SACX,MAAM,WACJ,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,KACpD,CAAC,MAAM,IAAI,CAAC;IAOf;;;;;;;OAOG;IACH,gBAAgB,YACL,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI;IAG5D,2EAA2E;IAC3E;;;;;;OAMG;IACH,QAAQ,UAAU,MAAM,GAAG,MAAM,GAAG,IAAI;IAKxC;;;;;;;OAOG;IACH,WAAW,YAAY,eAAe;IAGtC,IAAI;IAEJ,wDAAwD;IACxD,OAAO;CACR,CAAC"}
package/dist/app.js ADDED
@@ -0,0 +1,79 @@
1
+ import { bridgeInfo, invoke, listen } from "./transport.js";
2
+ export const app = {
3
+ name: () => invoke("app.name"),
4
+ version: () => invoke("app.version"),
5
+ identifier: () => invoke("app.identifier"),
6
+ info: () => invoke("app.info"),
7
+ /** Whether the app is running under `vantail dev`. */
8
+ isDev: () => invoke("app.isDev"),
9
+ /**
10
+ * The same facts as {@link app.info}, without awaiting.
11
+ *
12
+ * The runtime injects them before any application code runs, so this is
13
+ * safe to read during module evaluation. Returns `undefined` in a browser.
14
+ */
15
+ infoSync: () => {
16
+ const info = bridgeInfo();
17
+ if (!info)
18
+ return undefined;
19
+ const { name, version, identifier, isDev } = info;
20
+ return { name, version, identifier, isDev };
21
+ },
22
+ /**
23
+ * Send an application-defined event to another window, or to all of them.
24
+ *
25
+ * This is how two windows talk to each other: there is no shared memory
26
+ * between webviews, so a message goes out through the runtime and comes
27
+ * back in on the other side.
28
+ *
29
+ * ```ts
30
+ * // in the main window
31
+ * await app.emit("document-saved", { path }, { to: "preview" });
32
+ *
33
+ * // in the preview window
34
+ * app.listen<{ path: string }>("document-saved", ({ path }) => reload(path));
35
+ * ```
36
+ */
37
+ emit: (event, payload, options = {}) => invoke("app.emit", { event, payload: payload ?? null, ...options }),
38
+ /**
39
+ * Listen for events sent with {@link app.emit}. Returns an unsubscribe
40
+ * function. The second argument tells you which window sent it.
41
+ */
42
+ listen: (event, handler) =>
43
+ // User events travel under a `user:` prefix so an application can name
44
+ // its events anything without colliding with `window.resized` and friends.
45
+ listen(`user:${event}`, (message) => handler(message.payload, { from: message.from })),
46
+ /**
47
+ * Somebody started the application again while it was already running.
48
+ *
49
+ * Only fires when `singleInstance` is on, which is where the second launch
50
+ * hands over its arguments and exits instead of opening a second copy. The
51
+ * runtime has already brought the existing window to the front by the time
52
+ * this arrives.
53
+ */
54
+ onSecondInstance: (handler) => listen("app.secondInstance", handler),
55
+ /** Close the application. Does not resolve - the process is going away. */
56
+ /**
57
+ * The badge on the application's icon - an unread count, usually.
58
+ * `null` clears it.
59
+ *
60
+ * macOS shows any text. Linux shows a number, so a label that is not one is
61
+ * refused there. Windows has no text badge and answers `UNSUPPORTED`.
62
+ */
63
+ setBadge: (label) => invoke("app.setBadge", {
64
+ label: label === null ? null : String(label),
65
+ }),
66
+ /**
67
+ * The progress bar drawn across the application's icon or taskbar button.
68
+ *
69
+ * ```ts
70
+ * await app.setProgress({ value: 40, state: "normal" });
71
+ * await app.setProgress({ state: "none" }); // done
72
+ * ```
73
+ */
74
+ setProgress: (options) => invoke("app.setProgress", options),
75
+ quit: () => invoke("app.quit"),
76
+ /** Relaunch the application with the same arguments. */
77
+ restart: () => invoke("app.restart"),
78
+ };
79
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAmB5D,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAS,UAAU,CAAC;IACtC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAS,aAAa,CAAC;IAC5C,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAS,gBAAgB,CAAC;IAClD,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAU,UAAU,CAAC;IAEvC,sDAAsD;IACtD,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAU,WAAW,CAAC;IAEzC;;;;;OAKG;IACH,QAAQ,EAAE,GAAwB,EAAE;QAClC,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAClD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,CAAC,KAAa,EAAE,OAAiB,EAAE,OAAO,GAAoB,EAAE,EAAE,EAAE,CACxE,MAAM,CAAO,UAAU,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;IAE3E;;;OAGG;IACH,MAAM,EAAE,CACN,KAAa,EACb,OAAqD,EACvC,EAAE;IAChB,uEAAuE;IACvE,2EAA2E;IAC3E,MAAM,CAA+B,QAAQ,KAAK,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,CAChE,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CACjD;IAEH;;;;;;;OAOG;IACH,gBAAgB,EAAE,CAChB,OAA0D,EAC1D,EAAE,CAAC,MAAM,CAAkC,oBAAoB,EAAE,OAAO,CAAC;IAE3E,2EAA2E;IAC3E;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,KAA6B,EAAE,EAAE,CAC1C,MAAM,CAAO,cAAc,EAAE;QAC3B,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KAC7C,CAAC;IAEJ;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,OAAwB,EAAE,EAAE,CACxC,MAAM,CAAO,iBAAiB,EAAE,OAAO,CAAC;IAE1C,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAO,UAAU,CAAC;IAEpC,wDAAwD;IACxD,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAO,aAAa,CAAC;CAC3C,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Starting when the user logs in.
3
+ *
4
+ * Each platform keeps its own register of these - a launch agent on macOS, a
5
+ * `Run` value on Windows, a desktop entry on Linux - and all three name a
6
+ * path, so this only works on a packaged application. Calling it from
7
+ * `vantail dev` throws `UNSUPPORTED` rather than registering a path that will
8
+ * not exist tomorrow.
9
+ *
10
+ * ```ts
11
+ * if (!(await autostart.isEnabled())) await autostart.enable();
12
+ * ```
13
+ */
14
+ export declare const autostart: {
15
+ /** Start this application at login. */
16
+ enable(): Promise<void>;
17
+ /** Stop starting it. Doing this twice is not an error. */
18
+ disable(): Promise<void>;
19
+ isEnabled(): Promise<boolean>;
20
+ };
21
+ //# sourceMappingURL=autostart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autostart.d.ts","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS;IACpB,uCAAuC;IACvC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,0DAA0D;IAC1D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;CAG9B,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { invoke } from "./transport.js";
2
+ /**
3
+ * Starting when the user logs in.
4
+ *
5
+ * Each platform keeps its own register of these - a launch agent on macOS, a
6
+ * `Run` value on Windows, a desktop entry on Linux - and all three name a
7
+ * path, so this only works on a packaged application. Calling it from
8
+ * `vantail dev` throws `UNSUPPORTED` rather than registering a path that will
9
+ * not exist tomorrow.
10
+ *
11
+ * ```ts
12
+ * if (!(await autostart.isEnabled())) await autostart.enable();
13
+ * ```
14
+ */
15
+ export const autostart = {
16
+ /** Start this application at login. */
17
+ enable() {
18
+ return invoke("autostart.enable");
19
+ },
20
+ /** Stop starting it. Doing this twice is not an error. */
21
+ disable() {
22
+ return invoke("autostart.disable");
23
+ },
24
+ isEnabled() {
25
+ return invoke("autostart.isEnabled");
26
+ },
27
+ };
28
+ //# sourceMappingURL=autostart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autostart.js","sourceRoot":"","sources":["../src/autostart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,uCAAuC;IACvC,MAAM;QACJ,OAAO,MAAM,CAAO,kBAAkB,CAAC,CAAC;IAC1C,CAAC;IAED,0DAA0D;IAC1D,OAAO;QACL,OAAO,MAAM,CAAO,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IAED,SAAS;QACP,OAAO,MAAM,CAAU,qBAAqB,CAAC,CAAC;IAChD,CAAC;CACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Binary data on the wire.
3
+ *
4
+ * The IPC channel carries JSON, so bytes travel as base64. That costs a third
5
+ * again in size and has to be built in memory on both sides, which is why the
6
+ * runtime caps binary calls at 64 MB rather than pretending this is a stream.
7
+ */
8
+ /** Bytes accepted by `filesystem.writeBinary`. */
9
+ export type BinaryInput = Uint8Array | ArrayBuffer | ArrayBufferView;
10
+ export declare function toBytes(input: BinaryInput): Uint8Array;
11
+ export declare function encode(input: BinaryInput): string;
12
+ export declare function decode(base64: string): Uint8Array;
13
+ //# sourceMappingURL=binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,eAAe,CAAC;AAErE,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAItD;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAejD;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAYjD"}
package/dist/binary.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Binary data on the wire.
3
+ *
4
+ * The IPC channel carries JSON, so bytes travel as base64. That costs a third
5
+ * again in size and has to be built in memory on both sides, which is why the
6
+ * runtime caps binary calls at 64 MB rather than pretending this is a stream.
7
+ */
8
+ export function toBytes(input) {
9
+ if (input instanceof Uint8Array)
10
+ return input;
11
+ if (input instanceof ArrayBuffer)
12
+ return new Uint8Array(input);
13
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
14
+ }
15
+ export function encode(input) {
16
+ const bytes = toBytes(input);
17
+ // Newer engines have this and it is markedly faster on large buffers.
18
+ const fast = bytes.toBase64;
19
+ if (typeof fast === "function")
20
+ return fast.call(bytes);
21
+ // btoa takes a string of code units, and a spread of a large array blows
22
+ // the argument limit - hence the chunking.
23
+ let binary = "";
24
+ const CHUNK = 0x8000;
25
+ for (let index = 0; index < bytes.length; index += CHUNK) {
26
+ binary += String.fromCharCode(...bytes.subarray(index, index + CHUNK));
27
+ }
28
+ return btoa(binary);
29
+ }
30
+ export function decode(base64) {
31
+ const fast = Uint8Array.fromBase64;
32
+ if (typeof fast === "function")
33
+ return fast(base64);
34
+ const binary = atob(base64);
35
+ const bytes = new Uint8Array(binary.length);
36
+ for (let index = 0; index < binary.length; index += 1) {
37
+ bytes[index] = binary.charCodeAt(index);
38
+ }
39
+ return bytes;
40
+ }
41
+ //# sourceMappingURL=binary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.js","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,UAAU,OAAO,CAAC,KAAkB;IACxC,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9C,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/D,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAkB;IACvC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAE7B,sEAAsE;IACtE,MAAM,IAAI,GAAI,KAAqC,CAAC,QAAQ,CAAC;IAC7D,IAAI,OAAO,IAAI,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAExD,yEAAyE;IACzE,2CAA2C;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,KAAK,GAAG,MAAM,CAAC;IACrB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,KAAK,EAAE,CAAC;QACzD,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,MAAc;IACnC,MAAM,IAAI,GACR,UACD,CAAC,UAAU,CAAC;IACb,IAAI,OAAO,IAAI,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { type BinaryInput } from "./binary.js";
2
+ export interface ClipboardImage {
3
+ width: number;
4
+ height: number;
5
+ /** The image as PNG bytes. */
6
+ data: Uint8Array;
7
+ }
8
+ /** The system clipboard. */
9
+ export declare const clipboard: {
10
+ /** Resolves to an empty string when the clipboard holds no text. */
11
+ readText: () => Promise<string>;
12
+ writeText: (text: string) => Promise<null>;
13
+ hasText: () => Promise<boolean>;
14
+ clear: () => Promise<null>;
15
+ /**
16
+ * The clipboard's image as PNG bytes, or `null` when it holds no image.
17
+ *
18
+ * ```ts
19
+ * const image = await clipboard.readImage();
20
+ * if (image) {
21
+ * const url = URL.createObjectURL(new Blob([image.data], { type: "image/png" }));
22
+ * document.querySelector("img").src = url;
23
+ * }
24
+ * ```
25
+ */
26
+ readImage(): Promise<ClipboardImage | null>;
27
+ /**
28
+ * Put a PNG on the clipboard.
29
+ *
30
+ * The clipboard itself holds raw pixels, so this is converted on the way -
31
+ * an image without an alpha channel is fine.
32
+ */
33
+ writeImage: (png: BinaryInput) => Promise<null>;
34
+ hasImage: () => Promise<boolean>;
35
+ };
36
+ //# sourceMappingURL=clipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/D,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,4BAA4B;AAC5B,eAAO,MAAM,SAAS;IACpB,oEAAoE;IACpE,QAAQ;IACR,SAAS,SAAS,MAAM;IACxB,OAAO;IACP,KAAK;IAEL;;;;;;;;;;OAUG;IACG,SAAS,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAUjD;;;;;OAKG;IACH,UAAU,QAAQ,WAAW;IAG7B,QAAQ;CACT,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { decode, encode } from "./binary.js";
2
+ import { invoke } from "./transport.js";
3
+ /** The system clipboard. */
4
+ export const clipboard = {
5
+ /** Resolves to an empty string when the clipboard holds no text. */
6
+ readText: () => invoke("clipboard.readText"),
7
+ writeText: (text) => invoke("clipboard.writeText", { text }),
8
+ hasText: () => invoke("clipboard.hasText"),
9
+ clear: () => invoke("clipboard.clear"),
10
+ /**
11
+ * The clipboard's image as PNG bytes, or `null` when it holds no image.
12
+ *
13
+ * ```ts
14
+ * const image = await clipboard.readImage();
15
+ * if (image) {
16
+ * const url = URL.createObjectURL(new Blob([image.data], { type: "image/png" }));
17
+ * document.querySelector("img").src = url;
18
+ * }
19
+ * ```
20
+ */
21
+ async readImage() {
22
+ const result = await invoke("clipboard.readImage");
23
+ return result && { ...result, data: decode(result.data) };
24
+ },
25
+ /**
26
+ * Put a PNG on the clipboard.
27
+ *
28
+ * The clipboard itself holds raw pixels, so this is converted on the way -
29
+ * an image without an alpha channel is fine.
30
+ */
31
+ writeImage: (png) => invoke("clipboard.writeImage", { data: encode(png) }),
32
+ hasImage: () => invoke("clipboard.hasImage"),
33
+ };
34
+ //# sourceMappingURL=clipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AASxC,4BAA4B;AAC5B,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,oEAAoE;IACpE,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAS,oBAAoB,CAAC;IACpD,SAAS,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAO,qBAAqB,EAAE,EAAE,IAAI,EAAE,CAAC;IAC1E,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAU,mBAAmB,CAAC;IACnD,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAO,iBAAiB,CAAC;IAE5C;;;;;;;;;;OAUG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,MAAM,GAAG,MAAM,MAAM,CAIjB,qBAAqB,CAAC,CAAC;QAEjC,OAAO,MAAM,IAAI,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACH,UAAU,EAAE,CAAC,GAAgB,EAAE,EAAE,CAC/B,MAAM,CAAO,sBAAsB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAE7D,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAU,oBAAoB,CAAC;CACtD,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Links to your application, from anywhere on the machine.
3
+ *
4
+ * Register a scheme in `vantail.config.ts` and `myapp://...` reaches you -
5
+ * which is how a desktop application finishes an OAuth sign-in, since the
6
+ * browser needs somewhere to send the user back to.
7
+ *
8
+ * ```ts
9
+ * deepLink.onOpen((url) => {
10
+ * const code = new URL(url).searchParams.get("code");
11
+ * if (code) void exchangeForToken(code);
12
+ * });
13
+ * ```
14
+ *
15
+ * **Treat the URL as input from a stranger.** Any web page or program on the
16
+ * machine can open one. The runtime guarantees only that the scheme is one of
17
+ * yours; everything after that is unverified, so check the state parameter of
18
+ * an OAuth callback rather than trusting it arrived.
19
+ *
20
+ * A link that launched the application arrives before any page exists. It is
21
+ * held for you, and delivered as soon as you register a handler - so there is
22
+ * no window in which the link that started the app can be missed.
23
+ */
24
+ export declare const deepLink: {
25
+ /**
26
+ * Handle links, including any that arrived before this ran.
27
+ *
28
+ * Returns an unsubscribe function.
29
+ */
30
+ onOpen: (handler: (url: string) => void) => (() => void);
31
+ /** The schemes this application registered. */
32
+ protocols: () => Promise<string[]>;
33
+ };
34
+ /** Only used by tests, to undo the module-level cache. */
35
+ export declare function resetDeepLinkState(): void;
36
+ //# sourceMappingURL=deeplink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deeplink.d.ts","sourceRoot":"","sources":["../src/deeplink.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,QAAQ;IACnB;;;;OAIG;IACH,MAAM,YAAY,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC;IAqBtD,+CAA+C;IAC/C,SAAS;CACV,CAAC;AAUF,0DAA0D;AAC1D,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
@@ -0,0 +1,61 @@
1
+ import { invoke, listen } from "./transport.js";
2
+ /**
3
+ * Links to your application, from anywhere on the machine.
4
+ *
5
+ * Register a scheme in `vantail.config.ts` and `myapp://...` reaches you -
6
+ * which is how a desktop application finishes an OAuth sign-in, since the
7
+ * browser needs somewhere to send the user back to.
8
+ *
9
+ * ```ts
10
+ * deepLink.onOpen((url) => {
11
+ * const code = new URL(url).searchParams.get("code");
12
+ * if (code) void exchangeForToken(code);
13
+ * });
14
+ * ```
15
+ *
16
+ * **Treat the URL as input from a stranger.** Any web page or program on the
17
+ * machine can open one. The runtime guarantees only that the scheme is one of
18
+ * yours; everything after that is unverified, so check the state parameter of
19
+ * an OAuth callback rather than trusting it arrived.
20
+ *
21
+ * A link that launched the application arrives before any page exists. It is
22
+ * held for you, and delivered as soon as you register a handler - so there is
23
+ * no window in which the link that started the app can be missed.
24
+ */
25
+ export const deepLink = {
26
+ /**
27
+ * Handle links, including any that arrived before this ran.
28
+ *
29
+ * Returns an unsubscribe function.
30
+ */
31
+ onOpen: (handler) => {
32
+ // Registered before subscribing: subscribing releases whatever the
33
+ // runtime was holding, and a handler added afterwards would miss exactly
34
+ // the link it was written for.
35
+ const stop = listen("deeplink.open", ({ url }) => handler(url));
36
+ if (arrived === undefined) {
37
+ // First subscriber: ask the runtime for what it held, and remember it
38
+ // so a handler registered later in this session still sees it.
39
+ arrived = invoke("deeplink.subscribe");
40
+ }
41
+ void arrived.then((urls) => {
42
+ for (const url of urls)
43
+ handler(url);
44
+ });
45
+ return stop;
46
+ },
47
+ /** The schemes this application registered. */
48
+ protocols: () => invoke("deeplink.protocols"),
49
+ };
50
+ /**
51
+ * Links the application was started with.
52
+ *
53
+ * Cached so that every handler sees them, not only whichever one happened to
54
+ * register first.
55
+ */
56
+ let arrived;
57
+ /** Only used by tests, to undo the module-level cache. */
58
+ export function resetDeepLinkState() {
59
+ arrived = undefined;
60
+ }
61
+ //# sourceMappingURL=deeplink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deeplink.js","sourceRoot":"","sources":["../src/deeplink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB;;;;OAIG;IACH,MAAM,EAAE,CAAC,OAA8B,EAAgB,EAAE;QACvD,mEAAmE;QACnE,yEAAyE;QACzE,+BAA+B;QAC/B,MAAM,IAAI,GAAG,MAAM,CAAkB,eAAe,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAChE,OAAO,CAAC,GAAG,CAAC,CACb,CAAC;QAEF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,sEAAsE;YACtE,+DAA+D;YAC/D,OAAO,GAAG,MAAM,CAAW,oBAAoB,CAAC,CAAC;QACnD,CAAC;QAED,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACzB,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+CAA+C;IAC/C,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAW,oBAAoB,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,IAAI,OAAsC,CAAC;AAE3C,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB;IAChC,OAAO,GAAG,SAAS,CAAC;AACtB,CAAC"}
@@ -0,0 +1,48 @@
1
+ export interface FileFilter {
2
+ /** Shown in the dialog's file-type dropdown, e.g. "Markdown". */
3
+ name: string;
4
+ /** Extensions without the dot, e.g. `["md", "markdown"]`. */
5
+ extensions: string[];
6
+ }
7
+ export interface OpenOptions {
8
+ title?: string;
9
+ /** A file or directory to open the dialog at. */
10
+ defaultPath?: string;
11
+ filters?: FileFilter[];
12
+ }
13
+ export interface SaveOptions {
14
+ title?: string;
15
+ defaultPath?: string;
16
+ /** Pre-filled file name. */
17
+ defaultName?: string;
18
+ filters?: FileFilter[];
19
+ }
20
+ export interface MessageOptions {
21
+ title?: string;
22
+ kind?: "info" | "warning" | "error";
23
+ }
24
+ export interface ConfirmOptions extends MessageOptions {
25
+ okLabel?: string;
26
+ cancelLabel?: string;
27
+ }
28
+ /**
29
+ * Native dialogs.
30
+ *
31
+ * A path the user picks here is also *granted* to `filesystem` for the rest
32
+ * of the session - the user's choice is the authorisation. That is what makes
33
+ * a tight `permissions.filesystem` scope practical.
34
+ *
35
+ * Every picker resolves to `null` when the user cancels.
36
+ */
37
+ export declare const dialog: {
38
+ openFile: (options?: OpenOptions) => Promise<string | null>;
39
+ openFiles: (options?: OpenOptions) => Promise<string[]>;
40
+ openDirectory: (options?: OpenOptions) => Promise<string | null>;
41
+ openDirectories: (options?: OpenOptions) => Promise<string[]>;
42
+ saveFile: (options?: SaveOptions) => Promise<string | null>;
43
+ /** An informational dialog with a single dismiss button. */
44
+ message: (message: string, options?: MessageOptions) => Promise<null>;
45
+ /** Resolves `true` when the user accepts. */
46
+ confirm: (message: string, options?: ConfirmOptions) => Promise<boolean>;
47
+ };
48
+ //# sourceMappingURL=dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../src/dialog.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM;IACjB,QAAQ,aAAY,WAAW;IAG/B,SAAS,aAAY,WAAW;IAGhC,aAAa,aAAY,WAAW;IAMpC,eAAe,aAAY,WAAW;IAGtC,QAAQ,aAAY,WAAW;IAG/B,4DAA4D;IAC5D,OAAO,YAAY,MAAM,YAAW,cAAc;IAGlD,6CAA6C;IAC7C,OAAO,YAAY,MAAM,YAAW,cAAc;CAEnD,CAAC"}
package/dist/dialog.js ADDED
@@ -0,0 +1,25 @@
1
+ import { invoke } from "./transport.js";
2
+ /**
3
+ * Native dialogs.
4
+ *
5
+ * A path the user picks here is also *granted* to `filesystem` for the rest
6
+ * of the session - the user's choice is the authorisation. That is what makes
7
+ * a tight `permissions.filesystem` scope practical.
8
+ *
9
+ * Every picker resolves to `null` when the user cancels.
10
+ */
11
+ export const dialog = {
12
+ openFile: (options = {}) => invoke("dialog.openFile", { ...options, multiple: false }),
13
+ openFiles: (options = {}) => invoke("dialog.openFile", { ...options, multiple: true }),
14
+ openDirectory: (options = {}) => invoke("dialog.openDirectory", {
15
+ ...options,
16
+ multiple: false,
17
+ }),
18
+ openDirectories: (options = {}) => invoke("dialog.openDirectory", { ...options, multiple: true }),
19
+ saveFile: (options = {}) => invoke("dialog.saveFile", { ...options, multiple: false }),
20
+ /** An informational dialog with a single dismiss button. */
21
+ message: (message, options = {}) => invoke("dialog.message", { ...options, message }),
22
+ /** Resolves `true` when the user accepts. */
23
+ confirm: (message, options = {}) => invoke("dialog.confirm", { ...options, message }),
24
+ };
25
+ //# sourceMappingURL=dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.js","sourceRoot":"","sources":["../src/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAkCxC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,QAAQ,EAAE,CAAC,OAAO,GAAgB,EAAE,EAAE,EAAE,CACtC,MAAM,CAAgB,iBAAiB,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAE3E,SAAS,EAAE,CAAC,OAAO,GAAgB,EAAE,EAAE,EAAE,CACvC,MAAM,CAAW,iBAAiB,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAErE,aAAa,EAAE,CAAC,OAAO,GAAgB,EAAE,EAAE,EAAE,CAC3C,MAAM,CAAgB,sBAAsB,EAAE;QAC5C,GAAG,OAAO;QACV,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEJ,eAAe,EAAE,CAAC,OAAO,GAAgB,EAAE,EAAE,EAAE,CAC7C,MAAM,CAAW,sBAAsB,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAE1E,QAAQ,EAAE,CAAC,OAAO,GAAgB,EAAE,EAAE,EAAE,CACtC,MAAM,CAAgB,iBAAiB,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAE3E,4DAA4D;IAC5D,OAAO,EAAE,CAAC,OAAe,EAAE,OAAO,GAAmB,EAAE,EAAE,EAAE,CACzD,MAAM,CAAO,gBAAgB,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;IAEzD,6CAA6C;IAC7C,OAAO,EAAE,CAAC,OAAe,EAAE,OAAO,GAAmB,EAAE,EAAE,EAAE,CACzD,MAAM,CAAU,gBAAgB,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC;CAC7D,CAAC"}
package/dist/drop.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ export interface DropEvent {
2
+ /** Absolute paths of what was dropped. */
3
+ paths: string[];
4
+ /** Where, relative to the window's top-left corner. */
5
+ position: {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ }
10
+ /**
11
+ * Files dragged onto the window.
12
+ *
13
+ * HTML5 drag events give a page the *contents* of a dropped file but never its
14
+ * path, so a dropped file cannot be handed to {@link filesystem}. These events
15
+ * carry the paths, and a dropped path becomes readable for the rest of the
16
+ * session - dropping a file is the user choosing it, exactly as a dialog is.
17
+ * (`filesystem.grantFromDrop`, on by default, controls that.)
18
+ *
19
+ * Needs `permissions.dragDrop`. **Turning it on changes what the page sees:**
20
+ * the runtime handles the drop, so HTML5 `drop` events stop firing for files
21
+ * and these arrive instead. With the permission off, nothing changes.
22
+ *
23
+ * ```ts
24
+ * fileDrop.onDrop(async ({ paths }) => {
25
+ * for (const path of paths) console.log(await filesystem.readText(path));
26
+ * });
27
+ * ```
28
+ */
29
+ export declare const fileDrop: {
30
+ /** A drag arrived over the window, carrying these paths. */
31
+ onEnter: (handler: (event: DropEvent) => void) => () => void;
32
+ /** They were let go. */
33
+ onDrop: (handler: (event: DropEvent) => void) => () => void;
34
+ /** The drag left the window, or was cancelled. */
35
+ onLeave: (handler: () => void) => () => void;
36
+ };
37
+ //# sourceMappingURL=drop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drop.d.ts","sourceRoot":"","sources":["../src/drop.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACxB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,uDAAuD;IACvD,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ;IACnB,4DAA4D;IAC5D,OAAO,YAAY,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI;IAG7C,wBAAwB;IACxB,MAAM,YAAY,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI;IAG5C,kDAAkD;IAClD,OAAO,YAAY,MAAM,IAAI;CAE9B,CAAC"}
package/dist/drop.js ADDED
@@ -0,0 +1,29 @@
1
+ import { listen } from "./transport.js";
2
+ /**
3
+ * Files dragged onto the window.
4
+ *
5
+ * HTML5 drag events give a page the *contents* of a dropped file but never its
6
+ * path, so a dropped file cannot be handed to {@link filesystem}. These events
7
+ * carry the paths, and a dropped path becomes readable for the rest of the
8
+ * session - dropping a file is the user choosing it, exactly as a dialog is.
9
+ * (`filesystem.grantFromDrop`, on by default, controls that.)
10
+ *
11
+ * Needs `permissions.dragDrop`. **Turning it on changes what the page sees:**
12
+ * the runtime handles the drop, so HTML5 `drop` events stop firing for files
13
+ * and these arrive instead. With the permission off, nothing changes.
14
+ *
15
+ * ```ts
16
+ * fileDrop.onDrop(async ({ paths }) => {
17
+ * for (const path of paths) console.log(await filesystem.readText(path));
18
+ * });
19
+ * ```
20
+ */
21
+ export const fileDrop = {
22
+ /** A drag arrived over the window, carrying these paths. */
23
+ onEnter: (handler) => listen("drop.entered", handler),
24
+ /** They were let go. */
25
+ onDrop: (handler) => listen("drop.dropped", handler),
26
+ /** The drag left the window, or was cancelled. */
27
+ onLeave: (handler) => listen("drop.left", handler),
28
+ };
29
+ //# sourceMappingURL=drop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drop.js","sourceRoot":"","sources":["../src/drop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AASxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,4DAA4D;IAC5D,OAAO,EAAE,CAAC,OAAmC,EAAE,EAAE,CAC/C,MAAM,CAAY,cAAc,EAAE,OAAO,CAAC;IAE5C,wBAAwB;IACxB,MAAM,EAAE,CAAC,OAAmC,EAAE,EAAE,CAC9C,MAAM,CAAY,cAAc,EAAE,OAAO,CAAC;IAE5C,kDAAkD;IAClD,OAAO,EAAE,CAAC,OAAmB,EAAE,EAAE,CAC/B,MAAM,CAAwB,WAAW,EAAE,OAAO,CAAC;CACtD,CAAC"}