Commit 6809bf9f authored by jan.koester's avatar jan.koester
Browse files

test

parent 66204268
Loading
Loading
Loading
Loading
+201 −9
Changes for data/themes/default/editor.html: 201 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -648,7 +648,10 @@

            <!-- Theme Color Palette -->
            <div id="theme-palette" class="bg-gray-800 p-4 rounded-lg shadow-inner mt-4">
                <h3 class="font-bold text-purple-300 mb-2">${I18N_COLOR_PALETTE}</h3>
                <div class="flex justify-between items-center mb-2 gap-2">
                    <h3 class="font-bold text-purple-300">${I18N_COLOR_PALETTE}</h3>
                    <button class="tpl-btn tpl-btn-secondary" type="button" onclick="showThemeCssExportModal()">CSS Export</button>
                </div>
                <p class="text-xs text-gray-500 mb-2">${I18N_COLOR_PALETTE_DESC}</p>
                <div id="theme-swatches" style="display:flex; flex-wrap:wrap; gap:6px;"></div>
            </div>
@@ -2919,19 +2922,208 @@
        /**
         * Reads CSS custom properties from :root and builds clickable swatches.
         */
        function initThemeSwatches() {
            const container = document.getElementById('theme-swatches');
            if (!container) return;

            const themeVars = [
        function getThemeVarDefinitions() {
            return [
                { var: '--blogi-bg', label: 'BG' },
                { var: '--blogi-surface', label: 'Surface' },
                { var: '--blogi-surface-a', label: 'Surface Alpha' },
                { var: '--blogi-text', label: 'Text' },
                { var: '--blogi-text-muted', label: 'Text Muted' },
                { var: '--blogi-accent', label: 'Accent' },
                { var: '--blogi-nav-active', label: 'Nav' },
                { var: '--blogi-nav-hover',  label: 'Hover' },
                { var: '--blogi-nav-border', label: 'Border' },
                { var: '--blogi-accent-dark', label: 'Accent Dark' },
                { var: '--blogi-border', label: 'Border' },
                { var: '--blogi-bg-alt', label: 'Background Alt' },
                { var: '--blogi-error', label: 'Error' },
                { var: '--blogi-error-bg', label: 'Error Background' },
                { var: '--blogi-error-text', label: 'Error Text' },
                { var: '--blogi-success-bg', label: 'Success Background' },
                { var: '--blogi-success-text', label: 'Success Text' },
                { var: '--blogi-nav-active', label: 'Nav Active' },
                { var: '--blogi-nav-hover', label: 'Nav Hover' },
                { var: '--blogi-nav-border', label: 'Nav Border' },
            ];
        }

        function readThemeCssVars(themeMode) {
            const root = document.documentElement;
            const prevTheme = root.getAttribute('data-theme');

            if (themeMode) {
                root.setAttribute('data-theme', themeMode);
            } else {
                root.removeAttribute('data-theme');
            }

            const rootStyles = getComputedStyle(root);
            const values = {};
            for (const tv of getThemeVarDefinitions()) {
                values[tv.var] = rootStyles.getPropertyValue(tv.var).trim();
            }

            if (prevTheme === null) {
                root.removeAttribute('data-theme');
            } else {
                root.setAttribute('data-theme', prevTheme);
            }

            return values;
        }

        function buildThemeCssExport() {
            const darkVars = readThemeCssVars('dark');
            const lightVars = readThemeCssVars('light');
            const vars = getThemeVarDefinitions();

            const formatBlock = (selector, values) => {
                let block = `${selector} {\n`;
                for (const tv of vars) {
                    block += `  ${tv.var}: ${values[tv.var] || ''};\n`;
                }
                block += '}\n';
                return block;
            };

            let css = '/* Blogi theme colors exported from Webeditor */\n';
            css += '/* Dark mode defaults */\n';
            css += formatBlock(':root', darkVars);
            css += '\n/* Explicit light mode */\n';
            css += formatBlock(':root[data-theme="light"]', lightVars);
            css += '\n/* Auto light mode when dark mode is not forced */\n';
            css += '@media (prefers-color-scheme: light) {\n';
            css += formatBlock('  :root:not([data-theme="dark"])', lightVars);
            css += '}\n';
            return css;
        }

        function buildThemePromptExport() {
            const darkVars = readThemeCssVars('dark');
            const lightVars = readThemeCssVars('light');
            const vars = getThemeVarDefinitions();

            const formatPromptLines = (title, values) => {
                let block = `${title}:\n`;
                for (const tv of vars) {
                    block += `- ${tv.var}: ${values[tv.var] || ''}\n`;
                }
                return block;
            };

            let prompt = 'Use these Blogi theme design tokens consistently in generated UI output.\n';
            prompt += 'Preserve the distinction between dark mode and light mode.\n\n';
            prompt += formatPromptLines('Dark mode tokens', darkVars);
            prompt += '\n';
            prompt += formatPromptLines('Light mode tokens', lightVars);
            prompt += '\nGuidelines:\n';
            prompt += '- Use CSS custom properties exactly as named when possible.\n';
            prompt += '- Prefer accent colors for actions, links, and highlights.\n';
            prompt += '- Keep borders and surfaces subtle and readable in both modes.\n';
            prompt += '- Ensure text uses the matching theme text colors for contrast.\n';
            return prompt;
        }

        function downloadTextFile(filename, content, mimeType = 'text/plain;charset=utf-8') {
            const blob = new Blob([content], { type: mimeType });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            URL.revokeObjectURL(url);
        }

        function showThemeCssExportModal() {
            document.getElementById('theme-css-export-modal')?.remove();
            const cssExport = buildThemeCssExport();
            const promptExport = buildThemePromptExport();

            const overlay = document.createElement('div');
            overlay.id = 'theme-css-export-modal';
            overlay.className = 'modal-overlay';
            overlay.onclick = (event) => {
                if (event.target === overlay) overlay.remove();
            };

            const modal = document.createElement('div');
            modal.className = 'modal-content text-gray-800';
            modal.style.width = 'min(900px, 92vw)';
            modal.style.maxHeight = '85vh';
            modal.innerHTML = `
                <div class="flex justify-between items-center border-b pb-2 mb-4">
                    <h3 class="text-2xl font-bold text-blue-700">Theme CSS Export</h3>
                    <button type="button" onclick="document.getElementById('theme-css-export-modal').remove()" class="text-gray-500 hover:text-red-500 transition-colors duration-150 p-1 rounded-full">&#x2715;</button>
                </div>
                <p class="text-sm text-gray-600 mb-3">Exported CSS with dark and light Blogi theme variables for reuse in prompts or stylesheets.</p>
                <textarea id="theme-css-export-text" class="prop-textarea" style="min-height:360px; font-family:monospace; white-space:pre;">${escapeHtml(cssExport)}</textarea>
                <div class="flex gap-2 mt-4">
                    <button type="button" class="tpl-btn tpl-btn-primary" onclick="copyThemeCssExport()">Copy CSS</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="downloadThemeCssExport()">Download CSS</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="copyThemePromptExport()">Copy AI Prompt</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="document.getElementById('theme-css-export-modal').remove()">Close</button>
                </div>
                <p class="text-sm text-gray-600 mt-5 mb-3">AI prompt block for importing the same theme tokens into design or code generation prompts.</p>
                <textarea id="theme-prompt-export-text" class="prop-textarea" style="min-height:280px; font-family:monospace; white-space:pre;">${escapeHtml(promptExport)}</textarea>
                <div id="theme-css-export-status" class="prop-status mt-2"></div>
            `;

            overlay.appendChild(modal);
            document.body.appendChild(overlay);
        }

        async function copyThemeCssExport() {
            const textEl = document.getElementById('theme-css-export-text');
            const statusEl = document.getElementById('theme-css-export-status');
            if (!textEl) return;

            try {
                await navigator.clipboard.writeText(textEl.value);
                if (statusEl) {
                    statusEl.textContent = 'CSS copied to clipboard.';
                    statusEl.style.color = '#16a34a';
                }
            } catch (error) {
                textEl.select();
                document.execCommand('copy');
                if (statusEl) {
                    statusEl.textContent = 'CSS copied using fallback copy.';
                    statusEl.style.color = '#16a34a';
                }
            }
        }

        function downloadThemeCssExport() {
            const textEl = document.getElementById('theme-css-export-text');
            if (!textEl) return;
            downloadTextFile('blogi-theme-colors.css', textEl.value, 'text/css;charset=utf-8');
        }

        async function copyThemePromptExport() {
            const textEl = document.getElementById('theme-prompt-export-text');
            const statusEl = document.getElementById('theme-css-export-status');
            if (!textEl) return;

            try {
                await navigator.clipboard.writeText(textEl.value);
                if (statusEl) {
                    statusEl.textContent = 'AI prompt copied to clipboard.';
                    statusEl.style.color = '#16a34a';
                }
            } catch (error) {
                textEl.select();
                document.execCommand('copy');
                if (statusEl) {
                    statusEl.textContent = 'AI prompt copied using fallback copy.';
                    statusEl.style.color = '#16a34a';
                }
            }
        }

        function initThemeSwatches() {
            const container = document.getElementById('theme-swatches');
            if (!container) return;

            const themeVars = getThemeVarDefinitions();

            const rootStyles = getComputedStyle(document.documentElement);
            let html = '';
+201 −9
Changes for data/themes/minimal/editor.html: 201 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -648,7 +648,10 @@

            <!-- Theme Color Palette -->
            <div id="theme-palette" class="bg-gray-800 p-4 rounded-lg shadow-inner mt-4">
                <h3 class="font-bold text-purple-300 mb-2">${I18N_COLOR_PALETTE}</h3>
                <div class="flex justify-between items-center mb-2 gap-2">
                    <h3 class="font-bold text-purple-300">${I18N_COLOR_PALETTE}</h3>
                    <button class="tpl-btn tpl-btn-secondary" type="button" onclick="showThemeCssExportModal()">CSS Export</button>
                </div>
                <p class="text-xs text-gray-500 mb-2">${I18N_COLOR_PALETTE_DESC}</p>
                <div id="theme-swatches" style="display:flex; flex-wrap:wrap; gap:6px;"></div>
            </div>
@@ -2919,19 +2922,208 @@
        /**
         * Reads CSS custom properties from :root and builds clickable swatches.
         */
        function initThemeSwatches() {
            const container = document.getElementById('theme-swatches');
            if (!container) return;

            const themeVars = [
        function getThemeVarDefinitions() {
            return [
                { var: '--blogi-bg', label: 'BG' },
                { var: '--blogi-surface', label: 'Surface' },
                { var: '--blogi-surface-a', label: 'Surface Alpha' },
                { var: '--blogi-text', label: 'Text' },
                { var: '--blogi-text-muted', label: 'Text Muted' },
                { var: '--blogi-accent', label: 'Accent' },
                { var: '--blogi-nav-active', label: 'Nav' },
                { var: '--blogi-nav-hover',  label: 'Hover' },
                { var: '--blogi-nav-border', label: 'Border' },
                { var: '--blogi-accent-dark', label: 'Accent Dark' },
                { var: '--blogi-border', label: 'Border' },
                { var: '--blogi-bg-alt', label: 'Background Alt' },
                { var: '--blogi-error', label: 'Error' },
                { var: '--blogi-error-bg', label: 'Error Background' },
                { var: '--blogi-error-text', label: 'Error Text' },
                { var: '--blogi-success-bg', label: 'Success Background' },
                { var: '--blogi-success-text', label: 'Success Text' },
                { var: '--blogi-nav-active', label: 'Nav Active' },
                { var: '--blogi-nav-hover', label: 'Nav Hover' },
                { var: '--blogi-nav-border', label: 'Nav Border' },
            ];
        }

        function readThemeCssVars(themeMode) {
            const root = document.documentElement;
            const prevTheme = root.getAttribute('data-theme');

            if (themeMode) {
                root.setAttribute('data-theme', themeMode);
            } else {
                root.removeAttribute('data-theme');
            }

            const rootStyles = getComputedStyle(root);
            const values = {};
            for (const tv of getThemeVarDefinitions()) {
                values[tv.var] = rootStyles.getPropertyValue(tv.var).trim();
            }

            if (prevTheme === null) {
                root.removeAttribute('data-theme');
            } else {
                root.setAttribute('data-theme', prevTheme);
            }

            return values;
        }

        function buildThemeCssExport() {
            const darkVars = readThemeCssVars('dark');
            const lightVars = readThemeCssVars('light');
            const vars = getThemeVarDefinitions();

            const formatBlock = (selector, values) => {
                let block = `${selector} {\n`;
                for (const tv of vars) {
                    block += `  ${tv.var}: ${values[tv.var] || ''};\n`;
                }
                block += '}\n';
                return block;
            };

            let css = '/* Blogi theme colors exported from Webeditor */\n';
            css += '/* Dark mode defaults */\n';
            css += formatBlock(':root', darkVars);
            css += '\n/* Explicit light mode */\n';
            css += formatBlock(':root[data-theme="light"]', lightVars);
            css += '\n/* Auto light mode when dark mode is not forced */\n';
            css += '@media (prefers-color-scheme: light) {\n';
            css += formatBlock('  :root:not([data-theme="dark"])', lightVars);
            css += '}\n';
            return css;
        }

        function buildThemePromptExport() {
            const darkVars = readThemeCssVars('dark');
            const lightVars = readThemeCssVars('light');
            const vars = getThemeVarDefinitions();

            const formatPromptLines = (title, values) => {
                let block = `${title}:\n`;
                for (const tv of vars) {
                    block += `- ${tv.var}: ${values[tv.var] || ''}\n`;
                }
                return block;
            };

            let prompt = 'Use these Blogi theme design tokens consistently in generated UI output.\n';
            prompt += 'Preserve the distinction between dark mode and light mode.\n\n';
            prompt += formatPromptLines('Dark mode tokens', darkVars);
            prompt += '\n';
            prompt += formatPromptLines('Light mode tokens', lightVars);
            prompt += '\nGuidelines:\n';
            prompt += '- Use CSS custom properties exactly as named when possible.\n';
            prompt += '- Prefer accent colors for actions, links, and highlights.\n';
            prompt += '- Keep borders and surfaces subtle and readable in both modes.\n';
            prompt += '- Ensure text uses the matching theme text colors for contrast.\n';
            return prompt;
        }

        function downloadTextFile(filename, content, mimeType = 'text/plain;charset=utf-8') {
            const blob = new Blob([content], { type: mimeType });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            URL.revokeObjectURL(url);
        }

        function showThemeCssExportModal() {
            document.getElementById('theme-css-export-modal')?.remove();
            const cssExport = buildThemeCssExport();
            const promptExport = buildThemePromptExport();

            const overlay = document.createElement('div');
            overlay.id = 'theme-css-export-modal';
            overlay.className = 'modal-overlay';
            overlay.onclick = (event) => {
                if (event.target === overlay) overlay.remove();
            };

            const modal = document.createElement('div');
            modal.className = 'modal-content text-gray-800';
            modal.style.width = 'min(900px, 92vw)';
            modal.style.maxHeight = '85vh';
            modal.innerHTML = `
                <div class="flex justify-between items-center border-b pb-2 mb-4">
                    <h3 class="text-2xl font-bold text-blue-700">Theme CSS Export</h3>
                    <button type="button" onclick="document.getElementById('theme-css-export-modal').remove()" class="text-gray-500 hover:text-red-500 transition-colors duration-150 p-1 rounded-full">&#x2715;</button>
                </div>
                <p class="text-sm text-gray-600 mb-3">Exported CSS with dark and light Blogi theme variables for reuse in prompts or stylesheets.</p>
                <textarea id="theme-css-export-text" class="prop-textarea" style="min-height:360px; font-family:monospace; white-space:pre;">${escapeHtml(cssExport)}</textarea>
                <div class="flex gap-2 mt-4">
                    <button type="button" class="tpl-btn tpl-btn-primary" onclick="copyThemeCssExport()">Copy CSS</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="downloadThemeCssExport()">Download CSS</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="copyThemePromptExport()">Copy AI Prompt</button>
                    <button type="button" class="tpl-btn tpl-btn-secondary" onclick="document.getElementById('theme-css-export-modal').remove()">Close</button>
                </div>
                <p class="text-sm text-gray-600 mt-5 mb-3">AI prompt block for importing the same theme tokens into design or code generation prompts.</p>
                <textarea id="theme-prompt-export-text" class="prop-textarea" style="min-height:280px; font-family:monospace; white-space:pre;">${escapeHtml(promptExport)}</textarea>
                <div id="theme-css-export-status" class="prop-status mt-2"></div>
            `;

            overlay.appendChild(modal);
            document.body.appendChild(overlay);
        }

        async function copyThemeCssExport() {
            const textEl = document.getElementById('theme-css-export-text');
            const statusEl = document.getElementById('theme-css-export-status');
            if (!textEl) return;

            try {
                await navigator.clipboard.writeText(textEl.value);
                if (statusEl) {
                    statusEl.textContent = 'CSS copied to clipboard.';
                    statusEl.style.color = '#16a34a';
                }
            } catch (error) {
                textEl.select();
                document.execCommand('copy');
                if (statusEl) {
                    statusEl.textContent = 'CSS copied using fallback copy.';
                    statusEl.style.color = '#16a34a';
                }
            }
        }

        function downloadThemeCssExport() {
            const textEl = document.getElementById('theme-css-export-text');
            if (!textEl) return;
            downloadTextFile('blogi-theme-colors.css', textEl.value, 'text/css;charset=utf-8');
        }

        async function copyThemePromptExport() {
            const textEl = document.getElementById('theme-prompt-export-text');
            const statusEl = document.getElementById('theme-css-export-status');
            if (!textEl) return;

            try {
                await navigator.clipboard.writeText(textEl.value);
                if (statusEl) {
                    statusEl.textContent = 'AI prompt copied to clipboard.';
                    statusEl.style.color = '#16a34a';
                }
            } catch (error) {
                textEl.select();
                document.execCommand('copy');
                if (statusEl) {
                    statusEl.textContent = 'AI prompt copied using fallback copy.';
                    statusEl.style.color = '#16a34a';
                }
            }
        }

        function initThemeSwatches() {
            const container = document.getElementById('theme-swatches');
            if (!container) return;

            const themeVars = getThemeVarDefinitions();

            const rootStyles = getComputedStyle(document.documentElement);
            let html = '';