@8btc/ppt-generator-mcp 0.0.31-beta.2 → 0.0.31-beta.3

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.
@@ -68,7 +68,7 @@ const toolHandler = async ({ outline, templateFilePath, outputPath, }) => {
68
68
  templateFilePath = node_path_1.default.join(__dirname, "..", "tpls", "tpl-2.json");
69
69
  }
70
70
  // 演示用,固定模版
71
- // templateFilePath = path.join(__dirname, "..", "tpls", "custom-1.json");
71
+ templateFilePath = node_path_1.default.join(__dirname, "..", "tpls", "custom-1.json");
72
72
  if (!outputPath) {
73
73
  outputPath = process.cwd();
74
74
  }
@@ -1,3 +1,2 @@
1
1
  export { get_ppt_template_list } from "./get-ppt-template-list";
2
2
  export { generate_ppt } from "./generate-ppt";
3
- export { update_ppt_outline } from "./update-ppt-outline";
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.update_ppt_outline = exports.generate_ppt = exports.get_ppt_template_list = void 0;
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; } });
@@ -56,7 +56,7 @@ const generatePPTSlides = (templateSlides, outlineList, imgs = []) => {
56
56
  transitionIndex += 1;
57
57
  }
58
58
  else if (outlineItem.type === "content") {
59
- const contentSlide = generateContent(outlineItem, contentTemplates);
59
+ const contentSlide = generateContent(outlineItem, imgs, contentTemplates);
60
60
  slides.push(contentSlide);
61
61
  }
62
62
  else if (outlineItem.type === "end") {
@@ -181,13 +181,6 @@ const generateCover = (outlineItem, imgs, coverTemplates) => {
181
181
  maxLine: 1,
182
182
  });
183
183
  }
