Notification / index.html
Examups's picture
Update index.html
86ce656 verified
Raw History Blame Contribute Delete
77.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Advanced Component Builder</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script> <script src="https://cdn.ckeditor.com/ckeditor5/41.4.2/classic/ckeditor.js"></script> <style> :root { --primary-color: #3b82f6; --primary-hover-color: #2563eb; --secondary-color: #10b981; --secondary-hover-color: #059669; --text-color: #374151; --heading-color: #111827; --background-color: #f9fafb; --font-family: 'Inter', sans-serif; } body { font-family: var(--font-family); color: var(--text-color); background-color: var(--background-color); } h1, h2, h3, h4, h5, h6 { color: var(--heading-color); } /* Custom scrollbar for webkit browsers */ ::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-track { background: #f1f1f1; } ::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; } ::-webkit-scrollbar-thumb:hover { background: #555; } .preview-iframe { width: 100%; height: 100%; border: 0; transition: all 0.3s ease-in-out; } #preview-container.preview-desktop .preview-iframe { width: 100%; } #preview-container.preview-tablet .preview-iframe { width: 768px; margin: 0 auto; } #preview-container.preview-mobile .preview-iframe { width: 375px; margin: 0 auto; } .toast { visibility: hidden; min-width: 250px; background-color: #333; color: #fff; text-align: center; border-radius: 8px; padding: 16px; position: fixed; z-index: 100; left: 50%; bottom: 30px; transform: translateX(-50%); opacity: 0; transition: opacity 0.3s, visibility 0.3s; } .toast.show { visibility: visible; opacity: 1; } /* New Professional Controls UI Styles */ #controls-layout { display: flex; height: 100%; } #controls-nav { width: 180px; flex-shrink: 0; background-color: #f8fafc; border-right: 1px solid #e5e7eb; padding: 0.5rem; overflow-y: auto; } .control-nav-button { display: flex; align-items: center; width: 100%; padding: 0.75rem; border-radius: 0.375rem; font-weight: 500; color: var(--text-color); transition: background-color 0.2s, color 0.2s; text-align: left; } .control-nav-button:hover { background-color: #e5e7eb; } .control-nav-button.active { background-color: var(--primary-color); color: white; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); } .control-nav-button i { margin-right: 0.75rem; width: 20px; text-align: center; } #controls-panels { flex-grow: 1; padding: 1.5rem; overflow-y: auto; } .control-panel { display: none; } .control-panel.active { display: block; } .control-panel h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1.5rem; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.75rem; } .control-group-label { font-weight: 600; font-size: 0.875rem; color: #4b5563; margin-top: 1.25rem; margin-bottom: 0.75rem; padding-bottom: 0.25rem; border-bottom: 1px solid #e5e7eb; } .item-toolbar { display: flex; justify-content: flex-end; gap: 0.25rem; margin-bottom: 0.5rem; } .item-toolbar button { line-height: 1; } .layout-item { cursor: move; } .code-modal-pre { background-color: #2d3748; color: #e2e8f0; padding: 1rem; border-radius: 0.375rem; max-height: 200px; overflow-y: auto; position: relative; } /* CKEditor Styles */ .ck-editor__editable_inline { min-height: 150px; } .info-card-item-controls .controls-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem; background-color: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 0.375rem; cursor: pointer; } .info-card-item-controls .controls-body { display: none; padding: 1.25rem; border: 1px solid #e5e7eb; border-top: 0; border-radius: 0 0 0.375rem 0.375rem; } .info-card-item-controls.open .controls-body { display: block; } </style> </head> <body class="text-gray-800"> <div id="app" class="flex flex-col h-screen"> <header class="bg-white shadow-md p-4 flex justify-between items-center z-20"> <h1 class="text-xl font-bold text-gray-700">Component Builder</h1> <div class="flex items-center space-x-4"> <button id="import-btn" class="flex items-center space-x-2 bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> <path d="M10 2a1 1 0 00-1 1v5.586l-1.293-1.293a1 1 0 00-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 8.586V3a1 1 0 00-1-1z"></path> <path d="M4 14a1 1 0 011 1v1a1 1 0 001 1h8a1 1 0 001-1v-1a1 1 0 112 0v1a3 3 0 01-3 3H6a3 3 0 01-3-3v-1a1 1 0 011-1z"></path> </svg> <span>Import</span> </button> <input type="file" id="import-file-input" class="hidden" accept=".html"> <div id="export-menu-container" class="relative"> <button id="export-menu-btn" class="flex items-center space-x-2 bg-green-600 text-white font-bold py-2 px-4 rounded-md hover:bg-green-700 transition"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg> <span>Export Page</span> </button> <div id="export-dropdown" class="hidden absolute right-0 mt-2 w-64 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-30"> <div class="py-1" role="menu" aria-orientation="vertical" aria-labelledby="export-menu-btn"> <a href="#" id="copy-combined-code" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path></svg> <span>Copy Combined Code</span> </a> <a href="#" id="copy-html" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path d="M5 5a2 2 0 012-2h10a2 2 0 012 2v1h- savaşmak-14V5zM3 8h18v10a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"></path></svg> <span>Copy Page HTML</span> </a> <a href="#" id="copy-css" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01"></path></svg> <span>Copy Page CSS</span> </a> <a href="#" id="copy-js" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1h1a1 1 0 010 2h-1v1a1 1 0 01-2 0V6H8a1 1 0 010-2h1V3a1 1 0 011-1zM5 5a3 3 0 013-3h4a3 3 0 013 3v1h-1V5a2 2 0 00-2-2H8a2 2 0 00-2 2v1H5V5zm2 5a1 1 0 011-1h4a1 1 0 110 2H8a1 1 0 01-1-1zm-1 4a1 1 0 100 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /></svg> <span>Copy Page JS</span> </a> <div class="border-t border-gray-100"></div> <a href="#" id="download-zip-btn" class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-3 text-gray-500" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 3a1 1 0 000 2h10a1 1 0 100-2H5zM5 13a1 1 0 100 2h10a1 1 0 100-2H5z" clip-rule="evenodd"></path></svg> <span>Download Page .zip</span> </a> </div> </div> </div> <div class="flex items-center space-x-2"> <span class="text-sm font-medium text-gray-500">Preview:</span> <button id="desktop-btn" class="p-2 rounded-md bg-blue-500 text-white shadow" title="Desktop View"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 2a2 2 0 00-2 2v1H6a2 2 0 00-2 2v7a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2V4a2 2 0 00-2-2zm-1 3V4a1 1 0 112 0v1h-2zM6 7v7h8V7H6z" clip-rule="evenodd"></path></svg> </button> <button id="tablet-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Tablet View"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4 2a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2H4zm1 2a1 1 0 00-1 1v10a1 1 0 001 1h10a1 1 0 001-1V5a1 1 0 00-1-1H5z" clip-rule="evenodd"></path></svg> </button> <button id="mobile-btn" class="p-2 rounded-md bg-gray-200 text-gray-700" title="Mobile View"> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path d="M5 2a2 2 0 00-2 2v12a2 2 0 002 2h6a2 2 0 002-2V4a2 2 0 00-2-2H5z"></path></svg> </button> </div> </div> </header> <div class="flex flex-1 overflow-hidden"> <aside class="w-1/3 bg-white shadow-lg overflow-hidden"> <div id="controls-layout"> <nav id="controls-nav" class="space-y-2"> <button class="control-nav-button" data-target="#panel-global-settings"><i class="fas fa-cog"></i>Global</button> <button class="control-nav-button" data-target="#panel-layout"><i class="fas fa-layer-group"></i>Layout</button> <button class="control-nav-button" data-target="#panel-page-title"><i class="fas fa-heading"></i>Page Title</button> <button class="control-nav-button" data-target="#panel-info-cards"><i class="fas fa-info-circle"></i>Info Cards</button> <button class="control-nav-button" data-target="#panel-custom-html"><i class="fas fa-code"></i>Custom HTML</button> </nav> <div id="controls-panels"> <div id="panel-global-settings" class="control-panel"> <h3>⚙️ Global Settings</h3> <div class="space-y-4"> <div class="space-y-2 border-b pb-4"> <label class="font-medium text-sm">Color Palette</label> <div class="grid grid-cols-2 gap-2 text-xs"> <div> <label for="global-color-primary">Primary</label> <input type="color" id="global-color-primary" class="w-full p-0 h-8 border-none rounded-md"> </div> <div> <label for="global-color-secondary">Secondary</label> <input type="color" id="global-color-secondary" class="w-full p-0 h-8 border-none rounded-md"> </div> <div> <label for="global-color-text">Text</label> <input type="color" id="global-color-text" class="w-full p-0 h-8 border-none rounded-md"> </div> <div> <label for="global-color-heading">Heading</label> <input type="color" id="global-color-heading" class="w-full p-0 h-8 border-none rounded-md"> </div> </div> </div> <div class="space-y-2 border-b pb-4"> <label class="font-medium text-sm">Typography</label> <div> <label for="global-font-family" class="text-xs">Font Family</label> <select id="global-font-family" class="w-full p-1 border rounded-md text-sm"> <option value="'Inter', sans-serif">Inter</option> <option value="'Roboto', sans-serif">Roboto</option> <option value="'Open Sans', sans-serif">Open Sans</option> <option value="'Lato', sans-serif">Lato</option> <option value="'Montserrat', sans-serif">Montserrat</option> <option value="'Poppins', sans-serif">Poppins</option> </select> </div> </div> <button id="apply-global-settings" class="w-full bg-blue-600 text-white font-bold py-2 px-4 rounded-md hover:bg-blue-700 transition">Apply Global Styles</button> </div> </div> <div id="panel-layout" class="control-panel"> <h3>↕️ Component Layout</h3> <p class="text-xs text-gray-500 mb-4">Drag and drop to change the vertical order of the components on your page.</p> <div id="layout-builder-container" class="space-y-2"></div> </div> <div id="panel-page-title" class="control-panel"> <div class="flex justify-between items-center mb-4"> <h3 class="mb-0 pb-0 border-b-0">✏️ Page Title</h3> <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="pageTitle"> <i class="fas fa-code mr-1"></i> Get Code </button> </div> <div class="space-y-4"> <div class="flex items-center space-x-2 border-b pb-4"> <input type="checkbox" id="page-title-toggle" class="h-4 w-4 rounded"> <label for="page-title-toggle" class="font-medium">Enable Page Title Section</label> </div> <div id="page-title-builder" class="space-y-4"> <div> <label for="page-title-text" class="text-sm font-medium">Main Title</label> <input type="text" id="page-title-text" class="w-full p-2 border rounded-md mt-1"> </div> <div> <label for="page-subtitle-text" class="text-sm font-medium">Subtitle</label> <textarea id="page-subtitle-text" rows="3" class="w-full p-2 border rounded-md mt-1"></textarea> </div> <div class="grid grid-cols-2 gap-4"> <div> <label for="page-title-size" class="text-sm font-medium">Title Size</label> <select id="page-title-size" class="w-full p-2 border rounded-md mt-1"> <option value="text-2xl">Small</option> <option value="text-3xl">Medium</option> <option value="text-4xl">Large</option> <option value="text-5xl">XL</option> <option value="text-6xl">2XL</option> </select> </div> <div> <label for="page-subtitle-size" class="text-sm font-medium">Subtitle Size</label> <select id="page-subtitle-size" class="w-full p-2 border rounded-md mt-1"> <option value="text-base">Small</option> <option value="text-lg">Medium</option> <option value="text-xl">Large</option> <option value="text-2xl">XL</option> </select> </div> </div> <div> <label class="text-sm font-medium">Text Alignment</label> <div id="page-title-alignment" class="flex items-center space-x-4 mt-2 p-1 bg-gray-100 rounded-lg"> <label class="flex-1 text-center p-1 rounded-md cursor-pointer has-[:checked]:bg-white has-[:checked]:shadow-sm"> <input type="radio" name="alignment" value="left" class="sr-only"> Left </label> <label class="flex-1 text-center p-1 rounded-md cursor-pointer has-[:checked]:bg-white has-[:checked]:shadow-sm"> <input type="radio" name="alignment" value="center" class="sr-only"> Center </label> <label class="flex-1 text-center p-1 rounded-md cursor-pointer has-[:checked]:bg-white has-[:checked]:shadow-sm"> <input type="radio" name="alignment" value="right" class="sr-only"> Right </label> </div> </div> </div> </div> </div> <div id="panel-info-cards" class="control-panel"> <div class="flex justify-between items-center mb-4"> <h3 class="mb-0 pb-0 border-b-0">ℹ️ Information Cards</h3> <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="infoCards"> <i class="fas fa-code mr-1"></i> Get Code </button> </div> <div class="flex items-center space-x-2 mb-4 border-b pb-4"> <input type="checkbox" id="info-cards-toggle" class="h-4 w-4 rounded"> <label for="info-cards-toggle" class="font-medium">Enable Info Cards Section</label> </div> <div id="info-cards-list" class="space-y-3"></div> <button id="add-info-card-btn" class="mt-4 w-full flex items-center justify-center space-x-2 bg-green-600 text-white font-bold py-2 px-4 rounded-md hover:bg-green-700 transition"> <i class="fas fa-plus"></i> <span>Add New Info Card</span> </button> </div> <div id="panel-custom-html" class="control-panel"> <div class="flex justify-between items-center mb-6"> <h3 class="mb-0 pb-0 border-b-0"> </> Custom HTML</h3> <button class="get-component-code-btn text-sm bg-indigo-500 text-white py-1 px-3 rounded-md hover:bg-indigo-600" data-component-key="customHtml"> <i class="fas fa-code mr-1"></i> Get Code </button> </div> <div class="space-y-4"> <div class="flex items-center space-x-2 border-b pb-4"> <input type="checkbox" id="custom-html-toggle" class="h-4 w-4 rounded"> <label for="custom-html-toggle" class="font-medium">Enable Custom HTML Section</label> </div> <div id="custom-html-builder"> <label for="custom-html-content" class="text-sm font-medium">HTML Content</label> <p class="text-xs text-gray-500 mb-2">Paste any valid HTML. Be cautious, as invalid code can break the page layout.</p> <textarea id="custom-html-content" rows="10" class="w-full p-2 border rounded-md font-mono text-sm"></textarea> </div> </div> </div> </div> </div> </aside> <main class="w-2/3 bg-gray-200 p-4 flex flex-col items-center justify-center overflow-hidden"> <div id="preview-container" class="bg-white shadow-lg rounded-lg w-full h-full overflow-hidden"> <iframe id="preview-iframe" class="preview-iframe"></iframe> </div> </main> </div> </div> <div id="toast-notification" class="toast"></div> <div id="code-modal" class="hidden fixed inset-0 bg-gray-600 bg-opacity-75 overflow-y-auto h-full w-full z-50"> <div class="relative top-10 mx-auto p-5 border w-11/12 md:w-2/3 shadow-lg rounded-md bg-white"> <div class="flex justify-between items-center border-b pb-3"> <h3 id="code-modal-title" class="text-lg leading-6 font-medium text-gray-900">Component Code</h3> <button id="close-code-modal-btn" class="text-gray-400 hover:text-gray-600">&times;</button> </div> <div class="mt-4 space-y-4"> <div> <label class="font-semibold text-gray-700">HTML</label> <pre id="code-modal-html" class="code-modal-pre"><code></code></pre> </div> <div> <label class="font-semibold text-gray-700">CSS</label> <pre id="code-modal-css" class="code-modal-pre"><code></code></pre> </div> <div> <label class="font-semibold text-gray-700">JavaScript</label> <pre id="code-modal-js" class="code-modal-pre"><code></code></pre> </div> </div> <div class="items-center px-4 py-3 mt-4 text-right bg-gray-50 -mx-5 -mb-5 rounded-b-md"> <button id="download-component-zip-btn" class="px-4 py-2 bg-green-600 text-white text-base font-medium rounded-md shadow-sm hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-300"> Download .zip </button> <button id="close-code-modal-btn-2" class="px-4 py-2 bg-gray-200 text-gray-800 text-base font-medium rounded-md shadow-sm hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-300 ml-2"> Close </button> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', () => { // State object to hold all configurations const config = { globalSettings: { colors: { primary: '#3b82f6', secondary: '#10b981', text: '#374151', heading: '#111827', }, typography: { fontFamily: "'Inter', sans-serif", } }, componentOrder: [ 'pageTitle', 'infoCards', 'customHtml' ], pageTitle: { enabled: true, title: 'Welcome to Our Page', subtitle: 'This is a subtitle describing the page content. You can edit this text in the control panel.', alignment: 'center', titleSize: 'text-4xl', subtitleSize: 'text-lg' }, infoCards: { enabled: true, items: [ { id: Date.now(), imageUrl: 'https://images.unsplash.com/photo-1517694712202-14dd9538aa97?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=60', title: 'Enhanced Information Card', date: '2025-08-15', batch: 'New', summary: 'This card is now more powerful with new features like image positioning, a CTA button, and smooth animations.', content: '<p>This is the <strong>detailed information</strong> that appears when you expand the card. It supports <em>rich text</em>, lists, and more, thanks to CKEditor.</p><ul><li>Easy to edit.</li><li>Visually appealing.</li><li>Fully customizable.</li></ul>', button: { enabled: true, text: 'Learn More', url: '#', }, imagePosition: 'left', defaultExpanded: false, }, { id: Date.now() + 1, imageUrl: 'https://images.unsplash.com/photo-1499951360447-b19be8fe80f5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=800&q=60', title: 'Older Post Example', date: '2025-08-10', batch: 'Hot', summary: 'This is an example of an older card to demonstrate the sorting functionality.', content: '<p>This content belongs to the older card.</p>', button: { enabled: true, text: 'Read Story', url: '#', }, imagePosition: 'right', defaultExpanded: false, } ] }, customHtml: { enabled: false, content: '' } }; const componentNames = { pageTitle: 'Page Title', infoCards: 'Info Cards', customHtml: 'Custom HTML' }; // UI Element References let editors = {}; const ui = { previewIframe: document.getElementById('preview-iframe'), controls: { nav: document.getElementById('controls-nav'), panels: document.getElementById('controls-panels'), }, globalSettings: { primaryColor: document.getElementById('global-color-primary'), secondaryColor: document.getElementById('global-color-secondary'), textColor: document.getElementById('global-color-text'), headingColor: document.getElementById('global-color-heading'), fontFamily: document.getElementById('global-font-family'), applyBtn: document.getElementById('apply-global-settings'), }, layout: { container: document.getElementById('layout-builder-container'), panel: document.getElementById('panel-layout') }, pageTitle: { toggle: document.getElementById('page-title-toggle'), title: document.getElementById('page-title-text'), subtitle: document.getElementById('page-subtitle-text'), alignment: document.getElementById('page-title-alignment'), titleSize: document.getElementById('page-title-size'), subtitleSize: document.getElementById('page-subtitle-size'), }, infoCards: { toggle: document.getElementById('info-cards-toggle'), listContainer: document.getElementById('info-cards-list'), addBtn: document.getElementById('add-info-card-btn'), }, customHtml: { toggle: document.getElementById('custom-html-toggle'), content: document.getElementById('custom-html-content'), }, buttons: { desktop: document.getElementById('desktop-btn'), tablet: document.getElementById('tablet-btn'), mobile: document.getElementById('mobile-btn'), import: document.getElementById('import-btn'), importFile: document.getElementById('import-file-input'), }, exportMenu: { container: document.getElementById('export-menu-container'), button: document.getElementById('export-menu-btn'), dropdown: document.getElementById('export-dropdown'), copyCombined: document.getElementById('copy-combined-code'), copyHtml: document.getElementById('copy-html'), copyCss: document.getElementById('copy-css'), copyJs: document.getElementById('copy-js'), downloadZip: document.getElementById('download-zip-btn'), }, codeModal: { modal: document.getElementById('code-modal'), title: document.getElementById('code-modal-title'), htmlContainer: document.getElementById('code-modal-html'), cssContainer: document.getElementById('code-modal-css'), jsContainer: document.getElementById('code-modal-js'), htmlCode: document.querySelector('#code-modal-html code'), cssCode: document.querySelector('#code-modal-css code'), jsCode: document.querySelector('#code-modal-js code'), downloadBtn: document.getElementById('download-component-zip-btn'), closeBtns: [document.getElementById('close-code-modal-btn'), document.getElementById('close-code-modal-btn-2')], }, previewContainer: document.getElementById('preview-container'), }; // --- Event Listeners --- function setupEventListeners() { ui.controls.nav.addEventListener('click', (e) => { const button = e.target.closest('.control-nav-button'); if (!button) return; const targetPanelId = button.dataset.target; ui.controls.nav.querySelectorAll('.control-nav-button').forEach(btn => btn.classList.remove('active')); button.classList.add('active'); ui.controls.panels.querySelectorAll('.control-panel').forEach(panel => { panel.classList.toggle('active', `#${panel.id}` === targetPanelId); }); }); // Global Settings Listeners ui.globalSettings.primaryColor.addEventListener('input', e => { config.globalSettings.colors.primary = e.target.value; renderAll(); }); ui.globalSettings.secondaryColor.addEventListener('input', e => { config.globalSettings.colors.secondary = e.target.value; renderAll(); }); ui.globalSettings.textColor.addEventListener('input', e => { config.globalSettings.colors.text = e.target.value; renderAll(); }); ui.globalSettings.headingColor.addEventListener('input', e => { config.globalSettings.colors.heading = e.target.value; renderAll(); }); ui.globalSettings.fontFamily.addEventListener('change', e => { config.globalSettings.typography.fontFamily = e.target.value; renderAll(); }); ui.globalSettings.applyBtn.addEventListener('click', () => { renderAll(); showToast('Global styles applied!'); }); // Layout Controls ui.layout.panel.addEventListener('click', handleLayoutControlsClick); setupDragAndDrop(); // --- Component Listeners: Page Title --- ui.pageTitle.toggle.addEventListener('change', e => { config.pageTitle.enabled = e.target.checked; renderAll(); }); ui.pageTitle.title.addEventListener('input', e => { config.pageTitle.title = e.target.value; renderAll(); }); ui.pageTitle.subtitle.addEventListener('input', e => { config.pageTitle.subtitle = e.target.value; renderAll(); }); ui.pageTitle.alignment.addEventListener('change', e => { if (e.target.name === 'alignment') { config.pageTitle.alignment = e.target.value; renderAll(); } }); ui.pageTitle.titleSize.addEventListener('change', e => { config.pageTitle.titleSize = e.target.value; renderAll(); }); ui.pageTitle.subtitleSize.addEventListener('change', e => { config.pageTitle.subtitleSize = e.target.value; renderAll(); }); // --- Component Listeners: Info Cards --- ui.infoCards.toggle.addEventListener('change', e => { config.infoCards.enabled = e.target.checked; renderAll(); }); ui.infoCards.addBtn.addEventListener('click', handleAddInfoCard); ui.infoCards.listContainer.addEventListener('click', handleInfoCardListClick); ui.infoCards.listContainer.addEventListener('input', handleInfoCardInputChange); setupInfoCardDragAndDrop(); // --- Component Listeners: Custom HTML --- ui.customHtml.toggle.addEventListener('change', e => { config.customHtml.enabled = e.target.checked; renderAll(); }); ui.customHtml.content.addEventListener('input', e => { config.customHtml.content = e.target.value; renderAll(); }); // Preview & Export ui.buttons.desktop.addEventListener('click', () => setPreviewMode('desktop')); ui.buttons.tablet.addEventListener('click', () => setPreviewMode('tablet')); ui.buttons.mobile.addEventListener('click', () => setPreviewMode('mobile')); ui.exportMenu.button.addEventListener('click', (e) => { e.stopPropagation(); ui.exportMenu.dropdown.classList.toggle('hidden'); }); window.addEventListener('click', (e) => { if (!ui.exportMenu.container.contains(e.target)) { ui.exportMenu.dropdown.classList.add('hidden'); } }); const copyAction = (e, dataGetter, message) => { e.preventDefault(); navigator.clipboard.writeText(dataGetter()).then(() => showToast(message)); ui.exportMenu.dropdown.classList.add('hidden'); }; ui.exportMenu.copyCombined.addEventListener('click', (e) => copyAction(e, getCombinedCode, 'Combined code copied!')); ui.exportMenu.copyHtml.addEventListener('click', (e) => copyAction(e, getAllHtml, 'All HTML copied!')); ui.exportMenu.copyCss.addEventListener('click', (e) => copyAction(e, getFullCSS, 'All CSS copied!')); ui.exportMenu.copyJs.addEventListener('click', (e) => copyAction(e, getFullJS, 'All JS copied!')); ui.exportMenu.downloadZip.addEventListener('click', (e) => { e.preventDefault(); generatePageZip(); ui.exportMenu.dropdown.classList.add('hidden'); }); // Import ui.buttons.import.addEventListener('click', () => ui.buttons.importFile.click()); ui.buttons.importFile.addEventListener('change', handleFileImport); // Code Modal Listeners ui.controls.panels.addEventListener('click', handleGetCodeClick); ui.codeModal.closeBtns.forEach(btn => btn.addEventListener('click', () => ui.codeModal.modal.classList.add('hidden'))); } // --- LAYOUT CONTROLS --- function renderLayoutControls() { ui.layout.container.innerHTML = config.componentOrder.map((key, index) => { const total = config.componentOrder.length; return ` <div class="layout-item p-3 border rounded-md bg-white flex items-center justify-between" draggable="true" data-key="${key}"> <span class="font-medium text-sm"><i class="fas fa-grip-vertical mr-3 text-gray-400"></i> ${componentNames[key]}</span> <div class="item-toolbar mb-0"> <button class="reorder-layout-up-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === 0 ? 'disabled' : ''}><i class="fas fa-arrow-up fa-fw"></i></button> <button class="reorder-layout-down-btn text-xs bg-gray-200 text-gray-700 p-1 rounded-md hover:bg-gray-300" data-index="${index}" ${index === total - 1 ? 'disabled' : ''}><i class="fas fa-arrow-down fa-fw"></i></button> </div> </div>`; }).join(''); } function handleLayoutControlsClick(e) { const button = e.target.closest('button'); if (!button) return; const index = parseInt(button.dataset.index, 10); const order = config.componentOrder; if (button.classList.contains('reorder-layout-up-btn') && index > 0) { [order[index], order[index - 1]] = [order[index - 1], order[index]]; } else if (button.classList.contains('reorder-layout-down-btn') && index < order.length - 1) { [order[index], order[index + 1]] = [order[index + 1], order[index]]; } renderLayoutControls(); renderAll(); } function setupDragAndDrop() { let draggedItem = null; ui.layout.container.addEventListener('dragstart', e => { draggedItem = e.target; setTimeout(() => e.target.style.display = 'none', 0); }); ui.layout.container.addEventListener('dragend', () => { setTimeout(() => { draggedItem.style.display = 'flex'; draggedItem = null; }, 0); }); ui.layout.container.addEventListener('dragover', e => { e.preventDefault(); const afterElement = [...ui.layout.container.querySelectorAll('.layout-item:not(.dragging)')].reduce((closest, child) => { const box = child.getBoundingClientRect(); const offset = e.clientY - box.top - box.height / 2; return (offset < 0 && offset > closest.offset) ? { offset: offset, element: child } : closest; }, { offset: Number.NEGATIVE_INFINITY }).element; if (afterElement == null) { ui.layout.container.appendChild(draggedItem); } else { ui.layout.container.insertBefore(draggedItem, afterElement); } }); ui.layout.container.addEventListener('drop', e => { e.preventDefault(); config.componentOrder = [...ui.layout.container.querySelectorAll('.layout-item')].map(item => item.dataset.key); renderLayoutControls(); renderAll(); }); } // --- Info Cards UI & Logic --- function renderInfoCardControls() { ui.infoCards.listContainer.innerHTML = config.infoCards.items.map((card, index) => { const cardId = `info-card-${card.id}`; return ` <div class="info-card-item-controls border border-gray-300 rounded-md" data-id="${card.id}" draggable="true"> <div class="controls-header bg-gray-100 p-2 rounded-t-md cursor-pointer flex justify-between items-center"> <span class="font-semibold text-sm flex items-center"> <i class="fas fa-grip-vertical mr-2 text-gray-400"></i> ${card.title || 'New Card'} </span> <div> <button class="text-red-500 hover:text-red-700 remove-info-card-btn p-1"><i class="fas fa-trash-alt"></i></button> <button class="text-gray-500 toggle-accordion-btn p-1"><i class="fas fa-chevron-down"></i></button> </div> </div> <div class="controls-body p-4 space-y-4"> <h4 class="control-group-label">Content</h4> <div class="grid grid-cols-2 gap-4"> <div> <label class="text-sm font-medium">Title</label> <input type="text" data-prop="title" value="${card.title}" class="w-full p-2 border rounded-md mt-1"> </div> <div> <label class="text-sm font-medium">Date</label> <input type="date" data-prop="date" value="${card.date}" class="w-full p-2 border rounded-md mt-1"> </div> </div> <div> <label class="text-sm font-medium">Image URL</label> <input type="text" data-prop="imageUrl" value="${card.imageUrl}" class="w-full p-2 border rounded-md mt-1" placeholder="https://example.com/image.jpg"> </div> <div> <label class="text-sm font-medium">Summary</label> <textarea data-prop="summary" rows="3" class="w-full p-2 border rounded-md mt-1">${card.summary}</textarea> </div> <div> <label class="text-sm font-medium">Full Content (Details)</label> <div class="mt-1"><textarea id="${cardId}-content">${card.content}</textarea></div> </div> <h4 class="control-group-label">Button (Optional)</h4> <div class="space-y-4"> <div class="flex items-center space-x-2"> <input type="checkbox" data-prop="button.enabled" ${card.button.enabled ? 'checked' : ''} class="h-4 w-4 rounded"> <label class="text-sm font-medium">Enable Button</label> </div> <div class="grid grid-cols-2 gap-4"> <div> <label class="text-sm font-medium">Button Text</label> <input type="text" data-prop="button.text" value="${card.button.text}" class="w-full p-2 border rounded-md mt-1"> </div> <div> <label class="text-sm font-medium">Button URL</label> <input type="text" data-prop="button.url" value="${card.button.url}" class="w-full p-2 border rounded-md mt-1" placeholder="#"> </div> </div> </div> <h4 class="control-group-label">Appearance & Behavior</h4> <div class="grid grid-cols-2 gap-4"> <div> <label class="text-sm font-medium">Image Position</label> <select data-prop="imagePosition" class="w-full p-2 border rounded-md mt-1"> <option value="left" ${card.imagePosition === 'left' ? 'selected' : ''}>Left</option> <option value="right" ${card.imagePosition === 'right' ? 'selected' : ''}>Right</option> <option value="top" ${card.imagePosition === 'top' ? 'selected' : ''}>Top</option> </select> </div> <div> <label class="text-sm font-medium">Batch</label> <select data-prop="batch" class="w-full p-2 border rounded-md mt-1"> <option value="">None</option> <option value="New" ${card.batch === 'New' ? 'selected' : ''}>New</option> <option value="Hot" ${card.batch === 'Hot' ? 'selected' : ''}>Hot</option> <option value="Premium" ${card.batch === 'Premium' ? 'selected' : ''}>Premium</option> <option value="Live" ${card.batch === 'Live' ? 'selected' : ''}>Live</option> <option value="Latest" ${card.batch === 'Latest' ? 'selected' : ''}>Latest</option> </select> </div> </div> <div class="flex items-center space-x-2"> <input type="checkbox" data-prop="defaultExpanded" ${card.defaultExpanded ? 'checked' : ''} class="h-4 w-4 rounded"> <label class="text-sm font-medium">Expanded by default</label> </div> </div> </div> `; }).join(''); initEditorsForInfoCards(); } function initEditorsForInfoCards() { Object.values(editors).forEach(editor => editor.destroy()); editors = {}; config.infoCards.items.forEach(card => { const textarea = document.getElementById(`info-card-${card.id}-content`); if (textarea) { ClassicEditor .create(textarea) .then(editor => { editors[card.id] = editor; editor.model.document.on('change:data', () => { const cardToUpdate = config.infoCards.items.find(c => c.id === card.id); if (cardToUpdate) { cardToUpdate.content = editor.getData(); renderAll(); } }); }) .catch(error => console.error('CKEditor initialization error:', error)); } }); } function handleAddInfoCard() { const newCard = { id: Date.now(), imageUrl: '', title: 'New Information Card', date: '', batch: '', summary: 'A brief summary of the new card.', content: '<p>Detailed content goes here.</p>', button: { enabled: false, text: 'Click Me', url: '#' }, imagePosition: 'left', defaultExpanded: false, }; config.infoCards.items.push(newCard); renderInfoCardControls(); renderAll(); } function handleInfoCardListClick(e) { const removeBtn = e.target.closest('.remove-info-card-btn'); const toggleBtn = e.target.closest('.toggle-accordion-btn'); if (removeBtn) { const cardElement = removeBtn.closest('.info-card-item-controls'); const cardId = parseInt(cardElement.dataset.id, 10); if (confirm('Are you sure you want to delete this card?')) { config.infoCards.items = config.infoCards.items.filter(card => card.id !== cardId); renderInfoCardControls(); renderAll(); } } else if (toggleBtn) { const cardElement = toggleBtn.closest('.info-card-item-controls'); cardElement.classList.toggle('open'); const icon = toggleBtn.querySelector('i'); icon.classList.toggle('fa-chevron-down'); icon.classList.toggle('fa-chevron-up'); } } function handleInfoCardInputChange(e) { const input = e.target; const propPath = input.dataset.prop; if (!propPath) return; const cardElement = input.closest('.info-card-item-controls'); const cardId = parseInt(cardElement.dataset.id, 10); const card = config.infoCards.items.find(c => c.id === cardId); if (!card) return; let value = input.type === 'checkbox' ? input.checked : input.value; const props = propPath.split('.'); let current = card; for (let i = 0; i < props.length - 1; i++) { current = current[props[i]]; } current[props[props.length - 1]] = value; if (propPath === 'title') { cardElement.querySelector('.controls-header span').textContent = value || 'New Card'; } renderAll(); } function setupInfoCardDragAndDrop() { let draggedItem = null; ui.infoCards.listContainer.addEventListener('dragstart', e => { if (e.target.classList.contains('info-card-item-controls')) { draggedItem = e.target; setTimeout(() => e.target.style.opacity = '0.5', 0); } }); ui.infoCards.listContainer.addEventListener('dragend', () => { if(draggedItem) { setTimeout(() => { draggedItem.style.opacity = '1'; draggedItem = null; }, 0); } }); ui.infoCards.listContainer.addEventListener('dragover', e => { e.preventDefault(); if (!draggedItem) return; const afterElement = [...ui.infoCards.listContainer.querySelectorAll('.info-card-item-controls:not(.dragging)')].reduce((closest, child) => { const box = child.getBoundingClientRect(); const offset = e.clientY - box.top - box.height / 2; return (offset < 0 && offset > closest.offset) ? { offset: offset, element: child } : closest; }, { offset: Number.NEGATIVE_INFINITY }).element; if (afterElement == null) { ui.infoCards.listContainer.appendChild(draggedItem); } else { ui.infoCards.listContainer.insertBefore(draggedItem, afterElement); } }); ui.infoCards.listContainer.addEventListener('drop', e => { e.preventDefault(); if (!draggedItem) return; const newOrder = [...ui.infoCards.listContainer.querySelectorAll('.info-card-item-controls')].map(item => parseInt(item.dataset.id, 10)); config.infoCards.items.sort((a, b) => newOrder.indexOf(a.id) - newOrder.indexOf(b.id)); renderAll(); }); } // --- HTML Generation Logic --- const componentGenerators = { pageTitle: generatePageTitleHTML, infoCards: generateInfoCardsHTML, customHtml: generateCustomHtmlHTML }; function getAllHtml() { return config.componentOrder .map(key => componentGenerators[key] ? componentGenerators[key]() : '') .filter(Boolean) .join('\n\n'); } function generatePageTitleHTML() { if (!config.pageTitle.enabled) return ''; const { title, subtitle, alignment, titleSize, subtitleSize } = config.pageTitle; return ` <div class="page-title-container" data-alignment="${alignment}"> <h1 class="page-main-title ${titleSize}">${title}</h1> <p class="page-subtitle ${subtitleSize}">${subtitle}</p> </div>`; } function generateInfoCardsHTML() { if (!config.infoCards.enabled) return ''; const cardsHtml = config.infoCards.items.map(card => { const { imageUrl, title, summary, content, button, imagePosition, defaultExpanded, date, batch } = card; const expandedClass = defaultExpanded ? 'expanded' : ''; const buttonHtml = button.enabled ? `<a href="${button.url}" class="info-card-cta">${button.text}</a>` : ''; const dateHtml = date ? `<p class="info-card-date">${date}</p>` : ''; const batchHtml = batch ? `<div class="info-card-batch batch-${batch.toLowerCase()}">${batch}</div>` : ''; return ` <div class="info-card ${expandedClass}" data-image-position="${imagePosition}"> ${batchHtml} <div class="info-card-header"> <img src="${imageUrl}" alt="${title}" class="info-card-image"> <div class="info-card-summary-content"> <h4 class="info-card-title">${title}</h4> ${dateHtml} <p class="info-card-summary">${summary}</p> </div> <i class="fas fa-chevron-down info-card-icon"></i> </div> <div class="info-card-body"> <div class="info-card-body-content"> ${content} ${buttonHtml} </div> </div> </div>`; }).join(''); const viewToggleHtml = ` <div class="info-card-view-toggle"> <button class="active" data-view="card" title="Card View"><i class="fas fa-th-large"></i></button> <button data-view="list" title="List View"><i class="fas fa-list"></i></button> </div> `; return `<div class="info-cards-container p-4"> ${viewToggleHtml} <div class="space-y-4">${cardsHtml}</div></div>`; } function generateCustomHtmlHTML() { if (!config.customHtml.enabled) return ''; return `<div class="custom-html-section">${config.customHtml.content}</div>`; } function generateComponentCSS(targetKey = null) { const { colors, typography } = config.globalSettings; const css = {}; css.global = ` /* --- Global --- */ :root { --primary-color: ${colors.primary}; --secondary-color: ${colors.secondary}; --text-color: ${colors.text}; --heading-color: ${colors.heading}; --font-family: ${typography.fontFamily}; } body { font-family: var(--font-family); color: var(--text-color); margin: 0; background-color: #f0f2f5; } h1,h2,h3,h4,h5,h6 { color: var(--heading-color); } `; if(config.pageTitle.enabled) css.pageTitle = ` /* --- Page Title Section --- */ .page-title-container { padding: 2.5rem 1rem; } .page-title-container[data-alignment="left"] { text-align: left; } .page-title-container[data-alignment="center"] { text-align: center; } .page-title-container[data-alignment="right"] { text-align: right; } .page-main-title { font-weight: 800; color: var(--heading-color); line-height: 1.2; margin-bottom: 0.75rem; } .page-subtitle { color: var(--text-color); max-width: 650px; opacity: 0.9; } .page-title-container[data-alignment="center"] .page-subtitle { margin-left: auto; margin-right: auto; } .page-title-container[data-alignment="right"] .page-subtitle { margin-left: auto; } `; if(config.infoCards.enabled) css.infoCards = ` /* --- Info Card Section --- */ .info-card { position: relative; background-color: white; border-radius: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1); overflow: hidden; } .info-card-header { display: flex; align-items: center; gap: 1rem; padding: 1rem; cursor: pointer; transition: background-color 0.2s; } .info-card-header:hover { background-color: #f9fafb; } .info-card-summary-content { flex-grow: 1; } .info-card-title { font-size: 1.125rem; font-weight: 600; color: var(--heading-color); margin-bottom: 0.25rem; } .info-card-date { font-size: 0.75rem; color: #6b7280; margin-bottom: 0.5rem; } .info-card-summary { font-size: 0.875rem; color: var(--text-color); opacity: 0.9; } .info-card-icon { transition: transform 0.4s ease; } .info-card.expanded .info-card-icon { transform: rotate(180deg); } /* Batch Styles */ .info-card-batch { position: absolute; top: 0.75rem; right: 0.75rem; padding: 0.25rem 0.6rem; font-size: 0.7rem; font-weight: bold; color: white; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.5px; } .batch-new { background-color: #3b82f6; } .batch-hot { background-color: #ef4444; } .batch-premium { background-color: #a855f7; } .batch-live { background-color: #22c55e; } .batch-latest { background-color: #f97316; } /* Image Positions */ .info-card[data-image-position="right"] .info-card-header { flex-direction: row-reverse; } .info-card[data-image-position="top"] .info-card-header { flex-direction: column; align-items: flex-start; } .info-card[data-image-position="top"] .info-card-image { width: 100%; height: auto; margin-bottom: 0.75rem; } .info-card[data-image-position="top"] .info-card-icon { align-self: flex-end; margin-top: -2.5rem; padding-right: 0.5rem; color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.5); } .info-card-image { width: 128px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 0.375rem; flex-shrink: 0; } /* Body Animation */ .info-card-body { max-height: 0; overflow: hidden; transition: max-height 0.5s ease-in-out, padding 0.5s ease-in-out; padding: 0 1rem; } .info-card.expanded .info-card-body { max-height: 1500px; /* Should be larger than any possible content */ padding: 1rem 1rem; border-top: 1px solid #e5e7eb; } .info-card-body-content { line-height: 1.6; } /* CTA Button */ .info-card-cta { display: inline-block; margin-top: 1.25rem; padding: 0.6rem 1.5rem; background-color: #ede9fe; /* Light Violet */ color: #5b21b6; /* Dark Violet */ text-decoration: none; border-radius: 9999px; font-weight: 600; transition: background-color 0.2s; } .info-card-cta:hover { background-color: #ddd6fe; /* Slightly darker violet on hover */ } /* CKEditor Content Styles */ .info-card-body-content h1, .info-card-body-content h2, .info-card-body-content h3 { margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 600; color: var(--heading-color); } .info-card-body-content p { margin-bottom: 1rem; } .info-card-body-content ul, .info-card-body-content ol { margin-left: 1.5rem; margin-bottom: 1rem; } .info-card-body-content ul { list-style-type: disc; } .info-card-body-content ol { list-style-type: decimal; } .info-card-body-content a:not(.info-card-cta) { text-decoration: underline; color: var(--primary-color); } .info-card-body-content blockquote { border-left: 4px solid #e5e7eb; padding-left: 1rem; margin: 1rem 0; font-style: italic; } /* Mobile View Toggle */ .info-card-view-toggle { display: none; /* Hidden by default */ justify-content: center; margin-bottom: 1rem; background-color: #e5e7eb; padding: 0.25rem; border-radius: 999px; width: -moz-fit-content; width: fit-content; margin-left: auto; margin-right: auto; } .info-card-view-toggle button { border: none; background-color: transparent; border-radius: 999px; cursor: pointer; color: #4b5563; transition: all 0.2s; display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; font-size: 1rem; } .info-card-view-toggle button.active { background-color: white; color: var(--primary-color); box-shadow: 0 1px 3px rgba(0,0,0,0.1); } /* Responsive adjustments */ @media (max-width: 640px) { .info-card-view-toggle { display: flex; } .info-card-cta { width: 100%; text-align: center; } /* Default Mobile View: Card Layout */ .info-card[data-image-position="right"] .info-card-header, .info-card[data-image-position="left"] .info-card-header, .info-card-header { flex-direction: column; align-items: flex-start; } .info-card-image { width: 100%; height: auto; margin-bottom: 0.75rem; } .info-card-icon { align-self: flex-end; margin-top: -2.5rem; padding-right: 0.5rem; color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.5); } /* Optional Mobile View: List Layout */ .info-cards-container.list-view-active .info-card-header { flex-direction: row; align-items: center; } .info-cards-container.list-view-active .info-card-image { width: 64px; height: 64px; aspect-ratio: 1/1; margin-bottom: 0; } .info-cards-container.list-view-active .info-card-icon { align-self: center; margin-top: 0; padding-right: 0; color: var(--text-color); text-shadow: none; } .info-cards-container.list-view-active .info-card-summary { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } } `; if(config.customHtml.enabled) css.customHtml = `/* --- Custom HTML Section --- */ .custom-html-section { padding: 1rem 0; }`; return targetKey ? { global: css.global, component: css[targetKey] || '' } : css; } function getFullCSS() { const cssObject = generateComponentCSS(); const orderedCSS = config.componentOrder.map(key => cssObject[key]).filter(Boolean); return [cssObject.global, ...orderedCSS].join('\n\n'); } function generateComponentJavaScript(targetKey = null) { const js = {}; js.pageTitle = `/* No JS needed for Page Title */`; js.infoCards = ` /* --- Info Card Accordion Logic --- */ document.querySelectorAll('.info-card-header').forEach(header => { header.addEventListener('click', () => { header.parentElement.classList.toggle('expanded'); }); }); /* --- Info Card View Toggle (Mobile) --- */ const viewToggle = document.querySelector('.info-card-view-toggle'); if (viewToggle) { const container = document.querySelector('.info-cards-container'); const buttons = viewToggle.querySelectorAll('button'); viewToggle.addEventListener('click', (e) => { const button = e.target.closest('button'); if (!button || button.classList.contains('active')) return; const view = button.dataset.view; buttons.forEach(btn => btn.classList.remove('active')); button.classList.add('active'); if (view === 'list') { container.classList.add('list-view-active'); } else { container.classList.remove('list-view-active'); } }); } `; return targetKey ? (js[targetKey] || '') : js; } function getFullJS() { const jsObject = generateComponentJavaScript(); return config.componentOrder.map(key => jsObject[key] || '').filter(Boolean).join('\n\n'); } function getCombinedCode() { const htmlBody = getAllHtml(); const css = getFullCSS(); let js = getFullJS(); if (js.trim()) { js = `document.addEventListener('DOMContentLoaded', () => { \n${js.trim()} \n});`; } return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Exported Page</title> <script src="https://cdn.tailwindcss.com"><\/script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> <style> ${css} </style> </head> <body> ${htmlBody} ${js ? `<script>${js}<\/script>` : ''} </body> </html>`; } // --- Rendering --- function renderAll() { const fullJs = getFullJS(); const previewContent = `<!DOCTYPE html><html><head><title>Preview</title> <script src="https://cdn.tailwindcss.com"><\/script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> <style>${getFullCSS()}</style></head><body> <div class="site-wrapper">${getAllHtml()}</div> <script> ${fullJs ? `document.addEventListener('DOMContentLoaded', () => { \n${fullJs} \n});` : ''} <\/script></body></html>`; ui.previewIframe.srcdoc = previewContent; } // --- Utility Functions --- function setPreviewMode(mode) { ui.previewContainer.className = `bg-white shadow-lg rounded-lg w-full h-full overflow-hidden transition-all duration-300 preview-${mode}`; ['desktop', 'tablet', 'mobile'].forEach(m => { const btn = ui.buttons[m]; btn.classList.toggle('bg-blue-500', m === mode); btn.classList.toggle('text-white', m === mode); btn.classList.toggle('bg-gray-200', m !== mode); }); } function showToast(message) { const toast = document.getElementById('toast-notification'); toast.textContent = message; toast.classList.add('show'); setTimeout(() => { toast.classList.remove('show'); }, 3000); } function generatePageZip() { const zip = new JSZip(); const html = `<!DOCTYPE html> <html lang="en"><head> <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Exported Page</title> <script src="https://cdn.tailwindcss.com"><\/script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link rel="stylesheet" href="style.css"> </head> <body> ${getAllHtml()} <script src="script.js"><\/script> </body></html>`; const css = getFullCSS(); const js = getFullJS(); zip.file("index.html", html); zip.file("style.css", css); if (js.trim()) { zip.file("script.js", `document.addEventListener('DOMContentLoaded', () => { \n${js} \n});`); } zip.generateAsync({type:"blob"}).then(content => saveAs(content, "exported-page.zip")); } function handleFileImport(event) { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = e => { try { const doc = new DOMParser().parseFromString(e.target.result, 'text/html'); parseImportedDocument(doc); showToast('Import successful!'); } catch (error) { showToast('Error: Could not parse file.'); } event.target.value = null; }; reader.readAsText(file); } function parseImportedDocument(doc) { /* Placeholder for future import logic */ } function handleGetCodeClick(e) { const button = e.target.closest('.get-component-code-btn'); if (!button) return; const key = button.dataset.componentKey; const html = componentGenerators[key] ? componentGenerators[key]() : 'N/A'; const { global, component: css } = generateComponentCSS(key); const js = generateComponentJavaScript(key); ui.codeModal.title.textContent = `${componentNames[key]} Component Code`; ui.codeModal.htmlCode.textContent = html; ui.codeModal.cssCode.textContent = (global + '\n\n' + css).trim(); ui.codeModal.jsCode.textContent = js.trim() ? `document.addEventListener('DOMContentLoaded', () => { \n${js.trim()}\n });` : '// No JS'; [ui.codeModal.htmlContainer, ui.codeModal.cssContainer, ui.codeModal.jsContainer].forEach(el => { const code = el.querySelector('code').textContent; el.style.display = (code.trim() === '' || code.startsWith('// No JS')) ? 'none' : 'block'; }); ui.codeModal.downloadBtn.onclick = () => generateComponentZip(key); ui.codeModal.modal.classList.remove('hidden'); } function generateComponentZip(key) { const zip = new JSZip(); const { global, component: css } = generateComponentCSS(key); const js = generateComponentJavaScript(key); const htmlBody = componentGenerators[key] ? componentGenerators[key]() : ''; const html = `<!DOCTYPE html> <html lang="en"><head> <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>${componentNames[key]} Component</title> <script src="https://cdn.tailwindcss.com"><\/script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> <link rel="stylesheet" href="style.css"> </head><body> ${htmlBody} ${js.trim() && !js.trim().startsWith('/*') ? '<script src="script.js"><\/script>' : ''} </body></html>`; zip.file("index.html", html); zip.file("style.css", (global + '\n\n' + css).trim()); if (js.trim() && !js.trim().startsWith('/*')) { zip.file("script.js", `document.addEventListener('DOMContentLoaded', () => { \n${js} \n});`); } zip.generateAsync({type:"blob"}).then(content => saveAs(content, `${key}-component.zip`)); } // --- Initial Load --- function init() { const { pageTitle, infoCards, customHtml, globalSettings } = config; // Init Global Settings ui.globalSettings.primaryColor.value = globalSettings.colors.primary; ui.globalSettings.secondaryColor.value = globalSettings.colors.secondary; ui.globalSettings.textColor.value = globalSettings.colors.text; ui.globalSettings.headingColor.value = globalSettings.colors.heading; ui.globalSettings.fontFamily.value = globalSettings.typography.fontFamily; // Init Page Title ui.pageTitle.toggle.checked = pageTitle.enabled; ui.pageTitle.title.value = pageTitle.title; ui.pageTitle.subtitle.value = pageTitle.subtitle; ui.pageTitle.alignment.querySelector(`input[value="${pageTitle.alignment}"]`).checked = true; ui.pageTitle.titleSize.value = pageTitle.titleSize; ui.pageTitle.subtitleSize.value = pageTitle.subtitleSize; // Init Info Cards ui.infoCards.toggle.checked = infoCards.enabled; // Sort info cards by date in descending order config.infoCards.items.sort((a, b) => new Date(b.date) - new Date(a.date)); renderInfoCardControls(); // Init Custom HTML ui.customHtml.toggle.checked = customHtml.enabled; ui.customHtml.content.value = customHtml.content; setupEventListeners(); renderLayoutControls(); renderAll(); if(!document.querySelector('.control-nav-button.active')){ ui.controls.nav.querySelector('.control-nav-button').click(); } } init(); }); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced Component Builder</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Open+Sans:wght@400;700&family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/41.4.2/classic/ckeditor.js"></script>
<style>
:root {
--primary-color: #3b82f6;
--primary-hover-color: #2563eb;
--secondary-color: #10b981;
--secondary-hover-color: #059669;
--text-color: #374151;
--heading-color: #111827;
--background-color: #f9fafb;
--font-family: 'Inter', sans-serif;
}
body {
font-family: var(--font-family);
color: var(--text-color);
background-color: var(--background-color);
}
h1, h2, h3, h4, h5, h6 {
color: var(--heading-color);
}
/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
.preview-iframe {
width: 100%;
height: 100%;
border: 0;
transition: all 0.3s ease-in-out;
}
#preview-container.preview-desktop .preview-iframe { width: 100%; }
#preview-container.preview-tablet .preview-iframe { width: 768px; margin: 0 auto; }
#preview-container.preview-mobile .preview-iframe { width: 375px; margin: 0 auto; }
.toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 8px;
padding: 16px;
position: fixed;
z-index: 100;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
opacity: 0;
transition: opacity 0.3s, visibility 0.3s;
}
.toast.show {
visibility: visible;
opacity: 1;
}
/* New Professional Controls UI Styles */
#controls-layout {
display: flex;
height: 100%;
}
#controls-nav {
width: 180px;
flex-shrink: 0;
background-color: #f8fafc;
border-right: 1px solid #e5e7eb;
padding: 0.5rem;
overflow-y: auto;
}
.control-nav-button {
display: flex;
align-items: center;
width: 100%;
padding: 0.75rem;
border-radius: 0.375rem;
font-weight: 500;
color: var(--text-color);