Add bundled bus fonts and shared font favorites
This commit is contained in:
@@ -32,6 +32,7 @@ const fontOptions = document.getElementById("text-font-options");
|
||||
const importFontButton = document.getElementById("import-font");
|
||||
const fontFileInput = document.getElementById("font-file");
|
||||
const fontFeedback = document.getElementById("font-feedback");
|
||||
let favoriteEpoch = 0;
|
||||
let initialized = false;
|
||||
let suppressForm = false;
|
||||
let renderedSelectionId = null;
|
||||
@@ -43,6 +44,25 @@ let acceptedFontExtensions = [".ttf", ".otf", ".ttc", ".otc"];
|
||||
const fontPicker = createFontPicker({
|
||||
input: fontInput,
|
||||
listbox: fontOptions,
|
||||
onOpen() {
|
||||
const epoch = ++favoriteEpoch;
|
||||
apiJson("/api/fonts").then(catalog => { if (epoch === favoriteEpoch) fontPicker.setFavorites(catalog.favorite_ids); }).catch(() => {
|
||||
setFontFeedbackTemplate("copy.dynamic.font.read_error", "收藏状态读取失败,请重新打开字体列表", {}, true);
|
||||
});
|
||||
},
|
||||
async onFavorite(item, favorite) {
|
||||
favoriteEpoch += 1;
|
||||
try {
|
||||
const result = await apiJson("/api/fonts/favorite", {
|
||||
method: "PUT", body: JSON.stringify({ id: item.id, favorite }),
|
||||
});
|
||||
setFontFeedbackTemplate(favorite ? "copy.dynamic.font.saved" : "copy.dynamic.font.removed", favorite ? "字体已收藏" : "已取消收藏字体");
|
||||
return result.favorite_ids;
|
||||
} catch (error) {
|
||||
setFontFeedbackTemplate("copy.dynamic.font.save_error", "收藏保存失败:{error}", { error: error.message }, true);
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
onCommit(item) {
|
||||
const selected = getSelectedTextElement();
|
||||
if (!selected) return;
|
||||
@@ -220,6 +240,7 @@ subscribeScene(renderSelection);
|
||||
async function loadFontCatalog() {
|
||||
const catalog = await apiJson("/api/fonts");
|
||||
fontPicker.setItems(catalog.items);
|
||||
fontPicker.setFavorites(catalog.favorite_ids);
|
||||
acceptedFontExtensions = Array.isArray(catalog.accepted_extensions)
|
||||
? catalog.accepted_extensions.map((value) => String(value).toLowerCase())
|
||||
: acceptedFontExtensions;
|
||||
|
||||
Reference in New Issue
Block a user