@silkui/core 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -171,6 +171,42 @@ registerShortcut("Mod+Shift+B", build); // Mod is Command on macOS, Control else
171
171
  whichever app has focus; another app may hold it, and Wayland has none. `removeTray()` and
172
172
  `unregisterShortcut(accelerator)` undo them.
173
173
 
174
+ The rest of a desktop app's shell is direct calls too, shaped like Electron's so a desktop app
175
+ moves over without an IPC layer. Everything runs in the app's own process.
176
+
177
+ ```ts
178
+ import { setApplicationMenu, showContextMenu, showOpenDialog, appWindow } from "@silkui/core";
179
+
180
+ setApplicationMenu([
181
+ { role: "appMenu" },
182
+ { label: "File", submenu: [{ label: "Open…", accelerator: "Mod+O", click: open }] },
183
+ { role: "editMenu" },
184
+ { role: "viewMenu" },
185
+ { role: "windowMenu" },
186
+ ]);
187
+ node.addEventListener("contextmenu", (event) =>
188
+ showContextMenu([{ label: "Rename", click: rename }, { type: "separator" }, { label: "Delete", click: remove }], {
189
+ x: event.clientX,
190
+ y: event.clientY,
191
+ }),
192
+ );
193
+ const { canceled, filePaths } = await showOpenDialog({ properties: ["openDirectory"] });
194
+ appWindow.addEventListener("fullscreenchange", ({ fullScreen }) => setInset(fullScreen ? 0 : 80));
195
+ ```
196
+
197
+ | Call | Does |
198
+ | --- | --- |
199
+ | `setApplicationMenu(template)` | The menu bar. `role`s are the system's items (`quit`, `copy`, `togglefullscreen`, `front`), `zoomIn`/`zoomOut`/`resetZoom` zoom the page, `appMenu`, `editMenu`, `viewMenu`, `windowMenu` are whole menus |
200
+ | `showContextMenu(template, { x, y })` | A native context menu; resolves to `true` when it closes, or at once to `false` where the system has none (Linux, the browser) |
201
+ | `showOpenDialog({ properties, filters, defaultPath })`, `showSaveDialog(...)` | File and folder pickers; resolve to `{ canceled, filePaths }` and `{ canceled, filePath }` |
202
+ | `openExternal(url)`, `showItemInFolder(path)` | The default browser (or mail app), and Finder or Explorer with the item selected |
203
+ | `startFileDrag(paths)` | From a `pointerdown` or `pointermove`, drags the files out to other apps (macOS, Windows) |
204
+ | `setBadge(text)`, `setProgress(fraction)` | The dock or taskbar icon's badge and progress |
205
+ | `appWindow` | `setFullScreen`, `isFullScreen`, `minimize`, `focus`, `show`, `hide`, `setTitle`, `setZoomFactor`, `getZoomFactor`, and `fullscreenchange` and `zoomchange` events |
206
+
207
+ A hidden title bar with the window controls inset is the app's configuration, not a call:
208
+ `.titleBar(TitleBar.transparent(height).buttons(left, top))` in its `tasks.silk`.
209
+
174
210
  `memoryUsage()` is the app's memory as the system shows it to users, to put next to an
175
211
  Electron app's in Activity Monitor or Task Manager. It is synchronous and allocates almost
176
212
  nothing, so it can run every second.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silkui/core",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "The node and event API of a Silk UI tree for JavaScript applications that run on the embedded SilkJS engine",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.d.ts CHANGED
@@ -849,8 +849,188 @@ export function removeTray(): void;
849
849
  * elsewhere) is pressed, whichever app has focus. Resolves to whether the system took it.
850
850
  */
851
851
  export function registerShortcut(accelerator: string, callback: () => void): Promise<boolean>;
