@embedpdf/plugin-commands 3.0.0-next.13 → 3.0.0-next.15

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,242 @@
1
+ import { DocumentsToken } from "@embedpdf/core";
2
+ import { ActionsToken } from "@embedpdf/plugin-actions/contract";
3
+ import { AnnotationToken } from "@embedpdf/plugin-annotation/contract";
4
+ import { InteractionToken } from "@embedpdf/plugin-interaction/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, delete, download and
11
+ * print, with shortcuts, and labels in EmbedPDF's eight languages (the i18n
12
+ * plugin has the strings). Three of them reach the browser (the clipboard, a
13
+ * file download, the print dialog), which plugins never touch, so each
14
+ * framework's `/commands` builds them with its platform: that is the
15
+ * `standardCommands` an app imports.
16
+ */
17
+ const stageOf = (context) => context.tryGet(StageToken);
18
+ const interactionOf = (context) => context.tryGet(InteractionToken);
19
+ /** Enabled while the document has a Stage. */
20
+ const hasStage = (context) => stageOf(context) !== null;
21
+ /** The ids of a tool list, made once per list, which keeps its identity while the tools don't change. */
22
+ const toolIds = /* @__PURE__ */ new WeakMap();
23
+ const idsOf = (tools) => {
24
+ let ids = toolIds.get(tools);
25
+ if (!ids) {
26
+ ids = tools.map((tool) => tool.id);
27
+ toolIds.set(tools, ids);
28
+ }
29
+ return ids;
30
+ };
31
+ /**
32
+ * Whether the user may use a tool: one that draws annotations needs permission to create them.
33
+ * A tool another plugin owns asks nothing here; that plugin refuses its own gesture.
34
+ */
35
+ const mayUseTool = (context, toolId) => {
36
+ const annotation = context.tryGet(AnnotationToken);
37
+ return !annotation?.tools.get(toolId) || annotation.canCreate();
38
+ };
39
+ /** Switching to a tool: active while it's the tool, there only when the document has it. */
40
+ const toolCommand = (toolId) => ({
41
+ labelKey: `commands.tool.${toolId}`,
42
+ label: toolId,
43
+ icon: toolId,
44
+ categories: ["tool"],
45
+ run: (context) => interactionOf(context)?.activateTool(toolId),
46
+ active: (context) => interactionOf(context)?.getActiveToolId() === toolId,
47
+ visible: (context) => interactionOf(context)?.hasTool(toolId) ?? false,
48
+ enabled: (context) => mayUseTool(context, toolId)
49
+ });
50
+ /** `tool:<id>` for every tool the document has. */
51
+ const toolCommands = {
52
+ prefix: "tool:",
53
+ names: (context) => {
54
+ const interaction = interactionOf(context);
55
+ return interaction ? idsOf(interaction.listTools()) : [];
56
+ },
57
+ command: toolCommand
58
+ };
59
+ /** The standard commands, with the browser's part from `platform`. */
60
+ function createStandardCommands(platform) {
61
+ return [
62
+ {
63
+ id: "zoom:in",
64
+ labelKey: "commands.zoom.in",
65
+ label: "Zoom in",
66
+ icon: "zoom-in",
67
+ shortcut: ["Mod+=", "Mod+NumpadAdd"],
68
+ categories: ["zoom"],
69
+ run: (context) => stageOf(context)?.zoomIn(),
70
+ enabled: hasStage
71
+ },
72
+ {
73
+ id: "zoom:out",
74
+ labelKey: "commands.zoom.out",
75
+ label: "Zoom out",
76
+ icon: "zoom-out",
77
+ shortcut: ["Mod+-", "Mod+NumpadSubtract"],
78
+ categories: ["zoom"],
79
+ run: (context) => stageOf(context)?.zoomOut(),
80
+ enabled: hasStage
81
+ },
82
+ {
83
+ id: "zoom:fit-width",
84
+ labelKey: "commands.zoom.fitWidth",
85
+ label: "Fit width",
86
+ icon: "fit-width",
87
+ categories: ["zoom"],
88
+ run: (context) => stageOf(context)?.fitWidth(),
89
+ active: (context) => stageOf(context)?.getZoomMode() === "fit-width",
90
+ enabled: hasStage
91
+ },
92
+ {
93
+ id: "zoom:fit-page",
94
+ labelKey: "commands.zoom.fitPage",
95
+ label: "Fit page",
96
+ icon: "fit-page",
97
+ categories: ["zoom"],
98
+ run: (context) => stageOf(context)?.fitPage(),
99
+ active: (context) => stageOf(context)?.getZoomMode() === "fit-page",
100
+ enabled: hasStage
101
+ },
102
+ {
103
+ id: "page:next",
104
+ labelKey: "commands.page.next",
105
+ label: "Next page",
106
+ icon: "next-page",
107
+ shortcut: "ArrowRight",
108
+ categories: ["page"],
109
+ run: (context) => stageOf(context)?.nextPage(),
110
+ enabled: (context) => stageOf(context)?.canGoNext() ?? false
111
+ },
112
+ {
113
+ id: "page:previous",
114
+ labelKey: "commands.page.previous",
115
+ label: "Previous page",
116
+ icon: "previous-page",
117
+ shortcut: "ArrowLeft",
118
+ categories: ["page"],
119
+ run: (context) => stageOf(context)?.previousPage(),
120
+ enabled: (context) => stageOf(context)?.canGoPrevious() ?? false
121
+ },
122
+ {
123
+ id: "page:first",
124
+ labelKey: "commands.page.first",
125
+ label: "First page",
126
+ icon: "first-page",
127
+ shortcut: "Home",
128
+ categories: ["page"],
129
+ run: (context) => stageOf(context)?.goToFirstPage(),
130
+ enabled: (context) => stageOf(context)?.canGoPrevious() ?? false
131
+ },
132
+ {
133
+ id: "page:last",
134
+ labelKey: "commands.page.last",
135
+ label: "Last page",
136
+ icon: "last-page",
137
+ shortcut: "End",
138
+ categories: ["page"],
139
+ run: (context) => stageOf(context)?.goToLastPage(),
140
+ enabled: (context) => stageOf(context)?.canGoNext() ?? false
141
+ },
142
+ {
143
+ id: "view:rotate-clockwise",
144
+ labelKey: "commands.view.rotateClockwise",
145
+ label: "Rotate clockwise",
146
+ icon: "rotate-clockwise",
147
+ categories: ["view"],
148
+ run: (context) => stageOf(context)?.rotateViewBy(90),
149
+ enabled: hasStage
150
+ },
151
+ {
152
+ id: "view:rotate-counterclockwise",
153
+ labelKey: "commands.view.rotateCounterclockwise",
154
+ label: "Rotate counterclockwise",
155
+ icon: "rotate-counterclockwise",
156
+ categories: ["view"],
157
+ run: (context) => stageOf(context)?.rotateViewBy(-90),
158
+ enabled: hasStage
159
+ },
160
+ {
161
+ ...toolCommand("pointer"),
162
+ id: "tool:pointer",
163
+ shortcut: "V"
164
+ },
165
+ {
166
+ ...toolCommand("pan"),
167
+ id: "tool:pan",
168
+ shortcut: "H"
169
+ },
170
+ toolCommands,
171
+ {
172
+ id: "selection:copy",
173
+ labelKey: "commands.selection.copy",
174
+ label: "Copy",
175
+ icon: "copy",
176
+ shortcut: "Mod+C",
177
+ categories: ["selection"],
178
+ run: (context) => platform.copySelection(context.get(SelectionToken)),
179
+ enabled: (context) => {
180
+ const selection = context.tryGet(SelectionToken);
181
+ return !!selection && selection.hasSelection() && selection.canCopy();
182
+ }
183
+ },
184
+ {
185
+ id: "annotation:delete",
186
+ labelKey: "commands.annotation.delete",
187
+ label: "Delete",
188
+ icon: "delete",
189
+ shortcut: ["Delete", "Backspace"],
190
+ categories: ["annotation"],
191
+ run: (context) => context.get(AnnotationToken).selection.delete({ signal: context.signal }),
192
+ enabled: (context) => {
193
+ const annotation = context.tryGet(AnnotationToken);
194
+ if (!annotation) return false;
195
+ const selected = annotation.selection.list();
196
+ return selected.length > 0 && selected.every(({ ref }) => annotation.canDelete(ref) && annotation.isEditable(ref));
197
+ }
198
+ },
199
+ {
200
+ id: "document:download",
201
+ labelKey: "commands.document.download",
202
+ label: "Download",
203
+ icon: "download",
204
+ shortcut: "Mod+S",
205
+ categories: ["document"],
206
+ allowed: (context) => context.tryGet(DocumentsToken)?.canDownload() ?? true,
207
+ notAllowedKey: "commands.notAllowed.doc-download",
208
+ run: async (context) => {
209
+ const documents = context.get(DocumentsToken);
210
+ const id = context.documentId ?? void 0;
211
+ const bytes = await documents.download(id, { signal: context.signal });
212
+ platform.saveFile(bytes, fileNameOf(documents.get(id)?.name));
213
+ },
214
+ enabled: (context) => context.documentId !== null
215
+ },
216
+ {
217
+ id: "document:print",
218
+ labelKey: "commands.document.print",
219
+ label: "Print",
220
+ icon: "print",
221
+ shortcut: "Mod+P",
222
+ categories: ["document"],
223
+ allowed: (context) => context.tryGet(DocumentsToken)?.canPrint() ?? true,
224
+ notAllowedKey: "commands.notAllowed.doc-print",
225
+ run: (context) => {
226
+ const actions = context.tryGet(ActionsToken);
227
+ if (actions) return actions.runDocumentVerb("print", () => platform.print());
228
+ platform.print();
229
+ },
230
+ enabled: (context) => context.documentId !== null
231
+ }
232
+ ];
233
+ }
234
+ /** The download's file name: the document's name, ending in `.pdf`. */
235
+ function fileNameOf(name) {
236
+ if (!name) return "document.pdf";
237
+ return /\.pdf$/i.test(name) ? name : `${name}.pdf`;
238
+ }
239
+ //#endregion
240
+ export { createStandardCommands };
241
+
242
+ //# 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, delete, download and\n * print, with shortcuts, and labels in EmbedPDF's eight languages (the i18n\n * plugin has the strings). Three of them reach the browser (the clipboard, a\n * file download, the print dialog), which plugins never touch, so each\n * framework's `/commands` builds them with its platform: that is the\n * `standardCommands` an app imports.\n */\nimport { DocumentsToken } from '@embedpdf/core';\nimport { ActionsToken } from '@embedpdf/plugin-actions/contract';\nimport { AnnotationToken } from '@embedpdf/plugin-annotation/contract';\nimport { InteractionToken, type Tool } from '@embedpdf/plugin-interaction/contract';\nimport { SelectionToken, type SelectionCapability } from '@embedpdf/plugin-selection/contract';\nimport { StageToken } from '@embedpdf/plugin-stage/contract';\n\nimport type { CommandContext, CommandDef, 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 /** Give the user the bytes as a file download. */\n saveFile(bytes: Uint8Array, fileName: string): void;\n /** Open the print dialog. */\n print(): void;\n}\n\nconst stageOf = (context: CommandContext) => context.tryGet(StageToken);\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<CommandDef, '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 (CommandDef | 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: hasStage,\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: hasStage,\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 two built-in ones have shortcuts; the family covers every other ──\n { ...toolCommand('pointer'), id: 'tool:pointer', shortcut: 'V' },\n { ...toolCommand('pan'), id: 'tool:pan', shortcut: 'H' },\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.list();\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 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));\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 document's own print actions run around the dialog when the\n // actions plugin is there.\n run: (context) => {\n const actions = context.tryGet(ActionsToken);\n if (actions) return actions.runDocumentVerb('print', () => platform.print());\n platform.print();\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"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAM,WAAW,YAA4B,QAAQ,OAAO,UAAU;AACtE,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,KAAK,WAAW,UAAU;AAChE;;AAGA,MAAM,eAAe,YAAyD;CAC5E,UAAU,iBAAiB;CAC3B,OAAO;CACP,MAAM;CACN,YAAY,CAAC,MAAM;CACnB,MAAM,YAAY,cAAc,OAAO,CAAC,EAAE,aAAa,MAAM;CAC7D,SAAS,YAAY,cAAc,OAAO,CAAC,EAAE,gBAAgB,MAAM;CACnE,UAAU,YAAY,cAAc,OAAO,CAAC,EAAE,QAAQ,MAAM,KAAK;C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;CACpD,IAAI,CAAC,MAAM,OAAO;CAClB,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK;AAC/C"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-commands",
3
- "version": "3.0.0-next.13",
3
+ "version": "3.0.0-next.15",
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",
@@ -16,16 +16,29 @@
16
16
  "import": "./dist/contract.js",
