Add expressive unified file icons for popular extension families
This commit is contained in:
1 parent
d8bdf5f390
commit
6aca927851
6 files changed
+320
-26
No files matched your search
@@ -1,42 +1,47 @@
|
||||
<template>
|
||||
<AppIcon v-if="directory" name="folder" class="file-icon" />
|
||||
<svg
|
||||
v-else
|
||||
class="app-icon file-icon"
|
||||
viewBox="0 0 24 24"
|
||||
:class="`file-icon--${icon.kind}`"
|
||||
viewBox="0 0 32 32"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.4"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M5 2h9l5 5v15H5z M14 2v6h5" />
|
||||
<template v-if="!directory">
|
||||
<path
|
||||
d="M6 2h14l7 7v19a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z"
|
||||
fill="currentColor"
|
||||
fill-opacity=".09"
|
||||
/>
|
||||
<path d="M20 2v7h7" fill="currentColor" fill-opacity=".18" />
|
||||
</template>
|
||||
<path
|
||||
:d="icon.path"
|
||||
:fill="directory ? 'currentColor' : 'none'"
|
||||
:fill-opacity="directory ? '.16' : undefined"
|
||||
/>
|
||||
<text
|
||||
v-if="extension"
|
||||
x="12"
|
||||
y="17"
|
||||
v-if="!directory"
|
||||
x="15.5"
|
||||
y="27"
|
||||
text-anchor="middle"
|
||||
fill="currentColor"
|
||||
stroke="none"
|
||||
font-size="3.8"
|
||||
font-weight="650"
|
||||
font-size="4.5"
|
||||
font-weight="750"
|
||||
letter-spacing=".25"
|
||||
font-family="system-ui, sans-serif"
|
||||
>
|
||||
{{ extension }}
|
||||
{{ icon.label }}
|
||||
</text>
|
||||
<path v-else d="M8 12h8 M8 16h6" />
|
||||
</svg>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import AppIcon from "../AppIcon.vue";
|
||||
import { fileIcon } from "@/utils/file-icons";
|
||||
const props = defineProps<{ name: string; directory?: boolean }>();
|
||||
const extension = computed(
|
||||
() =>
|
||||
props.name
|
||||
.match(/\.([^.]+)$/)?.[0]
|
||||
.slice(0, 5)
|
||||
.toLowerCase() || ""
|
||||
);
|
||||
const icon = computed(() => fileIcon(props.name, props.directory));
|
||||
</script>
|
||||
@@ -9,15 +9,136 @@
|
||||
overflow: visible;
|
||||
}
|
||||
.file-icon {
|
||||
color: var(--blue);
|
||||
color: var(--file-tint, var(--blue));
|
||||
}
|
||||
.file-icon--folder,
|
||||
.file-icon--archive {
|
||||
--file-tint: #a56508;
|
||||
}
|
||||
.file-icon--pdf {
|
||||
--file-tint: #cb3343;
|
||||
}
|
||||
.file-icon--document {
|
||||
--file-tint: #3265ca;
|
||||
}
|
||||
.file-icon--spreadsheet {
|
||||
--file-tint: #16834d;
|
||||
}
|
||||
.file-icon--presentation {
|
||||
--file-tint: #c45d19;
|
||||
}
|
||||
.file-icon--image {
|
||||
--file-tint: #16838c;
|
||||
}
|
||||
.file-icon--vector,
|
||||
.file-icon--design {
|
||||
--file-tint: #ad4d99;
|
||||
}
|
||||
.file-icon--audio {
|
||||
--file-tint: #bd417d;
|
||||
}
|
||||
.file-icon--video {
|
||||
--file-tint: #8450c8;
|
||||
}
|
||||
.file-icon--code {
|
||||
--file-tint: #575ac4;
|
||||
}
|
||||
.file-icon--config,
|
||||
.file-icon--file,
|
||||
.file-icon--text {
|
||||
--file-tint: #64748b;
|
||||
}
|
||||
.file-icon--database {
|
||||
--file-tint: #167e9b;
|
||||
}
|
||||
.file-icon--executable {
|
||||
--file-tint: #b36037;
|
||||
}
|
||||
.file-icon--disc {
|
||||
--file-tint: #6b65ae;
|
||||
}
|
||||
.file-icon--medical {
|
||||
--file-tint: #078578;
|
||||
}
|
||||
.file-icon--book {
|
||||
--file-tint: #8b61ad;
|
||||
}
|
||||
.file-icon--font {
|
||||
--file-tint: #8d622f;
|
||||
}
|
||||
.file-icon--model {
|
||||
--file-tint: #397cb7;
|
||||
}
|
||||
.file-icon--certificate,
|
||||
.file-icon--torrent {
|
||||
--file-tint: #448241;
|
||||
}
|
||||
:root.dark .file-icon--folder,
|
||||
:root.dark .file-icon--archive {
|
||||
--file-tint: #efbf62;
|
||||
}
|
||||
:root.dark .file-icon--pdf {
|
||||
--file-tint: #fb7f8d;
|
||||
}
|
||||
:root.dark .file-icon--document {
|
||||
--file-tint: #83acff;
|
||||
}
|
||||
:root.dark .file-icon--spreadsheet {
|
||||
--file-tint: #6cd39c;
|
||||
}
|
||||
:root.dark .file-icon--presentation {
|
||||
--file-tint: #ffad70;
|
||||
}
|
||||
:root.dark .file-icon--image {
|
||||
--file-tint: #69cbd5;
|
||||
}
|
||||
:root.dark .file-icon--vector,
|
||||
:root.dark .file-icon--design {
|
||||
--file-tint: #e594d5;
|
||||
}
|
||||
:root.dark .file-icon--audio {
|
||||
--file-tint: #f18fbc;
|
||||
}
|
||||
:root.dark .file-icon--video {
|
||||
--file-tint: #b998ef;
|
||||
}
|
||||
:root.dark .file-icon--code {
|
||||
--file-tint: #a2a7ff;
|
||||
}
|
||||
:root.dark .file-icon--config,
|
||||
:root.dark .file-icon--file,
|
||||
:root.dark .file-icon--text {
|
||||
--file-tint: #adbbce;
|
||||
}
|
||||
:root.dark .file-icon--database {
|
||||
--file-tint: #74c7e7;
|
||||
}
|
||||
:root.dark .file-icon--executable {
|
||||
--file-tint: #e4a080;
|
||||
}
|
||||
:root.dark .file-icon--disc {
|
||||
--file-tint: #aaa2e7;
|
||||
}
|
||||
:root.dark .file-icon--medical {
|
||||
--file-tint: #65d2c0;
|
||||
}
|
||||
:root.dark .file-icon--book {
|
||||
--file-tint: #c5a2e1;
|
||||
}
|
||||
:root.dark .file-icon--font {
|
||||
--file-tint: #d6b07c;
|
||||
}
|
||||
:root.dark .file-icon--model {
|
||||
--file-tint: #84bae9;
|
||||
}
|
||||
:root.dark .file-icon--certificate,
|
||||
:root.dark .file-icon--torrent {
|
||||
--file-tint: #a0ce84;
|
||||
}
|
||||
.file-icons [aria-label^="."],
|
||||
.file-icons [data-ext=".bak"] {
|
||||
opacity: 0.55;
|
||||
}
|
||||
.file-icons [aria-selected="true"] .file-icon {
|
||||
color: inherit;
|
||||
}
|
||||
#listing .item .file-icon {
|
||||
font-size: 56px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { fileIcon } from "../file-icons";
|
||||
|
||||
it("distinguishes common formats by symbol family as well as extension", () => {
|
||||
const examples: Record<string, string[]> = {
|
||||
pdf: ["pdf"],
|
||||
document: ["doc", "docx", "odt", "rtf"],
|
||||
spreadsheet: ["xlsx", "ods", "csv"],
|
||||
presentation: ["pptx", "odp", "key"],
|
||||
image: ["jpg", "png", "heic", "nef"],
|
||||
vector: ["svg", "eps"],
|
||||
audio: ["mp3", "flac", "opus"],
|
||||
video: ["mp4", "mkv", "avi"],
|
||||
archive: ["zip", "rar", "7z", "gz"],
|
||||
code: ["ts", "js", "go", "py", "html", "vue"],
|
||||
config: ["json", "yaml", "toml"],
|
||||
database: ["sql", "sqlite", "parquet"],
|
||||
executable: ["exe", "msi", "deb", "rpm"],
|
||||
disc: ["iso", "vhdx"],
|
||||
medical: ["dcm", "dicom", "nii.gz"],
|
||||
book: ["epub", "fb2"],
|
||||
font: ["ttf", "woff2"],
|
||||
model: ["stl", "glb", "blend"],
|
||||
design: ["psd", "fig"],
|
||||
certificate: ["pem", "crt"],
|
||||
torrent: ["torrent"],
|
||||
text: ["txt", "md", "log"],
|
||||
};
|
||||
for (const [kind, extensions] of Object.entries(examples))
|
||||
for (const ext of extensions)
|
||||
expect(fileIcon(`sample.${ext.toUpperCase()}`).kind).toBe(kind);
|
||||
const icons = Object.values(examples).map((exts) => fileIcon(`a.${exts[0]}`));
|
||||
expect(new Set(icons.map((icon) => icon.path)).size).toBe(icons.length);
|
||||
});
|
||||
it("recognises special filenames, bounds labels and prioritises directories", () => {
|
||||
expect(fileIcon("README").kind).toBe("text");
|
||||
expect(fileIcon("Dockerfile").kind).toBe("code");
|
||||
expect(fileIcon(".env.production").kind).toBe("config");
|
||||
expect(fileIcon(".gitignore").kind).toBe("config");
|
||||
expect(fileIcon("C:\\folder\\a.dcm").label).toBe("DCM");
|
||||
expect(fileIcon("folder.png", true)).toMatchObject({
|
||||
kind: "folder",
|
||||
label: "",
|
||||
});
|
||||
expect(fileIcon("a.unknown-extension")).toMatchObject({
|
||||
kind: "file",
|
||||
label: "FILE",
|
||||
});
|
||||
expect(fileIcon("a.<svg>").label).toBe("FILE");
|
||||
expect(fileIcon("a.docx").label).toBe("DOCX");
|
||||
expect(fileIcon("a.doc").label).toBe("DOC");
|
||||
expect(fileIcon("constructor").kind).toBe("file");
|
||||
expect(fileIcon("__proto__").kind).toBe("file");
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
// Shared by listing, public downloads, preview fallbacks and ZIP entries.
|
||||
// Shapes and labels keep types distinguishable without relying on colour alone.
|
||||
const symbols = {
|
||||
file: "M10 12h9 M10 16h9 M10 20h6",
|
||||
text: "M9 11h12 M9 15h12 M9 19h8",
|
||||
pdf: "M10 20c4-3 6-8 4-9-2-1-1 8 4 8s-3-3-8 1z",
|
||||
document: "M9 11l2 9 4-6 4 6 2-9",
|
||||
spreadsheet: "M9 11h12v10H9z M9 16h12 M15 11v10",
|
||||
presentation: "M9 10h12v9H9z M15 19v3 M12 22h6 M12 16l3-3 3 2",
|
||||
image: "M9 10h12v11H9z m0 8 4-4 4 4 2-2 2 2 M18 13h.01",
|
||||
vector: "m15 10 6 6-6 6-6-6z M15 13v6 M12 16h6",
|
||||
audio:
|
||||
"M14 18v-7l7-1v7 M14 18a2 2 0 1 1-4 0 2 2 0 0 1 4 0 M21 17a2 2 0 1 1-4 0 2 2 0 0 1 4 0",
|
||||
video: "M9 10h12v11H9z m4 3 5 3-5 3z",
|
||||
archive: "M14 10h2 M16 12h2 M14 14h2 M16 16h2 M14 18h4v4h-4z",
|
||||
code: "m12 12-4 4 4 4 m6-8 4 4-4 4 M16 11l-2 10",
|
||||
config: "M9 13h5 M18 13h3 M9 19h2 M15 19h6 M14 11h4v4h-4z M11 17h4v4h-4z",
|
||||
database:
|
||||
"M21 12c0 3-12 3-12 0s12-3 12 0v8c0 3-12 3-12 0v-8 M9 16c0 3 12 3 12 0",
|
||||
executable: "m9 13 6-3 6 3-6 3z M9 13v6l6 3 6-3v-6 M15 16v6",
|
||||
disc: "M22 16a7 7 0 1 1-14 0 7 7 0 0 1 14 0 M17 16a2 2 0 1 1-4 0 2 2 0 0 1 4 0 M11 12l1 1 M18 19l1 1",
|
||||
medical: "M9 10h12v12H9z M10 16h2l2-3 2 6 2-3h2",
|
||||
book: "M9 10h12v12H9z M12 10v12 M15 13h3 M15 16h3",
|
||||
font: "m10 21 5-11 5 11 M12 17h6",
|
||||
model: "m15 10 7 4v6l-7 4-7-4v-6z M8 14l7 4 7-4 M15 18v6 M15 10v8",
|
||||
design: "m9 21 3-7 7-5 3 3-5 7z M12 14l5 5 M9 21l5-5",
|
||||
certificate: "M20 14a5 5 0 1 1-10 0 5 5 0 0 1 10 0 M12 18l-1 5 4-2 4 2-1-5",
|
||||
torrent: "M15 10v10 m-4-4 4 4 4-4 M9 20v3h12v-3",
|
||||
folder:
|
||||
"M3 9V6a2 2 0 0 1 2-2h7l3 3h12a2 2 0 0 1 2 2v17a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z M3 11h26",
|
||||
} as const;
|
||||
export type FileIconKind = keyof typeof symbols;
|
||||
const extensions: Partial<Record<FileIconKind, string>> = {
|
||||
pdf: "pdf",
|
||||
document: "doc docx docm dot dotx odt rtf pages wpd",
|
||||
spreadsheet: "xls xlsx xlsm xlsb ods numbers csv tsv",
|
||||
presentation: "ppt pptx pptm pps ppsx odp key",
|
||||
image:
|
||||
"jpg jpeg jfif png gif webp avif heic heif bmp tif tiff ico icns raw dng cr2 cr3 nef arw raf orf rw2",
|
||||
vector: "svg eps ai cdr",
|
||||
audio:
|
||||
"mp3 wav wave ogg oga opus flac aac m4a alac aiff aif wma mid midi ape amr ac3 m3u m3u8 pls",
|
||||
video: "mp4 m4v webm mkv avi mov wmv flv mpg mpeg m2ts mts ts vob ogv 3gp",
|
||||
archive:
|
||||
"zip zipx rar 7z tar gz gzip tgz bz2 tbz2 xz txz zst zstd lz lzma cab arj cpio br",
|
||||
code: "js mjs cjs jsx ts tsx py pyw go rs c cpp cc cxx h hpp cs java class jar kt kts swift rb php phtml pl pm lua r dart vue svelte astro html htm xhtml css scss sass less wasm ipynb sh bash zsh fish bat cmd ps1 vbs dockerfile makefile cmake gradle",
|
||||
config:
|
||||
"json jsonc json5 yaml yml toml ini conf cfg config env properties editorconfig gitignore gitattributes lock service reg desktop xml plist manifest",
|
||||
database:
|
||||
"sql db sqlite sqlite3 db3 mdb accdb bson parquet arrow feather h5 hdf5",
|
||||
executable:
|
||||
"exe msi msix appx app apk aab deb rpm appimage dmg pkg dll so dylib bin elf com scr",
|
||||
disc: "iso img vhd vhdx vmdk qcow qcow2 vdi cue nrg",
|
||||
medical: "dcm dicom ima nii nrrd mhd mha",
|
||||
book: "epub mobi azw azw3 fb2 djvu djv cbz cbr",
|
||||
font: "ttf otf woff woff2 eot fon",
|
||||
model: "stl obj fbx gltf glb blend 3ds dae ply step stp iges igs dwg dxf",
|
||||
design: "psd psb sketch fig xcf afdesign afphoto indd aep prproj drp",
|
||||
certificate: "pem crt cer p12 pfx p7b key pub asc gpg sig",
|
||||
torrent: "torrent",
|
||||
text: "txt text log md markdown rst adoc nfo srt vtt ass sub tex bib",
|
||||
};
|
||||
const lookup = new Map<string, FileIconKind>();
|
||||
for (const [kind, names] of Object.entries(extensions))
|
||||
for (const name of names.split(" "))
|
||||
if (!lookup.has(name)) lookup.set(name, kind as FileIconKind);
|
||||
// Resolve ambiguous extensions toward the common workspace use.
|
||||
lookup.set("ts", "code");
|
||||
lookup.set("key", "presentation");
|
||||
const named: Record<string, FileIconKind> = {
|
||||
dockerfile: "code",
|
||||
makefile: "code",
|
||||
cmakelists: "code",
|
||||
jenkinsfile: "code",
|
||||
license: "text",
|
||||
licence: "text",
|
||||
readme: "text",
|
||||
changelog: "text",
|
||||
authors: "text",
|
||||
copying: "text",
|
||||
};
|
||||
export function fileIcon(name: string, directory = false) {
|
||||
const base = name.split(/[\\/]/).pop()?.toLowerCase() || "";
|
||||
const extension = base.includes(".") ? base.split(".").pop() || "" : "";
|
||||
let kind: FileIconKind = directory
|
||||
? "folder"
|
||||
: (Object.prototype.hasOwnProperty.call(named, base)
|
||||
? named[base]
|
||||
: undefined) ||
|
||||
(base.startsWith(".env") && (base === ".env" || base.startsWith(".env."))
|
||||
? "config"
|
||||
: lookup.get(extension) || "file");
|
||||
// Never truncate long/unknown extensions into a misleading recognised label.
|
||||
if (!directory && base.endsWith(".nii.gz")) kind = "medical";
|
||||
const fallbackLabels: Partial<Record<FileIconKind, string>> = {
|
||||
text: "TXT",
|
||||
code: "CODE",
|
||||
config: "CONF",
|
||||
document: "DOC",
|
||||
spreadsheet: "TABLE",
|
||||
presentation: "SLIDE",
|
||||
image: "IMAGE",
|
||||
archive: "ZIP",
|
||||
medical: "DCM",
|
||||
database: "DATA",
|
||||
certificate: "CERT",
|
||||
};
|
||||
const label = directory
|
||||
? ""
|
||||
: /^[a-z0-9]{1,5}$/.test(extension)
|
||||
? extension.toUpperCase()
|
||||
: fallbackLabels[kind] || "FILE";
|
||||
return { kind, label, path: symbols[kind] };
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
param([string]$Version = '3.0.0-sso.15')
|
||||
param([string]$Version = '3.0.0-sso.16')
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
Push-Location $repo
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
VERSION="${VERSION:-3.0.0-sso.15}"
|
||||
VERSION="${VERSION:-3.0.0-sso.16}"
|
||||
COMMIT=$(git rev-parse --short HEAD)
|
||||
(cd frontend && pnpm install --frozen-lockfile && pnpm run build)
|
||||
mkdir -p build/release/linux-amd64
|
||||
|
||||
Reference in new issue
Block a user