852
+
853
+ /** An event of a {@link WebView}; its other members depend on `type`. */
854
+ export class WebViewEvent {
855
+ readonly type: string;
856
+ readonly url?: string;
857
+ readonly title?: string;
858
+ readonly ok?: boolean;
859
+ readonly error?: string;
860
+ readonly progress?: number;
861
+ readonly canGoBack?: boolean;
862
+ readonly canGoForward?: boolean;
863
+ readonly request?: number;
864
+ readonly userInitiated?: boolean;
865
+ readonly focused?: boolean;
866
+ readonly level?: "debug" | "log" | "info" | "warning" | "error";
867
+ readonly message?: string;
868
+ readonly command?: string;
869
+ readonly reason?: string;
870
+ }
871
+
872
+ export interface WebViewOptions {
873
+ url?: string;
874
+ /** A name keeps cookies and storage between runs; empty forgets them when the view closes. */
875
+ profile?: string;
876
+ /** Lets Web Inspector attach (default true). */
877
+ inspectable?: boolean;
878
+ /** Every main frame navigation waits for `answerNavigation`. */
879
+ askBeforeNavigating?: boolean;
880
+ /** The node's background shows until the page paints. */
881
+ transparent?: boolean;
882
+ }
883
+
884
+ export interface WebViewScreenshot {
885
+ width: number;
886
+ height: number;
887
+ /** RGBA, rows top first, device pixels. */
888
+ data: Uint8Array;
889
+ }
890
+
891
+ /** A real browser page shown over a node (WKWebView on macOS). */
892
+ export class WebView {
893
+ readonly id: number;
894
+ readonly node: Node;
895
+ readonly opened: Promise<boolean>;
896
+ url: string;
897
+ title: string;
898
+ favicon: string;
899
+ loading: boolean;
900
+ progress: number;
901
+ canGoBack: boolean;
902
+ canGoForward: boolean;
903
+ focused: boolean;
904
+ addEventListener(type: string, listener: (event: WebViewEvent) => void): void;
905
+ removeEventListener(type: string, listener: (event: WebViewEvent) => void): void;
906
+ navigate(url: string): void;
907
+ loadHtml(html: string, baseUrl?: string): void;
908
+ back(): void;
909
+ forward(): void;
910
+ reload(): void;
911
+ hardReload(): void;
912
+ stop(): void;
913
+ setZoom(factor: number): void;
914
+ focus(): void;
915
+ openDevTools(): void;
916
+ setAudioMuted(muted: boolean): void;
917
+ setColorScheme(scheme: "system" | "light" | "dark"): void;
918
+ setShown(shown: boolean): void;
919
+ evaluate(script: string): Promise<unknown>;
920
+ snapshot(): Promise<string>;
921
+ screenshot(): Promise<WebViewScreenshot>;
922
+ clickElement(ref: string): Promise<void>;
923
+ fillElement(ref: string, text: string): Promise<void>;
924
+ clickAt(x: number, y: number, options?: { button?: number; clickCount?: number; modifiers?: number }): void;
925
+ movePointer(x: number, y: number, options?: { modifiers?: number }): void;
926
+ scroll(x: number, y: number, deltaX: number, deltaY: number, options?: { modifiers?: number }): void;
927
+ typeText(text: string): void;
928
+ pressKey(key: string, modifiers?: number): void;
929
+ answerNavigation(request: number, allow: boolean): void;
930
+ findInPage(text: string, options?: { forward?: boolean; newSession?: boolean }): Promise<{ matches: number; activeMatchOrdinal: number }>;
931
+ stopFindInPage(): void;
932
+ close(): void;
933
+ }
934
+
935
+ /** Shows a web view over `node`; the page covers its border box and follows it. */
936
+ export function createWebView(node: Node, options?: WebViewOptions): WebView;
937
+
938
+ /** Clears what the pages of a profile stored: cookies and site storage, the cache, or both. */
939
+ export function clearWebViewData(options?: { profile?: string; cookies?: boolean; cache?: boolean }): Promise<void>;
940
+
941
+ export function quit(code?: number): void;
852
942
  export function unregisterShortcut(accelerator: string): void;
853
943
 
