ppt-dsl-renderer 1.1.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/AGENT_PPTX_EXPORT.md +81 -0
- package/AGENT_USAGE.md +87 -0
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/THIRD_PARTY_NOTICES.md +43 -0
- package/dist/browser/renderer.css +1 -0
- package/dist/browser/renderer.js +80 -0
- package/dist/cli.js +243 -0
- package/dist/index.js +140 -0
- package/dist/pptx/exporter.js +129 -0
- package/dist/pptx/index.js +7437 -0
- package/dist/vue/renderer.css +1 -0
- package/dist/vue/renderer.js +577 -0
- package/docs/AGENT.md +36 -0
- package/docs/DSL.md +60 -0
- package/docs/VUE.md +231 -0
- package/examples/deck.json +302 -0
- package/package.json +85 -0
- package/src/index.d.ts +24 -0
- package/src/pptx.d.ts +30 -0
- package/src/types/ppt-dsl.d.ts +241 -0
- package/src/types/vue.d.ts +40 -0
- package/src/vue.d.ts +16 -0
- package/third-party-licenses/core-util-is/LICENSE +19 -0
- package/third-party-licenses/dompurify/LICENSE +568 -0
- package/third-party-licenses/echarts/LICENSE +222 -0
- package/third-party-licenses/echarts/LICENSE-d3 +27 -0
- package/third-party-licenses/echarts/NOTICE +5 -0
- package/third-party-licenses/immediate/LICENSE.txt +20 -0
- package/third-party-licenses/inherits/LICENSE +16 -0
- package/third-party-licenses/isarray/LICENSE +22 -0
- package/third-party-licenses/jszip/LICENSE.markdown +651 -0
- package/third-party-licenses/lie/license.md +7 -0
- package/third-party-licenses/pako/LICENSE +21 -0
- package/third-party-licenses/pptxgenjs/LICENSE +21 -0
- package/third-party-licenses/readable-stream/LICENSE +47 -0
- package/third-party-licenses/safe-buffer/LICENSE +21 -0
- package/third-party-licenses/setimmediate/LICENSE.txt +20 -0
- package/third-party-licenses/string_decoder/LICENSE +48 -0
- package/third-party-licenses/svg-pathdata/LICENSE +20 -0
- package/third-party-licenses/tinycolor2/LICENSE +20 -0
- package/third-party-licenses/tslib/LICENSE.txt +12 -0
- package/third-party-licenses/util-deprecate/LICENSE +24 -0
- package/third-party-licenses/vue/LICENSE +21 -0
- package/third-party-licenses/vue-reactivity/LICENSE +21 -0
- package/third-party-licenses/vue-runtime-core/LICENSE +21 -0
- package/third-party-licenses/vue-runtime-dom/LICENSE +21 -0
- package/third-party-licenses/vue-shared/LICENSE +21 -0
- package/third-party-licenses/zrender/LICENSE +29 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PptDslDocument } from './types/ppt-dsl.js'
|
|
2
|
+
|
|
3
|
+
export type * from './types/ppt-dsl.js'
|
|
4
|
+
|
|
5
|
+
export interface RenderOptions {
|
|
6
|
+
/** 从 1 开始;省略时生成全部页。重复页码合并,始终按文档顺序返回。 */
|
|
7
|
+
pages?: number[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface RenderedPage {
|
|
11
|
+
pageNumber: number
|
|
12
|
+
slideId: string
|
|
13
|
+
width: number
|
|
14
|
+
height: number
|
|
15
|
+
html: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RenderStatus {
|
|
19
|
+
status: 'loading' | 'ready' | 'error'
|
|
20
|
+
errors: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 生成 HTML 字符串,不启动浏览器、不写文件、不修改输入。 */
|
|
24
|
+
export function renderToHtml(document: PptDslDocument, options?: RenderOptions): Promise<RenderedPage[]>
|
package/src/pptx.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PptDslDocument } from './types/ppt-dsl.js'
|
|
2
|
+
|
|
3
|
+
export interface PptxExportOptions {
|
|
4
|
+
/** 从 1 开始;省略导出全部页,重复页码合并并按文档顺序导出。 */
|
|
5
|
+
pages?: number[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface PptxExportState {
|
|
9
|
+
/** generated 仅表示二进制已生成,不表示已上传或保存。 */
|
|
10
|
+
status: 'idle' | 'exporting' | 'writing' | 'generated' | 'error'
|
|
11
|
+
completedPages: number
|
|
12
|
+
totalPages: number
|
|
13
|
+
fileName: string
|
|
14
|
+
errors: string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 浏览器侧状态;同一页面同时只允许一次导出。 */
|
|
18
|
+
export const pptxExportState: PptxExportState
|
|
19
|
+
|
|
20
|
+
/** 返回完整 PPTX ArrayBuffer,不触发下载或上传;包含音视频并应用默认母版。仅限浏览器。 */
|
|
21
|
+
export function exportToPptx(document: PptDslDocument, options?: PptxExportOptions): Promise<ArrayBuffer>
|
|
22
|
+
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
/** 加载 dist/pptx/exporter.js 后可用;仅导入模块不会安装全局方法。 */
|
|
26
|
+
exportToPptx?: typeof exportToPptx
|
|
27
|
+
/** 运行脚本加载后即可读取初始状态。 */
|
|
28
|
+
__PPT_DSL_EXPORT__?: PptxExportState
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
export type PptDslElementType = 'text' | 'image' | 'shape' | 'line' | 'chart' | 'table' | 'latex' | 'video' | 'audio'
|
|
2
|
+
|
|
3
|
+
export interface PptDslOutline {
|
|
4
|
+
color?: string
|
|
5
|
+
style?: 'solid' | 'dashed' | 'dotted'
|
|
6
|
+
width?: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PptDslShadow {
|
|
10
|
+
blur: number
|
|
11
|
+
color: string
|
|
12
|
+
h: number
|
|
13
|
+
v: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PptDslGradient {
|
|
17
|
+
colors: Array<{ color: string; pos: number }>
|
|
18
|
+
rotate?: number
|
|
19
|
+
type: 'linear' | 'radial'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PptDslBaseElement {
|
|
23
|
+
class?: string
|
|
24
|
+
groupId?: string
|
|
25
|
+
height?: number
|
|
26
|
+
id: string
|
|
27
|
+
left: number
|
|
28
|
+
link?: { target: string; type: 'slide' | 'web' }
|
|
29
|
+
lock?: boolean
|
|
30
|
+
name?: string
|
|
31
|
+
opacity?: number
|
|
32
|
+
rotate?: number
|
|
33
|
+
top: number
|
|
34
|
+
type: PptDslElementType
|
|
35
|
+
width?: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface PptDslTextElement extends PptDslBaseElement {
|
|
39
|
+
content: string
|
|
40
|
+
defaultColor?: string
|
|
41
|
+
defaultFontName?: string
|
|
42
|
+
fill?: string
|
|
43
|
+
fixedHeight?: boolean
|
|
44
|
+
/** 内边距,按上、右、下、左排列,单位为 CSS 像素。 */
|
|
45
|
+
inset?: [number, number, number, number]
|
|
46
|
+
lineHeight?: number
|
|
47
|
+
outline?: PptDslOutline
|
|
48
|
+
paragraphSpace?: number
|
|
49
|
+
shadow?: PptDslShadow
|
|
50
|
+
type: 'text'
|
|
51
|
+
/** 文本用途标记;PPTX 导出保持原始文本框尺寸。 */
|
|
52
|
+
textType?: 'title' | 'subtitle' | 'content' | 'item' | 'itemTitle' | 'notes' | 'header' | 'footer' | 'partNumber' | 'itemNumber'
|
|
53
|
+
vAlign?: 'bottom' | 'middle' | 'top'
|
|
54
|
+
vertical?: boolean
|
|
55
|
+
wordSpace?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PptDslImageElement extends PptDslBaseElement {
|
|
59
|
+
clip?: { range: [[number, number], [number, number]]; shape?: string }
|
|
60
|
+
colorMask?: string
|
|
61
|
+
filters?: Record<string, string>
|
|
62
|
+
fixedRatio?: boolean
|
|
63
|
+
fit?: 'contain' | 'cover' | 'fill'
|
|
64
|
+
flipH?: boolean
|
|
65
|
+
flipV?: boolean
|
|
66
|
+
outline?: PptDslOutline
|
|
67
|
+
radius?: number
|
|
68
|
+
shadow?: PptDslShadow
|
|
69
|
+
src: string
|
|
70
|
+
type: 'image'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface PptDslShapeText {
|
|
74
|
+
align?: 'bottom' | 'middle' | 'top'
|
|
75
|
+
content: string
|
|
76
|
+
defaultColor?: string
|
|
77
|
+
defaultFontName?: string
|
|
78
|
+
/** 内边距,按上、右、下、左排列,单位为 CSS 像素。 */
|
|
79
|
+
inset?: [number, number, number, number]
|
|
80
|
+
lineHeight?: number
|
|
81
|
+
paragraphSpace?: number
|
|
82
|
+
wordSpace?: number
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface PptDslShapeElement extends PptDslBaseElement {
|
|
86
|
+
fill?: string
|
|
87
|
+
fixedRatio?: boolean
|
|
88
|
+
flipH?: boolean
|
|
89
|
+
flipV?: boolean
|
|
90
|
+
gradient?: PptDslGradient
|
|
91
|
+
keypoints?: number[]
|
|
92
|
+
outline?: PptDslOutline
|
|
93
|
+
path: string
|
|
94
|
+
/** PPTX 导出支持图片填充;只读预览暂不使用。 */
|
|
95
|
+
pattern?: string
|
|
96
|
+
pathFormula?: string
|
|
97
|
+
shadow?: PptDslShadow
|
|
98
|
+
special?: boolean
|
|
99
|
+
text?: PptDslShapeText
|
|
100
|
+
type: 'shape'
|
|
101
|
+
viewBox: [number, number]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface PptDslLineElement extends PptDslBaseElement {
|
|
105
|
+
/** 以下控制点用于 PPTX 导出,坐标相对线条 left/top。 */
|
|
106
|
+
broken?: [number, number]
|
|
107
|
+
broken2?: [number, number]
|
|
108
|
+
broken2Direction?: 'horizontal' | 'vertical'
|
|
109
|
+
curve?: [number, number]
|
|
110
|
+
cubic?: [[number, number], [number, number]]
|
|
111
|
+
color: string
|
|
112
|
+
end: [number, number]
|
|
113
|
+
points?: ['', ''] | ['arrow' | 'dot' | '', 'arrow' | 'dot' | '']
|
|
114
|
+
start: [number, number]
|
|
115
|
+
shadow?: PptDslShadow
|
|
116
|
+
style?: 'solid' | 'dashed' | 'dotted'
|
|
117
|
+
type: 'line'
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type PptDslChartType = 'area' | 'bar' | 'column' | 'line' | 'pie' | 'radar' | 'ring' | 'scatter'
|
|
121
|
+
|
|
122
|
+
export interface PptDslChartElement extends PptDslBaseElement {
|
|
123
|
+
chartType: PptDslChartType
|
|
124
|
+
data: {
|
|
125
|
+
labels: string[]
|
|
126
|
+
legends: string[]
|
|
127
|
+
series: number[][]
|
|
128
|
+
}
|
|
129
|
+
fill?: string
|
|
130
|
+
lineColor?: string
|
|
131
|
+
options?: { lineSmooth?: boolean; stack?: boolean }
|
|
132
|
+
outline?: PptDslOutline
|
|
133
|
+
textColor?: string
|
|
134
|
+
themeColors?: string[]
|
|
135
|
+
type: 'chart'
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface PptDslTableCell {
|
|
139
|
+
colspan?: number
|
|
140
|
+
id: string
|
|
141
|
+
rowspan?: number
|
|
142
|
+
style?: {
|
|
143
|
+
align?: 'center' | 'justify' | 'left' | 'right'
|
|
144
|
+
backcolor?: string
|
|
145
|
+
bold?: boolean
|
|
146
|
+
color?: string
|
|
147
|
+
em?: boolean
|
|
148
|
+
fontname?: string
|
|
149
|
+
fontsize?: string
|
|
150
|
+
underline?: boolean
|
|
151
|
+
vAlign?: 'bottom' | 'middle' | 'top'
|
|
152
|
+
}
|
|
153
|
+
text: string
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface PptDslTableElement extends PptDslBaseElement {
|
|
157
|
+
cellMinHeight?: number
|
|
158
|
+
colWidths?: number[]
|
|
159
|
+
data: PptDslTableCell[][]
|
|
160
|
+
fill?: string
|
|
161
|
+
outline?: PptDslOutline
|
|
162
|
+
/** PPTX 导出使用的表格主题,单元格显式背景优先。 */
|
|
163
|
+
theme?: {
|
|
164
|
+
color: string
|
|
165
|
+
rowHeader: boolean
|
|
166
|
+
rowFooter: boolean
|
|
167
|
+
colHeader: boolean
|
|
168
|
+
colFooter: boolean
|
|
169
|
+
}
|
|
170
|
+
type: 'table'
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface PptDslLatexElement extends PptDslBaseElement {
|
|
174
|
+
color?: string
|
|
175
|
+
fixedRatio?: boolean
|
|
176
|
+
latex: string
|
|
177
|
+
path?: string
|
|
178
|
+
strokeWidth?: number
|
|
179
|
+
type: 'latex'
|
|
180
|
+
viewBox?: [number, number]
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface PptDslVideoElement extends PptDslBaseElement {
|
|
184
|
+
autoplay?: boolean
|
|
185
|
+
ext?: string
|
|
186
|
+
poster?: string
|
|
187
|
+
src: string
|
|
188
|
+
type: 'video'
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface PptDslAudioElement extends PptDslBaseElement {
|
|
192
|
+
autoplay?: boolean
|
|
193
|
+
color?: string
|
|
194
|
+
ext?: string
|
|
195
|
+
fixedRatio?: boolean
|
|
196
|
+
loop?: boolean
|
|
197
|
+
src: string
|
|
198
|
+
type: 'audio'
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type PptDslElement = PptDslTextElement | PptDslImageElement | PptDslShapeElement | PptDslLineElement | PptDslChartElement | PptDslTableElement | PptDslLatexElement | PptDslVideoElement | PptDslAudioElement
|
|
202
|
+
|
|
203
|
+
export interface PptDslBackground {
|
|
204
|
+
color?: string
|
|
205
|
+
gradient?: PptDslGradient
|
|
206
|
+
image?: { size?: 'contain' | 'cover' | 'stretch'; src: string }
|
|
207
|
+
type: 'gradient' | 'image' | 'solid'
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface PptDslSlide {
|
|
211
|
+
background?: PptDslBackground
|
|
212
|
+
elements: PptDslElement[]
|
|
213
|
+
id: string
|
|
214
|
+
remark?: string
|
|
215
|
+
type?: 'content' | 'contents' | 'cover' | 'end' | 'transition'
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface PptDslTheme {
|
|
219
|
+
backgroundColor?: string
|
|
220
|
+
fontColor?: string
|
|
221
|
+
fontName?: string
|
|
222
|
+
outline?: PptDslOutline
|
|
223
|
+
shadow?: PptDslShadow
|
|
224
|
+
themeColors?: string[]
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface PptDslDocument {
|
|
228
|
+
height: number
|
|
229
|
+
slides: PptDslSlide[]
|
|
230
|
+
theme?: PptDslTheme
|
|
231
|
+
title: string
|
|
232
|
+
width: number
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface PptDslElementFrame {
|
|
236
|
+
height: number
|
|
237
|
+
left: number
|
|
238
|
+
rotate: number
|
|
239
|
+
top: number
|
|
240
|
+
width: number
|
|
241
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { VNode } from 'vue'
|
|
2
|
+
import type { PptDslElement, PptDslShapeElement, PptDslSlide, PptDslTableCell, PptDslTableElement, PptDslTextElement } from './ppt-dsl.js'
|
|
3
|
+
|
|
4
|
+
export interface SlideRendererProps {
|
|
5
|
+
slide: PptDslSlide
|
|
6
|
+
width: number
|
|
7
|
+
height: number
|
|
8
|
+
/** 仅缩放展示,不改变 DSL 坐标或布局占位;默认 1。 */
|
|
9
|
+
scale?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ElementRendererProps {
|
|
13
|
+
element: PptDslElement
|
|
14
|
+
/** 从 0 开始的 DSL 数组下标,用于确定图层顺序。 */
|
|
15
|
+
elementIndex: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TextEditorSlotProps {
|
|
19
|
+
element: PptDslTextElement
|
|
20
|
+
content: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ShapeTextEditorSlotProps {
|
|
24
|
+
element: PptDslShapeElement
|
|
25
|
+
content: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TableCellEditorSlotProps {
|
|
29
|
+
element: PptDslTableElement
|
|
30
|
+
cell: PptDslTableCell
|
|
31
|
+
rowIndex: number
|
|
32
|
+
colIndex: number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 仅替换内容,容器、形状、表格结构和样式仍由渲染器维护。 */
|
|
36
|
+
export interface ElementRendererSlots {
|
|
37
|
+
'text-editor'?: (props: TextEditorSlotProps) => VNode[]
|
|
38
|
+
'shape-text-editor'?: (props: ShapeTextEditorSlotProps) => VNode[]
|
|
39
|
+
'table-cell-editor'?: (props: TableCellEditorSlotProps) => VNode[]
|
|
40
|
+
}
|
package/src/vue.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CSSProperties, DefineComponent, DefineSetupFnComponent, HTMLAttributes, SlotsType } from 'vue'
|
|
2
|
+
import type { PptDslElement, PptDslElementFrame, PptDslLineElement, PptDslSlide } from './types/ppt-dsl.js'
|
|
3
|
+
import type { ElementRendererProps, ElementRendererSlots, SlideRendererProps } from './types/vue.js'
|
|
4
|
+
|
|
5
|
+
export type * from './types/ppt-dsl.js'
|
|
6
|
+
export type * from './types/vue.js'
|
|
7
|
+
|
|
8
|
+
/** 只读整页组件;class、style、id 和原生事件透传至根节点。 */
|
|
9
|
+
export const SlideRenderer: DefineComponent<SlideRendererProps & HTMLAttributes>
|
|
10
|
+
|
|
11
|
+
/** 单元素组件;编辑内容由插槽注入,数据更新及交互由宿主处理。 */
|
|
12
|
+
export const ElementRenderer: DefineSetupFnComponent<ElementRendererProps & HTMLAttributes, {}, SlotsType<ElementRendererSlots>>
|
|
13
|
+
|
|
14
|
+
export function getPptDslElementFrame(element: PptDslElement): PptDslElementFrame
|
|
15
|
+
export function getPptDslLineFrame(element: PptDslLineElement): PptDslElementFrame
|
|
16
|
+
export function getPptDslSlideStyle(slide: PptDslSlide, width: number, height: number, scale?: number): CSSProperties
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright Node.js contributors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
|
5
|
+
deal in the Software without restriction, including without limitation the
|
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19
|
+
IN THE SOFTWARE.
|