dsh-edge 0.18.0 → 0.19.0-alpha.2

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 (118) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +8 -8
  3. package/README.zh.md +8 -8
  4. package/THIRD_PARTY_NOTICES.md +2011 -449
  5. package/dist/assets/fonts/Montserrat-OFL.txt +93 -0
  6. package/dist/assets/fonts/montserrat-light-Cvd2VjE_.woff2 +0 -0
  7. package/dist/assets/fonts/montserrat-medium-B4OyO9CN.woff2 +0 -0
  8. package/dist/assets/fonts/montserrat-regular-DYep38cA.woff2 +0 -0
  9. package/dist/assets/index-Cq6ljTv2.css +1 -0
  10. package/dist/assets/index-Dy0OhsZ5.js +127 -0
  11. package/dist/assets/langs/asciidoc-Ve4PFQV2.js +2 -0
  12. package/dist/assets/langs/bat-BkioyH1T.js +2 -0
  13. package/dist/assets/langs/bibtex-CHM0blh-.js +2 -0
  14. package/dist/assets/langs/clojure-P80f7IUj.js +2 -0
  15. package/dist/assets/langs/cmake-D1j8_8rp.js +2 -0
  16. package/dist/assets/langs/csv-fuZLfV_i.js +2 -0
  17. package/dist/assets/langs/dart-bE4Kk8sk.js +2 -0
  18. package/dist/assets/langs/diff-D97Zzqfu.js +2 -0
  19. package/dist/assets/langs/dotenv-Da5cRb03.js +2 -0
  20. package/dist/assets/langs/elixir-CvYZzuDY.js +2 -0
  21. package/dist/assets/langs/erlang-DsQrWhSR.js +2 -0
  22. package/dist/assets/langs/fish-BvzEVeQv.js +2 -0
  23. package/dist/assets/langs/fsharp-CXgrBDvD.js +2 -0
  24. package/dist/assets/langs/graphql-DujV8YkJ.js +2 -0
  25. package/dist/assets/langs/groovy-gcz8RCvz.js +2 -0
  26. package/dist/assets/langs/haskell-Df6bDoY_.js +2 -0
  27. package/dist/assets/langs/hcl-BWvSN4gD.js +2 -0
  28. package/dist/assets/langs/html-derivative-DOyKdj44.js +2 -0
  29. package/dist/assets/langs/html-fwsONPVS.js +2 -0
  30. package/dist/assets/langs/http-DcV90OkR.js +2 -0
  31. package/dist/assets/langs/javascript-DI5JR1nB.js +2 -0
  32. package/dist/assets/langs/julia-BpJ6DjL_.js +2 -0
  33. package/dist/assets/langs/latex-B4C7GdlO.js +2 -0
  34. package/dist/assets/langs/log-2UxHyX5q.js +2 -0
  35. package/dist/assets/langs/make-CHLpvVh8.js +2 -0
  36. package/dist/assets/langs/nix-CwoSXNpI.js +2 -0
  37. package/dist/assets/langs/perl-DsWkoyyU.js +2 -0
  38. package/dist/assets/langs/php-LEPfNACG.js +2 -0
  39. package/dist/assets/langs/powershell-Dpen1YoG.js +2 -0
  40. package/dist/assets/langs/proto-C7zT0LnQ.js +2 -0
  41. package/dist/assets/langs/r-Dspwwk_N.js +2 -0
  42. package/dist/assets/langs/rst-BbocfKWr.js +2 -0
  43. package/dist/assets/langs/ruby-R292Iif0.js +2 -0
  44. package/dist/assets/langs/scala-C151Ov-r.js +2 -0
  45. package/dist/assets/langs/svelte-DNMY6jOf.js +2 -0
  46. package/dist/assets/langs/system-verilog-CnnmHF94.js +2 -0
  47. package/dist/assets/langs/vb-D17OF-Vu.js +2 -0
  48. package/dist/assets/langs/verilog-BQ8w6xss.js +2 -0
  49. package/dist/assets/langs/vue-Dq2x6432.js +2 -0
  50. package/dist/favicon-dark.svg +3 -0
  51. package/dist/favicon.svg +0 -5
  52. package/dist/index.html +5 -4
  53. package/dist/manifest.webmanifest +3 -4
  54. package/dist/plugins/@deepseek-ai/dsh-api-gateway/client.js +353 -101
  55. package/dist/plugins/@deepseek-ai/dsh-api-job-controller/client.js +367 -0
  56. package/dist/plugins/@deepseek-ai/dsh-api-remotes/client.js +7223 -3584
  57. package/dist/plugins/@deepseek-ai/dsh-api-session-controller/client.js +1107 -991
  58. package/dist/plugins/@deepseek-ai/dsh-api-workspace-controller/client.js +119 -6
  59. package/dist/plugins/@deepseek-ai/dsh-api-workspace-files/client.js +41 -35
  60. package/dist/plugins/@deepseek-ai/dsh-client-connection/client.js +354 -5279
  61. package/dist/plugins/@deepseek-ai/dsh-client-file-upload/client.js +10 -23
  62. package/dist/plugins/@deepseek-ai/dsh-client-locale/client.js +234 -80
  63. package/dist/plugins/@deepseek-ai/dsh-client-modules/client.js +554 -46
  64. package/dist/plugins/@deepseek-ai/dsh-client-shortcuts/client.js +2006 -0
  65. package/dist/plugins/@deepseek-ai/dsh-client-ui-agent-preset/client.js +1090 -914
  66. package/dist/plugins/@deepseek-ai/dsh-client-ui-approval/client.js +79 -6
  67. package/dist/plugins/@deepseek-ai/dsh-client-ui-attachment/client.js +126 -155
  68. package/dist/plugins/@deepseek-ai/dsh-client-ui-chat/client.js +5776 -1593
  69. package/dist/plugins/@deepseek-ai/dsh-client-ui-commands/client.js +375 -121
  70. package/dist/plugins/@deepseek-ai/dsh-client-ui-conversation/client.js +3524 -1923
  71. package/dist/plugins/@deepseek-ai/dsh-client-ui-deliverables/client.js +1615 -258
  72. package/dist/plugins/@deepseek-ai/dsh-client-ui-directory-picker-browse/client.js +9 -9
  73. package/dist/plugins/@deepseek-ai/dsh-client-ui-goal/client.js +25 -10
  74. package/dist/plugins/@deepseek-ai/dsh-client-ui-input-trigger/client.js +169 -24
  75. package/dist/plugins/@deepseek-ai/dsh-client-ui-jobs/client.js +413 -63
  76. package/dist/plugins/@deepseek-ai/dsh-client-ui-layout/client.js +131 -14
  77. package/dist/plugins/@deepseek-ai/dsh-client-ui-message-feedback/client.js +24 -22
  78. package/dist/plugins/@deepseek-ai/dsh-client-ui-model-selection/client.js +281 -128
  79. package/dist/plugins/@deepseek-ai/dsh-client-ui-open-in-app/client.js +674 -223
  80. package/dist/plugins/@deepseek-ai/dsh-client-ui-plan/client.js +596 -18
  81. package/dist/plugins/@deepseek-ai/dsh-client-ui-reference/client.js +92 -9
  82. package/dist/plugins/@deepseek-ai/dsh-client-ui-renderer/client.js +467 -59
  83. package/dist/plugins/@deepseek-ai/dsh-client-ui-session/client.js +231 -72
  84. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings/client.js +281 -117
  85. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-general/client.js +642 -122
  86. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-models/client.js +1565 -438
  87. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/client.js +201 -75
  88. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-plugins/client.js +30 -1628
  89. package/dist/plugins/@deepseek-ai/dsh-client-ui-shortcuts/client.js +1163 -0
  90. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar/client.js +165 -39
  91. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-browser/client.js +1648 -0
  92. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-documentpreview/client.js +5515 -25622
  93. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-files/client.js +419 -118
  94. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-right/client.js +5692 -260
  95. package/dist/plugins/@deepseek-ai/dsh-client-ui-skill/client.js +156 -41
  96. package/dist/plugins/@deepseek-ai/dsh-client-ui-subagent/client.js +386 -263
  97. package/dist/plugins/@deepseek-ai/dsh-client-ui-theme/client.js +183 -73
  98. package/dist/plugins/@deepseek-ai/dsh-client-ui-tool/client.js +2367 -429
  99. package/dist/plugins/@deepseek-ai/dsh-client-ui-trajectory/client.js +788 -270
  100. package/dist/plugins/@deepseek-ai/dsh-client-ui-user-questions/client.js +87 -79
  101. package/dist/plugins/@deepseek-ai/dsh-client-ui-workflow-run/client.js +28 -14
  102. package/dist/plugins/@deepseek-ai/dsh-client-ui-workspace/client.js +2647 -1044
  103. package/dist/plugins/@deepseek-ai/dsh-typert-registry/client.js +22 -7
  104. package/dist/plugins/dsh-edge-client-ui/client.js +1 -10
  105. package/package.json +96 -86
  106. package/scripts/cli.mjs +16 -4
  107. package/scripts/install.d.mts +12 -2
  108. package/scripts/install.mjs +36 -9
  109. package/scripts/legal-files.mjs +15 -0
  110. package/worker/direct/index.js +2564 -1822
  111. package/worker/isolated/index.js +2144 -1402
  112. package/dist/assets/index-BKQ_L1z6.js +0 -117
  113. package/dist/assets/index-DPX2bQLO.css +0 -1
  114. package/dist/assets/langs/html-CfGypltT.js +0 -2
  115. package/dist/assets/langs/php-DJl5gRdb.js +0 -2
  116. package/dist/assets/langs/ruby-5eNB0pDK.js +0 -2
  117. package/dist/plugins/@deepseek-ai/dsh-client-ui-permission-presets/client.js +0 -505
  118. package/dist/plugins/@deepseek-ai/dsh-client-ui-schedule/client.js +0 -307
