mp-darkmode 1.0.5 → 1.0.9
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/dist/darkmode.js +209 -165
- package/dist/darkmode.js.map +1 -1
- package/dist/darkmode.min.js +1 -1
- package/doc/cn/API.md +1 -0
- package/doc/en/API.md +1 -0
- package/package.json +1 -1
package/dist/darkmode.js
CHANGED
|
@@ -2327,6 +2327,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2327
2327
|
*
|
|
2328
2328
|
* @function init 初始化Dark Mode配置
|
|
2329
2329
|
* @param {Function} opt.begin 开始处理时触发的回调
|
|
2330
|
+
* @param {Function} opt.showFirstPage 首屏处理完成时触发的回调
|
|
2330
2331
|
* @param {Function} opt.error 发生error时触发的回调
|
|
2331
2332
|
* @param {String} opt.mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
|
|
2332
2333
|
* @param {Object} opt.whitelist 节点白名单
|
|
@@ -2353,6 +2354,8 @@ var config = {
|
|
|
2353
2354
|
// hooks
|
|
2354
2355
|
begin: null,
|
|
2355
2356
|
// 开始处理时触发的回调
|
|
2357
|
+
showFirstPage: null,
|
|
2358
|
+
// 首屏处理完成时触发的回调
|
|
2356
2359
|
error: null,
|
|
2357
2360
|
// 发生error时触发的回调
|
|
2358
2361
|
mode: '',
|
|
@@ -2471,6 +2474,8 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
|
|
|
2471
2474
|
|
|
2472
2475
|
domUtils.showFirstPageNodes(); // 显示首屏节点
|
|
2473
2476
|
|
|
2477
|
+
typeof config.showFirstPage === 'function' && config.showFirstPage(); // 执行首屏回调
|
|
2478
|
+
|
|
2474
2479
|
cssUtils.addCss(sdk.convert(node), false); // 写入非首屏样式
|
|
2475
2480
|
}
|
|
2476
2481
|
}
|
|
@@ -2484,6 +2489,12 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
|
|
|
2484
2489
|
});
|
|
2485
2490
|
}
|
|
2486
2491
|
|
|
2492
|
+
if (config.needJudgeFirstPage || !config.needJudgeFirstPage && !domUtils.showFirstPage) {
|
|
2493
|
+
// config.needJudgeFirstPage === ture,表示需要判断首屏但是正文长度没超过一屏
|
|
2494
|
+
// config.needJudgeFirstPage === false && domUtils.showFirstPage === false,表示不需要判断首屏且没有做首屏优化
|
|
2495
|
+
typeof config.showFirstPage === 'function' && config.showFirstPage();
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2487
2498
|
cssUtils.writeStyle(); // 写入非首屏样式表
|
|
2488
2499
|
} else {
|
|
2489
2500
|
// 首次加载页面时为非Dark Mode,标记为不需要判断首屏
|
|
@@ -2496,7 +2507,7 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
|
|
|
2496
2507
|
}
|
|
2497
2508
|
}
|
|
2498
2509
|
} catch (e) {
|
|
2499
|
-
console.error
|
|
2510
|
+
console.log('An error occurred when running the dark mode conversion algorithm\n', e);
|
|
2500
2511
|
typeof config.error === 'function' && config.error(e);
|
|
2501
2512
|
}
|
|
2502
2513
|
};
|
|
@@ -2529,6 +2540,7 @@ function init() {
|
|
|
2529
2540
|
}
|
|
2530
2541
|
|
|
2531
2542
|
setConfig('function', opt, 'begin');
|
|
2543
|
+
setConfig('function', opt, 'showFirstPage');
|
|
2532
2544
|
setConfig('function', opt, 'error');
|
|
2533
2545
|
setConfig('boolean', opt, 'needJudgeFirstPage');
|
|
2534
2546
|
setConfig('boolean', opt, 'delayBgJudge');
|
|
@@ -2685,7 +2697,7 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2685
2697
|
/*!*********************************!*\
|
|
2686
2698
|
!*** ./src/modules/constant.js ***!
|
|
2687
2699
|
\*********************************/
|
|
2688
|
-
/*! exports provided: MEDIA_QUERY, CLASS_PREFIX, HTML_CLASS, COLORATTR, BGCOLORATTR, ORIGINAL_COLORATTR, ORIGINAL_BGCOLORATTR, BGIMAGEATTR, DEFAULT_LIGHT_TEXTCOLOR, DEFAULT_LIGHT_BGCOLOR, DEFAULT_DARK_TEXTCOLOR, DEFAULT_DARK_BGCOLOR, GRAY_MASK_COLOR, WHITE_LIKE_COLOR_BRIGHTNESS, MAX_LIMIT_BGCOLOR_BRIGHTNESS, MIN_LIMIT_OFFSET_BRIGHTNESS, HIGH_BGCOLOR_BRIGHTNESS, HIGH_BLACKWHITE_HSL_BRIGHTNESS, LOW_BLACKWHITE_HSL_BRIGHTNESS, PAGE_HEIGHT, TABLE_NAME,
|
|
2700
|
+
/*! exports provided: MEDIA_QUERY, CLASS_PREFIX, HTML_CLASS, COLORATTR, BGCOLORATTR, ORIGINAL_COLORATTR, ORIGINAL_BGCOLORATTR, BGIMAGEATTR, DEFAULT_LIGHT_TEXTCOLOR, DEFAULT_LIGHT_BGCOLOR, DEFAULT_DARK_TEXTCOLOR, DEFAULT_DARK_BGCOLOR, GRAY_MASK_COLOR, WHITE_LIKE_COLOR_BRIGHTNESS, MAX_LIMIT_BGCOLOR_BRIGHTNESS, MIN_LIMIT_OFFSET_BRIGHTNESS, HIGH_BGCOLOR_BRIGHTNESS, HIGH_BLACKWHITE_HSL_BRIGHTNESS, LOW_BLACKWHITE_HSL_BRIGHTNESS, PAGE_HEIGHT, TABLE_NAME, IMPORTANT_REGEXP */
|
|
2689
2701
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2690
2702
|
|
|
2691
2703
|
"use strict";
|
|
@@ -2711,7 +2723,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2711
2723
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LOW_BLACKWHITE_HSL_BRIGHTNESS", function() { return LOW_BLACKWHITE_HSL_BRIGHTNESS; });
|
|
2712
2724
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PAGE_HEIGHT", function() { return PAGE_HEIGHT; });
|
|
2713
2725
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TABLE_NAME", function() { return TABLE_NAME; });
|
|
2714
|
-
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "IS_PC", function() { return IS_PC; });
|
|
2715
2726
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "IMPORTANT_REGEXP", function() { return IMPORTANT_REGEXP; });
|
|
2716
2727
|
/**
|
|
2717
2728
|
* @name 常量
|
|
@@ -2750,8 +2761,6 @@ var LOW_BLACKWHITE_HSL_BRIGHTNESS = 22;
|
|
|
2750
2761
|
var PAGE_HEIGHT = window.getInnerHeight && window.getInnerHeight() || window.innerHeight || document.documentElement.clientHeight;
|
|
2751
2762
|
var TABLE_NAME = ['TABLE', 'TR', 'TD', 'TH']; // 支持bgcolor属性的table标签列表
|
|
2752
2763
|
|
|
2753
|
-
var UA = navigator.userAgent;
|
|
2754
|
-
var IS_PC = /windows\snt/i.test(UA) && !/Windows\sPhone/i.test(UA) || /mac\sos/i.test(UA) && !/(iPhone|iPad|iPod|iOS)/i.test(UA);
|
|
2755
2764
|
var IMPORTANT_REGEXP = / !important$/; // !important
|
|
2756
2765
|
|
|
2757
2766
|
/***/ }),
|
|
@@ -2958,6 +2967,8 @@ function hasTableClass(dom) {
|
|
|
2958
2967
|
* @constructor
|
|
2959
2968
|
* @param {Object} config Darkmode配置
|
|
2960
2969
|
*
|
|
2970
|
+
* @attr {boolean} showFirstPage 是否已显示首屏
|
|
2971
|
+
*
|
|
2961
2972
|
* @method set 设置要处理的节点列表
|
|
2962
2973
|
* @param {Dom Object Array} nodes 要处理的节点列表
|
|
2963
2974
|
*
|
|
@@ -2983,6 +2994,7 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
2983
2994
|
// 要处理的节点列表
|
|
2984
2995
|
// 首屏节点列表
|
|
2985
2996
|
// 延迟处理的节点列表
|
|
2997
|
+
// 是否已显示首屏
|
|
2986
2998
|
function DomUtils(config) {
|
|
2987
2999
|
_classCallCheck(this, DomUtils);
|
|
2988
3000
|
|
|
@@ -2992,6 +3004,8 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
2992
3004
|
|
|
2993
3005
|
_defineProperty(this, "_delayNodes", []);
|
|
2994
3006
|
|
|
3007
|
+
_defineProperty(this, "showFirstPage", false);
|
|
3008
|
+
|
|
2995
3009
|
this._config = config;
|
|
2996
3010
|
}
|
|
2997
3011
|
|
|
@@ -3059,6 +3073,8 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3059
3073
|
|
|
3060
3074
|
|
|
3061
3075
|
this._firstPageNodes = []; // 处理完之后清空列表
|
|
3076
|
+
|
|
3077
|
+
this.showFirstPage = true; // 记录为已显示首屏
|
|
3062
3078
|
}
|
|
3063
3079
|
}]);
|
|
3064
3080
|
|
|
@@ -3134,27 +3150,32 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3134
3150
|
|
|
3135
3151
|
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
|
|
3136
3152
|
|
|
3153
|
+
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255, 0]; // 支持透明,暂定用白色透明度0来表示
|
|
3154
|
+
|
|
3137
3155
|
// 节点相关操作工具API
|
|
3138
3156
|
|
|
3139
3157
|
|
|
3140
3158
|
var colorNameReg = new RegExp(Object.keys(color_name__WEBPACK_IMPORTED_MODULE_1___default.a).map(function (colorName) {
|
|
3141
|
-
return "
|
|
3159
|
+
return "\\b".concat(colorName, "\\b");
|
|
3142
3160
|
}).join('|'), 'ig'); // 生成正则表达式来匹配这些colorName
|
|
3143
3161
|
|
|
3144
|
-
var colorReg =
|
|
3145
|
-
var colorRegGlobal =
|
|
3162
|
+
var colorReg = /\brgba?\([^)]+\)/i;
|
|
3163
|
+
var colorRegGlobal = /\brgba?\([^)]+\)/ig;
|
|
3146
3164
|
|
|
3147
3165
|
var removeImportant = function removeImportant(value) {
|
|
3148
3166
|
return value.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"], '');
|
|
3149
3167
|
}; // 清除!important
|
|
3150
3168
|
|
|
3151
3169
|
|
|
3152
|
-
var parseColor = function parseColor(value) {
|
|
3170
|
+
var parseColor = function parseColor(value, parseTransparent) {
|
|
3153
3171
|
return removeImportant(value).replace(colorNameReg, function (match) {
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
}; // 处理颜色,包括清除!important和转换英文定义颜色
|
|
3172
|
+
// 处理颜色,包括清除!important和转换英文定义颜色
|
|
3173
|
+
if (!parseTransparent && match === 'transparent') return match; // 如果不转换transparent,直接返回transparent
|
|
3157
3174
|
|
|
3175
|
+
var color = color_name__WEBPACK_IMPORTED_MODULE_1___default.a[match.toLowerCase()];
|
|
3176
|
+
return "".concat(color.length > 3 ? 'rgba' : 'rgb', "(").concat(color.toString(), ")");
|
|
3177
|
+
});
|
|
3178
|
+
};
|
|
3158
3179
|
|
|
3159
3180
|
var BG_COLOR_DELIMITER = '|'; // 计算mix颜色
|
|
3160
3181
|
|
|
@@ -3361,6 +3382,16 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3361
3382
|
extStyle: extStyle
|
|
3362
3383
|
};
|
|
3363
3384
|
}
|
|
3385
|
+
}, {
|
|
3386
|
+
key: "_try",
|
|
3387
|
+
value: function _try(func) {
|
|
3388
|
+
try {
|
|
3389
|
+
return func();
|
|
3390
|
+
} catch (e) {
|
|
3391
|
+
console.log('An error occurred when running the dark mode conversion algorithm\n', e);
|
|
3392
|
+
typeof this._config.error === 'function' && this._config.error(e);
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3364
3395
|
}, {
|
|
3365
3396
|
key: "convert",
|
|
3366
3397
|
value: function convert(el) {
|
|
@@ -3432,27 +3463,30 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3432
3463
|
|
|
3433
3464
|
if (_constant__WEBPACK_IMPORTED_MODULE_2__["TABLE_NAME"].indexOf(nodeName) > -1 && !hasInlineBackground) {
|
|
3434
3465
|
// 如果table没有内联样式
|
|
3435
|
-
|
|
3466
|
+
this._try(function () {
|
|
3467
|
+
var color = Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["hasTableClass"])(el); // 获取class对应的lm色值
|
|
3436
3468
|
|
|
3437
|
-
|
|
3469
|
+
if (!color) color = el.getAttribute('bgcolor'); // 如果没有class则获取bgcolor的色值
|
|
3438
3470
|
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3471
|
+
if (color) {
|
|
3472
|
+
// 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
|
|
3473
|
+
cssKVList.unshift(['background-color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
|
|
3474
|
+
hasInlineBackground = true;
|
|
3475
|
+
}
|
|
3476
|
+
});
|
|
3444
3477
|
}
|
|
3445
3478
|
|
|
3446
3479
|
if (nodeName === 'FONT' && !hasInlineColor) {
|
|
3447
3480
|
// 如果是font标签且没有内联样式
|
|
3448
|
-
|
|
3481
|
+
this._try(function () {
|
|
3482
|
+
var color = el.getAttribute('color'); // 获取color的色值
|
|
3449
3483
|
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
}
|
|
3484
|
+
if (color) {
|
|
3485
|
+
// 有色值,则当做内联样式来处理
|
|
3486
|
+
cssKVList.push(['color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
|
|
3487
|
+
hasInlineColor = true;
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3456
3490
|
} // 处理-webkit-text相关样式
|
|
3457
3491
|
|
|
3458
3492
|
|
|
@@ -3464,31 +3498,35 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3464
3498
|
key = _ref9[0],
|
|
3465
3499
|
value = _ref9[1];
|
|
3466
3500
|
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3501
|
+
return _this._try(function () {
|
|
3502
|
+
if (key.indexOf('-webkit-text') !== 0) {
|
|
3503
|
+
// 遍历到非-webkit-text样式
|
|
3504
|
+
webkitTextLen = idx; // 记录-webkit-text相关样式的长度
|
|
3470
3505
|
|
|
3471
|
-
|
|
3472
|
-
|
|
3506
|
+
return true; // 结束遍历
|
|
3507
|
+
}
|
|
3473
3508
|
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
// 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
|
|
3487
|
-
webkitStrokeColor = parseWebkitFillColorAndStrokeColor(value);
|
|
3488
|
-
break;
|
|
3489
|
-
}
|
|
3509
|
+
switch (key) {
|
|
3510
|
+
case '-webkit-text-fill-color':
|
|
3511
|
+
webkitFillColor = parseWebkitFillColorAndStrokeColor(value);
|
|
3512
|
+
break;
|
|
3513
|
+
|
|
3514
|
+
case '-webkit-text-stroke':
|
|
3515
|
+
{
|
|
3516
|
+
// 有-webkit-text-stroke时就不会有-webkit-text-stroke-color
|
|
3517
|
+
var newValue = value.split(' ');
|
|
3518
|
+
newValue.length === 2 && (webkitStrokeColor = parseWebkitFillColorAndStrokeColor(newValue[1]));
|
|
3519
|
+
break;
|
|
3520
|
+
}
|
|
3490
3521
|
|
|
3491
|
-
|
|
3522
|
+
case '-webkit-text-stroke-color':
|
|
3523
|
+
// 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
|
|
3524
|
+
webkitStrokeColor = parseWebkitFillColorAndStrokeColor(value);
|
|
3525
|
+
break;
|
|
3526
|
+
}
|
|
3527
|
+
|
|
3528
|
+
return false; // 继续遍历
|
|
3529
|
+
});
|
|
3492
3530
|
});
|
|
3493
3531
|
|
|
3494
3532
|
if (webkitFillColor) {
|
|
@@ -3514,154 +3552,160 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3514
3552
|
key = _ref11[0],
|
|
3515
3553
|
value = _ref11[1];
|
|
3516
3554
|
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
value = parseColor(value); // 找出色值来处理
|
|
3555
|
+
return _this._try(function () {
|
|
3556
|
+
var oldValue = value;
|
|
3557
|
+
var cssChange = false; // 找出色值来处理
|
|
3521
3558
|
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3559
|
+
var isBgColor = /^background/.test(key);
|
|
3560
|
+
var isTextShadow = key === 'text-shadow';
|
|
3561
|
+
var textColorIdx = ['-webkit-text-stroke-color', 'color', '-webkit-text-fill-color'].indexOf(key);
|
|
3562
|
+
var isBorderColor = /^border/.test(key);
|
|
3563
|
+
var isGradient = /gradient/.test(value);
|
|
3564
|
+
var gradientColors = [];
|
|
3565
|
+
var extStyle = '';
|
|
3566
|
+
var gradientMixColor; // 将英文定义颜色转换为rgb格式
|
|
3530
3567
|
|
|
3531
|
-
|
|
3532
|
-
if (isGradient) {
|
|
3533
|
-
// 把原渐变色取出来
|
|
3534
|
-
value.replace(colorRegGlobal, function (match) {
|
|
3535
|
-
return gradientColors.push(match);
|
|
3536
|
-
}); // 计算出一个mix颜色
|
|
3568
|
+
value = parseColor(value, isGradient); // 渐变需要处理透明
|
|
3537
3569
|
|
|
3538
|
-
|
|
3539
|
-
}
|
|
3540
|
-
|
|
3541
|
-
var replaceIndex = 0;
|
|
3542
|
-
value = value.replace(colorRegGlobal, function (match) {
|
|
3543
|
-
// 渐变色统一改成mix纯色
|
|
3570
|
+
if (colorReg.test(value)) {
|
|
3544
3571
|
if (isGradient) {
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
} // 使用颜色处理算法
|
|
3548
|
-
|
|
3572
|
+
// 把原渐变色取出来
|
|
3573
|
+
var matches = colorRegGlobal.exec(value);
|
|
3549
3574
|
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
isBorderColor: isBorderColor,
|
|
3555
|
-
hasInlineColor: hasInlineColor
|
|
3556
|
-
});
|
|
3575
|
+
while (matches) {
|
|
3576
|
+
gradientColors.push(matches[0]);
|
|
3577
|
+
matches = colorRegGlobal.exec(value);
|
|
3578
|
+
} // 计算出一个mix颜色
|
|
3557
3579
|
|
|
3558
|
-
var retColor = !hasInlineBackgroundImage && ret.newColor;
|
|
3559
|
-
extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
|
|
3560
3580
|
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
var attrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"];
|
|
3564
|
-
var originalAttrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"];
|
|
3565
|
-
var retColorStr = retColor ? retColor.toString() : match;
|
|
3566
|
-
replaceIndex === 0 && Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3567
|
-
var originalAttrValue = dom.getAttribute(originalAttrName) || _this._config.defaultLightBgColor;
|
|
3568
|
-
|
|
3569
|
-
dom.setAttribute(attrName, retColorStr);
|
|
3570
|
-
dom.setAttribute(originalAttrName, originalAttrValue.split(BG_COLOR_DELIMITER).concat(match).join(BG_COLOR_DELIMITER)); // 如果设置背景颜色,取消背景图片的影响
|
|
3581
|
+
gradientMixColor = mixColor(gradientColors);
|
|
3582
|
+
}
|
|
3571
3583
|
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3584
|
+
var replaceIndex = 0;
|
|
3585
|
+
value = value.replace(colorRegGlobal, function (match) {
|
|
3586
|
+
// 渐变色统一改成mix纯色
|
|
3587
|
+
if (isGradient) {
|
|
3588
|
+
match = gradientMixColor;
|
|
3589
|
+
cssChange = true;
|
|
3590
|
+
} // 使用颜色处理算法
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
var ret = _this._adjustBrightness(color__WEBPACK_IMPORTED_MODULE_0___default()(match), el, {
|
|
3594
|
+
isBgColor: isBgColor,
|
|
3595
|
+
isTextShadow: isTextShadow,
|
|
3596
|
+
isTextColor: textColorIdx > -1,
|
|
3597
|
+
isBorderColor: isBorderColor,
|
|
3598
|
+
hasInlineColor: hasInlineColor
|
|
3575
3599
|
});
|
|
3576
|
-
}
|
|
3577
3600
|
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
return retColor || match;
|
|
3581
|
-
}).replace(/\s?!\s?important/ig, '');
|
|
3582
|
-
}
|
|
3601
|
+
var retColor = !hasInlineBackgroundImage && ret.newColor;
|
|
3602
|
+
extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
|
|
3583
3603
|
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3604
|
+
if (isBgColor || textColorIdx > 0) {
|
|
3605
|
+
// 不处理-webkit-text-stroke-color
|
|
3606
|
+
var attrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"];
|
|
3607
|
+
var originalAttrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"];
|
|
3608
|
+
var retColorStr = retColor ? retColor.toString() : match;
|
|
3609
|
+
replaceIndex === 0 && Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3610
|
+
var originalAttrValue = dom.getAttribute(originalAttrName) || _this._config.defaultLightBgColor;
|
|
3587
3611
|
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
|
|
3595
|
-
cssChange = true;
|
|
3596
|
-
var imgBgColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]) || _this._config.defaultLightBgColor).split(BG_COLOR_DELIMITER)); // 在背景图片下加一层原背景颜色:
|
|
3597
|
-
// background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering);
|
|
3598
|
-
// border-image不支持多层背景,需要添加background-color
|
|
3599
|
-
|
|
3600
|
-
value = value.replace(/^(.*?)url\(([^)]*)\)(.*)$/i, function (matches) {
|
|
3601
|
-
var newValue = matches;
|
|
3602
|
-
var newBackgroundPositionValue = '';
|
|
3603
|
-
var newBackgroundSizeValue = '';
|
|
3604
|
-
var tmpCssKvStr = '';
|
|
3605
|
-
|
|
3606
|
-
if (el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]) !== '1') {
|
|
3607
|
-
// 避免重复setAttribute
|
|
3608
|
-
Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3609
|
-
return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"], '1');
|
|
3612
|
+
dom.setAttribute(attrName, retColorStr);
|
|
3613
|
+
dom.setAttribute(originalAttrName, originalAttrValue.split(BG_COLOR_DELIMITER).concat(match).join(BG_COLOR_DELIMITER)); // 如果设置背景颜色,取消背景图片的影响
|
|
3614
|
+
|
|
3615
|
+
if (isBgColor && color__WEBPACK_IMPORTED_MODULE_0___default()(retColorStr).alpha() >= 0.05 && dom.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"])) {
|
|
3616
|
+
dom.removeAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]);
|
|
3617
|
+
}
|
|
3610
3618
|
});
|
|
3611
|
-
}
|
|
3619
|
+
}
|
|
3612
3620
|
|
|
3621
|
+
retColor && (cssChange = true);
|
|
3622
|
+
replaceIndex += 1;
|
|
3623
|
+
return retColor || match;
|
|
3624
|
+
}).replace(/\s?!\s?important/ig, '');
|
|
3625
|
+
}
|
|
3613
3626
|
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3627
|
+
if (extStyle) {
|
|
3628
|
+
cssKV += extStyle;
|
|
3629
|
+
}
|
|
3617
3630
|
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3631
|
+
if (!(el instanceof SVGElement)) {
|
|
3632
|
+
// 先不处理SVG
|
|
3633
|
+
// 背景图片、边框图片
|
|
3634
|
+
var isBackgroundAttr = /^background/.test(key);
|
|
3635
|
+
var isBorderImageAttr = /^(-webkit-)?border-image/.test(key);
|
|
3623
3636
|
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3637
|
+
if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
|
|
3638
|
+
cssChange = true;
|
|
3639
|
+
var imgBgColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]) || _this._config.defaultLightBgColor).split(BG_COLOR_DELIMITER)); // 在背景图片下加一层原背景颜色:
|
|
3640
|
+
// background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering);
|
|
3641
|
+
// border-image不支持多层背景,需要添加background-color
|
|
3642
|
+
|
|
3643
|
+
value = value.replace(/^(.*?)url\(([^)]*)\)(.*)$/i, function (matches) {
|
|
3644
|
+
var newValue = matches;
|
|
3645
|
+
var newBackgroundPositionValue = '';
|
|
3646
|
+
var newBackgroundSizeValue = '';
|
|
3647
|
+
var tmpCssKvStr = '';
|
|
3648
|
+
|
|
3649
|
+
if (el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]) !== '1') {
|
|
3650
|
+
// 避免重复setAttribute
|
|
3651
|
+
Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3652
|
+
return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"], '1');
|
|
3653
|
+
});
|
|
3654
|
+
} // background-image
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
if (isBackgroundAttr) {
|
|
3658
|
+
newValue = "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),").concat(matches);
|
|
3659
|
+
tmpCssKvStr = _this._cssUtils.genCssKV(key, "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"));
|
|
3660
|
+
|
|
3661
|
+
if (elBackgroundPositionAttr) {
|
|
3662
|
+
newBackgroundPositionValue = "top left,".concat(elBackgroundPositionAttr);
|
|
3663
|
+
cssKV += _this._cssUtils.genCssKV('background-position', "".concat(newBackgroundPositionValue));
|
|
3664
|
+
tmpCssKvStr += _this._cssUtils.genCssKV('background-position', "".concat(newBackgroundPositionValue, ",top left"));
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
if (elBackgroundSizeAttr) {
|
|
3668
|
+
newBackgroundSizeValue = "100%,".concat(elBackgroundSizeAttr);
|
|
3669
|
+
cssKV += _this._cssUtils.genCssKV('background-size', "".concat(newBackgroundSizeValue));
|
|
3670
|
+
tmpCssKvStr += _this._cssUtils.genCssKV('background-size', "".concat(newBackgroundSizeValue, ",100%"));
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
_this._bgStack.push(el, tmpCssKvStr); // 背景图入栈
|
|
3674
|
+
|
|
3675
|
+
} else {
|
|
3676
|
+
// border-image元素,如果当前元素没有背景颜色,补背景颜色
|
|
3677
|
+
!hasInlineBackground && _this._bgStack.push(el, _this._cssUtils.genCssKV('background-image', "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"))); // 背景图入栈
|
|
3628
3678
|
}
|
|
3629
3679
|
|
|
3630
|
-
|
|
3680
|
+
return newValue;
|
|
3681
|
+
}); // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
|
|
3631
3682
|
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3683
|
+
if (!hasInlineColor) {
|
|
3684
|
+
var textColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]) || _this._config.defaultLightTextColor).split(BG_COLOR_DELIMITER));
|
|
3685
|
+
cssKV += _this._cssUtils.genCssKV('color', textColor);
|
|
3686
|
+
Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3687
|
+
return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"], textColor);
|
|
3688
|
+
});
|
|
3635
3689
|
}
|
|
3636
|
-
|
|
3637
|
-
return newValue;
|
|
3638
|
-
}); // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
|
|
3639
|
-
|
|
3640
|
-
if (!hasInlineColor) {
|
|
3641
|
-
var textColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]) || _this._config.defaultLightTextColor).split(BG_COLOR_DELIMITER));
|
|
3642
|
-
cssKV += _this._cssUtils.genCssKV('color', textColor);
|
|
3643
|
-
Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3644
|
-
return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"], textColor);
|
|
3645
|
-
});
|
|
3646
3690
|
}
|
|
3647
3691
|
}
|
|
3648
|
-
}
|
|
3649
3692
|
|
|
3650
|
-
|
|
3651
|
-
|
|
3693
|
+
if (cssChange) {
|
|
3694
|
+
_constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] = removeImportant(oldValue)); // 清除inline style的!important
|
|
3652
3695
|
|
|
3653
|
-
|
|
3654
|
-
|
|
3696
|
+
if (isGradient) {
|
|
3697
|
+
_this._bgStack.push(el, _this._cssUtils.genCssKV(key, value)); // 渐变入栈
|
|
3655
3698
|
|
|
3656
|
-
|
|
3657
|
-
|
|
3699
|
+
} else {
|
|
3700
|
+
cssKV += _this._cssUtils.genCssKV(key, value);
|
|
3701
|
+
}
|
|
3658
3702
|
}
|
|
3659
|
-
}
|
|
3703
|
+
});
|
|
3660
3704
|
});
|
|
3661
3705
|
|
|
3662
3706
|
if (cssKV) {
|
|
3663
3707
|
// 有处理过或者是背景图片就加class以及css
|
|
3664
|
-
|
|
3708
|
+
el.setAttribute('data-style', styles.cssText); // 备份内联样式到data-style里,供编辑器做反处理
|
|
3665
3709
|
|
|
3666
3710
|
var className = "".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["CLASS_PREFIX"]).concat(this._idx++);
|
|
3667
3711
|
el.classList.add(className);
|