Files
soroban-abacus-flashcards/apps/web/scripts/generateBlogExamples.ts
Thomas Hallock b36df3a40c fix(worksheets): ten-frames not rendering in mastery mode
Fixed two critical bugs preventing ten-frames from rendering:

1. **Mastery mode not handled** (typstGenerator.ts:61)
   - Code only checked for 'smart' | 'manual' modes
   - Mastery mode fell into manual path, tried to use boolean flags that don't exist
   - Resulted in all display options being `undefined`
   - Fix: Check for both 'smart' OR 'mastery' modes (both use displayRules)

2. **Typst array membership syntax** (already fixed in previous commit)
   - Used `(i in array)` which doesn't work in Typst
   - Changed to `array.contains(i)`

Added comprehensive unit tests (tenFrames.test.ts):
- Problem analysis tests (regrouping detection)
- Display rule evaluation tests
- Full Typst template generation tests
- Mastery mode specific tests
- All 14 tests now passing

Added debug logging to trace display rules resolution:
- displayRules.ts: Shows rule evaluation per problem
- typstGenerator.ts: Shows enriched problems and Typst data
- Helps diagnose future issues

The issue was that mastery mode (which uses displayRules like smart mode)
was being treated as manual mode (which uses boolean flags), resulting in
undefined display options.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:06:27 -06:00

128 lines
3.7 KiB
TypeScript

// Script to generate example worksheet images for the blog post
// Shows different scaffolding levels for the 2D difficulty blog post
import fs from 'fs'
import path from 'path'
import { generateWorksheetPreview } from '../src/app/create/worksheets/addition/generatePreview'
import { DIFFICULTY_PROFILES } from '../src/app/create/worksheets/addition/difficultyProfiles'
// Output directory
const outputDir = path.join(process.cwd(), 'public', 'blog', 'difficulty-examples')
// Ensure output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}
// Generate examples with SAME regrouping level but different scaffolding
// This clearly shows how scaffolding changes while keeping problem complexity constant
const examples = [
{
name: 'full-scaffolding',
filename: 'full-scaffolding.svg',
description: 'Full Scaffolding: Maximum visual support',
// Use medium regrouping with full scaffolding
config: {
pAllStart: 0.3,
pAnyStart: 0.7,
displayRules: {
carryBoxes: 'always' as const,
answerBoxes: 'always' as const,
placeValueColors: 'always' as const,
tenFrames: 'always' as const,
problemNumbers: 'always' as const,
cellBorders: 'always' as const,
},
},
},
{
name: 'medium-scaffolding',
filename: 'medium-scaffolding.svg',
description: 'Medium Scaffolding: Strategic support',
config: {
pAllStart: 0.3,
pAnyStart: 0.7,
displayRules: {
carryBoxes: 'whenRegrouping' as const,
answerBoxes: 'always' as const,
placeValueColors: 'when3PlusDigits' as const,
tenFrames: 'never' as const,
problemNumbers: 'always' as const,
cellBorders: 'always' as const,
},
},
},
{
name: 'minimal-scaffolding',
filename: 'minimal-scaffolding.svg',
description: 'Minimal Scaffolding: Carry boxes only',
config: {
pAllStart: 0.3,
pAnyStart: 0.7,
displayRules: {
carryBoxes: 'whenMultipleRegroups' as const,
answerBoxes: 'never' as const,
placeValueColors: 'never' as const,
tenFrames: 'never' as const,
problemNumbers: 'always' as const,
cellBorders: 'always' as const,
},
},
},
{
name: 'no-scaffolding',
filename: 'no-scaffolding.svg',
description: 'No Scaffolding: Students work independently',
config: {
pAllStart: 0.3,
pAnyStart: 0.7,
displayRules: {
carryBoxes: 'never' as const,
answerBoxes: 'never' as const,
placeValueColors: 'never' as const,
tenFrames: 'never' as const,
problemNumbers: 'always' as const,
cellBorders: 'always' as const,
},
},
},
] as const
console.log('Generating blog example worksheets...\n')
for (const example of examples) {
console.log(`Generating ${example.description}...`)
const config = {
pAllStart: example.config.pAllStart,
pAnyStart: example.config.pAnyStart,
displayRules: example.config.displayRules,
problemsPerPage: 4,
pages: 1,
cols: 2,
}
try {
const result = generateWorksheetPreview(config)
if (!result.success || !result.pages || result.pages.length === 0) {
console.error(`Failed to generate ${example.name}:`, result.error)
continue
}
// Get the first page's SVG
const svg = result.pages[0]
// Save to file
const outputPath = path.join(outputDir, example.filename)
fs.writeFileSync(outputPath, svg, 'utf-8')
console.log(` ✓ Saved to ${outputPath}`)
} catch (error) {
console.error(` ✗ Error generating ${example.name}:`, error)
}
}
console.log('\nDone! Example worksheets generated.')
console.log(`\nFiles saved to: ${outputDir}`)