vendor: amis 6.13.0 base (fork root)

This commit is contained in:
2026-06-16 22:14:57 +08:00
commit 8c8e4247a9
3840 changed files with 2467374 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
import {Excel} from '../src';
import {OfficeViewer} from '../src/OfficeViewer';
import {createOfficeViewer} from '../src/createOfficeViewer';
import XMLPackageParser from '../src/package/XMLPackageParser';
let office: OfficeViewer;
export class App {
dir: string;
fileLists: Record<string, string[]>;
viewerElement: HTMLElement;
renderOptions: any;
initFile: string;
constructor(
dir: string,
fileLists: Record<string, string[]>,
viewerElement: HTMLElement,
renderOptions: any
) {
this.dir = dir;
this.fileLists = fileLists;
this.viewerElement = viewerElement;
this.renderOptions = renderOptions;
// 支持临时拖拽文件到页面里显示
document.addEventListener('dragover', function (event) {
event.preventDefault();
});
document.addEventListener(
'drop',
e => {
e.preventDefault();
let dt = e.dataTransfer!;
let files = dt.files;
this.renderDrop(files[0]);
},
false
);
const url = new URL(location.href);
const initFile = url.searchParams.get('file');
if (initFile) {
this.renderFile(initFile);
}
this.initFile = initFile || '';
this.renderFileList();
const uploadFile = document.getElementById('uploadFile')!;
uploadFile.addEventListener('change', e => {
const files = (e.target as HTMLInputElement).files;
if (files && files.length > 0) {
this.renderDrop(files[0]);
}
e.stopPropagation();
});
}
renderFileList() {
const fileLists = this.fileLists;
const fileListElement = document.getElementById('files')!;
const html: string[] = ['<select id="fileList">'];
for (const dirName in fileLists) {
html.push(`<optgroup label="${dirName}">`);
const dir = dirName as keyof typeof fileLists;
for (const file of fileLists[dir]) {
const fileName = file.split('.')[0];
const selected =
this.initFile === `${dirName}/${file}` ? 'selected' : '';
html.push(
`<option value="${dirName}/${file}" ${selected}>${fileName}</option>`
);
}
html.push('</optgroup>');
}
fileListElement.innerHTML = html.join('');
document.getElementById('fileList')!.addEventListener('change', e => {
const fileName = (e.target as HTMLSelectElement).value;
history.pushState({fileName}, fileName, `?file=${fileName}`);
this.renderFile(fileName);
});
}
/**
* 支持临时拖拽文件到页面里显示
*/
renderDrop(file: File) {
const reader = new FileReader();
reader.onload = _e => {
const data = reader.result as ArrayBuffer;
this.renderOffice(data, file.name);
};
reader.readAsArrayBuffer(file);
}
async renderFile(fileName: string) {
const filePath = `${this.dir}/${fileName}`;
const file = await (await fetch(filePath)).arrayBuffer();
await this.renderOffice(file, fileName);
}
/**
* 渲染
*/
async renderOffice(data: ArrayBuffer, fileName: string) {
if (office) {
office.destroy();
}
if (fileName.endsWith('.xml')) {
office = await createOfficeViewer(
data,
this.renderOptions,
fileName,
new XMLPackageParser()
);
} else {
office = await createOfficeViewer(data, this.renderOptions, fileName);
if (office instanceof Excel) {
await office.loadExcel();
}
}
const fileNameSplit = fileName.split('/');
const downloadName = fileNameSplit[fileNameSplit.length - 1].replace(
'.xml',
'.docx'
);
(window as any).downloadDocx = () => {
office.download(downloadName);
};
(window as any).printDocx = () => {
office.print();
};
office.render(this.viewerElement, this.renderOptions);
}
}

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>excel viewer</title>
<link rel="stylesheet" href="/examples/static/css/app.css" />
<link rel="stylesheet" href="../scss/office.scss" />
<style>
@font-face {
font-family: DengXian;
src: local('DengXian'), url('static/font/DengXian.ttf');
}
@font-face {
font-family: '\u7b49\u7ebf';
src: local('\u7b49\u7ebf'), local('DengXian'),
url('static/font/DengXian.ttf');
}
</style>
<script>
window['OFFICE_VIEWER_DEBUG'] = true;
</script>
</head>
<body>
<div class="columns">
<div class="column file-list" id="fileList">
<button type="button" onclick="downloadDocx()">dl</button>
<button type="button" onclick="printDocx()">print</button>
<div id="files"></div>
<div id="upload">
<input
type="file"
id="uploadFile"
name="uploadFile"
accept=".docx, .xlsx"
/>
</div>
<div id="mousePosition"></div>
<div id="hitTestResult"></div>
</div>
<div class="column">
<div id="viewer"></div>
</div>
</div>
<script type="module" src="/examples/excel.ts"></script>
</body>
</html>

