Update Settings Shell.

This commit is contained in:
Bruce
2025-11-29 23:02:15 +08:00
parent cf50b09bf0
commit 5796fb40e1
41 changed files with 515 additions and 383 deletions
+3
View File
@@ -39,6 +39,9 @@
byid: function(resid) { return ext.System.Resources.GetById(resid); },
nameToId: function(resname) { return ext.System.Resources.ToId(resname); },
idToName: function(resid) { return ext.System.Resources.ToName(resid); },
fromOthers: function(filepath, resid) { return ext.System.Resources.GetFromOthers(filepath, resid); },
fromFile: function(filepath, resid) { return ext.System.Resources.GetFromOthers(filepath, resid); },
fromfile: function(filepath, resid) { return ext.System.Resources.GetFromOthers(filepath, resid); },
},
Package: {
filepaths: function() {
+60
View File
@@ -482,5 +482,65 @@
var json = JSON.parse(window.external.IEFrame.ParseHtmlColor(str));
return new Color(json.r, json.g, json.b, json.a);
}
Color.getSuitableForegroundTextColor = function(backgroundColor, foregroundColorArray) {
// 将 0255 转为 W3C 的 01,并做 gamma 校正
function gammaCorrect(c) {
c /= 255;
if (c <= 0.03928) return c / 12.92;
return Math.pow((c + 0.055) / 1.055, 2.4);
}
// 计算相对亮度 L01
function relativeLuminance(color) {
var R = gammaCorrect(color.red);
var G = gammaCorrect(color.green);
var B = gammaCorrect(color.blue);
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
}
// 计算对比度 (L1+0.05)/(L2+0.05)
function contrastRatio(l1, l2) {
var light = Math.max(l1, l2);
var dark = Math.min(l1, l2);
return (light + 0.05) / (dark + 0.05);
}
// 混合背景透明度:背景 alpha 与白色混合
function blendWithWhite(color) {
const a = (color.alpha !== undefined ? color.alpha : 255) / 255;
return {
red: color.red * a + 255 * (1 - a),
green: color.green * a + 255 * (1 - a),
blue: color.blue * a + 255 * (1 - a),
alpha: 255
};
}
// 透明背景视为与白色叠加
const bg = blendWithWhite(backgroundColor);
const bgL = relativeLuminance(bg);
// 找出和背景对比度最高的前景色
let bestColor = null;
let bestContrast = -1;
for (var i = 0; i < foregroundColorArray.length; i++) {
var fg = foregroundColorArray[i];
var fgBlended = blendWithWhite(fg); // 若前景也有透明度
var fgL = relativeLuminance(fgBlended);
var cr = contrastRatio(bgL, fgL);
if (cr > bestContrast) {
bestContrast = cr;
bestColor = fg;
}
}
return bestColor;
}
Color.Const = {
white: new Color(255, 255, 255),
black: new Color(0, 0, 0),
red: new Color(255, 0, 0),
green: new Color(0, 255, 0),
blue: new Color(0, 0, 255),
yellow: new Color(255, 255, 0),
cyan: new Color(0, 255, 255),
magenta: new Color(255, 0, 255),
transparent: new Color(0, 0, 0, 0),
};
module.exports = { Color: Color };
})(this);
+12
View File
@@ -1,5 +1,17 @@
(function(global) {
"use strict";
var storage = Bridge.External.Storage;
var path = storage.path;
var root = path.getDir(path.program);
var respath = path.combine(root, "reslib.dll");
var res = Bridge.Resources;
global.respath = respath;
global.getPublicRes = function(resId) {
return res.fromfile(respath, resId);
}
global.publicRes = function(resId) {
return getFileResPair(respath, resId);
}
function ready(e) {
function nextstep() {
+18 -1
View File
@@ -12,17 +12,27 @@
}
var byName = el.getAttribute('data-res-byname');
var byId = el.getAttribute('data-res-byid');
if ((byName && !Bridge.NString.empty(byName)) || (byId && parseInt(byId, 10) > 0)) {
var fromFile = el.getAttribute('data-res-fromfile');
if ((byName && !Bridge.NString.empty(byName)) || (byId && parseInt(byId, 10) > 0) || (fromFile && !Bridge.NString.empty(fromFile))) {
result.push(el);
}
}
return result; // 返回符合条件的元素数组
}
module.exports = {
getFileResPair: function(filepath, resid) {
return {
filepath: filepath,
resid: resid
};
}
};
module.exports = {
Resources: {
processAll: function() {
var nodes = getAllNodesHasResource();
var resources = Bridge.Resources;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].hasAttribute('data-res-byname')) {
var resName = nodes[i].getAttribute('data-res-byname');
@@ -30,6 +40,13 @@
} else if (nodes[i].hasAttribute('data-res-byid')) {
var resId = parseInt(nodes[i].getAttribute('data-res-byid'), 10);
nodes[i].textContent = Bridge.Resources.byid(resId);
} else if (nodes[i].hasAttribute('data-res-fromfile')) {
try {
var obj = eval(nodes[i].getAttribute('data-res-fromfile'));
nodes[i].textContent = resources.fromfile(obj.filepath, obj.resid);
} catch (e) {
nodes[i].textContent = "";
}
} else {
nodes[i].textContent = "";
}