@8btc/ppt-generator-mcp 0.0.32-beta.2 → 0.0.32
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/dist/tools/generate-ppt.d.ts +0 -34
- package/dist/tools/generate-ppt.js +0 -11
- package/dist/tools/get-ppt-template-list.js +20 -20
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +1 -3
- package/dist/tools/pptGenerator/export-pptx.js +0 -7
- package/dist/tools/pptGenerator/generate-ppt-slides.d.ts +1 -1
- package/dist/tools/pptGenerator/generate-ppt-slides.js +65 -82
- package/dist/tools/pptGenerator/ppt-generator.js +1 -1
- package/dist/types/outline.d.ts +0 -10
- package/package.json +1 -1
|
@@ -86,36 +86,18 @@ declare const t: z.ZodObject<{
|
|
|
86
86
|
title: string;
|
|
87
87
|
text: string;
|
|
88
88
|
}>, "many">;
|
|
89
|
-
images: z.ZodArray<z.ZodObject<{
|
|
90
|
-
imageType: z.ZodEnum<["pageFigure", "itemFigure"]>;
|
|
91
|
-
src: z.ZodString;
|
|
92
|
-
}, "strip", z.ZodTypeAny, {
|
|
93
|
-
src: string;
|
|
94
|
-
imageType: "pageFigure" | "itemFigure";
|
|
95
|
-
}, {
|
|
96
|
-
src: string;
|
|
97
|
-
imageType: "pageFigure" | "itemFigure";
|
|
98
|
-
}>, "many">;
|
|
99
89
|
}, "strip", z.ZodTypeAny, {
|
|
100
90
|
title: string;
|
|
101
91
|
items: {
|
|
102
92
|
title: string;
|
|
103
93
|
text: string;
|
|
104
94
|
}[];
|
|
105
|
-
images: {
|
|
106
|
-
src: string;
|
|
107
|
-
imageType: "pageFigure" | "itemFigure";
|
|
108
|
-
}[];
|
|
109
95
|
}, {
|
|
110
96
|
title: string;
|
|
111
97
|
items: {
|
|
112
98
|
title: string;
|
|
113
99
|
text: string;
|
|
114
100
|
}[];
|
|
115
|
-
images: {
|
|
116
|
-
src: string;
|
|
117
|
-
imageType: "pageFigure" | "itemFigure";
|
|
118
|
-
}[];
|
|
119
101
|
}>;
|
|
120
102
|
}, "strip", z.ZodTypeAny, {
|
|
121
103
|
type: "content";
|
|
@@ -125,10 +107,6 @@ declare const t: z.ZodObject<{
|
|
|
125
107
|
title: string;
|
|
126
108
|
text: string;
|
|
127
109
|
}[];
|
|
128
|
-
images: {
|
|
129
|
-
src: string;
|
|
130
|
-
imageType: "pageFigure" | "itemFigure";
|
|
131
|
-
}[];
|
|
132
110
|
};
|
|
133
111
|
}, {
|
|
134
112
|
type: "content";
|
|
@@ -138,10 +116,6 @@ declare const t: z.ZodObject<{
|
|
|
138
116
|
title: string;
|
|
139
117
|
text: string;
|
|
140
118
|
}[];
|
|
141
|
-
images: {
|
|
142
|
-
src: string;
|
|
143
|
-
imageType: "pageFigure" | "itemFigure";
|
|
144
|
-
}[];
|
|
145
119
|
};
|
|
146
120
|
}>, z.ZodObject<{
|
|
147
121
|
type: z.ZodLiteral<"end">;
|
|
@@ -177,10 +151,6 @@ declare const t: z.ZodObject<{
|
|
|
177
151
|
title: string;
|
|
178
152
|
text: string;
|
|
179
153
|
}[];
|
|
180
|
-
images: {
|
|
181
|
-
src: string;
|
|
182
|
-
imageType: "pageFigure" | "itemFigure";
|
|
183
|
-
}[];
|
|
184
154
|
};
|
|
185
155
|
} | {
|
|
186
156
|
type: "end";
|
|
@@ -214,10 +184,6 @@ declare const t: z.ZodObject<{
|
|
|
214
184
|
title: string;
|
|
215
185
|
text: string;
|
|
216
186
|
}[];
|
|
217
|
-
images: {
|
|
218
|
-
src: string;
|
|
219
|
-
imageType: "pageFigure" | "itemFigure";
|
|
220
|
-
}[];
|
|
221
187
|
};
|
|
222
188
|
} | {
|
|
223
189
|
type: "end";
|
|
@@ -47,10 +47,6 @@ const inputSchema = {
|
|
|
47
47
|
title: zod_1.z.string(),
|
|
48
48
|
text: zod_1.z.string(),
|
|
49
49
|
})),
|
|
50
|
-
images: zod_1.z.array(zod_1.z.object({
|
|
51
|
-
imageType: zod_1.z.enum(["pageFigure", "itemFigure"]), // 先不要背景
|
|
52
|
-
src: zod_1.z.string(),
|
|
53
|
-
})),
|
|
54
50
|
}),
|
|
55
51
|
}),
|
|
56
52
|
zod_1.z.object({
|
|
@@ -76,13 +72,6 @@ const toolHandler = async ({ outline, templateFilePath, outputPath, }) => {
|
|
|
76
72
|
if (!outputPath) {
|
|
77
73
|
outputPath = process.cwd();
|
|
78
74
|
}
|
|
79
|
-
// 去掉有几率传入的后缀
|
|
80
|
-
if (outputPath.endsWith(".pptx")) {
|
|
81
|
-
outputPath = outputPath.substring(0, outputPath.length - 5);
|
|
82
|
-
}
|
|
83
|
-
if (outputPath.endsWith(".ppt")) {
|
|
84
|
-
outputPath = outputPath.substring(0, outputPath.length - 4);
|
|
85
|
-
}
|
|
86
75
|
outputPath = node_path_1.default.resolve(outputPath);
|
|
87
76
|
try {
|
|
88
77
|
fs_extra_1.default.ensureDirSync(outputPath);
|
|
@@ -23,30 +23,30 @@ const toolHandler = async () => {
|
|
|
23
23
|
{
|
|
24
24
|
type: "text",
|
|
25
25
|
text: JSON.stringify([
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
{
|
|
27
|
+
name: "清新风格模板-图标比较多",
|
|
28
|
+
path: node_path_1.default.join(__dirname, "..", "tpls", "tpl-3.json"),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "研究报告风格模板-紫色系",
|
|
32
|
+
path: node_path_1.default.join(__dirname, "..", "tpls", "tpl-4.json"),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "简约风格模板-莫兰迪色系",
|
|
36
|
+
path: node_path_1.default.join(__dirname, "..", "tpls", "tpl-2.json"),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "简单模板-蓝色调",
|
|
40
|
+
path: node_path_1.default.join(__dirname, "..", "tpls", "tpl-1.json"),
|
|
41
|
+
},
|
|
42
42
|
{
|
|
43
43
|
name: "通用模板-商务风格",
|
|
44
44
|
path: node_path_1.default.join(__dirname, "..", "tpls", "custom-1.json"),
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
{
|
|
47
|
+
name: "通用模板-报告风格",
|
|
48
|
+
path: node_path_1.default.join(__dirname, "..", "tpls", "custom-2.json"),
|
|
49
|
+
},
|
|
50
50
|
]),
|
|
51
51
|
},
|
|
52
52
|
],
|
package/dist/tools/index.d.ts
CHANGED
package/dist/tools/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generate_ppt = exports.get_ppt_template_list = void 0;
|
|
4
4
|
var get_ppt_template_list_1 = require("./get-ppt-template-list");
|
|
5
5
|
Object.defineProperty(exports, "get_ppt_template_list", { enumerable: true, get: function () { return get_ppt_template_list_1.get_ppt_template_list; } });
|
|
6
6
|
var generate_ppt_1 = require("./generate-ppt");
|
|
7
7
|
Object.defineProperty(exports, "generate_ppt", { enumerable: true, get: function () { return generate_ppt_1.generate_ppt; } });
|
|
8
|
-
var update_ppt_outline_1 = require("./update-ppt-outline");
|
|
9
|
-
Object.defineProperty(exports, "update_ppt_outline", { enumerable: true, get: function () { return update_ppt_outline_1.update_ppt_outline; } });
|
|
@@ -137,13 +137,6 @@ const exportPPTX = (_slides, ignoreMedia, options) => {
|
|
|
137
137
|
w: el.width / ratioPx2Inch(viewportSize),
|
|
138
138
|
h: el.height / ratioPx2Inch(viewportSize),
|
|
139
139
|
};
|
|
140
|
-
if (el.imageType) {
|
|
141
|
-
options.sizing = {
|
|
142
|
-
type: "contain",
|
|
143
|
-
w: el.width / ratioPx2Inch(viewportSize),
|
|
144
|
-
h: el.height / ratioPx2Inch(viewportSize),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
140
|
if (isBase64Image(el.src))
|
|
148
141
|
options.data = el.src;
|
|
149
142
|
else
|
|
@@ -6,5 +6,5 @@ interface ImgPoolItem {
|
|
|
6
6
|
width: number;
|
|
7
7
|
height: number;
|
|
8
8
|
}
|
|
9
|
-
export declare const generatePPTSlides: (templateSlides: Slide[], outlineList: Outline[], imgs?: ImgPoolItem[]) =>
|
|
9
|
+
export declare const generatePPTSlides: (templateSlides: Slide[], outlineList: Outline[], imgs?: ImgPoolItem[]) => Slide[];
|
|
10
10
|
export {};
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.generatePPTSlides = void 0;
|
|
7
|
-
const logger_1 = __importDefault(require("../../utils/logger"));
|
|
8
|
-
const loadImage_1 = require("../../utils/loadImage");
|
|
9
|
-
const slides_util_1 = require("./slides-util");
|
|
10
4
|
class CanvasBrowser {
|
|
11
5
|
constructor(width, height) {
|
|
12
6
|
this.el = document.createElement("canvas");
|
|
@@ -24,7 +18,7 @@ if (!globalThis.CanvasImpl) {
|
|
|
24
18
|
const nanoid = (length = 10) => {
|
|
25
19
|
return Math.random().toString(16).slice(0, length);
|
|
26
20
|
};
|
|
27
|
-
const generatePPTSlides =
|
|
21
|
+
const generatePPTSlides = (templateSlides, outlineList, imgs = []) => {
|
|
28
22
|
const slides = [];
|
|
29
23
|
const coverTemplates = [];
|
|
30
24
|
const contentsTemplates = [];
|
|
@@ -62,7 +56,7 @@ const generatePPTSlides = async (templateSlides, outlineList, imgs = []) => {
|
|
|
62
56
|
transitionIndex += 1;
|
|
63
57
|
}
|
|
64
58
|
else if (outlineItem.type === "content") {
|
|
65
|
-
const contentSlide =
|
|
59
|
+
const contentSlide = generateContent(outlineItem, imgs, contentTemplates);
|
|
66
60
|
slides.push(contentSlide);
|
|
67
61
|
}
|
|
68
62
|
else if (outlineItem.type === "end") {
|
|
@@ -76,7 +70,7 @@ exports.generatePPTSlides = generatePPTSlides;
|
|
|
76
70
|
const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
77
71
|
const normalizedOutlineList = [];
|
|
78
72
|
const maxContentsCount = contentsTemplates.reduce((acc, cur) => {
|
|
79
|
-
const count = cur.elements.filter((el) =>
|
|
73
|
+
const count = cur.elements.filter((el) => checkTextType(el, "item")).length;
|
|
80
74
|
acc = Math.max(acc, count);
|
|
81
75
|
return acc;
|
|
82
76
|
}, 1);
|
|
@@ -180,21 +174,14 @@ const generateCover = (outlineItem, imgs, coverTemplates) => {
|
|
|
180
174
|
return getNewImgElement(el, imgs);
|
|
181
175
|
if (el.type !== "text" && el.type !== "shape")
|
|
182
176
|
return el;
|
|
183
|
-
if (
|
|
177
|
+
if (checkTextType(el, "title") && outlineItem.data.title) {
|
|
184
178
|
return getNewTextElement({
|
|
185
179
|
el,
|
|
186
180
|
text: outlineItem.data.title,
|
|
187
181
|
maxLine: 1,
|
|
188
182
|
});
|
|
189
183
|
}
|
|
190
|
-
if (
|
|
191
|
-
return getNewTextElement({
|
|
192
|
-
el,
|
|
193
|
-
text: outlineItem.data.subtitle,
|
|
194
|
-
maxLine: 1,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
if ((0, slides_util_1.checkTextType)(el, "content") && outlineItem.data.text) {
|
|
184
|
+
if (checkTextType(el, "content") && outlineItem.data.text) {
|
|
198
185
|
return getNewTextElement({
|
|
199
186
|
el,
|
|
200
187
|
text: outlineItem.data.text,
|
|
@@ -210,9 +197,9 @@ const generateCover = (outlineItem, imgs, coverTemplates) => {
|
|
|
210
197
|
};
|
|
211
198
|
};
|
|
212
199
|
const generateContents = (outlineItem, imgs, contentsTemplates) => {
|
|
213
|
-
const _contentsTemplates =
|
|
200
|
+
const _contentsTemplates = getUseableTemplates(contentsTemplates, outlineItem.data.items.length, "item");
|
|
214
201
|
const contentsTemplate = _contentsTemplates[Math.floor(Math.random() * _contentsTemplates.length)];
|
|
215
|
-
const sortedNumberItems = contentsTemplate.elements.filter((el) =>
|
|
202
|
+
const sortedNumberItems = contentsTemplate.elements.filter((el) => checkTextType(el, "itemNumber"));
|
|
216
203
|
const sortedNumberItemIds = sortedNumberItems
|
|
217
204
|
.sort((a, b) => {
|
|
218
205
|
if (sortedNumberItems.length > 6) {
|
|
@@ -237,7 +224,7 @@ const generateContents = (outlineItem, imgs, contentsTemplates) => {
|
|
|
237
224
|
return aIndex - bIndex;
|
|
238
225
|
})
|
|
239
226
|
.map((el) => el.id);
|
|
240
|
-
const sortedItems = contentsTemplate.elements.filter((el) =>
|
|
227
|
+
const sortedItems = contentsTemplate.elements.filter((el) => checkTextType(el, "item"));
|
|
241
228
|
const sortedItemIds = sortedItems
|
|
242
229
|
.sort((a, b) => {
|
|
243
230
|
if (sortedItems.length > 6) {
|
|
@@ -262,7 +249,7 @@ const generateContents = (outlineItem, imgs, contentsTemplates) => {
|
|
|
262
249
|
return getNewImgElement(el, imgs);
|
|
263
250
|
if (el.type !== "text" && el.type !== "shape")
|
|
264
251
|
return el;
|
|
265
|
-
if (
|
|
252
|
+
if (checkTextType(el, "item")) {
|
|
266
253
|
const index = sortedItemIds.findIndex((id) => id === el.id);
|
|
267
254
|
const itemTitle = outlineItem.data.items[index];
|
|
268
255
|
if (itemTitle)
|
|
@@ -276,7 +263,7 @@ const generateContents = (outlineItem, imgs, contentsTemplates) => {
|
|
|
276
263
|
if (el.groupId)
|
|
277
264
|
unusedGroupIds.push(el.groupId);
|
|
278
265
|
}
|
|
279
|
-
if (
|
|
266
|
+
if (checkTextType(el, "itemNumber")) {
|
|
280
267
|
const index = sortedNumberItemIds.findIndex((id) => id === el.id);
|
|
281
268
|
const offset = outlineItem.offset || 0;
|
|
282
269
|
return getNewTextElement({
|
|
@@ -302,21 +289,21 @@ const generateTransition = (outlineItem, imgs, transitionTemplate, transitionInd
|
|
|
302
289
|
return getNewImgElement(el, imgs);
|
|
303
290
|
if (el.type !== "text" && el.type !== "shape")
|
|
304
291
|
return el;
|
|
305
|
-
if (
|
|
292
|
+
if (checkTextType(el, "title") && outlineItem.data.title) {
|
|
306
293
|
return getNewTextElement({
|
|
307
294
|
el,
|
|
308
295
|
text: outlineItem.data.title,
|
|
309
296
|
maxLine: 1,
|
|
310
297
|
});
|
|
311
298
|
}
|
|
312
|
-
if (
|
|
299
|
+
if (checkTextType(el, "content") && outlineItem.data.text) {
|
|
313
300
|
return getNewTextElement({
|
|
314
301
|
el,
|
|
315
302
|
text: outlineItem.data.text,
|
|
316
303
|
maxLine: 3,
|
|
317
304
|
});
|
|
318
305
|
}
|
|
319
|
-
if (
|
|
306
|
+
if (checkTextType(el, "partNumber")) {
|
|
320
307
|
return getNewTextElement({
|
|
321
308
|
el,
|
|
322
309
|
text: transitionIndex + "",
|
|
@@ -332,11 +319,11 @@ const generateTransition = (outlineItem, imgs, transitionTemplate, transitionInd
|
|
|
332
319
|
elements,
|
|
333
320
|
};
|
|
334
321
|
};
|
|
335
|
-
const generateContent =
|
|
336
|
-
const _contentTemplates = (
|
|
322
|
+
const generateContent = (outlineItem, imgs, contentTemplates) => {
|
|
323
|
+
const _contentTemplates = getUseableTemplates(contentTemplates, outlineItem.data.items.length, "item");
|
|
337
324
|
const contentTemplate = _contentTemplates[Math.floor(Math.random() * _contentTemplates.length)];
|
|
338
325
|
const sortedTitleItemIds = contentTemplate.elements
|
|
339
|
-
.filter((el) =>
|
|
326
|
+
.filter((el) => checkTextType(el, "itemTitle"))
|
|
340
327
|
.sort((a, b) => {
|
|
341
328
|
const aIndex = a.left + a.top * 2;
|
|
342
329
|
const bIndex = b.left + b.top * 2;
|
|
@@ -344,7 +331,7 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
344
331
|
})
|
|
345
332
|
.map((el) => el.id);
|
|
346
333
|
const sortedTextItemIds = contentTemplate.elements
|
|
347
|
-
.filter((el) =>
|
|
334
|
+
.filter((el) => checkTextType(el, "item"))
|
|
348
335
|
.sort((a, b) => {
|
|
349
336
|
const aIndex = a.left + a.top * 2;
|
|
350
337
|
const bIndex = b.left + b.top * 2;
|
|
@@ -352,15 +339,7 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
352
339
|
})
|
|
353
340
|
.map((el) => el.id);
|
|
354
341
|
const sortedNumberItemIds = contentTemplate.elements
|
|
355
|
-
.filter((el) =>
|
|
356
|
-
.sort((a, b) => {
|
|
357
|
-
const aIndex = a.left + a.top * 2;
|
|
358
|
-
const bIndex = b.left + b.top * 2;
|
|
359
|
-
return aIndex - bIndex;
|
|
360
|
-
})
|
|
361
|
-
.map((el) => el.id);
|
|
362
|
-
const sortedImageItemIds = contentTemplate.elements
|
|
363
|
-
.filter((el) => el.type === "image" && el.imageType)
|
|
342
|
+
.filter((el) => checkTextType(el, "itemNumber"))
|
|
364
343
|
.sort((a, b) => {
|
|
365
344
|
const aIndex = a.left + a.top * 2;
|
|
366
345
|
const bIndex = b.left + b.top * 2;
|
|
@@ -377,17 +356,14 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
377
356
|
}
|
|
378
357
|
const longestTitle = itemTitles.reduce((longest, current) => (current.length > longest.length ? current : longest), "");
|
|
379
358
|
const longestText = itemTexts.reduce((longest, current) => (current.length > longest.length ? current : longest), "");
|
|
380
|
-
const
|
|
381
|
-
if (el.type === "image" && el.imageType)
|
|
382
|
-
|
|
383
|
-
const imageItem = outlineItem.data.images?.[index];
|
|
384
|
-
return await updateImgElement(el, imageItem);
|
|
385
|
-
}
|
|
359
|
+
const elements = contentTemplate.elements.map((el) => {
|
|
360
|
+
if (el.type === "image" && el.imageType)
|
|
361
|
+
return getNewImgElement(el, imgs);
|
|
386
362
|
if (el.type !== "text" && el.type !== "shape")
|
|
387
363
|
return el;
|
|
388
364
|
if (outlineItem.data.items.length === 1) {
|
|
389
365
|
const contentItem = outlineItem.data.items[0];
|
|
390
|
-
if (
|
|
366
|
+
if (checkTextType(el, "content") && contentItem.text) {
|
|
391
367
|
return getNewTextElement({
|
|
392
368
|
el,
|
|
393
369
|
text: contentItem.text,
|
|
@@ -396,7 +372,7 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
396
372
|
}
|
|
397
373
|
}
|
|
398
374
|
else {
|
|
399
|
-
if (
|
|
375
|
+
if (checkTextType(el, "itemTitle")) {
|
|
400
376
|
const index = sortedTitleItemIds.findIndex((id) => id === el.id);
|
|
401
377
|
const contentItem = outlineItem.data.items[index];
|
|
402
378
|
if (contentItem && contentItem.title) {
|
|
@@ -408,7 +384,7 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
408
384
|
});
|
|
409
385
|
}
|
|
410
386
|
}
|
|
411
|
-
if (
|
|
387
|
+
if (checkTextType(el, "item")) {
|
|
412
388
|
const index = sortedTextItemIds.findIndex((id) => id === el.id);
|
|
413
389
|
const contentItem = outlineItem.data.items[index];
|
|
414
390
|
if (contentItem && contentItem.text) {
|
|
@@ -420,7 +396,7 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
420
396
|
});
|
|
421
397
|
}
|
|
422
398
|
}
|
|
423
|
-
if (
|
|
399
|
+
if (checkTextType(el, "itemNumber")) {
|
|
424
400
|
const index = sortedNumberItemIds.findIndex((id) => id === el.id);
|
|
425
401
|
const offset = outlineItem.offset || 0;
|
|
426
402
|
return getNewTextElement({
|
|
@@ -431,26 +407,15 @@ const generateContent = async (outlineItem, contentTemplates) => {
|
|
|
431
407
|
});
|
|
432
408
|
}
|
|
433
409
|
}
|
|
434
|
-
if (
|
|
410
|
+
if (checkTextType(el, "title") && outlineItem.data.title) {
|
|
435
411
|
return getNewTextElement({
|
|
436
412
|
el,
|
|
437
413
|
text: outlineItem.data.title,
|
|
438
414
|
maxLine: 1,
|
|
439
415
|
});
|
|
440
416
|
}
|
|
441
|
-
if ((0, slides_util_1.checkTextType)(el, "subtitle") && outlineItem.data.subtitle) {
|
|
442
|
-
return getNewTextElement({
|
|
443
|
-
el,
|
|
444
|
-
text: outlineItem.data.subtitle,
|
|
445
|
-
maxLine: 1,
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
417
|
return el;
|
|
449
|
-
};
|
|
450
|
-
const elements = [];
|
|
451
|
-
for (const el of contentTemplate.elements) {
|
|
452
|
-
elements.push(await getEl(el));
|
|
453
|
-
}
|
|
418
|
+
});
|
|
454
419
|
return {
|
|
455
420
|
...contentTemplate,
|
|
456
421
|
id: `${contentTemplate.id}-${nanoid(10)}`,
|
|
@@ -521,28 +486,46 @@ const getNewImgElement = (el, imgs) => {
|
|
|
521
486
|
height: randomImg.height,
|
|
522
487
|
};
|
|
523
488
|
};
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
src: imageItem.src,
|
|
539
|
-
};
|
|
489
|
+
const checkTextType = (el, type) => {
|
|
490
|
+
return ((el.type === "text" && el.textType === type) ||
|
|
491
|
+
(el.type === "shape" && el.text && el.text.type === type));
|
|
492
|
+
};
|
|
493
|
+
const getUseableTemplates = (templates, n, type) => {
|
|
494
|
+
if (n === 1) {
|
|
495
|
+
const list = templates.filter((slide) => {
|
|
496
|
+
const items = slide.elements.filter((el) => checkTextType(el, type));
|
|
497
|
+
const titles = slide.elements.filter((el) => checkTextType(el, "title"));
|
|
498
|
+
const texts = slide.elements.filter((el) => checkTextType(el, "content"));
|
|
499
|
+
return !items.length && titles.length === 1 && texts.length === 1;
|
|
500
|
+
});
|
|
501
|
+
if (list.length)
|
|
502
|
+
return list;
|
|
540
503
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
504
|
+
let target = null;
|
|
505
|
+
const list = templates.filter((slide) => {
|
|
506
|
+
const len = slide.elements.filter((el) => checkTextType(el, type)).length;
|
|
507
|
+
return len >= n;
|
|
508
|
+
});
|
|
509
|
+
if (list.length === 0) {
|
|
510
|
+
const sorted = templates.sort((a, b) => {
|
|
511
|
+
const aLen = a.elements.filter((el) => checkTextType(el, type)).length;
|
|
512
|
+
const bLen = b.elements.filter((el) => checkTextType(el, type)).length;
|
|
513
|
+
return aLen - bLen;
|
|
514
|
+
});
|
|
515
|
+
target = sorted[sorted.length - 1];
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
target = list.reduce((closest, current) => {
|
|
519
|
+
const currentLen = current.elements.filter((el) => checkTextType(el, type)).length;
|
|
520
|
+
const closestLen = closest.elements.filter((el) => checkTextType(el, type)).length;
|
|
521
|
+
return currentLen - n <= closestLen - n ? current : closest;
|
|
522
|
+
});
|
|
544
523
|
}
|
|
545
|
-
return
|
|
524
|
+
return templates.filter((slide) => {
|
|
525
|
+
const len = slide.elements.filter((el) => checkTextType(el, type)).length;
|
|
526
|
+
const targetLen = target.elements.filter((el) => checkTextType(el, type)).length;
|
|
527
|
+
return len === targetLen;
|
|
528
|
+
});
|
|
546
529
|
};
|
|
547
530
|
const getNewTextElement = ({ el, text, maxLine, longestText, digitPadding, }) => {
|
|
548
531
|
const padding = 10;
|
|
@@ -11,7 +11,7 @@ class PPTGenerator {
|
|
|
11
11
|
try {
|
|
12
12
|
const { outline, templateData } = params;
|
|
13
13
|
// 使用AIPPT函数生成slides
|
|
14
|
-
const generatedSlides =
|
|
14
|
+
const generatedSlides = (0, generate_ppt_slides_1.generatePPTSlides)(templateData.slides, outline);
|
|
15
15
|
// 构建完整的result对象,包含模板的其他属性
|
|
16
16
|
const resultData = {
|
|
17
17
|
width: templateData.width,
|
package/dist/types/outline.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { type ImageType } from "./slide";
|
|
2
|
-
export interface IImage {
|
|
3
|
-
imageType: ImageType;
|
|
4
|
-
src: string;
|
|
5
|
-
}
|
|
6
1
|
export interface OutlineCover {
|
|
7
2
|
type: "cover";
|
|
8
3
|
data: {
|
|
9
4
|
title: string;
|
|
10
|
-
subtitle?: string;
|
|
11
5
|
text: string;
|
|
12
6
|
};
|
|
13
7
|
}
|
|
@@ -15,7 +9,6 @@ export interface OutlineContents {
|
|
|
15
9
|
type: "contents";
|
|
16
10
|
data: {
|
|
17
11
|
items: string[];
|
|
18
|
-
images?: IImage[];
|
|
19
12
|
};
|
|
20
13
|
offset?: number;
|
|
21
14
|
}
|
|
@@ -24,19 +17,16 @@ export interface OutlineTransition {
|
|
|
24
17
|
data: {
|
|
25
18
|
title: string;
|
|
26
19
|
text: string;
|
|
27
|
-
images?: IImage[];
|
|
28
20
|
};
|
|
29
21
|
}
|
|
30
22
|
export interface OutlineContent {
|
|
31
23
|
type: "content";
|
|
32
24
|
data: {
|
|
33
25
|
title: string;
|
|
34
|
-
subtitle?: string;
|
|
35
26
|
items: {
|
|
36
27
|
title: string;
|
|
37
28
|
text: string;
|
|
38
29
|
}[];
|
|
39
|
-
images?: IImage[];
|
|
40
30
|
};
|
|
41
31
|
offset?: number;
|
|
42
32
|
}
|