View File

@@ -0,0 +1,39 @@
/**
* 本地测试例子
*/
import {HitTestResult} from '../src/excel/render/selection/hitTest';
import {App} from './common';
import fileLists from './excelFileList';
const viewerElement = document.getElementById('viewer') as HTMLElement;
const testDir = '/__tests__/xlsx';
const data = {};
const renderOptions = {
height: 700,
debug: true,
editable: true,
fontURL: {
等线: '/examples/static/font/DengXian.ttf',
仿宋: '/examples/static/font/STFANGSO.TTF',
黑体: '/examples/static/font/simhei.ttf'
},
data,
mousePositionTracker: (
x: number,
y: number,
hitTestResult: HitTestResult | null
) => {
document.getElementById('mousePosition')!.innerText = `x${x}, y${y}`;
if (hitTestResult) {
document.getElementById(
'hitTestResult'
)!.innerHTML = `${hitTestResult.type}<br/>row: ${hitTestResult.startRow}<br/>col: ${hitTestResult.startCol}<br/>endRow: ${hitTestResult.endRow}<br/>endCol: ${hitTestResult.endCol}<br/>r: ${hitTestResult.region}<br/>width: ${hitTestResult.width}<br/>height: ${hitTestResult.height}`;
}
},
enableVar: true
};
new App(testDir, fileLists, viewerElement, renderOptions);

View File

@@ -0,0 +1,140 @@
export default {
auto_filter: ['autofilter.xlsx', 'eq.xlsx', 'init.xlsx'],
chart: [
'chart.xlsx',
'chart_area.xlsx',
'chart_bar.xlsx',
'chart_clustered.xlsx',
'chart_column.xlsx',
'chart_combined.xlsx',
'chart_data_labels.xlsx',
'chart_data_table.xlsx',
'chart_data_tools.xlsx',
'chart_date_axis.xlsx',
'chart_doughnut.xlsx',
'chart_gauge.xlsx',
'chart_gradient.xlsx',
'chart_line.xlsx',
'chart_pareto.xlsx',
'chart_pattern.xlsx',
'chart_pie.xlsx',
'chart_radar.xlsx',
'chart_scatter.xlsx',
'chart_secondary_axis.xlsx',
'chart_stock.xlsx',
'chart_styles.xlsx',
'chartsheet.xlsx'
],
conditional_format: [
'3color.xlsx',
'blank.xlsx',
'bottom_range.xlsx',
'conditional_format.xlsx',
'databar.xlsx',
'databar_number.xlsx',
'date.xlsx',
'iconset.xlsx',
'simple.xlsx',
'x14_iconset.xlsx'
],
csv: ['simple.csv', 'simple.tsv'],
font: ['custom_font.xlsx'],
formula: [
'Expenses01.xlsx',
'Expenses02.xlsx',
'Expenses03.xlsx',
'array_formula.xlsx',
'formula.xlsx',
'lambda.xlsx'
],
freeze: ['freeze.xlsx', 'freeze_col.xlsx', 'freeze_row.xlsx', 'panes.xlsx'],
image: [
'crop.xlsx',
'image.xlsx',
'image_group.xlsx',
'images.xlsx',
'img.xlsx'
],
large: ['100.xlsx', '100k.xlsx', '10k.xlsx', '1k.xlsx', '关键词速查表.xlsx'],
malformed: ['lowcase.xlsx'],
merge: [
'merge1.xlsx',
'merge_cell.xlsx',
'merge_rich_string.xlsx',
'scroll_left.xlsx'
],
numfmt: [
'1904.xlsx',
'aaa.xlsx',
'aaaa.xlsx',
'nan.xlsx',
'number_as_text.xlsx',
'numfmt_color.xlsx',
'rmb.xlsx'
],
outline: ['outline.xlsx', 'outline_collapsed.xlsx'],
pivot: ['pivot_table_data.xlsx', 'simple.xlsx'],
protect: ['protect.xlsx'],
sheet: ['many_sheet.xlsx', 'sheet_color.xlsx', 'sheet_hide.xlsx'],
simple: [
'all.xlsx',
'colRowSize.xlsx',
'datetimes.xlsx',
'defaultColWidth.xlsx',
'definedName.xlsx',
'demo.xlsx',
'e.xlsx',
'full.xlsx',
'gridline.xlsx',
'hidden.xlsx',
'hide.xlsx',
'hide_row_col.xlsx',
'multipleSheet.xlsx',
'noHeaderGrid.xlsx',
'presetCellStyles.xlsx'
],
slow: ['many_text.xlsx'],
sparklines: ['sparklines1.xlsx', 'sparklines2.xlsx'],
style: ['border.xlsx', 'diag_border.xlsx'],
table: ['slicer.xlsx', 'tableFilter.xlsx', 'tables.xlsx'],
text: [
'auto_clip.xlsx',
'auto_height.xlsx',
'background.xlsx',
'bottom.xlsx',
'bug_1.xlsx',
'cell_indentation.xlsx',
'clip.xlsx',
'fontStyle.xlsx',
'hyperlink.xlsx',
'link.xlsx',
'number.xlsx',
'rich.xlsx',
'rich_strings.xlsx',
'right_to_left.xlsx',
'sharedString.xlsx',
'textFill.xlsx',
'textRotation.xlsx',
'text_indent.xlsx',
'wrap.xlsx'
],
textbox: [
'background.xlsx',
'image_group.xlsx',
'rich.xlsx',
'shape.xlsx',
'simple.xlsx',
'textbox.xlsx'
],
todo: [
'autofit.xlsx',
'background.xlsx',
'comments.xlsx',
'comments1.xlsx',
'data_validate.xlsx',
'defined_name.xlsx',
'dynamic_arrays.xlsx',
'ignore_errors.xlsx',
'protection.xlsx'
]
};

