(background, props, options = {})
| 10 | }; |
| 11 | |
| 12 | export function generateExportCode(background, props, options = {}) { |
| 13 | if (!background) return { commands: null, jsxCode: '' }; |
| 14 | |
| 15 | const { label, id } = background; |
| 16 | const { language = 'JS', style = 'Tailwind' } = options; |
| 17 | const componentName = label.replace(/\s+/g, ''); |
| 18 | |
| 19 | const commands = generateCliCommands(language, style, 'backgrounds', id); |
| 20 | |
| 21 | if (id === 'hyperspeed' && props.preset) { |
| 22 | const presetKey = props.preset || 'one'; |
| 23 | const presetLabel = HYPERSPEED_PRESET_LABELS[presetKey] || 'Cyberpunk'; |
| 24 | |
| 25 | const jsxCode = `import { hyperspeedPresets } from './HyperSpeedPresets'; |
| 26 | |
| 27 | // Using "${presetLabel}" preset |
| 28 | <div style={{ width: '1080px', height: '1080px', position: 'relative' }}> |
| 29 | <Hyperspeed |
| 30 | effectOptions={hyperspeedPresets.${presetKey}} |
| 31 | /> |
| 32 | </div>`; |
| 33 | |
| 34 | return { commands, jsxCode }; |
| 35 | } |
| 36 | |
| 37 | const allProps = background.props || []; |
| 38 | |
| 39 | const propsEntries = allProps.map(propDef => { |
| 40 | const value = props[propDef.name] !== undefined ? props[propDef.name] : propDef.default; |
| 41 | return [propDef.name, value]; |
| 42 | }); |
| 43 | |
| 44 | let propsString = ''; |
| 45 | if (propsEntries.length > 0) { |
| 46 | propsString = propsEntries |
| 47 | .map(([key, value]) => { |
| 48 | if (typeof value === 'string') { |
| 49 | return ` ${key}="${value}"`; |
| 50 | } else if (typeof value === 'boolean') { |
| 51 | return value ? ` ${key}` : ` ${key}={false}`; |
| 52 | } else if (Array.isArray(value)) { |
| 53 | return ` ${key}={${JSON.stringify(value)}}`; |
| 54 | } else if (typeof value === 'object') { |
| 55 | return ` ${key}={${JSON.stringify(value)}}`; |
| 56 | } else { |
| 57 | return ` ${key}={${value}}`; |
| 58 | } |
| 59 | }) |
| 60 | .join('\n'); |
| 61 | } |
| 62 | |
| 63 | const jsxCode = |
| 64 | propsEntries.length > 0 |
| 65 | ? `<div style={{ width: '1080px', height: '1080px', position: 'relative' }}>\n <${componentName}\n ${propsString.split('\n').join('\n ')}\n />\n</div>` |
| 66 | : `<div style={{ width: '1080px', height: '1080px', position: 'relative' }}>\n <${componentName} />\n</div>`; |
| 67 | |
| 68 | return { |
| 69 | commands, |
no test coverage detected