@krate/app 0.0.0-stage → 0.5.0-rc.11

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 (132) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +88 -2
  3. package/dist/automation.d.ts +11 -0
  4. package/dist/automation.d.ts.map +1 -0
  5. package/dist/automation.js +27 -0
  6. package/dist/badge.d.ts +13 -0
  7. package/dist/badge.d.ts.map +1 -0
  8. package/dist/badge.js +34 -0
  9. package/dist/chrome.d.ts +90 -0
  10. package/dist/chrome.d.ts.map +1 -0
  11. package/dist/chrome.js +133 -0
  12. package/dist/client.d.ts +26 -0
  13. package/dist/client.d.ts.map +1 -0
  14. package/dist/client.js +545 -0
  15. package/dist/clipboard.d.ts +19 -0
  16. package/dist/clipboard.d.ts.map +1 -0
  17. package/dist/clipboard.js +51 -0
  18. package/dist/cookies.d.ts +44 -0
  19. package/dist/cookies.d.ts.map +1 -0
  20. package/dist/cookies.js +45 -0
  21. package/dist/crash.d.ts +35 -0
  22. package/dist/crash.d.ts.map +1 -0
  23. package/dist/crash.js +28 -0
  24. package/dist/db.d.ts +14 -0
  25. package/dist/db.d.ts.map +1 -0
  26. package/dist/db.js +23 -0
  27. package/dist/dialog.d.ts +36 -0
  28. package/dist/dialog.d.ts.map +1 -0
  29. package/dist/dialog.js +23 -0
  30. package/dist/downloads.d.ts +35 -0
  31. package/dist/downloads.d.ts.map +1 -0
  32. package/dist/downloads.js +30 -0
  33. package/dist/driver.d.ts +190 -0
  34. package/dist/driver.d.ts.map +1 -0
  35. package/dist/driver.js +637 -0
  36. package/dist/errors.d.ts +7 -0
  37. package/dist/errors.d.ts.map +1 -0
  38. package/dist/errors.js +11 -0
  39. package/dist/events.d.ts +6 -0
  40. package/dist/events.d.ts.map +1 -0
  41. package/dist/events.js +47 -0
  42. package/dist/extension.d.ts +10 -0
  43. package/dist/extension.d.ts.map +1 -0
  44. package/dist/extension.js +25 -0
  45. package/dist/fakehost.d.ts +18 -0
  46. package/dist/fakehost.d.ts.map +1 -0
  47. package/dist/fakehost.js +199 -0
  48. package/dist/fs.d.ts +26 -0
  49. package/dist/fs.d.ts.map +1 -0
  50. package/dist/fs.js +38 -0
  51. package/dist/host.d.ts +4 -0
  52. package/dist/host.d.ts.map +1 -0
  53. package/dist/host.js +25 -0
  54. package/dist/index.d.ts +19 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +40 -0
  57. package/dist/kv.d.ts +6 -0
  58. package/dist/kv.d.ts.map +1 -0
  59. package/dist/kv.js +19 -0
  60. package/dist/lifecycle.d.ts +22 -0
  61. package/dist/lifecycle.d.ts.map +1 -0
  62. package/dist/lifecycle.js +85 -0
  63. package/dist/login.d.ts +10 -0
  64. package/dist/login.d.ts.map +1 -0
  65. package/dist/login.js +8 -0
  66. package/dist/media.d.ts +50 -0
  67. package/dist/media.d.ts.map +1 -0
  68. package/dist/media.js +70 -0
  69. package/dist/menu.d.ts +71 -0
  70. package/dist/menu.d.ts.map +1 -0
  71. package/dist/menu.js +114 -0
  72. package/dist/mock.d.ts +14 -0
  73. package/dist/mock.d.ts.map +1 -0
  74. package/dist/mock.js +47 -0
  75. package/dist/notify.d.ts +25 -0
  76. package/dist/notify.d.ts.map +1 -0
  77. package/dist/notify.js +32 -0
  78. package/dist/offscreen.d.ts +24 -0
  79. package/dist/offscreen.d.ts.map +1 -0
  80. package/dist/offscreen.js +27 -0
  81. package/dist/os.d.ts +20 -0
  82. package/dist/os.d.ts.map +1 -0
  83. package/dist/os.js +43 -0
  84. package/dist/page.d.ts +69 -0
  85. package/dist/page.d.ts.map +1 -0
  86. package/dist/page.js +61 -0
  87. package/dist/permission.d.ts +5 -0
  88. package/dist/permission.d.ts.map +1 -0
  89. package/dist/permission.js +18 -0
  90. package/dist/port.d.ts +35 -0
  91. package/dist/port.d.ts.map +1 -0
  92. package/dist/port.js +159 -0
  93. package/dist/power.d.ts +19 -0
  94. package/dist/power.d.ts.map +1 -0
  95. package/dist/power.js +35 -0
  96. package/dist/remote.d.ts +156 -0
  97. package/dist/remote.d.ts.map +1 -0
  98. package/dist/remote.js +115 -0
  99. package/dist/screen.d.ts +25 -0
  100. package/dist/screen.d.ts.map +1 -0
  101. package/dist/screen.js +23 -0
  102. package/dist/shortcut.d.ts +2 -0
  103. package/dist/shortcut.d.ts.map +1 -0
  104. package/dist/shortcut.js +44 -0
  105. package/dist/testing.d.ts +6 -0
  106. package/dist/testing.d.ts.map +1 -0
  107. package/dist/testing.js +9 -0
  108. package/dist/theme.d.ts +12 -0
  109. package/dist/theme.d.ts.map +1 -0
  110. package/dist/theme.js +13 -0
  111. package/dist/tray.d.ts +18 -0
  112. package/dist/tray.d.ts.map +1 -0
  113. package/dist/tray.js +23 -0
  114. package/dist/types.d.ts +16 -0
  115. package/dist/types.d.ts.map +1 -0
  116. package/dist/types.js +1 -0
  117. package/dist/updater.d.ts +36 -0
  118. package/dist/updater.d.ts.map +1 -0
  119. package/dist/updater.js +58 -0
  120. package/dist/window.d.ts +154 -0
  121. package/dist/window.d.ts.map +1 -0
  122. package/dist/window.js +205 -0
  123. package/dist/wire.d.ts +26 -0
  124. package/dist/wire.d.ts.map +1 -0
  125. package/dist/wire.js +328 -0
  126. package/dist/worker-host.d.ts +6 -0
  127. package/dist/worker-host.d.ts.map +1 -0
  128. package/dist/worker-host.js +36 -0
  129. package/dist/worker.d.ts +62 -0
  130. package/dist/worker.d.ts.map +1 -0
  131. package/dist/worker.js +86 -0
  132. package/package.json +188 -3
