CatPtain commited on
Commit
35bfa3f
·
verified ·
1 Parent(s): 7363663

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -0
  2. shared/export-utils.js +730 -0
  3. shared/package.json +6 -0
Dockerfile CHANGED
@@ -27,6 +27,10 @@ RUN adduser -S nodejs -u 1001
27
  # 设置工作目录
28
  WORKDIR /app
29
 
 
 
 
 
30
  # 复制前端所有文件(包括配置文件)
31
  COPY frontend/ ./frontend/
32
  RUN chown -R nodejs:nodejs ./frontend
 
27
  # 设置工作目录
28
  WORKDIR /app
29
 
30
+ # 复制共享模块
31
+ COPY shared/ ./shared/
32
+ RUN chown -R nodejs:nodejs ./shared
33
+
34
  # 复制前端所有文件(包括配置文件)
35
  COPY frontend/ ./frontend/
36
  RUN chown -R nodejs:nodejs ./frontend
shared/export-utils.js ADDED
@@ -0,0 +1,730 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // 前后端共享的PPT导出工具
2
+ // 可以在浏览器和Node.js环境中运行
3
+
4
+ export const generateSlideHTML = (pptData, slideIndex, options = {}) => {
5
+ const {
6
+ width = 1000,
7
+ height = 562,
8
+ includeInteractive = false,
9
+ format = 'view' // 'view' | 'export' | 'screenshot'
10
+ } = options;
11
+
12
+ const slide = pptData.slides[slideIndex];
13
+ if (!slide) {
14
+ throw new Error(`Slide ${slideIndex} not found`);
15
+ }
16
+
17
+ const theme = pptData.theme || {};
18
+
19
+ // 计算实际尺寸
20
+ const actualWidth = pptData.viewportSize || width;
21
+ const actualHeight = Math.ceil(actualWidth * (pptData.viewportRatio || 0.5625));
22
+
23
+ // 渲染元素
24
+ const renderElements = (elements) => {
25
+ if (!elements || elements.length === 0) return '';
26
+
27
+ return elements.map(element => {
28
+ const baseStyle = `
29
+ position: absolute;
30
+ left: ${element.left || 0}px;
31
+ top: ${element.top || 0}px;
32
+ width: ${element.width || 0}px;
33
+ height: ${element.height || 0}px;
34
+ z-index: ${element.zIndex || 1};
35
+ transform: rotate(${element.rotate || 0}deg);
36
+ `;
37
+
38
+ let content = '';
39
+ let specificStyles = '';
40
+
41
+ switch (element.type) {
42
+ case 'text':
43
+ const fontFamily = element.fontName || 'Microsoft YaHei';
44
+ const fontFallback = `${fontFamily}, 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'SimHei', 'SimSun', Arial, Helvetica, sans-serif`;
45
+
46
+ specificStyles = `
47
+ font-family: ${fontFallback};
48
+ font-size: ${element.fontSize || 14}px;
49
+ color: ${element.defaultColor || element.color || '#000'};
50
+ font-weight: ${element.bold ? 'bold' : 'normal'};
51
+ font-style: ${element.italic ? 'italic' : 'normal'};
52
+ text-decoration: ${element.underline ? 'underline' : 'none'};
53
+ text-align: ${element.align || 'left'};
54
+ line-height: ${element.lineHeight || 1.2};
55
+ padding: 10px;
56
+ word-wrap: break-word;
57
+ overflow: hidden;
58
+ box-sizing: border-box;
59
+ -webkit-font-smoothing: antialiased;
60
+ -moz-osx-font-smoothing: grayscale;
61
+ text-rendering: optimizeLegibility;
62
+ `;
63
+ content = element.content || '';
64
+ break;
65
+
66
+ case 'image':
67
+ specificStyles = `
68
+ background-image: url('${element.src}');
69
+ background-size: ${element.objectFit || 'cover'};
70
+ background-position: center;
71
+ background-repeat: no-repeat;
72
+ `;
73
+ break;
74
+
75
+ case 'shape':
76
+ specificStyles = `
77
+ background-color: ${element.fill || 'transparent'};
78
+ border: ${element.outline?.width || 0}px ${element.outline?.style || 'solid'} ${element.outline?.color || 'transparent'};
79
+ border-radius: ${element.shape === 'ellipse' ? '50%' : '0px'};
80
+ `;
81
+ break;
82
+ }
83
+
84
+ return `<div style="${baseStyle}${specificStyles}">${content}</div>`;
85
+ }).join('');
86
+ };
87
+
88
+ // 生成样式
89
+ const generateStyles = () => {
90
+ const baseStyles = `
91
+ * { box-sizing: border-box; margin: 0; padding: 0; }
92
+ body {
93
+ font-family: 'Microsoft YaHei', 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'SimHei', 'SimSun', Arial, Helvetica, sans-serif;
94
+ margin: 0;
95
+ padding: 0;
96
+ }
97
+ .slide-container {
98
+ position: relative;
99
+ width: ${actualWidth}px;
100
+ height: ${actualHeight}px;
101
+ background: ${slide.background?.color || theme.backgroundColor || '#ffffff'};
102
+ margin: 0 auto;
103
+ overflow: hidden;
104
+ }
105
+ `;
106
+
107
+ if (format === 'view') {
108
+ return baseStyles + `
109
+ html, body {
110
+ width: 100vw;
111
+ height: 100vh;
112
+ background: #000;
113
+ display: flex;
114
+ align-items: center;
115
+ justify-content: center;
116
+ overflow: hidden;
117
+ }
118
+ .slide-container {
119
+ transform-origin: center center;
120
+ }
121
+ `;
122
+ }
123
+
124
+ return baseStyles;
125
+ };
126
+
127
+ // 生成JavaScript(仅用于view模式)
128
+ const generateScript = () => {
129
+ if (format !== 'view') return '';
130
+
131
+ return `
132
+ <script>
133
+ function scalePPTToFitWindow() {
134
+ const container = document.querySelector('.slide-container');
135
+ if (!container) return;
136
+
137
+ const windowWidth = window.innerWidth;
138
+ const windowHeight = window.innerHeight;
139
+ const pptWidth = ${actualWidth};
140
+ const pptHeight = ${actualHeight};
141
+
142
+ const scaleX = windowWidth / pptWidth;
143
+ const scaleY = windowHeight / pptHeight;
144
+ const scale = Math.min(scaleX, scaleY, 1);
145
+
146
+ container.style.transform = 'scale(' + scale + ')';
147
+ }
148
+
149
+ window.addEventListener('load', scalePPTToFitWindow);
150
+ window.addEventListener('resize', scalePPTToFitWindow);
151
+ window.addEventListener('orientationchange', () => {
152
+ setTimeout(scalePPTToFitWindow, 100);
153
+ });
154
+ </script>
155
+ `;
156
+ };
157
+
158
+ return `<!DOCTYPE html>
159
+ <html lang="zh-CN">
160
+ <head>
161
+ <meta charset="UTF-8">
162
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
163
+ <title>${pptData.title || 'PPT'} - Page ${slideIndex + 1}</title>
164
+ <style>${generateStyles()}</style>
165
+ </head>
166
+ <body>
167
+ <div class="slide-container">
168
+ ${renderElements(slide.elements)}
169
+ </div>
170
+ ${generateScript()}
171
+ </body>
172
+ </html>`;
173
+ };
174
+
175
+ export const generateExportPage = (pptData, slideIndex, options = {}) => {
176
+ const {
177
+ format = 'jpeg',
178
+ quality = 90,
179
+ autoDownload = false
180
+ } = options;
181
+
182
+ const slideHTML = generateSlideHTML(pptData, slideIndex, {
183
+ ...options,
184
+ format: 'export'
185
+ });
186
+
187
+ // 提取slide-container内容
188
+ const slideContent = slideHTML.match(/<div class="slide-container">(.*?)<\/div>/s)?.[1] || '';
189
+
190
+ return `<!DOCTYPE html>
191
+ <html lang="zh-CN">
192
+ <head>
193
+ <meta charset="UTF-8">
194
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
195
+ <title>PPT Export - ${pptData.title}</title>
196
+ <style>
197
+ body {
198
+ margin: 0;
199
+ padding: 20px;
200
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
201
+ font-family: 'Microsoft YaHei', sans-serif;
202
+ min-height: 100vh;
203
+ display: flex;
204
+ flex-direction: column;
205
+ align-items: center;
206
+ justify-content: center;
207
+ }
208
+ .container {
209
+ background: white;
210
+ border-radius: 15px;
211
+ padding: 30px;
212
+ box-shadow: 0 20px 40px rgba(0,0,0,0.1);
213
+ text-align: center;
214
+ }
215
+ .slide-container {
216
+ position: relative;
217
+ width: ${pptData.viewportSize || 1000}px;
218
+ height: ${Math.ceil((pptData.viewportSize || 1000) * (pptData.viewportRatio || 0.5625))}px;
219
+ background: ${pptData.slides[slideIndex].background?.color || '#ffffff'};
220
+ margin: 20px auto;
221
+ overflow: hidden;
222
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
223
+ border-radius: 4px;
224
+ }
225
+ .btn {
226
+ background: #4CAF50;
227
+ color: white;
228
+ border: none;
229
+ padding: 12px 24px;
230
+ border-radius: 5px;
231
+ cursor: pointer;
232
+ margin: 5px;
233
+ font-size: 16px;
234
+ font-weight: bold;
235
+ }
236
+ .btn:hover { background: #45a049; }
237
+ .btn:disabled { background: #cccccc; cursor: not-allowed; }
238
+ .status {
239
+ margin: 15px 0;
240
+ padding: 10px;
241
+ border-radius: 5px;
242
+ font-size: 14px;
243
+ }
244
+ .status.success { background: #e8f5e8; color: #2e7d32; }
245
+ .status.error { background: #fdeaea; color: #c62828; }
246
+ .status.info { background: #e3f2fd; color: #1565c0; }
247
+ </style>
248
+ </head>
249
+ <body>
250
+ <div class="container">
251
+ <h1>🚀 PPT Export</h1>
252
+ <p>${pptData.title} - Slide ${slideIndex + 1}</p>
253
+
254
+ <div class="slide-container" id="slideContainer">
255
+ ${slideContent}
256
+ </div>
257
+
258
+ <button class="btn" onclick="generateScreenshot()">📸 Generate Screenshot</button>
259
+ <button class="btn" onclick="downloadScreenshot()" id="downloadBtn" disabled>💾 Download</button>
260
+
261
+ <div id="status" class="status info">Ready to generate screenshot</div>
262
+ </div>
263
+
264
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js"></script>
265
+ <script>
266
+ let currentScreenshot = null;
267
+
268
+ async function generateScreenshot() {
269
+ try {
270
+ document.getElementById('status').textContent = 'Generating...';
271
+ document.getElementById('status').className = 'status info';
272
+
273
+ if (document.fonts && document.fonts.ready) {
274
+ await document.fonts.ready;
275
+ }
276
+ await new Promise(resolve => setTimeout(resolve, 300));
277
+
278
+ const canvas = await html2canvas(document.getElementById('slideContainer'), {
279
+ scale: 2,
280
+ useCORS: true,
281
+ allowTaint: true,
282
+ backgroundColor: null
283
+ });
284
+
285
+ currentScreenshot = canvas.toDataURL('image/${format}', ${quality / 100});
286
+
287
+ document.getElementById('status').textContent = 'Screenshot generated successfully!';
288
+ document.getElementById('status').className = 'status success';
289
+ document.getElementById('downloadBtn').disabled = false;
290
+
291
+ ${autoDownload ? 'downloadScreenshot();' : ''}
292
+
293
+ } catch (error) {
294
+ document.getElementById('status').textContent = 'Generation failed: ' + error.message;
295
+ document.getElementById('status').className = 'status error';
296
+ }
297
+ }
298
+
299
+ function downloadScreenshot() {
300
+ if (!currentScreenshot) return;
301
+
302
+ const link = document.createElement('a');
303
+ link.download = 'ppt-slide-${slideIndex + 1}.${format}';
304
+ link.href = currentScreenshot;
305
+ link.click();
306
+
307
+ document.getElementById('status').textContent = 'Downloaded successfully!';
308
+ document.getElementById('status').className = 'status success';
309
+ }
310
+
311
+ window.addEventListener('load', function() {
312
+ ${autoDownload ? 'setTimeout(generateScreenshot, 500);' : ''}
313
+ });
314
+ </script>
315
+ </body>
316
+ </html>`;
317
+ };
318
+
319
+ // 新增:前端导出功能的服务器端实现
320
+ export const exportPPTToJSON = (pptData) => {
321
+ return {
322
+ title: pptData.title,
323
+ width: pptData.viewportSize || 1000,
324
+ height: Math.ceil((pptData.viewportSize || 1000) * (pptData.viewportRatio || 0.5625)),
325
+ theme: pptData.theme,
326
+ slides: pptData.slides,
327
+ exportedAt: new Date().toISOString(),
328
+ format: 'json',
329
+ version: '1.0'
330
+ };
331
+ };
332
+
333
+ // 新增:生成完整的HTML演示文稿
334
+ export const generateHTMLPresentation = (pptData, options = {}) => {
335
+ const {
336
+ includeInteractivity = true,
337
+ standalone = true,
338
+ includeCSS = true
339
+ } = options;
340
+
341
+ const viewportSize = pptData.viewportSize || 1000;
342
+ const viewportRatio = pptData.viewportRatio || 0.5625;
343
+ const slideHeight = Math.round(viewportSize * viewportRatio);
344
+ const theme = pptData.theme || {};
345
+
346
+ // CSS样式
347
+ const css = includeCSS ? `
348
+ <style>
349
+ * {
350
+ margin: 0;
351
+ padding: 0;
352
+ box-sizing: border-box;
353
+ }
354
+
355
+ body {
356
+ font-family: '${theme.fontName || 'Microsoft YaHei'}', 'Microsoft YaHei', Arial, sans-serif;
357
+ background: ${theme.backgroundColor || '#000'};
358
+ color: ${theme.fontColor || '#333'};
359
+ overflow: hidden;
360
+ }
361
+
362
+ .presentation-container {
363
+ width: 100vw;
364
+ height: 100vh;
365
+ display: flex;
366
+ justify-content: center;
367
+ align-items: center;
368
+ background: #000;
369
+ }
370
+
371
+ .slide-container {
372
+ width: ${viewportSize}px;
373
+ height: ${slideHeight}px;
374
+ background: #fff;
375
+ position: relative;
376
+ overflow: hidden;
377
+ transform-origin: center;
378
+ box-shadow: 0 8px 32px rgba(0,0,0,0.3);
379
+ }
380
+
381
+ .slide {
382
+ width: 100%;
383
+ height: 100%;
384
+ position: absolute;
385
+ top: 0;
386
+ left: 0;
387
+ display: none;
388
+ }
389
+
390
+ .slide.active {
391
+ display: block;
392
+ }
393
+
394
+ .element {
395
+ position: absolute;
396
+ word-wrap: break-word;
397
+ }
398
+
399
+ .text-element {
400
+ display: flex;
401
+ align-items: center;
402
+ justify-content: center;
403
+ text-align: center;
404
+ }
405
+
406
+ .image-element img {
407
+ width: 100%;
408
+ height: 100%;
409
+ object-fit: contain;
410
+ }
411
+
412
+ .shape-element {
413
+ border-radius: var(--border-radius, 0);
414
+ }
415
+
416
+ .navigation {
417
+ position: fixed;
418
+ bottom: 30px;
419
+ left: 50%;
420
+ transform: translateX(-50%);
421
+ display: flex;
422
+ gap: 10px;
423
+ z-index: 1000;
424
+ }
425
+
426
+ .nav-btn {
427
+ padding: 12px 20px;
428
+ background: rgba(255,255,255,0.9);
429
+ border: none;
430
+ border-radius: 25px;
431
+ cursor: pointer;
432
+ font-size: 14px;
433
+ font-weight: bold;
434
+ transition: all 0.3s ease;
435
+ box-shadow: 0 4px 15px rgba(0,0,0,0.2);
436
+ }
437
+
438
+ .nav-btn:hover {
439
+ background: rgba(255,255,255,1);
440
+ transform: translateY(-2px);
441
+ }
442
+
443
+ .nav-btn:disabled {
444
+ opacity: 0.5;
445
+ cursor: not-allowed;
446
+ }
447
+
448
+ .slide-counter {
449
+ position: fixed;
450
+ top: 30px;
451
+ right: 30px;
452
+ background: rgba(0,0,0,0.7);
453
+ color: white;
454
+ padding: 8px 16px;
455
+ border-radius: 20px;
456
+ font-size: 14px;
457
+ z-index: 1000;
458
+ }
459
+
460
+ .fullscreen-btn {
461
+ position: fixed;
462
+ top: 30px;
463
+ left: 30px;
464
+ background: rgba(0,0,0,0.7);
465
+ color: white;
466
+ border: none;
467
+ padding: 8px 16px;
468
+ border-radius: 20px;
469
+ cursor: pointer;
470
+ font-size: 14px;
471
+ z-index: 1000;
472
+ }
473
+
474
+ /* 响应式缩放 */
475
+ @media (max-width: 1200px) {
476
+ .slide-container {
477
+ transform: scale(0.8);
478
+ }
479
+ }
480
+
481
+ @media (max-width: 800px) {
482
+ .slide-container {
483
+ transform: scale(0.6);
484
+ }
485
+ }
486
+
487
+ @media (max-width: 600px) {
488
+ .slide-container {
489
+ transform: scale(0.4);
490
+ }
491
+ }
492
+ </style>
493
+ ` : '';
494
+
495
+ // JavaScript交互功能
496
+ const javascript = includeInteractivity ? `
497
+ <script>
498
+ class PPTViewer {
499
+ constructor() {
500
+ this.currentSlide = 0;
501
+ this.totalSlides = ${pptData.slides.length};
502
+ this.init();
503
+ }
504
+
505
+ init() {
506
+ this.updateSlide();
507
+ this.bindEvents();
508
+ this.autoScale();
509
+ window.addEventListener('resize', () => this.autoScale());
510
+ }
511
+
512
+ bindEvents() {
513
+ document.addEventListener('keydown', (e) => {
514
+ switch(e.key) {
515
+ case 'ArrowLeft':
516
+ case 'ArrowUp':
517
+ this.prevSlide();
518
+ break;
519
+ case 'ArrowRight':
520
+ case 'ArrowDown':
521
+ case ' ':
522
+ this.nextSlide();
523
+ break;
524
+ case 'Home':
525
+ this.goToSlide(0);
526
+ break;
527
+ case 'End':
528
+ this.goToSlide(this.totalSlides - 1);
529
+ break;
530
+ case 'F11':
531
+ this.toggleFullscreen();
532
+ break;
533
+ }
534
+ });
535
+ }
536
+
537
+ nextSlide() {
538
+ if (this.currentSlide < this.totalSlides - 1) {
539
+ this.currentSlide++;
540
+ this.updateSlide();
541
+ }
542
+ }
543
+
544
+ prevSlide() {
545
+ if (this.currentSlide > 0) {
546
+ this.currentSlide--;
547
+ this.updateSlide();
548
+ }
549
+ }
550
+
551
+ goToSlide(index) {
552
+ if (index >= 0 && index < this.totalSlides) {
553
+ this.currentSlide = index;
554
+ this.updateSlide();
555
+ }
556
+ }
557
+
558
+ updateSlide() {
559
+ document.querySelectorAll('.slide').forEach(slide => {
560
+ slide.classList.remove('active');
561
+ });
562
+
563
+ const currentSlideEl = document.getElementById('slide-' + this.currentSlide);
564
+ if (currentSlideEl) {
565
+ currentSlideEl.classList.add('active');
566
+ }
567
+
568
+ const counter = document.querySelector('.slide-counter');
569
+ if (counter) {
570
+ counter.textContent = \`\${this.currentSlide + 1} / \${this.totalSlides}\`;
571
+ }
572
+
573
+ const prevBtn = document.getElementById('prevBtn');
574
+ const nextBtn = document.getElementById('nextBtn');
575
+ if (prevBtn) prevBtn.disabled = this.currentSlide === 0;
576
+ if (nextBtn) nextBtn.disabled = this.totalSlides - 1;
577
+ }
578
+
579
+ autoScale() {
580
+ const container = document.querySelector('.slide-container');
581
+ if (!container) return;
582
+
583
+ const windowWidth = window.innerWidth;
584
+ const windowHeight = window.innerHeight;
585
+ const slideWidth = ${viewportSize};
586
+ const slideHeight = ${slideHeight};
587
+
588
+ const scaleX = (windowWidth * 0.9) / slideWidth;
589
+ const scaleY = (windowHeight * 0.9) / slideHeight;
590
+ const scale = Math.min(scaleX, scaleY, 1);
591
+
592
+ container.style.transform = \`scale(\${scale})\`;
593
+ }
594
+
595
+ toggleFullscreen() {
596
+ if (!document.fullscreenElement) {
597
+ document.documentElement.requestFullscreen();
598
+ } else {
599
+ document.exitFullscreen();
600
+ }
601
+ }
602
+ }
603
+
604
+ // 初始化PPT查看器
605
+ document.addEventListener('DOMContentLoaded', () => {
606
+ window.pptViewer = new PPTViewer();
607
+ });
608
+ </script>
609
+ ` : '';
610
+
611
+ // 格式化幻灯片背景
612
+ const formatSlideBackground = (background) => {
613
+ if (!background) return 'background: #ffffff;';
614
+
615
+ if (background.type === 'solid') {
616
+ return `background: ${background.color || '#ffffff'};`;
617
+ }
618
+
619
+ if (background.type === 'gradient') {
620
+ const { gradientType, colors } = background;
621
+ if (gradientType === 'linear') {
622
+ return `background: linear-gradient(${background.gradientRotate || 0}deg, ${colors.map(c => c.color).join(', ')});`;
623
+ }
624
+ return `background: radial-gradient(${colors.map(c => c.color).join(', ')});`;
625
+ }
626
+
627
+ if (background.type === 'image' && background.image) {
628
+ return `background-image: url(${background.image.src}); background-size: cover; background-position: center;`;
629
+ }
630
+
631
+ return 'background: #ffffff;';
632
+ };
633
+
634
+ // 格式化元素
635
+ const formatElement = (element) => {
636
+ const baseStyle = `
637
+ left: ${element.left || 0}px;
638
+ top: ${element.top || 0}px;
639
+ width: ${element.width || 100}px;
640
+ height: ${element.height || 100}px;
641
+ transform: rotate(${element.rotate || 0}deg);
642
+ `;
643
+
644
+ if (element.type === 'text') {
645
+ const fontFamily = element.fontName || 'Microsoft YaHei';
646
+ const fontFallback = `${fontFamily}, 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'SimHei', 'SimSun', Arial, Helvetica, sans-serif`;
647
+
648
+ const textStyle = `
649
+ font-size: ${element.fontSize || 16}px;
650
+ font-family: ${fontFallback};
651
+ color: ${element.defaultColor || element.color || '#000000'};
652
+ font-weight: ${element.bold ? 'bold' : 'normal'};
653
+ font-style: ${element.italic ? 'italic' : 'normal'};
654
+ text-decoration: ${element.underline ? 'underline' : 'none'};
655
+ text-align: ${element.align || 'left'};
656
+ line-height: ${element.lineHeight || 1.5};
657
+ padding: 10px;
658
+ word-wrap: break-word;
659
+ overflow: hidden;
660
+ box-sizing: border-box;
661
+ -webkit-font-smoothing: antialiased;
662
+ -moz-osx-font-smoothing: grayscale;
663
+ text-rendering: optimizeLegibility;
664
+ `;
665
+
666
+ return `<div class="element text-element" style="${baseStyle}${textStyle}">${element.content || ''}</div>`;
667
+ }
668
+
669
+ if (element.type === 'image' && element.src) {
670
+ return `<div class="element image-element" style="${baseStyle}"><img src="${element.src}" alt="图片" /></div>`;
671
+ }
672
+
673
+ if (element.type === 'shape') {
674
+ const shapeStyle = `
675
+ background: ${element.fill || '#ffffff'};
676
+ border: ${element.outline?.width || 0}px solid ${element.outline?.color || '#000000'};
677
+ border-radius: ${element.borderRadius || 0}px;
678
+ `;
679
+
680
+ return `<div class="element shape-element" style="${baseStyle}${shapeStyle}"></div>`;
681
+ }
682
+
683
+ // 其他元素类型的基本处理
684
+ return `<div class="element" style="${baseStyle}"></div>`;
685
+ };
686
+
687
+ // 生成幻灯片HTML
688
+ const slidesHTML = pptData.slides.map((slide, index) => {
689
+ const slideBackground = formatSlideBackground(slide.background);
690
+ const elementsHTML = slide.elements.map(element => formatElement(element)).join('');
691
+
692
+ return `
693
+ <div id="slide-${index}" class="slide ${index === 0 ? 'active' : ''}" style="${slideBackground}">
694
+ ${elementsHTML}
695
+ </div>
696
+ `;
697
+ }).join('');
698
+
699
+ // 导航控件HTML
700
+ const navigationHTML = includeInteractivity ? `
701
+ <div class="navigation">
702
+ <button id="prevBtn" class="nav-btn" onclick="window.pptViewer?.prevSlide()">上一页</button>
703
+ <button id="nextBtn" class="nav-btn" onclick="window.pptViewer?.nextSlide()">下一页</button>
704
+ </div>
705
+ <div class="slide-counter">1 / ${pptData.slides.length}</div>
706
+ <button class="fullscreen-btn" onclick="window.pptViewer?.toggleFullscreen()">全屏</button>
707
+ ` : '';
708
+
709
+ // 组装完整HTML
710
+ return `<!DOCTYPE html>
711
+ <html lang="zh-CN">
712
+ <head>
713
+ <meta charset="UTF-8">
714
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
715
+ <title>${pptData.title}</title>
716
+ <meta name="description" content="PPTist导出的HTML演示文稿">
717
+ <meta name="generator" content="PPTist">
718
+ ${css}
719
+ </head>
720
+ <body>
721
+ <div class="presentation-container">
722
+ <div class="slide-container">
723
+ ${slidesHTML}
724
+ </div>
725
+ </div>
726
+ ${navigationHTML}
727
+ ${javascript}
728
+ </body>
729
+ </html>`;
730
+ };
shared/package.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "type": "module",
3
+ "name": "shared-export-utils",
4
+ "version": "1.0.0",
5
+ "description": "Shared export utilities for PPTist frontend and backend"
6
+ }