@visactor/vtable-export 0.16.4-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/cjs/csv/index.d.ts +4 -0
- package/cjs/csv/index.js +33 -0
- package/cjs/csv/index.js.map +1 -0
- package/cjs/excel/index.d.ts +3 -0
- package/cjs/excel/index.js +92 -0
- package/cjs/excel/index.js.map +1 -0
- package/cjs/excel/style.d.ts +6 -0
- package/cjs/excel/style.js +84 -0
- package/cjs/excel/style.js.map +1 -0
- package/cjs/index.d.ts +4 -0
- package/cjs/index.js +41 -0
- package/cjs/index.js.map +1 -0
- package/cjs/util/color.d.ts +152 -0
- package/cjs/util/color.js +193 -0
- package/cjs/util/color.js.map +1 -0
- package/cjs/util/download.d.ts +2 -0
- package/cjs/util/download.js +30 -0
- package/cjs/util/download.js.map +1 -0
- package/cjs/util/encode.d.ts +3 -0
- package/cjs/util/encode.js +17 -0
- package/cjs/util/encode.js.map +1 -0
- package/cjs/util/type.d.ts +6 -0
- package/cjs/util/type.js +6 -0
- package/cjs/util/type.js.map +1 -0
- package/dist/vtable-export.js +76258 -0
- package/dist/vtable-export.min.js +92 -0
- package/es/csv/index.d.ts +4 -0
- package/es/csv/index.js +25 -0
- package/es/csv/index.js.map +1 -0
- package/es/excel/index.d.ts +3 -0
- package/es/excel/index.js +82 -0
- package/es/excel/index.js.map +1 -0
- package/es/excel/style.d.ts +6 -0
- package/es/excel/style.js +75 -0
- package/es/excel/style.js.map +1 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +7 -0
- package/es/index.js.map +1 -0
- package/es/util/color.d.ts +152 -0
- package/es/util/color.js +186 -0
- package/es/util/color.js.map +1 -0
- package/es/util/download.d.ts +2 -0
- package/es/util/download.js +22 -0
- package/es/util/download.js.map +1 -0
- package/es/util/encode.d.ts +3 -0
- package/es/util/encode.js +10 -0
- package/es/util/encode.js.map +1 -0
- package/es/util/type.d.ts +6 -0
- package/es/util/type.js +2 -0
- package/es/util/type.js.map +1 -0
- package/package.json +87 -0
package/es/csv/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const newLine = "\r\n", separator = ",";
|
|
2
|
+
|
|
3
|
+
export function exportVTableToCsv(tableInstance) {
|
|
4
|
+
const maxRow = tableInstance.rowCount - 1, maxCol = tableInstance.colCount - 1;
|
|
5
|
+
let copyValue = "";
|
|
6
|
+
for (let row = 0; row <= maxRow; row++) {
|
|
7
|
+
for (let col = 0; col <= maxCol; col++) {
|
|
8
|
+
const copyCellValue = getCopyCellValue(col, row, tableInstance);
|
|
9
|
+
if ("undefined" != typeof Promise && copyCellValue instanceof Promise) ; else {
|
|
10
|
+
const strCellValue = `${copyCellValue}`;
|
|
11
|
+
/^\[object .*\]$/.exec(strCellValue) || (copyValue += strCellValue);
|
|
12
|
+
}
|
|
13
|
+
copyValue += ",";
|
|
14
|
+
}
|
|
15
|
+
copyValue += "\r\n";
|
|
16
|
+
}
|
|
17
|
+
return copyValue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getCopyCellValue(col, row, tableInstance) {
|
|
21
|
+
const cellRange = tableInstance.getCellRange(col, row), copyStartCol = cellRange.start.col, copyStartRow = cellRange.start.row;
|
|
22
|
+
if (copyStartCol !== col || copyStartRow !== row) return "";
|
|
23
|
+
return tableInstance.getCellValue(col, row);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["csv/index.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,UAAU,iBAAiB,CAAC,aAAsB;IACtD,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC;IAE1C,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3C,KAAK,IAAI,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,EAAE,EAAE;YAC3C,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;YAChE,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,aAAa,YAAY,OAAO,EAAE;aAEvE;iBAAM;gBACL,MAAM,YAAY,GAAG,GAAG,aAAa,EAAE,CAAC;gBACxC,IAAI,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;iBAEzC;qBAAM;oBACL,SAAS,IAAI,YAAY,CAAC;iBAC3B;aACF;YACD,SAAS,IAAI,SAAS,CAAC;SACxB;QACD,SAAS,IAAI,OAAO,CAAC;KACtB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW,EAAE,GAAW,EAAE,aAAsB;IACxE,MAAM,SAAS,GAAc,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IACzC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;IAEzC,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,GAAG,EAAE;QAChD,OAAO,EAAE,CAAC;KACX;IAED,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC;AACf,CAAC","file":"index.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\ntype CellRange = VTable.TYPES.CellRange;\n\nconst newLine = '\\r\\n';\nconst separator = ',';\n\nexport function exportVTableToCsv(tableInstance: IVTable): string {\n const minRow = 0;\n const maxRow = tableInstance.rowCount - 1;\n const minCol = 0;\n const maxCol = tableInstance.colCount - 1;\n\n let copyValue = '';\n for (let row = minRow; row <= maxRow; row++) {\n for (let col = minCol; col <= maxCol; col++) {\n const copyCellValue = getCopyCellValue(col, row, tableInstance);\n if (typeof Promise !== 'undefined' && copyCellValue instanceof Promise) {\n // not support async\n } else {\n const strCellValue = `${copyCellValue}`;\n if (/^\\[object .*\\]$/.exec(strCellValue)) {\n // ignore object\n } else {\n copyValue += strCellValue;\n }\n }\n copyValue += separator;\n }\n copyValue += newLine;\n }\n return copyValue;\n}\n\nfunction getCopyCellValue(col: number, row: number, tableInstance: IVTable): string | Promise<string> | void {\n const cellRange: CellRange = tableInstance.getCellRange(col, row);\n const copyStartCol = cellRange.start.col;\n const copyStartRow = cellRange.start.row;\n\n if (copyStartCol !== col || copyStartRow !== row) {\n return '';\n }\n\n const value = tableInstance.getCellValue(col, row);\n return value;\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2
|
+
return new (P || (P = Promise))((function(resolve, reject) {
|
|
3
|
+
function fulfilled(value) {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function rejected(value) {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function step(result) {
|
|
18
|
+
var value;
|
|
19
|
+
result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P((function(resolve) {
|
|
20
|
+
resolve(value);
|
|
21
|
+
}))).then(fulfilled, rejected);
|
|
22
|
+
}
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
import ExcelJS from "exceljs";
|
|
28
|
+
|
|
29
|
+
import { encodeCellAddress } from "../util/encode";
|
|
30
|
+
|
|
31
|
+
import { getCellAlignment, getCellBorder, getCellFill, getCellFont } from "./style";
|
|
32
|
+
|
|
33
|
+
export function exportVTableToExcel(tableInstance) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, (function*() {
|
|
35
|
+
const workbook = new ExcelJS.Workbook, worksheet = workbook.addWorksheet("sheet1");
|
|
36
|
+
worksheet.properties.defaultRowHeight = 40;
|
|
37
|
+
const columns = [], maxRow = tableInstance.rowCount - 1, maxCol = tableInstance.colCount - 1, mergeCells = [], mergeCellSet = new Set;
|
|
38
|
+
for (let col = 0; col <= maxCol; col++) {
|
|
39
|
+
const colWith = tableInstance.getColWidth(col);
|
|
40
|
+
columns[col] = {
|
|
41
|
+
width: colWith / 6
|
|
42
|
+
};
|
|
43
|
+
for (let row = 0; row <= maxRow; row++) {
|
|
44
|
+
if (0 === col) {
|
|
45
|
+
const rowHeight = tableInstance.getRowHeight(row);
|
|
46
|
+
worksheet.getRow(row + 1).height = rowHeight;
|
|
47
|
+
}
|
|
48
|
+
const cellValue = tableInstance.getCellValue(col, row), cellStyle = tableInstance.getCellStyle(col, row), cellType = tableInstance.getCellType(col, row), cell = worksheet.getCell(encodeCellAddress(col, row));
|
|
49
|
+
cell.value = getCellValue(cellValue, cellType), cell.font = getCellFont(cellStyle, cellType),
|
|
50
|
+
cell.fill = getCellFill(cellStyle), cell.border = getCellBorder(cellStyle), cell.alignment = getCellAlignment(cellStyle);
|
|
51
|
+
const cellRange = tableInstance.getCellRange(col, row);
|
|
52
|
+
if (cellRange.start.col !== cellRange.end.col || cellRange.start.row !== cellRange.end.row) {
|
|
53
|
+
const key = `${cellRange.start.col},${cellRange.start.row}:${cellRange.end.col},${cellRange.end.row}}`;
|
|
54
|
+
mergeCellSet.has(key) || (mergeCellSet.add(key), mergeCells.push(cellRange));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
worksheet.columns = columns, mergeCells.forEach((mergeCell => {
|
|
59
|
+
worksheet.mergeCells(mergeCell.start.row + 1, mergeCell.start.col + 1, mergeCell.end.row + 1, mergeCell.end.col + 1);
|
|
60
|
+
}));
|
|
61
|
+
const frozenView = [];
|
|
62
|
+
tableInstance.frozenRowCount > 0 && frozenView.push({
|
|
63
|
+
state: "frozen",
|
|
64
|
+
ySplit: tableInstance.frozenRowCount,
|
|
65
|
+
topLeftCell: encodeCellAddress(0, tableInstance.frozenRowCount)
|
|
66
|
+
}), tableInstance.frozenColCount > 0 && frozenView.push({
|
|
67
|
+
state: "frozen",
|
|
68
|
+
xSplit: tableInstance.frozenColCount,
|
|
69
|
+
topLeftCell: encodeCellAddress(tableInstance.frozenColCount, 0)
|
|
70
|
+
}), worksheet.views = frozenView;
|
|
71
|
+
return yield workbook.xlsx.writeBuffer();
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getCellValue(cellValue, cellType) {
|
|
76
|
+
return "link" === cellType ? {
|
|
77
|
+
text: cellValue,
|
|
78
|
+
hyperlink: cellValue,
|
|
79
|
+
tooltip: cellValue
|
|
80
|
+
} : cellValue;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["excel/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpF,MAAM,UAAgB,mBAAmB,CAAC,aAAsB;;QAC9D,MAAM,Q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CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,EACvB,SAAS,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,EACvB,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,EACrB,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CACtB,CAAC;QACJ,CAAC,CAAC,CAAC;QAGH,MAAM,UAAU,GAAkC,EAAE,CAAC;QAErD,IAAI,aAAa,CAAC,cAAc,GAAG,CAAC,EAAE;YACpC,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,QAAQ;gBACf,MAAM,EAAE,aAAa,CAAC,cAAc;gBAEpC,WAAW,EAAE,iBAAiB,CAAC,CAAC,EAAE,aAAa,CAAC,cAAc,CAAC;aAChE,CAAC,CAAC;SACJ;QAED,IAAI,aAAa,CAAC,cAAc,GAAG,CAAC,EAAE;YACpC,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,QAAQ;gBACf,MAAM,EAAE,aAAa,CAAC,cAAc;gBAEpC,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC,CAAC;aAChE,CAAC,CAAC;SACJ;QAED,SAAS,CAAC,KAAK,GAAG,UAAU,CAAC;QAE7B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjD,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAED,SAAS,YAAY,CAAC,SAAiB,EAAE,QAAkB;IACzD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO;YACL,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,SAAS;SACnB,CAAC;KACH;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","file":"index.js","sourcesContent":["import ExcelJS from 'exceljs';\nimport { encodeCellAddress } from '../util/encode';\nimport type { CellType, IVTable } from '../util/type';\nimport { getCellAlignment, getCellBorder, getCellFill, getCellFont } from './style';\n\nexport async function exportVTableToExcel(tableInstance: IVTable) {\n const workbook = new ExcelJS.Workbook();\n const worksheet = workbook.addWorksheet('sheet1');\n worksheet.properties.defaultRowHeight = 40;\n\n const columns = [];\n const minRow = 0;\n const maxRow = tableInstance.rowCount - 1;\n const minCol = 0;\n const maxCol = tableInstance.colCount - 1;\n const mergeCells = [];\n const mergeCellSet = new Set();\n\n for (let col = minCol; col <= maxCol; col++) {\n const colWith = tableInstance.getColWidth(col);\n columns[col] = { width: colWith / 6 };\n for (let row = minRow; row <= maxRow; row++) {\n if (col === minCol) {\n const rowHeight = tableInstance.getRowHeight(row);\n const worksheetRow = worksheet.getRow(row + 1);\n // worksheetRow.height = rowHeight * 0.75;\n worksheetRow.height = rowHeight;\n }\n\n const cellValue = tableInstance.getCellValue(col, row);\n const cellStyle = tableInstance.getCellStyle(col, row);\n const cellType = tableInstance.getCellType(col, row);\n\n const cell = worksheet.getCell(encodeCellAddress(col, row));\n cell.value = getCellValue(cellValue, cellType);\n cell.font = getCellFont(cellStyle, cellType);\n cell.fill = getCellFill(cellStyle);\n cell.border = getCellBorder(cellStyle);\n cell.alignment = getCellAlignment(cellStyle);\n\n const cellRange = tableInstance.getCellRange(col, row);\n if (cellRange.start.col !== cellRange.end.col || cellRange.start.row !== cellRange.end.row) {\n const key = `${cellRange.start.col},${cellRange.start.row}:${cellRange.end.col},${cellRange.end.row}}`;\n if (!mergeCellSet.has(key)) {\n mergeCellSet.add(key);\n mergeCells.push(cellRange);\n }\n }\n }\n }\n\n worksheet.columns = columns;\n mergeCells.forEach(mergeCell => {\n worksheet.mergeCells(\n mergeCell.start.row + 1,\n mergeCell.start.col + 1,\n mergeCell.end.row + 1,\n mergeCell.end.col + 1\n );\n });\n\n // frozen\n const frozenView: ExcelJS.WorksheetViewFrozen[] = [];\n // top frozen\n if (tableInstance.frozenRowCount > 0) {\n frozenView.push({\n state: 'frozen',\n ySplit: tableInstance.frozenRowCount,\n // activeCell: 'A1',\n topLeftCell: encodeCellAddress(0, tableInstance.frozenRowCount)\n });\n }\n // left frozen\n if (tableInstance.frozenColCount > 0) {\n frozenView.push({\n state: 'frozen',\n xSplit: tableInstance.frozenColCount,\n // activeCell: 'A1',\n topLeftCell: encodeCellAddress(tableInstance.frozenColCount, 0)\n });\n }\n // not support bottom&right frozen\n worksheet.views = frozenView;\n\n const buffer = await workbook.xlsx.writeBuffer();\n return buffer;\n}\n\nfunction getCellValue(cellValue: string, cellType: CellType) {\n if (cellType === 'link') {\n return {\n text: cellValue,\n hyperlink: cellValue,\n tooltip: cellValue\n };\n }\n return cellValue;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type ExcelJS from 'exceljs';
|
|
2
|
+
import type { CellStyle, CellType } from '../util/type';
|
|
3
|
+
export declare function getCellFont(cellStyle: CellStyle, cellType: CellType): Partial<ExcelJS.Font>;
|
|
4
|
+
export declare function getCellFill(cellStyle: CellStyle): ExcelJS.Fill;
|
|
5
|
+
export declare function getCellBorder(cellStyle: CellStyle): Partial<ExcelJS.Borders>;
|
|
6
|
+
export declare function getCellAlignment(cellStyle: CellStyle): Partial<ExcelJS.Alignment>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { colorStringToRGB, rgbaToHex } from "../util/color";
|
|
2
|
+
|
|
3
|
+
export function getCellFont(cellStyle, cellType) {
|
|
4
|
+
return {
|
|
5
|
+
name: getFirstFontFromFontFamily(cellStyle.fontFamily) || "Arial",
|
|
6
|
+
size: cellStyle.fontSize || 10,
|
|
7
|
+
bold: "bold" === cellStyle.fontWeight,
|
|
8
|
+
italic: "italic" === cellStyle.fontStyle,
|
|
9
|
+
color: getColor("link" === cellType ? cellStyle._linkColor : cellStyle.color),
|
|
10
|
+
underline: cellStyle.underline
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getFirstFontFromFontFamily(fontFamily) {
|
|
15
|
+
return fontFamily.split(",").map((font => font.trim()))[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getCellFill(cellStyle) {
|
|
19
|
+
return {
|
|
20
|
+
type: "pattern",
|
|
21
|
+
pattern: "solid",
|
|
22
|
+
fgColor: getColor(cellStyle.bgColor)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getCellBorder(cellStyle) {
|
|
27
|
+
var _a, _b, _c, _d, _e;
|
|
28
|
+
const {borderColor: borderColor, borderLineWidth: borderLineWidth, borderLineDash: borderLineDash, _strokeArrayWidth: _strokeArrayWidth, _strokeArrayColor: _strokeArrayColor} = cellStyle;
|
|
29
|
+
if (_strokeArrayColor || _strokeArrayWidth) {
|
|
30
|
+
const border = {};
|
|
31
|
+
return _strokeArrayColor && !_strokeArrayColor[0] || _strokeArrayWidth && !_strokeArrayWidth[0] || (border.top = {
|
|
32
|
+
style: getBorderStyle(null !== (_a = null == _strokeArrayWidth ? void 0 : _strokeArrayWidth[0]) && void 0 !== _a ? _a : borderLineWidth, borderLineDash),
|
|
33
|
+
color: getColor(null !== (_b = null == _strokeArrayColor ? void 0 : _strokeArrayColor[0]) && void 0 !== _b ? _b : borderColor)
|
|
34
|
+
}), _strokeArrayColor && !_strokeArrayColor[1] || _strokeArrayWidth && !_strokeArrayWidth[1] || (border.right = {
|
|
35
|
+
style: getBorderStyle(null !== (_c = null == _strokeArrayWidth ? void 0 : _strokeArrayWidth[1]) && void 0 !== _c ? _c : borderLineWidth, borderLineDash),
|
|
36
|
+
color: getColor(null == _strokeArrayColor ? void 0 : _strokeArrayColor[1])
|
|
37
|
+
}), _strokeArrayColor && !_strokeArrayColor[2] || _strokeArrayWidth && !_strokeArrayWidth[2] || (border.bottom = {
|
|
38
|
+
style: getBorderStyle(null !== (_d = null == _strokeArrayWidth ? void 0 : _strokeArrayWidth[2]) && void 0 !== _d ? _d : borderLineWidth, borderLineDash),
|
|
39
|
+
color: getColor(null == _strokeArrayColor ? void 0 : _strokeArrayColor[2])
|
|
40
|
+
}), _strokeArrayColor && !_strokeArrayColor[3] || _strokeArrayWidth && !_strokeArrayWidth[3] || (border.left = {
|
|
41
|
+
style: getBorderStyle(null !== (_e = null == _strokeArrayWidth ? void 0 : _strokeArrayWidth[3]) && void 0 !== _e ? _e : borderLineWidth, borderLineDash),
|
|
42
|
+
color: getColor(null == _strokeArrayColor ? void 0 : _strokeArrayColor[3])
|
|
43
|
+
}), border;
|
|
44
|
+
}
|
|
45
|
+
if (0 === borderLineWidth) return {};
|
|
46
|
+
const border = {
|
|
47
|
+
style: getBorderStyle(borderLineWidth, borderLineDash),
|
|
48
|
+
color: getColor(borderColor)
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
top: border,
|
|
52
|
+
left: border,
|
|
53
|
+
bottom: border,
|
|
54
|
+
right: border
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getBorderStyle(lineWidth, borderLineDash) {
|
|
59
|
+
return borderLineDash && borderLineDash.length ? lineWidth <= 2 ? "dashed" : "mediumDashed" : lineWidth <= .5 ? "hair" : lineWidth <= 1 ? "thin" : lineWidth <= 2 ? "medium" : "thick";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getCellAlignment(cellStyle) {
|
|
63
|
+
return {
|
|
64
|
+
horizontal: cellStyle.textAlign || "left",
|
|
65
|
+
vertical: cellStyle.textBaseline || "middle",
|
|
66
|
+
wrapText: cellStyle.autoWrapText || !1
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getColor(color) {
|
|
71
|
+
return {
|
|
72
|
+
argb: rgbaToHex(colorStringToRGB(color))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["excel/style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,UAAU,WAAW,CAAC,SAAoB,EAAE,QAA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YAAY,IAAI,QAAQ;QAC5C,QAAQ,EAAE,SAAS,CAAC,YAAY,IAAI,KAAK;KACnC,CAAC;AACX,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAE7B,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;KACzC,CAAC;AACJ,CAAC","file":"style.js","sourcesContent":["import type ExcelJS from 'exceljs';\nimport { colorStringToRGB, rgbaToHex } from '../util/color';\nimport type { CellStyle, CellType, LineDashsDef } from '../util/type';\n\nexport function getCellFont(cellStyle: CellStyle, cellType: CellType): Partial<ExcelJS.Font> {\n return {\n name: getFirstFontFromFontFamily(cellStyle.fontFamily as string) || 'Arial', // only one font family name\n size: cellStyle.fontSize || 10,\n bold: cellStyle.fontWeight === 'bold', // only bold or not\n italic: cellStyle.fontStyle === 'italic', // only italic or not\n color: getColor(cellType === 'link' ? (cellStyle._linkColor as string) : (cellStyle.color as string)),\n underline: cellStyle.underline\n };\n}\n\nfunction getFirstFontFromFontFamily(fontFamily: string) {\n const fonts = fontFamily.split(',').map(font => font.trim());\n return fonts[0];\n}\n\nexport function getCellFill(cellStyle: CellStyle): ExcelJS.Fill {\n return {\n type: 'pattern',\n pattern: 'solid',\n fgColor: getColor(cellStyle.bgColor as string)\n };\n}\n\nexport function getCellBorder(cellStyle: CellStyle): Partial<ExcelJS.Borders> {\n const { borderColor, borderLineWidth, borderLineDash, _strokeArrayWidth, _strokeArrayColor } = cellStyle;\n if (_strokeArrayColor || _strokeArrayWidth) {\n const border: Partial<ExcelJS.Borders> = {};\n if (!((_strokeArrayColor && !_strokeArrayColor[0]) || (_strokeArrayWidth && !_strokeArrayWidth[0]))) {\n border.top = {\n style: getBorderStyle((_strokeArrayWidth?.[0] as number) ?? (borderLineWidth as number), borderLineDash),\n color: getColor((_strokeArrayColor?.[0] as string) ?? (borderColor as string))\n };\n }\n if (!((_strokeArrayColor && !_strokeArrayColor[1]) || (_strokeArrayWidth && !_strokeArrayWidth[1]))) {\n border.right = {\n style: getBorderStyle((_strokeArrayWidth?.[1] as number) ?? (borderLineWidth as number), borderLineDash),\n color: getColor(_strokeArrayColor?.[1] as string)\n };\n }\n if (!((_strokeArrayColor && !_strokeArrayColor[2]) || (_strokeArrayWidth && !_strokeArrayWidth[2]))) {\n border.bottom = {\n style: getBorderStyle((_strokeArrayWidth?.[2] as number) ?? (borderLineWidth as number), borderLineDash),\n color: getColor(_strokeArrayColor?.[2] as string)\n };\n }\n if (!((_strokeArrayColor && !_strokeArrayColor[3]) || (_strokeArrayWidth && !_strokeArrayWidth[3]))) {\n border.left = {\n style: getBorderStyle((_strokeArrayWidth?.[3] as number) ?? (borderLineWidth as number), borderLineDash),\n color: getColor(_strokeArrayColor?.[3] as string)\n };\n }\n return border;\n }\n\n if (borderLineWidth === 0) {\n return {};\n }\n const border = {\n style: getBorderStyle(borderLineWidth as number, borderLineDash),\n color: getColor(borderColor as string)\n };\n return {\n top: border,\n left: border,\n bottom: border,\n right: border\n };\n}\n\nfunction getBorderStyle(lineWidth: number, borderLineDash: LineDashsDef): ExcelJS.BorderStyle {\n // hair:0.5\n // thin:1\n // medium:2.0\n // thick:3.0\n if (borderLineDash && borderLineDash.length) {\n if (lineWidth <= 2) {\n return 'dashed';\n }\n return 'mediumDashed';\n }\n if (lineWidth <= 0.5) {\n return 'hair';\n } else if (lineWidth <= 1) {\n return 'thin';\n } else if (lineWidth <= 2) {\n return 'medium';\n }\n return 'thick';\n}\n\nexport function getCellAlignment(cellStyle: CellStyle): Partial<ExcelJS.Alignment> {\n return {\n horizontal: cellStyle.textAlign || 'left',\n vertical: cellStyle.textBaseline || 'middle',\n wrapText: cellStyle.autoWrapText || false\n } as any;\n}\n\nfunction getColor(color: string) {\n // to do: support gradient color\n return {\n argb: rgbaToHex(colorStringToRGB(color))\n };\n}\n"]}
|
package/es/index.d.ts
ADDED
package/es/index.js
ADDED
package/es/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC","file":"index.js","sourcesContent":["export { exportVTableToCsv } from './csv';\nexport { downloadCsv } from './util/download';\n\nexport { exportVTableToExcel } from './excel';\nexport { downloadExcel } from './util/download';\n"]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
export declare function colorStringToRGB(colorString: string): number[];
|
|
2
|
+
export declare function rgbaToHex(rgbaArray: number[]): string;
|
|
3
|
+
export declare const DEFAULT_COLORS: {
|
|
4
|
+
aliceblue: number;
|
|
5
|
+
antiquewhite: number;
|
|
6
|
+
aqua: number;
|
|
7
|
+
aquamarine: number;
|
|
8
|
+
azure: number;
|
|
9
|
+
beige: number;
|
|
10
|
+
bisque: number;
|
|
11
|
+
black: number;
|
|
12
|
+
blanchedalmond: number;
|
|
13
|
+
blue: number;
|
|
14
|
+
blueviolet: number;
|
|
15
|
+
brown: number;
|
|
16
|
+
burlywood: number;
|
|
17
|
+
cadetblue: number;
|
|
18
|
+
chartreuse: number;
|
|
19
|
+
chocolate: number;
|
|
20
|
+
coral: number;
|
|
21
|
+
cornflowerblue: number;
|
|
22
|
+
cornsilk: number;
|
|
23
|
+
crimson: number;
|
|
24
|
+
cyan: number;
|
|
25
|
+
darkblue: number;
|
|
26
|
+
darkcyan: number;
|
|
27
|
+
darkgoldenrod: number;
|
|
28
|
+
darkgray: number;
|
|
29
|
+
darkgreen: number;
|
|
30
|
+
darkgrey: number;
|
|
31
|
+
darkkhaki: number;
|
|
32
|
+
darkmagenta: number;
|
|
33
|
+
darkolivegreen: number;
|
|
34
|
+
darkorange: number;
|
|
35
|
+
darkorchid: number;
|
|
36
|
+
darkred: number;
|
|
37
|
+
darksalmon: number;
|
|
38
|
+
darkseagreen: number;
|
|
39
|
+
darkslateblue: number;
|
|
40
|
+
darkslategray: number;
|
|
41
|
+
darkslategrey: number;
|
|
42
|
+
darkturquoise: number;
|
|
43
|
+
darkviolet: number;
|
|
44
|
+
deeppink: number;
|
|
45
|
+
deepskyblue: number;
|
|
46
|
+
dimgray: number;
|
|
47
|
+
dimgrey: number;
|
|
48
|
+
dodgerblue: number;
|
|
49
|
+
firebrick: number;
|
|
50
|
+
floralwhite: number;
|
|
51
|
+
forestgreen: number;
|
|
52
|
+
fuchsia: number;
|
|
53
|
+
gainsboro: number;
|
|
54
|
+
ghostwhite: number;
|
|
55
|
+
gold: number;
|
|
56
|
+
goldenrod: number;
|
|
57
|
+
gray: number;
|
|
58
|
+
green: number;
|
|
59
|
+
greenyellow: number;
|
|
60
|
+
grey: number;
|
|
61
|
+
honeydew: number;
|
|
62
|
+
hotpink: number;
|
|
63
|
+
indianred: number;
|
|
64
|
+
indigo: number;
|
|
65
|
+
ivory: number;
|
|
66
|
+
khaki: number;
|
|
67
|
+
lavender: number;
|
|
68
|
+
lavenderblush: number;
|
|
69
|
+
lawngreen: number;
|
|
70
|
+
lemonchiffon: number;
|
|
71
|
+
lightblue: number;
|
|
72
|
+
lightcoral: number;
|
|
73
|
+
lightcyan: number;
|
|
74
|
+
lightgoldenrodyellow: number;
|
|
75
|
+
lightgray: number;
|
|
76
|
+
lightgreen: number;
|
|
77
|
+
lightgrey: number;
|
|
78
|
+
lightpink: number;
|
|
79
|
+
lightsalmon: number;
|
|
80
|
+
lightseagreen: number;
|
|
81
|
+
lightskyblue: number;
|
|
82
|
+
lightslategray: number;
|
|
83
|
+
lightslategrey: number;
|
|
84
|
+
lightsteelblue: number;
|
|
85
|
+
lightyellow: number;
|
|
86
|
+
lime: number;
|
|
87
|
+
limegreen: number;
|
|
88
|
+
linen: number;
|
|
89
|
+
magenta: number;
|
|
90
|
+
maroon: number;
|
|
91
|
+
mediumaquamarine: number;
|
|
92
|
+
mediumblue: number;
|
|
93
|
+
mediumorchid: number;
|
|
94
|
+
mediumpurple: number;
|
|
95
|
+
mediumseagreen: number;
|
|
96
|
+
mediumslateblue: number;
|
|
97
|
+
mediumspringgreen: number;
|
|
98
|
+
mediumturquoise: number;
|
|
99
|
+
mediumvioletred: number;
|
|
100
|
+
midnightblue: number;
|
|
101
|
+
mintcream: number;
|
|
102
|
+
mistyrose: number;
|
|
103
|
+
moccasin: number;
|
|
104
|
+
navajowhite: number;
|
|
105
|
+
navy: number;
|
|
106
|
+
oldlace: number;
|
|
107
|
+
olive: number;
|
|
108
|
+
olivedrab: number;
|
|
109
|
+
orange: number;
|
|
110
|
+
orangered: number;
|
|
111
|
+
orchid: number;
|
|
112
|
+
palegoldenrod: number;
|
|
113
|
+
palegreen: number;
|
|
114
|
+
paleturquoise: number;
|
|
115
|
+
palevioletred: number;
|
|
116
|
+
papayawhip: number;
|
|
117
|
+
peachpuff: number;
|
|
118
|
+
peru: number;
|
|
119
|
+
pink: number;
|
|
120
|
+
plum: number;
|
|
121
|
+
powderblue: number;
|
|
122
|
+
purple: number;
|
|
123
|
+
rebeccapurple: number;
|
|
124
|
+
red: number;
|
|
125
|
+
rosybrown: number;
|
|
126
|
+
royalblue: number;
|
|
127
|
+
saddlebrown: number;
|
|
128
|
+
salmon: number;
|
|
129
|
+
sandybrown: number;
|
|
130
|
+
seagreen: number;
|
|
131
|
+
seashell: number;
|
|
132
|
+
sienna: number;
|
|
133
|
+
silver: number;
|
|
134
|
+
skyblue: number;
|
|
135
|
+
slateblue: number;
|
|
136
|
+
slategray: number;
|
|
137
|
+
slategrey: number;
|
|
138
|
+
snow: number;
|
|
139
|
+
springgreen: number;
|
|
140
|
+
steelblue: number;
|
|
141
|
+
tan: number;
|
|
142
|
+
teal: number;
|
|
143
|
+
thistle: number;
|
|
144
|
+
tomato: number;
|
|
145
|
+
turquoise: number;
|
|
146
|
+
violet: number;
|
|
147
|
+
wheat: number;
|
|
148
|
+
white: number;
|
|
149
|
+
whitesmoke: number;
|
|
150
|
+
yellow: number;
|
|
151
|
+
yellowgreen: number;
|
|
152
|
+
};
|
package/es/util/color.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
export function colorStringToRGB(colorString) {
|
|
2
|
+
if (colorString.startsWith("#")) {
|
|
3
|
+
let hex = colorString.substring(1);
|
|
4
|
+
3 === hex.length && (hex = hex.replace(/(.)/g, "$1$1"));
|
|
5
|
+
return [ parseInt(hex.substring(0, 2), 16), parseInt(hex.substring(2, 4), 16), parseInt(hex.substring(4, 6), 16) ];
|
|
6
|
+
}
|
|
7
|
+
if (colorString.startsWith("rgb(")) {
|
|
8
|
+
return colorString.substring(4, colorString.length - 1).split(",").map(Number);
|
|
9
|
+
}
|
|
10
|
+
if (colorString.startsWith("rgba(")) {
|
|
11
|
+
return colorString.substring(5, colorString.length - 1).split(",").map(Number);
|
|
12
|
+
}
|
|
13
|
+
if (DEFAULT_COLORS[colorString]) return rgb(DEFAULT_COLORS[colorString]);
|
|
14
|
+
if (DEFAULT_COLORS_OPACITY[colorString]) return rgba(DEFAULT_COLORS_OPACITY[colorString]);
|
|
15
|
+
throw new Error("Unsupported color format");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function rgbaToHex(rgbaArray) {
|
|
19
|
+
if (3 === rgbaArray.length && rgbaArray.push(1), 4 !== rgbaArray.length) throw new Error("Invalid RGBA array");
|
|
20
|
+
const [r, g, b, a] = rgbaArray.map(Math.round);
|
|
21
|
+
return `${Math.round(255 * a).toString(16).padStart(2, "0")}${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function rgb(value) {
|
|
25
|
+
return [ value >> 16, value >> 8 & 255, 255 & value, 1 ];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function rgba(value) {
|
|
29
|
+
return [ value >>> 24, value >>> 16 & 255, value >>> 8 & 255, 255 & value ];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DEFAULT_COLORS_OPACITY = {
|
|
33
|
+
transparent: 4294967040
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_COLORS = {
|
|
37
|
+
aliceblue: 15792383,
|
|
38
|
+
antiquewhite: 16444375,
|
|
39
|
+
aqua: 65535,
|
|
40
|
+
aquamarine: 8388564,
|
|
41
|
+
azure: 15794175,
|
|
42
|
+
beige: 16119260,
|
|
43
|
+
bisque: 16770244,
|
|
44
|
+
black: 0,
|
|
45
|
+
blanchedalmond: 16772045,
|
|
46
|
+
blue: 255,
|
|
47
|
+
blueviolet: 9055202,
|
|
48
|
+
brown: 10824234,
|
|
49
|
+
burlywood: 14596231,
|
|
50
|
+
cadetblue: 6266528,
|
|
51
|
+
chartreuse: 8388352,
|
|
52
|
+
chocolate: 13789470,
|
|
53
|
+
coral: 16744272,
|
|
54
|
+
cornflowerblue: 6591981,
|
|
55
|
+
cornsilk: 16775388,
|
|
56
|
+
crimson: 14423100,
|
|
57
|
+
cyan: 65535,
|
|
58
|
+
darkblue: 139,
|
|
59
|
+
darkcyan: 35723,
|
|
60
|
+
darkgoldenrod: 12092939,
|
|
61
|
+
darkgray: 11119017,
|
|
62
|
+
darkgreen: 25600,
|
|
63
|
+
darkgrey: 11119017,
|
|
64
|
+
darkkhaki: 12433259,
|
|
65
|
+
darkmagenta: 9109643,
|
|
66
|
+
darkolivegreen: 5597999,
|
|
67
|
+
darkorange: 16747520,
|
|
68
|
+
darkorchid: 10040012,
|
|
69
|
+
darkred: 9109504,
|
|
70
|
+
darksalmon: 15308410,
|
|
71
|
+
darkseagreen: 9419919,
|
|
72
|
+
darkslateblue: 4734347,
|
|
73
|
+
darkslategray: 3100495,
|
|
74
|
+
darkslategrey: 3100495,
|
|
75
|
+
darkturquoise: 52945,
|
|
76
|
+
darkviolet: 9699539,
|
|
77
|
+
deeppink: 16716947,
|
|
78
|
+
deepskyblue: 49151,
|
|
79
|
+
dimgray: 6908265,
|
|
80
|
+
dimgrey: 6908265,
|
|
81
|
+
dodgerblue: 2003199,
|
|
82
|
+
firebrick: 11674146,
|
|
83
|
+
floralwhite: 16775920,
|
|
84
|
+
forestgreen: 2263842,
|
|
85
|
+
fuchsia: 16711935,
|
|
86
|
+
gainsboro: 14474460,
|
|
87
|
+
ghostwhite: 16316671,
|
|
88
|
+
gold: 16766720,
|
|
89
|
+
goldenrod: 14329120,
|
|
90
|
+
gray: 8421504,
|
|
91
|
+
green: 32768,
|
|
92
|
+
greenyellow: 11403055,
|
|
93
|
+
grey: 8421504,
|
|
94
|
+
honeydew: 15794160,
|
|
95
|
+
hotpink: 16738740,
|
|
96
|
+
indianred: 13458524,
|
|
97
|
+
indigo: 4915330,
|
|
98
|
+
ivory: 16777200,
|
|
99
|
+
khaki: 15787660,
|
|
100
|
+
lavender: 15132410,
|
|
101
|
+
lavenderblush: 16773365,
|
|
102
|
+
lawngreen: 8190976,
|
|
103
|
+
lemonchiffon: 16775885,
|
|
104
|
+
lightblue: 11393254,
|
|
105
|
+
lightcoral: 15761536,
|
|
106
|
+
lightcyan: 14745599,
|
|
107
|
+
lightgoldenrodyellow: 16448210,
|
|
108
|
+
lightgray: 13882323,
|
|
109
|
+
lightgreen: 9498256,
|
|
110
|
+
lightgrey: 13882323,
|
|
111
|
+
lightpink: 16758465,
|
|
112
|
+
lightsalmon: 16752762,
|
|
113
|
+
lightseagreen: 2142890,
|
|
114
|
+
lightskyblue: 8900346,
|
|
115
|
+
lightslategray: 7833753,
|
|
116
|
+
lightslategrey: 7833753,
|
|
117
|
+
lightsteelblue: 11584734,
|
|
118
|
+
lightyellow: 16777184,
|
|
119
|
+
lime: 65280,
|
|
120
|
+
limegreen: 3329330,
|
|
121
|
+
linen: 16445670,
|
|
122
|
+
magenta: 16711935,
|
|
123
|
+
maroon: 8388608,
|
|
124
|
+
mediumaquamarine: 6737322,
|
|
125
|
+
mediumblue: 205,
|
|
126
|
+
mediumorchid: 12211667,
|
|
127
|
+
mediumpurple: 9662683,
|
|
128
|
+
mediumseagreen: 3978097,
|
|
129
|
+
mediumslateblue: 8087790,
|
|
130
|
+
mediumspringgreen: 64154,
|
|
131
|
+
mediumturquoise: 4772300,
|
|
132
|
+
mediumvioletred: 13047173,
|
|
133
|
+
midnightblue: 1644912,
|
|
134
|
+
mintcream: 16121850,
|
|
135
|
+
mistyrose: 16770273,
|
|
136
|
+
moccasin: 16770229,
|
|
137
|
+
navajowhite: 16768685,
|
|
138
|
+
navy: 128,
|
|
139
|
+
oldlace: 16643558,
|
|
140
|
+
olive: 8421376,
|
|
141
|
+
olivedrab: 7048739,
|
|
142
|
+
orange: 16753920,
|
|
143
|
+
orangered: 16729344,
|
|
144
|
+
orchid: 14315734,
|
|
145
|
+
palegoldenrod: 15657130,
|
|
146
|
+
palegreen: 10025880,
|
|
147
|
+
paleturquoise: 11529966,
|
|
148
|
+
palevioletred: 14381203,
|
|
149
|
+
papayawhip: 16773077,
|
|
150
|
+
peachpuff: 16767673,
|
|
151
|
+
peru: 13468991,
|
|
152
|
+
pink: 16761035,
|
|
153
|
+
plum: 14524637,
|
|
154
|
+
powderblue: 11591910,
|
|
155
|
+
purple: 8388736,
|
|
156
|
+
rebeccapurple: 6697881,
|
|
157
|
+
red: 16711680,
|
|
158
|
+
rosybrown: 12357519,
|
|
159
|
+
royalblue: 4286945,
|
|
160
|
+
saddlebrown: 9127187,
|
|
161
|
+
salmon: 16416882,
|
|
162
|
+
sandybrown: 16032864,
|
|
163
|
+
seagreen: 3050327,
|
|
164
|
+
seashell: 16774638,
|
|
165
|
+
sienna: 10506797,
|
|
166
|
+
silver: 12632256,
|
|
167
|
+
skyblue: 8900331,
|
|
168
|
+
slateblue: 6970061,
|
|
169
|
+
slategray: 7372944,
|
|
170
|
+
slategrey: 7372944,
|
|
171
|
+
snow: 16775930,
|
|
172
|
+
springgreen: 65407,
|
|
173
|
+
steelblue: 4620980,
|
|
174
|
+
tan: 13808780,
|
|
175
|
+
teal: 32896,
|
|
176
|
+
thistle: 14204888,
|
|
177
|
+
tomato: 16737095,
|
|
178
|
+
turquoise: 4251856,
|
|
179
|
+
violet: 15631086,
|
|
180
|
+
wheat: 16113331,
|
|
181
|
+
white: 16777215,
|
|
182
|
+
whitesmoke: 16119285,
|
|
183
|
+
yellow: 16776960,
|
|
184
|
+
yellowgreen: 10145074
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["util/color.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAE/B,IAAI,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAGnC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;YACpB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACnC;QAED,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAClB;SAAM,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAEzC,MAAM,MAAM,GAAG,WAAW;aACvB,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;aACpC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG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AE,QAAQ;IACvB,GAAG,EAAE,QAAQ;IACb,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,WAAW,EAAE,QAAQ;IACrB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;IACnB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,QAAQ;IACrB,SAAS,EAAE,QAAQ;IACnB,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,QAAQ;IACf,UAAU,EAAE,QAAQ;IACpB,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,QAAQ;CACtB,CAAC","file":"color.js","sourcesContent":["export function colorStringToRGB(colorString: string) {\n if (colorString.startsWith('#')) {\n // 处理十六进制颜色值(例如:#RRGGBB 或 #RGB)\n let hex = colorString.substring(1);\n\n // 处理缩写的十六进制颜色值(例如:#RGB)\n if (hex.length === 3) {\n hex = hex.replace(/(.)/g, '$1$1');\n }\n\n const r = parseInt(hex.substring(0, 2), 16);\n const g = parseInt(hex.substring(2, 4), 16);\n const b = parseInt(hex.substring(4, 6), 16);\n return [r, g, b];\n } else if (colorString.startsWith('rgb(')) {\n // 处理RGB颜色值(例如:rgb(R, G, B))\n const values = colorString\n .substring(4, colorString.length - 1)\n .split(',')\n .map(Number);\n return values;\n } else if (colorString.startsWith('rgba(')) {\n // 处理RGBA颜色值(例如:rgba(R, G, B, A))\n const values = colorString\n .substring(5, colorString.length - 1)\n .split(',')\n .map(Number);\n return values;\n } else if (DEFAULT_COLORS[colorString]) {\n return rgb(DEFAULT_COLORS[colorString]);\n } else if (DEFAULT_COLORS_OPACITY[colorString]) {\n return rgba(DEFAULT_COLORS_OPACITY[colorString]);\n }\n\n throw new Error('Unsupported color format');\n}\n\nexport function rgbaToHex(rgbaArray: number[]) {\n if (rgbaArray.length === 3) {\n rgbaArray.push(1);\n }\n\n if (rgbaArray.length !== 4) {\n throw new Error('Invalid RGBA array');\n }\n\n const [r, g, b, a] = rgbaArray.map(Math.round);\n const alphaHex = Math.round(a * 255)\n .toString(16)\n .padStart(2, '0');\n\n return `${alphaHex}${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b\n .toString(16)\n .padStart(2, '0')}`;\n}\n\nfunction rgb(value: number) {\n return [(value as number) >> 16, ((value as number) >> 8) & 0xff, (value as number) & 0xff, 1];\n}\n\nfunction rgba(value: number) {\n return [\n (value as number) >>> 24,\n ((value as number) >>> 16) & 0xff,\n ((value as number) >>> 8) & 0xff,\n (value as number) & 0xff\n ];\n}\n\nconst DEFAULT_COLORS_OPACITY = {\n transparent: 0xffffff00\n};\n\nexport const DEFAULT_COLORS = {\n aliceblue: 0xf0f8ff,\n antiquewhite: 0xfaebd7,\n aqua: 0x00ffff,\n aquamarine: 0x7fffd4,\n azure: 0xf0ffff,\n beige: 0xf5f5dc,\n bisque: 0xffe4c4,\n black: 0x000000,\n blanchedalmond: 0xffebcd,\n blue: 0x0000ff,\n blueviolet: 0x8a2be2,\n brown: 0xa52a2a,\n burlywood: 0xdeb887,\n cadetblue: 0x5f9ea0,\n chartreuse: 0x7fff00,\n chocolate: 0xd2691e,\n coral: 0xff7f50,\n cornflowerblue: 0x6495ed,\n cornsilk: 0xfff8dc,\n crimson: 0xdc143c,\n cyan: 0x00ffff,\n darkblue: 0x00008b,\n darkcyan: 0x008b8b,\n darkgoldenrod: 0xb8860b,\n darkgray: 0xa9a9a9,\n darkgreen: 0x006400,\n darkgrey: 0xa9a9a9,\n darkkhaki: 0xbdb76b,\n darkmagenta: 0x8b008b,\n darkolivegreen: 0x556b2f,\n darkorange: 0xff8c00,\n darkorchid: 0x9932cc,\n darkred: 0x8b0000,\n darksalmon: 0xe9967a,\n darkseagreen: 0x8fbc8f,\n darkslateblue: 0x483d8b,\n darkslategray: 0x2f4f4f,\n darkslategrey: 0x2f4f4f,\n darkturquoise: 0x00ced1,\n darkviolet: 0x9400d3,\n deeppink: 0xff1493,\n deepskyblue: 0x00bfff,\n dimgray: 0x696969,\n dimgrey: 0x696969,\n dodgerblue: 0x1e90ff,\n firebrick: 0xb22222,\n floralwhite: 0xfffaf0,\n forestgreen: 0x228b22,\n fuchsia: 0xff00ff,\n gainsboro: 0xdcdcdc,\n ghostwhite: 0xf8f8ff,\n gold: 0xffd700,\n goldenrod: 0xdaa520,\n gray: 0x808080,\n green: 0x008000,\n greenyellow: 0xadff2f,\n grey: 0x808080,\n honeydew: 0xf0fff0,\n hotpink: 0xff69b4,\n indianred: 0xcd5c5c,\n indigo: 0x4b0082,\n ivory: 0xfffff0,\n khaki: 0xf0e68c,\n lavender: 0xe6e6fa,\n lavenderblush: 0xfff0f5,\n lawngreen: 0x7cfc00,\n lemonchiffon: 0xfffacd,\n lightblue: 0xadd8e6,\n lightcoral: 0xf08080,\n lightcyan: 0xe0ffff,\n lightgoldenrodyellow: 0xfafad2,\n lightgray: 0xd3d3d3,\n lightgreen: 0x90ee90,\n lightgrey: 0xd3d3d3,\n lightpink: 0xffb6c1,\n lightsalmon: 0xffa07a,\n lightseagreen: 0x20b2aa,\n lightskyblue: 0x87cefa,\n lightslategray: 0x778899,\n lightslategrey: 0x778899,\n lightsteelblue: 0xb0c4de,\n lightyellow: 0xffffe0,\n lime: 0x00ff00,\n limegreen: 0x32cd32,\n linen: 0xfaf0e6,\n magenta: 0xff00ff,\n maroon: 0x800000,\n mediumaquamarine: 0x66cdaa,\n mediumblue: 0x0000cd,\n mediumorchid: 0xba55d3,\n mediumpurple: 0x9370db,\n mediumseagreen: 0x3cb371,\n mediumslateblue: 0x7b68ee,\n mediumspringgreen: 0x00fa9a,\n mediumturquoise: 0x48d1cc,\n mediumvioletred: 0xc71585,\n midnightblue: 0x191970,\n mintcream: 0xf5fffa,\n mistyrose: 0xffe4e1,\n moccasin: 0xffe4b5,\n navajowhite: 0xffdead,\n navy: 0x000080,\n oldlace: 0xfdf5e6,\n olive: 0x808000,\n olivedrab: 0x6b8e23,\n orange: 0xffa500,\n orangered: 0xff4500,\n orchid: 0xda70d6,\n palegoldenrod: 0xeee8aa,\n palegreen: 0x98fb98,\n paleturquoise: 0xafeeee,\n palevioletred: 0xdb7093,\n papayawhip: 0xffefd5,\n peachpuff: 0xffdab9,\n peru: 0xcd853f,\n pink: 0xffc0cb,\n plum: 0xdda0dd,\n powderblue: 0xb0e0e6,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n red: 0xff0000,\n rosybrown: 0xbc8f8f,\n royalblue: 0x4169e1,\n saddlebrown: 0x8b4513,\n salmon: 0xfa8072,\n sandybrown: 0xf4a460,\n seagreen: 0x2e8b57,\n seashell: 0xfff5ee,\n sienna: 0xa0522d,\n silver: 0xc0c0c0,\n skyblue: 0x87ceeb,\n slateblue: 0x6a5acd,\n slategray: 0x708090,\n slategrey: 0x708090,\n snow: 0xfffafa,\n springgreen: 0x00ff7f,\n steelblue: 0x4682b4,\n tan: 0xd2b48c,\n teal: 0x008080,\n thistle: 0xd8bfd8,\n tomato: 0xff6347,\n turquoise: 0x40e0d0,\n violet: 0xee82ee,\n wheat: 0xf5deb3,\n white: 0xffffff,\n whitesmoke: 0xf5f5f5,\n yellow: 0xffff00,\n yellowgreen: 0x9acd32\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { saveAs } from "file-saver";
|
|
2
|
+
|
|
3
|
+
export function downloadCsv(str, name) {
|
|
4
|
+
const blob = new Blob([ `\ufeff${str}` ], {
|
|
5
|
+
type: "text/csv;charset=utf-8"
|
|
6
|
+
});
|
|
7
|
+
saveAs(blob, `${name}.csv`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function downloadExcel(arrayBuffer, name) {
|
|
11
|
+
const blob = new Blob([ arrayBuffer ], {
|
|
12
|
+
type: "application/octet-stream"
|
|
13
|
+
});
|
|
14
|
+
saveAs(blob, `${name}.xlsx`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function workSheetStr2ArrayBuffer(workSheetStr) {
|
|
18
|
+
const buffer = new ArrayBuffer(workSheetStr.length), arrayBuffer = new Uint8Array(buffer);
|
|
19
|
+
for (let i = 0; i < workSheetStr.length; ++i) arrayBuffer[i] = 255 & workSheetStr.charCodeAt(i);
|
|
20
|
+
return buffer;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["util/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,IAAY;IACnD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,EAAE;QACtC,IAAI,EAAE,wBAAwB;KAC/B,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,IAAY;IAElE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE;QACnC,IAAI,EAAE,0BAA0B;KACjC,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,wBAAwB,CAAC,YAAoB;IACpD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAE3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QAC5C,WAAW,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;KACpD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"download.js","sourcesContent":["import { saveAs } from 'file-saver';\n\nexport function downloadCsv(str: string, name: string) {\n const blob = new Blob([`\\ufeff${str}`], {\n type: 'text/csv;charset=utf-8'\n });\n\n saveAs(blob, `${name}.csv`);\n}\n\nexport function downloadExcel(arrayBuffer: ArrayBuffer, name: string) {\n // const arrayBuffer = workSheetStr2ArrayBuffer(workSheetStr);\n const blob = new Blob([arrayBuffer], {\n type: 'application/octet-stream'\n });\n\n saveAs(blob, `${name}.xlsx`);\n}\n\nfunction workSheetStr2ArrayBuffer(workSheetStr: string) {\n const buffer = new ArrayBuffer(workSheetStr.length);\n const arrayBuffer = new Uint8Array(buffer);\n\n for (let i = 0; i < workSheetStr.length; ++i) {\n arrayBuffer[i] = workSheetStr.charCodeAt(i) & 0xff;\n }\n\n return buffer;\n}\n"]}
|