An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Improve loading indicators with customizable fading rings https://github.com/siyuan-note/siyuan/issues/20835
Daniela647c908ac95
diff --git a/app/src/assets/scss/base.scss b/app/src/assets/scss/base.scssindex e3668ff53b..cb83aa7e77 100644--- a/app/src/assets/scss/base.scss+++ b/app/src/assets/scss/base.scss@@ -5,6 +5,7 @@@use "business/template-manager" as *;@use "business/skill-manager" as *;@use "component/chip" as *;+@use "component/loading" as *;@use "component/slider" as *;@use "component/switch" as *;@use "util/scroll" as *;diff --git a/app/src/assets/scss/business/_ai_agent.scss b/app/src/assets/scss/business/_ai_agent.scssindex cfb925a22f..500dc06f35 100644--- a/app/src/assets/scss/business/_ai_agent.scss+++ b/app/src/assets/scss/business/_ai_agent.scss@@ -1225,19 +1225,7 @@}.agent-chat__mirror-spinner {- width: 10px;- height: 10px;- border: 2px solid var(--b3-theme-on-surface-light);- border-top-color: transparent;- border-radius: 50%;- animation: agent-mirror-spin 0.8s linear infinite;- flex-shrink: 0;-}--@keyframes agent-mirror-spin {- to {- transform: rotate(360deg);- }+ align-self: center;}// 发送框和历史消息编辑器复用相同排版,尺寸和滚动按使用场景分别约束。diff --git a/app/src/assets/scss/component/_loading.scss b/app/src/assets/scss/component/_loading.scssnew file mode 100644index 0000000000..e189b8bf35--- /dev/null+++ b/app/src/assets/scss/component/_loading.scss@@ -0,0 +1,65 @@+// 空的 .b3-loading 元素只负责指示器,显示状态和布局由外部容器控制。+// 主题可设置 --b3-loading-size、--b3-loading-color、--b3-loading-width、--b3-loading-duration,+// 或覆盖 ::before、::after 自行绘制动画;启动阶段不依赖图标库或主题初始化。+.b3-loading {+ position: relative;+ display: inline-block;+ flex-shrink: 0;+ width: var(--b3-loading-size, 32px);+ height: var(--b3-loading-size, 32px);+ vertical-align: middle;+ color: var(--b3-loading-color, var(--b3-theme-on-surface, #808080));++ &--small {+ width: var(--b3-loading-size, 16px);+ height: var(--b3-loading-size, 16px);+ }++ &--large {+ width: var(--b3-loading-size, 48px);+ height: var(--b3-loading-size, 48px);+ }++ &::before {+ content: "";+ position: absolute;+ inset: 0;+ box-sizing: border-box;+ border: var(--b3-loading-width, 2px) solid currentColor;+ border-right-color: transparent;+ border-radius: 50%;+ animation: b3-loading-spin var(--b3-loading-duration, 1s) linear infinite;+ }+}++// 不支持渐变遮罩的 WebView 保留可见的单圆环。+@supports (background: conic-gradient(transparent, currentColor)) and ((mask: radial-gradient(#000, transparent)) or (-webkit-mask: radial-gradient(#000, transparent))) {+ .b3-loading::before {+ border: 0;+ background: conic-gradient(from -90deg, transparent 0deg, currentColor 300deg, transparent 301deg);+ -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--b3-loading-width, 2px) - .3px), #000 calc(100% - var(--b3-loading-width, 2px) + .3px));+ mask: radial-gradient(farthest-side, transparent calc(100% - var(--b3-loading-width, 2px) - .3px), #000 calc(100% - var(--b3-loading-width, 2px) + .3px));+ }+}++@keyframes b3-loading-spin {+ to {+ transform: rotate(360deg);+ }+}++@media (prefers-reduced-motion: reduce) {+ .b3-loading::before {+ animation: none;+ }+}++@media (forced-colors: active) {+ .b3-loading::before {+ border: var(--b3-loading-width, 2px) solid CanvasText;+ border-right-color: transparent;+ background: none;+ -webkit-mask: none;+ mask: none;+ }+}diff --git a/app/src/assets/scss/export.scss b/app/src/assets/scss/export.scssindex 0312e62465..df048e4c6c 100644--- a/app/src/assets/scss/export.scss+++ b/app/src/assets/scss/export.scss@@ -1,5 +1,6 @@@use "util/mixin" as *;@use "component/tooltips" as *;+@use "component/loading" as *;@use "protyle/wysiwyg" as * with ($block-rtl-selector: '[style*="direction: rtl"]');@use "component/typography" as *;@use "protyle/attr" as *;diff --git a/app/src/assets/scss/mobile.scss b/app/src/assets/scss/mobile.scssindex 2b09692a5c..a44551aba5 100644--- a/app/src/assets/scss/mobile.scss+++ b/app/src/assets/scss/mobile.scss@@ -1,6 +1,7 @@@use "util/keyframes" as *;@use "util/function" as *;@use "component/chip" as *;+@use "component/loading" as *;@use "component/slider" as *;@use "component/switch" as *;@use "component/dialog" as *;diff --git a/app/src/assets/template/app/window.tpl b/app/src/assets/template/app/window.tplindex d50754f3d7..61405e2e11 100644--- a/app/src/assets/template/app/window.tpl+++ b/app/src/assets/template/app/window.tpl@@ -27,7 +27,7 @@</head><body class="fn__flex-column body--window" aria-busy="true"><div id="loading" class="fn__loading window-loading" role="status">- <img width="48" src="../../loading-pure.svg" alt="">+ <span class="b3-loading b3-loading--large" aria-hidden="true"></span></div><div class="fn__flex-1 fn__flex"><div id="layouts" class="layout fn__flex-1"></div>diff --git a/app/src/config/assets.ts b/app/src/config/assets.tsindex 7c202556cb..afc8b3fec9 100644--- a/app/src/config/assets.ts+++ b/app/src/config/assets.ts@@ -43,7 +43,7 @@ const loadMissingAssets = async (panel: Element) => {}panel.setAttribute("data-loading", "true");const list = panel.querySelector(".config-assets__list");- list.innerHTML = '<li class="fn__loading"><img src="/stage/loading-pure.svg"></li>';+ list.innerHTML = '<li class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></li>';try {const response = await fetchSyncPost("/api/asset/getMissingAssets", {});if (response.code !== 0) {@@ -151,7 +151,7 @@ const assets = {</div><div class="fn__hr"></div><ul class="b3-list b3-list--background config-assets__list">- <li class="fn__loading"><img src="/stage/loading-pure.svg"></li>+ <li class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></li></ul><div class="config-assets__preview fn__none"></div></div>@@ -166,14 +166,14 @@ const assets = {</div><div class="fn__hr"></div><ul class="b3-list b3-list--background config-assets__list">- <li class="fn__loading"><img src="/stage/loading-pure.svg"></li>+ <li class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></li></ul><div class="config-assets__preview fn__none" style="display: block;padding: 8px;"></div></div><div class="fn__none config-assets${mobile ? " b3-list--mobile" : ""}" data-type="missing"><div class="fn__hr"></div><ul class="b3-list b3-list--background config-assets__list">- <li class="fn__loading"><img src="/stage/loading-pure.svg"></li>+ <li class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></li></ul><div class="fn__hr"></div></div>diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex e4072e6ded..f1952dbe02 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -298,7 +298,7 @@ export const bazaar = {</div>`;}const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];- const loadingHTML = `<div style="height: ${bazaar.element.clientHeight - 160}px;display: flex;align-items: center;justify-content: center;"><img src="/stage/loading-pure.svg"></div>`;+ const loadingHTML = `<div style="height: ${bazaar.element.clientHeight - 160}px;display: flex;align-items: center;justify-content: center;"><span class="b3-loading" aria-hidden="true"></span></div>`;return `<div class="config-bazaar fn__flex-column" style="height: 100%"><div class="config-bazaar__main fn__flex-column fn__flex-1"><div class="config-bazaar__drop fn__none">@@ -749,7 +749,7 @@ ${primaryAction ? '<div class="fn__hr"></div>' : ""}installAllElement?.classList.add("fn__none");if (this._updateState === "loading" || this._updateState === "idle") {counterElement.classList.add("fn__none");- contentElement.innerHTML = `<div style="height: ${bazaar.element.clientHeight - 160}px;display: flex;align-items: center;justify-content: center;"><img src="/stage/loading-pure.svg"></div>`;+ contentElement.innerHTML = `<div style="height: ${bazaar.element.clientHeight - 160}px;display: flex;align-items: center;justify-content: center;"><span class="b3-loading" aria-hidden="true"></span></div>`;renderBazaarInstall(bazaar.element);return;}@@ -1183,7 +1183,7 @@ type="checkbox"></blockquote></div><div class="item__readme b3-typography b3-typography--default">- <img data-type="img-loading" style="height: 64px;width: 100%;padding: 16px 0;" src="/stage/loading-pure.svg">+ <div data-type="img-loading" class="fn__flex" style="height:64px;padding:16px 0;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div></div>${isMobile() ? readmeActionsHTML : ""}`;renderBazaarInstall(bazaar.element);@@ -1939,7 +1939,7 @@ type="checkbox">if (response.code === 1) {// 安装集市包 /api/bazaar/installBazaar* 失败showMessage(response.msg);- element.querySelectorAll("img[data-type='img-loading']").forEach((item) => {+ element.querySelectorAll("[data-type='img-loading']").forEach((item) => {item.remove();});return;diff --git a/app/src/config/tabs/ai/aiCapabilityUi.ts b/app/src/config/tabs/ai/aiCapabilityUi.tsindex d9439dd6a7..217496ca2a 100644--- a/app/src/config/tabs/ai/aiCapabilityUi.ts+++ b/app/src/config/tabs/ai/aiCapabilityUi.ts@@ -196,7 +196,7 @@ const showAgentCapabilityLoading = (root: HTMLElement) => {</div></div><div class="b3-dialog__body fn__flex-1 fn__flex-center">- <img src="/stage/loading-pure.svg" style="height:64px;width:64px;">+ <span class="b3-loading" aria-hidden="true"></span></div>`;view.onchange = null;view.onclick = (event) => {diff --git a/app/src/config/tabs/ai/aiSkillUi.ts b/app/src/config/tabs/ai/aiSkillUi.tsindex b11ff1bc07..cc05046583 100644--- a/app/src/config/tabs/ai/aiSkillUi.ts+++ b/app/src/config/tabs/ai/aiSkillUi.ts@@ -57,7 +57,7 @@ const showUserSkillsLoading = (root: HTMLElement, builtin: boolean) => {</div></div><div class="b3-dialog__body fn__flex-1 fn__flex-center">- <img src="/stage/loading-pure.svg" style="height:64px;width:64px;">+ <span class="b3-loading" aria-hidden="true"></span></div>`;view.onchange = null;view.onclick = (event) => {diff --git a/app/src/config/tabs/syncUi.ts b/app/src/config/tabs/syncUi.tsindex 52b06683bf..82e0481965 100644--- a/app/src/config/tabs/syncUi.ts+++ b/app/src/config/tabs/syncUi.ts@@ -860,5 +860,5 @@ const buildCloudSpaceHtml = (data: CloudSpaceDisplayData, loading: boolean) =></ul></div></div>- ${loading ? '<div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div>' : ""}+ ${loading ? '<div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div>' : ""}</div>`;diff --git a/app/src/config/tabs/workspaceStorage.test.ts b/app/src/config/tabs/workspaceStorage.test.tsindex ca4ae333c6..8da44065d3 100644--- a/app/src/config/tabs/workspaceStorage.test.ts+++ b/app/src/config/tabs/workspaceStorage.test.ts@@ -8,7 +8,7 @@ import {test} from "node:test";import {createSourceFile, isVariableStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";import type {WorkspaceStorageData} from "../../types/api";-const browserCases = async (source: string, sharedSource: string, echartsPath: string, locales: Record<string, Record<string, string>>, loadingImage: string) => {+const browserCases = async (source: string, sharedSource: string, echartsPath: string, locales: Record<string, Record<string, string>>) => {const languages = locales.en;const check = require("node:assert/strict");const shared = {} as typeof import("../render/fragments") & Pick<typeof import("../render/render"), "genButtonHtml" | "genButtonRowHtml" | "genConfigGroup">;@@ -83,9 +83,10 @@ const browserCases = async (source: string, sharedSource: string, echartsPath: sshared.genButtonRowHtml("storageReferenceControl", window.siyuan.languages.reloadUI,window.siyuan.languages.reloadUITip, window.siyuan.languages.reloadUI, "iconRefresh"), window.siyuan.languages.configGroupMaintenance);exports.mountWorkspaceStorage(root);- const image = root.querySelector<HTMLImageElement>("[data-storage-loading] img");- check.equal(image.getAttribute("src"), "/stage/loading-pure.svg");- image.src = loadingImage;+ const spinner = root.querySelector<HTMLElement>("[data-storage-loading] .b3-loading");+ check.equal(spinner.childElementCount, 0);+ check.equal(spinner.getAttribute("aria-hidden"), "true");+ check.match(getComputedStyle(spinner, "::before").backgroundImage, /conic-gradient/);};mount();const tick = () => new Promise(resolve => setTimeout(resolve, 30));@@ -310,9 +311,8 @@ test("workspace storage rendering, refresh, theme, mobile layout and lifecycle",const theme = readFileSync(path.resolve("appearance/themes/daylight/theme.css"), "utf8");const darkTheme = readFileSync(path.resolve("appearance/themes/midnight/theme.css"), "utf8");const icons = readFileSync(path.resolve("appearance/icons/litheness/icon.js"), "utf8");- const loadingImage = "data:image/svg+xml;base64," + readFileSync(path.resolve("stage/loading-pure.svg")).toString("base64");const commonCSS = theme + darkTheme.replace(/:root/g, ':root[data-theme-mode="dark"]') + "\nbody{margin:0;font:16px sans-serif;color:var(--b3-theme-on-background);background:var(--b3-theme-background)}";- const code = `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(sharedSource)}, ${JSON.stringify(path.resolve("stage/protyle/js/echarts/echarts.min.js"))}, ${JSON.stringify(locales)}, ${JSON.stringify(loadingImage)})`;+ const code = `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(sharedSource)}, ${JSON.stringify(path.resolve("stage/protyle/js/echarts/echarts.min.js"))}, ${JSON.stringify(locales)})`;writeFileSync(script, `const {app, BrowserWindow, ipcMain} = require("electron");const fs = require("node:fs");const path = require("node:path");diff --git a/app/src/config/tabs/workspaceStorage.ts b/app/src/config/tabs/workspaceStorage.tsindex 4091340f05..67faf324b3 100644--- a/app/src/config/tabs/workspaceStorage.ts+++ b/app/src/config/tabs/workspaceStorage.ts@@ -24,7 +24,7 @@ export const genWorkspaceStorageHtml = () => `<div class="b3-label config-item w</div><div class="b3-label__text workspace-storage__status" data-storage-status role="status"></div><div class="workspace-storage__placeholder fn__none" data-storage-loading role="status" aria-label="${window.siyuan.languages.loading}">- <div class="fn__loading"><img width="64" src="/stage/loading-pure.svg" alt=""></div>+ <div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div></div><div class="workspace-storage__content fn__none" data-storage-content><div class="workspace-storage__figure">diff --git a/app/src/history/doc.ts b/app/src/history/doc.tsindex 20df4ede65..cad3604b54 100644--- a/app/src/history/doc.ts+++ b/app/src/history/doc.ts@@ -115,7 +115,7 @@ const renderRepo = async (element: HTMLElement, currentPage: number, id: string,pageNumElement.textContent = currentPage.toString();previousElement.setAttribute("disabled", "disabled");nextElement.setAttribute("disabled", "disabled");- listElement.innerHTML = '<li style="position: relative;height: 100%;"><div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div></li>';+ listElement.innerHTML = '<li style="position: relative;height: 100%;"><div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div></li>';let response: APIPOSTRoutes["/api/repo/getRepoDocHistory"]["response"] | APITransportError;try {@@ -224,7 +224,7 @@ export const openDocHistory = (options: {</div><div class="fn__flex fn__flex-1 history__panel"><ul class="b3-list b3-list--background history__side" ${isMobile() ? "" : `style="width: ${window.siyuan.storage[Constants.LOCAL_HISTORY].sideDocWidth}"`}>- <li class="fn__loading"><img style="height: 64px;width: 64px" src="/stage/loading-pure.svg"></li>+ <li class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></li></ul><div class="history__resize"></div><div class="fn__flex-1 fn__flex-column">diff --git a/app/src/history/docDiff.ts b/app/src/history/docDiff.tsindex 3cb98a95d6..214d46e0eb 100644--- a/app/src/history/docDiff.ts+++ b/app/src/history/docDiff.ts@@ -196,7 +196,7 @@ export const showDocVersionDiff = (app: App, firstRef: IDocVersionRef, secondRefpanel.querySelector(".history__compare-label").textContent = index === 0 ? leftRef.label : rightRef.label;panel.querySelector(".protyle-title__input").textContent = "";panel.querySelector(".history__compare-content").innerHTML =- '<div class="fn__loading"><img style="height: 64px;width: 64px" src="/stage/loading-pure.svg"></div>';+ '<div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div>';});};diff --git a/app/src/history/history.ts b/app/src/history/history.tsindex 00b4d3ef23..557ca4e7bf 100644--- a/app/src/history/history.ts+++ b/app/src/history/history.ts@@ -314,7 +314,7 @@ const renderRepo = async (element: Element, currentPage: number) => {const nextElement = element.querySelector('[data-type="next"]');const pageElement = nextElement.nextElementSibling.nextElementSibling;const searchButton = searchInputElement.nextElementSibling as HTMLButtonElement;- listElement.innerHTML = '<li class="history__snapshot-loading"><div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div></li>';+ listElement.innerHTML = '<li class="history__snapshot-loading"><div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div></li>';updateRepoSelection(element);element.setAttribute("data-page", String(currentPage));pageBtn.textContent = String(currentPage);diff --git a/app/src/layout/dock/BacklinkContent.ts b/app/src/layout/dock/BacklinkContent.tsindex a464746ca8..89b1ff4374 100644--- a/app/src/layout/dock/BacklinkContent.ts+++ b/app/src/layout/dock/BacklinkContent.ts@@ -1848,7 +1848,7 @@ export class BacklinkContent extends Model {this.showingLoading = true;this.resetRenderedData(false);this.element.classList.remove("sy__backlink--backlinks-empty", "sy__backlink--mentions-empty");- const loadingHTML = '<div class="backlinkList__loading"><img width="32px" height="32px" src="/stage/loading-pure.svg"></div>';+ const loadingHTML = '<div class="backlinkList__loading"><span class="b3-loading" aria-hidden="true"></span></div>';this.tree.element.innerHTML = loadingHTML;this.mTree.element.innerHTML = loadingHTML;this.element.querySelector(".listCount").textContent = "";diff --git a/app/src/layout/dock/Inbox.ts b/app/src/layout/dock/Inbox.tsindex 81f5a351dd..6cc46a3f4e 100644--- a/app/src/layout/dock/Inbox.ts+++ b/app/src/layout/dock/Inbox.ts@@ -55,7 +55,7 @@ export class Inbox extends Model {<svg data-type="more" class="toolbar__icon fn__none"><use xlink:href='#iconMore'></use></svg></div><div class="fn__loading fn__none">- <img width="64px" src="/stage/loading-pure.svg"></div>+ <span class="b3-loading" aria-hidden="true"></span></div></div><div class="fn__flex-1 fn__none inboxDetails fn__flex-column" style="min-height: auto;background-color: var(--b3-theme-background)"></div><div class="fn__flex-1"></div>`;@@ -77,7 +77,7 @@ export class Inbox extends Model {<span data-type="min" class="block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.min}${updateHotkeyAfterTip(window.siyuan.config.keymap.general.closeTab.custom)}"><svg><use xlink:href="#iconMin"></use></svg></span></div><div class="fn__loading fn__none">- <img width="64px" src="/stage/loading-pure.svg"></div>+ <span class="b3-loading" aria-hidden="true"></span></div></div><div class="fn__flex-1 fn__none inboxDetails fn__flex-column" style="min-height: auto;background-color: var(--b3-theme-background)"></div><div class="fn__flex-1"></div>`;diff --git a/app/src/layout/dock/agent/AgentChat.ts b/app/src/layout/dock/agent/AgentChat.tsindex e925211a6a..eab79533ea 100644--- a/app/src/layout/dock/agent/AgentChat.ts+++ b/app/src/layout/dock/agent/AgentChat.ts@@ -1540,7 +1540,7 @@ export class AgentChat extends Model {const el = document.createElement("div");el.className = "agent-chat__msg agent-chat__msg--mirror";el.innerHTML = '<div class="agent-chat__body agent-chat__body--mirror">' +- '<span class="agent-chat__mirror-spinner"></span>' ++ '<span class="b3-loading b3-loading--small agent-chat__mirror-spinner" aria-hidden="true"></span>' +"<span>" + escapeHtml(message) + "</span>" +"</div>";this.messagesContainer.appendChild(el);diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex 2c1924d1ce..ff9e1201fa 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -174,7 +174,7 @@ const buildAssetMenu = (protyle: IProtyle, position: IPosition, callback?: (url:<span class="fn__space"></span><span data-type="next" class="block__icon block__icon--show"><svg><use xlink:href="#iconRight"></use></svg></span></div>- <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg"></div>+ <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div><div id="preview" style="width: 360px;display: ${isMobile() || window.outerWidth < window.outerWidth / 2 + 260 ? "none" : "flex"};padding: 8px;overflow: auto;justify-content: center;align-items: center;word-break: break-all;"></div></div>`,diff --git a/app/src/mobile/dock/MobileBookmarks.ts b/app/src/mobile/dock/MobileBookmarks.tsindex 0991f97b07..e4a70d2b8a 100644--- a/app/src/mobile/dock/MobileBookmarks.ts+++ b/app/src/mobile/dock/MobileBookmarks.ts@@ -34,7 +34,7 @@ export class MobileBookmarks {<svg data-type="collapse" class="toolbar__icon"><use xlink:href="#iconContract"></use></svg></div><div class="fn__flex-1 bookmarkList"></div>-<img style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;padding: 30vw;box-sizing: border-box;" src="/stage/loading-pure.svg">`;+<div class="fn__loading" style="left:0"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>`;const inputElement = this.element.querySelector("input.b3-text-field.search__label") as HTMLInputElement;bindPanelSearch(inputElement,this.element.querySelector('[data-type="search"]'), () => this.filter(), {diff --git a/app/src/mobile/dock/MobileTags.ts b/app/src/mobile/dock/MobileTags.tsindex 8377a08bbd..f22753be67 100644--- a/app/src/mobile/dock/MobileTags.ts+++ b/app/src/mobile/dock/MobileTags.ts@@ -40,7 +40,7 @@ export class MobileTags {<svg data-type="sort" class="toolbar__icon${window.siyuan.config.readonly ? " fn__none" : ""}"><use xlink:href="#iconSort"></use></svg></div><div class="fn__flex-1 tagList"></div>-<img style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;padding: 30vw;box-sizing: border-box;" src="/stage/loading-pure.svg">`;+<div class="fn__loading" style="left:0"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>`;const inputElement = this.element.querySelector("input.b3-text-field.search__label") as HTMLInputElement;bindPanelSearch(inputElement,this.element.querySelector('[data-type="search"]'), () => this.filter(), {diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.tsindex 7023d39d20..e315768c91 100644--- a/app/src/mobile/menu/search.ts+++ b/app/src/mobile/menu/search.ts@@ -940,7 +940,7 @@ export const popSearch = (app: App, searchConfig?: Config.IUILayoutTabSearchConf<span class="fn__flex-1"></span></div></div>- <div class="fn__loading"><img width="120px" src="/stage/loading-pure.svg"></div>+ <div class="fn__loading"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div></div>`,destroyCallback() {destroyed = true;diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.tsindex c4905720aa..2f216e6c09 100644--- a/app/src/protyle/export/index.ts+++ b/app/src/protyle/export/index.ts@@ -540,7 +540,7 @@ const renderPDF = async (id: string) => {</div><div id="previewContainer"><div style="zoom:${localData.scale || 1}" id="preview">- <div class="fn__loading" style="left:0;height:100vh"><img width="48px" src="${servePath}stage/loading-pure.svg"></div>+ <div class="fn__loading" style="left:0;height:100vh"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div></div></div>${getIconScript(servePath)}@@ -840,7 +840,7 @@ ${getIconScript(servePath)}const refreshPreview = () => {const revision = ++previewRevision;actionElement.querySelector('.b3-button--text').disabled = true;- previewElement.innerHTML = '<div class="fn__loading" style="left:0;height: 100vh"><img width="48px" src="${servePath}stage/loading-pure.svg"></div>'+ previewElement.innerHTML = '<div class="fn__loading" style="left:0;height: 100vh"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>'fetchPost("/api/export/exportPreviewHTML", {id: "${id}",keepJSEmbed: true,diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.tsindex 5ca2d41379..c29932f51a 100644--- a/app/src/protyle/export/util.ts+++ b/app/src/protyle/export/util.ts@@ -80,7 +80,7 @@ export const exportImage = (id: string, copyOnly = false) => {<button data-type="copy" disabled class="b3-button b3-button--text${copyOnly ? " fn__none" : ""}">${window.siyuan.languages.copyAsPNG}</button><div class="fn__space${copyOnly ? " fn__none" : ""}"></div><button data-type="export" disabled class="b3-button b3-button--text${copyOnly ? " fn__none" : ""}">${window.siyuan.languages.exportFile}</button></div>- <div class="fn__loading"><img height="128px" width="128px" src="stage/loading-pure.svg"></div>`,+ <div class="fn__loading"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>`,width: isMobile() ? "92vw" : "990px",height: "70vh",resizeCallback() {@@ -258,7 +258,7 @@ export const exportImage = (id: string, copyOnly = false) => {const revision = ++previewRevision;setActionDisabled(true);if (!exportDialog.element.querySelector(".fn__loading")) {- exportButton.parentElement.insertAdjacentHTML("afterend", '<div class="fn__loading"><img height="128px" width="128px" src="stage/loading-pure.svg"></div>');+ exportButton.parentElement.insertAdjacentHTML("afterend", '<div class="fn__loading"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>');}requestPreview(revision);};diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.tsindex aaa07812a5..58ae04e8ff 100644--- a/app/src/protyle/header/Background.ts+++ b/app/src/protyle/header/Background.ts@@ -301,7 +301,7 @@ export class Background {const dialog = new Dialog({title: window.siyuan.languages.builtIn,content: `<div class="b3-cards" style="padding:16px;justify-content:center;align-items:center;min-height:200px">- <img src="/stage/loading-pure.svg" style="width:64px;height:64px">+ <span class="b3-loading" aria-hidden="true"></span></div>`,width: isMobile() ? "92vw" : "912px",height: isMobile() ? "80vh" : "70vh",@@ -827,7 +827,7 @@ export class Background {<input class="b3-text-field fn__flex-shrink" placeholder="${window.siyuan.languages.tag}"/><div class="fn__hr"></div><div class="b3-list fn__flex-1 b3-list--background">- <img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">+ <div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div>`,bind: (element) => {diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 56bbab1b55..6b14d284ce 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -690,7 +690,7 @@ export class Hint {this.destroyEmojiPanel();const wasHidden = this.element.classList.contains("fn__none");if (this.element.classList.contains("fn__none")) {- this.element.innerHTML = '<div class="fn__loading" style="height: 128px;position: initial"><img width="64px" src="/stage/loading-pure.svg"></div>';+ this.element.innerHTML = '<div class="fn__loading" style="height: 128px;position: initial"><span class="b3-loading" aria-hidden="true"></span></div>';this.element.classList.remove("fn__none");if (this.source === "av") {const cellElement = getAVBindingCell(protyle.toolbar.range);@@ -712,7 +712,7 @@ export class Hint {/// #endif}} else if (!this.element.querySelector(".fn__loading")) {- this.element.insertAdjacentHTML("beforeend", '<div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div>');+ this.element.insertAdjacentHTML("beforeend", '<div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div>');}if (delay > 0) {// 首次打开时延迟显示整个占位面板,更新候选项时只延迟显示加载遮罩@@ -922,7 +922,7 @@ export class Hint {private genSearchHTML(protyle: IProtyle, searchElement: HTMLInputElement, nodeElement: false | HTMLElement, oldValue: string, source: THintSource) {const createTarget = this.prepareCreateTarget(protyle, "ref");- this.element.lastElementChild.innerHTML = '<div class="ft__center"><img style="height:32px;width:32px;" src="/stage/loading-pure.svg"></div>';+ this.element.lastElementChild.innerHTML = '<div class="ft__center"><span class="b3-loading" aria-hidden="true"></span></div>';const searchParam: import("../../types/api").SearchRefBlockRequestInput = {k: searchElement.value,id: nodeElement ? nodeElement.getAttribute("data-node-id") : protyle.block.parentID,diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.tsindex 061724064e..b1325598b8 100644--- a/app/src/protyle/preview/index.ts+++ b/app/src/protyle/preview/index.ts@@ -264,7 +264,7 @@ export class Preview {let loadingElement = this.element.querySelector(".fn__loading");if (!loadingElement) {this.element.insertAdjacentHTML("beforeend", `<div style="flex-direction: column;" class="fn__loading">- <img width="48px" src="/stage/loading-pure.svg">+ <span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>`);loadingElement = this.element.querySelector(".fn__loading");}diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.tsindex 38512e8efa..9d797cd45b 100644--- a/app/src/protyle/render/av/relation.ts+++ b/app/src/protyle/render/av/relation.ts@@ -55,7 +55,7 @@ interface IOpenSearchAVOptions {const RELATION_PAGE_SIZE = 16;const relationItemPreviews = new WeakMap<HTMLElement, {keyword: string, preview: AVRelationItemPreview}>();-const SEARCH_AV_LOADING_HTML = '<img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">';+const SEARCH_AV_LOADING_HTML = '<div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>';const genSearchList = (element: Element, keyword: string, options: IOpenSearchAVOptions, signal: AbortSignal,cb?: () => void) => {@@ -524,7 +524,7 @@ ${!preview || preview.error || creating ? "disabled" : ""} title="${escapeAttr(p};const genRelationLoaderHTML = (loading: boolean, visible = loading) => {- return `<img data-relation-type="loader" class="${loading ? "" : "fn__none"}" style="${visible ? "" : "visibility: hidden;"}margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">`;+ return `<div data-relation-type="loader" class="fn__flex${loading ? "" : " fn__none"}" style="${visible ? "" : "visibility: hidden;"}height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>`;};export const bindRelationEvent = (options: {diff --git a/app/src/protyle/render/av/rollup.ts b/app/src/protyle/render/av/rollup.tsindex 54bfb4152a..74ad871df5 100644--- a/app/src/protyle/render/av/rollup.ts+++ b/app/src/protyle/render/av/rollup.ts@@ -144,7 +144,7 @@ export const goSearchRollupCol = (options: {<input spellcheck="false" class="b3-text-field fn__flex-shrink" placeholder="${window.siyuan.languages[options.isRelation ? "searchRelation" : "searchRollupProperty"]}"/><div class="fn__hr"></div><div class="b3-list fn__flex-1 b3-list--background">- <img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">+ <div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div>`,bind(element) {diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.tsindex 5b8d7d8711..4d798d113e 100644--- a/app/src/protyle/render/listMindmap/index.ts+++ b/app/src/protyle/render/listMindmap/index.ts@@ -1124,7 +1124,7 @@ export const initListMindmaps = (owner: IProtyle) => {host.className = "mindmap-view";host.contentEditable = "false";host.setAttribute("aria-busy", "true");- host.innerHTML = '<div class="fn__loading"><img width="64" src="/stage/loading-pure.svg" alt=""></div>';+ host.innerHTML = '<div class="fn__loading"><span class="b3-loading" aria-hidden="true"></span></div>';syncListMindmapHeight(list, host);placeholders.set(list, host);list.appendChild(host);diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.tsindex e0fbe530c7..d7e80cdc13 100644--- a/app/src/protyle/toolbar/index.ts+++ b/app/src/protyle/toolbar/index.ts@@ -2156,7 +2156,7 @@ export class Toolbar {<span class="fn__space"></span><span data-type="next" class="block__icon block__icon--show"><svg><use xlink:href="#iconRight"></use></svg></span></div>- <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg"></div>+ <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div><div class="toolbarResize" style=" cursor: col-resize;box-shadow: 2px 0 0 0 var(--b3-theme-surface) inset, 3px 0 0 0 var(--b3-border-color) inset;@@ -2318,7 +2318,7 @@ export class Toolbar {window.siyuan.menus.menu.remove();this.subElement.innerHTML = `<div class="fn__flex-column" style="max-height:50vh"><input spellcheck="false" style="margin: 0 8px 4px 8px" class="b3-text-field"/>- <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><img style="margin: 0 auto;display: block;width: 64px;height:64px" src="/stage/loading-pure.svg"></div>+ <div class="b3-list fn__flex-1 b3-list--background" style="position: relative"><div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div>`;const listElement = this.subElement.lastElementChild.lastElementChild as HTMLElement;const inputElement = this.subElement.querySelector("input");diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.tsindex e48a95aeaa..24a21d9af8 100644--- a/app/src/protyle/ui/initUI.ts+++ b/app/src/protyle/ui/initUI.ts@@ -353,7 +353,7 @@ export const addLoading = (protyle: IProtyle, msg?: string) => {setTimeout(() => {if (protyle.element.getAttribute("data-loading") !== "finished") {protyle.element.insertAdjacentHTML("beforeend", `<div style="background-color: var(--b3-theme-background);flex-direction: column;" class="fn__loading wysiwygLoading">- <img width="48px" src="/stage/loading-pure.svg">+ <span class="b3-loading b3-loading--large" aria-hidden="true"></span><div style="color: var(--b3-theme-on-surface);margin-top: 8px;">${sanitizeKernelHTML(msg || "")}</div></div>`);}diff --git a/app/src/search/util.ts b/app/src/search/util.tsindex 176046dbb8..d0e03a8492 100644--- a/app/src/search/util.ts+++ b/app/src/search/util.ts@@ -284,7 +284,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele<kbd>Esc</kbd> ${window.siyuan.languages.searchTip5}</div></div>-<div class="fn__loading"><img width="120px" src="/stage/loading-pure.svg"></div>`;+<div class="fn__loading"><span class="b3-loading b3-loading--large" aria-hidden="true"></span></div>`;const criteriaData: Config.IUILayoutTabSearchConfig[] = [];initCriteriaMenu(element.querySelector("#criteria"), criteriaData, config);diff --git a/app/src/sync/syncGuide.ts b/app/src/sync/syncGuide.tsindex 14a12ed8f8..a419c9e0cc 100644--- a/app/src/sync/syncGuide.ts+++ b/app/src/sync/syncGuide.ts@@ -34,7 +34,7 @@ export const addCloudName = (cloudListElement: Element) => {value: "main",description: window.siyuan.languages.reposTip,onConfirm: (value, dialog) => {- cloudListElement.innerHTML = '<img style="margin: 0 auto;display: block;width: 64px;height: 100%" src="/stage/loading-pure.svg">';+ cloudListElement.innerHTML = '<div class="fn__flex" style="height:100%;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>';fetchPost("/api/sync/createCloudSyncDir", {name: value}, () => {dialog.destroy();renderSyncCloudList(cloudListElement, true);@@ -59,7 +59,7 @@ export const bindSyncCloudListEvent = (cloudListElement: Element, cb?: (ready: bbreak;case "removeCloud":confirmDialog(window.siyuan.languages.deleteOpConfirm, `${window.siyuan.languages.confirmDeleteCloudDir} <i>${target.parentElement.getAttribute("data-name")}</i>`, () => {- cloudListElement.innerHTML = '<img style="margin: 0 auto;display: block;width: 64px;height: 100%" src="/stage/loading-pure.svg">';+ cloudListElement.innerHTML = '<div class="fn__flex" style="height:100%;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>';fetchPost("/api/sync/removeCloudSyncDir", {name: target.parentElement.getAttribute("data-name")}, (response) => {window.siyuan.config.sync.cloudName = response.data;renderSyncCloudList(cloudListElement, true, cb);@@ -67,7 +67,7 @@ export const bindSyncCloudListEvent = (cloudListElement: Element, cb?: (ready: b}, undefined, true);break;case "selectCloud":- cloudListElement.innerHTML = '<img style="margin: 0 auto;display: block;width: 64px;height: 100%" src="/stage/loading-pure.svg">';+ cloudListElement.innerHTML = '<div class="fn__flex" style="height:100%;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>';configApi.set("sync.cloudName", target.getAttribute("data-name"), () => {window.siyuan.config.sync.cloudName = target.getAttribute("data-name");renderSyncCloudList(cloudListElement, true, cb);@@ -104,7 +104,7 @@ export const renderSyncCloudList = (cloudListElement: Element, reload = false, c}const canManage = provider === 0 || provider === 4;cb?.(false);- cloudListElement.innerHTML = '<img style="margin: 0 auto;display: block;width: 64px;height: 100%" src="/stage/loading-pure.svg">';+ cloudListElement.innerHTML = '<div class="fn__flex" style="height:100%;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div>';fetchPost("/api/sync/listCloudSyncDir", {}, (response) => {if (provider !== window.siyuan.config.sync.provider) {return;@@ -280,7 +280,7 @@ const setSync = (key?: string, dialog?: Dialog) => {const listHTML = `<div class="b3-dialog__content"><div class="ft__on-surface">${window.siyuan.languages.syncConfGuide3}</div><div style="display: flex;flex-direction: column;height: 40vh;">- <img style="margin: 0 auto;display: block;width: 64px;height: 100%" src="/stage/loading-pure.svg">+ <div class="fn__flex" style="height:100%;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div></div><div class="b3-dialog__action">diff --git a/app/src/util/noRelyPCFunction.ts b/app/src/util/noRelyPCFunction.tsindex 634c13462c..7f63447783 100644--- a/app/src/util/noRelyPCFunction.ts+++ b/app/src/util/noRelyPCFunction.ts@@ -40,7 +40,7 @@ export const renameTag = (labelName: string) => {value: labelName,bindInput: false,extraContent: `<div class="b3-list fn__flex-1 b3-list--background fn__none protyle-hint" style="position: absolute;width: calc(100% - 48px);">- <img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">+ <div class="fn__flex" style="height:64px;align-items:center;justify-content:center"><span class="b3-loading" aria-hidden="true"></span></div></div>`,onConfirm: (value, dialog) => {fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: value}, () => {diff --git a/app/stage/service-worker.js b/app/stage/service-worker.jsindex 07b748067a..15d6142169 100644--- a/app/stage/service-worker.js+++ b/app/stage/service-worker.js@@ -5,7 +5,6 @@ const INITIAL_CACHED_RESOURCES = ["/favicon.ico","/stage/icon-large.png","/stage/icon.png",- "/stage/loading-pure.svg","/appearance/fonts/JetBrainsMono-2.304/JetBrainsMono-Regular.woff2","/stage/protyle/js/lute/lute.min.js","/stage/protyle/js/protyle-html.js"diff --git a/app/tests/detachedWindowLoading.test.js b/app/tests/detachedWindowLoading.test.jsindex 8c6aff7df3..6dc39e8efd 100644--- a/app/tests/detachedWindowLoading.test.js+++ b/app/tests/detachedWindowLoading.test.js@@ -101,12 +101,15 @@ const runRendererCase = async (sources, expected) => {assert.equal(getComputedStyle(loader).getPropertyValue("-webkit-app-region"), "drag");const rect = loader.getBoundingClientRect();assert.deepEqual([rect.x, rect.y, rect.width, rect.height], [0, 0, innerWidth, innerHeight]);- const image = loader.querySelector("img");- if (!image.complete) await new Promise(resolve => image.addEventListener("load", resolve, {once: true}));- assert.ok(image.naturalWidth > 0, "shared spinner loads");- const imgRect = image.getBoundingClientRect();- assert.ok(Math.abs(imgRect.x + imgRect.width / 2 - innerWidth / 2) < 1);- assert.ok(Math.abs(imgRect.y + imgRect.height / 2 - innerHeight / 2) < 1);+ const spinner = loader.querySelector(".b3-loading");+ assert.equal(spinner.childElementCount, 0, "shared spinner needs no icon library or image");+ assert.equal(getComputedStyle(spinner).color, "rgb(171, 205, 239)", "startup foreground is available before the theme");+ assert.match(getComputedStyle(spinner, "::before").backgroundImage, /conic-gradient/);+ const spinnerRect = spinner.getBoundingClientRect();+ assert.equal(spinnerRect.width, 48);+ assert.equal(spinnerRect.height, 48);+ assert.ok(Math.abs(spinnerRect.x + spinnerRect.width / 2 - innerWidth / 2) < 1);+ assert.ok(Math.abs(spinnerRect.y + spinnerRect.height / 2 - innerHeight / 2) < 1);assert.equal(appearance.getWindowAppearance().backgroundColor, expected.hex);let done = false;let renderDone = false;@@ -197,11 +200,6 @@ if (process.versions.electron && process.type === "browser") {response.end(css);return;}- if (pathname === "/stage/loading-pure.svg") {- response.setHeader("Content-Type", "image/svg+xml");- response.end(fs.readFileSync(path.join(__dirname, "../stage/loading-pure.svg")));- return;- }if (pathname === "/stage/build/app/window.html") {response.setHeader("Content-Type", "text/html");response.end(template);diff --git a/app/tests/loadingIndicator.test.js b/app/tests/loadingIndicator.test.jsnew file mode 100644index 0000000000..aea2735c25--- /dev/null+++ b/app/tests/loadingIndicator.test.js@@ -0,0 +1,219 @@+const assert = require("node:assert/strict");+const fs = require("node:fs");+const os = require("node:os");+const path = require("node:path");+const ts = require("typescript");++const read = name => fs.readFileSync(path.join(__dirname, "..", name), "utf8");+const compile = source => ts.transpileModule(source, {+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},+}).outputText;+const declarations = (file, names) => {+ const source = ts.createSourceFile(file, read(file), ts.ScriptTarget.Latest, true);+ return source.statements.filter(statement => ts.isVariableStatement(statement) &&+ statement.declarationList.declarations.some(item => names.includes(item.name.getText(source))))+ .map(statement => statement.getText(source)).join("\n");+};++const browserCases = async (sources, entries, themes) => {+ const check = require("node:assert/strict");+ const {ipcRenderer} = require("electron");+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));+ const styles = document.createElement("style");+ const custom = document.createElement("style");+ document.head.append(styles, custom);+ document.body.style.background = "var(--b3-theme-background, #fff)";+ const host = document.createElement("div");+ host.style.cssText = "position:relative;width:300px;height:200px;margin:16px;display:flex;align-items:center;justify-content:space-evenly";+ document.body.append(host);+ const spinnerHTML = '<span class="b3-loading" aria-hidden="true"></span>';+ for (const [entry, css] of Object.entries(entries)) {+ for (const theme of ["light", "dark", "startup"]) {+ styles.textContent = css + (themes[theme] || "");+ host.innerHTML = '<span class="b3-loading b3-loading--small" aria-hidden="true"></span>' + spinnerHTML ++ '<span class="b3-loading b3-loading--large" aria-hidden="true"></span>';+ const spinners = Array.from(host.children);+ const spinner = spinners[1];+ check.deepEqual(spinners.map(element => element.getBoundingClientRect().width), [16, 32, 48]);+ check.deepEqual(spinners.map(element => element.getBoundingClientRect().height), [16, 32, 48]);+ check.equal(spinner.childElementCount, 0);+ const foreground = document.createElement("div");+ foreground.style.color = "var(--b3-theme-on-surface, #808080)";+ host.append(foreground);+ check.equal(getComputedStyle(spinner).color, getComputedStyle(foreground).color);+ foreground.remove();+ check.match(getComputedStyle(spinner, "::before").backgroundImage, /conic-gradient/);+ check.notEqual(getComputedStyle(spinner, "::before").maskImage, "none");+ const first = getComputedStyle(spinner, "::before").transform;+ await wait(100);+ check.notEqual(getComputedStyle(spinner, "::before").transform, first, `${entry}/${theme}: animates`);+ await ipcRenderer.invoke("capture-loading", `${entry}-${theme}`);+ custom.textContent = ".b3-loading{--b3-loading-size:24px;--b3-loading-color:#345678;--b3-loading-width:3px;--b3-loading-duration:2s}";+ check.deepEqual(spinners.map(element => element.getBoundingClientRect().width), [24, 24, 24]);+ check.equal(getComputedStyle(spinner).color, "rgb(52, 86, 120)");+ check.equal(getComputedStyle(spinner, "::before").animationDuration, "2s");+ check.match(getComputedStyle(spinner, "::before").maskImage, /3\.3px/);+ custom.textContent += ".b3-loading::before{border:0;border-radius:0;background:currentColor;mask:none;-webkit-mask:none;animation:none}" ++ '.b3-loading::after{content:"";position:absolute;width:4px;height:4px;background:currentColor}';+ check.equal(getComputedStyle(spinner, "::before").animationName, "none");+ check.equal(getComputedStyle(spinner, "::before").maskImage, "none");+ check.equal(getComputedStyle(spinner, "::before").backgroundColor, "rgb(52, 86, 120)");+ check.equal(getComputedStyle(spinner, "::after").content, '""');+ check.equal(spinner.childElementCount, 0, "themes can replace the graphic without changing markup");+ custom.textContent = "";+ host.classList.add("fn__none");+ check.equal(spinner.getClientRects().length, 0);+ host.classList.remove("fn__none");+ }+ }+ await ipcRenderer.invoke("loading-media", [{name: "prefers-reduced-motion", value: "reduce"}]);+ check.equal(matchMedia("(prefers-reduced-motion: reduce)").matches, true);+ check.equal(getComputedStyle(host.querySelector(".b3-loading"), "::before").animationName, "none");+ await ipcRenderer.invoke("loading-media", [{name: "forced-colors", value: "active"}]);+ const forced = getComputedStyle(host.querySelector(".b3-loading"), "::before");+ check.equal(forced.maskImage, "none");+ check.equal(forced.backgroundImage, "none");+ check.equal(forced.borderTopWidth, "2px");+ await ipcRenderer.invoke("loading-media", []);++ styles.textContent = entries.base + themes.light;+ host.replaceChildren();+ const editor = {};+ new Function("exports", "Constants", "sanitizeKernelHTML", sources.editor)(editor,+ {TIMEOUT_LOAD: 20}, text => text);+ const protyle = {element: host};+ editor.addLoading(protyle, "Loading");+ editor.removeLoading(protyle);+ await wait(40);+ check.equal(host.querySelector(".b3-loading"), null, "fast operations do not flash a loader");+ editor.addLoading(protyle, "Loading");+ await wait(40);+ check.ok(host.querySelector(".wysiwygLoading .b3-loading"));+ check.equal(host.textContent.trim(), "Loading");+ editor.removeLoading(protyle);+ check.equal(host.querySelector(".b3-loading"), null);+ check.equal(host.dataset.loading, "finished");++ styles.textContent = entries.mobile + themes.light;+ window.siyuan = {languages: {}, config: {readonly: false, tag: {sort: 0}}};+ for (const name of ["MobileBookmarks", "MobileTags"]) {+ const requests = [];+ const exports = {};+ const modules = {+ "../../layout/dock/panelSearch": {bindPanelSearch() {}},+ "../../util/fetch": {fetchPost: (_url, _data, callback) => requests.push(callback)},+ "../../constants": {Constants: {SIYUAN_APPID: "loading-test"}},+ "../../layout/dock/tagFilter": {getTagFilterKeywords: () => []},+ "../../util/Tree": {Tree: class {+ updateData() {}+ getExpandIds() { return []; }+ collapseAll() {}+ setExpandIds() {}+ }},+ };+ new Function("require", "exports", sources[name])(module => modules[module] || {}, exports);+ const panel = new exports[name]({}, host);+ const loading = host.lastElementChild;+ check.ok(loading.matches(".fn__loading"));+ check.ok(loading.querySelector(".b3-loading"));+ const bounds = loading.getBoundingClientRect();+ const indicator = loading.querySelector(".b3-loading").getBoundingClientRect();+ check.ok(Math.abs(indicator.x + indicator.width / 2 - bounds.x - bounds.width / 2) < 1);+ check.ok(Math.abs(indicator.y + indicator.height / 2 - bounds.y - bounds.height / 2) < 1);+ panel.update();+ requests.shift()({data: []});+ check.equal(getComputedStyle(loading).display, "flex", "queued refresh keeps the indicator visible");+ requests.shift()({data: []});+ check.equal(getComputedStyle(loading).display, "none", "mobile completion hides the outer container");+ panel.update();+ check.equal(getComputedStyle(loading).display, "flex");+ requests.shift()({data: []});+ check.equal(getComputedStyle(loading).display, "none");+ }++ host.innerHTML = '<div id="packages">' + sources.bazaarLoader + "<img data-content-image>" + spinnerHTML + "</div>";+ const messages = [];+ const bazaar = new Function("element", "BAZAAR_PACKAGE_CONFIG", "showMessage", sources.bazaar)(host,+ {plugins: {panelID: "packages"}}, message => messages.push(message));+ bazaar._onBazaar({code: 1, msg: "Failed"}, "plugins", {});+ check.equal(host.querySelector('[data-type="img-loading"]'), null, "marketplace errors remove the CSS loader container");+ check.ok(host.querySelector("[data-content-image]"));+ check.ok(host.querySelector(".b3-loading"), "unrelated indicators remain intact");+ check.deepEqual(messages, ["Failed"]);+};++if (process.versions.electron && process.type === "browser") {+ const {app, BrowserWindow, ipcMain} = require("electron");+ app.setPath("userData", process.argv[2]);+ app.disableHardwareAcceleration();+ app.whenReady().then(async () => {+ const win = new BrowserWindow({show: false, width: 380, height: 280,+ webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true, backgroundThrottling: false}});+ const watchdog = setTimeout(() => app.exit(1), 50000);+ try {+ const entries = Object.fromEntries(["base", "mobile", "export"].map(name => [name,+ require("sass").compile(path.join(__dirname, `../src/assets/scss/${name}.scss`),+ {logger: require("sass").Logger.silent}).css]));+ const themes = {light: read("appearance/themes/daylight/theme.css"), dark: read("appearance/themes/midnight/theme.css")};+ const bazaarText = read("src/config/bazaar.ts");+ const bazaarAST = ts.createSourceFile("bazaar.ts", bazaarText, ts.ScriptTarget.Latest, true);+ const bazaarObject = bazaarAST.statements.find(statement => ts.isVariableStatement(statement) &&+ statement.declarationList.declarations.some(item => item.name.getText(bazaarAST) === "bazaar"))+ .declarationList.declarations[0].initializer;+ const method = bazaarObject.properties.find(property => property.name?.getText(bazaarAST) === "_onBazaar");+ const sources = {+ editor: compile(declarations("src/protyle/ui/initUI.ts", ["addLoading", "removeLoading"])),+ MobileBookmarks: compile(read("src/mobile/dock/MobileBookmarks.ts")),+ MobileTags: compile(read("src/mobile/dock/MobileTags.ts")),+ bazaar: compile(`const bazaar = {element, _isBazaarRequestCurrent: () => true, ${method.getText(bazaarAST)}};`) + "return bazaar;",+ bazaarLoader: bazaarText.match(/<div data-type="img-loading"[^>]*>[\s\S]*?<\/div>/)[0],+ };+ win.webContents.debugger.attach("1.3");+ ipcMain.handle("loading-media", (_event, features) => win.webContents.debugger.sendCommand("Emulation.setEmulatedMedia", {features}));+ ipcMain.handle("capture-loading", async (_event, name) => {+ if (!process.env.SIYUAN_LOADING_SCREENSHOTS) return;+ // 隐藏窗口切换整张样式表后,等待离屏绘制完成再保存截图。+ await win.webContents.executeJavaScript("new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)))");+ await new Promise(resolve => setTimeout(resolve, 200));+ fs.mkdirSync(process.env.SIYUAN_LOADING_SCREENSHOTS, {recursive: true});+ fs.writeFileSync(path.join(process.env.SIYUAN_LOADING_SCREENSHOTS, `${name}.png`), (await win.webContents.capturePage()).toPNG());+ });+ await win.loadURL("about:blank");+ await win.webContents.executeJavaScript(`(${browserCases.toString()})(${JSON.stringify(sources)}, ${JSON.stringify(entries)}, ${JSON.stringify(themes)})`);+ console.log("Verified loading themes, customization, accessibility, editor timing, mobile refresh and marketplace failure");+ win.destroy();+ clearTimeout(watchdog);+ app.exit(0);+ } catch (error) {+ console.error(error);+ win.destroy();+ app.exit(1);+ }+ });+} else {+ const {test} = require("node:test");+ const {execFile} = require("node:child_process");+ const {promisify} = require("node:util");+ test("loading indicators share CSS on desktop, mobile and export and preserve lifecycle behavior", {timeout: 60000}, async () => {+ const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-loading-indicator-"));+ const env = {...process.env};+ delete env.ELECTRON_RUN_AS_NODE;+ try {+ const result = await promisify(execFile)(require("electron"), [__filename, temporary],+ {env, windowsHide: true, timeout: 55000});+ assert.match(result.stdout, /Verified loading themes/);+ } finally {+ assert.equal(path.dirname(path.resolve(temporary)), path.resolve(os.tmpdir()));+ fs.rmSync(temporary, {recursive: true, force: true, maxRetries: 5, retryDelay: 100});+ }+ });++ test("built-in loading indicators no longer request external spinner images", () => {+ const walk = directory => fs.readdirSync(directory, {withFileTypes: true}).flatMap(entry =>+ entry.isDirectory() ? walk(path.join(directory, entry.name)) : [path.join(directory, entry.name)]);+ for (const file of walk(path.join(__dirname, "../src"))) {+ if (!/\.(ts|tpl)$/.test(file) || file.endsWith(".test.ts")) continue;+ assert.doesNotMatch(fs.readFileSync(file, "utf8"), /loading(?:-pure)?\.svg/, file);+ }+ });+}diff --git a/app/tests/serviceWorker.test.js b/app/tests/serviceWorker.test.jsindex 8c8bae0b2c..bddb5352c3 100644--- a/app/tests/serviceWorker.test.js+++ b/app/tests/serviceWorker.test.js@@ -46,7 +46,8 @@ test("precache waits for every resource and preserves successes when one requestassert.equal(completed, false);finishPending();await installation;- assert.equal(cached.length, 6);+ assert.equal(cached.length, 5);+ assert.ok(!cached.some(resource => resource.endsWith("loading-pure.svg")), "CSS loading indicators need no image precache");assert.equal(warnings.length, 1);assert.equal(warnings[0][1], "/favicon.ico");const font = cached.find(resource => resource.endsWith(".woff2"));