944
+ /** An item of `setApplicationMenu` or `showContextMenu`, as Electron's menu templates. */
945
+ export interface MenuItem {
946
+ label?: string;
947
+ click?: (item: MenuItem) => void;
948
+ /** `"Mod+Shift+K"`, `"CmdOrCtrl+O"`, `"F5"`: `Mod` is Command on macOS, Control elsewhere. */
949
+ accelerator?: string;
950
+ enabled?: boolean;
951
+ checked?: boolean;
952
+ visible?: boolean;
953
+ type?: "normal" | "separator" | "checkbox" | "radio" | "submenu";
954
+ /**
955
+ * The system's own items (`about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`,
956
+ * `close`, `minimize`, `zoom`, `togglefullscreen`, `front`, `undo`, `redo`, `cut`, `copy`,
957
+ * `paste`, `selectAll`), the page zoom (`zoomIn`, `zoomOut`, `resetZoom`), or a whole menu
958
+ * (`appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `windowMenu`).
959
+ */
960
+ role?: string;
961
+ submenu?: MenuItem[];
962
+ }
963
+
964
+ /** Replaces the app's menu bar. On macOS the first menu is the app menu. */
965
+ export function setApplicationMenu(template: MenuItem[]): Promise<void>;
966
+
967
+ /**
968
+ * Opens a native context menu at `x`, `y` (CSS pixels in the window). Resolves to `true` when
969
+ * it closes, or at once to `false` where the system has none and the app draws its own.
970
+ */
971
+ export function showContextMenu(template: MenuItem[], position?: { x?: number; y?: number }): Promise<boolean>;
972
+
973
+ export interface FileFilter {
974
+ name?: string;
975
+ /** Without dots; `"*"` for every file. */
976
+ extensions: string[];
977
+ }
978
+
979
+ export interface OpenDialogOptions {
980
+ title?: string;
981
+ defaultPath?: string;
982
+ filters?: FileFilter[];
983
+ properties?: Array<"openFile" | "openDirectory" | "multiSelections" | "createDirectory" | "showHiddenFiles">;
984
+ }
985
+
986
+ export interface SaveDialogOptions {
987
+ title?: string;
988
+ /** A folder, a file name, or a path to a file. */
989
+ defaultPath?: string;
990
+ filters?: FileFilter[];
991
+ }
992
+
993
+ export function showOpenDialog(options?: OpenDialogOptions): Promise<{ canceled: boolean; filePaths: string[] }>;
994
+ export function showSaveDialog(options?: SaveDialogOptions): Promise<{ canceled: boolean; filePath: string }>;
995
+
996
+ /** Puts `text` on the dock or taskbar icon; `""` takes it off. Resolves to whether it shows. */
997
+ export function setBadge(text: string): Promise<boolean>;
998
+ /** Progress from 0 to 1 on the dock or taskbar icon; negative takes it off. */
999
+ export function setProgress(fraction: number): Promise<boolean>;
1000
+ /** Opens `url` with the system's handler (the default browser for a web page). */
1001
+ export function openExternal(url: string): Promise<boolean>;
1002
+ /** Shows the file or folder at `path` selected in Finder, Explorer or the file manager. */
1003
+ export function showItemInFolder(path: string): Promise<boolean>;
1004
+ /**
1005
+ * Drags the files at `paths` out to other apps; call it from `pointerdown` or `pointermove`
1006
+ * while the button is down. Resolves to whether it started (macOS and Windows).
1007
+ */
1008
+ export function startFileDrag(paths: string | string[]): Promise<boolean>;
1009
+
1010
+ /** The window the app runs in. */
1011
+ export interface AppWindow {
1012
+ readonly fullScreen: boolean;
1013
+ /** The page zoom, 1 at 100%. */
1014
+ readonly zoomFactor: number;
1015
+ setFullScreen(on: boolean): void;
1016
+ toggleFullScreen(): void;
1017
+ isFullScreen(): boolean;
1018
+ minimize(): void;
1019
+ /** Shows the window and brings it to the front with keyboard focus. */
1020
+ focus(): void;
1021
+ show(): void;
1022
+ hide(): void;
1023
+ setTitle(title: string): void;
1024
+ /** From 0.25 to 5; resolves to the zoom now. */
1025
+ setZoomFactor(zoom: number): Promise<number>;
1026
+ getZoomFactor(): number;
1027
+ addEventListener(type: "fullscreenchange", listener: (event: { type: "fullscreenchange"; fullScreen: boolean }) => void): void;
1028
+ addEventListener(type: "zoomchange", listener: (event: { type: "zoomchange"; zoomFactor: number }) => void): void;
1029
+ removeEventListener(type: "fullscreenchange" | "zoomchange", listener: (event: never) => void): void;
1030
+ }
1031
+
1032
+ export const appWindow: AppWindow;
1033
+
854
1034
  /** The app's memory: `footprint` in bytes over `processes` processes. */
855
1035
  export interface MemoryUsage {
856
1036
  footprint: number;