@sinm/kai 1.12.8 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RELEASE_NOTES.md +160 -0
- package/dist-cli/kai-cli.js +144111 -149439
- package/dist-electron/renderer/assets/LICENSE-CRnx3_A4. +122 -0
- package/dist-electron/renderer/assets/NOTICE-VFih955g. +229 -0
- package/dist-electron/renderer/assets/README-BLVCeaHS.md +498 -0
- package/dist-electron/renderer/assets/{_baseUniq-D1YNIFcF.js → _baseUniq-IzQS5rpq.js} +1 -1
- package/dist-electron/renderer/assets/_commonjsHelpers-CCIqAdii.js +38 -0
- package/dist-electron/renderer/assets/{arc-Bm6fPazK.js → arc-0FUHmmYf.js} +23 -23
- package/dist-electron/renderer/assets/{architectureDiagram-Q4EWVU46-Cj7Ijbdx.js → architectureDiagram-Q4EWVU46-lERxZBZ3.js} +8 -5
- package/dist-electron/renderer/assets/assets-FW_AxgRe.js +172 -0
- package/dist-electron/renderer/assets/billboard-BSTFvQMm.js +24870 -0
- package/dist-electron/renderer/assets/{blockDiagram-DXYQGD6D-h_hfApKW.js → blockDiagram-DXYQGD6D-50KC-L6H.js} +10 -7
- package/dist-electron/renderer/assets/{c4Diagram-AHTNJAMY-Bc9WKYcR.js → c4Diagram-AHTNJAMY-CGUZg_Lb.js} +5 -2
- package/dist-electron/renderer/assets/{channel-rz5HhnUN.js → channel-BhiLrT8b.js} +1 -1
- package/dist-electron/renderer/assets/{chunk-4BX2VUAB-CSIA4CEs.js → chunk-4BX2VUAB-Dsk-FZLe.js} +1 -1
- package/dist-electron/renderer/assets/{chunk-4TB4RGXK-wmbLtxbh.js → chunk-4TB4RGXK-Cg08E4uS.js} +6 -5
- package/dist-electron/renderer/assets/{chunk-55IACEB6-CyTu0W4e.js → chunk-55IACEB6-CaY4ZtxG.js} +2 -1
- package/dist-electron/renderer/assets/{chunk-EDXVE4YY-BkuoJ9Rg.js → chunk-EDXVE4YY-D-vr_LVm.js} +1 -1
- package/dist-electron/renderer/assets/{chunk-FMBD7UC4-CXLzwK-p.js → chunk-FMBD7UC4-CgfLwyI0.js} +1 -1
- package/dist-electron/renderer/assets/{chunk-OYMX7WX6-89Cfdes5.js → chunk-OYMX7WX6-B2UNIH07.js} +3 -3
- package/dist-electron/renderer/assets/{chunk-QZHKN3VN-BP7yAqUC.js → chunk-QZHKN3VN-8pnIXhD9.js} +1 -1
- package/dist-electron/renderer/assets/{chunk-YZCP3GAM-DlXeY35D.js → chunk-YZCP3GAM-1OCqrydc.js} +2 -1
- package/dist-electron/renderer/assets/{classDiagram-v2-HSJHXN6E-BhvGIqCe.js → classDiagram-6PBFFD2Q-D6s4rntl.js} +9 -6
- package/dist-electron/renderer/assets/{classDiagram-6PBFFD2Q-BhvGIqCe.js → classDiagram-v2-HSJHXN6E-D6s4rntl.js} +9 -6
- package/dist-electron/renderer/assets/{clone-B0IYq2dM.js → clone-ONN7myYv.js} +1 -1
- package/dist-electron/renderer/assets/{cose-bilkent-S5V4N54A-CXkTOxYF.js → cose-bilkent-S5V4N54A-B4V7g-PN.js} +4 -1
- package/dist-electron/renderer/assets/{dagre-KV5264BT-CDhOvCqP.js → dagre-KV5264BT-BxdReG41.js} +9 -6
- package/dist-electron/renderer/assets/{defaultLocale-B2RvLBDe.js → defaultLocale-DCJjMHFj.js} +6 -3
- package/dist-electron/renderer/assets/{diagram-5BDNPKRD-BVi_bgHy.js → diagram-5BDNPKRD-BXmSoRSx.js} +9 -6
- package/dist-electron/renderer/assets/{diagram-G4DWMVQ6-rSfxvI7w.js → diagram-G4DWMVQ6-Cal8PS1h.js} +12 -335
- package/dist-electron/renderer/assets/{diagram-MMDJMWI5-CQyMbB4C.js → diagram-MMDJMWI5-BxRETzVk.js} +8 -5
- package/dist-electron/renderer/assets/{diagram-TYMM5635-CTtX0t8J.js → diagram-TYMM5635-cUUOAiip.js} +8 -5
- package/dist-electron/renderer/assets/docx-preview-D79uFTI3.js +6286 -0
- package/dist-electron/renderer/assets/{erDiagram-SMLLAGMA-OPI6814M.js → erDiagram-SMLLAGMA-DOKXfo5a.js} +7 -4
- package/dist-electron/renderer/assets/export-BB2y0kyx.js +17 -0
- package/dist-electron/renderer/assets/{flowDiagram-DWJPFMVM-zQ37QQ6j.js → flowDiagram-DWJPFMVM-DMeT6oIp.js} +9 -6
- package/dist-electron/renderer/assets/frame-cache-FJQQ95VR.mjs +731 -0
- package/dist-electron/renderer/assets/{ganttDiagram-T4ZO3ILL-SabGKVNy.js → ganttDiagram-T4ZO3ILL-BP29Llrv.js} +17 -1019
- package/dist-electron/renderer/assets/{gitGraphDiagram-UUTBAWPF-Cf76EqK-.js → gitGraphDiagram-UUTBAWPF-C7d6IjfR.js} +9 -6
- package/dist-electron/renderer/assets/{graph-XEjbXiT4.js → graph-PHPHiJJP.js} +2 -2
- package/dist-electron/renderer/assets/image-BPoy6OwY.js +256 -0
- package/dist-electron/renderer/assets/index-B3YxBY6K.js +2203 -0
- package/dist-electron/renderer/assets/index-B8e4CGoa.js +36 -0
- package/dist-electron/renderer/assets/index-BEeZTDSC.js +23 -0
- package/dist-electron/renderer/assets/index-BM3qXY96.js +22 -0
- package/dist-electron/renderer/assets/index-BW_kBMIl.js +336 -0
- package/dist-electron/renderer/assets/index-Bmnq51hA.js +22 -0
- package/dist-electron/renderer/assets/{index-CvNq2hZf.js → index-C1vtUg_s.js} +38843 -33243
- package/dist-electron/renderer/assets/{index-v7BYTcWh.css → index-CwhZMs_P.css} +11127 -8033
- package/dist-electron/renderer/assets/index-ZtFtJCDp.js +35 -0
- package/dist-electron/renderer/assets/index-t7Uht1Bm.js +823 -0
- package/dist-electron/renderer/assets/index.d-BlbVvgf5.ts +189 -0
- package/dist-electron/renderer/assets/index.es-eU8DIFZe.js +8641 -0
- package/dist-electron/renderer/assets/{infoDiagram-42DDH7IO-BwaUrrr6.js → infoDiagram-42DDH7IO-DX82xpv-.js} +7 -4
- package/dist-electron/renderer/assets/{ishikawaDiagram-UXIWVN3A-9ug8d1vP.js → ishikawaDiagram-UXIWVN3A-AgnLKWJ1.js} +4 -1
- package/dist-electron/renderer/assets/{journeyDiagram-VCZTEJTY-TD9rr0Yb.js → journeyDiagram-VCZTEJTY-DBoO0fyn.js} +11 -8
- package/dist-electron/renderer/assets/jszip.min-Ca5jExEq.js +2320 -0
- package/dist-electron/renderer/assets/{kanban-definition-6JOO6SKY-DbYJfuxU.js → kanban-definition-6JOO6SKY-Da9qGyC6.js} +5 -2
- package/dist-electron/renderer/assets/{layout-BhL6ZYG7.js → layout-CWvzTDIs.js} +4 -4
- package/dist-electron/renderer/assets/{linear-BgmkulGp.js → linear-iB_ZihXg.js} +7 -12
- package/dist-electron/renderer/assets/{min-Ux8OpRLr.js → min-Cy3zXhhU.js} +2 -2
- package/dist-electron/renderer/assets/{mindmap-definition-QFDTVHPH-hafJ1k0V.js → mindmap-definition-QFDTVHPH-DcbS1qdR.js} +6 -3
- package/dist-electron/renderer/assets/office-preview-J3VSY6Z8.js +234 -0
- package/dist-electron/renderer/assets/office-preview-dcvGW2k2.css +31 -0
- package/dist-electron/renderer/assets/options-SsS0Y_ki.js +14 -0
- package/dist-electron/renderer/assets/parser-DYEwxOAz.js +36438 -0
- package/dist-electron/renderer/assets/pdf-Cg5OXHy4.js +45988 -0
- package/dist-electron/renderer/assets/pdf.worker-BRVikHnI.js +63582 -0
- package/dist-electron/renderer/assets/pdfIdentityFontRepair-D1LMksnQ.js +19540 -0
- package/dist-electron/renderer/assets/pie-n6faJLD3.js +57 -0
- package/dist-electron/renderer/assets/{pieDiagram-DEJITSTG-Ds-EF9ih.js → pieDiagram-DEJITSTG-DoHeHbCw.js} +13 -62
- package/dist-electron/renderer/assets/ppt-font-cjk-DxgKpThH.otf +0 -0
- package/dist-electron/renderer/assets/ppt-kMUvGcTn.js +548 -0
- package/dist-electron/renderer/assets/ppt-native-FimRYTDZ.wasm +0 -0
- package/dist-electron/renderer/assets/pptx-Bc4I5s0W.js +1561 -0
- package/dist-electron/renderer/assets/pptx.worker-BB0HgzXA.js +9243 -0
- package/dist-electron/renderer/assets/pptx.worker-uagKfrvK.js +31 -0
- package/dist-electron/renderer/assets/preload-helper-DMSNAyVy.js +103 -0
- package/dist-electron/renderer/assets/printLayout-CIlG68Nj.js +75 -0
- package/dist-electron/renderer/assets/{quadrantDiagram-34T5L4WZ-w34cZgIo.js → quadrantDiagram-34T5L4WZ-B4eVOkpY.js} +7 -3
- package/dist-electron/renderer/assets/{requirementDiagram-MS252O5E-scA2ZKRK.js → requirementDiagram-MS252O5E-_X6prUEb.js} +6 -3
- package/dist-electron/renderer/assets/{sankeyDiagram-XADWPNL6-BAen7KsY.js → sankeyDiagram-XADWPNL6-Cwh5jd49.js} +4 -1
- package/dist-electron/renderer/assets/{sequenceDiagram-FGHM5R23-CTs2YiIq.js → sequenceDiagram-FGHM5R23-DuyO7VVc.js} +6 -3
- package/dist-electron/renderer/assets/spreadsheet-DGapha57.js +3835 -0
- package/dist-electron/renderer/assets/{stateDiagram-FHFEXIEX-Bh0sWvlc.js → stateDiagram-FHFEXIEX-CakMKYdt.js} +12 -9
- package/dist-electron/renderer/assets/{stateDiagram-v2-QKLJ7IA2-B2Hm2wBr.js → stateDiagram-v2-QKLJ7IA2-DzNdAqgI.js} +7 -4
- package/dist-electron/renderer/assets/time-Bll8bhEl.js +1053 -0
- package/dist-electron/renderer/assets/{timeline-definition-GMOUNBTQ-CbeMRmLK.js → timeline-definition-GMOUNBTQ-CZVCXf6-.js} +9 -6
- package/dist-electron/renderer/assets/transform-xbmqYlhd.js +3127 -0
- package/dist-electron/renderer/assets/{vennDiagram-DHZGUBPP-DJhwj_mO.js → vennDiagram-DHZGUBPP-C6K4wHQL.js} +4 -1
- package/dist-electron/renderer/assets/{wardley-RL74JXVD-DBLZJp8R.js → wardley-RL74JXVD-C-ecli15.js} +5 -3
- package/dist-electron/renderer/assets/{wardleyDiagram-NUSXRM2D-Cu85Zz7H.js → wardleyDiagram-NUSXRM2D-BQXEBLy4.js} +8 -5
- package/dist-electron/renderer/assets/wordDoc-sBzzGoFh.js +6553 -0
- package/dist-electron/renderer/assets/wordDocx-vtTbrlFg.js +567 -0
- package/dist-electron/renderer/assets/worker-C5LZNsKY.mjs +1650 -0
- package/dist-electron/renderer/assets/{xychartDiagram-5P7HB3ND-DF6f5m7g.js → xychartDiagram-5P7HB3ND-DwZWCBJI.js} +9 -5
- package/dist-electron/renderer/assets/zoom-jYhmkcQX.js +17 -0
- package/dist-electron/renderer/index.html +5 -2
- package/dist-electron/renderer/office-preview.html +19 -0
- package/package.json +15 -15
- package/dist-electron/renderer/assets/_baseUniq-D1YNIFcF.js.gz +0 -0
- package/dist-electron/renderer/assets/arc-Bm6fPazK.js.gz +0 -0
- package/dist-electron/renderer/assets/architectureDiagram-Q4EWVU46-Cj7Ijbdx.js.gz +0 -0
- package/dist-electron/renderer/assets/blockDiagram-DXYQGD6D-h_hfApKW.js.gz +0 -0
- package/dist-electron/renderer/assets/c4Diagram-AHTNJAMY-Bc9WKYcR.js.gz +0 -0
- package/dist-electron/renderer/assets/chunk-4TB4RGXK-wmbLtxbh.js.gz +0 -0
- package/dist-electron/renderer/assets/chunk-EDXVE4YY-BkuoJ9Rg.js.gz +0 -0
- package/dist-electron/renderer/assets/chunk-OYMX7WX6-89Cfdes5.js.gz +0 -0
- package/dist-electron/renderer/assets/chunk-YZCP3GAM-DlXeY35D.js.gz +0 -0
- package/dist-electron/renderer/assets/cose-bilkent-S5V4N54A-CXkTOxYF.js.gz +0 -0
- package/dist-electron/renderer/assets/cytoscape.esm-D6E6cAed.js.gz +0 -0
- package/dist-electron/renderer/assets/dagre-KV5264BT-CDhOvCqP.js.gz +0 -0
- package/dist-electron/renderer/assets/defaultLocale-B2RvLBDe.js.gz +0 -0
- package/dist-electron/renderer/assets/diagram-5BDNPKRD-BVi_bgHy.js.gz +0 -0
- package/dist-electron/renderer/assets/diagram-G4DWMVQ6-rSfxvI7w.js.gz +0 -0
- package/dist-electron/renderer/assets/diagram-MMDJMWI5-CQyMbB4C.js.gz +0 -0
- package/dist-electron/renderer/assets/diagram-TYMM5635-CTtX0t8J.js.gz +0 -0
- package/dist-electron/renderer/assets/erDiagram-SMLLAGMA-OPI6814M.js.gz +0 -0
- package/dist-electron/renderer/assets/flowDiagram-DWJPFMVM-zQ37QQ6j.js.gz +0 -0
- package/dist-electron/renderer/assets/ganttDiagram-T4ZO3ILL-SabGKVNy.js.gz +0 -0
- package/dist-electron/renderer/assets/gitGraphDiagram-UUTBAWPF-Cf76EqK-.js.gz +0 -0
- package/dist-electron/renderer/assets/graph-XEjbXiT4.js.gz +0 -0
- package/dist-electron/renderer/assets/index-CvNq2hZf.js.gz +0 -0
- package/dist-electron/renderer/assets/index-v7BYTcWh.css.gz +0 -0
- package/dist-electron/renderer/assets/ishikawaDiagram-UXIWVN3A-9ug8d1vP.js.gz +0 -0
- package/dist-electron/renderer/assets/journeyDiagram-VCZTEJTY-TD9rr0Yb.js.gz +0 -0
- package/dist-electron/renderer/assets/kanban-definition-6JOO6SKY-DbYJfuxU.js.gz +0 -0
- package/dist-electron/renderer/assets/katex-CYis69t2.js.gz +0 -0
- package/dist-electron/renderer/assets/layout-BhL6ZYG7.js.gz +0 -0
- package/dist-electron/renderer/assets/linear-BgmkulGp.js.gz +0 -0
- package/dist-electron/renderer/assets/min-Ux8OpRLr.js.gz +0 -0
- package/dist-electron/renderer/assets/mindmap-definition-QFDTVHPH-hafJ1k0V.js.gz +0 -0
- package/dist-electron/renderer/assets/ordinal-CxptdPJm.js.gz +0 -0
- package/dist-electron/renderer/assets/pieDiagram-DEJITSTG-Ds-EF9ih.js.gz +0 -0
- package/dist-electron/renderer/assets/quadrantDiagram-34T5L4WZ-w34cZgIo.js.gz +0 -0
- package/dist-electron/renderer/assets/requirementDiagram-MS252O5E-scA2ZKRK.js.gz +0 -0
- package/dist-electron/renderer/assets/sankeyDiagram-XADWPNL6-BAen7KsY.js.gz +0 -0
- package/dist-electron/renderer/assets/sequenceDiagram-FGHM5R23-CTs2YiIq.js.gz +0 -0
- package/dist-electron/renderer/assets/stateDiagram-FHFEXIEX-Bh0sWvlc.js.gz +0 -0
- package/dist-electron/renderer/assets/timeline-definition-GMOUNBTQ-CbeMRmLK.js.gz +0 -0
- package/dist-electron/renderer/assets/vennDiagram-DHZGUBPP-DJhwj_mO.js.gz +0 -0
- package/dist-electron/renderer/assets/wardley-RL74JXVD-DBLZJp8R.js.gz +0 -0
- package/dist-electron/renderer/assets/wardleyDiagram-NUSXRM2D-Cu85Zz7H.js.gz +0 -0
- package/dist-electron/renderer/assets/xychartDiagram-5P7HB3ND-DF6f5m7g.js.gz +0 -0
|
@@ -0,0 +1,3835 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./parser-DYEwxOAz.js","./jszip.min-Ca5jExEq.js","./_commonjsHelpers-CCIqAdii.js","./preload-helper-DMSNAyVy.js","./assets-FW_AxgRe.js","./index-B3YxBY6K.js","./zoom-jYhmkcQX.js","./options-SsS0Y_ki.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import { _ as __vitePreload } from "./preload-helper-DMSNAyVy.js";
|
|
3
|
+
import { e as resolveFileViewerSpreadsheetWorkerUrl, r as resolveFileViewerRuntimeAssetBaseUrl } from "./assets-FW_AxgRe.js";
|
|
4
|
+
import { c as createFileViewerTranslator, r as registerFileViewerZoomProvider, u as unregisterFileViewerZoomProvider } from "./index-B3YxBY6K.js";
|
|
5
|
+
import { c as createFileViewerZoomChangeEmitter } from "./zoom-jYhmkcQX.js";
|
|
6
|
+
import { r as resolveFileViewerColorScheme } from "./options-SsS0Y_ki.js";
|
|
7
|
+
const createFileViewerWorkerController = (factory, options = {}) => {
|
|
8
|
+
const instance = factory();
|
|
9
|
+
const eventHandlers = /* @__PURE__ */ new Map();
|
|
10
|
+
const messageHooks = /* @__PURE__ */ new Set();
|
|
11
|
+
const errorHooks = /* @__PURE__ */ new Set();
|
|
12
|
+
const emit = (type, payload) => {
|
|
13
|
+
instance === null || instance === void 0 ? void 0 : instance.postMessage({
|
|
14
|
+
type,
|
|
15
|
+
payload
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const handleMessage = (event) => {
|
|
19
|
+
const { type, payload } = event.data || {};
|
|
20
|
+
const handlers = eventHandlers.get(type);
|
|
21
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.forEach((handler) => handler(payload));
|
|
22
|
+
messageHooks.forEach((hook) => hook(event));
|
|
23
|
+
};
|
|
24
|
+
const handleError = (event) => {
|
|
25
|
+
if (options.logErrors !== false) {
|
|
26
|
+
console.error(event);
|
|
27
|
+
}
|
|
28
|
+
errorHooks.forEach((hook) => hook(event));
|
|
29
|
+
};
|
|
30
|
+
instance === null || instance === void 0 ? void 0 : instance.addEventListener("message", handleMessage);
|
|
31
|
+
instance === null || instance === void 0 ? void 0 : instance.addEventListener("error", handleError);
|
|
32
|
+
const worker = {
|
|
33
|
+
emit
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
instance,
|
|
37
|
+
worker,
|
|
38
|
+
emit,
|
|
39
|
+
onWorkerMessage(hook) {
|
|
40
|
+
messageHooks.add(hook);
|
|
41
|
+
return () => {
|
|
42
|
+
messageHooks.delete(hook);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
onWorkerError(hook) {
|
|
46
|
+
errorHooks.add(hook);
|
|
47
|
+
return () => {
|
|
48
|
+
errorHooks.delete(hook);
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
onWorkerEvent(type, hook) {
|
|
52
|
+
let handlers = eventHandlers.get(type);
|
|
53
|
+
if (!handlers) {
|
|
54
|
+
handlers = /* @__PURE__ */ new Set();
|
|
55
|
+
eventHandlers.set(type, handlers);
|
|
56
|
+
}
|
|
57
|
+
handlers.add(hook);
|
|
58
|
+
return () => {
|
|
59
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.delete(hook);
|
|
60
|
+
if ((handlers === null || handlers === void 0 ? void 0 : handlers.size) === 0) {
|
|
61
|
+
eventHandlers.delete(type);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
mapEvents(mappings) {
|
|
66
|
+
if (Array.isArray(mappings)) {
|
|
67
|
+
return mappings.reduce((result, key) => {
|
|
68
|
+
result[key] = (payload) => emit(key, payload);
|
|
69
|
+
return result;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(mappings).reduce((result, key) => {
|
|
73
|
+
const name = mappings[key];
|
|
74
|
+
result[name] = (payload) => emit(key, payload);
|
|
75
|
+
return result;
|
|
76
|
+
}, {});
|
|
77
|
+
},
|
|
78
|
+
destroy() {
|
|
79
|
+
instance === null || instance === void 0 ? void 0 : instance.removeEventListener("message", handleMessage);
|
|
80
|
+
instance === null || instance === void 0 ? void 0 : instance.removeEventListener("error", handleError);
|
|
81
|
+
instance === null || instance === void 0 ? void 0 : instance.terminate();
|
|
82
|
+
eventHandlers.clear();
|
|
83
|
+
messageHooks.clear();
|
|
84
|
+
errorHooks.clear();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
89
|
+
const DEFAULT_COLORS = ["#4472c4", "#ed7d31", "#70ad47", "#ffc000", "#5b9bd5", "#a5a5a5"];
|
|
90
|
+
const svgElement = (documentRef, name, attributes = {}) => {
|
|
91
|
+
const element = documentRef.createElementNS(SVG_NAMESPACE, name);
|
|
92
|
+
Object.entries(attributes).forEach(([key, value]) => element.setAttribute(key, `${value}`));
|
|
93
|
+
return element;
|
|
94
|
+
};
|
|
95
|
+
const svgText = (documentRef, value, x, y, options = {}) => {
|
|
96
|
+
const text = svgElement(documentRef, "text", {
|
|
97
|
+
x,
|
|
98
|
+
y,
|
|
99
|
+
"text-anchor": options.anchor || "start",
|
|
100
|
+
"font-family": "Aptos, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif",
|
|
101
|
+
"font-size": options.size || 11,
|
|
102
|
+
"font-weight": options.weight || "400",
|
|
103
|
+
fill: options.fill || "#5f6368"
|
|
104
|
+
});
|
|
105
|
+
if (options.rotate) {
|
|
106
|
+
text.setAttribute("transform", `rotate(${options.rotate} ${x} ${y})`);
|
|
107
|
+
}
|
|
108
|
+
text.textContent = value;
|
|
109
|
+
return text;
|
|
110
|
+
};
|
|
111
|
+
const seriesColor = (series, index) => {
|
|
112
|
+
return series.color || DEFAULT_COLORS[index % DEFAULT_COLORS.length];
|
|
113
|
+
};
|
|
114
|
+
const categoryLabels = (chart) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const labels = ((_a = chart.series.find((series) => series.categories.length)) === null || _a === void 0 ? void 0 : _a.categories) || [];
|
|
117
|
+
const valueCount = Math.max(0, ...chart.series.map((series) => series.values.length));
|
|
118
|
+
return labels.length ? labels : Array.from({ length: valueCount }, (_, index) => `${index + 1}`);
|
|
119
|
+
};
|
|
120
|
+
const valueDomain = (chart) => {
|
|
121
|
+
const values = chart.series.flatMap((series) => series.values).filter(Number.isFinite);
|
|
122
|
+
const min = Math.min(0, ...values);
|
|
123
|
+
const max = Math.max(0, ...values);
|
|
124
|
+
if (min === max) {
|
|
125
|
+
return { min: 0, max: Math.max(1, max), span: Math.max(1, max) };
|
|
126
|
+
}
|
|
127
|
+
return { min, max, span: max - min };
|
|
128
|
+
};
|
|
129
|
+
const createPlot = (chart) => {
|
|
130
|
+
const hasTitle = !!chart.title;
|
|
131
|
+
const hasLegend = !!chart.legendPosition;
|
|
132
|
+
const rightLegend = chart.legendPosition === "right";
|
|
133
|
+
const top = hasTitle ? 48 : 24;
|
|
134
|
+
const bottom = hasLegend && !rightLegend ? 302 : 326;
|
|
135
|
+
const left = chart.valueAxisTitle ? 76 : 58;
|
|
136
|
+
const right = rightLegend ? 492 : 612;
|
|
137
|
+
return {
|
|
138
|
+
left,
|
|
139
|
+
top,
|
|
140
|
+
width: right - left,
|
|
141
|
+
height: bottom - top,
|
|
142
|
+
bottom
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
const drawValueGrid = (documentRef, svg, plot, domain) => {
|
|
146
|
+
const tickCount = 5;
|
|
147
|
+
for (let index = 0; index <= tickCount; index += 1) {
|
|
148
|
+
const ratio = index / tickCount;
|
|
149
|
+
const y = plot.bottom - ratio * plot.height;
|
|
150
|
+
const value = domain.min + ratio * domain.span;
|
|
151
|
+
svg.appendChild(svgElement(documentRef, "line", {
|
|
152
|
+
x1: plot.left,
|
|
153
|
+
y1: y,
|
|
154
|
+
x2: plot.left + plot.width,
|
|
155
|
+
y2: y,
|
|
156
|
+
stroke: index === 0 ? "#9ca3af" : "#e5e7eb",
|
|
157
|
+
"stroke-width": 1
|
|
158
|
+
}));
|
|
159
|
+
svg.appendChild(svgText(documentRef, Number.isInteger(value) ? `${value}` : value.toFixed(1), plot.left - 8, y + 4, {
|
|
160
|
+
anchor: "end",
|
|
161
|
+
size: 10
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const drawCategoryLabels = (documentRef, svg, chart, plot) => {
|
|
166
|
+
const categories = categoryLabels(chart);
|
|
167
|
+
if (!categories.length) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const step = plot.width / categories.length;
|
|
171
|
+
categories.forEach((category, index) => {
|
|
172
|
+
const maxLength = categories.length > 8 ? 8 : 14;
|
|
173
|
+
const label = category.length > maxLength ? `${category.slice(0, maxLength - 1)}…` : category;
|
|
174
|
+
svg.appendChild(svgText(documentRef, label, plot.left + (index + 0.5) * step, plot.bottom + 17, {
|
|
175
|
+
anchor: "middle",
|
|
176
|
+
size: 10
|
|
177
|
+
}));
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const drawColumnChart = (documentRef, svg, chart, plot) => {
|
|
181
|
+
const domain = valueDomain(chart);
|
|
182
|
+
const categories = categoryLabels(chart);
|
|
183
|
+
const categoryCount = Math.max(categories.length, ...chart.series.map((series) => series.values.length), 1);
|
|
184
|
+
const groupWidth = plot.width / categoryCount;
|
|
185
|
+
const seriesCount = Math.max(chart.series.length, 1);
|
|
186
|
+
const slotWidth = groupWidth * 0.76 / seriesCount;
|
|
187
|
+
const zeroY = plot.bottom - (0 - domain.min) / domain.span * plot.height;
|
|
188
|
+
drawValueGrid(documentRef, svg, plot, domain);
|
|
189
|
+
chart.series.forEach((series, seriesIndex) => {
|
|
190
|
+
series.values.forEach((value, valueIndex) => {
|
|
191
|
+
const valueY = plot.bottom - (value - domain.min) / domain.span * plot.height;
|
|
192
|
+
const x = plot.left + valueIndex * groupWidth + groupWidth * 0.12 + seriesIndex * slotWidth;
|
|
193
|
+
const y = Math.min(zeroY, valueY);
|
|
194
|
+
const rect = svgElement(documentRef, "rect", {
|
|
195
|
+
x,
|
|
196
|
+
y,
|
|
197
|
+
width: Math.max(1, slotWidth - 2),
|
|
198
|
+
height: Math.max(1, Math.abs(zeroY - valueY)),
|
|
199
|
+
fill: seriesColor(series, seriesIndex),
|
|
200
|
+
rx: 1
|
|
201
|
+
});
|
|
202
|
+
const title = svgElement(documentRef, "title");
|
|
203
|
+
title.textContent = `${series.name}: ${value}`;
|
|
204
|
+
rect.appendChild(title);
|
|
205
|
+
svg.appendChild(rect);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
drawCategoryLabels(documentRef, svg, chart, plot);
|
|
209
|
+
};
|
|
210
|
+
const drawHorizontalBarChart = (documentRef, svg, chart, plot) => {
|
|
211
|
+
const domain = valueDomain(chart);
|
|
212
|
+
const categories = categoryLabels(chart);
|
|
213
|
+
const categoryCount = Math.max(categories.length, ...chart.series.map((series) => series.values.length), 1);
|
|
214
|
+
const groupHeight = plot.height / categoryCount;
|
|
215
|
+
const seriesCount = Math.max(chart.series.length, 1);
|
|
216
|
+
const slotHeight = groupHeight * 0.76 / seriesCount;
|
|
217
|
+
const zeroX = plot.left + (0 - domain.min) / domain.span * plot.width;
|
|
218
|
+
for (let index = 0; index <= 5; index += 1) {
|
|
219
|
+
const ratio = index / 5;
|
|
220
|
+
const x = plot.left + ratio * plot.width;
|
|
221
|
+
svg.appendChild(svgElement(documentRef, "line", {
|
|
222
|
+
x1: x,
|
|
223
|
+
y1: plot.top,
|
|
224
|
+
x2: x,
|
|
225
|
+
y2: plot.bottom,
|
|
226
|
+
stroke: "#e5e7eb",
|
|
227
|
+
"stroke-width": 1
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
chart.series.forEach((series, seriesIndex) => {
|
|
231
|
+
series.values.forEach((value, valueIndex) => {
|
|
232
|
+
const valueX = plot.left + (value - domain.min) / domain.span * plot.width;
|
|
233
|
+
const y = plot.top + valueIndex * groupHeight + groupHeight * 0.12 + seriesIndex * slotHeight;
|
|
234
|
+
svg.appendChild(svgElement(documentRef, "rect", {
|
|
235
|
+
x: Math.min(zeroX, valueX),
|
|
236
|
+
y,
|
|
237
|
+
width: Math.max(1, Math.abs(valueX - zeroX)),
|
|
238
|
+
height: Math.max(1, slotHeight - 2),
|
|
239
|
+
fill: seriesColor(series, seriesIndex),
|
|
240
|
+
rx: 1
|
|
241
|
+
}));
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
categories.forEach((category, index) => {
|
|
245
|
+
svg.appendChild(svgText(documentRef, category, plot.left - 8, plot.top + (index + 0.5) * groupHeight + 4, {
|
|
246
|
+
anchor: "end",
|
|
247
|
+
size: 10
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const drawLineChart = (documentRef, svg, chart, plot, fillArea) => {
|
|
252
|
+
const domain = valueDomain(chart);
|
|
253
|
+
const count = Math.max(...chart.series.map((series) => series.values.length), 1);
|
|
254
|
+
const step = count > 1 ? plot.width / (count - 1) : plot.width;
|
|
255
|
+
drawValueGrid(documentRef, svg, plot, domain);
|
|
256
|
+
chart.series.forEach((series, seriesIndex) => {
|
|
257
|
+
const points = series.values.map((value, index) => ({
|
|
258
|
+
x: plot.left + (count > 1 ? index * step : plot.width / 2),
|
|
259
|
+
y: plot.bottom - (value - domain.min) / domain.span * plot.height
|
|
260
|
+
}));
|
|
261
|
+
if (!points.length) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const pathData = points.map((point, index) => `${index ? "L" : "M"}${point.x},${point.y}`).join(" ");
|
|
265
|
+
if (fillArea && points.length > 1) {
|
|
266
|
+
svg.appendChild(svgElement(documentRef, "path", {
|
|
267
|
+
d: `${pathData} L${points[points.length - 1].x},${plot.bottom} L${points[0].x},${plot.bottom} Z`,
|
|
268
|
+
fill: seriesColor(series, seriesIndex),
|
|
269
|
+
opacity: 0.2
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
svg.appendChild(svgElement(documentRef, "path", {
|
|
273
|
+
d: pathData,
|
|
274
|
+
fill: "none",
|
|
275
|
+
stroke: seriesColor(series, seriesIndex),
|
|
276
|
+
"stroke-width": 2.5,
|
|
277
|
+
"stroke-linejoin": "round",
|
|
278
|
+
"stroke-linecap": "round"
|
|
279
|
+
}));
|
|
280
|
+
points.forEach((point) => {
|
|
281
|
+
svg.appendChild(svgElement(documentRef, "circle", {
|
|
282
|
+
cx: point.x,
|
|
283
|
+
cy: point.y,
|
|
284
|
+
r: 3.5,
|
|
285
|
+
fill: seriesColor(series, seriesIndex),
|
|
286
|
+
stroke: "#ffffff",
|
|
287
|
+
"stroke-width": 1
|
|
288
|
+
}));
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
drawCategoryLabels(documentRef, svg, chart, plot);
|
|
292
|
+
};
|
|
293
|
+
const polarPoint = (cx, cy, radius, angle) => {
|
|
294
|
+
const radians = (angle - 90) * Math.PI / 180;
|
|
295
|
+
return {
|
|
296
|
+
x: cx + radius * Math.cos(radians),
|
|
297
|
+
y: cy + radius * Math.sin(radians)
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
const pieSlicePath = (cx, cy, outerRadius, innerRadius, startAngle, endAngle) => {
|
|
301
|
+
const outerStart = polarPoint(cx, cy, outerRadius, endAngle);
|
|
302
|
+
const outerEnd = polarPoint(cx, cy, outerRadius, startAngle);
|
|
303
|
+
const largeArc = endAngle - startAngle > 180 ? 1 : 0;
|
|
304
|
+
if (!innerRadius) {
|
|
305
|
+
return `M${cx},${cy} L${outerStart.x},${outerStart.y} A${outerRadius},${outerRadius} 0 ${largeArc},0 ${outerEnd.x},${outerEnd.y} Z`;
|
|
306
|
+
}
|
|
307
|
+
const innerStart = polarPoint(cx, cy, innerRadius, startAngle);
|
|
308
|
+
const innerEnd = polarPoint(cx, cy, innerRadius, endAngle);
|
|
309
|
+
return `M${outerStart.x},${outerStart.y} A${outerRadius},${outerRadius} 0 ${largeArc},0 ${outerEnd.x},${outerEnd.y} L${innerStart.x},${innerStart.y} A${innerRadius},${innerRadius} 0 ${largeArc},1 ${innerEnd.x},${innerEnd.y} Z`;
|
|
310
|
+
};
|
|
311
|
+
const drawPieChart = (documentRef, svg, chart, doughnut) => {
|
|
312
|
+
const series = chart.series[0];
|
|
313
|
+
const values = (series === null || series === void 0 ? void 0 : series.values) || [];
|
|
314
|
+
const categories = (series === null || series === void 0 ? void 0 : series.categories) || [];
|
|
315
|
+
const total = values.reduce((sum, value) => sum + Math.max(0, value), 0) || 1;
|
|
316
|
+
const cx = chart.legendPosition === "right" ? 260 : 320;
|
|
317
|
+
const cy = chart.title ? 180 : 170;
|
|
318
|
+
const radius = 120;
|
|
319
|
+
let angle = 0;
|
|
320
|
+
values.forEach((value, index) => {
|
|
321
|
+
const nextAngle = angle + Math.max(0, value) / total * 360;
|
|
322
|
+
const color = DEFAULT_COLORS[index % DEFAULT_COLORS.length];
|
|
323
|
+
const path = svgElement(documentRef, "path", {
|
|
324
|
+
d: pieSlicePath(cx, cy, radius, doughnut ? 62 : 0, angle, nextAngle),
|
|
325
|
+
fill: color,
|
|
326
|
+
stroke: "#ffffff",
|
|
327
|
+
"stroke-width": 1.5
|
|
328
|
+
});
|
|
329
|
+
const title = svgElement(documentRef, "title");
|
|
330
|
+
title.textContent = `${categories[index] || index + 1}: ${value}`;
|
|
331
|
+
path.appendChild(title);
|
|
332
|
+
svg.appendChild(path);
|
|
333
|
+
angle = nextAngle;
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
const drawLegend = (documentRef, svg, chart) => {
|
|
337
|
+
if (!chart.legendPosition) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const right = chart.legendPosition === "right";
|
|
341
|
+
chart.series.slice(0, 8).forEach((series, index) => {
|
|
342
|
+
const x = right ? 510 : 76 + index % 4 * 136;
|
|
343
|
+
const y = right ? 72 + index * 28 : 342 - Math.floor(index / 4) * 20;
|
|
344
|
+
svg.appendChild(svgElement(documentRef, "rect", {
|
|
345
|
+
x,
|
|
346
|
+
y: y - 10,
|
|
347
|
+
width: 10,
|
|
348
|
+
height: 10,
|
|
349
|
+
fill: seriesColor(series, index)
|
|
350
|
+
}));
|
|
351
|
+
const label = series.name.length > 16 ? `${series.name.slice(0, 15)}…` : series.name;
|
|
352
|
+
svg.appendChild(svgText(documentRef, label, x + 15, y, { size: 10 }));
|
|
353
|
+
});
|
|
354
|
+
};
|
|
355
|
+
const renderSpreadsheetChart = (documentRef, chart) => {
|
|
356
|
+
const container = documentRef.createElement("div");
|
|
357
|
+
container.className = "excel-chart";
|
|
358
|
+
container.dataset.chartId = chart.id;
|
|
359
|
+
container.dataset.chartType = chart.type;
|
|
360
|
+
container.dataset.seriesNames = JSON.stringify(chart.series.map((series) => series.name));
|
|
361
|
+
container.setAttribute("role", "img");
|
|
362
|
+
container.setAttribute("aria-label", chart.title || chart.id || "Spreadsheet chart");
|
|
363
|
+
const svg = svgElement(documentRef, "svg", {
|
|
364
|
+
viewBox: "0 0 640 360",
|
|
365
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
366
|
+
focusable: "false",
|
|
367
|
+
"aria-hidden": "true"
|
|
368
|
+
});
|
|
369
|
+
svg.appendChild(svgElement(documentRef, "rect", {
|
|
370
|
+
x: 0.5,
|
|
371
|
+
y: 0.5,
|
|
372
|
+
width: 639,
|
|
373
|
+
height: 359,
|
|
374
|
+
fill: "#ffffff",
|
|
375
|
+
stroke: "#d1d5db"
|
|
376
|
+
}));
|
|
377
|
+
if (chart.title) {
|
|
378
|
+
svg.appendChild(svgText(documentRef, chart.title, 320, 28, {
|
|
379
|
+
anchor: "middle",
|
|
380
|
+
size: 16,
|
|
381
|
+
weight: "600",
|
|
382
|
+
fill: "#1f2937"
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
385
|
+
const plot = createPlot(chart);
|
|
386
|
+
switch (chart.type) {
|
|
387
|
+
case "pie":
|
|
388
|
+
drawPieChart(documentRef, svg, chart, false);
|
|
389
|
+
break;
|
|
390
|
+
case "doughnut":
|
|
391
|
+
drawPieChart(documentRef, svg, chart, true);
|
|
392
|
+
break;
|
|
393
|
+
case "line":
|
|
394
|
+
case "scatter":
|
|
395
|
+
case "radar":
|
|
396
|
+
drawLineChart(documentRef, svg, chart, plot, false);
|
|
397
|
+
break;
|
|
398
|
+
case "area":
|
|
399
|
+
drawLineChart(documentRef, svg, chart, plot, true);
|
|
400
|
+
break;
|
|
401
|
+
case "bar":
|
|
402
|
+
default:
|
|
403
|
+
if (chart.barDirection === "bar") {
|
|
404
|
+
drawHorizontalBarChart(documentRef, svg, chart, plot);
|
|
405
|
+
} else {
|
|
406
|
+
drawColumnChart(documentRef, svg, chart, plot);
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
if (chart.categoryAxisTitle && chart.type !== "pie" && chart.type !== "doughnut") {
|
|
411
|
+
svg.appendChild(svgText(documentRef, chart.categoryAxisTitle, plot.left + plot.width / 2, 324, {
|
|
412
|
+
anchor: "middle",
|
|
413
|
+
size: 11,
|
|
414
|
+
fill: "#374151"
|
|
415
|
+
}));
|
|
416
|
+
}
|
|
417
|
+
if (chart.valueAxisTitle && chart.type !== "pie" && chart.type !== "doughnut") {
|
|
418
|
+
svg.appendChild(svgText(documentRef, chart.valueAxisTitle, 18, plot.top + plot.height / 2, {
|
|
419
|
+
anchor: "middle",
|
|
420
|
+
size: 11,
|
|
421
|
+
fill: "#374151",
|
|
422
|
+
rotate: -90
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
drawLegend(documentRef, svg, chart);
|
|
426
|
+
container.appendChild(svg);
|
|
427
|
+
return container;
|
|
428
|
+
};
|
|
429
|
+
const WINDOW_SIZE = 500;
|
|
430
|
+
const PREFETCH_AHEAD = 3;
|
|
431
|
+
const PREFETCH_BEHIND = 1;
|
|
432
|
+
const INDEX_COLUMN_KEY = "__index";
|
|
433
|
+
const ROW_KEY_FIELD = "__k";
|
|
434
|
+
const ROW_STATE_FIELD = "__s";
|
|
435
|
+
const DEFAULT_SHEET_DEFAULTS = {
|
|
436
|
+
rowHeight: 20,
|
|
437
|
+
colWidth: 64
|
|
438
|
+
};
|
|
439
|
+
const RowState = {
|
|
440
|
+
Placeholder: 0,
|
|
441
|
+
Loading: 1,
|
|
442
|
+
Loaded: 2
|
|
443
|
+
};
|
|
444
|
+
const createEmptyVirtualState = () => ({
|
|
445
|
+
active: false,
|
|
446
|
+
totalRows: 0,
|
|
447
|
+
totalCols: 0,
|
|
448
|
+
indexOffset: 0,
|
|
449
|
+
defaults: { ...DEFAULT_SHEET_DEFAULTS },
|
|
450
|
+
dataKeys: [],
|
|
451
|
+
rows: [],
|
|
452
|
+
columns: [],
|
|
453
|
+
cellCache: /* @__PURE__ */ new Map(),
|
|
454
|
+
mergeStartMap: /* @__PURE__ */ new Map(),
|
|
455
|
+
mergeCoveredMap: /* @__PURE__ */ new Map(),
|
|
456
|
+
rowHeightCache: /* @__PURE__ */ new Map(),
|
|
457
|
+
windowRows: /* @__PURE__ */ new Map(),
|
|
458
|
+
windowCells: /* @__PURE__ */ new Map(),
|
|
459
|
+
loadedWindows: /* @__PURE__ */ new Set(),
|
|
460
|
+
loadingWindows: /* @__PURE__ */ new Set()
|
|
461
|
+
});
|
|
462
|
+
const displayCellKey = (row, col) => {
|
|
463
|
+
return `${row}-${col}`;
|
|
464
|
+
};
|
|
465
|
+
const getDataKey = (index) => {
|
|
466
|
+
return `c${index}`;
|
|
467
|
+
};
|
|
468
|
+
const getRowState = (row) => {
|
|
469
|
+
var _a;
|
|
470
|
+
return (_a = row === null || row === void 0 ? void 0 : row[ROW_STATE_FIELD]) !== null && _a !== void 0 ? _a : RowState.Placeholder;
|
|
471
|
+
};
|
|
472
|
+
const buildRows = (count) => {
|
|
473
|
+
const rows = new Array(count);
|
|
474
|
+
for (let index = 0; index < count; index += 1) {
|
|
475
|
+
rows[index] = {
|
|
476
|
+
[ROW_KEY_FIELD]: `${index}`,
|
|
477
|
+
[ROW_STATE_FIELD]: RowState.Placeholder
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
return rows;
|
|
481
|
+
};
|
|
482
|
+
const getMaxWindowStart = (totalRows) => {
|
|
483
|
+
if (!totalRows) {
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
return Math.floor(Math.max(totalRows - 1, 0) / WINDOW_SIZE) * WINDOW_SIZE;
|
|
487
|
+
};
|
|
488
|
+
const clampWindowStart = (startRow = 0, totalRows = 0) => {
|
|
489
|
+
return Math.min(Math.max(startRow, 0), getMaxWindowStart(totalRows));
|
|
490
|
+
};
|
|
491
|
+
const getWindowStart = (row = 0, totalRows = 0) => {
|
|
492
|
+
const start = Math.floor(Math.max(row, 0) / WINDOW_SIZE) * WINDOW_SIZE;
|
|
493
|
+
return clampWindowStart(start, totalRows);
|
|
494
|
+
};
|
|
495
|
+
const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
|
|
496
|
+
const starts = /* @__PURE__ */ new Set();
|
|
497
|
+
const firstWindow = getWindowStart(startRow, totalRows);
|
|
498
|
+
const lastWindow = getWindowStart(endRow, totalRows);
|
|
499
|
+
for (let current = firstWindow; current <= lastWindow; current += WINDOW_SIZE) {
|
|
500
|
+
starts.add(current);
|
|
501
|
+
}
|
|
502
|
+
const ahead = far ? PREFETCH_AHEAD + 1 : PREFETCH_AHEAD;
|
|
503
|
+
const behind = far ? PREFETCH_BEHIND + 1 : PREFETCH_BEHIND;
|
|
504
|
+
const anchor = direction > 0 ? lastWindow : firstWindow;
|
|
505
|
+
for (let step = 1; step <= ahead; step += 1) {
|
|
506
|
+
starts.add(clampWindowStart(anchor + direction * step * WINDOW_SIZE, totalRows));
|
|
507
|
+
}
|
|
508
|
+
for (let step = 1; step <= behind; step += 1) {
|
|
509
|
+
starts.add(clampWindowStart(anchor - direction * step * WINDOW_SIZE, totalRows));
|
|
510
|
+
}
|
|
511
|
+
return Array.from(starts);
|
|
512
|
+
};
|
|
513
|
+
const markWindowState = (rows, totalRows, windowStart, nextState) => {
|
|
514
|
+
const endRow = Math.min(windowStart + WINDOW_SIZE, totalRows);
|
|
515
|
+
for (let rowIndex = windowStart; rowIndex < endRow; rowIndex += 1) {
|
|
516
|
+
const row = rows[rowIndex];
|
|
517
|
+
if (!row) {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
row[ROW_STATE_FIELD] = nextState;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
function _typeof(obj) {
|
|
524
|
+
"@babel/helpers - typeof";
|
|
525
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
526
|
+
return typeof obj2;
|
|
527
|
+
} : function(obj2) {
|
|
528
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
529
|
+
}, _typeof(obj);
|
|
530
|
+
}
|
|
531
|
+
var trimLeft = /^\s+/;
|
|
532
|
+
var trimRight = /\s+$/;
|
|
533
|
+
function tinycolor(color, opts) {
|
|
534
|
+
color = color ? color : "";
|
|
535
|
+
opts = opts || {};
|
|
536
|
+
if (color instanceof tinycolor) {
|
|
537
|
+
return color;
|
|
538
|
+
}
|
|
539
|
+
if (!(this instanceof tinycolor)) {
|
|
540
|
+
return new tinycolor(color, opts);
|
|
541
|
+
}
|
|
542
|
+
var rgb = inputToRGB(color);
|
|
543
|
+
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
544
|
+
this._gradientType = opts.gradientType;
|
|
545
|
+
if (this._r < 1) this._r = Math.round(this._r);
|
|
546
|
+
if (this._g < 1) this._g = Math.round(this._g);
|
|
547
|
+
if (this._b < 1) this._b = Math.round(this._b);
|
|
548
|
+
this._ok = rgb.ok;
|
|
549
|
+
}
|
|
550
|
+
tinycolor.prototype = {
|
|
551
|
+
isDark: function isDark() {
|
|
552
|
+
return this.getBrightness() < 128;
|
|
553
|
+
},
|
|
554
|
+
isLight: function isLight() {
|
|
555
|
+
return !this.isDark();
|
|
556
|
+
},
|
|
557
|
+
isValid: function isValid() {
|
|
558
|
+
return this._ok;
|
|
559
|
+
},
|
|
560
|
+
getOriginalInput: function getOriginalInput() {
|
|
561
|
+
return this._originalInput;
|
|
562
|
+
},
|
|
563
|
+
getFormat: function getFormat() {
|
|
564
|
+
return this._format;
|
|
565
|
+
},
|
|
566
|
+
getAlpha: function getAlpha() {
|
|
567
|
+
return this._a;
|
|
568
|
+
},
|
|
569
|
+
getBrightness: function getBrightness() {
|
|
570
|
+
var rgb = this.toRgb();
|
|
571
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
572
|
+
},
|
|
573
|
+
getLuminance: function getLuminance() {
|
|
574
|
+
var rgb = this.toRgb();
|
|
575
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
576
|
+
RsRGB = rgb.r / 255;
|
|
577
|
+
GsRGB = rgb.g / 255;
|
|
578
|
+
BsRGB = rgb.b / 255;
|
|
579
|
+
if (RsRGB <= 0.03928) R = RsRGB / 12.92;
|
|
580
|
+
else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
581
|
+
if (GsRGB <= 0.03928) G = GsRGB / 12.92;
|
|
582
|
+
else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
583
|
+
if (BsRGB <= 0.03928) B = BsRGB / 12.92;
|
|
584
|
+
else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
585
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
586
|
+
},
|
|
587
|
+
setAlpha: function setAlpha(value) {
|
|
588
|
+
this._a = boundAlpha(value);
|
|
589
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
590
|
+
return this;
|
|
591
|
+
},
|
|
592
|
+
toHsv: function toHsv() {
|
|
593
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
594
|
+
return {
|
|
595
|
+
h: hsv.h * 360,
|
|
596
|
+
s: hsv.s,
|
|
597
|
+
v: hsv.v,
|
|
598
|
+
a: this._a
|
|
599
|
+
};
|
|
600
|
+
},
|
|
601
|
+
toHsvString: function toHsvString() {
|
|
602
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
603
|
+
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
604
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
605
|
+
},
|
|
606
|
+
toHsl: function toHsl() {
|
|
607
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
608
|
+
return {
|
|
609
|
+
h: hsl.h * 360,
|
|
610
|
+
s: hsl.s,
|
|
611
|
+
l: hsl.l,
|
|
612
|
+
a: this._a
|
|
613
|
+
};
|
|
614
|
+
},
|
|
615
|
+
toHslString: function toHslString() {
|
|
616
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
617
|
+
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
618
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
619
|
+
},
|
|
620
|
+
toHex: function toHex(allow3Char) {
|
|
621
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
622
|
+
},
|
|
623
|
+
toHexString: function toHexString(allow3Char) {
|
|
624
|
+
return "#" + this.toHex(allow3Char);
|
|
625
|
+
},
|
|
626
|
+
toHex8: function toHex8(allow4Char) {
|
|
627
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
628
|
+
},
|
|
629
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
630
|
+
return "#" + this.toHex8(allow4Char);
|
|
631
|
+
},
|
|
632
|
+
toRgb: function toRgb() {
|
|
633
|
+
return {
|
|
634
|
+
r: Math.round(this._r),
|
|
635
|
+
g: Math.round(this._g),
|
|
636
|
+
b: Math.round(this._b),
|
|
637
|
+
a: this._a
|
|
638
|
+
};
|
|
639
|
+
},
|
|
640
|
+
toRgbString: function toRgbString() {
|
|
641
|
+
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
642
|
+
},
|
|
643
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
644
|
+
return {
|
|
645
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
646
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
647
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
648
|
+
a: this._a
|
|
649
|
+
};
|
|
650
|
+
},
|
|
651
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
652
|
+
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
653
|
+
},
|
|
654
|
+
toName: function toName() {
|
|
655
|
+
if (this._a === 0) {
|
|
656
|
+
return "transparent";
|
|
657
|
+
}
|
|
658
|
+
if (this._a < 1) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
662
|
+
},
|
|
663
|
+
toFilter: function toFilter(secondColor) {
|
|
664
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
665
|
+
var secondHex8String = hex8String;
|
|
666
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
667
|
+
if (secondColor) {
|
|
668
|
+
var s = tinycolor(secondColor);
|
|
669
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
670
|
+
}
|
|
671
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
672
|
+
},
|
|
673
|
+
toString: function toString(format) {
|
|
674
|
+
var formatSet = !!format;
|
|
675
|
+
format = format || this._format;
|
|
676
|
+
var formattedString = false;
|
|
677
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
678
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
679
|
+
if (needsAlphaFormat) {
|
|
680
|
+
if (format === "name" && this._a === 0) {
|
|
681
|
+
return this.toName();
|
|
682
|
+
}
|
|
683
|
+
return this.toRgbString();
|
|
684
|
+
}
|
|
685
|
+
if (format === "rgb") {
|
|
686
|
+
formattedString = this.toRgbString();
|
|
687
|
+
}
|
|
688
|
+
if (format === "prgb") {
|
|
689
|
+
formattedString = this.toPercentageRgbString();
|
|
690
|
+
}
|
|
691
|
+
if (format === "hex" || format === "hex6") {
|
|
692
|
+
formattedString = this.toHexString();
|
|
693
|
+
}
|
|
694
|
+
if (format === "hex3") {
|
|
695
|
+
formattedString = this.toHexString(true);
|
|
696
|
+
}
|
|
697
|
+
if (format === "hex4") {
|
|
698
|
+
formattedString = this.toHex8String(true);
|
|
699
|
+
}
|
|
700
|
+
if (format === "hex8") {
|
|
701
|
+
formattedString = this.toHex8String();
|
|
702
|
+
}
|
|
703
|
+
if (format === "name") {
|
|
704
|
+
formattedString = this.toName();
|
|
705
|
+
}
|
|
706
|
+
if (format === "hsl") {
|
|
707
|
+
formattedString = this.toHslString();
|
|
708
|
+
}
|
|
709
|
+
if (format === "hsv") {
|
|
710
|
+
formattedString = this.toHsvString();
|
|
711
|
+
}
|
|
712
|
+
return formattedString || this.toHexString();
|
|
713
|
+
},
|
|
714
|
+
clone: function clone() {
|
|
715
|
+
return tinycolor(this.toString());
|
|
716
|
+
},
|
|
717
|
+
_applyModification: function _applyModification(fn, args) {
|
|
718
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
719
|
+
this._r = color._r;
|
|
720
|
+
this._g = color._g;
|
|
721
|
+
this._b = color._b;
|
|
722
|
+
this.setAlpha(color._a);
|
|
723
|
+
return this;
|
|
724
|
+
},
|
|
725
|
+
lighten: function lighten() {
|
|
726
|
+
return this._applyModification(_lighten, arguments);
|
|
727
|
+
},
|
|
728
|
+
brighten: function brighten() {
|
|
729
|
+
return this._applyModification(_brighten, arguments);
|
|
730
|
+
},
|
|
731
|
+
darken: function darken() {
|
|
732
|
+
return this._applyModification(_darken, arguments);
|
|
733
|
+
},
|
|
734
|
+
desaturate: function desaturate() {
|
|
735
|
+
return this._applyModification(_desaturate, arguments);
|
|
736
|
+
},
|
|
737
|
+
saturate: function saturate() {
|
|
738
|
+
return this._applyModification(_saturate, arguments);
|
|
739
|
+
},
|
|
740
|
+
greyscale: function greyscale() {
|
|
741
|
+
return this._applyModification(_greyscale, arguments);
|
|
742
|
+
},
|
|
743
|
+
spin: function spin() {
|
|
744
|
+
return this._applyModification(_spin, arguments);
|
|
745
|
+
},
|
|
746
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
747
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
748
|
+
},
|
|
749
|
+
analogous: function analogous() {
|
|
750
|
+
return this._applyCombination(_analogous, arguments);
|
|
751
|
+
},
|
|
752
|
+
complement: function complement() {
|
|
753
|
+
return this._applyCombination(_complement, arguments);
|
|
754
|
+
},
|
|
755
|
+
monochromatic: function monochromatic() {
|
|
756
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
757
|
+
},
|
|
758
|
+
splitcomplement: function splitcomplement() {
|
|
759
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
760
|
+
},
|
|
761
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
762
|
+
// polyad: function (number) {
|
|
763
|
+
// return this._applyCombination(polyad, [number]);
|
|
764
|
+
// },
|
|
765
|
+
triad: function triad() {
|
|
766
|
+
return this._applyCombination(polyad, [3]);
|
|
767
|
+
},
|
|
768
|
+
tetrad: function tetrad() {
|
|
769
|
+
return this._applyCombination(polyad, [4]);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
tinycolor.fromRatio = function(color, opts) {
|
|
773
|
+
if (_typeof(color) == "object") {
|
|
774
|
+
var newColor = {};
|
|
775
|
+
for (var i in color) {
|
|
776
|
+
if (color.hasOwnProperty(i)) {
|
|
777
|
+
if (i === "a") {
|
|
778
|
+
newColor[i] = color[i];
|
|
779
|
+
} else {
|
|
780
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
color = newColor;
|
|
785
|
+
}
|
|
786
|
+
return tinycolor(color, opts);
|
|
787
|
+
};
|
|
788
|
+
function inputToRGB(color) {
|
|
789
|
+
var rgb = {
|
|
790
|
+
r: 0,
|
|
791
|
+
g: 0,
|
|
792
|
+
b: 0
|
|
793
|
+
};
|
|
794
|
+
var a = 1;
|
|
795
|
+
var s = null;
|
|
796
|
+
var v = null;
|
|
797
|
+
var l = null;
|
|
798
|
+
var ok = false;
|
|
799
|
+
var format = false;
|
|
800
|
+
if (typeof color == "string") {
|
|
801
|
+
color = stringInputToObject(color);
|
|
802
|
+
}
|
|
803
|
+
if (_typeof(color) == "object") {
|
|
804
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
805
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
806
|
+
ok = true;
|
|
807
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
808
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
809
|
+
s = convertToPercentage(color.s);
|
|
810
|
+
v = convertToPercentage(color.v);
|
|
811
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
812
|
+
ok = true;
|
|
813
|
+
format = "hsv";
|
|
814
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
815
|
+
s = convertToPercentage(color.s);
|
|
816
|
+
l = convertToPercentage(color.l);
|
|
817
|
+
rgb = hslToRgb(color.h, s, l);
|
|
818
|
+
ok = true;
|
|
819
|
+
format = "hsl";
|
|
820
|
+
}
|
|
821
|
+
if (color.hasOwnProperty("a")) {
|
|
822
|
+
a = color.a;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
a = boundAlpha(a);
|
|
826
|
+
return {
|
|
827
|
+
ok,
|
|
828
|
+
format: color.format || format,
|
|
829
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
830
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
831
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
832
|
+
a
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function rgbToRgb(r, g, b) {
|
|
836
|
+
return {
|
|
837
|
+
r: bound01(r, 255) * 255,
|
|
838
|
+
g: bound01(g, 255) * 255,
|
|
839
|
+
b: bound01(b, 255) * 255
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function rgbToHsl(r, g, b) {
|
|
843
|
+
r = bound01(r, 255);
|
|
844
|
+
g = bound01(g, 255);
|
|
845
|
+
b = bound01(b, 255);
|
|
846
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
847
|
+
var h, s, l = (max + min) / 2;
|
|
848
|
+
if (max == min) {
|
|
849
|
+
h = s = 0;
|
|
850
|
+
} else {
|
|
851
|
+
var d = max - min;
|
|
852
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
853
|
+
switch (max) {
|
|
854
|
+
case r:
|
|
855
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
856
|
+
break;
|
|
857
|
+
case g:
|
|
858
|
+
h = (b - r) / d + 2;
|
|
859
|
+
break;
|
|
860
|
+
case b:
|
|
861
|
+
h = (r - g) / d + 4;
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
h /= 6;
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
h,
|
|
868
|
+
s,
|
|
869
|
+
l
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function hslToRgb(h, s, l) {
|
|
873
|
+
var r, g, b;
|
|
874
|
+
h = bound01(h, 360);
|
|
875
|
+
s = bound01(s, 100);
|
|
876
|
+
l = bound01(l, 100);
|
|
877
|
+
function hue2rgb(p2, q2, t) {
|
|
878
|
+
if (t < 0) t += 1;
|
|
879
|
+
if (t > 1) t -= 1;
|
|
880
|
+
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
881
|
+
if (t < 1 / 2) return q2;
|
|
882
|
+
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
883
|
+
return p2;
|
|
884
|
+
}
|
|
885
|
+
if (s === 0) {
|
|
886
|
+
r = g = b = l;
|
|
887
|
+
} else {
|
|
888
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
889
|
+
var p = 2 * l - q;
|
|
890
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
891
|
+
g = hue2rgb(p, q, h);
|
|
892
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
893
|
+
}
|
|
894
|
+
return {
|
|
895
|
+
r: r * 255,
|
|
896
|
+
g: g * 255,
|
|
897
|
+
b: b * 255
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
function rgbToHsv(r, g, b) {
|
|
901
|
+
r = bound01(r, 255);
|
|
902
|
+
g = bound01(g, 255);
|
|
903
|
+
b = bound01(b, 255);
|
|
904
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
905
|
+
var h, s, v = max;
|
|
906
|
+
var d = max - min;
|
|
907
|
+
s = max === 0 ? 0 : d / max;
|
|
908
|
+
if (max == min) {
|
|
909
|
+
h = 0;
|
|
910
|
+
} else {
|
|
911
|
+
switch (max) {
|
|
912
|
+
case r:
|
|
913
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
914
|
+
break;
|
|
915
|
+
case g:
|
|
916
|
+
h = (b - r) / d + 2;
|
|
917
|
+
break;
|
|
918
|
+
case b:
|
|
919
|
+
h = (r - g) / d + 4;
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
h /= 6;
|
|
923
|
+
}
|
|
924
|
+
return {
|
|
925
|
+
h,
|
|
926
|
+
s,
|
|
927
|
+
v
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
function hsvToRgb(h, s, v) {
|
|
931
|
+
h = bound01(h, 360) * 6;
|
|
932
|
+
s = bound01(s, 100);
|
|
933
|
+
v = bound01(v, 100);
|
|
934
|
+
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
935
|
+
return {
|
|
936
|
+
r: r * 255,
|
|
937
|
+
g: g * 255,
|
|
938
|
+
b: b * 255
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
942
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
943
|
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
944
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
945
|
+
}
|
|
946
|
+
return hex.join("");
|
|
947
|
+
}
|
|
948
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
949
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
950
|
+
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
951
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
952
|
+
}
|
|
953
|
+
return hex.join("");
|
|
954
|
+
}
|
|
955
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
956
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
957
|
+
return hex.join("");
|
|
958
|
+
}
|
|
959
|
+
tinycolor.equals = function(color1, color2) {
|
|
960
|
+
if (!color1 || !color2) return false;
|
|
961
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
962
|
+
};
|
|
963
|
+
tinycolor.random = function() {
|
|
964
|
+
return tinycolor.fromRatio({
|
|
965
|
+
r: Math.random(),
|
|
966
|
+
g: Math.random(),
|
|
967
|
+
b: Math.random()
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
function _desaturate(color, amount) {
|
|
971
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
972
|
+
var hsl = tinycolor(color).toHsl();
|
|
973
|
+
hsl.s -= amount / 100;
|
|
974
|
+
hsl.s = clamp01(hsl.s);
|
|
975
|
+
return tinycolor(hsl);
|
|
976
|
+
}
|
|
977
|
+
function _saturate(color, amount) {
|
|
978
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
979
|
+
var hsl = tinycolor(color).toHsl();
|
|
980
|
+
hsl.s += amount / 100;
|
|
981
|
+
hsl.s = clamp01(hsl.s);
|
|
982
|
+
return tinycolor(hsl);
|
|
983
|
+
}
|
|
984
|
+
function _greyscale(color) {
|
|
985
|
+
return tinycolor(color).desaturate(100);
|
|
986
|
+
}
|
|
987
|
+
function _lighten(color, amount) {
|
|
988
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
989
|
+
var hsl = tinycolor(color).toHsl();
|
|
990
|
+
hsl.l += amount / 100;
|
|
991
|
+
hsl.l = clamp01(hsl.l);
|
|
992
|
+
return tinycolor(hsl);
|
|
993
|
+
}
|
|
994
|
+
function _brighten(color, amount) {
|
|
995
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
996
|
+
var rgb = tinycolor(color).toRgb();
|
|
997
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
998
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
999
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
1000
|
+
return tinycolor(rgb);
|
|
1001
|
+
}
|
|
1002
|
+
function _darken(color, amount) {
|
|
1003
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
1004
|
+
var hsl = tinycolor(color).toHsl();
|
|
1005
|
+
hsl.l -= amount / 100;
|
|
1006
|
+
hsl.l = clamp01(hsl.l);
|
|
1007
|
+
return tinycolor(hsl);
|
|
1008
|
+
}
|
|
1009
|
+
function _spin(color, amount) {
|
|
1010
|
+
var hsl = tinycolor(color).toHsl();
|
|
1011
|
+
var hue = (hsl.h + amount) % 360;
|
|
1012
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
1013
|
+
return tinycolor(hsl);
|
|
1014
|
+
}
|
|
1015
|
+
function _complement(color) {
|
|
1016
|
+
var hsl = tinycolor(color).toHsl();
|
|
1017
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
1018
|
+
return tinycolor(hsl);
|
|
1019
|
+
}
|
|
1020
|
+
function polyad(color, number) {
|
|
1021
|
+
if (isNaN(number) || number <= 0) {
|
|
1022
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
1023
|
+
}
|
|
1024
|
+
var hsl = tinycolor(color).toHsl();
|
|
1025
|
+
var result = [tinycolor(color)];
|
|
1026
|
+
var step = 360 / number;
|
|
1027
|
+
for (var i = 1; i < number; i++) {
|
|
1028
|
+
result.push(tinycolor({
|
|
1029
|
+
h: (hsl.h + i * step) % 360,
|
|
1030
|
+
s: hsl.s,
|
|
1031
|
+
l: hsl.l
|
|
1032
|
+
}));
|
|
1033
|
+
}
|
|
1034
|
+
return result;
|
|
1035
|
+
}
|
|
1036
|
+
function _splitcomplement(color) {
|
|
1037
|
+
var hsl = tinycolor(color).toHsl();
|
|
1038
|
+
var h = hsl.h;
|
|
1039
|
+
return [tinycolor(color), tinycolor({
|
|
1040
|
+
h: (h + 72) % 360,
|
|
1041
|
+
s: hsl.s,
|
|
1042
|
+
l: hsl.l
|
|
1043
|
+
}), tinycolor({
|
|
1044
|
+
h: (h + 216) % 360,
|
|
1045
|
+
s: hsl.s,
|
|
1046
|
+
l: hsl.l
|
|
1047
|
+
})];
|
|
1048
|
+
}
|
|
1049
|
+
function _analogous(color, results, slices) {
|
|
1050
|
+
results = results || 6;
|
|
1051
|
+
slices = slices || 30;
|
|
1052
|
+
var hsl = tinycolor(color).toHsl();
|
|
1053
|
+
var part = 360 / slices;
|
|
1054
|
+
var ret = [tinycolor(color)];
|
|
1055
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
1056
|
+
hsl.h = (hsl.h + part) % 360;
|
|
1057
|
+
ret.push(tinycolor(hsl));
|
|
1058
|
+
}
|
|
1059
|
+
return ret;
|
|
1060
|
+
}
|
|
1061
|
+
function _monochromatic(color, results) {
|
|
1062
|
+
results = results || 6;
|
|
1063
|
+
var hsv = tinycolor(color).toHsv();
|
|
1064
|
+
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
1065
|
+
var ret = [];
|
|
1066
|
+
var modification = 1 / results;
|
|
1067
|
+
while (results--) {
|
|
1068
|
+
ret.push(tinycolor({
|
|
1069
|
+
h,
|
|
1070
|
+
s,
|
|
1071
|
+
v
|
|
1072
|
+
}));
|
|
1073
|
+
v = (v + modification) % 1;
|
|
1074
|
+
}
|
|
1075
|
+
return ret;
|
|
1076
|
+
}
|
|
1077
|
+
tinycolor.mix = function(color1, color2, amount) {
|
|
1078
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
1079
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
1080
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
1081
|
+
var p = amount / 100;
|
|
1082
|
+
var rgba = {
|
|
1083
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
1084
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
1085
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
1086
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
1087
|
+
};
|
|
1088
|
+
return tinycolor(rgba);
|
|
1089
|
+
};
|
|
1090
|
+
tinycolor.readability = function(color1, color2) {
|
|
1091
|
+
var c1 = tinycolor(color1);
|
|
1092
|
+
var c2 = tinycolor(color2);
|
|
1093
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
1094
|
+
};
|
|
1095
|
+
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
1096
|
+
var readability = tinycolor.readability(color1, color2);
|
|
1097
|
+
var wcag2Parms, out;
|
|
1098
|
+
out = false;
|
|
1099
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
1100
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
1101
|
+
case "AAsmall":
|
|
1102
|
+
case "AAAlarge":
|
|
1103
|
+
out = readability >= 4.5;
|
|
1104
|
+
break;
|
|
1105
|
+
case "AAlarge":
|
|
1106
|
+
out = readability >= 3;
|
|
1107
|
+
break;
|
|
1108
|
+
case "AAAsmall":
|
|
1109
|
+
out = readability >= 7;
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
return out;
|
|
1113
|
+
};
|
|
1114
|
+
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
1115
|
+
var bestColor = null;
|
|
1116
|
+
var bestScore = 0;
|
|
1117
|
+
var readability;
|
|
1118
|
+
var includeFallbackColors, level, size;
|
|
1119
|
+
args = args || {};
|
|
1120
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
1121
|
+
level = args.level;
|
|
1122
|
+
size = args.size;
|
|
1123
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
1124
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
1125
|
+
if (readability > bestScore) {
|
|
1126
|
+
bestScore = readability;
|
|
1127
|
+
bestColor = tinycolor(colorList[i]);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
1131
|
+
level,
|
|
1132
|
+
size
|
|
1133
|
+
}) || !includeFallbackColors) {
|
|
1134
|
+
return bestColor;
|
|
1135
|
+
} else {
|
|
1136
|
+
args.includeFallbackColors = false;
|
|
1137
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
var names = tinycolor.names = {
|
|
1141
|
+
aliceblue: "f0f8ff",
|
|
1142
|
+
antiquewhite: "faebd7",
|
|
1143
|
+
aqua: "0ff",
|
|
1144
|
+
aquamarine: "7fffd4",
|
|
1145
|
+
azure: "f0ffff",
|
|
1146
|
+
beige: "f5f5dc",
|
|
1147
|
+
bisque: "ffe4c4",
|
|
1148
|
+
black: "000",
|
|
1149
|
+
blanchedalmond: "ffebcd",
|
|
1150
|
+
blue: "00f",
|
|
1151
|
+
blueviolet: "8a2be2",
|
|
1152
|
+
brown: "a52a2a",
|
|
1153
|
+
burlywood: "deb887",
|
|
1154
|
+
burntsienna: "ea7e5d",
|
|
1155
|
+
cadetblue: "5f9ea0",
|
|
1156
|
+
chartreuse: "7fff00",
|
|
1157
|
+
chocolate: "d2691e",
|
|
1158
|
+
coral: "ff7f50",
|
|
1159
|
+
cornflowerblue: "6495ed",
|
|
1160
|
+
cornsilk: "fff8dc",
|
|
1161
|
+
crimson: "dc143c",
|
|
1162
|
+
cyan: "0ff",
|
|
1163
|
+
darkblue: "00008b",
|
|
1164
|
+
darkcyan: "008b8b",
|
|
1165
|
+
darkgoldenrod: "b8860b",
|
|
1166
|
+
darkgray: "a9a9a9",
|
|
1167
|
+
darkgreen: "006400",
|
|
1168
|
+
darkgrey: "a9a9a9",
|
|
1169
|
+
darkkhaki: "bdb76b",
|
|
1170
|
+
darkmagenta: "8b008b",
|
|
1171
|
+
darkolivegreen: "556b2f",
|
|
1172
|
+
darkorange: "ff8c00",
|
|
1173
|
+
darkorchid: "9932cc",
|
|
1174
|
+
darkred: "8b0000",
|
|
1175
|
+
darksalmon: "e9967a",
|
|
1176
|
+
darkseagreen: "8fbc8f",
|
|
1177
|
+
darkslateblue: "483d8b",
|
|
1178
|
+
darkslategray: "2f4f4f",
|
|
1179
|
+
darkslategrey: "2f4f4f",
|
|
1180
|
+
darkturquoise: "00ced1",
|
|
1181
|
+
darkviolet: "9400d3",
|
|
1182
|
+
deeppink: "ff1493",
|
|
1183
|
+
deepskyblue: "00bfff",
|
|
1184
|
+
dimgray: "696969",
|
|
1185
|
+
dimgrey: "696969",
|
|
1186
|
+
dodgerblue: "1e90ff",
|
|
1187
|
+
firebrick: "b22222",
|
|
1188
|
+
floralwhite: "fffaf0",
|
|
1189
|
+
forestgreen: "228b22",
|
|
1190
|
+
fuchsia: "f0f",
|
|
1191
|
+
gainsboro: "dcdcdc",
|
|
1192
|
+
ghostwhite: "f8f8ff",
|
|
1193
|
+
gold: "ffd700",
|
|
1194
|
+
goldenrod: "daa520",
|
|
1195
|
+
gray: "808080",
|
|
1196
|
+
green: "008000",
|
|
1197
|
+
greenyellow: "adff2f",
|
|
1198
|
+
grey: "808080",
|
|
1199
|
+
honeydew: "f0fff0",
|
|
1200
|
+
hotpink: "ff69b4",
|
|
1201
|
+
indianred: "cd5c5c",
|
|
1202
|
+
indigo: "4b0082",
|
|
1203
|
+
ivory: "fffff0",
|
|
1204
|
+
khaki: "f0e68c",
|
|
1205
|
+
lavender: "e6e6fa",
|
|
1206
|
+
lavenderblush: "fff0f5",
|
|
1207
|
+
lawngreen: "7cfc00",
|
|
1208
|
+
lemonchiffon: "fffacd",
|
|
1209
|
+
lightblue: "add8e6",
|
|
1210
|
+
lightcoral: "f08080",
|
|
1211
|
+
lightcyan: "e0ffff",
|
|
1212
|
+
lightgoldenrodyellow: "fafad2",
|
|
1213
|
+
lightgray: "d3d3d3",
|
|
1214
|
+
lightgreen: "90ee90",
|
|
1215
|
+
lightgrey: "d3d3d3",
|
|
1216
|
+
lightpink: "ffb6c1",
|
|
1217
|
+
lightsalmon: "ffa07a",
|
|
1218
|
+
lightseagreen: "20b2aa",
|
|
1219
|
+
lightskyblue: "87cefa",
|
|
1220
|
+
lightslategray: "789",
|
|
1221
|
+
lightslategrey: "789",
|
|
1222
|
+
lightsteelblue: "b0c4de",
|
|
1223
|
+
lightyellow: "ffffe0",
|
|
1224
|
+
lime: "0f0",
|
|
1225
|
+
limegreen: "32cd32",
|
|
1226
|
+
linen: "faf0e6",
|
|
1227
|
+
magenta: "f0f",
|
|
1228
|
+
maroon: "800000",
|
|
1229
|
+
mediumaquamarine: "66cdaa",
|
|
1230
|
+
mediumblue: "0000cd",
|
|
1231
|
+
mediumorchid: "ba55d3",
|
|
1232
|
+
mediumpurple: "9370db",
|
|
1233
|
+
mediumseagreen: "3cb371",
|
|
1234
|
+
mediumslateblue: "7b68ee",
|
|
1235
|
+
mediumspringgreen: "00fa9a",
|
|
1236
|
+
mediumturquoise: "48d1cc",
|
|
1237
|
+
mediumvioletred: "c71585",
|
|
1238
|
+
midnightblue: "191970",
|
|
1239
|
+
mintcream: "f5fffa",
|
|
1240
|
+
mistyrose: "ffe4e1",
|
|
1241
|
+
moccasin: "ffe4b5",
|
|
1242
|
+
navajowhite: "ffdead",
|
|
1243
|
+
navy: "000080",
|
|
1244
|
+
oldlace: "fdf5e6",
|
|
1245
|
+
olive: "808000",
|
|
1246
|
+
olivedrab: "6b8e23",
|
|
1247
|
+
orange: "ffa500",
|
|
1248
|
+
orangered: "ff4500",
|
|
1249
|
+
orchid: "da70d6",
|
|
1250
|
+
palegoldenrod: "eee8aa",
|
|
1251
|
+
palegreen: "98fb98",
|
|
1252
|
+
paleturquoise: "afeeee",
|
|
1253
|
+
palevioletred: "db7093",
|
|
1254
|
+
papayawhip: "ffefd5",
|
|
1255
|
+
peachpuff: "ffdab9",
|
|
1256
|
+
peru: "cd853f",
|
|
1257
|
+
pink: "ffc0cb",
|
|
1258
|
+
plum: "dda0dd",
|
|
1259
|
+
powderblue: "b0e0e6",
|
|
1260
|
+
purple: "800080",
|
|
1261
|
+
rebeccapurple: "663399",
|
|
1262
|
+
red: "f00",
|
|
1263
|
+
rosybrown: "bc8f8f",
|
|
1264
|
+
royalblue: "4169e1",
|
|
1265
|
+
saddlebrown: "8b4513",
|
|
1266
|
+
salmon: "fa8072",
|
|
1267
|
+
sandybrown: "f4a460",
|
|
1268
|
+
seagreen: "2e8b57",
|
|
1269
|
+
seashell: "fff5ee",
|
|
1270
|
+
sienna: "a0522d",
|
|
1271
|
+
silver: "c0c0c0",
|
|
1272
|
+
skyblue: "87ceeb",
|
|
1273
|
+
slateblue: "6a5acd",
|
|
1274
|
+
slategray: "708090",
|
|
1275
|
+
slategrey: "708090",
|
|
1276
|
+
snow: "fffafa",
|
|
1277
|
+
springgreen: "00ff7f",
|
|
1278
|
+
steelblue: "4682b4",
|
|
1279
|
+
tan: "d2b48c",
|
|
1280
|
+
teal: "008080",
|
|
1281
|
+
thistle: "d8bfd8",
|
|
1282
|
+
tomato: "ff6347",
|
|
1283
|
+
turquoise: "40e0d0",
|
|
1284
|
+
violet: "ee82ee",
|
|
1285
|
+
wheat: "f5deb3",
|
|
1286
|
+
white: "fff",
|
|
1287
|
+
whitesmoke: "f5f5f5",
|
|
1288
|
+
yellow: "ff0",
|
|
1289
|
+
yellowgreen: "9acd32"
|
|
1290
|
+
};
|
|
1291
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
1292
|
+
function flip(o) {
|
|
1293
|
+
var flipped = {};
|
|
1294
|
+
for (var i in o) {
|
|
1295
|
+
if (o.hasOwnProperty(i)) {
|
|
1296
|
+
flipped[o[i]] = i;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return flipped;
|
|
1300
|
+
}
|
|
1301
|
+
function boundAlpha(a) {
|
|
1302
|
+
a = parseFloat(a);
|
|
1303
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
1304
|
+
a = 1;
|
|
1305
|
+
}
|
|
1306
|
+
return a;
|
|
1307
|
+
}
|
|
1308
|
+
function bound01(n, max) {
|
|
1309
|
+
if (isOnePointZero(n)) n = "100%";
|
|
1310
|
+
var processPercent = isPercentage(n);
|
|
1311
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1312
|
+
if (processPercent) {
|
|
1313
|
+
n = parseInt(n * max, 10) / 100;
|
|
1314
|
+
}
|
|
1315
|
+
if (Math.abs(n - max) < 1e-6) {
|
|
1316
|
+
return 1;
|
|
1317
|
+
}
|
|
1318
|
+
return n % max / parseFloat(max);
|
|
1319
|
+
}
|
|
1320
|
+
function clamp01(val) {
|
|
1321
|
+
return Math.min(1, Math.max(0, val));
|
|
1322
|
+
}
|
|
1323
|
+
function parseIntFromHex(val) {
|
|
1324
|
+
return parseInt(val, 16);
|
|
1325
|
+
}
|
|
1326
|
+
function isOnePointZero(n) {
|
|
1327
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1328
|
+
}
|
|
1329
|
+
function isPercentage(n) {
|
|
1330
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1331
|
+
}
|
|
1332
|
+
function pad2(c) {
|
|
1333
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
1334
|
+
}
|
|
1335
|
+
function convertToPercentage(n) {
|
|
1336
|
+
if (n <= 1) {
|
|
1337
|
+
n = n * 100 + "%";
|
|
1338
|
+
}
|
|
1339
|
+
return n;
|
|
1340
|
+
}
|
|
1341
|
+
function convertDecimalToHex(d) {
|
|
1342
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1343
|
+
}
|
|
1344
|
+
function convertHexToDecimal(h) {
|
|
1345
|
+
return parseIntFromHex(h) / 255;
|
|
1346
|
+
}
|
|
1347
|
+
var matchers = (function() {
|
|
1348
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1349
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1350
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1351
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1352
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1353
|
+
return {
|
|
1354
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1355
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1356
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1357
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1358
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1359
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1360
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1361
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1362
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1363
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1364
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1365
|
+
};
|
|
1366
|
+
})();
|
|
1367
|
+
function isValidCSSUnit(color) {
|
|
1368
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
1369
|
+
}
|
|
1370
|
+
function stringInputToObject(color) {
|
|
1371
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1372
|
+
var named = false;
|
|
1373
|
+
if (names[color]) {
|
|
1374
|
+
color = names[color];
|
|
1375
|
+
named = true;
|
|
1376
|
+
} else if (color == "transparent") {
|
|
1377
|
+
return {
|
|
1378
|
+
r: 0,
|
|
1379
|
+
g: 0,
|
|
1380
|
+
b: 0,
|
|
1381
|
+
a: 0,
|
|
1382
|
+
format: "name"
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
var match;
|
|
1386
|
+
if (match = matchers.rgb.exec(color)) {
|
|
1387
|
+
return {
|
|
1388
|
+
r: match[1],
|
|
1389
|
+
g: match[2],
|
|
1390
|
+
b: match[3]
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
if (match = matchers.rgba.exec(color)) {
|
|
1394
|
+
return {
|
|
1395
|
+
r: match[1],
|
|
1396
|
+
g: match[2],
|
|
1397
|
+
b: match[3],
|
|
1398
|
+
a: match[4]
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
if (match = matchers.hsl.exec(color)) {
|
|
1402
|
+
return {
|
|
1403
|
+
h: match[1],
|
|
1404
|
+
s: match[2],
|
|
1405
|
+
l: match[3]
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
if (match = matchers.hsla.exec(color)) {
|
|
1409
|
+
return {
|
|
1410
|
+
h: match[1],
|
|
1411
|
+
s: match[2],
|
|
1412
|
+
l: match[3],
|
|
1413
|
+
a: match[4]
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
if (match = matchers.hsv.exec(color)) {
|
|
1417
|
+
return {
|
|
1418
|
+
h: match[1],
|
|
1419
|
+
s: match[2],
|
|
1420
|
+
v: match[3]
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
if (match = matchers.hsva.exec(color)) {
|
|
1424
|
+
return {
|
|
1425
|
+
h: match[1],
|
|
1426
|
+
s: match[2],
|
|
1427
|
+
v: match[3],
|
|
1428
|
+
a: match[4]
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
if (match = matchers.hex8.exec(color)) {
|
|
1432
|
+
return {
|
|
1433
|
+
r: parseIntFromHex(match[1]),
|
|
1434
|
+
g: parseIntFromHex(match[2]),
|
|
1435
|
+
b: parseIntFromHex(match[3]),
|
|
1436
|
+
a: convertHexToDecimal(match[4]),
|
|
1437
|
+
format: named ? "name" : "hex8"
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
if (match = matchers.hex6.exec(color)) {
|
|
1441
|
+
return {
|
|
1442
|
+
r: parseIntFromHex(match[1]),
|
|
1443
|
+
g: parseIntFromHex(match[2]),
|
|
1444
|
+
b: parseIntFromHex(match[3]),
|
|
1445
|
+
format: named ? "name" : "hex"
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
if (match = matchers.hex4.exec(color)) {
|
|
1449
|
+
return {
|
|
1450
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1451
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1452
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1453
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1454
|
+
format: named ? "name" : "hex8"
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
if (match = matchers.hex3.exec(color)) {
|
|
1458
|
+
return {
|
|
1459
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1460
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1461
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1462
|
+
format: named ? "name" : "hex"
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
return false;
|
|
1466
|
+
}
|
|
1467
|
+
function validateWCAG2Parms(parms) {
|
|
1468
|
+
var level, size;
|
|
1469
|
+
parms = parms || {
|
|
1470
|
+
level: "AA",
|
|
1471
|
+
size: "small"
|
|
1472
|
+
};
|
|
1473
|
+
level = (parms.level || "AA").toUpperCase();
|
|
1474
|
+
size = (parms.size || "small").toLowerCase();
|
|
1475
|
+
if (level !== "AA" && level !== "AAA") {
|
|
1476
|
+
level = "AA";
|
|
1477
|
+
}
|
|
1478
|
+
if (size !== "small" && size !== "large") {
|
|
1479
|
+
size = "small";
|
|
1480
|
+
}
|
|
1481
|
+
return {
|
|
1482
|
+
level,
|
|
1483
|
+
size
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
const INDEX_COLUMN_WIDTH = 68;
|
|
1487
|
+
const TABLE_FONT_FAMILY = 'Aptos, Calibri, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif';
|
|
1488
|
+
const TABLE_FONT_SIZE = 11;
|
|
1489
|
+
const MIN_RENDERABLE_ROW_HEIGHT = 8;
|
|
1490
|
+
const HIDDEN_ROW_HEIGHT = 0.1;
|
|
1491
|
+
const CELL_PADDING = 2;
|
|
1492
|
+
const CELL_LINE_HEIGHT = 1.2;
|
|
1493
|
+
const HEADER_HEIGHT = 34;
|
|
1494
|
+
const RESIZABLE_COLUMN_MIN_WIDTH = 40;
|
|
1495
|
+
const RESIZABLE_ROW_MIN_HEIGHT = 18;
|
|
1496
|
+
const EXCEL_HEADER_BG = "#f3f3f3";
|
|
1497
|
+
const EXCEL_HEADER_TEXT = "#5f6368";
|
|
1498
|
+
const EXCEL_GRID = "#d7dbe0";
|
|
1499
|
+
const EXCEL_DARK_HEADER_BG = "#1f2937";
|
|
1500
|
+
const EXCEL_DARK_HEADER_TEXT = "#cbd5e1";
|
|
1501
|
+
const EXCEL_DARK_GRID = "#374151";
|
|
1502
|
+
const EXCEL_DARK_BODY_BG = "#111827";
|
|
1503
|
+
const EXCEL_DARK_BODY_TEXT = "#e5e7eb";
|
|
1504
|
+
const EXCEL_GREEN = "#21a366";
|
|
1505
|
+
const EXCEL_GREEN_SOFT = "rgba(33, 163, 102, 0.1)";
|
|
1506
|
+
const DATA_AREA_MIN_COL_INDEX = 1;
|
|
1507
|
+
const DEFAULT_BORDER_COLOR = "#000000";
|
|
1508
|
+
const BORDER_STYLE_PRIORITY = {
|
|
1509
|
+
double: 8,
|
|
1510
|
+
solid: 7,
|
|
1511
|
+
dashed: 5,
|
|
1512
|
+
dotted: 4
|
|
1513
|
+
};
|
|
1514
|
+
const HEADER_FONT = `bold 12px ${TABLE_FONT_FAMILY}`;
|
|
1515
|
+
const BODY_FONT = `${TABLE_FONT_SIZE}px ${TABLE_FONT_FAMILY}`;
|
|
1516
|
+
const MAX_OVERFLOW_SCAN_COLS = 32;
|
|
1517
|
+
let measureCanvas;
|
|
1518
|
+
const textWidthCache = /* @__PURE__ */ new Map();
|
|
1519
|
+
const normalizeZoomScale = (scale = 1) => {
|
|
1520
|
+
return Number.isFinite(scale) ? Math.min(2.5, Math.max(0.5, scale)) : 1;
|
|
1521
|
+
};
|
|
1522
|
+
const scaleNumber = (value, zoomScale) => {
|
|
1523
|
+
return Math.max(1, Math.round(value * normalizeZoomScale(zoomScale)));
|
|
1524
|
+
};
|
|
1525
|
+
const scaleFont = (font, zoomScale) => {
|
|
1526
|
+
if (!font) {
|
|
1527
|
+
return font;
|
|
1528
|
+
}
|
|
1529
|
+
const normalizedScale = normalizeZoomScale(zoomScale);
|
|
1530
|
+
return font.replace(/(\d+(?:\.\d+)?)px/g, (_, size) => {
|
|
1531
|
+
return `${Number(size) * normalizedScale}px`;
|
|
1532
|
+
});
|
|
1533
|
+
};
|
|
1534
|
+
const scaleBorder = (border, zoomScale) => {
|
|
1535
|
+
if (!border) {
|
|
1536
|
+
return void 0;
|
|
1537
|
+
}
|
|
1538
|
+
return {
|
|
1539
|
+
...border,
|
|
1540
|
+
width: Math.max(0.5, border.width * normalizeZoomScale(zoomScale))
|
|
1541
|
+
};
|
|
1542
|
+
};
|
|
1543
|
+
const scaleCellStyle = (style, zoomScale) => {
|
|
1544
|
+
if (!style) {
|
|
1545
|
+
return void 0;
|
|
1546
|
+
}
|
|
1547
|
+
return {
|
|
1548
|
+
...style,
|
|
1549
|
+
font: scaleFont(style.font, zoomScale),
|
|
1550
|
+
borderTop: scaleBorder(style.borderTop, zoomScale),
|
|
1551
|
+
borderRight: scaleBorder(style.borderRight, zoomScale),
|
|
1552
|
+
borderBottom: scaleBorder(style.borderBottom, zoomScale),
|
|
1553
|
+
borderLeft: scaleBorder(style.borderLeft, zoomScale)
|
|
1554
|
+
};
|
|
1555
|
+
};
|
|
1556
|
+
const getHeaderFont = (zoomScale) => scaleFont(HEADER_FONT, zoomScale) || HEADER_FONT;
|
|
1557
|
+
const getBodyFont = (zoomScale) => scaleFont(BODY_FONT, zoomScale) || BODY_FONT;
|
|
1558
|
+
const getIndexCellStyle = (zoomScale, darkMode = false) => ({
|
|
1559
|
+
backgroundColor: darkMode ? EXCEL_DARK_HEADER_BG : EXCEL_HEADER_BG,
|
|
1560
|
+
color: darkMode ? EXCEL_DARK_HEADER_TEXT : EXCEL_HEADER_TEXT,
|
|
1561
|
+
font: getHeaderFont(zoomScale)
|
|
1562
|
+
});
|
|
1563
|
+
const getLoadingCellStyle = (zoomScale, darkMode = false) => ({
|
|
1564
|
+
backgroundColor: darkMode ? "#18212f" : "#f4f7f9",
|
|
1565
|
+
color: darkMode ? "#94a3b8" : "#73808d",
|
|
1566
|
+
font: scaleFont(`italic ${TABLE_FONT_SIZE}px ${TABLE_FONT_FAMILY}`, zoomScale)
|
|
1567
|
+
});
|
|
1568
|
+
const cloneColumns = (columns) => {
|
|
1569
|
+
return columns.map((column) => {
|
|
1570
|
+
var _a;
|
|
1571
|
+
return {
|
|
1572
|
+
...column,
|
|
1573
|
+
...((_a = column.children) === null || _a === void 0 ? void 0 : _a.length) ? { children: cloneColumns(column.children) } : {}
|
|
1574
|
+
};
|
|
1575
|
+
});
|
|
1576
|
+
};
|
|
1577
|
+
const buildFont = (style) => {
|
|
1578
|
+
if (typeof style.font === "string" && style.font.trim()) {
|
|
1579
|
+
return style.font;
|
|
1580
|
+
}
|
|
1581
|
+
const hasFont = style.fontFamily !== void 0 || style.fontSize !== void 0 || style.fontWeight !== void 0 || style.fontStyle !== void 0;
|
|
1582
|
+
if (!hasFont) {
|
|
1583
|
+
return void 0;
|
|
1584
|
+
}
|
|
1585
|
+
const normalizedWeight = (() => {
|
|
1586
|
+
const { fontWeight } = style;
|
|
1587
|
+
if (typeof fontWeight === "number") {
|
|
1588
|
+
return fontWeight >= 600 ? "bold" : "normal";
|
|
1589
|
+
}
|
|
1590
|
+
if (typeof fontWeight === "string") {
|
|
1591
|
+
const trimmed = fontWeight.trim();
|
|
1592
|
+
if (/^\d+$/.test(trimmed)) {
|
|
1593
|
+
return Number(trimmed) >= 600 ? "bold" : "normal";
|
|
1594
|
+
}
|
|
1595
|
+
return trimmed;
|
|
1596
|
+
}
|
|
1597
|
+
return "normal";
|
|
1598
|
+
})();
|
|
1599
|
+
return [
|
|
1600
|
+
style.fontStyle || "normal",
|
|
1601
|
+
normalizedWeight,
|
|
1602
|
+
`${Number.parseInt(style.fontSize, 10) || TABLE_FONT_SIZE}px`,
|
|
1603
|
+
style.fontFamily || TABLE_FONT_FAMILY
|
|
1604
|
+
].join(" ");
|
|
1605
|
+
};
|
|
1606
|
+
const alignFromClassName = (className) => {
|
|
1607
|
+
if (!className) {
|
|
1608
|
+
return void 0;
|
|
1609
|
+
}
|
|
1610
|
+
if (className.includes("htLeft")) {
|
|
1611
|
+
return "left";
|
|
1612
|
+
}
|
|
1613
|
+
if (className.includes("htRight")) {
|
|
1614
|
+
return "right";
|
|
1615
|
+
}
|
|
1616
|
+
if (className.includes("htCenter")) {
|
|
1617
|
+
return "center";
|
|
1618
|
+
}
|
|
1619
|
+
return void 0;
|
|
1620
|
+
};
|
|
1621
|
+
const verticalAlignFromClassName = (className) => {
|
|
1622
|
+
if (!className) {
|
|
1623
|
+
return void 0;
|
|
1624
|
+
}
|
|
1625
|
+
if (className.includes("htTop")) {
|
|
1626
|
+
return "top";
|
|
1627
|
+
}
|
|
1628
|
+
if (className.includes("htBottom")) {
|
|
1629
|
+
return "bottom";
|
|
1630
|
+
}
|
|
1631
|
+
if (className.includes("htMiddle")) {
|
|
1632
|
+
return "middle";
|
|
1633
|
+
}
|
|
1634
|
+
return void 0;
|
|
1635
|
+
};
|
|
1636
|
+
const hasClassName = (className, value) => {
|
|
1637
|
+
return !!(className === null || className === void 0 ? void 0 : className.split(/\s+/).includes(value));
|
|
1638
|
+
};
|
|
1639
|
+
const getColumnWidth = (widths, index, fallback) => {
|
|
1640
|
+
var _a;
|
|
1641
|
+
if (typeof widths === "number") {
|
|
1642
|
+
return widths;
|
|
1643
|
+
}
|
|
1644
|
+
return (_a = widths === null || widths === void 0 ? void 0 : widths[index]) !== null && _a !== void 0 ? _a : fallback;
|
|
1645
|
+
};
|
|
1646
|
+
const getRenderColumnWidth = (column) => {
|
|
1647
|
+
const width = Number(column === null || column === void 0 ? void 0 : column.width);
|
|
1648
|
+
return Number.isFinite(width) && width > 0 ? width : 0;
|
|
1649
|
+
};
|
|
1650
|
+
const isVisibleDataColumn = (column) => {
|
|
1651
|
+
return !!column && !column.hide && getRenderColumnWidth(column) > 0;
|
|
1652
|
+
};
|
|
1653
|
+
const getSheetColumnsMeta = (ws) => {
|
|
1654
|
+
var _a, _b;
|
|
1655
|
+
return ((_b = (_a = ws.structure) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.length) ? ws.structure.columns : ws.columns;
|
|
1656
|
+
};
|
|
1657
|
+
const getSheetColWidths = (ws) => {
|
|
1658
|
+
var _a, _b;
|
|
1659
|
+
return (_b = (_a = ws.structure) === null || _a === void 0 ? void 0 : _a.colWidths) !== null && _b !== void 0 ? _b : ws.colWidths;
|
|
1660
|
+
};
|
|
1661
|
+
const getRowHeight = (heights, index, fallback) => {
|
|
1662
|
+
var _a;
|
|
1663
|
+
if (typeof heights === "number") {
|
|
1664
|
+
return heights;
|
|
1665
|
+
}
|
|
1666
|
+
return (_a = heights === null || heights === void 0 ? void 0 : heights[index]) !== null && _a !== void 0 ? _a : fallback;
|
|
1667
|
+
};
|
|
1668
|
+
const normalizeRowHeight = (height, fallback) => {
|
|
1669
|
+
if (typeof height === "number" && Number.isFinite(height)) {
|
|
1670
|
+
if (height <= 0) {
|
|
1671
|
+
return HIDDEN_ROW_HEIGHT;
|
|
1672
|
+
}
|
|
1673
|
+
return Math.max(Math.ceil(height), MIN_RENDERABLE_ROW_HEIGHT);
|
|
1674
|
+
}
|
|
1675
|
+
return Math.max(Math.ceil(fallback), MIN_RENDERABLE_ROW_HEIGHT);
|
|
1676
|
+
};
|
|
1677
|
+
const isPlainTextCell = (value) => {
|
|
1678
|
+
if (value === null || value === void 0) {
|
|
1679
|
+
return false;
|
|
1680
|
+
}
|
|
1681
|
+
const text = `${value}`.trim();
|
|
1682
|
+
if (!text) {
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
return !/^\d+([./:-]\d+)*$/.test(text);
|
|
1686
|
+
};
|
|
1687
|
+
const detectIndexOffset = (ws) => {
|
|
1688
|
+
const meta = ws.meta;
|
|
1689
|
+
const rows = ws.data || [];
|
|
1690
|
+
if (!meta || rows.length < 2 || (ws.merge || []).length) {
|
|
1691
|
+
return 0;
|
|
1692
|
+
}
|
|
1693
|
+
const firstRow = rows[0] || [];
|
|
1694
|
+
const secondRow = rows[1] || [];
|
|
1695
|
+
const firstRowValues = firstRow.filter((value) => `${value !== null && value !== void 0 ? value : ""}`.trim() !== "");
|
|
1696
|
+
const secondRowValues = secondRow.filter((value) => `${value !== null && value !== void 0 ? value : ""}`.trim() !== "");
|
|
1697
|
+
if (firstRowValues.length < Math.min(Math.max(Math.floor(meta.totalCols / 2), 3), 6)) {
|
|
1698
|
+
return 0;
|
|
1699
|
+
}
|
|
1700
|
+
if (!firstRowValues.every(isPlainTextCell) || secondRowValues.length < 2) {
|
|
1701
|
+
return 0;
|
|
1702
|
+
}
|
|
1703
|
+
return 1;
|
|
1704
|
+
};
|
|
1705
|
+
const buildColumns = (ws) => {
|
|
1706
|
+
var _a;
|
|
1707
|
+
const columnsMeta = getSheetColumnsMeta(ws);
|
|
1708
|
+
const colWidths = getSheetColWidths(ws);
|
|
1709
|
+
const columns = [{
|
|
1710
|
+
key: INDEX_COLUMN_KEY,
|
|
1711
|
+
title: "",
|
|
1712
|
+
type: "index",
|
|
1713
|
+
fixed: "left",
|
|
1714
|
+
width: INDEX_COLUMN_WIDTH,
|
|
1715
|
+
minWidth: INDEX_COLUMN_WIDTH,
|
|
1716
|
+
maxWidth: INDEX_COLUMN_WIDTH,
|
|
1717
|
+
widthFillDisable: true,
|
|
1718
|
+
headerAlign: "center",
|
|
1719
|
+
align: "center",
|
|
1720
|
+
headerVerticalAlign: "middle",
|
|
1721
|
+
verticalAlign: "middle",
|
|
1722
|
+
overflowTooltipShow: false,
|
|
1723
|
+
overflowTooltipHeaderShow: false
|
|
1724
|
+
}];
|
|
1725
|
+
const dataKeys = [];
|
|
1726
|
+
for (let index = 0; index < (((_a = ws.meta) === null || _a === void 0 ? void 0 : _a.totalCols) || 0); index += 1) {
|
|
1727
|
+
const key = getDataKey(index);
|
|
1728
|
+
const column = columnsMeta === null || columnsMeta === void 0 ? void 0 : columnsMeta[index];
|
|
1729
|
+
const width = getColumnWidth(colWidths, index, ws.defaults.colWidth);
|
|
1730
|
+
const hidden = !!(column === null || column === void 0 ? void 0 : column.hidden) || width <= 0;
|
|
1731
|
+
const columnVerticalAlign = verticalAlignFromClassName(column === null || column === void 0 ? void 0 : column.className) || "middle";
|
|
1732
|
+
dataKeys.push(key);
|
|
1733
|
+
columns.push({
|
|
1734
|
+
key,
|
|
1735
|
+
title: (column === null || column === void 0 ? void 0 : column.title) || `${index + 1}`,
|
|
1736
|
+
width: hidden ? 0 : Math.max(Math.ceil(width), 1),
|
|
1737
|
+
hide: hidden,
|
|
1738
|
+
widthFillDisable: true,
|
|
1739
|
+
renderType: "both",
|
|
1740
|
+
headerAlign: "center",
|
|
1741
|
+
headerVerticalAlign: "middle",
|
|
1742
|
+
align: alignFromClassName(column === null || column === void 0 ? void 0 : column.className) || "left",
|
|
1743
|
+
verticalAlign: columnVerticalAlign,
|
|
1744
|
+
overflowTooltipShow: true,
|
|
1745
|
+
overflowTooltipHeaderShow: true
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
return { columns, dataKeys };
|
|
1749
|
+
};
|
|
1750
|
+
const scaleColumn = (column, zoomScale) => {
|
|
1751
|
+
var _a;
|
|
1752
|
+
const nextColumn = {
|
|
1753
|
+
...column,
|
|
1754
|
+
...((_a = column.children) === null || _a === void 0 ? void 0 : _a.length) ? { children: column.children.map((child) => scaleColumn(child, zoomScale)) } : {}
|
|
1755
|
+
};
|
|
1756
|
+
const width = Number(column.width);
|
|
1757
|
+
if (Number.isFinite(width) && width > 0) {
|
|
1758
|
+
nextColumn.width = scaleNumber(width, zoomScale);
|
|
1759
|
+
}
|
|
1760
|
+
const minWidth = Number(column.minWidth);
|
|
1761
|
+
if (Number.isFinite(minWidth) && minWidth > 0) {
|
|
1762
|
+
nextColumn.minWidth = scaleNumber(minWidth, zoomScale);
|
|
1763
|
+
}
|
|
1764
|
+
const maxWidth = Number(column.maxWidth);
|
|
1765
|
+
if (Number.isFinite(maxWidth) && maxWidth > 0) {
|
|
1766
|
+
nextColumn.maxWidth = scaleNumber(maxWidth, zoomScale);
|
|
1767
|
+
}
|
|
1768
|
+
return nextColumn;
|
|
1769
|
+
};
|
|
1770
|
+
const getDisplayColumns = (columns, zoomScale = 1) => {
|
|
1771
|
+
const normalizedScale = normalizeZoomScale(zoomScale);
|
|
1772
|
+
if (normalizedScale === 1) {
|
|
1773
|
+
return cloneColumns(columns);
|
|
1774
|
+
}
|
|
1775
|
+
return columns.map((column) => scaleColumn(column, normalizedScale));
|
|
1776
|
+
};
|
|
1777
|
+
const toBorderWidth = (value) => {
|
|
1778
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1779
|
+
return Math.max(value, 0);
|
|
1780
|
+
}
|
|
1781
|
+
if (typeof value === "string") {
|
|
1782
|
+
const parsed = Number.parseFloat(value);
|
|
1783
|
+
return Number.isFinite(parsed) ? Math.max(parsed, 0) : 0;
|
|
1784
|
+
}
|
|
1785
|
+
return 0;
|
|
1786
|
+
};
|
|
1787
|
+
const toBorderStyle = (value) => {
|
|
1788
|
+
if (typeof value !== "string") {
|
|
1789
|
+
return "solid";
|
|
1790
|
+
}
|
|
1791
|
+
const style = value.trim();
|
|
1792
|
+
switch (style) {
|
|
1793
|
+
case "double":
|
|
1794
|
+
case "dashed":
|
|
1795
|
+
case "dotted":
|
|
1796
|
+
case "solid":
|
|
1797
|
+
return style;
|
|
1798
|
+
default:
|
|
1799
|
+
return "solid";
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
const getBorderSide = (style, side) => {
|
|
1803
|
+
const width = toBorderWidth(style[`border${side}Width`]);
|
|
1804
|
+
if (!width) {
|
|
1805
|
+
return void 0;
|
|
1806
|
+
}
|
|
1807
|
+
return {
|
|
1808
|
+
width,
|
|
1809
|
+
style: toBorderStyle(style[`border${side}Style`]),
|
|
1810
|
+
color: style[`border${side}Color`] || DEFAULT_BORDER_COLOR
|
|
1811
|
+
};
|
|
1812
|
+
};
|
|
1813
|
+
const hasBorder = (style) => {
|
|
1814
|
+
if (!style) {
|
|
1815
|
+
return false;
|
|
1816
|
+
}
|
|
1817
|
+
return !!(style.borderTop || style.borderRight || style.borderBottom || style.borderLeft);
|
|
1818
|
+
};
|
|
1819
|
+
const hasTextLayout = (style) => {
|
|
1820
|
+
if (!style) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
return !!(style.horizontalAlign || style.verticalAlign || style.wrapText || style.shrinkToFit);
|
|
1824
|
+
};
|
|
1825
|
+
const shouldRenderTextInOverlay = (style, column) => {
|
|
1826
|
+
if (!hasTextLayout(style)) {
|
|
1827
|
+
return false;
|
|
1828
|
+
}
|
|
1829
|
+
return !!((style === null || style === void 0 ? void 0 : style.wrapText) || (style === null || style === void 0 ? void 0 : style.shrinkToFit) || (style === null || style === void 0 ? void 0 : style.horizontalAlign) && style.horizontalAlign !== ((column === null || column === void 0 ? void 0 : column.align) || "left") || (style === null || style === void 0 ? void 0 : style.verticalAlign) && style.verticalAlign !== ((column === null || column === void 0 ? void 0 : column.verticalAlign) || "middle"));
|
|
1830
|
+
};
|
|
1831
|
+
const toFlexJustify = (align) => {
|
|
1832
|
+
switch (align) {
|
|
1833
|
+
case "center":
|
|
1834
|
+
return "center";
|
|
1835
|
+
case "right":
|
|
1836
|
+
return "flex-end";
|
|
1837
|
+
default:
|
|
1838
|
+
return "flex-start";
|
|
1839
|
+
}
|
|
1840
|
+
};
|
|
1841
|
+
const toFlexAlign = (verticalAlign) => {
|
|
1842
|
+
switch (verticalAlign) {
|
|
1843
|
+
case "top":
|
|
1844
|
+
return "flex-start";
|
|
1845
|
+
case "bottom":
|
|
1846
|
+
return "flex-end";
|
|
1847
|
+
default:
|
|
1848
|
+
return "center";
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
const toTextLayerLeft = (align, ownWidth, overflowWidth, leftRoom) => {
|
|
1852
|
+
switch (align) {
|
|
1853
|
+
case "right":
|
|
1854
|
+
return ownWidth - overflowWidth;
|
|
1855
|
+
case "center":
|
|
1856
|
+
return -Math.min(leftRoom, Math.max((overflowWidth - ownWidth) / 2, 0));
|
|
1857
|
+
default:
|
|
1858
|
+
return 0;
|
|
1859
|
+
}
|
|
1860
|
+
};
|
|
1861
|
+
const isHiddenVirtualRow = (row) => {
|
|
1862
|
+
return typeof row._height === "number" && row._height <= HIDDEN_ROW_HEIGHT;
|
|
1863
|
+
};
|
|
1864
|
+
const getDataColumnIndex = (column, fallbackColIndex) => {
|
|
1865
|
+
const key = column === null || column === void 0 ? void 0 : column.key;
|
|
1866
|
+
if (typeof key === "string" && key.startsWith("c")) {
|
|
1867
|
+
const index = Number(key.slice(1));
|
|
1868
|
+
if (Number.isInteger(index) && index >= 0) {
|
|
1869
|
+
return index;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return Math.max(fallbackColIndex - 1, 0);
|
|
1873
|
+
};
|
|
1874
|
+
const getCellCacheKey = (rowIndex, colIndex, column) => {
|
|
1875
|
+
return displayCellKey(rowIndex, getDataColumnIndex(column, colIndex) + 1);
|
|
1876
|
+
};
|
|
1877
|
+
const getCellKeyByDataColumn = (rowIndex, dataColIndex) => {
|
|
1878
|
+
return displayCellKey(rowIndex, dataColIndex + 1);
|
|
1879
|
+
};
|
|
1880
|
+
const getTextValue = (value) => {
|
|
1881
|
+
if (value === null || value === void 0) {
|
|
1882
|
+
return "";
|
|
1883
|
+
}
|
|
1884
|
+
return `${value}`;
|
|
1885
|
+
};
|
|
1886
|
+
const hasRenderableValue = (value) => {
|
|
1887
|
+
return getTextValue(value).trim() !== "";
|
|
1888
|
+
};
|
|
1889
|
+
const isNumericLikeValue = (text) => {
|
|
1890
|
+
return /^[+-]?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?%?$/.test(text.trim());
|
|
1891
|
+
};
|
|
1892
|
+
const measureTextWidth = (text, font, padding, documentRef) => {
|
|
1893
|
+
const cacheKey = `${font}
|
|
1894
|
+
${padding}
|
|
1895
|
+
${text}`;
|
|
1896
|
+
const cached = textWidthCache.get(cacheKey);
|
|
1897
|
+
if (cached !== void 0) {
|
|
1898
|
+
return cached;
|
|
1899
|
+
}
|
|
1900
|
+
if (!measureCanvas && documentRef) {
|
|
1901
|
+
measureCanvas = documentRef.createElement("canvas");
|
|
1902
|
+
}
|
|
1903
|
+
const context = measureCanvas === null || measureCanvas === void 0 ? void 0 : measureCanvas.getContext("2d");
|
|
1904
|
+
if (!context) {
|
|
1905
|
+
return text.length * TABLE_FONT_SIZE;
|
|
1906
|
+
}
|
|
1907
|
+
context.font = font;
|
|
1908
|
+
const width = context.measureText(text).width + padding * 2;
|
|
1909
|
+
textWidthCache.set(cacheKey, width);
|
|
1910
|
+
return width;
|
|
1911
|
+
};
|
|
1912
|
+
const isBlankOverflowTarget = (virtualState, row, rowIndex, dataColIndex) => {
|
|
1913
|
+
const column = virtualState.columns[dataColIndex + 1];
|
|
1914
|
+
if (!isVisibleDataColumn(column)) {
|
|
1915
|
+
return false;
|
|
1916
|
+
}
|
|
1917
|
+
const cellKey = getCellKeyByDataColumn(rowIndex, dataColIndex);
|
|
1918
|
+
if (virtualState.mergeStartMap.has(cellKey) || virtualState.mergeCoveredMap.has(cellKey)) {
|
|
1919
|
+
return false;
|
|
1920
|
+
}
|
|
1921
|
+
return !hasRenderableValue(row[getDataKey(dataColIndex)]);
|
|
1922
|
+
};
|
|
1923
|
+
const collectOverflowRoom = (virtualState, row, rowIndex, dataColIndex, direction) => {
|
|
1924
|
+
let room = 0;
|
|
1925
|
+
for (let step = 1; step <= MAX_OVERFLOW_SCAN_COLS; step += 1) {
|
|
1926
|
+
const nextColIndex = dataColIndex + step * direction;
|
|
1927
|
+
if (nextColIndex < 0 || nextColIndex >= virtualState.totalCols) {
|
|
1928
|
+
break;
|
|
1929
|
+
}
|
|
1930
|
+
if (!isBlankOverflowTarget(virtualState, row, rowIndex, nextColIndex)) {
|
|
1931
|
+
break;
|
|
1932
|
+
}
|
|
1933
|
+
room += getRenderColumnWidth(virtualState.columns[nextColIndex + 1]);
|
|
1934
|
+
}
|
|
1935
|
+
return room;
|
|
1936
|
+
};
|
|
1937
|
+
const getExcelOverflowLayout = (virtualState, row, rowIndex, dataColIndex, column, style, value, zoomScale, documentRef) => {
|
|
1938
|
+
const text = getTextValue(value);
|
|
1939
|
+
if (!text || (style === null || style === void 0 ? void 0 : style.wrapText) || (style === null || style === void 0 ? void 0 : style.shrinkToFit) || isNumericLikeValue(text)) {
|
|
1940
|
+
return void 0;
|
|
1941
|
+
}
|
|
1942
|
+
const cellKey = getCellKeyByDataColumn(rowIndex, dataColIndex);
|
|
1943
|
+
if (virtualState.mergeStartMap.has(cellKey) || virtualState.mergeCoveredMap.has(cellKey)) {
|
|
1944
|
+
return void 0;
|
|
1945
|
+
}
|
|
1946
|
+
const ownWidth = getRenderColumnWidth(column);
|
|
1947
|
+
if (!ownWidth) {
|
|
1948
|
+
return void 0;
|
|
1949
|
+
}
|
|
1950
|
+
const font = (style === null || style === void 0 ? void 0 : style.font) || BODY_FONT;
|
|
1951
|
+
const measuredWidth = Math.ceil(measureTextWidth(text, font, scaleNumber(CELL_PADDING, zoomScale), documentRef));
|
|
1952
|
+
if (measuredWidth <= ownWidth) {
|
|
1953
|
+
return void 0;
|
|
1954
|
+
}
|
|
1955
|
+
const align = (style === null || style === void 0 ? void 0 : style.horizontalAlign) || (column === null || column === void 0 ? void 0 : column.align) || "left";
|
|
1956
|
+
const leftRoom = align === "right" || align === "center" ? collectOverflowRoom(virtualState, row, rowIndex, dataColIndex, -1) : 0;
|
|
1957
|
+
const rightRoom = align !== "right" ? collectOverflowRoom(virtualState, row, rowIndex, dataColIndex, 1) : 0;
|
|
1958
|
+
const maxWidth = ownWidth + leftRoom + rightRoom;
|
|
1959
|
+
if (maxWidth <= ownWidth) {
|
|
1960
|
+
return void 0;
|
|
1961
|
+
}
|
|
1962
|
+
const width = Math.min(measuredWidth, maxWidth);
|
|
1963
|
+
return {
|
|
1964
|
+
left: toTextLayerLeft(align, ownWidth, width, leftRoom),
|
|
1965
|
+
width
|
|
1966
|
+
};
|
|
1967
|
+
};
|
|
1968
|
+
const getDataColumnSpanWidth = (virtualState, startDataColIndex, endDataColIndex) => {
|
|
1969
|
+
let width = 0;
|
|
1970
|
+
for (let index = startDataColIndex; index < endDataColIndex; index += 1) {
|
|
1971
|
+
width += getRenderColumnWidth(virtualState.columns[index + 1]);
|
|
1972
|
+
}
|
|
1973
|
+
return width;
|
|
1974
|
+
};
|
|
1975
|
+
const getLeftOverflowMirror = (virtualState, row, rowIndex, targetDataColIndex, zoomScale, documentRef) => {
|
|
1976
|
+
if (!isBlankOverflowTarget(virtualState, row, rowIndex, targetDataColIndex)) {
|
|
1977
|
+
return void 0;
|
|
1978
|
+
}
|
|
1979
|
+
const targetColumn = virtualState.columns[targetDataColIndex + 1];
|
|
1980
|
+
const targetWidth = getRenderColumnWidth(targetColumn);
|
|
1981
|
+
if (!targetWidth) {
|
|
1982
|
+
return void 0;
|
|
1983
|
+
}
|
|
1984
|
+
for (let step = 1; step <= MAX_OVERFLOW_SCAN_COLS; step += 1) {
|
|
1985
|
+
const sourceDataColIndex = targetDataColIndex - step;
|
|
1986
|
+
if (sourceDataColIndex < 0) {
|
|
1987
|
+
break;
|
|
1988
|
+
}
|
|
1989
|
+
const sourceColumn = virtualState.columns[sourceDataColIndex + 1];
|
|
1990
|
+
if (!isVisibleDataColumn(sourceColumn)) {
|
|
1991
|
+
break;
|
|
1992
|
+
}
|
|
1993
|
+
const sourceValue = row[getDataKey(sourceDataColIndex)];
|
|
1994
|
+
if (!hasRenderableValue(sourceValue)) {
|
|
1995
|
+
if (!isBlankOverflowTarget(virtualState, row, rowIndex, sourceDataColIndex)) {
|
|
1996
|
+
break;
|
|
1997
|
+
}
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
const sourceCellKey = getCellKeyByDataColumn(rowIndex, sourceDataColIndex);
|
|
2001
|
+
const rawSourceStyle = virtualState.cellCache.get(sourceCellKey);
|
|
2002
|
+
const sourceStyle = {
|
|
2003
|
+
...scaleCellStyle(rawSourceStyle, zoomScale) || {},
|
|
2004
|
+
horizontalAlign: (rawSourceStyle === null || rawSourceStyle === void 0 ? void 0 : rawSourceStyle.horizontalAlign) || (sourceColumn === null || sourceColumn === void 0 ? void 0 : sourceColumn.align),
|
|
2005
|
+
verticalAlign: (rawSourceStyle === null || rawSourceStyle === void 0 ? void 0 : rawSourceStyle.verticalAlign) || (sourceColumn === null || sourceColumn === void 0 ? void 0 : sourceColumn.verticalAlign)
|
|
2006
|
+
};
|
|
2007
|
+
const sourceLayout = getExcelOverflowLayout(virtualState, row, rowIndex, sourceDataColIndex, sourceColumn, sourceStyle, sourceValue, zoomScale, documentRef);
|
|
2008
|
+
if (!sourceLayout) {
|
|
2009
|
+
return void 0;
|
|
2010
|
+
}
|
|
2011
|
+
const targetOffset = getDataColumnSpanWidth(virtualState, sourceDataColIndex, targetDataColIndex);
|
|
2012
|
+
const sourceTextLeft = sourceLayout.left;
|
|
2013
|
+
const sourceTextRight = sourceLayout.left + sourceLayout.width;
|
|
2014
|
+
const targetLeft = targetOffset;
|
|
2015
|
+
const targetRight = targetOffset + targetWidth;
|
|
2016
|
+
if (sourceTextLeft < targetRight && sourceTextRight > targetLeft) {
|
|
2017
|
+
return {
|
|
2018
|
+
value: sourceValue,
|
|
2019
|
+
style: sourceStyle,
|
|
2020
|
+
overflowLayout: {
|
|
2021
|
+
left: sourceLayout.left - targetOffset,
|
|
2022
|
+
width: sourceLayout.width
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
return void 0;
|
|
2027
|
+
}
|
|
2028
|
+
return void 0;
|
|
2029
|
+
};
|
|
2030
|
+
const getBorderScore = (border) => {
|
|
2031
|
+
if (!border) {
|
|
2032
|
+
return 0;
|
|
2033
|
+
}
|
|
2034
|
+
return border.width * 100 + (BORDER_STYLE_PRIORITY[border.style] || 1);
|
|
2035
|
+
};
|
|
2036
|
+
const getCollapsedBorderStyle = (virtualState, rowIndex, dataColIndex, style, zoomScale) => {
|
|
2037
|
+
const previousRow = scaleCellStyle(virtualState.cellCache.get(displayCellKey(rowIndex - 1, dataColIndex + 1)), zoomScale);
|
|
2038
|
+
const nextRow = scaleCellStyle(virtualState.cellCache.get(displayCellKey(rowIndex + 1, dataColIndex + 1)), zoomScale);
|
|
2039
|
+
const previousCol = scaleCellStyle(virtualState.cellCache.get(displayCellKey(rowIndex, dataColIndex)), zoomScale);
|
|
2040
|
+
const nextCol = scaleCellStyle(virtualState.cellCache.get(displayCellKey(rowIndex, dataColIndex + 2)), zoomScale);
|
|
2041
|
+
const borderTop = getBorderScore(style.borderTop) >= getBorderScore(previousRow === null || previousRow === void 0 ? void 0 : previousRow.borderBottom) ? style.borderTop : void 0;
|
|
2042
|
+
const borderBottom = getBorderScore(style.borderBottom) > getBorderScore(nextRow === null || nextRow === void 0 ? void 0 : nextRow.borderTop) ? style.borderBottom : void 0;
|
|
2043
|
+
const borderLeft = getBorderScore(style.borderLeft) >= getBorderScore(previousCol === null || previousCol === void 0 ? void 0 : previousCol.borderRight) ? style.borderLeft : void 0;
|
|
2044
|
+
const borderRight = getBorderScore(style.borderRight) > getBorderScore(nextCol === null || nextCol === void 0 ? void 0 : nextCol.borderLeft) ? style.borderRight : void 0;
|
|
2045
|
+
return {
|
|
2046
|
+
...style,
|
|
2047
|
+
borderTop,
|
|
2048
|
+
borderRight,
|
|
2049
|
+
borderBottom,
|
|
2050
|
+
borderLeft
|
|
2051
|
+
};
|
|
2052
|
+
};
|
|
2053
|
+
const createBorderLine = (documentRef, side, border) => {
|
|
2054
|
+
const line = documentRef.createElement("span");
|
|
2055
|
+
const half = border.width / 2;
|
|
2056
|
+
Object.assign(line.style, {
|
|
2057
|
+
position: "absolute",
|
|
2058
|
+
pointerEvents: "none",
|
|
2059
|
+
boxSizing: "border-box"
|
|
2060
|
+
});
|
|
2061
|
+
if (side === "top" || side === "bottom") {
|
|
2062
|
+
Object.assign(line.style, {
|
|
2063
|
+
left: `${-half}px`,
|
|
2064
|
+
width: `calc(100% + ${border.width}px)`,
|
|
2065
|
+
height: "0"
|
|
2066
|
+
});
|
|
2067
|
+
line.style[side] = `${-half}px`;
|
|
2068
|
+
line.style.borderTop = `${border.width}px ${border.style} ${border.color}`;
|
|
2069
|
+
} else {
|
|
2070
|
+
Object.assign(line.style, {
|
|
2071
|
+
top: `${-half}px`,
|
|
2072
|
+
height: `calc(100% + ${border.width}px)`,
|
|
2073
|
+
width: "0"
|
|
2074
|
+
});
|
|
2075
|
+
line.style[side] = `${-half}px`;
|
|
2076
|
+
line.style.borderLeft = `${border.width}px ${border.style} ${border.color}`;
|
|
2077
|
+
}
|
|
2078
|
+
return line;
|
|
2079
|
+
};
|
|
2080
|
+
const createTextLayer = (documentRef, value, style, padding) => {
|
|
2081
|
+
const text = documentRef.createElement("span");
|
|
2082
|
+
text.textContent = getTextValue(value);
|
|
2083
|
+
Object.assign(text.style, {
|
|
2084
|
+
position: "relative",
|
|
2085
|
+
zIndex: "1",
|
|
2086
|
+
width: "100%",
|
|
2087
|
+
height: "100%",
|
|
2088
|
+
boxSizing: "border-box",
|
|
2089
|
+
display: "flex",
|
|
2090
|
+
alignItems: toFlexAlign(style.verticalAlign),
|
|
2091
|
+
justifyContent: toFlexJustify(style.horizontalAlign),
|
|
2092
|
+
padding: `0 ${padding}px`,
|
|
2093
|
+
overflow: "hidden",
|
|
2094
|
+
textOverflow: style.wrapText ? "clip" : "ellipsis",
|
|
2095
|
+
whiteSpace: style.wrapText ? "pre-wrap" : "nowrap",
|
|
2096
|
+
wordBreak: style.wrapText ? "break-word" : "normal",
|
|
2097
|
+
lineHeight: `${CELL_LINE_HEIGHT}`,
|
|
2098
|
+
textAlign: style.horizontalAlign || "left",
|
|
2099
|
+
color: style.color || "inherit",
|
|
2100
|
+
font: style.font || BODY_FONT,
|
|
2101
|
+
transform: style.shrinkToFit ? "scale(0.92)" : "none",
|
|
2102
|
+
transformOrigin: `${style.horizontalAlign || "left"} center`
|
|
2103
|
+
});
|
|
2104
|
+
return text;
|
|
2105
|
+
};
|
|
2106
|
+
const applyOverflowLayout = (text, overflowLayout) => {
|
|
2107
|
+
if (!overflowLayout) {
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
Object.assign(text.style, {
|
|
2111
|
+
position: "absolute",
|
|
2112
|
+
left: `${overflowLayout.left}px`,
|
|
2113
|
+
top: "0",
|
|
2114
|
+
width: `${overflowLayout.width}px`,
|
|
2115
|
+
overflow: "hidden",
|
|
2116
|
+
textOverflow: "clip"
|
|
2117
|
+
});
|
|
2118
|
+
};
|
|
2119
|
+
const renderCellOverlay = (cellEl, borderStyle, textStyle, textValue, renderText, overflowLayout, zoomScale) => {
|
|
2120
|
+
const documentRef = cellEl.ownerDocument;
|
|
2121
|
+
cellEl.replaceChildren();
|
|
2122
|
+
Object.assign(cellEl.style, {
|
|
2123
|
+
pointerEvents: "none",
|
|
2124
|
+
overflow: overflowLayout ? "hidden" : "visible",
|
|
2125
|
+
background: "transparent"
|
|
2126
|
+
});
|
|
2127
|
+
const fragment = documentRef.createDocumentFragment();
|
|
2128
|
+
if (renderText) {
|
|
2129
|
+
const text = createTextLayer(documentRef, textValue, textStyle, scaleNumber(CELL_PADDING, zoomScale));
|
|
2130
|
+
applyOverflowLayout(text, overflowLayout);
|
|
2131
|
+
fragment.appendChild(text);
|
|
2132
|
+
}
|
|
2133
|
+
if (borderStyle.borderTop) {
|
|
2134
|
+
fragment.appendChild(createBorderLine(documentRef, "top", borderStyle.borderTop));
|
|
2135
|
+
}
|
|
2136
|
+
if (borderStyle.borderRight) {
|
|
2137
|
+
fragment.appendChild(createBorderLine(documentRef, "right", borderStyle.borderRight));
|
|
2138
|
+
}
|
|
2139
|
+
if (borderStyle.borderBottom) {
|
|
2140
|
+
fragment.appendChild(createBorderLine(documentRef, "bottom", borderStyle.borderBottom));
|
|
2141
|
+
}
|
|
2142
|
+
if (borderStyle.borderLeft) {
|
|
2143
|
+
fragment.appendChild(createBorderLine(documentRef, "left", borderStyle.borderLeft));
|
|
2144
|
+
}
|
|
2145
|
+
cellEl.appendChild(fragment);
|
|
2146
|
+
};
|
|
2147
|
+
const normalizeCellStyle = (meta) => {
|
|
2148
|
+
if (!meta) {
|
|
2149
|
+
return void 0;
|
|
2150
|
+
}
|
|
2151
|
+
const style = meta.style || {};
|
|
2152
|
+
const nextStyle = {};
|
|
2153
|
+
if (style.backgroundColor) {
|
|
2154
|
+
nextStyle.backgroundColor = style.backgroundColor;
|
|
2155
|
+
}
|
|
2156
|
+
if (style.color) {
|
|
2157
|
+
nextStyle.color = style.color;
|
|
2158
|
+
} else if (style.backgroundColor && tinycolor(style.backgroundColor).isDark()) {
|
|
2159
|
+
nextStyle.color = "#ffffff";
|
|
2160
|
+
}
|
|
2161
|
+
const font = buildFont(style);
|
|
2162
|
+
if (font) {
|
|
2163
|
+
nextStyle.font = font;
|
|
2164
|
+
} else if (style.backgroundColor && tinycolor(style.backgroundColor).isDark()) {
|
|
2165
|
+
nextStyle.font = `bold ${TABLE_FONT_SIZE}px ${TABLE_FONT_FAMILY}`;
|
|
2166
|
+
}
|
|
2167
|
+
const borderTop = getBorderSide(style, "Top");
|
|
2168
|
+
if (borderTop) {
|
|
2169
|
+
nextStyle.borderTop = borderTop;
|
|
2170
|
+
}
|
|
2171
|
+
const borderRight = getBorderSide(style, "Right");
|
|
2172
|
+
if (borderRight) {
|
|
2173
|
+
nextStyle.borderRight = borderRight;
|
|
2174
|
+
}
|
|
2175
|
+
const borderBottom = getBorderSide(style, "Bottom");
|
|
2176
|
+
if (borderBottom) {
|
|
2177
|
+
nextStyle.borderBottom = borderBottom;
|
|
2178
|
+
}
|
|
2179
|
+
const borderLeft = getBorderSide(style, "Left");
|
|
2180
|
+
if (borderLeft) {
|
|
2181
|
+
nextStyle.borderLeft = borderLeft;
|
|
2182
|
+
}
|
|
2183
|
+
const horizontalAlign = alignFromClassName(meta.className);
|
|
2184
|
+
if (horizontalAlign) {
|
|
2185
|
+
nextStyle.horizontalAlign = horizontalAlign;
|
|
2186
|
+
}
|
|
2187
|
+
const verticalAlign = verticalAlignFromClassName(meta.className);
|
|
2188
|
+
if (verticalAlign) {
|
|
2189
|
+
nextStyle.verticalAlign = verticalAlign;
|
|
2190
|
+
}
|
|
2191
|
+
if (hasClassName(meta.className, "htWrap")) {
|
|
2192
|
+
nextStyle.wrapText = true;
|
|
2193
|
+
}
|
|
2194
|
+
if (hasClassName(meta.className, "htShrink")) {
|
|
2195
|
+
nextStyle.shrinkToFit = true;
|
|
2196
|
+
}
|
|
2197
|
+
if (!nextStyle.backgroundColor && !nextStyle.color && !nextStyle.font && !hasBorder(nextStyle) && !hasTextLayout(nextStyle)) {
|
|
2198
|
+
return void 0;
|
|
2199
|
+
}
|
|
2200
|
+
return nextStyle;
|
|
2201
|
+
};
|
|
2202
|
+
const createTableConfig = ({ hostHeight, darkMode = false, resizableColumns = false, resizableRows = false, copySelection, sheetDefaults, virtualState, zoomScale = 1 }) => {
|
|
2203
|
+
const normalizedScale = normalizeZoomScale(zoomScale);
|
|
2204
|
+
const scaledPadding = scaleNumber(CELL_PADDING, normalizedScale);
|
|
2205
|
+
const scaledHeaderHeight = scaleNumber(HEADER_HEIGHT, normalizedScale);
|
|
2206
|
+
const scaledCellHeight = scaleNumber(normalizeRowHeight(sheetDefaults.rowHeight, sheetDefaults.rowHeight), normalizedScale);
|
|
2207
|
+
const scaledCellWidth = scaleNumber(sheetDefaults.colWidth, normalizedScale);
|
|
2208
|
+
const headerStyle = getIndexCellStyle(normalizedScale, darkMode);
|
|
2209
|
+
const loadingStyle = getLoadingCellStyle(normalizedScale, darkMode);
|
|
2210
|
+
const spanMethod = ({ rowIndex, colIndex, column }) => {
|
|
2211
|
+
if (colIndex === 0) {
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
const key = getCellCacheKey(rowIndex, colIndex, column);
|
|
2215
|
+
if (virtualState.mergeCoveredMap.has(key)) {
|
|
2216
|
+
return { rowspan: 0, colspan: 0 };
|
|
2217
|
+
}
|
|
2218
|
+
const merge = virtualState.mergeStartMap.get(key);
|
|
2219
|
+
if (!merge) {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
return {
|
|
2223
|
+
rowspan: merge.rowspan,
|
|
2224
|
+
colspan: merge.colspan
|
|
2225
|
+
};
|
|
2226
|
+
};
|
|
2227
|
+
const headerStyleMethod = () => headerStyle;
|
|
2228
|
+
const styleMethod = ({ row, rowIndex, colIndex, column }) => {
|
|
2229
|
+
if (colIndex === 0) {
|
|
2230
|
+
return headerStyle;
|
|
2231
|
+
}
|
|
2232
|
+
const currentRow = row;
|
|
2233
|
+
if (isHiddenVirtualRow(currentRow)) {
|
|
2234
|
+
return void 0;
|
|
2235
|
+
}
|
|
2236
|
+
if (getRowState(currentRow) !== RowState.Loaded) {
|
|
2237
|
+
return loadingStyle;
|
|
2238
|
+
}
|
|
2239
|
+
return scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
|
|
2240
|
+
};
|
|
2241
|
+
const renderMethod = ({ row, rowIndex, colIndex, column, value }) => {
|
|
2242
|
+
const currentRow = row;
|
|
2243
|
+
if (colIndex === 0 || isHiddenVirtualRow(currentRow) || getRowState(currentRow) !== RowState.Loaded) {
|
|
2244
|
+
return void 0;
|
|
2245
|
+
}
|
|
2246
|
+
const cellKey = getCellCacheKey(rowIndex, colIndex, column);
|
|
2247
|
+
if (virtualState.mergeCoveredMap.has(cellKey)) {
|
|
2248
|
+
return void 0;
|
|
2249
|
+
}
|
|
2250
|
+
const style = scaleCellStyle(virtualState.cellCache.get(cellKey), normalizedScale);
|
|
2251
|
+
const dataColIndex = getDataColumnIndex(column, colIndex);
|
|
2252
|
+
const measureDocument = typeof document === "undefined" ? void 0 : document;
|
|
2253
|
+
const overflowLayout = getExcelOverflowLayout(virtualState, currentRow, rowIndex, dataColIndex, column, style, value, normalizedScale, measureDocument);
|
|
2254
|
+
const mirror = !hasRenderableValue(value) ? getLeftOverflowMirror(virtualState, currentRow, rowIndex, dataColIndex, normalizedScale, measureDocument) : void 0;
|
|
2255
|
+
const renderText = shouldRenderTextInOverlay(style, column) || !!overflowLayout || !!mirror;
|
|
2256
|
+
if (!hasBorder(style) && !renderText) {
|
|
2257
|
+
return void 0;
|
|
2258
|
+
}
|
|
2259
|
+
return ((cellEl) => {
|
|
2260
|
+
const baseStyle = {
|
|
2261
|
+
...style || {},
|
|
2262
|
+
horizontalAlign: (style === null || style === void 0 ? void 0 : style.horizontalAlign) || (column === null || column === void 0 ? void 0 : column.align),
|
|
2263
|
+
verticalAlign: (style === null || style === void 0 ? void 0 : style.verticalAlign) || (column === null || column === void 0 ? void 0 : column.verticalAlign)
|
|
2264
|
+
};
|
|
2265
|
+
const collapsedStyle = hasBorder(style) ? getCollapsedBorderStyle(virtualState, rowIndex, dataColIndex, baseStyle, normalizedScale) : baseStyle;
|
|
2266
|
+
renderCellOverlay(cellEl, collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : value, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
|
|
2267
|
+
});
|
|
2268
|
+
};
|
|
2269
|
+
return {
|
|
2270
|
+
ROW_KEY: ROW_KEY_FIELD,
|
|
2271
|
+
DISABLED: true,
|
|
2272
|
+
HEIGHT: Math.max(hostHeight, 240),
|
|
2273
|
+
MAX_HEIGHT: Math.max(hostHeight, 240),
|
|
2274
|
+
HEADER_HEIGHT: scaledHeaderHeight,
|
|
2275
|
+
CELL_HEIGHT: scaledCellHeight,
|
|
2276
|
+
CELL_WIDTH: scaledCellWidth,
|
|
2277
|
+
CELL_PADDING: scaledPadding,
|
|
2278
|
+
CELL_LINE_HEIGHT,
|
|
2279
|
+
COLUMNS_VERTICAL_ALIGN: "middle",
|
|
2280
|
+
HEADER_FONT: getHeaderFont(normalizedScale),
|
|
2281
|
+
BODY_FONT: getBodyFont(normalizedScale),
|
|
2282
|
+
BORDER_RADIUS: 0,
|
|
2283
|
+
BORDER_COLOR: darkMode ? EXCEL_DARK_GRID : EXCEL_GRID,
|
|
2284
|
+
HEADER_BG_COLOR: darkMode ? EXCEL_DARK_HEADER_BG : EXCEL_HEADER_BG,
|
|
2285
|
+
BODY_BG_COLOR: darkMode ? EXCEL_DARK_BODY_BG : "#ffffff",
|
|
2286
|
+
HEADER_TEXT_COLOR: darkMode ? EXCEL_DARK_HEADER_TEXT : EXCEL_HEADER_TEXT,
|
|
2287
|
+
BODY_TEXT_COLOR: darkMode ? EXCEL_DARK_BODY_TEXT : "#202124",
|
|
2288
|
+
READONLY_COLOR: darkMode ? EXCEL_DARK_BODY_BG : "#ffffff",
|
|
2289
|
+
READONLY_TEXT_COLOR: darkMode ? EXCEL_DARK_BODY_TEXT : "#202124",
|
|
2290
|
+
EDIT_BG_COLOR: darkMode ? "#18212f" : "#ffffff",
|
|
2291
|
+
PLACEHOLDER_COLOR: darkMode ? "#94a3b8" : "#8a94a3",
|
|
2292
|
+
SCROLLER_COLOR: darkMode ? "#475569" : "#c1c7d0",
|
|
2293
|
+
SCROLLER_FOCUS_COLOR: darkMode ? "#64748b" : "#9aa0a6",
|
|
2294
|
+
SELECT_ROW_COL_BG_COLOR: EXCEL_GREEN_SOFT,
|
|
2295
|
+
SELECT_AREA_COLOR: "rgba(33, 163, 102, 0.14)",
|
|
2296
|
+
SELECT_BORDER_COLOR: EXCEL_GREEN,
|
|
2297
|
+
AUTOFILL_POINT_BORDER_COLOR: EXCEL_GREEN,
|
|
2298
|
+
ENABLE_SELECTOR: true,
|
|
2299
|
+
ENABLE_SELECTOR_SINGLE: false,
|
|
2300
|
+
ENABLE_SELECTOR_SPAN_COL: true,
|
|
2301
|
+
ENABLE_SELECTOR_SPAN_ROW: true,
|
|
2302
|
+
ENABLE_SELECTOR_ALL_ROWS: true,
|
|
2303
|
+
ENABLE_SELECTOR_ALL_COLS: true,
|
|
2304
|
+
SELECTOR_AREA_MIN_X: DATA_AREA_MIN_COL_INDEX,
|
|
2305
|
+
ENABLE_CONTEXT_MENU: false,
|
|
2306
|
+
ENABLE_HEADER_CONTEXT_MENU: false,
|
|
2307
|
+
ENABLE_AUTOFILL: true,
|
|
2308
|
+
ENABLE_AUTOFILL_SPAN_COL: true,
|
|
2309
|
+
ENABLE_AUTOFILL_SPAN_ROW: true,
|
|
2310
|
+
ENABLE_PASTER: false,
|
|
2311
|
+
ENABLE_HISTORY: false,
|
|
2312
|
+
ENABLE_RESIZE_COLUMN: resizableColumns,
|
|
2313
|
+
ENABLE_RESIZE_COLUMN_TEXT: resizableColumns,
|
|
2314
|
+
RESIZE_COLUMN_LINE_COLOR: EXCEL_GREEN,
|
|
2315
|
+
RESIZE_COLUMN_TEXT_BG_COLOR: EXCEL_GREEN,
|
|
2316
|
+
RESIZE_COLUMN_MIN_WIDTH: RESIZABLE_COLUMN_MIN_WIDTH,
|
|
2317
|
+
ENABLE_RESIZE_ROW: resizableRows,
|
|
2318
|
+
RESIZE_ROW_LINE_COLOR: EXCEL_GREEN,
|
|
2319
|
+
RESIZE_ROW_MIN_HEIGHT: scaleNumber(RESIZABLE_ROW_MIN_HEIGHT, normalizedScale),
|
|
2320
|
+
ENABLE_KEYBOARD: true,
|
|
2321
|
+
ENABLE_COPY: true,
|
|
2322
|
+
BEFORE_COPY_METHOD: copySelection ? (params) => {
|
|
2323
|
+
copySelection(params);
|
|
2324
|
+
return void 0;
|
|
2325
|
+
} : void 0,
|
|
2326
|
+
// 预览态只开放“拖动扩选”的交互,不允许真正写回单元格内容。
|
|
2327
|
+
BEFORE_AUTOFILL_DATA_METHOD: () => [],
|
|
2328
|
+
SPAN_METHOD: spanMethod,
|
|
2329
|
+
HEADER_CELL_STYLE_METHOD: headerStyleMethod,
|
|
2330
|
+
BODY_CELL_STYLE_METHOD: styleMethod,
|
|
2331
|
+
BODY_CELL_RENDER_METHOD: renderMethod,
|
|
2332
|
+
BODY_CELL_FORMATTER_METHOD: ({ row, rowIndex, colIndex, column, value }) => {
|
|
2333
|
+
if (isHiddenVirtualRow(row)) {
|
|
2334
|
+
return "";
|
|
2335
|
+
}
|
|
2336
|
+
if (colIndex === 0) {
|
|
2337
|
+
const displayIndex = rowIndex + 1 - virtualState.indexOffset;
|
|
2338
|
+
return displayIndex > 0 ? `${displayIndex}` : "";
|
|
2339
|
+
}
|
|
2340
|
+
if (getRowState(row) !== RowState.Loaded) {
|
|
2341
|
+
return "";
|
|
2342
|
+
}
|
|
2343
|
+
const currentRow = row;
|
|
2344
|
+
const style = scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
|
|
2345
|
+
const dataColIndex = getDataColumnIndex(column, colIndex);
|
|
2346
|
+
const measureDocument = typeof document === "undefined" ? void 0 : document;
|
|
2347
|
+
const overflowLayout = getExcelOverflowLayout(virtualState, currentRow, rowIndex, dataColIndex, column, style, value, normalizedScale, measureDocument);
|
|
2348
|
+
const mirror = !hasRenderableValue(value) ? getLeftOverflowMirror(virtualState, currentRow, rowIndex, dataColIndex, normalizedScale, measureDocument) : void 0;
|
|
2349
|
+
if (shouldRenderTextInOverlay(style, column) || overflowLayout || mirror) {
|
|
2350
|
+
return "";
|
|
2351
|
+
}
|
|
2352
|
+
if (value === null || value === void 0) {
|
|
2353
|
+
return "";
|
|
2354
|
+
}
|
|
2355
|
+
return `${value}`;
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
};
|
|
2359
|
+
const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
|
|
2360
|
+
const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
|
|
2361
|
+
const E_VIRT_TABLE_STYLE_MARKERS = [
|
|
2362
|
+
".e-virt-table-container",
|
|
2363
|
+
".e-virt-table-overlayer",
|
|
2364
|
+
".e-virt-table-editor",
|
|
2365
|
+
".e-virt-table-context-menu"
|
|
2366
|
+
];
|
|
2367
|
+
const SPREADSHEET_STYLE_SCOPE = ".excel-wrapper[data-file-viewer-spreadsheet-root]";
|
|
2368
|
+
const E_VIRT_TABLE_ROTATE_KEYFRAME = "file-viewer-e-virt-table-rotate";
|
|
2369
|
+
const spreadsheetStyle = `
|
|
2370
|
+
.excel-wrapper{position:relative;width:100%;height:100%;display:flex;flex-direction:column;background:var(--file-viewer-render-surface-background,#fff);color:#172033;font-family:Aptos,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif}
|
|
2371
|
+
.excel-wrapper *{box-sizing:border-box}
|
|
2372
|
+
.excel-wrapper .table-wrapper{position:relative;width:100%;flex:1;min-height:0;background:#fff;overflow:hidden}
|
|
2373
|
+
.excel-wrapper .table-host{position:absolute;inset:0}
|
|
2374
|
+
.excel-wrapper .table-target{width:100%;height:100%}
|
|
2375
|
+
.excel-wrapper .table-host .e-virt-table-container,.excel-wrapper .table-host .e-virt-table-stage{width:100%!important}
|
|
2376
|
+
.excel-wrapper .table-host .e-virt-table-container{height:100%!important}
|
|
2377
|
+
.excel-wrapper .table-host .e-virt-table-stage{overflow:hidden}
|
|
2378
|
+
.excel-wrapper .sheet-loading{position:absolute;right:18px;bottom:18px;z-index:20;display:inline-flex;align-items:center;gap:8px;padding:10px 14px;border-radius:14px;background:rgba(33,163,102,.1);border:1px solid rgba(33,163,102,.2);box-shadow:0 8px 20px rgba(33,163,102,.12);color:#1a7f50;font-size:12px;font-weight:700;pointer-events:none}
|
|
2379
|
+
.excel-wrapper .sheet-loading-dot{width:8px;height:8px;flex-shrink:0;border-radius:999px;background:#21a366;box-shadow:0 0 0 6px rgba(33,163,102,.12);animation:file-viewer-spreadsheet-loading-pulse 1.2s ease-in-out infinite}
|
|
2380
|
+
.excel-wrapper .sheet-loading-summary{color:#5f6368}
|
|
2381
|
+
.excel-wrapper .excel-image-viewport{position:absolute;z-index:35;overflow:hidden;pointer-events:none}
|
|
2382
|
+
.excel-wrapper .excel-image-layer{position:absolute;inset:0 auto auto 0;width:0;height:0;transform-origin:0 0;will-change:transform}
|
|
2383
|
+
.excel-wrapper .excel-image{position:absolute;display:block;max-width:none;height:auto;object-fit:contain;user-select:none}
|
|
2384
|
+
.excel-wrapper .excel-chart{position:absolute;display:block;max-width:none;overflow:hidden;background:#fff;box-shadow:0 1px 3px rgba(15,23,42,.08);user-select:none}
|
|
2385
|
+
.excel-wrapper .excel-chart svg{display:block;width:100%;height:100%;overflow:visible}
|
|
2386
|
+
.excel-wrapper .loading{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.96);z-index:999;backdrop-filter:blur(6px)}
|
|
2387
|
+
.excel-wrapper .loading-card{width:min(100%,460px);display:flex;align-items:center;gap:18px;padding:22px;border-radius:24px;background:rgba(255,255,255,.92);border:1px solid rgba(33,163,102,.1);box-shadow:0 22px 48px rgba(18,36,27,.12)}
|
|
2388
|
+
.excel-wrapper .loading-brand{flex-shrink:0;width:78px;height:78px;display:flex;align-items:center;justify-content:center;border-radius:22px;background:linear-gradient(135deg,rgba(33,163,102,.14),rgba(33,163,102,.04));color:#1a7f50;font-size:18px;font-weight:900;letter-spacing:0}
|
|
2389
|
+
.excel-wrapper .loading-copy{min-width:0;flex:1}
|
|
2390
|
+
.excel-wrapper .loading-kicker{display:block;color:#21a366;font-size:12px;font-weight:800;letter-spacing:.08em;text-transform:uppercase}
|
|
2391
|
+
.excel-wrapper .loading-copy strong{display:block;margin-top:6px;color:#183828;font-size:20px;line-height:1.3}
|
|
2392
|
+
.excel-wrapper .loading-copy p{margin:8px 0 0;color:#64748b;font-size:13px;line-height:1.5}
|
|
2393
|
+
.excel-wrapper .loading-spinner{width:28px;height:28px;border-radius:999px;border:3px solid rgba(33,163,102,.16);border-top-color:#21a366;animation:file-viewer-spreadsheet-loading-spin .8s linear infinite}
|
|
2394
|
+
.excel-wrapper .error{position:absolute;left:50%;top:50%;z-index:1000;transform:translate(-50%,-50%);max-width:min(520px,calc(100% - 48px));padding:16px 18px;border-radius:16px;background:#fff7ed;color:#9a3412;border:1px solid rgba(234,88,12,.18);box-shadow:0 18px 42px rgba(154,52,18,.12);font-size:14px;line-height:1.6}
|
|
2395
|
+
.excel-wrapper .toolbar{min-height:44px;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 12px;border-top:1px solid #e5e7eb;background:#f8fafc}
|
|
2396
|
+
.excel-wrapper .btn-group{min-width:0;max-width:100%;flex:1 1 auto;display:flex;align-items:center;gap:6px;overflow-x:auto;overflow-y:hidden;scrollbar-gutter:stable;scrollbar-width:thin;overscroll-behavior-x:contain}
|
|
2397
|
+
.excel-wrapper .sheet-tab{flex:0 0 auto;width:max-content;min-width:72px;max-width:min(260px,70vw);height:30px;border:1px solid transparent;border-radius:8px;padding:0 12px;background:transparent;color:#526173;font:inherit;font-size:12px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
|
|
2398
|
+
.excel-wrapper .sheet-tab:hover{background:#edf2f7}
|
|
2399
|
+
.excel-wrapper .sheet-tab.active{border-color:rgba(33,163,102,.28);background:rgba(33,163,102,.12);color:#137347}
|
|
2400
|
+
.excel-wrapper .summary{flex:0 0 auto;max-width:42%;overflow:hidden;color:#64748b;font-size:12px;font-weight:700;white-space:nowrap;text-overflow:ellipsis}
|
|
2401
|
+
.excel-wrapper .hidden{display:none!important}
|
|
2402
|
+
.excel-wrapper[data-spreadsheet-theme='dark']{color-scheme:dark;background:var(--file-viewer-render-surface-background,#0f172a);color:#e5e7eb}
|
|
2403
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .table-wrapper{background:#111827}
|
|
2404
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .toolbar{background:#111827;border-color:rgba(148,163,184,.22)}
|
|
2405
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .sheet-tab{color:#cbd5e1}
|
|
2406
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .sheet-tab:hover{background:#1f2937}
|
|
2407
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .sheet-tab.active{border-color:rgba(52,211,153,.38);background:rgba(33,163,102,.2);color:#6ee7b7}
|
|
2408
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .summary,.excel-wrapper[data-spreadsheet-theme='dark'] .sheet-loading-summary{color:#94a3b8}
|
|
2409
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .loading{background:rgba(2,6,23,.9)}
|
|
2410
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .loading-card{border-color:rgba(52,211,153,.2);background:rgba(17,24,39,.96);box-shadow:0 24px 58px rgba(0,0,0,.42)}
|
|
2411
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .loading-copy strong{color:#f0fdf4}
|
|
2412
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .loading-copy p{color:#94a3b8}
|
|
2413
|
+
.excel-wrapper[data-spreadsheet-theme='dark'] .error{border-color:rgba(251,146,60,.28);background:#2a1710;color:#fdba74;box-shadow:0 20px 48px rgba(0,0,0,.36)}
|
|
2414
|
+
@keyframes file-viewer-spreadsheet-loading-spin{to{transform:rotate(360deg)}}
|
|
2415
|
+
@keyframes file-viewer-spreadsheet-loading-pulse{0%,100%{opacity:.55;transform:scale(.9)}50%{opacity:1;transform:scale(1)}}
|
|
2416
|
+
@media (max-width:720px){.excel-wrapper .toolbar{align-items:stretch;flex-direction:column}.excel-wrapper .btn-group{flex:0 0 auto}.excel-wrapper .summary{max-width:none;white-space:normal}.excel-wrapper .sheet-loading{left:12px;right:12px;bottom:58px;justify-content:center}.excel-wrapper .loading-card{margin:18px;flex-direction:column;text-align:center}}
|
|
2417
|
+
`;
|
|
2418
|
+
const scopedSpreadsheetStyle = spreadsheetStyle.replace(/\.excel-wrapper/g, SPREADSHEET_STYLE_SCOPE);
|
|
2419
|
+
const isEVirtTableConstructor = (value) => {
|
|
2420
|
+
return typeof value === "function";
|
|
2421
|
+
};
|
|
2422
|
+
const asModuleRecord = (value) => {
|
|
2423
|
+
return value && typeof value === "object" ? value : null;
|
|
2424
|
+
};
|
|
2425
|
+
const getEVirtTableGlobalCandidate = () => {
|
|
2426
|
+
const globalRecord = typeof globalThis === "undefined" ? null : globalThis;
|
|
2427
|
+
return globalRecord === null || globalRecord === void 0 ? void 0 : globalRecord.EVirtTable;
|
|
2428
|
+
};
|
|
2429
|
+
const resolveEVirtTableConstructor = (module) => {
|
|
2430
|
+
const record = asModuleRecord(module);
|
|
2431
|
+
const defaultRecord = asModuleRecord(record === null || record === void 0 ? void 0 : record.default);
|
|
2432
|
+
const moduleExportsRecord = asModuleRecord(record === null || record === void 0 ? void 0 : record["module.exports"]);
|
|
2433
|
+
const globalCandidate = getEVirtTableGlobalCandidate();
|
|
2434
|
+
const candidates = [
|
|
2435
|
+
module,
|
|
2436
|
+
record === null || record === void 0 ? void 0 : record.default,
|
|
2437
|
+
record === null || record === void 0 ? void 0 : record.EVirtTable,
|
|
2438
|
+
record === null || record === void 0 ? void 0 : record["module.exports"],
|
|
2439
|
+
defaultRecord === null || defaultRecord === void 0 ? void 0 : defaultRecord.default,
|
|
2440
|
+
defaultRecord === null || defaultRecord === void 0 ? void 0 : defaultRecord.EVirtTable,
|
|
2441
|
+
moduleExportsRecord === null || moduleExportsRecord === void 0 ? void 0 : moduleExportsRecord.default,
|
|
2442
|
+
moduleExportsRecord === null || moduleExportsRecord === void 0 ? void 0 : moduleExportsRecord.EVirtTable,
|
|
2443
|
+
globalCandidate
|
|
2444
|
+
];
|
|
2445
|
+
const constructor = candidates.find(isEVirtTableConstructor);
|
|
2446
|
+
if (!constructor) {
|
|
2447
|
+
const keys = record ? Object.keys(record).join(", ") : typeof module;
|
|
2448
|
+
throw new Error(`Unable to resolve e-virt-table constructor from module exports: ${keys}`);
|
|
2449
|
+
}
|
|
2450
|
+
return constructor;
|
|
2451
|
+
};
|
|
2452
|
+
const isEVirtTableStyleText = (value) => {
|
|
2453
|
+
return E_VIRT_TABLE_STYLE_MARKERS.every((marker) => value.includes(marker));
|
|
2454
|
+
};
|
|
2455
|
+
const collectEVirtTableStyleDocuments = (documentRef) => [
|
|
2456
|
+
documentRef,
|
|
2457
|
+
typeof document === "undefined" ? null : document
|
|
2458
|
+
].filter((value, index, values) => !!value && values.indexOf(value) === index);
|
|
2459
|
+
const collectStyleElements = (documents) => documents.flatMap((candidateDocument) => {
|
|
2460
|
+
var _a;
|
|
2461
|
+
return Array.from(((_a = candidateDocument.head) === null || _a === void 0 ? void 0 : _a.querySelectorAll("style")) || []);
|
|
2462
|
+
});
|
|
2463
|
+
let loadedEVirtTableStyleText = "";
|
|
2464
|
+
const resolveEVirtTableStyleText = (documentRef) => {
|
|
2465
|
+
var _a;
|
|
2466
|
+
const styles = collectStyleElements(collectEVirtTableStyleDocuments(documentRef));
|
|
2467
|
+
for (let index = styles.length - 1; index >= 0; index -= 1) {
|
|
2468
|
+
const cssText = ((_a = styles[index]) === null || _a === void 0 ? void 0 : _a.textContent) || "";
|
|
2469
|
+
if (isEVirtTableStyleText(cssText)) {
|
|
2470
|
+
return cssText;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
return "";
|
|
2474
|
+
};
|
|
2475
|
+
const loadEVirtTable = async (documentRef) => {
|
|
2476
|
+
const documents = collectEVirtTableStyleDocuments(documentRef);
|
|
2477
|
+
const stylesBeforeImport = new Set(collectStyleElements(documents));
|
|
2478
|
+
const module = await __vitePreload(() => import("./index.es-eU8DIFZe.js"), true ? [] : void 0, import.meta.url);
|
|
2479
|
+
const injectedStyles = collectStyleElements(documents).filter((style) => !stylesBeforeImport.has(style) && isEVirtTableStyleText(style.textContent || ""));
|
|
2480
|
+
const injectedStyle = injectedStyles[injectedStyles.length - 1];
|
|
2481
|
+
if (injectedStyle) {
|
|
2482
|
+
loadedEVirtTableStyleText = injectedStyle.textContent || "";
|
|
2483
|
+
}
|
|
2484
|
+
injectedStyles.forEach((style) => style.remove());
|
|
2485
|
+
return {
|
|
2486
|
+
constructor: resolveEVirtTableConstructor(module),
|
|
2487
|
+
// The vendor entry injects CSS while its dynamic import is evaluated.
|
|
2488
|
+
// Prefer that newly-created node so an app's independently loaded table
|
|
2489
|
+
// version cannot be mistaken for the renderer-owned dependency.
|
|
2490
|
+
styleText: loadedEVirtTableStyleText || resolveEVirtTableStyleText(documentRef)
|
|
2491
|
+
};
|
|
2492
|
+
};
|
|
2493
|
+
const scopeEVirtTableStyleText = (cssText, shadow) => {
|
|
2494
|
+
const rootScope = shadow ? `:host,${SPREADSHEET_STYLE_SCOPE}` : SPREADSHEET_STYLE_SCOPE;
|
|
2495
|
+
const darkScope = shadow ? `:host(.dark),${SPREADSHEET_STYLE_SCOPE}[data-spreadsheet-theme='dark']` : `${SPREADSHEET_STYLE_SCOPE}[data-spreadsheet-theme='dark']`;
|
|
2496
|
+
const scopeSelector = (selector) => {
|
|
2497
|
+
const normalized = selector.trim();
|
|
2498
|
+
if (normalized === ":root") {
|
|
2499
|
+
return rootScope;
|
|
2500
|
+
}
|
|
2501
|
+
if (normalized === ".dark") {
|
|
2502
|
+
return darkScope;
|
|
2503
|
+
}
|
|
2504
|
+
return `${SPREADSHEET_STYLE_SCOPE} ${normalized}`;
|
|
2505
|
+
};
|
|
2506
|
+
return cssText.replace(/@keyframes\s+rotate\b/g, `@keyframes ${E_VIRT_TABLE_ROTATE_KEYFRAME}`).replace(/animation:\s*rotate\b/g, `animation:${E_VIRT_TABLE_ROTATE_KEYFRAME}`).replace(/(^|})\s*(:root|\.dark|\.e-virt-table-[^{}]+)\{/g, (_match, boundary, selectorList) => {
|
|
2507
|
+
const scopedSelectors = selectorList.split(",").map(scopeSelector).join(",");
|
|
2508
|
+
return `${boundary}${scopedSelectors}{`;
|
|
2509
|
+
});
|
|
2510
|
+
};
|
|
2511
|
+
const getTargetWindow = (target) => {
|
|
2512
|
+
return target.ownerDocument.defaultView;
|
|
2513
|
+
};
|
|
2514
|
+
const getDocumentBaseUrl = (target) => {
|
|
2515
|
+
return resolveFileViewerRuntimeAssetBaseUrl(target.ownerDocument);
|
|
2516
|
+
};
|
|
2517
|
+
const callListener = (listener, event) => {
|
|
2518
|
+
if (!listener) {
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
if (typeof listener === "function") {
|
|
2522
|
+
listener(event);
|
|
2523
|
+
return;
|
|
2524
|
+
}
|
|
2525
|
+
listener.handleEvent(event);
|
|
2526
|
+
};
|
|
2527
|
+
class MainThreadSpreadsheetWorker {
|
|
2528
|
+
constructor(targetWindow) {
|
|
2529
|
+
this.onmessage = null;
|
|
2530
|
+
this.onerror = null;
|
|
2531
|
+
this.destroyed = false;
|
|
2532
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
2533
|
+
this.parserPromise = null;
|
|
2534
|
+
this.context = null;
|
|
2535
|
+
this.targetWindow = targetWindow;
|
|
2536
|
+
}
|
|
2537
|
+
addEventListener(type, listener) {
|
|
2538
|
+
var _a;
|
|
2539
|
+
if (!this.listeners.has(type)) {
|
|
2540
|
+
this.listeners.set(type, /* @__PURE__ */ new Set());
|
|
2541
|
+
}
|
|
2542
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.add(listener);
|
|
2543
|
+
}
|
|
2544
|
+
removeEventListener(type, listener) {
|
|
2545
|
+
var _a;
|
|
2546
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.delete(listener);
|
|
2547
|
+
}
|
|
2548
|
+
terminate() {
|
|
2549
|
+
this.destroyed = true;
|
|
2550
|
+
this.listeners.clear();
|
|
2551
|
+
}
|
|
2552
|
+
postMessage(message) {
|
|
2553
|
+
void this.handleMessage(message);
|
|
2554
|
+
}
|
|
2555
|
+
async loadParser() {
|
|
2556
|
+
if (!this.parserPromise) {
|
|
2557
|
+
this.parserPromise = __vitePreload(() => import("./parser-DYEwxOAz.js"), true ? __vite__mapDeps([0,1,2,3,4,5,6,7]) : void 0, import.meta.url);
|
|
2558
|
+
}
|
|
2559
|
+
const parser = await this.parserPromise;
|
|
2560
|
+
if (!this.context) {
|
|
2561
|
+
this.context = parser.createSpreadsheetParserContext();
|
|
2562
|
+
}
|
|
2563
|
+
return parser;
|
|
2564
|
+
}
|
|
2565
|
+
dispatch(type, event) {
|
|
2566
|
+
var _a;
|
|
2567
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((listener) => callListener(listener, event));
|
|
2568
|
+
}
|
|
2569
|
+
dispatchMessage(data) {
|
|
2570
|
+
var _a;
|
|
2571
|
+
const targetGlobal = this.targetWindow;
|
|
2572
|
+
const MessageEventCtor = (targetGlobal === null || targetGlobal === void 0 ? void 0 : targetGlobal.MessageEvent) || (typeof MessageEvent !== "undefined" ? MessageEvent : void 0);
|
|
2573
|
+
const event = MessageEventCtor ? new MessageEventCtor("message", { data }) : { type: "message", data };
|
|
2574
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
2575
|
+
this.dispatch("message", event);
|
|
2576
|
+
}
|
|
2577
|
+
dispatchError(error) {
|
|
2578
|
+
var _a;
|
|
2579
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2580
|
+
const targetGlobal = this.targetWindow;
|
|
2581
|
+
const ErrorEventCtor = (targetGlobal === null || targetGlobal === void 0 ? void 0 : targetGlobal.ErrorEvent) || (typeof ErrorEvent !== "undefined" ? ErrorEvent : void 0);
|
|
2582
|
+
const event = ErrorEventCtor ? new ErrorEventCtor("error", { message, error }) : { type: "error", message, error };
|
|
2583
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
2584
|
+
this.dispatch("error", event);
|
|
2585
|
+
}
|
|
2586
|
+
async handleMessage(message) {
|
|
2587
|
+
if (this.destroyed) {
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2590
|
+
try {
|
|
2591
|
+
const parser = await this.loadParser();
|
|
2592
|
+
const responses = await parser.handleSpreadsheetWorkerRequest(this.context || parser.createSpreadsheetParserContext(), message);
|
|
2593
|
+
responses.forEach((response) => {
|
|
2594
|
+
if (!this.destroyed) {
|
|
2595
|
+
this.dispatchMessage(response);
|
|
2596
|
+
}
|
|
2597
|
+
});
|
|
2598
|
+
} catch (error) {
|
|
2599
|
+
if (!this.destroyed) {
|
|
2600
|
+
this.dispatchError(error);
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
class AutoFallbackSpreadsheetWorker {
|
|
2606
|
+
constructor(primary, createFallback) {
|
|
2607
|
+
this.createFallback = createFallback;
|
|
2608
|
+
this.onmessage = null;
|
|
2609
|
+
this.onerror = null;
|
|
2610
|
+
this.destroyed = false;
|
|
2611
|
+
this.usingFallback = false;
|
|
2612
|
+
this.hasPrimaryMessage = false;
|
|
2613
|
+
this.pendingMessages = [];
|
|
2614
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
2615
|
+
this.handleMessage = (event) => {
|
|
2616
|
+
var _a;
|
|
2617
|
+
if (this.destroyed) {
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
if (!this.usingFallback) {
|
|
2621
|
+
this.hasPrimaryMessage = true;
|
|
2622
|
+
this.pendingMessages.length = 0;
|
|
2623
|
+
}
|
|
2624
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
2625
|
+
this.dispatch("message", event);
|
|
2626
|
+
};
|
|
2627
|
+
this.handleError = (event) => {
|
|
2628
|
+
var _a;
|
|
2629
|
+
if (this.destroyed) {
|
|
2630
|
+
return;
|
|
2631
|
+
}
|
|
2632
|
+
if (!this.usingFallback && !this.hasPrimaryMessage) {
|
|
2633
|
+
this.switchToFallback(event);
|
|
2634
|
+
return;
|
|
2635
|
+
}
|
|
2636
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, event);
|
|
2637
|
+
this.dispatch("error", event);
|
|
2638
|
+
};
|
|
2639
|
+
this.active = primary;
|
|
2640
|
+
this.attach(primary);
|
|
2641
|
+
}
|
|
2642
|
+
addEventListener(type, listener) {
|
|
2643
|
+
var _a;
|
|
2644
|
+
if (!this.listeners.has(type)) {
|
|
2645
|
+
this.listeners.set(type, /* @__PURE__ */ new Set());
|
|
2646
|
+
}
|
|
2647
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.add(listener);
|
|
2648
|
+
}
|
|
2649
|
+
removeEventListener(type, listener) {
|
|
2650
|
+
var _a;
|
|
2651
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.delete(listener);
|
|
2652
|
+
}
|
|
2653
|
+
terminate() {
|
|
2654
|
+
this.destroyed = true;
|
|
2655
|
+
this.detach(this.active);
|
|
2656
|
+
this.active.terminate();
|
|
2657
|
+
this.pendingMessages.length = 0;
|
|
2658
|
+
this.listeners.clear();
|
|
2659
|
+
}
|
|
2660
|
+
postMessage(message) {
|
|
2661
|
+
if (this.destroyed) {
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
if (!this.usingFallback && !this.hasPrimaryMessage) {
|
|
2665
|
+
this.pendingMessages.push(message);
|
|
2666
|
+
}
|
|
2667
|
+
this.active.postMessage(message);
|
|
2668
|
+
}
|
|
2669
|
+
attach(worker) {
|
|
2670
|
+
worker.addEventListener("message", this.handleMessage);
|
|
2671
|
+
worker.addEventListener("error", this.handleError);
|
|
2672
|
+
}
|
|
2673
|
+
detach(worker) {
|
|
2674
|
+
worker.removeEventListener("message", this.handleMessage);
|
|
2675
|
+
worker.removeEventListener("error", this.handleError);
|
|
2676
|
+
}
|
|
2677
|
+
dispatch(type, event) {
|
|
2678
|
+
var _a;
|
|
2679
|
+
(_a = this.listeners.get(type)) === null || _a === void 0 ? void 0 : _a.forEach((listener) => callListener(listener, event));
|
|
2680
|
+
}
|
|
2681
|
+
switchToFallback(event) {
|
|
2682
|
+
var _a;
|
|
2683
|
+
const messages = this.pendingMessages.splice(0);
|
|
2684
|
+
this.detach(this.active);
|
|
2685
|
+
this.active.terminate();
|
|
2686
|
+
this.usingFallback = true;
|
|
2687
|
+
this.hasPrimaryMessage = false;
|
|
2688
|
+
try {
|
|
2689
|
+
this.active = this.createFallback();
|
|
2690
|
+
this.attach(this.active);
|
|
2691
|
+
console.warn("[file-viewer] Spreadsheet Worker 自动模式启动失败,已回退到主线程解析。", event.message || event.type);
|
|
2692
|
+
messages.forEach((message) => this.active.postMessage(message));
|
|
2693
|
+
} catch (fallbackError) {
|
|
2694
|
+
const targetGlobal = typeof window !== "undefined" ? window : void 0;
|
|
2695
|
+
const ErrorEventCtor = (targetGlobal === null || targetGlobal === void 0 ? void 0 : targetGlobal.ErrorEvent) || (typeof ErrorEvent !== "undefined" ? ErrorEvent : void 0);
|
|
2696
|
+
const message = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
2697
|
+
const nextEvent = ErrorEventCtor ? new ErrorEventCtor("error", { message, error: fallbackError }) : { type: "error", message, error: fallbackError };
|
|
2698
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, nextEvent);
|
|
2699
|
+
this.dispatch("error", nextEvent);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
const createMainThreadSpreadsheetWorker = (target) => {
|
|
2704
|
+
return new MainThreadSpreadsheetWorker(getTargetWindow(target));
|
|
2705
|
+
};
|
|
2706
|
+
const getSpreadsheetWorkerMode = (context) => {
|
|
2707
|
+
var _a, _b, _c;
|
|
2708
|
+
return (_c = (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.spreadsheet) === null || _b === void 0 ? void 0 : _b.worker) !== null && _c !== void 0 ? _c : "auto";
|
|
2709
|
+
};
|
|
2710
|
+
const shouldUseSpreadsheetWorker = (byteLength, context) => {
|
|
2711
|
+
var _a;
|
|
2712
|
+
const spreadsheetOptions = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.spreadsheet;
|
|
2713
|
+
const workerMode = getSpreadsheetWorkerMode(context);
|
|
2714
|
+
if (workerMode === true) {
|
|
2715
|
+
return true;
|
|
2716
|
+
}
|
|
2717
|
+
if (workerMode === false) {
|
|
2718
|
+
return false;
|
|
2719
|
+
}
|
|
2720
|
+
const threshold = typeof (spreadsheetOptions === null || spreadsheetOptions === void 0 ? void 0 : spreadsheetOptions.workerAutoThreshold) === "number" && Number.isFinite(spreadsheetOptions.workerAutoThreshold) && spreadsheetOptions.workerAutoThreshold >= 0 ? spreadsheetOptions.workerAutoThreshold : DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD;
|
|
2721
|
+
return byteLength >= threshold;
|
|
2722
|
+
};
|
|
2723
|
+
const wrapAutoSpreadsheetWorker = (worker, target, context) => {
|
|
2724
|
+
if (getSpreadsheetWorkerMode(context) !== "auto") {
|
|
2725
|
+
return worker;
|
|
2726
|
+
}
|
|
2727
|
+
return new AutoFallbackSpreadsheetWorker(worker, () => createMainThreadSpreadsheetWorker(target));
|
|
2728
|
+
};
|
|
2729
|
+
const createSpreadsheetWorkerFactory = (target, bufferByteLength, context) => {
|
|
2730
|
+
return () => {
|
|
2731
|
+
var _a;
|
|
2732
|
+
if (!shouldUseSpreadsheetWorker(bufferByteLength, context)) {
|
|
2733
|
+
return createMainThreadSpreadsheetWorker(target);
|
|
2734
|
+
}
|
|
2735
|
+
const view = getTargetWindow(target);
|
|
2736
|
+
const WorkerCtor = (view === null || view === void 0 ? void 0 : view.Worker) || (typeof Worker !== "undefined" ? Worker : void 0);
|
|
2737
|
+
if (!WorkerCtor) {
|
|
2738
|
+
return createMainThreadSpreadsheetWorker(target);
|
|
2739
|
+
}
|
|
2740
|
+
const workerUrl = resolveFileViewerSpreadsheetWorkerUrl((_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.spreadsheet, getDocumentBaseUrl(target));
|
|
2741
|
+
try {
|
|
2742
|
+
return wrapAutoSpreadsheetWorker(new WorkerCtor(workerUrl, { type: "module" }), target, context);
|
|
2743
|
+
} catch (moduleWorkerError) {
|
|
2744
|
+
try {
|
|
2745
|
+
return wrapAutoSpreadsheetWorker(new WorkerCtor(workerUrl), target, context);
|
|
2746
|
+
} catch (classicWorkerError) {
|
|
2747
|
+
console.warn("[file-viewer] Spreadsheet Worker 无法创建,已回退到主线程解析。", classicWorkerError || moduleWorkerError);
|
|
2748
|
+
return createMainThreadSpreadsheetWorker(target);
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
};
|
|
2753
|
+
const createStyle = (documentRef, cssText = scopedSpreadsheetStyle) => {
|
|
2754
|
+
const style = documentRef.createElement("style");
|
|
2755
|
+
style.textContent = cssText;
|
|
2756
|
+
return style;
|
|
2757
|
+
};
|
|
2758
|
+
const createEVirtTableStyle = (documentRef, target, cssText) => {
|
|
2759
|
+
var _a;
|
|
2760
|
+
if (!cssText) {
|
|
2761
|
+
throw new Error("Unable to resolve the e-virt-table stylesheet for the spreadsheet render surface.");
|
|
2762
|
+
}
|
|
2763
|
+
const rootNode = target.getRootNode();
|
|
2764
|
+
const ShadowRootCtor = (_a = target.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.ShadowRoot;
|
|
2765
|
+
const shadow = !!ShadowRootCtor && rootNode instanceof ShadowRootCtor;
|
|
2766
|
+
const style = createStyle(documentRef, scopeEVirtTableStyleText(cssText, shadow));
|
|
2767
|
+
style.dataset.fileViewerVendorStyle = "e-virt-table";
|
|
2768
|
+
return style;
|
|
2769
|
+
};
|
|
2770
|
+
const setHidden = (element, hidden) => {
|
|
2771
|
+
element.classList.toggle("hidden", hidden);
|
|
2772
|
+
};
|
|
2773
|
+
const clampZoom = (value) => {
|
|
2774
|
+
return Math.min(2.5, Math.max(0.5, Number(value.toFixed(2))));
|
|
2775
|
+
};
|
|
2776
|
+
const serializeSpreadsheetCopyCell = (value) => {
|
|
2777
|
+
if (value === null || value === void 0) {
|
|
2778
|
+
return "";
|
|
2779
|
+
}
|
|
2780
|
+
const text = `${value}`;
|
|
2781
|
+
return /[\t\r\n"]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
2782
|
+
};
|
|
2783
|
+
const serializeSpreadsheetCopyData = (data) => {
|
|
2784
|
+
if (!Array.isArray(data)) {
|
|
2785
|
+
return serializeSpreadsheetCopyCell(data);
|
|
2786
|
+
}
|
|
2787
|
+
return data.map((row) => {
|
|
2788
|
+
if (!Array.isArray(row)) {
|
|
2789
|
+
return serializeSpreadsheetCopyCell(row);
|
|
2790
|
+
}
|
|
2791
|
+
return row.map(serializeSpreadsheetCopyCell).join(" ");
|
|
2792
|
+
}).join("\n");
|
|
2793
|
+
};
|
|
2794
|
+
const copyTextWithTextareaFallback = (documentRef, text) => {
|
|
2795
|
+
var _a;
|
|
2796
|
+
const body = documentRef.body;
|
|
2797
|
+
if (!body || typeof documentRef.execCommand !== "function") {
|
|
2798
|
+
return false;
|
|
2799
|
+
}
|
|
2800
|
+
const activeElement = documentRef.activeElement;
|
|
2801
|
+
const textarea = documentRef.createElement("textarea");
|
|
2802
|
+
textarea.value = text;
|
|
2803
|
+
textarea.setAttribute("readonly", "true");
|
|
2804
|
+
textarea.setAttribute("aria-hidden", "true");
|
|
2805
|
+
Object.assign(textarea.style, {
|
|
2806
|
+
position: "fixed",
|
|
2807
|
+
top: "0",
|
|
2808
|
+
left: "0",
|
|
2809
|
+
width: "1px",
|
|
2810
|
+
height: "1px",
|
|
2811
|
+
padding: "0",
|
|
2812
|
+
border: "0",
|
|
2813
|
+
opacity: "0",
|
|
2814
|
+
pointerEvents: "none"
|
|
2815
|
+
});
|
|
2816
|
+
body.appendChild(textarea);
|
|
2817
|
+
textarea.focus({ preventScroll: true });
|
|
2818
|
+
textarea.select();
|
|
2819
|
+
textarea.setSelectionRange(0, textarea.value.length);
|
|
2820
|
+
let copied = false;
|
|
2821
|
+
try {
|
|
2822
|
+
copied = documentRef.execCommand("copy");
|
|
2823
|
+
} finally {
|
|
2824
|
+
textarea.remove();
|
|
2825
|
+
(_a = activeElement === null || activeElement === void 0 ? void 0 : activeElement.focus) === null || _a === void 0 ? void 0 : _a.call(activeElement, { preventScroll: true });
|
|
2826
|
+
}
|
|
2827
|
+
return copied;
|
|
2828
|
+
};
|
|
2829
|
+
const writeSpreadsheetClipboard = async (documentRef, text) => {
|
|
2830
|
+
var _a;
|
|
2831
|
+
const targetWindow = documentRef.defaultView;
|
|
2832
|
+
const clipboard = (_a = targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.navigator) === null || _a === void 0 ? void 0 : _a.clipboard;
|
|
2833
|
+
const useAsyncClipboard = !!(targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.isSecureContext) && typeof (clipboard === null || clipboard === void 0 ? void 0 : clipboard.writeText) === "function";
|
|
2834
|
+
if (useAsyncClipboard) {
|
|
2835
|
+
try {
|
|
2836
|
+
await clipboard.writeText(text);
|
|
2837
|
+
return true;
|
|
2838
|
+
} catch {
|
|
2839
|
+
return copyTextWithTextareaFallback(documentRef, text);
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
return copyTextWithTextareaFallback(documentRef, text);
|
|
2843
|
+
};
|
|
2844
|
+
const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
2845
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
2846
|
+
const documentRef = target.ownerDocument;
|
|
2847
|
+
const loadedEVirtTable = await loadEVirtTable(documentRef);
|
|
2848
|
+
const EVirtTable = loadedEVirtTable.constructor;
|
|
2849
|
+
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
2850
|
+
const zoomEmitter = createFileViewerZoomChangeEmitter();
|
|
2851
|
+
const systemDark = (_c = (_b = (_a = documentRef.defaultView) === null || _a === void 0 ? void 0 : _a.matchMedia) === null || _b === void 0 ? void 0 : _b.call(_a, "(prefers-color-scheme: dark)").matches) !== null && _c !== void 0 ? _c : false;
|
|
2852
|
+
const darkMode = resolveFileViewerColorScheme((_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.theme, systemDark) === "dark";
|
|
2853
|
+
const root = documentRef.createElement("div");
|
|
2854
|
+
root.className = "excel-wrapper";
|
|
2855
|
+
root.dataset.fileViewerSpreadsheetRoot = "true";
|
|
2856
|
+
root.dataset.spreadsheetTheme = darkMode ? "dark" : "light";
|
|
2857
|
+
root.dataset.viewerZoomProvider = "xlsx";
|
|
2858
|
+
const loading = documentRef.createElement("div");
|
|
2859
|
+
loading.className = "loading";
|
|
2860
|
+
const loadingCard = documentRef.createElement("div");
|
|
2861
|
+
loadingCard.className = "loading-card";
|
|
2862
|
+
const loadingBrand = documentRef.createElement("div");
|
|
2863
|
+
loadingBrand.className = "loading-brand";
|
|
2864
|
+
loadingBrand.textContent = "XLSX";
|
|
2865
|
+
const loadingCopy = documentRef.createElement("div");
|
|
2866
|
+
loadingCopy.className = "loading-copy";
|
|
2867
|
+
const loadingKicker = documentRef.createElement("span");
|
|
2868
|
+
loadingKicker.className = "loading-kicker";
|
|
2869
|
+
loadingKicker.textContent = t("spreadsheet.loading.kicker");
|
|
2870
|
+
const loadingTitle = documentRef.createElement("strong");
|
|
2871
|
+
loadingTitle.dataset.loadingTitle = "true";
|
|
2872
|
+
loadingTitle.textContent = t("spreadsheet.loading.title");
|
|
2873
|
+
const loadingHint = documentRef.createElement("p");
|
|
2874
|
+
loadingHint.textContent = t("spreadsheet.loading.hint");
|
|
2875
|
+
loadingCopy.append(loadingKicker, loadingTitle, loadingHint);
|
|
2876
|
+
const loadingSpinner = documentRef.createElement("span");
|
|
2877
|
+
loadingSpinner.className = "loading-spinner";
|
|
2878
|
+
loadingCard.append(loadingBrand, loadingCopy, loadingSpinner);
|
|
2879
|
+
loading.appendChild(loadingCard);
|
|
2880
|
+
const error = documentRef.createElement("div");
|
|
2881
|
+
error.className = "error hidden";
|
|
2882
|
+
const tableWrapper = documentRef.createElement("div");
|
|
2883
|
+
tableWrapper.className = "table-wrapper";
|
|
2884
|
+
const sheetLoading = documentRef.createElement("div");
|
|
2885
|
+
sheetLoading.className = "sheet-loading hidden";
|
|
2886
|
+
const sheetLoadingDot = documentRef.createElement("span");
|
|
2887
|
+
sheetLoadingDot.className = "sheet-loading-dot";
|
|
2888
|
+
const sheetLoadingText = documentRef.createElement("span");
|
|
2889
|
+
sheetLoadingText.textContent = t("spreadsheet.loading.streaming");
|
|
2890
|
+
const sheetLoadingSummary = documentRef.createElement("span");
|
|
2891
|
+
sheetLoadingSummary.className = "sheet-loading-summary";
|
|
2892
|
+
sheetLoading.append(sheetLoadingDot, sheetLoadingText, sheetLoadingSummary);
|
|
2893
|
+
const tableHostShell = documentRef.createElement("div");
|
|
2894
|
+
tableHostShell.className = "table-host";
|
|
2895
|
+
const tableHost = documentRef.createElement("div");
|
|
2896
|
+
tableHost.className = "table-target";
|
|
2897
|
+
const imageViewport = documentRef.createElement("div");
|
|
2898
|
+
imageViewport.className = "excel-image-viewport hidden";
|
|
2899
|
+
const imageLayer = documentRef.createElement("div");
|
|
2900
|
+
imageLayer.className = "excel-image-layer";
|
|
2901
|
+
imageViewport.appendChild(imageLayer);
|
|
2902
|
+
tableHostShell.append(tableHost, imageViewport);
|
|
2903
|
+
tableWrapper.append(sheetLoading, tableHostShell);
|
|
2904
|
+
const toolbar = documentRef.createElement("div");
|
|
2905
|
+
toolbar.className = "toolbar";
|
|
2906
|
+
const sheetTabsBar = documentRef.createElement("div");
|
|
2907
|
+
sheetTabsBar.className = "btn-group";
|
|
2908
|
+
sheetTabsBar.setAttribute("aria-label", t("spreadsheet.tabs.ariaLabel"));
|
|
2909
|
+
const summary = documentRef.createElement("div");
|
|
2910
|
+
summary.className = "summary";
|
|
2911
|
+
toolbar.append(sheetTabsBar, summary);
|
|
2912
|
+
root.append(loading, error, tableWrapper, toolbar);
|
|
2913
|
+
target.replaceChildren(createEVirtTableStyle(documentRef, target, loadedEVirtTable.styleText), createStyle(documentRef), root);
|
|
2914
|
+
let sheets = [];
|
|
2915
|
+
let sheetIndex = 0;
|
|
2916
|
+
let errorMessage = "";
|
|
2917
|
+
let totalRows = 0;
|
|
2918
|
+
let totalCols = 0;
|
|
2919
|
+
let sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
|
|
2920
|
+
let sheetInitializing = true;
|
|
2921
|
+
let hasInitialWindow = false;
|
|
2922
|
+
let loadedWindowCount = 0;
|
|
2923
|
+
let loadingWindowCount = 0;
|
|
2924
|
+
let sheetImages = [];
|
|
2925
|
+
let sheetCharts = [];
|
|
2926
|
+
let zoom = 1;
|
|
2927
|
+
let imageViewportState = {
|
|
2928
|
+
scrollX: 0,
|
|
2929
|
+
scrollY: 0,
|
|
2930
|
+
width: 0,
|
|
2931
|
+
height: 0
|
|
2932
|
+
};
|
|
2933
|
+
let loadingState = true;
|
|
2934
|
+
let virtualState = createEmptyVirtualState();
|
|
2935
|
+
const sheetStateCache = /* @__PURE__ */ new Map();
|
|
2936
|
+
const sheetImageCache = /* @__PURE__ */ new Map();
|
|
2937
|
+
const sheetChartCache = /* @__PURE__ */ new Map();
|
|
2938
|
+
let table = null;
|
|
2939
|
+
let resizeObserver = null;
|
|
2940
|
+
let resizeFrame = 0;
|
|
2941
|
+
let scrollFrame = 0;
|
|
2942
|
+
let layoutRefreshToken = 0;
|
|
2943
|
+
const layoutRefreshTimers = [];
|
|
2944
|
+
let viewportRange = { start: 0, end: 0 };
|
|
2945
|
+
let scrollDirection = 1;
|
|
2946
|
+
let lastScrollY = 0;
|
|
2947
|
+
let sheetSessionId = 0;
|
|
2948
|
+
let disposed = false;
|
|
2949
|
+
let hasNotifiedFirstPaint = false;
|
|
2950
|
+
const resizableColumns = ((_f = (_e = context === null || context === void 0 ? void 0 : context.options) === null || _e === void 0 ? void 0 : _e.spreadsheet) === null || _f === void 0 ? void 0 : _f.resizableColumns) === true;
|
|
2951
|
+
const resizableRows = ((_h = (_g = context === null || context === void 0 ? void 0 : context.options) === null || _g === void 0 ? void 0 : _g.spreadsheet) === null || _h === void 0 ? void 0 : _h.resizableRows) === true;
|
|
2952
|
+
const controller = createFileViewerWorkerController(createSpreadsheetWorkerFactory(target, buffer.byteLength, context), { logErrors: false });
|
|
2953
|
+
const getActiveSheet = () => sheets.find((sheet) => sheet.id === sheetIndex);
|
|
2954
|
+
const getSheetTabs = () => {
|
|
2955
|
+
const visible = sheets.filter((sheet) => !sheet.hidden);
|
|
2956
|
+
return visible.length ? visible : sheets;
|
|
2957
|
+
};
|
|
2958
|
+
const getActiveSheetId = () => {
|
|
2959
|
+
var _a2;
|
|
2960
|
+
return sheetIndex !== null && sheetIndex !== void 0 ? sheetIndex : (_a2 = sheets[0]) === null || _a2 === void 0 ? void 0 : _a2.id;
|
|
2961
|
+
};
|
|
2962
|
+
const getHostHeight = () => tableHost.clientHeight || 0;
|
|
2963
|
+
const showBlockingLoading = () => !errorMessage && !hasInitialWindow && (loadingState || sheetInitializing);
|
|
2964
|
+
const showStreamingLoading = () => !showBlockingLoading() && !errorMessage && hasInitialWindow && loadingWindowCount > 0;
|
|
2965
|
+
const scalePx = (value) => Math.max(1, Math.round(value * zoom));
|
|
2966
|
+
const scaleRowHeight = (value) => Math.max(0.1, Math.round(value * zoom));
|
|
2967
|
+
const getSheetLoadingText = () => {
|
|
2968
|
+
var _a2;
|
|
2969
|
+
if (!sheets.length) {
|
|
2970
|
+
return t("spreadsheet.state.parsingWorkbook");
|
|
2971
|
+
}
|
|
2972
|
+
const activeName = (_a2 = getActiveSheet()) === null || _a2 === void 0 ? void 0 : _a2.name;
|
|
2973
|
+
return activeName ? t("spreadsheet.state.preparingSheetNamed", { name: activeName }) : t("spreadsheet.state.preparingSheet");
|
|
2974
|
+
};
|
|
2975
|
+
const getCachedSummary = () => {
|
|
2976
|
+
if (!totalRows) {
|
|
2977
|
+
return "";
|
|
2978
|
+
}
|
|
2979
|
+
const cachedRows = Math.min(loadedWindowCount * WINDOW_SIZE, totalRows);
|
|
2980
|
+
return t("spreadsheet.state.cachedRows", {
|
|
2981
|
+
cached: cachedRows.toLocaleString(),
|
|
2982
|
+
total: totalRows.toLocaleString()
|
|
2983
|
+
});
|
|
2984
|
+
};
|
|
2985
|
+
const getStatusSummary = () => {
|
|
2986
|
+
var _a2, _b2;
|
|
2987
|
+
const rows = totalRows || ((_a2 = getActiveSheet()) === null || _a2 === void 0 ? void 0 : _a2.rowCount) || 0;
|
|
2988
|
+
const cols = totalCols || ((_b2 = getActiveSheet()) === null || _b2 === void 0 ? void 0 : _b2.colCount) || 0;
|
|
2989
|
+
if (!rows) {
|
|
2990
|
+
return "";
|
|
2991
|
+
}
|
|
2992
|
+
if (!cols) {
|
|
2993
|
+
return t("spreadsheet.state.rows", { rows: rows.toLocaleString() });
|
|
2994
|
+
}
|
|
2995
|
+
return t("spreadsheet.state.rowsAndColumns", {
|
|
2996
|
+
rows: rows.toLocaleString(),
|
|
2997
|
+
cols: cols.toLocaleString()
|
|
2998
|
+
});
|
|
2999
|
+
};
|
|
3000
|
+
const getZoomState = () => ({
|
|
3001
|
+
scale: zoom,
|
|
3002
|
+
label: `${Math.round(zoom * 100)}%`,
|
|
3003
|
+
canZoomIn: zoom < 2.5,
|
|
3004
|
+
canZoomOut: zoom > 0.5,
|
|
3005
|
+
canReset: zoom !== 1,
|
|
3006
|
+
minScale: 0.5,
|
|
3007
|
+
maxScale: 2.5
|
|
3008
|
+
});
|
|
3009
|
+
const getImageViewportScrollbarGuard = () => {
|
|
3010
|
+
const tableContainer = tableHost.querySelector(".e-virt-table-container");
|
|
3011
|
+
const vertical = tableContainer ? Math.max(tableContainer.offsetWidth - tableContainer.clientWidth, 0) : 0;
|
|
3012
|
+
const horizontal = tableContainer ? Math.max(tableContainer.offsetHeight - tableContainer.clientHeight, 0) : 0;
|
|
3013
|
+
return {
|
|
3014
|
+
vertical: vertical || EXCEL_IMAGE_SCROLLBAR_GUARD,
|
|
3015
|
+
horizontal: horizontal || EXCEL_IMAGE_SCROLLBAR_GUARD
|
|
3016
|
+
};
|
|
3017
|
+
};
|
|
3018
|
+
const renderImages = () => {
|
|
3019
|
+
const margin = 240;
|
|
3020
|
+
const guard = getImageViewportScrollbarGuard();
|
|
3021
|
+
const width = Math.max(imageViewportState.width - scalePx(INDEX_COLUMN_WIDTH) - guard.vertical, 0);
|
|
3022
|
+
const height = Math.max(imageViewportState.height - scalePx(HEADER_HEIGHT) - guard.horizontal, 0);
|
|
3023
|
+
const visibleImages = sheetImages.filter((image) => {
|
|
3024
|
+
const x = scalePx(image.left) - imageViewportState.scrollX;
|
|
3025
|
+
const y = scalePx(image.top) - imageViewportState.scrollY;
|
|
3026
|
+
return x + scalePx(image.width) >= -margin && x <= width + margin && y + scalePx(image.height) >= -margin && y <= height + margin;
|
|
3027
|
+
});
|
|
3028
|
+
const visibleCharts = sheetCharts.filter((chart) => {
|
|
3029
|
+
const x = scalePx(chart.left) - imageViewportState.scrollX;
|
|
3030
|
+
const y = scalePx(chart.top) - imageViewportState.scrollY;
|
|
3031
|
+
return x + scalePx(chart.width) >= -margin && x <= width + margin && y + scalePx(chart.height) >= -margin && y <= height + margin;
|
|
3032
|
+
});
|
|
3033
|
+
setHidden(imageViewport, visibleImages.length === 0 && visibleCharts.length === 0);
|
|
3034
|
+
Object.assign(imageViewport.style, {
|
|
3035
|
+
left: `${scalePx(INDEX_COLUMN_WIDTH)}px`,
|
|
3036
|
+
top: `${scalePx(HEADER_HEIGHT)}px`,
|
|
3037
|
+
right: "auto",
|
|
3038
|
+
bottom: "auto",
|
|
3039
|
+
width: `${width}px`,
|
|
3040
|
+
height: `${height}px`
|
|
3041
|
+
});
|
|
3042
|
+
imageLayer.style.transform = `translate(${-imageViewportState.scrollX}px, ${-imageViewportState.scrollY}px)`;
|
|
3043
|
+
const imageElements = visibleImages.map((image, index) => {
|
|
3044
|
+
const element = documentRef.createElement("img");
|
|
3045
|
+
element.className = "excel-image";
|
|
3046
|
+
element.src = image.src;
|
|
3047
|
+
element.alt = image.id;
|
|
3048
|
+
element.draggable = false;
|
|
3049
|
+
Object.assign(element.style, {
|
|
3050
|
+
left: `${scalePx(image.left)}px`,
|
|
3051
|
+
top: `${scalePx(image.top)}px`,
|
|
3052
|
+
width: `${scalePx(image.width)}px`,
|
|
3053
|
+
height: `${scalePx(image.height)}px`
|
|
3054
|
+
});
|
|
3055
|
+
element.dataset.imageIndex = `${index}`;
|
|
3056
|
+
return element;
|
|
3057
|
+
});
|
|
3058
|
+
const chartElements = visibleCharts.map((chart) => {
|
|
3059
|
+
const element = renderSpreadsheetChart(documentRef, chart);
|
|
3060
|
+
Object.assign(element.style, {
|
|
3061
|
+
left: `${scalePx(chart.left)}px`,
|
|
3062
|
+
top: `${scalePx(chart.top)}px`,
|
|
3063
|
+
width: `${scalePx(chart.width)}px`,
|
|
3064
|
+
height: `${scalePx(chart.height)}px`
|
|
3065
|
+
});
|
|
3066
|
+
return element;
|
|
3067
|
+
});
|
|
3068
|
+
imageLayer.replaceChildren(...imageElements, ...chartElements);
|
|
3069
|
+
};
|
|
3070
|
+
const scrollActiveSheetIntoView = () => {
|
|
3071
|
+
requestAnimationFrame(() => {
|
|
3072
|
+
var _a2;
|
|
3073
|
+
(_a2 = sheetTabsBar.querySelector(".sheet-tab.active")) === null || _a2 === void 0 ? void 0 : _a2.scrollIntoView({
|
|
3074
|
+
block: "nearest",
|
|
3075
|
+
inline: "center",
|
|
3076
|
+
behavior: "smooth"
|
|
3077
|
+
});
|
|
3078
|
+
});
|
|
3079
|
+
};
|
|
3080
|
+
const renderChrome = () => {
|
|
3081
|
+
setHidden(loading, !showBlockingLoading());
|
|
3082
|
+
const loadingTitle2 = loading.querySelector("[data-loading-title]");
|
|
3083
|
+
if (loadingTitle2) {
|
|
3084
|
+
loadingTitle2.textContent = getSheetLoadingText();
|
|
3085
|
+
}
|
|
3086
|
+
error.textContent = errorMessage;
|
|
3087
|
+
setHidden(error, !errorMessage);
|
|
3088
|
+
setHidden(sheetLoading, !showStreamingLoading());
|
|
3089
|
+
const cacheText = sheetLoading.querySelector(".sheet-loading-summary");
|
|
3090
|
+
if (cacheText) {
|
|
3091
|
+
cacheText.textContent = getCachedSummary();
|
|
3092
|
+
}
|
|
3093
|
+
summary.textContent = getStatusSummary();
|
|
3094
|
+
sheetTabsBar.replaceChildren(...getSheetTabs().map((sheet) => {
|
|
3095
|
+
const button = documentRef.createElement("button");
|
|
3096
|
+
button.type = "button";
|
|
3097
|
+
button.className = `sheet-tab${sheetIndex === sheet.id ? " active" : ""}`;
|
|
3098
|
+
button.title = sheet.name;
|
|
3099
|
+
button.textContent = sheet.name;
|
|
3100
|
+
button.setAttribute("aria-pressed", sheetIndex === sheet.id ? "true" : "false");
|
|
3101
|
+
button.addEventListener("click", () => handleSheet(sheet.id));
|
|
3102
|
+
return button;
|
|
3103
|
+
}));
|
|
3104
|
+
renderImages();
|
|
3105
|
+
};
|
|
3106
|
+
const setLoading = (value) => {
|
|
3107
|
+
loadingState = value;
|
|
3108
|
+
renderChrome();
|
|
3109
|
+
};
|
|
3110
|
+
const emitWorker = (type2, payload) => {
|
|
3111
|
+
setLoading(true);
|
|
3112
|
+
controller.emit(type2, payload);
|
|
3113
|
+
};
|
|
3114
|
+
const applyRowHeight = (row, baseHeight) => {
|
|
3115
|
+
row.__baseHeight = baseHeight;
|
|
3116
|
+
row._height = scaleRowHeight(baseHeight);
|
|
3117
|
+
};
|
|
3118
|
+
const syncScaledRowHeights = () => {
|
|
3119
|
+
virtualState.rowHeightCache.forEach((height, rowIndex) => {
|
|
3120
|
+
const row = virtualState.rows[rowIndex];
|
|
3121
|
+
if (row) {
|
|
3122
|
+
applyRowHeight(row, height);
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
};
|
|
3126
|
+
const setZoom = (scale) => {
|
|
3127
|
+
zoom = clampZoom(scale);
|
|
3128
|
+
syncScaledRowHeights();
|
|
3129
|
+
syncTableLayout();
|
|
3130
|
+
zoomEmitter.emit();
|
|
3131
|
+
renderChrome();
|
|
3132
|
+
return getZoomState();
|
|
3133
|
+
};
|
|
3134
|
+
registerFileViewerZoomProvider(root, {
|
|
3135
|
+
zoomIn: () => setZoom(zoom + 0.1),
|
|
3136
|
+
zoomOut: () => setZoom(zoom - 0.1),
|
|
3137
|
+
resetZoom: () => setZoom(1),
|
|
3138
|
+
setZoom,
|
|
3139
|
+
getState: getZoomState,
|
|
3140
|
+
subscribe: zoomEmitter.subscribe
|
|
3141
|
+
});
|
|
3142
|
+
const syncWindowStats = () => {
|
|
3143
|
+
loadedWindowCount = virtualState.loadedWindows.size;
|
|
3144
|
+
loadingWindowCount = virtualState.loadingWindows.size;
|
|
3145
|
+
renderChrome();
|
|
3146
|
+
};
|
|
3147
|
+
const syncImageViewport = () => {
|
|
3148
|
+
imageViewportState = {
|
|
3149
|
+
scrollX: (table === null || table === void 0 ? void 0 : table.ctx.scrollX) || 0,
|
|
3150
|
+
scrollY: (table === null || table === void 0 ? void 0 : table.ctx.scrollY) || 0,
|
|
3151
|
+
width: tableHost.clientWidth || 0,
|
|
3152
|
+
height: tableHost.clientHeight || 0
|
|
3153
|
+
};
|
|
3154
|
+
renderImages();
|
|
3155
|
+
};
|
|
3156
|
+
const markCopiedSelection = (params) => {
|
|
3157
|
+
var _a2, _b2, _c2, _d2;
|
|
3158
|
+
const selector = table === null || table === void 0 ? void 0 : table.ctx.selector;
|
|
3159
|
+
if (!selector) {
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
selector.xArrCopy = params.xArr.slice();
|
|
3163
|
+
selector.yArrCopy = params.yArr.slice();
|
|
3164
|
+
(_b2 = table === null || table === void 0 ? void 0 : (_a2 = table.ctx).emit) === null || _b2 === void 0 ? void 0 : _b2.call(_a2, "copyChange", {
|
|
3165
|
+
xArr: selector.xArrCopy,
|
|
3166
|
+
yArr: selector.yArrCopy,
|
|
3167
|
+
data: params.data
|
|
3168
|
+
});
|
|
3169
|
+
(_d2 = table === null || table === void 0 ? void 0 : (_c2 = table.ctx).emit) === null || _d2 === void 0 ? void 0 : _d2.call(_c2, "draw");
|
|
3170
|
+
};
|
|
3171
|
+
const copySpreadsheetSelection = (params) => {
|
|
3172
|
+
const text = serializeSpreadsheetCopyData(params.data);
|
|
3173
|
+
void writeSpreadsheetClipboard(documentRef, text).then((copied) => {
|
|
3174
|
+
if (copied) {
|
|
3175
|
+
markCopiedSelection(params);
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
console.error("Spreadsheet copy failed: clipboard fallback returned false.");
|
|
3179
|
+
}).catch((error2) => {
|
|
3180
|
+
console.error("Spreadsheet copy failed:", error2);
|
|
3181
|
+
});
|
|
3182
|
+
};
|
|
3183
|
+
const buildTableView = () => ({
|
|
3184
|
+
config: createTableConfig({
|
|
3185
|
+
hostHeight: getHostHeight(),
|
|
3186
|
+
darkMode,
|
|
3187
|
+
resizableColumns,
|
|
3188
|
+
resizableRows,
|
|
3189
|
+
copySelection: copySpreadsheetSelection,
|
|
3190
|
+
sheetDefaults,
|
|
3191
|
+
virtualState,
|
|
3192
|
+
zoomScale: zoom
|
|
3193
|
+
}),
|
|
3194
|
+
columns: getDisplayColumns(virtualState.columns, zoom)
|
|
3195
|
+
});
|
|
3196
|
+
const resetViewportTracking = () => {
|
|
3197
|
+
viewportRange = { start: 0, end: 0 };
|
|
3198
|
+
scrollDirection = 1;
|
|
3199
|
+
lastScrollY = 0;
|
|
3200
|
+
};
|
|
3201
|
+
const ensureViewportWindows = (startRow, endRow) => {
|
|
3202
|
+
if (!virtualState.active || !virtualState.totalRows) {
|
|
3203
|
+
return;
|
|
3204
|
+
}
|
|
3205
|
+
collectWindowStarts({
|
|
3206
|
+
startRow,
|
|
3207
|
+
endRow,
|
|
3208
|
+
direction: scrollDirection,
|
|
3209
|
+
totalRows: virtualState.totalRows
|
|
3210
|
+
}).forEach((windowStart) => requestWindow(windowStart, true));
|
|
3211
|
+
};
|
|
3212
|
+
const scheduleViewportLoad = () => {
|
|
3213
|
+
if (!table || disposed) {
|
|
3214
|
+
return;
|
|
3215
|
+
}
|
|
3216
|
+
if (scrollFrame) {
|
|
3217
|
+
cancelAnimationFrame(scrollFrame);
|
|
3218
|
+
}
|
|
3219
|
+
scrollFrame = requestAnimationFrame(() => {
|
|
3220
|
+
scrollFrame = 0;
|
|
3221
|
+
if (!table || !virtualState.active || !virtualState.totalRows || disposed) {
|
|
3222
|
+
return;
|
|
3223
|
+
}
|
|
3224
|
+
const head = Math.max(table.ctx.body.headIndex || 0, 0);
|
|
3225
|
+
const tail = Math.max(table.ctx.body.tailIndex || head, head);
|
|
3226
|
+
const scrollY = table.ctx.scrollY || 0;
|
|
3227
|
+
scrollDirection = scrollY >= lastScrollY ? 1 : -1;
|
|
3228
|
+
lastScrollY = scrollY;
|
|
3229
|
+
viewportRange = { start: head, end: tail };
|
|
3230
|
+
syncImageViewport();
|
|
3231
|
+
ensureViewportWindows(head, tail);
|
|
3232
|
+
});
|
|
3233
|
+
};
|
|
3234
|
+
const ensureTable = () => {
|
|
3235
|
+
if (table) {
|
|
3236
|
+
return table;
|
|
3237
|
+
}
|
|
3238
|
+
table = new EVirtTable(tableHost, {
|
|
3239
|
+
data: [],
|
|
3240
|
+
columns: [],
|
|
3241
|
+
config: createTableConfig({
|
|
3242
|
+
hostHeight: getHostHeight(),
|
|
3243
|
+
darkMode,
|
|
3244
|
+
resizableColumns,
|
|
3245
|
+
resizableRows,
|
|
3246
|
+
copySelection: copySpreadsheetSelection,
|
|
3247
|
+
sheetDefaults,
|
|
3248
|
+
virtualState,
|
|
3249
|
+
zoomScale: zoom
|
|
3250
|
+
})
|
|
3251
|
+
});
|
|
3252
|
+
table.on("onScrollX", scheduleViewportLoad);
|
|
3253
|
+
table.on("onScrollY", scheduleViewportLoad);
|
|
3254
|
+
table.on("resize", scheduleViewportLoad);
|
|
3255
|
+
table.on("resizeColumnChange", handleColumnResizeChange);
|
|
3256
|
+
table.on("resizeRowChange", handleRowResizeChange);
|
|
3257
|
+
return table;
|
|
3258
|
+
};
|
|
3259
|
+
const renderTable = (instance, columns = virtualState.columns, rows = virtualState.rows, resetScroll = false) => {
|
|
3260
|
+
const view = {
|
|
3261
|
+
config: createTableConfig({
|
|
3262
|
+
hostHeight: getHostHeight(),
|
|
3263
|
+
darkMode,
|
|
3264
|
+
resizableColumns,
|
|
3265
|
+
resizableRows,
|
|
3266
|
+
copySelection: copySpreadsheetSelection,
|
|
3267
|
+
sheetDefaults,
|
|
3268
|
+
virtualState,
|
|
3269
|
+
zoomScale: zoom
|
|
3270
|
+
}),
|
|
3271
|
+
columns: getDisplayColumns(columns, zoom)
|
|
3272
|
+
};
|
|
3273
|
+
instance.loadConfig(view.config);
|
|
3274
|
+
instance.loadColumns(view.columns);
|
|
3275
|
+
instance.loadData(rows);
|
|
3276
|
+
instance.draw();
|
|
3277
|
+
syncImageViewport();
|
|
3278
|
+
if (resetScroll) {
|
|
3279
|
+
requestAnimationFrame(() => {
|
|
3280
|
+
instance.scrollTo(0, 0);
|
|
3281
|
+
instance.draw();
|
|
3282
|
+
syncImageViewport();
|
|
3283
|
+
scheduleViewportLoad();
|
|
3284
|
+
});
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3287
|
+
scheduleViewportLoad();
|
|
3288
|
+
};
|
|
3289
|
+
function syncTableLayout() {
|
|
3290
|
+
const instance = ensureTable();
|
|
3291
|
+
const { config, columns } = buildTableView();
|
|
3292
|
+
instance.loadConfig(config);
|
|
3293
|
+
if (virtualState.active && columns.length) {
|
|
3294
|
+
instance.loadColumns(columns);
|
|
3295
|
+
}
|
|
3296
|
+
instance.doLayout();
|
|
3297
|
+
instance.draw();
|
|
3298
|
+
syncImageViewport();
|
|
3299
|
+
scheduleViewportLoad();
|
|
3300
|
+
}
|
|
3301
|
+
const clearScheduledLayoutRefresh = () => {
|
|
3302
|
+
layoutRefreshToken += 1;
|
|
3303
|
+
const view = getTargetWindow(target);
|
|
3304
|
+
while (layoutRefreshTimers.length) {
|
|
3305
|
+
const timer = layoutRefreshTimers.pop();
|
|
3306
|
+
if (timer !== void 0) {
|
|
3307
|
+
view === null || view === void 0 ? void 0 : view.clearTimeout(timer);
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
};
|
|
3311
|
+
const refreshTableLayoutWhenVisible = () => {
|
|
3312
|
+
if (disposed || !table || !virtualState.active) {
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
const rect = tableHost.getBoundingClientRect();
|
|
3316
|
+
if (rect.width <= 0 || rect.height <= 0) {
|
|
3317
|
+
return;
|
|
3318
|
+
}
|
|
3319
|
+
syncTableLayout();
|
|
3320
|
+
};
|
|
3321
|
+
const scheduleStableFirstPaintRefresh = () => {
|
|
3322
|
+
var _a2;
|
|
3323
|
+
clearScheduledLayoutRefresh();
|
|
3324
|
+
const token = layoutRefreshToken;
|
|
3325
|
+
const view = getTargetWindow(target);
|
|
3326
|
+
if (!view) {
|
|
3327
|
+
return;
|
|
3328
|
+
}
|
|
3329
|
+
const delays = [0, 32, 120, 300, 700];
|
|
3330
|
+
delays.forEach((delay) => {
|
|
3331
|
+
const timer = view.setTimeout(() => {
|
|
3332
|
+
const index = layoutRefreshTimers.indexOf(timer);
|
|
3333
|
+
if (index >= 0) {
|
|
3334
|
+
layoutRefreshTimers.splice(index, 1);
|
|
3335
|
+
}
|
|
3336
|
+
view.requestAnimationFrame(() => {
|
|
3337
|
+
if (token !== layoutRefreshToken) {
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
refreshTableLayoutWhenVisible();
|
|
3341
|
+
});
|
|
3342
|
+
}, delay);
|
|
3343
|
+
layoutRefreshTimers.push(timer);
|
|
3344
|
+
});
|
|
3345
|
+
void ((_a2 = documentRef.fonts) === null || _a2 === void 0 ? void 0 : _a2.ready.then(() => {
|
|
3346
|
+
if (token !== layoutRefreshToken) {
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3349
|
+
refreshTableLayoutWhenVisible();
|
|
3350
|
+
}).catch(() => {
|
|
3351
|
+
}));
|
|
3352
|
+
};
|
|
3353
|
+
function setColumnWidthByKey(columns, key, width) {
|
|
3354
|
+
for (const column of columns) {
|
|
3355
|
+
if (`${column.key}` === key) {
|
|
3356
|
+
column.width = width;
|
|
3357
|
+
return true;
|
|
3358
|
+
}
|
|
3359
|
+
if (Array.isArray(column.children) && setColumnWidthByKey(column.children, key, width)) {
|
|
3360
|
+
return true;
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
return false;
|
|
3364
|
+
}
|
|
3365
|
+
function clearTableResizableHeaderCache() {
|
|
3366
|
+
var _a2;
|
|
3367
|
+
try {
|
|
3368
|
+
(_a2 = table === null || table === void 0 ? void 0 : table.setCustomHeader) === null || _a2 === void 0 ? void 0 : _a2.call(table, { resizableData: {} }, true);
|
|
3369
|
+
} catch {
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
function handleColumnResizeChange(event) {
|
|
3373
|
+
if (!resizableColumns || disposed) {
|
|
3374
|
+
return;
|
|
3375
|
+
}
|
|
3376
|
+
const key = (event === null || event === void 0 ? void 0 : event.key) === void 0 ? "" : `${event.key}`;
|
|
3377
|
+
const displayWidth = Number(event === null || event === void 0 ? void 0 : event.width);
|
|
3378
|
+
if (!key || key === INDEX_COLUMN_KEY || !Number.isFinite(displayWidth) || displayWidth <= 0) {
|
|
3379
|
+
return;
|
|
3380
|
+
}
|
|
3381
|
+
const baseWidth = Math.max(1, Math.round(displayWidth / Math.max(zoom, 0.01)));
|
|
3382
|
+
const changed = setColumnWidthByKey(virtualState.columns, key, Math.max(baseWidth, Math.round(RESIZABLE_COLUMN_MIN_WIDTH / Math.max(zoom, 1))));
|
|
3383
|
+
if (!changed) {
|
|
3384
|
+
return;
|
|
3385
|
+
}
|
|
3386
|
+
const activeSheetId = getActiveSheetId();
|
|
3387
|
+
if (activeSheetId !== void 0) {
|
|
3388
|
+
sheetStateCache.set(activeSheetId, virtualState);
|
|
3389
|
+
}
|
|
3390
|
+
clearTableResizableHeaderCache();
|
|
3391
|
+
syncTableLayout();
|
|
3392
|
+
}
|
|
3393
|
+
function handleRowResizeChange(event) {
|
|
3394
|
+
if (!resizableRows || disposed) {
|
|
3395
|
+
return;
|
|
3396
|
+
}
|
|
3397
|
+
const rowIndex = Number(event === null || event === void 0 ? void 0 : event.rowIndex);
|
|
3398
|
+
const displayHeight = Number(event === null || event === void 0 ? void 0 : event.height);
|
|
3399
|
+
if (!Number.isInteger(rowIndex) || rowIndex < 0 || !Number.isFinite(displayHeight) || displayHeight <= 0) {
|
|
3400
|
+
return;
|
|
3401
|
+
}
|
|
3402
|
+
const row = virtualState.rows[rowIndex];
|
|
3403
|
+
if (!row) {
|
|
3404
|
+
return;
|
|
3405
|
+
}
|
|
3406
|
+
const baseHeight = normalizeRowHeight(Math.max(RESIZABLE_ROW_MIN_HEIGHT, Math.round(displayHeight / Math.max(zoom, 0.01))), virtualState.defaults.rowHeight);
|
|
3407
|
+
applyRowHeight(row, baseHeight);
|
|
3408
|
+
virtualState.rowHeightCache.set(rowIndex, baseHeight);
|
|
3409
|
+
const activeSheetId = getActiveSheetId();
|
|
3410
|
+
if (activeSheetId !== void 0) {
|
|
3411
|
+
sheetStateCache.set(activeSheetId, virtualState);
|
|
3412
|
+
}
|
|
3413
|
+
syncTableLayout();
|
|
3414
|
+
}
|
|
3415
|
+
function requestWindow(startRow = 0, silent = true) {
|
|
3416
|
+
const sheetId = getActiveSheetId();
|
|
3417
|
+
if (sheetId === void 0) {
|
|
3418
|
+
return;
|
|
3419
|
+
}
|
|
3420
|
+
const windowStart = clampWindowStart(startRow, virtualState.totalRows);
|
|
3421
|
+
if (virtualState.loadedWindows.has(windowStart) || virtualState.loadingWindows.has(windowStart)) {
|
|
3422
|
+
return;
|
|
3423
|
+
}
|
|
3424
|
+
virtualState.loadingWindows.add(windowStart);
|
|
3425
|
+
syncWindowStats();
|
|
3426
|
+
if (virtualState.active) {
|
|
3427
|
+
markWindowState(virtualState.rows, virtualState.totalRows, windowStart, RowState.Loading);
|
|
3428
|
+
table === null || table === void 0 ? void 0 : table.draw();
|
|
3429
|
+
}
|
|
3430
|
+
errorMessage = "";
|
|
3431
|
+
emitWorker("parseSheet", {
|
|
3432
|
+
sheet: sheetId,
|
|
3433
|
+
startRow: windowStart,
|
|
3434
|
+
pageSize: WINDOW_SIZE,
|
|
3435
|
+
sessionId: sheetSessionId
|
|
3436
|
+
});
|
|
3437
|
+
if (silent) {
|
|
3438
|
+
loadingState = false;
|
|
3439
|
+
renderChrome();
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
const initializeVirtualSheet = (ws) => {
|
|
3443
|
+
const meta = ws.meta;
|
|
3444
|
+
if (!meta) {
|
|
3445
|
+
return;
|
|
3446
|
+
}
|
|
3447
|
+
const { columns, dataKeys } = buildColumns(ws);
|
|
3448
|
+
virtualState = {
|
|
3449
|
+
...createEmptyVirtualState(),
|
|
3450
|
+
active: true,
|
|
3451
|
+
totalRows: meta.totalRows,
|
|
3452
|
+
totalCols: meta.totalCols,
|
|
3453
|
+
indexOffset: detectIndexOffset(ws),
|
|
3454
|
+
defaults: ws.defaults,
|
|
3455
|
+
dataKeys,
|
|
3456
|
+
rows: buildRows(meta.totalRows),
|
|
3457
|
+
columns
|
|
3458
|
+
};
|
|
3459
|
+
sheetDefaults = ws.defaults;
|
|
3460
|
+
totalRows = meta.totalRows;
|
|
3461
|
+
totalCols = meta.totalCols;
|
|
3462
|
+
syncWindowStats();
|
|
3463
|
+
};
|
|
3464
|
+
const clearVirtualRow = (row) => {
|
|
3465
|
+
virtualState.dataKeys.forEach((key) => {
|
|
3466
|
+
delete row[key];
|
|
3467
|
+
});
|
|
3468
|
+
};
|
|
3469
|
+
const applyStructureRowHeights = (rowHeights) => {
|
|
3470
|
+
if (!Array.isArray(rowHeights)) {
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
rowHeights.forEach((rawHeight, absoluteRow) => {
|
|
3474
|
+
if (rawHeight === void 0) {
|
|
3475
|
+
return;
|
|
3476
|
+
}
|
|
3477
|
+
const row = virtualState.rows[absoluteRow];
|
|
3478
|
+
if (!row) {
|
|
3479
|
+
return;
|
|
3480
|
+
}
|
|
3481
|
+
const height = normalizeRowHeight(rawHeight, virtualState.defaults.rowHeight);
|
|
3482
|
+
applyRowHeight(row, height);
|
|
3483
|
+
virtualState.rowHeightCache.set(absoluteRow, height);
|
|
3484
|
+
});
|
|
3485
|
+
};
|
|
3486
|
+
const applyWindowRows = (ws) => {
|
|
3487
|
+
var _a2, _b2;
|
|
3488
|
+
const meta = ws.meta;
|
|
3489
|
+
if (!meta) {
|
|
3490
|
+
return;
|
|
3491
|
+
}
|
|
3492
|
+
const rowIndexes = [];
|
|
3493
|
+
const endRow = Math.min(meta.endRow, virtualState.totalRows);
|
|
3494
|
+
for (let absoluteRow = meta.startRow; absoluteRow < endRow; absoluteRow += 1) {
|
|
3495
|
+
const row = virtualState.rows[absoluteRow];
|
|
3496
|
+
const relativeRow = absoluteRow - meta.startRow;
|
|
3497
|
+
if (!row) {
|
|
3498
|
+
continue;
|
|
3499
|
+
}
|
|
3500
|
+
clearVirtualRow(row);
|
|
3501
|
+
const data = ((_a2 = ws.data) === null || _a2 === void 0 ? void 0 : _a2[relativeRow]) || [];
|
|
3502
|
+
data.forEach((value, colIndex) => {
|
|
3503
|
+
if (value === "" || value === null || value === void 0) {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
row[getDataKey(colIndex)] = value;
|
|
3507
|
+
});
|
|
3508
|
+
const windowHeight = getRowHeight(ws.rowHeights, relativeRow, virtualState.defaults.rowHeight);
|
|
3509
|
+
const height = normalizeRowHeight(getRowHeight((_b2 = ws.structure) === null || _b2 === void 0 ? void 0 : _b2.rowHeights, absoluteRow, windowHeight), virtualState.defaults.rowHeight);
|
|
3510
|
+
applyRowHeight(row, height);
|
|
3511
|
+
row[ROW_STATE_FIELD] = RowState.Loaded;
|
|
3512
|
+
virtualState.rowHeightCache.set(absoluteRow, height);
|
|
3513
|
+
rowIndexes.push(absoluteRow);
|
|
3514
|
+
}
|
|
3515
|
+
virtualState.windowRows.set(meta.startRow, rowIndexes);
|
|
3516
|
+
};
|
|
3517
|
+
const applyWindowCells = (ws) => {
|
|
3518
|
+
const meta = ws.meta;
|
|
3519
|
+
if (!meta) {
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
const keys = [];
|
|
3523
|
+
Object.entries(ws.cell || {}).forEach(([key, value]) => {
|
|
3524
|
+
const [row, col] = key.split("-").map(Number);
|
|
3525
|
+
const absoluteKey = displayCellKey(meta.startRow + row, col + 1);
|
|
3526
|
+
const style = normalizeCellStyle(value);
|
|
3527
|
+
if (!style) {
|
|
3528
|
+
return;
|
|
3529
|
+
}
|
|
3530
|
+
virtualState.cellCache.set(absoluteKey, style);
|
|
3531
|
+
keys.push(absoluteKey);
|
|
3532
|
+
});
|
|
3533
|
+
virtualState.windowCells.set(meta.startRow, keys);
|
|
3534
|
+
};
|
|
3535
|
+
const setSheetMerges = (merges) => {
|
|
3536
|
+
virtualState.mergeStartMap.clear();
|
|
3537
|
+
virtualState.mergeCoveredMap.clear();
|
|
3538
|
+
merges.forEach((merge) => {
|
|
3539
|
+
const startKey = displayCellKey(merge.row, merge.col + 1);
|
|
3540
|
+
virtualState.mergeStartMap.set(startKey, {
|
|
3541
|
+
...merge,
|
|
3542
|
+
col: merge.col + 1
|
|
3543
|
+
});
|
|
3544
|
+
for (let rowOffset = 0; rowOffset < merge.rowspan; rowOffset += 1) {
|
|
3545
|
+
for (let colOffset = 0; colOffset < merge.colspan; colOffset += 1) {
|
|
3546
|
+
if (rowOffset === 0 && colOffset === 0) {
|
|
3547
|
+
continue;
|
|
3548
|
+
}
|
|
3549
|
+
const coveredKey = displayCellKey(merge.row + rowOffset, merge.col + colOffset + 1);
|
|
3550
|
+
virtualState.mergeCoveredMap.set(coveredKey, true);
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
};
|
|
3555
|
+
const applySheetStructure = (ws) => {
|
|
3556
|
+
const structure = ws.structure;
|
|
3557
|
+
const mergeList = structure === null || structure === void 0 ? void 0 : structure.merge;
|
|
3558
|
+
if (mergeList) {
|
|
3559
|
+
setSheetMerges(mergeList);
|
|
3560
|
+
} else {
|
|
3561
|
+
const meta = ws.meta;
|
|
3562
|
+
if (meta && !virtualState.mergeStartMap.size) {
|
|
3563
|
+
setSheetMerges((ws.merge || []).map((merge) => ({
|
|
3564
|
+
...merge,
|
|
3565
|
+
row: merge.row + meta.startRow
|
|
3566
|
+
})));
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
applyStructureRowHeights(structure === null || structure === void 0 ? void 0 : structure.rowHeights);
|
|
3570
|
+
if (structure === null || structure === void 0 ? void 0 : structure.images) {
|
|
3571
|
+
sheetImages = structure.images;
|
|
3572
|
+
const sheetId = getActiveSheetId();
|
|
3573
|
+
if (sheetId !== void 0) {
|
|
3574
|
+
sheetImageCache.set(sheetId, structure.images);
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
if (structure === null || structure === void 0 ? void 0 : structure.charts) {
|
|
3578
|
+
sheetCharts = structure.charts;
|
|
3579
|
+
const sheetId = getActiveSheetId();
|
|
3580
|
+
if (sheetId !== void 0) {
|
|
3581
|
+
sheetChartCache.set(sheetId, structure.charts);
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
};
|
|
3585
|
+
const applyVirtualWindow = (ws) => {
|
|
3586
|
+
var _a2;
|
|
3587
|
+
const meta = ws.meta;
|
|
3588
|
+
if (!meta) {
|
|
3589
|
+
return;
|
|
3590
|
+
}
|
|
3591
|
+
const isFirstWindow = !hasInitialWindow;
|
|
3592
|
+
if (!virtualState.active) {
|
|
3593
|
+
initializeVirtualSheet(ws);
|
|
3594
|
+
}
|
|
3595
|
+
applySheetStructure(ws);
|
|
3596
|
+
applyWindowRows(ws);
|
|
3597
|
+
applyWindowCells(ws);
|
|
3598
|
+
virtualState.loadedWindows.add(meta.startRow);
|
|
3599
|
+
virtualState.loadingWindows.delete(meta.startRow);
|
|
3600
|
+
syncWindowStats();
|
|
3601
|
+
hasInitialWindow = true;
|
|
3602
|
+
const activeSheetId = getActiveSheetId();
|
|
3603
|
+
if (activeSheetId !== void 0) {
|
|
3604
|
+
sheetStateCache.set(activeSheetId, virtualState);
|
|
3605
|
+
}
|
|
3606
|
+
if (isFirstWindow) {
|
|
3607
|
+
renderTable(ensureTable(), virtualState.columns, virtualState.rows, true);
|
|
3608
|
+
} else {
|
|
3609
|
+
table === null || table === void 0 ? void 0 : table.draw();
|
|
3610
|
+
}
|
|
3611
|
+
loadingState = false;
|
|
3612
|
+
sheetInitializing = false;
|
|
3613
|
+
renderChrome();
|
|
3614
|
+
if (!hasNotifiedFirstPaint) {
|
|
3615
|
+
hasNotifiedFirstPaint = true;
|
|
3616
|
+
(_a2 = context === null || context === void 0 ? void 0 : context.onProgressiveRender) === null || _a2 === void 0 ? void 0 : _a2.call(context);
|
|
3617
|
+
}
|
|
3618
|
+
if (isFirstWindow) {
|
|
3619
|
+
scheduleStableFirstPaintRefresh();
|
|
3620
|
+
}
|
|
3621
|
+
const start = viewportRange.start || meta.startRow;
|
|
3622
|
+
const end = Math.max(viewportRange.end, meta.endRow - 1, meta.startRow);
|
|
3623
|
+
ensureViewportWindows(start, end);
|
|
3624
|
+
};
|
|
3625
|
+
const resetViewState = () => {
|
|
3626
|
+
errorMessage = "";
|
|
3627
|
+
totalRows = 0;
|
|
3628
|
+
totalCols = 0;
|
|
3629
|
+
sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
|
|
3630
|
+
sheetImages = [];
|
|
3631
|
+
sheetCharts = [];
|
|
3632
|
+
virtualState = createEmptyVirtualState();
|
|
3633
|
+
hasInitialWindow = false;
|
|
3634
|
+
resetViewportTracking();
|
|
3635
|
+
syncWindowStats();
|
|
3636
|
+
syncImageViewport();
|
|
3637
|
+
if (!table) {
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
table.loadColumns([]);
|
|
3641
|
+
table.loadData([]);
|
|
3642
|
+
table.scrollTo(0, 0);
|
|
3643
|
+
table.draw();
|
|
3644
|
+
};
|
|
3645
|
+
const cacheCurrentSheetState = () => {
|
|
3646
|
+
const sheetId = getActiveSheetId();
|
|
3647
|
+
if (sheetId === void 0 || !virtualState.active) {
|
|
3648
|
+
return;
|
|
3649
|
+
}
|
|
3650
|
+
sheetStateCache.set(sheetId, virtualState);
|
|
3651
|
+
};
|
|
3652
|
+
const restoreCachedSheetState = (sheetId) => {
|
|
3653
|
+
const cached = sheetStateCache.get(sheetId);
|
|
3654
|
+
if (!cached) {
|
|
3655
|
+
return false;
|
|
3656
|
+
}
|
|
3657
|
+
cached.loadingWindows.clear();
|
|
3658
|
+
virtualState = cached;
|
|
3659
|
+
errorMessage = "";
|
|
3660
|
+
totalRows = cached.totalRows;
|
|
3661
|
+
totalCols = cached.totalCols;
|
|
3662
|
+
sheetDefaults = cached.defaults;
|
|
3663
|
+
sheetImages = sheetImageCache.get(sheetId) || [];
|
|
3664
|
+
sheetCharts = sheetChartCache.get(sheetId) || [];
|
|
3665
|
+
hasInitialWindow = cached.loadedWindows.size > 0;
|
|
3666
|
+
sheetInitializing = !hasInitialWindow;
|
|
3667
|
+
syncWindowStats();
|
|
3668
|
+
queueMicrotask(() => {
|
|
3669
|
+
if (disposed) {
|
|
3670
|
+
return;
|
|
3671
|
+
}
|
|
3672
|
+
renderTable(ensureTable(), cached.columns, cached.rows);
|
|
3673
|
+
syncImageViewport();
|
|
3674
|
+
scheduleStableFirstPaintRefresh();
|
|
3675
|
+
});
|
|
3676
|
+
return true;
|
|
3677
|
+
};
|
|
3678
|
+
const startSheetSession = () => {
|
|
3679
|
+
const sheetId = getActiveSheetId();
|
|
3680
|
+
if (sheetId === void 0) {
|
|
3681
|
+
loadingState = false;
|
|
3682
|
+
sheetInitializing = false;
|
|
3683
|
+
renderChrome();
|
|
3684
|
+
return;
|
|
3685
|
+
}
|
|
3686
|
+
sheetSessionId += 1;
|
|
3687
|
+
if (restoreCachedSheetState(sheetId)) {
|
|
3688
|
+
loadingState = false;
|
|
3689
|
+
renderChrome();
|
|
3690
|
+
return;
|
|
3691
|
+
}
|
|
3692
|
+
sheetInitializing = true;
|
|
3693
|
+
resetViewState();
|
|
3694
|
+
requestWindow(0, false);
|
|
3695
|
+
};
|
|
3696
|
+
function handleSheet(index) {
|
|
3697
|
+
if (sheetIndex === index) {
|
|
3698
|
+
scrollActiveSheetIntoView();
|
|
3699
|
+
return;
|
|
3700
|
+
}
|
|
3701
|
+
cacheCurrentSheetState();
|
|
3702
|
+
sheetIndex = index;
|
|
3703
|
+
renderChrome();
|
|
3704
|
+
startSheetSession();
|
|
3705
|
+
scrollActiveSheetIntoView();
|
|
3706
|
+
}
|
|
3707
|
+
const emitParseWorkbook = () => {
|
|
3708
|
+
var _a2, _b2;
|
|
3709
|
+
emitWorker("parseWorkbook", {
|
|
3710
|
+
workbook: buffer,
|
|
3711
|
+
fileType: type,
|
|
3712
|
+
filename: context === null || context === void 0 ? void 0 : context.filename,
|
|
3713
|
+
textEncoding: (_b2 = (_a2 = context === null || context === void 0 ? void 0 : context.options) === null || _a2 === void 0 ? void 0 : _a2.spreadsheet) === null || _b2 === void 0 ? void 0 : _b2.textEncoding
|
|
3714
|
+
});
|
|
3715
|
+
};
|
|
3716
|
+
controller.onWorkerEvent("sheets", ({ sheets: list }) => {
|
|
3717
|
+
sheets = list;
|
|
3718
|
+
const firstSheet = list.find((sheet) => !sheet.hidden) || list[0];
|
|
3719
|
+
if (firstSheet) {
|
|
3720
|
+
sheetIndex = firstSheet.id;
|
|
3721
|
+
renderChrome();
|
|
3722
|
+
startSheetSession();
|
|
3723
|
+
scrollActiveSheetIntoView();
|
|
3724
|
+
return;
|
|
3725
|
+
}
|
|
3726
|
+
sheetInitializing = false;
|
|
3727
|
+
loadingState = false;
|
|
3728
|
+
renderChrome();
|
|
3729
|
+
});
|
|
3730
|
+
controller.onWorkerEvent("parseSheet", ({ sessionId, sheet, sheetData: ws }) => {
|
|
3731
|
+
if (sessionId !== sheetSessionId || sheet !== getActiveSheetId()) {
|
|
3732
|
+
return;
|
|
3733
|
+
}
|
|
3734
|
+
applyVirtualWindow(ws);
|
|
3735
|
+
});
|
|
3736
|
+
controller.onWorkerEvent("parseError", ({ sessionId, startRow, message }) => {
|
|
3737
|
+
if (sessionId && sessionId !== sheetSessionId) {
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
sheetInitializing = false;
|
|
3741
|
+
loadingState = false;
|
|
3742
|
+
if (typeof startRow === "number") {
|
|
3743
|
+
virtualState.loadingWindows.delete(startRow);
|
|
3744
|
+
syncWindowStats();
|
|
3745
|
+
if (virtualState.active) {
|
|
3746
|
+
markWindowState(virtualState.rows, virtualState.totalRows, startRow, RowState.Placeholder);
|
|
3747
|
+
table === null || table === void 0 ? void 0 : table.draw();
|
|
3748
|
+
}
|
|
3749
|
+
} else {
|
|
3750
|
+
virtualState.loadingWindows.clear();
|
|
3751
|
+
syncWindowStats();
|
|
3752
|
+
}
|
|
3753
|
+
errorMessage = message || t("spreadsheet.error.parseFailed");
|
|
3754
|
+
renderChrome();
|
|
3755
|
+
});
|
|
3756
|
+
controller.onWorkerError((event) => {
|
|
3757
|
+
sheetInitializing = false;
|
|
3758
|
+
loadingState = false;
|
|
3759
|
+
errorMessage = event.message || t("spreadsheet.error.workerFailed");
|
|
3760
|
+
renderChrome();
|
|
3761
|
+
});
|
|
3762
|
+
(_j = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _j === void 0 ? void 0 : _j.call(context, {
|
|
3763
|
+
print: false,
|
|
3764
|
+
exportHtml: false
|
|
3765
|
+
});
|
|
3766
|
+
(_k = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _k === void 0 ? void 0 : _k.call(context, {
|
|
3767
|
+
beforeCapture: async ({ signal }) => {
|
|
3768
|
+
while (!hasInitialWindow && !errorMessage && !disposed) {
|
|
3769
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
3770
|
+
throw signal.reason;
|
|
3771
|
+
}
|
|
3772
|
+
await new Promise((resolve) => {
|
|
3773
|
+
const view = getTargetWindow(target);
|
|
3774
|
+
if (view)
|
|
3775
|
+
view.setTimeout(resolve, 16);
|
|
3776
|
+
else
|
|
3777
|
+
setTimeout(resolve, 16);
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3780
|
+
if (errorMessage) {
|
|
3781
|
+
throw new Error(errorMessage);
|
|
3782
|
+
}
|
|
3783
|
+
},
|
|
3784
|
+
getTarget: () => tableWrapper
|
|
3785
|
+
});
|
|
3786
|
+
ensureTable();
|
|
3787
|
+
const ResizeObserverCtor = ((_l = getTargetWindow(target)) === null || _l === void 0 ? void 0 : _l.ResizeObserver) || (typeof ResizeObserver !== "undefined" ? ResizeObserver : void 0);
|
|
3788
|
+
if (ResizeObserverCtor) {
|
|
3789
|
+
resizeObserver = new ResizeObserverCtor(() => {
|
|
3790
|
+
if (resizeFrame) {
|
|
3791
|
+
cancelAnimationFrame(resizeFrame);
|
|
3792
|
+
}
|
|
3793
|
+
resizeFrame = requestAnimationFrame(() => {
|
|
3794
|
+
resizeFrame = 0;
|
|
3795
|
+
syncTableLayout();
|
|
3796
|
+
});
|
|
3797
|
+
});
|
|
3798
|
+
resizeObserver.observe(tableHost);
|
|
3799
|
+
}
|
|
3800
|
+
renderChrome();
|
|
3801
|
+
emitParseWorkbook();
|
|
3802
|
+
return {
|
|
3803
|
+
$el: root,
|
|
3804
|
+
unmount() {
|
|
3805
|
+
var _a2, _b2;
|
|
3806
|
+
disposed = true;
|
|
3807
|
+
if (resizeFrame) {
|
|
3808
|
+
cancelAnimationFrame(resizeFrame);
|
|
3809
|
+
}
|
|
3810
|
+
if (scrollFrame) {
|
|
3811
|
+
cancelAnimationFrame(scrollFrame);
|
|
3812
|
+
}
|
|
3813
|
+
clearScheduledLayoutRefresh();
|
|
3814
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
3815
|
+
resizeObserver = null;
|
|
3816
|
+
unregisterFileViewerZoomProvider(root);
|
|
3817
|
+
controller.destroy();
|
|
3818
|
+
table === null || table === void 0 ? void 0 : table.destroy();
|
|
3819
|
+
table = null;
|
|
3820
|
+
(_a2 = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a2 === void 0 ? void 0 : _a2.call(context, null);
|
|
3821
|
+
(_b2 = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b2 === void 0 ? void 0 : _b2.call(context, null);
|
|
3822
|
+
}
|
|
3823
|
+
};
|
|
3824
|
+
};
|
|
3825
|
+
const spreadsheet = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3826
|
+
__proto__: null,
|
|
3827
|
+
default: renderFileViewerSpreadsheet,
|
|
3828
|
+
resolveEVirtTableConstructor,
|
|
3829
|
+
resolveEVirtTableStyleText,
|
|
3830
|
+
scopeEVirtTableStyleText
|
|
3831
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3832
|
+
export {
|
|
3833
|
+
spreadsheet as s,
|
|
3834
|
+
tinycolor as t
|
|
3835
|
+
};
|