json2pptx 0.5.1 → 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/README.md +3 -4
- package/dist/index.d.mts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm i json2pptx
|
|
|
13
13
|
```ts
|
|
14
14
|
import { createPPTX } from 'json2pptx'
|
|
15
15
|
|
|
16
|
-
const
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
@@ -1231,7 +1231,7 @@ function getLineArrowType(value) {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
|
|
1233
1233
|
// src/renderers/elements.ts
|
|
1234
|
-
function addTextElement(slide, element,
|
|
1234
|
+
function addTextElement(slide, element, presentation, slideIndex, elementIndex, ratioPx2Pt, ratioPx2Inch, textPadding, fillPatches) {
|
|
1235
1235
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1236
1236
|
if (element.type !== "text" || !element.content) return;
|
|
1237
1237
|
const textProps = formatHTML(element.content, ratioPx2Pt);
|
|
@@ -1244,7 +1244,7 @@ function addTextElement(slide, element, template, slideIndex, elementIndex, rati
|
|
|
1244
1244
|
w: ((_d = element.width) != null ? _d : 0) / ratioPx2Inch,
|
|
1245
1245
|
h: ((_e = element.height) != null ? _e : 0) / ratioPx2Inch,
|
|
1246
1246
|
fontSize: DEFAULT_FONT_SIZE / ratioPx2Pt,
|
|
1247
|
-
fontFace: element.defaultFontName || ((_f =
|
|
1247
|
+
fontFace: element.defaultFontName || ((_f = presentation.theme) == null ? void 0 : _f.fontName) || DEFAULT_FONT_FACE,
|
|
1248
1248
|
color: "#000000",
|
|
1249
1249
|
valign: "top",
|
|
1250
1250
|
// pptxgenjs margin order: [left, right, bottom, top]
|
|
@@ -1489,21 +1489,21 @@ function parseDataUrlImage(dataUrl) {
|
|
|
1489
1489
|
};
|
|
1490
1490
|
return { mime, data, ext: (_a = extMap[mime]) != null ? _a : "png" };
|
|
1491
1491
|
}
|
|
1492
|
-
async function createPPTX(
|
|
1492
|
+
async function createPPTX(presentation) {
|
|
1493
1493
|
var _a, _b, _c, _d;
|
|
1494
|
-
const
|
|
1495
|
-
const
|
|
1494
|
+
const parsedPresentation = (0, import_json2pptx_schema.parseDocument)(presentation);
|
|
1495
|
+
const normalizedPresentation = parsedPresentation;
|
|
1496
1496
|
const pptx = new import_pptxgenjs.default();
|
|
1497
1497
|
const fillPatches = [];
|
|
1498
|
-
const width =
|
|
1499
|
-
const height =
|
|
1498
|
+
const width = parsedPresentation.width;
|
|
1499
|
+
const height = parsedPresentation.height;
|
|
1500
1500
|
const ratioPx2Inch = 96 * (width / 960);
|
|
1501
1501
|
const ratioPx2Pt = 96 / 72 * (width / 960);
|
|
1502
1502
|
const textPadding = 10 / ratioPx2Pt;
|
|
1503
1503
|
applyPptxLayout(pptx, width, height);
|
|
1504
|
-
for (const [slideIndex, slideJson] of ((_a =
|
|
1504
|
+
for (const [slideIndex, slideJson] of ((_a = normalizedPresentation.slides) != null ? _a : []).entries()) {
|
|
1505
1505
|
const slide = pptx.addSlide();
|
|
1506
|
-
applySlideBackground(slide, slideJson,
|
|
1506
|
+
applySlideBackground(slide, slideJson, normalizedPresentation.theme);
|
|
1507
1507
|
if (slideJson.background && fillRequiresXmlPatch(slideJson.background)) {
|
|
1508
1508
|
fillPatches.push({
|
|
1509
1509
|
kind: "background",
|
|
@@ -1515,7 +1515,7 @@ async function createPPTX(template) {
|
|
|
1515
1515
|
addTextElement(
|
|
1516
1516
|
slide,
|
|
1517
1517
|
element,
|
|
1518
|
-
|
|
1518
|
+
normalizedPresentation,
|
|
1519
1519
|
slideIndex,
|
|
1520
1520
|
elementIndex,
|
|
1521
1521
|
ratioPx2Pt,
|
|
@@ -1537,7 +1537,7 @@ async function createPPTX(template) {
|
|
|
1537
1537
|
addTableElement(slide, element, ratioPx2Pt, ratioPx2Inch);
|
|
1538
1538
|
}
|
|
1539
1539
|
}
|
|
1540
|
-
const fileName = `${sanitizeFileName(
|
|
1540
|
+
const fileName = `${sanitizeFileName(parsedPresentation.title || "presentation")}.pptx`;
|
|
1541
1541
|
const pptxBuffer = await pptx.write({
|
|
1542
1542
|
outputType: "arraybuffer",
|
|
1543
1543
|
compression: true
|