@@ -0,0 +1,50 @@
1
+ import { type SubscribeOptions } from "./events.js";
2
+ export type PermissionKind = "camera" | "microphone" | "screen" | "location" | "notifications" | "clipboardRead";
3
+ export type PermissionPolicy = "prompt" | "allow" | "deny";
4
+ export type Remember = "app" | "view" | "none";
5
+ export type OSConsentKind = "camera" | "microphone" | "screen" | "location";
6
+ export type OSConsent = "granted" | "denied" | "notDetermined" | "restricted" | "unknown";
7
+ export type MediaPolicy = Record<PermissionKind, PermissionPolicy>;
8
+ export interface PermissionDecision {
9
+ kind: PermissionKind;
10
+ scope: string;
11
+ allow: boolean;
12
+ at: Date | string;
13
+ }
14
+ export interface PermissionRequest {
15
+ id: number;
16
+ view: string;
17
+ origin: string;
18
+ kinds: PermissionKind[];
19
+ }
20
+ export interface PermissionOutcome extends PermissionRequest {
21
+ allowed: boolean;
22
+ reason: string;
23
+ }
24
+ export interface Verdict {
25
+ allow: boolean;
26
+ remember?: Remember;
27
+ }
28
+ export interface CaptureSource {
29
+ id: string;
30
+ kind: "screen" | "window";
31
+ name: string;
32
+ app: string;
33
+ width: number;
34
+ height: number;
35
+ thumbnail: Uint8Array | null;
36
+ }
37
+ export declare function getPolicy(): Promise<MediaPolicy>;
38
+ export declare function setPolicy(kind: PermissionKind, policy: PermissionPolicy): Promise<void>;
39
+ export declare function decisions(): Promise<PermissionDecision[]>;
40
+ export declare function decide(kind: PermissionKind, allow: boolean, scope?: string): Promise<void>;
41
+ export declare function reset(kind?: PermissionKind): Promise<void>;
42
+ export declare function onRequest(handler: (r: PermissionRequest) => Verdict | boolean | Promise<Verdict | boolean>, opts?: SubscribeOptions): () => void;
43
+ export declare function onOutcome(fn: (o: PermissionOutcome) => void, opts?: SubscribeOptions): () => void;
44
+ export declare function osStatus(kind: OSConsentKind): Promise<OSConsent>;
45
+ export declare function osRequest(kind: OSConsentKind): Promise<OSConsent>;
46
+ export declare function sources(opts?: {
47
+ thumbnailWidth?: number;
48
+ }): Promise<CaptureSource[]>;
49
+ export declare function chooseSource(id: string): Promise<void>;
50
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAMA,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,eAAe,GAAG,eAAe,CAAC;AACj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D;AAGD,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvF;AAGD,wBAAgB,SAAS,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAEzD;AAID,wBAAgB,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,SAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzF;AAGD,wBAAgB,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;AAKD,wBAAgB,SAAS,CACvB,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,EACjF,IAAI,CAAC,EAAE,gBAAgB,GACtB,MAAM,IAAI,CAiBZ;AAGD,wBAAgB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAEjG;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAEhE;AAGD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAEjE;AAKD,wBAAgB,OAAO,CAAC,IAAI,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAExF;AAKD,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD"}
package/dist/media.js ADDED
@@ -0,0 +1,70 @@
1
+ // Camera, microphone, screen capture and location for the page, with
2
+ // app-controlled permissions. Reading the state needs the "media" permission;
3
+ // changing it, answering requests and listing screens needs "media:manage".
4
+ // The page's own getUserMedia / getDisplayMedia / geolocation calls need
5
+ // "media" (camera, microphone, screen) or "location" in the window's scope.
6
+ import { call } from "./index.js";
7
+ import { subscribe } from "./events.js";
8
+ // The policy of each kind from native.media.
9
+ export function getPolicy() {
10
+ return call("krate/media.policy", []);
11
+ }
12
+ // Set what happens to undecided requests of a kind.
13
+ export function setPolicy(kind, policy) {
14
+ return call("krate/media.setPolicy", [kind, policy]);
15
+ }
16
+ // The remembered decisions.
17
+ export function decisions() {
18
+ return call("krate/media.decisions", []);
19
+ }
20
+ // Store a decision without waiting for a request. scope is "app" or a window
21
+ // or view id.
22
+ export function decide(kind, allow, scope = "app") {
23
+ return call("krate/media.decide", [kind, scope, allow]);
24
+ }
25
+ // Forget the decisions of a kind, or of all kinds.
26
+ export function reset(kind) {
27
+ return call("krate/media.reset", kind === undefined ? [] : [kind]);
28
+ }
29
+ // Decide permission requests. While a handler is subscribed, a request that no
30
+ // remembered decision covers is passed to it. The handler has a minute to
31
+ // answer; a throw or a timeout denies.
32
+ export function onRequest(handler, opts) {
33
+ return subscribe("krate/media.requests", (r) => {
34
+ void (async () => {
35
+ let v = false;
36
+ try {
37
+ v = await handler(r);
38
+ }
39
+ catch (e) {
40
+ console.error(e);
41
+ }
42
+ const verdict = typeof v === "boolean" ? { allow: v } : v;
43
+ await call("krate/media.respond", [r.id, verdict.allow, verdict.remember ?? ""]).catch(() => { });
44
+ })();
45
+ }, opts);
46
+ }
47
+ // Called when a request ended, whoever decided it.
48
+ export function onOutcome(fn, opts) {
49
+ return subscribe("krate/media.events", fn, opts);
50
+ }
51
+ // The operating system's consent state, without prompting.
52
+ export function osStatus(kind) {
53
+ return call("krate/media.osStatus", [kind]);
54
+ }
55
+ // Show the operating system's consent prompt when it was not answered yet.
56
+ export function osRequest(kind) {
57
+ return call("krate/media.osRequest", [kind]);
58
+ }
59
+ // Screens and windows that can be captured, with thumbnails of the given
60
+ // width. Fails with an "unsupported" error on a platform that cannot list them
61
+ // (Linux: the portal picker is the only way).
62
+ export function sources(opts = {}) {
63
+ return call("krate/media.sources", [{ thumbnailWidth: opts.thumbnailWidth ?? 0 }]);
64
+ }
65
+ // Would choose the source of the next getDisplayMedia call. No engine accepts
66
+ // that, so it always fails with an "unsupported" error and the system picker
67
+ // decides.
68
+ export function chooseSource(id) {
69
+ return call("krate/media.chooseSource", [id]);
70
+ }
package/dist/menu.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { type SubscribeOptions } from "./events.js";
2
+ export type ItemKind = "normal" | "check" | "radio" | "separator" | "submenu";
3
+ export interface MenuItem {
4
+ id?: string;
5
+ label?: string;
6
+ kind?: ItemKind;
7
+ accelerator?: string;
8
+ disabled?: boolean;
9
+ checked?: boolean;
10
+ submenu?: MenuItem[];
11
+ }
12
+ export interface MenuEvent {
13
+ id: string;
14
+ window: string;
15
+ checked: boolean;
16
+ }
17
+ export declare function toWire(items: MenuItem[]): unknown[];
18
+ export declare function setApp(items: MenuItem[]): Promise<void>;
19
+ export interface PopupOptions {
20
+ window?: string;
21
+ x?: number;
22
+ y?: number;
23
+ }
24
+ export declare function popup(items: MenuItem[], o?: PopupOptions): Promise<void>;
25
+ export declare function onClick(fn: (e: MenuEvent) => void, opts?: SubscribeOptions): () => void;
26
+ export declare function onMenu(id: string, fn: (e: MenuEvent) => void, opts?: SubscribeOptions): () => void;
27
+ export type ContextMenuMode = "default" | "none" | "custom" | "extend";
28
+ export interface ContextMenuOptions {
29
+ mode: ContextMenuMode;
30
+ items?: MenuItem[];
31
+ }
32
+ export type ContextKind = "page" | "link" | "image" | "media" | "editable" | "selection";
33
+ export interface ContextMenuEvent {
34
+ window: string;
35
+ view: string;
36
+ x: number;
37
+ y: number;
38
+ windowX: number;
39
+ windowY: number;
40
+ kinds: ContextKind[];
41
+ linkUrl: string;
42
+ imageUrl: string;
43
+ mediaUrl: string;
44
+ selectionText: string;
45
+ misspelled: string;
46
+ suggestions: string[];
47
+ inspectable: boolean;
48
+ }
49
+ export interface ContextMenuTarget {
50
+ window?: string;
51
+ view?: string;
52
+ }
53
+ export declare function setContextMenu(options: ContextMenuOptions, target?: ContextMenuTarget): Promise<void>;
54
+ export declare function onContext(fn: (e: ContextMenuEvent) => void, opts?: SubscribeOptions): () => void;
55
+ export declare function onContextMenu(fn: (e: ContextMenuEvent) => MenuItem[] | null | undefined | Promise<MenuItem[] | null | undefined>, opts?: SubscribeOptions): () => void;
56
+ export declare const actions: {
57
+ undo: string;
58
+ redo: string;
59
+ cut: string;
60
+ copy: string;
61
+ paste: string;
62
+ selectAll: string;
63
+ delete: string;
64
+ inspectElement: string;
65
+ addToDictionary: string;
66
+ replaceMisspelling: (word: string) => string;
67
+ copyLink: (url: string) => string;
68
+ copyImageUrl: (url: string) => string;
69
+ };
70
+ export declare function defaultContextItems(e: ContextMenuEvent): MenuItem[];
71
+ //# sourceMappingURL=menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC;AAE9E,MAAM,WAAW,QAAQ;IAEvB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,QAAQ,CAAC;IAEhB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,OAAO,CAAC;CAClB;AAID,wBAAgB,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG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MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IAGtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAGhC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAGD,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzG;AAGD,wBAAgB,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAEhG;AAKD,wBAAgB,aAAa,CAC3B,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,QAAQ,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC,EACnG,IAAI,CAAC,EAAE,gBAAgB,GACtB,MAAM,IAAI,CAKZ;AAID,eAAO,MAAM,OAAO;;;;;;;;;;+BAUS,MAAM;oBACjB,MAAM;wBACF,MAAM;CAC3B,CAAC;AAOF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,gBAAgB,GAAG,QAAQ,EAAE,CA2CnE"}
package/dist/menu.js ADDED
@@ -0,0 +1,114 @@
1
+ // Application menu bar and context menus. Needs the "menu" permission.
2
+ import { call } from "./index.js";
3
+ import { subscribe } from "./events.js";
4
+ const KINDS = { normal: 0, check: 1, radio: 2, separator: 3, submenu: 4 };
5
+ export function toWire(items) {
6
+ return items.map((it) => ({
7
+ id: it.id ?? "",
8
+ label: it.label ?? "",
9
+ kind: KINDS[it.kind ?? (it.submenu ? "submenu" : "normal")],
10
+ accelerator: it.accelerator ?? "",
11
+ disabled: it.disabled ?? false,
12
+ checked: it.checked ?? false,
13
+ submenu: toWire(it.submenu ?? []),
14
+ }));
15
+ }
16
+ // setApp installs the menu bar on every window; [] removes it.
17
+ export function setApp(items) {
18
+ return call("krate/menu.setApp", [toWire(items)]);
19
+ }
20
+ export function popup(items, o = {}) {
21
+ return call("krate/menu.popup", [o.window ?? "", o.x ?? -1, o.y ?? -1, toWire(items)]);
22
+ }
23
+ // onClick calls fn for every menu click; the returned function stops it.
24
+ export function onClick(fn, opts) {
25
+ return subscribe("krate/menu.events", fn, opts);
26
+ }
27
+ // onMenu calls fn when the item with this id is clicked.
28
+ export function onMenu(id, fn, opts) {
29
+ return onClick((e) => {
30
+ if (e.id === id)
31
+ fn(e);
32
+ }, opts);
33
+ }
34
+ // setContextMenu sets the context menu behavior of a window or view.
35
+ export function setContextMenu(options, target = {}) {
36
+ return call("krate/menu.setContextMenu", [
37
+ target.window ?? "",
38
+ target.view ?? "",
39
+ { mode: options.mode, items: toWire(options.items ?? []) },
40
+ ]);
41
+ }
42
+ // onContext calls fn for every right click in a view whose mode is "custom".
43
+ export function onContext(fn, opts) {
44
+ return subscribe("krate/menu.contextEvents", fn, opts);
45
+ }
46
+ // onContextMenu answers right clicks in "custom" views: fn returns the items
47
+ // (or nothing, for no menu) and they pop up at the click. Start from
48
+ // defaultContextItems to keep the usual entries.
49
+ export function onContextMenu(fn, opts) {
50
+ return onContext(async (e) => {
51
+ const items = await fn(e);
52
+ if (items && items.length > 0)
53
+ await popup(items, { window: e.window, x: e.windowX, y: e.windowY });
54
+ }, opts);
55
+ }
56
+ // Ids of the built-in actions: the shell runs them on the view that showed
57
+ // the menu instead of reporting a click.
58
+ export const actions = {
59
+ undo: "krate:undo",
60
+ redo: "krate:redo",
61
+ cut: "krate:cut",
62
+ copy: "krate:copy",
63
+ paste: "krate:paste",
64
+ selectAll: "krate:selectAll",
65
+ delete: "krate:delete",
66
+ inspectElement: "krate:inspectElement",
67
+ addToDictionary: "krate:addToDictionary",
68
+ replaceMisspelling: (word) => `krate:replaceMisspelling:${word}`,
69
+ copyLink: (url) => `krate:copyLink:${url}`,
70
+ copyImageUrl: (url) => `krate:copyImageUrl:${url}`,
71
+ };
72
+ // defaultContextItems is the menu a browser would show for e (English
73
+ // labels): in editable fields spelling suggestions with "Add to Dictionary"
74
+ // (when the engine reported a misspelling), undo, redo, cut, copy, paste and
75
+ // select all; "Copy" for a selection; "Copy Link Address" for a link; and, in
76
+ // dev builds, "Inspect Element".
77
+ export function defaultContextItems(e) {
78
+ const items = [];
79
+ const sep = () => {
80
+ if (items.length > 0 && items[items.length - 1].kind !== "separator")
81
+ items.push({ kind: "separator" });
82
+ };
83
+ const has = (k) => e.kinds.includes(k);
84
+ const editable = has("editable");
85
+ if (editable && e.misspelled) {
86
+ for (const s of e.suggestions)
87
+ items.push({ id: actions.replaceMisspelling(s), label: s });
88
+ if (e.suggestions.length === 0)
89
+ items.push({ label: "No Guesses Found", disabled: true });
90
+ items.push({ id: actions.addToDictionary, label: "Add to Dictionary" });
91
+ sep();
92
+ }
93
+ if (has("link") && e.linkUrl) {
94
+ items.push({ id: actions.copyLink(e.linkUrl), label: "Copy Link Address" });
95
+ sep();
96
+ }
97
+ if (has("image") && e.imageUrl) {
98
+ items.push({ id: actions.copyImageUrl(e.imageUrl), label: "Copy Image Address" });
99
+ sep();
100
+ }
101
+ if (editable) {
102
+ items.push({ id: actions.undo, label: "Undo", accelerator: "CmdOrCtrl+Z" }, { id: actions.redo, label: "Redo", accelerator: "CmdOrCtrl+Shift+Z" }, { kind: "separator" }, { id: actions.cut, label: "Cut", accelerator: "CmdOrCtrl+X" }, { id: actions.copy, label: "Copy", accelerator: "CmdOrCtrl+C" }, { id: actions.paste, label: "Paste", accelerator: "CmdOrCtrl+V" }, { id: actions.selectAll, label: "Select All", accelerator: "CmdOrCtrl+A" });
103
+ }
104
+ else if (has("selection")) {
105
+ items.push({ id: actions.copy, label: "Copy", accelerator: "CmdOrCtrl+C" }, { id: actions.selectAll, label: "Select All", accelerator: "CmdOrCtrl+A" });
106
+ }
107
+ if (e.inspectable) {
108
+ sep();
109
+ items.push({ id: actions.inspectElement, label: "Inspect Element" });
110
+ }
111
+ while (items.length > 0 && items[items.length - 1].kind === "separator")
112
+ items.pop();
113
+ return items;
114
+ }
package/dist/mock.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { ReadonlyHostSignal, Impl } from "./types.js";
2
+ export declare function setMock(moduleId: string, impl: Impl): void;
3
+ export declare function clearMocks(): void;
4
+ export declare function hasMocks(): boolean;
5
+ export declare function findMock(fn: string): {
6
+ impl: Impl;
7
+ name: string;
8
+ } | undefined;
9
+ export declare function mockFn(m: {
10
+ impl: Impl;
11
+ name: string;
12
+ }, fn: string): (...args: unknown[]) => unknown;
13
+ export declare function mockSignal(name: string): ReadonlyHostSignal<unknown> | undefined;
14
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAI3D,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAE1D;AAED,wBAAgB,UAAU,IAAI,IAAI,CAEjC;AAED,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAOD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAK7E;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAInG;AAID,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,SAAS,CAahF"}
package/dist/mock.js ADDED
@@ -0,0 +1,47 @@
1
+ // Registry of in-process host implementations used by @krate/app/testing.
2
+ import { KrateError } from "./errors.js";
3
+ const mocks = new Map();
4
+ export function setMock(moduleId, impl) {
5
+ mocks.set(moduleId, impl);
6
+ }
7
+ export function clearMocks() {
8
+ mocks.clear();
9
+ }
10
+ export function hasMocks() {
11
+ return mocks.size > 0;
12
+ }
13
+ function split(fn) {
14
+ const i = fn.lastIndexOf(".");
15
+ return i === -1 ? ["", fn] : [fn.slice(0, i), fn.slice(i + 1)];
16
+ }
17
+ export function findMock(fn) {
18
+ if (mocks.size === 0)
19
+ return undefined;
20
+ const [mod, name] = split(fn);
21
+ const impl = mocks.get(mod);
22
+ return impl ? { impl, name } : undefined;
23
+ }
24
+ export function mockFn(m, fn) {
25
+ const f = m.impl[m.name];
26
+ if (typeof f !== "function")
27
+ throw new KrateError("not_found", `no mock for ${fn}`);
28
+ return f;
29
+ }
30
+ // mockSignal returns a read-only view when the signal's module is mocked. The
31
+ // impl value is either a host signal (get/subscribe) or a plain value.
32
+ export function mockSignal(name) {
33
+ const m = findMock(name);
34
+ if (!m)
35
+ return undefined;
36
+ const v = m.impl[m.name];
37
+ if (v && typeof v === "object" && typeof v.get === "function" && typeof v.subscribe === "function") {
38
+ const read = (() => v.get());
39
+ read.subscribe = (fn) => v.subscribe(fn);
40
+ return read;
41
+ }
42
+ if (typeof v === "function")
43
+ throw new KrateError("not_found", `mock ${name} is a function, not a signal`);
44
+ const read = (() => v);
45
+ read.subscribe = () => () => { };
46
+ return read;
47
+ }
@@ -0,0 +1,25 @@
1
+ import { type SubscribeOptions } from "./events.js";
2
+ export interface NotificationAction {
3
+ id: string;
4
+ label: string;
5
+ }
6
+ export interface Notification {
7
+ id?: string;
8
+ title: string;
9
+ body?: string;
10
+ icon?: string;
11
+ actions?: NotificationAction[];
12
+ urgency?: "low" | "normal" | "critical";
13
+ timeoutMs?: number;
14
+ silent?: boolean;
15
+ }
16
+ export interface NotificationEvent {
17
+ id: string;
18
+ action: string;
19
+ closed: boolean;
20
+ }
21
+ export declare function send(n: Notification): Promise<void>;
22
+ export declare function close(id: string): Promise<void>;
23
+ export declare function onEvent(fn: (e: NotificationEvent) => void, opts?: SubscribeOptions): () => void;
24
+ export declare function onAction(id: string, action: string, fn: () => void, opts?: SubscribeOptions): () => void;
25
+ //# sourceMappingURL=notify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../src/notify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAE3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,UAAU,CAAC;IAExC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,EAAE,OAAO,CAAC;CACjB;AAID,wBAAgB,IAAI,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAanD;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAE/F;AAID,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAIxG"}
package/dist/notify.js ADDED
@@ -0,0 +1,32 @@
1
+ // Desktop notifications. Needs the "notify" permission.
2
+ import { call } from "./index.js";
3
+ import { subscribe } from "./events.js";
4
+ const URGENCY = { low: 0, normal: 1, critical: 2 };
5
+ export function send(n) {
6
+ return call("krate/notify.send", [
7
+ {
8
+ id: n.id ?? "",
9
+ title: n.title,
10
+ body: n.body ?? "",
11
+ icon: n.icon ?? "",
12
+ actions: n.actions ?? [],
13
+ urgency: URGENCY[n.urgency ?? "normal"],
14
+ timeoutMs: n.timeoutMs ?? 0,
15
+ silent: n.silent ?? false,
16
+ },
17
+ ]);
18
+ }
19
+ export function close(id) {
20
+ return call("krate/notify.close", [id]);
21
+ }
22
+ export function onEvent(fn, opts) {
23
+ return subscribe("krate/notify.events", fn, opts);
24
+ }
25
+ // onAction calls fn when the action (or, with "", the notification body) of
26
+ // the notification with this id is chosen.
27
+ export function onAction(id, action, fn, opts) {
28
+ return onEvent((e) => {
29
+ if (e.id === id && e.action === action && !e.closed)
30
+ fn();
31
+ }, opts);
32
+ }
@@ -0,0 +1,24 @@
1
+ export interface OffscreenOptions {
2
+ path?: string;
3
+ width?: number;
4
+ height?: number;
5
+ }
6
+ export interface CaptureOptions {
7
+ format?: "png" | "bgra";
8
+ fullDocument?: boolean;
9
+ fps?: number;
10
+ maxFrames?: number;
11
+ }
12
+ export interface Frame {
13
+ seq: number;
14
+ timeMs: number;
15
+ width: number;
16
+ height: number;
17
+ format: "png" | "bgra";
18
+ dropped: number;
19
+ data: Uint8Array;
20
+ }
21
+ export declare function openOffscreen(options?: OffscreenOptions): Promise<string>;
22
+ export declare function captureFrame(window?: string, options?: CaptureOptions): Promise<Frame>;
23
+ export declare function frames(window?: string, options?: CaptureOptions, signal?: AbortSignal): AsyncIterable<Frame>;
24
+ //# sourceMappingURL=offscreen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offscreen.d.ts","sourceRoot":"","sources":["../src/offscreen.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,gBAAgB;IAE/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAE7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAExB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IAGvB,OAAO,EAAE,MAAM,CAAC;IAEhB,IAAI,EAAE,UAAU,CAAC;CAClB;AAKD,wBAAgB,aAAa,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7E;AAGD,wBAAgB,YAAY,CAAC,MAAM,SAAK,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAEtF;AAKD,wBAAgB,MAAM,CAAC,MAAM,SAAK,EAAE,OAAO,GAAE,cAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAE5G"}
@@ -0,0 +1,27 @@
1
+ // Offscreen rendering: windows that render out of sight, and frames of any
2
+ // window. Needs the "offscreen" permission.
3
+ //
4
+ // The system webviews cannot push frames the way Chromium's offscreen mode
5
+ // does. A window opened here is never shown (a GtkOffscreenWindow on Linux, a
6
+ // window parked off every display on Windows and macOS) and its page renders
7
+ // normally; frames are snapshots (WebKitGTK get_snapshot, WKWebView
8
+ // takeSnapshot, WebView2 CapturePreview) taken one at a time at the requested
9
+ // rate. A slow consumer makes the stream skip frames, counted in
10
+ // Frame.dropped, instead of queueing them.
11
+ import { call, stream } from "./index.js";
12
+ // openOffscreen creates a window that is never shown and returns its id. Use
13
+ // the window module's navigate and close with it, and window.thisView in its
14
+ // page if it needs its own id.
15
+ export function openOffscreen(options = {}) {
16
+ return call("krate/offscreen.open", [options]);
17
+ }
18
+ // captureFrame takes one frame of a window or view ("" is the main window).
19
+ export function captureFrame(window = "", options = {}) {
20
+ return call("krate/offscreen.capture", [window, options]);
21
+ }
22
+ // frames yields frames of a window or view at options.fps until the loop is
23
+ // left, the signal aborts, or maxFrames is reached. The next frame is taken
24
+ // only after the consumer returned for the last one (backpressure).
25
+ export function frames(window = "", options = {}, signal) {
26
+ return stream("krate/offscreen.frames", [window, options], { signal });
27
+ }
package/dist/os.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export interface OsInfo {
2
+ os: string;
3
+ arch: string;
4
+ osVersion: string;
5
+ hostname: string;
6
+ locale: string;
7
+ appId: string;
8
+ appVersion: string;
9
+ }
10
+ export declare function appDataDir(): Promise<string>;
11
+ export declare function cacheDir(): Promise<string>;
12
+ export declare function configDir(): Promise<string>;
13
+ export declare function logDir(): Promise<string>;
14
+ export declare function tempDir(): Promise<string>;
15
+ export declare function info(): Promise<OsInfo>;
16
+ export declare function openExternal(url: string): Promise<void>;
17
+ export declare function secretSet(key: string, value: string): Promise<void>;
18
+ export declare function secretGet(key: string): Promise<string | null>;
19
+ export declare function secretDelete(key: string): Promise<void>;
20
+ //# sourceMappingURL=os.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,MAAM;IAErB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IAEjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAGD,wBAAgB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5C;AACD,wBAAgB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAE1C;AACD,wBAAgB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAE3C;AACD,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAExC;AACD,wBAAgB,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAEzC;AAGD,wBAAgB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAEtC;AAID,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD;AAOD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnE;AAGD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE7D;AAGD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD"}
package/dist/os.js ADDED
@@ -0,0 +1,43 @@
1
+ // App directories, OS information, opening URLs and secrets.
2
+ // Host ids krate/os.*; permissions are in the table at the end of this file.
3
+ import { call } from "./index.js";
4
+ // The directories are created on first use. Permission: os:info.
5
+ export function appDataDir() {
6
+ return call("krate/os.appDataDir", [], { dedupe: true });
7
+ }
8
+ export function cacheDir() {
9
+ return call("krate/os.cacheDir", [], { dedupe: true });
10
+ }
11
+ export function configDir() {
12
+ return call("krate/os.configDir", [], { dedupe: true });
13
+ }
14
+ export function logDir() {
15
+ return call("krate/os.logDir", [], { dedupe: true });
16
+ }
17
+ export function tempDir() {
18
+ return call("krate/os.tempDir", [], { dedupe: true });
19
+ }
20
+ // Permission: os:info.
21
+ export function info() {
22
+ return call("krate/os.info", [], { dedupe: true });
23
+ }
24
+ // Opens an http, https or mailto URL in the OS default handler.
25
+ // Permission: shell:openExternal.
26
+ export function openExternal(url) {
27
+ return call("krate/os.openExternal", [url]);
28
+ }
29
+ // Secrets live in the OS credential store, scoped to the app. They reject with
30
+ // code "unsupported" where the platform has no store (for example Linux with
31
+ // no Secret Service provider).
32
+ // Permission: os:secrets.
33
+ export function secretSet(key, value) {
34
+ return call("krate/os.secretSet", [key, value]);
35
+ }
36
+ // Resolves null when the key has no secret. Permission: os:secrets.read.
37
+ export function secretGet(key) {
38
+ return call("krate/os.secretGet", [key]);
39
+ }
40
+ // Deleting a missing key succeeds. Permission: os:secrets.
41
+ export function secretDelete(key) {
42
+ return call("krate/os.secretDelete", [key]);
43
+ }
package/dist/page.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { type SubscribeOptions } from "./events.js";
2
+ export type PageSize = "A3" | "A4" | "A5" | "Letter" | "Legal" | "Tabloid" | {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export interface Margins {
7
+ top?: number;
8
+ right?: number;
9
+ bottom?: number;
10
+ left?: number;
11
+ }
12
+ export interface PdfOptions {
13
+ /** The view to print; default is the calling view. */
14
+ view?: string;
15
+ landscape?: boolean;
16
+ /** Print CSS backgrounds. Default false. */
17
+ printBackground?: boolean;
18
+ /** A named paper size or a size in inches. Default "A4". */
19
+ pageSize?: PageSize;
20
+ /** Margins in inches. Default 0.4 on every side. */
21
+ margins?: Margins;
22
+ }
23
+ export interface FindOptions {
24
+ /** The view to search; default is the calling view. */
25
+ view?: string;
26
+ /** Search towards the start of the page. */
27
+ backward?: boolean;
28
+ matchCase?: boolean;
29
+ /** Stop at the end of the page instead of wrapping around. */
30
+ noWrap?: boolean;
31
+ /** Move to the next (or, with backward, previous) match of the running search for the same text. */
32
+ continue?: boolean;
33
+ }
34
+ export interface FindEvent {
35
+ /** The view that was searched. */
36
+ view: string;
37
+ text: string;
38
+ /** Number of matches. */
39
+ matches: number;
40
+ /** 1-based index of the highlighted match; 0 when unknown or without matches. */
41
+ active: number;
42
+ /** True when `matches` will not change for this search. */
43
+ final: boolean;
44
+ }
45
+ /** print opens the system print dialog for the view. */
46
+ declare function pagePrint(view?: string): Promise<void>;
47
+ /**
48
+ * printToPdf renders the view to a PDF and resolves to its bytes. Write them
49
+ * with @krate/app/fs.writeFile, or hand them to Go host code.
50
+ */
51
+ declare function pagePrintToPdf(options?: PdfOptions): Promise<Uint8Array>;
52
+ /**
53
+ * find searches for text, highlights the first match and reports the match
54
+ * count through onFind. Call it again with `continue: true` to step through
55
+ * the matches.
56
+ */
57
+ declare function pageFind(text: string, options?: FindOptions): Promise<void>;
58
+ /** stopFind clears the highlight of the search. */
59
+ declare function pageStopFind(view?: string): Promise<void>;
60
+ /** onFind calls fn with the result of every find until the returned function is called. */
61
+ declare function pageOnFind(fn: (e: FindEvent) => void, opts?: SubscribeOptions): () => void;
62
+ /** zoom resolves to the zoom factor of the view; 1 is 100 percent. */
63
+ declare function pageZoom(view?: string): Promise<number>;
64
+ /** setZoom sets the zoom factor, between 0.25 and 5. Ctrl/Cmd plus, minus and 0 also change it. */
65
+ declare function pageSetZoom(factor: number, view?: string): Promise<void>;
66
+ /** capture resolves to a PNG of the visible area of the view. */
67
+ declare function pageCapture(view?: string): Promise<Uint8Array>;
68
+ export { pagePrint as print, pagePrintToPdf as printToPdf, pageFind as find, pageStopFind as stopFind, pageOnFind as onFind, pageZoom as zoom, pageSetZoom as setZoom, pageCapture as capture };
69
+ //# sourceMappingURL=page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,gBAAgB,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