@xlsx-editor.dev/core 0.0.0-placeholder.0 → 0.1.0-beta.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/LICENSE +217 -0
- package/README.md +254 -2
- package/THIRD_PARTY_NOTICES.md +78 -0
- package/dist/automation.d.ts +299 -0
- package/dist/automation.js +42 -0
- package/dist/builtins-nmHrq2Et.d.ts +37 -0
- package/dist/cascade.d.ts +196 -0
- package/dist/cascade.js +60 -0
- package/dist/cell-format-DW8yF-c-.d.ts +226 -0
- package/dist/chunk-2DLJYRJC.js +3171 -0
- package/dist/chunk-2ZU4337U.js +204 -0
- package/dist/chunk-44L37ENZ.js +8219 -0
- package/dist/chunk-77N55BLP.js +911 -0
- package/dist/chunk-7PV5HQPE.js +84 -0
- package/dist/chunk-E4VJJ556.js +756 -0
- package/dist/chunk-KG4IL4JI.js +436 -0
- package/dist/chunk-PLDK4XO6.js +9125 -0
- package/dist/chunk-PRHLYXHL.js +1699 -0
- package/dist/chunk-TE4FXG5T.js +3156 -0
- package/dist/contracts.d.ts +32 -0
- package/dist/contracts.js +0 -0
- package/dist/dist-C7NLNUMD.js +2850 -0
- package/dist/editor.d.ts +3167 -0
- package/dist/editor.js +309 -0
- package/dist/harfbuzz-measurer-CkKfsEyu.d.ts +128 -0
- package/dist/harfbuzz.wasm +0 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +309 -0
- package/dist/layout.d.ts +111 -0
- package/dist/layout.js +104 -0
- package/dist/merge-commands-DthcNpfw.d.ts +53 -0
- package/dist/node-module-shim-LQXGL47O.js +18 -0
- package/dist/ops-CfUCjyph.d.ts +629 -0
- package/dist/output.d.ts +177 -0
- package/dist/output.js +29 -0
- package/dist/sheet-index-P5vevMWX.d.ts +52 -0
- package/dist/sheet-layout-D9M_4EBn.d.ts +494 -0
- package/dist/sheet-protection-D8goxm58.d.ts +209 -0
- package/dist/store.d.ts +615 -0
- package/dist/store.js +272 -0
- package/dist/theme-BprDji6x.d.ts +16 -0
- package/dist/units-D6CD_A5I.d.ts +13 -0
- package/dist/workbook-index-DsbeR8Kb.d.ts +294 -0
- package/licenses/Emscripten-LICENSE.txt +102 -0
- package/licenses/HarfBuzz-COPYING.txt +42 -0
- package/licenses/HarfBuzz-USE-MIT.txt +21 -0
- package/licenses/HarfBuzz-source-notices.txt +4508 -0
- package/licenses/README.md +19 -0
- package/licenses/Unicode-LICENSE.txt +39 -0
- package/licenses/compiler-rt-LICENSE.txt +311 -0
- package/licenses/harfbuzz-manifest.json +84 -0
- package/licenses/musl-COPYRIGHT.txt +193 -0
- package/package.json +79 -6
- package/src/styles/editor.css +1933 -0
- package/src/styles/editor.css.d.ts +2 -0
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toCss
|
|
3
|
+
} from "./chunk-KG4IL4JI.js";
|
|
4
|
+
import {
|
|
5
|
+
binaryPartOf,
|
|
6
|
+
formatCellRef
|
|
7
|
+
} from "./chunk-2DLJYRJC.js";
|
|
8
|
+
|
|
9
|
+
// ../ooxml-core/src/image-size.ts
|
|
10
|
+
var MAX_PIXELS = 1 << 16;
|
|
11
|
+
var MAX_JPEG_SCAN = 4 * 1024 * 1024;
|
|
12
|
+
var u16be = (b, i) => b[i] << 8 | b[i + 1];
|
|
13
|
+
var u16le = (b, i) => b[i] | b[i + 1] << 8;
|
|
14
|
+
var u32be = (b, i) => (b[i] << 24 >>> 0) + (b[i + 1] << 16) + (b[i + 2] << 8) + b[i + 3];
|
|
15
|
+
var i32le = (b, i) => b[i] | b[i + 1] << 8 | b[i + 2] << 16 | b[i + 3] << 24;
|
|
16
|
+
var valid = (w, h) => Number.isInteger(w) && Number.isInteger(h) && w > 0 && h > 0 && w <= MAX_PIXELS && h <= MAX_PIXELS;
|
|
17
|
+
var dpi = (v) => Number.isFinite(v) && v >= 1 && v <= 1e4 ? v : void 0;
|
|
18
|
+
function png(b) {
|
|
19
|
+
if (b.length < 33 || u32be(b, 12) !== 1229472850) return null;
|
|
20
|
+
const width = u32be(b, 16);
|
|
21
|
+
const height = u32be(b, 20);
|
|
22
|
+
if (!valid(width, height)) return null;
|
|
23
|
+
let i = 8;
|
|
24
|
+
for (let n = 0; n < 64 && i + 8 <= b.length; n += 1) {
|
|
25
|
+
const length = u32be(b, i);
|
|
26
|
+
const type = u32be(b, i + 4);
|
|
27
|
+
if (type === 1229209940) break;
|
|
28
|
+
if (type === 1883789683 && length === 9 && i + 17 <= b.length && b[i + 16] === 1) {
|
|
29
|
+
const x = dpi(u32be(b, i + 8) * 0.0254);
|
|
30
|
+
const y = dpi(u32be(b, i + 12) * 0.0254);
|
|
31
|
+
return { width, height, ...x ? { dpiX: x } : {}, ...y ? { dpiY: y } : {} };
|
|
32
|
+
}
|
|
33
|
+
if (length > b.length) break;
|
|
34
|
+
i += 12 + length;
|
|
35
|
+
}
|
|
36
|
+
return { width, height };
|
|
37
|
+
}
|
|
38
|
+
function jpeg(b) {
|
|
39
|
+
let i = 2;
|
|
40
|
+
let density = {};
|
|
41
|
+
const end = Math.min(b.length, MAX_JPEG_SCAN);
|
|
42
|
+
while (i + 4 <= end) {
|
|
43
|
+
if (b[i] !== 255) return null;
|
|
44
|
+
const marker = b[i + 1];
|
|
45
|
+
if (marker === 255) {
|
|
46
|
+
i += 1;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const length = u16be(b, i + 2);
|
|
50
|
+
if (length < 2) return null;
|
|
51
|
+
if (marker === 224 && i + 18 <= end && b[i + 4] === 74 && b[i + 5] === 70) {
|
|
52
|
+
const units = b[i + 11];
|
|
53
|
+
const f = units === 1 ? 1 : units === 2 ? 2.54 : 0;
|
|
54
|
+
if (f) density = { x: dpi(u16be(b, i + 12) * f), y: dpi(u16be(b, i + 14) * f) };
|
|
55
|
+
}
|
|
56
|
+
const isFrame = marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204;
|
|
57
|
+
if (isFrame) {
|
|
58
|
+
if (i + 9 > end) return null;
|
|
59
|
+
const height = u16be(b, i + 5);
|
|
60
|
+
const width = u16be(b, i + 7);
|
|
61
|
+
if (!valid(width, height)) return null;
|
|
62
|
+
return {
|
|
63
|
+
width,
|
|
64
|
+
height,
|
|
65
|
+
...density.x ? { dpiX: density.x } : {},
|
|
66
|
+
...density.y ? { dpiY: density.y } : {}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
i += 2 + length;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function gif(b) {
|
|
74
|
+
if (b.length < 10) return null;
|
|
75
|
+
const width = u16le(b, 6);
|
|
76
|
+
const height = u16le(b, 8);
|
|
77
|
+
return valid(width, height) ? { width, height } : null;
|
|
78
|
+
}
|
|
79
|
+
function bmp(b) {
|
|
80
|
+
if (b.length < 46) return null;
|
|
81
|
+
const width = i32le(b, 18);
|
|
82
|
+
const height = Math.abs(i32le(b, 22));
|
|
83
|
+
if (!valid(width, height)) return null;
|
|
84
|
+
const x = dpi(i32le(b, 38) * 0.0254);
|
|
85
|
+
const y = dpi(i32le(b, 42) * 0.0254);
|
|
86
|
+
return { width, height, ...x ? { dpiX: x } : {}, ...y ? { dpiY: y } : {} };
|
|
87
|
+
}
|
|
88
|
+
function imageSize(bytes) {
|
|
89
|
+
const b = bytes;
|
|
90
|
+
if (b.length >= 8 && b[0] === 137 && b[1] === 80 && b[2] === 78 && b[3] === 71)
|
|
91
|
+
return png(b);
|
|
92
|
+
if (b.length >= 4 && b[0] === 255 && b[1] === 216) return jpeg(b);
|
|
93
|
+
if (b.length >= 6 && b[0] === 71 && b[1] === 73 && b[2] === 70) return gif(b);
|
|
94
|
+
if (b.length >= 2 && b[0] === 66 && b[1] === 77) return bmp(b);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/output/pattern-tiles.ts
|
|
99
|
+
var PATTERN_TILE_SIZE = 8;
|
|
100
|
+
var PATTERN_PIXEL_PT = 1;
|
|
101
|
+
var PATTERN_TILES = Object.freeze({
|
|
102
|
+
darkGray: [
|
|
103
|
+
"11101110",
|
|
104
|
+
"10111011",
|
|
105
|
+
"11101110",
|
|
106
|
+
"10111011",
|
|
107
|
+
"11101110",
|
|
108
|
+
"10111011",
|
|
109
|
+
"11101110",
|
|
110
|
+
"10111011"
|
|
111
|
+
],
|
|
112
|
+
mediumGray: [
|
|
113
|
+
"10101010",
|
|
114
|
+
"01010101",
|
|
115
|
+
"10101010",
|
|
116
|
+
"01010101",
|
|
117
|
+
"10101010",
|
|
118
|
+
"01010101",
|
|
119
|
+
"10101010",
|
|
120
|
+
"01010101"
|
|
121
|
+
],
|
|
122
|
+
lightGray: [
|
|
123
|
+
"10001000",
|
|
124
|
+
"00100010",
|
|
125
|
+
"10001000",
|
|
126
|
+
"00100010",
|
|
127
|
+
"10001000",
|
|
128
|
+
"00100010",
|
|
129
|
+
"10001000",
|
|
130
|
+
"00100010"
|
|
131
|
+
],
|
|
132
|
+
gray125: [
|
|
133
|
+
"10001000",
|
|
134
|
+
"00000000",
|
|
135
|
+
"00100010",
|
|
136
|
+
"00000000",
|
|
137
|
+
"10001000",
|
|
138
|
+
"00000000",
|
|
139
|
+
"00100010",
|
|
140
|
+
"00000000"
|
|
141
|
+
],
|
|
142
|
+
gray0625: [
|
|
143
|
+
"10000000",
|
|
144
|
+
"00000000",
|
|
145
|
+
"00001000",
|
|
146
|
+
"00000000",
|
|
147
|
+
"10000000",
|
|
148
|
+
"00000000",
|
|
149
|
+
"00001000",
|
|
150
|
+
"00000000"
|
|
151
|
+
],
|
|
152
|
+
darkHorizontal: [
|
|
153
|
+
"11111111",
|
|
154
|
+
"11111111",
|
|
155
|
+
"00000000",
|
|
156
|
+
"00000000",
|
|
157
|
+
"11111111",
|
|
158
|
+
"11111111",
|
|
159
|
+
"00000000",
|
|
160
|
+
"00000000"
|
|
161
|
+
],
|
|
162
|
+
darkVertical: [
|
|
163
|
+
"11001100",
|
|
164
|
+
"11001100",
|
|
165
|
+
"11001100",
|
|
166
|
+
"11001100",
|
|
167
|
+
"11001100",
|
|
168
|
+
"11001100",
|
|
169
|
+
"11001100",
|
|
170
|
+
"11001100"
|
|
171
|
+
],
|
|
172
|
+
darkDown: [
|
|
173
|
+
"11001100",
|
|
174
|
+
"01100110",
|
|
175
|
+
"00110011",
|
|
176
|
+
"10011001",
|
|
177
|
+
"11001100",
|
|
178
|
+
"01100110",
|
|
179
|
+
"00110011",
|
|
180
|
+
"10011001"
|
|
181
|
+
],
|
|
182
|
+
darkUp: [
|
|
183
|
+
"00110011",
|
|
184
|
+
"01100110",
|
|
185
|
+
"11001100",
|
|
186
|
+
"10011001",
|
|
187
|
+
"00110011",
|
|
188
|
+
"01100110",
|
|
189
|
+
"11001100",
|
|
190
|
+
"10011001"
|
|
191
|
+
],
|
|
192
|
+
darkGrid: [
|
|
193
|
+
"10011001",
|
|
194
|
+
"01100110",
|
|
195
|
+
"01100110",
|
|
196
|
+
"10011001",
|
|
197
|
+
"10011001",
|
|
198
|
+
"01100110",
|
|
199
|
+
"01100110",
|
|
200
|
+
"10011001"
|
|
201
|
+
],
|
|
202
|
+
darkTrellis: [
|
|
203
|
+
"11111111",
|
|
204
|
+
"01100110",
|
|
205
|
+
"11111111",
|
|
206
|
+
"10011001",
|
|
207
|
+
"11111111",
|
|
208
|
+
"01100110",
|
|
209
|
+
"11111111",
|
|
210
|
+
"10011001"
|
|
211
|
+
],
|
|
212
|
+
lightHorizontal: [
|
|
213
|
+
"11111111",
|
|
214
|
+
"00000000",
|
|
215
|
+
"00000000",
|
|
216
|
+
"00000000",
|
|
217
|
+
"11111111",
|
|
218
|
+
"00000000",
|
|
219
|
+
"00000000",
|
|
220
|
+
"00000000"
|
|
221
|
+
],
|
|
222
|
+
lightVertical: [
|
|
223
|
+
"10001000",
|
|
224
|
+
"10001000",
|
|
225
|
+
"10001000",
|
|
226
|
+
"10001000",
|
|
227
|
+
"10001000",
|
|
228
|
+
"10001000",
|
|
229
|
+
"10001000",
|
|
230
|
+
"10001000"
|
|
231
|
+
],
|
|
232
|
+
lightDown: [
|
|
233
|
+
"10001000",
|
|
234
|
+
"01000100",
|
|
235
|
+
"00100010",
|
|
236
|
+
"00010001",
|
|
237
|
+
"10001000",
|
|
238
|
+
"01000100",
|
|
239
|
+
"00100010",
|
|
240
|
+
"00010001"
|
|
241
|
+
],
|
|
242
|
+
lightUp: [
|
|
243
|
+
"00010001",
|
|
244
|
+
"00100010",
|
|
245
|
+
"01000100",
|
|
246
|
+
"10001000",
|
|
247
|
+
"00010001",
|
|
248
|
+
"00100010",
|
|
249
|
+
"01000100",
|
|
250
|
+
"10001000"
|
|
251
|
+
],
|
|
252
|
+
lightGrid: [
|
|
253
|
+
"11111111",
|
|
254
|
+
"10001000",
|
|
255
|
+
"10001000",
|
|
256
|
+
"10001000",
|
|
257
|
+
"11111111",
|
|
258
|
+
"10001000",
|
|
259
|
+
"10001000",
|
|
260
|
+
"10001000"
|
|
261
|
+
],
|
|
262
|
+
lightTrellis: [
|
|
263
|
+
"10001000",
|
|
264
|
+
"01010101",
|
|
265
|
+
"00100010",
|
|
266
|
+
"01010101",
|
|
267
|
+
"10001000",
|
|
268
|
+
"01010101",
|
|
269
|
+
"00100010",
|
|
270
|
+
"01010101"
|
|
271
|
+
]
|
|
272
|
+
});
|
|
273
|
+
function patternCoverage(pattern) {
|
|
274
|
+
const tile = Object.hasOwn(PATTERN_TILES, pattern) ? PATTERN_TILES[pattern] : void 0;
|
|
275
|
+
if (!tile) return 0;
|
|
276
|
+
let set = 0;
|
|
277
|
+
for (const row of tile) for (const bit of row) if (bit === "1") set += 1;
|
|
278
|
+
return set / (PATTERN_TILE_SIZE * PATTERN_TILE_SIZE);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/output/paint-style.ts
|
|
282
|
+
var HEX = /^[0-9A-Fa-f]{6}$/;
|
|
283
|
+
function cssColor(rgb, fallback = "#000000") {
|
|
284
|
+
return rgb !== void 0 && HEX.test(rgb) ? `#${rgb.toUpperCase()}` : fallback;
|
|
285
|
+
}
|
|
286
|
+
function cssRgba(color) {
|
|
287
|
+
return toCss(color);
|
|
288
|
+
}
|
|
289
|
+
var LINES = Object.freeze({
|
|
290
|
+
thin: { width: 1, dash: [], double: false },
|
|
291
|
+
medium: { width: 2, dash: [], double: false },
|
|
292
|
+
thick: { width: 3, dash: [], double: false },
|
|
293
|
+
double: { width: 3, dash: [], double: true },
|
|
294
|
+
hair: { width: 1, dash: [1, 1], double: false },
|
|
295
|
+
dotted: { width: 1, dash: [1, 1], double: false },
|
|
296
|
+
dashed: { width: 1, dash: [3, 1], double: false },
|
|
297
|
+
dashDot: { width: 1, dash: [9, 3, 3, 3], double: false },
|
|
298
|
+
dashDotDot: { width: 1, dash: [9, 3, 3, 3, 3, 3], double: false },
|
|
299
|
+
mediumDashed: { width: 2, dash: [9, 3], double: false },
|
|
300
|
+
mediumDashDot: { width: 2, dash: [9, 3, 3, 3], double: false },
|
|
301
|
+
mediumDashDotDot: { width: 2, dash: [9, 3, 3, 3, 3, 3], double: false },
|
|
302
|
+
slantDashDot: { width: 2, dash: [11, 1, 5, 1], double: false }
|
|
303
|
+
});
|
|
304
|
+
function borderLine(style) {
|
|
305
|
+
return Object.hasOwn(LINES, style) ? LINES[style] : void 0;
|
|
306
|
+
}
|
|
307
|
+
var channel = (rgb, i) => parseInt(rgb.slice(i * 2, i * 2 + 2), 16);
|
|
308
|
+
function mix(a, b, share) {
|
|
309
|
+
if (!HEX.test(a) || !HEX.test(b)) return cssColor(a);
|
|
310
|
+
const out = [0, 1, 2].map(
|
|
311
|
+
(i) => Math.round(channel(a, i) * share + channel(b, i) * (1 - share)).toString(16).padStart(2, "0")
|
|
312
|
+
);
|
|
313
|
+
return `#${out.join("").toUpperCase()}`;
|
|
314
|
+
}
|
|
315
|
+
function fillPaint(fill) {
|
|
316
|
+
if (fill.kind === "none") return { kind: "none" };
|
|
317
|
+
if (fill.kind === "solid") return { kind: "color", color: cssColor(fill.color, "#FFFFFF") };
|
|
318
|
+
if (fill.kind === "pattern") {
|
|
319
|
+
const background = fill.background ?? "FFFFFF";
|
|
320
|
+
const mixed = mix(fill.foreground, background, patternCoverage(fill.pattern));
|
|
321
|
+
if (!Object.hasOwn(PATTERN_TILES, fill.pattern)) return { kind: "color", color: mixed };
|
|
322
|
+
return {
|
|
323
|
+
kind: "pattern",
|
|
324
|
+
pattern: fill.pattern,
|
|
325
|
+
foreground: cssColor(fill.foreground, "#000000"),
|
|
326
|
+
background: cssColor(background, "#FFFFFF"),
|
|
327
|
+
mix: mixed
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const stops = fill.stops.map((s) => ({ offset: Math.min(1, Math.max(0, s.position)), color: cssColor(s.color) })).sort((a, b) => a.offset - b.offset);
|
|
331
|
+
if (stops.length === 0) return { kind: "none" };
|
|
332
|
+
if (stops.length === 1) return { kind: "color", color: stops[0].color };
|
|
333
|
+
return { kind: "gradient", type: fill.type, degree: fill.degree, rect: fill.rect, stops };
|
|
334
|
+
}
|
|
335
|
+
var DEFAULT_GRIDLINE_COLOR = "D4D4D4";
|
|
336
|
+
function lineBand(at, widthPx, pixel) {
|
|
337
|
+
const start = at - Math.floor((widthPx - 1) / 2) * pixel;
|
|
338
|
+
return [start, widthPx * pixel];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/output/paint-fills.ts
|
|
342
|
+
var MAX_TILE_SIDE = 512;
|
|
343
|
+
var TILE_CACHE_CAP = 256;
|
|
344
|
+
var TILE_CACHE_AREA = 16 * 1024 * 1024;
|
|
345
|
+
var TILE_CACHES = /* @__PURE__ */ new WeakMap();
|
|
346
|
+
function paintFill(fc, paint, rect, bleed) {
|
|
347
|
+
const { g } = fc;
|
|
348
|
+
if (paint.kind === "none") return;
|
|
349
|
+
const box = { x: rect.x, y: rect.y, width: rect.width + bleed, height: rect.height + bleed };
|
|
350
|
+
if (paint.kind === "color" || paint.kind === "pattern") {
|
|
351
|
+
g.fillStyle = paint.kind === "color" ? paint.color : patternStyle(fc, paint) ?? paint.mix;
|
|
352
|
+
g.fillRect(box.x, box.y, box.width, box.height);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (paint.type === "linear") linear(g, box, paint.degree, paint.stops);
|
|
356
|
+
else path(g, box, paint.rect, paint.stops, 1 / fc.ratio);
|
|
357
|
+
}
|
|
358
|
+
function tileBitmap(ratio) {
|
|
359
|
+
const one = PATTERN_TILE_SIZE * PATTERN_PIXEL_PT * ratio;
|
|
360
|
+
if (one < PATTERN_TILE_SIZE || one > MAX_TILE_SIDE) return void 0;
|
|
361
|
+
let best = { tiles: 1, side: Math.round(one), error: Math.abs(one - Math.round(one)) };
|
|
362
|
+
for (let k = 2; k <= 8 && Math.round(one * k) <= MAX_TILE_SIDE; k++) {
|
|
363
|
+
const error = Math.abs(one * k - Math.round(one * k)) / k;
|
|
364
|
+
if (error < best.error - 1e-9) best = { tiles: k, side: Math.round(one * k), error };
|
|
365
|
+
}
|
|
366
|
+
return { tiles: best.tiles, side: best.side };
|
|
367
|
+
}
|
|
368
|
+
function pixelEdges(side, count) {
|
|
369
|
+
return Array.from({ length: count + 1 }, (_, j) => Math.round(j * side / count));
|
|
370
|
+
}
|
|
371
|
+
function patternStyle(fc, paint) {
|
|
372
|
+
const { g, ratio } = fc;
|
|
373
|
+
const bitmap = tileBitmap(ratio);
|
|
374
|
+
if (!bitmap || typeof g.createPattern !== "function") return void 0;
|
|
375
|
+
const key = `${paint.pattern}|${paint.foreground}|${paint.background}|${bitmap.side}|${bitmap.tiles}`;
|
|
376
|
+
if (fc.patterns.has(key)) return fc.patterns.get(key) ?? void 0;
|
|
377
|
+
const canvas = tileCanvas(g, paint, bitmap.side, bitmap.tiles, key);
|
|
378
|
+
let pattern = canvas ? g.createPattern(canvas, "repeat") : null;
|
|
379
|
+
if (pattern && typeof pattern.setTransform === "function") {
|
|
380
|
+
const phase = (v) => {
|
|
381
|
+
const d = Math.round(v * ratio) % bitmap.side;
|
|
382
|
+
return (d < 0 ? d + bitmap.side : d) / ratio;
|
|
383
|
+
};
|
|
384
|
+
const e = phase(fc.origin.x);
|
|
385
|
+
const f = phase(fc.origin.y);
|
|
386
|
+
pattern.setTransform({ a: 1 / ratio, b: 0, c: 0, d: 1 / ratio, e, f });
|
|
387
|
+
} else pattern = null;
|
|
388
|
+
fc.patterns.set(key, pattern);
|
|
389
|
+
return pattern ?? void 0;
|
|
390
|
+
}
|
|
391
|
+
function tileCanvas(g, paint, side, tiles, key) {
|
|
392
|
+
const doc = g.canvas?.ownerDocument;
|
|
393
|
+
const rows = Object.hasOwn(PATTERN_TILES, paint.pattern) ? PATTERN_TILES[paint.pattern] : void 0;
|
|
394
|
+
if (!doc || !rows) return void 0;
|
|
395
|
+
let cache = TILE_CACHES.get(doc);
|
|
396
|
+
if (!cache) {
|
|
397
|
+
cache = /* @__PURE__ */ new Map();
|
|
398
|
+
TILE_CACHES.set(doc, cache);
|
|
399
|
+
}
|
|
400
|
+
const hit = cache.get(key);
|
|
401
|
+
if (hit) {
|
|
402
|
+
cache.delete(key);
|
|
403
|
+
cache.set(key, hit);
|
|
404
|
+
return hit;
|
|
405
|
+
}
|
|
406
|
+
const canvas = doc.createElement("canvas");
|
|
407
|
+
canvas.width = side;
|
|
408
|
+
canvas.height = side;
|
|
409
|
+
const t = canvas.getContext("2d");
|
|
410
|
+
if (!t) return void 0;
|
|
411
|
+
const count = PATTERN_TILE_SIZE * tiles;
|
|
412
|
+
const edge2 = pixelEdges(side, count);
|
|
413
|
+
t.fillStyle = paint.background;
|
|
414
|
+
t.fillRect(0, 0, side, side);
|
|
415
|
+
t.fillStyle = paint.foreground;
|
|
416
|
+
for (let r = 0; r < count; r++) {
|
|
417
|
+
const bits = rows[r % PATTERN_TILE_SIZE];
|
|
418
|
+
for (let c = 0; c < count; c++)
|
|
419
|
+
if (bits[c % PATTERN_TILE_SIZE] === "1")
|
|
420
|
+
t.fillRect(edge2[c], edge2[r], edge2[c + 1] - edge2[c], edge2[r + 1] - edge2[r]);
|
|
421
|
+
}
|
|
422
|
+
let area = side * side;
|
|
423
|
+
for (const c of cache.values()) area += c.width * c.height;
|
|
424
|
+
for (const [old, c] of cache) {
|
|
425
|
+
if (cache.size < TILE_CACHE_CAP && area <= TILE_CACHE_AREA) break;
|
|
426
|
+
area -= c.width * c.height;
|
|
427
|
+
cache.delete(old);
|
|
428
|
+
}
|
|
429
|
+
cache.set(key, canvas);
|
|
430
|
+
return canvas;
|
|
431
|
+
}
|
|
432
|
+
function linearEnds(rect, degree) {
|
|
433
|
+
const rad = degree * Math.PI / 180;
|
|
434
|
+
const cos = Math.cos(rad);
|
|
435
|
+
const sin = Math.sin(rad);
|
|
436
|
+
const reach = (Math.abs(cos) + Math.abs(sin)) / 2;
|
|
437
|
+
const cx = rect.x + rect.width / 2;
|
|
438
|
+
const cy = rect.y + rect.height / 2;
|
|
439
|
+
const dx = cos * reach * rect.width;
|
|
440
|
+
const dy = sin * reach * rect.height;
|
|
441
|
+
return [cx - dx, cy - dy, cx + dx, cy + dy];
|
|
442
|
+
}
|
|
443
|
+
var UNIT = Object.freeze({ x: 0, y: 0, width: 1, height: 1 });
|
|
444
|
+
function linear(g, box, degree, stops) {
|
|
445
|
+
if (box.width <= 0 || box.height <= 0) return;
|
|
446
|
+
g.save();
|
|
447
|
+
g.translate(box.x, box.y);
|
|
448
|
+
g.scale(box.width, box.height);
|
|
449
|
+
const grad = g.createLinearGradient(...linearEnds(UNIT, degree));
|
|
450
|
+
for (const s of stops) grad.addColorStop(s.offset, s.color);
|
|
451
|
+
g.fillStyle = grad;
|
|
452
|
+
g.fillRect(0, 0, 1, 1);
|
|
453
|
+
g.restore();
|
|
454
|
+
}
|
|
455
|
+
function pathShapes(rect, inner, overlap) {
|
|
456
|
+
const { x, y, width: w, height: h } = rect;
|
|
457
|
+
const L = x + inner.left * w;
|
|
458
|
+
const R = x + inner.right * w;
|
|
459
|
+
const T = y + inner.top * h;
|
|
460
|
+
const B = y + inner.bottom * h;
|
|
461
|
+
const X = x + w;
|
|
462
|
+
const Y = y + h;
|
|
463
|
+
const shapes = [
|
|
464
|
+
{ points: [[x, y], [X, y], [X, Y], [x, Y]], from: [x, y], to: [x, y] }
|
|
465
|
+
// prettier-ignore
|
|
466
|
+
];
|
|
467
|
+
const band = (x0, x1, from, to) => shapes.push({ points: [[x0, y], [x1, y], [x1, Y], [x0, Y]], from: [from, 0], to: [to, 0] });
|
|
468
|
+
if (L > x) band(x, Math.min(X, L + overlap), L, x);
|
|
469
|
+
if (X > R) band(Math.max(x, L, R - overlap), X, R, X);
|
|
470
|
+
if (T > y || B > T)
|
|
471
|
+
shapes.push({ points: [[x, y], [X, y], [R, T], [R, B], [L, B], [L, T]], from: [0, T], to: [0, y] });
|
|
472
|
+
if (Y > B || B > T)
|
|
473
|
+
shapes.push({ points: [[x, Y], [X, Y], [R, B], [R, T], [L, T], [L, B]], from: [0, B], to: [0, Y] });
|
|
474
|
+
return shapes;
|
|
475
|
+
}
|
|
476
|
+
function path(g, box, inner, stops, overlap) {
|
|
477
|
+
if (stops.length === 0) return;
|
|
478
|
+
for (const shape of pathShapes(box, inner, overlap)) {
|
|
479
|
+
const [fx, fy] = shape.from;
|
|
480
|
+
const [tx, ty] = shape.to;
|
|
481
|
+
if (fx === tx && fy === ty) g.fillStyle = stops[0].color;
|
|
482
|
+
else {
|
|
483
|
+
const grad = g.createLinearGradient(fx, fy, tx, ty);
|
|
484
|
+
for (const s of stops) grad.addColorStop(s.offset, s.color);
|
|
485
|
+
g.fillStyle = grad;
|
|
486
|
+
}
|
|
487
|
+
g.beginPath();
|
|
488
|
+
shape.points.forEach(([px, py], i) => i === 0 ? g.moveTo(px, py) : g.lineTo(px, py));
|
|
489
|
+
g.closePath();
|
|
490
|
+
g.fill();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/output/paint-sheet.ts
|
|
495
|
+
var MAX_CANVAS_SIDE = 16384;
|
|
496
|
+
function fontOf(faceId, sizePt, bold, italic) {
|
|
497
|
+
const safe = faceId.replace(/[^A-Za-z0-9_-]/g, "");
|
|
498
|
+
const family = safe.length > 0 ? `${safe}, sans-serif` : "sans-serif";
|
|
499
|
+
return `${italic ? "italic " : ""}${bold ? "bold " : ""}${sizePt}px ${family}`;
|
|
500
|
+
}
|
|
501
|
+
function gridlines(ctx, pane) {
|
|
502
|
+
if (pane.columns.length === 0 || pane.rows.length === 0) return;
|
|
503
|
+
const { g, px } = ctx;
|
|
504
|
+
const top = pane.rows[0].start;
|
|
505
|
+
const last = pane.rows[pane.rows.length - 1];
|
|
506
|
+
const bottom = last.start + last.size;
|
|
507
|
+
const left = pane.columns[0].start;
|
|
508
|
+
const end = pane.columns[pane.columns.length - 1];
|
|
509
|
+
const right = end.start + end.size;
|
|
510
|
+
g.fillStyle = cssColor(ctx.options.gridlineColor ?? DEFAULT_GRIDLINE_COLOR);
|
|
511
|
+
for (const c of pane.columns) g.fillRect(c.start, top, px, bottom - top);
|
|
512
|
+
g.fillRect(right, top, px, bottom - top);
|
|
513
|
+
for (const r of pane.rows) g.fillRect(left, r.start, right - left, px);
|
|
514
|
+
g.fillRect(left, bottom, right - left, px);
|
|
515
|
+
}
|
|
516
|
+
function fills(ctx, pane) {
|
|
517
|
+
const fc = {
|
|
518
|
+
g: ctx.g,
|
|
519
|
+
ratio: ctx.ratio,
|
|
520
|
+
origin: ctx.options.patternOrigin ?? pane.sheetOrigin,
|
|
521
|
+
patterns: /* @__PURE__ */ new Map()
|
|
522
|
+
};
|
|
523
|
+
for (const box of pane.cells) paintFill(fc, fillPaint(box.fill), box.rect, ctx.px);
|
|
524
|
+
}
|
|
525
|
+
function edge(ctx, line, color, vertical, at, from, length) {
|
|
526
|
+
const { g, px } = ctx;
|
|
527
|
+
const [start, size] = lineBand(at, line.width, px);
|
|
528
|
+
const bands = line.double ? [
|
|
529
|
+
[start, px],
|
|
530
|
+
[start + 2 * px, px]
|
|
531
|
+
] : [[start, size]];
|
|
532
|
+
for (const [s, w] of bands) {
|
|
533
|
+
if (line.dash.length === 0) {
|
|
534
|
+
g.fillStyle = color;
|
|
535
|
+
if (vertical) g.fillRect(s, from, w, length + px);
|
|
536
|
+
else g.fillRect(from, s, length + px, w);
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
const mid = s + w / 2;
|
|
540
|
+
g.strokeStyle = color;
|
|
541
|
+
g.lineWidth = w;
|
|
542
|
+
g.setLineDash(line.dash.map((d) => d * px));
|
|
543
|
+
g.beginPath();
|
|
544
|
+
g.moveTo(vertical ? mid : from, vertical ? from : mid);
|
|
545
|
+
g.lineTo(vertical ? mid : from + length + px, vertical ? from + length + px : mid);
|
|
546
|
+
g.stroke();
|
|
547
|
+
g.setLineDash([]);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function borders(ctx, pane) {
|
|
551
|
+
const { g, px } = ctx;
|
|
552
|
+
for (const box of pane.cells) {
|
|
553
|
+
const { x, y, width, height } = box.rect;
|
|
554
|
+
const b = box.border;
|
|
555
|
+
const sides = [
|
|
556
|
+
[b.left, true, x, y, height],
|
|
557
|
+
[b.right, true, x + width, y, height],
|
|
558
|
+
[b.top, false, y, x, width],
|
|
559
|
+
[b.bottom, false, y + height, x, width]
|
|
560
|
+
];
|
|
561
|
+
for (const [e, vertical, at, from, length] of sides) {
|
|
562
|
+
const line = borderLine(e.style);
|
|
563
|
+
if (line) edge(ctx, line, cssColor(e.color), vertical, at, from, length);
|
|
564
|
+
}
|
|
565
|
+
diagonals(g, box, px);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
function diagonals(g, box, px) {
|
|
569
|
+
const b = box.border;
|
|
570
|
+
const diagonal = borderLine(b.diagonal.style);
|
|
571
|
+
if (!diagonal || !(b.diagonalUp || b.diagonalDown)) return;
|
|
572
|
+
const { x, y, width, height } = box.rect;
|
|
573
|
+
g.strokeStyle = cssColor(b.diagonal.color);
|
|
574
|
+
g.lineWidth = diagonal.width * px;
|
|
575
|
+
g.setLineDash(diagonal.dash.map((d) => d * px));
|
|
576
|
+
g.beginPath();
|
|
577
|
+
if (b.diagonalDown) {
|
|
578
|
+
g.moveTo(x, y);
|
|
579
|
+
g.lineTo(x + width, y + height);
|
|
580
|
+
}
|
|
581
|
+
if (b.diagonalUp) {
|
|
582
|
+
g.moveTo(x, y + height);
|
|
583
|
+
g.lineTo(x + width, y);
|
|
584
|
+
}
|
|
585
|
+
g.stroke();
|
|
586
|
+
g.setLineDash([]);
|
|
587
|
+
}
|
|
588
|
+
function spanText(ctx, span, baseline, last, clip) {
|
|
589
|
+
const { g } = ctx;
|
|
590
|
+
const s = span.style;
|
|
591
|
+
const font = fontOf(s.faceId, s.sizePt, s.synthBold, s.synthItalic);
|
|
592
|
+
if (font !== last) g.font = font;
|
|
593
|
+
const color = cssColor(s.color);
|
|
594
|
+
g.fillStyle = color;
|
|
595
|
+
const text = span.text;
|
|
596
|
+
const [from, to] = glyphsInClip(span, clip);
|
|
597
|
+
for (let i = from; i < to; ) {
|
|
598
|
+
const cp = text.codePointAt(i);
|
|
599
|
+
const n = cp > 65535 ? 2 : 1;
|
|
600
|
+
if (cp !== 32) g.fillText(text.slice(i, i + n), span.positions[i] ?? span.x, baseline);
|
|
601
|
+
i += n;
|
|
602
|
+
}
|
|
603
|
+
let end = text.length;
|
|
604
|
+
while (end > 0 && text[end - 1] === " ") end -= 1;
|
|
605
|
+
const x0 = span.positions[0] ?? span.x;
|
|
606
|
+
const x1 = end >= text.length ? span.x + span.width : span.positions[end] ?? x0;
|
|
607
|
+
if (x1 <= x0) return font;
|
|
608
|
+
const m = s.metrics;
|
|
609
|
+
const thickness = Math.max(m.underlineThickness * s.sizePt, s.sizePt / 20);
|
|
610
|
+
if (s.underline !== "none") {
|
|
611
|
+
const y = baseline - m.underlinePosition * s.sizePt;
|
|
612
|
+
g.fillRect(x0, y, x1 - x0, thickness);
|
|
613
|
+
if (s.underline === "double" || s.underline === "doubleAccounting")
|
|
614
|
+
g.fillRect(x0, y + thickness * 2, x1 - x0, thickness);
|
|
615
|
+
}
|
|
616
|
+
if (s.strike) g.fillRect(x0, baseline - s.sizePt * 0.3 - thickness / 2, x1 - x0, thickness);
|
|
617
|
+
return font;
|
|
618
|
+
}
|
|
619
|
+
function glyphsInClip(span, clip) {
|
|
620
|
+
const { text, positions } = span;
|
|
621
|
+
if (!clip || positions.length !== text.length) return [0, text.length];
|
|
622
|
+
const margin = span.style.sizePt;
|
|
623
|
+
const first = (x, orAt) => {
|
|
624
|
+
let lo = 0;
|
|
625
|
+
let hi = positions.length;
|
|
626
|
+
while (lo < hi) {
|
|
627
|
+
const mid = lo + hi >>> 1;
|
|
628
|
+
if (orAt ? positions[mid] < x : positions[mid] <= x) lo = mid + 1;
|
|
629
|
+
else hi = mid;
|
|
630
|
+
}
|
|
631
|
+
return lo;
|
|
632
|
+
};
|
|
633
|
+
let from = Math.max(0, first(clip.x - margin, true) - 1);
|
|
634
|
+
const unit = text.charCodeAt(from);
|
|
635
|
+
if (from > 0 && unit >= 56320 && unit <= 57343) from -= 1;
|
|
636
|
+
return [from, first(clip.x + clip.width + margin, false)];
|
|
637
|
+
}
|
|
638
|
+
function texts(ctx, pane) {
|
|
639
|
+
const { g } = ctx;
|
|
640
|
+
for (const box of pane.texts) {
|
|
641
|
+
g.save();
|
|
642
|
+
g.beginPath();
|
|
643
|
+
g.rect(box.clip.x, box.clip.y, box.clip.width, box.clip.height);
|
|
644
|
+
g.clip();
|
|
645
|
+
textBox(ctx, box);
|
|
646
|
+
g.restore();
|
|
647
|
+
}
|
|
648
|
+
return pane.texts.length;
|
|
649
|
+
}
|
|
650
|
+
var outsideClip = (span, clip) => span.x + span.width + span.style.sizePt < clip.x || span.x - span.style.sizePt > clip.x + clip.width;
|
|
651
|
+
function textBox(ctx, box) {
|
|
652
|
+
const t = box.text;
|
|
653
|
+
if (t.rotation) {
|
|
654
|
+
ctx.g.translate(t.rotation.originX, t.rotation.originY);
|
|
655
|
+
ctx.g.rotate(-t.rotation.angle * Math.PI / 180);
|
|
656
|
+
}
|
|
657
|
+
let font = "";
|
|
658
|
+
for (const line of t.lines)
|
|
659
|
+
for (const span of line.spans) {
|
|
660
|
+
if (t.rotation) font = spanText(ctx, span, line.baseline, font, null);
|
|
661
|
+
else if (!outsideClip(span, box.clip))
|
|
662
|
+
font = spanText(ctx, span, line.baseline, font, box.clip);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function tracePath(g, p) {
|
|
666
|
+
g.beginPath();
|
|
667
|
+
for (const c of p.commands) {
|
|
668
|
+
if (c.op === "M") g.moveTo(c.x, c.y);
|
|
669
|
+
else if (c.op === "L") g.lineTo(c.x, c.y);
|
|
670
|
+
else if (c.op === "C") g.bezierCurveTo(c.x1, c.y1, c.x2, c.y2, c.x, c.y);
|
|
671
|
+
else if (c.op === "Q") g.quadraticCurveTo(c.x1, c.y1, c.x, c.y);
|
|
672
|
+
else g.closePath();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
function shade(mode) {
|
|
676
|
+
if (mode === "lighten") return ["#FFFFFF", 0.4];
|
|
677
|
+
if (mode === "lightenLess") return ["#FFFFFF", 0.2];
|
|
678
|
+
if (mode === "darken") return ["#000000", 0.4];
|
|
679
|
+
if (mode === "darkenLess") return ["#000000", 0.2];
|
|
680
|
+
return void 0;
|
|
681
|
+
}
|
|
682
|
+
function drawing(ctx, d) {
|
|
683
|
+
const { g, px } = ctx;
|
|
684
|
+
const { x, y, width: w, height: h } = d.rect;
|
|
685
|
+
g.save();
|
|
686
|
+
g.translate(x, y);
|
|
687
|
+
if (d.rotation) {
|
|
688
|
+
g.translate(w / 2, h / 2);
|
|
689
|
+
g.rotate(d.rotation * Math.PI / 180);
|
|
690
|
+
g.translate(-w / 2, -h / 2);
|
|
691
|
+
}
|
|
692
|
+
if (d.flipH || d.flipV) {
|
|
693
|
+
g.translate(d.flipH ? w : 0, d.flipV ? h : 0);
|
|
694
|
+
g.scale(d.flipH ? -1 : 1, d.flipV ? -1 : 1);
|
|
695
|
+
}
|
|
696
|
+
if (d.kind === "shape") {
|
|
697
|
+
for (const p of d.geometry.paths) {
|
|
698
|
+
tracePath(g, p);
|
|
699
|
+
if (d.fill && p.fill !== "none") {
|
|
700
|
+
g.fillStyle = cssRgba(d.fill);
|
|
701
|
+
g.fill();
|
|
702
|
+
const overlay = shade(p.fill);
|
|
703
|
+
if (overlay) {
|
|
704
|
+
g.globalAlpha = overlay[1];
|
|
705
|
+
g.fillStyle = overlay[0];
|
|
706
|
+
g.fill();
|
|
707
|
+
g.globalAlpha = 1;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (p.stroke && d.line) {
|
|
711
|
+
g.strokeStyle = cssRgba(d.line.color);
|
|
712
|
+
g.lineWidth = d.line.width;
|
|
713
|
+
g.stroke();
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
} else if (d.kind === "picture") {
|
|
717
|
+
const state = ctx.options.pictures?.get(d.partName, d.contentType);
|
|
718
|
+
if (state?.kind === "loading") ctx.pending += 1;
|
|
719
|
+
else if (state?.kind === "ready") g.drawImage(state.bitmap, 0, 0, w, h);
|
|
720
|
+
else if (state?.kind === "unsupported") {
|
|
721
|
+
g.fillStyle = "#F2F2F2";
|
|
722
|
+
g.fillRect(0, 0, w, h);
|
|
723
|
+
g.strokeStyle = "#BFBFBF";
|
|
724
|
+
g.lineWidth = px;
|
|
725
|
+
g.strokeRect(px / 2, px / 2, w - px, h - px);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
g.restore();
|
|
729
|
+
}
|
|
730
|
+
function paintPane(ctx, pane) {
|
|
731
|
+
const { g } = ctx;
|
|
732
|
+
const c = pane.clip;
|
|
733
|
+
g.save();
|
|
734
|
+
g.beginPath();
|
|
735
|
+
g.rect(c.x, c.y, c.width, c.height);
|
|
736
|
+
g.clip();
|
|
737
|
+
if (ctx.options.gridlines) gridlines(ctx, pane);
|
|
738
|
+
fills(ctx, pane);
|
|
739
|
+
borders(ctx, pane);
|
|
740
|
+
const count = texts(ctx, pane);
|
|
741
|
+
for (const d of pane.drawings) drawing(ctx, d);
|
|
742
|
+
g.restore();
|
|
743
|
+
return count;
|
|
744
|
+
}
|
|
745
|
+
function paintSheet(canvas, layout, options) {
|
|
746
|
+
const w = Math.max(0, options.width);
|
|
747
|
+
const h = Math.max(0, options.height);
|
|
748
|
+
const wanted = options.scale * (options.devicePixelRatio ?? 1);
|
|
749
|
+
const ratio = Math.min(
|
|
750
|
+
wanted,
|
|
751
|
+
MAX_CANVAS_SIDE / Math.max(1, w),
|
|
752
|
+
MAX_CANVAS_SIDE / Math.max(1, h)
|
|
753
|
+
);
|
|
754
|
+
const bw = Math.max(1, Math.round(w * ratio));
|
|
755
|
+
const bh = Math.max(1, Math.round(h * ratio));
|
|
756
|
+
if (canvas.width !== bw) canvas.width = bw;
|
|
757
|
+
if (canvas.height !== bh) canvas.height = bh;
|
|
758
|
+
canvas.style.width = `${w * options.scale}px`;
|
|
759
|
+
canvas.style.height = `${h * options.scale}px`;
|
|
760
|
+
let cells = 0;
|
|
761
|
+
let drawings = 0;
|
|
762
|
+
for (const pane of layout.panes) {
|
|
763
|
+
cells += pane.cells.length;
|
|
764
|
+
drawings += pane.drawings.length;
|
|
765
|
+
}
|
|
766
|
+
const g = canvas.getContext("2d");
|
|
767
|
+
if (!g) return { cells, texts: 0, drawings, pendingPictures: 0 };
|
|
768
|
+
g.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
769
|
+
g.fillStyle = "#FFFFFF";
|
|
770
|
+
g.fillRect(0, 0, w, h);
|
|
771
|
+
const ctx = {
|
|
772
|
+
g,
|
|
773
|
+
options,
|
|
774
|
+
px: 72 / layout.metrics.pixelsPerInch,
|
|
775
|
+
ratio,
|
|
776
|
+
pending: 0
|
|
777
|
+
};
|
|
778
|
+
if ("fontKerning" in g) g.fontKerning = "none";
|
|
779
|
+
g.textBaseline = "alphabetic";
|
|
780
|
+
let textCount = 0;
|
|
781
|
+
for (const pane of layout.panes) textCount += paintPane(ctx, pane);
|
|
782
|
+
if (options.frozenLines) {
|
|
783
|
+
g.fillStyle = "#808080";
|
|
784
|
+
if (layout.frozenEdges.x !== void 0) g.fillRect(layout.frozenEdges.x, 0, ctx.px, h);
|
|
785
|
+
if (layout.frozenEdges.y !== void 0) g.fillRect(0, layout.frozenEdges.y, w, ctx.px);
|
|
786
|
+
}
|
|
787
|
+
return { cells, texts: textCount, drawings, pendingPictures: ctx.pending };
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/output/accessible-grid.ts
|
|
791
|
+
function cellText(box) {
|
|
792
|
+
if (box.shownText !== void 0) return box.shownText;
|
|
793
|
+
return box.text.lines.map((l) => l.spans.map((s) => s.text).join("")).join(" ");
|
|
794
|
+
}
|
|
795
|
+
function accessibleGrid(doc, layout, labels) {
|
|
796
|
+
const table = doc.createElement("div");
|
|
797
|
+
table.setAttribute("role", "rowgroup");
|
|
798
|
+
table.className = "xlsx-a11y-rows";
|
|
799
|
+
const boxes = layout.panes.flatMap((p) => p.texts).slice().sort((a, b) => a.row - b.row || a.col - b.col);
|
|
800
|
+
let row = null;
|
|
801
|
+
let rowIndex = -1;
|
|
802
|
+
for (const box of boxes) {
|
|
803
|
+
if (box.row !== rowIndex) {
|
|
804
|
+
row = doc.createElement("div");
|
|
805
|
+
row.setAttribute("role", "row");
|
|
806
|
+
row.setAttribute("aria-rowindex", String(box.row + 1));
|
|
807
|
+
table.appendChild(row);
|
|
808
|
+
rowIndex = box.row;
|
|
809
|
+
}
|
|
810
|
+
const cell = doc.createElement("div");
|
|
811
|
+
cell.setAttribute("role", "gridcell");
|
|
812
|
+
cell.setAttribute("aria-colindex", String(box.col + 1));
|
|
813
|
+
cell.setAttribute("data-cell", formatCellRef({ row: box.row, col: box.col }));
|
|
814
|
+
const text = cellText(box);
|
|
815
|
+
if (box.stale) cell.setAttribute("data-stale", "1");
|
|
816
|
+
cell.textContent = !box.stale ? text : text ? labels.staleCell(text) : labels.staleNoResult;
|
|
817
|
+
row.appendChild(cell);
|
|
818
|
+
}
|
|
819
|
+
return table;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// src/output/pictures.ts
|
|
823
|
+
var MAX_PICTURE_PIXELS = 5e7;
|
|
824
|
+
var RASTER_TYPES = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/gif", "image/bmp"]);
|
|
825
|
+
function createPictureStore(pkg, win) {
|
|
826
|
+
const states = /* @__PURE__ */ new Map();
|
|
827
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
828
|
+
let disposed = false;
|
|
829
|
+
const settle = (partName, state) => {
|
|
830
|
+
if (disposed) {
|
|
831
|
+
if (state.kind === "ready") state.bitmap.close();
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
states.set(partName, state);
|
|
835
|
+
for (const l of [...listeners]) l();
|
|
836
|
+
};
|
|
837
|
+
return {
|
|
838
|
+
get(partName, contentType) {
|
|
839
|
+
const known = states.get(partName);
|
|
840
|
+
if (known) return known;
|
|
841
|
+
const type = (contentType ?? "").toLowerCase();
|
|
842
|
+
const bytes = binaryPartOf(pkg, partName);
|
|
843
|
+
let state;
|
|
844
|
+
if (!bytes) state = { kind: "unsupported", reason: "missing-part" };
|
|
845
|
+
else if (!RASTER_TYPES.has(type)) state = { kind: "unsupported", reason: "content-type" };
|
|
846
|
+
else if (!win || typeof win.createImageBitmap !== "function")
|
|
847
|
+
state = { kind: "unsupported", reason: "no-decoder" };
|
|
848
|
+
else {
|
|
849
|
+
const size = imageSize(bytes);
|
|
850
|
+
if (!size) state = { kind: "unsupported", reason: "unknown-size" };
|
|
851
|
+
else if (size.width * size.height > MAX_PICTURE_PIXELS)
|
|
852
|
+
state = { kind: "unsupported", reason: "too-large" };
|
|
853
|
+
else {
|
|
854
|
+
state = { kind: "loading" };
|
|
855
|
+
win.createImageBitmap(new win.Blob([bytes.slice()], { type })).then(
|
|
856
|
+
(bitmap) => settle(partName, { kind: "ready", bitmap }),
|
|
857
|
+
() => settle(partName, { kind: "unsupported", reason: "decode" })
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
states.set(partName, state);
|
|
862
|
+
return state;
|
|
863
|
+
},
|
|
864
|
+
onReady(listener) {
|
|
865
|
+
listeners.add(listener);
|
|
866
|
+
return () => listeners.delete(listener);
|
|
867
|
+
},
|
|
868
|
+
dispose() {
|
|
869
|
+
disposed = true;
|
|
870
|
+
for (const s of states.values()) if (s.kind === "ready") s.bitmap.close();
|
|
871
|
+
states.clear();
|
|
872
|
+
listeners.clear();
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/output/font-faces.ts
|
|
878
|
+
function registerFontFaces(doc, faces) {
|
|
879
|
+
const added = [];
|
|
880
|
+
const loads = [];
|
|
881
|
+
const FontFaceCtor = (doc.defaultView ?? globalThis).FontFace;
|
|
882
|
+
if (typeof FontFaceCtor !== "function" || !doc.fonts)
|
|
883
|
+
return { ready: Promise.resolve(), dispose: () => {
|
|
884
|
+
} };
|
|
885
|
+
for (const f of faces) {
|
|
886
|
+
const face = new FontFaceCtor(f.id, f.bytes.slice().buffer, { weight: "400", style: "normal" });
|
|
887
|
+
loads.push(face.load().catch(() => void 0));
|
|
888
|
+
doc.fonts.add(face);
|
|
889
|
+
added.push(face);
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
ready: Promise.all(loads).then(() => void 0),
|
|
893
|
+
dispose: () => {
|
|
894
|
+
for (const face of added) doc.fonts.delete(face);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export {
|
|
900
|
+
cssColor,
|
|
901
|
+
borderLine,
|
|
902
|
+
fillPaint,
|
|
903
|
+
DEFAULT_GRIDLINE_COLOR,
|
|
904
|
+
MAX_CANVAS_SIDE,
|
|
905
|
+
paintSheet,
|
|
906
|
+
cellText,
|
|
907
|
+
accessibleGrid,
|
|
908
|
+
MAX_PICTURE_PIXELS,
|
|
909
|
+
createPictureStore,
|
|
910
|
+
registerFontFaces
|
|
911
|
+
};
|