View File

@@ -0,0 +1,613 @@
/* 从 office 365 抄来的,目前主要作为参考,由于版权问题只下载了等线做测试 */
@font-face {
font-family: msofp;
font-style: normal;
font-weight: 400;
src: url(https://fs.microsoft.com/fs/4.9/flat_officeFontsPreview.ttf)
format('truetype');
}
@font-face {
font-family: Aharoni;
src: local('Aharoni'),
url(https://fs.microsoft.com/fs/4.9/rawguids/27490885900);
}
@font-face {
font-family: 'Aptos Display';
src: local('Aptos Display'),
url(https://fs.microsoft.com/fs/4.35/rawguids/23001069669);
}
@font-face {
font-family: 'Aptos Narrow';
src: local('Aptos Narrow'),
url(https://fs.microsoft.com/fs/4.35/rawguids/31558910439);
}
@font-face {
font-family: 'Angsana New';
src: local('Angsana New'),
url(https://fs.microsoft.com/fs/4.7/rawguids/289217233594);
}
@font-face {
font-family: 'Arial Black';
src: local('Arial Black'),
url(https://fs.microsoft.com/fs/4.7/rawguids/36152637550);
}
@font-face {
font-family: Batang;
src: local('Batang'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: '\ubc14\ud0d5';
src: local('\ubc14\ud0d5'), local('Batang'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: BatangChe;
src: local('BatangChe'), local('\ubc14\ud0d5\uccb4'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: '\ubc14\ud0d5';
src: local('\ubc14\ud0d5\uccb4'), local('BatangChe'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: 'Book Antiqua';
src: local('Book Antiqua'),
url(https://fs.microsoft.com/fs/4.7/rawguids/40122424405);
}
@font-face {
font-family: 'Browallia New';
src: local('Browallia New'),
url(https://fs.microsoft.com/fs/4.7/rawguids/291604924610);
}
@font-face {
font-family: Cambria;
src: local('Cambria'),
url(https://fs.microsoft.com/fs/4.7/rawguids/87548952391);
}
@font-face {
font-family: Candara;
src: local('Candara'),
url(https://fs.microsoft.com/fs/4.7/rawguids/38835860617);
}
@font-face {
font-family: Century;
src: local('Century'),
url(https://fs.microsoft.com/fs/4.7/rawguids/38027012730);
}
@font-face {
font-family: 'Comic Sans MS';
src: local('Comic Sans MS'),
url(https://fs.microsoft.com/fs/4.7/rawguids/34621977852);
}
@font-face {
font-family: Consolas;
src: local('Consolas'),
url(https://fs.microsoft.com/fs/4.7/rawguids/33167468773);
}
@font-face {
font-family: Constantia;
src: local('Constantia'),
url(https://fs.microsoft.com/fs/4.7/rawguids/31448377222);
}
@font-face {
font-family: Corbel;
src: local('Corbel'),
url(https://fs.microsoft.com/fs/4.7/rawguids/35115404204);
}
@font-face {
font-family: 'Cordia New';
src: local('Cordia New'),
url(https://fs.microsoft.com/fs/4.7/rawguids/298741729875);
}
@font-face {
font-family: 'Courier New';
src: local('Courier New'),
url(https://fs.microsoft.com/fs/4.7/rawguids/39673202522);
}
@font-face {
font-family: DengXian;
src: local('DengXian'),
url(https://fs.microsoft.com/fs/4.9/rawguids/53665963276);
}
@font-face {
font-family: '\u7b49\u7ebf';
src: local('\u7b49\u7ebf'), local('DengXian'),
url(https://fs.microsoft.com/fs/4.9/rawguids/53665963276);
}
@font-face {
font-family: DilleniaUPC;
src: local('DilleniaUPC'),
url(https://fs.microsoft.com/fs/4.7/rawguids/31371064924);
}
@font-face {
font-family: Dotum;
src: local('Dotum'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: '\ub3cb\uc6c0';
src: local('\ub3cb\uc6c0'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: DotumChe;
src: local('DotumChe'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: '\ub3cb\uc6c0\uccb4';
src: local('\ub3cb\uc6c0\uccb4'), local('DotumChe'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: FangSong;
src: local('FangSong'),
url(https://fs.microsoft.com/fs/4.7/rawguids/29400494812);
}
@font-face {
font-family: '\u4eff\u5b8b';
src: local('\u4eff\u5b8b'), local('FangSong'),
url(https://fs.microsoft.com/fs/4.7/rawguids/29400494812);
}
@font-face {
font-family: Garamond;
src: local('Garamond'),
url(https://fs.microsoft.com/fs/4.7/rawguids/36480320667);
}
@font-face {
font-family: Georgia;
src: local('Georgia'),
url(https://fs.microsoft.com/fs/4.7/rawguids/35602463917);
}
@font-face {
font-family: Gulim;
src: local('Gulim'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: '\uad74\ub9bc';
src: local('\uad74\ub9bc'), local('Gulim'),
url(https://fs.microsoft.com/fs/4.7/rawguids/156326683380);
}
@font-face {
font-family: Gungsuh;
src: local('Gungsuh'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: '\uad81\uc11c';
src: local('\uad81\uc11c'), local('Gungsuh'),
url(https://fs.microsoft.com/fs/4.7/rawguids/161036472418);
}
@font-face {
font-family: KaiTi;
src: local('KaiTi'), url(https://fs.microsoft.com/fs/4.7/rawguids/28214366148);
}
@font-face {
font-family: '\u6977\u4f53';
src: local('\u6977\u4f53'), local('KaiTi'),
url(https://fs.microsoft.com/fs/4.7/rawguids/28214366148);
}
@font-face {
font-family: JasmineUPC;
src: local('JasmineUPC'),
url(https://fs.microsoft.com/fs/4.7/rawguids/29339734237);
}
@font-face {
font-family: 'Malgun Gothic';
src: local('Malgun Gothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/41226677490);
}
@font-face {
font-family: '\ub9d1\uc740 \uace0\ub515';
src: local('\ub9d1\uc740 \uace0\ub515'), local('Malgun Gothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/41226677490);
}
@font-face {
font-family: Mangal;
src: local('Mangal'),
url(https://fs.microsoft.com/fs/4.7/rawguids/41732083461);
}
@font-face {
font-family: Meiryo;
src: local('Meiryo'),
url(https://fs.microsoft.com/fs/4.7/rawguids/128117683827);
}
@font-face {
font-family: '\u30e1\u30a4\u30ea\u30aa';
src: local('\u30e1\u30a4\u30ea\u30aa'), local('Meiryo'),
url(https://fs.microsoft.com/fs/4.7/rawguids/128117683827);
}
@font-face {
font-family: 'Microsoft JhengHei';
src: local('Microsoft JhengHei'),
url(https://fs.microsoft.com/fs/4.7/rawguids/78992571833);
}
@font-face {
font-family: 'Microsoft YaHei';
src: local('Microsoft YaHei'),
url(https://fs.microsoft.com/fs/4.7/rawguids/91766082489);
}
@font-face {
font-family: MingLiU;
src: local('MingLiU'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: '\u7d30\u660e\u9ad4';
src: local('MingLiU'), local('\u7d30\u660e\u9ad4'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: MingLiU_HKSCS;
src: local('MingLiU_HKSCS'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: '\u7d30\u660e\u9ad4_HKSCS';
src: local('MingLiU_HKSCS'), local('\u7d30\u660e\u9ad4_HKSCS'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: 'MS Gothic';
src: local('MS Gothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/126469790770);
}
@font-face {
font-family: '\uff2d\uff33 \u30b4\u30b7\u30c3\u30af';
src: local('\uff2d\uff33 \u30b4\u30b7\u30c3\u30af'), local('MS Gothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/126469790770);
}
@font-face {
font-family: 'MS Mincho';
src: local('MS Mincho'), local('\uff2d\uff33 \u660e\u671d'),
url(https://fs.microsoft.com/fs/4.7/rawguids/79832647984);
}
@font-face {
font-family: '\uff2d\uff33 \u660e\u671d';
src: local('MS Mincho'), local('\uff2d\uff33 \u660e\u671d'),
url(https://fs.microsoft.com/fs/4.7/rawguids/79832647984);
}
@font-face {
font-family: 'MS PGothic';
src: local('MS PGothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/126469790770);
}
@font-face {
font-family: '\uff2d\uff33 \uff30\u30b4\u30b7\u30c3\u30af';
src: local('\uff2d\uff33 \uff30\u30b4\u30b7\u30c3\u30af'), local('MS PGothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/126469790770);
}
@font-face {
font-family: 'MS PMincho';
src: local('MS PMincho'),
url(https://fs.microsoft.com/fs/4.7/rawguids/79832647984);
}
@font-face {
font-family: '\uff2d\uff33 \uff30\u660e\u671d';
src: local('MS PMincho'), local('\uff2d\uff33 \uff30\u660e\u671d'),
url(https://fs.microsoft.com/fs/4.7/rawguids/79832647984);
}
@font-face {
font-family: 'Open Sans';
src: local('Open Sans'),
url(https://fs.microsoft.com/fs/4.16/rawguids/24492784331);
}
@font-face {
font-family: PMingLiU;
src: local('PMingLiU'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: '\u65b0\u7d30\u660e\u9ad4';
src: local('\u65b0\u7d30\u660e\u9ad4'), local('PMingLiU'),
url(https://fs.microsoft.com/fs/4.7/rawguids/107373335009);
}
@font-face {
font-family: PMingLiU-ExtB;
src: local('PMingLiU-ExtB'),
url(https://fs.microsoft.com/fs/4.7/rawguids/100045330013);
}
@font-face {
font-family: '\u65b0\u7d30\u660e\u9ad4-ExtB';
src: local('\u65b0\u7d30\u660e\u9ad4-ExtB'), local('PMingLiU-ExtB'),
url(https://fs.microsoft.com/fs/4.7/rawguids/100045330013);
}
@font-face {
font-family: Roboto;
src: local('Roboto'),
url(https://fs.microsoft.com/fs/4.16/rawguids/26892287593);
}
@font-face {
font-family: SimHei;
src: local('SimHei'),
url(https://fs.microsoft.com/fs/4.7/rawguids/32980441079);
}
@font-face {
font-family: '\u9ed1\u4f53';
src: local('\u9ed1\u4f53'), local('SimHei'),
url(https://fs.microsoft.com/fs/4.7/rawguids/32980441079);
}
@font-face {
font-family: SimSun;
src: local('SimSun'),
url(https://fs.microsoft.com/fs/4.7/rawguids/88761586021);
}
@font-face {
font-family: '\u5b8b\u4f53';
src: local('\u5b8b\u4f53'), local('SimSun'),
url(https://fs.microsoft.com/fs/4.7/rawguids/88761586021);
}
@font-face {
font-family: SimSun-ExtB;
src: local('SimSun-ExtB'),
url(https://fs.microsoft.com/fs/4.7/rawguids/27824684633);
}
@font-face {
font-family: 'Source Sans Pro';
src: local('Source Sans Pro'),
url(https://fs.microsoft.com/fs/4.7/rawguids/35021733747);
}
@font-face {
font-family: Tahoma;
src: local('Tahoma'),
url(https://fs.microsoft.com/fs/4.7/rawguids/50941620409);
}
@font-face {
font-family: 'TH SarabunPSK';
src: local('TH SarabunPSK'),
url(https://fs.microsoft.com/fs/4.7/rawguids/40796829544);
}
@font-face {
font-family: 'Trebuchet MS';
src: local('Trebuchet MS'),
url(https://fs.microsoft.com/fs/4.7/rawguids/34633337668);
}
@font-face {
font-family: Verdana;
src: local('Verdana'),
url(https://fs.microsoft.com/fs/4.7/rawguids/31984381249);
}
@font-face {
font-family: 'Yu Gothic';
src: local('Yu Gothic'),
url(https://fs.microsoft.com/fs/4.7/rawguids/59386888943);
}
@font-face {
font-family: '\u6e38\u30b4\u30b7\u30c3\u30af';
src: local('Yu Gothic'), local('\u6e38\u30b4\u30b7\u30c3\u30af'),
url(https://fs.microsoft.com/fs/4.7/rawguids/59386888943);
}
@font-face {
font-family: 'Yu Mincho';
src: local('Yu Mincho'),
url(https://fs.microsoft.com/fs/4.7/rawguids/31515951246);
}
@font-face {
font-family: '\u6e38\u660e\u671d';
src: local('\u6e38\u660e\u671d'), local('Yu Mincho'),
url(https://fs.microsoft.com/fs/4.7/rawguids/31515951246);
}
@font-face {
font-family: HGGothicE;
src: local('HGGothicE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: 'HG\uff7a\uff9e\uff7c\uff6f\uff78E';
src: local('HG\uff7a\uff9e\uff7c\uff6f\uff78E'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: HGMaruGothicMPRO;
src: local('HGGothicE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/28193954534);
}
@font-face {
font-family: 'HG\u4e38\uff7a\uff9e\uff7c\uff6f\uff78M-PRO';
src: local('HG\u4e38\uff7a\uff9e\uff7c\uff6f\uff78M-PRO'),
url(https://fs.microsoft.com/fs/4.16/rawguids/28193954534);
}
@font-face {
font-family: HGMinchoE;
src: local('HGMinchoE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: 'HG\u660e\u671dE';
src: local('HG\u660e\u671dE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: HGPGothicE;
src: local('HGPGothicE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: 'HGP\uff7a\uff9e\uff7c\uff6f\uff78E';
src: local('HGP\uff7a\uff9e\uff7c\uff6f\uff78E'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: HGPMinchoE;
src: local('HGPMinchoE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: 'HGP\u660e\u671dE';
src: local('HGP\u660e\u671dE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: HGPSoeiKakugothicUB;
src: local('HGPSoeiKakugothicUB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: 'HGP\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB';
src: local('HGP\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: HGSGothicE;
src: local('HGSGothicE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: 'HGS\uff7a\uff9e\uff7c\uff6f\uff78E';
src: local('HGS\uff7a\uff9e\uff7c\uff6f\uff78E'),
url(https://fs.microsoft.com/fs/4.16/rawguids/83208183430);
}
@font-face {
font-family: HGSMinchoE;
src: local('HGSMinchoE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: 'HGS\u660e\u671dE';
src: local('HGS\u660e\u671dE'),
url(https://fs.microsoft.com/fs/4.16/rawguids/67824027433);
}
@font-face {
font-family: HGSSoeiKakugothicUB;
src: local('HGSSoeiKakugothicUB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: 'HGS\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB';
src: local('HGS\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: HGSoeiKakugothicUB;
src: local('HGSoeiKakugothicUB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: 'HG\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB';
src: local('HG\u5275\u82f1\u89d2\uff7a\uff9e\uff7c\uff6f\uff78UB'),
url(https://fs.microsoft.com/fs/4.16/rawguids/81181548348);
}
@font-face {
font-family: 'MS UI Gothic';
src: local('MS UI Gothic'),
url(https://fs.microsoft.com/fs/4.16/rawguids/126469790770);
}
@font-face {
font-family: 'Meiryo UI';
src: local('Meiryo UI'),
url(https://fs.microsoft.com/fs/4.16/rawguids/128117683827);
}
@font-face {
font-family: 'UD Digi Kyokasho N-B';
src: local('UD Digi Kyokasho N-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 N-B';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 N-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD Digi Kyokasho N-R';
src: local('UD Digi Kyokasho N-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 N-R';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 N-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'UD Digi Kyokasho NK-B';
src: local('UD Digi Kyokasho NK-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NK-B';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NK-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD Digi Kyokasho NK-R';
src: local('UD Digi Kyokasho NK-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NK-R';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NK-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'UD Digi Kyokasho NP-B';
src: local('UD Digi Kyokasho NP-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NP-B';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NP-B'),
url(https://fs.microsoft.com/fs/4.16/rawguids/80295677972);
}
@font-face {
font-family: 'UD Digi Kyokasho NP-R';
src: local('UD Digi Kyokasho NP-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NP-R';
src: local('UD \u30c7\u30b8\u30bf\u30eb \u6559\u79d1\u66f8\u4f53 NP-R'),
url(https://fs.microsoft.com/fs/4.16/rawguids/72819386698);
}
@font-face {
font-family: 'Yu Gothic Light';
src: local('Yu Gothic Light'),
url(https://fs.microsoft.com/fs/4.16/rawguids/63234296555);
}
@font-face {
font-family: '\u6e38\u30b4\u30b7\u30c3\u30af';
src: local('Yu Gothic Light'), local('\u6e38\u30b4\u30b7\u30c3\u30af'),
url(https://fs.microsoft.com/fs/4.16/rawguids/63234296555);
}
@font-face {
font-family: 'Yu Gothic Medium';
src: local('Yu Gothic Medium'),
url(https://fs.microsoft.com/fs/4.16/rawguids/79019533632);
}
@font-face {
font-family: 'Yu Gothic UI Light';
src: local('Yu Gothic UI Light'),
url(https://fs.microsoft.com/fs/4.16/rawguids/63234296555);
}
@font-face {
font-family: 'Yu Gothic UI';
src: local('Yu Gothic UI'),
url(https://fs.microsoft.com/fs/4.16/rawguids/118823493255);
}
@font-face {
font-family: 'Yu Gothic UI Semibold';
src: local('Yu Gothic UI Semibold'),
url(https://fs.microsoft.com/fs/4.16/rawguids/71559817051);
}
@font-face {
font-family: 'Yu Gothic UI Semilight';
src: local('Yu Gothic UI Semilight'),
url(https://fs.microsoft.com/fs/4.16/rawguids/71559817051);
}
@font-face {
font-family: 'Yu Mincho Demibold';
src: local('Yu Mincho Demibold'),
url(https://fs.microsoft.com/fs/4.16/rawguids/32128654173);
}
@font-face {
font-family: '\u6e38\u660e\u671d';
src: local('\u6e38\u660e\u671d'),
url(https://fs.microsoft.com/fs/4.16/rawguids/32128654173);
}
@font-face {
font-family: 'Yu Mincho Light';
src: local('Yu Mincho Light'),
url(https://fs.microsoft.com/fs/4.16/rawguids/32976986095);
}

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Preset Shape</title>
<link rel="stylesheet" href="./static/css/app.css" />
</head>
<body>
<div id="shapes"></div>
<script type="module" src="./presetShape.ts"></script>
</body>
</html>

View File

@@ -0,0 +1,32 @@
import {presetShape} from '../src/openxml/drawing/presetShape';
import {shapeToSVG} from '../src/openxml/drawing/svg/shapeToSVG';
const container = document.getElementById('shapes')! as HTMLElement;
for (const shapeName in presetShape) {
// 临时测试用
if (shapeName !== 'smileyFace') {
// continue;
}
const shape = presetShape[shapeName];
console.log('render shape', shapeName);
const svg = shapeToSVG(shape, [], {}, 100, 100, {
fillColor: '#4472C4'
});
const div = document.createElement('div');
div.style.display = 'inline-block';
div.style.margin = '12px 40px';
div.style.width = '100px';
div.style.height = '120px';
div.style.boxSizing = 'border-box';
div.style.verticalAlign = 'top';
div.style.textAlign = 'center';
div.appendChild(svg);
const p = document.createElement('p');
p.innerText = shapeName;
div.appendChild(p);
container.appendChild(div);
}

View File

@@ -0,0 +1,111 @@
html,
body {
margin: 0;
padding: 0;
}
@font-face {
font-family: Wingdings;
src: url(/examples/static/font/wingding.ttf) format('truetype');
}
@font-face {
font-family: Symbol;
src: url(/examples/static/font/symbol.ttf) format('truetype');
}
/** 参考 bulma 的命名 */
.columns {
display: flex;
}
.column {
display: block;
flex-basis: 0;
flex-grow: 1;
flex-shrink: 1;
}
.file-list {
flex: none;
width: 100px;
padding-top: 4px;
padding-left: 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
select {
width: 100%;
}
}
.file {
cursor: pointer;
}
.file:hover {
color: hsl(217, 71%, 53%);
}
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 30px;
height: 18px;
}
/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: 0.4s;
transition: 0.4s;
}
.slider:before {
position: absolute;
content: '';
height: 16px;
width: 16px;
left: 1px;
bottom: 1px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}
input:checked + .slider {
background-color: #2196f3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196f3;
}
input:checked + .slider:before {
-webkit-transform: translateX(12px);
transform: translateX(12px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>word viewer</title>
<link rel="stylesheet" href="/examples/static/css/app.css" />
<link rel="stylesheet" href="../scss/office.scss" />
</head>
<body>
<div class="columns">
<div class="column file-list" id="fileList">
<button type="button" onclick="downloadDocx()">dl</button>
<button type="button" onclick="printDocx()">print</button>
<p id="page">
page
<label class="switch">
<input
type="checkbox"
onchange="switchPage(this.checked)"
id="switchPage"
/>
<span class="slider round" id="pageSlider"></span>
</label>
</p>
<div id="files"></div>
<div id="upload">
<input
type="file"
id="uploadFile"
name="uploadFile"
accept=".docx, .xlsx"
/>
</div>
</div>
<div class="column">
<div id="viewer"></div>
</div>
</div>
<script type="module" src="/examples/word.ts"></script>
</body>
</html>

View File

@@ -0,0 +1,132 @@
/**
* 本地测试例子
*/
import {App} from './common';
const viewerElement = document.getElementById('viewer') as HTMLElement;
const testDir = '/__tests__/docx';
const fileLists = {
simple: [
'br.xml',
'bold.xml',
'drop-cap.xml',
'em.xml',
'embed-font.xml',
'hideMark.xml',
'highlight.xml',
'image.xml',
'image-var.docx',
'info.xml',
'link.xml',
'list.xml',
'math.xml',
'noBreakHyphen.xml',
'pinyin.xml',
'svg.xml',
'sym.xml',
'shadow.xml',
'shape-ellipse.xml',
'shape-custom.xml',
'all-shape-1.xml',
'all-shape-2.xml',
'tableborder.xml',
'tablestyle.xml',
'textbox.xml',
'textbox-background.xml',
'textbox-behindDoc.xml',
'textbox-vert.xml',
'textbox-rotation.xml',
'textbox-order.xml',
'tooltip.xml',
'w.xml',
'jianli.docx',
'text-background.docx',
'group.docx',
'group-in-group.docx',
'shape-group.docx',
'tab2.xml'
],
docx4j: [
'ArialUnicodeMS.docx',
'Symbols.docx',
'Word2007-fonts.docx',
'chart.docx',
'decracdiscrim1.docx',
'docProps.docx',
'fonts-modesOfApplication.docx',
'hyperlinks-internal.docx',
'toc.docx',
'unmarshallFromTemplateDirtyExample.docx',
'unmarshallFromTemplateExample.docx',
'numberingrestart.xml',
'sample-docx.xml',
'table-features.xml',
'table-spans.xml'
]
};
// local storage 里的 key
const pageKey = 'page';
const page = !!localStorage.getItem(pageKey) || false;
if (page) {
// 不知道为啥,大概是 vite 的问题
setTimeout(() => {
const pageSwitch = document.getElementById(
'switchPage'
)! as HTMLInputElement;
pageSwitch.checked = true;
}, 0);
}
(window as any).switchPage = (checked: boolean) => {
if (checked) {
localStorage.setItem(pageKey, 'true');
} else {
localStorage.removeItem(pageKey);
}
location.reload();
};
const data = {
date: 'amis',
list: [
{
item1: 'item1.0',
item2: 'item2.0',
img: '/examples/static/image/firefox.jpg'
},
{
item1: 'item1.1',
item2: 'item2.1',
img: '/examples/static/image/ie.png'
}
],
list2: [
{
item1: 'item2-1.0',
item2: 'item2-2.0',
img: '/examples/static/image/firefox.jpg'
},
{
item1: 'item2-1.1',
item2: 'item2-2.1',
img: '/examples/static/image/ie.png'
}
],
sum: 'sum20',
aImg: '/examples/static/image/ie.png'
};
const renderOptions = {
debug: true,
page,
data,
enableVar: true
};
new App(testDir, fileLists, viewerElement, renderOptions);