Dynamic Form Builder
Run ID: 69bca53177c0421c0bf497532026-03-29Web Development
PantheraHive BOS
BOS Dashboard

Workflow Execution: Dynamic Form Builder - Step 1/2: Generate

Your request to generate a dynamic form structure using the "websitebuilder" app has been successfully processed. Based on your specified form_purpose and fields count, a foundational HTML form with integrated CSS for basic styling and a placeholder for dynamic behavior has been generated. This output provides a robust starting point for your "Test Form Purpose" form.


1. Generated Form Structure (HTML & CSS)

Below is the complete HTML structure for your dynamic form, including embedded CSS for immediate visual presentation. This structure includes 5 diverse input fields as requested, designed to be easily customizable and extendable.

html • 7,454 chars
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dynamic Form: Test Form Purpose</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f7f6;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
            margin: 20px 0;
        }
        .form-container {
            background-color: #ffffff;
            padding: 30px 40px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 600px;
            box-sizing: border-box;
        }
        h2 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-size: 1.8em;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
        }
        input[type="text"],
        input[type="email"],
        input[type="number"],
        textarea,
        select {
            width: 100%;
            padding: 12px;
            border: 1px solid #ccc;
            border-radius: 5px;
            box-sizing: border-box;
            font-size: 1em;
            transition: border-color 0.3s ease;
        }
        input[type="text"]:focus,
        input[type="email"]:focus,
        input[type="number"]:focus,
        textarea:focus,
        select:focus {
            border-color: #007bff;
            outline: none;
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
        }
        textarea {
            resize: vertical;
            min-height: 100px;
        }
        button {
            width: 100%;
            padding: 14px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 1.1em;
            cursor: pointer;
            transition: background-color 0.3s ease;
            margin-top: 20px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .error-message {
            color: #dc3545;
            font-size: 0.9em;
            margin-top: 5px;
            display: none; /* Hidden by default, shown by JS validation */
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h2>Test Form Purpose</h2>
        <form id="dynamicForm" action="#" method="POST">
            <!-- Field 1: Text Input -->
            <div class="form-group">
                <label for="fullName">Full Name</label>
                <input type="text" id="fullName" name="fullName" placeholder="Enter your full name" required>
                <div class="error-message" id="fullNameError">Please enter your full name.</div>
            </div>

            <!-- Field 2: Email Input -->
            <div class="form-group">
                <label for="email">Email Address</label>
                <input type="email" id="email" name="email" placeholder="e.g., your.email@example.com" required>
                <div class="error-message" id="emailError">Please enter a valid email address.</div>
            </div>

            <!-- Field 3: Number Input -->
            <div class="form-group">
                <label for="age">Age</label>
                <input type="number" id="age" name="age" min="18" max="99" placeholder="Enter your age" required>
                <div class="error-message" id="ageError">Please enter a valid age (18-99).</div>
            </div>

            <!-- Field 4: Textarea -->
            <div class="form-group">
                <label for="message">Your Message</label>
                <textarea id="message" name="message" rows="5" placeholder="Type your message here..." required></textarea>
                <div class="error-message" id="messageError">Please enter your message.</div>
            </div>

            <!-- Field 5: Select/Dropdown -->
            <div class="form-group">
                <label for="topic">Select Topic</label>
                <select id="topic" name="topic" required>
                    <option value="">-- Please choose an option --</option>
                    <option value="support">Support Request</option>
                    <option value="feedback">Product Feedback</option>
                    <option value="inquiry">General Inquiry</option>
                    <option value="other">Other</option>
                </select>
                <div class="error-message" id="topicError">Please select a topic.</div>
            </div>

            <button type="submit">Submit Form</button>
        </form>
    </div>

    <script>
        // Placeholder for dynamic form behavior and validation
        document.getElementById('dynamicForm').addEventListener('submit', function(event) {
            event.preventDefault(); // Prevent default form submission

            let isValid = true;
            const fields = [
                { id: 'fullName', errorId: 'fullNameError', message: 'Please enter your full name.' },
                { id: 'email', errorId: 'emailError', message: 'Please enter a valid email address.', type: 'email' },
                { id: 'age', errorId: 'ageError', message: 'Please enter a valid age (18-99).', type: 'number', min: 18, max: 99 },
                { id: 'message', errorId: 'messageError', message: 'Please enter your message.' },
                { id: 'topic', errorId: 'topicError', message: 'Please select a topic.' }
            ];

            fields.forEach(field => {
                const input = document.getElementById(field.id);
                const errorDiv = document.getElementById(field.errorId);
                errorDiv.style.display = 'none'; // Hide previous errors

                if (!input.value.trim()) {
                    errorDiv.textContent = field.message;
                    errorDiv.style.display = 'block';
                    isValid = false;
                } else if (field.type === 'email' && !/\S+@\S+\.\S+/.test(input.value)) {
                    errorDiv.textContent = field.message;
                    errorDiv.style.display = 'block';
                    isValid = false;
                } else if (field.type === 'number') {
                    const numValue = parseInt(input.value, 10);
                    if (isNaN(numValue) || numValue < field.min || numValue > field.max) {
                        errorDiv.textContent = field.message;
                        errorDiv.style.display = 'block';
                        isValid = false;
                    }
                }
            });

            if (isValid) {
                alert('Form submitted successfully! (This is a placeholder action)');
                // Here you would typically send the form data to a server
                // e.g., using fetch API:
                // const formData = new FormData(this);
                // fetch(this.action, {
                //     method: this.method,
                //     body: formData
                // })
                // .then(response => response.json())
                // .then(data => console.log(data))
                // .catch(error => console.error('Error:', error));
            }
        });
    </script>
</body>
</html>
Sandboxed live preview

4. Actionable Recommendations for Next Steps

To fully leverage this generated form and enhance its dynamic capabilities, consider the following:

  1. Customization:

* Content: Modify the <h2> title, field labels, placeholders, and select options to precisely match your "Test Form Purpose" requirements.

* Styling: Adjust the CSS within the <style> tags or link to an external stylesheet (<link rel="stylesheet" href="styles.css">) to integrate with your website's branding.

* Add/Remove Fields: Use the provided HTML structure as a template to add more fields or remove existing ones. Refer to the JSON structure for common field properties.

  1. Enhanced Client-Side Validation:

* Regular Expressions: Implement more complex validation patterns for fields like phone numbers, postal codes, or custom IDs using JavaScript regular expressions.

* Real-time Validation: Add input or change event listeners to fields to provide immediate feedback to users as they type, rather than just on submission.

  1. Server-Side Integration:

* Update action attribute: Change <form action="#" method="POST"> to point to your actual backend API endpoint (e.g., action="/api/submit-form").

* Backend Validation: Always implement server-side validation to ensure data integrity and security, as client-side validation can be bypassed.

* Data Handling: On form submission, the JavaScript currently shows an alert. Replace this with actual fetch or XMLHttpRequest logic to send the formData to your server.

  1. Dynamic Field Management (Advanced):

* JavaScript Frameworks: For truly dynamic forms where users can add/remove fields or change field types in real-time, consider integrating with JavaScript frameworks like React, Vue, or Angular. The provided JSON structure is ideal for feeding into such frameworks.

* Conditional Logic: Implement JavaScript to show/hide fields based on previous selections (e.g., if "Other" is selected in "Select Topic", show a "Specify Other" text field).

  1. Error Handling & User Feedback:

* Clearer Messages: Make error messages specific and helpful.

* Success States: Provide clear visual feedback upon successful submission (e.g., a success message, redirect to a thank-you page).


This generated output provides a solid foundation. You can now take this HTML, CSS, and JavaScript, and begin integrating it into your project, customizing it to meet the specific needs of your "Test Form Purpose."

Step 2: collab

Dynamic Form Builder Workflow Execution Report

Workflow Category: Web Development

Workflow Name: Dynamic Form Builder

Execution Status: Completed

Step: 2 of 2 (document)

This report details the successful generation of your dynamic form based on the provided specifications. The form structure, an example HTML implementation, and key recommendations for further development and integration are provided below.


1. Workflow Execution Summary

A dynamic form has been generated with the purpose "Test Form Purpose" and includes 5 distinct input fields. This output provides the foundational structure for your form, enabling quick integration and further customization.

Form Details:

  • Purpose: Test Form Purpose
  • Number of Fields Generated: 5

2. Generated Form Structure (JSON Format)

The following JSON object represents the structured definition of your generated form fields. This format is ideal for programmatic use, database storage, or API integration.


{
  "formId": "test-form-purpose-12345",
  "purpose": "Test Form Purpose",
  "fields": [
    {
      "id": "field-name",
      "name": "userName",
      "label": "Your Name",
      "type": "text",
      "placeholder": "Enter your full name",
      "required": true,
      "validation": {
        "minLength": 2,
        "maxLength": 100
      }
    },
    {
      "id": "field-email",
      "name": "userEmail",
      "label": "Email Address",
      "type": "email",
      "placeholder": "your.email@example.com",
      "required": true,
      "validation": {
        "pattern": "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"
      }
    },
    {
      "id": "field-subject",
      "name": "subject",
      "label": "Subject",
      "type": "text",
      "placeholder": "Briefly describe your inquiry",
      "required": false,
      "validation": {
        "maxLength": 200
      }
    },
    {
      "id": "field-message",
      "name": "message",
      "label": "Your Message",
      "type": "textarea",
      "placeholder": "Type your detailed message here...",
      "required": true,
      "validation": {
        "minLength": 10,
        "maxLength": 1000
      }
    },
    {
      "id": "field-terms",
      "name": "agreeTerms",
      "label": "I agree to the Terms and Conditions",
      "type": "checkbox",
      "required": true
    }
  ]
}

3. Example HTML Implementation

Below is a basic HTML snippet that demonstrates how you can render this form. This code provides a functional starting point for integration into your web project.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Form Purpose</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; background-color: #f4f4f4; }
        .form-container { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); max-width: 600px; margin: auto; }
        .form-group { margin-bottom: 15px; }
        label { display: block; margin-bottom: 5px; font-weight: bold; color: #333; }
        input[type="text"],
        input[type="email"],
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box; /* Ensures padding doesn't affect overall width */
            font-size: 16px;
        }
        input[type="checkbox"] {
            margin-right: 10px;
        }
        textarea { resize: vertical; min-height: 100px; }
        button {
            background-color: #007bff;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }
        button:hover { background-color: #0056b3; }
        .checkbox-group { display: flex; align-items: center; }
        .checkbox-group label { margin-bottom: 0; }
    </style>
</head>
<body>
    <div class="form-container">
        <h2>Test Form Purpose</h2>
        <p>Please fill out the form below.</p>
        <form action="/submit-form" method="POST">
            <div class="form-group">
                <label for="field-name">Your Name</label>
                <input type="text" id="field-name" name="userName" placeholder="Enter your full name" required minlength="2" maxlength="100">
            </div>

            <div class="form-group">
                <label for="field-email">Email Address</label>
                <input type="email" id="field-email" name="userEmail" placeholder="your.email@example.com" required pattern="^[^\s@]+@[^\s@]+\.[^\s@]+$">
            </div>

            <div class="form-group">
                <label for="field-subject">Subject</label>
                <input type="text" id="field-subject" name="subject" placeholder="Briefly describe your inquiry" maxlength="200">
            </div>

            <div class="form-group">
                <label for="field-message">Your Message</label>
                <textarea id="field-message" name="message" placeholder="Type your detailed message here..." required minlength="10" maxlength="1000"></textarea>
            </div>

            <div class="form-group checkbox-group">
                <input type="checkbox" id="field-terms" name="agreeTerms" required>
                <label for="field-terms">I agree to the Terms and Conditions</label>
            </div>

            <button type="submit">Submit Form</button>
        </form>
    </div>
</body>
</html>

Note:

  • The action="/submit-form" attribute in the <form> tag is a placeholder. You will need to replace this with the actual endpoint of your server-side form handler.
  • The method="POST" attribute specifies that data will be sent via an HTTP POST request.
  • Basic inline CSS is included for immediate visual representation. For a production environment, it is highly recommended to externalize styles into a dedicated CSS file or use a CSS framework (e.g., Bootstrap, Tailwind CSS).

4. Key Recommendations and Next Steps

To fully leverage your new dynamic form, consider the following actionable recommendations:

4.1. Backend Integration & Data Handling

  • Server-Side Endpoint: Develop a backend endpoint (e.g., /submit-form) that listens for POST requests. This endpoint will receive the form data.
  • Data Validation: Implement robust server-side validation to ensure data integrity and security, even if client-side validation is present.
  • Data Storage: Decide where to store the submitted data (e.g., database like PostgreSQL, MongoDB; CRM system; email service).
  • Response Handling: Provide clear feedback to the user upon submission (e.g., success message, error message, redirect).

4.2. Frontend Enhancements

  • Advanced Styling: Integrate with a CSS framework (e.g., Bootstrap, Tailwind CSS) for a more polished and responsive design.
  • Client-Side Validation (JavaScript): Enhance the basic HTML5 validation with custom JavaScript for real-time feedback, more complex rules, or dynamic error messages.
  • AJAX Submission: Consider using JavaScript (e.g., Fetch API, Axios) to submit the form asynchronously without a full page reload, improving user experience.
  • Accessibility (A11Y): Ensure your form is accessible to all users by utilizing ARIA attributes, proper labeling, and keyboard navigation.

4.3. Security Best Practices

  • CSRF Protection: Implement Cross-Site Request Forgery (CSRF) tokens to protect against malicious attacks.
  • Input Sanitization: Sanitize all user inputs on the server-side to prevent injection attacks (e.g., XSS, SQL injection).
  • Rate Limiting: Implement rate limiting on your form submission endpoint to prevent abuse and spam.

4.4. Customization & Expansion

  • Additional Field Types: Easily add more field types (e.g., number, date, select dropdowns, radio buttons, file uploads) by extending the JSON structure and updating your HTML rendering logic.
  • Conditional Logic: Implement JavaScript to show/hide fields based on user selections (e.g., "Show additional fields if 'Yes' is selected").
  • Multi-step Forms: For longer forms, consider breaking them into multiple steps for a better user experience.

5. Structured Data for Integration

For developers looking to integrate this form definition into a larger system or generate forms dynamically, here's the structured data again for easy parsing:


formId: test-form-purpose-12345
purpose: Test Form Purpose
fields:
  - id: field-name
    name: userName
    label: Your Name
    type: text
    placeholder: Enter your full name
    required: true
    validation:
      minLength: 2
      maxLength: 100
  - id: field-email
    name: userEmail
    label: Email Address
    type: email
    placeholder: your.email@example.com
    required: true
    validation:
      pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$"
  - id: field-subject
    name: subject
    label: Subject
    type: text
    placeholder: Briefly describe your inquiry
    required: false
    validation:
      maxLength: 200
  - id: field-message
    name: message
    label: Your Message
    type: textarea
    placeholder: Type your detailed message here...
    required: true
    validation:
      minLength: 10
      maxLength: 1000
  - id: field-terms
    name: agreeTerms
    label: I agree to the Terms and Conditions
    type: checkbox
    required: true

This comprehensive output provides you with a robust foundation for your "Test Form Purpose" form. Should you require further assistance or wish to generate more complex forms, please initiate the "Dynamic Form Builder" workflow again with your updated requirements.

dynamic_form_builder.html
Download source file
Copy all content
Full output as text
Download ZIP
IDE-ready project ZIP
Copy share link
Permanent URL for this run
Get Embed Code
Embed this result on any website
Print / Save PDF
Use browser print dialog
\n\n\n";var _phIsHtml=true;var _phFname="dynamic_form_builder.html";var _phPreviewUrl="/api/runs/69bca53177c0421c0bf49753/preview";var _phAll="## Workflow Execution: Dynamic Form Builder - Step 1/2: Generate\n\nYour request to generate a dynamic form structure using the \"websitebuilder\" app has been successfully processed. Based on your specified `form_purpose` and `fields` count, a foundational HTML form with integrated CSS for basic styling and a placeholder for dynamic behavior has been generated. This output provides a robust starting point for your \"Test Form Purpose\" form.\n\n---\n\n## 1. Generated Form Structure (HTML & CSS)\n\nBelow is the complete HTML structure for your dynamic form, including embedded CSS for immediate visual presentation. This structure includes 5 diverse input fields as requested, designed to be easily customizable and extendable.\n\n```html\n\n\n\n \n \n Dynamic Form: Test Form Purpose\n \n\n\n
\n

Test Form Purpose

\n
\n \n
\n \n \n
Please enter your full name.
\n
\n\n \n
\n \n \n
Please enter a valid email address.
\n
\n\n \n
\n \n \n
Please enter a valid age (18-99).
\n
\n\n \n
\n \n \n
Please enter your message.
\n
\n\n \n
\n \n \n
Please select a topic.
\n
\n\n \n
\n
\n\n \n\n\n```\n\n---\n\n## 2. Key Features and Design Choices\n\nThis generated form incorporates several best practices for web forms:\n\n* **Semantic HTML5:** Uses appropriate HTML5 elements (`
`, ``, `
\n\n
\n \n \n
\n\n \n \n \n\n\n```\n\n**Note:**\n* The `action=\"/submit-form\"` attribute in the `
` tag is a placeholder. You will need to replace this with the actual endpoint of your server-side form handler.\n* The `method=\"POST\"` attribute specifies that data will be sent via an HTTP POST request.\n* Basic inline CSS is included for immediate visual representation. For a production environment, it is highly recommended to externalize styles into a dedicated CSS file or use a CSS framework (e.g., Bootstrap, Tailwind CSS).\n\n---\n\n## 4. Key Recommendations and Next Steps\n\nTo fully leverage your new dynamic form, consider the following actionable recommendations:\n\n### 4.1. Backend Integration & Data Handling\n* **Server-Side Endpoint:** Develop a backend endpoint (e.g., `/submit-form`) that listens for `POST` requests. This endpoint will receive the form data.\n* **Data Validation:** Implement robust server-side validation to ensure data integrity and security, even if client-side validation is present.\n* **Data Storage:** Decide where to store the submitted data (e.g., database like PostgreSQL, MongoDB; CRM system; email service).\n* **Response Handling:** Provide clear feedback to the user upon submission (e.g., success message, error message, redirect).\n\n### 4.2. Frontend Enhancements\n* **Advanced Styling:** Integrate with a CSS framework (e.g., Bootstrap, Tailwind CSS) for a more polished and responsive design.\n* **Client-Side Validation (JavaScript):** Enhance the basic HTML5 validation with custom JavaScript for real-time feedback, more complex rules, or dynamic error messages.\n* **AJAX Submission:** Consider using JavaScript (e.g., Fetch API, Axios) to submit the form asynchronously without a full page reload, improving user experience.\n* **Accessibility (A11Y):** Ensure your form is accessible to all users by utilizing ARIA attributes, proper labeling, and keyboard navigation.\n\n### 4.3. Security Best Practices\n* **CSRF Protection:** Implement Cross-Site Request Forgery (CSRF) tokens to protect against malicious attacks.\n* **Input Sanitization:** Sanitize all user inputs on the server-side to prevent injection attacks (e.g., XSS, SQL injection).\n* **Rate Limiting:** Implement rate limiting on your form submission endpoint to prevent abuse and spam.\n\n### 4.4. Customization & Expansion\n* **Additional Field Types:** Easily add more field types (e.g., `number`, `date`, `select` dropdowns, `radio` buttons, `file` uploads) by extending the JSON structure and updating your HTML rendering logic.\n* **Conditional Logic:** Implement JavaScript to show/hide fields based on user selections (e.g., \"Show additional fields if 'Yes' is selected\").\n* **Multi-step Forms:** For longer forms, consider breaking them into multiple steps for a better user experience.\n\n---\n\n## 5. Structured Data for Integration\n\nFor developers looking to integrate this form definition into a larger system or generate forms dynamically, here's the structured data again for easy parsing:\n\n```yaml\nformId: test-form-purpose-12345\npurpose: Test Form Purpose\nfields:\n - id: field-name\n name: userName\n label: Your Name\n type: text\n placeholder: Enter your full name\n required: true\n validation:\n minLength: 2\n maxLength: 100\n - id: field-email\n name: userEmail\n label: Email Address\n type: email\n placeholder: your.email@example.com\n required: true\n validation:\n pattern: \"^[^\\\\s@]+@[^\\\\s@]+\\\\.[^\\\\s@]+$\"\n - id: field-subject\n name: subject\n label: Subject\n type: text\n placeholder: Briefly describe your inquiry\n required: false\n validation:\n maxLength: 200\n - id: field-message\n name: message\n label: Your Message\n type: textarea\n placeholder: Type your detailed message here...\n required: true\n validation:\n minLength: 10\n maxLength: 1000\n - id: field-terms\n name: agreeTerms\n label: I agree to the Terms and Conditions\n type: checkbox\n required: true\n```\n\n---\n\nThis comprehensive output provides you with a robust foundation for your \"Test Form Purpose\" form. Should you require further assistance or wish to generate more complex forms, please initiate the \"Dynamic Form Builder\" workflow again with your updated requirements.";function phTab(btn,name){document.querySelectorAll(".ph-panel").forEach(function(el){el.classList.remove("active");});document.querySelectorAll(".ph-tab").forEach(function(el){el.classList.remove("active");el.classList.add("inactive");});var p=document.getElementById("panel-"+name);if(p)p.classList.add("active");btn.classList.remove("inactive");btn.classList.add("active");if(name==="preview"){var fr=document.getElementById("ph-preview-frame");if(fr&&!fr.dataset.loaded){if(_phIsHtml){fr.srcdoc=_phCode;}else{var vc=document.getElementById("panel-content");fr.srcdoc=vc?""+vc.innerHTML+"":"

No content

";}fr.dataset.loaded="1";}}}function phCopyCode(){navigator.clipboard.writeText(_phCode).then(function(){var b=document.getElementById("tab-code");if(b){var o=b.innerHTML;b.innerHTML=' Copied!';setTimeout(function(){b.innerHTML=o;},2000);}});}function phCopyAll(){navigator.clipboard.writeText(_phAll).then(function(){alert("Content copied to clipboard!");});}function phDownload(){var content=_phCode||_phAll;if(!content){alert("No content to download.");return;}var fn=_phFname;if(!_phCode&&fn.endsWith(".txt"))fn=fn.replace(/\.txt$/,".md");var a=document.createElement("a");a.href="data:text/plain;charset=utf-8,"+encodeURIComponent(content);a.download=fn;a.click();}function phDownloadZip(){ var lbl=document.getElementById("ph-zip-lbl"); if(lbl)lbl.textContent="Preparing\u2026"; /* ===== HELPERS ===== */ function cc(s){ return s.replace(/[_\-\s]+([a-z])/g,function(m,c){return c.toUpperCase();}) .replace(/^[a-z]/,function(m){return m.toUpperCase();}); } function pkgName(app){ return app.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"my_app"; } function slugTitle(app){ return app.replace(/_/g," "); } /* Generic code block extractor. Finds marker comments like: // lib/main.dart or # lib/main.dart or ## lib/main.dart and collects lines until the next marker. Also strips markdown fences (\`\`\`lang ... \`\`\`) from each block. */ function extractFiles(txt, pathRe){ var files={}, cur=null, buf=[]; function flush(){ if(cur&&buf.length){ files[cur]=buf.join("\n").trim(); } } txt.split("\n").forEach(function(line){ var m=line.trim().match(pathRe); if(m){ flush(); cur=m[1]; buf=[]; return; } if(cur) buf.push(line); }); flush(); // Strip \`\`\`...\`\`\` fences from each file Object.keys(files).forEach(function(k){ files[k]=files[k].replace(/^\`\`\`[a-z]*\n?/,"").replace(/\n?\`\`\`$/,"").trim(); }); return files; } /* General path extractor that covers most languages */ function extractCode(txt){ var re=/^(?:\/\/|#|##)\s*((?:lib|src|test|tests|Sources?|app|components?|screens?|views?|hooks?|routes?|store|services?|models?|pages?)\/[\w\/\-\.]+\.\w+|pubspec\.yaml|Package\.swift|angular\.json|babel\.config\.(?:js|ts)|vite\.config\.(?:js|ts)|tsconfig\.(?:json|app\.json)|app\.json|App\.(?:tsx|jsx|vue|kt|swift)|MainActivity(?:\.kt)?|ContentView\.swift)/i; return extractFiles(txt, re); } /* Detect language from combined code+panel text */ function detectLang(code, panel){ var t=(code+" "+panel).toLowerCase(); if(t.indexOf("import 'package:flutter")>=0||t.indexOf('import "package:flutter')>=0) return "flutter"; if(t.indexOf("statelesswidget")>=0||t.indexOf("statefulwidget")>=0) return "flutter"; if((t.indexOf(".dart")>=0)&&(t.indexOf("pubspec")>=0||t.indexOf("flutter:")>=0)) return "flutter"; if(t.indexOf("react-native")>=0||t.indexOf("react_native")>=0) return "react-native"; if(t.indexOf("stylesheet.create")>=0||t.indexOf("view, text, touchableopacity")>=0) return "react-native"; if(t.indexOf("expo(")>=0||t.indexOf("\"expo\":")>=0||t.indexOf("from 'expo")>=0) return "react-native"; if(t.indexOf("import swiftui")>=0||t.indexOf("import uikit")>=0) return "swift"; if(t.indexOf(".swift")>=0&&(t.indexOf("func body")>=0||t.indexOf("@main")>=0||t.indexOf("var body: some view")>=0)) return "swift"; if(t.indexOf("import android.")>=0||t.indexOf("package com.example")>=0) return "kotlin"; if(t.indexOf("@composable")>=0||t.indexOf("fun mainactivity")>=0||(t.indexOf(".kt")>=0&&t.indexOf("androidx")>=0)) return "kotlin"; if(t.indexOf("@ngmodule")>=0||t.indexOf("@component")>=0) return "angular"; if(t.indexOf("angular.json")>=0||t.indexOf("from '@angular")>=0) return "angular"; if(t.indexOf(".vue")>=0||t.indexOf("