@embedpdf/plugin-commands 3.0.0-next.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,296 @@
1
+ import { DocumentsToken } from "@embedpdf/core";
2
+ import { AnnotationToken } from "@embedpdf/plugin-annotation/contract";
3
+ import { InteractionToken } from "@embedpdf/plugin-interaction/contract";
4
+ import { RenderToken, SNAPSHOT_TOOL } from "@embedpdf/plugin-render/contract";
5
+ import { SelectionToken } from "@embedpdf/plugin-selection/contract";
6
+ import { StageToken } from "@embedpdf/plugin-stage/contract";
7
+ //#region src/standard.ts
8
+ /**
9
+ * @embedpdf/plugin-commands/standard — the commands every viewer has: zoom,
10
+ * pages, view rotation, a command for every tool, copy, the snapshot, delete,
11
+ * download and print, with shortcuts, and labels in EmbedPDF's eight
12
+ * languages (the i18n plugin has the strings). Some of them reach the browser
13
+ * (the clipboard, a file download), which plugins never touch, so each
14
+ * framework's `/commands` builds them with its platform: that is the
15
+ * `standardCommands` an app imports. Print goes through the kernel, which has
16
+ * the host's printer.
17
+ */
18
+ const stageOf = (context) => context.tryGet(StageToken);
19
+ const snapshotOf = (context) => context.tryGet(RenderToken)?.getSnapshot() ?? null;
20
+ const interactionOf = (context) => context.tryGet(InteractionToken);
21
+ /** Enabled while the document has a Stage. */
22
+ const hasStage = (context) => stageOf(context) !== null;
23
+ /** The ids of a tool list, made once per list, which keeps its identity while the tools don't change. */
24
+ const toolIds = /* @__PURE__ */ new WeakMap();
25
+ const idsOf = (tools) => {
26
+ let ids = toolIds.get(tools);
27
+ if (!ids) {
28
+ ids = tools.map((tool) => tool.id);
29
+ toolIds.set(tools, ids);
30
+ }
31
+ return ids;
32
+ };
33
+ /**
34
+ * Whether the user may use a tool: one that draws annotations needs permission to create them.
35
+ * A tool another plugin owns asks nothing here; that plugin refuses its own gesture.
36
+ */
37
+ const mayUseTool = (context, toolId) => {
38
+ const annotation = context.tryGet(AnnotationToken);
39
+ return !annotation?.tools.get(toolId) || annotation.canCreate();
40
+ };
41
+ /** Switching to a tool: active while it's the tool, there only when the document has it. */
42
+ const toolCommand = (toolId) => ({
43
+ labelKey: `commands.tool.${toolId}`,
44
+ label: toolId,
45
+ icon: toolId,
46
+ categories: ["tool"],
47
+ run: (context) => interactionOf(context)?.activateTool(toolId),
48
+ active: (context) => interactionOf(context)?.getActiveToolId() === toolId,
49
+ visible: (context) => interactionOf(context)?.hasTool(toolId) ?? false,
50
+ enabled: (context) => mayUseTool(context, toolId)
51
+ });
52
+ /** `tool:<id>` for every tool the document has. */
53
+ const toolCommands = {
54
+ prefix: "tool:",
55
+ names: (context) => {
56
+ const interaction = interactionOf(context);
57
+ return interaction ? idsOf(interaction.listTools()) : [];
58
+ },
59
+ command: toolCommand
60
+ };
61
+ /** The standard commands, with the browser's part from `platform`. */
62
+ function createStandardCommands(platform) {
63
+ return [
64
+ {
65
+ id: "zoom:in",
66
+ labelKey: "commands.zoom.in",
67
+ label: "Zoom in",
68
+ icon: "zoom-in",
69
+ shortcut: ["Mod+=", "Mod+NumpadAdd"],
70
+ categories: ["zoom"],
71
+ run: (context) => stageOf(context)?.zoomIn(),
72
+ enabled: (context) => stageOf(context)?.canZoomIn() ?? false
73
+ },
74
+ {
75
+ id: "zoom:out",
76
+ labelKey: "commands.zoom.out",
77
+ label: "Zoom out",
78
+ icon: "zoom-out",
79
+ shortcut: ["Mod+-", "Mod+NumpadSubtract"],
80
+ categories: ["zoom"],
81
+ run: (context) => stageOf(context)?.zoomOut(),
82
+ enabled: (context) => stageOf(context)?.canZoomOut() ?? false
83
+ },
84
+ {
85
+ id: "zoom:fit-width",
86
+ labelKey: "commands.zoom.fitWidth",
87
+ label: "Fit width",
88
+ icon: "fit-width",
89
+ categories: ["zoom"],
90
+ run: (context) => stageOf(context)?.fitWidth(),
91
+ active: (context) => stageOf(context)?.getZoomMode() === "fit-width",
92
+ enabled: hasStage
93
+ },
94
+ {
95
+ id: "zoom:fit-page",
96
+ labelKey: "commands.zoom.fitPage",
97
+ label: "Fit page",
98
+ icon: "fit-page",
99
+ categories: ["zoom"],
100
+ run: (context) => stageOf(context)?.fitPage(),
101
+ active: (context) => stageOf(context)?.getZoomMode() === "fit-page",
102
+ enabled: hasStage
103
+ },
104
+ {
105
+ id: "page:next",
106
+ labelKey: "commands.page.next",
107
+ label: "Next page",
108
+ icon: "next-page",
109
+ shortcut: "ArrowRight",
110
+ categories: ["page"],
111
+ run: (context) => stageOf(context)?.nextPage(),
112
+ enabled: (context) => stageOf(context)?.canGoNext() ?? false
113
+ },
114
+ {
115
+ id: "page:previous",
116
+ labelKey: "commands.page.previous",
117
+ label: "Previous page",
118
+ icon: "previous-page",
119
+ shortcut: "ArrowLeft",
120
+ categories: ["page"],
121
+ run: (context) => stageOf(context)?.previousPage(),
122
+ enabled: (context) => stageOf(context)?.canGoPrevious() ?? false
123
+ },
124
+ {
125
+ id: "page:first",
126
+ labelKey: "commands.page.first",
127
+ label: "First page",
128
+ icon: "first-page",
129
+ shortcut: "Home",
130
+ categories: ["page"],
131
+ run: (context) => stageOf(context)?.goToFirstPage(),
132
+ enabled: (context) => stageOf(context)?.canGoPrevious() ?? false
133
+ },
134
+ {
135
+ id: "page:last",
136
+ labelKey: "commands.page.last",
137
+ label: "Last page",
138
+ icon: "last-page",
139
+ shortcut: "End",
140
+ categories: ["page"],
141
+ run: (context) => stageOf(context)?.goToLastPage(),
142
+ enabled: (context) => stageOf(context)?.canGoNext() ?? false
143
+ },
144
+ {
145
+ id: "view:rotate-clockwise",
146
+ labelKey: "commands.view.rotateClockwise",
147
+ label: "Rotate clockwise",
148
+ icon: "rotate-clockwise",
149
+ categories: ["view"],
150
+ run: (context) => stageOf(context)?.rotateViewBy(90),
151
+ enabled: hasStage
152
+ },
153
+ {
154
+ id: "view:rotate-counterclockwise",
155
+ labelKey: "commands.view.rotateCounterclockwise",
156
+ label: "Rotate counterclockwise",
157
+ icon: "rotate-counterclockwise",
158
+ categories: ["view"],
159
+ run: (context) => stageOf(context)?.rotateViewBy(-90),
160
+ enabled: hasStage
161
+ },
162
+ {
163
+ ...toolCommand("pointer"),
164
+ id: "tool:pointer",
165
+ shortcut: "V"
166
+ },
167
+ {
168
+ ...toolCommand("pan"),
169
+ id: "tool:pan",
170
+ shortcut: "H"
171
+ },
172
+ {
173
+ ...toolCommand("zoom"),
174
+ id: "tool:zoom",
175
+ shortcut: "Z"
176
+ },
177
+ {
178
+ ...toolCommand(SNAPSHOT_TOOL),
179
+ id: "tool:snapshot",
180
+ allowed: (context) => context.tryGet(RenderToken)?.canSnapshot() ?? true,
181
+ notAllowedKey: "commands.notAllowed.doc-content-copy"
182
+ },
183
+ toolCommands,
184
+ {
185
+ id: "selection:copy",
186
+ labelKey: "commands.selection.copy",
187
+ label: "Copy",
188
+ icon: "copy",
189
+ shortcut: "Mod+C",
190
+ categories: ["selection"],
191
+ run: (context) => platform.copySelection(context.get(SelectionToken)),
192
+ enabled: (context) => {
193
+ const selection = context.tryGet(SelectionToken);
194
+ return !!selection && selection.hasSelection() && selection.canCopy();
195
+ }
196
+ },
197
+ {
198
+ id: "annotation:delete",
199
+ labelKey: "commands.annotation.delete",
200
+ label: "Delete",
201
+ icon: "delete",
202
+ shortcut: ["Delete", "Backspace"],
203
+ categories: ["annotation"],
204
+ run: (context) => context.get(AnnotationToken).selection.delete({ signal: context.signal }),
205
+ enabled: (context) => {
206
+ const annotation = context.tryGet(AnnotationToken);
207
+ if (!annotation) return false;
208
+ const selected = annotation.selection.getSelected();
209
+ return selected.length > 0 && selected.every(({ ref }) => annotation.canDelete(ref) && annotation.isEditable(ref));
210
+ }
211
+ },
212
+ {
213
+ id: "snapshot:copy",
214
+ labelKey: "commands.snapshot.copy",
215
+ label: "Copy",
216
+ icon: "copy",
217
+ shortcut: "Mod+C",
218
+ categories: ["snapshot"],
219
+ run: (context) => {
220
+ const snapshot = snapshotOf(context);
221
+ return snapshot ? platform.copyImage(snapshot.image) : void 0;
222
+ },
223
+ enabled: (context) => snapshotOf(context) !== null
224
+ },
225
+ {
226
+ id: "snapshot:save",
227
+ labelKey: "commands.snapshot.save",
228
+ label: "Save image",
229
+ icon: "download",
230
+ categories: ["snapshot"],
231
+ run: async (context) => {
232
+ const snapshot = snapshotOf(context);
233
+ if (!snapshot) return;
234
+ const documents = context.get(DocumentsToken);
235
+ const id = context.documentId ?? void 0;
236
+ const blob = await (await snapshot.image).blob();
237
+ const number = documents.listPages(id).findIndex((page) => page.ref.objectNumber === snapshot.page.objectNumber) + 1;
238
+ platform.saveFile(blob, snapshotFileNameOf(documents.get(id)?.name, number), "image/png");
239
+ },
240
+ enabled: (context) => snapshotOf(context) !== null
241
+ },
242
+ {
243
+ id: "snapshot:clear",
244
+ labelKey: "commands.snapshot.clear",
245
+ label: "Clear snapshot",
246
+ shortcut: "Escape",
247
+ categories: ["snapshot"],
248
+ run: (context) => context.get(RenderToken).clearSnapshot(),
249
+ enabled: (context) => snapshotOf(context) !== null
250
+ },
251
+ {
252
+ id: "document:download",
253
+ labelKey: "commands.document.download",
254
+ label: "Download",
255
+ icon: "download",
256
+ shortcut: "Mod+S",
257
+ categories: ["document"],
258
+ allowed: (context) => context.tryGet(DocumentsToken)?.canDownload() ?? true,
259
+ notAllowedKey: "commands.notAllowed.doc-download",
260
+ run: async (context) => {
261
+ const documents = context.get(DocumentsToken);
262
+ const id = context.documentId ?? void 0;
263
+ const bytes = await documents.download(id, { signal: context.signal });
264
+ platform.saveFile(bytes, fileNameOf(documents.get(id)?.name), "application/pdf");
265
+ },
266
+ enabled: (context) => context.documentId !== null
267
+ },
268
+ {
269
+ id: "document:print",
270
+ labelKey: "commands.document.print",
271
+ label: "Print",
272
+ icon: "print",
273
+ shortcut: "Mod+P",
274
+ categories: ["document"],
275
+ allowed: (context) => context.tryGet(DocumentsToken)?.canPrint() ?? true,
276
+ notAllowedKey: "commands.notAllowed.doc-print",
277
+ run: async (context) => {
278
+ await context.get(DocumentsToken).print(context.documentId ?? void 0, { signal: context.signal });
279
+ },
280
+ enabled: (context) => context.documentId !== null
281
+ }
282
+ ];
283
+ }
284
+ /** The download's file name: the document's name, ending in `.pdf`. */
285
+ function fileNameOf(name) {
286
+ if (!name) return "document.pdf";
287
+ return /\.pdf$/i.test(name) ? name : `${name}.pdf`;
288
+ }
289
+ /** A snapshot's file name: the document's name and the page's number, as a PNG (`Report p3.png`). */
290
+ function snapshotFileNameOf(name, pageNumber) {
291
+ return `${(name ?? "document").replace(/\.pdf$/i, "")} p${pageNumber}.png`;
292
+ }
293
+ //#endregion
294
+ export { createStandardCommands };
295
+
296
+ //# sourceMappingURL=standard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.js","names":[],"sources":["../src/standard.ts"],"sourcesContent":["/**\n * @embedpdf/plugin-commands/standard — the commands every viewer has: zoom,\n * pages, view rotation, a command for every tool, copy, the snapshot, delete,\n * download and print, with shortcuts, and labels in EmbedPDF's eight\n * languages (the i18n plugin has the strings). Some of them reach the browser\n * (the clipboard, a file download), which plugins never touch, so each\n * framework's `/commands` builds them with its platform: that is the\n * `standardCommands` an app imports. Print goes through the kernel, which has\n * the host's printer.\n */\nimport { DocumentsToken } from '@embedpdf/core';\nimport { AnnotationToken } from '@embedpdf/plugin-annotation/contract';\nimport { InteractionToken, type Tool } from '@embedpdf/plugin-interaction/contract';\nimport { RenderToken, SNAPSHOT_TOOL, type PageImage } from '@embedpdf/plugin-render/contract';\nimport { SelectionToken, type SelectionCapability } from '@embedpdf/plugin-selection/contract';\nimport { StageToken } from '@embedpdf/plugin-stage/contract';\n\nimport type { CommandContext, CommandDefinition, CommandFamily } from './contract';\n\n/** What the standard commands need from the browser. */\nexport interface StandardCommandsPlatform {\n /** Copy the selected text to the clipboard. */\n copySelection(selection: SelectionCapability): Promise<unknown>;\n /**\n * Copy an image to the clipboard. Called in the press or key itself, before\n * the image is there: a browser may take the clipboard only then.\n */\n copyImage(image: Promise<PageImage>): Promise<unknown>;\n /** Give the user the bytes as a file download, of the given content type. */\n saveFile(bytes: Uint8Array | Blob, fileName: string, contentType: string): void;\n}\n\nconst stageOf = (context: CommandContext) => context.tryGet(StageToken);\nconst snapshotOf = (context: CommandContext) => context.tryGet(RenderToken)?.getSnapshot() ?? null;\nconst interactionOf = (context: CommandContext) => context.tryGet(InteractionToken);\n\n/** Enabled while the document has a Stage. */\nconst hasStage = (context: CommandContext): boolean => stageOf(context) !== null;\n\n/** The ids of a tool list, made once per list, which keeps its identity while the tools don't change. */\nconst toolIds = new WeakMap<readonly Tool[], readonly string[]>();\nconst idsOf = (tools: readonly Tool[]): readonly string[] => {\n let ids = toolIds.get(tools);\n if (!ids) {\n ids = tools.map((tool) => tool.id);\n toolIds.set(tools, ids);\n }\n return ids;\n};\n\n/**\n * Whether the user may use a tool: one that draws annotations needs permission to create them.\n * A tool another plugin owns asks nothing here; that plugin refuses its own gesture.\n */\nconst mayUseTool = (context: CommandContext, toolId: string): boolean => {\n const annotation = context.tryGet(AnnotationToken);\n return !annotation?.tools.get(toolId) || annotation.canCreate();\n};\n\n/** Switching to a tool: active while it's the tool, there only when the document has it. */\nconst toolCommand = (toolId: string): Omit<CommandDefinition, 'id' | 'shortcut'> => ({\n labelKey: `commands.tool.${toolId}`,\n label: toolId,\n icon: toolId,\n categories: ['tool'],\n run: (context) => interactionOf(context)?.activateTool(toolId),\n active: (context) => interactionOf(context)?.getActiveToolId() === toolId,\n visible: (context) => interactionOf(context)?.hasTool(toolId) ?? false,\n enabled: (context) => mayUseTool(context, toolId),\n});\n\n/** `tool:<id>` for every tool the document has. */\nconst toolCommands: CommandFamily = {\n prefix: 'tool:',\n names: (context) => {\n const interaction = interactionOf(context);\n return interaction ? idsOf(interaction.listTools()) : [];\n },\n command: toolCommand,\n};\n\n/** The standard commands, with the browser's part from `platform`. */\nexport function createStandardCommands(\n platform: StandardCommandsPlatform,\n): readonly (CommandDefinition | CommandFamily)[] {\n return [\n // ── zoom ──\n {\n id: 'zoom:in',\n labelKey: 'commands.zoom.in',\n label: 'Zoom in',\n icon: 'zoom-in',\n shortcut: ['Mod+=', 'Mod+NumpadAdd'],\n categories: ['zoom'],\n run: (context) => stageOf(context)?.zoomIn(),\n enabled: (context) => stageOf(context)?.canZoomIn() ?? false,\n },\n {\n id: 'zoom:out',\n labelKey: 'commands.zoom.out',\n label: 'Zoom out',\n icon: 'zoom-out',\n shortcut: ['Mod+-', 'Mod+NumpadSubtract'],\n categories: ['zoom'],\n run: (context) => stageOf(context)?.zoomOut(),\n enabled: (context) => stageOf(context)?.canZoomOut() ?? false,\n },\n {\n id: 'zoom:fit-width',\n labelKey: 'commands.zoom.fitWidth',\n label: 'Fit width',\n icon: 'fit-width',\n categories: ['zoom'],\n run: (context) => stageOf(context)?.fitWidth(),\n active: (context) => stageOf(context)?.getZoomMode() === 'fit-width',\n enabled: hasStage,\n },\n {\n id: 'zoom:fit-page',\n labelKey: 'commands.zoom.fitPage',\n label: 'Fit page',\n icon: 'fit-page',\n categories: ['zoom'],\n run: (context) => stageOf(context)?.fitPage(),\n active: (context) => stageOf(context)?.getZoomMode() === 'fit-page',\n enabled: hasStage,\n },\n\n // ── pages ──\n {\n id: 'page:next',\n labelKey: 'commands.page.next',\n label: 'Next page',\n icon: 'next-page',\n shortcut: 'ArrowRight',\n categories: ['page'],\n run: (context) => stageOf(context)?.nextPage(),\n enabled: (context) => stageOf(context)?.canGoNext() ?? false,\n },\n {\n id: 'page:previous',\n labelKey: 'commands.page.previous',\n label: 'Previous page',\n icon: 'previous-page',\n shortcut: 'ArrowLeft',\n categories: ['page'],\n run: (context) => stageOf(context)?.previousPage(),\n enabled: (context) => stageOf(context)?.canGoPrevious() ?? false,\n },\n {\n id: 'page:first',\n labelKey: 'commands.page.first',\n label: 'First page',\n icon: 'first-page',\n shortcut: 'Home',\n categories: ['page'],\n run: (context) => stageOf(context)?.goToFirstPage(),\n enabled: (context) => stageOf(context)?.canGoPrevious() ?? false,\n },\n {\n id: 'page:last',\n labelKey: 'commands.page.last',\n label: 'Last page',\n icon: 'last-page',\n shortcut: 'End',\n categories: ['page'],\n run: (context) => stageOf(context)?.goToLastPage(),\n enabled: (context) => stageOf(context)?.canGoNext() ?? false,\n },\n\n // ── view rotation: how the pages show, nothing written to the PDF ──\n {\n id: 'view:rotate-clockwise',\n labelKey: 'commands.view.rotateClockwise',\n label: 'Rotate clockwise',\n icon: 'rotate-clockwise',\n categories: ['view'],\n run: (context) => stageOf(context)?.rotateViewBy(90),\n enabled: hasStage,\n },\n {\n id: 'view:rotate-counterclockwise',\n labelKey: 'commands.view.rotateCounterclockwise',\n label: 'Rotate counterclockwise',\n icon: 'rotate-counterclockwise',\n categories: ['view'],\n run: (context) => stageOf(context)?.rotateViewBy(-90),\n enabled: hasStage,\n },\n\n // ── tools: the built-in ones have Acrobat's single keys; the family covers every other ──\n { ...toolCommand('pointer'), id: 'tool:pointer', shortcut: 'V' },\n { ...toolCommand('pan'), id: 'tool:pan', shortcut: 'H' },\n { ...toolCommand('zoom'), id: 'tool:zoom', shortcut: 'Z' },\n {\n ...toolCommand(SNAPSHOT_TOOL),\n id: 'tool:snapshot',\n allowed: (context) => context.tryGet(RenderToken)?.canSnapshot() ?? true,\n notAllowedKey: 'commands.notAllowed.doc-content-copy',\n },\n toolCommands,\n\n // ── selections ──\n {\n id: 'selection:copy',\n labelKey: 'commands.selection.copy',\n label: 'Copy',\n icon: 'copy',\n shortcut: 'Mod+C',\n categories: ['selection'],\n run: (context) => platform.copySelection(context.get(SelectionToken)),\n // `canCopy()` in `enabled`, not `allowed`: a refused command keeps its keys, and Mod+C\n // with nothing selected in the viewer belongs to the page. The clipboard wiring says\n // when a selection may not be copied.\n enabled: (context) => {\n const selection = context.tryGet(SelectionToken);\n return !!selection && selection.hasSelection() && selection.canCopy();\n },\n },\n {\n id: 'annotation:delete',\n labelKey: 'commands.annotation.delete',\n label: 'Delete',\n icon: 'delete',\n shortcut: ['Delete', 'Backspace'],\n categories: ['annotation'],\n run: (context) => context.get(AnnotationToken).selection.delete({ signal: context.signal }),\n enabled: (context) => {\n const annotation = context.tryGet(AnnotationToken);\n if (!annotation) return false;\n const selected = annotation.selection.getSelected();\n // `isEditable`: the annotation plugin's `editable` setting lets people change it by hand.\n return (\n selected.length > 0 &&\n selected.every(({ ref }) => annotation.canDelete(ref) && annotation.isEditable(ref))\n );\n },\n },\n\n // ── the snapshot the snapshot tool holds ──\n {\n id: 'snapshot:copy',\n labelKey: 'commands.snapshot.copy',\n label: 'Copy',\n icon: 'copy',\n shortcut: 'Mod+C',\n categories: ['snapshot'],\n // Straight to the clipboard, in the press itself: the picture follows when it's there.\n run: (context) => {\n const snapshot = snapshotOf(context);\n return snapshot ? platform.copyImage(snapshot.image) : undefined;\n },\n enabled: (context) => snapshotOf(context) !== null,\n },\n {\n id: 'snapshot:save',\n labelKey: 'commands.snapshot.save',\n label: 'Save image',\n icon: 'download',\n categories: ['snapshot'],\n run: async (context) => {\n const snapshot = snapshotOf(context);\n if (!snapshot) return;\n const documents = context.get(DocumentsToken);\n const id = context.documentId ?? undefined;\n const blob = await (await snapshot.image).blob();\n const number =\n documents\n .listPages(id)\n .findIndex((page) => page.ref.objectNumber === snapshot.page.objectNumber) + 1;\n platform.saveFile(blob, snapshotFileNameOf(documents.get(id)?.name, number), 'image/png');\n },\n enabled: (context) => snapshotOf(context) !== null,\n },\n {\n id: 'snapshot:clear',\n labelKey: 'commands.snapshot.clear',\n label: 'Clear snapshot',\n shortcut: 'Escape',\n categories: ['snapshot'],\n run: (context) => context.get(RenderToken).clearSnapshot(),\n enabled: (context) => snapshotOf(context) !== null,\n },\n\n // ── the document ──\n {\n id: 'document:download',\n labelKey: 'commands.document.download',\n label: 'Download',\n icon: 'download',\n shortcut: 'Mod+S',\n categories: ['document'],\n allowed: (context) => context.tryGet(DocumentsToken)?.canDownload() ?? true,\n notAllowedKey: 'commands.notAllowed.doc-download',\n run: async (context) => {\n const documents = context.get(DocumentsToken);\n const id = context.documentId ?? undefined;\n const bytes = await documents.download(id, { signal: context.signal });\n platform.saveFile(bytes, fileNameOf(documents.get(id)?.name), 'application/pdf');\n },\n enabled: (context) => context.documentId !== null,\n },\n {\n id: 'document:print',\n labelKey: 'commands.document.print',\n label: 'Print',\n icon: 'print',\n shortcut: 'Mod+P',\n categories: ['document'],\n allowed: (context) => context.tryGet(DocumentsToken)?.canPrint() ?? true,\n notAllowedKey: 'commands.notAllowed.doc-print',\n // The kernel prints the document's pages, and runs the document's own\n // print actions around the dialog when the actions plugin is there.\n run: async (context) => {\n const documents = context.get(DocumentsToken);\n await documents.print(context.documentId ?? undefined, { signal: context.signal });\n },\n enabled: (context) => context.documentId !== null,\n },\n ];\n}\n\n/** The download's file name: the document's name, ending in `.pdf`. */\nfunction fileNameOf(name: string | undefined): string {\n if (!name) return 'document.pdf';\n return /\\.pdf$/i.test(name) ? name : `${name}.pdf`;\n}\n\n/** A snapshot's file name: the document's name and the page's number, as a PNG (`Report p3.png`). */\nfunction snapshotFileNameOf(name: string | undefined, pageNumber: number): string {\n const base = (name ?? 'document').replace(/\\.pdf$/i, '');\n return `${base} p${pageNumber}.png`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,WAAW,YAA4B,QAAQ,OAAO,UAAU;AACtE,MAAM,cAAc,YAA4B,QAAQ,OAAO,WAAW,CAAC,EAAE,YAAY,KAAK;AAC9F,MAAM,iBAAiB,YAA4B,QAAQ,OAAO,gBAAgB;;AAGlF,MAAM,YAAY,YAAqC,QAAQ,OAAO,MAAM;;AAG5E,MAAM,0BAAU,IAAI,QAA4C;AAChE,MAAM,SAAS,UAA8C;CAC3D,IAAI,MAAM,QAAQ,IAAI,KAAK;CAC3B,IAAI,CAAC,KAAK;EACR,MAAM,MAAM,KAAK,SAAS,KAAK,EAAE;EACjC,QAAQ,IAAI,OAAO,GAAG;CACxB;CACA,OAAO;AACT;;;;;AAMA,MAAM,cAAc,SAAyB,WAA4B;CACvE,MAAM,aAAa,QAAQ,OAAO,eAAe;CACjD,OAAO,CAAC,YAAY,MAAM,IAAI,MAAM,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AAc,CAAC,EAAE,SAAS,KAAK;GACpE,eAAe;GAGf,KAAK,OAAO,YAAY;IAEtB,MADkB,QAAQ,IAAI,cAChB,CAAC,CAAC,MAAM,QAAQ,cAAc,KAAA,GAAW,EAAE,QAAQ,QAAQ,OAAO,CAAC;GACnF;GACA,UAAU,YAAY,QAAQ,eAAe;EAC/C;CACF;AACF;;AAGA,SAAS,WAAW,MAAkC;CACpD,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK;AAC/C;;AAGA,SAAS,mBAAmB,MAA0B,YAA4B;CAEhF,OAAO,IADO,QAAQ,WAAA,CAAY,QAAQ,WAAW,EACxC,EAAE,IAAI,WAAW;AAChC"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-commands",
3
- "version": "3.0.0-next.8",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
- "description": "The command registry: the single vocabulary of verbs. Definitions are app content (mechanism/content split); state (label · icon · enabled · active · visible) derives purely from other capabilities, so every consumer is reactive through the kernel's one change stream — no events, no diffing.",
5
+ "description": "The commands: one name per action of the viewer, with its label, icon, state and shortcut, which toolbars, menus, a command palette and the keyboard all show and run. A command's state is read from live state, so every reader follows the kernel's one change stream. `/standard` has the commands every viewer has.",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.js",
@@ -12,16 +12,33 @@
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
14
  },
