fix: PDF generation now respects operator and digitRange settings
The PDF generation route was ignoring the operator and digitRange settings, always generating 2-digit addition problems regardless of configuration. The preview worked correctly but PDF generation was broken. Changes: - Add conditional logic to call appropriate problem generator based on operator - Pass digitRange parameter to all problem generators - Add generatePlaceValueColors() to Typst template for color definitions - Import DisplayOptions type for internal use in typstHelpers Fixes worksheet PDF generation for subtraction, mixed, and multi-digit problems. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { execSync } from 'child_process'
|
||||
import { validateWorksheetConfig } from '@/app/create/worksheets/addition/validation'
|
||||
import { generateProblems } from '@/app/create/worksheets/addition/problemGenerator'
|
||||
import {
|
||||
generateProblems,
|
||||
generateSubtractionProblems,
|
||||
generateMixedProblems,
|
||||
} from '@/app/create/worksheets/addition/problemGenerator'
|
||||
import { generateTypstSource } from '@/app/create/worksheets/addition/typstGenerator'
|
||||
import type { WorksheetFormState } from '@/app/create/worksheets/addition/types'
|
||||
import type { WorksheetFormState, WorksheetProblem } from '@/app/create/worksheets/addition/types'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
@@ -22,14 +26,37 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const config = validation.config
|
||||
|
||||
// Generate problems
|
||||
const problems = generateProblems(
|
||||
config.total,
|
||||
config.pAnyStart,
|
||||
config.pAllStart,
|
||||
config.interpolate,
|
||||
config.seed
|
||||
)
|
||||
// Generate problems based on operator type
|
||||
let problems: WorksheetProblem[]
|
||||
if (config.operator === 'addition') {
|
||||
problems = generateProblems(
|
||||
config.total,
|
||||
config.pAnyStart,
|
||||
config.pAllStart,
|
||||
config.interpolate,
|
||||
config.seed,
|
||||
config.digitRange
|
||||
)
|
||||
} else if (config.operator === 'subtraction') {
|
||||
problems = generateSubtractionProblems(
|
||||
config.total,
|
||||
config.digitRange,
|
||||
config.pAnyStart,
|
||||
config.pAllStart,
|
||||
config.interpolate,
|
||||
config.seed
|
||||
)
|
||||
} else {
|
||||
// mixed
|
||||
problems = generateMixedProblems(
|
||||
config.total,
|
||||
config.digitRange,
|
||||
config.pAnyStart,
|
||||
config.pAllStart,
|
||||
config.interpolate,
|
||||
config.seed
|
||||
)
|
||||
}
|
||||
|
||||
// Generate Typst sources (one per page)
|
||||
const typstSources = generateTypstSource(config, problems)
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
generateTypstHelpers,
|
||||
generateProblemStackFunction,
|
||||
generateSubtractionProblemStackFunction,
|
||||
generatePlaceValueColors,
|
||||
} from './typstHelpers'
|
||||
import { analyzeProblem, analyzeSubtractionProblem } from './problemAnalysis'
|
||||
import { resolveDisplayForProblem } from './displayRules'
|
||||
@@ -185,6 +186,8 @@ function generatePageTypst(
|
||||
: 'false'
|
||||
}
|
||||
|
||||
${generatePlaceValueColors()}
|
||||
|
||||
${generateTypstHelpers(cellSize)}
|
||||
|
||||
${generateProblemStackFunction(cellSize, maxDigits)}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
// NOTE: This file now re-exports from the modular typstHelpers/ directory
|
||||
// for backward compatibility. New code should import from typstHelpers/ directly.
|
||||
|
||||
// Import types for internal use
|
||||
import type { DisplayOptions } from './typstHelpers/shared/types'
|
||||
|
||||
// Re-export everything from modular structure
|
||||
export type { DisplayOptions, CellDimensions } from './typstHelpers/shared/types'
|
||||
export { generateTypstHelpers } from './typstHelpers/shared/helpers'
|
||||
|
||||
Reference in New Issue
Block a user