@particle-academy/dark-slide 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/index.cjs +3534 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +379 -0
- package/dist/index.d.ts +379 -0
- package/dist/index.js +3522 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public deck types — mirror `@particle-academy/fancy-slides`. Inputs are loose
|
|
3
|
+
* agent JSON, so most fields are optional and extra keys are tolerated; the
|
|
4
|
+
* Validator is the gate.
|
|
5
|
+
*/
|
|
6
|
+
type ElementType = "text" | "image" | "chart" | "code" | "table" | "shape" | "embed";
|
|
7
|
+
interface ThemeColors {
|
|
8
|
+
background?: string;
|
|
9
|
+
text?: string;
|
|
10
|
+
muted?: string;
|
|
11
|
+
accent?: string;
|
|
12
|
+
surface?: string;
|
|
13
|
+
}
|
|
14
|
+
interface ThemeFonts {
|
|
15
|
+
heading?: string;
|
|
16
|
+
body?: string;
|
|
17
|
+
mono?: string;
|
|
18
|
+
}
|
|
19
|
+
interface DeckTheme {
|
|
20
|
+
name: string;
|
|
21
|
+
aspectRatio?: number;
|
|
22
|
+
slideWidth?: number;
|
|
23
|
+
defaultTransition?: Transition;
|
|
24
|
+
colors?: ThemeColors;
|
|
25
|
+
fonts?: ThemeFonts;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface Transition {
|
|
29
|
+
kind: "none" | "fade" | "slide" | "zoom";
|
|
30
|
+
duration?: number;
|
|
31
|
+
direction?: "left" | "right" | "up" | "down";
|
|
32
|
+
}
|
|
33
|
+
interface Animation {
|
|
34
|
+
effect: "fade" | "fly-in" | "zoom" | "wipe";
|
|
35
|
+
trigger?: "on-click" | "with-prev" | "after-prev";
|
|
36
|
+
direction?: "left" | "right" | "up" | "down";
|
|
37
|
+
duration?: number;
|
|
38
|
+
delay?: number;
|
|
39
|
+
order?: number;
|
|
40
|
+
byParagraph?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface SlideElement {
|
|
43
|
+
id: string;
|
|
44
|
+
type: ElementType;
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
w: number;
|
|
48
|
+
h: number;
|
|
49
|
+
rotation?: number;
|
|
50
|
+
z?: number;
|
|
51
|
+
locked?: boolean;
|
|
52
|
+
hidden?: boolean;
|
|
53
|
+
href?: string;
|
|
54
|
+
animation?: Animation;
|
|
55
|
+
content?: string;
|
|
56
|
+
format?: "markdown" | "html" | "plain";
|
|
57
|
+
style?: Record<string, unknown>;
|
|
58
|
+
src?: string;
|
|
59
|
+
alt?: string;
|
|
60
|
+
fit?: "fill" | "cover" | "contain" | "scale-down";
|
|
61
|
+
crop?: {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
w: number;
|
|
65
|
+
h: number;
|
|
66
|
+
};
|
|
67
|
+
shape?: "rect" | "rounded-rect" | "ellipse" | "triangle" | "line" | "arrow";
|
|
68
|
+
fill?: string;
|
|
69
|
+
stroke?: string;
|
|
70
|
+
strokeWidth?: number;
|
|
71
|
+
dashed?: boolean;
|
|
72
|
+
radius?: number;
|
|
73
|
+
code?: string;
|
|
74
|
+
language?: string;
|
|
75
|
+
codeTheme?: string;
|
|
76
|
+
columns?: {
|
|
77
|
+
key: string;
|
|
78
|
+
label: string;
|
|
79
|
+
}[];
|
|
80
|
+
rows?: Record<string, unknown>[];
|
|
81
|
+
option?: Record<string, unknown>;
|
|
82
|
+
chartTheme?: string;
|
|
83
|
+
image?: string;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
interface SlideBackground {
|
|
87
|
+
color?: string;
|
|
88
|
+
image?: string;
|
|
89
|
+
imageFit?: "contain" | "cover" | "fill";
|
|
90
|
+
gradient?: string;
|
|
91
|
+
}
|
|
92
|
+
interface Slide {
|
|
93
|
+
id: string;
|
|
94
|
+
layout?: string;
|
|
95
|
+
elements: SlideElement[];
|
|
96
|
+
background?: SlideBackground;
|
|
97
|
+
transition?: Transition;
|
|
98
|
+
notes?: string;
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
interface Deck {
|
|
102
|
+
id: string;
|
|
103
|
+
title: string;
|
|
104
|
+
theme: DeckTheme;
|
|
105
|
+
slides: Slide[];
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
interface ValidationError {
|
|
109
|
+
path: string;
|
|
110
|
+
expected: string;
|
|
111
|
+
got: string;
|
|
112
|
+
value: unknown;
|
|
113
|
+
hint: string;
|
|
114
|
+
}
|
|
115
|
+
interface RepairResult {
|
|
116
|
+
ok: boolean;
|
|
117
|
+
schema: Record<string, unknown>;
|
|
118
|
+
errors: ValidationError[];
|
|
119
|
+
}
|
|
120
|
+
interface WriteResult {
|
|
121
|
+
path: string;
|
|
122
|
+
bytes: number;
|
|
123
|
+
slides: number;
|
|
124
|
+
}
|
|
125
|
+
interface WriteOptions {
|
|
126
|
+
tempDir?: string;
|
|
127
|
+
allowHttpImages?: boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Agent — the structured-tool surface for DarkSlide. Mirrors PHP `Agent`.
|
|
132
|
+
* Universal methods are synchronous; file-touching methods (`write`) are async
|
|
133
|
+
* and Node-only (browsers have no sync FS).
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/** Feature-parity baseline with PHP dark-slide; bumped independently on npm. */
|
|
137
|
+
declare const VERSION = "0.5.2";
|
|
138
|
+
type Any$4 = any;
|
|
139
|
+
declare const Agent: {
|
|
140
|
+
/** Validate a deck without writing. Empty array = valid. */
|
|
141
|
+
validate(deck: Any$4): ValidationError[];
|
|
142
|
+
/**
|
|
143
|
+
* Validate + apply heuristic repairs. Returns `{ ok, schema, errors }` where
|
|
144
|
+
* `ok` is true when the (possibly repaired) deck validates clean.
|
|
145
|
+
*/
|
|
146
|
+
validateAndRepair(deck: Any$4): RepairResult;
|
|
147
|
+
/** PPTX bytes for a deck (no temp file). Universal. Throws SchemaException if invalid. */
|
|
148
|
+
toBytes(deck: Any$4, options?: WriteOptions): Uint8Array;
|
|
149
|
+
/** Write a deck to disk as a PPTX file (Node only). Throws SchemaException if invalid. */
|
|
150
|
+
write(deck: Any$4, path: string, options?: WriteOptions): Promise<WriteResult>;
|
|
151
|
+
/** Read PPTX bytes back into the Deck schema. Universal. */
|
|
152
|
+
read(input: Uint8Array | ArrayBuffer): Record<string, unknown>;
|
|
153
|
+
/** Alias for {@see read}. */
|
|
154
|
+
fromBytes(input: Uint8Array | ArrayBuffer): Record<string, unknown>;
|
|
155
|
+
/** Plain-text summary of a deck. Mirrors PHP `Agent::describe`. */
|
|
156
|
+
describe(deck: Any$4): string;
|
|
157
|
+
/** JSON Schema export for LLM tool-use registration. */
|
|
158
|
+
jsonSchema(): Record<string, unknown>;
|
|
159
|
+
version(): string;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Top-level instance API mirroring PHP `DarkSlide`. Delegates to {@see Agent};
|
|
164
|
+
* exists so DI consumers can hold a configured instance (tempDir /
|
|
165
|
+
* allowHttpImages) with familiar instance semantics.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
type Any$3 = any;
|
|
169
|
+
declare class DarkSlide {
|
|
170
|
+
private tempDir;
|
|
171
|
+
private allowHttpImages;
|
|
172
|
+
static readonly VERSION = "0.5.2";
|
|
173
|
+
constructor(tempDir?: string | null, allowHttpImages?: boolean);
|
|
174
|
+
validate(deck: Any$3): ValidationError[];
|
|
175
|
+
validateAndRepair(deck: Any$3): RepairResult;
|
|
176
|
+
write(deck: Any$3, path: string): Promise<WriteResult>;
|
|
177
|
+
toBytes(deck: Any$3): Uint8Array;
|
|
178
|
+
private throwIfInvalid;
|
|
179
|
+
read(input: Uint8Array | ArrayBuffer): Record<string, unknown>;
|
|
180
|
+
describe(deck: Any$3): string;
|
|
181
|
+
jsonSchema(): Record<string, unknown>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Thrown by Agent.write/toBytes when the schema is invalid. Mirrors PHP `SchemaException`. */
|
|
185
|
+
declare class SchemaException extends Error {
|
|
186
|
+
readonly errors: ValidationError[];
|
|
187
|
+
constructor(message: string, errors: ValidationError[]);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
type Any$2 = any;
|
|
191
|
+
/** Liberal schema validator. Mirrors PHP `Schema\Validator`. */
|
|
192
|
+
declare class Validator {
|
|
193
|
+
validate(deck: Any$2): ValidationError[];
|
|
194
|
+
private validateSlide;
|
|
195
|
+
private validateElement;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
type Any$1 = any;
|
|
199
|
+
/** Heuristic deck repair. Mirrors PHP `Schema\Repairer`. Never mutates input. */
|
|
200
|
+
declare class Repairer {
|
|
201
|
+
private idCounter;
|
|
202
|
+
repair(deckInput: Any$1): Record<string, unknown>;
|
|
203
|
+
private repairTheme;
|
|
204
|
+
private repairSlides;
|
|
205
|
+
private repairSlide;
|
|
206
|
+
private repairElements;
|
|
207
|
+
private repairElement;
|
|
208
|
+
private generateId;
|
|
209
|
+
private clamp;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Schema constants describing the Deck shape. Mirrors PHP `Schema\Schema`
|
|
214
|
+
* (and `@particle-academy/fancy-slides` types.ts).
|
|
215
|
+
*/
|
|
216
|
+
declare const Schema: {
|
|
217
|
+
VERSION: string;
|
|
218
|
+
ELEMENT_TYPES: readonly ["text", "image", "chart", "code", "table", "shape", "embed"];
|
|
219
|
+
SLIDE_LAYOUTS: readonly ["blank", "title", "title-content", "two-column", "section-divider", "image-text", "text-image", "quote"];
|
|
220
|
+
SHAPE_KINDS: readonly ["rect", "rounded-rect", "ellipse", "triangle", "line", "arrow"];
|
|
221
|
+
TEXT_FORMATS: readonly ["markdown", "html", "plain"];
|
|
222
|
+
SLIDE_TRANSITION_KINDS: readonly ["none", "fade", "slide", "zoom"];
|
|
223
|
+
SLIDE_TRANSITION_DIRECTIONS: readonly ["left", "right", "up", "down"];
|
|
224
|
+
ANIMATION_EFFECTS: readonly ["fade", "fly-in", "zoom", "wipe"];
|
|
225
|
+
ANIMATION_TRIGGERS: readonly ["on-click", "with-prev", "after-prev"];
|
|
226
|
+
ANIMATION_DIRECTIONS: readonly ["left", "right", "up", "down"];
|
|
227
|
+
ANIMATION_DEFAULT_DURATION_MS: number;
|
|
228
|
+
DEFAULT_SLIDE_WIDTH_EMU: number;
|
|
229
|
+
DEFAULT_SLIDE_HEIGHT_EMU: number;
|
|
230
|
+
DEFAULT_THEME_NAME: string;
|
|
231
|
+
deckRequiredKeys(): string[];
|
|
232
|
+
slideRequiredKeys(): string[];
|
|
233
|
+
elementRequiredKeys(): string[];
|
|
234
|
+
jsonSchema(): Record<string, unknown>;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* PPTX (Office Open XML) writer. Faithful 1:1 port of PHP
|
|
239
|
+
* `DarkSlide\Writer\PptxWriter`. Builds the archive entirely in memory and
|
|
240
|
+
* returns its bytes via the vendored `zipSync`. Every emitted string mirrors
|
|
241
|
+
* the PHP writer byte-for-byte.
|
|
242
|
+
*/
|
|
243
|
+
type Any = any;
|
|
244
|
+
declare class PptxWriter {
|
|
245
|
+
private tempDir;
|
|
246
|
+
private allowHttpImages;
|
|
247
|
+
private mediaCounter;
|
|
248
|
+
private chartCounter;
|
|
249
|
+
/** Ordered list of media files queued for the archive. */
|
|
250
|
+
private mediaFiles;
|
|
251
|
+
/** Ordered list of chart part XML queued for the archive. */
|
|
252
|
+
private chartFiles;
|
|
253
|
+
private themeAccent;
|
|
254
|
+
private tnId;
|
|
255
|
+
private pendingSlideRels;
|
|
256
|
+
constructor(tempDir?: string | null, allowHttpImages?: boolean);
|
|
257
|
+
write(): never;
|
|
258
|
+
toBytes(deck: Any): Uint8Array;
|
|
259
|
+
private buildContentTypes;
|
|
260
|
+
private buildTopRels;
|
|
261
|
+
private buildCoreProps;
|
|
262
|
+
private buildAppProps;
|
|
263
|
+
private buildPresentation;
|
|
264
|
+
private buildPresentationRels;
|
|
265
|
+
private buildTheme;
|
|
266
|
+
private buildSlideMaster;
|
|
267
|
+
private buildSlideLayoutIdLst;
|
|
268
|
+
private buildSlideMasterRels;
|
|
269
|
+
private layoutNumberFor;
|
|
270
|
+
private layoutTypeFor;
|
|
271
|
+
private buildSlideLayout;
|
|
272
|
+
private buildSlideLayoutRels;
|
|
273
|
+
private buildSlideXml;
|
|
274
|
+
private buildTransition;
|
|
275
|
+
private transitionSpeed;
|
|
276
|
+
private transitionDirection;
|
|
277
|
+
private buildTiming;
|
|
278
|
+
private buildTargetEl;
|
|
279
|
+
private buildStepPar;
|
|
280
|
+
private buildEffectPar;
|
|
281
|
+
private animationPresetId;
|
|
282
|
+
private buildVisibilitySet;
|
|
283
|
+
private buildFadeEffect;
|
|
284
|
+
private buildFlyInEffect;
|
|
285
|
+
private buildZoomEffect;
|
|
286
|
+
private buildWipeEffect;
|
|
287
|
+
private animationEffect;
|
|
288
|
+
private animationTrigger;
|
|
289
|
+
private animationDirection;
|
|
290
|
+
private animationDuration;
|
|
291
|
+
private animationDelay;
|
|
292
|
+
private buildBackground;
|
|
293
|
+
private parseGradient;
|
|
294
|
+
private splitTopLevelCommas;
|
|
295
|
+
private parseGradientDirection;
|
|
296
|
+
private buildElementXml;
|
|
297
|
+
private applyHyperlink;
|
|
298
|
+
private buildTextShape;
|
|
299
|
+
private buildImageShape;
|
|
300
|
+
private imageCropRect;
|
|
301
|
+
private coverSrcRect;
|
|
302
|
+
private containedRect;
|
|
303
|
+
private buildShape;
|
|
304
|
+
private buildCodeShape;
|
|
305
|
+
private buildHighlightedCodeBody;
|
|
306
|
+
private buildTable;
|
|
307
|
+
private buildTableCell;
|
|
308
|
+
private buildChart;
|
|
309
|
+
private chartPreRenderSrc;
|
|
310
|
+
private buildChartFrame;
|
|
311
|
+
private buildChartPart;
|
|
312
|
+
private buildBarChartXml;
|
|
313
|
+
private buildLineChartXml;
|
|
314
|
+
private buildPieChartXml;
|
|
315
|
+
private buildScatterChartXml;
|
|
316
|
+
private buildCatValAxes;
|
|
317
|
+
private chartSeriesName;
|
|
318
|
+
private chartSeriesFill;
|
|
319
|
+
private chartSeriesLine;
|
|
320
|
+
private chartCatRef;
|
|
321
|
+
private chartValRef;
|
|
322
|
+
private numLit;
|
|
323
|
+
private numStr;
|
|
324
|
+
private chartColor;
|
|
325
|
+
private buildChartPlaceholder;
|
|
326
|
+
private buildPlaceholder;
|
|
327
|
+
private buildTextBody;
|
|
328
|
+
private buildRun;
|
|
329
|
+
private weightToBold;
|
|
330
|
+
private alignToAlgn;
|
|
331
|
+
private xfrmFromFractions;
|
|
332
|
+
private stageMedia;
|
|
333
|
+
private loadImageBytes;
|
|
334
|
+
private extensionForMime;
|
|
335
|
+
private buildSlideRels;
|
|
336
|
+
private buildNotesSlideXml;
|
|
337
|
+
private buildNotesSlideRels;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Best-effort PPTX → Deck reader. Faithful 1:1 port of PHP
|
|
342
|
+
* `DarkSlide\Reader\PptxReader`. Uses the vendored zip + XML parser instead of
|
|
343
|
+
* ZipArchive / SimpleXML.
|
|
344
|
+
*/
|
|
345
|
+
declare class PptxReader {
|
|
346
|
+
private currentSlideRels;
|
|
347
|
+
private parts;
|
|
348
|
+
/** Read a PPTX file's bytes into a Deck schema object. */
|
|
349
|
+
read(bytes: Uint8Array): Record<string, unknown>;
|
|
350
|
+
fromBytes(bytes: Uint8Array): Record<string, unknown>;
|
|
351
|
+
private getPart;
|
|
352
|
+
private extract;
|
|
353
|
+
private parseSlideRels;
|
|
354
|
+
private resolveRelTarget;
|
|
355
|
+
private extractSlideTargets;
|
|
356
|
+
private readCoreTitle;
|
|
357
|
+
private readNotesFor;
|
|
358
|
+
private parseNotesText;
|
|
359
|
+
private parseSlide;
|
|
360
|
+
private parseBackground;
|
|
361
|
+
private gradFillToCss;
|
|
362
|
+
private readMediaAsDataUri;
|
|
363
|
+
private guessMimeFromArchivePath;
|
|
364
|
+
private parseShape;
|
|
365
|
+
private parsePic;
|
|
366
|
+
private parseGraphicFrame;
|
|
367
|
+
private cellText;
|
|
368
|
+
private paragraphToMarkdown;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface ZipFile {
|
|
372
|
+
name: string;
|
|
373
|
+
data: Uint8Array;
|
|
374
|
+
}
|
|
375
|
+
declare function zipSync(files: ZipFile[]): Uint8Array;
|
|
376
|
+
|
|
377
|
+
declare function unzipSync(data: Uint8Array): Record<string, Uint8Array>;
|
|
378
|
+
|
|
379
|
+
export { Agent, type Animation, DarkSlide, type Deck, type DeckTheme, type ElementType, PptxReader, PptxWriter, type RepairResult, Repairer, Schema, SchemaException, type Slide, type SlideBackground, type SlideElement, type ThemeColors, type ThemeFonts, type Transition, VERSION, type ValidationError, Validator, type WriteOptions, type WriteResult, type ZipFile, unzipSync, zipSync };
|