MCPcopy Index your code
hub / github.com/simstudioai/sim / getStyleSections

Function getStyleSections

apps/sim/lib/pptx-renderer/renderer/table-renderer.ts:54–135  ·  view source on GitHub ↗

* Get the appropriate style section from a table style for a given cell position. * Priority: specific section > wholeTbl (fallback).

(
  tblStyle: SafeXmlNode,
  rowIdx: number,
  colIdx: number,
  totalRows: number,
  totalCols: number,
  tblPr: SafeXmlNode | undefined
)

Source from the content-addressed store, hash-verified

52 * Priority: specific section > wholeTbl (fallback).
53 */
54function getStyleSections(
55 tblStyle: SafeXmlNode,
56 rowIdx: number,
57 colIdx: number,
58 totalRows: number,
59 totalCols: number,
60 tblPr: SafeXmlNode | undefined
61): SafeXmlNode[] {
62 const sections: SafeXmlNode[] = []
63
64 // Style parts enabled only when tblPr has attribute "1" (or true); per spec default is off.
65 // pptxjs uses attrs only (firstCol === "1"); we also accept child elements for compatibility.
66 const flag = (attrName: string, childName: string): boolean => {
67 if (!tblPr) return false
68 const attr = tblPr.attr(attrName)
69 if (attr !== undefined) return attr === '1' || attr === 'true'
70 const ch = tblPr.child(childName)
71 if (ch.exists()) {
72 const val = ch.attr('val')
73 return val !== '0' && val !== 'false'
74 }
75 return false
76 }
77 const bandRow =
78 tblPr?.attr('bandRow') === '1' ||
79 tblPr?.attr('bandRow') === 'true' ||
80 tblPr?.child('bandRow').exists()
81 const bandCol =
82 tblPr?.attr('bandCol') === '1' ||
83 tblPr?.attr('bandCol') === 'true' ||
84 tblPr?.child('bandCol').exists()
85 const isFirstRow = flag('firstRow', 'firstRow')
86 const isLastRow = flag('lastRow', 'lastRow')
87 const isFirstCol = flag('firstCol', 'firstCol')
88 const isLastCol = flag('lastCol', 'lastCol')
89
90 // wholeTbl is the base (lowest priority)
91 const wholeTbl = tblStyle.child('wholeTbl')
92 if (wholeTbl.exists()) sections.push(wholeTbl)
93
94 // Banding (applied on top of wholeTbl)
95 if (bandRow) {
96 const effectiveRow = isFirstRow ? rowIdx - 1 : rowIdx
97 if (effectiveRow >= 0 && effectiveRow % 2 === 1) {
98 const band = tblStyle.child('band2H')
99 if (band.exists()) sections.push(band)
100 } else if (effectiveRow >= 0 && effectiveRow % 2 === 0) {
101 const band = tblStyle.child('band1H')
102 if (band.exists()) sections.push(band)
103 }
104 }
105
106 if (bandCol) {
107 if (colIdx % 2 === 1) {
108 const band = tblStyle.child('band2V')
109 if (band.exists()) sections.push(band)
110 } else {
111 const band = tblStyle.child('band1V')

Callers 1

renderTableFunction · 0.85

Calls 5

flagFunction · 0.85
attrMethod · 0.80
existsMethod · 0.80
childMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected