* Apply borders from a table style tcStyle node. * Structure: / / / ...
( td: HTMLElement, tcStyle: SafeXmlNode, ctx: RenderContext, rowIdx?: number, colIdx?: number, totalRows?: number, totalCols?: number )
| 265 | * Structure: <a:tcStyle> <a:tcBdr> <a:top>/<a:bottom>/<a:left>/<a:right> <a:ln>... |
| 266 | */ |
| 267 | function applyStyleBorders( |
| 268 | td: HTMLElement, |
| 269 | tcStyle: SafeXmlNode, |
| 270 | ctx: RenderContext, |
| 271 | rowIdx?: number, |
| 272 | colIdx?: number, |
| 273 | totalRows?: number, |
| 274 | totalCols?: number |
| 275 | ): void { |
| 276 | const tcBdr = tcStyle.child('tcBdr') |
| 277 | if (!tcBdr.exists()) return |
| 278 | |
| 279 | const borderMap: Array<[string, 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight']> = [ |
| 280 | ['top', 'borderTop'], |
| 281 | ['bottom', 'borderBottom'], |
| 282 | ['left', 'borderLeft'], |
| 283 | ['right', 'borderRight'], |
| 284 | ] |
| 285 | |
| 286 | // Map insideH/insideV to individual cell borders: |
| 287 | // insideH → borderBottom for non-last rows, borderTop for non-first rows |
| 288 | // insideV → borderRight for non-last cols, borderLeft for non-first cols |
| 289 | const insideH = tcBdr.child('insideH') |
| 290 | if (insideH.exists() && rowIdx !== undefined && totalRows !== undefined) { |
| 291 | if (rowIdx < totalRows - 1) { |
| 292 | borderMap.push(['insideH', 'borderBottom']) |
| 293 | } |
| 294 | if (rowIdx > 0) { |
| 295 | borderMap.push(['insideH', 'borderTop']) |
| 296 | } |
| 297 | } |
| 298 | const insideV = tcBdr.child('insideV') |
| 299 | if (insideV.exists() && colIdx !== undefined && totalCols !== undefined) { |
| 300 | if (colIdx < totalCols - 1) { |
| 301 | borderMap.push(['insideV', 'borderRight']) |
| 302 | } |
| 303 | if (colIdx > 0) { |
| 304 | borderMap.push(['insideV', 'borderLeft']) |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | for (const [xmlName, cssProp] of borderMap) { |
| 309 | const side = tcBdr.child(xmlName) |
| 310 | if (!side.exists()) continue |
| 311 | |
| 312 | // Direct <a:ln> element |
| 313 | const ln = side.child('ln') |
| 314 | if (ln.exists()) { |
| 315 | const noFill = ln.child('noFill') |
| 316 | if (noFill.exists()) continue |
| 317 | |
| 318 | const style = resolveLineStyle(ln, ctx) |
| 319 | if (style.width > 0 && style.color !== 'transparent') { |
| 320 | td.style[cssProp] = `${Math.max(style.width, 0.5)}px ${style.dash} ${style.color}` |
| 321 | } |
| 322 | continue |
| 323 | } |
| 324 |
no test coverage detected