-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathindex.html
More file actions
736 lines (726 loc) · 27.8 KB
/
index.html
File metadata and controls
736 lines (726 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>AI PPT</title>
<style>
::-webkit-scrollbar {
width: 5px;
height: 5px;
background-color: #fff;
}
::-webkit-scrollbar-thumb {
background-color: #c1c1c1;
}
.docmee {
z-index: 9999;
background-image: linear-gradient(to left, rgb(107, 90, 196), rgb(96, 84, 189));
background-clip: text;
color: transparent;
font-weight: bold;
display: inline-block;
font-size: 1.125rem;
line-height: 1.75rem;
user-select: none;
cursor: pointer;
position: fixed;
top: 10px;
left: 15px;
}
#div1 {
text-align: center;
margin-top: 60px;
}
#div1, #div2, #div3, #nextTo2, #nextTo3, #desc, #right_canvas {
display: none;
}
#outline {
text-align: left;
margin: 0 calc(20vw);
}
#templates {
width: 80%;
max-width: 1050px;
margin: auto;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
text-align: center;
}
.template {
margin: 8px;
width: 240px;
height: 136px;
cursor: pointer;
overflow: hidden;
border-radius: 12px;
background-color: #ecedf4;
border: 2px solid transparent;
}
.template img {
width: 100%;
height: 100%;
opacity: 1;
object-fit: cover;
transition: all .6s ease;
}
.template img:hover {
transform: scale(1.2);
transition-duration: .3s;
}
h1 {
font-size: 1.6em;
margin-block-start: 0.5em;
margin-block-end: 0.5em;
}
h2 {
font-size: 1.3em;
margin-block-start: 0.7em;
margin-block-end: 0.7em;
}
h3 {
font-size: 1.1em;
margin-block-start: 0.9em;
margin-block-end: 0.9em;
}
h4 {
margin-block-start: 1.1em;
margin-block-end: 1.1em;
}
ul {
list-style: none;
}
#pptDownload {
display: none;
float: right;
}
.left_div {
align-items: center;
display: flex;
flex-direction: column;
flex-shrink: 0;
height: 96vh;
justify-content: center;
position: absolute;
width: 158px;
}
.left_div_child {
background: #fff;
border: 1px solid #fff;
border-radius: 6px;
box-shadow: 0 4px 10px 0 #0003;
margin-left: 12px;
margin-top: 28px;
max-height: calc(100vh - 130px);
width: 200px;
}
.left_div_child_child {
max-height: calc(100vh - 130px);
overflow-x: hidden;
overflow-y: auto;
padding: 0 8px 0 2px;
}
.left_div_item {
display: flex;
cursor: pointer;
margin: 10px 0;
}
.left_div_item_index {
color: #8d90a5;
flex-shrink: 0;
padding-right: 6px;
padding-top: 30px;
text-align: right;
width: 23px;
}
.left_div_item_img {
height: 80px;
border: 1px solid #ccc;
}
.right_div {
position: absolute;
margin-left: 280px;
top: 50%;
transform: translateY(-50%);
}
#right_canvas {
margin: 0px auto;
display: block;
border: 1px solid #666;
}
.item_select {
border: 2px solid #491ff8;
}
.draw_el_class {
position: fixed;
}
.draw_el_class:hover {
cursor: text;
border: 1.5px solid red;
}
.lang-switch {
position: fixed;
top: 10px;
right: 15px;
z-index: 9999;
cursor: pointer;
font-size: 14px;
color: #666;
user-select: none;
}
.lang-switch:hover {
color: #491ff8;
}
</style>
</head>
<body>
<a href="https://docmee.cn" target="_blank" class="docmee" data-i18n="brand_title" title="进入文多多AiPPT官网">文多多 AiPPT</a>
<div class="lang-switch" onclick="toggleLanguage()">
<span id="lang-text">EN</span>
</div>
<!-- 大纲生成 -->
<div id="div1">
<div style="margin-bottom: 50px;">
<h1 data-i18n="page1_title">🤖 AI智能生成PPT演示文稿</h1>
<div style="font-size: 14px;color: #999;" data-i18n="page1_steps">生成大纲 ---> 挑选模板 ---> 实时生成PPT</div>
</div>
<label data-i18n="subject_label">主题:</label>
<input type="text" id="subject" data-i18n-placeholder="subject_placeholder" placeholder="请输入PPT主题" maxlength="30" />
<button onclick="generateOutline()" data-i18n="generate_outline_btn">生成大纲</button>
<button id="nextTo2" class="next_but" onclick="nextTo2()" data-i18n="next_to_template_btn">下一步:选择模板</button>
<div id="outline"></div>
</div>
<!-- 选择模板 -->
<div id="div2">
<div style="text-align: center;margin: 10px;">
<div data-i18n="select_template_title">---- 选择模板 ----</div>
<button id="nextTo3" class="next_but" style="margin-top: 10px;" onclick="nextTo3()" data-i18n="next_to_generate_btn">下一步:生成PPT</button>
</div>
<div id="templates" data-i18n="templates_loading">模板加载中...</div>
</div>
<!-- PPT页面 -->
<div id="div3">
<div id="desc" style="text-align: center;margin-top: 20px">
<span id="desc_msg" data-i18n="generating_msg">正在生成中,请稍后...</span>
<span id="desc_time" style="margin-left: 5px"></span>
</div>
<div class="left_div">
<div class="left_div_child">
<div id="left_image_list" class="left_div_child_child">
<!--
<div class="left_div_item" onclick="drawPptx(0)">
<div class="left_div_item_index">1</div>
<img src="1.png" class="left_div_item_img" />
</div>
-->
</div>
</div>
</div>
<div class="right_div">
<select id="insert_element" style="display: none;margin-left: 10px" onchange="insertElement(this.value.split(',')[0], this.value.split(',')[1])">
<option value="" data-i18n="insert_element_title">-- 插入元素 --</option>
<option value="text,title1" data-i18n="insert_title1">插入大标题</option>
<option value="text,title2" data-i18n="insert_title2">插入副标题</option>
<option value="text,content" data-i18n="insert_content">插入正文文本</option>
<option value="image" data-i18n="insert_image">插入图片</option>
<option value="geometry" data-i18n="insert_geometry">插入随机形状</option>
<option value="table" data-i18n="insert_table">插入表格</option>
<option value="chart,bar" data-i18n="insert_bar_chart">插入柱状图</option>
<option value="chart,pie" data-i18n="insert_pie_chart">插入饼图</option>
<option value="chart,doughnut" data-i18n="insert_doughnut_chart">插入环形图</option>
<option value="chart,line" data-i18n="insert_line_chart">插入折线图</option>
</select>
<div id="pptDownload">
<select id="download_select" style="margin-right: 5px">
<option value="" data-i18n="download_options_title">-- 下载选项 --</option>
<option value="0" data-i18n="download_no_animation">不添加动画</option>
<option value="1" data-i18n="download_with_animation">智能添加动画</option>
</select>
<a id="downloadPptx" href="javascript:downloadPptx()" data-i18n="download_pptx_btn">渲染pptx并下载</a>
</div>
<div id="right_container" style="padding-top: 8px;">
<!--<canvas id="right_canvas" width="1920" height="1080" style="width: 960px;height: 540px;"></canvas>-->
<svg id="right_canvas"></svg>
</div>
</div>
</div>
<script src="static/i18n.js"></script>
<script src="static/sse.js"></script>
<script src="static/chart.js"></script>
<script src="static/geometry.js"></script>
<script src="static/element.js"></script>
<script src="static/ppt2svg.js"></script>
<script src="static/ppt2canvas.js"></script>
<script src="static/base64js.js"></script>
<script src="static/pako.js"></script>
<script src="static/marked.js"></script>
<script>
// 文多多AiPPT
// 官网 https://docmee.cn
// 开放平台 https://docmee.cn/open-platform
const apiKey = '4u2Fo50Alk1ym2Os'
var pptxId = null
var outline = ''
var templateId = ''
var pptxObj = null
var selectIdx = 0
var mTimer = null
var gening = false
var markdownRenderer = new marked.Renderer()
marked.setOptions({
renderer: markdownRenderer,
async: false, // 是否异步渲染
gfm: true, // 运行github标准的markdown
tables: true, // 表格
breaks: false, // 回车换行
pedantic: false, // 兼容隐晦部分
silent: true // 错误时不抛异常
})
// canvas
// var painter = new Ppt2Canvas('right_canvas')
// var canvas = painter.getCanvas()
// svg
var painter = new Ppt2Svg('right_canvas')
var canvas = painter.svgNode()
painter.setMode('edit')
function generateOutline() {
let subject = document.getElementById('subject').value
if (!subject) {
alert(t('alert_empty_subject'))
return
}
if (subject.length <= 1) {
alert(t('alert_subject_too_short'))
return
}
if (subject.length > 30) {
alert(t('alert_subject_too_long'))
return
}
if (gening) {
return
}
outline = ''
gening = true
const url = 'https://docmee.cn/api/public/ppt/generateOutline?apiKey=' + apiKey
var source = new SSE(url, {
method: 'POST',
// withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache'
},
payload: JSON.stringify({ subject }),
})
source.onmessage = function (data) {
let json = JSON.parse(data.data)
if (json.status == -1) {
gening = false
alert(t('alert_outline_error') + json.error)
return
}
outline += json.text
document.getElementById('outline').innerHTML = window.marked.marked(outline.replaceAll('```markdown', '').replaceAll('```', ''))
window.scrollTo({ behavior: 'smooth', top: document.body.scrollHeight })
}
source.onend = function (data) {
gening = false
if (data.data.startsWith('{') && data.data.endsWith('}')) {
const json = JSON.parse(data.data)
if (json.code != 0) {
alert(t('alert_outline_error') + json.message)
return
}
}
document.getElementById('nextTo2').style.display = 'inline-block'
window.scrollTo(0, 0)
}
source.onerror = function (err) {
gening = false
console.error('生成大纲异常', err)
alert(t('alert_outline_error'))
}
source.stream()
}
function nextTo2() {
document.getElementById('nextTo2').style.display = 'none'
document.getElementById('div1').style.display = 'none'
document.getElementById('div2').style.display = 'block'
window.scrollTo(0, 0)
loadTemplates()
}
function loadTemplates() {
let url = 'https://docmee.cn/api/public/ppt/randomTemplates?apiKey=' + apiKey
let xhr = new XMLHttpRequest()
xhr.open('POST', url, true)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify({ page: 1, size: 28, filters: { type: 1 } }))
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let resp = JSON.parse(xhr.responseText)
let list = resp.data
let templates = ''
for (let i = 0; i < list.length; i++) {
let id = list[i].id
let coverUrl = list[i].coverUrl
let html = `<div id="${id}" class="template" onclick="selectTemplate('${id}')">`
html += `<img id="img_${id}" src="${coverUrl}" />`
html += '</div>'
templates += html
}
templates += `<div style="width: 100%;padding: 10px;text-align: center;"><button onclick="loadTemplates()">${t('load_more_templates')}</button></div>`
document.getElementById('templates').innerHTML = templates
selectTemplate(list[0].id)
}
}
}
xhr.onerror = function (e) {
console.error(e)
}
}
async function selectTemplate(id) {
if (templateId) {
let ele = document.getElementById(templateId)
if (ele) {
ele.classList.remove('item_select')
}
}
templateId = id
document.getElementById('nextTo3').style.display = 'inline-block'
document.getElementById(id).classList.add('item_select')
let color = await calcSubjectColor(document.getElementById(`img_${id}`).src)
document.body.style.background = color
}
function nextTo3() {
document.body.style.background = null
document.getElementById('nextTo3').style.display = 'none'
document.getElementById('div2').style.display = 'none'
document.getElementById('div3').style.display = 'block'
generatePptx()
}
function generatePptx() {
var count = 0
var timer = setInterval(() => {
count = count + 1
document.getElementById('desc').style.display = 'block'
document.getElementById('desc_time').innerHTML = count + t('seconds')
}, 1000)
const url = 'https://docmee.cn/api/public/ppt/generateContent?apiKey=' + apiKey
var source = new SSE(url, {
method: 'POST',
// withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache'
},
payload: JSON.stringify({ outlineMarkdown: outline, asyncGenPptx: true, templateId }),
})
source.onmessage = function (data) {
let json = JSON.parse(data.data)
if (json.status == -1) {
alert(t('alert_ppt_error') + json.error)
return
}
if (json.pptId) {
document.getElementById('desc_msg').innerText = `${t('generating_progress')} ${json.current}/${json.total},${t('generating_msg')}`
asyncGenPptxInfo(json.pptId)
}
}
source.onend = function (data) {
if (data.data.startsWith('{') && data.data.endsWith('}')) {
const json = JSON.parse(data.data)
if (json.code != 0) {
alert(t('alert_ppt_error') + json.message)
return
}
}
clearInterval(timer)
document.getElementById('desc').style.display = 'none'
document.getElementById('pptDownload').style.display = 'inline-block'
document.getElementById('insert_element').style.display = 'inline-block'
drawPptxList()
}
source.onerror = function (err) {
clearInterval(timer)
console.error('生成内容异常', err)
alert(t('alert_ppt_error'))
}
source.stream()
}
function asyncGenPptxInfo(id) {
pptxId = id
let url = `https://docmee.cn/api/public/ppt/asyncPptInfo?apiKey=${apiKey}&pptId=${pptxId}`
let xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.send()
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
let resp = JSON.parse(xhr.responseText)
let gzipBase64 = resp.data.pptxProperty
let gzip = base64js.toByteArray(gzipBase64)
let json = pako.ungzip(gzip, { to: 'string' })
pptxObj = JSON.parse(json)
drawPptxList(resp.data.current - 1, true)
}
}
}
xhr.onerror = function (e) {
console.error(e)
document.getElementById('desc').style.display = 'none'
}
}
async function drawPptxList(idx, asyncGen) {
if (idx == null || document.getElementById('img_' + idx) == null) {
let html = ''
for (let i = 0; i < pptxObj.pages.length; i++) {
if (asyncGen && i > idx) {
break
}
html += '<div class="left_div_item" onclick="drawPptx(' + i + ')">'
html += '<div class="left_div_item_index">' + (i + 1) + '</div>'
html += '<canvas id="img_' + i + '" width="288" height="162" style="width: 144px;height: 81px;" class="left_div_item_img" />'
html += '</div>'
}
if (asyncGen && idx < pptxObj.pages.length - 1) {
html += '<div class="left_div_item">'
html += '<div class="left_div_item_index">' + (idx + 2) + '</div>'
html += `<div style="width: 144px;height: 81px;text-align: center;line-height: 81px;color: #666;cursor: default;" class="left_div_item_img">${t('generating_msg')}</div>`
html += '</div>'
}
let itemList = document.getElementById('left_image_list')
itemList.innerHTML = html
if (asyncGen) {
itemList.scrollBy(0, itemList.scrollHeight)
}
for (let i = 0; i < pptxObj.pages.length; i++) {
let imgCanvas = document.getElementById('img_' + i)
if (!imgCanvas) {
continue
}
try {
let _ppt2Canvas = new Ppt2Canvas(imgCanvas)
await _ppt2Canvas.drawPptx(pptxObj, i)
} catch(e) {
console.log('渲染第' + (i + 1) + '页封面异常', e)
}
}
} else if (idx != null) {
try {
let imgCanvas = document.getElementById('img_' + idx)
let _ppt2Canvas = new Ppt2Canvas(imgCanvas)
await _ppt2Canvas.drawPptx(pptxObj, idx)
} catch(e) {
console.log('渲染第' + (idx + 1) + '页封面异常', e)
}
}
drawPptx(idx || 0)
}
function drawPptx(idx) {
if (idx == 0) {
document.getElementById('img_0').scrollIntoView(true)
}
let lastSelect = document.getElementById('img_' + selectIdx)
lastSelect && lastSelect.classList.remove('item_select')
document.getElementById('right_canvas').style.display = 'block'
selectIdx = idx
let current = document.getElementById('img_' + idx)
current.classList.add('item_select')
painter.drawPptx(pptxObj, idx)
}
function downloadPptx() {
let download = document.getElementById('downloadPptx')
// 渲染pptx并下载
const downloadBtnText = t('download_pptx_btn')
if (download.innerText !== downloadBtnText) {
return
}
download.innerText = t('rendering')
let animationType = document.getElementById('download_select').value
if (animationType != '1' && animationType != '2') {
animationType = null
}
let xhr = new XMLHttpRequest()
xhr.responseType = 'blob'
xhr.open('POST', 'https://docmee.cn/api/public/ppt/json2ppt?animationType=' + (animationType || '') + '&apiKey=' + apiKey)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.onload = function() {
if (this.status == 200) {
download.innerText = t('download_pptx_btn')
let blob = this.response
if (blob.type == 'application/json') {
const reader = new FileReader()
reader.onload = function(e) {
let json = JSON.parse(e.target.result)
alert(t('alert_download_error') + json.message)
}
reader.readAsText(blob)
return
}
let a = document.createElement('a')
a.href = window.URL.createObjectURL(blob)
let name = 'download'
let subject = document.getElementById('subject')
if (subject && subject.value) {
name = subject.value
}
a.download = name + '.pptx'
a.click()
}
}
xhr.onerror = function (e) {
console.error(e)
download.innerText = t('download_pptx_btn')
}
xhr.send(JSON.stringify(pptxObj))
}
async function calcSubjectColor(src) {
let img = new Image()
await new Promise(resolve => {
let eqOrigin = src.startsWith('data:') || src.startsWith(document.location.origin) || (src.startsWith('//') && (document.location.protocol + src).startsWith(document.location.origin))
if (!eqOrigin) {
img.crossOrigin = 'anonymous'
}
img.src = src
img.onload = function() {
resolve(img)
}
img.onerror = function (e) {
resolve()
}
})
let canvas = document.createElement('canvas')
let ctx = canvas.getContext('2d')
canvas.width = img.width
canvas.height = img.height
ctx.drawImage(img, 0, 0)
let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
let data = imageData.data
let map = {}
for (let i = 0; i < data.length; i += 4) {
let r = data[i]
let g = data[i + 1]
let b = data[i + 2]
let rgb = r + g + b
if (rgb <= 50 || rgb >= 660) {
// 忽略黑白
continue
}
let color = `${r},${g},${b}`
map[color] = (map[color] || 0) + 1
}
let valueMap = {}
for (let k in map) {
let v = map[k]
let ks = valueMap[v]
if (ks) {
ks.push(k)
} else {
valueMap[v] = [k]
}
}
let colors = []
let values = Object.values(map).sort()
for (let i = values.length - 1; i >= 0; i--) {
let ks = valueMap[values[i]]
for (let j = 0; j < ks.length; j++) {
colors.push(ks[j])
if (colors.length >= 3) {
break
}
}
if (colors.length >= 3) {
break
}
}
// return `rgb(${colors[0]})`
return `linear-gradient(to bottom right, rgb(${colors[0]}), rgb(${colors[1]}), rgb(${colors[2]}))`
}
function insertElement(type, subType) {
let element = null
if (type == 'text') {
// 文本
element = createTextBox(subType)
} else if (type == 'image') {
// 图片
let input = document.createElement('input')
input.type = 'file'
input.accept = '.jpg,.png'
input.onchange = function(e1) {
const file = e1.target.files[0]
if (!file) return
const reader = new FileReader()
reader.onload = function(e2) {
const base64 = e2.target.result
const img = new Image()
img.src = base64
img.onload = function() {
const width = img.width > 300 ? 300 : img.width
const height = img.height * (width / img.width)
element = createImage(base64, width, height)
pptxObj.pages[selectIdx].children.push(element)
painter.drawPptx(pptxObj, selectIdx)
}
}
reader.readAsDataURL(file)
}
input.click()
} else if (type == 'geometry') {
// 形状
let geometryName = subType
if (!geometryName) {
// 随机形状
let keys = Object.keys(geometryMap)
geometryName = keys[Math.floor(Math.random() * keys.length)]
console.log('geometry', geometryName)
}
element = createGeometry(geometryName)
} else if (type == 'table') {
// 表格
let rowColumnDataList = [
[t('table_cell').replace('{row}', '1').replace('{col}', '1'), t('table_cell').replace('{row}', '1').replace('{col}', '2'), t('table_cell').replace('{row}', '1').replace('{col}', '3')],
[t('table_cell').replace('{row}', '2').replace('{col}', '1'), t('table_cell').replace('{row}', '2').replace('{col}', '2'), t('table_cell').replace('{row}', '2').replace('{col}', '3')],
[t('table_cell').replace('{row}', '3').replace('{col}', '1'), t('table_cell').replace('{row}', '3').replace('{col}', '2'), t('table_cell').replace('{row}', '3').replace('{col}', '3')]
]
element = createTable(rowColumnDataList)
} else if (type == 'chart') {
// 图表
let rowColumnDataList = []
if (subType == 'pie' || subType == 'doughnut') {
rowColumnDataList = [[' ', t('chart_sales')], [t('chart_q1'), '8.2'], [t('chart_q2'), '3.2'], [t('chart_q3'), '1.4'], [t('chart_q4'), '1.2']]
} else {
rowColumnDataList = [
[' ', t('chart_series').replace('{n}', '1'), t('chart_series').replace('{n}', '2'), t('chart_series').replace('{n}', '3')],
[t('chart_category').replace('{n}', '1'), '4.3', '2.4', '2'],
[t('chart_category').replace('{n}', '2'), '2.5', '4.4', '2'],
[t('chart_category').replace('{n}', '3'), '3.5', '1.8', '3'],
[t('chart_category').replace('{n}', '4'), '4.5', '2.8', '5']
]
}
element = createChart(t('chart_title'), subType, rowColumnDataList)
}
if (element) {
pptxObj.pages[selectIdx].children.push(element)
painter.drawPptx(pptxObj, selectIdx)
}
document.getElementById('insert_element').value = ''
}
function resetSize() {
let width = Math.max(Math.min(document.body.clientWidth - 400, 1600), 480)
painter.resetSize(width, width * 0.5625)
}
window.addEventListener('resize', function() {
mTimer && clearTimeout(mTimer)
mTimer = setTimeout(() => {
resetSize()
}, 50)
})
// 初始化
document.getElementById('div1').style.display = 'block'
applyLanguage()
resetSize()
</script>
</body>
</html>