@sinm/kai 1.15.8 → 1.15.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/RELEASE_NOTES.md +75 -0
- package/dist-cli/kai-cli.js +89519 -85867
- package/dist-electron/main/image-worker.js +3 -1
- package/dist-electron/main/plugin-host.js +179 -22
- package/dist-electron/renderer/assets/{ContextDraftStrip-BdkjcFzK.js → ContextDraftStrip-CM-2aRnV.js} +34 -5
- package/dist-electron/renderer/assets/{desktop-overlay-reason-Brz0kEaz.js → desktop-overlay-reason-Lk3ArWYm.js} +108 -59
- package/dist-electron/renderer/assets/{index-DZMGo-eK.js → index-2o21y_A2.js} +10372 -6588
- package/dist-electron/renderer/assets/{index-BmJPPSwb.css → index-CNIvLq5A.css} +3942 -1721
- package/dist-electron/renderer/assets/{index-Dw1GJ0F4.js → index-D-VQacpk.js} +2 -2
- package/dist-electron/renderer/assets/{index-CxNNir1f.js → index-D13SQmIx.js} +63 -11
- package/dist-electron/renderer/assets/{localUrlCodec-BE9hUkWM.js → localUrlCodec-DIa41KGx.js} +29 -15
- package/dist-electron/renderer/assets/{index.es-B-PFCvGY.js → office-preview-BS5mB52v.js} +526 -1
- package/dist-electron/renderer/assets/{overlay-jC_zo_GK.js → overlay-CBbZ1t7x.js} +53 -7
- package/dist-electron/renderer/assets/{parser-Bgw_IcYs.js → parser-BfKF1DWc.js} +1 -1
- package/dist-electron/renderer/assets/{spreadsheet-DCnzJbCU.js → spreadsheet-1QmRJRGI.js} +3 -3
- package/dist-electron/renderer/index.html +4 -4
- package/dist-electron/renderer/office-preview.html +2 -2
- package/dist-electron/renderer/overlay.html +3 -3
- package/package.json +1 -1
- package/dist-electron/renderer/assets/office-preview-D7ZVJjw5.js +0 -240
|
@@ -1,3 +1,216 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-DQKbw6RS.js","./preload-helper-DVzrZ_Op.js","./index-B5MYHOIO.js","./index-DJvBCnCx.js","./index-BOyfEjY-.js","./index-D-VQacpk.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import { _ as __vitePreload } from "./preload-helper-DVzrZ_Op.js";
|
|
3
|
+
import { O as OFFICE_PREVIEW_FORMATS, e as encodePathPreservingSlashes } from "./localUrlCodec-DIa41KGx.js";
|
|
4
|
+
const SHEET_PICK_CONTRACT = {
|
|
5
|
+
/** 当前 sheet 名。读不到=**不写**这一位(不是空串):缺席即「这条路走不通」。 */
|
|
6
|
+
sheetName: "kaiSheetName",
|
|
7
|
+
/** 选区零基闭区间(文件坐标):`minCol,minRow,maxCol,maxRow`。 */
|
|
8
|
+
range: "kaiSheetRange",
|
|
9
|
+
/** 选区矩形:`x,y,width,height`,CSS px 视口坐标。 */
|
|
10
|
+
rect: "kaiSheetRect",
|
|
11
|
+
/** sheet 可视区矩形(抓取范围):`x,y,width,height`,CSS px 视口坐标。 */
|
|
12
|
+
viewport: "kaiSheetViewport",
|
|
13
|
+
/**
|
|
14
|
+
* 选区内的**显示值**,二维文本:行内 `\t`、行间 `\n`。
|
|
15
|
+
*
|
|
16
|
+
* 读不到(图片格、自定义渲染、引擎没给格式化值)就**不写**这一位——拿公式或空串冒充内容
|
|
17
|
+
* 是把「我看不清」说成「里面是空的」。
|
|
18
|
+
*/
|
|
19
|
+
text: "kaiSheetText",
|
|
20
|
+
/**
|
|
21
|
+
* 选区文字**截断前**的总字数:与 `text` 一起写、一起缺。
|
|
22
|
+
*
|
|
23
|
+
* 为什么单独一位而不在文本里做标记:采集面凭它算出「已截断到 N 字(原文 M 字)」,
|
|
24
|
+
* 让标记长在正文里就成了内容的一部分,模型会把它当成表格里的字。
|
|
25
|
+
*/
|
|
26
|
+
textChars: "kaiSheetTextChars"
|
|
27
|
+
};
|
|
28
|
+
const SHEET_PICK_CHANGE_EVENT = "kai-sheet-pick-change";
|
|
29
|
+
const pptxWorkerUrl = "" + new URL("pptx.worker-B9OfaFQ0.js", import.meta.url).href;
|
|
30
|
+
const isSpreadsheetFormat = (format) => format === "xlsx" || format === "xls" || format === "csv" || format === "tsv";
|
|
31
|
+
const createContext = (file, signal) => ({
|
|
32
|
+
filename: file.name,
|
|
33
|
+
signal,
|
|
34
|
+
options: {
|
|
35
|
+
theme: "light",
|
|
36
|
+
locale: navigator.language.toLowerCase().startsWith("zh") ? "zh-CN" : "en-US",
|
|
37
|
+
...isSpreadsheetFormat(file.format) ? { initialViewState: { scale: 1 } } : {},
|
|
38
|
+
docx: {
|
|
39
|
+
worker: false,
|
|
40
|
+
progressive: true,
|
|
41
|
+
// 连续流式阅读:页式布局把每节固定成页高并 overflow:hidden,自动分页切不动的块会被静默裁掉
|
|
42
|
+
// (实测单表格 300 段只剩首屏);整篇切分还随篇幅超线性增长(实测 2000 段 4.2s vs 35ms)。
|
|
43
|
+
visualPagination: false
|
|
44
|
+
},
|
|
45
|
+
spreadsheet: {
|
|
46
|
+
worker: false,
|
|
47
|
+
resizableColumns: true,
|
|
48
|
+
resizableRows: true
|
|
49
|
+
},
|
|
50
|
+
presentation: {
|
|
51
|
+
pptWorker: false,
|
|
52
|
+
pptCache: false,
|
|
53
|
+
workerUrl: pptxWorkerUrl
|
|
54
|
+
},
|
|
55
|
+
pdf: {
|
|
56
|
+
toolbar: true,
|
|
57
|
+
navigation: true,
|
|
58
|
+
thumbnails: true,
|
|
59
|
+
cjkFontFallback: false,
|
|
60
|
+
identityFontRepair: true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const getCompatibility = (format) => {
|
|
65
|
+
if (format === "ppt") {
|
|
66
|
+
return { compatibility: "limited", warnings: ["legacy-format", "watermarked"] };
|
|
67
|
+
}
|
|
68
|
+
if (format === "doc" || format === "xls") {
|
|
69
|
+
return { compatibility: "limited", warnings: ["legacy-format"] };
|
|
70
|
+
}
|
|
71
|
+
if (format === "csv" || format === "tsv") {
|
|
72
|
+
return { compatibility: "limited", warnings: ["encoding-ambiguous"] };
|
|
73
|
+
}
|
|
74
|
+
return { compatibility: "standard", warnings: [] };
|
|
75
|
+
};
|
|
76
|
+
const loadRenderer = async (format) => {
|
|
77
|
+
if (format === "docx" || format === "doc") {
|
|
78
|
+
const { renderFileViewerWordDocx, renderFileViewerWordDoc } = await __vitePreload(async () => {
|
|
79
|
+
const { renderFileViewerWordDocx: renderFileViewerWordDocx2, renderFileViewerWordDoc: renderFileViewerWordDoc2 } = await import("./index-DQKbw6RS.js");
|
|
80
|
+
return { renderFileViewerWordDocx: renderFileViewerWordDocx2, renderFileViewerWordDoc: renderFileViewerWordDoc2 };
|
|
81
|
+
}, true ? __vite__mapDeps([0,1,2]) : void 0, import.meta.url);
|
|
82
|
+
return format === "doc" ? renderFileViewerWordDoc : renderFileViewerWordDocx;
|
|
83
|
+
}
|
|
84
|
+
if (format === "pdf") return (await __vitePreload(async () => {
|
|
85
|
+
const { renderFileViewerPdf } = await import("./index-DJvBCnCx.js");
|
|
86
|
+
return { renderFileViewerPdf };
|
|
87
|
+
}, true ? __vite__mapDeps([3,1,2]) : void 0, import.meta.url)).renderFileViewerPdf;
|
|
88
|
+
if (format === "ppt" || format === "pptx") {
|
|
89
|
+
const { renderFileViewerBinaryPresentation, renderFileViewerPresentation } = await __vitePreload(async () => {
|
|
90
|
+
const { renderFileViewerBinaryPresentation: renderFileViewerBinaryPresentation2, renderFileViewerPresentation: renderFileViewerPresentation2 } = await import("./index-BOyfEjY-.js");
|
|
91
|
+
return { renderFileViewerBinaryPresentation: renderFileViewerBinaryPresentation2, renderFileViewerPresentation: renderFileViewerPresentation2 };
|
|
92
|
+
}, true ? __vite__mapDeps([4,1,2]) : void 0, import.meta.url);
|
|
93
|
+
return format === "ppt" ? renderFileViewerBinaryPresentation : renderFileViewerPresentation;
|
|
94
|
+
}
|
|
95
|
+
return (await __vitePreload(async () => {
|
|
96
|
+
const { renderFileViewerSpreadsheet } = await import("./index-D-VQacpk.js");
|
|
97
|
+
return { renderFileViewerSpreadsheet };
|
|
98
|
+
}, true ? __vite__mapDeps([5,1,2]) : void 0, import.meta.url)).renderFileViewerSpreadsheet;
|
|
99
|
+
};
|
|
100
|
+
const renderOfficePreview = async (file, target, signal) => {
|
|
101
|
+
const renderer = await loadRenderer(file.format);
|
|
102
|
+
const instance = await renderer(file.buffer, target, file.format, createContext(file, signal));
|
|
103
|
+
return { ...getCompatibility(file.format), instance };
|
|
104
|
+
};
|
|
105
|
+
const destroyRenderedInstance = async (instance) => {
|
|
106
|
+
if (!instance) return;
|
|
107
|
+
if ("unmount" in instance) await instance.unmount();
|
|
108
|
+
else if ("$destroy" in instance) await instance.$destroy();
|
|
109
|
+
else await instance.destroy();
|
|
110
|
+
};
|
|
111
|
+
const SUPPORTED_FORMATS = new Set(OFFICE_PREVIEW_FORMATS);
|
|
112
|
+
function createOfficePreviewRuntime() {
|
|
113
|
+
const electronBridge = window.officePreview;
|
|
114
|
+
if (electronBridge) {
|
|
115
|
+
const sessionId = new URLSearchParams(window.location.hash.slice(1)).get("session");
|
|
116
|
+
if (!sessionId) throw new Error("ERROR_INVALID_OFFICE_PREVIEW_SESSION");
|
|
117
|
+
return { bridge: electronBridge, sessionId };
|
|
118
|
+
}
|
|
119
|
+
const config = parseRemoteConfig();
|
|
120
|
+
return {
|
|
121
|
+
bridge: createRemoteBridge(config),
|
|
122
|
+
sessionId: config.generation
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function parseRemoteConfig() {
|
|
126
|
+
const query = new URLSearchParams(window.location.search);
|
|
127
|
+
const hash = new URLSearchParams(window.location.hash.slice(1));
|
|
128
|
+
const token = query.get("token");
|
|
129
|
+
const source = hash.get("source");
|
|
130
|
+
const format = hash.get("format");
|
|
131
|
+
const generation = hash.get("generation");
|
|
132
|
+
if (!token || !source || !source.startsWith("/") || !format || !SUPPORTED_FORMATS.has(format) || !generation) {
|
|
133
|
+
throw new Error("ERROR_INVALID_OFFICE_PREVIEW_INPUT");
|
|
134
|
+
}
|
|
135
|
+
return { token, source, format, generation };
|
|
136
|
+
}
|
|
137
|
+
function createRemoteBridge(config) {
|
|
138
|
+
const endpoint = new URL(
|
|
139
|
+
`/api/office-preview/load${encodePathPreservingSlashes(config.source)}`,
|
|
140
|
+
window.location.origin
|
|
141
|
+
);
|
|
142
|
+
endpoint.searchParams.set("format", config.format);
|
|
143
|
+
endpoint.searchParams.set("token", config.token);
|
|
144
|
+
return {
|
|
145
|
+
async load() {
|
|
146
|
+
let failureReported = false;
|
|
147
|
+
try {
|
|
148
|
+
const response = await fetch(endpoint, {
|
|
149
|
+
cache: "no-store",
|
|
150
|
+
credentials: "omit"
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
failureReported = true;
|
|
154
|
+
reportRemoteLoadFailure(config, classifyRemoteLoadStatus(response.status));
|
|
155
|
+
throw new Error(`ERROR_OFFICE_PREVIEW_LOAD_${response.status}`);
|
|
156
|
+
}
|
|
157
|
+
const sourceVersion = readSourceVersion(response.headers);
|
|
158
|
+
return {
|
|
159
|
+
buffer: await response.arrayBuffer(),
|
|
160
|
+
generation: config.generation,
|
|
161
|
+
name: config.source.split("/").pop() || "office-file",
|
|
162
|
+
format: config.format,
|
|
163
|
+
sourceVersion
|
|
164
|
+
};
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (!failureReported) reportRemoteLoadFailure(config, "load-failed");
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
async save() {
|
|
171
|
+
throw new Error("ERROR_OFFICE_PREVIEW_READ_ONLY");
|
|
172
|
+
},
|
|
173
|
+
async reportReady(report) {
|
|
174
|
+
postParentEvent("ready", report);
|
|
175
|
+
},
|
|
176
|
+
async reportFailure(report) {
|
|
177
|
+
postParentEvent("failed", report);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function classifyRemoteLoadStatus(status) {
|
|
182
|
+
if (status === 401 || status === 403) return "permission-denied";
|
|
183
|
+
if (status === 404) return "file-not-found";
|
|
184
|
+
if (status === 409) return "source-changed";
|
|
185
|
+
if (status === 413) return "file-too-large";
|
|
186
|
+
if (status === 415) return "unsupported-format";
|
|
187
|
+
if (status === 422) return "corrupted-file";
|
|
188
|
+
return "load-failed";
|
|
189
|
+
}
|
|
190
|
+
function reportRemoteLoadFailure(config, reason) {
|
|
191
|
+
postParentEvent("failed", {
|
|
192
|
+
sessionId: config.generation,
|
|
193
|
+
generation: config.generation,
|
|
194
|
+
reason
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function readSourceVersion(headers) {
|
|
198
|
+
const sizeHeader = headers.get("x-kai-source-size");
|
|
199
|
+
const mtimeHeader = headers.get("x-kai-source-mtime-ms");
|
|
200
|
+
if (sizeHeader === null || mtimeHeader === null) {
|
|
201
|
+
throw new Error("ERROR_INVALID_OFFICE_PREVIEW_RESPONSE");
|
|
202
|
+
}
|
|
203
|
+
const size = Number(sizeHeader);
|
|
204
|
+
const mtimeMs = Number(mtimeHeader);
|
|
205
|
+
if (!Number.isSafeInteger(size) || size < 0 || !Number.isFinite(mtimeMs) || mtimeMs < 0) {
|
|
206
|
+
throw new Error("ERROR_INVALID_OFFICE_PREVIEW_RESPONSE");
|
|
207
|
+
}
|
|
208
|
+
return { size, mtimeMs };
|
|
209
|
+
}
|
|
210
|
+
function postParentEvent(status, detail) {
|
|
211
|
+
if (window.parent === window) return;
|
|
212
|
+
window.parent.postMessage({ type: "kai:office-preview", status, detail }, window.location.origin);
|
|
213
|
+
}
|
|
1
214
|
(function() {
|
|
2
215
|
try {
|
|
3
216
|
if (typeof document < "u") {
|
|
@@ -8741,6 +8954,318 @@ const yt = class yt2 {
|
|
|
8741
8954
|
};
|
|
8742
8955
|
r(yt, "locale");
|
|
8743
8956
|
let Ht = yt;
|
|
8957
|
+
const index_es = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
8958
|
+
__proto__: null,
|
|
8959
|
+
default: Ht
|
|
8960
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
8961
|
+
const SHEET_FORMATS = /* @__PURE__ */ new Set(["xlsx", "xls", "csv", "tsv"]);
|
|
8962
|
+
const DATA_COLUMN_MIN = 1;
|
|
8963
|
+
const TEXT_MAX_CHARS = 2e3;
|
|
8964
|
+
const TEXT_MAX_CELLS = 200;
|
|
8965
|
+
const PATCHED = /* @__PURE__ */ Symbol.for("kai.sheetPickContract.patched");
|
|
8966
|
+
const ADOPTED = /* @__PURE__ */ new WeakSet();
|
|
8967
|
+
let installed = false;
|
|
8968
|
+
let current = null;
|
|
8969
|
+
let scheduled = 0;
|
|
8970
|
+
let lastFocus = null;
|
|
8971
|
+
function swallowBlur(event) {
|
|
8972
|
+
event.stopImmediatePropagation();
|
|
8973
|
+
}
|
|
8974
|
+
function restoreFocusCell() {
|
|
8975
|
+
const table = current;
|
|
8976
|
+
const focus = lastFocus;
|
|
8977
|
+
if (!table || !focus || table.ctx.focusCell) return;
|
|
8978
|
+
const cell = table.ctx.body?.renderRows?.find((row) => row.rowIndex === focus.rowIndex)?.cells?.find((candidate) => candidate.colIndex === focus.colIndex);
|
|
8979
|
+
if (!cell) return;
|
|
8980
|
+
const focusable = cell;
|
|
8981
|
+
focusable.rowIndex = focus.rowIndex;
|
|
8982
|
+
focusable.colIndex = focus.colIndex;
|
|
8983
|
+
table.ctx.setFocusCell?.(focusable);
|
|
8984
|
+
}
|
|
8985
|
+
function rememberFocusCell(table) {
|
|
8986
|
+
const cell = table.ctx.focusCell;
|
|
8987
|
+
if (cell) lastFocus = { rowIndex: cell.rowIndex, colIndex: cell.colIndex };
|
|
8988
|
+
}
|
|
8989
|
+
function patchEngine() {
|
|
8990
|
+
const prototype = Ht.prototype;
|
|
8991
|
+
if (prototype[PATCHED]) return;
|
|
8992
|
+
Object.defineProperty(prototype, PATCHED, { value: true, enumerable: false });
|
|
8993
|
+
for (const method of ["draw", "loadData"]) {
|
|
8994
|
+
const original = prototype[method];
|
|
8995
|
+
if (typeof original !== "function") continue;
|
|
8996
|
+
prototype[method] = function patched(...args) {
|
|
8997
|
+
adopt(this);
|
|
8998
|
+
return original.apply(this, args);
|
|
8999
|
+
};
|
|
9000
|
+
}
|
|
9001
|
+
}
|
|
9002
|
+
function adopt(table) {
|
|
9003
|
+
current = table;
|
|
9004
|
+
if (ADOPTED.has(table)) return;
|
|
9005
|
+
ADOPTED.add(table);
|
|
9006
|
+
for (const event of ["setSelector", "clearSelector", "onScrollX", "onScrollY"]) {
|
|
9007
|
+
try {
|
|
9008
|
+
table.on(event, schedule);
|
|
9009
|
+
} catch {
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
schedule();
|
|
9013
|
+
}
|
|
9014
|
+
function schedule() {
|
|
9015
|
+
if (scheduled) return;
|
|
9016
|
+
scheduled = requestAnimationFrame(() => {
|
|
9017
|
+
scheduled = 0;
|
|
9018
|
+
publish();
|
|
9019
|
+
});
|
|
9020
|
+
}
|
|
9021
|
+
function readSheetName() {
|
|
9022
|
+
const active = document.querySelector(
|
|
9023
|
+
'.sheet-tab[aria-pressed="true"], .sheet-tab.active'
|
|
9024
|
+
);
|
|
9025
|
+
const name = active?.textContent?.trim() ?? "";
|
|
9026
|
+
return name === "" ? null : name;
|
|
9027
|
+
}
|
|
9028
|
+
function dataColumn(table, columnIndex) {
|
|
9029
|
+
const header = table.ctx.header?.leafCellHeaders?.[columnIndex];
|
|
9030
|
+
const matched = /^c(\d+)$/u.exec(header?.key ?? "");
|
|
9031
|
+
if (matched) return Number(matched[1]);
|
|
9032
|
+
if (columnIndex < DATA_COLUMN_MIN) return null;
|
|
9033
|
+
return columnIndex - DATA_COLUMN_MIN;
|
|
9034
|
+
}
|
|
9035
|
+
function selectionRect(table, bounds) {
|
|
9036
|
+
const canvas = table.ctx.canvasElement;
|
|
9037
|
+
if (!canvas) return null;
|
|
9038
|
+
const origin = canvas.getBoundingClientRect();
|
|
9039
|
+
let left = Number.POSITIVE_INFINITY;
|
|
9040
|
+
let top = Number.POSITIVE_INFINITY;
|
|
9041
|
+
let right = Number.NEGATIVE_INFINITY;
|
|
9042
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
9043
|
+
for (const row of table.ctx.body?.renderRows ?? []) {
|
|
9044
|
+
if (row.rowIndex < bounds.minRow || row.rowIndex > bounds.maxRow) continue;
|
|
9045
|
+
top = Math.min(top, origin.top + row.y);
|
|
9046
|
+
bottom = Math.max(bottom, origin.top + row.y + row.height);
|
|
9047
|
+
}
|
|
9048
|
+
for (let columnIndex = bounds.minCol; columnIndex <= bounds.maxCol; columnIndex += 1) {
|
|
9049
|
+
const header = table.ctx.header?.leafCellHeaders?.[columnIndex];
|
|
9050
|
+
if (!header) continue;
|
|
9051
|
+
left = Math.min(left, origin.left + header.drawX);
|
|
9052
|
+
right = Math.max(right, origin.left + header.drawX + header.width);
|
|
9053
|
+
}
|
|
9054
|
+
if (!Number.isFinite(left) || !Number.isFinite(top)) return null;
|
|
9055
|
+
return { x: left, y: top, width: Math.max(0, right - left), height: Math.max(0, bottom - top) };
|
|
9056
|
+
}
|
|
9057
|
+
function viewportRect(table) {
|
|
9058
|
+
const container = table.ctx.containerElement;
|
|
9059
|
+
if (!container) return null;
|
|
9060
|
+
const rect = container.getBoundingClientRect();
|
|
9061
|
+
if (rect.width < 1 || rect.height < 1) return null;
|
|
9062
|
+
return { x: rect.x, y: rect.y, width: rect.width, height: rect.height };
|
|
9063
|
+
}
|
|
9064
|
+
function cellDisplayText(cell) {
|
|
9065
|
+
const display = cell?.displayText;
|
|
9066
|
+
return typeof display === "string" ? display : null;
|
|
9067
|
+
}
|
|
9068
|
+
function readRowFields(table, bounds) {
|
|
9069
|
+
const rendered = /* @__PURE__ */ new Map();
|
|
9070
|
+
for (const row of table.ctx.body?.renderRows ?? []) {
|
|
9071
|
+
const bucket = rendered.get(row.rowIndex);
|
|
9072
|
+
if (bucket) bucket.push(row);
|
|
9073
|
+
else rendered.set(row.rowIndex, [row]);
|
|
9074
|
+
}
|
|
9075
|
+
const startColumn = Math.max(bounds.minCol, DATA_COLUMN_MIN);
|
|
9076
|
+
const lines = [];
|
|
9077
|
+
for (let rowIndex = bounds.minRow; rowIndex <= bounds.maxRow; rowIndex += 1) {
|
|
9078
|
+
const variants = rendered.get(rowIndex) ?? [];
|
|
9079
|
+
const fields = [];
|
|
9080
|
+
for (let columnIndex = startColumn; columnIndex <= bounds.maxCol; columnIndex += 1) {
|
|
9081
|
+
const value = variants.reduce(
|
|
9082
|
+
(found, row) => found ?? cellDisplayText(row.cells?.[columnIndex]),
|
|
9083
|
+
null
|
|
9084
|
+
);
|
|
9085
|
+
fields.push(value === null ? "" : value.trim().replace(/\s+/gu, " "));
|
|
9086
|
+
}
|
|
9087
|
+
while (fields.length > 0 && fields[fields.length - 1] === "") fields.pop();
|
|
9088
|
+
lines.push(fields);
|
|
9089
|
+
}
|
|
9090
|
+
while (lines.length > 0 && lines[lines.length - 1].length === 0) lines.pop();
|
|
9091
|
+
while (lines.length > 0 && lines[0].length === 0) lines.shift();
|
|
9092
|
+
return lines;
|
|
9093
|
+
}
|
|
9094
|
+
function truncateLines(lines) {
|
|
9095
|
+
let out = "";
|
|
9096
|
+
let cells = 0;
|
|
9097
|
+
for (const fields of lines) {
|
|
9098
|
+
const row = [];
|
|
9099
|
+
for (const field of fields) {
|
|
9100
|
+
if (field === "") {
|
|
9101
|
+
row.push("");
|
|
9102
|
+
continue;
|
|
9103
|
+
}
|
|
9104
|
+
if (cells >= TEXT_MAX_CELLS) return out;
|
|
9105
|
+
const addition = (row.length > 0 ? " " : "") + field;
|
|
9106
|
+
const prefix = out === "" ? "" : `${out}
|
|
9107
|
+
`;
|
|
9108
|
+
const room = TEXT_MAX_CHARS - prefix.length - row.join(" ").length;
|
|
9109
|
+
if (addition.length > room) {
|
|
9110
|
+
if (out === "" && row.length === 0) return field.slice(0, TEXT_MAX_CHARS);
|
|
9111
|
+
return out;
|
|
9112
|
+
}
|
|
9113
|
+
row.push(field);
|
|
9114
|
+
cells += 1;
|
|
9115
|
+
}
|
|
9116
|
+
out = out === "" ? row.join(" ") : `${out}
|
|
9117
|
+
${row.join(" ")}`;
|
|
9118
|
+
}
|
|
9119
|
+
return out;
|
|
9120
|
+
}
|
|
9121
|
+
function selectionText(table, bounds) {
|
|
9122
|
+
const lines = readRowFields(table, bounds);
|
|
9123
|
+
const full = lines.map((fields) => fields.join(" ")).join("\n");
|
|
9124
|
+
if (full.trim() === "") return null;
|
|
9125
|
+
return { text: truncateLines(lines), charCount: full.length };
|
|
9126
|
+
}
|
|
9127
|
+
function currentSelection(table) {
|
|
9128
|
+
const selector = table.ctx.selector;
|
|
9129
|
+
if (!selector?.enable) return null;
|
|
9130
|
+
const { xArr, yArr } = selector;
|
|
9131
|
+
if (xArr.length < 2 || yArr.length < 2) return null;
|
|
9132
|
+
const sheetName = readSheetName();
|
|
9133
|
+
if (!sheetName) return null;
|
|
9134
|
+
const minColumn = Math.min(...xArr);
|
|
9135
|
+
const maxColumn = Math.max(...xArr);
|
|
9136
|
+
const minCol = dataColumn(table, minColumn);
|
|
9137
|
+
const maxCol = dataColumn(table, maxColumn);
|
|
9138
|
+
if (minCol === null || maxCol === null) return null;
|
|
9139
|
+
const minRow = Math.min(...yArr);
|
|
9140
|
+
const maxRow = Math.max(...yArr);
|
|
9141
|
+
const rect = selectionRect(table, { minCol: minColumn, maxCol: maxColumn, minRow, maxRow });
|
|
9142
|
+
const viewport = viewportRect(table);
|
|
9143
|
+
if (!rect || !viewport) return null;
|
|
9144
|
+
const text = selectionText(table, { minCol: minColumn, maxCol: maxColumn, minRow, maxRow });
|
|
9145
|
+
return { sheetName, minCol, minRow, maxCol, maxRow, rect, viewport, text };
|
|
9146
|
+
}
|
|
9147
|
+
function formatRect(rect) {
|
|
9148
|
+
return [rect.x, rect.y, rect.width, rect.height].map((value) => Math.round(value)).join(",");
|
|
9149
|
+
}
|
|
9150
|
+
function publish() {
|
|
9151
|
+
const root = document.documentElement;
|
|
9152
|
+
if (!root) return;
|
|
9153
|
+
if (current) rememberFocusCell(current);
|
|
9154
|
+
const selection = current ? currentSelection(current) : null;
|
|
9155
|
+
if (!selection) {
|
|
9156
|
+
clearContract();
|
|
9157
|
+
return;
|
|
9158
|
+
}
|
|
9159
|
+
root.dataset[SHEET_PICK_CONTRACT.sheetName] = selection.sheetName;
|
|
9160
|
+
root.dataset[SHEET_PICK_CONTRACT.range] = [
|
|
9161
|
+
selection.minCol,
|
|
9162
|
+
selection.minRow,
|
|
9163
|
+
selection.maxCol,
|
|
9164
|
+
selection.maxRow
|
|
9165
|
+
].join(",");
|
|
9166
|
+
root.dataset[SHEET_PICK_CONTRACT.rect] = formatRect(selection.rect);
|
|
9167
|
+
root.dataset[SHEET_PICK_CONTRACT.viewport] = formatRect(selection.viewport);
|
|
9168
|
+
if (selection.text) {
|
|
9169
|
+
root.dataset[SHEET_PICK_CONTRACT.text] = selection.text.text;
|
|
9170
|
+
root.dataset[SHEET_PICK_CONTRACT.textChars] = String(selection.text.charCount);
|
|
9171
|
+
} else {
|
|
9172
|
+
delete root.dataset[SHEET_PICK_CONTRACT.text];
|
|
9173
|
+
delete root.dataset[SHEET_PICK_CONTRACT.textChars];
|
|
9174
|
+
}
|
|
9175
|
+
document.dispatchEvent(new CustomEvent(SHEET_PICK_CHANGE_EVENT));
|
|
9176
|
+
}
|
|
9177
|
+
function clearContract() {
|
|
9178
|
+
const root = document.documentElement;
|
|
9179
|
+
if (!root) return;
|
|
9180
|
+
const changed = Object.values(SHEET_PICK_CONTRACT).some((key) => key in root.dataset);
|
|
9181
|
+
for (const key of Object.values(SHEET_PICK_CONTRACT)) delete root.dataset[key];
|
|
9182
|
+
if (changed) document.dispatchEvent(new CustomEvent(SHEET_PICK_CHANGE_EVENT));
|
|
9183
|
+
}
|
|
9184
|
+
function installSheetPickContract(format) {
|
|
9185
|
+
if (!SHEET_FORMATS.has(format) || installed) return () => {
|
|
9186
|
+
};
|
|
9187
|
+
installed = true;
|
|
9188
|
+
patchEngine();
|
|
9189
|
+
const onResize = () => schedule();
|
|
9190
|
+
window.addEventListener("resize", onResize, { passive: true });
|
|
9191
|
+
window.addEventListener("blur", swallowBlur);
|
|
9192
|
+
document.addEventListener("mousedown", restoreFocusCell, { capture: true });
|
|
9193
|
+
const observer = new MutationObserver(() => schedule());
|
|
9194
|
+
observer.observe(document.body, {
|
|
9195
|
+
subtree: true,
|
|
9196
|
+
childList: true,
|
|
9197
|
+
attributes: true,
|
|
9198
|
+
attributeFilter: ["aria-pressed", "class"]
|
|
9199
|
+
});
|
|
9200
|
+
schedule();
|
|
9201
|
+
return () => {
|
|
9202
|
+
window.removeEventListener("resize", onResize);
|
|
9203
|
+
window.removeEventListener("blur", swallowBlur);
|
|
9204
|
+
document.removeEventListener("mousedown", restoreFocusCell, { capture: true });
|
|
9205
|
+
observer.disconnect();
|
|
9206
|
+
if (scheduled) cancelAnimationFrame(scheduled);
|
|
9207
|
+
scheduled = 0;
|
|
9208
|
+
current = null;
|
|
9209
|
+
lastFocus = null;
|
|
9210
|
+
installed = false;
|
|
9211
|
+
clearContract();
|
|
9212
|
+
};
|
|
9213
|
+
}
|
|
9214
|
+
let renderedInstance = null;
|
|
9215
|
+
const abortController = new AbortController();
|
|
9216
|
+
let disposeSheetPick = null;
|
|
9217
|
+
async function start() {
|
|
9218
|
+
const root = document.querySelector("#office-preview-root");
|
|
9219
|
+
if (!root) return;
|
|
9220
|
+
let bridge = null;
|
|
9221
|
+
let file = null;
|
|
9222
|
+
let sessionId = null;
|
|
9223
|
+
try {
|
|
9224
|
+
const runtime = createOfficePreviewRuntime();
|
|
9225
|
+
bridge = runtime.bridge;
|
|
9226
|
+
sessionId = runtime.sessionId;
|
|
9227
|
+
file = await bridge.load(sessionId);
|
|
9228
|
+
document.documentElement.dataset.officePreviewFormat = file.format;
|
|
9229
|
+
disposeSheetPick = installSheetPickContract(file.format);
|
|
9230
|
+
root.replaceChildren();
|
|
9231
|
+
const result = await renderOfficePreview(file, root, abortController.signal);
|
|
9232
|
+
renderedInstance = result.instance;
|
|
9233
|
+
await bridge.reportReady({
|
|
9234
|
+
sessionId,
|
|
9235
|
+
generation: file.generation,
|
|
9236
|
+
compatibility: result.compatibility,
|
|
9237
|
+
warnings: result.warnings
|
|
9238
|
+
});
|
|
9239
|
+
} catch (error) {
|
|
9240
|
+
root.classList.add("office-preview-status");
|
|
9241
|
+
root.textContent = file ? "无法预览此文件。" : "无法读取此文件。";
|
|
9242
|
+
if (bridge && file && sessionId) {
|
|
9243
|
+
await bridge.reportFailure({
|
|
9244
|
+
sessionId,
|
|
9245
|
+
generation: file.generation,
|
|
9246
|
+
reason: classifyFailure(error)
|
|
9247
|
+
});
|
|
9248
|
+
}
|
|
9249
|
+
}
|
|
9250
|
+
}
|
|
9251
|
+
function classifyFailure(error) {
|
|
9252
|
+
const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
9253
|
+
if (message.includes("encrypt") || message.includes("password")) return "encrypted";
|
|
9254
|
+
if (message.includes("memory") || message.includes("limit") || message.includes("too large")) {
|
|
9255
|
+
return "resource-limit";
|
|
9256
|
+
}
|
|
9257
|
+
return "corrupted-file";
|
|
9258
|
+
}
|
|
9259
|
+
window.addEventListener(
|
|
9260
|
+
"beforeunload",
|
|
9261
|
+
() => {
|
|
9262
|
+
abortController.abort();
|
|
9263
|
+
disposeSheetPick?.();
|
|
9264
|
+
void destroyRenderedInstance(renderedInstance);
|
|
9265
|
+
},
|
|
9266
|
+
{ once: true }
|
|
9267
|
+
);
|
|
9268
|
+
void start();
|
|
8744
9269
|
export {
|
|
8745
|
-
|
|
9270
|
+
index_es as i
|
|
8746
9271
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as instance, a as installOverlayTransport, c as clientExports, j as jsxRuntimeExports, r as reactExports, d as describePluginPageOpenError, b as describePluginViewFailure, e as describeDesktopOverlayReason, P as PluginViewHost } from "./desktop-overlay-reason-
|
|
1
|
+
import { i as instance, a as installOverlayTransport, c as clientExports, j as jsxRuntimeExports, r as reactExports, d as describePluginPageOpenError, b as describePluginViewFailure, e as describeDesktopOverlayReason, P as PluginViewHost } from "./desktop-overlay-reason-Lk3ArWYm.js";
|
|
2
2
|
import "./_commonjsHelpers-DWwsNxpa.js";
|
|
3
|
-
import "./localUrlCodec-
|
|
3
|
+
import "./localUrlCodec-DIa41KGx.js";
|
|
4
4
|
const shell = "_shell_n0fba_9";
|
|
5
5
|
const titleBar = "_titleBar_n0fba_24";
|
|
6
6
|
const grip = "_grip_n0fba_45";
|
|
@@ -125,19 +125,65 @@ function OverlayShell({ host: host2 }) {
|
|
|
125
125
|
window.clearTimeout(throughTimerRef.current);
|
|
126
126
|
};
|
|
127
127
|
}, [applyThrough, host2]);
|
|
128
|
+
const replyBounds = reactExports.useCallback(
|
|
129
|
+
async (target) => {
|
|
130
|
+
if (!target) return;
|
|
131
|
+
let rect = null;
|
|
132
|
+
try {
|
|
133
|
+
const states = await host2.getState();
|
|
134
|
+
rect = states.find((state) => state.pluginId === host2.pluginId)?.bounds ?? null;
|
|
135
|
+
} catch {
|
|
136
|
+
rect = null;
|
|
137
|
+
}
|
|
138
|
+
target.postMessage(
|
|
139
|
+
{
|
|
140
|
+
type: "kai.overlay.bounds",
|
|
141
|
+
bounds: rect ? {
|
|
142
|
+
...rect,
|
|
143
|
+
availWidth: window.screen.availWidth,
|
|
144
|
+
availHeight: window.screen.availHeight
|
|
145
|
+
} : null
|
|
146
|
+
},
|
|
147
|
+
"*"
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
[host2]
|
|
151
|
+
);
|
|
152
|
+
const moveAccRef = reactExports.useRef({ dx: 0, dy: 0, scheduled: false });
|
|
153
|
+
const flushMove = reactExports.useCallback(() => {
|
|
154
|
+
const acc = moveAccRef.current;
|
|
155
|
+
acc.scheduled = false;
|
|
156
|
+
const { dx, dy } = acc;
|
|
157
|
+
acc.dx = 0;
|
|
158
|
+
acc.dy = 0;
|
|
159
|
+
if (dx !== 0 || dy !== 0) void host2.moveBy(dx, dy);
|
|
160
|
+
}, [host2]);
|
|
161
|
+
const scheduleMove = reactExports.useCallback(() => {
|
|
162
|
+
const acc = moveAccRef.current;
|
|
163
|
+
if (acc.scheduled) return;
|
|
164
|
+
acc.scheduled = true;
|
|
165
|
+
requestAnimationFrame(flushMove);
|
|
166
|
+
window.setTimeout(flushMove, 32);
|
|
167
|
+
}, [flushMove]);
|
|
128
168
|
reactExports.useEffect(() => {
|
|
129
169
|
const onMessage = (event) => {
|
|
130
170
|
const frame = document.querySelector("iframe");
|
|
131
171
|
if (!frame || event.source !== frame.contentWindow) return;
|
|
132
172
|
const data = event.data;
|
|
133
|
-
if (!data || typeof data !== "object"
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
173
|
+
if (!data || typeof data !== "object") return;
|
|
174
|
+
if (data.type === "kai.overlay.move") {
|
|
175
|
+
if (typeof data.dx !== "number" || typeof data.dy !== "number") return;
|
|
176
|
+
if (!Number.isFinite(data.dx) || !Number.isFinite(data.dy)) return;
|
|
177
|
+
moveAccRef.current.dx += data.dx;
|
|
178
|
+
moveAccRef.current.dy += data.dy;
|
|
179
|
+
scheduleMove();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (data.type === "kai.overlay.query-bounds") void replyBounds(frame.contentWindow);
|
|
137
183
|
};
|
|
138
184
|
window.addEventListener("message", onMessage);
|
|
139
185
|
return () => window.removeEventListener("message", onMessage);
|
|
140
|
-
}, [host2]);
|
|
186
|
+
}, [host2, replyBounds, scheduleMove]);
|
|
141
187
|
const close = reactExports.useCallback(() => {
|
|
142
188
|
void host2.setOverlay(false);
|
|
143
189
|
}, [host2]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./UTIF-CVZ0V0ma.js","./_commonjsHelpers-DWwsNxpa.js","./_commonjs-dynamic-modules-TGKdzP3c.js","./index-C0ieAyi1.js","./parser-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./UTIF-CVZ0V0ma.js","./_commonjsHelpers-DWwsNxpa.js","./_commonjs-dynamic-modules-TGKdzP3c.js","./index-C0ieAyi1.js","./office-preview-BS5mB52v.js","./preload-helper-DVzrZ_Op.js","./localUrlCodec-DIa41KGx.js","./office-preview-D1GRjX_y.css","./parser-BfKF1DWc.js","./jszip.min-CkAgz-ea.js","./index-B5MYHOIO.js","./assets-tzxXyukA.js","./zoom-jYhmkcQX.js","./options-SsS0Y_ki.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import { _ as __vitePreload } from "./preload-helper-DVzrZ_Op.js";
|
|
3
3
|
import { d as resolveFileViewerSpreadsheetWorkerUrl, r as resolveFileViewerRuntimeAssetBaseUrl } from "./assets-tzxXyukA.js";
|
|
4
4
|
import { c as createFileViewerTranslator, r as registerFileViewerZoomProvider, u as unregisterFileViewerZoomProvider, a as resolveFileViewerFitScale } from "./index-B5MYHOIO.js";
|
|
@@ -2617,7 +2617,7 @@ const resolveEVirtTableStyleText = (documentRef) => {
|
|
|
2617
2617
|
const loadEVirtTable = async (documentRef) => {
|
|
2618
2618
|
const documents = collectEVirtTableStyleDocuments(documentRef);
|
|
2619
2619
|
const stylesBeforeImport = new Set(collectStyleElements(documents));
|
|
2620
|
-
const module = await __vitePreload(() => import("./
|
|
2620
|
+
const module = await __vitePreload(() => import("./office-preview-BS5mB52v.js").then((n) => n.i), true ? __vite__mapDeps([4,5,6,7]) : void 0, import.meta.url);
|
|
2621
2621
|
const injectedStyles = collectStyleElements(documents).filter((style) => !stylesBeforeImport.has(style) && isEVirtTableStyleText(style.textContent || ""));
|
|
2622
2622
|
const injectedStyle = injectedStyles[injectedStyles.length - 1];
|
|
2623
2623
|
if (injectedStyle) {
|
|
@@ -2696,7 +2696,7 @@ class MainThreadSpreadsheetWorker {
|
|
|
2696
2696
|
}
|
|
2697
2697
|
async loadParser() {
|
|
2698
2698
|
if (!this.parserPromise) {
|
|
2699
|
-
this.parserPromise = __vitePreload(() => import("./parser-
|
|
2699
|
+
this.parserPromise = __vitePreload(() => import("./parser-BfKF1DWc.js"), true ? __vite__mapDeps([8,9,1,2,10,5,11,12,13]) : void 0, import.meta.url);
|
|
2700
2700
|
}
|
|
2701
2701
|
const parser = await this.parserPromise;
|
|
2702
2702
|
if (!this.context) {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>KAi</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-2o21y_A2.js"></script>
|
|
8
8
|
<link rel="modulepreload" crossorigin href="./assets/_commonjsHelpers-DWwsNxpa.js">
|
|
9
|
-
<link rel="modulepreload" crossorigin href="./assets/localUrlCodec-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="./assets/desktop-overlay-reason-
|
|
9
|
+
<link rel="modulepreload" crossorigin href="./assets/localUrlCodec-DIa41KGx.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="./assets/desktop-overlay-reason-Lk3ArWYm.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-DVzrZ_Op.js">
|
|
12
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
12
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CNIvLq5A.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
/>
|
|
10
10
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
11
11
|
<title>KAi Office Preview</title>
|
|
12
|
-
<script type="module" crossorigin src="./assets/office-preview-
|
|
12
|
+
<script type="module" crossorigin src="./assets/office-preview-BS5mB52v.js"></script>
|
|
13
13
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-DVzrZ_Op.js">
|
|
14
|
-
<link rel="modulepreload" crossorigin href="./assets/localUrlCodec-
|
|
14
|
+
<link rel="modulepreload" crossorigin href="./assets/localUrlCodec-DIa41KGx.js">
|
|
15
15
|
<link rel="stylesheet" crossorigin href="./assets/office-preview-D1GRjX_y.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|