@embedpdf/plugin-commands 3.0.0-next.22 → 3.0.0-next.23

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.
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("../contract-sqmSSPlP.cjs");
2
+ const require_contract = require("../contract-CgR0waU2.cjs");
3
3
  //#region src/host-contract.ts
4
4
  /**
5
5
  * @embedpdf/plugin-commands/contract/host — the host lens: the keystroke
@@ -1,3 +1,3 @@
1
- import { S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDef, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "../contract-lGfvyWMG.cjs";
2
- import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-Db4TZ_JI.cjs";
3
- export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
1
+ import { S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "../contract-Bt0jzEeF.cjs";
2
+ import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-BvjavDn3.cjs";
3
+ export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,3 +1,3 @@
1
- import { S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDef, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "../contract-lGfvyWMG.js";
2
- import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-B58WiZ-H.js";
3
- export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
1
+ import { S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "../contract-Bt0jzEeF.js";
2
+ import { n as CommandsToken, r as ShortcutMatch, t as CommandsHostCapability } from "../host-contract-WcBrcWQN.js";
3
+ export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsHostCapability, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, ShortcutMatch, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,4 +1,4 @@
1
- import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken$1, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "../contract-FbiUhTWC.js";
1
+ import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken$1, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "../contract-DzkHZxi7.js";
2
2
  import { createHostToken } from "@embedpdf/core";
3
3
  //#region src/host-contract.ts
4
4
  /**
@@ -34,16 +34,20 @@ interface IconAccent {
34
34
  }
35
35
  /**
36
36
  * One command, as you define it. Its functions get your app's state as `AppState`; they're
37
- * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.
37
+ * methods, so a command typed for your state (`CommandDefinition<Review>`) goes wherever a command does.
38
38
  */
