@ai-matrx/office 0.3.0 → 0.4.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/CHANGELOG.md +15 -0
- package/dist/chunk-5T2M6LSI.js +529 -0
- package/dist/chunk-5T2M6LSI.js.map +1 -0
- package/dist/chunk-QZE7HBZB.cjs +529 -0
- package/dist/chunk-QZE7HBZB.cjs.map +1 -0
- package/dist/chunk-WKBWRG7N.js +209 -0
- package/dist/chunk-WKBWRG7N.js.map +1 -0
- package/dist/chunk-ZDZCCOUB.cjs +209 -0
- package/dist/chunk-ZDZCCOUB.cjs.map +1 -0
- package/dist/core.d.cts +5 -1
- package/dist/core.d.ts +5 -1
- package/dist/matrxImagePorts-JDFYE4QI.cjs +59 -0
- package/dist/matrxImagePorts-JDFYE4QI.cjs.map +1 -0
- package/dist/matrxImagePorts-VPBBUADM.js +59 -0
- package/dist/matrxImagePorts-VPBBUADM.js.map +1 -0
- package/dist/sheets-xlsx.cjs +525 -0
- package/dist/sheets-xlsx.cjs.map +1 -0
- package/dist/sheets-xlsx.d.cts +153 -0
- package/dist/sheets-xlsx.d.ts +153 -0
- package/dist/sheets-xlsx.js +525 -0
- package/dist/sheets-xlsx.js.map +1 -0
- package/dist/sheets.cjs +921 -0
- package/dist/sheets.cjs.map +1 -0
- package/dist/sheets.d.cts +605 -0
- package/dist/sheets.d.ts +605 -0
- package/dist/sheets.js +921 -0
- package/dist/sheets.js.map +1 -0
- package/dist/univer-collab.cjs +2 -78
- package/dist/univer-collab.cjs.map +1 -1
- package/dist/univer-collab.d.cts +7 -15
- package/dist/univer-collab.d.ts +7 -15
- package/dist/univer-collab.js +2 -78
- package/dist/univer-collab.js.map +1 -1
- package/dist/univer-realtime.cjs +102 -0
- package/dist/univer-realtime.cjs.map +1 -0
- package/dist/univer-realtime.d.cts +15 -0
- package/dist/univer-realtime.d.ts +15 -0
- package/dist/univer-realtime.js +80 -0
- package/dist/univer-realtime.js.map +1 -0
- package/dist/xlsx-to-univer-AQAXU3TC.cjs +7 -0
- package/dist/xlsx-to-univer-AQAXU3TC.cjs.map +1 -0
- package/dist/xlsx-to-univer-OPMMBWEW.js +7 -0
- package/dist/xlsx-to-univer-OPMMBWEW.js.map +1 -0
- package/package.json +41 -4
package/dist/sheets.cjs
ADDED
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _chunkZDZCCOUBcjs = require('./chunk-ZDZCCOUB.cjs');
|
|
20
|
+
|
|
21
|
+
// src/sheets/univer-snapshot-rows.ts
|
|
22
|
+
function univerSheetIds(snapshot) {
|
|
23
|
+
if (typeof snapshot !== "object" || snapshot === null) return [];
|
|
24
|
+
const shape = snapshot;
|
|
25
|
+
const sheets = _nullishCoalesce(shape.sheets, () => ( {}));
|
|
26
|
+
const ordered = (_nullishCoalesce(shape.sheetOrder, () => ( []))).filter((id) => sheets[id]);
|
|
27
|
+
return ordered.length ? ordered : Object.keys(sheets);
|
|
28
|
+
}
|
|
29
|
+
function patternOf(cell, styles) {
|
|
30
|
+
const s = _optionalChain([cell, 'optionalAccess', _2 => _2.s]);
|
|
31
|
+
const style = typeof s === "string" ? _optionalChain([styles, 'optionalAccess', _3 => _3[s]]) : s && typeof s === "object" ? s : null;
|
|
32
|
+
const pattern = _optionalChain([style, 'optionalAccess', _4 => _4.n, 'optionalAccess', _5 => _5.pattern]);
|
|
33
|
+
return typeof pattern === "string" ? pattern : null;
|
|
34
|
+
}
|
|
35
|
+
var DAY_MS = 864e5;
|
|
36
|
+
var SERIAL_EPOCH_MS = Date.UTC(1899, 11, 30);
|
|
37
|
+
function cellText(cell, styles) {
|
|
38
|
+
const value = _optionalChain([cell, 'optionalAccess', _6 => _6.v]);
|
|
39
|
+
if (value === null || value === void 0) return "";
|
|
40
|
+
if (typeof value === "number") {
|
|
41
|
+
const pattern = _nullishCoalesce(_optionalChain([patternOf, 'call', _7 => _7(cell, styles), 'optionalAccess', _8 => _8.replace, 'call', _9 => _9(/"[^"]*"/g, ""), 'access', _10 => _10.toLowerCase, 'call', _11 => _11()]), () => ( ""));
|
|
42
|
+
if (/[dy]/.test(pattern)) {
|
|
43
|
+
const iso = new Date(Math.round(SERIAL_EPOCH_MS + value * DAY_MS)).toISOString();
|
|
44
|
+
return /h/.test(pattern) ? `${iso.slice(0, 10)} ${iso.slice(11, 16)}` : iso.slice(0, 10);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return String(value);
|
|
48
|
+
}
|
|
49
|
+
function univerSnapshotToRows(snapshot, options = {}) {
|
|
50
|
+
if (typeof snapshot !== "object" || snapshot === null) return null;
|
|
51
|
+
const shape = snapshot;
|
|
52
|
+
const sheets = _nullishCoalesce(shape.sheets, () => ( {}));
|
|
53
|
+
const styles = shape.styles;
|
|
54
|
+
const firstId = options.sheetId ? sheets[options.sheetId] ? options.sheetId : void 0 : _nullishCoalesce(_optionalChain([shape, 'access', _12 => _12.sheetOrder, 'optionalAccess', _13 => _13.find, 'call', _14 => _14((id) => sheets[id])]), () => ( Object.keys(sheets)[0]));
|
|
55
|
+
if (!firstId) return null;
|
|
56
|
+
const sheet = sheets[firstId];
|
|
57
|
+
const cellData = _nullishCoalesce(_optionalChain([sheet, 'optionalAccess', _15 => _15.cellData]), () => ( {}));
|
|
58
|
+
let maxRow = -1;
|
|
59
|
+
let maxCol = -1;
|
|
60
|
+
for (const [rowKey, row] of Object.entries(cellData)) {
|
|
61
|
+
const rowIndex = Number(rowKey);
|
|
62
|
+
if (!Number.isInteger(rowIndex) || !row) continue;
|
|
63
|
+
for (const [colKey, cell] of Object.entries(row)) {
|
|
64
|
+
const colIndex = Number(colKey);
|
|
65
|
+
if (!Number.isInteger(colIndex)) continue;
|
|
66
|
+
if (cellText(cell) === "") continue;
|
|
67
|
+
if (rowIndex > maxRow) maxRow = rowIndex;
|
|
68
|
+
if (colIndex > maxCol) maxCol = colIndex;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const range = options.range;
|
|
72
|
+
if (range) {
|
|
73
|
+
maxRow = range.endRow;
|
|
74
|
+
maxCol = range.endColumn;
|
|
75
|
+
}
|
|
76
|
+
if (maxRow < 0 || maxCol < 0) {
|
|
77
|
+
return { sheetName: _nullishCoalesce(_optionalChain([sheet, 'optionalAccess', _16 => _16.name]), () => ( "Sheet1")), rows: [], frozenRows: 0, frozenCols: 0 };
|
|
78
|
+
}
|
|
79
|
+
const firstRow = _nullishCoalesce(_optionalChain([range, 'optionalAccess', _17 => _17.startRow]), () => ( 0));
|
|
80
|
+
const firstCol = _nullishCoalesce(_optionalChain([range, 'optionalAccess', _18 => _18.startColumn]), () => ( 0));
|
|
81
|
+
const hiddenCol = (c) => options.skipHidden === true && _optionalChain([sheet, 'optionalAccess', _19 => _19.columnData, 'optionalAccess', _20 => _20[String(c)], 'optionalAccess', _21 => _21.hd]) === 1;
|
|
82
|
+
const hiddenRow = (r) => options.skipHidden === true && _optionalChain([sheet, 'optionalAccess', _22 => _22.rowData, 'optionalAccess', _23 => _23[String(r)], 'optionalAccess', _24 => _24.hd]) === 1;
|
|
83
|
+
const rows = [];
|
|
84
|
+
const ySplit = Math.max(0, _nullishCoalesce(_optionalChain([sheet, 'optionalAccess', _25 => _25.freeze, 'optionalAccess', _26 => _26.ySplit]), () => ( 0)));
|
|
85
|
+
const xSplit = Math.max(0, _nullishCoalesce(_optionalChain([sheet, 'optionalAccess', _27 => _27.freeze, 'optionalAccess', _28 => _28.xSplit]), () => ( 0)));
|
|
86
|
+
let frozenRows = 0;
|
|
87
|
+
let frozenCols = 0;
|
|
88
|
+
for (let r = firstRow; r <= maxRow; r += 1) {
|
|
89
|
+
if (hiddenRow(r)) continue;
|
|
90
|
+
if (r < ySplit) frozenRows += 1;
|
|
91
|
+
const row = [];
|
|
92
|
+
const source = _nullishCoalesce(cellData[String(r)], () => ( {}));
|
|
93
|
+
let colsFrozenHere = 0;
|
|
94
|
+
for (let c = firstCol; c <= maxCol; c += 1) {
|
|
95
|
+
if (hiddenCol(c)) continue;
|
|
96
|
+
if (c < xSplit) colsFrozenHere += 1;
|
|
97
|
+
row.push(cellText(source[String(c)], styles));
|
|
98
|
+
}
|
|
99
|
+
frozenCols = colsFrozenHere;
|
|
100
|
+
rows.push(row);
|
|
101
|
+
}
|
|
102
|
+
return { sheetName: _nullishCoalesce(_optionalChain([sheet, 'optionalAccess', _29 => _29.name]), () => ( "Sheet1")), rows, frozenRows, frozenCols };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/sheets/snapshot-preview-svg.ts
|
|
106
|
+
var THUMB_WIDTH = 320;
|
|
107
|
+
var THUMB_HEIGHT = 414;
|
|
108
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
109
|
+
function color(c, fallback) {
|
|
110
|
+
const v = _optionalChain([c, 'optionalAccess', _30 => _30.rgb]);
|
|
111
|
+
return typeof v === "string" && v.length > 0 ? v : fallback;
|
|
112
|
+
}
|
|
113
|
+
var EXCEL_EPOCH = Date.UTC(1899, 11, 30);
|
|
114
|
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
115
|
+
function formatCellValue(v, pattern) {
|
|
116
|
+
if (v === null || v === void 0) return "";
|
|
117
|
+
if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
|
|
118
|
+
if (typeof v !== "number" || !pattern || pattern === "General") return String(v);
|
|
119
|
+
const p = pattern.toLowerCase();
|
|
120
|
+
if (/[dy]/.test(p) && !p.includes("$")) {
|
|
121
|
+
const d = new Date(EXCEL_EPOCH + Math.round(v) * 864e5);
|
|
122
|
+
const mm = d.getUTCMonth();
|
|
123
|
+
const dd = d.getUTCDate();
|
|
124
|
+
const yy = d.getUTCFullYear();
|
|
125
|
+
if (p.includes("mmm")) return `${MONTHS[mm]} ${dd}${p.includes("y") ? `, ${yy}` : ""}`;
|
|
126
|
+
return p.includes("y") ? `${mm + 1}/${dd}/${yy}` : `${mm + 1}/${dd}`;
|
|
127
|
+
}
|
|
128
|
+
const decimals = (_nullishCoalesce(_optionalChain([pattern, 'access', _31 => _31.split, 'call', _32 => _32("."), 'access', _33 => _33[1], 'optionalAccess', _34 => _34.match, 'call', _35 => _35(/0/g)]), () => ( []))).length;
|
|
129
|
+
if (p.includes("%")) return `${(v * 100).toFixed(decimals)}%`;
|
|
130
|
+
const grouped = Math.abs(v).toLocaleString("en-US", {
|
|
131
|
+
minimumFractionDigits: decimals,
|
|
132
|
+
maximumFractionDigits: decimals,
|
|
133
|
+
useGrouping: pattern.includes(",")
|
|
134
|
+
});
|
|
135
|
+
const sign = v < 0 ? "-" : "";
|
|
136
|
+
return p.includes("$") ? `${sign}$${grouped}` : `${sign}${grouped}`;
|
|
137
|
+
}
|
|
138
|
+
function parseResource(wb, name) {
|
|
139
|
+
const res = _optionalChain([wb, 'access', _36 => _36.resources, 'optionalAccess', _37 => _37.find, 'call', _38 => _38((r) => r.name === name)]);
|
|
140
|
+
if (!_optionalChain([res, 'optionalAccess', _39 => _39.data])) return null;
|
|
141
|
+
try {
|
|
142
|
+
return JSON.parse(res.data);
|
|
143
|
+
} catch (e2) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function cfMatch(rule, v) {
|
|
148
|
+
if (rule.type !== "highlightCell") return false;
|
|
149
|
+
if (rule.subType === "number" && typeof v === "number") {
|
|
150
|
+
const x = rule.value;
|
|
151
|
+
const [a = 0, b = 0] = Array.isArray(x) ? x : [Number(x), Number(x)];
|
|
152
|
+
switch (rule.operator) {
|
|
153
|
+
case "greaterThan":
|
|
154
|
+
return v > a;
|
|
155
|
+
case "greaterThanOrEqual":
|
|
156
|
+
return v >= a;
|
|
157
|
+
case "lessThan":
|
|
158
|
+
return v < a;
|
|
159
|
+
case "lessThanOrEqual":
|
|
160
|
+
return v <= a;
|
|
161
|
+
case "equal":
|
|
162
|
+
return v === a;
|
|
163
|
+
case "notEqual":
|
|
164
|
+
return v !== a;
|
|
165
|
+
case "between":
|
|
166
|
+
return v >= a && v <= b;
|
|
167
|
+
default:
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (rule.subType === "text" && v !== void 0 && v !== null) {
|
|
172
|
+
const s = String(v).toLowerCase();
|
|
173
|
+
const want = String(_nullishCoalesce(rule.value, () => ( ""))).toLowerCase();
|
|
174
|
+
switch (rule.operator) {
|
|
175
|
+
case "containsText":
|
|
176
|
+
return s.includes(want);
|
|
177
|
+
case "equal":
|
|
178
|
+
return s === want;
|
|
179
|
+
case "beginsWith":
|
|
180
|
+
return s.startsWith(want);
|
|
181
|
+
default:
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
function workbookPreviewSvg(snapshot) {
|
|
188
|
+
const wb = _nullishCoalesce(snapshot, () => ( {}));
|
|
189
|
+
const firstId = _nullishCoalesce(_optionalChain([wb, 'access', _40 => _40.sheetOrder, 'optionalAccess', _41 => _41[0]]), () => ( Object.keys(_nullishCoalesce(wb.sheets, () => ( {})))[0]));
|
|
190
|
+
const sheet = firstId && _optionalChain([wb, 'access', _42 => _42.sheets, 'optionalAccess', _43 => _43[firstId]]) || {};
|
|
191
|
+
const sheetId = _nullishCoalesce(_nullishCoalesce(sheet.id, () => ( firstId)), () => ( ""));
|
|
192
|
+
const styles = _nullishCoalesce(wb.styles, () => ( {}));
|
|
193
|
+
const cfAll = parseResource(wb, "SHEET_CONDITIONAL_FORMATTING_PLUGIN");
|
|
194
|
+
const cf = (_nullishCoalesce(_optionalChain([cfAll, 'optionalAccess', _44 => _44[sheetId]]), () => ( []))).filter((r) => r.rule && r.ranges);
|
|
195
|
+
const dvAll = parseResource(
|
|
196
|
+
wb,
|
|
197
|
+
"SHEET_DATA_VALIDATION_PLUGIN"
|
|
198
|
+
);
|
|
199
|
+
const checkboxRanges = (_nullishCoalesce(_optionalChain([dvAll, 'optionalAccess', _45 => _45[sheetId]]), () => ( []))).filter((d) => d.type === "checkbox").flatMap((d) => _nullishCoalesce(d.ranges, () => ( [])));
|
|
200
|
+
const inRanges = (rs, r, c) => (_nullishCoalesce(rs, () => ( []))).some((x) => r >= x.startRow && r <= x.endRow && c >= x.startColumn && c <= x.endColumn);
|
|
201
|
+
const dcw = _nullishCoalesce(sheet.defaultColumnWidth, () => ( 88));
|
|
202
|
+
const drh = _nullishCoalesce(sheet.defaultRowHeight, () => ( 24));
|
|
203
|
+
const colW = (c) => _optionalChain([sheet, 'access', _46 => _46.columnData, 'optionalAccess', _47 => _47[c], 'optionalAccess', _48 => _48.hd]) ? 0 : _nullishCoalesce(_optionalChain([sheet, 'access', _49 => _49.columnData, 'optionalAccess', _50 => _50[c], 'optionalAccess', _51 => _51.w]), () => ( dcw));
|
|
204
|
+
const rowH = (r) => _optionalChain([sheet, 'access', _52 => _52.rowData, 'optionalAccess', _53 => _53[r], 'optionalAccess', _54 => _54.hd]) ? 0 : _nullishCoalesce(_optionalChain([sheet, 'access', _55 => _55.rowData, 'optionalAccess', _56 => _56[r], 'optionalAccess', _57 => _57.h]), () => ( drh));
|
|
205
|
+
let maxCol = 0;
|
|
206
|
+
for (const row of Object.values(_nullishCoalesce(sheet.cellData, () => ( {})))) {
|
|
207
|
+
for (const c of Object.keys(_nullishCoalesce(row, () => ( {})))) maxCol = Math.max(maxCol, Number(c));
|
|
208
|
+
}
|
|
209
|
+
let used = 0;
|
|
210
|
+
for (let c = 0; c <= maxCol; c++) used += colW(c);
|
|
211
|
+
const span = Math.min(Math.max(used + 12, dcw * 5), 640);
|
|
212
|
+
const scale = THUMB_WIDTH / span;
|
|
213
|
+
const out = [];
|
|
214
|
+
out.push(`<rect width="${THUMB_WIDTH}" height="${THUMB_HEIGHT}" fill="#ffffff"/>`);
|
|
215
|
+
const gridOn = sheet.showGridlines !== 0;
|
|
216
|
+
const merges = _nullishCoalesce(sheet.mergeData, () => ( []));
|
|
217
|
+
const covered = /* @__PURE__ */ new Set();
|
|
218
|
+
for (const m of merges) {
|
|
219
|
+
for (let r = m.startRow; r <= m.endRow; r++)
|
|
220
|
+
for (let c = m.startColumn; c <= m.endColumn; c++)
|
|
221
|
+
if (r !== m.startRow || c !== m.startColumn) covered.add(`${r}:${c}`);
|
|
222
|
+
}
|
|
223
|
+
const texts = [];
|
|
224
|
+
let y = 0;
|
|
225
|
+
for (let r = 0; y * scale < THUMB_HEIGHT && r < 400; r++) {
|
|
226
|
+
const h = rowH(r);
|
|
227
|
+
let x = 0;
|
|
228
|
+
for (let c = 0; x * scale < THUMB_WIDTH && c < 60; c++) {
|
|
229
|
+
const w = colW(c);
|
|
230
|
+
if (w === 0 || h === 0 || covered.has(`${r}:${c}`)) {
|
|
231
|
+
x += w;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const m = merges.find((mm) => mm.startRow === r && mm.startColumn === c);
|
|
235
|
+
let cw = w;
|
|
236
|
+
let ch = h;
|
|
237
|
+
if (m) {
|
|
238
|
+
cw = 0;
|
|
239
|
+
for (let k = m.startColumn; k <= m.endColumn; k++) cw += colW(k);
|
|
240
|
+
ch = 0;
|
|
241
|
+
for (let k = m.startRow; k <= m.endRow; k++) ch += rowH(k);
|
|
242
|
+
}
|
|
243
|
+
const cell = _optionalChain([sheet, 'access', _58 => _58.cellData, 'optionalAccess', _59 => _59[r], 'optionalAccess', _60 => _60[c]]);
|
|
244
|
+
const base = _nullishCoalesce((typeof _optionalChain([cell, 'optionalAccess', _61 => _61.s]) === "string" ? styles[cell.s] : _optionalChain([cell, 'optionalAccess', _62 => _62.s])), () => ( {}));
|
|
245
|
+
let st = base;
|
|
246
|
+
for (const rule of cf) {
|
|
247
|
+
if (inRanges(rule.ranges, r, c) && rule.rule && cfMatch(rule.rule, _optionalChain([cell, 'optionalAccess', _63 => _63.v]))) {
|
|
248
|
+
st = { ...st, ...rule.rule.style };
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const X = x * scale;
|
|
253
|
+
const Y = y * scale;
|
|
254
|
+
const W = cw * scale;
|
|
255
|
+
const H = ch * scale;
|
|
256
|
+
const bg = _optionalChain([st, 'access', _64 => _64.bg, 'optionalAccess', _65 => _65.rgb]);
|
|
257
|
+
if (bg) out.push(`<rect x="${X.toFixed(1)}" y="${Y.toFixed(1)}" width="${W.toFixed(1)}" height="${H.toFixed(1)}" fill="${esc(bg)}"/>`);
|
|
258
|
+
if (gridOn) out.push(`<rect x="${X.toFixed(1)}" y="${Y.toFixed(1)}" width="${W.toFixed(1)}" height="${H.toFixed(1)}" fill="none" stroke="#e2e3e3" stroke-width="0.5"/>`);
|
|
259
|
+
const fs = Math.max((_nullishCoalesce(st.fs, () => ( 10))) * 1.333 * scale, 3);
|
|
260
|
+
const midY = Y + H / 2 + fs * 0.35;
|
|
261
|
+
if (inRanges(checkboxRanges, r, c) && r > 0 && (_optionalChain([cell, 'optionalAccess', _66 => _66.v]) === true || _optionalChain([cell, 'optionalAccess', _67 => _67.v]) === false || _optionalChain([cell, 'optionalAccess', _68 => _68.v]) === 1 || _optionalChain([cell, 'optionalAccess', _69 => _69.v]) === 0 || _optionalChain([cell, 'optionalAccess', _70 => _70.v]) === "TRUE" || _optionalChain([cell, 'optionalAccess', _71 => _71.v]) === "FALSE")) {
|
|
262
|
+
const box = Math.min(H * 0.55, 9);
|
|
263
|
+
const bx = X + W / 2 - box / 2;
|
|
264
|
+
const by = Y + H / 2 - box / 2;
|
|
265
|
+
const on = _optionalChain([cell, 'optionalAccess', _72 => _72.v]) === true || _optionalChain([cell, 'optionalAccess', _73 => _73.v]) === 1 || _optionalChain([cell, 'optionalAccess', _74 => _74.v]) === "TRUE";
|
|
266
|
+
out.push(`<rect x="${bx.toFixed(1)}" y="${by.toFixed(1)}" width="${box.toFixed(1)}" height="${box.toFixed(1)}" rx="1" fill="${on ? "#1a73e8" : "#ffffff"}" stroke="${on ? "#1a73e8" : "#5f6368"}" stroke-width="0.7"/>`);
|
|
267
|
+
if (on) out.push(`<path d="M${(bx + box * 0.2).toFixed(1)} ${(by + box * 0.5).toFixed(1)} l${(box * 0.25).toFixed(1)} ${(box * 0.25).toFixed(1)} l${(box * 0.4).toFixed(1)} ${(-box * 0.45).toFixed(1)}" stroke="#fff" stroke-width="0.9" fill="none"/>`);
|
|
268
|
+
} else if (cell && cell.v !== void 0 && cell.v !== null && cell.v !== "") {
|
|
269
|
+
const text = formatCellValue(cell.v, _optionalChain([st, 'access', _75 => _75.n, 'optionalAccess', _76 => _76.pattern]));
|
|
270
|
+
const numeric = typeof cell.v === "number";
|
|
271
|
+
const ht = _nullishCoalesce(st.ht, () => ( (numeric ? 3 : 1)));
|
|
272
|
+
const anchor = ht === 2 ? "middle" : ht === 3 ? "end" : "start";
|
|
273
|
+
const tx = ht === 2 ? X + W / 2 : ht === 3 ? X + W - 2 * scale * 2 : X + 3 * scale;
|
|
274
|
+
const maxChars = Math.max(Math.floor((m ? W : W * (ht === 1 && !numeric ? 3 : 1)) / (fs * 0.55)), 1);
|
|
275
|
+
const shown = text.length > maxChars ? text.slice(0, maxChars) : text;
|
|
276
|
+
texts.push(
|
|
277
|
+
`<text x="${tx.toFixed(1)}" y="${midY.toFixed(1)}" font-size="${fs.toFixed(1)}" text-anchor="${anchor}" fill="${esc(color(st.cl, "#202124"))}"${st.bl ? ' font-weight="700"' : ""}${st.it ? ' font-style="italic"' : ""}>${esc(shown)}</text>`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
x += w;
|
|
281
|
+
}
|
|
282
|
+
y += h;
|
|
283
|
+
}
|
|
284
|
+
return wrapSvg([...out, ...texts].join(""));
|
|
285
|
+
}
|
|
286
|
+
var CONTROL = /[\x1A\x1B\x1C\x1D\x0E\x0F\x1F\x1E\b]/g;
|
|
287
|
+
function documentPreviewSvg(snapshot) {
|
|
288
|
+
const doc = _nullishCoalesce(snapshot, () => ( {}));
|
|
289
|
+
const stream = _nullishCoalesce(_optionalChain([doc, 'access', _77 => _77.body, 'optionalAccess', _78 => _78.dataStream]), () => ( ""));
|
|
290
|
+
const pageW = _nullishCoalesce(_optionalChain([doc, 'access', _79 => _79.documentStyle, 'optionalAccess', _80 => _80.pageSize, 'optionalAccess', _81 => _81.width]), () => ( 595));
|
|
291
|
+
const scale = THUMB_WIDTH / pageW;
|
|
292
|
+
const ml = (_nullishCoalesce(_optionalChain([doc, 'access', _82 => _82.documentStyle, 'optionalAccess', _83 => _83.marginLeft]), () => ( 72))) * scale;
|
|
293
|
+
const mr = (_nullishCoalesce(_optionalChain([doc, 'access', _84 => _84.documentStyle, 'optionalAccess', _85 => _85.marginRight]), () => ( 72))) * scale;
|
|
294
|
+
const mt = (_nullishCoalesce(_optionalChain([doc, 'access', _86 => _86.documentStyle, 'optionalAccess', _87 => _87.marginTop]), () => ( 72))) * scale;
|
|
295
|
+
const contentW = THUMB_WIDTH - ml - mr;
|
|
296
|
+
const runs = [..._nullishCoalesce(_optionalChain([doc, 'access', _88 => _88.body, 'optionalAccess', _89 => _89.textRuns]), () => ( []))].sort((a, b) => a.st - b.st);
|
|
297
|
+
const tables = _nullishCoalesce(_optionalChain([doc, 'access', _90 => _90.body, 'optionalAccess', _91 => _91.tables]), () => ( []));
|
|
298
|
+
const styleAt = (i) => _nullishCoalesce(_optionalChain([runs, 'access', _92 => _92.find, 'call', _93 => _93((r) => i >= r.st && i < r.ed), 'optionalAccess', _94 => _94.ts]), () => ( {}));
|
|
299
|
+
const dominantStyle = (from, to) => {
|
|
300
|
+
const counts = /* @__PURE__ */ new Map();
|
|
301
|
+
for (let i = from; i < to; i++) {
|
|
302
|
+
if (/\s/.test(_nullishCoalesce(stream[i], () => ( "")))) continue;
|
|
303
|
+
const ts = styleAt(i);
|
|
304
|
+
const k = JSON.stringify(ts);
|
|
305
|
+
const e = _nullishCoalesce(counts.get(k), () => ( { n: 0, ts }));
|
|
306
|
+
e.n++;
|
|
307
|
+
counts.set(k, e);
|
|
308
|
+
}
|
|
309
|
+
let best = null;
|
|
310
|
+
for (const e of counts.values()) if (!best || e.n > best.n) best = e;
|
|
311
|
+
return _nullishCoalesce(_optionalChain([best, 'optionalAccess', _95 => _95.ts]), () => ( {}));
|
|
312
|
+
};
|
|
313
|
+
const out = [`<rect width="${THUMB_WIDTH}" height="${THUMB_HEIGHT}" fill="#ffffff"/>`];
|
|
314
|
+
let y = mt;
|
|
315
|
+
let start = 0;
|
|
316
|
+
const paragraphs = _nullishCoalesce(_optionalChain([doc, 'access', _96 => _96.body, 'optionalAccess', _97 => _97.paragraphs]), () => ( []));
|
|
317
|
+
for (let p = 0; p < paragraphs.length && y < THUMB_HEIGHT; p++) {
|
|
318
|
+
const para = paragraphs[p];
|
|
319
|
+
if (!para) break;
|
|
320
|
+
const end = para.startIndex;
|
|
321
|
+
const table = tables.find((t) => start >= t.startIndex && start < t.endIndex);
|
|
322
|
+
if (table) {
|
|
323
|
+
const raw = stream.slice(table.startIndex, table.endIndex);
|
|
324
|
+
const rows = raw.split("\x1B").slice(1).map(
|
|
325
|
+
(row) => row.split("").slice(1).map((cell) => cell.replace(/[\r\n]/g, " ").replace(CONTROL, "").trim())
|
|
326
|
+
);
|
|
327
|
+
const cols = Math.max(1, ...rows.map((r) => r.length));
|
|
328
|
+
const cw = contentW / cols;
|
|
329
|
+
const headerBold = styleAt(table.startIndex + 4).bl === 1;
|
|
330
|
+
for (let r = 0; r < rows.length && y < THUMB_HEIGHT; r++) {
|
|
331
|
+
const rh = 16 * scale * 1.2 + 6 * scale;
|
|
332
|
+
for (let c = 0; c < cols; c++) {
|
|
333
|
+
const cx = ml + c * cw;
|
|
334
|
+
out.push(`<rect x="${cx.toFixed(1)}" y="${y.toFixed(1)}" width="${cw.toFixed(1)}" height="${rh.toFixed(1)}" fill="${r === 0 && headerBold ? "#f1f3f4" : "none"}" stroke="#9aa0a6" stroke-width="0.4"/>`);
|
|
335
|
+
const fs2 = 11 * 1.333 * scale;
|
|
336
|
+
const maxChars = Math.max(Math.floor((cw - 6 * scale) / (fs2 * 0.5)), 1);
|
|
337
|
+
const t = _nullishCoalesce(_optionalChain([rows, 'access', _98 => _98[r], 'optionalAccess', _99 => _99[c]]), () => ( ""));
|
|
338
|
+
out.push(`<text x="${(cx + 4 * scale).toFixed(1)}" y="${(y + rh / 2 + fs2 * 0.35).toFixed(1)}" font-size="${fs2.toFixed(1)}" fill="#202124"${r === 0 && headerBold ? ' font-weight="700"' : ""}>${esc(t.slice(0, maxChars))}</text>`);
|
|
339
|
+
}
|
|
340
|
+
y += rh;
|
|
341
|
+
}
|
|
342
|
+
while (p + 1 < paragraphs.length && (_nullishCoalesce(_optionalChain([paragraphs, 'access', _100 => _100[p + 1], 'optionalAccess', _101 => _101.startIndex]), () => ( Infinity))) < table.endIndex) p++;
|
|
343
|
+
start = table.endIndex;
|
|
344
|
+
y += 6 * scale;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const text = stream.slice(start, end).replace(CONTROL, "");
|
|
348
|
+
const st = dominantStyle(start, end);
|
|
349
|
+
const ps = _nullishCoalesce(para.paragraphStyle, () => ( {}));
|
|
350
|
+
const fsPt = _nullishCoalesce(st.fs, () => ( 11));
|
|
351
|
+
const fs = fsPt * 1.333 * scale;
|
|
352
|
+
const lineH = fs * 1.3;
|
|
353
|
+
y += (_nullishCoalesce(_optionalChain([ps, 'access', _102 => _102.spaceAbove, 'optionalAccess', _103 => _103.v]), () => ( (fsPt > 13 ? 8 : 0)))) * scale;
|
|
354
|
+
const align = _nullishCoalesce(ps.horizontalAlign, () => ( 1));
|
|
355
|
+
const anchor = align === 2 ? "middle" : align === 3 ? "end" : "start";
|
|
356
|
+
const tx = align === 2 ? ml + contentW / 2 : align === 3 ? ml + contentW : ml;
|
|
357
|
+
if (!text.trim()) {
|
|
358
|
+
y += lineH * 0.8;
|
|
359
|
+
} else {
|
|
360
|
+
const maxChars = Math.max(Math.floor(contentW / (fs * (st.bl ? 0.56 : 0.5))), 4);
|
|
361
|
+
const words = text.split(/\s+/);
|
|
362
|
+
const lines = [];
|
|
363
|
+
let line = "";
|
|
364
|
+
for (const w of words) {
|
|
365
|
+
if ((line + " " + w).trim().length > maxChars && line) {
|
|
366
|
+
lines.push(line);
|
|
367
|
+
line = w;
|
|
368
|
+
} else line = (line + " " + w).trim();
|
|
369
|
+
}
|
|
370
|
+
if (line) lines.push(line);
|
|
371
|
+
for (const l of lines) {
|
|
372
|
+
if (y > THUMB_HEIGHT) break;
|
|
373
|
+
y += lineH;
|
|
374
|
+
if (_optionalChain([st, 'access', _104 => _104.bg, 'optionalAccess', _105 => _105.rgb])) out.push(`<rect x="${ml.toFixed(1)}" y="${(y - fs).toFixed(1)}" width="${contentW.toFixed(1)}" height="${lineH.toFixed(1)}" fill="${esc(st.bg.rgb)}"/>`);
|
|
375
|
+
out.push(`<text x="${tx.toFixed(1)}" y="${y.toFixed(1)}" font-size="${fs.toFixed(1)}" text-anchor="${anchor}" fill="${esc(color(st.cl, "#202124"))}"${st.bl ? ' font-weight="700"' : ""}${st.it ? ' font-style="italic"' : ""}${st.ff && /serif|georgia|times|garamond/i.test(st.ff) && !/sans/i.test(st.ff) ? ' font-family="Georgia, serif"' : ""}>${esc(l)}</text>`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
y += (_nullishCoalesce(_optionalChain([ps, 'access', _106 => _106.spaceBelow, 'optionalAccess', _107 => _107.v]), () => ( 4))) * scale;
|
|
379
|
+
start = end + 1;
|
|
380
|
+
}
|
|
381
|
+
return wrapSvg(out.join(""));
|
|
382
|
+
}
|
|
383
|
+
function wrapSvg(body) {
|
|
384
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${THUMB_WIDTH}" height="${THUMB_HEIGHT}" viewBox="0 0 ${THUMB_WIDTH} ${THUMB_HEIGHT}" font-family="Arial, Helvetica, sans-serif">${body}</svg>`;
|
|
385
|
+
}
|
|
386
|
+
function snapshotPreviewSvg(kind, snapshot) {
|
|
387
|
+
return kind === "workbook" ? workbookPreviewSvg(snapshot) : documentPreviewSvg(snapshot);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/sheets/snapshot-grid.ts
|
|
391
|
+
var GRID_MAX_ROWS = 500;
|
|
392
|
+
var GRID_MAX_COLUMNS = 60;
|
|
393
|
+
var PT_TO_PX = 1.333;
|
|
394
|
+
var isCheckboxValue = (v) => v === true || v === false || v === 1 || v === 0 || v === "TRUE" || v === "FALSE";
|
|
395
|
+
var isOn = (v) => v === true || v === 1 || v === "TRUE";
|
|
396
|
+
function hasValue(cell) {
|
|
397
|
+
const v = _optionalChain([cell, 'optionalAccess', _108 => _108.v]);
|
|
398
|
+
return v !== void 0 && v !== null && v !== "";
|
|
399
|
+
}
|
|
400
|
+
function snapshotToGridSheets(snapshot) {
|
|
401
|
+
if (typeof snapshot !== "object" || snapshot === null) return [];
|
|
402
|
+
const wb = snapshot;
|
|
403
|
+
const sheets = _nullishCoalesce(wb.sheets, () => ( {}));
|
|
404
|
+
const order = (_nullishCoalesce(wb.sheetOrder, () => ( []))).filter((id) => sheets[id]);
|
|
405
|
+
const ids = order.length > 0 ? order : Object.keys(sheets);
|
|
406
|
+
const out = [];
|
|
407
|
+
for (const id of ids) {
|
|
408
|
+
const grid = sheetToGrid(wb, id, sheets[id]);
|
|
409
|
+
if (grid) out.push(grid);
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
function sheetToGrid(wb, id, sheet) {
|
|
414
|
+
if (sheet.hidden === 1) return null;
|
|
415
|
+
const cellData = _nullishCoalesce(sheet.cellData, () => ( {}));
|
|
416
|
+
let maxRow = -1;
|
|
417
|
+
let maxCol = -1;
|
|
418
|
+
for (const [rk, row] of Object.entries(cellData)) {
|
|
419
|
+
const r = Number(rk);
|
|
420
|
+
if (!Number.isInteger(r) || !row) continue;
|
|
421
|
+
for (const [ck, cell] of Object.entries(row)) {
|
|
422
|
+
const c = Number(ck);
|
|
423
|
+
if (!Number.isInteger(c) || !hasValue(cell)) continue;
|
|
424
|
+
if (r > maxRow) maxRow = r;
|
|
425
|
+
if (c > maxCol) maxCol = c;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (maxRow < 0 || maxCol < 0) return null;
|
|
429
|
+
const styles = _nullishCoalesce(wb.styles, () => ( {}));
|
|
430
|
+
const sheetId = _nullishCoalesce(sheet.id, () => ( id));
|
|
431
|
+
const cfAll = parseResource(wb, "SHEET_CONDITIONAL_FORMATTING_PLUGIN");
|
|
432
|
+
const cf = (_nullishCoalesce(_optionalChain([cfAll, 'optionalAccess', _109 => _109[sheetId]]), () => ( []))).filter((r) => r.rule && r.ranges);
|
|
433
|
+
const dvAll = parseResource(
|
|
434
|
+
wb,
|
|
435
|
+
"SHEET_DATA_VALIDATION_PLUGIN"
|
|
436
|
+
);
|
|
437
|
+
const checkboxRanges = (_nullishCoalesce(_optionalChain([dvAll, 'optionalAccess', _110 => _110[sheetId]]), () => ( []))).filter((d) => d.type === "checkbox").flatMap((d) => _nullishCoalesce(d.ranges, () => ( [])));
|
|
438
|
+
const inRanges = (rs, r, c) => (_nullishCoalesce(rs, () => ( []))).some((x) => r >= x.startRow && r <= x.endRow && c >= x.startColumn && c <= x.endColumn);
|
|
439
|
+
const dcw = _nullishCoalesce(sheet.defaultColumnWidth, () => ( 88));
|
|
440
|
+
const drh = _nullishCoalesce(sheet.defaultRowHeight, () => ( 24));
|
|
441
|
+
const lastCol = Math.min(maxCol, GRID_MAX_COLUMNS - 1);
|
|
442
|
+
const columns = [];
|
|
443
|
+
for (let c = 0; c <= lastCol; c += 1) {
|
|
444
|
+
const col = _optionalChain([sheet, 'access', _111 => _111.columnData, 'optionalAccess', _112 => _112[String(c)]]);
|
|
445
|
+
if (_optionalChain([col, 'optionalAccess', _113 => _113.hd]) === 1) continue;
|
|
446
|
+
columns.push({ index: c, width: _nullishCoalesce(_optionalChain([col, 'optionalAccess', _114 => _114.w]), () => ( dcw)) });
|
|
447
|
+
}
|
|
448
|
+
const merges = _nullishCoalesce(sheet.mergeData, () => ( []));
|
|
449
|
+
const covered = /* @__PURE__ */ new Set();
|
|
450
|
+
for (const m of merges) {
|
|
451
|
+
for (let r = m.startRow; r <= m.endRow; r += 1)
|
|
452
|
+
for (let c = m.startColumn; c <= m.endColumn; c += 1) if (r !== m.startRow || c !== m.startColumn) covered.add(`${r}:${c}`);
|
|
453
|
+
}
|
|
454
|
+
const rows = [];
|
|
455
|
+
const lastRow = Math.min(maxRow, GRID_MAX_ROWS - 1);
|
|
456
|
+
for (let r = 0; r <= lastRow; r += 1) {
|
|
457
|
+
const rd = _optionalChain([sheet, 'access', _115 => _115.rowData, 'optionalAccess', _116 => _116[String(r)]]);
|
|
458
|
+
if (_optionalChain([rd, 'optionalAccess', _117 => _117.hd]) === 1) continue;
|
|
459
|
+
const source = _nullishCoalesce(cellData[String(r)], () => ( {}));
|
|
460
|
+
const cells = columns.map(({ index: c }) => {
|
|
461
|
+
const cell = _nullishCoalesce(source[String(c)], () => ( void 0));
|
|
462
|
+
const base = _nullishCoalesce((typeof _optionalChain([cell, 'optionalAccess', _118 => _118.s]) === "string" ? styles[cell.s] : _optionalChain([cell, 'optionalAccess', _119 => _119.s])), () => ( {}));
|
|
463
|
+
let st = base;
|
|
464
|
+
for (const rule of cf) {
|
|
465
|
+
if (inRanges(rule.ranges, r, c) && rule.rule && cfMatch(rule.rule, _optionalChain([cell, 'optionalAccess', _120 => _120.v]))) {
|
|
466
|
+
st = { ...st, ...rule.rule.style };
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const m = merges.find((mm) => mm.startRow === r && mm.startColumn === c);
|
|
471
|
+
const v = _optionalChain([cell, 'optionalAccess', _121 => _121.v]);
|
|
472
|
+
const box = hasValue(cell) && inRanges(checkboxRanges, r, c) && isCheckboxValue(v);
|
|
473
|
+
const numeric = typeof v === "number";
|
|
474
|
+
const ht = _nullishCoalesce(st.ht, () => ( 0));
|
|
475
|
+
return {
|
|
476
|
+
text: box ? "" : hasValue(cell) ? formatCellValue(v, _optionalChain([st, 'access', _122 => _122.n, 'optionalAccess', _123 => _123.pattern])) : "",
|
|
477
|
+
checkbox: box ? { checked: isOn(v) } : void 0,
|
|
478
|
+
align: box || ht === 2 ? "center" : ht === 3 || ht === 0 && numeric ? "right" : "left",
|
|
479
|
+
bold: st.bl === 1,
|
|
480
|
+
italic: st.it === 1,
|
|
481
|
+
fontPx: Math.round((_nullishCoalesce(st.fs, () => ( 10))) * PT_TO_PX),
|
|
482
|
+
bg: _nullishCoalesce(_optionalChain([st, 'access', _124 => _124.bg, 'optionalAccess', _125 => _125.rgb]), () => ( void 0)),
|
|
483
|
+
color: _nullishCoalesce(_optionalChain([st, 'access', _126 => _126.cl, 'optionalAccess', _127 => _127.rgb]), () => ( void 0)),
|
|
484
|
+
wrap: st.tb === 3,
|
|
485
|
+
rowSpan: m ? m.endRow - m.startRow + 1 : 1,
|
|
486
|
+
colSpan: m ? m.endColumn - m.startColumn + 1 : 1,
|
|
487
|
+
covered: covered.has(`${r}:${c}`)
|
|
488
|
+
};
|
|
489
|
+
});
|
|
490
|
+
rows.push({ index: r, height: _nullishCoalesce(_optionalChain([rd, 'optionalAccess', _128 => _128.h]), () => ( drh)), cells });
|
|
491
|
+
}
|
|
492
|
+
const ySplit = _nullishCoalesce(_optionalChain([sheet, 'access', _129 => _129.freeze, 'optionalAccess', _130 => _130.ySplit]), () => ( 0));
|
|
493
|
+
const xSplit = _nullishCoalesce(_optionalChain([sheet, 'access', _131 => _131.freeze, 'optionalAccess', _132 => _132.xSplit]), () => ( 0));
|
|
494
|
+
return {
|
|
495
|
+
id: sheetId,
|
|
496
|
+
name: _nullishCoalesce(sheet.name, () => ( "Sheet1")),
|
|
497
|
+
columns,
|
|
498
|
+
rows,
|
|
499
|
+
frozenRows: Math.min(rows.filter((r) => r.index < ySplit).length, rows.length),
|
|
500
|
+
frozenColumns: Math.min(columns.filter((c) => c.index < xSplit).length, columns.length),
|
|
501
|
+
gridlines: sheet.showGridlines !== 0,
|
|
502
|
+
truncatedFrom: maxRow > lastRow ? maxRow + 1 : null
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/core/document-page-style.ts
|
|
507
|
+
var PX_PER_INCH = 96;
|
|
508
|
+
var PAPER_SIZES = {
|
|
509
|
+
Letter: { width: 816, height: 1056, label: "Letter (8.5 x 11 in)" },
|
|
510
|
+
Legal: { width: 816, height: 1344, label: "Legal (8.5 x 14 in)" },
|
|
511
|
+
Tabloid: { width: 1056, height: 1632, label: "Tabloid (11 x 17 in)" },
|
|
512
|
+
Executive: { width: 696, height: 1008, label: "Executive (7.25 x 10.5 in)" },
|
|
513
|
+
Statement: { width: 528, height: 816, label: "Statement (5.5 x 8.5 in)" },
|
|
514
|
+
A3: { width: 1123, height: 1587, label: "A3 (11.69 x 16.54 in)" },
|
|
515
|
+
A4: { width: 794, height: 1124, label: "A4 (8.27 x 11.69 in)" },
|
|
516
|
+
A5: { width: 559, height: 794, label: "A5 (5.83 x 8.27 in)" }
|
|
517
|
+
};
|
|
518
|
+
var PAGE_COLORS = ["#ffffff", "#fff8e7", "#f3f3f3", "#e8f0fe", "#e6f4ea", "#fef7e0"];
|
|
519
|
+
var DEFAULT_PAGE_COLOR = PAGE_COLORS[0];
|
|
520
|
+
|
|
521
|
+
// src/sheets/sheet-page-setup.ts
|
|
522
|
+
var SHEET_SCALES = ["normal", "width", "height", "page"];
|
|
523
|
+
var SHEET_MARGIN_PRESETS = ["normal", "narrow", "wide", "custom"];
|
|
524
|
+
var SHEET_PRINT_SCOPES = ["sheet", "workbook", "selection"];
|
|
525
|
+
var DEFAULT_SHEET_PAGE_SETUP = {
|
|
526
|
+
paper: "Letter",
|
|
527
|
+
orientation: "portrait",
|
|
528
|
+
scale: "normal",
|
|
529
|
+
margins: "normal",
|
|
530
|
+
customMargins: { top: 0.75, bottom: 0.75, left: 0.7, right: 0.7 },
|
|
531
|
+
scope: "sheet",
|
|
532
|
+
gridlines: true,
|
|
533
|
+
repeatFrozenRows: false,
|
|
534
|
+
repeatFrozenColumns: false,
|
|
535
|
+
pageOrder: "down-over",
|
|
536
|
+
alignH: "left",
|
|
537
|
+
alignV: "top"
|
|
538
|
+
};
|
|
539
|
+
var MARGIN_PRESET_INCHES = {
|
|
540
|
+
normal: { top: 0.75, bottom: 0.75, left: 0.7, right: 0.7 },
|
|
541
|
+
narrow: { top: 0.25, bottom: 0.25, left: 0.25, right: 0.25 },
|
|
542
|
+
wide: { top: 1, bottom: 1, left: 1, right: 1 }
|
|
543
|
+
};
|
|
544
|
+
var isPaper = (v) => typeof v === "string" && v in PAPER_SIZES;
|
|
545
|
+
var oneOf = (list, v, fallback) => typeof v === "string" && list.includes(v) ? v : fallback;
|
|
546
|
+
var inches = (v, fallback) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 5 ? v : fallback;
|
|
547
|
+
function normalizeSheetPageSetup(raw) {
|
|
548
|
+
const r = raw && typeof raw === "object" ? raw : {};
|
|
549
|
+
const m = r.customMargins && typeof r.customMargins === "object" ? r.customMargins : {};
|
|
550
|
+
const d = DEFAULT_SHEET_PAGE_SETUP;
|
|
551
|
+
return {
|
|
552
|
+
paper: isPaper(r.paper) ? r.paper : d.paper,
|
|
553
|
+
orientation: r.orientation === "landscape" ? "landscape" : "portrait",
|
|
554
|
+
scale: oneOf(SHEET_SCALES, r.scale, d.scale),
|
|
555
|
+
margins: oneOf(SHEET_MARGIN_PRESETS, r.margins, d.margins),
|
|
556
|
+
customMargins: {
|
|
557
|
+
top: inches(m.top, d.customMargins.top),
|
|
558
|
+
bottom: inches(m.bottom, d.customMargins.bottom),
|
|
559
|
+
left: inches(m.left, d.customMargins.left),
|
|
560
|
+
right: inches(m.right, d.customMargins.right)
|
|
561
|
+
},
|
|
562
|
+
scope: oneOf(SHEET_PRINT_SCOPES, r.scope, d.scope),
|
|
563
|
+
gridlines: typeof r.gridlines === "boolean" ? r.gridlines : d.gridlines,
|
|
564
|
+
repeatFrozenRows: r.repeatFrozenRows === true,
|
|
565
|
+
repeatFrozenColumns: r.repeatFrozenColumns === true,
|
|
566
|
+
pageOrder: r.pageOrder === "over-down" ? "over-down" : "down-over",
|
|
567
|
+
alignH: oneOf(["left", "center", "right"], r.alignH, d.alignH),
|
|
568
|
+
alignV: oneOf(["top", "middle", "bottom"], r.alignV, d.alignV)
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function pageSetupFromMetadata(metadata) {
|
|
572
|
+
return normalizeSheetPageSetup(_optionalChain([metadata, 'optionalAccess', _133 => _133.page_setup]));
|
|
573
|
+
}
|
|
574
|
+
function printGeometry(setup) {
|
|
575
|
+
const base = PAPER_SIZES[setup.paper];
|
|
576
|
+
const landscape = setup.orientation === "landscape";
|
|
577
|
+
const paperWidth = landscape ? base.height : base.width;
|
|
578
|
+
const paperHeight = landscape ? base.width : base.height;
|
|
579
|
+
const m = setup.margins === "custom" ? setup.customMargins : MARGIN_PRESET_INCHES[setup.margins];
|
|
580
|
+
const px = (n) => Math.round(n * PX_PER_INCH);
|
|
581
|
+
const geometry = {
|
|
582
|
+
paperWidth,
|
|
583
|
+
paperHeight,
|
|
584
|
+
marginTop: px(m.top),
|
|
585
|
+
marginBottom: px(m.bottom),
|
|
586
|
+
marginLeft: px(m.left),
|
|
587
|
+
marginRight: px(m.right)
|
|
588
|
+
};
|
|
589
|
+
return {
|
|
590
|
+
...geometry,
|
|
591
|
+
areaWidth: Math.max(48, paperWidth - geometry.marginLeft - geometry.marginRight),
|
|
592
|
+
areaHeight: Math.max(48, paperHeight - geometry.marginTop - geometry.marginBottom)
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
var PRINT_ROW_HEIGHT = 22;
|
|
596
|
+
var MIN_COL = 48;
|
|
597
|
+
var MAX_COL = 320;
|
|
598
|
+
var CHAR_PX = 7;
|
|
599
|
+
function printColumnWidths(rows) {
|
|
600
|
+
const width = rows.reduce((n, r) => Math.max(n, r.length), 0);
|
|
601
|
+
const out = [];
|
|
602
|
+
for (let c = 0; c < width; c += 1) {
|
|
603
|
+
let longest = 0;
|
|
604
|
+
for (const r of rows) longest = Math.max(longest, (_nullishCoalesce(r[c], () => ( ""))).length);
|
|
605
|
+
out.push(Math.min(MAX_COL, Math.max(MIN_COL, longest * CHAR_PX + 16)));
|
|
606
|
+
}
|
|
607
|
+
return out;
|
|
608
|
+
}
|
|
609
|
+
function bands(sizes, capacityPx, frozen, repeat) {
|
|
610
|
+
const total = sizes.length;
|
|
611
|
+
if (total === 0) return [];
|
|
612
|
+
const result = [];
|
|
613
|
+
const lead = repeat ? Math.min(frozen, total) : 0;
|
|
614
|
+
const leadPx = sizes.slice(0, lead).reduce((a, b) => a + b, 0);
|
|
615
|
+
let at = 0;
|
|
616
|
+
while (at < total) {
|
|
617
|
+
const first = result.length === 0;
|
|
618
|
+
const carry = !first && lead > 0 ? Array.from({ length: lead }, (_, i) => i) : [];
|
|
619
|
+
let used = first ? 0 : leadPx;
|
|
620
|
+
const band = [...carry];
|
|
621
|
+
if (!first && leadPx >= capacityPx) used = 0;
|
|
622
|
+
let added = 0;
|
|
623
|
+
while (at < total) {
|
|
624
|
+
const size = sizes[at];
|
|
625
|
+
if (used + size > capacityPx && added > 0) break;
|
|
626
|
+
band.push(at);
|
|
627
|
+
used += size;
|
|
628
|
+
added += 1;
|
|
629
|
+
at += 1;
|
|
630
|
+
}
|
|
631
|
+
result.push(band);
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
function planSheetPrint(rows, setup, frozen = { rows: 0, cols: 0 }) {
|
|
636
|
+
const geometry = printGeometry(setup);
|
|
637
|
+
const colWidths = printColumnWidths(rows);
|
|
638
|
+
const totalW = colWidths.reduce((a, b) => a + b, 0) || 1;
|
|
639
|
+
const totalH = rows.length * PRINT_ROW_HEIGHT || 1;
|
|
640
|
+
const fitW = geometry.areaWidth / totalW;
|
|
641
|
+
const fitH = geometry.areaHeight / totalH;
|
|
642
|
+
const scale = setup.scale === "width" ? Math.min(1, fitW) : setup.scale === "height" ? Math.min(1, fitH) : setup.scale === "page" ? Math.min(1, fitW, fitH) : 1;
|
|
643
|
+
const rowBands = bands(
|
|
644
|
+
rows.map(() => PRINT_ROW_HEIGHT),
|
|
645
|
+
geometry.areaHeight / scale,
|
|
646
|
+
frozen.rows,
|
|
647
|
+
setup.repeatFrozenRows
|
|
648
|
+
);
|
|
649
|
+
const colBands = bands(colWidths, geometry.areaWidth / scale, frozen.cols, setup.repeatFrozenColumns);
|
|
650
|
+
const pages = [];
|
|
651
|
+
if (setup.pageOrder === "down-over") {
|
|
652
|
+
for (const cols of colBands) for (const r of rowBands) pages.push({ rows: r, cols });
|
|
653
|
+
} else {
|
|
654
|
+
for (const r of rowBands) for (const cols of colBands) pages.push({ rows: r, cols });
|
|
655
|
+
}
|
|
656
|
+
return { scale, geometry, colWidths, pages };
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/sheets/sheet-page-setup-service.ts
|
|
660
|
+
var _db = require('@ai-matrx/data/db');
|
|
661
|
+
var db = () => _chunkZDZCCOUBcjs.getSheetsHost.call(void 0, ).getSupabase();
|
|
662
|
+
async function readSheetPageSetup(workbookId) {
|
|
663
|
+
const { data, error } = await db().schema("workbench").from("udt_workbooks").select("metadata").eq("id", workbookId).maybeSingle();
|
|
664
|
+
if (error) return { ok: false, error: error.message };
|
|
665
|
+
return { ok: true, data: pageSetupFromMetadata(_optionalChain([data, 'optionalAccess', _134 => _134.metadata])) };
|
|
666
|
+
}
|
|
667
|
+
async function writeSheetPageSetup(workbookId, setup) {
|
|
668
|
+
const clean = normalizeSheetPageSetup(setup);
|
|
669
|
+
const result = await _db.mergeJsonColumn.call(void 0, {
|
|
670
|
+
fetchCurrent: () => db().schema("workbench").from("udt_workbooks").select("id, version, metadata").eq("id", workbookId).maybeSingle(),
|
|
671
|
+
readColumn: (row) => row.metadata,
|
|
672
|
+
merge: (current2) => ({ ...current2, page_setup: clean }),
|
|
673
|
+
applyUpdate: ({ value, expectedVersion, nextVersion }) => db().schema("workbench").from("udt_workbooks").update({ metadata: value, version: nextVersion }).eq("id", workbookId).eq("version", expectedVersion).select("id, version, metadata").maybeSingle()
|
|
674
|
+
});
|
|
675
|
+
if (result.status === "saved") return { ok: true, data: pageSetupFromMetadata(result.row.metadata) };
|
|
676
|
+
if (result.status === "not_found") return { ok: false, error: "This workbook could not be found" };
|
|
677
|
+
if (result.status === "conflict") return { ok: false, error: "The workbook changed while saving; try again" };
|
|
678
|
+
const reason = result.error;
|
|
679
|
+
return { ok: false, error: reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Something went wrong" };
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/sheets/sheet-print-pages.ts
|
|
683
|
+
function collectPrintSheets(snapshot, setup, options) {
|
|
684
|
+
const read = (sheetId, range) => {
|
|
685
|
+
const grid = univerSnapshotToRows(snapshot, { skipHidden: true, ...sheetId ? { sheetId } : {}, ...range ? { range } : {} });
|
|
686
|
+
if (!grid || grid.rows.length === 0) return null;
|
|
687
|
+
return { name: grid.sheetName, rows: grid.rows, frozenRows: grid.frozenRows, frozenCols: grid.frozenCols };
|
|
688
|
+
};
|
|
689
|
+
if (setup.scope === "workbook") {
|
|
690
|
+
return univerSheetIds(snapshot).map((id) => read(id)).filter((s) => s !== null);
|
|
691
|
+
}
|
|
692
|
+
if (setup.scope === "selection") {
|
|
693
|
+
const sel = options.selection;
|
|
694
|
+
if (!sel || sel.startRow === sel.endRow && sel.startColumn === sel.endColumn) return [];
|
|
695
|
+
const one2 = read(options.sheetId, sel);
|
|
696
|
+
return one2 ? [one2] : [];
|
|
697
|
+
}
|
|
698
|
+
const one = read(options.sheetId);
|
|
699
|
+
return one ? [one] : [];
|
|
700
|
+
}
|
|
701
|
+
var esc2 = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
702
|
+
var JUSTIFY = { left: "flex-start", center: "center", right: "flex-end" };
|
|
703
|
+
var ALIGN = { top: "flex-start", middle: "center", bottom: "flex-end" };
|
|
704
|
+
function pageHtml(sheet, page, scale, colWidths, g, setup, numbering) {
|
|
705
|
+
const widths = page.cols.map((c) => _nullishCoalesce(colWidths[c], () => ( 0)));
|
|
706
|
+
const tableW = widths.reduce((a, b) => a + b, 0);
|
|
707
|
+
const tableH = page.rows.length * PRINT_ROW_HEIGHT;
|
|
708
|
+
const border = setup.gridlines ? "1px solid #b7b7b7" : "none";
|
|
709
|
+
const body = page.rows.map(
|
|
710
|
+
(r) => `<tr style="height:${PRINT_ROW_HEIGHT}px">${page.cols.map((c) => `<td style="border:${border}">${esc2(_nullishCoalesce(_optionalChain([sheet, 'access', _135 => _135.rows, 'access', _136 => _136[r], 'optionalAccess', _137 => _137[c]]), () => ( "")))}</td>`).join("")}</tr>`
|
|
711
|
+
).join("");
|
|
712
|
+
const cols = widths.map((w) => `<col style="width:${w}px">`).join("");
|
|
713
|
+
return `<section data-print-page data-sheet="${esc2(numbering.sheet)}" data-page-number="${numbering.at}" data-page-count="${numbering.of}" data-page-rows="${page.rows.length}" data-page-cols="${page.cols.length}" style="width:${g.paperWidth}px;height:${g.paperHeight}px;box-sizing:border-box;padding:${g.marginTop}px ${g.marginRight}px ${g.marginBottom}px ${g.marginLeft}px;background:#fff;overflow:hidden;break-after:page;page-break-after:always">
|
|
714
|
+
<div style="width:${g.areaWidth}px;height:${g.areaHeight}px;display:flex;justify-content:${JUSTIFY[setup.alignH]};align-items:${ALIGN[setup.alignV]};overflow:hidden">
|
|
715
|
+
<div data-print-content style="width:${tableW * scale}px;height:${tableH * scale}px;flex:none;overflow:hidden">
|
|
716
|
+
<table style="width:${tableW}px;table-layout:fixed;border-collapse:collapse;transform:scale(${scale});transform-origin:0 0;font:12px/${PRINT_ROW_HEIGHT - 2}px system-ui,sans-serif;color:#111"><colgroup>${cols}</colgroup><tbody>${body}</tbody></table>
|
|
717
|
+
</div></div></section>`;
|
|
718
|
+
}
|
|
719
|
+
function buildPrintDocument(sheets, setup) {
|
|
720
|
+
const out = [];
|
|
721
|
+
let geometry = null;
|
|
722
|
+
for (const sheet of sheets) {
|
|
723
|
+
const plan = planSheetPrint(sheet.rows, setup, { rows: sheet.frozenRows, cols: sheet.frozenCols });
|
|
724
|
+
geometry = plan.geometry;
|
|
725
|
+
plan.pages.forEach((page, i) => {
|
|
726
|
+
out.push(pageHtml(sheet, page, plan.scale, plan.colWidths, plan.geometry, setup, { sheet: sheet.name, at: i + 1, of: plan.pages.length }));
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
if (!geometry || out.length === 0) return null;
|
|
730
|
+
return {
|
|
731
|
+
pagesHtml: out,
|
|
732
|
+
pageWidth: geometry.paperWidth,
|
|
733
|
+
pageHeight: geometry.paperHeight,
|
|
734
|
+
pageSizeInches: { width: geometry.paperWidth / PX_PER_INCH, height: geometry.paperHeight / PX_PER_INCH }
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
function printDocumentHtml(doc, title) {
|
|
738
|
+
const { width, height } = doc.pageSizeInches;
|
|
739
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>${esc2(title)}</title>
|
|
740
|
+
<style>@page{size:${width.toFixed(3)}in ${height.toFixed(3)}in;margin:0}html,body{margin:0;padding:0;background:#fff}td{padding:0 6px;overflow:hidden;white-space:nowrap;text-overflow:clip;vertical-align:middle}section:last-child{break-after:auto;page-break-after:auto}</style></head>
|
|
741
|
+
<body data-print-paper="${width.toFixed(3)}x${height.toFixed(3)}in">${doc.pagesHtml.join("\n")}</body></html>`;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// src/sheets/sheet-output.ts
|
|
745
|
+
var _download = require('@ai-matrx/kit/download');
|
|
746
|
+
var _read = require('@ai-matrx/alchemy/operate/read');
|
|
747
|
+
function rowsToCsv(rows) {
|
|
748
|
+
const [header, ...body] = rows;
|
|
749
|
+
if (!header) return "";
|
|
750
|
+
return _read.toDelimitedText.call(void 0, header, body, { spreadsheetSafe: false });
|
|
751
|
+
}
|
|
752
|
+
function downloadSheetAsCsv(snapshot, options) {
|
|
753
|
+
const grid = univerSnapshotToRows(snapshot, { skipHidden: true, ...options.sheetId ? { sheetId: options.sheetId } : {} });
|
|
754
|
+
if (!grid || grid.rows.length === 0) return false;
|
|
755
|
+
const name = `${options.filename.replace(/\.csv$/i, "")}.csv`;
|
|
756
|
+
const blob = new Blob(["\uFEFF", rowsToCsv(grid.rows)], { type: "text/csv;charset=utf-8" });
|
|
757
|
+
_download.downloadFile.call(void 0, name, blob, blob.type);
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
function downloadSheetAsTsv(snapshot, options) {
|
|
761
|
+
const grid = univerSnapshotToRows(snapshot, { skipHidden: true, ...options.sheetId ? { sheetId: options.sheetId } : {} });
|
|
762
|
+
if (!grid || grid.rows.length === 0) return false;
|
|
763
|
+
const [header, ...body] = grid.rows;
|
|
764
|
+
const text = _read.toDelimitedText.call(void 0, header, body, { format: "tsv", spreadsheetSafe: false });
|
|
765
|
+
const blob = new Blob(["\uFEFF", text], { type: "text/tab-separated-values;charset=utf-8" });
|
|
766
|
+
_download.downloadFile.call(void 0, `${options.filename.replace(/\.tsv$/i, "")}.tsv`, blob, blob.type);
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
function downloadSheetAsHtml(snapshot, options) {
|
|
770
|
+
const grid = univerSnapshotToRows(snapshot, { skipHidden: true, ...options.sheetId ? { sheetId: options.sheetId } : {} });
|
|
771
|
+
if (!grid || grid.rows.length === 0) return false;
|
|
772
|
+
const body = grid.rows.map((r) => `<tr>${r.map((c) => `<td>${esc3(c)}</td>`).join("")}</tr>`).join("\n");
|
|
773
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><title>${esc3(options.filename)} \u2014 ${esc3(grid.sheetName)}</title>
|
|
774
|
+
<style>body{font:13px system-ui,sans-serif;margin:16px}table{border-collapse:collapse}td{border:1px solid #c0c0c0;padding:2px 6px;vertical-align:top}</style></head>
|
|
775
|
+
<body><table>
|
|
776
|
+
${body}
|
|
777
|
+
</table></body></html>`;
|
|
778
|
+
const blob = new Blob([html], { type: "text/html;charset=utf-8" });
|
|
779
|
+
_download.downloadFile.call(void 0, `${options.filename.replace(/\.html?$/i, "")}.html`, blob, blob.type);
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
function esc3(s) {
|
|
783
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
784
|
+
}
|
|
785
|
+
function printDocumentFor(snapshot, options) {
|
|
786
|
+
const sheets = collectPrintSheets(snapshot, options.setup, {
|
|
787
|
+
...options.sheetId ? { sheetId: options.sheetId } : {},
|
|
788
|
+
selection: _nullishCoalesce(options.selection, () => ( null))
|
|
789
|
+
});
|
|
790
|
+
return buildPrintDocument(sheets, options.setup);
|
|
791
|
+
}
|
|
792
|
+
function printSheet(snapshot, options) {
|
|
793
|
+
const doc = printDocumentFor(snapshot, options);
|
|
794
|
+
if (!doc) return false;
|
|
795
|
+
const html = printDocumentHtml(doc, options.title);
|
|
796
|
+
const frame = document.createElement("iframe");
|
|
797
|
+
frame.style.cssText = "position:fixed;right:0;bottom:0;width:0;height:0;border:0";
|
|
798
|
+
document.body.appendChild(frame);
|
|
799
|
+
const fdoc = frame.contentDocument;
|
|
800
|
+
const win = frame.contentWindow;
|
|
801
|
+
if (!fdoc || !win) {
|
|
802
|
+
frame.remove();
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
fdoc.open();
|
|
806
|
+
fdoc.write(html);
|
|
807
|
+
fdoc.close();
|
|
808
|
+
win.addEventListener("afterprint", () => frame.remove());
|
|
809
|
+
win.focus();
|
|
810
|
+
win.print();
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
function rowsToMarkdownTable(rows) {
|
|
814
|
+
if (rows.length === 0) return "";
|
|
815
|
+
const width = Math.max(...rows.map((r) => r.length));
|
|
816
|
+
const cell = (v) => (_nullishCoalesce(v, () => ( ""))).replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
817
|
+
const line = (r) => `| ${Array.from({ length: width }, (_, i) => cell(r[i])).join(" | ")} |`;
|
|
818
|
+
const [head, ...rest] = rows;
|
|
819
|
+
return [line(head), `| ${Array.from({ length: width }, () => "---").join(" | ")} |`, ...rest.map(line)].join("\n");
|
|
820
|
+
}
|
|
821
|
+
async function downloadSheetAsPdf(snapshot, options) {
|
|
822
|
+
const doc = printDocumentFor(snapshot, options);
|
|
823
|
+
if (!doc) return false;
|
|
824
|
+
const [{ renderElement, pagesToPdf }, { downloadFile: save }] = await Promise.all([
|
|
825
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("@ai-matrx/alchemy/operate/capture"))),
|
|
826
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("@ai-matrx/kit/download")))
|
|
827
|
+
]);
|
|
828
|
+
const host = document.createElement("div");
|
|
829
|
+
host.setAttribute("aria-hidden", "true");
|
|
830
|
+
host.style.cssText = "position:fixed;left:-20000px;top:0";
|
|
831
|
+
host.innerHTML = `<style>td{padding:0 6px;overflow:hidden;white-space:nowrap;vertical-align:middle}</style>${doc.pagesHtml.join("")}`;
|
|
832
|
+
document.body.appendChild(host);
|
|
833
|
+
try {
|
|
834
|
+
const pages = [];
|
|
835
|
+
for (const el of Array.from(host.querySelectorAll("[data-print-page]"))) {
|
|
836
|
+
const image = await renderElement(el, { pixelRatio: 2, backgroundColor: "#ffffff", cacheBust: true });
|
|
837
|
+
pages.push({ image, imageType: "JPEG", quality: 0.92, placement: "fill" });
|
|
838
|
+
}
|
|
839
|
+
const mm = (px) => Math.round(px / PX_PER_INCH * 25.4 * 100) / 100;
|
|
840
|
+
const pdf = await pagesToPdf(pages, {
|
|
841
|
+
orientation: doc.pageWidth > doc.pageHeight ? "landscape" : "portrait",
|
|
842
|
+
unit: "mm",
|
|
843
|
+
format: [mm(Math.min(doc.pageWidth, doc.pageHeight)), mm(Math.max(doc.pageWidth, doc.pageHeight))]
|
|
844
|
+
});
|
|
845
|
+
save(`${options.title.replace(/[\\/:*?"<>|]+/g, " ").trim() || "workbook"}.pdf`, pdf, "application/pdf");
|
|
846
|
+
} finally {
|
|
847
|
+
host.remove();
|
|
848
|
+
}
|
|
849
|
+
return true;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/sheets/workbook-scope-source.ts
|
|
853
|
+
var current = null;
|
|
854
|
+
function registerWorkbookScopeSource(registration) {
|
|
855
|
+
current = registration;
|
|
856
|
+
return () => {
|
|
857
|
+
if (current === registration) current = null;
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
function readWorkbookScopeSource(workbookId) {
|
|
861
|
+
if (!current || current.workbookId !== workbookId) return null;
|
|
862
|
+
return current.read();
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
exports.DEFAULT_SHEET_PAGE_SETUP = DEFAULT_SHEET_PAGE_SETUP; exports.GRID_MAX_COLUMNS = GRID_MAX_COLUMNS; exports.GRID_MAX_ROWS = GRID_MAX_ROWS; exports.MARGIN_PRESET_INCHES = MARGIN_PRESET_INCHES; exports.PRINT_ROW_HEIGHT = PRINT_ROW_HEIGHT; exports.SHEET_MARGIN_PRESETS = SHEET_MARGIN_PRESETS; exports.SHEET_PRINT_SCOPES = SHEET_PRINT_SCOPES; exports.SHEET_SCALES = SHEET_SCALES; exports.THUMB_HEIGHT = THUMB_HEIGHT; exports.THUMB_WIDTH = THUMB_WIDTH; exports.buildPrintDocument = buildPrintDocument; exports.cfMatch = cfMatch; exports.collectPrintSheets = collectPrintSheets; exports.configureSheetsHost = _chunkZDZCCOUBcjs.configureSheetsHost; exports.copyWorkbook = _chunkZDZCCOUBcjs.copyWorkbook; exports.createWorkbook = _chunkZDZCCOUBcjs.createWorkbook; exports.deleteWorkbook = _chunkZDZCCOUBcjs.deleteWorkbook; exports.discardFailedWorkbook = _chunkZDZCCOUBcjs.discardFailedWorkbook; exports.documentPreviewSvg = documentPreviewSvg; exports.downloadSheetAsCsv = downloadSheetAsCsv; exports.downloadSheetAsHtml = downloadSheetAsHtml; exports.downloadSheetAsPdf = downloadSheetAsPdf; exports.downloadSheetAsTsv = downloadSheetAsTsv; exports.formatCellValue = formatCellValue; exports.getLatestSnapshot = _chunkZDZCCOUBcjs.getLatestSnapshot; exports.getSheetsHost = _chunkZDZCCOUBcjs.getSheetsHost; exports.getWorkbook = _chunkZDZCCOUBcjs.getWorkbook; exports.listAccessibleWorkbooks = _chunkZDZCCOUBcjs.listAccessibleWorkbooks; exports.listSnapshots = _chunkZDZCCOUBcjs.listSnapshots; exports.listTrashedWorkbooks = _chunkZDZCCOUBcjs.listTrashedWorkbooks; exports.moveWorkbook = _chunkZDZCCOUBcjs.moveWorkbook; exports.normalizeSheetPageSetup = normalizeSheetPageSetup; exports.pageSetupFromMetadata = pageSetupFromMetadata; exports.parseResource = parseResource; exports.planSheetPrint = planSheetPrint; exports.printColumnWidths = printColumnWidths; exports.printDocumentHtml = printDocumentHtml; exports.printGeometry = printGeometry; exports.printSheet = printSheet; exports.readSheetPageSetup = readSheetPageSetup; exports.readWorkbookScopeSource = readWorkbookScopeSource; exports.registerWorkbookScopeSource = registerWorkbookScopeSource; exports.renameWorkbook = _chunkZDZCCOUBcjs.renameWorkbook; exports.restoreWorkbook = _chunkZDZCCOUBcjs.restoreWorkbook; exports.rowsToCsv = rowsToCsv; exports.rowsToMarkdownTable = rowsToMarkdownTable; exports.saveSnapshot = _chunkZDZCCOUBcjs.saveSnapshot; exports.snapshotPreviewSvg = snapshotPreviewSvg; exports.snapshotToGridSheets = snapshotToGridSheets; exports.univerSheetIds = univerSheetIds; exports.univerSnapshotToRows = univerSnapshotToRows; exports.updateWorkbookDescription = _chunkZDZCCOUBcjs.updateWorkbookDescription; exports.workbookPreviewSvg = workbookPreviewSvg; exports.workbookSourceLabel = _chunkZDZCCOUBcjs.workbookSourceLabel; exports.writeSheetPageSetup = writeSheetPageSetup;
|
|
921
|
+
//# sourceMappingURL=sheets.cjs.map
|