Skip to content

Commit d6d0c33

Browse files
refactor-botWscats
authored andcommitted
refactor: complete JS to TypeScript migration for spreadsheet engine
- Convert all 10 source files from JS to TypeScript - Create src/types.ts with 18 interfaces/types (CellStyle, CellBorder, CellValue, etc.) - Add global Window type extensions for WolfTable - Type Canvas2d class with index signature for dynamic proxy methods - Type Area class with RowGetter/ColGetter/RowInfo/ColInfo - Type Range class: fix within() bug (startCode → startCol) - Type Range.empty: fix getter calling rows() as function instead of property - Type Viewport with TableContext interface - Type Table class with all 20+ properties - Type throttle as generic function - Type event handlers with MouseEvent casts - Fix alphabet.ts: parseInt → Math.floor for column index calculation - Use Math.min/Math.max in Range.union() instead of ternary - Add JSDoc documentation to all public APIs - Update tsconfig: allowJs=false
1 parent f7d8b3d commit d6d0c33

File tree

18 files changed

+1350
-1323
lines changed

18 files changed

+1350
-1323
lines changed

src/alphabet.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/alphabet.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/** Column alphabet letters. */
2+
const alphabets: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
3+
4+
/** Convert a zero-based column index to a column letter string (e.g., 0 → 'A', 26 → 'AA'). */
5+
export function stringAt(index: number): string {
6+
let str = '';
7+
let cindex = index;
8+
while (cindex >= alphabets.length) {
9+
cindex /= alphabets.length;
10+
cindex -= 1;
11+
str += alphabets[Math.floor(cindex) % alphabets.length];
12+
}
13+
const last = index % alphabets.length;
14+
str += alphabets[last];
15+
return str;
16+
}
17+
18+
/** Convert a column letter string to a zero-based index (e.g., 'A' → 0, 'AA' → 26). */
19+
export function indexAt(str: string): number {
20+
let ret = 0;
21+
for (let i = 0; i < str.length - 1; i += 1) {
22+
const cindex = str.charCodeAt(i) - 65;
23+
const exponent = str.length - 1 - i;
24+
ret += (alphabets.length ** exponent) + (alphabets.length * cindex);
25+
}
26+
ret += str.charCodeAt(str.length - 1) - 65;
27+
return ret;
28+
}
29+
30+
/** Convert a cell reference (e.g., 'B10') to [colIndex, rowIndex]. */
31+
export function expr2xy(src: string): [number, number] {
32+
let x = '';
33+
let y = '';
34+
for (let i = 0; i < src.length; i += 1) {
35+
if (src.charAt(i) >= '0' && src.charAt(i) <= '9') {
36+
y += src.charAt(i);
37+
} else {
38+
x += src.charAt(i).toUpperCase();
39+
}
40+
}
41+
return [indexAt(x), parseInt(y, 10) - 1];
42+
}
43+
44+
/** Convert [colIndex, rowIndex] to a cell reference (e.g., [1, 9] → 'B10'). */
45+
export function xy2expr(x: number, y: number): string {
46+
return `${stringAt(x)}${y + 1}`;
47+
}
48+
49+
/** Offset a cell reference by (xn, yn). */
50+
export function expr2expr(src: string, xn: number, yn: number): string {
51+
const [x, y] = expr2xy(src);
52+
return xy2expr(x + xn, y + yn);
53+
}
54+
55+
export default {
56+
stringAt,
57+
indexAt,
58+
expr2xy,
59+
xy2expr,
60+
expr2expr,
61+
};

src/area.js

Lines changed: 0 additions & 247 deletions
This file was deleted.

0 commit comments

Comments
 (0)