Download index.html from Examups/Pdf_Viwer: direct link, hf CLI and curl.
- Browser
- Download file 81.5 kB
-
https://huggingface.co/spaces/Examups/Pdf_Viwer/resolve/main/index.html
- Command line
-
hf download hf://spaces/Examups/Pdf_Viwer/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Examups/Pdf_Viwer/resolve/main/index.html
81.5 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://mozilla.github.io/pdf.js/build/pdf.js"></script>
<style>
:root {
--primary-color: #3b82f6;
--primary-hover-color: #2563eb;
--secondary-color: #10b981;
--secondary-hover-color: #059669;
--text-color: #374151;
--heading-color: #111827;
--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;
}
.nested-builder {
margin-left: 1rem;
padding-left: 1rem;
border-left: 2px solid #e5e7eb;
margin-top: 1rem;
padding-top: 1rem;
}
.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;
}
/* Feature: Hide/Show Sidebar */
#controls-sidebar {
flex-shrink: 0;
}
#main-container.sidebar-collapsed #controls-sidebar {
width: 0;
padding: 0;
overflow: hidden;
}
#main-container.sidebar-collapsed #preview-main {
width: 100%;
}
</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">
<div class="flex items-center space-x-3">
<h1 class="text-xl font-bold text-gray-700">Component Builder</h1>
<button id="toggle-sidebar-btn" class="p-2 rounded-md hover:bg-gray-200 text-gray-600" title="Hide Controls">
<i class="fas fa-chevron-left"></i>
</button>
</div>
<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-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" id="main-container">
<aside id="controls-sidebar" class="w-1/3 bg-white shadow-lg overflow-hidden transition-all duration-300 ease-in-out">
<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-ebook-carousel"><i class="fas fa-book-open"></i>Ebooks</button>
<button class="control-nav-button" data-target="#panel-categories-grid"><i class="fas fa-th-large"></i>Categories</button>
<button class="control-nav-button" data-target="#panel-pdf-viewer"><i class="fas fa-file-pdf"></i>PDF Viewer</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-ebook-carousel" class="control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0">📚 Popular Ebooks</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="ebookCarousel">
<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="ebook-carousel-toggle" class="h-4 w-4 rounded">
<label for="ebook-carousel-toggle" class="font-medium">Enable Ebooks Carousel</label>
</div>
<div id="ebook-carousel-builder">
<p class="text-xs text-gray-500 mb-2">Manage the books in the carousel. Use vertical images for best results.</p>
<div id="ebook-builder-container" class="space-y-3 max-h-96 overflow-y-auto pr-2">
</div>
<button id="add-ebook-btn" class="mt-4 w-full text-sm bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-md transition">
<i class="fas fa-plus mr-2"></i>Add Book
</button>
</div>
</div>
</div>
<div id="panel-categories-grid" class="control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0">🗂️ Categories Grid</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="categoriesGrid">
<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="categories-grid-toggle" class="h-4 w-4 rounded">
<label for="categories-grid-toggle" class="font-medium">Enable Categories Grid</label>
</div>
<div id="categories-grid-builder">
<div class="space-y-2 border-b pb-4">
<div class="text-xs">
<label class="font-medium">"View All" Link Text</label>
<input type="text" id="categories-grid-link-text" class="w-full p-1 border rounded-md">
</div>
<div class="text-xs">
<label class="font-medium">"View All" Link URL</label>
<input type="text" id="categories-grid-link-url" class="w-full p-1 border rounded-md">
</div>
</div>
<p class="text-xs text-gray-500 my-2">Manage the categories in the grid. Use Font Awesome 5 icon classes (e.g., 'fas fa-book').</p>
<div id="category-builder-container" class="space-y-3 max-h-80 overflow-y-auto pr-2"></div>
<button id="add-category-btn" class="mt-4 w-full text-sm bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-md transition">
<i class="fas fa-plus mr-2"></i>Add Category
</button>
</div>
</div>
</div>
<div id="panel-pdf-viewer" class="control-panel">
<div class="flex justify-between items-center mb-6">
<h3 class="mb-0 pb-0 border-b-0">📄 PDF Viewer</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="pdfViewer">
<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="pdf-viewer-toggle" class="h-4 w-4 rounded">
<label for="pdf-viewer-toggle" class="font-medium">Enable PDF Viewer</label>
</div>
<div id="pdf-viewer-builder" class="space-y-3">
<div class="text-xs">
<label class="font-medium">Title</label>
<input type="text" id="pdf-viewer-title" class="w-full p-1 border rounded-md">
</div>
<div class="text-xs">
<label class="font-medium">PDF URL</label>
<input type="url" id="pdf-viewer-url" class="w-full p-1 border rounded-md">
<p class="text-gray-500 mt-1">Must be a public URL with CORS enabled.</p>
</div>
<div class="text-xs">
<label class="font-medium">Download Button Text</label>
<input type="text" id="pdf-viewer-btn-text" class="w-full p-1 border rounded-md">
</div>
<div class="text-xs">
<label class="font-medium">Number of clear preview pages</label>
<input type="number" id="pdf-viewer-preview-pages" class="w-full p-1 border rounded-md" min="1">
</div>
</div>
</div>
</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 id="preview-main" class="w-2/3 bg-gray-200 p-4 flex flex-col items-center justify-center overflow-hidden transition-all duration-300 ease-in-out">
<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">×</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: [
'ebookCarousel',
'categoriesGrid',
'pdfViewer',
'customHtml'
],
ebookCarousel: {
enabled: true,
books: [
{ id: Date.now() + 1, imgSrc: 'https://placehold.co/200x300/f87171/ffffff?text=Book+1', title: 'The Midnight Library', author: 'Matt Haig', link: '#' },
{ id: Date.now() + 2, imgSrc: 'https://placehold.co/200x300/60a5fa/ffffff?text=Book+2', title: 'Project Hail Mary', author: 'Andy Weir', link: '#' },
]
},
categoriesGrid: {
enabled: true,
viewAllLinkText: 'View All 100+ Categories',
viewAllLinkUrl: '#',
categories: [
{ id: Date.now() + 10, icon: 'fas fa-book', title: 'Fiction', description: 'Novels, stories & literature', link: '#' },
{ id: Date.now() + 11, icon: 'fas fa-brain', title: 'Non-Fiction', description: 'Learn something new', link: '#' },
{ id: Date.now() + 12, icon: 'fas fa-briefcase', title: 'Business', description: 'Grow your career', link: '#' },
{ id: Date.now() + 13, icon: 'fas fa-heart', title: 'Romance', description: 'Love stories & passion', link: '#' },
]
},
pdfViewer: {
enabled: true,
title: 'Pests, Diseases, and Disorders',
pdfUrl: 'https://examups.com/wp-content/uploads/2025/01/Pests-Diseases-and-Disorders-1.pdf',
downloadButtonText: 'Download PDF',
previewPages: 1
},
customHtml: {
enabled: false,
content: ''
}
};
const componentNames = {
ebookCarousel: 'Popular Ebooks',
categoriesGrid: 'Categories Grid',
pdfViewer: 'PDF Viewer',
customHtml: 'Custom HTML'
};
// UI Element References
const ui = {
previewIframe: document.getElementById('preview-iframe'),
mainContainer: document.getElementById('main-container'),
toggleSidebarBtn: document.getElementById('toggle-sidebar-btn'),
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')
},
ebookCarousel: {
panel: document.getElementById('panel-ebook-carousel'),
toggle: document.getElementById('ebook-carousel-toggle'),
builderContainer: document.getElementById('ebook-builder-container'),
addBtn: document.getElementById('add-ebook-btn'),
},
categoriesGrid: {
toggle: document.getElementById('categories-grid-toggle'),
linkText: document.getElementById('categories-grid-link-text'),
linkUrl: document.getElementById('categories-grid-link-url'),
builderContainer: document.getElementById('category-builder-container'),
addBtn: document.getElementById('add-category-btn'),
},
pdfViewer: {
toggle: document.getElementById('pdf-viewer-toggle'),
title: document.getElementById('pdf-viewer-title'),
url: document.getElementById('pdf-viewer-url'),
btnText: document.getElementById('pdf-viewer-btn-text'),
previewPages: document.getElementById('pdf-viewer-preview-pages'),
},
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;});
ui.globalSettings.secondaryColor.addEventListener('input', e => {config.globalSettings.colors.secondary = e.target.value;});
ui.globalSettings.textColor.addEventListener('input', e => {config.globalSettings.colors.text = e.target.value;});
ui.globalSettings.headingColor.addEventListener('input', e => {config.globalSettings.colors.heading = e.target.value;});
ui.globalSettings.fontFamily.addEventListener('change', e => {config.globalSettings.typography.fontFamily = e.target.value;});
ui.globalSettings.applyBtn.addEventListener('click', () => {
renderAll();
showToast('Global styles applied!');
});
// Layout Controls
ui.layout.panel.addEventListener('click', handleLayoutControlsClick);
setupDragAndDrop();
// Component Listeners
ui.ebookCarousel.toggle.addEventListener('change', e => { config.ebookCarousel.enabled = e.target.checked; renderAll(); });
ui.ebookCarousel.addBtn.addEventListener('click', handleAddEbook);
ui.ebookCarousel.builderContainer.addEventListener('click', handleEbookItemClick);
ui.ebookCarousel.builderContainer.addEventListener('input', handleEbookItemInput);
ui.categoriesGrid.toggle.addEventListener('change', e => { config.categoriesGrid.enabled = e.target.checked; renderAll(); });
ui.categoriesGrid.linkText.addEventListener('input', e => { config.categoriesGrid.viewAllLinkText = e.target.value; renderAll(); });
ui.categoriesGrid.linkUrl.addEventListener('input', e => { config.categoriesGrid.viewAllLinkUrl = e.target.value; renderAll(); });
ui.categoriesGrid.addBtn.addEventListener('click', handleAddCategory);
ui.categoriesGrid.builderContainer.addEventListener('click', handleCategoryItemClick);
ui.categoriesGrid.builderContainer.addEventListener('input', handleCategoryItemInput);
ui.pdfViewer.toggle.addEventListener('change', e => { config.pdfViewer.enabled = e.target.checked; renderAll(); });
ui.pdfViewer.title.addEventListener('input', e => { config.pdfViewer.title = e.target.value; renderAll(); });
ui.pdfViewer.url.addEventListener('input', e => { config.pdfViewer.pdfUrl = e.target.value; renderAll(); });
ui.pdfViewer.btnText.addEventListener('input', e => { config.pdfViewer.downloadButtonText = e.target.value; renderAll(); });
ui.pdfViewer.previewPages.addEventListener('input', e => { config.pdfViewer.previewPages = parseInt(e.target.value, 10) || 1; renderAll(); });
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')));
ui.codeModal.modal.addEventListener('click', (e) => {
if (e.target.id === 'code-modal-html' || e.target.id === 'code-modal-css' || e.target.id === 'code-modal-js') {
const code = e.target.querySelector('code').innerText;
navigator.clipboard.writeText(code).then(() => showToast('Copied to clipboard!'));
}
});
// Sidebar Toggle Listener
ui.toggleSidebarBtn.addEventListener('click', () => {
ui.mainContainer.classList.toggle('sidebar-collapsed');
const isCollapsed = ui.mainContainer.classList.contains('sidebar-collapsed');
const icon = ui.toggleSidebarBtn.querySelector('i');
icon.classList.toggle('fa-chevron-left', !isCollapsed);
icon.classList.toggle('fa-chevron-right', isCollapsed);
ui.toggleSidebarBtn.title = isCollapsed ? 'Show Controls' : 'Hide Controls';
});
}
// --- EBOOK CONTROLS ---
function renderEbookControls() {
ui.ebookCarousel.builderContainer.innerHTML = config.ebookCarousel.books.map(book => `
<div class="p-3 border rounded-md bg-white space-y-2" data-ebook-id="${book.id}">
<div class="flex justify-end">
<button class="remove-ebook-btn text-red-500 hover:text-red-700 text-xs p-1"><i class="fas fa-trash-alt"></i></button>
</div>
<div class="text-xs">
<label class="font-medium">Image URL</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="imgSrc" value="${book.imgSrc}">
</div>
<div class="text-xs">
<label class="font-medium">Link URL</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="link" value="${book.link}">
</div>
<div class="text-xs">
<label class="font-medium">Title</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="title" value="${book.title}">
</div>
<div class="text-xs">
<label class="font-medium">Author</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="author" value="${book.author}">
</div>
</div>
`).join('');
}
function handleAddEbook() {
const newBook = {
id: Date.now(),
imgSrc: 'https://placehold.co/200x300/cccccc/ffffff?text=New+Book',
link: '#',
title: 'New Book Title',
author: 'Author Name'
};
config.ebookCarousel.books.push(newBook);
renderEbookControls();
renderAll();
}
function handleEbookItemClick(e) {
const removeBtn = e.target.closest('.remove-ebook-btn');
if (removeBtn) {
const bookItem = removeBtn.closest('[data-ebook-id]');
const bookId = parseInt(bookItem.dataset.ebookId, 10);
config.ebookCarousel.books = config.ebookCarousel.books.filter(b => b.id !== bookId);
renderEbookControls();
renderAll();
}
}
function handleEbookItemInput(e) {
const input = e.target;
if (input.tagName === 'INPUT') {
const bookItem = input.closest('[data-ebook-id]');
const bookId = parseInt(bookItem.dataset.ebookId, 10);
const property = input.dataset.property;
const book = config.ebookCarousel.books.find(b => b.id === bookId);
if (book) {
book[property] = input.value;
renderAll();
}
}
}
// --- CATEGORIES GRID CONTROLS ---
function renderCategoriesGridControls() {
ui.categoriesGrid.builderContainer.innerHTML = config.categoriesGrid.categories.map(cat => `
<div class="p-3 border rounded-md bg-white space-y-2" data-category-id="${cat.id}">
<div class="flex justify-end">
<button class="remove-category-btn text-red-500 hover:text-red-700 text-xs p-1"><i class="fas fa-trash-alt"></i></button>
</div>
<div class="text-xs">
<label class="font-medium">Icon Class</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="icon" value="${cat.icon}">
</div>
<div class="text-xs">
<label class="font-medium">Title</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="title" value="${cat.title}">
</div>
<div class="text-xs">
<label class="font-medium">Description</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="description" value="${cat.description}">
</div>
<div class="text-xs">
<label class="font-medium">Link URL</label>
<input type="text" class="w-full p-1 border rounded-md" data-property="link" value="${cat.link}">
</div>
</div>
`).join('');
}
function handleAddCategory() {
const newCategory = {
id: Date.now(),
icon: 'fas fa-tag',
title: 'New Category',
description: 'A short description',
link: '#'
};
config.categoriesGrid.categories.push(newCategory);
renderCategoriesGridControls();
renderAll();
}
function handleCategoryItemClick(e) {
const removeBtn = e.target.closest('.remove-category-btn');
if (removeBtn) {
const categoryItem = removeBtn.closest('[data-category-id]');
const categoryId = parseInt(categoryItem.dataset.categoryId, 10);
config.categoriesGrid.categories = config.categoriesGrid.categories.filter(c => c.id !== categoryId);
renderCategoriesGridControls();
renderAll();
}
}
function handleCategoryItemInput(e) {
const input = e.target;
if (input.tagName === 'INPUT') {
const categoryItem = input.closest('[data-category-id]');
const categoryId = parseInt(categoryItem.dataset.categoryId, 10);
const property = input.dataset.property;
const category = config.categoriesGrid.categories.find(c => c.id === categoryId);
if (category) {
category[property] = input.value;
renderAll();
}
}
}
// --- 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;
let changed = false;
if (button.classList.contains('reorder-layout-up-btn') && index > 0) {
[order[index], order[index - 1]] = [order[index - 1], order[index]];
changed = true;
} else if (button.classList.contains('reorder-layout-down-btn') && index < order.length - 1) {
[order[index], order[index + 1]] = [order[index + 1], order[index]];
changed = true;
}
if(changed) {
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', e => {
setTimeout(() => {
draggedItem.style.display = 'flex';
draggedItem = null;
}, 0);
});
ui.layout.container.addEventListener('dragover', e => {
e.preventDefault();
const afterElement = getDragAfterElement(ui.layout.container, e.clientY);
if (afterElement == null) {
ui.layout.container.appendChild(draggedItem);
} else {
ui.layout.container.insertBefore(draggedItem, afterElement);
}
});
ui.layout.container.addEventListener('drop', e => {
e.preventDefault();
const newOrderKeys = [...ui.layout.container.querySelectorAll('.layout-item')].map(item => item.dataset.key);
config.componentOrder = newOrderKeys;
renderLayoutControls();
renderAll();
});
}
function getDragAfterElement(container, y) {
const draggableElements = [...container.querySelectorAll('.layout-item:not(.dragging)')];
return draggableElements.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
if (offset < 0 && offset > closest.offset) {
return { offset: offset, element: child };
} else {
return closest;
}
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
// --- HTML Generation Logic ---
const componentGenerators = {
ebookCarousel: generateEbooksCarouselHTML,
categoriesGrid: generateCategoriesGridHTML,
pdfViewer: generatePdfViewerHTML,
customHtml: generateCustomHtmlHTML
};
function getAllHtml() {
return config.componentOrder
.map(key => componentGenerators[key] ? componentGenerators[key]() : '')
.filter(Boolean)
.join('\n\n');
}
function generateEbooksCarouselHTML() {
if (!config.ebookCarousel.enabled) return '';
const bookCards = config.ebookCarousel.books.map(book => `
<li class="ebook-list-item">
<a href="${book.link}" class="ebook-card" target="_blank" rel="noopener noreferrer">
<div class="ebook-card-img-wrapper">
<img src="${book.imgSrc}" alt="Cover of ${book.title}" loading="lazy">
</div>
<div class="ebook-card-label"><i class="fas fa-book-open"></i> Ebook</div>
<h4 class="ebook-card-title">${book.title}</h4>
<p class="ebook-card-author">${book.author}</p>
</a>
</li>
`).join('');
return `
<section class="ebook-carousel-section">
<div class="ebook-carousel-container">
<div class="ebook-carousel-header">
<h3 class="section-title">Popular Ebooks</h3>
<div class="flex items-center">
<a href="#" class="mr-4 hover:underline">See More</a>
<div class="ebook-carousel-nav">
<button class="ebook-carousel-prev" aria-label="Previous books"><i class="fas fa-chevron-left"></i></button>
<button class="ebook-carousel-next" aria-label="Next books"><i class="fas fa-chevron-right"></i></button>
</div>
</div>
</div>
<div class="ebook-carousel-slider-wrapper">
<ul class="ebook-carousel-slider">
${bookCards}
</ul>
</div>
</div>
</section>
`;
}
function generateCategoriesGridHTML() {
if (!config.categoriesGrid.enabled) return '';
const categoryCards = config.categoriesGrid.categories.map(cat => `
<a href="${cat.link}" class="category-card">
<div class="category-card-icon"><i class="${cat.icon}"></i></div>
<div>
<h4 class="category-card-title">${cat.title}</h4>
<p class="category-card-description">${cat.description}</p>
</div>
</a>
`).join('');
return `
<section class="categories-grid-section">
<div class="categories-grid-container">
<div class="categories-grid">
${categoryCards}
</div>
<div class="categories-view-all">
<a href="${config.categoriesGrid.viewAllLinkUrl}">${config.categoriesGrid.viewAllLinkText} →</a>
</div>
</div>
</section>
`;
}
function generatePdfViewerHTML() {
if (!config.pdfViewer.enabled) return '';
return `
<section class="pdf-viewer-section">
<div class="pdf-viewer-container" id="pdf-viewer-component" data-config='${JSON.stringify(config.pdfViewer)}'>
<div class="pdf-viewer-header">
<div class="pdf-viewer-header-info">
<h3 class="pdf-viewer-title">${config.pdfViewer.title}</h3>
<span class="pdf-viewer-page-count"></span>
</div>
<a href="${config.pdfViewer.pdfUrl}" class="pdf-viewer-download-btn" target="_blank" rel="noopener noreferrer">
<i class="fas fa-download"></i>
<span>${config.pdfViewer.downloadButtonText}</span>
</a>
</div>
<div class="pdf-viewer-body">
<div class="pdf-pages-container"></div>
<div class="pdf-viewer-loader">Loading PDF...</div>
</div>
</div>
</section>
`;
}
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);
}
.container { max-width: 1280px; }
a { text-decoration: none; transition: color 0.2s; color: var(--primary-color); }
.section-title { text-align: center; font-size: 1.8rem; font-weight: 700; margin: 0 0 2rem 0; }
`;
if(config.ebookCarousel.enabled) css.ebookCarousel = `
/* --- Ebook Carousel --- */
.ebook-carousel-section { width: 100%; padding: 2rem 0; overflow: hidden; }
.ebook-carousel-container { max-width: 1280px; margin: 0 auto; padding: 0 1.5rem; }
.ebook-carousel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.ebook-carousel-header .section-title { margin-bottom: 0; text-align: left; }
.ebook-carousel-header a { font-weight: 500; white-space: nowrap; }
.ebook-carousel-nav { display: flex; gap: 0.5rem; margin-left: 1rem; }
.ebook-carousel-nav button { width: 2.5rem; height: 2.5rem; border-radius: 9999px; background-color: #e5e7eb; color: #4b5563; border: none; cursor: pointer; transition: background-color 0.2s; display: inline-flex; align-items: center; justify-content: center; }
.ebook-carousel-nav button:hover { background-color: #d1d5db; }
.ebook-carousel-nav button:disabled { opacity: 0.5; cursor: not-allowed; }
.ebook-carousel-slider-wrapper { overflow-x: auto; scroll-behavior: smooth; -ms-overflow-style: none; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.ebook-carousel-slider-wrapper::-webkit-scrollbar { display: none; }
.ebook-carousel-slider { display: flex; gap: 1rem; list-style: none; padding: 0.5rem 0; margin: 0; }
.ebook-list-item { flex-shrink: 0; width: calc((100% / 7) - 1rem + (1rem / 7)); min-width: 130px; }
a.ebook-card { display: block; width: 100%; height: 100%; 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; text-align: center; transition: transform 0.2s, box-shadow 0.2s; padding-bottom: 1rem; color: var(--text-color); }
a.ebook-card:hover { transform: translateY(-5px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05); }
.ebook-card-img-wrapper { width: 100%; aspect-ratio: 2 / 3; margin-bottom: 0.75rem; background-color: #f3f4f6; }
.ebook-card-img-wrapper img { width: 100%; height: 100%; object-fit: cover; }
.ebook-card-label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; color: var(--secondary-color); font-weight: 500; margin-bottom: 0.25rem; }
.ebook-card-title { font-weight: 700; font-size: 0.9rem; padding: 0 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; color: var(--heading-color); }
.ebook-card-author { font-size: 0.8rem; color: #6b7280; padding: 0 0.75rem; margin: 0; }
@media (max-width: 1280px) { .ebook-list-item { width: calc((100% / 5) - 1rem + (1rem / 5)); } }
@media (max-width: 1024px) { .ebook-list-item { width: calc((100% / 4) - 1rem + (1rem / 4)); } }
@media (max-width: 768px) { .ebook-list-item { width: calc((100% / 3) - 1rem + (1rem / 3)); } .ebook-carousel-header .section-title { font-size: 1.5rem; } }
@media (max-width: 640px) { .ebook-list-item { width: calc((100% / 2) - 1rem + (1rem / 2)); } .ebook-carousel-header a { display: none; } }
`;
if(config.categoriesGrid.enabled) css.categoriesGrid = `
/* --- Categories Grid --- */
.categories-grid-section { width: 100%; padding: 2rem 1rem; }
.categories-grid-container { max-width: 1100px; margin: 0 auto; }
.categories-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.category-card { display: flex; align-items: center; gap: 1rem; background-color: #ffffff; padding: 1.25rem; border-radius: 0.5rem; border: 1px solid #e5e7eb; transition: transform 0.2s, box-shadow 0.2s; color: var(--text-color); }
.category-card:hover { transform: translateY(-4px); box-shadow: 0 8px 16px rgba(0,0,0,0.08); }
.category-card-icon { font-size: 1.5rem; color: var(--primary-color); }
.category-card-title { font-weight: 600; font-size: 1rem; color: var(--heading-color); margin: 0 0 0.125rem 0; }
.category-card-description { font-size: 0.875rem; color: var(--text-color); margin: 0; }
.categories-view-all { text-align: center; margin-top: 2.5rem; }
.categories-view-all a { font-weight: 600; color: var(--primary-color); }
.categories-view-all a:hover { text-decoration: underline; }
@media (max-width: 1024px) { .categories-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .categories-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 540px) { .categories-grid { grid-template-columns: 1fr; } }
`;
if(config.pdfViewer.enabled) css.pdfViewer = `
/* --- PDF Viewer --- */
.pdf-viewer-section { padding: 2rem 1rem; }
.pdf-viewer-container { max-width: 800px; margin: 0 auto; background: #fff; border: 1px solid #e5e7eb; 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); }
.pdf-viewer-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; border-bottom: 1px solid #e5e7eb; }
.pdf-viewer-title { font-size: 1.25rem; font-weight: 600; color: var(--heading-color); margin: 0; }
.pdf-viewer-page-count { font-size: 0.875rem; color: var(--text-color); margin-left: 1rem; background-color: #f3f4f6; padding: 0.25rem 0.5rem; border-radius: 0.25rem; }
.pdf-viewer-download-btn { display: inline-flex; align-items: center; gap: 0.5rem; background-color: var(--primary-color); color: white; font-weight: 500; padding: 0.5rem 1rem; border-radius: 0.375rem; transition: background-color 0.2s; }
.pdf-viewer-download-btn:hover { background-color: var(--primary-hover-color); }
.pdf-viewer-body { max-height: 70vh; overflow-y: auto; padding: 1rem; background-color: #f9fafb; }
.pdf-pages-container { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.pdf-page-wrapper { position: relative; }
.pdf-page-wrapper canvas { max-width: 100%; height: auto; display: block; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.pdf-page-wrapper canvas.blurred { filter: blur(8px); }
.pdf-page-blur-overlay { position: absolute; inset: 0; background-color: rgba(255, 255, 255, 0.6); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--heading-color); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.pdf-page-blur-overlay .icon { font-size: 2.5rem; }
.pdf-page-blur-overlay .text { font-weight: 600; margin-top: 1rem; }
.pdf-viewer-loader { text-align: center; padding: 2rem; }
`;
if(config.customHtml.enabled) css.customHtml = `
/* --- Custom HTML Section --- */
.custom-html-section { padding: 1rem 0; }`;
if (targetKey) {
return {
global: css.global,
component: css[targetKey] || ''
}
}
return 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 = {};
if(config.ebookCarousel.enabled) js.ebookCarousel = `
// --- Ebook Carousel Logic ---
const ebookCarousel = document.querySelector('.ebook-carousel-section');
if (ebookCarousel) {
const sliderWrapper = ebookCarousel.querySelector('.ebook-carousel-slider-wrapper');
const prevBtn = ebookCarousel.querySelector('.ebook-carousel-prev');
const nextBtn = ebookCarousel.querySelector('.ebook-carousel-next');
const updateNavButtons = () => { if (!sliderWrapper) return; const maxScrollLeft = sliderWrapper.scrollWidth - sliderWrapper.clientWidth; prevBtn.disabled = sliderWrapper.scrollLeft <= 0; nextBtn.disabled = sliderWrapper.scrollLeft >= maxScrollLeft - 1; };
const slide = (direction) => { if (!sliderWrapper) return; const slideAmount = sliderWrapper.clientWidth * 0.8; sliderWrapper.scrollLeft += direction === 'next' ? slideAmount : -slideAmount; };
prevBtn.addEventListener('click', () => slide('prev'));
nextBtn.addEventListener('click', () => slide('next'));
let scrollTimer; sliderWrapper.addEventListener('scroll', () => { clearTimeout(scrollTimer); scrollTimer = setTimeout(updateNavButtons, 100); });
window.addEventListener('resize', updateNavButtons);
updateNavButtons();
}`;
if(config.pdfViewer.enabled) js.pdfViewer = `
// --- PDF Viewer Logic ---
const pdfViewerComponent = document.getElementById('pdf-viewer-component');
if (pdfViewerComponent) {
const config = JSON.parse(pdfViewerComponent.dataset.config);
const url = config.pdfUrl;
const previewPages = config.previewPages || 1;
const pagesContainer = pdfViewerComponent.querySelector('.pdf-pages-container');
const pageCountSpan = pdfViewerComponent.querySelector('.pdf-viewer-page-count');
const loader = pdfViewerComponent.querySelector('.pdf-viewer-loader');
// Set the worker source for PDF.js
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://mozilla.github.io/pdf.js/build/pdf.worker.js';
const renderPdf = async () => {
if (!url) {
loader.textContent = 'No PDF URL provided.';
return;
}
try {
loader.style.display = 'block';
pagesContainer.innerHTML = '';
const loadingTask = pdfjsLib.getDocument(url);
const pdf = await loadingTask.promise;
pageCountSpan.textContent = pdf.numPages + ' pages';
for (let i = 1; i <= pdf.numPages; i++) {
const page = await pdf.getPage(i);
const viewport = page.getViewport({ scale: 1.5 });
const wrapper = document.createElement('div');
wrapper.className = 'pdf-page-wrapper';
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {
canvasContext: context,
viewport: viewport
};
wrapper.appendChild(canvas);
if (i > previewPages) {
canvas.classList.add('blurred');
const overlay = document.createElement('div');
overlay.className = 'pdf-page-blur-overlay';
overlay.innerHTML = '<div class="icon"><i class="fas fa-lock"></i></div><div class="text">Download to view all pages</div>';
wrapper.appendChild(overlay);
}
pagesContainer.appendChild(wrapper);
await page.render(renderContext).promise;
}
loader.style.display = 'none';
} catch (error) {
console.error('Error rendering PDF:', error);
loader.textContent = 'Failed to load PDF. Check the URL and CORS policy.';
}
};
renderPdf();
}`;
if (targetKey) {
return js[targetKey] || '';
}
return js;
}
function getFullJS() {
const jsObject = generateComponentJavaScript();
return config.componentOrder.map(key => {
let script = jsObject[key] || '';
return script;
}).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">
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"><\/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">
<style>
${css}
</style>
</head>
<body class="bg-gray-100">
${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">
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"><\/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">
<style>${getFullCSS()}</style></head><body>
<div class="site-wrapper">
${getAllHtml()}
<div style="min-height: 400px; padding: 40px; text-align: center; color: #6b7280; font-family: 'Inter', sans-serif;"></div>
</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('shadow', m === mode);
btn.classList.toggle('bg-gray-200', m !== mode);
btn.classList.toggle('text-gray-700', 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">
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"><\/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="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(function(content) {
saveAs(content, "exported-page.zip");
showToast("ZIP file generated!");
});
}
function handleFileImport(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
try {
const parser = new DOMParser();
const doc = parser.parseFromString(content, 'text/html');
parseImportedDocument(doc);
showToast('Import successful!');
} catch (error) {
console.error('Error parsing imported file:', error);
showToast('Error: Could not parse file.');
}
event.target.value = null; // Reset file input
};
reader.readAsText(file);
}
function parseImportedDocument(doc) {
console.log("Parsing imported document...");
}
function handleGetCodeClick(e) {
const button = e.target.closest('.get-component-code-btn');
if (!button) return;
const key = button.dataset.componentKey;
if (!key) return;
const html = componentGenerators[key] ? componentGenerators[key]() : 'Not available';
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();
let jsWithWrapper = js.trim();
if (jsWithWrapper) {
jsWithWrapper = `document.addEventListener('DOMContentLoaded', () => { \n${jsWithWrapper}\n });`;
}
ui.codeModal.jsCode.textContent = jsWithWrapper || '// No JavaScript for this component';
[ui.codeModal.htmlContainer, ui.codeModal.cssContainer, ui.codeModal.jsContainer].forEach(el => {
const codeContent = el.querySelector('code').textContent.trim();
const isEmpty = codeContent === '' || codeContent.startsWith('// No JavaScript');
const parentDiv = el.parentElement;
if(parentDiv.tagName === 'DIV' && parentDiv.children.length === 2) { // check if it's one of the code blocks
parentDiv.style.display = isEmpty ? '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">
<script src="https://mozilla.github.io/pdf.js/build/pdf.js"><\/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="style.css">
</head>
<body>
${htmlBody}
${js.trim() ? '<script src="script.js"><\/script>' : ''}
</body>
</html>`;
zip.file("index.html", html);
zip.file("style.css", (global + '\n\n' + css).trim());
if (js.trim()) {
let jsWithWrapper = `document.addEventListener('DOMContentLoaded', () => { \n${js} \n});`;
zip.file("script.js", jsWithWrapper);
}
zip.generateAsync({type:"blob"}).then(function(content) {
saveAs(content, `${key}-component.zip`);
showToast("Component ZIP generated!");
});
}
// Initial Load
function init() {
const { ebookCarousel, categoriesGrid, pdfViewer, 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 Ebook Carousel
ui.ebookCarousel.toggle.checked = ebookCarousel.enabled;
// Init Categories Grid
ui.categoriesGrid.toggle.checked = categoriesGrid.enabled;
ui.categoriesGrid.linkText.value = categoriesGrid.viewAllLinkText;
ui.categoriesGrid.linkUrl.value = categoriesGrid.viewAllLinkUrl;
// Init PDF Viewer
ui.pdfViewer.toggle.checked = pdfViewer.enabled;
ui.pdfViewer.title.value = pdfViewer.title;
ui.pdfViewer.url.value = pdfViewer.pdfUrl;
ui.pdfViewer.btnText.value = pdfViewer.downloadButtonText;
ui.pdfViewer.previewPages.value = pdfViewer.previewPages;
// Init Custom HTML
ui.customHtml.toggle.checked = customHtml.enabled;
ui.customHtml.content.value = customHtml.content;
setupEventListeners();
renderLayoutControls();
renderEbookControls();
renderCategoriesGridControls();
renderAll();
if(!document.querySelector('.control-nav-button.active')){
ui.controls.nav.querySelector('.control-nav-button').click();
}
}
init();
});
</script>
</body>
</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://mozilla.github.io/pdf.js/build/pdf.js"></script>
<style>
:root {
--primary-color: #3b82f6;
--primary-hover-color: #2563eb;
--secondary-color: #10b981;
--secondary-hover-color: #059669;
--text-color: #374151;
--heading-color: #111827;
--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);