json2pptx 0.4.2 → 0.5.0

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,13 +13,13 @@ npm i json2pptx
13
13
  ```ts
14
14
  import { createPPTX } from 'json2pptx'
15
15
 
16
- const slide = {
16
+ const deck = {
17
17
  title: 'Demo',
18
18
  width: 1000,
19
19
  height: 562.5,
20
20
  slides: [
21
21
  {
22
- background: { color: '#ffffff' },
22
+ background: { type: 'solid', color: '#ffffff' },
23
23
  elements: [
24
24
  {
25
25
  type: 'text',
@@ -34,7 +34,7 @@ const slide = {
34
34
  ]
35
35
  }
36
36
 
37
- const { blob, fileName } = await createPPTX(slide)
37
+ const { blob, fileName } = await createPPTX(deck)
38
38
  // 在浏览器中下载:
39
39
  // const url = URL.createObjectURL(blob)
40
40
  // const a = document.createElement('a')
@@ -45,9 +45,10 @@ const { blob, fileName } = await createPPTX(slide)
45
45
 
46
46
  ## API
47
47
 
48
- ### `createPPTX(template: Deck): Promise<{ blob: Blob; fileName: string }>`
48
+ ### `createPPTX(template: Presentation): Promise<{ blob: Blob; fileName: string }>`
49
49
 
50
- 根据 `Deck` 数据生成 PPTX 的 `Blob` 与建议文件名。
50
+ 根据 `Presentation` 数据生成 PPTX 的 `Blob` 与建议文件名。输入会先经过
51
+ `json2pptx-schema` 的迁移、校验和规范化流程。
51
52
 
52
53
  ### `resolveImageData(src: string): Promise<string>`
53
54
 
@@ -59,7 +60,15 @@ const { blob, fileName } = await createPPTX(slide)
59
60
  ## 类型
60
61
 
61
62
  包内导出了常用类型:
62
- `Deck`、`Slide`、`SlideElement`、`TextElement`、`ImageElement`、`ShapeElement`、`LineElement` 等。
63
+ `Presentation`、`PresentationData`、`PresentationTheme`、`Slide`、`SlideElement`、
64
+ `TextElement`、`ImageElement`、`ShapeElement`、`LineElement` 等。
65
+
66
+ ## 说明
67
+
68
+ - `background` / `fill` 使用显式联合类型:`solid | gradient | image`。
69
+ - 导出的 `.pptx` 只使用 Office 原生 XML 表达视觉信息,不会嵌入自定义 JSON 文件。
70
+ - 与 `ppt2json` 的视觉 round-trip 优先围绕共享视觉 primitive 和仓库内模板优化。
71
+ - `Deck` / `DeckTheme` 仍保留为兼容别名,但新的推荐命名是 `Presentation` / `PresentationTheme`。
63
72
 
64
73
  ## 开发
65
74
 
package/dist/index.d.mts CHANGED
@@ -1,3 +1,26 @@
1
+ type FillGradientStop = {
2
+ pos?: number;
3
+ color?: string;
4
+ };
5
+ type FillGradient = {
6
+ type?: string;
7
+ rotate?: number;
8
+ colors?: FillGradientStop[];
9
+ };
10
+ type SolidFill = {
11
+ type: 'solid';
12
+ color?: string;
13
+ };
14
+ type GradientFill = {
15
+ type: 'gradient';
16
+ gradient?: FillGradient;
17
+ };
18
+ type ImageFill = {
19
+ type: 'image';
20
+ src?: string;
21
+ opacity?: number;
22
+ };
23
+ type ElementFill = SolidFill | GradientFill | ImageFill;
1
24
  type ElementShadow = {
2
25
  color?: string;
3
26
  h?: number;
@@ -41,7 +64,7 @@ type TextElement = BaseElement<'text'> & {
41
64
  content?: string;
42
65
  defaultFontName?: string;
43
66
  defaultColor?: string;
44
- fill?: string;
67
+ fill?: ElementFill;
45
68
  wordSpace?: number;
46
69
  lineHeight?: number;
47
70
  paragraphSpace?: number;
@@ -57,8 +80,7 @@ type ShapeElement = BaseElement<'shape'> & {
57
80
  type: 'shape';
58
81
  path?: string;
59
82
  viewBox?: [number, number];
60
- fill?: string;
61
- pattern?: string;
83
+ fill?: ElementFill;
62
84
  text?: TextContent;
63
85
  };
64
86
  type LineElement = BaseElement<'line'> & {
@@ -94,23 +116,29 @@ type TableElement = BaseElement<'table'> & {
94
116
  cellMinHeight?: number;
95
117
  };
96
118
  type SlideElement = TextElement | ImageElement | ShapeElement | LineElement | TableElement;
97
- type SlideBackground = {
98
- color?: string;
99
- };
119
+ type SlideBackground = ElementFill;
100
120
  type Slide = {
101
121
  background?: SlideBackground;
102
122
  elements?: SlideElement[];
103
123
  };
104
- type DeckTheme = {
124
+ type PresentationTheme = {
125
+ themeColors?: string[];
105
126
  fontName?: string;
127
+ fontColor?: string;
128
+ backgroundColor?: string;
129
+ shadow?: ElementShadow;
130
+ outline?: ElementOutline;
106
131
  };
107
- type Deck = {
132
+ type Presentation = {
108
133
  title?: string;
109
134
  width?: number;
110
135
  height?: number;
111
136
  slides?: Slide[];
112
- theme?: DeckTheme;
137
+ theme?: PresentationTheme;
113
138
  };
139
+ type PresentationData = Presentation;
140
+ type DeckTheme = PresentationTheme;
141
+ type Deck = Presentation;
114
142
 
115
143
  declare const getElementRange: (element: SlideElement) => {
116
144
  minX: number;
@@ -122,13 +150,10 @@ declare const getLineElementPath: (element: SlideElement) => string;
122
150
 
123
151
  declare const resolveImageData: (src: string) => Promise<string>;
124
152
 
125
- declare const ENABLE_DECK_JSON = false;
126
- declare const PPTX_JSON_PAYLOAD_PATH = "json2ppt-editor.json";
127
- declare const PPTX_JSON_PAYLOAD_VERSION = 1;
128
- declare function createPPTX(template: Deck): Promise<{
153
+ declare function createPPTX(template: Presentation): Promise<{
129
154
  blob: Blob;
130
155
  fileName: string;
131
156
  }>;
132
157
  declare const buildPptxBlob: typeof createPPTX;
133
158
 
134
- export { type BaseElement, type Deck, type DeckTheme, ENABLE_DECK_JSON, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, PPTX_JSON_PAYLOAD_PATH, PPTX_JSON_PAYLOAD_VERSION, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
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 };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,26 @@
1
+ type FillGradientStop = {
2
+ pos?: number;
3
+ color?: string;
4
+ };
5
+ type FillGradient = {
6
+ type?: string;
7
+ rotate?: number;
8
+ colors?: FillGradientStop[];
9
+ };
10
+ type SolidFill = {
11
+ type: 'solid';
12
+ color?: string;
13
+ };
14
+ type GradientFill = {
15
+ type: 'gradient';
16
+ gradient?: FillGradient;
17
+ };
18
+ type ImageFill = {
19
+ type: 'image';
20
+ src?: string;
21
+ opacity?: number;
22
+ };
23
+ type ElementFill = SolidFill | GradientFill | ImageFill;
1
24
  type ElementShadow = {
2
25
  color?: string;
3
26
  h?: number;
@@ -41,7 +64,7 @@ type TextElement = BaseElement<'text'> & {
41
64
  content?: string;
42
65
  defaultFontName?: string;
43
66
  defaultColor?: string;
44
- fill?: string;
67
+ fill?: ElementFill;
45
68
  wordSpace?: number;
46
69
  lineHeight?: number;
47
70
  paragraphSpace?: number;
@@ -57,8 +80,7 @@ type ShapeElement = BaseElement<'shape'> & {
57
80
  type: 'shape';
58
81
  path?: string;
59
82
  viewBox?: [number, number];
60
- fill?: string;
61
- pattern?: string;
83
+ fill?: ElementFill;
62
84
  text?: TextContent;
63
85
  };
64
86
  type LineElement = BaseElement<'line'> & {
@@ -94,23 +116,29 @@ type TableElement = BaseElement<'table'> & {
94
116
  cellMinHeight?: number;
95
117
  };
96
118
  type SlideElement = TextElement | ImageElement | ShapeElement | LineElement | TableElement;
97
- type SlideBackground = {
98
- color?: string;
99
- };
119
+ type SlideBackground = ElementFill;
100
120
  type Slide = {
101
121
  background?: SlideBackground;
102
122
  elements?: SlideElement[];
103
123
  };
104
- type DeckTheme = {
124
+ type PresentationTheme = {
125
+ themeColors?: string[];
105
126
  fontName?: string;
127
+ fontColor?: string;
128
+ backgroundColor?: string;
129
+ shadow?: ElementShadow;
130
+ outline?: ElementOutline;
106
131
  };
107
- type Deck = {
132
+ type Presentation = {
108
133
  title?: string;
109
134
  width?: number;
110
135
  height?: number;
111
136
  slides?: Slide[];
112
- theme?: DeckTheme;
137
+ theme?: PresentationTheme;
113
138
  };
139
+ type PresentationData = Presentation;
140
+ type DeckTheme = PresentationTheme;
141
+ type Deck = Presentation;
114
142
 
115
143
  declare const getElementRange: (element: SlideElement) => {
116
144
  minX: number;
@@ -122,13 +150,10 @@ declare const getLineElementPath: (element: SlideElement) => string;
122
150
 
123
151
  declare const resolveImageData: (src: string) => Promise<string>;
124
152
 
125
- declare const ENABLE_DECK_JSON = false;
126
- declare const PPTX_JSON_PAYLOAD_PATH = "json2ppt-editor.json";
127
- declare const PPTX_JSON_PAYLOAD_VERSION = 1;
128
- declare function createPPTX(template: Deck): Promise<{
153
+ declare function createPPTX(template: Presentation): Promise<{
129
154
  blob: Blob;
130
155
  fileName: string;
131
156
  }>;
132
157
  declare const buildPptxBlob: typeof createPPTX;
133
158
 
134
- export { type BaseElement, type Deck, type DeckTheme, ENABLE_DECK_JSON, type ElementClip, type ElementFilters, type ElementOutline, type ElementShadow, type ImageElement, type LineElement, PPTX_JSON_PAYLOAD_PATH, PPTX_JSON_PAYLOAD_VERSION, type ShapeElement, type Slide, type SlideBackground, type SlideElement, type TextContent, type TextElement, buildPptxBlob, createPPTX, getElementRange, getLineElementPath, resolveImageData };
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 };