(classData)
| 636 | } |
| 637 | |
| 638 | function generateClassDeclaration(classData) { |
| 639 | let output = ''; |
| 640 | const className = classData.name.startsWith('p5.') ? classData.name.substring(3) : classData.name; |
| 641 | const actualClassName = className === 'Graphics' ? '__Graphics' : className; |
| 642 | |
| 643 | if (classData.description) { |
| 644 | output += ' /**\n'; |
| 645 | output += formatJSDocComment(classData.description, 2) + '\n'; |
| 646 | output += ' */\n'; |
| 647 | } |
| 648 | |
| 649 | const extendsClause = classData.extends ? ` extends ${classData.extends}` : ''; |
| 650 | output += ` class ${actualClassName}${extendsClause} {\n`; |
| 651 | |
| 652 | // Constructor |
| 653 | if (classData.params?.length > 0) { |
| 654 | output += ' constructor('; |
| 655 | output += classData.params |
| 656 | .map(param => generateParamDeclaration(param, { currentClass: className, isInsideNamespace: true }, classData.params)) |
| 657 | .join(', '); |
| 658 | output += ');\n\n'; |
| 659 | } |
| 660 | |
| 661 | const options = { currentClass: className, isInsideNamespace: true }; |
| 662 | const originalClassName = classData.name; |
| 663 | |
| 664 | // Class methods |
| 665 | const classMethodsList = Object.values(processed.classMethods[originalClassName] || {}); |
| 666 | const methodNames = new Set(classMethodsList.map(method => method.name)); |
| 667 | |
| 668 | // Class properties |
| 669 | const classProperties = processed.classitems.filter(item => |
| 670 | item.class === originalClassName && item.itemtype === 'property' |
| 671 | ); |
| 672 | |
| 673 | classProperties.forEach(prop => { |
| 674 | // Skip properties that conflict with method names |
| 675 | if (methodNames.has(prop.name)) { |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | if (prop.description) { |
| 680 | output += ' /**\n'; |
| 681 | output += formatJSDocComment(prop.description, 4) + '\n'; |
| 682 | output += ' */\n'; |
| 683 | } |
| 684 | const type = convertTypeToTypeScript(prop.type, options); |
| 685 | output += ` ${prop.name}: ${type};\n\n`; |
| 686 | }); |
| 687 | const staticMethods = classMethodsList.filter(method => method.static); |
| 688 | const instanceMethods = classMethodsList.filter(method => !method.static); |
| 689 | |
| 690 | staticMethods.forEach(method => { |
| 691 | output += generateMethodDeclaration(method, options); |
| 692 | }); |
| 693 | |
| 694 | instanceMethods.forEach(method => { |
| 695 | output += generateMethodDeclaration(method, options); |
no test coverage detected