17
17
  "require": "./dist/contract.cjs"
18
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
+ },
19
27
  "./package.json": "./package.json"
20
28
  },
21
29
  "files": [
22
30
  "dist"
23
31
  ],
24
32
  "dependencies": {
25
- "@embedpdf/core": "3.0.0-next.13",
26
- "@embedpdf/plugin-shell": "3.0.0-next.13",
27
- "@embedpdf/plugin-i18n": "3.0.0-next.13",
28
- "@embedpdf/core-ui": "3.0.0-next.13"
33
+ "@embedpdf/core": "3.0.0-next.15",
34
+ "@embedpdf/core-ui": "3.0.0-next.15",
35
+ "@embedpdf/plugin-actions": "3.0.0-next.15",
36
+ "@embedpdf/plugin-annotation": "3.0.0-next.15",
37
+ "@embedpdf/plugin-i18n": "3.0.0-next.15",
38
+ "@embedpdf/plugin-interaction": "3.0.0-next.15",
39
+ "@embedpdf/plugin-shell": "3.0.0-next.15",
40
+ "@embedpdf/plugin-stage": "3.0.0-next.15",
41
+ "@embedpdf/plugin-selection": "3.0.0-next.15"
29
42
  },
30
43
  "devDependencies": {
31
44
  "typescript": "^5.0.0",
@@ -1,137 +0,0 @@
1
- import { CapabilityToken, CoreState } from "@embedpdf/core";
2
- import { KeyStroke } from "@embedpdf/core-ui";
3
- //#region src/types.d.ts
4
- /**
5
- * @embedpdf/plugin-commands — the contract.
6
- *
7
- * Commands are the single vocabulary of verbs: toolbars, menus, contextual
8
- * strips, shortcuts, and the palette are all projections of this registry.
9
- * The plugin ships ZERO commands (mechanism here, definitions in the product
10
- * — same split as plugin-i18n's locale packs).
11
- *
12
- * Command state is a pure DERIVATION over the store: `resolve()` reads other
13
- * capabilities' selectors at call time, so any store change is reflected on
14
- * the next read and the framework binding's one change stream makes every
15
- * consumer reactive. There is no CommandStateChangedEvent, no diffing, no
16
- * cache — v2's entire notification apparatus has no v3 equivalent because
17
- * the reactive store subsumes it.
18
- *
19
- * Definitions hold functions, so they live in the plugin's registry (config
20
- * + `register()`), never in the store; store state is only the serializable
21
- * `disabledCategories`.
22
- */
23
- /** What a derivation or `run` sees: capability resolution bound to the
24
- * command's target document (explicit, else the active one). */
25
- interface CommandCtx {
26
- /** The target document, or null when no document is open. */
27
- readonly documentId: string | null;
28
- core(): CoreState;
29
- /** Resolve a capability; document-scoped tokens bind to the target document. */
30
- get<T>(token: CapabilityToken<T>): T;
31
- /** Like `get`, but null when unavailable (no provider / no document). */
32
- tryGet<T>(token: CapabilityToken<T>): T | null;
33
- }
34
- /**
35
- * Up to two theme colors accompanying a command's icon — typed FACTS any
36
- * renderer can interpret (tint a glyph's slots, show a swatch), never
37
- * renderer props. The registry carries it the way it carries `icon`: as
38
- * data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —
39
- * renderer-specific needs live app-side, joined by command id.
40
- */
41
- interface IconAccent {
42
- /** The mark: stroke / markup / font color. */
43
- readonly primary?: string;
44
- /** The fill, when there is one. */
45
- readonly secondary?: string;
46
- }
47
- interface CommandDef {
48
- /** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */
49
- readonly id: string;
50
- /** i18n key, resolved through I18nToken when present (else shown verbatim). */
51
- readonly labelKey: string;
52
- readonly icon?: string;
53
- /** Live color accent for the icon (a tool previewing its drawing defaults).
54
- * A pure derivation over the store, exactly like `active`/`enabled`. */
55
- readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;
56
- /** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */
57
- readonly shortcut?: string | readonly string[];
58
- /** Feature-gating tags: a disabled category hides its commands everywhere. */
59
- readonly categories?: readonly string[];
60
- /** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */
61
- readonly menu?: string;
62
- /** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */
63
- readonly panel?: string | {
64
- readonly id: string;
65
- readonly exclusive?: string;
66
- };
67
- /** Toggles a modal surface (exclusive within the built-in 'modal' tag). */
68
- readonly modal?: string;
69
- readonly enabled?: (ctx: CommandCtx) => boolean;
70
- readonly active?: (ctx: CommandCtx) => boolean;
71
- readonly visible?: (ctx: CommandCtx) => boolean;
72
- /** The verb. Optional for pure surface-target commands. Runs before the
73
- * default target routing when both are present. */
74
- readonly run?: (ctx: CommandCtx) => void;
75
- }
76
- /** A command as a renderer sees it — everything resolved for the target document. */
77
- interface ResolvedCommand {
78
- readonly id: string;
79
- readonly label: string;
80
- readonly icon?: string;
81
- readonly iconAccent?: IconAccent;
82
- readonly shortcuts: readonly string[];
83
- readonly menu?: string;
84
- readonly enabled: boolean;
85
- readonly active: boolean;
86
- readonly visible: boolean;
87
- readonly categories: readonly string[];
88
- }
89
- /** Value equality over resolved commands — `resolve()` mints a fresh object
90
- * per read, so reactive bindings memo by value to re-render on real change. */
91
- declare const resolvedCommandsEqual: (a: ResolvedCommand | null, b: ResolvedCommand | null) => boolean;
92
- interface CommandsState {
93
- readonly disabledCategories: readonly string[];
94
- }
95
- type CommandsAction = {
96
- type: 'COMMANDS/DISABLE_CATEGORY';
97
- category: string;
98
- } | {
99
- type: 'COMMANDS/ENABLE_CATEGORY';
100
- category: string;
101
- } | {
102
- type: 'COMMANDS/SET_DISABLED_CATEGORIES';
103
- categories: readonly string[];
104
- };
105
- interface CommandsConfig {
106
- /** The app's command definitions (content — the plugin ships none). */
107
- commands?: readonly CommandDef[];
108
- /** Categories disabled at startup (host feature-gating). */
109
- disabledCategories?: readonly string[];
110
- }
111
- interface CommandsCapability {
112
- register(def: CommandDef): void;
113
- unregister(id: string): void;
114
- has(id: string): boolean;
115
- ids(): string[];
116
- resolve(id: string, documentId?: string): ResolvedCommand | null;
117
- /** Palette query: visible commands whose resolved label matches. */
118
- search(query: string, documentId?: string): ResolvedCommand[];
119
- /** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */
120
- menuTarget(id: string): {
121
- menu?: string;
122
- } | null;
123
- execute(id: string, documentId?: string): void;
124
- /** Match a keystroke against every registered shortcut → command id or null. */
125
- matchStroke(stroke: KeyStroke, opts: {
126
- isMac: boolean;
127
- }): string | null;
128
- disabledCategories(): readonly string[];
129
- isCategoryDisabled(category: string): boolean;
130
- disableCategory(category: string): void;
131
- enableCategory(category: string): void;
132
- setDisabledCategories(categories: readonly string[]): void;
133
- }
134
- declare const CommandsToken: CapabilityToken<CommandsCapability>;
135
- //#endregion
136
- export { CommandsConfig as a, IconAccent as c, CommandsCapability as i, ResolvedCommand as l, CommandDef as n, CommandsState as o, CommandsAction as r, CommandsToken as s, CommandCtx as t, resolvedCommandsEqual as u };
137
- //# sourceMappingURL=contract-CSIfF6wC.d.cts.map
@@ -1,137 +0,0 @@
1
- import { CapabilityToken, CoreState } from "@embedpdf/core";
2
- import { KeyStroke } from "@embedpdf/core-ui";
3
- //#region src/types.d.ts
4
- /**
5
- * @embedpdf/plugin-commands — the contract.
6
- *
7
- * Commands are the single vocabulary of verbs: toolbars, menus, contextual
8
- * strips, shortcuts, and the palette are all projections of this registry.
9
- * The plugin ships ZERO commands (mechanism here, definitions in the product
10
- * — same split as plugin-i18n's locale packs).
11
- *
12
- * Command state is a pure DERIVATION over the store: `resolve()` reads other
13
- * capabilities' selectors at call time, so any store change is reflected on
14
- * the next read and the framework binding's one change stream makes every
15
- * consumer reactive. There is no CommandStateChangedEvent, no diffing, no
16
- * cache — v2's entire notification apparatus has no v3 equivalent because
17
- * the reactive store subsumes it.
18
- *
19
- * Definitions hold functions, so they live in the plugin's registry (config
20
- * + `register()`), never in the store; store state is only the serializable
21
- * `disabledCategories`.
22
- */
23
- /** What a derivation or `run` sees: capability resolution bound to the
24
- * command's target document (explicit, else the active one). */
25
- interface CommandCtx {
26
- /** The target document, or null when no document is open. */
27
- readonly documentId: string | null;
28
- core(): CoreState;
29
- /** Resolve a capability; document-scoped tokens bind to the target document. */
30
- get<T>(token: CapabilityToken<T>): T;
31
- /** Like `get`, but null when unavailable (no provider / no document). */
32
- tryGet<T>(token: CapabilityToken<T>): T | null;
33
- }
34
- /**
35
- * Up to two theme colors accompanying a command's icon — typed FACTS any
36
- * renderer can interpret (tint a glyph's slots, show a swatch), never
37
- * renderer props. The registry carries it the way it carries `icon`: as
38
- * data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —
39
- * renderer-specific needs live app-side, joined by command id.
40
- */
41
- interface IconAccent {
42
- /** The mark: stroke / markup / font color. */
43
- readonly primary?: string;
44
- /** The fill, when there is one. */
45
- readonly secondary?: string;
46
- }
47
- interface CommandDef {
48
- /** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */
49
- readonly id: string;
50
- /** i18n key, resolved through I18nToken when present (else shown verbatim). */
51
- readonly labelKey: string;
52
- readonly icon?: string;
53
- /** Live color accent for the icon (a tool previewing its drawing defaults).
54
- * A pure derivation over the store, exactly like `active`/`enabled`. */
55
- readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;
56
- /** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */
57
- readonly shortcut?: string | readonly string[];
58
- /** Feature-gating tags: a disabled category hides its commands everywhere. */
59
- readonly categories?: readonly string[];
60
- /** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */
61
- readonly menu?: string;
62
- /** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */
63
- readonly panel?: string | {
64
- readonly id: string;
65
- readonly exclusive?: string;
66
- };
67
- /** Toggles a modal surface (exclusive within the built-in 'modal' tag). */
68
- readonly modal?: string;
69
- readonly enabled?: (ctx: CommandCtx) => boolean;
70
- readonly active?: (ctx: CommandCtx) => boolean;
71
- readonly visible?: (ctx: CommandCtx) => boolean;
72
- /** The verb. Optional for pure surface-target commands. Runs before the
73
- * default target routing when both are present. */
74
- readonly run?: (ctx: CommandCtx) => void;
75
- }
76
- /** A command as a renderer sees it — everything resolved for the target document. */
77
- interface ResolvedCommand {
78
- readonly id: string;
79
- readonly label: string;
80
- readonly icon?: string;
81
- readonly iconAccent?: IconAccent;
82
- readonly shortcuts: readonly string[];
83
- readonly menu?: string;
84
- readonly enabled: boolean;
85
- readonly active: boolean;
86
- readonly visible: boolean;
87
- readonly categories: readonly string[];
88
- }
89
- /** Value equality over resolved commands — `resolve()` mints a fresh object
90
- * per read, so reactive bindings memo by value to re-render on real change. */
91
- declare const resolvedCommandsEqual: (a: ResolvedCommand | null, b: ResolvedCommand | null) => boolean;
92
- interface CommandsState {
93
- readonly disabledCategories: readonly string[];
94
- }
95
- type CommandsAction = {
96
- type: 'COMMANDS/DISABLE_CATEGORY';
97
- category: string;
98
- } | {
99
- type: 'COMMANDS/ENABLE_CATEGORY';
100
- category: string;
101
- } | {
102
- type: 'COMMANDS/SET_DISABLED_CATEGORIES';
103
- categories: readonly string[];
104
- };
105
- interface CommandsConfig {
106
- /** The app's command definitions (content — the plugin ships none). */
107
- commands?: readonly CommandDef[];
108
- /** Categories disabled at startup (host feature-gating). */
109
- disabledCategories?: readonly string[];
110
- }
111
- interface CommandsCapability {
112
- register(def: CommandDef): void;
113
- unregister(id: string): void;
114
- has(id: string): boolean;
115
- ids(): string[];
116
- resolve(id: string, documentId?: string): ResolvedCommand | null;
117
- /** Palette query: visible commands whose resolved label matches. */
118
- search(query: string, documentId?: string): ResolvedCommand[];
119
- /** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */
120
- menuTarget(id: string): {
121
- menu?: string;
122
- } | null;
123
- execute(id: string, documentId?: string): void;
124
- /** Match a keystroke against every registered shortcut → command id or null. */
125
- matchStroke(stroke: KeyStroke, opts: {
126
- isMac: boolean;
127
- }): string | null;
128
- disabledCategories(): readonly string[];
129
- isCategoryDisabled(category: string): boolean;
130
- disableCategory(category: string): void;
131
- enableCategory(category: string): void;
132
- setDisabledCategories(categories: readonly string[]): void;
133
- }
134
- declare const CommandsToken: CapabilityToken<CommandsCapability>;
135
- //#endregion
136
- export { CommandsConfig as a, IconAccent as c, CommandsCapability as i, ResolvedCommand as l, CommandDef as n, CommandsState as o, CommandsAction as r, CommandsToken as s, CommandCtx as t, resolvedCommandsEqual as u };
137
- //# sourceMappingURL=contract-CSIfF6wC.d.ts.map
@@ -1,25 +0,0 @@
1
- let _embedpdf_core = require("@embedpdf/core");
2
- //#region src/types.ts
3
- /** Value equality over resolved commands — `resolve()` mints a fresh object
4
- * per read, so reactive bindings memo by value to re-render on real change. */
5
- const resolvedCommandsEqual = (a, b) => {
6
- if (a === b) return true;
7
- if (!a || !b) return false;
8
- return a.id === b.id && a.label === b.label && a.icon === b.icon && a.iconAccent?.primary === b.iconAccent?.primary && a.iconAccent?.secondary === b.iconAccent?.secondary && a.menu === b.menu && a.enabled === b.enabled && a.active === b.active && a.visible === b.visible && a.shortcuts.length === b.shortcuts.length && a.shortcuts.every((s, i) => s === b.shortcuts[i]);
9
- };
10
- const CommandsToken = (0, _embedpdf_core.createCapabilityToken)("commands");
11
- //#endregion
12
- Object.defineProperty(exports, "CommandsToken", {
13
- enumerable: true,
14
- get: function() {
15
- return CommandsToken;
16
- }
17
- });
18
- Object.defineProperty(exports, "resolvedCommandsEqual", {
19
- enumerable: true,
20
- get: function() {
21
- return resolvedCommandsEqual;
22
- }
23
- });
24
-
25
- //# sourceMappingURL=contract-DYlaVyVk.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-DYlaVyVk.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import { createCapabilityToken } from '@embedpdf/core';\nimport type { CapabilityToken, CoreState } from '@embedpdf/core';\nimport type { KeyStroke } from '@embedpdf/core-ui';\n\n/**\n * @embedpdf/plugin-commands — the contract.\n *\n * Commands are the single vocabulary of verbs: toolbars, menus, contextual\n * strips, shortcuts, and the palette are all projections of this registry.\n * The plugin ships ZERO commands (mechanism here, definitions in the product\n * — same split as plugin-i18n's locale packs).\n *\n * Command state is a pure DERIVATION over the store: `resolve()` reads other\n * capabilities' selectors at call time, so any store change is reflected on\n * the next read and the framework binding's one change stream makes every\n * consumer reactive. There is no CommandStateChangedEvent, no diffing, no\n * cache — v2's entire notification apparatus has no v3 equivalent because\n * the reactive store subsumes it.\n *\n * Definitions hold functions, so they live in the plugin's registry (config\n * + `register()`), never in the store; store state is only the serializable\n * `disabledCategories`.\n */\n\n/** What a derivation or `run` sees: capability resolution bound to the\n * command's target document (explicit, else the active one). */\nexport interface CommandCtx {\n /** The target document, or null when no document is open. */\n readonly documentId: string | null;\n core(): CoreState;\n /** Resolve a capability; document-scoped tokens bind to the target document. */\n get<T>(token: CapabilityToken<T>): T;\n /** Like `get`, but null when unavailable (no provider / no document). */\n tryGet<T>(token: CapabilityToken<T>): T | null;\n}\n\n/**\n * Up to two theme colors accompanying a command's icon — typed FACTS any\n * renderer can interpret (tint a glyph's slots, show a swatch), never\n * renderer props. The registry carries it the way it carries `icon`: as\n * data it doesn't interpret. Deliberately NOT v2's `iconProps` bag —\n * renderer-specific needs live app-side, joined by command id.\n */\nexport interface IconAccent {\n /** The mark: stroke / markup / font color. */\n readonly primary?: string;\n /** The fill, when there is one. */\n readonly secondary?: string;\n}\n\nexport interface CommandDef {\n /** Convention: 'domain:verb' — 'zoom:in', 'mode:annotate', 'panel:search'. */\n readonly id: string;\n /** i18n key, resolved through I18nToken when present (else shown verbatim). */\n readonly labelKey: string;\n readonly icon?: string;\n /** Live color accent for the icon (a tool previewing its drawing defaults).\n * A pure derivation over the store, exactly like `active`/`enabled`. */\n readonly iconAccent?: (ctx: CommandCtx) => IconAccent | null;\n /** 'Mod+K' style (ui-core grammar). Multiple bindings allowed. */\n readonly shortcut?: string | readonly string[];\n /** Feature-gating tags: a disabled category hides its commands everywhere. */\n readonly categories?: readonly string[];\n\n // ── declarative surface targets ──────────────────────────────────────────\n // A command that opens chrome DECLARES what it opens instead of doing it\n // imperatively. This is load-bearing: buttons render carets/aria-haspopup,\n // `active` derives automatically from the surface's open state, and the\n // overflow projection renders `menu` targets as nested submenus.\n /** Toggles a named dropdown menu (a MenuSchema id in the app's chrome). */\n readonly menu?: string;\n /** Toggles a named shell surface, optionally exclusive within a tag ('left'…). */\n readonly panel?: string | { readonly id: string; readonly exclusive?: string };\n /** Toggles a modal surface (exclusive within the built-in 'modal' tag). */\n readonly modal?: string;\n\n // ── pure derivations over the store ──────────────────────────────────────\n readonly enabled?: (ctx: CommandCtx) => boolean;\n readonly active?: (ctx: CommandCtx) => boolean;\n readonly visible?: (ctx: CommandCtx) => boolean;\n\n /** The verb. Optional for pure surface-target commands. Runs before the\n * default target routing when both are present. */\n readonly run?: (ctx: CommandCtx) => void;\n}\n\n/** A command as a renderer sees it — everything resolved for the target 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\n/** Value equality over resolved commands — `resolve()` mints a fresh object\n * per read, so reactive bindings memo by value to re-render on real change. */\nexport const resolvedCommandsEqual = (\n a: ResolvedCommand | null,\n b: ResolvedCommand | null,\n): boolean => {\n if (a === b) return true;\n if (!a || !b) return false;\n return (\n a.id === b.id &&\n a.label === b.label &&\n a.icon === b.icon &&\n // by value: resolve() mints a fresh accent object each read\n a.iconAccent?.primary === b.iconAccent?.primary &&\n a.iconAccent?.secondary === b.iconAccent?.secondary &&\n a.menu === b.menu &&\n a.enabled === b.enabled &&\n a.active === b.active &&\n a.visible === b.visible &&\n a.shortcuts.length === b.shortcuts.length &&\n a.shortcuts.every((s, i) => s === b.shortcuts[i])\n );\n};\n\nexport interface CommandsState {\n readonly disabledCategories: readonly string[];\n}\n\nexport type CommandsAction =\n | { type: 'COMMANDS/DISABLE_CATEGORY'; category: string }\n | { type: 'COMMANDS/ENABLE_CATEGORY'; category: string }\n | { type: 'COMMANDS/SET_DISABLED_CATEGORIES'; categories: readonly string[] };\n\nexport interface CommandsConfig {\n /** The app's command definitions (content — the plugin ships none). */\n commands?: readonly CommandDef[];\n /** Categories disabled at startup (host feature-gating). */\n disabledCategories?: readonly string[];\n}\n\nexport interface CommandsCapability {\n // ── registry ──\n register(def: CommandDef): void;\n unregister(id: string): void;\n has(id: string): boolean;\n ids(): string[];\n\n // ── resolution (pure reads; reactive through the store) ──\n resolve(id: string, documentId?: string): ResolvedCommand | null;\n /** Palette query: visible commands whose resolved label matches. */\n search(query: string, documentId?: string): ResolvedCommand[];\n /** The one fact the overflow projection needs (ResolveMenuTarget-shaped). */\n menuTarget(id: string): { menu?: string } | null;\n\n // ── execution (the ONLY path; guarded by enabled/visible) ──\n execute(id: string, documentId?: string): void;\n /** Match a keystroke against every registered shortcut → command id or null. */\n matchStroke(stroke: KeyStroke, opts: { isMac: boolean }): string | null;\n\n // ── category gating ──\n disabledCategories(): readonly string[];\n isCategoryDisabled(category: string): boolean;\n disableCategory(category: string): void;\n enableCategory(category: string): void;\n setDisabledCategories(categories: readonly string[]): void;\n}\n\nexport const CommandsToken = createCapabilityToken<CommandsCapability>('commands');\n"],"mappings":";;;;AAsGA,MAAa,yBACX,GACA,MACY;CACZ,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,CAAC,KAAK,CAAC,GAAG,OAAO;CACrB,OACE,EAAE,OAAO,EAAE,MACX,EAAE,UAAU,EAAE,SACd,EAAE,SAAS,EAAE,QAEb,EAAE,YAAY,YAAY,EAAE,YAAY,WACxC,EAAE,YAAY,cAAc,EAAE,YAAY,aAC1C,EAAE,SAAS,EAAE,QACb,EAAE,YAAY,EAAE,WAChB,EAAE,WAAW,EAAE,UACf,EAAE,YAAY,EAAE,WAChB,EAAE,UAAU,WAAW,EAAE,UAAU,UACnC,EAAE,UAAU,OAAO,GAAG,MAAM,MAAM,EAAE,UAAU,EAAE;AAEpD;AA6CA,MAAa,iBAAA,GAAA,eAAA,sBAAA,CAA0D,UAAU"}
@@ -1,14 +0,0 @@
1
- import { createCapabilityToken } from "@embedpdf/core";
2
- //#region src/types.ts
3
- /** Value equality over resolved commands — `resolve()` mints a fresh object
4
- * per read, so reactive bindings memo by value to re-render on real change. */
5
- const resolvedCommandsEqual = (a, b) => {
6
- if (a === b) return true;
7
- if (!a || !b) return false;
8
- return a.id === b.id && a.label === b.label && a.icon === b.icon && a.iconAccent?.primary === b.iconAccent?.primary && a.iconAccent?.secondary === b.iconAccent?.secondary && a.menu === b.menu && a.enabled === b.enabled && a.active === b.active && a.visible === b.visible && a.shortcuts.length === b.shortcuts.length && a.shortcuts.every((s, i) => s === b.shortcuts[i]);
9
- };
10
- const CommandsToken = createCapabilityToken("commands");
11
- //#endregion
12
- export { resolvedCommandsEqual as n, CommandsToken as t };
13
-
14
- //# sourceMappingURL=contract-UFgXphIQ.js.map