@quirekit/pptx-editor 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +296 -0
- package/README.md +36 -2
- package/README.zh-CN.md +35 -0
- package/THIRD_PARTY_NOTICES.md +141 -0
- package/dist/ai.d.mts +296 -0
- package/dist/ai.mjs +786 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.mjs +90 -0
- package/dist/styles.css +2362 -0
- package/dist/svg-raster-DL19F7ez.mjs +11 -0
- package/dist/types-Bed8XDUh.d.mts +1589 -0
- package/package.json +95 -4
package/dist/ai.d.mts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { _ as PptxCommandName, d as PptxEditorSession, g as PptxCommandDescriptor, h as PptxCommandAgentContext, m as PptxChain, o as PptxEditorPanel, v as PptxCommandRegistry, x as PptxLayoutChecker, y as PptxCommands } from "./types-Bed8XDUh.mjs";
|
|
2
|
+
import { PresentationData, SlideData } from "@quirekit/office-kit-pptx";
|
|
3
|
+
import { QuireAiModelConnection, QuireAiProviderPlugin } from "@quirekit/ai-assistant";
|
|
4
|
+
import { QuireAiSlidesDocument, QuireAiSlidesSlideDesign } from "@quirekit/ai-runtime/slides";
|
|
5
|
+
import { QuireAiSkillLibrary, QuireAiSkillRecord } from "@quirekit/ai-runtime";
|
|
6
|
+
import { QuireAiPiHostHeaderResolver } from "@quirekit/ai-orchestrator-pi";
|
|
7
|
+
|
|
8
|
+
//#region src/ai/types.d.ts
|
|
9
|
+
/** Host configuration of the PPTX editor assistant. */
|
|
10
|
+
interface PptxEditorAiOptions {
|
|
11
|
+
/** Document that owns the settings dialog. */
|
|
12
|
+
readonly ownerDocument: Document;
|
|
13
|
+
/** Browser-local persistence for provider settings, selected model and authorization preset. */
|
|
14
|
+
readonly storage: Storage;
|
|
15
|
+
/** Application-managed models. Supplying this hides local provider settings and bypasses saved connection preferences. */
|
|
16
|
+
readonly connection?: (() => Promise<QuireAiModelConnection>) | undefined;
|
|
17
|
+
/** AI Host used until the user saves explicit provider settings. */
|
|
18
|
+
readonly defaultHostUrl?: string | undefined;
|
|
19
|
+
/** Provider plugins offered in the model settings; the built-in ones when omitted, such as to add OpenRouter sign-in. */
|
|
20
|
+
readonly providers?: readonly QuireAiProviderPlugin[] | undefined;
|
|
21
|
+
/** Applies saved provider settings; by default the open panels switch to the new models without reloading the page. */
|
|
22
|
+
readonly reconnect?: (() => void) | undefined;
|
|
23
|
+
/** Fetch implementation for tests or an application gateway. */
|
|
24
|
+
readonly fetch?: typeof globalThis.fetch | undefined;
|
|
25
|
+
/** Lazy resolver for application authentication headers sent to the Host. */
|
|
26
|
+
readonly getHeaders?: QuireAiPiHostHeaderResolver | undefined;
|
|
27
|
+
/** Open the panel when the editor mounts. */
|
|
28
|
+
readonly defaultOpen?: boolean | undefined;
|
|
29
|
+
/** Set false to keep one unsaved conversation instead of the deck's stored conversations. */
|
|
30
|
+
readonly documentKey?: false | undefined;
|
|
31
|
+
/** Skills the assistant reads design knowledge from; the built-in design method and scene skills by default. */
|
|
32
|
+
readonly skills?: QuireAiSkillLibrary | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Generates pictures the assistant places from a description. Left out, a connected provider that generates
|
|
35
|
+
* pictures (Model Studio's Qwen-Image) is used; false, or no such provider, leaves the assistant icons and shapes.
|
|
36
|
+
*/
|
|
37
|
+
readonly pictures?: PptxAiPictureSource | false | undefined;
|
|
38
|
+
}
|
|
39
|
+
/** A host's picture generator, such as an image model the host connects to. */
|
|
40
|
+
interface PptxAiPictureSource {
|
|
41
|
+
/**
|
|
42
|
+
* @param request - What the picture shows, its size in pixels, and a signal that stops it when the editor closes.
|
|
43
|
+
* @returns PNG or JPEG bytes.
|
|
44
|
+
*/
|
|
45
|
+
generate(request: {
|
|
46
|
+
readonly prompt: string;
|
|
47
|
+
readonly width: number;
|
|
48
|
+
readonly height: number;
|
|
49
|
+
readonly signal?: AbortSignal | undefined;
|
|
50
|
+
}): Promise<Uint8Array>;
|
|
51
|
+
}
|
|
52
|
+
/** Assembled assistant for one page. */
|
|
53
|
+
interface PptxEditorAi {
|
|
54
|
+
/** Panel to pass to the editor's `panels`. */
|
|
55
|
+
readonly panel: PptxEditorPanel;
|
|
56
|
+
/** Removes the settings dialog; editors release their conversations themselves. */
|
|
57
|
+
destroy(): void;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/ai/create.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* Assembles the first-party PPTX editor assistant: provider settings, model connection and the
|
|
63
|
+
* side panel. Pass `panel` to the editor's `panels`.
|
|
64
|
+
* @param options - Host document, storage and optional defaults.
|
|
65
|
+
* @returns Panel and a page-level teardown.
|
|
66
|
+
*/
|
|
67
|
+
declare function createPptxEditorAi(options: PptxEditorAiOptions): PptxEditorAi;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/command/registry.d.ts
|
|
70
|
+
/** Winning command implementations of the installed extensions. */
|
|
71
|
+
interface PptxCommandTable {
|
|
72
|
+
/** Command factories by name; later extensions override earlier ones. */
|
|
73
|
+
readonly factories: Readonly<Partial<PptxCommandRegistry>>;
|
|
74
|
+
/** Typed single-command entry. */
|
|
75
|
+
readonly commands: PptxCommands;
|
|
76
|
+
/** @returns A new chain. */
|
|
77
|
+
chain(): PptxChain;
|
|
78
|
+
/** @returns Agent descriptions of the described commands, in registration order. */
|
|
79
|
+
descriptors(): ReadonlyMap<PptxCommandName, PptxCommandDescriptor>;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/types.d.ts
|
|
83
|
+
/** What the user has selected: a current slide and, optionally, shapes on it. */
|
|
84
|
+
interface PptxSelection {
|
|
85
|
+
/** Part name of the current slide, or null for an empty deck. */
|
|
86
|
+
readonly slide: string | null;
|
|
87
|
+
/** Selected shape ids on the current slide, in selection order. */
|
|
88
|
+
readonly shapes: readonly number[];
|
|
89
|
+
}
|
|
90
|
+
/** Where a kept change came from. */
|
|
91
|
+
type PptxChangeOrigin = "user" | "command" | "agent" | "history" | "file";
|
|
92
|
+
/** Notification of a kept change or a selection move. */
|
|
93
|
+
interface PptxDocumentChange {
|
|
94
|
+
/** Whether the deck itself changed; false when only the selection moved. */
|
|
95
|
+
readonly content: boolean;
|
|
96
|
+
/** Origin of the change. */
|
|
97
|
+
readonly origin: PptxChangeOrigin;
|
|
98
|
+
/** Whether this is a frame of a running gesture, which is followed by its commit. */
|
|
99
|
+
readonly live?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/** Live deck with its selection and undo history; the single authority every view and command edits. */
|
|
102
|
+
interface PptxDocument {
|
|
103
|
+
/** @returns Live presentation; read it, but change it only through `transact` or `live`. */
|
|
104
|
+
presentation(): PresentationData;
|
|
105
|
+
/** @returns Counter that grows with every content change, including live gesture frames. */
|
|
106
|
+
version(): number;
|
|
107
|
+
/** @returns Current selection. */
|
|
108
|
+
selection(): PptxSelection;
|
|
109
|
+
/** @param selection - New selection; shapes that are not on the slide are dropped. */
|
|
110
|
+
select(selection: PptxSelection): void;
|
|
111
|
+
/**
|
|
112
|
+
* Runs one synchronous edit as one undo step. When the edit throws or returns false after it
|
|
113
|
+
* may have changed the deck, the last committed state is restored and nothing is kept.
|
|
114
|
+
* @param label - Undo step name.
|
|
115
|
+
* @param edit - Edit of the live presentation; returns false to discard itself, or null when it changed nothing.
|
|
116
|
+
* @param origin - Who made the edit.
|
|
117
|
+
* @returns Whether the edit was kept.
|
|
118
|
+
*/
|
|
119
|
+
transact(label: string, edit: (presentation: PresentationData) => boolean | null, origin?: PptxChangeOrigin): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Replaces the deck with other bytes as one undo step, such as taking back a reviewed AI request.
|
|
122
|
+
* @param bytes - Deck bytes.
|
|
123
|
+
* @param label - Undo step name.
|
|
124
|
+
* @param origin - Who made the change.
|
|
125
|
+
* @returns Whether the bytes could be read.
|
|
126
|
+
*/
|
|
127
|
+
adopt(bytes: Uint8Array, label: string, origin: PptxChangeOrigin): Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Applies one frame of a gesture, such as a drag, without adding an undo step.
|
|
130
|
+
* @param edit - Frame edit.
|
|
131
|
+
*/
|
|
132
|
+
live(edit: (presentation: PresentationData) => void): void;
|
|
133
|
+
/** @param label - Closes the running gesture as one undo step. */
|
|
134
|
+
commit(label: string): void;
|
|
135
|
+
/** @returns Whether the gesture was cancelled and its frames dropped. */
|
|
136
|
+
cancelLive(): Promise<boolean>;
|
|
137
|
+
/** @returns Whether undo is possible now. */
|
|
138
|
+
canUndo(): boolean;
|
|
139
|
+
/** @returns Whether redo is possible now. */
|
|
140
|
+
canRedo(): boolean;
|
|
141
|
+
/** @returns Whether a step was undone. */
|
|
142
|
+
undo(): Promise<boolean>;
|
|
143
|
+
/** @returns Whether a step was redone. */
|
|
144
|
+
redo(): Promise<boolean>;
|
|
145
|
+
/**
|
|
146
|
+
* Takes back the newest step and forgets it, so redo cannot bring it back; for steps that turned out to change
|
|
147
|
+
* nothing the author meant, such as a text box left empty.
|
|
148
|
+
* @param label - Name the step must have; any other newest step is kept.
|
|
149
|
+
* @returns Whether the step was taken back.
|
|
150
|
+
*/
|
|
151
|
+
discard(label: string): Promise<boolean>;
|
|
152
|
+
/** @returns Whether the deck has changes since it was last marked saved. */
|
|
153
|
+
isDirty(): boolean;
|
|
154
|
+
/** Marks the current state as saved. */
|
|
155
|
+
markSaved(): void;
|
|
156
|
+
/** @returns The deck as `.pptx` bytes, fixed at the moment of the call. */
|
|
157
|
+
save(): Promise<Uint8Array>;
|
|
158
|
+
/**
|
|
159
|
+
* Replaces the whole deck, clearing history.
|
|
160
|
+
* @param bytes - Deck bytes.
|
|
161
|
+
* @returns Whether they could be read.
|
|
162
|
+
*/
|
|
163
|
+
replace(bytes: Uint8Array): Promise<boolean>;
|
|
164
|
+
/** @param listener - Receives every change. @returns Detaches it. */
|
|
165
|
+
subscribe(listener: (change: PptxDocumentChange) => void): () => void;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/session/session.d.ts
|
|
169
|
+
/** Session with the parts only first-party views and adapters use. */
|
|
170
|
+
interface PptxMountedSession extends PptxEditorSession {
|
|
171
|
+
/** Editing authority: live deck, selection and history. */
|
|
172
|
+
readonly document: PptxDocument;
|
|
173
|
+
/** Installed command table, also read by AI adapters for its descriptions. */
|
|
174
|
+
readonly table: PptxCommandTable;
|
|
175
|
+
/** Releases listeners and pending reads. */
|
|
176
|
+
destroy(): void;
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/ai/document.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Adapts a session to the AI core's slide document port. Every step runs through the session's
|
|
182
|
+
* command table, and all steps of one call share one transaction, so a call is one undo step.
|
|
183
|
+
* @param session - Mounted session.
|
|
184
|
+
* @param layout - Checks drawn slides for layout problems, in hosts with a page.
|
|
185
|
+
* @param picture - Draws a slide as PNG bytes at a width, in hosts with a page; without it the model gets no pictures.
|
|
186
|
+
* @param drawing - Line icons once loaded, whether the host generates pictures, and a checker that measures the samples
|
|
187
|
+
* of offered directions.
|
|
188
|
+
* @returns Slide document port, with `close` for its owner to call when the panel goes away.
|
|
189
|
+
*/
|
|
190
|
+
declare function createPptxAiDocument(session: PptxMountedSession, layout?: PptxLayoutChecker, picture?: (part: string, width: number) => Promise<Uint8Array>, drawing?: {
|
|
191
|
+
readonly icons?: () => PptxCommandAgentContext["icons"];
|
|
192
|
+
readonly pictures?: boolean;
|
|
193
|
+
readonly samples?: PptxLayoutChecker;
|
|
194
|
+
}): QuireAiSlidesDocument & {
|
|
195
|
+
close(): void;
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/ai/eval/fixtures.d.ts
|
|
199
|
+
/** Input decks of the design evaluation tasks, written here so every run starts from the same file. */
|
|
200
|
+
type PptxEvalFixture = "blank" | "denseLecture" | "textWall" | "plain" | "singleNumber";
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/ai/eval/score.d.ts
|
|
203
|
+
/** Measures of a finished task that need no judgement. */
|
|
204
|
+
interface PptxEvalScore {
|
|
205
|
+
/** Number of slides. */
|
|
206
|
+
readonly slides: number;
|
|
207
|
+
/** Mean visible characters per slide, notes left out. */
|
|
208
|
+
readonly charsMean: number;
|
|
209
|
+
/** Most visible characters on one slide. */
|
|
210
|
+
readonly charsMax: number;
|
|
211
|
+
/** Share of slides with speaker notes. */
|
|
212
|
+
readonly notesShare: number;
|
|
213
|
+
/** Share of slides with animations. */
|
|
214
|
+
readonly motionShare: number;
|
|
215
|
+
/** Distinct compositions among composed slides, a composition being its element kinds in order. */
|
|
216
|
+
readonly compositions: number;
|
|
217
|
+
/** Longest run of consecutive slides with the same composition. */
|
|
218
|
+
readonly longestRepeat: number;
|
|
219
|
+
/** Theme name, which names the style a styled deck uses. */
|
|
220
|
+
readonly theme: string | null;
|
|
221
|
+
/** Design notes over all slides, crowding left out since a saved deck has no drawn text. */
|
|
222
|
+
readonly designNotes: number;
|
|
223
|
+
/** Design notes by kind. */
|
|
224
|
+
readonly designNoteKinds: Readonly<Record<string, number>>;
|
|
225
|
+
/** Most clicks one slide takes in the show. */
|
|
226
|
+
readonly clicksMax: number;
|
|
227
|
+
/** Layout problems over all slides, measured on the drawn page; null when scored without a page. */
|
|
228
|
+
readonly layoutProblems: number | null;
|
|
229
|
+
/** Layout problems by kind, empty without a page. */
|
|
230
|
+
readonly layoutProblemKinds: Readonly<Record<string, number>>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Scores a deck.
|
|
234
|
+
* @param bytes - Deck as saved.
|
|
235
|
+
* @param checker - Measures drawn slides for layout problems, in a page; without it they are not counted.
|
|
236
|
+
* @returns Its measures.
|
|
237
|
+
*/
|
|
238
|
+
declare function scorePptxEvalDeck(bytes: Uint8Array, checker?: PptxLayoutChecker): Promise<PptxEvalScore>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/ai/eval/tasks.d.ts
|
|
241
|
+
/** One task of the design evaluation set. */
|
|
242
|
+
interface PptxEvalTask {
|
|
243
|
+
/** Stable id, T1 to T13. */
|
|
244
|
+
readonly id: string;
|
|
245
|
+
/** What kind of work it tests. */
|
|
246
|
+
readonly kind: "create" | "improve" | "restyle" | "motion" | "slide";
|
|
247
|
+
/** Input deck. */
|
|
248
|
+
readonly fixture: PptxEvalFixture;
|
|
249
|
+
/** Request typed into the assistant, word for word. */
|
|
250
|
+
readonly prompt: string;
|
|
251
|
+
}
|
|
252
|
+
/** The fixed tasks; change a prompt only together with a note in the evaluation record, or runs stop being comparable. */
|
|
253
|
+
declare const pptxEvalTasks: readonly PptxEvalTask[];
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/ai/eval/run.d.ts
|
|
256
|
+
/** Runs the design evaluation tasks against an editor: opens a task's input and measures the result. */
|
|
257
|
+
interface PptxAiEval {
|
|
258
|
+
/** The fixed tasks. */
|
|
259
|
+
readonly tasks: readonly PptxEvalTask[];
|
|
260
|
+
/**
|
|
261
|
+
* Opens a task's input deck in place of the current one.
|
|
262
|
+
* @param id - Task id.
|
|
263
|
+
* @returns The request to type into the assistant.
|
|
264
|
+
*/
|
|
265
|
+
prepare(id: string): Promise<string>;
|
|
266
|
+
/** @returns Measures of the deck as it is now, with seconds since the last prepare. */
|
|
267
|
+
score(): Promise<PptxEvalScore & {
|
|
268
|
+
readonly task: string | null;
|
|
269
|
+
readonly seconds: number | null;
|
|
270
|
+
}>;
|
|
271
|
+
/** @returns Each slide's composition and design facts, numbered from 1, for reading what the notes count. */
|
|
272
|
+
design(): Promise<readonly {
|
|
273
|
+
readonly slide: number;
|
|
274
|
+
readonly design: QuireAiSlidesSlideDesign;
|
|
275
|
+
}[]>;
|
|
276
|
+
/** @returns The deck as the assistant reads it; layout problems and crowding only in a page, where slides can be drawn. */
|
|
277
|
+
view(): Promise<string>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Creates the evaluation runner of an editor.
|
|
281
|
+
* @param session - Current editor session; the runner reads it on every call, so it follows remounts.
|
|
282
|
+
* @returns Runner.
|
|
283
|
+
*/
|
|
284
|
+
declare function createPptxAiEval(session: () => PptxEditorSession | undefined): PptxAiEval;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/ai/skills/library.d.ts
|
|
287
|
+
/** The presentation editor's built-in skills: the design method, annotated exemplars and the scenes they are used in. */
|
|
288
|
+
declare const pptxBuiltinSkills: readonly QuireAiSkillRecord[];
|
|
289
|
+
/**
|
|
290
|
+
* Creates the skill library the presentation assistant reads design knowledge from.
|
|
291
|
+
* @param skills - Skills to offer; the built-in ones by default.
|
|
292
|
+
* @returns Library; its list loads at once from memory, before the first request reads it.
|
|
293
|
+
*/
|
|
294
|
+
declare function createPptxAiSkills(skills?: readonly QuireAiSkillRecord[]): QuireAiSkillLibrary;
|
|
295
|
+
//#endregion
|
|
296
|
+
export { type PptxAiEval, type PptxAiPictureSource, type PptxEditorAi, type PptxEditorAiOptions, type PptxEvalScore, type PptxEvalTask, createPptxAiDocument, createPptxAiEval, createPptxAiSkills, createPptxEditorAi, pptxBuiltinSkills, pptxEvalTasks, scorePptxEvalDeck };
|