@rollrook-ai/sdk 0.0.0-stage → 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 (143) hide show
  1. package/dist/agents.d.ts +9 -0
  2. package/dist/agents.d.ts.map +1 -0
  3. package/dist/agents.js +13 -0
  4. package/dist/agents.js.map +1 -0
  5. package/dist/assets.d.ts +35 -0
  6. package/dist/assets.d.ts.map +1 -0
  7. package/dist/assets.js +66 -0
  8. package/dist/assets.js.map +1 -0
  9. package/dist/assistant.d.ts +76 -0
  10. package/dist/assistant.d.ts.map +1 -0
  11. package/dist/assistant.js +161 -0
  12. package/dist/assistant.js.map +1 -0
  13. package/dist/audio.d.ts +55 -0
  14. package/dist/audio.d.ts.map +1 -0
  15. package/dist/audio.js +82 -0
  16. package/dist/audio.js.map +1 -0
  17. package/dist/bridge.d.ts +51 -0
  18. package/dist/bridge.d.ts.map +1 -0
  19. package/dist/bridge.js +78 -0
  20. package/dist/bridge.js.map +1 -0
  21. package/dist/calendar.d.ts +33 -0
  22. package/dist/calendar.d.ts.map +1 -0
  23. package/dist/calendar.js +63 -0
  24. package/dist/calendar.js.map +1 -0
  25. package/dist/context.d.ts +19 -0
  26. package/dist/context.d.ts.map +1 -0
  27. package/dist/context.js +25 -0
  28. package/dist/context.js.map +1 -0
  29. package/dist/errors.d.ts +74 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +111 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/events.d.ts +36 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +81 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/files.d.ts +29 -0
  38. package/dist/files.d.ts.map +1 -0
  39. package/dist/files.js +43 -0
  40. package/dist/files.js.map +1 -0
  41. package/dist/index.d.ts +84 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +78 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/mock/index.d.ts +4 -0
  46. package/dist/mock/index.d.ts.map +1 -0
  47. package/dist/mock/index.js +3 -0
  48. package/dist/mock/index.js.map +1 -0
  49. package/dist/mock/mock-host.d.ts +255 -0
  50. package/dist/mock/mock-host.d.ts.map +1 -0
  51. package/dist/mock/mock-host.js +1274 -0
  52. package/dist/mock/mock-host.js.map +1 -0
  53. package/dist/mock/samples.d.ts +56 -0
  54. package/dist/mock/samples.d.ts.map +1 -0
  55. package/dist/mock/samples.js +283 -0
  56. package/dist/mock/samples.js.map +1 -0
  57. package/dist/mock/toolbar.d.ts +95 -0
  58. package/dist/mock/toolbar.d.ts.map +1 -0
  59. package/dist/mock/toolbar.js +279 -0
  60. package/dist/mock/toolbar.js.map +1 -0
  61. package/dist/net.d.ts +13 -0
  62. package/dist/net.d.ts.map +1 -0
  63. package/dist/net.js +26 -0
  64. package/dist/net.js.map +1 -0
  65. package/dist/plugin.d.ts +11 -0
  66. package/dist/plugin.d.ts.map +1 -0
  67. package/dist/plugin.js +13 -0
  68. package/dist/plugin.js.map +1 -0
  69. package/dist/raven.d.ts +51 -0
  70. package/dist/raven.d.ts.map +1 -0
  71. package/dist/raven.js +100 -0
  72. package/dist/raven.js.map +1 -0
  73. package/dist/segment-display.d.ts +93 -0
  74. package/dist/segment-display.d.ts.map +1 -0
  75. package/dist/segment-display.js +324 -0
  76. package/dist/segment-display.js.map +1 -0
  77. package/dist/settings.d.ts +19 -0
  78. package/dist/settings.d.ts.map +1 -0
  79. package/dist/settings.js +27 -0
  80. package/dist/settings.js.map +1 -0
  81. package/dist/storage.d.ts +28 -0
  82. package/dist/storage.d.ts.map +1 -0
  83. package/dist/storage.js +54 -0
  84. package/dist/storage.js.map +1 -0
  85. package/dist/system.d.ts +19 -0
  86. package/dist/system.d.ts.map +1 -0
  87. package/dist/system.js +24 -0
  88. package/dist/system.js.map +1 -0
  89. package/dist/theme.d.ts +51 -0
  90. package/dist/theme.d.ts.map +1 -0
  91. package/dist/theme.js +85 -0
  92. package/dist/theme.js.map +1 -0
  93. package/dist/types.d.ts +278 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/ui.d.ts +57 -0
  98. package/dist/ui.d.ts.map +1 -0
  99. package/dist/ui.js +78 -0
  100. package/dist/ui.js.map +1 -0
  101. package/dist/usage.d.ts +14 -0
  102. package/dist/usage.d.ts.map +1 -0
  103. package/dist/usage.js +19 -0
  104. package/dist/usage.js.map +1 -0
  105. package/dist/video.d.ts +11 -0
  106. package/dist/video.d.ts.map +1 -0
  107. package/dist/video.js +17 -0
  108. package/dist/video.js.map +1 -0
  109. package/dist/wire.d.ts +214 -0
  110. package/dist/wire.d.ts.map +1 -0
  111. package/dist/wire.js +538 -0
  112. package/dist/wire.js.map +1 -0
  113. package/package.json +39 -4
  114. package/src/agents.ts +14 -0
  115. package/src/assets.ts +80 -0
  116. package/src/assistant.ts +185 -0
  117. package/src/audio.ts +90 -0
  118. package/src/bridge.ts +96 -0
  119. package/src/calendar.ts +68 -0
  120. package/src/context.ts +28 -0
  121. package/src/errors.ts +131 -0
  122. package/src/events.ts +90 -0
  123. package/src/files.ts +47 -0
  124. package/src/index.ts +152 -0
  125. package/src/mock/index.ts +3 -0
  126. package/src/mock/mock-host.ts +1408 -0
  127. package/src/mock/samples.ts +300 -0
  128. package/src/mock/toolbar.ts +321 -0
  129. package/src/net.ts +27 -0
  130. package/src/plugin.ts +14 -0
  131. package/src/raven.ts +116 -0
  132. package/src/segment-display.ts +377 -0
  133. package/src/settings.ts +29 -0
  134. package/src/storage.ts +59 -0
  135. package/src/system.ts +26 -0
  136. package/src/theme.ts +97 -0
  137. package/src/types.ts +327 -0
  138. package/src/ui.ts +88 -0
  139. package/src/usage.ts +21 -0
  140. package/src/video.ts +17 -0
  141. package/src/wire.ts +608 -0
  142. package/theme.css +407 -0
  143. package/README.md +0 -3
