diff --git a/registry/dist/plugins/style/accent-color.js b/registry/dist/plugins/style/accent-color.js new file mode 100644 index 0000000000..3332144a95 --- /dev/null +++ b/registry/dist/plugins/style/accent-color.js @@ -0,0 +1 @@ +!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["style/accent-color"]=o():e["style/accent-color"]=o()}(globalThis,(()=>(()=>{"use strict";var e={d:(o,t)=>{for(var a in t)e.o(t,a)&&!e.o(o,a)&&Object.defineProperty(o,a,{enumerable:!0,get:t[a]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)},o={};e.d(o,{plugin:()=>t});const a=()=>{if(!CSS.supports("color","AccentColor"))return null;const e=document.createElement("div");e.style.cssText="position:fixed;pointer-events:none;opacity:0;color:AccentColor";document.body.appendChild(e);const o=getComputedStyle(e).color;document.body.removeChild(e);const t=o.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(!t)return null;const a=parseInt(t[1]).toString(16).padStart(2,"0"),n=parseInt(t[2]).toString(16).padStart(2,"0"),i=parseInt(t[3]).toString(16).padStart(2,"0");return`#${a}${n}${i}`};const t={name:"style.accentColor",displayName:"使用系统强调色作为主题颜色",description:"将主题颜色设置为操作系统的强调色(Accent Color)",setup:async e=>{const o=a();o&&(e.coreApis.settings.getGeneralSettings().themeColor=o)},commitHash:"9e0c2b5a843d267eb2e7b0b0fe0eafc254774ab1",coreVersion:"2.10.7"};return o=o.plugin})())); diff --git a/registry/lib/plugins/style/accent-color/index.ts b/registry/lib/plugins/style/accent-color/index.ts new file mode 100644 index 0000000000..32e0ddac77 --- /dev/null +++ b/registry/lib/plugins/style/accent-color/index.ts @@ -0,0 +1,33 @@ +import { PluginMetadata } from '@/plugins/plugin' + +const getAccentColor = (): string | null => { + if (!CSS.supports('color', 'AccentColor')) { + return null + } + const el = document.createElement('div') + el.style.cssText = 'position:fixed;pointer-events:none;opacity:0;color:AccentColor' + document.body.appendChild(el) + const { color } = getComputedStyle(el) + document.body.removeChild(el) + // Match both rgb() and rgba() formats returned by browsers + const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/) + if (!match) { + return null + } + const r = parseInt(match[1]).toString(16).padStart(2, '0') + const g = parseInt(match[2]).toString(16).padStart(2, '0') + const b = parseInt(match[3]).toString(16).padStart(2, '0') + return `#${r}${g}${b}` +} + +export const plugin: PluginMetadata = { + name: 'style.accentColor', + displayName: '使用系统强调色作为主题颜色', + description: '将主题颜色设置为操作系统的强调色(Accent Color)', + setup: async ({ coreApis: { settings } }) => { + const accentColor = getAccentColor() + if (accentColor) { + settings.getGeneralSettings().themeColor = accentColor + } + }, +}