All files / web/src/app/create/worksheets/typstHelpers/subtraction operatorOverlay.ts

100% Statements 39/39
100% Branches 1/1
100% Functions 1/1
100% Lines 39/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x  
// Operator overlay for subtraction problems
// Rendered last to ensure proper layering over all other elements
 
import type { CellDimensions } from '../shared/types'
 
/**
 * Generate Typst code for the operator overlay
 *
 * The operator (− sign) is rendered using place() to overlay it on top of
 * all other problem elements, ensuring proper layering regardless of
 * borrow boxes, scratch work, or other decorations.
 *
 * @param cellDimensions - Cell sizing information
 * @returns Typst code for operator overlay using place()
 */
export function generateOperatorOverlay(cellDimensions: CellDimensions): string {
  const { cellSizeIn, cellSizePt } = cellDimensions
 
  // The operator should be positioned at the subtrahend row level
  // Borrow boxes row height + minuend row height = 2 * cellSize from top
  // We position relative to the grid, so we need to account for:
  // - Row 0: borrow boxes (height: cellSize)
  // - Row 1: minuend row (height: cellSize)
  // - Row 2: subtrahend row (where operator should appear)
 
  return String.raw`
    // Operator overlay - rendered last for proper layering
    // Position: left edge, at subtrahend row vertical position
    #place(
      left + top,
      dx: 0pt,
      dy: ${cellSizeIn} * 2,  // Skip borrow boxes row + minuend row
      box(width: 0.5em, height: ${cellSizeIn})[
        #align(center + horizon)[
          #text(size: ${(cellSizePt * 0.8).toFixed(1)}pt)[−]
        ]
      ]
    )`
}