mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 15:06:46 +08:00
This commit is contained in:
1 parent
1914b5329a
commit
f9646c70e9
8 files changed
+163
-68
No files matched your search
@@ -265,12 +265,26 @@ a:focus-visible {
|
||||
}
|
||||
|
||||
.font-listbox [role="option"] {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 6px 8px;
|
||||
line-height: 1.4;
|
||||
overflow-wrap: anywhere;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.font-listbox [role="option"] > span:first-child {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.font-option-source {
|
||||
flex: none;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.font-listbox [role="option"]:hover,
|
||||
.font-listbox [aria-selected="true"] {
|
||||
background: var(--accent-soft);
|
||||
|
||||
@@ -26,6 +26,11 @@ export class FontPicker {
|
||||
setFonts(fonts, selected) {
|
||||
this.close();
|
||||
this.fonts = fonts;
|
||||
this.names = new Map();
|
||||
for (const font of fonts) {
|
||||
const name = (font.fullName || font.name).normalize("NFKC").toLocaleLowerCase();
|
||||
this.names.set(name, (this.names.get(name) || 0) + 1);
|
||||
}
|
||||
const key = font => font?.id || font?.postscriptName;
|
||||
this.value = fonts.length ? String(Math.max(0, fonts.findIndex(font => key(font) === key(selected)))) : "";
|
||||
this.restore();
|
||||
@@ -39,10 +44,17 @@ export class FontPicker {
|
||||
restore() {
|
||||
const font = this.fonts[Number(this.value)];
|
||||
this.input.value = font?.fullName || font?.name || "";
|
||||
this.input.title = font ? [this.input.value, this.sourceLabel(font)].filter(Boolean).join(" · ") : "";
|
||||
this.input.setAttribute("aria-expanded", String(this.open));
|
||||
this.input.removeAttribute("aria-activedescendant");
|
||||
}
|
||||
|
||||
sourceLabel(font) {
|
||||
const name = (font.fullName || font.name).normalize("NFKC").toLocaleLowerCase();
|
||||
if (this.names.get(name) < 2) return "";
|
||||
return font.embedded ? "内嵌" : font.file || ["stored", "upload"].includes(font.source) ? "上传" : "系统";
|
||||
}
|
||||
|
||||
show(query = "") {
|
||||
if (this.input.disabled) return;
|
||||
const normalize = value => value.normalize("NFKC").toLocaleLowerCase().replace(/\s+/g, " ").trim();
|
||||
@@ -58,7 +70,17 @@ export class FontPicker {
|
||||
option.dataset.index = String(index);
|
||||
option.setAttribute("role", "option");
|
||||
option.setAttribute("aria-disabled", String(Boolean(font.disabled)));
|
||||
option.textContent = font.fullName || font.name;
|
||||
const name = document.createElement("span");
|
||||
name.textContent = font.fullName || font.name;
|
||||
option.append(name);
|
||||
const source = this.sourceLabel(font);
|
||||
if (source) {
|
||||
const label = document.createElement("span");
|
||||
label.className = "font-option-source";
|
||||
label.textContent = source;
|
||||
option.append(label);
|
||||
}
|
||||
option.title = font.name || font.fullName;
|
||||
this.list.append(option);
|
||||
}
|
||||
if (!this.matches.length) {
|
||||
|
||||
Reference in new issue
Block a user