@modusoperandi/licit-import-utils 0.1.1 → 0.1.2

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.
@@ -108,6 +108,9 @@ interface LicitTableAttrsJSON extends LicitElementAttrsJSON {
108
108
  marginLeft: null;
109
109
  vignette: boolean;
110
110
  }
111
+ interface LicitTableRowAttrsJSON extends LicitElementAttrsJSON {
112
+ rowHeight: string;
113
+ }
111
114
  interface LicitTableCellAttrsJSON extends LicitElementAttrsJSON {
112
115
  colspan: number;
113
116
  rowspan: number;
@@ -134,6 +137,7 @@ interface LicitTableCellImageJSON extends LicitElementJSON {
134
137
  }
135
138
  interface LicitTableRowJSON extends LicitElementJSON {
136
139
  type: 'table_row';
140
+ attrs: LicitTableRowAttrsJSON;
137
141
  content: LicitTableCellJSON[];
138
142
  }
139
143
  export interface LicitTableJSON extends LicitElementJSON {
@@ -159,6 +163,15 @@ interface LicitOrderedListJSON extends LicitElementJSON {
159
163
  attrs: LicitBulletListAttrsJSON;
160
164
  content: LicitBulletListItemJSON[];
161
165
  }
166
+ interface CellStyleInfo {
167
+ className?: string;
168
+ id?: string;
169
+ marginTop?: string;
170
+ marginBottom?: string;
171
+ fontSize?: string;
172
+ letterSpacing?: string;
173
+ cellWidth?: string;
174
+ }
162
175
  export interface LicitDocumentJSON extends LicitElementJSON {
163
176
  type: 'doc';
164
177
  attrs: LicitDocumentAttrsJSON;
@@ -627,7 +640,8 @@ export declare class LicitTableCellParagraph extends LicitElement {
627
640
  colWidth: [number];
628
641
  content: any[];
629
642
  vAlign: string;
630
- constructor(node: HTMLElement, bgColor?: string, colwidth?: [number], vericalAlignment?: string);
643
+ cellStyleInfo?: CellStyleInfo;
644
+ constructor(node: HTMLElement, bgColor?: string, colwidth?: [number], vericalAlignment?: string, cellStyleInfo?: CellStyleInfo);
631
645
  render(): {
632
646
  type: string;
633
647
  attrs: {
@@ -684,7 +698,8 @@ export declare class LicitTableCellImageElement extends LicitElement {
684
698
  alt: string;
685
699
  fillImg: number;
686
700
  fitToParent: number;
687
- constructor(src: string, fillImg: number, fitToParent: number, bgColor?: string, imgHeight?: string, colWidth?: [number], alt?: string);
701
+ cellStyleInfo?: CellStyleInfo;
702
+ constructor(src: string, fillImg: number, fitToParent: number, bgColor?: string, imgHeight?: string, colWidth?: [number], alt?: string, cellStyleInfo?: CellStyleInfo);
688
703
  render(): LicitTableCellImageJSON;
689
704
  }
690
705
  export declare class LicitVignetteElement extends LicitElement {
@@ -747,7 +762,8 @@ export declare class LicitTableCellParaElement extends LicitElement {
747
762
  vAlign: string;
748
763
  isTableHeader: boolean;
749
764
  isTransparentTable: boolean;
750
- constructor(node: HTMLElement, bgColor?: string, colwidth?: [number], vericalAlignment?: string, isTableHeader?: boolean, isTransparentTable?: boolean);
765
+ cellStyleInfo?: CellStyleInfo;
766
+ constructor(node: HTMLElement, bgColor?: string, colwidth?: [number], vericalAlignment?: string, isTableHeader?: boolean, isTransparentTable?: boolean, cellStyleInfo?: CellStyleInfo);
751
767
  ConvertElements(node: HTMLElement): void;
752
768
  processChildNode(childNode: ChildNode): void;
753
769
  processChildOL(childNode: ChildNode): void;
@@ -759,6 +775,8 @@ export declare class LicitTableCellParaElement extends LicitElement {
759
775
  render(): LicitTableCellJSON;
760
776
  }
761
777
  export declare class LicitTableRowElement extends LicitElement {
778
+ height?: string;
779
+ rowHeight?: string;
762
780
  getBaseElement(): LicitTableRowJSON;
763
781
  cells: LicitTableCellElement[];
764
782
  addCell(cell: LicitTableCellElement): void;
@@ -769,6 +787,8 @@ export declare class LicitTableElement extends LicitElement {
769
787
  rows: LicitTableRowElement[];
770
788
  isVignette: boolean;
771
789
  capco?: string;
790
+ noOfColumns?: number;
791
+ tableHeight?: string;
772
792
  constructor(isVignette?: boolean, capco?: string);
773
793
  addRow(row: LicitTableRowElement): void;
774
794
  render(): LicitTableJSON;
package/licit-elements.js CHANGED
@@ -1876,11 +1876,13 @@ export class LicitTableCellParagraph extends LicitElement {
1876
1876
  colWidth;
1877
1877
  content = [];
1878
1878
  vAlign;
1879
- constructor(node, bgColor, colwidth, vericalAlignment) {
1879
+ cellStyleInfo;
1880
+ constructor(node, bgColor, colwidth, vericalAlignment, cellStyleInfo) {
1880
1881
  super();
1881
1882
  this.bgColor = bgColor;
1882
1883
  this.colWidth = colwidth;
1883
1884
  this.vAlign = vericalAlignment;
1885
+ this.cellStyleInfo = cellStyleInfo;
1884
1886
  const paragraph = new NewLicitParagraphElement(node, null);
1885
1887
  if (paragraph) {
1886
1888
  this.content.push(paragraph.render());
@@ -1996,7 +1998,8 @@ export class LicitTableCellImageElement extends LicitElement {
1996
1998
  alt;
1997
1999
  fillImg;
1998
2000
  fitToParent;
1999
- constructor(src, fillImg, fitToParent, bgColor, imgHeight, colWidth, alt) {
2001
+ cellStyleInfo;
2002
+ constructor(src, fillImg, fitToParent, bgColor, imgHeight, colWidth, alt, cellStyleInfo) {
2000
2003
  super();
2001
2004
  this.src = src;
2002
2005
  this.bgColor = bgColor;
@@ -2005,6 +2008,7 @@ export class LicitTableCellImageElement extends LicitElement {
2005
2008
  this.alt = alt;
2006
2009
  this.fillImg = fillImg;
2007
2010
  this.fitToParent = fitToParent;
2011
+ this.cellStyleInfo = cellStyleInfo;
2008
2012
  }
2009
2013
  render() {
2010
2014
  const element = this.getBaseElement();
@@ -2165,6 +2169,12 @@ export class LicitTableCellParaElement extends LicitElement {
2165
2169
  colwidth: this.colWidth || defaultColWidth,
2166
2170
  background: this.bgColor || defaultBgColor,
2167
2171
  vAlign: this.vAlign || 'middle',
2172
+ cellWidth: this.cellStyleInfo?.cellWidth ?? null,
2173
+ cellStyle: this.cellStyleInfo?.className ?? null,
2174
+ fontSize: this.cellStyleInfo?.fontSize ?? null,
2175
+ letterSpacing: this.cellStyleInfo?.letterSpacing ?? null,
2176
+ marginTop: this.cellStyleInfo?.marginTop ?? null,
2177
+ marginBottom: this.cellStyleInfo?.marginBottom ?? null,
2168
2178
  },
2169
2179
  content: [],
2170
2180
  };
@@ -2178,13 +2188,15 @@ export class LicitTableCellParaElement extends LicitElement {
2178
2188
  vAlign;
2179
2189
  isTableHeader;
2180
2190
  isTransparentTable;
2181
- constructor(node, bgColor, colwidth, vericalAlignment, isTableHeader, isTransparentTable) {
2191
+ cellStyleInfo;
2192
+ constructor(node, bgColor, colwidth, vericalAlignment, isTableHeader, isTransparentTable, cellStyleInfo) {
2182
2193
  super();
2183
2194
  this.bgColor = bgColor;
2184
2195
  this.colWidth = colwidth;
2185
2196
  this.vAlign = vericalAlignment;
2186
2197
  this.isTableHeader = isTableHeader;
2187
2198
  this.isTransparentTable = isTransparentTable;
2199
+ this.cellStyleInfo = cellStyleInfo;
2188
2200
  this.ConvertElements(node);
2189
2201
  }
2190
2202
  ConvertElements(node) {
@@ -2299,9 +2311,14 @@ export class LicitTableCellParaElement extends LicitElement {
2299
2311
  }
2300
2312
  }
2301
2313
  export class LicitTableRowElement extends LicitElement {
2314
+ height;
2315
+ rowHeight;
2302
2316
  getBaseElement() {
2303
2317
  return {
2304
2318
  type: 'table_row',
2319
+ attrs: {
2320
+ rowHeight: this.rowHeight,
2321
+ },
2305
2322
  content: [],
2306
2323
  };
2307
2324
  }
@@ -2325,6 +2342,8 @@ export class LicitTableElement extends LicitElement {
2325
2342
  marginLeft: null,
2326
2343
  vignette: this.isVignette,
2327
2344
  capco: this.capco,
2345
+ noOfColumns: this.noOfColumns ?? null,
2346
+ tableHeight: this.tableHeight ?? null,
2328
2347
  },
2329
2348
  content: [],
2330
2349
  };
@@ -2332,6 +2351,8 @@ export class LicitTableElement extends LicitElement {
2332
2351
  rows = [];
2333
2352
  isVignette = false;
2334
2353
  capco;
2354
+ noOfColumns;
2355
+ tableHeight;
2335
2356
  constructor(isVignette, capco) {
2336
2357
  super();
2337
2358
  this.isVignette = isVignette;
@@ -151,7 +151,29 @@ export declare class LicitConverter {
151
151
  private parseTableContent;
152
152
  private parseTableContentInnerLoopHelper;
153
153
  private addCell;
154
- private checkCellStyle;
154
+ /**
155
+ * Extracts style information from a table cell element per the ingest requirements.
156
+ * Captures: margins (top/bottom), font-size overrides, and letter-spacing for non-breaking spaces.
157
+ *
158
+ * @param cell - The HTMLTableCellElement to extract styles from
159
+ * @returns Object containing extracted style information
160
+ */
161
+ private extractCellStyles;
162
+ /**
163
+ * Extracts margin and font-size properties from a style string.
164
+ *
165
+ * @param style - The style attribute string
166
+ * @param styleInfo - The style info object to populate
167
+ */
168
+ private extractParagraphStyles;
169
+ /**
170
+ * Extracts the first letter-spacing value from spans containing non-breaking spaces.
171
+ *
172
+ * @param spans - NodeList of span elements with letter-spacing styles
173
+ * @param styleInfo - The style info object to populate
174
+ */
175
+ private extractLetterSpacing;
176
+ checkCellStyle(style: string | null): string | null;
155
177
  private addTableImageCell;
156
178
  private ParseNestedList;
157
179
  /**
@@ -964,6 +964,7 @@ export class LicitConverter {
964
964
  renderDocTable(e, licitDocument) {
965
965
  const licitTable = new LicitTableElement();
966
966
  const colWidthsArray = this.getColWidthArray(e.node);
967
+ licitTable.noOfColumns = colWidthsArray?.length ?? 0;
967
968
  const tableHead = e.node.querySelector('thead');
968
969
  const table = e.node.querySelector('tbody');
969
970
  licitTable.capco = getCapcoFromNode(table);
@@ -1175,6 +1176,7 @@ export class LicitConverter {
1175
1176
  */
1176
1177
  parseTableContent(_e, tableTag, querySel, isChapterHeader, licitTable, widthArray, isTransparent) {
1177
1178
  const rows = tableTag.querySelectorAll('tr');
1179
+ let totalTableHeight = 0;
1178
1180
  for (let i = 0; i < rows.length; i++) {
1179
1181
  if (!isTransparent &&
1180
1182
  i == 0 &&
@@ -1183,11 +1185,21 @@ export class LicitConverter {
1183
1185
  isChapterHeader = true;
1184
1186
  }
1185
1187
  const licitRow = new LicitTableRowElement();
1188
+ // ** Capture row height **
1189
+ const rowHeight = rows[i].getAttribute('height');
1190
+ if (rowHeight) {
1191
+ licitRow.height = rowHeight;
1192
+ licitRow.rowHeight = rowHeight;
1193
+ totalTableHeight += parseFloat(rowHeight);
1194
+ }
1186
1195
  const cells = rows[i].querySelectorAll(querySel);
1187
1196
  this.parseTableContentInnerLoopHelper(cells, i, isChapterHeader, licitRow, widthArray, isTransparent);
1188
1197
  licitTable.addRow(licitRow);
1189
1198
  isChapterHeader = false;
1190
1199
  }
1200
+ if (totalTableHeight > 0) {
1201
+ licitTable.tableHeight = `${totalTableHeight}px`;
1202
+ }
1191
1203
  }
1192
1204
  parseTableContentInnerLoopHelper(cells, _cellIndex, isChapterHeader, licitRow, widthArray, isTransparent) {
1193
1205
  for (let j = 0; j < cells.length; j++) {
@@ -1233,13 +1245,19 @@ export class LicitConverter {
1233
1245
  let colWidth;
1234
1246
  let licitCell = null;
1235
1247
  const text = cell.textContent ?? '';
1248
+ // Extract cell-level style information**
1249
+ const cellStyleInfo = this.extractCellStyles(cell);
1250
+ if (widthArray?.length > 0) {
1251
+ const computedWidth = this.setCellWidth(colspan, cellIndex, widthArray);
1252
+ cellStyleInfo.cellWidth = computedWidth?.join(',');
1253
+ }
1236
1254
  if (cell.childNodes?.length <= 0) {
1237
1255
  //condition
1238
- licitCell = new LicitTableCellParaElement(cell, bgColor, null, verAlign, isChapterHeader, isTransparent);
1256
+ licitCell = new LicitTableCellParaElement(cell, bgColor, null, verAlign, isChapterHeader, isTransparent, cellStyleInfo);
1239
1257
  }
1240
1258
  else if ('' === text &&
1241
1259
  cell.childNodes[0].querySelector('img')) {
1242
- ({ licitCell } = this.addTableImageCell(cell, bgColor, isChapterHeader, licitCell, verAlign));
1260
+ ({ licitCell } = this.addTableImageCell(cell, bgColor, isChapterHeader, licitCell, verAlign, cellStyleInfo));
1243
1261
  }
1244
1262
  else {
1245
1263
  if (isChapterHeader) {
@@ -1247,7 +1265,7 @@ export class LicitConverter {
1247
1265
  cell.align = 'center'; // NOSONAR used by Licit parser (depricated)
1248
1266
  cell.setAttribute('classname', 'LC-Center');
1249
1267
  }
1250
- licitCell = new LicitTableCellParaElement(cell, bgColor, colWidth, verAlign, isChapterHeader, isTransparent);
1268
+ licitCell = new LicitTableCellParaElement(cell, bgColor, colWidth, verAlign, isChapterHeader, isTransparent, cellStyleInfo);
1251
1269
  }
1252
1270
  licitCell.rowspan = rowspan;
1253
1271
  licitCell.colspan = colspan;
@@ -1256,6 +1274,80 @@ export class LicitConverter {
1256
1274
  }
1257
1275
  licitRow.addCell(licitCell);
1258
1276
  }
1277
+ /**
1278
+ * Extracts style information from a table cell element per the ingest requirements.
1279
+ * Captures: margins (top/bottom), font-size overrides, and letter-spacing for non-breaking spaces.
1280
+ *
1281
+ * @param cell - The HTMLTableCellElement to extract styles from
1282
+ * @returns Object containing extracted style information
1283
+ */
1284
+ extractCellStyles(cell) {
1285
+ const styleInfo = {};
1286
+ // Capture class and ID from the paragraph inside the cell
1287
+ const paragraph = cell.querySelector('p');
1288
+ if (paragraph) {
1289
+ if (paragraph.className) {
1290
+ styleInfo.className = paragraph.className;
1291
+ }
1292
+ if (paragraph.id) {
1293
+ styleInfo.id = paragraph.id;
1294
+ }
1295
+ // Extract style attributes from the paragraph's style attribute
1296
+ const style = paragraph.getAttribute('style');
1297
+ if (style) {
1298
+ this.extractParagraphStyles(style, styleInfo);
1299
+ }
1300
+ // Extract letter-spacing for non-breaking spaces
1301
+ const spans = paragraph.querySelectorAll('span[style*="letter-spacing"]');
1302
+ this.extractLetterSpacing(spans, styleInfo);
1303
+ }
1304
+ return styleInfo;
1305
+ }
1306
+ /**
1307
+ * Extracts margin and font-size properties from a style string.
1308
+ *
1309
+ * @param style - The style attribute string
1310
+ * @param styleInfo - The style info object to populate
1311
+ */
1312
+ extractParagraphStyles(style, styleInfo) {
1313
+ const styleProps = style.split(';');
1314
+ for (const prop of styleProps) {
1315
+ const trimmedProp = prop.trim();
1316
+ if (trimmedProp.startsWith('margin-top')) {
1317
+ styleInfo.marginTop = trimmedProp.split(':')[1]?.trim();
1318
+ }
1319
+ else if (trimmedProp.startsWith('margin-bottom')) {
1320
+ styleInfo.marginBottom = trimmedProp.split(':')[1]?.trim();
1321
+ }
1322
+ else if (trimmedProp.startsWith('font-size')) {
1323
+ styleInfo.fontSize = trimmedProp.split(':')[1]?.trim();
1324
+ }
1325
+ }
1326
+ }
1327
+ /**
1328
+ * Extracts the first letter-spacing value from spans containing non-breaking spaces.
1329
+ *
1330
+ * @param spans - NodeList of span elements with letter-spacing styles
1331
+ * @param styleInfo - The style info object to populate
1332
+ */
1333
+ extractLetterSpacing(spans, styleInfo) {
1334
+ const letterSpacingRegex = /letter-spacing\s{0,1000}:\s{0,1000}([^;]{1,1000})/;
1335
+ for (const span of Array.from(spans)) {
1336
+ // Check if this span contains a non-breaking space
1337
+ const content = span.innerHTML;
1338
+ if (content.includes('&#160;') || content.includes('&nbsp;')) {
1339
+ const spanStyle = span.getAttribute('style');
1340
+ if (spanStyle) {
1341
+ const match = letterSpacingRegex.exec(spanStyle);
1342
+ if (match) {
1343
+ // Store the first letter-spacing value found
1344
+ styleInfo.letterSpacing = match[1].trim();
1345
+ break;
1346
+ }
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1259
1351
  checkCellStyle(style) {
1260
1352
  let borderColor = null;
1261
1353
  if (style != null) {
@@ -1274,7 +1366,7 @@ export class LicitConverter {
1274
1366
  }
1275
1367
  return borderColor;
1276
1368
  }
1277
- addTableImageCell(cell, bgColor, isChapterHeader, licitCell, verAlign) {
1369
+ addTableImageCell(cell, bgColor, isChapterHeader, licitCell, verAlign, cellStyleInfo) {
1278
1370
  const image = cell.childNodes[0].querySelector('img');
1279
1371
  let altText = null;
1280
1372
  let imgHeight = null;
@@ -1295,10 +1387,10 @@ export class LicitConverter {
1295
1387
  const source = image?.getAttribute('srcRelative') ?? image?.src;
1296
1388
  if (source) {
1297
1389
  // seybi excluded image
1298
- licitCell = new LicitTableCellImageElement(source, fillImg, fitoParent, bgColor, imgHeight, colWidth, altText);
1390
+ licitCell = new LicitTableCellImageElement(source, fillImg, fitoParent, bgColor, imgHeight, colWidth, altText, cellStyleInfo);
1299
1391
  }
1300
1392
  else {
1301
- licitCell = new LicitTableCellParagraph(cell, bgColor, colWidth, verAlign);
1393
+ licitCell = new LicitTableCellParagraph(cell, bgColor, colWidth, verAlign, cellStyleInfo);
1302
1394
  }
1303
1395
  return { bgColor, isChapterHeader, licitCell };
1304
1396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modusoperandi/licit-import-utils",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "subversion": "1",
@@ -37,11 +37,11 @@
37
37
  "uuid": "^13.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@modusoperandi/mammoth": "^1.7.0-6",
40
+ "@modusoperandi/mammoth": "^1.7.0-8",
41
41
  "@modusoperandi/eslint-config": "^3.0.3",
42
42
  "@types/jest": "^30.0.0",
43
43
  "jszip": "^3.10.1",
44
- "eslint": "^9.39.2",
44
+ "eslint": "^9.39.3",
45
45
  "jest": "^30.2.0",
46
46
  "jest-environment-jsdom": "^30.2.0",
47
47
  "jest-junit": "^16.0.0",