#!/usr/bin/env node // Test script to verify SVG processing is working // This will test both browser-side and server-side processing const { generateSorobanSVG } = require('./src/lib/typst-soroban.ts') async function testSVGProcessing() { console.log('๐Ÿงช Testing SVG processing...\n') // Test configuration const testConfig = { number: 23, width: '120pt', height: '160pt', beadShape: 'diamond', colorScheme: 'place-value', hideInactiveBeads: false, enableServerFallback: false, } try { console.log('๐Ÿ“‹ Test Configuration:') console.log(JSON.stringify(testConfig, null, 2)) console.log('\n๐Ÿš€ Generating SVG...\n') const svg = await generateSorobanSVG(testConfig) console.log('โœ… SVG generated successfully!') console.log(`๐Ÿ“ SVG length: ${svg.length} characters`) // Check for processing evidence console.log('\n๐Ÿ” Checking for processing evidence:') // Check viewBox const viewBoxMatch = svg.match(/viewBox="([^"]*)"/) if (viewBoxMatch) { console.log(`โœ“ ViewBox found: ${viewBoxMatch[1]}`) } else { console.log('โŒ No viewBox found') } // Check for crop marks (should be present but could be removed) const hasCropMarks = svg.includes('crop-mark://') console.log( `${hasCropMarks ? 'โœ“' : 'โŒ'} Crop marks: ${hasCropMarks ? 'present' : 'not found'}` ) // Check for bead data attributes (evidence of processing) const hasBeadData = svg.includes('data-bead-') console.log( `${hasBeadData ? 'โœ“' : 'โŒ'} Bead data attributes: ${hasBeadData ? 'present' : 'not found'}` ) // Check for original typst elements vs processed elements const hasTypstGroups = svg.includes('class="typst-group"') console.log( `${hasTypstGroups ? 'โœ“' : 'โŒ'} Typst groups: ${hasTypstGroups ? 'present' : 'not found'}` ) // Extract some sample data attributes to verify processing const dataAttrMatches = svg.match(/data-bead-[^=]+=["'][^"']*["']/g) if (dataAttrMatches && dataAttrMatches.length > 0) { console.log(`โœ“ Found ${dataAttrMatches.length} bead data attributes:`) dataAttrMatches.slice(0, 3).forEach((attr) => { console.log(` - ${attr}`) }) if (dataAttrMatches.length > 3) { console.log(` - ... and ${dataAttrMatches.length - 3} more`) } } // Check for size optimization evidence const dimensions = svg.match(/width="([^"]*)".*height="([^"]*)"/) if (dimensions) { console.log(`โœ“ Dimensions: ${dimensions[1]} ร— ${dimensions[2]}`) } console.log('\n๐Ÿ“Š Summary:') console.log(`- SVG generation: โœ… SUCCESS`) console.log(`- ViewBox optimization: ${viewBoxMatch ? 'โœ…' : 'โŒ'}`) console.log(`- Bead annotation processing: ${hasBeadData ? 'โœ…' : 'โŒ'}`) console.log(`- Crop mark detection: ${hasCropMarks ? 'โœ…' : 'โŒ'}`) if (hasBeadData && viewBoxMatch) { console.log('\n๐ŸŽฏ CONCLUSION: SVG processor is working correctly!') console.log(' - ViewBox has been optimized for cropping') console.log(' - Bead annotations have been extracted and converted to data attributes') } else { console.log('\nโš ๏ธ CONCLUSION: SVG processor may not be working as expected') console.log(' - Check the processSVG function calls in the generation pipeline') } // Save a sample for manual inspection require('fs').writeFileSync('./sample-processed.svg', svg) console.log('\n๐Ÿ’พ Sample SVG saved to ./sample-processed.svg for manual inspection') } catch (error) { console.error('โŒ Test failed:', error.message) console.error('Stack:', error.stack) } } // Run the test testSVGProcessing().catch(console.error)