@@ -9,6 +9,9 @@ import { docxNumberigHelpers } from '@/core/super-converter/v2/importer/listImpo
99const MARKER_PADDING = 6 ;
1010const MARKER_OFFSET_RIGHT = 4 ;
1111const MIN_MARKER_WIDTH = 20 ;
12+ const POINT_TO_PIXEL_CONVERSION_FACTOR = 1.33 ;
13+ const DEFAULT_FONT_FAMILY = 'Arial, sans-serif' ;
14+ const DEFAULT_FONT_SIZE = '10pt' ;
1215
1316const IS_DEBUGGING = false ;
1417
@@ -338,26 +341,36 @@ export const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
338341 return result ;
339342} ;
340343
344+ /**
345+ * Calculate the width of the list item marker.
346+ * @param {HTMLElement } dom - The DOM element of the list item.
347+ * @param {HTMLElement } numberingDOM - The DOM element of the numbering.
348+ * @param {Object } param2 - Additional parameters.
349+ * @param {boolean } param2.withPadding - Whether to include padding in the calculation.
350+ * @returns {number } The width of the marker.
351+ */
341352function calculateMarkerWidth ( dom , numberingDOM , { withPadding = true } = { } ) {
342353 const markerText = numberingDOM . textContent || '' ;
343- const fontSize = dom . style . fontSize || '10pt' ;
354+ const fontSize = dom . style . fontSize || DEFAULT_FONT_SIZE ;
344355 const fontValue = dom . style . fontFamily ;
345- const fontFamily = fontValue && fontValue !== 'inherit' ? fontValue : 'Arial' ;
356+ const fontFamily = fontValue && fontValue !== 'inherit' ? fontValue : DEFAULT_FONT_FAMILY ;
346357
347358 if ( ! markerText . trim ( ) ) return 0 ;
348359
349360 try {
350361 const canvas = document . createElement ( 'canvas' ) ;
351362 const context = canvas . getContext ( '2d' ) ;
352363
353- const fontSizePx = fontSize . includes ( 'pt' ) ? Number . parseFloat ( fontSize ) * 1.33 : Number . parseFloat ( fontSize ) ;
364+ const fontSizePx = fontSize . includes ( 'pt' )
365+ ? Number . parseFloat ( fontSize ) * POINT_TO_PIXEL_CONVERSION_FACTOR
366+ : Number . parseFloat ( fontSize ) ;
354367
355368 context . font = `${ fontSizePx } px ${ fontFamily } ` ;
356369
357370 const textWidth = context . measureText ( markerText ) . width ;
358371 const resultWidth = withPadding ? Math . ceil ( textWidth + MARKER_PADDING ) : Math . ceil ( textWidth ) ;
359372 return resultWidth ;
360- } catch ( err ) {
373+ } catch {
361374 return 0 ;
362375 }
363376}
0 commit comments