mp-darkmode 1.1.4 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/README_CN.md +5 -1
- package/dist/darkmode.js +160 -99
- package/dist/darkmode.js.map +1 -1
- package/dist/darkmode.min.js +1 -1
- package/doc/cn/API.md +42 -10
- package/doc/en/API.md +37 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,12 +48,16 @@ Darkmode.run(document.body.querySelectorAll('*')); // process all DOM nodes unde
|
|
|
48
48
|
- `options.error` <Function> Callback triggered when an error occurs.
|
|
49
49
|
- `err` <Error> Error object.
|
|
50
50
|
- `options.mode` <string> The specified color mode (dark | light), if specified, the system color will not be monitored.
|
|
51
|
+
- ...
|
|
52
|
+
- ...
|
|
53
|
+
- ...
|
|
51
54
|
|
|
52
55
|
Run Dark Mode conversion algorithm.
|
|
53
56
|
|
|
54
57
|
```javascript
|
|
55
58
|
Darkmode.run(document.body.querySelectorAll('*'), {
|
|
56
|
-
mode: 'dark' // force dark mode
|
|
59
|
+
mode: 'dark', // force dark mode
|
|
60
|
+
... // other configuration items
|
|
57
61
|
});
|
|
58
62
|
```
|
|
59
63
|
|
package/README_CN.md
CHANGED
|
@@ -48,12 +48,16 @@ Darkmode.run(document.body.querySelectorAll('*')); // 处理body下的所有DOM
|
|
|
48
48
|
- `options.error` <Function> 发生 error 时触发的回调。
|
|
49
49
|
- `err` <Error> 错误对象。
|
|
50
50
|
- `options.mode` <string> 强制指定的颜色模式( dark | light ),指定了就不监听系统颜色。
|
|
51
|
+
- ...
|
|
52
|
+
- ...
|
|
53
|
+
- ...
|
|
51
54
|
|
|
52
55
|
运行 Dark Mode 转换算法。
|
|
53
56
|
|
|
54
57
|
```javascript
|
|
55
58
|
Darkmode.run(document.body.querySelectorAll('*'), {
|
|
56
|
-
mode: 'dark' // 强制指定深色模式
|
|
59
|
+
mode: 'dark', // 强制指定深色模式
|
|
60
|
+
... // 其它配置项
|
|
57
61
|
});
|
|
58
62
|
```
|
|
59
63
|
|
package/dist/darkmode.js
CHANGED
|
@@ -2312,7 +2312,7 @@ swizzle.wrap = function (fn) {
|
|
|
2312
2312
|
/*!*************************!*\
|
|
2313
2313
|
!*** ./src/darkmode.js ***!
|
|
2314
2314
|
\*************************/
|
|
2315
|
-
/*! exports provided: run, init, convertBg,
|
|
2315
|
+
/*! exports provided: run, init, convertBg, updateStyle, getContrast, extend */
|
|
2316
2316
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2317
2317
|
|
|
2318
2318
|
"use strict";
|
|
@@ -2320,9 +2320,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2320
2320
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "run", function() { return run; });
|
|
2321
2321
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "init", function() { return init; });
|
|
2322
2322
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "convertBg", function() { return convertBg; });
|
|
2323
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "extend", function() { return extend; });
|
|
2324
2323
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateStyle", function() { return updateStyle; });
|
|
2325
2324
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getContrast", function() { return getContrast; });
|
|
2325
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "extend", function() { return extend; });
|
|
2326
2326
|
/* harmony import */ var _modules_constant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/constant */ "./src/modules/constant.js");
|
|
2327
2327
|
/* harmony import */ var _modules_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/config */ "./src/modules/config.js");
|
|
2328
2328
|
/* harmony import */ var _modules_global__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/global */ "./src/modules/global.js");
|
|
@@ -2340,6 +2340,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2340
2340
|
* @param {string} opt.mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
|
|
2341
2341
|
* @param {Object} opt.whitelist 节点白名单
|
|
2342
2342
|
* @param {Array} opt.whitelist.tagName 标签名列表
|
|
2343
|
+
* @param {Array} opt.whitelist.attribute 属性列表
|
|
2343
2344
|
* @param {boolean} opt.needJudgeFirstPage 是否需要判断首屏
|
|
2344
2345
|
* @param {boolean} opt.delayBgJudge 是否延迟背景判断
|
|
2345
2346
|
* @param {DOM Object} opt.container 延迟运行js时使用的容器
|
|
@@ -2352,13 +2353,18 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2352
2353
|
* @function convertBg 处理背景
|
|
2353
2354
|
* @param {DOM Object Array} nodes 要处理的节点列表
|
|
2354
2355
|
*
|
|
2355
|
-
* @function extend 挂载插件
|
|
2356
|
-
* @param {Array} pluginList 插件列表
|
|
2357
|
-
*
|
|
2358
2356
|
* @function updateStyle 更新节点Dark Mode样式
|
|
2359
2357
|
* @param {DOM Object} node 要更新的节点
|
|
2360
2358
|
* @param {Object} styles 更新的样式键值对对象,如:{ color: '#ddd' }
|
|
2361
2359
|
*
|
|
2360
|
+
* @function getContrast 获取两个颜色的对比度
|
|
2361
|
+
* @param {string} color1 要计算颜色对比度的颜色1,支持css颜色格式
|
|
2362
|
+
* @param {string} color2 要计算颜色对比度的颜色2,支持css颜色格式
|
|
2363
|
+
* @return {number} contrast 颜色对比度,取值范围为`[1, 21]`
|
|
2364
|
+
*
|
|
2365
|
+
* @function extend 挂载插件
|
|
2366
|
+
* @param {Array} pluginList 插件列表
|
|
2367
|
+
*
|
|
2362
2368
|
*/
|
|
2363
2369
|
|
|
2364
2370
|
var classReg = new RegExp("".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "[^ ]+"), 'g'); // Darkmode配置
|
|
@@ -2475,10 +2481,17 @@ function init() {
|
|
|
2475
2481
|
_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].hasInit = true; // 记录为配置已设置
|
|
2476
2482
|
|
|
2477
2483
|
var tagName = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].whitelist.tagName;
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2484
|
+
var attribute = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].whitelist.attribute;
|
|
2485
|
+
|
|
2486
|
+
if (opt.whitelist) {
|
|
2487
|
+
opt.whitelist.tagName instanceof Array && opt.whitelist.tagName.forEach(function (item) {
|
|
2488
|
+
item = item.toUpperCase();
|
|
2489
|
+
tagName.indexOf(item) === -1 && tagName.push(item);
|
|
2490
|
+
});
|
|
2491
|
+
opt.whitelist.attribute instanceof Array && opt.whitelist.attribute.forEach(function (item) {
|
|
2492
|
+
attribute.indexOf(item) === -1 && attribute.push(item);
|
|
2493
|
+
});
|
|
2494
|
+
}
|
|
2482
2495
|
|
|
2483
2496
|
if (['dark', 'light'].indexOf(opt.mode) > -1) {
|
|
2484
2497
|
_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'mode');
|
|
@@ -2519,12 +2532,6 @@ function convertBg(nodes) {
|
|
|
2519
2532
|
});
|
|
2520
2533
|
}
|
|
2521
2534
|
;
|
|
2522
|
-
function extend(pluginList) {
|
|
2523
|
-
pluginList.forEach(function (plugin) {
|
|
2524
|
-
return _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].extend(plugin);
|
|
2525
|
-
});
|
|
2526
|
-
}
|
|
2527
|
-
;
|
|
2528
2535
|
function updateStyle(node, styles) {
|
|
2529
2536
|
if (!_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].isFinish) return; // 没有运行过Dark Mode处理逻辑则无需运行
|
|
2530
2537
|
|
|
@@ -2537,6 +2544,13 @@ function updateStyle(node, styles) {
|
|
|
2537
2544
|
function getContrast(color1, color2) {
|
|
2538
2545
|
return _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].getContrast(color1, color2);
|
|
2539
2546
|
}
|
|
2547
|
+
;
|
|
2548
|
+
function extend(pluginList) {
|
|
2549
|
+
pluginList.forEach(function (plugin) {
|
|
2550
|
+
return _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].extend(plugin);
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
;
|
|
2540
2554
|
|
|
2541
2555
|
/***/ }),
|
|
2542
2556
|
|
|
@@ -2576,7 +2590,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2576
2590
|
* @param {Function} callback 如果在背景节点区域内,则执行该回调函数
|
|
2577
2591
|
*
|
|
2578
2592
|
* @method update 更新堆栈的节点对象,主要解决前后节点不一致的问题
|
|
2579
|
-
* @param {DOM Object Array}
|
|
2593
|
+
* @param {DOM Object Array} els 要更新的节点对象列表
|
|
2580
2594
|
*
|
|
2581
2595
|
*/
|
|
2582
2596
|
// Darkmode配置
|
|
@@ -2635,12 +2649,12 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2635
2649
|
}
|
|
2636
2650
|
}, {
|
|
2637
2651
|
key: "update",
|
|
2638
|
-
value: function update(
|
|
2652
|
+
value: function update(els) {
|
|
2639
2653
|
this._stack.forEach(function (item) {
|
|
2640
2654
|
if (!item.updated) {
|
|
2641
|
-
Array.prototype.some.call(
|
|
2642
|
-
if (
|
|
2643
|
-
item.el =
|
|
2655
|
+
Array.prototype.some.call(els, function (el) {
|
|
2656
|
+
if (el.nodeType === 1 && el.classList.contains(item.className)) {
|
|
2657
|
+
item.el = el;
|
|
2644
2658
|
item.updated = true;
|
|
2645
2659
|
return true;
|
|
2646
2660
|
}
|
|
@@ -2704,7 +2718,8 @@ var config = {
|
|
|
2704
2718
|
error: null,
|
|
2705
2719
|
mode: '',
|
|
2706
2720
|
whitelist: {
|
|
2707
|
-
tagName: ['MPCPS', 'IFRAME']
|
|
2721
|
+
tagName: ['MPCPS', 'IFRAME'],
|
|
2722
|
+
attribute: []
|
|
2708
2723
|
},
|
|
2709
2724
|
needJudgeFirstPage: true,
|
|
2710
2725
|
delayBgJudge: false,
|
|
@@ -2805,7 +2820,7 @@ var DEFAULT_LIGHT_TEXTCOLOR = '#191919'; // 非Dark Mode下字体颜色
|
|
|
2805
2820
|
|
|
2806
2821
|
var DEFAULT_LIGHT_BGCOLOR = '#fff'; // 非Dark Mode下背景颜色
|
|
2807
2822
|
|
|
2808
|
-
var DEFAULT_DARK_TEXTCOLOR = '#a3a3a3'; //
|
|
2823
|
+
var DEFAULT_DARK_TEXTCOLOR = '#a3a3a3'; // Dark Mode下字体颜色,前景色:rgba(255,255,255,0.6) 背景色:#191919
|
|
2809
2824
|
|
|
2810
2825
|
var DEFAULT_DARK_BGCOLOR = '#191919'; // Dark Mode下背景颜色
|
|
2811
2826
|
|
|
@@ -3021,32 +3036,32 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
3021
3036
|
* @name 节点相关操作工具API
|
|
3022
3037
|
*
|
|
3023
3038
|
* @function getChildrenAndIt 获取某个节点及它的所有子节点
|
|
3024
|
-
* @param {DOM Object}
|
|
3039
|
+
* @param {DOM Object} el 节点对象
|
|
3025
3040
|
* @return {DOM Object Array} 节点对象列表
|
|
3026
3041
|
*
|
|
3027
3042
|
* @function hasTextNode 判断某个节点里是否包含文字节点
|
|
3028
|
-
* @param {DOM Object}
|
|
3043
|
+
* @param {DOM Object} el 节点对象
|
|
3029
3044
|
* @return {boolean} 判断结果
|
|
3030
3045
|
*
|
|
3031
3046
|
* @function hasTableClass 判断table相关元素有没有指定class
|
|
3032
|
-
* @param {DOM Object}
|
|
3047
|
+
* @param {DOM Object} el 节点对象
|
|
3033
3048
|
* @return {string | null} 判断结果,如果有,返回class对应的lm色值,否则返回null
|
|
3034
3049
|
*
|
|
3035
3050
|
*/
|
|
3036
3051
|
// Darkmode配置
|
|
3037
3052
|
|
|
3038
3053
|
|
|
3039
|
-
function getChildrenAndIt(
|
|
3054
|
+
function getChildrenAndIt(el) {
|
|
3040
3055
|
var _ref;
|
|
3041
3056
|
|
|
3042
|
-
return (_ref = [
|
|
3057
|
+
return (_ref = [el]).concat.apply(_ref, _toConsumableArray(el.querySelectorAll('*')));
|
|
3043
3058
|
}
|
|
3044
3059
|
;
|
|
3045
|
-
function hasTextNode(
|
|
3060
|
+
function hasTextNode(el) {
|
|
3046
3061
|
var cnt = '';
|
|
3047
|
-
Array.prototype.forEach.call(
|
|
3048
|
-
if (
|
|
3049
|
-
cnt +=
|
|
3062
|
+
Array.prototype.forEach.call(el.childNodes, function (child) {
|
|
3063
|
+
if (child.nodeType === 3) {
|
|
3064
|
+
cnt += child.nodeValue.replace(/\s/g, ''); // 不考虑空白字符
|
|
3050
3065
|
}
|
|
3051
3066
|
});
|
|
3052
3067
|
return cnt.length > 0;
|
|
@@ -3057,9 +3072,9 @@ var tableClassObj = {
|
|
|
3057
3072
|
'ue-table-interlace-color-single': '#fcfcfc',
|
|
3058
3073
|
'ue-table-interlace-color-double': '#f7faff'
|
|
3059
3074
|
};
|
|
3060
|
-
function hasTableClass(
|
|
3075
|
+
function hasTableClass(el) {
|
|
3061
3076
|
var color = null;
|
|
3062
|
-
Array.prototype.some.call(
|
|
3077
|
+
Array.prototype.some.call(el.classList, function (className) {
|
|
3063
3078
|
if (tableClassObj[className]) {
|
|
3064
3079
|
color = tableClassObj[className];
|
|
3065
3080
|
return true;
|
|
@@ -3079,7 +3094,7 @@ function hasTableClass(dom) {
|
|
|
3079
3094
|
* @attr {boolean} showFirstPage 是否已显示首屏
|
|
3080
3095
|
*
|
|
3081
3096
|
* @method set 设置要处理的节点列表
|
|
3082
|
-
* @param {DOM Object Array}
|
|
3097
|
+
* @param {DOM Object Array} els 要处理的节点列表
|
|
3083
3098
|
*
|
|
3084
3099
|
* @method get 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
|
|
3085
3100
|
* @return {DOM Object Array} 要处理的节点列表
|
|
@@ -3090,7 +3105,7 @@ function hasTableClass(dom) {
|
|
|
3090
3105
|
* @return {boolean} 判断结果
|
|
3091
3106
|
*
|
|
3092
3107
|
* @method addFirstPageNode 添加首屏节点
|
|
3093
|
-
* @param {DOM Object}
|
|
3108
|
+
* @param {DOM Object} el 要添加的首屏节点
|
|
3094
3109
|
*
|
|
3095
3110
|
* @method showFirstPageNodes 显示所有首屏节点
|
|
3096
3111
|
*
|
|
@@ -3106,11 +3121,11 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3106
3121
|
function DomUtils() {
|
|
3107
3122
|
_classCallCheck(this, DomUtils);
|
|
3108
3123
|
|
|
3109
|
-
_defineProperty(this, "
|
|
3124
|
+
_defineProperty(this, "_els", []);
|
|
3110
3125
|
|
|
3111
|
-
_defineProperty(this, "
|
|
3126
|
+
_defineProperty(this, "_firstPageEls", []);
|
|
3112
3127
|
|
|
3113
|
-
_defineProperty(this, "
|
|
3128
|
+
_defineProperty(this, "_delayEls", []);
|
|
3114
3129
|
|
|
3115
3130
|
_defineProperty(this, "showFirstPage", false);
|
|
3116
3131
|
}
|
|
@@ -3118,29 +3133,29 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3118
3133
|
_createClass(DomUtils, [{
|
|
3119
3134
|
key: "length",
|
|
3120
3135
|
get: function get() {
|
|
3121
|
-
return this.
|
|
3136
|
+
return this._els.length;
|
|
3122
3137
|
}
|
|
3123
3138
|
}, {
|
|
3124
3139
|
key: "set",
|
|
3125
3140
|
value: function set() {
|
|
3126
|
-
var
|
|
3127
|
-
this.
|
|
3141
|
+
var els = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3142
|
+
this._els = els;
|
|
3128
3143
|
}
|
|
3129
3144
|
}, {
|
|
3130
3145
|
key: "get",
|
|
3131
3146
|
value: function get() {
|
|
3132
3147
|
var res = [];
|
|
3133
3148
|
|
|
3134
|
-
if (this.
|
|
3149
|
+
if (this._els.length) {
|
|
3135
3150
|
// 有节点
|
|
3136
|
-
res = this.
|
|
3137
|
-
_global__WEBPACK_IMPORTED_MODULE_1__["sdk"].isDarkmode && (this.
|
|
3151
|
+
res = this._els;
|
|
3152
|
+
_global__WEBPACK_IMPORTED_MODULE_1__["sdk"].isDarkmode && (this._els = []);
|
|
3138
3153
|
} else {
|
|
3139
3154
|
// 如果没有节点
|
|
3140
|
-
if (this.
|
|
3155
|
+
if (this._delayEls.length) {
|
|
3141
3156
|
// 有延迟节点,则使用延迟节点
|
|
3142
|
-
res = this.
|
|
3143
|
-
this.
|
|
3157
|
+
res = this._delayEls;
|
|
3158
|
+
this._delayEls = [];
|
|
3144
3159
|
} else if (_config__WEBPACK_IMPORTED_MODULE_0__["default"].container) {
|
|
3145
3160
|
// 没有延迟节点,但有容器,重新获取容器内的节点
|
|
3146
3161
|
res = _config__WEBPACK_IMPORTED_MODULE_0__["default"].container.querySelectorAll('*');
|
|
@@ -3154,27 +3169,29 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3154
3169
|
value: function delay() {
|
|
3155
3170
|
var _this = this;
|
|
3156
3171
|
|
|
3157
|
-
Array.prototype.forEach.call(this.
|
|
3158
|
-
return _this.
|
|
3172
|
+
Array.prototype.forEach.call(this._els, function (el) {
|
|
3173
|
+
return _this._delayEls.push(el);
|
|
3159
3174
|
}); // 转移到延迟处理的节点里
|
|
3160
3175
|
|
|
3161
|
-
this.
|
|
3176
|
+
this._els = []; // 转移后清空列表
|
|
3162
3177
|
}
|
|
3163
3178
|
}, {
|
|
3164
3179
|
key: "hasDelay",
|
|
3165
3180
|
value: function hasDelay() {
|
|
3166
|
-
|
|
3181
|
+
if (this._els.length) return false; // 有节点,即不含延迟处理的节点
|
|
3182
|
+
|
|
3183
|
+
return this._delayEls.length > 0 || _config__WEBPACK_IMPORTED_MODULE_0__["default"].container !== null; // 否则需要判断延迟节点的列表和容器
|
|
3167
3184
|
}
|
|
3168
3185
|
}, {
|
|
3169
3186
|
key: "addFirstPageNode",
|
|
3170
|
-
value: function addFirstPageNode(
|
|
3171
|
-
this.
|
|
3187
|
+
value: function addFirstPageNode(el) {
|
|
3188
|
+
this._firstPageEls.push(el);
|
|
3172
3189
|
}
|
|
3173
3190
|
}, {
|
|
3174
3191
|
key: "showFirstPageNodes",
|
|
3175
3192
|
value: function showFirstPageNodes() {
|
|
3176
|
-
this.
|
|
3177
|
-
return !
|
|
3193
|
+
this._firstPageEls.forEach(function (el) {
|
|
3194
|
+
return !el.style.visibility && (el.style.visibility = 'visible');
|
|
3178
3195
|
}); // 显示首屏节点
|
|
3179
3196
|
|
|
3180
3197
|
|
|
@@ -3183,7 +3200,7 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3183
3200
|
}, {
|
|
3184
3201
|
key: "emptyFirstPageNodes",
|
|
3185
3202
|
value: function emptyFirstPageNodes() {
|
|
3186
|
-
this.
|
|
3203
|
+
this._firstPageEls = [];
|
|
3187
3204
|
}
|
|
3188
3205
|
}]);
|
|
3189
3206
|
|
|
@@ -3465,6 +3482,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3465
3482
|
// dependencies
|
|
3466
3483
|
|
|
3467
3484
|
|
|
3485
|
+
var ColorParser = function ColorParser(color) {
|
|
3486
|
+
var res = null;
|
|
3487
|
+
|
|
3488
|
+
try {
|
|
3489
|
+
res = color__WEBPACK_IMPORTED_MODULE_0___default()(color);
|
|
3490
|
+
} catch (e) {
|
|
3491
|
+
console.log("ignore the invalid color: `".concat(color, "`"));
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3494
|
+
return res;
|
|
3495
|
+
};
|
|
3496
|
+
|
|
3497
|
+
|
|
3468
3498
|
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
|
|
3469
3499
|
|
|
3470
3500
|
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255, 0]; // 支持透明,暂定用白色透明度0来表示
|
|
@@ -3501,16 +3531,29 @@ var parseColor = function parseColor(value, parseTransparent) {
|
|
|
3501
3531
|
var mixColor = function mixColor(colors) {
|
|
3502
3532
|
if (!colors || colors.length < 1) return '';
|
|
3503
3533
|
if (colors.length === 1) return colors[0];
|
|
3504
|
-
var
|
|
3505
|
-
var
|
|
3506
|
-
|
|
3507
|
-
while (
|
|
3508
|
-
var
|
|
3509
|
-
|
|
3510
|
-
|
|
3534
|
+
var retColorStr = colors.shift();
|
|
3535
|
+
var nextColorStr = colors.shift();
|
|
3536
|
+
|
|
3537
|
+
while (nextColorStr) {
|
|
3538
|
+
var retColor = ColorParser(retColorStr);
|
|
3539
|
+
var nextColor = ColorParser(nextColorStr);
|
|
3540
|
+
|
|
3541
|
+
if (!retColor && nextColor) {
|
|
3542
|
+
// 如果当前色值非法,混入色值合法,则直接使用混入色值
|
|
3543
|
+
retColorStr = nextColorStr;
|
|
3544
|
+
} else if (!retColor && !nextColor) {
|
|
3545
|
+
// 如果两个色值都非法,则使用下一批色值
|
|
3546
|
+
retColorStr = colors.shift() || '';
|
|
3547
|
+
} else if (retColor && nextColor) {
|
|
3548
|
+
// 如果两个色值都合法,执行mix
|
|
3549
|
+
retColorStr = retColor.mix(nextColor, nextColor.alpha());
|
|
3550
|
+
} // 如果当前色值合法,混入色值非法,无需处理
|
|
3551
|
+
|
|
3552
|
+
|
|
3553
|
+
nextColorStr = colors.shift();
|
|
3511
3554
|
}
|
|
3512
3555
|
|
|
3513
|
-
return
|
|
3556
|
+
return retColorStr;
|
|
3514
3557
|
}; // 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
|
|
3515
3558
|
|
|
3516
3559
|
|
|
@@ -3568,11 +3611,11 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3568
3611
|
|
|
3569
3612
|
_defineProperty(this, "_idx", 0);
|
|
3570
3613
|
|
|
3571
|
-
_defineProperty(this, "_defaultDarkTextColorRgb",
|
|
3614
|
+
_defineProperty(this, "_defaultDarkTextColorRgb", ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkTextColor).rgb().array());
|
|
3572
3615
|
|
|
3573
|
-
_defineProperty(this, "_defaultDarkBgColorRgb",
|
|
3616
|
+
_defineProperty(this, "_defaultDarkBgColorRgb", ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).rgb().array());
|
|
3574
3617
|
|
|
3575
|
-
_defineProperty(this, "_defaultDarkBgColorHSL",
|
|
3618
|
+
_defineProperty(this, "_defaultDarkBgColorHSL", ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).hsl().array());
|
|
3576
3619
|
|
|
3577
3620
|
_defineProperty(this, "_defaultDarkTextColorBrightness", getColorPerceivedBrightness(this._defaultDarkTextColorRgb));
|
|
3578
3621
|
|
|
@@ -3685,25 +3728,28 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3685
3728
|
newColor = this._adjustBackgroundBrightness(color);
|
|
3686
3729
|
|
|
3687
3730
|
if (!options.hasInlineColor) {
|
|
3688
|
-
var
|
|
3731
|
+
var parentTextColorStr = el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor;
|
|
3732
|
+
var parentTextColor = ColorParser(parentTextColorStr);
|
|
3689
3733
|
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3734
|
+
if (parentTextColor) {
|
|
3735
|
+
var ret = this._adjustBrightness(parentTextColor, el, {
|
|
3736
|
+
isTextColor: true,
|
|
3737
|
+
parentElementBgColorStr: newColor || color
|
|
3738
|
+
}, isUpdate);
|
|
3694
3739
|
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3740
|
+
if (ret.newColor) {
|
|
3741
|
+
extStyle += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', ret.newColor);
|
|
3742
|
+
} else {
|
|
3743
|
+
extStyle += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', parentTextColor);
|
|
3744
|
+
}
|
|
3699
3745
|
}
|
|
3700
3746
|
}
|
|
3701
3747
|
} else if (options.isTextColor || options.isBorderColor) {
|
|
3702
3748
|
// 字体色、边框色
|
|
3703
3749
|
var parentElementBgColorStr = options.parentElementBgColorStr || options.isTextColor && el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor;
|
|
3704
|
-
var parentElementBgColor =
|
|
3750
|
+
var parentElementBgColor = ColorParser(parentElementBgColorStr); // 无背景图片
|
|
3705
3751
|
|
|
3706
|
-
if (!el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
|
|
3752
|
+
if (parentElementBgColor && !el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
|
|
3707
3753
|
newColor = this._adjustTextBrightness(color, parentElementBgColor);
|
|
3708
3754
|
_global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit("afterConvertTextColor".concat(isUpdate ? 'ByUpdateStyle' : ''), el, {
|
|
3709
3755
|
// fontColor: color,
|
|
@@ -3748,6 +3794,9 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3748
3794
|
if (this.isDarkmode || isUpdate) {
|
|
3749
3795
|
var nodeName = el.nodeName;
|
|
3750
3796
|
if (_config__WEBPACK_IMPORTED_MODULE_3__["default"].whitelist.tagName.indexOf(nodeName) > -1) return '';
|
|
3797
|
+
if (_config__WEBPACK_IMPORTED_MODULE_3__["default"].whitelist.attribute.some(function (attribute) {
|
|
3798
|
+
return el.hasAttribute(attribute);
|
|
3799
|
+
})) return '';
|
|
3751
3800
|
var styles = el.style;
|
|
3752
3801
|
|
|
3753
3802
|
if (!cssKVList) {
|
|
@@ -3815,14 +3864,18 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3815
3864
|
if (_constant__WEBPACK_IMPORTED_MODULE_2__["TABLE_NAME"].indexOf(nodeName) > -1 && !hasInlineBackground) {
|
|
3816
3865
|
// 如果table没有内联样式
|
|
3817
3866
|
this._try(function () {
|
|
3818
|
-
var
|
|
3867
|
+
var colorStr = Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["hasTableClass"])(el); // 获取class对应的lm色值
|
|
3819
3868
|
|
|
3820
|
-
if (!
|
|
3869
|
+
if (!colorStr) colorStr = el.getAttribute('bgcolor'); // 如果没有class则获取bgcolor的色值
|
|
3821
3870
|
|
|
3822
|
-
if (
|
|
3871
|
+
if (colorStr) {
|
|
3823
3872
|
// 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
|
|
3824
|
-
|
|
3825
|
-
|
|
3873
|
+
var color = ColorParser(colorStr);
|
|
3874
|
+
|
|
3875
|
+
if (color) {
|
|
3876
|
+
cssKVList.unshift(['background-color', color.toString()]);
|
|
3877
|
+
hasInlineBackground = true;
|
|
3878
|
+
}
|
|
3826
3879
|
}
|
|
3827
3880
|
});
|
|
3828
3881
|
}
|
|
@@ -3830,12 +3883,16 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3830
3883
|
if (nodeName === 'FONT' && !hasInlineColor) {
|
|
3831
3884
|
// 如果是font标签且没有内联文本颜色样式
|
|
3832
3885
|
this._try(function () {
|
|
3833
|
-
var
|
|
3886
|
+
var colorStr = el.getAttribute('color'); // 获取color的色值
|
|
3834
3887
|
|
|
3835
|
-
if (
|
|
3888
|
+
if (colorStr) {
|
|
3836
3889
|
// 有色值,则当做内联样式来处理
|
|
3837
|
-
|
|
3838
|
-
|
|
3890
|
+
var color = ColorParser(colorStr);
|
|
3891
|
+
|
|
3892
|
+
if (color) {
|
|
3893
|
+
cssKVList.push(['color', color.toString()]);
|
|
3894
|
+
hasInlineColor = true;
|
|
3895
|
+
}
|
|
3839
3896
|
}
|
|
3840
3897
|
});
|
|
3841
3898
|
} // 处理-webkit-text相关样式
|
|
@@ -3961,9 +4018,9 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3961
4018
|
cssChange = true;
|
|
3962
4019
|
}
|
|
3963
4020
|
|
|
3964
|
-
var matchColor =
|
|
4021
|
+
var matchColor = ColorParser(match);
|
|
3965
4022
|
|
|
3966
|
-
if (matchColor.alpha() >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
|
|
4023
|
+
if ((matchColor === null || matchColor === void 0 ? void 0 : matchColor.alpha()) >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
|
|
3967
4024
|
// 忽略透明度低的色值
|
|
3968
4025
|
// 使用颜色处理算法
|
|
3969
4026
|
var ret = _this._adjustBrightness(matchColor, el, {
|
|
@@ -3990,7 +4047,9 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3990
4047
|
} // 如果设置背景颜色,取消背景图片的影响
|
|
3991
4048
|
|
|
3992
4049
|
|
|
3993
|
-
|
|
4050
|
+
var retColor = ColorParser(retColorStr);
|
|
4051
|
+
|
|
4052
|
+
if (isBgColor && (retColor === null || retColor === void 0 ? void 0 : retColor.alpha()) >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"] && dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
|
|
3994
4053
|
delete dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]];
|
|
3995
4054
|
}
|
|
3996
4055
|
});
|
|
@@ -4034,7 +4093,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4034
4093
|
|
|
4035
4094
|
|
|
4036
4095
|
if (isBackgroundAttr) {
|
|
4037
|
-
tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"));
|
|
4096
|
+
tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, imgBgColor ? "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")") : newValue);
|
|
4038
4097
|
|
|
4039
4098
|
if (elBackgroundPositionAttr) {
|
|
4040
4099
|
newBackgroundPositionValue = "top left,".concat(elBackgroundPositionAttr);
|
|
@@ -4057,7 +4116,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4057
4116
|
}
|
|
4058
4117
|
} else {
|
|
4059
4118
|
// border-image元素,如果当前元素没有背景颜色,补背景颜色
|
|
4060
|
-
if (!hasInlineBackground) {
|
|
4119
|
+
if (imgBgColor && !hasInlineBackground) {
|
|
4061
4120
|
tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-image', "linear-gradient(".concat(imgBgColor, ", ").concat(imgBgColor, ")"));
|
|
4062
4121
|
|
|
4063
4122
|
if (dmBgClassName) {
|
|
@@ -4131,8 +4190,10 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4131
4190
|
}
|
|
4132
4191
|
}, {
|
|
4133
4192
|
key: "getContrast",
|
|
4134
|
-
value: function getContrast(
|
|
4135
|
-
|
|
4193
|
+
value: function getContrast(colorStr1, colorStr2) {
|
|
4194
|
+
var color1 = ColorParser(colorStr1);
|
|
4195
|
+
var color2 = ColorParser(colorStr2);
|
|
4196
|
+
return color1 && color2 ? _getContrast(color1.rgb().array(), color2.rgb().array()) : 0;
|
|
4136
4197
|
}
|
|
4137
4198
|
}]);
|
|
4138
4199
|
|
|
@@ -4180,7 +4241,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
4180
4241
|
* @param {Function} callback 回调
|
|
4181
4242
|
*
|
|
4182
4243
|
* @method update 更新队列的节点对象,主要解决前后节点不一致的问题
|
|
4183
|
-
* @param {DOM Object Array}
|
|
4244
|
+
* @param {DOM Object Array} els 要更新的节点对象列表
|
|
4184
4245
|
*
|
|
4185
4246
|
*/
|
|
4186
4247
|
// Darkmode配置
|
|
@@ -4230,12 +4291,12 @@ var TextNodeQueue = /*#__PURE__*/function () {
|
|
|
4230
4291
|
}
|
|
4231
4292
|
}, {
|
|
4232
4293
|
key: "update",
|
|
4233
|
-
value: function update(
|
|
4294
|
+
value: function update(els) {
|
|
4234
4295
|
this._queue.forEach(function (item) {
|
|
4235
4296
|
if (!item.updated) {
|
|
4236
|
-
Array.prototype.some.call(
|
|
4237
|
-
if (
|
|
4238
|
-
item.el =
|
|
4297
|
+
Array.prototype.some.call(els, function (el) {
|
|
4298
|
+
if (el.nodeType === 1 && el.classList.contains(item.className)) {
|
|
4299
|
+
item.el = el;
|
|
4239
4300
|
item.updated = true;
|
|
4240
4301
|
return true;
|
|
4241
4302
|
}
|