@@ -0,0 +1,300 @@
1
+ import type { JsonObject } from "../types.js";
2
+
3
+ /** The canned data the mock host answers with, in wire form. */
4
+ export class MockSamples {
5
+ /** The system font stack the mock publishes as `--rr-font`. */
6
+ static readonly FONT = "-apple-system, BlinkMacSystemFont, \"SF Pro Text\", \"Helvetica Neue\", sans-serif";
7
+
8
+ /**
9
+ * A theme close to RollRook's, in wire form.
10
+ *
11
+ * @param is_dark - the dark theme rather than the light one
12
+ * @param is_high_contrast - the high-contrast variant
13
+ * @returns the theme
14
+ */
15
+ static theme(is_dark: boolean, is_high_contrast: boolean): JsonObject {
16
+ const colors = is_dark ? MockSamples.DARK_COLORS : MockSamples.LIGHT_COLORS;
17
+ const contrast = is_dark ? MockSamples.DARK_CONTRAST_COLORS : MockSamples.LIGHT_CONTRAST_COLORS;
18
+ return {
19
+ isDark: is_dark,
20
+ isHighContrast: is_high_contrast,
21
+ colors: is_high_contrast ? { ...colors, ...contrast } : colors,
22
+ };
23
+ }
24
+
25
+ private static readonly LIGHT_COLORS: JsonObject = {
26
+ background: "#e7e9ee",
27
+ surface: "rgba(255, 255, 255, 0.75)",
28
+ sidebar: "#edeff3",
29
+ text: "rgba(0, 0, 0, 0.85)",
30
+ secondaryText: "rgba(0, 0, 0, 0.5)",
31
+ tertiaryText: "rgba(0, 0, 0, 0.26)",
32
+ separator: "rgba(26, 34, 51, 0.09)",
33
+ accent: "#1c1c20",
34
+ onAccent: "#ffffff",
35
+ caution: "#1c1c20",
36
+ segment: "rgb(158, 18, 18)",
37
+ };
38
+
39
+ private static readonly DARK_COLORS: JsonObject = {
40
+ background: "#111318",
41
+ surface: "rgba(200, 210, 230, 0.05)",
42
+ sidebar: "#0d0f13",
43
+ text: "rgba(255, 255, 255, 0.85)",
44
+ secondaryText: "rgba(255, 255, 255, 0.55)",
45
+ tertiaryText: "rgba(255, 255, 255, 0.25)",
46
+ separator: "rgba(200, 210, 230, 0.08)",
47
+ accent: "#ffffff",
48
+ onAccent: "#1c1c20",
49
+ caution: "#ffffff",
50
+ segment: "rgb(255, 199, 31)",
51
+ };
52
+
53
+ private static readonly LIGHT_CONTRAST_COLORS: JsonObject = {
54
+ background: "#ffffff",
55
+ secondaryText: "rgba(0, 0, 0, 0.82)",
56
+ tertiaryText: "rgba(0, 0, 0, 0.66)",
57
+ separator: "rgb(15, 74, 133)",
58
+ };
59
+
60
+ private static readonly DARK_CONTRAST_COLORS: JsonObject = {
61
+ background: "#000000",
62
+ secondaryText: "rgba(255, 255, 255, 0.85)",
63
+ tertiaryText: "rgba(255, 255, 255, 0.7)",
64
+ separator: "rgb(112, 194, 222)",
65
+ };
66
+
67
+ /** Code agent sessions, as `agents.list` returns them. */
68
+ static readonly LIST_AGENTS: JsonObject[] = [
69
+ {
70
+ id: "mock-agent-1",
71
+ title: "Fix the flaky upload test",
72
+ harness: "claude",
73
+ state: "working",
74
+ host: "studio",
75
+ },
76
+ {
77
+ id: "mock-agent-2",
78
+ title: "Port the settings page to the new layout",
79
+ harness: "codex",
80
+ state: "needs_approval",
81
+ host: "studio",
82
+ },
83
+ {
84
+ id: "mock-agent-3",
85
+ title: "Write release notes for 2.4",
86
+ harness: "agy",
87
+ state: "idle",
88
+ host: "build-box",
89
+ },
90
+ ];
91
+
92
+ /**
93
+ * Code agent accounts with their limits, in wire form, as they stand at a
94
+ * moment: the limits creep up with time so the numbers move.
95
+ *
96
+ * @param now - the moment
97
+ * @returns the accounts
98
+ */
99
+ static accounts(now: Date): JsonObject[] {
100
+ const hour_ms = 3_600_000;
101
+ const at = (hours: number): string => new Date(now.getTime() + hours * hour_ms).toISOString();
102
+ const drift = (base: number, rate: number): number =>
103
+ Math.round((base + (now.getTime() / 60_000) * rate) % 100);
104
+ const limit = (id: string, title: string, used_percent: number, resets_at: string | null): JsonObject => ({
105
+ id,
106
+ title,
107
+ usedPercent: used_percent,
108
+ resetsAt: resets_at,
109
+ severity: used_percent >= MockSamples.CRITICAL_PERCENT
110
+ ? "critical"
111
+ : used_percent >= MockSamples.WARNING_PERCENT ? "warning" : "normal",
112
+ });
113
+ const fetched_at = now.toISOString();
114
+ return [
115
+ {
116
+ harness: "claude",
117
+ signedInAs: "dev@example.com",
118
+ plan: "max",
119
+ isDefault: true,
120
+ error: null,
121
+ fetchedAt: fetched_at,
122
+ limits: [limit("5h", "5h", drift(42, 0.7), at(3)), limit("7d", "7d", drift(67, 0.05), at(80))],
123
+ },
124
+ {
125
+ harness: "codex",
126
+ signedInAs: "dev@example.com",
127
+ plan: "pro",
128
+ isDefault: true,
129
+ error: null,
130
+ fetchedAt: fetched_at,
131
+ limits: [limit("5h", "5h", drift(12, 0.4), at(4)), limit("7d", "7d", drift(31, 0.03), null)],
132
+ },
133
+ {
134
+ harness: "agy",
135
+ signedInAs: null,
136
+ plan: null,
137
+ isDefault: true,
138
+ error: null,
139
+ fetchedAt: fetched_at,
140
+ limits: [limit("1d", "1d", 100, at(9))],
141
+ },
142
+ ];
143
+ }
144
+
145
+ /** The share of a limit from which it counts as a warning. */
146
+ static readonly WARNING_PERCENT = 75;
147
+
148
+ /** The share of a limit from which it counts as critical. */
149
+ static readonly CRITICAL_PERCENT = 90;
150
+
151
+ /** The mixer's settings for a track it has not touched, in wire form. */
152
+ static readonly DEFAULT_AUDIO_SETTINGS: JsonObject = {
153
+ isTakenOver: false,
154
+ isMuted: false,
155
+ volume: 1,
156
+ pan: 0,
157
+ isLeftInverted: false,
158
+ isRightInverted: false,
159
+ isSwapped: false,
160
+ width: 1,
161
+ isEqualizerEnabled: false,
162
+ equalizerGains: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
163
+ reverbRoom: "mediumRoom",
164
+ reverbMix: 0,
165
+ };
166
+
167
+ /** The most cities `system.searchCities` returns. */
168
+ static readonly CITY_RESULT_LIMIT = 8;
169
+
170
+ /** Cities the mock's `system.searchCities` knows beyond those time zones are named after, in wire form. */
171
+ static readonly LIST_CITIES: readonly JsonObject[] = [
172
+ { name: "Amsterdam", timeZoneId: "Europe/Amsterdam" },
173
+ { name: "Athens", timeZoneId: "Europe/Athens" },
174
+ { name: "Auckland", timeZoneId: "Pacific/Auckland" },
175
+ { name: "Austin", timeZoneId: "America/Chicago" },
176
+ { name: "Bangalore", timeZoneId: "Asia/Kolkata" },
177
+ { name: "Bangkok", timeZoneId: "Asia/Bangkok" },
178
+ { name: "Barcelona", timeZoneId: "Europe/Madrid" },
179
+ { name: "Beijing", timeZoneId: "Asia/Shanghai" },
180
+ { name: "Berlin", timeZoneId: "Europe/Berlin" },
181
+ { name: "Boston", timeZoneId: "America/New_York" },
182
+ { name: "Buenos Aires", timeZoneId: "America/Argentina/Buenos_Aires" },
183
+ { name: "Cairo", timeZoneId: "Africa/Cairo" },
184
+ { name: "Cape Town", timeZoneId: "Africa/Johannesburg" },
185
+ { name: "Chengdu", timeZoneId: "Asia/Shanghai" },
186
+ { name: "Chicago", timeZoneId: "America/Chicago" },
187
+ { name: "Copenhagen", timeZoneId: "Europe/Copenhagen" },
188
+ { name: "Delhi", timeZoneId: "Asia/Kolkata" },
189
+ { name: "Denver", timeZoneId: "America/Denver" },
190
+ { name: "Dubai", timeZoneId: "Asia/Dubai" },
191
+ { name: "Dublin", timeZoneId: "Europe/Dublin" },
192
+ { name: "Hangzhou", timeZoneId: "Asia/Shanghai" },
193
+ { name: "Helsinki", timeZoneId: "Europe/Helsinki" },
194
+ { name: "Ho Chi Minh City", timeZoneId: "Asia/Ho_Chi_Minh" },
195
+ { name: "Hong Kong", timeZoneId: "Asia/Hong_Kong" },
196
+ { name: "Honolulu", timeZoneId: "Pacific/Honolulu" },
197
+ { name: "Istanbul", timeZoneId: "Europe/Istanbul" },
198
+ { name: "Jakarta", timeZoneId: "Asia/Jakarta" },
199
+ { name: "Kuala Lumpur", timeZoneId: "Asia/Kuala_Lumpur" },
200
+ { name: "Lagos", timeZoneId: "Africa/Lagos" },
201
+ { name: "Lisbon", timeZoneId: "Europe/Lisbon" },
202
+ { name: "London", timeZoneId: "Europe/London" },
203
+ { name: "Los Angeles", timeZoneId: "America/Los_Angeles" },
204
+ { name: "Madrid", timeZoneId: "Europe/Madrid" },
205
+ { name: "Manila", timeZoneId: "Asia/Manila" },
206
+ { name: "Melbourne", timeZoneId: "Australia/Melbourne" },
207
+ { name: "Mexico City", timeZoneId: "America/Mexico_City" },
208
+ { name: "Miami", timeZoneId: "America/New_York" },
209
+ { name: "Milan", timeZoneId: "Europe/Rome" },
210
+ { name: "Montreal", timeZoneId: "America/Toronto" },
211
+ { name: "Moscow", timeZoneId: "Europe/Moscow" },
212
+ { name: "Mumbai", timeZoneId: "Asia/Kolkata" },
213
+ { name: "Munich", timeZoneId: "Europe/Berlin" },
214
+ { name: "Nairobi", timeZoneId: "Africa/Nairobi" },
215
+ { name: "New York", timeZoneId: "America/New_York" },
216
+ { name: "Osaka", timeZoneId: "Asia/Tokyo" },
217
+ { name: "Oslo", timeZoneId: "Europe/Oslo" },
218
+ { name: "Paris", timeZoneId: "Europe/Paris" },
219
+ { name: "Prague", timeZoneId: "Europe/Prague" },
220
+ { name: "Rome", timeZoneId: "Europe/Rome" },
221
+ { name: "San Francisco", timeZoneId: "America/Los_Angeles" },
222
+ { name: "São Paulo", timeZoneId: "America/Sao_Paulo" },
223
+ { name: "Seattle", timeZoneId: "America/Los_Angeles" },
224
+ { name: "Seoul", timeZoneId: "Asia/Seoul" },
225
+ { name: "Shanghai", timeZoneId: "Asia/Shanghai" },
226
+ { name: "Shenzhen", timeZoneId: "Asia/Shanghai" },
227
+ { name: "Singapore", timeZoneId: "Asia/Singapore" },
228
+ { name: "Stockholm", timeZoneId: "Europe/Stockholm" },
229
+ { name: "Sydney", timeZoneId: "Australia/Sydney" },
230
+ { name: "Taipei", timeZoneId: "Asia/Taipei" },
231
+ { name: "Tel Aviv", timeZoneId: "Asia/Jerusalem" },
232
+ { name: "Tokyo", timeZoneId: "Asia/Tokyo" },
233
+ { name: "Toronto", timeZoneId: "America/Toronto" },
234
+ { name: "Vancouver", timeZoneId: "America/Vancouver" },
235
+ { name: "Vienna", timeZoneId: "Europe/Vienna" },
236
+ { name: "Warsaw", timeZoneId: "Europe/Warsaw" },
237
+ { name: "Washington", timeZoneId: "America/New_York" },
238
+ { name: "Zurich", timeZoneId: "Europe/Zurich" },
239
+ ];
240
+
241
+ /**
242
+ * Search cities by name, as `system.searchCities` does on a Mac without
243
+ * Apple Maps: a bundled list and the cities time zones are named after,
244
+ * those whose name starts with the query first.
245
+ *
246
+ * @param query - what the user typed
247
+ * @returns up to 8 cities in wire form
248
+ */
249
+ static search_cities(query: string): JsonObject[] {
250
+ const wanted = query.trim().toLowerCase();
251
+ if (wanted === "") {
252
+ return [];
253
+ }
254
+ const list_zone_cities: JsonObject[] = typeof Intl.supportedValuesOf === "function"
255
+ ? Intl.supportedValuesOf("timeZone")
256
+ .filter((zone: string) => zone.includes("/"))
257
+ .map((zone: string) => ({ name: (zone.split("/").at(-1) ?? zone).replaceAll("_", " "), timeZoneId: zone }))
258
+ : [];
259
+ const set_seen = new Set<string>();
260
+ const list_matches: JsonObject[] = [];
261
+ for (const city of [...MockSamples.LIST_CITIES, ...list_zone_cities]) {
262
+ const name = String(city["name"]);
263
+ if (!set_seen.has(name) && name.toLowerCase().includes(wanted)) {
264
+ set_seen.add(name);
265
+ list_matches.push(city);
266
+ }
267
+ }
268
+ const is_prefixed = (city: JsonObject): number => Number(String(city["name"]).toLowerCase().startsWith(wanted));
269
+ return list_matches
270
+ .sort((a: JsonObject, b: JsonObject) => is_prefixed(b) - is_prefixed(a))
271
+ .slice(0, MockSamples.CITY_RESULT_LIMIT);
272
+ }
273
+
274
+ /**
275
+ * The canned answer Raven gives in the mock.
276
+ *
277
+ * @param prompt - what the plugin asked
278
+ * @returns the answer
279
+ */
280
+ static answer(prompt: string): string {
281
+ const lowered = prompt.toLowerCase();
282
+ if (lowered.includes("agent") || lowered.includes("brief") || lowered.includes("usage")) {
283
+ return [
284
+ "Here is where things stand.",
285
+ "",
286
+ "- Claude Code is fixing the flaky upload test and is still working.",
287
+ "- Codex is waiting for you on the settings page port.",
288
+ "- Antigravity is idle after the release notes.",
289
+ "",
290
+ "Antigravity's daily limit is at 88%, so give long tasks to Claude Code or Codex today.",
291
+ ].join("\n");
292
+ }
293
+ const quoted = prompt.length > MockSamples.QUOTE_MAX_LENGTH
294
+ ? `${prompt.slice(0, MockSamples.QUOTE_MAX_LENGTH)}…`
295
+ : prompt;
296
+ return `This is the mock host's canned answer. Inside RollRook, Raven would answer:\n\n> ${quoted}`;
297
+ }
298
+
299
+ private static readonly QUOTE_MAX_LENGTH = 200;
300
+ }
@@ -0,0 +1,321 @@
1
+ /** What the mock toolbar's buttons do. */
2
+ export interface MockToolbarActions {
3
+ on_toggle_theme: () => void;
4
+ on_toggle_contrast: () => void;
5
+ /** Opens the plugin's settings view; undefined when it has none. */
6
+ on_open_settings: (() => void) | undefined;
7
+ on_toggle_visibility: () => void;
8
+ }
9
+
10
+ /** A popover the mock opens as an overlay. */
11
+ export interface MockPopoverOptions {
12
+ /** The popover view's page. */
13
+ url: string;
14
+ width: number;
15
+ height: number;
16
+ /** Called when the user clicks outside the popover or presses Escape. */
17
+ on_dismiss: () => void;
18
+ /** Whether it is a settings view, shown as a sheet in the middle rather than under the toolbar. */
19
+ is_sheet: boolean;
20
+ }
21
+
22
+ /**
23
+ * The mock host's floating controls: theme and high-contrast switches, a
24
+ * visibility switch, the badge the plugin set, the toasts it shows, and the
25
+ * popovers it opens. They live in a shadow
26
+ * root so the plugin's styles and theirs never meet.
27
+ */
28
+ export class MockToolbar {
29
+ /** The tag of the element hosting the shadow root. */
30
+ static readonly TAG_NAME = "rollrook-mock-host";
31
+
32
+ /** How long a toast stays before it fades. */
33
+ static readonly TOAST_DURATION_MS = 2600;
34
+
35
+ /** How long a toast takes to fade in or out. */
36
+ static readonly TOAST_FADE_MS = 220;
37
+
38
+ /** A popover's size when its view names none. */
39
+ static readonly POPOVER_DEFAULT_SIZE = 320;
40
+
41
+ /** How long a popover takes to appear or go. */
42
+ static readonly POPOVER_FADE_MS = 160;
43
+
44
+ /** The tag of the element hosting a popover's shadow root. */
45
+ static readonly POPOVER_TAG_NAME = "rollrook-mock-popover";
46
+
47
+ private static readonly POPOVER_STYLE = `
48
+ :host { all: initial; }
49
+ .backdrop {
50
+ position: fixed;
51
+ inset: 0;
52
+ z-index: 2147483646;
53
+ }
54
+ .panel {
55
+ position: fixed;
56
+ top: 34px;
57
+ right: 12px;
58
+ z-index: 2147483647;
59
+ overflow: hidden;
60
+ border-radius: 12px;
61
+ background: var(--rr-background, #fff);
62
+ border: 0.5px solid var(--rr-separator, rgba(0, 0, 0, 0.1));
63
+ transition-property: opacity, transform, height;
64
+ box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.1);
65
+ opacity: 0;
66
+ transform: translateY(-4px) scale(0.97);
67
+ transform-origin: top right;
68
+ transition: opacity ${MockToolbar.POPOVER_FADE_MS}ms ease, transform ${MockToolbar.POPOVER_FADE_MS}ms ease;
69
+ }
70
+ .panel.sheet {
71
+ top: 50%;
72
+ right: auto;
73
+ left: 50%;
74
+ transform: translate(-50%, calc(-50% - 4px)) scale(0.97);
75
+ transform-origin: center;
76
+ }
77
+ .panel.shown { opacity: 1; transform: none; }
78
+ .panel.sheet.shown { transform: translate(-50%, -50%); }
79
+ iframe { display: block; border: 0; width: 100%; height: 100%; background: transparent; }
80
+ `;
81
+
82
+ private static readonly STYLE = `
83
+ :host { all: initial; }
84
+ .toolbar {
85
+ position: fixed;
86
+ right: 12px;
87
+ bottom: 12px;
88
+ z-index: 2147483647;
89
+ display: flex;
90
+ align-items: center;
91
+ gap: 2px;
92
+ padding: 3px;
93
+ border-radius: 999px;
94
+ background: var(--rr-surface, #fff);
95
+ border: 0.5px solid var(--rr-separator, rgba(0, 0, 0, 0.1));
96
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
97
+ font: 500 12px/1 var(--rr-font, -apple-system, sans-serif);
98
+ color: var(--rr-text, #1d1d1f);
99
+ opacity: 0.72;
100
+ transition: opacity 160ms ease;
101
+ }
102
+ .toolbar:hover { opacity: 1; }
103
+ button {
104
+ all: unset;
105
+ display: grid;
106
+ place-items: center;
107
+ width: 26px;
108
+ height: 26px;
109
+ border-radius: 999px;
110
+ color: var(--rr-secondary-text, rgba(0, 0, 0, 0.6));
111
+ cursor: default;
112
+ transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
113
+ }
114
+ button:hover { background: var(--rr-separator, rgba(0, 0, 0, 0.08)); color: var(--rr-text, #1d1d1f); }
115
+ button:active { transform: scale(0.92); }
116
+ button:focus-visible { outline: 2px solid var(--rr-accent, #1d1d1f); outline-offset: 1px; }
117
+ svg { width: 15px; height: 15px; }
118
+ .badge {
119
+ min-width: 8px;
120
+ padding: 5px 8px;
121
+ margin-left: 2px;
122
+ border-radius: 999px;
123
+ background: var(--rr-accent, #1d1d1f);
124
+ color: var(--rr-on-accent, #fff);
125
+ text-align: center;
126
+ transition: opacity 160ms ease, transform 160ms ease;
127
+ }
128
+ .badge[hidden] { display: none; }
129
+ .badge.dot { min-width: 0; width: 7px; height: 7px; padding: 0; margin: 0 6px; }
130
+ .toasts {
131
+ position: fixed;
132
+ left: 0;
133
+ right: 0;
134
+ bottom: 56px;
135
+ z-index: 2147483647;
136
+ display: flex;
137
+ flex-direction: column;
138
+ align-items: center;
139
+ gap: 6px;
140
+ pointer-events: none;
141
+ }
142
+ .toast {
143
+ max-width: min(320px, calc(100vw - 32px));
144
+ padding: 8px 14px;
145
+ border-radius: 10px;
146
+ background: var(--rr-text, #1d1d1f);
147
+ color: var(--rr-background, #fff);
148
+ font: 400 13px/1.35 var(--rr-font, -apple-system, sans-serif);
149
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
150
+ opacity: 0;
151
+ transform: translateY(6px) scale(0.98);
152
+ transition: opacity ${MockToolbar.TOAST_FADE_MS}ms ease, transform ${MockToolbar.TOAST_FADE_MS}ms ease;
153
+ }
154
+ .toast.shown { opacity: 1; transform: none; }
155
+ `;
156
+
157
+ private static readonly ICON_THEME = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><circle cx="8" cy="8" r="5.6"/><path d="M8 2.4a5.6 5.6 0 0 1 0 11.2z" fill="currentColor"/></svg>`;
158
+
159
+ private static readonly ICON_SETTINGS = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M2.5 4.5h6M11.5 4.5h2M2.5 11.5h2M7.5 11.5h6"/><circle cx="10" cy="4.5" r="1.5"/><circle cx="6" cy="11.5" r="1.5"/></svg>`;
160
+ private static readonly ICON_CONTRAST = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="2.4" y="2.4" width="11.2" height="11.2" rx="2.6"/><path d="M8 2.4h3a2.6 2.6 0 0 1 2.6 2.6v6a2.6 2.6 0 0 1-2.6 2.6H8z" fill="currentColor"/></svg>`;
161
+
162
+ private static readonly ICON_SHOWN = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M1.6 8s2.4-4.6 6.4-4.6S14.4 8 14.4 8s-2.4 4.6-6.4 4.6S1.6 8 1.6 8z"/><circle cx="8" cy="8" r="1.9"/></svg>`;
163
+
164
+ private static readonly ICON_HIDDEN = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M1.6 8s2.4-4.6 6.4-4.6S14.4 8 14.4 8s-2.4 4.6-6.4 4.6S1.6 8 1.6 8z"/><path d="M2.6 13.4 13.4 2.6"/></svg>`;
165
+
166
+ private readonly actions: MockToolbarActions;
167
+ private readonly host_element: HTMLElement;
168
+ private readonly badge_element: HTMLElement;
169
+ private readonly visibility_button: HTMLButtonElement;
170
+ private readonly toasts_element: HTMLElement;
171
+
172
+ /**
173
+ * @param actions - what the buttons do
174
+ */
175
+ constructor(actions: MockToolbarActions) {
176
+ this.actions = actions;
177
+ this.host_element = document.createElement(MockToolbar.TAG_NAME);
178
+ const shadow = this.host_element.attachShadow({ mode: "open" });
179
+ const style = document.createElement("style");
180
+ style.textContent = MockToolbar.STYLE;
181
+ const toolbar = document.createElement("div");
182
+ toolbar.className = "toolbar";
183
+ toolbar.setAttribute("role", "toolbar");
184
+ const theme_button = MockToolbar.button("Switch light and dark", MockToolbar.ICON_THEME);
185
+ theme_button.addEventListener("click", () => this.actions.on_toggle_theme());
186
+ const contrast_button = MockToolbar.button("Switch high contrast", MockToolbar.ICON_CONTRAST);
187
+ contrast_button.addEventListener("click", () => this.actions.on_toggle_contrast());
188
+ this.visibility_button = MockToolbar.button("Hide the tab", MockToolbar.ICON_SHOWN);
189
+ this.visibility_button.addEventListener("click", () => this.actions.on_toggle_visibility());
190
+ this.badge_element = document.createElement("span");
191
+ this.badge_element.className = "badge";
192
+ this.badge_element.hidden = true;
193
+ toolbar.append(theme_button, contrast_button, this.visibility_button);
194
+ const on_open_settings = this.actions.on_open_settings;
195
+ if (on_open_settings !== undefined) {
196
+ const settings_button = MockToolbar.button("Open the plugin's settings", MockToolbar.ICON_SETTINGS);
197
+ settings_button.addEventListener("click", () => on_open_settings());
198
+ toolbar.append(settings_button);
199
+ }
200
+ toolbar.append(this.badge_element);
201
+ this.toasts_element = document.createElement("div");
202
+ this.toasts_element.className = "toasts";
203
+ this.toasts_element.setAttribute("aria-live", "polite");
204
+ shadow.append(style, toolbar, this.toasts_element);
205
+ }
206
+
207
+ /** Put the toolbar on the page. */
208
+ attach(): void {
209
+ document.documentElement.append(this.host_element);
210
+ }
211
+
212
+ /** Take the toolbar off the page. */
213
+ remove(): void {
214
+ this.host_element.remove();
215
+ }
216
+
217
+ /**
218
+ * @param text - the badge; `""` shows a dot, undefined hides it
219
+ */
220
+ render_badge(text: string | undefined): void {
221
+ this.badge_element.textContent = text ?? "";
222
+ this.badge_element.hidden = text === undefined;
223
+ this.badge_element.classList.toggle("dot", text === "");
224
+ }
225
+
226
+ /**
227
+ * Open a popover view's page in a panel over this page.
228
+ *
229
+ * @param options - the page, its size and what dismissing it does
230
+ * @returns the element holding the popover, for `dismiss_popover`
231
+ */
232
+ static popover(options: MockPopoverOptions): HTMLElement {
233
+ const host_element = document.createElement(MockToolbar.POPOVER_TAG_NAME);
234
+ const shadow = host_element.attachShadow({ mode: "open" });
235
+ const style = document.createElement("style");
236
+ style.textContent = MockToolbar.POPOVER_STYLE;
237
+ const backdrop = document.createElement("div");
238
+ backdrop.className = "backdrop";
239
+ backdrop.addEventListener("click", () => options.on_dismiss());
240
+ const panel = document.createElement("div");
241
+ panel.className = options.is_sheet ? "panel sheet" : "panel";
242
+ panel.style.width = `${options.width}px`;
243
+ panel.style.height = `${options.height}px`;
244
+ const frame = document.createElement("iframe");
245
+ frame.src = options.url;
246
+ frame.title = options.is_sheet ? "Settings" : "Popover";
247
+ panel.append(frame);
248
+ shadow.append(style, backdrop, panel);
249
+ const on_key = (event: KeyboardEvent): void => {
250
+ if (event.key === "Escape") {
251
+ options.on_dismiss();
252
+ }
253
+ };
254
+ document.addEventListener("keydown", on_key);
255
+ host_element.addEventListener("rollrook-mock-dismiss", () => document.removeEventListener("keydown", on_key));
256
+ document.documentElement.append(host_element);
257
+ requestAnimationFrame(() => panel.classList.add("shown"));
258
+ return host_element;
259
+ }
260
+
261
+ /**
262
+ * Change a popover's or settings sheet's height, as `ui.height` asks.
263
+ *
264
+ * @param host_element - what `popover` returned
265
+ * @param height - the height in points
266
+ */
267
+ static resize_popover(host_element: HTMLElement, height: number): void {
268
+ const panel = host_element.shadowRoot?.querySelector<HTMLElement>(".panel");
269
+ if (panel !== null && panel !== undefined) {
270
+ panel.style.height = `${height}px`;
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Fade a popover out and remove it; it takes no clicks while it fades.
276
+ *
277
+ * @param host_element - what `popover` returned
278
+ */
279
+ static dismiss_popover(host_element: HTMLElement): void {
280
+ host_element.dispatchEvent(new Event("rollrook-mock-dismiss"));
281
+ host_element.style.pointerEvents = "none";
282
+ host_element.shadowRoot?.querySelector(".panel")?.classList.remove("shown");
283
+ setTimeout(() => host_element.remove(), MockToolbar.POPOVER_FADE_MS);
284
+ }
285
+
286
+ /**
287
+ * @param is_shown - whether the plugin's tab now counts as shown
288
+ */
289
+ render_visibility(is_shown: boolean): void {
290
+ this.visibility_button.innerHTML = is_shown ? MockToolbar.ICON_SHOWN : MockToolbar.ICON_HIDDEN;
291
+ const label = is_shown ? "Hide the tab" : "Show the tab";
292
+ this.visibility_button.title = label;
293
+ this.visibility_button.setAttribute("aria-label", label);
294
+ }
295
+
296
+ /**
297
+ * Show a toast that fades after a moment.
298
+ *
299
+ * @param text - the message
300
+ */
301
+ toast(text: string): void {
302
+ const toast = document.createElement("div");
303
+ toast.className = "toast";
304
+ toast.textContent = text;
305
+ this.toasts_element.append(toast);
306
+ requestAnimationFrame(() => toast.classList.add("shown"));
307
+ setTimeout(() => {
308
+ toast.classList.remove("shown");
309
+ setTimeout(() => toast.remove(), MockToolbar.TOAST_FADE_MS);
310
+ }, MockToolbar.TOAST_DURATION_MS);
311
+ }
312
+
313
+ private static button(label: string, icon: string): HTMLButtonElement {
314
+ const button = document.createElement("button");
315
+ button.type = "button";
316
+ button.title = label;
317
+ button.setAttribute("aria-label", label);
318
+ button.innerHTML = icon;
319
+ return button;
320
+ }
321
+ }
package/src/net.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Bridge } from "./bridge.js";
2
+ import type { FetchRequest, FetchResponse, JsonObject } from "./types.js";
3
+ import { Wire } from "./wire.js";
4
+
5
+ /**
6
+ * Fetch over https through RollRook. The page itself cannot reach the
7
+ * network; each host must be granted with a `net:<host>` permission.
8
+ */
9
+ export class NetApi {
10
+ /**
11
+ * @param request - the request to send
12
+ * @returns the response, its body as text
13
+ */
14
+ async fetch(request: FetchRequest): Promise<FetchResponse> {
15
+ const params: JsonObject = { url: request.url };
16
+ if (request.method !== undefined) {
17
+ params["method"] = request.method;
18
+ }
19
+ if (request.map_headers !== undefined) {
20
+ params["headers"] = { ...request.map_headers };
21
+ }
22
+ if (request.body !== undefined) {
23
+ params["body"] = request.body;
24
+ }
25
+ return Wire.fetch_response(await Bridge.call("net.fetch", params));
26
+ }
27
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Bridge } from "./bridge.js";
2
+ import type { JsonValue } from "./types.js";
3
+
4
+ /** The plugin's other running views; their messages arrive as the `message` event. */
5
+ export class PluginApi {
6
+ /**
7
+ * Send a message to every other instance of the plugin's views.
8
+ *
9
+ * @param message - any JSON value
10
+ */
11
+ async broadcast(message: JsonValue): Promise<void> {
12
+ await Bridge.call("plugin.broadcast", { message });
13
+ }
14
+ }