feat(bulk-api-tester): add shareable visual comparison studio with full-view interactive slider, side-by-side, and gallery
This commit is contained in:
+247
-1
@@ -1158,6 +1158,9 @@ const App = {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary btn-sm" style="height:32px; background:linear-gradient(135deg, #7257ff, #5935f8);" onclick="App.createShareableComparison()" ${bulk.results.length === 0 ? 'disabled' : ''} title="Create and copy shareable comparison link">
|
||||
<i class="fa-solid fa-share-nodes"></i> Share Comparison
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-sm" style="height:32px;" onclick="App.saveAllResults()" ${bulk.results.length === 0 ? 'disabled' : ''}>
|
||||
<i class="fa-solid fa-file-zipper"></i> ZIP
|
||||
</button>
|
||||
@@ -3012,6 +3015,245 @@ const App = {
|
||||
}
|
||||
},
|
||||
|
||||
// ── Shareable Visual Comparison Studio ─────────────────────────────────────
|
||||
async createShareableComparison() {
|
||||
const results = this.state.bulk.results;
|
||||
if (!results || results.length === 0) {
|
||||
return this.toast('No results to compare yet. Run requests or batch first.', 'warning');
|
||||
}
|
||||
|
||||
// Create sleek progress overlay
|
||||
const progressModal = document.createElement('div');
|
||||
progressModal.className = 'premium-modal-overlay share-progress-overlay';
|
||||
progressModal.style.zIndex = '99999';
|
||||
progressModal.innerHTML = `
|
||||
<div class="premium-modal-card" style="width:min(440px, 92vw); padding:26px; text-align:center;">
|
||||
<div style="font-size:32px; color:var(--accent); margin-bottom:12px;">
|
||||
<i class="fa-solid fa-spinner fa-spin"></i>
|
||||
</div>
|
||||
<h3 style="font-family:var(--font-display); font-size:16px; margin:0 0 6px 0; color:var(--text-1);">Packaging Comparison Snapshot</h3>
|
||||
<p id="share-progress-text" style="font-size:12px; color:var(--text-3); margin:0 0 16px 0;">Processing result assets (0/${results.length})...</p>
|
||||
<div class="progress-track" style="margin-bottom:0; height:6px;">
|
||||
<div id="share-progress-fill" class="progress-fill" style="width:0%; background:linear-gradient(90deg, #7257ff, #38bdf8);"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(progressModal);
|
||||
|
||||
const updateProgress = (done, total) => {
|
||||
const pText = document.getElementById('share-progress-text');
|
||||
const pFill = document.getElementById('share-progress-fill');
|
||||
if (pText) pText.textContent = `Processing result assets (${done}/${total})...`;
|
||||
if (pFill) pFill.style.width = `${Math.round((done / total) * 100)}%`;
|
||||
};
|
||||
|
||||
const blobToBase64 = (blob) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result);
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
const items = [];
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const r = results[i];
|
||||
updateProgress(i + 1, results.length);
|
||||
|
||||
let beforeData = '';
|
||||
let afterData = '';
|
||||
|
||||
// 1. Resolve Before Image
|
||||
const beforeObj = this.resolveOriginalImageForResult(r);
|
||||
if (beforeObj && beforeObj.url) {
|
||||
try {
|
||||
const bBlob = await fetch(beforeObj.url).then(res => res.blob());
|
||||
beforeData = await blobToBase64(bBlob);
|
||||
} catch(e) {
|
||||
console.warn("Failed to encode before image", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Resolve After Image
|
||||
if (r.blobUrl) {
|
||||
try {
|
||||
const aBlob = await fetch(r.blobUrl).then(res => res.blob());
|
||||
afterData = await blobToBase64(aBlob);
|
||||
} catch(e) {
|
||||
console.warn("Failed to encode after image", e);
|
||||
}
|
||||
} else if (r.binaryData) {
|
||||
afterData = r.binaryData.startsWith('data:') ? r.binaryData : `data:${r.contentType || 'image/png'};base64,${r.binaryData}`;
|
||||
}
|
||||
|
||||
items.push({
|
||||
index: r.index || (i + 1),
|
||||
status: r.status,
|
||||
latency: r.latency || 0,
|
||||
inputFilename: (beforeObj && beforeObj.name) || r.inputFilename || `input_${i+1}`,
|
||||
outputFilename: this.getFinalFilename(r),
|
||||
contentType: r.contentType || 'image/png',
|
||||
beforeData: beforeData,
|
||||
afterData: afterData,
|
||||
textContent: r.fullContent || (typeof r.data === 'string' ? r.data : '')
|
||||
});
|
||||
}
|
||||
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
const payload = {
|
||||
title: `Batch Comparison (${results.length} results)`,
|
||||
endpoint: this.state.url || '',
|
||||
spaceName: activeSpace ? activeSpace.name : 'Default Space',
|
||||
items: items
|
||||
};
|
||||
|
||||
const basePath = window.location.pathname.includes('/tool/bulk-api-tester') ? '/tool/bulk-api-tester' : '';
|
||||
const res = await fetch(`${basePath}/api/share-comparison`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
progressModal.remove();
|
||||
|
||||
if (!res.ok) {
|
||||
const errJson = await res.json().catch(() => ({}));
|
||||
throw new Error(errJson.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
if (!data.success) {
|
||||
throw new Error(data.error || 'Failed to create share link');
|
||||
}
|
||||
|
||||
// Build full public URL
|
||||
const origin = window.location.origin;
|
||||
const shareUrl = `${origin}${basePath}/compare/${data.shareId}`;
|
||||
|
||||
// Automatically copy to clipboard
|
||||
let copied = false;
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(shareUrl);
|
||||
copied = true;
|
||||
}
|
||||
} catch(_) {
|
||||
// Fallback for environments without direct clipboard focus
|
||||
try {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = shareUrl;
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
copied = document.execCommand('copy');
|
||||
ta.remove();
|
||||
} catch(__) {}
|
||||
}
|
||||
|
||||
if (copied) {
|
||||
this.toast('Shareable comparison link copied to clipboard!', 'success');
|
||||
} else {
|
||||
this.toast('Shareable comparison link created!', 'info');
|
||||
}
|
||||
|
||||
// Show Obsidian Liquid Glass Share Modal
|
||||
this.showShareComparisonModal(shareUrl, data.shareId, results.length);
|
||||
|
||||
} catch (e) {
|
||||
progressModal.remove();
|
||||
this.toast('Failed to create comparison: ' + (e ? e.message : 'Unknown error'), 'error');
|
||||
}
|
||||
},
|
||||
|
||||
showShareComparisonModal(shareUrl, shareId, count) {
|
||||
// Remove existing modal if any
|
||||
const existing = document.querySelector('.comparison-share-success-modal');
|
||||
if (existing) existing.remove();
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'premium-modal-overlay comparison-share-success-modal';
|
||||
modal.style.zIndex = '99999';
|
||||
|
||||
modal.innerHTML = `
|
||||
<div class="premium-modal-card" onclick="event.stopPropagation();" style="width:min(520px, 94vw); padding:26px; border-radius:var(--r-lg);">
|
||||
<div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:16px;">
|
||||
<div style="display:flex; align-items:center; gap:10px;">
|
||||
<div style="width:36px; height:36px; border-radius:var(--r-md); background:linear-gradient(135deg, #7257ff, #38bdf8); display:flex; align-items:center; justify-content:center; color:#fff; font-size:16px; box-shadow:0 4px 12px rgba(var(--accent-rgb), 0.4);">
|
||||
<i class="fa-solid fa-share-nodes"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h3 style="margin:0; font-family:var(--font-display); font-size:16px; color:var(--text-1);">Shareable Comparison Ready</h3>
|
||||
<span style="font-size:11.5px; color:var(--text-3); font-family:var(--font-mono);">${count} results packaged · ID: ${shareId}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="modal-close-btn" onclick="this.closest('.premium-modal-overlay').remove()">✕</button>
|
||||
</div>
|
||||
|
||||
<p style="font-size:12.5px; color:var(--text-2); margin-bottom:16px; line-height:1.5;">
|
||||
Anyone with this link can view the interactive Before & After split slider, side-by-side inspection, and download high-resolution outputs in full view.
|
||||
</p>
|
||||
|
||||
<!-- Link Copy Box -->
|
||||
<div style="display:flex; gap:8px; align-items:center; background:rgba(0,0,0,0.35); border:1px solid var(--border-2); border-radius:var(--r-md); padding:4px 6px 4px 12px; margin-bottom:18px;">
|
||||
<input type="text" id="share-modal-input" readonly value="${shareUrl}"
|
||||
style="flex:1; background:transparent; border:none; color:var(--cyan); font-family:var(--font-mono); font-size:12px; outline:none; text-overflow:ellipsis;"
|
||||
onclick="this.select();">
|
||||
<button class="btn btn-primary btn-sm" id="btn-modal-copy-link" onclick="App.copyLinkFromInput()">
|
||||
<i class="fa-solid fa-copy"></i> Copy
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Feature Highlights -->
|
||||
<div style="display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:20px;">
|
||||
<div style="background:rgba(255,255,255,0.03); border:1px solid var(--border-1); border-radius:var(--r-md); padding:10px 12px;">
|
||||
<div style="font-size:12px; font-weight:700; color:var(--text-1); margin-bottom:2px;"><i class="fa-solid fa-arrows-split-up-and-left" style="color:var(--accent);"></i> Interactive Studio</div>
|
||||
<div style="font-size:11px; color:var(--text-3);">Split slider, side-by-side & blink diff modes</div>
|
||||
</div>
|
||||
<div style="background:rgba(255,255,255,0.03); border:1px solid var(--border-1); border-radius:var(--r-md); padding:10px 12px;">
|
||||
<div style="font-size:12px; font-weight:700; color:var(--text-1); margin-bottom:2px;"><i class="fa-solid fa-file-zipper" style="color:var(--cyan);"></i> Standalone ZIP</div>
|
||||
<div style="font-size:11px; color:var(--text-3);">Recipients can download all results in 1 click</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Footer -->
|
||||
<div style="display:flex; justify-content:flex-end; gap:10px;">
|
||||
<button class="btn btn-ghost btn-sm" onclick="this.closest('.premium-modal-overlay').remove()">Close</button>
|
||||
<a href="${shareUrl}" target="_blank" class="btn btn-primary btn-sm" style="text-decoration:none;">
|
||||
<i class="fa-solid fa-arrow-up-right-from-square"></i> Open Comparison View
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(modal);
|
||||
modal.onclick = () => modal.remove();
|
||||
},
|
||||
|
||||
copyLinkFromInput() {
|
||||
const input = document.getElementById('share-modal-input');
|
||||
const btn = document.getElementById('btn-modal-copy-link');
|
||||
if (!input) return;
|
||||
|
||||
input.select();
|
||||
navigator.clipboard.writeText(input.value).then(() => {
|
||||
this.toast('Comparison link copied to clipboard!', 'success');
|
||||
if (btn) {
|
||||
const orig = btn.innerHTML;
|
||||
btn.innerHTML = `<i class="fa-solid fa-check"></i> Copied!`;
|
||||
btn.style.background = 'var(--success)';
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = orig;
|
||||
btn.style.background = '';
|
||||
}, 2000);
|
||||
}
|
||||
}).catch(err => {
|
||||
this.toast('Failed to copy link', 'error');
|
||||
});
|
||||
},
|
||||
|
||||
// --- Rendering ---
|
||||
|
||||
// Debounced render — coalesces rapid successive calls (e.g., keystrokes)
|
||||
@@ -3274,7 +3516,7 @@ const App = {
|
||||
if (isResults && bulk.results.length > 0) {
|
||||
const fp = this.state.outputFolderPath || 'None selected';
|
||||
c.style.display = 'flex';
|
||||
c.innerHTML = `<div class="folder-selector-container"><span class="folder-path-display" title="${fp}"><i class="fa-solid fa-folder-open"></i> ${fp}</span><button class="btn btn-ghost" style="padding:0 11px;height:100%;border:none;border-radius:0;border-left:1px solid var(--border-2);font-size:10px;" onclick="App.browseServerFolder()">Browse</button><button class="btn btn-primary" style="padding:0 11px;height:100%;border:none;border-radius:0;font-size:10px;" onclick="App.saveToServerFolder()"><i class="fa-solid fa-cloud-arrow-up"></i> Save</button></div><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.saveAllResults()"><i class="fa-solid fa-file-zipper"></i> ZIP</button><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.downloadHistory()"><i class="fa-solid fa-file-csv"></i> CSV</button><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.openFullscreenResults()"><i class="fa-solid fa-maximize"></i> Expand</button><button class="btn btn-danger btn-sm" style="height:30px;" onclick="App.clearBulkResults()"><i class="fa-solid fa-trash"></i> Clear</button>`;
|
||||
c.innerHTML = `<div class="folder-selector-container"><span class="folder-path-display" title="${fp}"><i class="fa-solid fa-folder-open"></i> ${fp}</span><button class="btn btn-ghost" style="padding:0 11px;height:100%;border:none;border-radius:0;border-left:1px solid var(--border-2);font-size:10px;" onclick="App.browseServerFolder()">Browse</button><button class="btn btn-primary" style="padding:0 11px;height:100%;border:none;border-radius:0;font-size:10px;" onclick="App.saveToServerFolder()"><i class="fa-solid fa-cloud-arrow-up"></i> Save</button></div><button class="btn btn-primary btn-sm" style="height:30px;background:linear-gradient(135deg,#7257ff,#5935f8);" onclick="App.createShareableComparison()" title="Create and copy shareable comparison link"><i class="fa-solid fa-share-nodes"></i> Share Comparison</button><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.saveAllResults()"><i class="fa-solid fa-file-zipper"></i> ZIP</button><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.downloadHistory()"><i class="fa-solid fa-file-csv"></i> CSV</button><button class="btn btn-ghost btn-sm" style="height:30px;" onclick="App.openFullscreenResults()"><i class="fa-solid fa-maximize"></i> Expand</button><button class="btn btn-danger btn-sm" style="height:30px;" onclick="App.clearBulkResults()"><i class="fa-solid fa-trash"></i> Clear</button>`;
|
||||
} else {
|
||||
c.style.display = 'none';
|
||||
}
|
||||
@@ -4305,6 +4547,9 @@ const App = {
|
||||
<button class="btn btn-ghost btn-sm" onclick="App.downloadIndividualResult(${result.index})">
|
||||
<i class="fa-solid fa-arrow-down"></i> Download Result
|
||||
</button>
|
||||
<button class="btn btn-primary btn-sm" style="background:linear-gradient(135deg,#7257ff,#5935f8);" onclick="App.createShareableComparison()">
|
||||
<i class="fa-solid fa-share-nodes"></i> Share Comparison
|
||||
</button>
|
||||
<button class="btn btn-primary btn-sm" onclick="App.saveIndividualToServerFolder(${result.index})">
|
||||
<i class="fa-solid fa-folder-plus"></i> Save to Server Folder
|
||||
</button>
|
||||
@@ -4520,6 +4765,7 @@ const App = {
|
||||
}
|
||||
};
|
||||
|
||||
window.App = App;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => App.init());
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user