/** * Represents a line item with text, font information, and spacing options. * @param {String} text The contents of the line * @param {FontInfo} fontInfo Font details to use for the line * @param {Boolean} moveDownAfter Provide extra spacing after this line? * @returns LineItem */ class LineItem { constructor(text, fontInfo, moveDownAfter) { this.text = text; this.fontInfo = fontInfo; this.moveDownAfter = moveDownAfter || false; return this; } /** * Set the contents of the line * @param {String} text The contents of the line * @returns LineItem */ setText(text) { if (typeof text !== 'string') { throw new Error('Text must be a string'); } this.text = text; return this; } /** * Set the font information for the line * @param {FontInfo} fontInfo Font details to use for the line * @returns LineItem */ setFontInfo(fontInfo) { if (!(fontInfo instanceof FontInfo)) { throw new Error('fontInfo must be an instance of FontInfo'); } this.fontInfo = fontInfo; return this; } /** * Set whether to provide extra spacing after this line * @param {Boolean} moveDownAfter Provide extra spacing after this line? * @returns LineItem */ setMoveDownAfter(moveDownAfter) { if (typeof moveDownAfter !== 'boolean') { throw new Error('moveDownAfter must be a boolean'); } this.moveDownAfter = moveDownAfter; return this; } } /** * Represents font information including name, size, and style. * @param {String} name The font name * @param {Number} size The font size * @param {String} style The font style * @returns FontInfo */ class FontInfo { constructor(name, size, style) { this.name = name || 'Helvetica'; this.style = style || ''; this.size = size || 12; return this; } /** * Set the font name * @param {String} name The font name * @returns FontInfo */ setName(name) { if (typeof name !== 'string') { throw new Error('Font name must be a string'); } this.name = name; return this; } /** * Set the font size * @param {Number} size The font size * @returns FontInfo */ setSize(size) { if (typeof size !== 'number' || size <= 0) { throw new Error('Font size must be a positive number'); } this.size = size; return this; } /** * Set the font style * @param {String} style The font style * @returns FontInfo */ setStyle(style) { if (typeof style !== 'string') { throw new Error('Font style must be a string'); } this.style = style; return this; } }