Visual Studio Code, rebuilt in Rust
Rust
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src {{csp_source}}; media-src {{csp_source}}; script-src 'nonce-{{nonce}}'; style-src 'nonce-{{nonce}}';">
<style nonce="{{nonce}}">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
/* imageCarousel.css */
.image-carousel-editor {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.image-carousel-editor .slideshow-container {
display: flex;
flex-direction: column;
height: 100%;
gap: 8px;
overflow: hidden;
}
.image-carousel-editor .slideshow-container:focus,
.image-carousel-editor .slideshow-container:focus-visible {
outline: none !important;
}
.image-carousel-editor .image-area {
flex: 1;
min-height: 0;
position: relative;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
/* imageViewer.ts at its `fit` scale: the image as large as fits, never past its own size. */
.image-carousel-editor .image-viewer {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.image-carousel-editor .image-viewer img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
border-radius: var(--vscode-cornerRadius-small);
}
.image-carousel-editor .video-container {
width: 100%;
height: 100%;
border-radius: 4px;
overflow: hidden;
}
.image-carousel-editor .video-container video {
width: 100%;
height: 100%;
object-fit: contain;
outline: none;
}
.image-carousel-editor .nav-arrow {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
background: var(--vscode-toolbar-hoverBackground);
color: var(--vscode-foreground);
border: none;
border-radius: 50%;
cursor: pointer;
opacity: 0;
transition: opacity 0.15s ease;
z-index: 1;
padding: 0;
}
.image-carousel-editor .slideshow-container:hover .nav-arrow:not(:disabled) {
opacity: 0.8;
}
.image-carousel-editor .slideshow-container:hover .nav-arrow:disabled {
opacity: 0.3;
}
.image-carousel-editor .nav-arrow:hover:not(:disabled) {
opacity: 1 !important;
background: var(--vscode-toolbar-activeBackground);
color: var(--vscode-foreground);
}
.image-carousel-editor .nav-arrow:focus-visible:not(:disabled) {
opacity: 1 !important;
outline: 1px solid var(--vscode-focusBorder);
outline-offset: -1px;
}
.image-carousel-editor .nav-arrow:disabled {
cursor: default;
}
.image-carousel-editor .nav-arrow.prev-arrow {
left: 8px;
}
.image-carousel-editor .nav-arrow.next-arrow {
right: 8px;
}
.image-carousel-editor .bottom-bar {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 4px 0 8px;
flex-shrink: 0;
min-width: 0;
max-width: 100%;
}
.image-carousel-editor .bottom-bar .sections-container {
margin-top: 4px;
}
.image-carousel-editor .image-info-bar {
display: flex;
align-items: center;
justify-content: center;
gap: var(--vscode-spacing-size80);
max-width: 100%;
box-sizing: border-box;
text-align: center;
color: var(--vscode-descriptionForeground);
font-size: var(--vscode-fontSize-label1);
padding: 0 var(--vscode-spacing-size240);
min-height: 16px;
}
.image-carousel-editor .image-info-text {
min-width: 0;
overflow-wrap: anywhere;
}
.image-carousel-editor .image-actions {
flex-shrink: 0;
display: flex;
}
/* actionbar.css and the toolbar's action-label. */
.image-carousel-editor .image-actions .action-label {
display: flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 3px;
border-radius: 5px;
color: var(--vscode-icon-foreground);
cursor: pointer;
}
.image-carousel-editor .image-actions .action-label:hover {
background-color: var(--vscode-toolbar-hoverBackground);
outline: 1px dashed var(--vscode-toolbar-hoverOutline);
outline-offset: -1px;
}
.image-carousel-editor .caption-separator::before {
content: '\00b7';
margin: 0 6px;
opacity: 0.6;
}
.image-carousel-editor .image-counter {
opacity: 0.7;
}
.image-carousel-editor .sections-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 6px;
overflow-x: auto;
justify-content: center;
justify-content: safe center;
padding: 0;
flex-shrink: 0;
min-width: 0;
max-width: 100%;
scrollbar-width: none;
}
.image-carousel-editor .sections-container::-webkit-scrollbar {
display: none;
}
.image-carousel-editor .thumbnail {
width: 48px;
height: 48px;
border: 2px solid transparent;
border-radius: 4px;
overflow: hidden;
cursor: pointer;
transition: border-color 0.15s ease, opacity 0.15s ease;
flex-shrink: 0;
opacity: 0.6;
padding: 0;
background: none;
}
.image-carousel-editor .thumbnail:hover {
opacity: 1;
border-color: var(--vscode-focusBorder);
}
.image-carousel-editor .thumbnail:focus-visible {
opacity: 1;
outline: 1px solid var(--vscode-focusBorder);
outline-offset: 1px;
}
.image-carousel-editor .thumbnail.active {
opacity: 1;
border-color: var(--vscode-focusBorder);
}
.image-carousel-editor .thumbnail.broken {
display: flex;
align-items: center;
justify-content: center;
background: var(--vscode-editor-background);
}
.image-carousel-editor .thumbnail-broken-icon,
.image-carousel-editor .thumbnail-play-icon {
width: 20px;
height: 20px;
color: var(--vscode-descriptionForeground);
}
.image-carousel-editor .thumbnail-image {
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
}
.image-carousel-editor .thumbnail.video-thumbnail {
display: flex;
align-items: center;
justify-content: center;
background: var(--vscode-editor-background);
}
.image-carousel-editor .sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
.icon svg {
display: block;
width: 16px;
height: 16px;
}
.thumbnail-broken-icon svg, .thumbnail-play-icon svg {
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<div class="image-carousel-editor"></div>
<script nonce="{{nonce}}">
// imageCarouselEditor.ts `buildSlideshow` and `updateCurrentImage` for one section of files.
const vscode = acquireVsCodeApi();
const images = {{images}};
const icons = {{icons}};
let current = {{start_index}};
const container = document.querySelector('.image-carousel-editor');
const element = (tag, className, attributes = {}) => {
const node = document.createElement(tag);
node.className = className;
for (const [name, value] of Object.entries(attributes)) {
node.setAttribute(name, value);
}
return node;
};
const icon = (name, className) => {
const node = element('span', `icon ${className}`, { 'aria-hidden': 'true' });
node.innerHTML = icons[name];
return node;
};
const root = element('div', 'slideshow-container', { role: 'group', 'aria-label': 'Images Preview', tabindex: '0' });
const imageArea = element('div', 'image-area');
const viewer = element('div', 'image-viewer');
const mainImage = element('img', '');
viewer.appendChild(mainImage);
const videoContainer = element('div', 'video-container');
videoContainer.style.display = 'none';
const prevBtn = element('button', 'nav-arrow prev-arrow', { 'aria-label': 'Previous image' });
prevBtn.appendChild(icon('chevron-left', ''));
const nextBtn = element('button', 'nav-arrow next-arrow', { 'aria-label': 'Next image' });
nextBtn.appendChild(icon('chevron-right', ''));
imageArea.append(viewer, videoContainer, prevBtn, nextBtn);
const bottomBar = element('div', 'bottom-bar');
const infoBar = element('div', 'image-info-bar');
const infoText = element('span', 'image-info-text');
const captionText = element('span', 'caption-text');
const captionSeparator = element('span', 'caption-separator', { 'aria-hidden': 'true' });
const counter = element('span', 'image-counter');
infoText.append(captionText, captionSeparator, counter);
const actions = element('div', 'image-actions', { role: 'toolbar', 'aria-label': 'Images Preview actions' });
const download = element('a', 'action-label', { role: 'button', title: 'Download', 'aria-label': 'Download' });
download.appendChild(icon('cloud-download', ''));
download.addEventListener('click', () => vscode.postMessage({ type: 'download', index: current }));
actions.appendChild(download);
infoBar.append(infoText, actions);
const sections = element('div', 'sections-container', { role: 'group', 'aria-label': 'Image thumbnails' });
const ariaStatus = element('span', 'sr-only', { 'aria-live': 'polite', 'aria-atomic': 'true' });
bottomBar.append(infoBar, sections, ariaStatus);
root.append(imageArea, bottomBar);
const thumbnails = images.map((image, index) => {
const button = element('button', image.video ? 'thumbnail video-thumbnail' : 'thumbnail', {
'aria-label': `${image.video ? 'Video' : 'Image'} ${index + 1} of ${images.length}`,
});
if (image.video) {
button.appendChild(icon('play', 'thumbnail-play-icon'));
} else {
const img = element('img', 'thumbnail-image', { alt: image.name });
img.addEventListener('error', () => {
button.classList.add('broken');
img.remove();
button.appendChild(icon('warning', 'thumbnail-broken-icon'));
});
img.src = image.src;
button.appendChild(img);
}
button.addEventListener('click', () => show(index));
sections.appendChild(button);
return button;
});
function show(index) {
if (index < 0 || index >= images.length) {
return;
}
current = index;
const image = images[index];
if (image.video) {
viewer.style.display = 'none';
mainImage.removeAttribute('src');
videoContainer.style.display = '';
videoContainer.replaceChildren(element('video', '', { controls: '', src: image.src }));
} else {
videoContainer.style.display = 'none';
videoContainer.replaceChildren();
viewer.style.display = '';
mainImage.alt = image.name;
mainImage.src = image.src;
}
// Files carry no caption: the separator and caption stay hidden.
captionText.style.display = 'none';
captionSeparator.style.display = 'none';
counter.textContent = `${index + 1} / ${images.length}`;
ariaStatus.textContent = `${image.video ? 'Video' : 'Image'} ${index + 1} of ${images.length}: ${image.name}`;
prevBtn.disabled = index === 0;
nextBtn.disabled = index === images.length - 1;
thumbnails.forEach((thumbnail, i) => thumbnail.classList.toggle('active', i === index));
thumbnails[index].scrollIntoView({ block: 'nearest', inline: 'nearest' });
vscode.setState({ index });
}
prevBtn.addEventListener('click', () => show(current - 1));
nextBtn.addEventListener('click', () => show(current + 1));
root.addEventListener('keydown', e => {
if (e.key === 'ArrowLeft') {
show(current - 1);
} else if (e.key === 'ArrowRight') {
show(current + 1);
} else {
return;
}
e.stopPropagation();
e.preventDefault();
});
window.addEventListener('message', e => {
if (e.data?.type === 'focus') {
root.focus();
}
});
container.appendChild(root);
show((vscode.getState() || {}).index ?? current);
root.focus();
</script>
</body>
</html>