Skip to content

Commit

Permalink
release v1.1.8 | bugfix: fix the issue that defaultDarkTextColor an…
Browse files Browse the repository at this point in the history
…d `defaultDarkBgColor` were not work
  • Loading branch information
JaminQ committed Dec 9, 2024
1 parent 978195d commit 55dce41
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
26 changes: 19 additions & 7 deletions dist/darkmode.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/darkmode.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mp-darkmode",
"version": "1.1.7",
"version": "1.1.8",
"description": "微信公众平台图文 Dark Mode 转换算法",
"main": "dist/darkmode.min.js",
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/darkmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export function init(opt = {}) {
config.set('string', opt, 'defaultDarkTextColor');
config.set('string', opt, 'defaultDarkBgColor');

sdk.init();

if (!config.mode && mql === null && window.matchMedia) {
// 匹配媒体查询
mql = window.matchMedia(MEDIA_QUERY);
Expand Down
24 changes: 17 additions & 7 deletions src/modules/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ const getContrast = (rgb1, rgb2) => {

export default class SDK {
_idx = 0; // 索引值
_defaultDarkTextColorRgb = ColorParser(config.defaultDarkTextColor).rgb().array();
_defaultDarkBgColorRgb = ColorParser(config.defaultDarkBgColor).rgb().array();
_defaultDarkBgColorHSL = ColorParser(config.defaultDarkBgColor).hsl().array();
_defaultDarkTextColorBrightness = getColorPerceivedBrightness(this._defaultDarkTextColorRgb);
_defaultDarkBgColorBrightness = getColorPerceivedBrightness(this._defaultDarkBgColorRgb);
_defaultDarkBgColorHslBrightness = this._defaultDarkBgColorHSL[2];
_maxLimitOffsetBrightness = this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness;
_defaultDarkTextColorRgb = null;
_defaultDarkBgColorRgb = null;
_defaultDarkBgColorHSL = null;
_defaultDarkTextColorBrightness = null;
_defaultDarkBgColorBrightness = null;
_defaultDarkBgColorHslBrightness = null;
_maxLimitOffsetBrightness = null;

isDarkmode = false; // 当前是否需要运行Darkmode处理

Expand Down Expand Up @@ -311,6 +311,16 @@ export default class SDK {
}
}

init() {
this._defaultDarkTextColorRgb = ColorParser(config.defaultDarkTextColor).rgb().array();
this._defaultDarkBgColorRgb = ColorParser(config.defaultDarkBgColor).rgb().array();
this._defaultDarkBgColorHSL = ColorParser(config.defaultDarkBgColor).hsl().array();
this._defaultDarkTextColorBrightness = getColorPerceivedBrightness(this._defaultDarkTextColorRgb);
this._defaultDarkBgColorBrightness = getColorPerceivedBrightness(this._defaultDarkBgColorRgb);
this._defaultDarkBgColorHslBrightness = this._defaultDarkBgColorHSL[2];
this._maxLimitOffsetBrightness = this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness;
}

convert(el, cssKVList, isUpdate) {
plugins.resetCss();
plugins.emit(`beforeConvertNode${isUpdate ? 'ByUpdateStyle' : ''}`, el);
Expand Down
2 changes: 1 addition & 1 deletion test/darkmode_online.js

Large diffs are not rendered by default.

0 comments on commit 55dce41

Please sign in to comment.