@@ -2,10 +2,14 @@ type RowElement = HTMLTableRowElement
22type CellElement = HTMLTableHeaderCellElement | HTMLTableCellElement
33
44export function parseTable ( tableElement : HTMLTableElement ) {
5+ return parseCellMatrix ( createCellMatrix ( tableElement ) )
6+ }
7+
8+ export function parseCellMatrix ( cellMatrix : CellElement [ ] [ ] ) {
59 let elementList = [ ]
610 let parsedInfoList = [ ]
711
8- return createCellMatrix ( tableElement ) . map ( ( row , rowIndex ) =>
12+ return cellMatrix . map ( ( row , rowIndex ) =>
913 row . map ( ( cell , colIndex ) => {
1014 let index = elementList . indexOf ( cell )
1115 if ( index === - 1 ) {
@@ -30,13 +34,12 @@ export function parseTable(tableElement: HTMLTableElement) {
3034 )
3135}
3236
33- export function getElementPositionInTable (
34- tableElement : HTMLTableElement ,
37+ export function getElementPositionInCellMatrix (
38+ cellMatrix : CellElement [ ] [ ] ,
3539 cellElement : CellElement
3640) {
37- const matrix = createCellMatrix ( tableElement )
38- for ( let y = 0 ; y < matrix . length ; y ++ ) {
39- const row = matrix [ y ]
41+ for ( let y = 0 ; y < cellMatrix . length ; y ++ ) {
42+ const row = cellMatrix [ y ]
4043 for ( let x = 0 ; x < row . length ; x ++ ) {
4144 if ( row [ x ] === cellElement ) {
4245 return { x, y }
@@ -57,7 +60,9 @@ Normalize table structure considering colspan and rowspan.
5760| | D |
5861+-------+-------+
5962*/
60- function createCellMatrix ( tableElement : HTMLTableElement ) {
63+ export function createCellMatrix (
64+ tableElement : HTMLTableElement
65+ ) : CellElement [ ] [ ] {
6166 const rows = [ tableElement . tHead ]
6267 . concat ( Array . from ( tableElement . tBodies ) )
6368 . concat ( tableElement . tFoot )
0 commit comments