Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getParagraphBorderBox,
computeBorderSpaceExpansion,
type BetweenBorderInfo,
} from './features/paragraph-borders/index.js';
} from './paragraph/borders/index.js';
import { hashParagraphBorders } from './paragraph-hash-utils.js';

/** Helper to create BetweenBorderInfo for tests that previously passed a boolean. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export const RENDERING_FEATURES = {
// ─── Paragraph Borders ───────────────────────────────────────────
// @spec ECMA-376 §17.3.1.24 (pBdr)
'w:pBdr': {
feature: 'paragraph-borders',
module: './paragraph-borders',
feature: 'paragraph/borders',
module: '../paragraph/borders',
handles: ['w:pBdr/w:top', 'w:pBdr/w:bottom', 'w:pBdr/w:left', 'w:pBdr/w:right', 'w:pBdr/w:between', 'w:pBdr/w:bar'],
spec: '§17.3.1.24',
},

// ─── Paragraph Shading ───────────────────────────────────────────
// @spec ECMA-376 §17.3.1.31 (shd)
'w:shd': {
feature: 'paragraph-borders', // shading shares the border layer module
module: './paragraph-borders',
feature: 'paragraph/borders', // shading shares the border layer module
module: '../paragraph/borders',
handles: ['w:shd/@w:fill', 'w:shd/@w:val', 'w:shd/@w:color'],
spec: '§17.3.1.31',
},
Expand Down
5 changes: 3 additions & 2 deletions packages/layout-engine/painters/dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export type {
PaintSnapshotImageEntity,
PaintSnapshotEntities,
} from './renderer.js';
export type { DomPainterInput, PositionMapping, RenderedLineInfo } from './renderer.js';
export type { DomPainterInput, PositionMapping } from './renderer.js';
export type { RenderedLineInfo } from './runs/index.js';

// Re-export utility functions for testing
export { sanitizeUrl, linkMetrics, applyRunDataAttributes } from './renderer.js';
export { sanitizeUrl, linkMetrics, applyRunDataAttributes } from './runs/index.js';

export { applySquareWrapExclusionsToLines } from './utils/anchor-helpers';
export { buildImagePmSelector, buildInlineImagePmSelector } from './utils/image-selectors.js';
Expand Down
116 changes: 10 additions & 106 deletions packages/layout-engine/painters/dom/src/paragraph-hash-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
Run,
ParagraphBorders,
ParagraphBorder,
TableBorders,
Expand Down Expand Up @@ -82,108 +81,13 @@ export const hashCellBorders = (borders: CellBorders | undefined): string => {
return parts.join(';');
};

/**
* Type guard to check if a run has a string property.
*
* @param run - The run to check
* @param prop - The property name to check
* @returns True if the run has the property and it's a string
*/
export const hasStringProp = (run: Run, prop: string): run is Run & Record<string, string> => {
return prop in run && typeof (run as Record<string, unknown>)[prop] === 'string';
};

/**
* Type guard to check if a run has a number property.
*
* @param run - The run to check
* @param prop - The property name to check
* @returns True if the run has the property and it's a number
*/
export const hasNumberProp = (run: Run, prop: string): run is Run & Record<string, number> => {
return prop in run && typeof (run as Record<string, unknown>)[prop] === 'number';
};

/**
* Type guard to check if a run has a boolean property.
*
* @param run - The run to check
* @param prop - The property name to check
* @returns True if the run has the property and it's a boolean
*/
export const hasBooleanProp = (run: Run, prop: string): run is Run & Record<string, boolean> => {
return prop in run && typeof (run as Record<string, unknown>)[prop] === 'boolean';
};

/**
* Safely gets a string property from a run, with type narrowing.
*
* @param run - The run to get the property from
* @param prop - The property name
* @returns The string value or empty string if not present
*/
export const getRunStringProp = (run: Run, prop: string): string => {
if (hasStringProp(run, prop)) {
return run[prop];
}
return '';
};

/**
* Safely gets a number property from a run, with type narrowing.
*
* @param run - The run to get the property from
* @param prop - The property name
* @returns The number value or 0 if not present
*/
export const getRunNumberProp = (run: Run, prop: string): number => {
if (hasNumberProp(run, prop)) {
return run[prop];
}
return 0;
};

/**
* Safely gets a boolean property from a run, with type narrowing.
*
* @param run - The run to get the property from
* @param prop - The property name
* @returns The boolean value or false if not present
*/
export const getRunBooleanProp = (run: Run, prop: string): boolean => {
if (hasBooleanProp(run, prop)) {
return run[prop];
}
return false;
};

/**
* Safely gets the underline style from a run.
* Handles the object-shaped underline property { style?, color? }.
*
* @param run - The run to get the underline style from
* @returns The underline style or empty string if not present
*/
export const getRunUnderlineStyle = (run: Run): string => {
if ('underline' in run && typeof run.underline === 'boolean') {
return run.underline ? 'single' : '';
}
if ('underline' in run && run.underline && typeof run.underline === 'object') {
return (run.underline as { style?: string }).style ?? '';
}
return '';
};

/**
* Safely gets the underline color from a run.
* Handles the object-shaped underline property { style?, color? }.
*
* @param run - The run to get the underline color from
* @returns The underline color or empty string if not present
*/
export const getRunUnderlineColor = (run: Run): string => {
if ('underline' in run && run.underline && typeof run.underline === 'object') {
return (run.underline as { color?: string }).color ?? '';
}
return '';
};
export {
getRunBooleanProp,
getRunNumberProp,
getRunStringProp,
getRunUnderlineColor,
getRunUnderlineStyle,
hasBooleanProp,
hasNumberProp,
hasStringProp,
} from './runs/hash.js';
Loading
Loading