@deckflow/deckuse 1.4.0 → 1.4.1
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/README.es.md +1 -1
- package/README.fr.md +1 -1
- package/README.ja.md +1 -1
- package/README.ko.md +1 -1
- package/README.md +3 -3
- package/README.pt-BR.md +1 -1
- package/README.ru.md +1 -1
- package/dist/core/schema.d.ts +314 -0
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +75 -0
- package/dist/core/schema.js.map +1 -1
- package/dist/deck2html-exec.d.ts +3 -0
- package/dist/deck2html-exec.d.ts.map +1 -0
- package/dist/deck2html-exec.js +22 -0
- package/dist/deck2html-exec.js.map +1 -0
- package/dist/help.js +3 -3
- package/dist/help.js.map +1 -1
- package/dist/monitor.d.ts +2 -2
- package/dist/monitor.d.ts.map +1 -1
- package/dist/monitor.js +8 -8
- package/dist/monitor.js.map +1 -1
- package/dist/pptx/chart.d.ts +16 -0
- package/dist/pptx/chart.d.ts.map +1 -1
- package/dist/pptx/chart.js +171 -8
- package/dist/pptx/chart.js.map +1 -1
- package/dist/pptx/elements.d.ts +18 -0
- package/dist/pptx/elements.d.ts.map +1 -1
- package/dist/pptx/elements.js +215 -15
- package/dist/pptx/elements.js.map +1 -1
- package/dist/pptx/mutations.d.ts.map +1 -1
- package/dist/pptx/mutations.js +124 -22
- package/dist/pptx/mutations.js.map +1 -1
- package/dist/pptx/properties.d.ts.map +1 -1
- package/dist/pptx/properties.js +113 -2
- package/dist/pptx/properties.js.map +1 -1
- package/dist/pptx/shape-presets.d.ts +11 -0
- package/dist/pptx/shape-presets.d.ts.map +1 -0
- package/dist/pptx/shape-presets.js +199 -0
- package/dist/pptx/shape-presets.js.map +1 -0
- package/dist/pptx/table-measure.d.ts +8 -0
- package/dist/pptx/table-measure.d.ts.map +1 -1
- package/dist/pptx/table-measure.js +28 -6
- package/dist/pptx/table-measure.js.map +1 -1
- package/dist/pptx/table.d.ts +6 -0
- package/dist/pptx/table.d.ts.map +1 -1
- package/dist/pptx/table.js +183 -3
- package/dist/pptx/table.js.map +1 -1
- package/dist/pptx/xml.d.ts +14 -1
- package/dist/pptx/xml.d.ts.map +1 -1
- package/dist/pptx/xml.js +82 -3
- package/dist/pptx/xml.js.map +1 -1
- package/dist/render.d.ts +3 -3
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +9 -9
- package/dist/render.js.map +1 -1
- package/package.json +25 -21
- package/schema/command.schema.json +346 -136
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OOXML ST_ShapeType values commonly used in consulting decks, plus a broad
|
|
3
|
+
* whitelist so agents can pass any ECMA-376 preset through `shapeType: "preset"`.
|
|
4
|
+
*/
|
|
5
|
+
export const ST_SHAPE_TYPES = [
|
|
6
|
+
'accentBorderCallout1',
|
|
7
|
+
'accentBorderCallout2',
|
|
8
|
+
'accentBorderCallout3',
|
|
9
|
+
'accentCallout1',
|
|
10
|
+
'accentCallout2',
|
|
11
|
+
'accentCallout3',
|
|
12
|
+
'actionButtonBackPrevious',
|
|
13
|
+
'actionButtonBeginning',
|
|
14
|
+
'actionButtonBlank',
|
|
15
|
+
'actionButtonDocument',
|
|
16
|
+
'actionButtonEnd',
|
|
17
|
+
'actionButtonForwardNext',
|
|
18
|
+
'actionButtonHelp',
|
|
19
|
+
'actionButtonHome',
|
|
20
|
+
'actionButtonInformation',
|
|
21
|
+
'actionButtonMovie',
|
|
22
|
+
'actionButtonReturn',
|
|
23
|
+
'actionButtonSound',
|
|
24
|
+
'arc',
|
|
25
|
+
'bentArrow',
|
|
26
|
+
'bentConnector2',
|
|
27
|
+
'bentConnector3',
|
|
28
|
+
'bentConnector4',
|
|
29
|
+
'bentConnector5',
|
|
30
|
+
'bentUpArrow',
|
|
31
|
+
'bevel',
|
|
32
|
+
'blockArc',
|
|
33
|
+
'borderCallout1',
|
|
34
|
+
'borderCallout2',
|
|
35
|
+
'borderCallout3',
|
|
36
|
+
'bracePair',
|
|
37
|
+
'bracketPair',
|
|
38
|
+
'callout1',
|
|
39
|
+
'callout2',
|
|
40
|
+
'callout3',
|
|
41
|
+
'can',
|
|
42
|
+
'chartPlus',
|
|
43
|
+
'chartStar',
|
|
44
|
+
'chartX',
|
|
45
|
+
'chevron',
|
|
46
|
+
'chord',
|
|
47
|
+
'circularArrow',
|
|
48
|
+
'cloud',
|
|
49
|
+
'cloudCallout',
|
|
50
|
+
'corner',
|
|
51
|
+
'cornerTabs',
|
|
52
|
+
'cube',
|
|
53
|
+
'curvedConnector2',
|
|
54
|
+
'curvedConnector3',
|
|
55
|
+
'curvedConnector4',
|
|
56
|
+
'curvedConnector5',
|
|
57
|
+
'curvedDownArrow',
|
|
58
|
+
'curvedLeftArrow',
|
|
59
|
+
'curvedRightArrow',
|
|
60
|
+
'curvedUpArrow',
|
|
61
|
+
'decagon',
|
|
62
|
+
'diagStripe',
|
|
63
|
+
'diamond',
|
|
64
|
+
'dodecagon',
|
|
65
|
+
'donut',
|
|
66
|
+
'doubleWave',
|
|
67
|
+
'downArrow',
|
|
68
|
+
'downArrowCallout',
|
|
69
|
+
'ellipse',
|
|
70
|
+
'ellipseRibbon',
|
|
71
|
+
'ellipseRibbon2',
|
|
72
|
+
'flowChartAlternateProcess',
|
|
73
|
+
'flowChartCollate',
|
|
74
|
+
'flowChartConnector',
|
|
75
|
+
'flowChartDecision',
|
|
76
|
+
'flowChartDelay',
|
|
77
|
+
'flowChartDisplay',
|
|
78
|
+
'flowChartDocument',
|
|
79
|
+
'flowChartExtract',
|
|
80
|
+
'flowChartInputOutput',
|
|
81
|
+
'flowChartInternalStorage',
|
|
82
|
+
'flowChartMagneticDisk',
|
|
83
|
+
'flowChartMagneticDrum',
|
|
84
|
+
'flowChartMagneticTape',
|
|
85
|
+
'flowChartManualInput',
|
|
86
|
+
'flowChartManualOperation',
|
|
87
|
+
'flowChartMerge',
|
|
88
|
+
'flowChartMultidocument',
|
|
89
|
+
'flowChartOfflineStorage',
|
|
90
|
+
'flowChartOffpageConnector',
|
|
91
|
+
'flowChartOnlineStorage',
|
|
92
|
+
'flowChartOr',
|
|
93
|
+
'flowChartPredefinedProcess',
|
|
94
|
+
'flowChartPreparation',
|
|
95
|
+
'flowChartProcess',
|
|
96
|
+
'flowChartPunchedCard',
|
|
97
|
+
'flowChartPunchedTape',
|
|
98
|
+
'flowChartSort',
|
|
99
|
+
'flowChartSummingJunction',
|
|
100
|
+
'flowChartTerminator',
|
|
101
|
+
'foldedCorner',
|
|
102
|
+
'frame',
|
|
103
|
+
'funnel',
|
|
104
|
+
'gear6',
|
|
105
|
+
'gear9',
|
|
106
|
+
'halfFrame',
|
|
107
|
+
'heart',
|
|
108
|
+
'heptagon',
|
|
109
|
+
'hexagon',
|
|
110
|
+
'homePlate',
|
|
111
|
+
'horizontalScroll',
|
|
112
|
+
'irregularSeal1',
|
|
113
|
+
'irregularSeal2',
|
|
114
|
+
'leftArrow',
|
|
115
|
+
'leftArrowCallout',
|
|
116
|
+
'leftBrace',
|
|
117
|
+
'leftBracket',
|
|
118
|
+
'leftCircularArrow',
|
|
119
|
+
'leftRightArrow',
|
|
120
|
+
'leftRightArrowCallout',
|
|
121
|
+
'leftRightCircularArrow',
|
|
122
|
+
'leftRightRibbon',
|
|
123
|
+
'leftRightUpArrow',
|
|
124
|
+
'leftUpArrow',
|
|
125
|
+
'lightningBolt',
|
|
126
|
+
'line',
|
|
127
|
+
'lineInv',
|
|
128
|
+
'mathDivide',
|
|
129
|
+
'mathEqual',
|
|
130
|
+
'mathMinus',
|
|
131
|
+
'mathMultiply',
|
|
132
|
+
'mathNotEqual',
|
|
133
|
+
'mathPlus',
|
|
134
|
+
'moon',
|
|
135
|
+
'nonIsoscelesTrapezoid',
|
|
136
|
+
'noSmoking',
|
|
137
|
+
'notchedRightArrow',
|
|
138
|
+
'octagon',
|
|
139
|
+
'parallelogram',
|
|
140
|
+
'pentagon',
|
|
141
|
+
'pie',
|
|
142
|
+
'pieWedge',
|
|
143
|
+
'plaque',
|
|
144
|
+
'plaqueTabs',
|
|
145
|
+
'plus',
|
|
146
|
+
'quadArrow',
|
|
147
|
+
'quadArrowCallout',
|
|
148
|
+
'rect',
|
|
149
|
+
'ribbon',
|
|
150
|
+
'ribbon2',
|
|
151
|
+
'rightArrow',
|
|
152
|
+
'rightArrowCallout',
|
|
153
|
+
'rightBrace',
|
|
154
|
+
'rightBracket',
|
|
155
|
+
'rtTriangle',
|
|
156
|
+
'smileyFace',
|
|
157
|
+
'snip1Rect',
|
|
158
|
+
'snip2DiagRect',
|
|
159
|
+
'snip2SameRect',
|
|
160
|
+
'snipRoundRect',
|
|
161
|
+
'squareTabs',
|
|
162
|
+
'star10',
|
|
163
|
+
'star12',
|
|
164
|
+
'star16',
|
|
165
|
+
'star24',
|
|
166
|
+
'star32',
|
|
167
|
+
'star4',
|
|
168
|
+
'star5',
|
|
169
|
+
'star6',
|
|
170
|
+
'star7',
|
|
171
|
+
'star8',
|
|
172
|
+
'straightConnector1',
|
|
173
|
+
'stripedRightArrow',
|
|
174
|
+
'sun',
|
|
175
|
+
'swooshArrow',
|
|
176
|
+
'teardrop',
|
|
177
|
+
'trapezoid',
|
|
178
|
+
'triangle',
|
|
179
|
+
'upArrow',
|
|
180
|
+
'upArrowCallout',
|
|
181
|
+
'upDownArrow',
|
|
182
|
+
'upDownArrowCallout',
|
|
183
|
+
'uturnArrow',
|
|
184
|
+
'verticalScroll',
|
|
185
|
+
'wave',
|
|
186
|
+
'wedgeEllipseCallout',
|
|
187
|
+
'wedgeRectCallout',
|
|
188
|
+
'wedgeRoundRectCallout',
|
|
189
|
+
];
|
|
190
|
+
export const ST_SHAPE_TYPE_SET = new Set(ST_SHAPE_TYPES);
|
|
191
|
+
export const isStShapeType = (value) => ST_SHAPE_TYPE_SET.has(value);
|
|
192
|
+
/** Harvey-ball fill fraction → pie adj (OOXML guide, 0–21600000 = full circle). */
|
|
193
|
+
export const harveyBallPieAdj = (value) => {
|
|
194
|
+
// Empty / full use ellipse; pie adj for partial fills: remaining unfilled arc.
|
|
195
|
+
const filled = value;
|
|
196
|
+
const unfilledFraction = 1 - filled;
|
|
197
|
+
return Math.round(unfilledFraction * 21_600_000);
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=shape-presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape-presets.js","sourceRoot":"","sources":["../../src/pptx/shape-presets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,sBAAsB;IACtB,sBAAsB;IACtB,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,0BAA0B;IAC1B,uBAAuB;IACvB,mBAAmB;IACnB,sBAAsB;IACtB,iBAAiB;IACjB,yBAAyB;IACzB,kBAAkB;IAClB,kBAAkB;IAClB,yBAAyB;IACzB,mBAAmB;IACnB,oBAAoB;IACpB,mBAAmB;IACnB,KAAK;IACL,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,OAAO;IACP,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,WAAW;IACX,aAAa;IACb,UAAU;IACV,UAAU;IACV,UAAU;IACV,KAAK;IACL,WAAW;IACX,WAAW;IACX,QAAQ;IACR,SAAS;IACT,OAAO;IACP,eAAe;IACf,OAAO;IACP,cAAc;IACd,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,kBAAkB;IAClB,eAAe;IACf,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,OAAO;IACP,YAAY;IACZ,WAAW;IACX,kBAAkB;IAClB,SAAS;IACT,eAAe;IACf,gBAAgB;IAChB,2BAA2B;IAC3B,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB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,KAAK;IACL,aAAa;IACb,UAAU;IACV,WAAW;IACX,UAAU;IACV,SAAS;IACT,gBAAgB;IAChB,aAAa;IACb,oBAAoB;IACpB,YAAY;IACZ,gBAAgB;IAChB,MAAM;IACN,qBAAqB;IACrB,kBAAkB;IAClB,uBAAuB;CACf,CAAC;AAIX,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,cAAc,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAa,EAAwB,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAEnG,mFAAmF;AACnF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAgC,EAAU,EAAE;IAC3E,+EAA+E;IAC/E,MAAM,MAAM,GAAG,KAAK,CAAC;IACrB,MAAM,gBAAgB,GAAG,CAAC,GAAG,MAAM,CAAC;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,UAAU,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -15,11 +15,19 @@ export interface TableMeasureInput {
|
|
|
15
15
|
readonly fontPt?: number;
|
|
16
16
|
/** When true, row 0 uses bold glyph widths. */
|
|
17
17
|
readonly headerBold?: boolean;
|
|
18
|
+
/** Per-column widths in EMU; defaults to equal split of widthEmu. */
|
|
19
|
+
readonly colWidthsEmu?: readonly number[];
|
|
20
|
+
/** Optional per-cell font overrides: [row][col] → { fontPt?, bold? }. */
|
|
21
|
+
readonly cellStyles?: readonly (readonly ({
|
|
22
|
+
fontPt?: number;
|
|
23
|
+
bold?: boolean;
|
|
24
|
+
} | undefined)[])[];
|
|
18
25
|
}
|
|
19
26
|
export interface TableMeasureResult {
|
|
20
27
|
readonly rowHeightsEmu: readonly number[];
|
|
21
28
|
readonly totalHeightEmu: number;
|
|
22
29
|
readonly colWidthEmu: number;
|
|
30
|
+
readonly colWidthsEmu: readonly number[];
|
|
23
31
|
readonly cols: number;
|
|
24
32
|
}
|
|
25
33
|
/** Minimum single-line row height including vertical padding and borders. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-measure.d.ts","sourceRoot":"","sources":["../../src/pptx/table-measure.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,0EAA0E;AAC1E,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAC3C,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IAC9C,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"table-measure.d.ts","sourceRoot":"","sources":["../../src/pptx/table-measure.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,0EAA0E;AAC1E,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAC3C,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AACxC,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IAC9C,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;I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gB,gBAAgB,CAAC,KAAK,EAAE;IACtC,oBAAoB,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,gBAAgB,CA2CnB;AAED,eAAO,MAAM,4BAA4B,GAAI,OAAO;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,KAAG;IACF,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAUjC,CAAC"}
|
|
@@ -16,6 +16,9 @@ export const estimateTableRowHeightEmu = (fontPt = TABLE_DEFAULT_FONT_PT) => {
|
|
|
16
16
|
};
|
|
17
17
|
/** Empty-cell fallback: rowCount × single-line row height (no wrap). */
|
|
18
18
|
export const estimateTableHeightEmu = (rowCount, fontPt = TABLE_DEFAULT_FONT_PT) => Math.round(Math.max(1, rowCount) * estimateTableRowHeightEmu(fontPt) * TABLE_HEIGHT_SAFETY);
|
|
19
|
+
/** CJK characters are typically wider than Latin in our heuristic; bump slightly. */
|
|
20
|
+
const CJK_WIDTH_FACTOR = 1.05;
|
|
21
|
+
const hasCjk = (text) => /[\u3400-\u9FFF\uF900-\uFAFF]/.test(text);
|
|
19
22
|
/**
|
|
20
23
|
* Per-row height from content wrap heuristics (measureText + cell padding/borders).
|
|
21
24
|
*/
|
|
@@ -24,8 +27,14 @@ export function measureTableLayout(input) {
|
|
|
24
27
|
const rows = input.rows.length > 0 ? input.rows : [['']];
|
|
25
28
|
const cols = Math.max(1, ...rows.map((r) => r.length));
|
|
26
29
|
const widthEmu = Math.max(1, input.widthEmu);
|
|
27
|
-
const
|
|
28
|
-
const
|
|
30
|
+
const equalCol = Math.floor(widthEmu / cols);
|
|
31
|
+
const colWidthsEmu = input.colWidthsEmu && input.colWidthsEmu.length === cols
|
|
32
|
+
? [...input.colWidthsEmu]
|
|
33
|
+
: Array.from({ length: cols }, () => equalCol);
|
|
34
|
+
if (colWidthsEmu.length > 0 && !input.colWidthsEmu) {
|
|
35
|
+
const sum = colWidthsEmu.reduce((a, b) => a + b, 0);
|
|
36
|
+
colWidthsEmu[colWidthsEmu.length - 1] += widthEmu - sum;
|
|
37
|
+
}
|
|
29
38
|
const headerBold = input.headerBold !== false;
|
|
30
39
|
const minRow = estimateTableRowHeightEmu(fontPt);
|
|
31
40
|
const rowHeightsEmu = rows.map((row, rowIndex) => {
|
|
@@ -33,11 +42,18 @@ export function measureTableLayout(input) {
|
|
|
33
42
|
for (let c = 0; c < cols; c++) {
|
|
34
43
|
const raw = row[c];
|
|
35
44
|
const text = typeof raw === 'string' ? raw : '';
|
|
45
|
+
const style = input.cellStyles?.[rowIndex]?.[c];
|
|
46
|
+
const cellFont = style?.fontPt ?? fontPt;
|
|
47
|
+
const cellBold = style?.bold ?? (headerBold && rowIndex === 0);
|
|
48
|
+
const colW = colWidthsEmu[c] ?? equalCol;
|
|
49
|
+
const contentWidthEmu = Math.max(1, colW - TABLE_CELL_PAD_X_EMU * 2 - TABLE_CELL_BORDER_EMU * 2);
|
|
36
50
|
const measured = measureText({
|
|
37
51
|
text: text.length > 0 ? text : ' ',
|
|
38
|
-
fontSize:
|
|
39
|
-
bold:
|
|
40
|
-
maxWidthEmu:
|
|
52
|
+
fontSize: cellFont,
|
|
53
|
+
bold: cellBold,
|
|
54
|
+
maxWidthEmu: hasCjk(text)
|
|
55
|
+
? Math.max(1, Math.floor(contentWidthEmu / CJK_WIDTH_FACTOR))
|
|
56
|
+
: contentWidthEmu,
|
|
41
57
|
});
|
|
42
58
|
const cellH = measured.heightEmu + TABLE_CELL_PAD_Y_EMU * 2 + TABLE_CELL_BORDER_EMU * 2;
|
|
43
59
|
maxCell = Math.max(maxCell, cellH);
|
|
@@ -55,7 +71,13 @@ export function measureTableLayout(input) {
|
|
|
55
71
|
rowHeightsEmu[rowHeightsEmu.length - 1] = Math.max(1, last + delta);
|
|
56
72
|
}
|
|
57
73
|
}
|
|
58
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
rowHeightsEmu,
|
|
76
|
+
totalHeightEmu,
|
|
77
|
+
colWidthEmu: colWidthsEmu[0] ?? equalCol,
|
|
78
|
+
colWidthsEmu,
|
|
79
|
+
cols,
|
|
80
|
+
};
|
|
59
81
|
}
|
|
60
82
|
/**
|
|
61
83
|
* Fit content row heights to a frame.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-measure.js","sourceRoot":"","sources":["../../src/pptx/table-measure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3D,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,yDAAyD;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,kDAAkD;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"table-measure.js","sourceRoot":"","sources":["../../src/pptx/table-measure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3D,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,yDAAyD;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,kDAAkD;AAClD,MAA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AM,CAAC,MAAM,4BAA4B,GAAG,CAAC,KAI5C,EAKC,EAAE,CAAC,CAAC;IACJ,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,uBAAuB;IAC7B,OAAO,EAAE,gBAAgB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,0CAA0C,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,4BAA4B;IAC/I,OAAO,EAAE;QACP,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE;CACF,CAAC,CAAC"}
|
package/dist/pptx/table.d.ts
CHANGED
|
@@ -9,12 +9,18 @@ export declare function deleteTableRow(node: Element, spec: unknown): void;
|
|
|
9
9
|
export declare function insertTableColumn(node: Element, spec: unknown): void;
|
|
10
10
|
export declare function deleteTableColumn(node: Element, spec: unknown): void;
|
|
11
11
|
export declare function setTableCellFill(cell: Element, value: unknown): void;
|
|
12
|
+
/** Remeasure table row heights after cell content/style changes. */
|
|
13
|
+
export declare function remeasureTableAfterCellChange(graphicFrame: Element): {
|
|
14
|
+
diagnostics: Diagnostic[];
|
|
15
|
+
grew: boolean;
|
|
16
|
+
};
|
|
12
17
|
export declare function applyTableProperties(node: Element, properties: Record<string, unknown>, context?: ShapePropertyContext): Result<{
|
|
13
18
|
applied: string[];
|
|
14
19
|
diagnostics: Diagnostic[];
|
|
15
20
|
}>;
|
|
16
21
|
export declare function applyTableCellProperties(node: Element, properties: Record<string, unknown>): Result<{
|
|
17
22
|
applied: string[];
|
|
23
|
+
diagnostics: Diagnostic[];
|
|
18
24
|
}>;
|
|
19
25
|
export declare function applyTableLayout(graphicFrame: Element, options: {
|
|
20
26
|
height?: 'auto' | number;
|
package/dist/pptx/table.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/pptx/table.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/pptx/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEf,KAAK,MAAM,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAkJ5B,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,GAC9B,cAAc,OAAO,EACrB,UAAU,oBAAoB,KAC7B,UAAU,EAkCZ,CAAC;AAwDF,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CA+BjE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAQjE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CA+BpE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAmBpE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CA4BpE;AA2ND,oEAAoE;AACpE,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,OAAO,GAAG;IACpE,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;CACf,CAwDA;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,CAAC;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CAoF1D;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,MAAM,CAAC;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC,CA8D1D;AAmBD,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,OAAO,EACrB,OAAO,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC,GACA,MAAM,CAAC;IACR,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC,CAuED"}
|
package/dist/pptx/table.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { err, ok } from '../core/index.js';
|
|
1
|
+
import { err, ok, parseLength, } from '../core/index.js';
|
|
2
2
|
import { applyShapeProperties, shapePropertyKeys, } from './properties.js';
|
|
3
3
|
import { readSlideSize } from './slide-size.js';
|
|
4
|
-
import { estimateTableHeightEmu, estimateTableRowHeightEmu, layoutTableFrame, measureTableLayout, } from './table-measure.js';
|
|
4
|
+
import { estimateTableHeightEmu, estimateTableRowHeightEmu, layoutTableFrame, measureTableLayout, tableHeightMayClipDiagnostic, } from './table-measure.js';
|
|
5
5
|
import { NS, attr, children, descendants, first, setNodeText } from './xml.js';
|
|
6
6
|
const DEFAULT_ROW_H = '370840';
|
|
7
7
|
const DEFAULT_COL_W = '914400';
|
|
@@ -443,6 +443,7 @@ const TABLE_STRUCTURAL_KEYS = new Set([
|
|
|
443
443
|
'deleteColumn',
|
|
444
444
|
'text',
|
|
445
445
|
'name',
|
|
446
|
+
'columnWidths',
|
|
446
447
|
]);
|
|
447
448
|
const TABLE_CELL_STROKE_ALIASES = ['stroke', 'border', 'outline', 'line'];
|
|
448
449
|
const TABLE_CELL_PADDING_KEYS = [
|
|
@@ -472,6 +473,7 @@ const TABLE_CELL_KEYS = new Set([
|
|
|
472
473
|
'text',
|
|
473
474
|
'fill',
|
|
474
475
|
'paragraph.align',
|
|
476
|
+
'merge',
|
|
475
477
|
...TABLE_CELL_STROKE_ALIASES,
|
|
476
478
|
...TABLE_CELL_PADDING_KEYS,
|
|
477
479
|
...TABLE_CELL_FONT_KEYS,
|
|
@@ -491,6 +493,167 @@ const setTableCellPadding = (cell, properties) => {
|
|
|
491
493
|
}
|
|
492
494
|
return applied;
|
|
493
495
|
};
|
|
496
|
+
const applyTableColumnWidths = (graphicFrame, raw) => {
|
|
497
|
+
const tbl = tblOf(graphicFrame);
|
|
498
|
+
const doc = graphicFrame.ownerDocument;
|
|
499
|
+
if (!doc)
|
|
500
|
+
throw new Error('Element has no document');
|
|
501
|
+
let grid = first(tbl, 'tblGrid');
|
|
502
|
+
if (!grid) {
|
|
503
|
+
grid = doc.createElementNS(NS.a, 'a:tblGrid');
|
|
504
|
+
const firstRow = directChildren(tbl, 'tr')[0];
|
|
505
|
+
if (firstRow)
|
|
506
|
+
tbl.insertBefore(grid, firstRow);
|
|
507
|
+
else
|
|
508
|
+
tbl.appendChild(grid);
|
|
509
|
+
}
|
|
510
|
+
const existing = directChildren(grid, 'gridCol');
|
|
511
|
+
const cols = existing.length ||
|
|
512
|
+
Math.max(1, ...directChildren(tbl, 'tr').map((r) => directChildren(r, 'tc').length));
|
|
513
|
+
const widthEmu = tableWidthEmu(graphicFrame);
|
|
514
|
+
if (!Array.isArray(raw))
|
|
515
|
+
throw new Error('columnWidths must be an array');
|
|
516
|
+
const widths = [];
|
|
517
|
+
for (let i = 0; i < cols; i++) {
|
|
518
|
+
const entry = raw[i];
|
|
519
|
+
if (entry === undefined) {
|
|
520
|
+
widths.push(Math.floor(widthEmu / cols));
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (typeof entry === 'string' && entry.trim().endsWith('%')) {
|
|
524
|
+
const pct = Number(entry.trim().replace(/%$/, ''));
|
|
525
|
+
if (!Number.isFinite(pct))
|
|
526
|
+
throw new Error(`Invalid columnWidths[%]: ${entry}`);
|
|
527
|
+
widths.push(Math.round((pct / 100) * widthEmu));
|
|
528
|
+
}
|
|
529
|
+
else if (typeof entry === 'number' || typeof entry === 'string') {
|
|
530
|
+
widths.push(parseLength(entry, { axis: 'x' }));
|
|
531
|
+
}
|
|
532
|
+
else
|
|
533
|
+
throw new Error('columnWidths entries must be lengths or percentages');
|
|
534
|
+
}
|
|
535
|
+
const sum = widths.reduce((a, b) => a + b, 0);
|
|
536
|
+
if (sum <= 0)
|
|
537
|
+
throw new Error('columnWidths sum must be positive');
|
|
538
|
+
const scaled = sum === widthEmu ? widths : widths.map((w) => Math.max(1, Math.round((w / sum) * widthEmu)));
|
|
539
|
+
if (sum !== widthEmu) {
|
|
540
|
+
const scaledSum = scaled.reduce((a, b) => a + b, 0);
|
|
541
|
+
scaled[scaled.length - 1] += widthEmu - scaledSum;
|
|
542
|
+
}
|
|
543
|
+
for (let i = 0; i < cols; i++) {
|
|
544
|
+
let col = existing[i];
|
|
545
|
+
if (!col) {
|
|
546
|
+
col = doc.createElementNS(NS.a, 'a:gridCol');
|
|
547
|
+
grid.appendChild(col);
|
|
548
|
+
}
|
|
549
|
+
col.setAttribute('w', String(scaled[i]));
|
|
550
|
+
}
|
|
551
|
+
// Drop extra columns if widths array shrank (rare).
|
|
552
|
+
for (const extra of existing.slice(cols))
|
|
553
|
+
grid.removeChild(extra);
|
|
554
|
+
};
|
|
555
|
+
const applyCellMerge = (cell, merge) => {
|
|
556
|
+
if (typeof merge !== 'object' || merge === null)
|
|
557
|
+
throw new Error('merge must be an object');
|
|
558
|
+
const rec = merge;
|
|
559
|
+
if (typeof rec['gridSpan'] === 'number' &&
|
|
560
|
+
Number.isInteger(rec['gridSpan']) &&
|
|
561
|
+
rec['gridSpan'] > 1)
|
|
562
|
+
cell.setAttribute('gridSpan', String(rec['gridSpan']));
|
|
563
|
+
else if (rec['gridSpan'] === null || rec['gridSpan'] === 1)
|
|
564
|
+
cell.removeAttribute('gridSpan');
|
|
565
|
+
if (typeof rec['rowSpan'] === 'number' && Number.isInteger(rec['rowSpan']) && rec['rowSpan'] > 1)
|
|
566
|
+
cell.setAttribute('rowSpan', String(rec['rowSpan']));
|
|
567
|
+
else if (rec['rowSpan'] === null || rec['rowSpan'] === 1)
|
|
568
|
+
cell.removeAttribute('rowSpan');
|
|
569
|
+
if (rec['hMerge'] === true)
|
|
570
|
+
cell.setAttribute('hMerge', '1');
|
|
571
|
+
else if (rec['hMerge'] === false || rec['hMerge'] === null)
|
|
572
|
+
cell.removeAttribute('hMerge');
|
|
573
|
+
if (rec['vMerge'] === true)
|
|
574
|
+
cell.setAttribute('vMerge', '1');
|
|
575
|
+
else if (rec['vMerge'] === false || rec['vMerge'] === null)
|
|
576
|
+
cell.removeAttribute('vMerge');
|
|
577
|
+
};
|
|
578
|
+
const findGraphicFrame = (node) => {
|
|
579
|
+
let current = node;
|
|
580
|
+
while (current) {
|
|
581
|
+
if (current.localName === 'graphicFrame')
|
|
582
|
+
return current;
|
|
583
|
+
current = current.parentNode;
|
|
584
|
+
}
|
|
585
|
+
return undefined;
|
|
586
|
+
};
|
|
587
|
+
const readCellFontPt = (tc) => {
|
|
588
|
+
const rPr = first(tc, 'rPr');
|
|
589
|
+
const sz = attr(rPr, 'sz');
|
|
590
|
+
if (sz === undefined)
|
|
591
|
+
return undefined;
|
|
592
|
+
const n = Number(sz) / 100;
|
|
593
|
+
return Number.isFinite(n) ? n : undefined;
|
|
594
|
+
};
|
|
595
|
+
const readCellBold = (tc) => {
|
|
596
|
+
const rPr = first(tc, 'rPr');
|
|
597
|
+
const b = attr(rPr, 'b');
|
|
598
|
+
return b === '1' || b === 'true';
|
|
599
|
+
};
|
|
600
|
+
/** Remeasure table row heights after cell content/style changes. */
|
|
601
|
+
export function remeasureTableAfterCellChange(graphicFrame) {
|
|
602
|
+
const tbl = first(graphicFrame, 'tbl');
|
|
603
|
+
if (!tbl)
|
|
604
|
+
return { diagnostics: [], grew: false };
|
|
605
|
+
const rows = directChildren(tbl, 'tr');
|
|
606
|
+
if (rows.length === 0)
|
|
607
|
+
return { diagnostics: [], grew: false };
|
|
608
|
+
const widthEmu = tableWidthEmu(graphicFrame);
|
|
609
|
+
const gridCols = descendants(graphicFrame, 'gridCol');
|
|
610
|
+
const colWidthsEmu = gridCols.length > 0
|
|
611
|
+
? gridCols.map((col) => Number(attr(col, 'w') ?? Math.floor(widthEmu / gridCols.length)))
|
|
612
|
+
: undefined;
|
|
613
|
+
const textRows = rows.map((tr) => directChildren(tr, 'tc').map((tc) => cellPlainText(tc)));
|
|
614
|
+
const cellStyles = rows.map((tr) => directChildren(tr, 'tc').map((tc) => {
|
|
615
|
+
const fontPt = readCellFontPt(tc);
|
|
616
|
+
const bold = readCellBold(tc);
|
|
617
|
+
return {
|
|
618
|
+
...(fontPt !== undefined ? { fontPt } : {}),
|
|
619
|
+
...(bold ? { bold: true } : {}),
|
|
620
|
+
};
|
|
621
|
+
}));
|
|
622
|
+
const measured = measureTableLayout({
|
|
623
|
+
rows: textRows,
|
|
624
|
+
widthEmu,
|
|
625
|
+
fontPt: 11,
|
|
626
|
+
...(colWidthsEmu ? { colWidthsEmu } : {}),
|
|
627
|
+
cellStyles,
|
|
628
|
+
});
|
|
629
|
+
const xfrm = first(graphicFrame, 'xfrm');
|
|
630
|
+
const ext = xfrm ? first(xfrm, 'ext') : undefined;
|
|
631
|
+
const currentCy = Number(attr(ext, 'cy') ?? 0);
|
|
632
|
+
// Auto-like: frame was previously sized to content (±20% of measured).
|
|
633
|
+
// A much shorter fixed frame must NOT be grown — emit TABLE_HEIGHT_MAY_CLIP instead.
|
|
634
|
+
const ratio = currentCy / Math.max(measured.totalHeightEmu, 1);
|
|
635
|
+
const wasContentSized = currentCy > 0 && ratio >= 0.8 && ratio <= 1.25;
|
|
636
|
+
const diagnostics = [];
|
|
637
|
+
let grew = false;
|
|
638
|
+
if (wasContentSized || currentCy <= 0) {
|
|
639
|
+
for (let i = 0; i < rows.length; i++) {
|
|
640
|
+
const h = measured.rowHeightsEmu[i] ?? estimateTableRowHeightEmu(11);
|
|
641
|
+
rows[i].setAttribute('h', String(h));
|
|
642
|
+
}
|
|
643
|
+
if (ext) {
|
|
644
|
+
if (measured.totalHeightEmu > currentCy)
|
|
645
|
+
grew = true;
|
|
646
|
+
ext.setAttribute('cy', String(measured.totalHeightEmu));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
else if (measured.totalHeightEmu > currentCy * 1.1) {
|
|
650
|
+
diagnostics.push(tableHeightMayClipDiagnostic({
|
|
651
|
+
estimatedEmu: measured.totalHeightEmu,
|
|
652
|
+
givenEmu: currentCy,
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
655
|
+
return { diagnostics, grew };
|
|
656
|
+
}
|
|
494
657
|
export function applyTableProperties(node, properties, context) {
|
|
495
658
|
const structural = {};
|
|
496
659
|
const visual = {};
|
|
@@ -542,6 +705,10 @@ export function applyTableProperties(node, properties, context) {
|
|
|
542
705
|
}
|
|
543
706
|
else if (structural['name'] !== undefined)
|
|
544
707
|
throw new Error('name must be a string');
|
|
708
|
+
if ('columnWidths' in structural) {
|
|
709
|
+
applyTableColumnWidths(node, structural['columnWidths']);
|
|
710
|
+
applied.push('columnWidths');
|
|
711
|
+
}
|
|
545
712
|
// Table fill/line map onto cells — graphicFrame has no spPr.
|
|
546
713
|
if ('fill' in visual) {
|
|
547
714
|
const cells = tableCells(node);
|
|
@@ -584,6 +751,7 @@ export function applyTableCellProperties(node, properties) {
|
|
|
584
751
|
if (unexpected.length)
|
|
585
752
|
return err('INVALID_COMMAND', `Unsupported tableCell setProperties keys: ${unexpected.join(', ')}`);
|
|
586
753
|
const applied = [];
|
|
754
|
+
const diagnostics = [];
|
|
587
755
|
try {
|
|
588
756
|
if (typeof properties['text'] === 'string') {
|
|
589
757
|
setNodeText(node, properties['text']);
|
|
@@ -603,6 +771,10 @@ export function applyTableCellProperties(node, properties) {
|
|
|
603
771
|
applied.push(strokeKeys[0]);
|
|
604
772
|
}
|
|
605
773
|
applied.push(...setTableCellPadding(node, properties));
|
|
774
|
+
if ('merge' in properties) {
|
|
775
|
+
applyCellMerge(node, properties['merge']);
|
|
776
|
+
applied.push('merge');
|
|
777
|
+
}
|
|
606
778
|
const styleProps = {};
|
|
607
779
|
if ('paragraph.align' in properties)
|
|
608
780
|
styleProps['paragraph.align'] = properties['paragraph.align'];
|
|
@@ -616,11 +788,19 @@ export function applyTableCellProperties(node, properties) {
|
|
|
616
788
|
return styled;
|
|
617
789
|
applied.push(...styled.value.applied);
|
|
618
790
|
}
|
|
791
|
+
const fontChanged = [...TABLE_CELL_FONT_KEYS].some((k) => k in properties) || 'text' in properties;
|
|
792
|
+
if (fontChanged) {
|
|
793
|
+
const frame = findGraphicFrame(node);
|
|
794
|
+
if (frame) {
|
|
795
|
+
const result = remeasureTableAfterCellChange(frame);
|
|
796
|
+
diagnostics.push(...result.diagnostics);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
619
799
|
}
|
|
620
800
|
catch (cause) {
|
|
621
801
|
return err('INVALID_COMMAND', cause instanceof Error ? cause.message : 'Invalid tableCell properties');
|
|
622
802
|
}
|
|
623
|
-
return ok({ applied });
|
|
803
|
+
return ok({ applied, diagnostics });
|
|
624
804
|
}
|
|
625
805
|
const cellPlainText = (tc) => descendants(tc, 't')
|
|
626
806
|
.map((t) => t.textContent ?? '')
|