Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 54 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,67 @@

<input id="file-input" type="file">

<div id="file-area">
<h2>Click to add your file</h2>
<p id="drop-hint-text">or drag and drop it here</p>
</div>
<div id="side-panel">
<button id="mode-button">Advanced mode</button>
</div>
<nav>
<span class="nav-title">Convert</span>
<div class="mode-switch">
<span class="mode-label active" id="mode-label-simple">Simple</span>
<button id="mode-button" class="toggle-switch" role="switch" aria-checked="false">
<span class="toggle-thumb"></span>
</button>
<span class="mode-label" id="mode-label-advanced">Advanced</span>
</div>
</nav>

<div id="format-containers">
<main>

<section id="file-area">
<div class="upload-icon">
<svg width="44" height="44" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
</div>
<h2>Drop your file here</h2>
<p id="drop-hint-text">or click to browse</p>
</section>

<div id="from-container" class="format-container">
<h2>Convert from:</h2>
<input type="text" id="search-from" class="search" placeholder="Search">
<div id="from-list" class="format-list">
<section id="format-containers">

<div id="from-container" class="format-container">
<label class="format-label">From</label>
<div class="search-wrapper">
<svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"/>
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
</svg>
<input type="text" id="search-from" class="search" placeholder="Search formats...">
</div>
<div id="from-list" class="format-list"></div>
</div>
</div>

<div id="to-container" class="format-container">
<h2>Convert to:</h2>
<input type="text" id="search-to" class="search" placeholder="Search">
<div id="to-list" class="format-list">
<div class="format-divider" aria-hidden="true">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="5" y1="12" x2="19" y2="12"/>
<polyline points="12 5 19 12 12 19"/>
</svg>
</div>

<div id="to-container" class="format-container">
<label class="format-label">To</label>
<div class="search-wrapper">
<svg class="search-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"/>
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
</svg>
<input type="text" id="search-to" class="search" placeholder="Search formats...">
</div>
<div id="to-list" class="format-list"></div>
</div>
</div>

</div>
</section>

</main>

<button id="convert-button" class="disabled">Convert</button>

Expand All @@ -49,4 +83,4 @@ <h2>Loading tools...</h2>
<script type="module" src="src/main.ts"></script>

</body>
</html>
</html>
26 changes: 14 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const searchHandler = (event: Event) => {
const target = event.target;
if (!(target instanceof HTMLInputElement)) return;

const targetParentList = target.parentElement?.querySelector(".format-list");
const targetParentList = target.closest(".format-container")?.querySelector(".format-list");
if (!(targetParentList instanceof HTMLDivElement)) return;

const string = target.value.toLowerCase();
Expand Down Expand Up @@ -103,10 +103,15 @@ const fileSelectHandler = (event: Event) => {
files.sort((a, b) => a.name === b.name ? 0 : (a.name < b.name ? -1 : 1));
selectedFiles = files;

ui.fileSelectArea.innerHTML = `<h2>
${files[0].name}
${files.length > 1 ? `<br>... and ${files.length - 1} more` : ""}
</h2>`;
ui.fileSelectArea.innerHTML = `
<div class="upload-icon">
<svg width="44" height="44" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
</svg>
</div>
<h2>${files[0].name}</h2>
${files.length > 1 ? `<p class="file-count">and ${files.length - 1} more</p>` : ""}`;

// Common MIME type adjustments (to match "mime" library)
let mimeType = normalizeMimeType(files[0].type);
Expand Down Expand Up @@ -292,13 +297,10 @@ async function buildOptionList () {

ui.modeToggleButton.addEventListener("click", () => {
simpleMode = !simpleMode;
if (simpleMode) {
ui.modeToggleButton.textContent = "Advanced mode";
document.body.style.setProperty("--highlight-color", "#1C77FF");
} else {
ui.modeToggleButton.textContent = "Simple mode";
document.body.style.setProperty("--highlight-color", "#FF6F1C");
}
ui.modeToggleButton.classList.toggle("active", !simpleMode);
ui.modeToggleButton.setAttribute("aria-checked", (!simpleMode).toString());
document.getElementById("mode-label-simple")?.classList.toggle("active", simpleMode);
document.getElementById("mode-label-advanced")?.classList.toggle("active", !simpleMode);
buildOptionList();
});

Expand Down
Loading