@@ -0,0 +1,2006 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@deepseek-ai/dsh-client-shortcuts",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ module.exports;
6
+ let _deepseek_ai_cordis = require("@deepseek-ai/cordis");
7
+ let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
8
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
+ //#region lib/types/binding.js
10
+ const keyNames = {
11
+ Slash: "/",
12
+ Comma: ",",
13
+ Period: ".",
14
+ Backslash: "\\",
15
+ Backquote: "`",
16
+ Minus: "-",
17
+ Equal: "=",
18
+ BracketLeft: "[",
19
+ BracketRight: "]",
20
+ Semicolon: ";",
21
+ Quote: "'",
22
+ Enter: "Enter",
23
+ Escape: "Esc",
24
+ Space: "Space",
25
+ Tab: "Tab",
26
+ Backspace: "Backspace",
27
+ Delete: "Delete",
28
+ ArrowUp: "↑",
29
+ ArrowDown: "↓",
30
+ ArrowLeft: "←",
31
+ ArrowRight: "→"
32
+ };
33
+ const modifierOrder = [
34
+ "control",
35
+ "alt",
36
+ "shift",
37
+ "meta"
38
+ ];
39
+ /**
40
+ * Expand logical modifiers, deduplicate, and validate the physical code.
41
+ * @param binding - declared binding.
42
+ * @param platform - receiving device platform.
43
+ * @returns canonical binding; unsupported codes throw during registration.
44
+ */
45
+ function normalizeBinding(binding, platform) {
46
+ const codes = [binding.code, ...binding.secondCode === void 0 ? [] : [binding.secondCode]];
47
+ codes.sort();
48
+ for (const code of codes) if (!/^(Key[A-Z]|Digit[0-9]|F([1-9]|1[0-9]|2[0-4]))$/u.test(code) && !Object.hasOwn(keyNames, code)) throw new Error(`Unsupported shortcut code: ${code}`);
49
+ if (codes.length === 2 && codes[0] === codes[1]) throw new Error("Shortcut keys must be distinct");
50
+ const modifiers = new Set(binding.modifiers.map((value) => value === "primary" ? platform === "macos" ? "meta" : "control" : value));
51
+ return {
52
+ code: codes[0],
53
+ ...codes[1] === void 0 ? {} : { secondCode: codes[1] },
54
+ modifiers: modifierOrder.filter((value) => modifiers.has(value))
55
+ };
56
+ }
57
+ /**
58
+ * Produce an exact-match index from a normalized binding.
59
+ * @param binding - normalized physical key and modifiers.
60
+ * @returns stable index used for both matching and conflict checks.
61
+ */
62
+ function bindingKey(binding) {
63
+ const codes = binding.secondCode === void 0 ? [binding.code] : [binding.code, binding.secondCode].sort();
64
+ return [...binding.modifiers, ...codes].join("+");
65
+ }
66
+ /**
67
+ * Format keycaps and ARIA; Windows separates modifiers with plus signs, while chord keys remain adjacent.
68
+ * @param binding - normalized binding, or null for an unbound command.
69
+ * @param platform - receiving device platform.
70
+ * @returns visible keycaps; two-key chords omit ARIA shortcuts, which only support one non-modifier key.
71
+ */
72
+ function presentBinding(binding, platform) {
73
+ if (binding === null) return {
74
+ keys: [],
75
+ aria: void 0
76
+ };
77
+ const key = keyNames[binding.code] ?? binding.code.replace(/^(Key|Digit)/u, "");
78
+ const symbols = platform === "macos" ? {
79
+ control: "⌃",
80
+ alt: "⌥",
81
+ shift: "⇧",
82
+ meta: "⌘"
83
+ } : {
84
+ control: "Ctrl",
85
+ alt: "Alt",
86
+ shift: "Shift",
87
+ meta: "Meta"
88
+ };
89
+ const ariaNames = {
90
+ control: "Control",
91
+ alt: "Alt",
92
+ shift: "Shift",
93
+ meta: "Meta"
94
+ };
95
+ const ariaKey = binding.code === "Space" ? "Space" : binding.code === "Escape" ? "Escape" : binding.code.startsWith("Arrow") ? binding.code : key;
96
+ const second = binding.secondCode === void 0 ? [] : [keyNames[binding.secondCode] ?? binding.secondCode.replace(/^(Key|Digit)/u, "")];
97
+ const keys = [...binding.modifiers.map((value) => symbols[value]), key];
98
+ return {
99
+ keys: [...platform === "windows" ? keys.flatMap((label, index) => index === 0 ? [label] : ["+", label]) : keys, ...second],
100
+ aria: binding.secondCode === void 0 ? [...binding.modifiers.map((value) => ariaNames[value]), ariaKey].join("+") : void 0
101
+ };
102
+ }
103
+ /**
104
+ * Check Web combinations: Windows and macOS also admit any three or four modifiers; Linux retains the limited set.
105
+ * @param binding - normalized candidate.
106
+ * @param platform - receiving device platform.
107
+ * @returns whether this combination is admitted; admission does not guarantee browser or system delivery.
108
+ */
109
+ function isWebBindingAllowed(binding, platform) {
110
+ if (binding.secondCode !== void 0) return false;
111
+ if (platform === "windows" || platform === "macos") {
112
+ if (binding.modifiers.length >= 3) return true;
113
+ const primary = platform === "macos" ? "meta" : "control";
114
+ if (binding.modifiers.length === 1 && (["Comma", "Backslash"].includes(binding.code) && binding.modifiers[0] === primary || binding.code === "Backquote" && binding.modifiers[0] === "control")) return true;
115
+ if (binding.modifiers.length === 2 && binding.modifiers.includes(primary) && (binding.modifiers.includes("alt") || binding.modifiers.includes("shift"))) return true;
116
+ }
117
+ return [
118
+ {
119
+ code: "Slash",
120
+ modifiers: ["primary"]
121
+ },
122
+ {
123
+ code: "Comma",
124
+ modifiers: ["primary", "shift"]
125
+ },
126
+ {
127
+ code: "Period",
128
+ modifiers: ["primary", "shift"]
129
+ }
130
+ ].some((candidate) => bindingKey(binding) === bindingKey(normalizeBinding(candidate, platform)));
131
+ }
132
+ //#endregion
133
+ //#region ../../util/values/lib/index.js
134
+ /** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
135
+ /**
136
+ * Mark an unreachable closed-union branch.
137
+ * @param value - impossible value; an unhandled typed variant fails at the call site.
138
+ * @param context - optional switch-site label included in the failure message.
139
+ * @returns never; a runtime value that escaped its type always throws.
140
+ */
141
+ function assertNever(value, context) {
142
+ const rendered = JSON.stringify(value) ?? String(value);
143
+ throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
144
+ }
145
+ //#endregion
146
+ //#region lib/types/configuration.js
147
+ /** Validated preference documents and deterministic conflict resolution, without browser dependencies. */
148
+ const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
149
+ const commandPattern = /^[a-z][a-zA-Z0-9-]*(?:\.[a-zA-Z][a-zA-Z0-9-]*)+$/u;
150
+ /**
151
+ * Validate JSON binding fields before normalization; unknown fields are rejected to prevent lossy rewrites.
152
+ * @param value - file or IPC input.
153
+ * @returns a binding with a supported physical code, or null for explicit removal.
154
+ */
155
+ function parseBinding(value) {
156
+ if (value === null) return null;
157
+ if (!record(value) || Object.keys(value).some((key) => key !== "code" && key !== "secondCode" && key !== "modifiers") || typeof value.code !== "string" || !Array.isArray(value.modifiers) || Object.hasOwn(value, "secondCode") && typeof value.secondCode !== "string" || !value.modifiers.every((modifier) => typeof modifier === "string" && [
158
+ "primary",
159
+ "control",
160
+ "alt",
161
+ "shift",
162
+ "meta"
163
+ ].includes(modifier))) throw new Error("Invalid shortcut binding");
164
+ const binding = {
165
+ code: value.code,
166
+ modifiers: value.modifiers,
167
+ ...typeof value.secondCode === "string" ? { secondCode: value.secondCode } : {}
168
+ };
169
+ normalizeBinding(binding, "windows");
170
+ return binding;
171
+ }
172
+ /**
173
+ * Decode the complete document while preserving dormant command overrides.
174
+ * @param raw - stored JSON, or null for a missing document.
175
+ * @returns the accepted document or a classified read failure.
176
+ */
177
+ function parseShortcutDocument(raw) {
178
+ if (raw === null) return {
179
+ schemaVersion: 1,
180
+ profiles: {}
181
+ };
182
+ try {
183
+ const value = JSON.parse(raw);
184
+ if (!record(value)) return "invalid";
185
+ if (typeof value.schemaVersion === "number" && value.schemaVersion > 2) return "future";
186
+ if (value.schemaVersion !== 1 && value.schemaVersion !== 2 || !record(value.profiles) || Object.keys(value).some((key) => key !== "schemaVersion" && key !== "profiles")) return "invalid";
187
+ const profiles = {};
188
+ for (const [profile, overrides] of Object.entries(value.profiles)) {
189
+ if (!/^(desktop|web):(macos|windows|linux)$/u.test(profile) || !record(overrides)) return "invalid";
190
+ const bindings = {};
191
+ for (const [id, binding] of Object.entries(overrides)) {
192
+ if (!commandPattern.test(id)) return "invalid";
193
+ const parsed = parseBinding(binding);
194
+ if (value.schemaVersion === 1 && parsed?.secondCode !== void 0) return "invalid";
195
+ bindings[id] = parsed;
196
+ }
197
+ profiles[profile] = bindings;
198
+ }
199
+ return {
200
+ schemaVersion: value.schemaVersion,
201
+ profiles
202
+ };
203
+ } catch (_error) {
204
+ return "invalid";
205
+ }
206
+ }
207
+ /**
208
+ * Check system, editor, and browser reservations using expanded physical modifiers.
209
+ * @param binding - normalized candidate.
210
+ * @param runtime - receiving application shell.
211
+ * @param platform - receiving device.
212
+ * @returns the rejection reason, or null when this combination is allowed.
213
+ */
214
+ function bindingIssue(binding, runtime, platform) {
215
+ const { code, modifiers } = binding;
216
+ if (runtime === "desktop" && (platform === "windows" || platform === "macos")) return null;
217
+ if (binding.secondCode !== void 0) return "unsupported-key";
218
+ if (modifiers.length === 0 || modifiers.every((modifier) => modifier === "shift")) return "modifier-required";
219
+ if ((platform === "windows" || platform === "macos") && modifiers.length >= 3) return null;
220
+ if (runtime === "web" && (platform === "windows" || platform === "macos") && isWebBindingAllowed(binding, platform)) return null;
221
+ const primary = modifiers.includes(platform === "macos" ? "meta" : "control");
222
+ if ([
223
+ "Escape",
224
+ "Tab",
225
+ "Space",
226
+ "Backspace",
227
+ "Delete",
228
+ "ArrowUp",
229
+ "ArrowDown",
230
+ "ArrowLeft",
231
+ "ArrowRight"
232
+ ].includes(code) || code === "Enter" && !modifiers.includes("alt") || primary && [
233
+ "KeyC",
234
+ "KeyV",
235
+ "KeyX",
236
+ "KeyZ",
237
+ "KeyY",
238
+ "KeyQ",
239
+ "KeyH"
240
+ ].includes(code) || primary && code === "KeyA" && !modifiers.includes("shift") || platform !== "macos" && (modifiers.includes("meta") || modifiers.includes("alt") && ["F4", "F2"].includes(code)) || platform === "macos" && modifiers.includes("control") && modifiers.includes("meta") || platform === "macos" && modifiers.includes("alt") && !primary) return "reserved";
241
+ if (runtime === "web" && !isWebBindingAllowed(binding, platform)) return "unsupported-browser";
242
+ return null;
243
+ }
244
+ /**
245
+ * Select the command owner's explicit default for one device profile.
246
+ * @param definition - command identity and per-profile defaults.
247
+ * @param runtime - receiving shell.
248
+ * @param platform - receiving device.
249
+ * @returns the declared physical binding, or undefined for an unbound action.
250
+ */
251
+ function resolveShortcutDefault(definition, runtime, platform) {
252
+ return definition.defaults[`${runtime}:${platform}`];
253
+ }
254
+ /**
255
+ * Resolve overrides and conflicts independently of registration order. Explicit overrides displace defaults.
256
+ * @param definitions - active commands.
257
+ * @param document - accepted preferences.
258
+ * @param runtime - receiving shell.
259
+ * @param platform - receiving device.
260
+ * @returns every active command, including unavailable conflicting bindings.
261
+ */
262
+ function effectiveShortcuts(definitions, document, runtime, platform) {
263
+ const overrides = document.profiles[`${runtime}:${platform}`] ?? {};
264
+ const fixed = definitions.flatMap((row) => row.fixed?.map((binding) => ({
265
+ id: row.id,
266
+ binding: normalizeBinding(binding, platform)
267
+ })) ?? []);
268
+ const rows = definitions.filter((row) => row.fixed === void 0).map(({ id, defaults }) => {
269
+ const modified = Object.hasOwn(overrides, id);
270
+ const candidate = modified ? overrides[id] : resolveShortcutDefault({
271
+ id,
272
+ defaults
273
+ }, runtime, platform);
274
+ const binding = candidate == null ? null : normalizeBinding(candidate, platform);
275
+ return {
276
+ id,
277
+ binding,
278
+ modified,
279
+ issue: binding === null ? null : bindingIssue(binding, runtime, platform)
280
+ };
281
+ });
282
+ return rows.map((row) => {
283
+ const binding = row.binding;
284
+ return {
285
+ ...row,
286
+ conflicts: binding === null ? [] : [...new Set([...rows.filter((other) => other.id !== row.id && other.binding !== null && other.issue === null && overlappingBindings(other.binding, binding) && (!row.modified || other.modified)).map((other) => other.id), ...fixed.filter((other) => overlappingBindings(other.binding, binding)).map((other) => other.id)])]
287
+ };
288
+ });
289
+ }
290
+ /**
291
+ * Detect identical combinations or a single key contained in a two-key chord.
292
+ * @param left - normalized candidate.
293
+ * @param right - normalized occupied binding.
294
+ * @returns whether both bindings require the same modifiers and overlap.
295
+ */
296
+ function overlappingBindings(left, right) {
297
+ if (left.modifiers.join("+") !== right.modifiers.join("+")) return false;
298
+ if (left.secondCode !== void 0 && right.secondCode !== void 0) return bindingKey(left) === bindingKey(right);
299
+ return [left.code, left.secondCode].some((code) => code !== void 0 && (code === right.code || code === right.secondCode));
300
+ }
301
+ /**
302
+ * Apply an edit without modifying other profiles or dormant overrides.
303
+ * @param document - accepted document.
304
+ * @param edit - validated operation.
305
+ * @param runtime - current shell.
306
+ * @param platform - current device.
307
+ * @returns the candidate document, pending conflict checks and durable storage.
308
+ */
309
+ function editShortcutDocument(document, edit, runtime, platform) {
310
+ const schemaVersion = runtime === "desktop" && (platform === "macos" || platform === "windows") ? 2 : document.schemaVersion;
311
+ const profile = `${runtime}:${platform}`;
312
+ let overrides = { ...document.profiles[profile] };
313
+ switch (edit.type) {
314
+ case "set":
315
+ overrides[edit.id] = edit.binding;
316
+ break;
317
+ case "reset": {
318
+ const { [edit.id]: _removed, ...remaining } = overrides;
319
+ overrides = remaining;
320
+ break;
321
+ }
322
+ case "reset-all":
323
+ overrides = {};
324
+ break;
325
+ /* v8 ignore next -- parseShortcutEdit validates this closed union before persistence. */
326
+ default: return assertNever(edit, "shortcut edit");
327
+ }
328
+ return {
329
+ schemaVersion,
330
+ profiles: {
331
+ ...document.profiles,
332
+ [profile]: overrides
333
+ }
334
+ };
335
+ }
336
+ //#endregion
337
+ //#region ../../util/crypto/lib/index.js
338
+ /**
339
+ * Random v4 UUID, minted from `crypto.getRandomValues`.
340
+ * @returns the UUID string.
341
+ */
342
+ function randomUUID() {
343
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
344
+ const hex = Array.from(bytes, (byte, index) => {
345
+ return (index === 6 ? byte & 15 | 64 : index === 8 ? byte & 63 | 128 : byte).toString(16).padStart(2, "0");
346
+ }).join("");
347
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
348
+ }
349
+ //#endregion
350
+ //#region lib/types/persistence.js
351
+ /** Serialized preference transactions; storage owners publish only accepted writes or read diagnostics. */
352
+ /**
353
+ * Create a disabled initial snapshot for asynchronous adapter startup.
354
+ * @returns a fresh configuration with no accepted persisted state.
355
+ */
356
+ function initialShortcutConfig() {
357
+ return {
358
+ revision: randomUUID(),
359
+ sequence: 0,
360
+ document: {
361
+ schemaVersion: 1,
362
+ profiles: {}
363
+ },
364
+ status: "loading",
365
+ error: null,
366
+ usingDefaults: true
367
+ };
368
+ }
369
+ /** Single-writer coordinator shared by localStorage and Electron's atomic file adapter. */
370
+ var ShortcutPersistence = class {
371
+ storage;
372
+ runtime;
373
+ platform;
374
+ rereadBeforeWrite;
375
+ publish;
376
+ snapshot = initialShortcutConfig();
377
+ raw;
378
+ queue = Promise.resolve();
379
+ definitions = null;
380
+ active = true;
381
+ constructor(storage, runtime, platform, rereadBeforeWrite, publish) {
382
+ this.storage = storage;
383
+ this.runtime = runtime;
384
+ this.platform = platform;
385
+ this.rereadBeforeWrite = rereadBeforeWrite;
386
+ this.publish = publish;
387
+ }
388
+ /**
389
+ * Install or revoke a product catalog and invalidate drafts from its previous lifetime.
390
+ * @param definitions - current trusted definitions, or null while the product is not ready.
391
+ */
392
+ setDefinitions(definitions) {
393
+ this.definitions = definitions;
394
+ this.accept({ ...this.snapshot });
395
+ }
396
+ /** Stop accepting edits or publishing late completions. */
397
+ dispose() {
398
+ this.active = false;
399
+ }
400
+ /**
401
+ * Read the current file; failures retain the last accepted document and disable ordinary writes.
402
+ * @returns the accepted snapshot or diagnostic snapshot.
403
+ */
404
+ readCurrent() {
405
+ return this.serialize(() => this.read());
406
+ }
407
+ /**
408
+ * Compare the draft revision, validate the complete candidate, then persist before publishing.
409
+ * @param edit - constrained preference operation.
410
+ * @param revision - state against which the user reviewed the edit.
411
+ * @returns a classified outcome and the currently accepted snapshot.
412
+ */
413
+ edit(edit, revision) {
414
+ return this.serialize(async () => {
415
+ if (this.rereadBeforeWrite) await this.read();
416
+ const result = (status) => ({
417
+ status,
418
+ snapshot: this.snapshot
419
+ });
420
+ if (!this.active || this.definitions === null || this.snapshot.status === "loading") return result("not-ready");
421
+ if (revision !== this.snapshot.revision) return result("stale");
422
+ if (this.snapshot.status === "unreadable") return result("unreadable");
423
+ if ((edit.type === "set" || edit.type === "reset") && !this.definitions.some((row) => row.id === edit.id && row.fixed === void 0)) return result("not-ready");
424
+ const document = editShortcutDocument(this.snapshot.document, edit, this.runtime, this.platform);
425
+ const rows = effectiveShortcuts(this.definitions, document, this.runtime, this.platform);
426
+ const invalid = rows.find((row) => (edit.type === "reset-all" || row.id === edit.id) && (row.issue !== null || row.conflicts.length > 0));
427
+ const displaced = edit.type === "set" ? rows.find((row) => row.conflicts.includes(edit.id)) : void 0;
428
+ if (invalid !== void 0 || displaced !== void 0) return {
429
+ ...result("conflict"),
430
+ ...invalid?.issue ? { issue: invalid.issue } : {},
431
+ conflicts: invalid?.conflicts.length ? invalid.conflicts : displaced === void 0 ? [] : [displaced.id]
432
+ };
433
+ try {
434
+ const raw = `${JSON.stringify(document, null, 2)}\n`;
435
+ await this.storage.write(raw);
436
+ this.raw = raw;
437
+ this.accept({
438
+ ...this.snapshot,
439
+ document,
440
+ status: "ready",
441
+ error: null,
442
+ usingDefaults: false
443
+ });
444
+ return result("saved");
445
+ } catch (_error) {
446
+ return result("write-failed");
447
+ }
448
+ });
449
+ }
450
+ serialize(operation) {
451
+ const next = this.queue.then(operation);
452
+ this.queue = next.catch(() => void 0);
453
+ return next;
454
+ }
455
+ accept(snapshot) {
456
+ this.snapshot = {
457
+ ...snapshot,
458
+ sequence: this.snapshot.sequence + 1,
459
+ revision: randomUUID()
460
+ };
461
+ if (!this.active) return;
462
+ try {
463
+ this.publish(this.snapshot);
464
+ } catch (error) {
465
+ console.error("Shortcut configuration subscriber failed:", error);
466
+ }
467
+ }
468
+ async read() {
469
+ let raw;
470
+ try {
471
+ raw = await this.storage.read();
472
+ } catch (_error) {
473
+ if (this.snapshot.error !== "read") this.accept({
474
+ ...this.snapshot,
475
+ status: "unreadable",
476
+ error: "read"
477
+ });
478
+ return this.snapshot;
479
+ }
480
+ if (raw === this.raw && this.snapshot.error !== "read") return this.snapshot;
481
+ this.raw = raw;
482
+ const document = parseShortcutDocument(raw);
483
+ if (typeof document === "string") this.accept({
484
+ ...this.snapshot,
485
+ status: "unreadable",
486
+ error: document
487
+ });
488
+ else this.accept({
489
+ ...this.snapshot,
490
+ document,
491
+ status: "ready",
492
+ error: null,
493
+ usingDefaults: raw === null
494
+ });
495
+ return this.snapshot;
496
+ }
497
+ };
498
+ //#endregion
499
+ //#region lib/types/client/registry.js
500
+ /** Command registration, normalized default bindings, and synchronous dispatch. */
501
+ /** Application command registry; adapters own event listeners, feature plugins own actions. */
502
+ var ShortcutRegistry = class {
503
+ runtime;
504
+ platform;
505
+ commands = /* @__PURE__ */ new Map();
506
+ fixedCommands = /* @__PURE__ */ new Map();
507
+ conflicts = /* @__PURE__ */ new Map();
508
+ bindings = /* @__PURE__ */ new Map();
509
+ state;
510
+ /** Effective localized rows derived from the accepted configuration. */
511
+ catalog;
512
+ /** Accepted preferences and visible read diagnostics. */
513
+ config;
514
+ /** Fixed local operations whose owning plugins are mounted. */
515
+ fixedCatalog = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)([]);
516
+ constructor(runtime, platform, config = {
517
+ ...initialShortcutConfig(),
518
+ status: "ready"
519
+ }) {
520
+ this.runtime = runtime;
521
+ this.platform = platform;
522
+ this.state = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
523
+ catalog: [],
524
+ config
525
+ });
526
+ this.catalog = {
527
+ getSnapshot: () => this.state.getSnapshot().catalog,
528
+ subscribe: (listener) => this.state.subscribe(listener)
529
+ };
530
+ this.config = {
531
+ getSnapshot: () => this.state.getSnapshot().config,
532
+ subscribe: (listener) => this.state.subscribe(listener)
533
+ };
534
+ }
535
+ /**
536
+ * Return the serializable active catalog for storage validation.
537
+ * @returns definitions without callbacks or localized labels.
538
+ */
539
+ definitions() {
540
+ return [...[...this.commands.values()].map(({ id, defaults }) => ({
541
+ id,
542
+ defaults
543
+ })), ...[...this.fixedCommands.values()].map(({ id, bindings }) => ({
544
+ id,
545
+ defaults: {},
546
+ fixed: bindings
547
+ }))];
548
+ }
549
+ /**
550
+ * Register a read-only input action whose keys cannot be assigned to editable commands.
551
+ * @param command - owner-localized action and readable sequence.
552
+ * @returns idempotent disposer removing its reference row.
553
+ */
554
+ registerFixed(command) {
555
+ if (this.fixedCommands.has(command.id) || this.commands.has(command.id)) throw new Error(`Duplicate shortcut command: ${command.id}`);
556
+ for (const binding of command.bindings) normalizeBinding(binding, this.platform);
557
+ this.fixedCommands.set(command.id, command);
558
+ this.refreshLabels();
559
+ return () => {
560
+ if (this.fixedCommands.get(command.id) !== command) return;
561
+ this.fixedCommands.delete(command.id);
562
+ this.refreshLabels();
563
+ };
564
+ }
565
+ refreshFixedLabels() {
566
+ this.fixedCatalog.set([...this.fixedCommands.values()].map((command) => ({
567
+ id: command.id,
568
+ label: command.label(),
569
+ keys: command.keys,
570
+ group: command.group,
571
+ bindings: command.bindings.map((binding) => normalizeBinding(binding, this.platform))
572
+ })));
573
+ }
574
+ /**
575
+ * Publish accepted preferences and all derived labels atomically.
576
+ * @param config - storage owner's latest accepted snapshot.
577
+ */
578
+ configure(config) {
579
+ const current = this.config.getSnapshot();
580
+ if (config.revision === current.revision && config.status === current.status && config.error === current.error) return;
581
+ this.refreshLabels(config);
582
+ }
583
+ /**
584
+ * Register atomically after checking defaults for all supported platforms and shells.
585
+ * @param command - feature-owned command definition.
586
+ * @returns idempotent disposer removing both matching and catalog entries.
587
+ */
588
+ register(command) {
589
+ if (this.commands.has(command.id) || this.fixedCommands.has(command.id)) throw new Error(`Duplicate shortcut command: ${command.id}`);
590
+ for (const runtime of ["desktop", "web"]) for (const platform of [
591
+ "macos",
592
+ "windows",
593
+ "linux"
594
+ ]) {
595
+ const candidate = resolveShortcutDefault(command, runtime, platform);
596
+ if (candidate === void 0) continue;
597
+ const binding = normalizeBinding(candidate, platform);
598
+ if (runtime === "web" && !isWebBindingAllowed(binding, platform)) throw new Error(`Unsupported Web shortcut: ${command.id}`);
599
+ if (bindingIssue(binding, runtime, platform) !== null) throw new Error(`Reserved shortcut default: ${command.id}`);
600
+ for (const existing of this.commands.values()) {
601
+ const other = resolveShortcutDefault(existing, runtime, platform);
602
+ if (other !== void 0 && overlappingBindings(binding, normalizeBinding(other, platform))) throw new Error(`Conflicting shortcut defaults: ${command.id} and ${existing.id} (${runtime}:${platform})`);
603
+ }
604
+ }
605
+ this.commands.set(command.id, command);
606
+ this.refreshLabels();
607
+ return () => {
608
+ if (this.commands.get(command.id) !== command) return;
609
+ this.commands.delete(command.id);
610
+ this.refreshLabels();
611
+ };
612
+ }
613
+ /**
614
+ * Recompute effective bindings when preferences, commands, or locale change.
615
+ * @param config - accepted configuration, defaulting to the current snapshot.
616
+ */
617
+ refreshLabels(config = this.config.getSnapshot()) {
618
+ this.bindings.clear();
619
+ this.conflicts.clear();
620
+ const catalog = effectiveShortcuts(this.definitions(), config.document, this.runtime, this.platform).map((row) => {
621
+ const command = this.commands.get(row.id);
622
+ const enabled = config.status !== "loading" && row.issue === null && row.conflicts.length === 0;
623
+ if (enabled && row.binding !== null) this.bindings.set(bindingKey(row.binding), command);
624
+ if (config.status !== "loading" && row.issue === null && row.conflicts.length > 0 && row.binding !== null) this.conflicts.set(bindingKey(row.binding), command);
625
+ return {
626
+ ...row,
627
+ label: command.label(),
628
+ aliases: command.aliases,
629
+ ...presentBinding(row.binding, this.platform),
630
+ aria: enabled ? presentBinding(row.binding, this.platform).aria : void 0
631
+ };
632
+ });
633
+ this.state.set({
634
+ config,
635
+ catalog
636
+ });
637
+ this.refreshFixedLabels();
638
+ }
639
+ /**
640
+ * Invoke a native menu selection independently of its optional key binding.
641
+ * @param id - registered product command.
642
+ * @param context - live input owner and modal state.
643
+ */
644
+ invoke(id, context) {
645
+ const command = this.commands.get(id);
646
+ if (command === void 0 || context.modal !== null && !command.modals.includes(context.modal)) return;
647
+ const result = command.resolve({
648
+ ...context,
649
+ source: "menu"
650
+ });
651
+ if (result.status === "handled") result.run();
652
+ }
653
+ /**
654
+ * Windows/macOS Desktop bindings override local regions and modal controls independently of their configuration source.
655
+ * @param gesture - normalized DOM/native input facts.
656
+ * @param context - synchronous input and modal owner.
657
+ * @param consume - adapter's preventDefault, called before business execution.
658
+ * @returns handled, blocked with a reason, or pass for local/system input.
659
+ */
660
+ dispatch(gesture, context, consume) {
661
+ if (gesture.defaultPrevented || gesture.composing) return { status: "pass" };
662
+ const modifiers = [
663
+ "control",
664
+ "alt",
665
+ "shift",
666
+ "meta"
667
+ ].filter((value) => gesture[value]);
668
+ const pairKey = bindingKey({
669
+ code: gesture.code,
670
+ modifiers,
671
+ ...gesture.secondCode === void 0 ? {} : { secondCode: gesture.secondCode }
672
+ });
673
+ const key = this.bindings.has(pairKey) || this.conflicts.has(pairKey) ? pairKey : bindingKey({
674
+ code: gesture.code,
675
+ modifiers
676
+ });
677
+ const command = this.bindings.get(key) ?? this.conflicts.get(key);
678
+ const priority = this.runtime === "desktop" && (this.platform === "windows" || this.platform === "macos");
679
+ if (command === void 0 || !priority && !command.regions.includes(context.region)) return { status: "pass" };
680
+ if (!priority && context.region === "terminal" && gesture.control && !gesture.meta && !gesture.alt && !gesture.shift && (gesture.code === "KeyW" || gesture.code === "KeyR")) return { status: "pass" };
681
+ if (!this.bindings.has(key)) {
682
+ consume();
683
+ return {
684
+ status: "blocked",
685
+ commandId: command.id,
686
+ reason: "conflict"
687
+ };
688
+ }
689
+ if (!priority && context.modal !== null && !command.modals.includes(context.modal)) {
690
+ consume();
691
+ return {
692
+ status: "blocked",
693
+ commandId: command.id,
694
+ reason: "modal"
695
+ };
696
+ }
697
+ const resolution = command.resolve(context);
698
+ if (resolution.status === "pass") return resolution;
699
+ consume();
700
+ if (resolution.status === "blocked") return {
701
+ ...resolution,
702
+ commandId: command.id
703
+ };
704
+ if (!gesture.repeat) resolution.run();
705
+ return {
706
+ status: "handled",
707
+ commandId: command.id
708
+ };
709
+ }
710
+ };
711
+ //#endregion
712
+ //#region lib/types/client/dom.js
713
+ /** Main-document keyboard adapter; local controls arbitrate before window bubbling. */
714
+ /**
715
+ * Detect the visiting device, never the server operating system.
716
+ * @param document - product document, marked by Electron preload when present.
717
+ * @param navigator - browser device identification.
718
+ * @returns explicit runtime and platform for default resolution.
719
+ */
720
+ function detectEnvironment(document, navigator) {
721
+ const desktop = document.documentElement.dataset.platform;
722
+ const device = desktop ?? navigator.platform;
723
+ return {
724
+ runtime: desktop === void 0 ? "web" : "desktop",
725
+ platform: /darwin|mac|iphone|ipad/iu.test(device) ? "macos" : /win/iu.test(device) ? "windows" : "linux"
726
+ };
727
+ }
728
+ /**
729
+ * Install document composition tracking and application dispatch after local handlers.
730
+ * @param window - input window owned by the client plugin.
731
+ * @param shortcuts - command registry for this window.
732
+ * @param fixed - optional fixed-sequence consumer after local controls.
733
+ * @param native - native input owns configurable bindings; DOM delivery only feeds fixed actions.
734
+ * @returns disposer releasing every listener.
735
+ */
736
+ function installKeyboard(window, shortcuts, fixed, native = false) {
737
+ const document = window.document;
738
+ const composition = (0, _deepseek_ai_dsh_client_ui_primitives.observeComposition)(document);
739
+ let pending = false;
740
+ let pendingTimer;
741
+ const reset = () => {
742
+ fixed?.({ type: "reset" });
743
+ };
744
+ let deadKey = false;
745
+ const blur = () => {
746
+ deadKey = false;
747
+ reset();
748
+ };
749
+ const containsModal = (node) => node instanceof Element && (node.matches(_deepseek_ai_dsh_client_ui_primitives.modalSelector) || node.querySelector(_deepseek_ai_dsh_client_ui_primitives.modalSelector) !== null);
750
+ const changedModals = (records) => {
751
+ if (records.some((record) => record.type === "attributes" ? record.oldValue === "dialog" || record.oldValue === "true" || containsModal(record.target) : [...record.addedNodes, ...record.removedNodes].some(containsModal))) reset();
752
+ };
753
+ const observer = fixed === void 0 ? void 0 : new MutationObserver(changedModals);
754
+ observer?.observe(document.documentElement, {
755
+ childList: true,
756
+ subtree: true,
757
+ attributes: true,
758
+ attributeFilter: ["role", "aria-modal"],
759
+ attributeOldValue: true
760
+ });
761
+ const capture = () => {
762
+ if (pending) reset();
763
+ window.clearTimeout(pendingTimer);
764
+ if (observer !== void 0) changedModals(observer.takeRecords());
765
+ pending = true;
766
+ pendingTimer = window.setTimeout(() => {
767
+ pending = false;
768
+ pendingTimer = void 0;
769
+ reset();
770
+ }, 0);
771
+ };
772
+ const keydown = (event) => {
773
+ window.clearTimeout(pendingTimer);
774
+ pendingTimer = void 0;
775
+ pending = false;
776
+ const target = event.composedPath().find((value) => value instanceof Element);
777
+ const element = target instanceof Element ? target : document.activeElement;
778
+ const region = element?.closest(".xterm") ? "terminal" : element?.closest("input, textarea, select, [contenteditable=\"true\"], [contenteditable=\"\"]") ? "editable" : "page";
779
+ const top = [...document.querySelectorAll(_deepseek_ai_dsh_client_ui_primitives.modalSelector)].at(-1);
780
+ const context = {
781
+ region,
782
+ modal: top === void 0 ? null : top.dataset.shortcutModal ?? "other",
783
+ target: element
784
+ };
785
+ const guarded = composition.guards(event) || deadKey || event.getModifierState("AltGraph");
786
+ const isDead = event.key === "Dead";
787
+ const commandDeadKey = isDead && shortcuts.runtime === "web" && shortcuts.platform === "macos" && event.code === "KeyN" && event.metaKey && event.altKey && !event.ctrlKey && !event.shiftKey;
788
+ deadKey = isDead;
789
+ const gesture = {
790
+ code: event.code,
791
+ control: event.ctrlKey,
792
+ alt: event.altKey,
793
+ shift: event.shiftKey,
794
+ meta: event.metaKey,
795
+ repeat: event.repeat,
796
+ composing: guarded || isDead,
797
+ defaultPrevented: event.defaultPrevented
798
+ };
799
+ const consume = () => {
800
+ event.preventDefault();
801
+ if (commandDeadKey) deadKey = false;
802
+ };
803
+ fixed?.({
804
+ type: "keydown",
805
+ gesture,
806
+ context,
807
+ consume
808
+ });
809
+ if (native) return;
810
+ shortcuts.dispatch({
811
+ ...gesture,
812
+ composing: guarded || isDead && !commandDeadKey,
813
+ defaultPrevented: event.defaultPrevented
814
+ }, context, consume);
815
+ };
816
+ document.addEventListener("compositionstart", reset, true);
817
+ document.addEventListener("compositionend", reset, true);
818
+ document.addEventListener("focusin", reset, true);
819
+ document.addEventListener("pointerdown", reset, true);
820
+ window.addEventListener("keydown", capture, true);
821
+ window.addEventListener("keydown", keydown);
822
+ window.addEventListener("blur", blur);
823
+ return () => {
824
+ pending = false;
825
+ window.clearTimeout(pendingTimer);
826
+ observer?.disconnect();
827
+ composition.dispose();
828
+ document.removeEventListener("compositionstart", reset, true);
829
+ document.removeEventListener("compositionend", reset, true);
830
+ document.removeEventListener("focusin", reset, true);
831
+ document.removeEventListener("pointerdown", reset, true);
832
+ window.removeEventListener("keydown", capture, true);
833
+ window.removeEventListener("keydown", keydown);
834
+ window.removeEventListener("blur", blur);
835
+ };
836
+ }
837
+ //#endregion
838
+ //#region lib/types/client/storage.js
839
+ /** Explicit browser and Desktop preference adapters; Desktop never falls back to browser storage. */
840
+ /** Browser-profile and origin-local preference key. */
841
+ const SHORTCUT_STORAGE_KEY = "dsh.keybindings.v1";
842
+ /**
843
+ * Connect localStorage and same-origin external updates to the shared transaction coordinator.
844
+ * @param window - owning browser window.
845
+ * @param platform - visiting device platform.
846
+ * @param publish - accepts complete configuration snapshots.
847
+ * @returns adapter and lifecycle disposal.
848
+ */
849
+ function webShortcutStorage(window, platform, publish) {
850
+ const persistence = new ShortcutPersistence({
851
+ read: () => window.localStorage.getItem(SHORTCUT_STORAGE_KEY),
852
+ write: (raw) => {
853
+ window.localStorage.setItem(SHORTCUT_STORAGE_KEY, raw);
854
+ }
855
+ }, "web", platform, true, publish);
856
+ const changed = (event) => {
857
+ if (event.key === null || event.key === "dsh.keybindings.v1") persistence.readCurrent();
858
+ };
859
+ window.addEventListener("storage", changed);
860
+ return {
861
+ get: (definitions) => {
862
+ persistence.setDefinitions(definitions);
863
+ return persistence.readCurrent();
864
+ },
865
+ edit: (edit, revision) => persistence.edit(edit, revision),
866
+ subscribe: () => () => {},
867
+ recording: async () => {},
868
+ dispose: () => {
869
+ window.removeEventListener("storage", changed);
870
+ persistence.dispose();
871
+ }
872
+ };
873
+ }
874
+ /**
875
+ * Read the origin-scoped preload capability; a missing bridge is an explicit configuration failure.
876
+ * @param window - product window.
877
+ * @returns the restricted Desktop API, or undefined while the preload is unavailable.
878
+ */
879
+ function desktopShortcutStorage(window) {
880
+ return window.dshDesktop?.shortcuts;
881
+ }
882
+ //#endregion
883
+ //#region lib/types/client/native.js
884
+ /** Desktop gestures use live focus, modal state, and verified embedding ownership. */
885
+ /**
886
+ * Route native menu, main-frame, and embedded-frame input through the shared command registry.
887
+ * @param window - trusted product document.
888
+ * @param keyboard - top-frame preload capability.
889
+ * @param registry - window-local command owner.
890
+ * @param snapshot - latest accepted configuration.
891
+ * @param reset - clears pending fixed sequences when native input bypasses DOM delivery.
892
+ * @returns disposer releasing native input.
893
+ */
894
+ function installNativeKeyboard(window, keyboard, registry, snapshot, reset) {
895
+ return keyboard.subscribe((input) => {
896
+ if (input.revision !== snapshot().revision) return;
897
+ reset?.();
898
+ let target = window.document.activeElement;
899
+ while (target?.shadowRoot?.activeElement != null && !target.matches("webview[data-sidebar-browser-frame]")) target = target.shadowRoot.activeElement;
900
+ const top = [...window.document.querySelectorAll(_deepseek_ai_dsh_client_ui_primitives.modalSelector)].at(-1);
901
+ const region = target?.closest(".xterm") ? "terminal" : target?.matches("input, textarea, select, [contenteditable=\"true\"], [contenteditable=\"\"]") ? "editable" : "page";
902
+ const context = {
903
+ target,
904
+ region,
905
+ modal: top?.dataset.shortcutModal ?? (top === void 0 ? null : "other")
906
+ };
907
+ if (input.kind === "menu") {
908
+ registry.invoke(input.commandId, context);
909
+ return;
910
+ }
911
+ if (input.kind === "keyboard") {
912
+ registry.dispatch({
913
+ ...input,
914
+ composing: false,
915
+ defaultPrevented: false
916
+ }, context, () => {});
917
+ return;
918
+ }
919
+ if (input.kind === "webview") {
920
+ if (target?.matches("webview[data-sidebar-browser-frame]") !== true || !target.isConnected || input.frameName === "" || target.getAttribute("name") !== input.frameName) return;
921
+ registry.dispatch({
922
+ ...input,
923
+ composing: false,
924
+ defaultPrevented: false
925
+ }, {
926
+ ...context,
927
+ source: "webview"
928
+ }, () => {});
929
+ return;
930
+ }
931
+ if (!(target instanceof HTMLIFrameElement) || !target.isConnected || !target.matches("iframe[data-sidebar-browser-frame], iframe[data-html-preview]") || input.frameName === "" || target.name !== input.frameName) return;
932
+ registry.dispatch({
933
+ ...input,
934
+ composing: false,
935
+ defaultPrevented: false
936
+ }, {
937
+ ...context,
938
+ source: "iframe"
939
+ }, () => {});
940
+ });
941
+ }
942
+ //#endregion
943
+ //#region ../../../vendor/cosmokit/lib/index.js
944
+ /** Return true when a value is `null` or `undefined`. */
945
+ function isNullable(value) {
946
+ return value === null || value === void 0;
947
+ }
948
+ /** Return true for non-array object values. */
949
+ function isPlainObject(data) {
950
+ return data && typeof data === "object" && !Array.isArray(data);
951
+ }
952
+ /** Filter object entries and return a new object. */
953
+ function filterKeys(object, filter) {
954
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
955
+ }
956
+ /** Map object values while preserving the original key set. */
957
+ function mapValues(object, transform) {
958
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
959
+ }
960
+ /** Pick selected keys from an object, optionally including `undefined` values. */
961
+ function pick(source, keys, forced) {
962
+ if (!keys) return { ...source };
963
+ const result = {};
964
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
965
+ return result;
966
+ }
967
+ /** Shared config references used by schema validators and plugin runtimes. */
968
+ const write = Symbol.for("cosmokit.volatile.write");
969
+ function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
970
+ if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
971
+ if (value === null || typeof value !== "object") return value;
972
+ if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
973
+ ancestors.add(value);
974
+ try {
975
+ if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
976
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
977
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
978
+ } finally {
979
+ ancestors.delete(value);
980
+ }
981
+ }
982
+ /**
983
+ * Create a detached reference containing an immutable copy of the supplied data.
984
+ * @param value - validated config data; class instances and functions are unsupported.
985
+ * @returns a reference whose value is updated only by its owning runtime.
986
+ */
987
+ function createVolatile(value) {
988
+ let current = snapshot(value);
989
+ return Object.freeze({
990
+ get: () => current,
991
+ [write]: (value) => {
992
+ current = value;
993
+ }
994
+ });
995
+ }
996
+ /**
997
+ * Identify references across ESM/CJS copies of the shared library.
998
+ * @param value - a parsed config value.
999
+ * @returns whether the value implements the shared reference protocol.
1000
+ */
1001
+ function isVolatile(value) {
1002
+ return typeof value === "object" && value !== null && write in value;
1003
+ }
1004
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
1005
+ function is(type, value) {
1006
+ if (arguments.length === 1) return (value) => is(type, value);
1007
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
1008
+ }
1009
+ function isArrayBufferLike(value) {
1010
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
1011
+ }
1012
+ function isArrayBufferSource(value) {
1013
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
1014
+ }
1015
+ /** Binary source detection and base64/hex conversion helpers. */
1016
+ var Binary;
1017
+ (function(Binary) {
1018
+ Binary.is = isArrayBufferLike;
1019
+ Binary.isSource = isArrayBufferSource;
1020
+ function fromSource(source) {
1021
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
1022
+ else return source;
1023
+ }
1024
+ Binary.fromSource = fromSource;
1025
+ function toBase64(source) {
1026
+ source = fromSource(source);
1027
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
1028
+ let binary = "";
1029
+ const bytes = new Uint8Array(source);
1030
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
1031
+ return btoa(binary);
1032
+ }
1033
+ Binary.toBase64 = toBase64;
1034
+ function fromBase64(source) {
1035
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
1036
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
1037
+ }
1038
+ Binary.fromBase64 = fromBase64;
1039
+ function toHex(source) {
1040
+ source = fromSource(source);
1041
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
1042
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
1043
+ }
1044
+ Binary.toHex = toHex;
1045
+ function fromHex(source) {
1046
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
1047
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
1048
+ const buffer = [];
1049
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
1050
+ return Uint8Array.from(buffer).buffer;
1051
+ }
1052
+ Binary.fromHex = fromHex;
1053
+ })(Binary || (Binary = {}));
1054
+ Binary.fromBase64;
1055
+ Binary.toBase64;
1056
+ Binary.fromHex;
1057
+ Binary.toHex;
1058
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
1059
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
1060
+ if (!source || typeof source !== "object") return source;
1061
+ if (is("Date", source)) return new Date(source.valueOf());
1062
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
1063
+ if (isArrayBufferLike(source)) return source.slice(0);
1064
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
1065
+ const cached = refs.get(source);
1066
+ if (cached) return cached;
1067
+ if (Array.isArray(source)) {
1068
+ const result = [];
1069
+ refs.set(source, result);
1070
+ source.forEach((value, index) => {
1071
+ result[index] = Reflect.apply(clone, null, [value, refs]);
1072
+ });
1073
+ return result;
1074
+ }
1075
+ const result = Object.create(Object.getPrototypeOf(source));
1076
+ refs.set(source, result);
1077
+ for (const key of Reflect.ownKeys(source)) {
1078
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
1079
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
1080
+ Reflect.defineProperty(result, key, descriptor);
1081
+ }
1082
+ return result;
1083
+ }
1084
+ /**
1085
+ * Compare values recursively, treating two volatile references as equal regardless of value.
1086
+ * Strict comparison distinguishes null/undefined, treats opaque objects by identity,
1087
+ * compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
1088
+ * @param a - first value.
1089
+ * @param b - second value.
1090
+ * @param strict - whether to require strict data equality outside volatile references.
1091
+ * @returns whether the values compare equal.
1092
+ */
1093
+ function deepEqual(a, b, strict) {
1094
+ const ancestors = /* @__PURE__ */ new Set();
1095
+ function compare(a, b) {
1096
+ if (a === b) return true;
1097
+ if (isVolatile(a) || isVolatile(b)) return isVolatile(a) && isVolatile(b);
1098
+ if (!strict && isNullable(a) && isNullable(b)) return true;
1099
+ if (typeof a !== typeof b || typeof a !== "object" || !a || !b) return false;
1100
+ if (ancestors.has(a)) return false;
1101
+ function check(test, then) {
1102
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
1103
+ }
1104
+ ancestors.add(a);
1105
+ try {
1106
+ return check(Array.isArray, (a, b) => {
1107
+ if (a.length !== b.length) return false;
1108
+ for (let index = 0; index < a.length; index++) if (!compare(a[index], b[index])) return false;
1109
+ return true;
1110
+ }) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("URL"), (a, b) => a.href === b.href) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
1111
+ if (a.byteLength !== b.byteLength) return false;
1112
+ const viewA = new Uint8Array(a);
1113
+ const viewB = new Uint8Array(b);
1114
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
1115
+ return true;
1116
+ }) ?? ((!strict || [a, b].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
1117
+ ...a,
1118
+ ...b
1119
+ }).every((key) => compare(a[key], b[key])));
1120
+ } finally {
1121
+ ancestors.delete(a);
1122
+ }
1123
+ }
1124
+ return compare(a, b);
1125
+ }
1126
+ /** Time constants plus parsing and formatting helpers. */
1127
+ var Time;
1128
+ (function(Time) {
1129
+ Time.millisecond = 1;
1130
+ Time.second = 1e3;
1131
+ Time.minute = Time.second * 60;
1132
+ Time.hour = Time.minute * 60;
1133
+ Time.day = Time.hour * 24;
1134
+ Time.week = Time.day * 7;
1135
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
1136
+ function setTimezoneOffset(offset) {
1137
+ timezoneOffset = offset;
1138
+ }
1139
+ Time.setTimezoneOffset = setTimezoneOffset;
1140
+ function getTimezoneOffset() {
1141
+ return timezoneOffset;
1142
+ }
1143
+ Time.getTimezoneOffset = getTimezoneOffset;
1144
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
1145
+ if (typeof date === "number") date = new Date(date);
1146
+ if (offset === void 0) offset = timezoneOffset;
1147
+ return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
1148
+ }
1149
+ Time.getDateNumber = getDateNumber;
1150
+ function fromDateNumber(value, offset) {
1151
+ const date = new Date(value * Time.day);
1152
+ if (offset === void 0) offset = timezoneOffset;
1153
+ return new Date(+date + offset * Time.minute);
1154
+ }
1155
+ Time.fromDateNumber = fromDateNumber;
1156
+ const numeric = /\d+(?:\.\d+)?/.source;
1157
+ const timeRegExp = new RegExp(`^${[
1158
+ "w(?:eek(?:s)?)?",
1159
+ "d(?:ay(?:s)?)?",
1160
+ "h(?:our(?:s)?)?",
1161
+ "m(?:in(?:ute)?(?:s)?)?",
1162
+ "s(?:ec(?:ond)?(?:s)?)?"
1163
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
1164
+ function parseTime(source) {
1165
+ const capture = timeRegExp.exec(source);
1166
+ if (!capture) return 0;
1167
+ return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
1168
+ }
1169
+ Time.parseTime = parseTime;
1170
+ function parseDate(date) {
1171
+ const parsed = parseTime(date);
1172
+ if (parsed) date = Date.now() + parsed;
1173
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
1174
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
1175
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
1176
+ }
1177
+ Time.parseDate = parseDate;
1178
+ function format(ms) {
1179
+ const abs = Math.abs(ms);
1180
+ if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
1181
+ else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
1182
+ else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
1183
+ else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
1184
+ return ms + "ms";
1185
+ }
1186
+ Time.format = format;
1187
+ function toDigits(source, length = 2) {
1188
+ return source.toString().padStart(length, "0");
1189
+ }
1190
+ Time.toDigits = toDigits;
1191
+ function template(template, time = /* @__PURE__ */ new Date()) {
1192
+ return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
1193
+ }
1194
+ Time.template = template;
1195
+ })(Time || (Time = {}));
1196
+ //#endregion
1197
+ //#region ../../../vendor/schemastery/lib/index.mjs
1198
+ const kSchema = Symbol.for("schemastery");
1199
+ const kValidationError = Symbol.for("ValidationError");
1200
+ globalThis.__schemastery_index__ ??= 0;
1201
+ globalThis.__schemastery_refs__ = void 0;
1202
+ var ValidationError = class extends TypeError {
1203
+ options;
1204
+ name = "ValidationError";
1205
+ constructor(message, options) {
1206
+ let prefix = "$";
1207
+ for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
1208
+ else if (typeof segment === "number") prefix += "[" + segment + "]";
1209
+ else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
1210
+ if (prefix.startsWith(".")) prefix = prefix.slice(1);
1211
+ super((prefix === "$" ? "" : `${prefix} `) + message);
1212
+ this.options = options;
1213
+ }
1214
+ static is(error) {
1215
+ return !!error?.[kValidationError];
1216
+ }
1217
+ };
1218
+ Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
1219
+ const Schema = function(options) {
1220
+ const schema = function(data, options = {}) {
1221
+ return Schema.resolve(data, schema, options)[0];
1222
+ };
1223
+ if (options.refs) {
1224
+ const refs = mapValues(options.refs, (options) => new Schema(options));
1225
+ const getRef = (uid) => refs[uid];
1226
+ for (const key in refs) {
1227
+ const options = refs[key];
1228
+ options.sKey = getRef(options.sKey);
1229
+ options.inner = getRef(options.inner);
1230
+ options.list = options.list && options.list.map(getRef);
1231
+ options.dict = options.dict && mapValues(options.dict, getRef);
1232
+ }
1233
+ return refs[options.uid];
1234
+ }
1235
+ Object.assign(schema, options);
1236
+ if (typeof schema.callback === "string") try {
1237
+ schema.callback = new Function("return " + schema.callback)();
1238
+ } catch {}
1239
+ Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
1240
+ Object.setPrototypeOf(schema, Schema.prototype);
1241
+ schema.meta ||= {};
1242
+ schema.toString = schema.toString.bind(schema);
1243
+ return schema;
1244
+ };
1245
+ Schema.prototype = Object.create(Function.prototype);
1246
+ Schema.prototype[kSchema] = true;
1247
+ Object.defineProperty(Schema.prototype, "~standard", { get() {
1248
+ return {
1249
+ version: 1,
1250
+ vendor: "schemastery",
1251
+ validate: (value) => {
1252
+ try {
1253
+ return { value: Schema.resolve(value, this, {})[0] };
1254
+ } catch (error) {
1255
+ if (ValidationError.is(error)) return { issues: [{
1256
+ message: error.message,
1257
+ path: error.options.path
1258
+ }] };
1259
+ throw error;
1260
+ }
1261
+ }
1262
+ };
1263
+ } });
1264
+ Schema.ValidationError = ValidationError;
1265
+ Schema.prototype.toJSON = function toJSON() {
1266
+ if (globalThis.__schemastery_refs__) {
1267
+ globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
1268
+ return this.uid;
1269
+ }
1270
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
1271
+ globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
1272
+ const result = {
1273
+ uid: this.uid,
1274
+ refs: globalThis.__schemastery_refs__
1275
+ };
1276
+ globalThis.__schemastery_refs__ = void 0;
1277
+ return result;
1278
+ };
1279
+ Schema.prototype.set = function set(key, value) {
1280
+ this.dict[key] = value;
1281
+ return this;
1282
+ };
1283
+ Schema.prototype.push = function push(value) {
1284
+ this.list.push(value);
1285
+ return this;
1286
+ };
1287
+ function mergeDesc(original, messages) {
1288
+ const result = typeof original === "string" ? { "": original } : { ...original };
1289
+ for (const locale in messages) {
1290
+ const value = messages[locale];
1291
+ if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
1292
+ else if (typeof value === "string") result[locale] = value;
1293
+ }
1294
+ return result;
1295
+ }
1296
+ function getInner(value) {
1297
+ return value?.$value ?? value?.$inner;
1298
+ }
1299
+ function extractKeys(data) {
1300
+ return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
1301
+ }
1302
+ Schema.prototype.i18n = function i18n(messages) {
1303
+ const schema = Schema(this);
1304
+ const desc = mergeDesc(schema.meta.description, messages);
1305
+ if (Object.keys(desc).length) schema.meta.description = desc;
1306
+ if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
1307
+ return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
1308
+ });
1309
+ if (schema.list) schema.list = schema.list.map((inner, index) => {
1310
+ return inner.i18n(mapValues(messages, (data = {}) => {
1311
+ if (Array.isArray(getInner(data))) return getInner(data)[index];
1312
+ if (Array.isArray(data)) return data[index];
1313
+ return extractKeys(data);
1314
+ }));
1315
+ });
1316
+ if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
1317
+ if (getInner(data)) return getInner(data);
1318
+ return extractKeys(data);
1319
+ }));
1320
+ if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
1321
+ return schema;
1322
+ };
1323
+ Schema.prototype.extra = function extra(key, value) {
1324
+ const schema = Schema(this);
1325
+ schema.meta = {
1326
+ ...schema.meta,
1327
+ [key]: value
1328
+ };
1329
+ return schema;
1330
+ };
1331
+ for (const key of [
1332
+ "required",
1333
+ "disabled",
1334
+ "collapse",
1335
+ "hidden",
1336
+ "loose"
1337
+ ]) Object.assign(Schema.prototype, { [key](value = true) {
1338
+ const schema = Schema(this);
1339
+ schema.meta = {
1340
+ ...schema.meta,
1341
+ [key]: value
1342
+ };
1343
+ return schema;
1344
+ } });
1345
+ Schema.prototype.deprecated = function deprecated() {
1346
+ const schema = Schema(this);
1347
+ schema.meta.badges ||= [];
1348
+ schema.meta.badges.push({
1349
+ text: "deprecated",
1350
+ type: "danger"
1351
+ });
1352
+ return schema;
1353
+ };
1354
+ Schema.prototype.experimental = function experimental() {
1355
+ const schema = Schema(this);
1356
+ schema.meta.badges ||= [];
1357
+ schema.meta.badges.push({
1358
+ text: "experimental",
1359
+ type: "warning"
1360
+ });
1361
+ return schema;
1362
+ };
1363
+ Schema.prototype.pattern = function pattern(regexp) {
1364
+ const schema = Schema(this);
1365
+ const pattern = pick(regexp, ["source", "flags"]);
1366
+ schema.meta = {
1367
+ ...schema.meta,
1368
+ pattern
1369
+ };
1370
+ return schema;
1371
+ };
1372
+ Schema.prototype.simplify = function simplify(value) {
1373
+ if (isVolatile(value)) value = value.get();
1374
+ if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
1375
+ if (isNullable(value)) return value;
1376
+ if (this.type === "object" || this.type === "dict") {
1377
+ const result = {};
1378
+ for (const key in value) {
1379
+ const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
1380
+ if (this.type === "dict" || !isNullable(item)) result[key] = item;
1381
+ }
1382
+ if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
1383
+ return result;
1384
+ } else if (this.type === "array" || this.type === "tuple") {
1385
+ const result = [];
1386
+ value.forEach((value, index) => {
1387
+ const schema = this.type === "array" ? this.inner : this.list[index];
1388
+ const item = schema ? schema.simplify(value) : value;
1389
+ result.push(item);
1390
+ });
1391
+ return result;
1392
+ } else if (this.type === "intersect") {
1393
+ const result = {};
1394
+ for (const item of this.list) Object.assign(result, item.simplify(value));
1395
+ return result;
1396
+ } else if (this.type === "union") for (const schema of this.list) try {
1397
+ Schema.resolve(value, schema, {});
1398
+ return schema.simplify(value);
1399
+ } catch {}
1400
+ return value;
1401
+ };
1402
+ Schema.prototype.toString = function toString(inline) {
1403
+ return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
1404
+ };
1405
+ Schema.prototype.role = function role(role, extra) {
1406
+ const schema = Schema(this);
1407
+ schema.meta = {
1408
+ ...schema.meta,
1409
+ role,
1410
+ extra
1411
+ };
1412
+ return schema;
1413
+ };
1414
+ for (const key of [
1415
+ "default",
1416
+ "link",
1417
+ "comment",
1418
+ "description",
1419
+ "max",
1420
+ "min",
1421
+ "step"
1422
+ ]) Object.assign(Schema.prototype, { [key](value) {
1423
+ const schema = Schema(this);
1424
+ schema.meta = {
1425
+ ...schema.meta,
1426
+ [key]: value
1427
+ };
1428
+ return schema;
1429
+ } });
1430
+ Schema.prototype.volatile = function volatile() {
1431
+ if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
1432
+ return this.extra("volatile", true);
1433
+ };
1434
+ const resolvers = {};
1435
+ const checkedVolatile = Symbol("checked-volatile-schema");
1436
+ function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
1437
+ const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
1438
+ if (states.has(blocked)) return;
1439
+ states.add(blocked);
1440
+ seen.set(schema, states);
1441
+ if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
1442
+ const nested = blocked || !!schema.meta?.volatile;
1443
+ if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path, key], nested, seen);
1444
+ if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
1445
+ if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
1446
+ if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
1447
+ }
1448
+ Schema.extend = function extend(type, resolve) {
1449
+ resolvers[type] = resolve;
1450
+ };
1451
+ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
1452
+ if (!schema) return [data];
1453
+ if (!options[checkedVolatile]) {
1454
+ validateVolatileSchema(schema, options.path);
1455
+ options = {
1456
+ ...options,
1457
+ [checkedVolatile]: true
1458
+ };
1459
+ }
1460
+ if (schema.meta?.volatile) {
1461
+ const inner = Schema(schema);
1462
+ inner.meta = {
1463
+ ...schema.meta,
1464
+ volatile: false
1465
+ };
1466
+ const [value, adapted] = Schema.resolve(data, inner, options, strict);
1467
+ try {
1468
+ return [createVolatile(value), adapted];
1469
+ } catch (error) {
1470
+ throw new ValidationError(error instanceof Error ? error.message : String(error), options);
1471
+ }
1472
+ }
1473
+ if (options.ignore?.(data, schema)) return [data];
1474
+ if (isNullable(data) && schema.type !== "lazy") {
1475
+ if (schema.meta.required) throw new ValidationError(`missing required value`, options);
1476
+ let current = schema;
1477
+ let fallback = schema.meta.default;
1478
+ while (current?.type === "intersect" && isNullable(fallback)) {
1479
+ current = current.list[0];
1480
+ fallback = current?.meta.default;
1481
+ }
1482
+ if (isNullable(fallback)) return [data];
1483
+ data = clone(fallback);
1484
+ }
1485
+ const callback = resolvers[schema.type];
1486
+ if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
1487
+ try {
1488
+ return callback(data, schema, options, strict);
1489
+ } catch (error) {
1490
+ if (!schema.meta.loose) throw error;
1491
+ return [schema.meta.default];
1492
+ }
1493
+ };
1494
+ Schema.from = function from(source) {
1495
+ if (isNullable(source)) return Schema.any();
1496
+ else if ([
1497
+ "string",
1498
+ "number",
1499
+ "boolean"
1500
+ ].includes(typeof source)) return Schema.const(source).required();
1501
+ else if (source[kSchema]) return source;
1502
+ else if (typeof source === "function") switch (source) {
1503
+ case String: return Schema.string().required();
1504
+ case Number: return Schema.number().required();
1505
+ case Boolean: return Schema.boolean().required();
1506
+ case Function: return Schema.function().required();
1507
+ default: return Schema.is(source).required();
1508
+ }
1509
+ else throw new TypeError(`cannot infer schema from ${source}`);
1510
+ };
1511
+ Schema.lazy = function lazy(builder) {
1512
+ const toJSON = () => {
1513
+ if (!schema.inner[kSchema]) {
1514
+ schema.inner = schema.builder();
1515
+ schema.inner.meta = {
1516
+ ...schema.meta,
1517
+ ...schema.inner.meta
1518
+ };
1519
+ }
1520
+ return schema.inner.toJSON();
1521
+ };
1522
+ const schema = new Schema({
1523
+ type: "lazy",
1524
+ builder,
1525
+ inner: { toJSON }
1526
+ });
1527
+ return schema;
1528
+ };
1529
+ Schema.natural = function natural() {
1530
+ return Schema.number().step(1).min(0);
1531
+ };
1532
+ Schema.percent = function percent() {
1533
+ return Schema.number().step(.01).min(0).max(1).role("slider");
1534
+ };
1535
+ Schema.date = function date() {
1536
+ return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
1537
+ const date = new Date(value);
1538
+ if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
1539
+ return date;
1540
+ }, true)]);
1541
+ };
1542
+ Schema.regExp = function regExp(flag = "") {
1543
+ return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
1544
+ try {
1545
+ return new RegExp(value, flag);
1546
+ } catch (e) {
1547
+ throw new ValidationError(e.message, options);
1548
+ }
1549
+ }, true)]);
1550
+ };
1551
+ Schema.arrayBuffer = function arrayBuffer(encoding) {
1552
+ return Schema.union([
1553
+ Schema.is(ArrayBuffer),
1554
+ Schema.is(SharedArrayBuffer),
1555
+ Schema.transform(Schema.any(), (value, options) => {
1556
+ if (Binary.isSource(value)) return Binary.fromSource(value);
1557
+ throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
1558
+ }, true),
1559
+ ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
1560
+ try {
1561
+ return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
1562
+ } catch (e) {
1563
+ throw new ValidationError(e.message, options);
1564
+ }
1565
+ }, true)] : []
1566
+ ]);
1567
+ };
1568
+ Schema.extend("lazy", (data, schema, options, strict) => {
1569
+ if (!schema.inner[kSchema]) {
1570
+ schema.inner = schema.builder();
1571
+ schema.inner.meta = {
1572
+ ...schema.meta,
1573
+ ...schema.inner.meta
1574
+ };
1575
+ validateVolatileSchema(schema.inner, options.path, true);
1576
+ }
1577
+ return Schema.resolve(data, schema.inner, options, strict);
1578
+ });
1579
+ Schema.extend("any", (data) => {
1580
+ return [data];
1581
+ });
1582
+ Schema.extend("never", (data, _, options) => {
1583
+ throw new ValidationError(`expected nullable but got ${data}`, options);
1584
+ });
1585
+ Schema.extend("const", (data, { value }, options) => {
1586
+ if (deepEqual(data, value)) return [value];
1587
+ throw new ValidationError(`expected ${value} but got ${data}`, options);
1588
+ });
1589
+ function checkWithinRange(data, meta, description, options, skipMin = false) {
1590
+ const { max = Infinity, min = -Infinity } = meta;
1591
+ if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
1592
+ if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
1593
+ }
1594
+ Schema.extend("string", (data, { meta }, options) => {
1595
+ if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
1596
+ if (meta.pattern) {
1597
+ const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
1598
+ if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
1599
+ }
1600
+ checkWithinRange(data.length, meta, "string length", options);
1601
+ return [data];
1602
+ });
1603
+ function decimalShift(data, digits) {
1604
+ const str = data.toString();
1605
+ if (str.includes("e")) return data * Math.pow(10, digits);
1606
+ const index = str.indexOf(".");
1607
+ if (index === -1) return data * Math.pow(10, digits);
1608
+ const frac = str.slice(index + 1);
1609
+ const integer = str.slice(0, index);
1610
+ if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
1611
+ return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
1612
+ }
1613
+ function isMultipleOf(data, min, step) {
1614
+ step = Math.abs(step);
1615
+ if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
1616
+ const index = step.toString().indexOf(".");
1617
+ const digits = step.toString().slice(index + 1).length;
1618
+ return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
1619
+ }
1620
+ Schema.extend("number", (data, { meta }, options) => {
1621
+ if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
1622
+ checkWithinRange(data, meta, "number", options);
1623
+ const { step } = meta;
1624
+ if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
1625
+ return [data];
1626
+ });
1627
+ Schema.extend("boolean", (data, _, options) => {
1628
+ if (typeof data === "boolean") return [data];
1629
+ throw new ValidationError(`expected boolean but got ${data}`, options);
1630
+ });
1631
+ Schema.extend("bitset", (data, { bits, meta }, options) => {
1632
+ let value = 0, keys = [];
1633
+ if (typeof data === "number") {
1634
+ value = data;
1635
+ for (const key in bits) if (data & bits[key]) keys.push(key);
1636
+ } else if (Array.isArray(data)) {
1637
+ keys = data;
1638
+ for (const key of keys) {
1639
+ if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
1640
+ if (key in bits) value |= bits[key];
1641
+ }
1642
+ } else throw new ValidationError(`expected number or array but got ${data}`, options);
1643
+ if (value === meta.default) return [value];
1644
+ return [value, keys];
1645
+ });
1646
+ Schema.extend("function", (data, _, options) => {
1647
+ if (typeof data === "function") return [data];
1648
+ throw new ValidationError(`expected function but got ${data}`, options);
1649
+ });
1650
+ Schema.extend("is", (data, { constructor }, options) => {
1651
+ if (typeof constructor === "function") {
1652
+ if (data instanceof constructor) return [data];
1653
+ throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
1654
+ } else {
1655
+ if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
1656
+ let prototype = Object.getPrototypeOf(data);
1657
+ while (prototype) {
1658
+ if (prototype.constructor?.name === constructor) return [data];
1659
+ prototype = Object.getPrototypeOf(prototype);
1660
+ }
1661
+ throw new ValidationError(`expected ${constructor} but got ${data}`, options);
1662
+ }
1663
+ });
1664
+ function property(data, key, schema, options) {
1665
+ try {
1666
+ const [value, adapted] = Schema.resolve(data[key], schema, {
1667
+ ...options,
1668
+ path: [...options.path || [], key]
1669
+ });
1670
+ if (adapted !== void 0) data[key] = adapted;
1671
+ return value;
1672
+ } catch (e) {
1673
+ if (!options?.autofix) throw e;
1674
+ delete data[key];
1675
+ return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
1676
+ }
1677
+ }
1678
+ Schema.extend("array", (data, { inner, meta }, options) => {
1679
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
1680
+ checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
1681
+ return [data.map((_, index) => property(data, index, inner, options))];
1682
+ });
1683
+ Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
1684
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
1685
+ const result = {};
1686
+ for (const key in data) {
1687
+ let rKey;
1688
+ try {
1689
+ rKey = Schema.resolve(key, sKey, options)[0];
1690
+ } catch (error) {
1691
+ if (strict) continue;
1692
+ throw error;
1693
+ }
1694
+ result[rKey] = property(data, key, inner, options);
1695
+ data[rKey] = data[key];
1696
+ if (key !== rKey) delete data[key];
1697
+ }
1698
+ return [result];
1699
+ });
1700
+ Schema.extend("tuple", (data, { list }, options, strict) => {
1701
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
1702
+ const result = list.map((inner, index) => property(data, index, inner, options));
1703
+ if (strict) return [result];
1704
+ result.push(...data.slice(list.length));
1705
+ return [result];
1706
+ });
1707
+ function merge(result, data) {
1708
+ for (const key in data) {
1709
+ if (key in result) continue;
1710
+ result[key] = data[key];
1711
+ }
1712
+ }
1713
+ Schema.extend("object", (data, { dict }, options, strict) => {
1714
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
1715
+ const result = {};
1716
+ for (const key in dict) {
1717
+ const value = property(data, key, dict[key], options);
1718
+ if (!isNullable(value) || key in data) result[key] = value;
1719
+ }
1720
+ if (!strict) merge(result, data);
1721
+ return [result];
1722
+ });
1723
+ Schema.extend("union", (data, { list, toString }, options, strict) => {
1724
+ const messages = [];
1725
+ for (const inner of list) try {
1726
+ return Schema.resolve(data, inner, options, strict);
1727
+ } catch (error) {
1728
+ messages.push(error);
1729
+ }
1730
+ throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
1731
+ });
1732
+ Schema.extend("intersect", (data, { list, toString }, options, strict) => {
1733
+ if (!list.length) return [data];
1734
+ let result;
1735
+ for (const inner of list) {
1736
+ const value = Schema.resolve(data, inner, options, true)[0];
1737
+ if (isNullable(value)) continue;
1738
+ if (isNullable(result)) result = value;
1739
+ else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
1740
+ else if (typeof value === "object") merge(result ??= {}, value);
1741
+ else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
1742
+ }
1743
+ if (!strict && isPlainObject(data)) merge(result, data);
1744
+ return [result];
1745
+ });
1746
+ Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
1747
+ const [result, adapted = data] = Schema.resolve(data, inner, options, true);
1748
+ if (preserve) return [callback(result)];
1749
+ else return [callback(result), callback(adapted)];
1750
+ });
1751
+ const formatters = {};
1752
+ function defineMethod(name, keys, format) {
1753
+ formatters[name] = format;
1754
+ Object.assign(Schema, { [name](...args) {
1755
+ const schema = new Schema({ type: name });
1756
+ keys.forEach((key, index) => {
1757
+ switch (key) {
1758
+ case "sKey":
1759
+ schema.sKey = args[index] ?? Schema.string();
1760
+ break;
1761
+ case "inner":
1762
+ schema.inner = Schema.from(args[index]);
1763
+ break;
1764
+ case "list":
1765
+ schema.list = args[index].map(Schema.from);
1766
+ break;
1767
+ case "dict":
1768
+ schema.dict = mapValues(args[index], Schema.from);
1769
+ break;
1770
+ case "bits":
1771
+ schema.bits = {};
1772
+ for (const key in args[index]) {
1773
+ if (typeof args[index][key] !== "number") continue;
1774
+ schema.bits[key] = args[index][key];
1775
+ }
1776
+ break;
1777
+ case "callback": {
1778
+ const callback = schema.callback = args[index];
1779
+ callback["toJSON"] ||= () => callback.toString();
1780
+ break;
1781
+ }
1782
+ case "constructor": {
1783
+ const constructor = schema.constructor = args[index];
1784
+ if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
1785
+ break;
1786
+ }
1787
+ default: schema[key] = args[index];
1788
+ }
1789
+ });
1790
+ if (name === "object" || name === "dict") schema.meta.default = {};
1791
+ else if (name === "array" || name === "tuple") schema.meta.default = [];
1792
+ else if (name === "bitset") schema.meta.default = 0;
1793
+ return schema;
1794
+ } });
1795
+ }
1796
+ defineMethod("is", ["constructor"], ({ constructor }) => {
1797
+ if (typeof constructor === "function") return constructor.name;
1798
+ else return constructor;
1799
+ });
1800
+ defineMethod("any", [], () => "any");
1801
+ defineMethod("never", [], () => "never");
1802
+ defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
1803
+ defineMethod("string", [], () => "string");
1804
+ defineMethod("number", [], () => "number");
1805
+ defineMethod("boolean", [], () => "boolean");
1806
+ defineMethod("bitset", ["bits"], () => "bitset");
1807
+ defineMethod("function", [], () => "function");
1808
+ defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
1809
+ defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
1810
+ defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
1811
+ defineMethod("object", ["dict"], ({ dict }) => {
1812
+ if (Object.keys(dict).length === 0) return "{}";
1813
+ return `{ ${Object.entries(dict).map(([key, inner]) => {
1814
+ return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
1815
+ }).join(", ")} }`;
1816
+ });
1817
+ defineMethod("union", ["list"], ({ list }, inline) => {
1818
+ const result = list.map(({ toString: format }) => format()).join(" | ");
1819
+ return inline ? `(${result})` : result;
1820
+ });
1821
+ defineMethod("intersect", ["list"], ({ list }) => {
1822
+ return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
1823
+ });
1824
+ defineMethod("transform", [
1825
+ "inner",
1826
+ "callback",
1827
+ "preserve"
1828
+ ], ({ inner }, isInner) => inner.toString(isInner));
1829
+ //#endregion
1830
+ //#region lib/types/config.js
1831
+ /** Window-local timing accepted by the Host and browser keyboard service. */
1832
+ /** Validated deployment settings for fixed keyboard sequences. */
1833
+ const Config = Schema.object({ stopSequenceMs: Schema.natural().min(1).max(2147483646).default(500) });
1834
+ //#endregion
1835
+ //#region lib/types/client/index.js
1836
+ /** Browser command service, with one keyboard adapter per plugin lifetime. */
1837
+ /** Cordis keyboard provider; Desktop startup requires its native keyboard bridge. */
1838
+ var ShortcutsService = class extends _deepseek_ai_cordis.Service {
1839
+ static inject = ["locale"];
1840
+ runtime;
1841
+ platform;
1842
+ catalog;
1843
+ config;
1844
+ fixedCatalog;
1845
+ stopSequenceMs;
1846
+ fixedListeners = /* @__PURE__ */ new Set();
1847
+ adapter;
1848
+ keyboard;
1849
+ active = true;
1850
+ connected = false;
1851
+ registry;
1852
+ constructor(ctx) {
1853
+ const environment = detectEnvironment(document, navigator);
1854
+ const keyboard = environment.runtime === "desktop" ? window.dshDesktop?.keyboard : void 0;
1855
+ if (environment.runtime === "desktop" && keyboard === void 0) throw new Error("Desktop keyboard bridge unavailable");
1856
+ super(ctx, "shortcuts");
1857
+ this.keyboard = keyboard;
1858
+ this.runtime = environment.runtime;
1859
+ this.platform = environment.platform;
1860
+ const config = Config(globalThis.__DSH_SHORTCUTS_CONFIG__ ?? {});
1861
+ this.stopSequenceMs = config.stopSequenceMs;
1862
+ this.registry = new ShortcutRegistry(this.runtime, this.platform, initialShortcutConfig());
1863
+ this.catalog = this.registry.catalog;
1864
+ this.config = this.registry.config;
1865
+ this.fixedCatalog = this.registry.fixedCatalog;
1866
+ const publish = (snapshot) => {
1867
+ if (this.active && this.connected && snapshot.sequence >= this.config.getSnapshot().sequence) this.registry.configure(snapshot);
1868
+ };
1869
+ const web = this.runtime === "web" ? webShortcutStorage(window, this.platform, publish) : void 0;
1870
+ this.adapter = web ?? desktopShortcutStorage(window);
1871
+ if (keyboard !== void 0) ctx.effect(() => installNativeKeyboard(window, keyboard, this.registry, () => this.config.getSnapshot(), () => {
1872
+ this.fixedInput({ type: "reset" });
1873
+ }), "shortcuts: native keyboard");
1874
+ ctx.effect(() => {
1875
+ const off = this.adapter?.subscribe(publish);
1876
+ return () => {
1877
+ this.active = false;
1878
+ off?.();
1879
+ web?.dispose();
1880
+ };
1881
+ }, "shortcuts: preferences");
1882
+ this.syncDefinitions();
1883
+ ctx.effect(() => {
1884
+ const off = installKeyboard(window, this.registry, (input) => {
1885
+ this.fixedInput(input);
1886
+ }, keyboard !== void 0 && (this.platform === "macos" || this.platform === "windows"));
1887
+ return () => {
1888
+ off();
1889
+ this.fixedListeners.clear();
1890
+ };
1891
+ }, "shortcuts: keyboard");
1892
+ ctx.effect(() => ctx.locale.subscribe(() => {
1893
+ this.registry.refreshLabels();
1894
+ }), "shortcuts: locale");
1895
+ }
1896
+ register(command) {
1897
+ const off = this.registry.register(command);
1898
+ this.syncDefinitions();
1899
+ return () => {
1900
+ off();
1901
+ this.syncDefinitions();
1902
+ };
1903
+ }
1904
+ registerFixed(command) {
1905
+ const off = this.registry.registerFixed(command);
1906
+ this.syncDefinitions();
1907
+ return () => {
1908
+ off();
1909
+ this.syncDefinitions();
1910
+ };
1911
+ }
1912
+ observeFixedInput(listener) {
1913
+ this.fixedListeners.add(listener);
1914
+ return () => {
1915
+ this.fixedListeners.delete(listener);
1916
+ };
1917
+ }
1918
+ fixedInput(input) {
1919
+ let consumed = false;
1920
+ for (const listener of [...this.fixedListeners]) {
1921
+ if (!this.fixedListeners.has(listener)) continue;
1922
+ try {
1923
+ listener(input.type === "reset" ? input : {
1924
+ ...input,
1925
+ gesture: {
1926
+ ...input.gesture,
1927
+ defaultPrevented: input.gesture.defaultPrevented || consumed
1928
+ },
1929
+ consume: () => {
1930
+ consumed = true;
1931
+ input.consume();
1932
+ }
1933
+ });
1934
+ } catch (error) {
1935
+ console.error("Fixed shortcut handler failed", error);
1936
+ }
1937
+ }
1938
+ }
1939
+ describeBinding(binding) {
1940
+ const normalized = binding === null ? null : normalizeBinding(binding, this.platform);
1941
+ return {
1942
+ binding: normalized,
1943
+ keys: presentBinding(normalized, this.platform).keys,
1944
+ issue: normalized === null ? null : bindingIssue(normalized, this.runtime, this.platform),
1945
+ conflicts: normalized === null ? [] : [...this.catalog.getSnapshot().filter((row) => row.binding !== null && overlappingBindings(row.binding, normalized)).map((row) => row.id), ...this.fixedCatalog.getSnapshot().filter((row) => row.bindings.some((binding) => overlappingBindings(binding, normalized))).map((row) => row.id)]
1946
+ };
1947
+ }
1948
+ syncDefinitions() {
1949
+ if (!this.active) return;
1950
+ if (this.adapter === void 0) {
1951
+ this.failRead();
1952
+ return;
1953
+ }
1954
+ this.adapter.get(this.registry.definitions()).then((snapshot) => {
1955
+ this.connected = true;
1956
+ if (this.active && snapshot.sequence >= this.config.getSnapshot().sequence) this.registry.configure(snapshot);
1957
+ }, () => {
1958
+ this.failRead();
1959
+ });
1960
+ }
1961
+ failRead() {
1962
+ if (this.active) this.registry.configure({
1963
+ ...this.config.getSnapshot(),
1964
+ status: "unreadable",
1965
+ error: "read"
1966
+ });
1967
+ }
1968
+ /**
1969
+ * Persist one reviewed operation while retaining accepted bindings on failure.
1970
+ * @param args - edit and expected revision supplied by the editor.
1971
+ * @returns classified save outcome and accepted snapshot.
1972
+ */
1973
+ async edit(...args) {
1974
+ if (this.adapter === void 0) return {
1975
+ status: "unreadable",
1976
+ snapshot: this.config.getSnapshot()
1977
+ };
1978
+ let result;
1979
+ try {
1980
+ result = await this.adapter.edit(...args);
1981
+ } catch (error) {
1982
+ if (this.active) console.error("Shortcut preference save failed", error);
1983
+ return {
1984
+ status: "write-failed",
1985
+ snapshot: this.config.getSnapshot()
1986
+ };
1987
+ }
1988
+ if (this.active && result.snapshot.sequence >= this.config.getSnapshot().sequence) this.registry.configure(result.snapshot);
1989
+ return result;
1990
+ }
1991
+ async recording(active) {
1992
+ if (this.adapter === void 0) throw new Error("Desktop shortcuts bridge unavailable");
1993
+ await this.adapter.recording(active);
1994
+ }
1995
+ async closeWindow() {
1996
+ if (this.keyboard === void 0) throw new Error("Desktop keyboard bridge unavailable");
1997
+ await this.keyboard.closeWindow(this.config.getSnapshot().revision);
1998
+ }
1999
+ };
2000
+ //#endregion
2001
+ module.exports = ShortcutsService;
2002
+ return module.exports;
2003
+ }
2004
+ });
2005
+
2006
+ //# sourceMappingURL=client.js.map