@liberation-data/desk 0.43.0 → 0.44.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.
- package/README.md +225 -8
- package/dist/core/hosted.d.ts +222 -0
- package/dist/core/hosted.d.ts.map +1 -0
- package/dist/core/hosted.js +166 -0
- package/dist/core/hosted.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/location.d.ts +8 -1
- package/dist/core/location.d.ts.map +1 -1
- package/dist/core/location.js +18 -2
- package/dist/core/location.js.map +1 -1
- package/dist/core/preferences.d.ts +27 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +121 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/scheme.d.ts +9 -3
- package/dist/core/scheme.d.ts.map +1 -1
- package/dist/core/scheme.js +13 -4
- package/dist/core/scheme.js.map +1 -1
- package/dist/core/theme.d.ts +41 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +56 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/core/themeChange.d.ts +25 -0
- package/dist/core/themeChange.d.ts.map +1 -0
- package/dist/core/themeChange.js +49 -0
- package/dist/core/themeChange.js.map +1 -0
- package/dist/css/apps.css +35 -1
- package/dist/css/shell.css +100 -0
- package/dist/css/tokens.css +10 -0
- package/dist/desk.css +45 -1
- package/dist/fx/fx.d.ts.map +1 -1
- package/dist/fx/fx.js +7 -31
- package/dist/fx/fx.js.map +1 -1
- package/dist/host/checkChrome.d.ts +20 -0
- package/dist/host/checkChrome.d.ts.map +1 -0
- package/dist/host/checkChrome.js +219 -0
- package/dist/host/checkChrome.js.map +1 -0
- package/dist/host/checkTheme.d.ts +35 -0
- package/dist/host/checkTheme.d.ts.map +1 -0
- package/dist/host/checkTheme.js +128 -0
- package/dist/host/checkTheme.js.map +1 -0
- package/dist/host/index.d.ts +7 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +8 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/router.d.ts +99 -0
- package/dist/host/router.d.ts.map +1 -0
- package/dist/host/router.js +279 -0
- package/dist/host/router.js.map +1 -0
- package/dist/react/Dock.d.ts +23 -4
- package/dist/react/Dock.d.ts.map +1 -1
- package/dist/react/Dock.js +17 -29
- package/dist/react/Dock.js.map +1 -1
- package/dist/react/MenuBar.d.ts +1 -1
- package/dist/react/MenuBar.d.ts.map +1 -1
- package/dist/react/MenuBar.js +20 -4
- package/dist/react/MenuBar.js.map +1 -1
- package/dist/react/app.d.ts +50 -9
- package/dist/react/app.d.ts.map +1 -1
- package/dist/react/app.js +59 -13
- package/dist/react/app.js.map +1 -1
- package/dist/react/appFrame.d.ts +11 -7
- package/dist/react/appFrame.d.ts.map +1 -1
- package/dist/react/appFrame.js +24 -6
- package/dist/react/appFrame.js.map +1 -1
- package/dist/react/appPanels.d.ts +4 -1
- package/dist/react/appPanels.d.ts.map +1 -1
- package/dist/react/appPanels.js +32 -23
- package/dist/react/appPanels.js.map +1 -1
- package/dist/react/appearance.d.ts +7 -1
- package/dist/react/appearance.d.ts.map +1 -1
- package/dist/react/appearance.js +32 -53
- package/dist/react/appearance.js.map +1 -1
- package/dist/react/context.d.ts +15 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.js +73 -14
- package/dist/react/context.js.map +1 -1
- package/dist/react/dockStatus.d.ts +19 -0
- package/dist/react/dockStatus.d.ts.map +1 -0
- package/dist/react/dockStatus.js +25 -0
- package/dist/react/dockStatus.js.map +1 -0
- package/dist/react/frameMenus.d.ts +28 -0
- package/dist/react/frameMenus.d.ts.map +1 -0
- package/dist/react/frameMenus.js +85 -0
- package/dist/react/frameMenus.js.map +1 -0
- package/dist/react/hostApp.d.ts +15 -0
- package/dist/react/hostApp.d.ts.map +1 -0
- package/dist/react/hostApp.js +77 -0
- package/dist/react/hostApp.js.map +1 -0
- package/dist/react/hostDock.d.ts +25 -0
- package/dist/react/hostDock.d.ts.map +1 -0
- package/dist/react/hostDock.js +98 -0
- package/dist/react/hostDock.js.map +1 -0
- package/dist/react/hostMenu.d.ts +2 -36
- package/dist/react/hostMenu.d.ts.map +1 -1
- package/dist/react/hostMenu.js.map +1 -1
- package/dist/react/hosted.d.ts +28 -0
- package/dist/react/hosted.d.ts.map +1 -0
- package/dist/react/hosted.js +53 -0
- package/dist/react/hosted.js.map +1 -0
- package/dist/react/index.d.ts +8 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/shell.d.ts +13 -1
- package/dist/react/shell.d.ts.map +1 -1
- package/dist/react/shell.js +19 -3
- package/dist/react/shell.js.map +1 -1
- package/dist/react/windowMenus.d.ts +19 -0
- package/dist/react/windowMenus.d.ts.map +1 -0
- package/dist/react/windowMenus.js +88 -0
- package/dist/react/windowMenus.js.map +1 -0
- package/dist/shell/HostShell.d.ts +53 -0
- package/dist/shell/HostShell.d.ts.map +1 -0
- package/dist/shell/HostShell.js +116 -0
- package/dist/shell/HostShell.js.map +1 -0
- package/dist/shell/index.d.ts +7 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +9 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/shell/keys.d.ts +47 -0
- package/dist/shell/keys.d.ts.map +1 -0
- package/dist/shell/keys.js +68 -0
- package/dist/shell/keys.js.map +1 -0
- package/dist/shell/motion.d.ts +72 -0
- package/dist/shell/motion.d.ts.map +1 -0
- package/dist/shell/motion.js +118 -0
- package/dist/shell/motion.js.map +1 -0
- package/llms.txt +48 -14
- package/package.json +10 -1
- package/src/core/hosted.ts +351 -0
- package/src/core/index.ts +28 -1
- package/src/core/location.ts +23 -3
- package/src/core/preferences.ts +132 -0
- package/src/core/scheme.ts +16 -5
- package/src/core/theme.ts +91 -0
- package/src/core/themeChange.ts +59 -0
- package/src/css/apps.css +35 -1
- package/src/css/shell.css +99 -0
- package/src/css/tokens.css +10 -0
- package/src/fx/fx.ts +7 -25
- package/src/host/checkChrome.ts +257 -0
- package/src/host/checkTheme.ts +134 -0
- package/src/host/index.ts +10 -0
- package/src/host/router.ts +374 -0
- package/src/react/Dock.tsx +34 -28
- package/src/react/MenuBar.tsx +22 -4
- package/src/react/app.tsx +84 -14
- package/src/react/appFrame.tsx +39 -14
- package/src/react/appPanels.tsx +38 -25
- package/src/react/appearance.tsx +36 -45
- package/src/react/context.tsx +88 -13
- package/src/react/dockStatus.ts +42 -0
- package/src/react/frameMenus.ts +100 -0
- package/src/react/hostApp.tsx +89 -0
- package/src/react/hostDock.tsx +118 -0
- package/src/react/hostMenu.ts +3 -38
- package/src/react/hosted.tsx +65 -0
- package/src/react/index.ts +9 -2
- package/src/react/shell.tsx +30 -3
- package/src/react/windowMenus.ts +107 -0
- package/src/shell/HostShell.tsx +220 -0
- package/src/shell/index.ts +11 -0
- package/src/shell/keys.ts +101 -0
- package/src/shell/motion.ts +163 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { fromOriginOrData, IMAGE_DATA, onOrigin } from './checkTheme.js';
|
|
2
|
+
/** The most the whole chrome may take as JSON: room for a dock of a few dozen `data:` icons. */
|
|
3
|
+
const MAX_CHROME = 2 * 1024 * 1024;
|
|
4
|
+
const MAX_TEXT = 1000;
|
|
5
|
+
const MAX_URL = 2048;
|
|
6
|
+
/** One `data:` icon. */
|
|
7
|
+
const MAX_IMAGE = 256 * 1024;
|
|
8
|
+
const MAX_MENUS = 50;
|
|
9
|
+
const MAX_ROWS = 500;
|
|
10
|
+
const MAX_SECTIONS = 200;
|
|
11
|
+
const MAX_LINKS = 50;
|
|
12
|
+
/** Thrown for a part that fails: the part is dropped, for this reason. */
|
|
13
|
+
class Refused extends Error {
|
|
14
|
+
}
|
|
15
|
+
/** Thrown for chrome of the wrong shape: the whole message is refused. */
|
|
16
|
+
class Malformed extends Error {
|
|
17
|
+
}
|
|
18
|
+
const refuse = (reason) => {
|
|
19
|
+
throw new Refused(reason);
|
|
20
|
+
};
|
|
21
|
+
const record = (value, what) => typeof value === 'object' && value !== null && !Array.isArray(value) ? value : refuse(`${what} is not an object`);
|
|
22
|
+
/** `make()`, or `otherwise` with the reason noted when the part fails. */
|
|
23
|
+
const orDrop = (c, make, otherwise) => {
|
|
24
|
+
try {
|
|
25
|
+
return make();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (!(error instanceof Refused))
|
|
29
|
+
throw error;
|
|
30
|
+
c.dropped.push(error.message);
|
|
31
|
+
return otherwise;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** The items of a list that pass `check`; the rest, and any past the first `max`, are dropped. */
|
|
35
|
+
const list = (c, value, max, what, check) => {
|
|
36
|
+
if (!Array.isArray(value))
|
|
37
|
+
return refuse(`${what} is not a list`);
|
|
38
|
+
if (value.length > max)
|
|
39
|
+
c.dropped.push(`${what}: ${value.length - max} past the first ${max}`);
|
|
40
|
+
return value.slice(0, max).flatMap(item => orDrop(c, () => [check(item)], []));
|
|
41
|
+
};
|
|
42
|
+
/** Text a host draws: a string, not too long, with no control or direction-overriding characters. */
|
|
43
|
+
const text = (value, what) =>
|
|
44
|
+
// eslint-disable-next-line no-control-regex
|
|
45
|
+
typeof value === 'string' && value.length <= MAX_TEXT && !/[\u0000-\u0008\u000b-\u001f\u007f--]/.test(value)
|
|
46
|
+
? value
|
|
47
|
+
: refuse(`${what} is not plain text`);
|
|
48
|
+
/** The field when present, checked by `check`; nothing when absent. */
|
|
49
|
+
const optional = (fields, key, check) => fields[key] === undefined ? {} : { [key]: check(fields[key], key) };
|
|
50
|
+
const flag = (value, what) => (typeof value === 'boolean' ? value : refuse(`${what} is not true or false`));
|
|
51
|
+
/**
|
|
52
|
+
* A link a host may open, in the system browser or a mail app: http(s) or `mailto:` anywhere, or the
|
|
53
|
+
* app's own origin. Resolved, so a relative one points at the app and not at the host.
|
|
54
|
+
*/
|
|
55
|
+
const link = (value, what, origin) => {
|
|
56
|
+
if (typeof value !== 'string' || value.length > MAX_URL)
|
|
57
|
+
return refuse(`${what} is not a link`);
|
|
58
|
+
try {
|
|
59
|
+
const url = new URL(value, origin);
|
|
60
|
+
if (url.protocol === 'http:' || url.protocol === 'https:' || url.protocol === 'mailto:' || onOrigin(url, origin))
|
|
61
|
+
return url.href;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Refused below.
|
|
65
|
+
}
|
|
66
|
+
return refuse(`${what} is not an http(s) or mailto: link`);
|
|
67
|
+
};
|
|
68
|
+
/** An image the host may load, dropped from its item when it fails: from the app's origin, or a `data:` raster image. Never SVG, which can carry script. */
|
|
69
|
+
const image = (c, fields, what) => orDrop(c, () => optional(fields, 'image', value => (typeof value === 'string' && value.length <= MAX_IMAGE && fromOriginOrData(value, c.origin, IMAGE_DATA)) || refuse(`${what}'s image is not from the app`)), {});
|
|
70
|
+
const menuItem = (value) => {
|
|
71
|
+
const item = record(value, 'a menu item');
|
|
72
|
+
if (item.items !== undefined)
|
|
73
|
+
throw new Malformed('a menu in a menu');
|
|
74
|
+
if (item.type !== 'item' && item.type !== 'separator' && item.type !== 'header')
|
|
75
|
+
return refuse('a menu item has no type');
|
|
76
|
+
return {
|
|
77
|
+
type: item.type,
|
|
78
|
+
...optional(item, 'id', text),
|
|
79
|
+
...optional(item, 'label', text),
|
|
80
|
+
...optional(item, 'detail', text),
|
|
81
|
+
...optional(item, 'shortcut', text),
|
|
82
|
+
...optional(item, 'showOnly', flag),
|
|
83
|
+
...optional(item, 'enabled', flag),
|
|
84
|
+
...optional(item, 'checked', flag),
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const menu = (c, value) => {
|
|
88
|
+
const m = record(value, 'a menu');
|
|
89
|
+
return {
|
|
90
|
+
id: text(m.id, 'a menu id'),
|
|
91
|
+
label: text(m.label, 'a menu label'),
|
|
92
|
+
...optional(m, 'primary', flag),
|
|
93
|
+
...optional(m, 'status', flag),
|
|
94
|
+
items: list(c, m.items, MAX_ROWS, 'a menu', menuItem),
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const dockItem = (c, value) => {
|
|
98
|
+
const item = record(value, 'a dock item');
|
|
99
|
+
if (item.type === 'stack')
|
|
100
|
+
throw new Malformed('a stack in a stack');
|
|
101
|
+
if (item.type !== 'item')
|
|
102
|
+
return refuse('a dock item has no type');
|
|
103
|
+
return {
|
|
104
|
+
type: 'item',
|
|
105
|
+
id: text(item.id, 'a dock id'),
|
|
106
|
+
label: text(item.label, 'a dock label'),
|
|
107
|
+
...optional(item, 'description', text),
|
|
108
|
+
...image(c, item, 'a dock item'),
|
|
109
|
+
...optional(item, 'badge', text),
|
|
110
|
+
...optional(item, 'disabled', flag),
|
|
111
|
+
running: flag(item.running, 'running'),
|
|
112
|
+
focused: flag(item.focused, 'focused'),
|
|
113
|
+
minimized: flag(item.minimized, 'minimized'),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const dockEntry = (c, value) => {
|
|
117
|
+
const entry = record(value, 'a dock entry');
|
|
118
|
+
if (entry.type === 'separator')
|
|
119
|
+
return { type: 'separator', id: text(entry.id, 'a dock id') };
|
|
120
|
+
if (entry.type !== 'stack')
|
|
121
|
+
return dockItem(c, entry);
|
|
122
|
+
return {
|
|
123
|
+
type: 'stack',
|
|
124
|
+
id: text(entry.id, 'a dock id'),
|
|
125
|
+
label: text(entry.label, 'a dock label'),
|
|
126
|
+
...image(c, entry, 'a stack'),
|
|
127
|
+
items: list(c, entry.items, MAX_ROWS, 'a stack', item => dockItem(c, item)),
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const settingsSection = (value) => {
|
|
131
|
+
const section = record(value, 'a settings section');
|
|
132
|
+
return {
|
|
133
|
+
id: text(section.id, 'a section id'),
|
|
134
|
+
title: text(section.title, 'a section title'),
|
|
135
|
+
...optional(section, 'group', text),
|
|
136
|
+
...optional(section, 'badge', text),
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const labelledLink = (c, value) => {
|
|
140
|
+
const l = record(value, 'a link');
|
|
141
|
+
return { label: text(l.label, 'a link label'), url: link(l.url, 'a link', c.origin) };
|
|
142
|
+
};
|
|
143
|
+
const fact = (c, value) => {
|
|
144
|
+
const f = record(value, 'a fact');
|
|
145
|
+
if (f.copy !== undefined && f.copy !== false)
|
|
146
|
+
return refuse('a fact has a bad copy');
|
|
147
|
+
return {
|
|
148
|
+
name: text(f.name, 'a fact name'),
|
|
149
|
+
value: text(f.value, 'a fact value'),
|
|
150
|
+
...(f.link === undefined ? {} : orDrop(c, () => ({ link: labelledLink(c, f.link) }), {})),
|
|
151
|
+
...(f.copy === false ? { copy: false } : {}),
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
const about = (c, value) => {
|
|
155
|
+
if (value === null)
|
|
156
|
+
return null;
|
|
157
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
158
|
+
throw new Malformed('about is not an object');
|
|
159
|
+
const a = value;
|
|
160
|
+
return orDrop(c, () => ({
|
|
161
|
+
name: text(a.name, 'the name'),
|
|
162
|
+
...optional(a, 'version', text),
|
|
163
|
+
links: list(c, a.links, MAX_LINKS, 'links', l => labelledLink(c, l)),
|
|
164
|
+
...optional(a, 'note', text),
|
|
165
|
+
facts: a.facts === null
|
|
166
|
+
? null
|
|
167
|
+
: list(c, a.facts, MAX_SECTIONS, 'facts', s => {
|
|
168
|
+
const section = record(s, 'a section of facts');
|
|
169
|
+
return { ...optional(section, 'title', text), facts: list(c, section.facts, MAX_ROWS, 'a section of facts', f => fact(c, f)) };
|
|
170
|
+
}),
|
|
171
|
+
}), null);
|
|
172
|
+
};
|
|
173
|
+
/** A top-level list: refused whole when it is not one. */
|
|
174
|
+
const topList = (c, value, max, what, check) => {
|
|
175
|
+
if (!Array.isArray(value))
|
|
176
|
+
throw new Malformed(`${what} is not a list`);
|
|
177
|
+
return list(c, value, max, what, check);
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Checks the chrome an app at `origin` sent before the host draws it, and returns a copy with only the
|
|
181
|
+
* fields a `DeskChrome` has. Text must be strings of bounded length, lists bounded too, links http(s),
|
|
182
|
+
* `mailto:` or the app's own, and images from `origin` or `data:` PNG, JPEG, WebP, AVIF or GIF.
|
|
183
|
+
* Relative links and images come back resolved against `origin`, since the host's frame is elsewhere.
|
|
184
|
+
* A part that fails is dropped and the rest kept, with a short reason in `dropped` for each; chrome
|
|
185
|
+
* of the wrong shape (see above) is refused whole.
|
|
186
|
+
*/
|
|
187
|
+
export function checkChrome(value, origin) {
|
|
188
|
+
let size;
|
|
189
|
+
try {
|
|
190
|
+
size = JSON.stringify(value ?? null).length;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return { ok: false, reason: 'not data' };
|
|
194
|
+
}
|
|
195
|
+
if (size > MAX_CHROME)
|
|
196
|
+
return { ok: false, reason: 'too large' };
|
|
197
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
198
|
+
return { ok: false, reason: 'chrome is not an object' };
|
|
199
|
+
const chrome = value;
|
|
200
|
+
const c = { origin, dropped: [] };
|
|
201
|
+
try {
|
|
202
|
+
return {
|
|
203
|
+
ok: true,
|
|
204
|
+
chrome: {
|
|
205
|
+
menus: topList(c, chrome.menus, MAX_MENUS, 'menus', m => menu(c, m)),
|
|
206
|
+
dock: topList(c, chrome.dock, MAX_ROWS, 'the dock', entry => dockEntry(c, entry)),
|
|
207
|
+
settings: topList(c, chrome.settings, MAX_SECTIONS, 'settings', settingsSection),
|
|
208
|
+
about: about(c, chrome.about),
|
|
209
|
+
},
|
|
210
|
+
dropped: c.dropped,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (error instanceof Malformed)
|
|
215
|
+
return { ok: false, reason: error.message };
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=checkChrome.js.map
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AAE,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACjF,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC;gBAChF,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC;aAC9B;YACD,OAAO,EAAE,CAAC,CAAC,OAAO;SACnB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,SAAS;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;QAC3E,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DeskTheme } from '../core/theme.js';
|
|
2
|
+
/** A theme fit to pass on, as a fresh copy, or why it is not. */
|
|
3
|
+
export type ThemeCheck = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly theme: DeskTheme;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Whether a custom property's value is plain: a colour, a length, a number, a font list or a gradient.
|
|
12
|
+
* Only letters, digits, spaces and `#.,%/'"+-()*` may appear, every function is one of `FUNCTIONS`, and
|
|
13
|
+
* nothing may escape, end the declaration or open a block. So `url(…)`, `image-set(…)`, `\75rl(` and
|
|
14
|
+
* `red; background: …` are all refused.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isPlainValue(value: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `url` is on `origin`: the same scheme and host. Compared by hand rather than by `URL.origin`,
|
|
19
|
+
* which is `'null'` for every scheme a browser does not know (an Electron app's `app://` among them,
|
|
20
|
+
* and `javascript:` too), so it would take any of them for any other. A URL with no host is on none.
|
|
21
|
+
*/
|
|
22
|
+
export declare function onOrigin(url: URL, origin: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* `src` as a URL safe to put in CSS, when it is a `data:` URI of one of `kinds` or a URL on `origin`;
|
|
25
|
+
* null otherwise. A URL comes back resolved and percent-encoded, so it holds no quote.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fromOriginOrData(src: string, origin: string, kinds: RegExp): string | null;
|
|
28
|
+
export declare const IMAGE_DATA: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* Checks a theme published by `origin` before it is passed to other pages, and returns a copy with
|
|
31
|
+
* only the fields a `DeskTheme` has. Tokens must be custom properties with plain values
|
|
32
|
+
* (`isPlainValue`); fonts and an image wallpaper must come from `origin` or be `data:` URIs.
|
|
33
|
+
*/
|
|
34
|
+
export declare function checkTheme(value: unknown, origin: string): ThemeCheck;
|
|
35
|
+
//# sourceMappingURL=checkTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkTheme.d.ts","sourceRoot":"","sources":["../../src/host/checkTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,kBAAkB,CAAA;AAY5D,iEAAiE;AACjE,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAe3H;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOnD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ1F;AAGD,eAAO,MAAM,UAAU,QAA0C,CAAA;AAIjE;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAsDrE"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { isImageRef } from '../core/theme.js';
|
|
2
|
+
const LOOKS = ['mac', 'gnome', 'windows'];
|
|
3
|
+
/** The CSS functions a token may use: colours, maths, gradients and other custom properties. Nothing that loads. */
|
|
4
|
+
const FUNCTIONS = new Set([
|
|
5
|
+
'rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color', 'color-mix', 'light-dark',
|
|
6
|
+
'var', 'calc', 'min', 'max', 'clamp',
|
|
7
|
+
'linear-gradient', 'radial-gradient', 'conic-gradient', 'repeating-linear-gradient', 'repeating-radial-gradient',
|
|
8
|
+
]);
|
|
9
|
+
const MAX_VALUE = 300;
|
|
10
|
+
const MAX_TOKENS = 400;
|
|
11
|
+
const MAX_FONTS = 16;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a custom property's value is plain: a colour, a length, a number, a font list or a gradient.
|
|
14
|
+
* Only letters, digits, spaces and `#.,%/'"+-()*` may appear, every function is one of `FUNCTIONS`, and
|
|
15
|
+
* nothing may escape, end the declaration or open a block. So `url(…)`, `image-set(…)`, `\75rl(` and
|
|
16
|
+
* `red; background: …` are all refused.
|
|
17
|
+
*/
|
|
18
|
+
export function isPlainValue(value) {
|
|
19
|
+
if (value.length > MAX_VALUE)
|
|
20
|
+
return false;
|
|
21
|
+
if (!/^[\w\s#.,%/'"+*()-]*$/.test(value))
|
|
22
|
+
return false;
|
|
23
|
+
for (const match of value.matchAll(/([\w-]*)\s*\(/g)) {
|
|
24
|
+
if (!FUNCTIONS.has((match[1] ?? '').toLowerCase()))
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether `url` is on `origin`: the same scheme and host. Compared by hand rather than by `URL.origin`,
|
|
31
|
+
* which is `'null'` for every scheme a browser does not know (an Electron app's `app://` among them,
|
|
32
|
+
* and `javascript:` too), so it would take any of them for any other. A URL with no host is on none.
|
|
33
|
+
*/
|
|
34
|
+
export function onOrigin(url, origin) {
|
|
35
|
+
const own = new URL(origin);
|
|
36
|
+
return url.host !== '' && url.protocol === own.protocol && url.host === own.host;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `src` as a URL safe to put in CSS, when it is a `data:` URI of one of `kinds` or a URL on `origin`;
|
|
40
|
+
* null otherwise. A URL comes back resolved and percent-encoded, so it holds no quote.
|
|
41
|
+
*/
|
|
42
|
+
export function fromOriginOrData(src, origin, kinds) {
|
|
43
|
+
if (src.startsWith('data:'))
|
|
44
|
+
return kinds.test(src.slice(5)) && !/["\\\s]/.test(src) ? src : null;
|
|
45
|
+
try {
|
|
46
|
+
const url = new URL(src, origin);
|
|
47
|
+
return onOrigin(url, origin) ? url.href : null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const FONT_DATA = /^(font\/|application\/(font|x-font|octet-stream))/i;
|
|
54
|
+
export const IMAGE_DATA = /^image\/(png|jpeg|webp|avif|gif)[;,]/i;
|
|
55
|
+
/** A font family as CSS names one: words, spaces and hyphens, nothing to quote or escape. */
|
|
56
|
+
const FAMILY = /^[\w -]{1,80}$/;
|
|
57
|
+
/**
|
|
58
|
+
* Checks a theme published by `origin` before it is passed to other pages, and returns a copy with
|
|
59
|
+
* only the fields a `DeskTheme` has. Tokens must be custom properties with plain values
|
|
60
|
+
* (`isPlainValue`); fonts and an image wallpaper must come from `origin` or be `data:` URIs.
|
|
61
|
+
*/
|
|
62
|
+
export function checkTheme(value, origin) {
|
|
63
|
+
const fail = (reason) => ({ ok: false, reason });
|
|
64
|
+
if (typeof value !== 'object' || value === null)
|
|
65
|
+
return fail('not an object');
|
|
66
|
+
const theme = value;
|
|
67
|
+
if (theme.mode !== 'light' && theme.mode !== 'dark')
|
|
68
|
+
return fail('mode must be light or dark');
|
|
69
|
+
if (typeof theme.look !== 'string' || !LOOKS.includes(theme.look))
|
|
70
|
+
return fail('look must be mac, gnome or windows');
|
|
71
|
+
if (typeof theme.tokens !== 'object' || theme.tokens === null)
|
|
72
|
+
return fail('tokens must be an object');
|
|
73
|
+
const entries = Object.entries(theme.tokens);
|
|
74
|
+
if (entries.length > MAX_TOKENS)
|
|
75
|
+
return fail('too many tokens');
|
|
76
|
+
const tokens = {};
|
|
77
|
+
for (const [name, token] of entries) {
|
|
78
|
+
if (!/^--[\w-]+$/.test(name))
|
|
79
|
+
return fail(`${name} is not a custom property`);
|
|
80
|
+
if (typeof token !== 'string' || !isPlainValue(token))
|
|
81
|
+
return fail(`${name} is not a plain value`);
|
|
82
|
+
tokens[name] = token;
|
|
83
|
+
}
|
|
84
|
+
let fonts;
|
|
85
|
+
if (theme.fonts !== undefined) {
|
|
86
|
+
if (!Array.isArray(theme.fonts) || theme.fonts.length > MAX_FONTS)
|
|
87
|
+
return fail('fonts must be a short list');
|
|
88
|
+
fonts = [];
|
|
89
|
+
for (const font of theme.fonts) {
|
|
90
|
+
const f = font;
|
|
91
|
+
if (typeof f?.family !== 'string' || !FAMILY.test(f.family))
|
|
92
|
+
return fail('a font family is not plain');
|
|
93
|
+
const src = typeof f.src === 'string' ? fromOriginOrData(f.src, origin, FONT_DATA) : null;
|
|
94
|
+
if (src === null)
|
|
95
|
+
return fail(`font ${f.family} is not from the publisher`);
|
|
96
|
+
if (f.weight !== undefined && (typeof f.weight !== 'string' || !/^\d{3}( \d{3})?$|^(normal|bold)$/.test(f.weight)))
|
|
97
|
+
return fail(`font ${f.family} has a bad weight`);
|
|
98
|
+
if (f.style !== undefined && f.style !== 'normal' && f.style !== 'italic')
|
|
99
|
+
return fail(`font ${f.family} has a bad style`);
|
|
100
|
+
fonts.push({
|
|
101
|
+
family: f.family,
|
|
102
|
+
src,
|
|
103
|
+
...(f.weight === undefined ? {} : { weight: f.weight }),
|
|
104
|
+
...(f.style === undefined ? {} : { style: f.style }),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let wallpaper;
|
|
109
|
+
if (theme.wallpaper !== undefined) {
|
|
110
|
+
if (typeof theme.wallpaper !== 'string')
|
|
111
|
+
return fail('wallpaper must be a string');
|
|
112
|
+
const image = isImageRef(theme.wallpaper) ? fromOriginOrData(theme.wallpaper, origin, IMAGE_DATA) : isPlainValue(theme.wallpaper) ? theme.wallpaper : null;
|
|
113
|
+
if (image === null)
|
|
114
|
+
return fail('wallpaper is not from the publisher');
|
|
115
|
+
wallpaper = image;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
theme: {
|
|
120
|
+
mode: theme.mode,
|
|
121
|
+
look: theme.look,
|
|
122
|
+
tokens,
|
|
123
|
+
...(fonts === undefined ? {} : { fonts }),
|
|
124
|
+
...(wallpaper === undefined ? {} : { wallpaper }),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=checkTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkTheme.js","sourceRoot":"","sources":["../../src/host/checkTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAgB7C,MAAM,KAAK,GAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AAE5D,oHAAoH;AACpH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,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AC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1J,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,qCAAqC,CAAC,CAAA;QACtE,SAAS,GAAG,KAAK,CAAA;IACnB,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI;QACR,KAAK,EAAE;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAY;YACxB,MAAM;YACN,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACzC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;SAClD;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { checkChrome } from './checkChrome.js';
|
|
2
|
+
export type { ChromeCheck } from './checkChrome.js';
|
|
3
|
+
export { checkTheme, isPlainValue } from './checkTheme.js';
|
|
4
|
+
export type { ThemeCheck } from './checkTheme.js';
|
|
5
|
+
export { createBroadcastRouter, createMemoryHost } from './router.js';
|
|
6
|
+
export type { BroadcastRouter, BroadcastRouterOptions, HostedApp, MemoryHost, Rate, RateLimits, Refusal } from './router.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1D,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACrE,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The host's side of hosted mode: what a native or web shell uses to run several Desk apps under one
|
|
3
|
+
* menu bar and dock. Apps never load it; they use `connectHost`, through `DeskProvider`, from core.
|
|
4
|
+
*/
|
|
5
|
+
export { checkChrome } from './checkChrome.js';
|
|
6
|
+
export { checkTheme, isPlainValue } from './checkTheme.js';
|
|
7
|
+
export { createBroadcastRouter, createMemoryHost } from './router.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { CommandTarget, DeskChrome, DeskHostBridge, HostToApp } from '../core/hosted.js';
|
|
2
|
+
/** An app as its host registers it. */
|
|
3
|
+
export interface HostedApp {
|
|
4
|
+
/** Stable across runs. */
|
|
5
|
+
readonly id: string;
|
|
6
|
+
/** Where the app is served: its theme's fonts and images, and its dock's images, must come from here. */
|
|
7
|
+
readonly origin: string;
|
|
8
|
+
/** The app whose theme every app wears. At most one. */
|
|
9
|
+
readonly primary?: boolean;
|
|
10
|
+
/** Topics it may publish (`ride.*` grants a branch). Granted by the host, never by the app. The primary needs `theme` among them. */
|
|
11
|
+
readonly publishes?: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** What a router needs from its host: a way to reach each app, and the host's own rules. */
|
|
14
|
+
export interface BroadcastRouterOptions {
|
|
15
|
+
/** Sends a message to an app, through the host's transport. One that throws keeps no other app from hearing: the first error is thrown once all have. */
|
|
16
|
+
readonly deliver: (appId: string, message: HostToApp) => void;
|
|
17
|
+
/**
|
|
18
|
+
* An app's menus and dock changed: the host draws them. Checked first (`checkChrome`): a part that
|
|
19
|
+
* fails is dropped and named in `dropped`, for the host to log; chrome of the wrong shape is not
|
|
20
|
+
* passed on, and the app keeps what it last sent. Null when the app is unregistered: the host stops
|
|
21
|
+
* drawing its chrome.
|
|
22
|
+
*/
|
|
23
|
+
readonly chrome?: (appId: string, chrome: DeskChrome | null, dropped: readonly string[]) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Checks a broadcast's payload on topics the host knows: return the payload to pass on, or
|
|
26
|
+
* `undefined` to drop it. The theme is always checked as well, whatever this does.
|
|
27
|
+
*/
|
|
28
|
+
readonly check?: (topic: string, payload: unknown, from: HostedApp) => unknown;
|
|
29
|
+
/** The most a payload may take as JSON. Default 64 KiB; larger ones are dropped. */
|
|
30
|
+
readonly maxPayload?: number;
|
|
31
|
+
/** How fast each publisher may broadcast on each topic: see `RateLimits`. */
|
|
32
|
+
readonly limits?: RateLimits;
|
|
33
|
+
/** The time, for tests: `now` in milliseconds, and `later` to run something after a delay, returning a canceller. */
|
|
34
|
+
readonly clock?: {
|
|
35
|
+
readonly now: () => number;
|
|
36
|
+
readonly later: (run: () => void, ms: number) => () => void;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A token bucket: `burst` broadcasts at once, then `perSecond`. */
|
|
40
|
+
export interface Rate {
|
|
41
|
+
readonly burst: number;
|
|
42
|
+
readonly perSecond: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Per publisher and topic, a bucket of broadcasts. Over it, nothing is queued and nothing lost: the
|
|
46
|
+
* latest payload is held, replacing any held before, and goes out when the bucket allows, so every
|
|
47
|
+
* subscriber still ends on the last value. Defaults: 20 at once then 10 a second; the theme 2 then 1
|
|
48
|
+
* a second, since it changes on a person's choice; and 64 topics per publisher at once, past which a
|
|
49
|
+
* broadcast on yet another topic is refused (`'rate limited'`) unless one of them is idle and full.
|
|
50
|
+
*/
|
|
51
|
+
export interface RateLimits extends Partial<Rate> {
|
|
52
|
+
/** Rates for particular topics, by exact name. The theme keeps its own unless named here. */
|
|
53
|
+
readonly topics?: Readonly<Record<string, Partial<Rate>>>;
|
|
54
|
+
readonly maxTopics?: number;
|
|
55
|
+
}
|
|
56
|
+
/** Why a message was not acted on, or null when it was. */
|
|
57
|
+
export type Refusal = 'unknown app' | 'malformed' | 'not granted' | 'not the primary' | 'refused by check' | 'too large' | 'rate limited' | null;
|
|
58
|
+
/** The rules of a host's broadcasts, kept in one place so every transport keeps them alike. */
|
|
59
|
+
export interface BroadcastRouter {
|
|
60
|
+
/**
|
|
61
|
+
* Adds an app, or updates one. Throws for a second primary: two looks cannot both be worn. An update
|
|
62
|
+
* drops what the app had held over its rate, unsent: it was vetted under the grants and origin it replaces.
|
|
63
|
+
*/
|
|
64
|
+
register(app: HostedApp): void;
|
|
65
|
+
/** Forgets an app: its chrome (`chrome` is called with null), its subscriptions, and what it published, except its last theme. */
|
|
66
|
+
unregister(appId: string): void;
|
|
67
|
+
/** Acts on a message an app sent. The app is identified by the transport, never by the message. */
|
|
68
|
+
receive(appId: string, message: unknown): Refusal;
|
|
69
|
+
/** The primary's id, or null while none is registered. */
|
|
70
|
+
primary(): string | null;
|
|
71
|
+
/** The last broadcast `publisher` made on `topic` that went out, if it is kept. */
|
|
72
|
+
kept(publisher: string, topic: string): unknown;
|
|
73
|
+
/** How many of an app's broadcasts were held and replaced by a newer one, or refused for its rate. */
|
|
74
|
+
limited(appId: string): number;
|
|
75
|
+
}
|
|
76
|
+
/** A router for a host to put behind its transport: see `BroadcastRouter`. */
|
|
77
|
+
export declare function createBroadcastRouter(options: BroadcastRouterOptions): BroadcastRouter;
|
|
78
|
+
/** A host that lives in one page: for tests, examples, and apps that host others in-process. */
|
|
79
|
+
export interface MemoryHost {
|
|
80
|
+
readonly router: BroadcastRouter;
|
|
81
|
+
/** Registers an app and gives it a bridge to this host. */
|
|
82
|
+
connect(app: HostedApp): DeskHostBridge;
|
|
83
|
+
/** The chrome each app last sent. */
|
|
84
|
+
chrome(appId: string): DeskChrome | undefined;
|
|
85
|
+
/** Sends an app a choice from its menus, its dock or its Settings, as a host's frame would. */
|
|
86
|
+
command(appId: string, target: CommandTarget, id: string): void;
|
|
87
|
+
/** Every message an app sent and how it went, newest last. */
|
|
88
|
+
readonly log: readonly {
|
|
89
|
+
readonly appId: string;
|
|
90
|
+
readonly message: unknown;
|
|
91
|
+
readonly refusal: Refusal;
|
|
92
|
+
}[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A host in memory. Messages are copied with `structuredClone` each way, as a real boundary would,
|
|
96
|
+
* so an app that sends something that cannot cross fails here too.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createMemoryHost(options?: Pick<BroadcastRouterOptions, 'check' | 'maxPayload'>): MemoryHost;
|
|
99
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/host/router.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAA;AAczH,uCAAuC;AACvC,MAAM,WAAW,SAAS;IACxB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,yGAAyG;IACzG,QAAQ,CAAC,MAAM,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