15
+ "./contract": {
16
+ "import": "./dist/contract.js",
17
+ "require": "./dist/contract.cjs"
18
+ },
19
+ "./contract/host": {
20
+ "import": "./dist/contract/host.js",
21
+ "require": "./dist/contract/host.cjs"
22
+ },
23
+ "./standard": {
24
+ "import": "./dist/standard.js",
25
+ "require": "./dist/standard.cjs"
26
+ },
15
27
  "./package.json": "./package.json"
16
28
  },
17
29
  "files": [
18
30
  "dist"
19
31
  ],
20
32
  "dependencies": {
21
- "@embedpdf/core": "3.0.0-next.8",
22
- "@embedpdf/plugin-i18n": "3.0.0-next.8",
23
- "@embedpdf/plugin-shell": "3.0.0-next.8",
24
- "@embedpdf/core-ui": "3.0.0-next.8"
33
+ "@embedpdf/core-ui": "3.0.0",
34
+ "@embedpdf/core": "3.0.0",
35
+ "@embedpdf/plugin-annotation": "3.0.0",
36
+ "@embedpdf/plugin-interaction": "3.0.0",
37
+ "@embedpdf/plugin-shell": "3.0.0",
38
+ "@embedpdf/plugin-stage": "3.0.0",
39
+ "@embedpdf/plugin-render": "3.0.0",
40
+ "@embedpdf/plugin-i18n": "3.0.0",
41
+ "@embedpdf/plugin-selection": "3.0.0"
25
42
  },
26
43
  "devDependencies": {
27
44
  "typescript": "^5.0.0",