json2pptx 0.5.1 → 0.5.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ npm i json2pptx
13
13
  ```ts
14
14
  import { createPPTX } from 'json2pptx'
15
15
 
16
- const deck = {
16
+ const presentation = {
17
17
  title: 'Demo',
18
18
  width: 1000,
19
19
  height: 562.5,
@@ -34,7 +34,7 @@ const deck = {
34
34
  ]
35
35
  }
36
36
 
37
- const { blob, fileName } = await createPPTX(deck)
37
+ const { blob, fileName } = await createPPTX(presentation)
38
38
  // 在浏览器中下载:
39
39
  // const url = URL.createObjectURL(blob)
40
40
  // const a = document.createElement('a')
@@ -45,7 +45,7 @@ const { blob, fileName } = await createPPTX(deck)
45
45
 
46
46
  ## API
47
47
 
48
- ### `createPPTX(template: Presentation): Promise<{ blob: Blob; fileName: string }>`
48
+ ### `createPPTX(presentation: Presentation): Promise<{ blob: Blob; fileName: string }>`
49
49
 
50
50
  根据 `Presentation` 数据生成 PPTX 的 `Blob` 与建议文件名。输入会先经过
51
51
  `json2pptx-schema` 的迁移、校验和规范化流程。
@@ -68,7 +68,6 @@ const { blob, fileName } = await createPPTX(deck)
68
68
  - `background` / `fill` 使用显式联合类型:`solid | gradient | image`。
69
69
  - 导出的 `.pptx` 只使用 Office 原生 XML 表达视觉信息,不会嵌入自定义 JSON 文件。
70
70
  - 与 `ppt2json` 的视觉 round-trip 优先围绕共享视觉 primitive 和仓库内模板优化。
71
- - `Deck` / `DeckTheme` 仍保留为兼容别名,但新的推荐命名是 `Presentation` / `PresentationTheme`。
72
71
 
73
72
  ## 开发
74
73
 
package/dist/index.d.mts CHANGED
@@ -137,8 +137,6 @@ type Presentation = {
137
137
  theme?: PresentationTheme;
138
138
  };
139
139
  type PresentationData = Presentation;
140
- type DeckTheme = PresentationTheme;
141
- type Deck = Presentation;
142
140
 
143
141
  declare const getElementRange: (element: SlideElement) => {
144
142
  minX: number;
@@ -150,10 +148,10 @@ declare const getLineElementPath: (element: SlideElement) => string;
150
148
 
151
149
  declare const resolveImageData: (src: string) => Promise<string>;
152
150
 
153
- declare function createPPTX(template: Presentation): Promise<{
151
+ declare function createPPTX(presentation: Presentation): Promise<{
154
152
  blob: Blob;
155
153
  fileName: string;
156
154
  }>;
157
155
  declare const buildPptxBlob: typeof createPPTX;
158
156
 
159
- export { type BaseElement, type Deck, type DeckTheme, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, type Presentation, type PresentationData, type PresentationTheme, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
157
+ export { type BaseElement, type Presentation as Deck, type PresentationTheme as DeckTheme, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, type Presentation, type PresentationData, type PresentationTheme, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
package/dist/index.d.ts CHANGED
@@ -137,8 +137,6 @@ type Presentation = {
137
137
  theme?: PresentationTheme;
138
138
  };
139
139
  type PresentationData = Presentation;
140
- type DeckTheme = PresentationTheme;
141
- type Deck = Presentation;
142
140
 
143
141
  declare const getElementRange: (element: SlideElement) => {
144
142
  minX: number;
@@ -150,10 +148,10 @@ declare const getLineElementPath: (element: SlideElement) => string;
150
148
 
151
149
  declare const resolveImageData: (src: string) => Promise<string>;
152
150
 
153
- declare function createPPTX(template: Presentation): Promise<{
151
+ declare function createPPTX(presentation: Presentation): Promise<{
154
152
  blob: Blob;
155
153
  fileName: string;
156
154
  }>;
157
155
  declare const buildPptxBlob: typeof createPPTX;
158
156
 
159
- export { type BaseElement, type Deck, type DeckTheme, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, type Presentation, type PresentationData, type PresentationTheme, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
157
+ export { type BaseElement, type Presentation as Deck, type PresentationTheme as DeckTheme, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, type Presentation, type PresentationData, type PresentationTheme, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
package/dist/index.js CHANGED
@@ -909,8 +909,9 @@ function getShadowOption(shadow, ratioPx2Pt) {
909
909
  angle = 225;
910
910
  }
911
911
  return {
912
+ type: "outer",
912
913
  color: c.color,
913
- transparency: (1 - c.alpha) * 100,
914
+ opacity: c.alpha,
914
915
  blur: ((_b = shadow.blur) != null ? _b : 0) / ratioPx2Pt,
915
916
  offset,
916
917
  angle
@@ -1231,7 +1232,7 @@ function getLineArrowType(value) {
1231
1232
  }
1232
1233
 
1233
1234
  // src/renderers/elements.ts
1234
- function addTextElement(slide, element, template, slideIndex, elementIndex, ratioPx2Pt, ratioPx2Inch, textPadding, fillPatches) {
1235
+ function addTextElement(slide, element, presentation, slideIndex, elementIndex, ratioPx2Pt, ratioPx2Inch, textPadding, fillPatches) {
1235
1236
  var _a, _b, _c, _d, _e, _f, _g;
1236
1237
  if (element.type !== "text" || !element.content) return;
1237
1238
  const textProps = formatHTML(element.content, ratioPx2Pt);
@@ -1244,7 +1245,7 @@ function addTextElement(slide, element, template, slideIndex, elementIndex, rati
1244
1245
  w: ((_d = element.width) != null ? _d : 0) / ratioPx2Inch,
1245
1246
  h: ((_e = element.height) != null ? _e : 0) / ratioPx2Inch,
1246
1247
  fontSize: DEFAULT_FONT_SIZE / ratioPx2Pt,
1247
- fontFace: element.defaultFontName || ((_f = template.theme) == null ? void 0 : _f.fontName) || DEFAULT_FONT_FACE,
1248
+ fontFace: element.defaultFontName || ((_f = presentation.theme) == null ? void 0 : _f.fontName) || DEFAULT_FONT_FACE,
1248
1249
  color: "#000000",
1249
1250
  valign: "top",
1250
1251
  // pptxgenjs margin order: [left, right, bottom, top]
@@ -1385,7 +1386,7 @@ function addShapeElement(slide, element, ratioPx2Pt, ratioPx2Inch, slideIndex, e
1385
1386
  fontFace: element.text.defaultFontName || DEFAULT_FONT_FACE,
1386
1387
  color: "#000000",
1387
1388
  paraSpaceBefore: 0,
1388
- valign: element.text.align === "middle" ? "mid" : element.text.align,
1389
+ valign: element.text.align === "middle" ? "middle" : element.text.align,
1389
1390
  fill: { color: "FFFFFF", transparency: 100 },
1390
1391
  fit: "none",
1391
1392
  objectName: `shape-text-${slideIndex}-${(_n = element.id) != null ? _n : elementIndex}`
@@ -1489,21 +1490,21 @@ function parseDataUrlImage(dataUrl) {
1489
1490
  };
1490
1491
  return { mime, data, ext: (_a = extMap[mime]) != null ? _a : "png" };
1491
1492
  }
1492
- async function createPPTX(template) {
1493
+ async function createPPTX(presentation) {
1493
1494
  var _a, _b, _c, _d;
1494
- const parsedTemplate = (0, import_json2pptx_schema.parseDocument)(template);
1495
- const renderTemplate = parsedTemplate;
1495
+ const parsedPresentation = (0, import_json2pptx_schema.parseDocument)(presentation);
1496
+ const normalizedPresentation = parsedPresentation;
1496
1497
  const pptx = new import_pptxgenjs.default();
1497
1498
  const fillPatches = [];
1498
- const width = parsedTemplate.width;
1499
- const height = parsedTemplate.height;
1499
+ const width = parsedPresentation.width;
1500
+ const height = parsedPresentation.height;
1500
1501
  const ratioPx2Inch = 96 * (width / 960);
1501
1502
  const ratioPx2Pt = 96 / 72 * (width / 960);
1502
1503
  const textPadding = 10 / ratioPx2Pt;
1503
1504
  applyPptxLayout(pptx, width, height);
1504
- for (const [slideIndex, slideJson] of ((_a = renderTemplate.slides) != null ? _a : []).entries()) {
1505
+ for (const [slideIndex, slideJson] of ((_a = normalizedPresentation.slides) != null ? _a : []).entries()) {
1505
1506
  const slide = pptx.addSlide();
1506
- applySlideBackground(slide, slideJson, renderTemplate.theme);
1507
+ applySlideBackground(slide, slideJson, normalizedPresentation.theme);
1507
1508
  if (slideJson.background && fillRequiresXmlPatch(slideJson.background)) {
1508
1509
  fillPatches.push({
1509
1510
  kind: "background",
@@ -1515,7 +1516,7 @@ async function createPPTX(template) {
1515
1516
  addTextElement(
1516
1517
  slide,
1517
1518
  element,
1518
- renderTemplate,
1519
+ normalizedPresentation,
1519
1520
  slideIndex,
1520
1521
  elementIndex,
1521
1522
  ratioPx2Pt,
@@ -1537,7 +1538,7 @@ async function createPPTX(template) {
1537
1538
  addTableElement(slide, element, ratioPx2Pt, ratioPx2Inch);
1538
1539
  }
1539
1540
  }
1540
- const fileName = `${sanitizeFileName(parsedTemplate.title || "presentation")}.pptx`;
1541
+ const fileName = `${sanitizeFileName(parsedPresentation.title || "presentation")}.pptx`;
1541
1542
  const pptxBuffer = await pptx.write({
1542
1543
  outputType: "arraybuffer",
1543
1544
  compression: true