39
- interface CommandDef<AppState = any> {
39
+ interface CommandDefinition<AppState = any> {
40
40
  /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */
41
41
  readonly id: string;
42
- /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */
42
+ /**
43
+ * What the user sees. With `labelKey` too, it's what shows when no language has the key. Its
44
+ * `{name}` slots take the values `labelParams` gives.
45
+ */
43
46
  readonly label?: string;
44
47
  /**
45
48
  * A translation key for the label, read through the i18n plugin. Without the plugin, or a
46
- * string for the key, the command shows `label`, else the key.
49
+ * string for the key, the command shows `label`, else the key. The string's `{name}` slots
50
+ * take the values `labelParams` gives, and a number `count` picks its plural form.
47
51
  */
48
52
  readonly labelKey?: string;
49
53
  /** Your icon's name; your buttons turn it into an icon. */
@@ -111,6 +115,12 @@ interface CommandDef<AppState = any> {
111
115
  active?(context: CommandContext<AppState>): boolean;
112
116
  /** When it shows at all. Default: always. One that throws counts as false. */
113
117
  visible?(context: CommandContext<AppState>): boolean;
118
+ /**
119
+ * The values for its label's `{name}` slots, such as how many pages are selected:
120
+ * `({ count: pageEdit.getSelected().length })`. A number `count` also picks the plural form of a
121
+ * translated label. One that throws gives none, and the slots show as they are.
122
+ */
123
+ labelParams?(context: CommandContext<AppState>): Readonly<Record<string, string | number>>;
114
124
  /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */
115
125
  run?(context: CommandContext<AppState>): void | Promise<unknown>;
116
126
  }
@@ -125,7 +135,7 @@ interface CommandFamily {
125
135
  /** The names the command's document has, in order. Return the same array while nothing changed. */
126
136
  readonly names: (context: CommandContext) => readonly string[];
127
137
  /** The command for one name. A family's commands have no shortcuts. */
128
- readonly command: (name: string) => Omit<CommandDef, 'id' | 'shortcut'>;
138
+ readonly command: (name: string) => Omit<CommandDefinition, 'id' | 'shortcut'>;
129
139
  }
130
140
  /** A command as a button shows it: everything read for its document. */
131
141
  interface ResolvedCommand {
@@ -173,12 +183,12 @@ interface BoundCommand extends ResolvedCommand {
173
183
  /** Run the command for the document it was read for. */
174
184
  readonly run: () => Promise<ExecuteResult>;
175
185
  /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */
176
- readonly shortcut: string | null;
186
+ readonly shortcutLabel: string | null;
177
187
  }
178
188
  /**
179
- * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is
180
- * its first shortcut formatted for the platform. Which platform is the caller's to know
181
- * (`isMacPlatform()` in `@embedpdf/web`).
189
+ * A resolved command, bound for a button: `run` executes it through `execute`, and
190
+ * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the
191
+ * caller's to know (`isMacPlatform()` in `@embedpdf/web`).
182
192
  */
183
193
  declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandId) => Promise<ExecuteResult>, options: {
184
194
  readonly isMac: boolean;
@@ -189,7 +199,7 @@ declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandI
189
199
  */
190
200
  interface CommandsSettings {
191
201
  /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */
192
- readonly commands: readonly (CommandDef | CommandFamily)[];
202
+ readonly commands: readonly (CommandDefinition | CommandFamily)[];
193
203
  /**
194
204
  * Your app's state, which every command's functions get as `appState`: values, and functions
195
205
  * that change them. A new value replaces the old one whole, and every command is asked again.
@@ -214,7 +224,7 @@ type NotAllowedMode = 'hide' | 'disable';
214
224
  declare const COMMANDS_DEFAULTS: CommandsSettings;
215
225
  /** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */
216
226
  type CommandsConfig<AppState = any> = Omit<DeepPartial<CommandsSettings>, 'commands' | 'appState'> & {
217
- readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];
227
+ readonly commands?: readonly (CommandDefinition<AppState> | CommandFamily)[];
218
228
  readonly appState?: AppState;
219
229
  };
220
230
  interface RegisterCommandOptions {
@@ -254,13 +264,13 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
254
264
  * Add a command while the app runs, and get a function that removes it. A taken id throws
255
265
  * `conflict` unless `replace`.
256
266
  */
257
- registerCommand(definition: CommandDef, options?: RegisterCommandOptions): Unsubscribe;
267
+ registerCommand(definition: CommandDefinition, options?: RegisterCommandOptions): Unsubscribe;
258
268
  /** `registerCommand` for several definitions; the function removes all of them. */
259
- registerCommands(definitions: readonly CommandDef[], options?: RegisterCommandOptions): Unsubscribe;
269
+ registerCommands(definitions: readonly CommandDefinition[], options?: RegisterCommandOptions): Unsubscribe;
260
270
  /** Whether a command has this id; with a family, every id that starts with its prefix does. */
261
271
  hasCommand(id: CommandId): boolean;
262
272
  /** A command as you defined it, or `null`. */
263
- getCommand(id: CommandId): CommandDef | null;
273
+ getCommand(id: CommandId): CommandDefinition | null;
264
274
  /** Every command's id for the active document, in the order they were added. The same array until one changes. */
265
275
  listCommandIds(): readonly CommandId[];
266
276
  /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */
@@ -314,5 +324,5 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
314
324
  readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;
315
325
  }
316
326
  //#endregion
317
- export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDef as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
318
- //# sourceMappingURL=contract-lGfvyWMG.d.ts.map
327
+ export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDefinition as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
328
+ //# sourceMappingURL=contract-Bt0jzEeF.d.cts.map
@@ -34,16 +34,20 @@ interface IconAccent {
34
34
  }
35
35
  /**
36
36
  * One command, as you define it. Its functions get your app's state as `AppState`; they're
37
- * methods, so a command typed for your state (`CommandDef<Review>`) goes wherever a command does.
37
+ * methods, so a command typed for your state (`CommandDefinition<Review>`) goes wherever a command does.
38
38
  */
39
- interface CommandDef<AppState = any> {
39
+ interface CommandDefinition<AppState = any> {
40
40
  /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */
41
41
  readonly id: string;
42
- /** What the user sees. With `labelKey` too, it's what shows when no language has the key. */
42
+ /**
43
+ * What the user sees. With `labelKey` too, it's what shows when no language has the key. Its
44
+ * `{name}` slots take the values `labelParams` gives.
45
+ */
43
46
  readonly label?: string;
44
47
  /**
45
48
  * A translation key for the label, read through the i18n plugin. Without the plugin, or a
46
- * string for the key, the command shows `label`, else the key.
49
+ * string for the key, the command shows `label`, else the key. The string's `{name}` slots
50
+ * take the values `labelParams` gives, and a number `count` picks its plural form.
47
51
  */
48
52
  readonly labelKey?: string;
49
53
  /** Your icon's name; your buttons turn it into an icon. */
@@ -111,6 +115,12 @@ interface CommandDef<AppState = any> {
111
115
  active?(context: CommandContext<AppState>): boolean;
112
116
  /** When it shows at all. Default: always. One that throws counts as false. */
113
117
  visible?(context: CommandContext<AppState>): boolean;
118
+ /**
119
+ * The values for its label's `{name}` slots, such as how many pages are selected:
120
+ * `({ count: pageEdit.getSelected().length })`. A number `count` also picks the plural form of a
121
+ * translated label. One that throws gives none, and the slots show as they are.
122
+ */
123
+ labelParams?(context: CommandContext<AppState>): Readonly<Record<string, string | number>>;
114
124
  /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */
115
125
  run?(context: CommandContext<AppState>): void | Promise<unknown>;
116
126
  }
@@ -125,7 +135,7 @@ interface CommandFamily {
125
135
  /** The names the command's document has, in order. Return the same array while nothing changed. */
126
136
  readonly names: (context: CommandContext) => readonly string[];
127
137
  /** The command for one name. A family's commands have no shortcuts. */
128
- readonly command: (name: string) => Omit<CommandDef, 'id' | 'shortcut'>;
138
+ readonly command: (name: string) => Omit<CommandDefinition, 'id' | 'shortcut'>;
129
139
  }
130
140
  /** A command as a button shows it: everything read for its document. */
131
141
  interface ResolvedCommand {
@@ -173,12 +183,12 @@ interface BoundCommand extends ResolvedCommand {
173
183
  /** Run the command for the document it was read for. */
174
184
  readonly run: () => Promise<ExecuteResult>;
175
185
  /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */
176
- readonly shortcut: string | null;
186
+ readonly shortcutLabel: string | null;
177
187
  }
178
188
  /**
179
- * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is
180
- * its first shortcut formatted for the platform. Which platform is the caller's to know
181
- * (`isMacPlatform()` in `@embedpdf/web`).
189
+ * A resolved command, bound for a button: `run` executes it through `execute`, and
190
+ * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the
191
+ * caller's to know (`isMacPlatform()` in `@embedpdf/web`).
182
192
  */
183
193
  declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandId) => Promise<ExecuteResult>, options: {
184
194
  readonly isMac: boolean;
@@ -189,7 +199,7 @@ declare function boundCommandOf(command: ResolvedCommand, execute: (id: CommandI
189
199
  */
190
200
  interface CommandsSettings {
191
201
  /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */
192
- readonly commands: readonly (CommandDef | CommandFamily)[];
202
+ readonly commands: readonly (CommandDefinition | CommandFamily)[];
193
203
  /**
194
204
  * Your app's state, which every command's functions get as `appState`: values, and functions
195
205
  * that change them. A new value replaces the old one whole, and every command is asked again.
@@ -214,7 +224,7 @@ type NotAllowedMode = 'hide' | 'disable';
214
224
  declare const COMMANDS_DEFAULTS: CommandsSettings;
215
225
  /** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */
216
226
  type CommandsConfig<AppState = any> = Omit<DeepPartial<CommandsSettings>, 'commands' | 'appState'> & {
217
- readonly commands?: readonly (CommandDef<AppState> | CommandFamily)[];
227
+ readonly commands?: readonly (CommandDefinition<AppState> | CommandFamily)[];
218
228
  readonly appState?: AppState;
219
229
  };
220
230
  interface RegisterCommandOptions {
@@ -254,13 +264,13 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
254
264
  * Add a command while the app runs, and get a function that removes it. A taken id throws
255
265
  * `conflict` unless `replace`.
256
266
  */
257
- registerCommand(definition: CommandDef, options?: RegisterCommandOptions): Unsubscribe;
267
+ registerCommand(definition: CommandDefinition, options?: RegisterCommandOptions): Unsubscribe;
258
268
  /** `registerCommand` for several definitions; the function removes all of them. */
259
- registerCommands(definitions: readonly CommandDef[], options?: RegisterCommandOptions): Unsubscribe;
269
+ registerCommands(definitions: readonly CommandDefinition[], options?: RegisterCommandOptions): Unsubscribe;
260
270
  /** Whether a command has this id; with a family, every id that starts with its prefix does. */
261
271
  hasCommand(id: CommandId): boolean;
262
272
  /** A command as you defined it, or `null`. */
263
- getCommand(id: CommandId): CommandDef | null;
273
+ getCommand(id: CommandId): CommandDefinition | null;
264
274
  /** Every command's id for the active document, in the order they were added. The same array until one changes. */
265
275
  listCommandIds(): readonly CommandId[];
266
276
  /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */
@@ -314,5 +324,5 @@ interface CommandsCapability extends SettingsApi<CommandsSettings> {
314
324
  readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;
315
325
  }
316
326
  //#endregion
317
- export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDef as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
318
- //# sourceMappingURL=contract-lGfvyWMG.d.cts.map
327
+ export { CommandsToken as C, unregisteredCommand as S, RegisterCommandOptions as _, CommandExecutedEvent as a, resolvedCommandsEqual as b, CommandId as c, CommandsConfig as d, CommandsSettings as f, NotAllowedMode as g, IconAccent as h, CommandDefinition as i, CommandRefusal as l, ExecuteResult as m, COMMANDS_DEFAULTS as n, CommandExecutionFailedEvent as o, ExecuteOptions as p, CommandContext as r, CommandFamily as s, BoundCommand as t, CommandsCapability as u, ResolvedCommand as v, unknownCommandWarning as x, boundCommandOf as y };
328
+ //# sourceMappingURL=contract-Bt0jzEeF.d.ts.map
@@ -31,16 +31,16 @@ const unregisteredCommand = (id) => ({
31
31
  /** What a component that asks for an id no plugin registered hears, in development. */
32
32
  const unknownCommandWarning = (id, known) => `no command "${id}"${(0, _embedpdf_core_ui.didYouMean)(id, known)}: it shows as neither visible nor enabled`;
33
33
  /**
34
- * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is
35
- * its first shortcut formatted for the platform. Which platform is the caller's to know
36
- * (`isMacPlatform()` in `@embedpdf/web`).
34
+ * A resolved command, bound for a button: `run` executes it through `execute`, and
35
+ * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the
36
+ * caller's to know (`isMacPlatform()` in `@embedpdf/web`).
37
37
  */
38
38
  function boundCommandOf(command, execute, options) {
39
39
  const [first] = command.shortcuts;
40
40
  return {
41
41
  ...command,
42
42
  run: () => execute(command.id),
43
- shortcut: first === void 0 ? null : (0, _embedpdf_core_ui.formatShortcut)(first, { isMac: options.isMac })
43
+ shortcutLabel: first === void 0 ? null : (0, _embedpdf_core_ui.formatShortcut)(first, { isMac: options.isMac })
44
44
  };
45
45
  }
46
46
  /** What the commands settings are when the app registers none. */
@@ -89,4 +89,4 @@ Object.defineProperty(exports, "unregisteredCommand", {
89
89
  }
90
90
  });
91
91
 
92
- //# sourceMappingURL=contract-sqmSSPlP.cjs.map
92
+ //# sourceMappingURL=contract-CgR0waU2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-CgR0waU2.cjs","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { CommandsCapability } from './contract';\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands', {\n hint: `add commandsPlugin() from '@embedpdf/plugin-commands' to your plugins list`,\n});\n","/**\n * @embedpdf/plugin-commands/contract — the commands that toolbars, menus,\n * shortcuts and a command palette all show and run.\n *\n * A command's state is read from live state: `resolveCommand` asks the other\n * capabilities when it's called, so every reader follows the kernel's one\n * change stream, with no events. Definitions hold functions, so they live in\n * the settings and the plugin's registry, never in state.\n */\nimport type {\n CapabilityToken,\n DeepPartial,\n EventHook,\n OperationOptions,\n Permission,\n PluginErrorInfo,\n SettingLock,\n SettingsApi,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { didYouMean, formatShortcut } from '@embedpdf/core-ui';\n\nexport { CommandsToken } from './token';\n\nexport type CommandId = string;\n\n/**\n * What a command's derivations and `run` see: capabilities resolved for the command's document\n * (the one named, else the document in scope, else the active one), and your app's state.\n */\nexport interface CommandContext<AppState = any> {\n /** The command's document, or `null` when none is open. */\n readonly documentId: string | null;\n /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */\n readonly appState: AppState;\n /** What the caller passed: `execute(id, { args })`. */\n readonly args?: unknown;\n /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */\n readonly signal?: AbortSignal;\n /** A capability, for the command's document when the plugin is document-scoped. Throws when it isn't available. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but `null` when the capability isn't available (no plugin, no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two colors that go with a command's icon, such as a tool's current color: data a\n * renderer may use (tint the icon, show a swatch), like `icon` itself.\n */\nexport interface IconAccent {\n /** The mark: a stroke, the markup or the text color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\n/**\n * One command, as you define it. Its functions get your app's state as `AppState`; they're\n * methods, so a command typed for your state (`CommandDefinition<Review>`) goes wherever a command does.\n */\nexport interface CommandDefinition<AppState = any> {\n /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */\n readonly id: string;\n /**\n * What the user sees. With `labelKey` too, it's what shows when no language has the key. Its\n * `{name}` slots take the values `labelParams` gives.\n */\n readonly label?: string;\n /**\n * A translation key for the label, read through the i18n plugin. Without the plugin, or a\n * string for the key, the command shows `label`, else the key. The string's `{name}` slots\n * take the values `labelParams` gives, and a number `count` picks its plural form.\n */\n readonly labelKey?: string;\n /** Your icon's name; your buttons turn it into an icon. */\n readonly icon?: string;\n /** Colors for the icon, read from live state like `active`. */\n iconAccent?(context: CommandContext<AppState>): IconAccent | null;\n /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */\n readonly shortcut?: string | readonly string[];\n /**\n * Whether its shortcut also runs while the cursor is in a text field where the shortcuts\n * listen (a search box, a comment), as the viewer's Find does. Default false: a key typed in\n * a field is the field's.\n */\n readonly shortcutInTextFields?: boolean;\n /**\n * The features it belongs to, so turning one off turns it off: `['annotations.highlight']`.\n * Turning off a feature turns off every feature under it, on whole dotted parts: `annotations`\n * covers `annotations.highlight`, not `annotationsExtra`.\n */\n readonly categories?: readonly string[];\n /**\n * The scope permissions it needs, such as `'doc.annotate.modify'`, checked against its\n * document. Without them it's hidden, or shown disabled with its reason under the\n * `notAllowed: 'disable'` setting. With no document open there is nothing to check.\n */\n readonly requires?: readonly Permission[];\n /**\n * Whether the session may run it, from the plugins' `can*` checks\n * (`documents.canPrint()`), for a command whose permission is a plugin's to know. When it\n * says no, the command isn't allowed, as with `requires`. Asked only while a document is\n * open; one that throws allows it.\n */\n allowed?(context: CommandContext<AppState>): boolean;\n /**\n * The translation key of the sentence that says why `allowed` refused it, with `{label}` for\n * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,\n * `commands.notAllowed.default`.\n */\n readonly notAllowedKey?: string;\n /**\n * The lock on the setting it changes, for a command that changes one\n * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.\n * While a lock holds, it shows disabled, whatever the `notAllowed` setting\n * says, with the sentence under the lock's `reasonKey` (else\n * `commands.locked.default`) as its `disabledReason`; it stays `active` for\n * its own value. One that throws counts as unlocked.\n */\n locked?(context: CommandContext<AppState>): SettingLock | null;\n\n // ── what the command opens ───────────────────────────────────────────────\n // A command that opens a panel, menu or dialog says so instead of opening\n // it in `run`: it then needs no `run`, it shows as active while the surface\n // is open, and a button can show that it opens a menu.\n /** Opens and closes a menu of yours, by its id. */\n readonly menu?: string;\n /**\n * Opens and closes a panel, closing the others with the same `exclusive` tag. With `focus`,\n * opening it asks for the cursor (the shell's `open(id, { focus: true })`).\n */\n readonly panel?:\n | string\n | { readonly id: string; readonly exclusive?: string; readonly focus?: boolean };\n /** Opens and closes a dialog; one dialog is open at a time. */\n readonly modal?: string;\n\n // ── read from live state and your app's, again whenever either changes ──\n /** When it can run. Default: always. One that throws counts as false. */\n enabled?(context: CommandContext<AppState>): boolean;\n /** When it shows as pressed, such as the current tool. One that throws counts as false. */\n active?(context: CommandContext<AppState>): boolean;\n /** When it shows at all. Default: always. One that throws counts as false. */\n visible?(context: CommandContext<AppState>): boolean;\n /**\n * The values for its label's `{name}` slots, such as how many pages are selected:\n * `({ count: pageEdit.getSelected().length })`. A number `count` also picks the plural form of a\n * translated label. One that throws gives none, and the slots show as they are.\n */\n labelParams?(context: CommandContext<AppState>): Readonly<Record<string, string | number>>;\n\n /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */\n run?(context: CommandContext<AppState>): void | Promise<unknown>;\n}\n\n/**\n * A command for each of a set of names, made from one definition, such as `tool:<id>` for every\n * tool a document has. Its commands resolve and run like any other, and `listCommands()` lists\n * one per name. A command defined with the same id wins over the family's.\n */\nexport interface CommandFamily {\n /** Where the commands' ids start: `'tool:'` makes `tool:highlight`. */\n readonly prefix: string;\n /** The names the command's document has, in order. Return the same array while nothing changed. */\n readonly names: (context: CommandContext) => readonly string[];\n /** The command for one name. A family's commands have no shortcuts. */\n readonly command: (name: string) => Omit<CommandDefinition, 'id' | 'shortcut'>;\n}\n\n/** A command as a button shows it: everything read for its document. */\nexport interface ResolvedCommand {\n readonly id: string;\n readonly label: string;\n readonly icon?: string;\n readonly iconAccent?: IconAccent;\n readonly shortcuts: readonly string[];\n readonly menu?: string;\n readonly enabled: boolean;\n readonly active: boolean;\n readonly visible: boolean;\n readonly categories: readonly string[];\n /**\n * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and\n * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.\n */\n readonly disabledReason?: string;\n}\n\n/**\n * Why a command won't run whatever the moment: it's turned off in this viewer\n * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock\n * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,\n * `visible`) has no refusal.\n */\nexport interface CommandRefusal {\n readonly reason: 'turned-off' | 'not-allowed' | 'locked';\n /** A sentence for the user, translated through the i18n plugin when it's there. */\n readonly message: string;\n}\n\n/**\n * Whether two resolved commands show the same, for readers that compare what a command looks\n * like rather than which object holds it (a group of commands, or one command for two documents).\n */\nexport const resolvedCommandsEqual = (\n left: ResolvedCommand | null,\n right: ResolvedCommand | null,\n): boolean => {\n if (left === right) return true;\n if (!left || !right) return false;\n return (\n left.id === right.id &&\n left.label === right.label &&\n left.icon === right.icon &&\n left.iconAccent?.primary === right.iconAccent?.primary &&\n left.iconAccent?.secondary === right.iconAccent?.secondary &&\n left.menu === right.menu &&\n left.enabled === right.enabled &&\n left.active === right.active &&\n left.visible === right.visible &&\n left.disabledReason === right.disabledReason &&\n left.shortcuts.length === right.shortcuts.length &&\n left.shortcuts.every((shortcut, index) => shortcut === right.shortcuts[index])\n );\n};\n\n/**\n * What a component or a toolbar draws for a command id no plugin registered: labelled with its\n * id, neither enabled nor visible, the way a turned-off command is.\n */\nexport const unregisteredCommand = (id: CommandId): ResolvedCommand => ({\n id,\n label: id,\n shortcuts: [],\n enabled: false,\n active: false,\n visible: false,\n categories: [],\n});\n\n/** What a component that asks for an id no plugin registered hears, in development. */\nexport const unknownCommandWarning = (id: CommandId, known: Iterable<CommandId>): string =>\n `no command \"${id}\"${didYouMean(id, known)}: it shows as neither visible nor enabled`;\n\n/** A command with everything a button needs: what it shows, `run`, and its shortcut for a tooltip. */\nexport interface BoundCommand extends ResolvedCommand {\n /** Run the command for the document it was read for. */\n readonly run: () => Promise<ExecuteResult>;\n /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */\n readonly shortcutLabel: string | null;\n}\n\n/**\n * A resolved command, bound for a button: `run` executes it through `execute`, and\n * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the\n * caller's to know (`isMacPlatform()` in `@embedpdf/web`).\n */\nexport function boundCommandOf(\n command: ResolvedCommand,\n execute: (id: CommandId) => Promise<ExecuteResult>,\n options: { readonly isMac: boolean },\n): BoundCommand {\n const [first] = command.shortcuts;\n return {\n ...command,\n run: () => execute(command.id),\n shortcutLabel: first === undefined ? null : formatShortcut(first, { isMac: options.isMac }),\n };\n}\n\n/**\n * The commands plugin's settings. `commandsPlugin(config)` registers them over\n * {@link COMMANDS_DEFAULTS}, and `updateSettings()` changes them while the app runs.\n */\nexport interface CommandsSettings {\n /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */\n readonly commands: readonly (CommandDefinition | CommandFamily)[];\n /**\n * Your app's state, which every command's functions get as `appState`: values, and functions\n * that change them. A new value replaces the old one whole, and every command is asked again.\n */\n readonly appState: unknown;\n /**\n * Categories turned off, with every category under them: their commands are hidden and\n * refused wherever they appear.\n */\n readonly disabledCategories: readonly string[];\n /** Commands turned off one by one, by id: hidden and refused wherever they appear. */\n readonly disabledCommands: readonly CommandId[];\n /**\n * What a command the scope doesn't allow does: `'hide'` leaves it out, `'disable'` shows it\n * disabled, with the reason in its `disabledReason`.\n */\n readonly notAllowed: NotAllowedMode;\n}\n\n/** How a command shows when the scope doesn't allow it: hidden, or disabled with its reason. */\nexport type NotAllowedMode = 'hide' | 'disable';\n\n/** What the commands settings are when the app registers none. */\nexport const COMMANDS_DEFAULTS: CommandsSettings = {\n commands: [],\n appState: undefined,\n disabledCategories: [],\n disabledCommands: [],\n notAllowed: 'hide',\n};\n\n/** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type CommandsConfig<AppState = any> = Omit<\n DeepPartial<CommandsSettings>,\n 'commands' | 'appState'\n> & {\n readonly commands?: readonly (CommandDefinition<AppState> | CommandFamily)[];\n readonly appState?: AppState;\n};\n\nexport interface RegisterCommandOptions {\n /** Replace a command with the same id; without it, a taken id throws `conflict`. */\n replace?: boolean;\n}\n\nexport interface ExecuteOptions extends OperationOptions {\n /** The document to run it for; the document in scope, else the active one, when left out. */\n documentId?: string;\n /** Passed to the command's `run` and derivations as `args`. */\n args?: unknown;\n}\n\n/** How `execute()` went: it ran, or it was refused before running, and why. */\nexport type ExecuteResult =\n | { readonly status: 'executed' }\n | { readonly status: 'rejected'; readonly reason: 'not-found' | 'disabled' | 'hidden' };\n\n// ── events ──\nexport interface CommandExecutedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly args: unknown;\n}\nexport interface CommandExecutionFailedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly error: PluginErrorInfo;\n}\n\n/**\n * The commands. A call that leaves out the document is for the document in scope when the\n * capability was resolved for one (`ctx.forDocument`, a `<DocumentScope>`), and for the active\n * document otherwise.\n */\nexport interface CommandsCapability extends SettingsApi<CommandsSettings> {\n // ── the commands ──\n /**\n * Add a command while the app runs, and get a function that removes it. A taken id throws\n * `conflict` unless `replace`.\n */\n registerCommand(definition: CommandDefinition, options?: RegisterCommandOptions): Unsubscribe;\n /** `registerCommand` for several definitions; the function removes all of them. */\n registerCommands(\n definitions: readonly CommandDefinition[],\n options?: RegisterCommandOptions,\n ): Unsubscribe;\n /** Whether a command has this id; with a family, every id that starts with its prefix does. */\n hasCommand(id: CommandId): boolean;\n /** A command as you defined it, or `null`. */\n getCommand(id: CommandId): CommandDefinition | null;\n /** Every command's id for the active document, in the order they were added. The same array until one changes. */\n listCommandIds(): readonly CommandId[];\n\n // ── what a button shows ──\n /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */\n resolveCommand(id: CommandId, documentId?: string): ResolvedCommand | null;\n /** Every command, resolved, in the order they were added. The same array while nothing changed. */\n listCommands(documentId?: string): readonly ResolvedCommand[];\n /** The visible commands whose label or id contains the query, for a command palette. */\n searchCommands(query: string, documentId?: string): readonly ResolvedCommand[];\n /** Every shortcut with its command, for a keyboard help sheet. The same array until the commands change. */\n listShortcuts(): readonly { readonly commandId: CommandId; readonly shortcut: string }[];\n\n // ── running them ──\n /**\n * Run a command; resolves once its `run` has, with `{ status: 'executed' }` and\n * `onExecuted`, or `{ status: 'rejected', reason }` for a command that is unknown, hidden or\n * disabled (a command turned off is hidden). A `run` that throws fires `onExecutionFailed` and rejects with its `PluginError`;\n * the signal rejects `operation-cancelled`.\n */\n execute(id: CommandId, options?: ExecuteOptions): Promise<ExecuteResult>;\n /** Whether a command can run now: it exists, and is enabled and visible. */\n canExecute(id: CommandId, documentId?: string): boolean;\n /**\n * Why a command won't run whatever the moment: it's turned off, or not allowed for its\n * document. `null` when it may run (or only can't right now), and for an unknown id.\n */\n getRefusal(id: CommandId, documentId?: string): CommandRefusal | null;\n\n // ── turning commands off ──\n /** The categories turned off. */\n getDisabledCategories(): readonly string[];\n /** Whether a category is turned off: it, or a category it's under (`annotations` for `annotations.highlight`). */\n isCategoryDisabled(category: string): boolean;\n /** Turn a category off, with every category under it: the `disabledCategories` setting gains it. */\n disableCategory(category: string): void;\n /** Turn a category on again. */\n enableCategory(category: string): void;\n /** Replace the categories that are off. */\n setDisabledCategories(categories: readonly string[]): void;\n /** The commands turned off one by one. */\n getDisabledCommands(): readonly CommandId[];\n /** Whether a command is turned off: by its id, or through one of its categories. */\n isCommandDisabled(id: CommandId): boolean;\n /** Turn one command off: the `disabledCommands` setting gains it. */\n disableCommand(id: CommandId): void;\n /** Turn a command on again; it stays off while one of its categories is. */\n enableCommand(id: CommandId): void;\n /** Replace the commands that are off one by one. */\n setDisabledCommands(ids: readonly CommandId[]): void;\n\n // ── events ──\n /** A command ran. */\n readonly onExecuted: EventHook<CommandExecutedEvent>;\n /** A command's `run` threw; `execute` rejects with the same error. */\n readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;\n}\n"],"mappings":";;;;;AAMA,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAA0D,YAAY,EACjF,MAAM,6EACR,CAAC;;;;;;;ACoMD,MAAa,yBACX,MACA,UACY;CACZ,IAAI,SAAS,OAAO,OAAO;CAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO;CAC5B,OACE,KAAK,OAAO,MAAM,MAClB,KAAK,UAAU,MAAM,SACrB,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,YAAY,MAAM,YAAY,WAC/C,KAAK,YAAY,cAAc,MAAM,YAAY,aACjD,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,MAAM,WACvB,KAAK,WAAW,MAAM,UACtB,KAAK,YAAY,MAAM,WACvB,KAAK,mBAAmB,MAAM,kBAC9B,KAAK,UAAU,WAAW,MAAM,UAAU,UAC1C,KAAK,UAAU,OAAO,UAAU,UAAU,aAAa,MAAM,UAAU,MAAM;AAEjF;;;;;AAMA,MAAa,uBAAuB,QAAoC;CACtE;CACA,OAAO;CACP,WAAW,CAAC;CACZ,SAAS;CACT,QAAQ;CACR,SAAS;CACT,YAAY,CAAC;AACf;;AAGA,MAAa,yBAAyB,IAAe,UACnD,eAAe,GAAG,IAAA,GAAA,kBAAA,WAAA,CAAc,IAAI,KAAK,EAAE;;;;;;AAe7C,SAAgB,eACd,SACA,SACA,SACc;CACd,MAAM,CAAC,SAAS,QAAQ;CACxB,OAAO;EACL,GAAG;EACH,WAAW,QAAQ,QAAQ,EAAE;EAC7B,eAAe,UAAU,KAAA,IAAY,QAAA,GAAA,kBAAA,eAAA,CAAsB,OAAO,EAAE,OAAO,QAAQ,MAAM,CAAC;CAC5F;AACF;;AAgCA,MAAa,oBAAsC;CACjD,UAAU,CAAC;CACX,UAAU,KAAA;CACV,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,YAAY;AACd"}
@@ -31,16 +31,16 @@ const unregisteredCommand = (id) => ({
31
31
  /** What a component that asks for an id no plugin registered hears, in development. */
32
32
  const unknownCommandWarning = (id, known) => `no command "${id}"${didYouMean(id, known)}: it shows as neither visible nor enabled`;
33
33
  /**
34
- * A resolved command, bound for a button: `run` executes it through `execute`, and `shortcut` is
35
- * its first shortcut formatted for the platform. Which platform is the caller's to know
36
- * (`isMacPlatform()` in `@embedpdf/web`).
34
+ * A resolved command, bound for a button: `run` executes it through `execute`, and
35
+ * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the
36
+ * caller's to know (`isMacPlatform()` in `@embedpdf/web`).
37
37
  */
38
38
  function boundCommandOf(command, execute, options) {
39
39
  const [first] = command.shortcuts;
40
40
  return {
41
41
  ...command,
42
42
  run: () => execute(command.id),
43
- shortcut: first === void 0 ? null : formatShortcut(first, { isMac: options.isMac })
43
+ shortcutLabel: first === void 0 ? null : formatShortcut(first, { isMac: options.isMac })
44
44
  };
45
45
  }
46
46
  /** What the commands settings are when the app registers none. */
@@ -54,4 +54,4 @@ const COMMANDS_DEFAULTS = {
54
54
  //#endregion
55
55
  export { unregisteredCommand as a, unknownCommandWarning as i, boundCommandOf as n, CommandsToken as o, resolvedCommandsEqual as r, COMMANDS_DEFAULTS as t };
56
56
 
57
- //# sourceMappingURL=contract-FbiUhTWC.js.map
57
+ //# sourceMappingURL=contract-DzkHZxi7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-DzkHZxi7.js","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here; `contract.ts` re-exports it and\n * `host-contract.ts` widens it to the host capability. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { CommandsCapability } from './contract';\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands', {\n hint: `add commandsPlugin() from '@embedpdf/plugin-commands' to your plugins list`,\n});\n","/**\n * @embedpdf/plugin-commands/contract — the commands that toolbars, menus,\n * shortcuts and a command palette all show and run.\n *\n * A command's state is read from live state: `resolveCommand` asks the other\n * capabilities when it's called, so every reader follows the kernel's one\n * change stream, with no events. Definitions hold functions, so they live in\n * the settings and the plugin's registry, never in state.\n */\nimport type {\n CapabilityToken,\n DeepPartial,\n EventHook,\n OperationOptions,\n Permission,\n PluginErrorInfo,\n SettingLock,\n SettingsApi,\n Unsubscribe,\n} from '@embedpdf/core';\nimport { didYouMean, formatShortcut } from '@embedpdf/core-ui';\n\nexport { CommandsToken } from './token';\n\nexport type CommandId = string;\n\n/**\n * What a command's derivations and `run` see: capabilities resolved for the command's document\n * (the one named, else the document in scope, else the active one), and your app's state.\n */\nexport interface CommandContext<AppState = any> {\n /** The command's document, or `null` when none is open. */\n readonly documentId: string | null;\n /** Your app's state, as the `appState` setting has it now: `any` until you give its type. */\n readonly appState: AppState;\n /** What the caller passed: `execute(id, { args })`. */\n readonly args?: unknown;\n /** Fires when the caller cancels `execute()`: pass it on to the calls `run` makes. */\n readonly signal?: AbortSignal;\n /** A capability, for the command's document when the plugin is document-scoped. Throws when it isn't available. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but `null` when the capability isn't available (no plugin, no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two colors that go with a command's icon, such as a tool's current color: data a\n * renderer may use (tint the icon, show a swatch), like `icon` itself.\n */\nexport interface IconAccent {\n /** The mark: a stroke, the markup or the text color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\n/**\n * One command, as you define it. Its functions get your app's state as `AppState`; they're\n * methods, so a command typed for your state (`CommandDefinition<Review>`) goes wherever a command does.\n */\nexport interface CommandDefinition<AppState = any> {\n /** A unique name, by convention `area:action`: `'zoom:in'`, `'review:approve'`. */\n readonly id: string;\n /**\n * What the user sees. With `labelKey` too, it's what shows when no language has the key. Its\n * `{name}` slots take the values `labelParams` gives.\n */\n readonly label?: string;\n /**\n * A translation key for the label, read through the i18n plugin. Without the plugin, or a\n * string for the key, the command shows `label`, else the key. The string's `{name}` slots\n * take the values `labelParams` gives, and a number `count` picks its plural form.\n */\n readonly labelKey?: string;\n /** Your icon's name; your buttons turn it into an icon. */\n readonly icon?: string;\n /** Colors for the icon, read from live state like `active`. */\n iconAccent?(context: CommandContext<AppState>): IconAccent | null;\n /** A key such as `'Mod+K'` (`Mod` is Cmd on a Mac, Ctrl elsewhere), or a list of them. */\n readonly shortcut?: string | readonly string[];\n /**\n * Whether its shortcut also runs while the cursor is in a text field where the shortcuts\n * listen (a search box, a comment), as the viewer's Find does. Default false: a key typed in\n * a field is the field's.\n */\n readonly shortcutInTextFields?: boolean;\n /**\n * The features it belongs to, so turning one off turns it off: `['annotations.highlight']`.\n * Turning off a feature turns off every feature under it, on whole dotted parts: `annotations`\n * covers `annotations.highlight`, not `annotationsExtra`.\n */\n readonly categories?: readonly string[];\n /**\n * The scope permissions it needs, such as `'doc.annotate.modify'`, checked against its\n * document. Without them it's hidden, or shown disabled with its reason under the\n * `notAllowed: 'disable'` setting. With no document open there is nothing to check.\n */\n readonly requires?: readonly Permission[];\n /**\n * Whether the session may run it, from the plugins' `can*` checks\n * (`documents.canPrint()`), for a command whose permission is a plugin's to know. When it\n * says no, the command isn't allowed, as with `requires`. Asked only while a document is\n * open; one that throws allows it.\n */\n allowed?(context: CommandContext<AppState>): boolean;\n /**\n * The translation key of the sentence that says why `allowed` refused it, with `{label}` for\n * its label: `'commands.notAllowed.doc-print'`. Without it, or a string for it,\n * `commands.notAllowed.default`.\n */\n readonly notAllowedKey?: string;\n /**\n * The lock on the setting it changes, for a command that changes one\n * (`(context) => context.get(StageToken).getLock('spread')`), or `null`.\n * While a lock holds, it shows disabled, whatever the `notAllowed` setting\n * says, with the sentence under the lock's `reasonKey` (else\n * `commands.locked.default`) as its `disabledReason`; it stays `active` for\n * its own value. One that throws counts as unlocked.\n */\n locked?(context: CommandContext<AppState>): SettingLock | null;\n\n // ── what the command opens ───────────────────────────────────────────────\n // A command that opens a panel, menu or dialog says so instead of opening\n // it in `run`: it then needs no `run`, it shows as active while the surface\n // is open, and a button can show that it opens a menu.\n /** Opens and closes a menu of yours, by its id. */\n readonly menu?: string;\n /**\n * Opens and closes a panel, closing the others with the same `exclusive` tag. With `focus`,\n * opening it asks for the cursor (the shell's `open(id, { focus: true })`).\n */\n readonly panel?:\n | string\n | { readonly id: string; readonly exclusive?: string; readonly focus?: boolean };\n /** Opens and closes a dialog; one dialog is open at a time. */\n readonly modal?: string;\n\n // ── read from live state and your app's, again whenever either changes ──\n /** When it can run. Default: always. One that throws counts as false. */\n enabled?(context: CommandContext<AppState>): boolean;\n /** When it shows as pressed, such as the current tool. One that throws counts as false. */\n active?(context: CommandContext<AppState>): boolean;\n /** When it shows at all. Default: always. One that throws counts as false. */\n visible?(context: CommandContext<AppState>): boolean;\n /**\n * The values for its label's `{name}` slots, such as how many pages are selected:\n * `({ count: pageEdit.getSelected().length })`. A number `count` also picks the plural form of a\n * translated label. One that throws gives none, and the slots show as they are.\n */\n labelParams?(context: CommandContext<AppState>): Readonly<Record<string, string | number>>;\n\n /** What it does; `execute()` resolves once it has. Not needed for a `menu`, `panel` or `modal`. */\n run?(context: CommandContext<AppState>): void | Promise<unknown>;\n}\n\n/**\n * A command for each of a set of names, made from one definition, such as `tool:<id>` for every\n * tool a document has. Its commands resolve and run like any other, and `listCommands()` lists\n * one per name. A command defined with the same id wins over the family's.\n */\nexport interface CommandFamily {\n /** Where the commands' ids start: `'tool:'` makes `tool:highlight`. */\n readonly prefix: string;\n /** The names the command's document has, in order. Return the same array while nothing changed. */\n readonly names: (context: CommandContext) => readonly string[];\n /** The command for one name. A family's commands have no shortcuts. */\n readonly command: (name: string) => Omit<CommandDefinition, 'id' | 'shortcut'>;\n}\n\n/** A command as a button shows it: everything read for its document. */\nexport interface ResolvedCommand {\n readonly id: string;\n readonly label: string;\n readonly icon?: string;\n readonly iconAccent?: IconAccent;\n readonly shortcuts: readonly string[];\n readonly menu?: string;\n readonly enabled: boolean;\n readonly active: boolean;\n readonly visible: boolean;\n readonly categories: readonly string[];\n /**\n * Why it's disabled, as a sentence for its tooltip: set when the scope doesn't allow it and\n * the `notAllowed` setting is `'disable'`, or when a lock holds the setting it changes.\n */\n readonly disabledReason?: string;\n}\n\n/**\n * Why a command won't run whatever the moment: it's turned off in this viewer\n * (`disabledCategories`, `disabledCommands`), the scope doesn't allow it (`requires`), or a lock\n * holds the setting it changes (`locked`). A command that only can't run right now (`enabled`,\n * `visible`) has no refusal.\n */\nexport interface CommandRefusal {\n readonly reason: 'turned-off' | 'not-allowed' | 'locked';\n /** A sentence for the user, translated through the i18n plugin when it's there. */\n readonly message: string;\n}\n\n/**\n * Whether two resolved commands show the same, for readers that compare what a command looks\n * like rather than which object holds it (a group of commands, or one command for two documents).\n */\nexport const resolvedCommandsEqual = (\n left: ResolvedCommand | null,\n right: ResolvedCommand | null,\n): boolean => {\n if (left === right) return true;\n if (!left || !right) return false;\n return (\n left.id === right.id &&\n left.label === right.label &&\n left.icon === right.icon &&\n left.iconAccent?.primary === right.iconAccent?.primary &&\n left.iconAccent?.secondary === right.iconAccent?.secondary &&\n left.menu === right.menu &&\n left.enabled === right.enabled &&\n left.active === right.active &&\n left.visible === right.visible &&\n left.disabledReason === right.disabledReason &&\n left.shortcuts.length === right.shortcuts.length &&\n left.shortcuts.every((shortcut, index) => shortcut === right.shortcuts[index])\n );\n};\n\n/**\n * What a component or a toolbar draws for a command id no plugin registered: labelled with its\n * id, neither enabled nor visible, the way a turned-off command is.\n */\nexport const unregisteredCommand = (id: CommandId): ResolvedCommand => ({\n id,\n label: id,\n shortcuts: [],\n enabled: false,\n active: false,\n visible: false,\n categories: [],\n});\n\n/** What a component that asks for an id no plugin registered hears, in development. */\nexport const unknownCommandWarning = (id: CommandId, known: Iterable<CommandId>): string =>\n `no command \"${id}\"${didYouMean(id, known)}: it shows as neither visible nor enabled`;\n\n/** A command with everything a button needs: what it shows, `run`, and its shortcut for a tooltip. */\nexport interface BoundCommand extends ResolvedCommand {\n /** Run the command for the document it was read for. */\n readonly run: () => Promise<ExecuteResult>;\n /** Its first shortcut, formatted for the platform (`'⌘K'` on a Mac, `'Ctrl+K'` elsewhere), or `null`. */\n readonly shortcutLabel: string | null;\n}\n\n/**\n * A resolved command, bound for a button: `run` executes it through `execute`, and\n * `shortcutLabel` is its first shortcut formatted for the platform. Which platform is the\n * caller's to know (`isMacPlatform()` in `@embedpdf/web`).\n */\nexport function boundCommandOf(\n command: ResolvedCommand,\n execute: (id: CommandId) => Promise<ExecuteResult>,\n options: { readonly isMac: boolean },\n): BoundCommand {\n const [first] = command.shortcuts;\n return {\n ...command,\n run: () => execute(command.id),\n shortcutLabel: first === undefined ? null : formatShortcut(first, { isMac: options.isMac }),\n };\n}\n\n/**\n * The commands plugin's settings. `commandsPlugin(config)` registers them over\n * {@link COMMANDS_DEFAULTS}, and `updateSettings()` changes them while the app runs.\n */\nexport interface CommandsSettings {\n /** The commands your viewer has. A later definition with an id that's taken replaces the earlier one. */\n readonly commands: readonly (CommandDefinition | CommandFamily)[];\n /**\n * Your app's state, which every command's functions get as `appState`: values, and functions\n * that change them. A new value replaces the old one whole, and every command is asked again.\n */\n readonly appState: unknown;\n /**\n * Categories turned off, with every category under them: their commands are hidden and\n * refused wherever they appear.\n */\n readonly disabledCategories: readonly string[];\n /** Commands turned off one by one, by id: hidden and refused wherever they appear. */\n readonly disabledCommands: readonly CommandId[];\n /**\n * What a command the scope doesn't allow does: `'hide'` leaves it out, `'disable'` shows it\n * disabled, with the reason in its `disabledReason`.\n */\n readonly notAllowed: NotAllowedMode;\n}\n\n/** How a command shows when the scope doesn't allow it: hidden, or disabled with its reason. */\nexport type NotAllowedMode = 'hide' | 'disable';\n\n/** What the commands settings are when the app registers none. */\nexport const COMMANDS_DEFAULTS: CommandsSettings = {\n commands: [],\n appState: undefined,\n disabledCategories: [],\n disabledCommands: [],\n notAllowed: 'hide',\n};\n\n/** What `commandsPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type CommandsConfig<AppState = any> = Omit<\n DeepPartial<CommandsSettings>,\n 'commands' | 'appState'\n> & {\n readonly commands?: readonly (CommandDefinition<AppState> | CommandFamily)[];\n readonly appState?: AppState;\n};\n\nexport interface RegisterCommandOptions {\n /** Replace a command with the same id; without it, a taken id throws `conflict`. */\n replace?: boolean;\n}\n\nexport interface ExecuteOptions extends OperationOptions {\n /** The document to run it for; the document in scope, else the active one, when left out. */\n documentId?: string;\n /** Passed to the command's `run` and derivations as `args`. */\n args?: unknown;\n}\n\n/** How `execute()` went: it ran, or it was refused before running, and why. */\nexport type ExecuteResult =\n | { readonly status: 'executed' }\n | { readonly status: 'rejected'; readonly reason: 'not-found' | 'disabled' | 'hidden' };\n\n// ── events ──\nexport interface CommandExecutedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly args: unknown;\n}\nexport interface CommandExecutionFailedEvent {\n readonly commandId: CommandId;\n readonly documentId: string | null;\n readonly error: PluginErrorInfo;\n}\n\n/**\n * The commands. A call that leaves out the document is for the document in scope when the\n * capability was resolved for one (`ctx.forDocument`, a `<DocumentScope>`), and for the active\n * document otherwise.\n */\nexport interface CommandsCapability extends SettingsApi<CommandsSettings> {\n // ── the commands ──\n /**\n * Add a command while the app runs, and get a function that removes it. A taken id throws\n * `conflict` unless `replace`.\n */\n registerCommand(definition: CommandDefinition, options?: RegisterCommandOptions): Unsubscribe;\n /** `registerCommand` for several definitions; the function removes all of them. */\n registerCommands(\n definitions: readonly CommandDefinition[],\n options?: RegisterCommandOptions,\n ): Unsubscribe;\n /** Whether a command has this id; with a family, every id that starts with its prefix does. */\n hasCommand(id: CommandId): boolean;\n /** A command as you defined it, or `null`. */\n getCommand(id: CommandId): CommandDefinition | null;\n /** Every command's id for the active document, in the order they were added. The same array until one changes. */\n listCommandIds(): readonly CommandId[];\n\n // ── what a button shows ──\n /** A command as a button shows it, or `null` for an unknown id. The same object while nothing about it changed. */\n resolveCommand(id: CommandId, documentId?: string): ResolvedCommand | null;\n /** Every command, resolved, in the order they were added. The same array while nothing changed. */\n listCommands(documentId?: string): readonly ResolvedCommand[];\n /** The visible commands whose label or id contains the query, for a command palette. */\n searchCommands(query: string, documentId?: string): readonly ResolvedCommand[];\n /** Every shortcut with its command, for a keyboard help sheet. The same array until the commands change. */\n listShortcuts(): readonly { readonly commandId: CommandId; readonly shortcut: string }[];\n\n // ── running them ──\n /**\n * Run a command; resolves once its `run` has, with `{ status: 'executed' }` and\n * `onExecuted`, or `{ status: 'rejected', reason }` for a command that is unknown, hidden or\n * disabled (a command turned off is hidden). A `run` that throws fires `onExecutionFailed` and rejects with its `PluginError`;\n * the signal rejects `operation-cancelled`.\n */\n execute(id: CommandId, options?: ExecuteOptions): Promise<ExecuteResult>;\n /** Whether a command can run now: it exists, and is enabled and visible. */\n canExecute(id: CommandId, documentId?: string): boolean;\n /**\n * Why a command won't run whatever the moment: it's turned off, or not allowed for its\n * document. `null` when it may run (or only can't right now), and for an unknown id.\n */\n getRefusal(id: CommandId, documentId?: string): CommandRefusal | null;\n\n // ── turning commands off ──\n /** The categories turned off. */\n getDisabledCategories(): readonly string[];\n /** Whether a category is turned off: it, or a category it's under (`annotations` for `annotations.highlight`). */\n isCategoryDisabled(category: string): boolean;\n /** Turn a category off, with every category under it: the `disabledCategories` setting gains it. */\n disableCategory(category: string): void;\n /** Turn a category on again. */\n enableCategory(category: string): void;\n /** Replace the categories that are off. */\n setDisabledCategories(categories: readonly string[]): void;\n /** The commands turned off one by one. */\n getDisabledCommands(): readonly CommandId[];\n /** Whether a command is turned off: by its id, or through one of its categories. */\n isCommandDisabled(id: CommandId): boolean;\n /** Turn one command off: the `disabledCommands` setting gains it. */\n disableCommand(id: CommandId): void;\n /** Turn a command on again; it stays off while one of its categories is. */\n enableCommand(id: CommandId): void;\n /** Replace the commands that are off one by one. */\n setDisabledCommands(ids: readonly CommandId[]): void;\n\n // ── events ──\n /** A command ran. */\n readonly onExecuted: EventHook<CommandExecutedEvent>;\n /** A command's `run` threw; `execute` rejects with the same error. */\n readonly onExecutionFailed: EventHook<CommandExecutionFailedEvent>;\n}\n"],"mappings":";;;;;AAMA,MAAa,gBAAgB,sBAA0C,YAAY,EACjF,MAAM,6EACR,CAAC;;;;;;;ACoMD,MAAa,yBACX,MACA,UACY;CACZ,IAAI,SAAS,OAAO,OAAO;CAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,OAAO;CAC5B,OACE,KAAK,OAAO,MAAM,MAClB,KAAK,UAAU,MAAM,SACrB,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,YAAY,MAAM,YAAY,WAC/C,KAAK,YAAY,cAAc,MAAM,YAAY,aACjD,KAAK,SAAS,MAAM,QACpB,KAAK,YAAY,MAAM,WACvB,KAAK,WAAW,MAAM,UACtB,KAAK,YAAY,MAAM,WACvB,KAAK,mBAAmB,MAAM,kBAC9B,KAAK,UAAU,WAAW,MAAM,UAAU,UAC1C,KAAK,UAAU,OAAO,UAAU,UAAU,aAAa,MAAM,UAAU,MAAM;AAEjF;;;;;AAMA,MAAa,uBAAuB,QAAoC;CACtE;CACA,OAAO;CACP,WAAW,CAAC;CACZ,SAAS;CACT,QAAQ;CACR,SAAS;CACT,YAAY,CAAC;AACf;;AAGA,MAAa,yBAAyB,IAAe,UACnD,eAAe,GAAG,GAAG,WAAW,IAAI,KAAK,EAAE;;;;;;AAe7C,SAAgB,eACd,SACA,SACA,SACc;CACd,MAAM,CAAC,SAAS,QAAQ;CACxB,OAAO;EACL,GAAG;EACH,WAAW,QAAQ,QAAQ,EAAE;EAC7B,eAAe,UAAU,KAAA,IAAY,OAAO,eAAe,OAAO,EAAE,OAAO,QAAQ,MAAM,CAAC;CAC5F;AACF;;AAgCA,MAAa,oBAAsC;CACjD,UAAU,CAAC;CACX,UAAU,KAAA;CACV,oBAAoB,CAAC;CACrB,kBAAkB,CAAC;CACnB,YAAY;AACd"}
package/dist/contract.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-sqmSSPlP.cjs");
2
+ const require_contract = require("./contract-CgR0waU2.cjs");
3
3
  exports.COMMANDS_DEFAULTS = require_contract.COMMANDS_DEFAULTS;
4
4
  exports.CommandsToken = require_contract.CommandsToken;
5
5
  exports.boundCommandOf = require_contract.boundCommandOf;
@@ -1,2 +1,2 @@
1
- import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDef, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-lGfvyWMG.cjs";
2
- export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
1
+ import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-Bt0jzEeF.cjs";
2
+ export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,2 +1,2 @@
1
- import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDef, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-lGfvyWMG.js";
2
- export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDef, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
1
+ import { C as CommandsToken, S as unregisteredCommand, _ as RegisterCommandOptions, a as CommandExecutedEvent, b as resolvedCommandsEqual, c as CommandId, d as CommandsConfig, f as CommandsSettings, g as NotAllowedMode, h as IconAccent, i as CommandDefinition, l as CommandRefusal, m as ExecuteResult, n as COMMANDS_DEFAULTS, o as CommandExecutionFailedEvent, p as ExecuteOptions, r as CommandContext, s as CommandFamily, t as BoundCommand, u as CommandsCapability, v as ResolvedCommand, x as unknownCommandWarning, y as boundCommandOf } from "./contract-Bt0jzEeF.js";
2
+ export { BoundCommand, COMMANDS_DEFAULTS, CommandContext, CommandDefinition, CommandExecutedEvent, CommandExecutionFailedEvent, CommandFamily, CommandId, CommandRefusal, CommandsCapability, CommandsConfig, CommandsSettings, CommandsToken, ExecuteOptions, ExecuteResult, IconAccent, NotAllowedMode, RegisterCommandOptions, ResolvedCommand, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
package/dist/contract.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "./contract-FbiUhTWC.js";
1
+ import { a as unregisteredCommand, i as unknownCommandWarning, n as boundCommandOf, o as CommandsToken, r as resolvedCommandsEqual, t as COMMANDS_DEFAULTS } from "./contract-DzkHZxi7.js";
2
2
  export { COMMANDS_DEFAULTS, CommandsToken, boundCommandOf, resolvedCommandsEqual, unknownCommandWarning, unregisteredCommand };
@@ -1,4 +1,4 @@
1
- import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-lGfvyWMG.cjs";
1
+ import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-Bt0jzEeF.cjs";
2
2
  import { KeyStroke } from "@embedpdf/core-ui";
3
3
  //#region src/host-contract.d.ts
4
4
  /** The command a keystroke's shortcut names, and why it won't run when it's refused. */
@@ -27,4 +27,4 @@ interface CommandsHostCapability extends CommandsCapability {
27
27
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsHostCapability>;
28
28
  //#endregion
29
29
  export { CommandsToken as n, ShortcutMatch as r, CommandsHostCapability as t };
30
- //# sourceMappingURL=host-contract-Db4TZ_JI.d.cts.map
30
+ //# sourceMappingURL=host-contract-BvjavDn3.d.cts.map
@@ -1,4 +1,4 @@
1
- import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-lGfvyWMG.js";
1
+ import { c as CommandId, l as CommandRefusal, u as CommandsCapability } from "./contract-Bt0jzEeF.js";
2
2
  import { KeyStroke } from "@embedpdf/core-ui";
3
3
  //#region src/host-contract.d.ts
4
4
  /** The command a keystroke's shortcut names, and why it won't run when it's refused. */
@@ -27,4 +27,4 @@ interface CommandsHostCapability extends CommandsCapability {
27
27
  declare const CommandsToken: import("@embedpdf/core").CapabilityToken<CommandsHostCapability>;
28
28
  //#endregion
29
29
  export { CommandsToken as n, ShortcutMatch as r, CommandsHostCapability as t };
30
- //# sourceMappingURL=host-contract-B58WiZ-H.d.ts.map
30
+ //# sourceMappingURL=host-contract-WcBrcWQN.d.ts.map
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-sqmSSPlP.cjs");
2
+ const require_contract = require("./contract-CgR0waU2.cjs");
3
3
  const require_contract_host = require("./contract/host.cjs");
4
4
  let _embedpdf_core = require("@embedpdf/core");
5
5
  let _embedpdf_plugin_i18n_contract = require("@embedpdf/plugin-i18n/contract");
@@ -33,17 +33,31 @@ function configuredCommands(items) {
33
33
  * dotted segments, so `annotations` covers `annotations.highlight` and not `annotationsExtra`.
34
34
  */
35
35
  const isCategoryOff = (category, disabled) => disabled.some((off) => category === off || category.startsWith(`${off}.`));
36
+ /** The values for a label's slots, from `labelParams`; none without it, or when it throws. */
37
+ const labelParamsOf = (definition, context) => {
38
+ if (!definition.labelParams) return void 0;
39
+ try {
40
+ return definition.labelParams(context);
41
+ } catch {
42
+ return;
43
+ }
44
+ };
36
45
  /**
37
46
  * The label: a language's string under the command's id, else under its `labelKey` (the current
38
- * language, then the fallback one), else `label`, else the id. So a string for
39
- * `'document:download'` relabels that one command, whichever key its label is under.
47
+ * language, then the fallback one), else `label`, else the id, with `labelParams` in its slots.
48
+ * So a string for `'document:download'` relabels that one command, whichever key its label is
49
+ * under.
40
50
  */
41
51
  const labelOf = (definition, context) => {
52
+ const params = labelParamsOf(definition, context);
42
53
  const i18n = context.tryGet(_embedpdf_plugin_i18n_contract.I18nToken);
43
- if (!i18n) return definition.label ?? definition.labelKey ?? definition.id;
44
- const fallbackKey = definition.labelKey ? { fallbackKey: definition.labelKey } : {};
45
- return definition.label === void 0 && definition.labelKey ? i18n.t(definition.id, fallbackKey) : i18n.t(definition.id, {
46
- ...fallbackKey,
54
+ if (!i18n) return (0, _embedpdf_plugin_i18n_contract.interpolate)(definition.label ?? definition.labelKey ?? definition.id, params);
55
+ const options = {
56
+ ...definition.labelKey ? { fallbackKey: definition.labelKey } : {},
57
+ ...params ? { params } : {}
58
+ };
59
+ return definition.label === void 0 && definition.labelKey ? i18n.t(definition.id, options) : i18n.t(definition.id, {
60
+ ...options,
47
61
  fallback: definition.label ?? definition.id
48
62
  });
49
63
  };