184
- if (checkTextType(el, "subtitle") && outlineItem.data.subtitle) {
185
- return getNewTextElement({
186
- el,
187
- text: outlineItem.data.subtitle,
188
- maxLine: 1,
189
- });
190
- }
191
184
  if (checkTextType(el, "content") && outlineItem.data.text) {
192
185
  return getNewTextElement({
193
186
  el,
@@ -326,7 +319,7 @@ const generateTransition = (outlineItem, imgs, transitionTemplate, transitionInd
326
319
  elements,
327
320
  };
328
321
  };
329
- const generateContent = (outlineItem, contentTemplates) => {
322
+ const generateContent = (outlineItem, imgs, contentTemplates) => {
330
323
  const _contentTemplates = getUseableTemplates(contentTemplates, outlineItem.data.items.length, "item");
331
324
  const contentTemplate = _contentTemplates[Math.floor(Math.random() * _contentTemplates.length)];
332
325
  const sortedTitleItemIds = contentTemplate.elements
@@ -353,14 +346,6 @@ const generateContent = (outlineItem, contentTemplates) => {
353
346
  return aIndex - bIndex;
354
347
  })
355
348
  .map((el) => el.id);
356
- const sortedImageItemIds = contentTemplate.elements
357
- .filter((el) => el.type === "image")
358
- .sort((a, b) => {
359
- const aIndex = a.left + a.top * 2;
360
- const bIndex = b.left + b.top * 2;
361
- return aIndex - bIndex;
362
- })
363
- .map((el) => el.id);
364
349
  const itemTitles = [];
365
350
  const itemTexts = [];
366
351
  for (const _item of outlineItem.data.items) {
@@ -372,11 +357,8 @@ const generateContent = (outlineItem, contentTemplates) => {
372
357
  const longestTitle = itemTitles.reduce((longest, current) => (current.length > longest.length ? current : longest), "");
373
358
  const longestText = itemTexts.reduce((longest, current) => (current.length > longest.length ? current : longest), "");
374
359
  const elements = contentTemplate.elements.map((el) => {
375
- if (el.type === "image" && el.imageType) {
376
- const index = sortedImageItemIds.findIndex((id) => id === el.id);
377
- const imageItem = outlineItem.data.images?.[index];
378
- return updateImgElement(el, imageItem);
379
- }
360
+ if (el.type === "image" && el.imageType)
361
+ return getNewImgElement(el, imgs);
380
362
  if (el.type !== "text" && el.type !== "shape")
381
363
  return el;
382
364
  if (outlineItem.data.items.length === 1) {
@@ -432,13 +414,6 @@ const generateContent = (outlineItem, contentTemplates) => {
432
414
  maxLine: 1,
433
415
  });
434
416
  }
435
- if (checkTextType(el, "subtitle") && outlineItem.data.subtitle) {
436
- return getNewTextElement({
437
- el,
438
- text: outlineItem.data.subtitle,
439
- maxLine: 1,
440
- });
441
- }
442
417
  return el;
443
418
  });
444
419
  return {
@@ -511,15 +486,6 @@ const getNewImgElement = (el, imgs) => {
511
486
  height: randomImg.height,
512
487
  };
513
488
  };
514
- // 替换图片元素
515
- const updateImgElement = (el, imageItem) => {
516
- if (!imageItem)
517
- return el;
518
- return {
519
- ...el,
520
- src: imageItem.src,
521
- };
522
- };
523
489
  const checkTextType = (el, type) => {
524
490
  return ((el.type === "text" && el.textType === type) ||
525
491
  (el.type === "shape" && el.text && el.text.type === type));
@@ -1,12 +1,7 @@
1
- export interface IImage {
2
- imageType: "pageFigure" | "itemFigure" | "background";
3
- src: string;
4
- }
5
1
  export interface OutlineCover {
6
2
  type: "cover";
7
3
  data: {
8
4
  title: string;
9
- subtitle?: string;
10
5
  text: string;
11
6
  };
12
7
  }
@@ -14,7 +9,6 @@ export interface OutlineContents {
14
9
  type: "contents";
15
10
  data: {
16
11
  items: string[];
17
- images?: IImage[];
18
12
  };
19
13
  offset?: number;
20
14
  }
@@ -23,19 +17,16 @@ export interface OutlineTransition {
23
17
  data: {
24
18
  title: string;
25
19
  text: string;
26
- images?: IImage[];
27
20
  };
28
21
  }
29
22
  export interface OutlineContent {
30
23
  type: "content";
31
24
  data: {
32
25
  title: string;
33
- subtitle?: string;
34
26
  items: {
35
27
  title: string;
36
28
  text: string;
37
29
  }[];
38
- images?: IImage[];
39
30
  };
40
31
  offset?: number;
41
32
  }
@@ -0,0 +1,6 @@
1
+ export declare const imageToBase64: (url: string) => Promise<{
2
+ base64: string;
3
+ dataUrl: string;
4
+ contentType: string;
5
+ size: number;
6
+ }>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.imageToBase64 = void 0;
7
+ const https_1 = __importDefault(require("https"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const imageToBase64 = (url) => {
10
+ return new Promise((resolve, reject) => {
11
+ // 根据URL协议选择模块
12
+ const client = url.startsWith("https") ? https_1.default : http_1.default;
13
+ client
14
+ .get(url, (response) => {
15
+ const chunks = [];
16
+ response.on("data", (chunk) => {
17
+ chunks.push(chunk);
18
+ });
19
+ response.on("end", () => {
20
+ const buffer = Buffer.concat(chunks);
21
+ const base64 = buffer.toString("base64");
22
+ // 获取内容类型
23
+ const contentType = response.headers["content-type"] || "image/jpeg";
24
+ const dataUrl = `data:${contentType};base64,${base64}`;
25
+ resolve({
26
+ base64: base64,
27
+ dataUrl: dataUrl,
28
+ contentType: contentType,
29
+ size: buffer.length,
30
+ });
31
+ });
32
+ response.on("error", reject);
33
+ })
34
+ .on("error", reject);
35
+ });
36
+ };
37
+ exports.imageToBase64 = imageToBase64;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8btc/ppt-generator-mcp",
3
- "version": "0.0.31-beta.2",
3
+ "version": "0.0.31-beta.3",
4
4
  "description": "MCP service for generating PPT files from AI-generated outlines and templates",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {