mp-darkmode 1.1.9 → 1.2.0-beta.0
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 +484 -271
- package/dist/darkmode.js.map +1 -1
- package/dist/darkmode.min.js +1 -1
- package/package.json +2 -1
package/dist/darkmode.js
CHANGED
|
@@ -96,6 +96,37 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
96
96
|
/************************************************************************/
|
|
97
97
|
/******/ ({
|
|
98
98
|
|
|
99
|
+
/***/ "./node_modules/color-blend/dist/index.modern.js":
|
|
100
|
+
/*!*******************************************************!*\
|
|
101
|
+
!*** ./node_modules/color-blend/dist/index.modern.js ***!
|
|
102
|
+
\*******************************************************/
|
|
103
|
+
/*! exports provided: color, colorBurn, colorDodge, darken, difference, exclusion, hardLight, hue, lighten, luminosity, multiply, normal, overlay, saturation, screen, softLight */
|
|
104
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
105
|
+
|
|
106
|
+
"use strict";
|
|
107
|
+
__webpack_require__.r(__webpack_exports__);
|
|
108
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "color", function() { return R; });
|
|
109
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "colorBurn", function() { return H; });
|
|
110
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "colorDodge", function() { return G; });
|
|
111
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "darken", function() { return E; });
|
|
112
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "difference", function() { return L; });
|
|
113
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "exclusion", function() { return N; });
|
|
114
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hardLight", function() { return J; });
|
|
115
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hue", function() { return P; });
|
|
116
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "lighten", function() { return F; });
|
|
117
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "luminosity", function() { return S; });
|
|
118
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "multiply", function() { return B; });
|
|
119
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "normal", function() { return A; });
|
|
120
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "overlay", function() { return D; });
|
|
121
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "saturation", function() { return Q; });
|
|
122
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "screen", function() { return C; });
|
|
123
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "softLight", function() { return K; });
|
|
124
|
+
function n(n,r,t){return{r:255*t(n.r/255,r.r/255),g:255*t(n.g/255,r.g/255),b:255*t(n.b/255,r.b/255)}}function r(n,r){return r}function t(n,r){return n*r}function u(n,r){return n+r-n*r}function i(n,r){return a(r,n)}function o(n,r){return Math.min(n,r)}function e(n,r){return Math.min(Math.max(n,r),1)}function c(n,r){return 0===n?0:1===r?1:Math.min(1,n/(1-r))}function f(n,r){return 1===n?1:0===r?0:1-Math.min(1,(1-n)/r)}function a(n,r){return r<=.5?t(n,2*r):u(n,2*r-1)}function b(n,r){return r<=.5?n-(1-2*r)*n*(1-n):n+(2*r-1)*((n<=.25?((16*n-12)*n+4)*n:Math.sqrt(n))-n)}function g(n,r){return Math.abs(n-r)}function h(n,r){return n+r-2*n*r}function M(n,r,t){return Math.min(Math.max(n||0,r),t)}function m(n){return{r:M(n.r,0,255),g:M(n.g,0,255),b:M(n.b,0,255),a:M(n.a,0,1)}}function d(n){return{r:255*n.r,g:255*n.g,b:255*n.b,a:n.a}}function p(n){return{r:n.r/255,g:n.g/255,b:n.b/255,a:n.a}}function v(n,r){void 0===r&&(r=0);var t=Math.pow(10,r);return{r:Math.round(n.r*t)/t,g:Math.round(n.g*t)/t,b:Math.round(n.b*t)/t,a:n.a}}function x(n,r,t,u,i,o){return(1-r/t)*u+r/t*Math.round((1-n)*i+n*o)}function O(n,r,t,u,i){void 0===i&&(i={unitInput:!1,unitOutput:!1,roundOutput:!0}),i.unitInput&&(n=d(n),r=d(r)),n=m(n);var o=(r=m(r)).a+n.a-r.a*n.a,e=t(n,r,u),c=m({r:x(n.a,r.a,o,n.r,r.r,e.r),g:x(n.a,r.a,o,n.g,r.g,e.g),b:x(n.a,r.a,o,n.b,r.b,e.b),a:o});return c=i.unitOutput?p(c):i.roundOutput?v(c):function(n){return v(n,9)}(c),c}function s(n,r,t){return d(t(p(n),p(r)))}function I(n){return.3*n.r+.59*n.g+.11*n.b}function q(n,r){var t=r-I(n);return function(n){var r=I(n),t=n.r,u=n.g,i=n.b,o=Math.min(t,u,i),e=Math.max(t,u,i);function c(n){return r+(n-r)*r/(r-o)}function f(n){return r+(n-r)*(1-r)/(e-r)}return o<0&&(t=c(t),u=c(u),i=c(i)),e>1&&(t=f(t),u=f(u),i=f(i)),{r:t,g:u,b:i}}({r:n.r+t,g:n.g+t,b:n.b+t})}function w(n){return Math.max(n.r,n.g,n.b)-Math.min(n.r,n.g,n.b)}function j(n,r){var t=["r","g","b"].sort(function(r,t){return n[r]-n[t]}),u=t[0],i=t[1],o=t[2],e={r:n.r,g:n.g,b:n.b};return e[o]>e[u]?(e[i]=(e[i]-e[u])*r/(e[o]-e[u]),e[o]=r):e[i]=e[o]=0,e[u]=0,e}function k(n,r){return q(j(r,w(n)),I(n))}function l(n,r){return q(j(n,w(r)),I(n))}function y(n,r){return q(r,I(n))}function z(n,r){return q(n,I(r))}function A(t,u){return O(t,u,n,r)}function B(r,u){return O(r,u,n,t)}function C(r,t){return O(r,t,n,u)}function D(r,t){return O(r,t,n,i)}function E(r,t){return O(r,t,n,o)}function F(r,t){return O(r,t,n,e)}function G(r,t){return O(r,t,n,c)}function H(r,t){return O(r,t,n,f)}function J(r,t){return O(r,t,n,a)}function K(r,t){return O(r,t,n,b)}function L(r,t){return O(r,t,n,g)}function N(r,t){return O(r,t,n,h)}function P(n,r){return O(n,r,s,k)}function Q(n,r){return O(n,r,s,l)}function R(n,r){return O(n,r,s,y)}function S(n,r){return O(n,r,s,z)}
|
|
125
|
+
//# sourceMappingURL=index.modern.js.map
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/***/ }),
|
|
129
|
+
|
|
99
130
|
/***/ "./node_modules/color-convert/conversions.js":
|
|
100
131
|
/*!***************************************************!*\
|
|
101
132
|
!*** ./node_modules/color-convert/conversions.js ***!
|
|
@@ -2329,9 +2360,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2329
2360
|
/**
|
|
2330
2361
|
* @name Darkmode主入口
|
|
2331
2362
|
*
|
|
2332
|
-
* @function run
|
|
2363
|
+
* @function run 初始化Dark Mode配置并运行Dark Mode处理
|
|
2333
2364
|
* @param {DOM Object Array} nodes 要处理的节点列表
|
|
2334
2365
|
* @param {Object} opt Dark Mode配置,详见init配置说明
|
|
2366
|
+
* @return void
|
|
2335
2367
|
*
|
|
2336
2368
|
* @function init 初始化Dark Mode配置
|
|
2337
2369
|
* @param {Function} opt.begin 开始处理时触发的回调
|
|
@@ -2349,23 +2381,28 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2349
2381
|
* @param {string} opt.defaultLightBgColor 非Dark Mode下背景颜色
|
|
2350
2382
|
* @param {string} opt.defaultDarkTextColor Dark Mode下字体颜色
|
|
2351
2383
|
* @param {string} opt.defaultDarkBgColor Dark Mode下背景颜色
|
|
2384
|
+
* @return void
|
|
2352
2385
|
*
|
|
2353
2386
|
* @function convertBg 处理背景
|
|
2354
2387
|
* @param {DOM Object Array} nodes 要处理的节点列表
|
|
2388
|
+
* @return void
|
|
2355
2389
|
*
|
|
2356
2390
|
* @function updateStyle 更新节点Dark Mode样式
|
|
2357
2391
|
* @param {DOM Object} node 要更新的节点
|
|
2358
2392
|
* @param {Object} styles 更新的样式键值对对象,如:{ color: '#ddd' }
|
|
2393
|
+
* @return void
|
|
2359
2394
|
*
|
|
2360
2395
|
* @function getContrast 获取两个颜色的对比度
|
|
2361
2396
|
* @param {string} color1 要计算颜色对比度的颜色1,支持css颜色格式
|
|
2362
2397
|
* @param {string} color2 要计算颜色对比度的颜色2,支持css颜色格式
|
|
2363
|
-
* @return {number}
|
|
2398
|
+
* @return {number} 颜色对比度,取值范围为`[1, 21]`
|
|
2364
2399
|
*
|
|
2365
2400
|
* @function extend 挂载插件
|
|
2366
2401
|
* @param {Array} pluginList 插件列表
|
|
2402
|
+
* @return void
|
|
2367
2403
|
*
|
|
2368
2404
|
*/
|
|
2405
|
+
// 常量
|
|
2369
2406
|
|
|
2370
2407
|
var classReg = new RegExp("".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "[^ ]+"), 'g'); // Darkmode配置
|
|
2371
2408
|
|
|
@@ -2462,7 +2499,8 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
|
|
|
2462
2499
|
console.log('An error occurred when running the dark mode conversion algorithm\n', e);
|
|
2463
2500
|
typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error(e);
|
|
2464
2501
|
}
|
|
2465
|
-
};
|
|
2502
|
+
}; // 初始化Dark Mode配置并运行Dark Mode处理
|
|
2503
|
+
|
|
2466
2504
|
|
|
2467
2505
|
function run(nodes, opt) {
|
|
2468
2506
|
init(opt); // 初始化配置
|
|
@@ -2473,7 +2511,8 @@ function run(nodes, opt) {
|
|
|
2473
2511
|
type: 'dom'
|
|
2474
2512
|
});
|
|
2475
2513
|
}
|
|
2476
|
-
;
|
|
2514
|
+
; // 初始化Dark Mode配置
|
|
2515
|
+
|
|
2477
2516
|
function init() {
|
|
2478
2517
|
var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2479
2518
|
if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].hasInit) return; // 只可设置一次配置
|
|
@@ -2517,7 +2556,8 @@ function init() {
|
|
|
2517
2556
|
mql.addListener(switchToDarkmode); // 监听
|
|
2518
2557
|
}
|
|
2519
2558
|
}
|
|
2520
|
-
;
|
|
2559
|
+
; // 处理背景
|
|
2560
|
+
|
|
2521
2561
|
function convertBg(nodes) {
|
|
2522
2562
|
_modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].set(nodes);
|
|
2523
2563
|
|
|
@@ -2532,7 +2572,8 @@ function convertBg(nodes) {
|
|
|
2532
2572
|
type: 'bg'
|
|
2533
2573
|
});
|
|
2534
2574
|
}
|
|
2535
|
-
;
|
|
2575
|
+
; // 更新节点Dark Mode样式
|
|
2576
|
+
|
|
2536
2577
|
function updateStyle(node, styles) {
|
|
2537
2578
|
if (!_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].isFinish) return; // 没有运行过Dark Mode处理逻辑则无需运行
|
|
2538
2579
|
|
|
@@ -2541,11 +2582,13 @@ function updateStyle(node, styles) {
|
|
|
2541
2582
|
}) : undefined, true), false);
|
|
2542
2583
|
_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle();
|
|
2543
2584
|
}
|
|
2544
|
-
;
|
|
2585
|
+
; // 获取两个颜色的对比度
|
|
2586
|
+
|
|
2545
2587
|
function getContrast(color1, color2) {
|
|
2546
2588
|
return _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].getContrast(color1, color2);
|
|
2547
2589
|
}
|
|
2548
|
-
;
|
|
2590
|
+
; // 挂载插件
|
|
2591
|
+
|
|
2549
2592
|
function extend(pluginList) {
|
|
2550
2593
|
pluginList.forEach(function (plugin) {
|
|
2551
2594
|
return _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].extend(plugin);
|
|
@@ -2585,13 +2628,16 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2585
2628
|
* @method push 背景节点入栈
|
|
2586
2629
|
* @param {DOM Object} el 背景节点对象
|
|
2587
2630
|
* @param {string} cssKV css键值对
|
|
2631
|
+
* @return void
|
|
2588
2632
|
*
|
|
2589
2633
|
* @method contains 判断节点是否在背景节点的区域
|
|
2590
2634
|
* @param {DOM Object} el 要判断的节点对象(非背景节点)
|
|
2591
2635
|
* @param {Function} callback 如果在背景节点区域内,则执行该回调函数
|
|
2636
|
+
* @return void
|
|
2592
2637
|
*
|
|
2593
2638
|
* @method update 更新堆栈的节点对象,主要解决前后节点不一致的问题
|
|
2594
2639
|
* @param {DOM Object Array} els 要更新的节点对象列表
|
|
2640
|
+
* @return void
|
|
2595
2641
|
*
|
|
2596
2642
|
*/
|
|
2597
2643
|
// Darkmode配置
|
|
@@ -2609,11 +2655,12 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2609
2655
|
|
|
2610
2656
|
this._prefix = prefix;
|
|
2611
2657
|
this.classNameReg = new RegExp("".concat(this._prefix, "\\d+"));
|
|
2612
|
-
}
|
|
2658
|
+
} // 背景节点入栈
|
|
2659
|
+
|
|
2613
2660
|
|
|
2614
2661
|
_createClass(BgNodeStack, [{
|
|
2615
2662
|
key: "push",
|
|
2616
|
-
value: function push(el, cssKV) {
|
|
2663
|
+
value: function push(el, cssKV, cb) {
|
|
2617
2664
|
var className = "".concat(this._prefix).concat(this._idx++);
|
|
2618
2665
|
el.classList.add(className);
|
|
2619
2666
|
|
|
@@ -2621,9 +2668,11 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2621
2668
|
el: el,
|
|
2622
2669
|
className: className,
|
|
2623
2670
|
cssKV: cssKV,
|
|
2624
|
-
updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge
|
|
2671
|
+
updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge,
|
|
2672
|
+
cb: cb
|
|
2625
2673
|
});
|
|
2626
|
-
}
|
|
2674
|
+
} // 判断节点是否在背景节点的区域
|
|
2675
|
+
|
|
2627
2676
|
}, {
|
|
2628
2677
|
key: "contains",
|
|
2629
2678
|
value: function contains(el, callback) {
|
|
@@ -2647,7 +2696,8 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2647
2696
|
|
|
2648
2697
|
typeof callback === 'function' && callback(item);
|
|
2649
2698
|
}
|
|
2650
|
-
}
|
|
2699
|
+
} // 更新堆栈的节点对象,主要解决前后节点不一致的问题
|
|
2700
|
+
|
|
2651
2701
|
}, {
|
|
2652
2702
|
key: "update",
|
|
2653
2703
|
value: function update(els) {
|
|
@@ -2675,6 +2725,164 @@ var BgNodeStack = /*#__PURE__*/function () {
|
|
|
2675
2725
|
|
|
2676
2726
|
/***/ }),
|
|
2677
2727
|
|
|
2728
|
+
/***/ "./src/modules/color.js":
|
|
2729
|
+
/*!******************************!*\
|
|
2730
|
+
!*** ./src/modules/color.js ***!
|
|
2731
|
+
\******************************/
|
|
2732
|
+
/*! exports provided: ColorParser, parseColorName, parseWebkitFillColorAndStrokeColor, mixColors, getColorPerceivedBrightness, adjustBrightnessTo */
|
|
2733
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2734
|
+
|
|
2735
|
+
"use strict";
|
|
2736
|
+
__webpack_require__.r(__webpack_exports__);
|
|
2737
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ColorParser", function() { return ColorParser; });
|
|
2738
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseColorName", function() { return parseColorName; });
|
|
2739
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseWebkitFillColorAndStrokeColor", function() { return parseWebkitFillColorAndStrokeColor; });
|
|
2740
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mixColors", function() { return mixColors; });
|
|
2741
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getColorPerceivedBrightness", function() { return getColorPerceivedBrightness; });
|
|
2742
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "adjustBrightnessTo", function() { return adjustBrightnessTo; });
|
|
2743
|
+
/* harmony import */ var color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! color */ "./node_modules/color/index.js");
|
|
2744
|
+
/* harmony import */ var color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(color__WEBPACK_IMPORTED_MODULE_0__);
|
|
2745
|
+
/* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js");
|
|
2746
|
+
/* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(color_name__WEBPACK_IMPORTED_MODULE_1__);
|
|
2747
|
+
/* harmony import */ var color_blend__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! color-blend */ "./node_modules/color-blend/dist/index.modern.js");
|
|
2748
|
+
/* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
|
|
2749
|
+
/**
|
|
2750
|
+
* @name 颜色操作相关API
|
|
2751
|
+
*
|
|
2752
|
+
* @function ColorParser 实例化Color对象,传参非法时返回null
|
|
2753
|
+
* @param {string} color css色值
|
|
2754
|
+
* @return {Color Object | null} 实例化结果
|
|
2755
|
+
*
|
|
2756
|
+
* @function parseColorName 处理颜色,包括清除!important和转换英文定义颜色
|
|
2757
|
+
* @param {string} color css色值
|
|
2758
|
+
* @param {boolean} supportTransparent 是否支持转换transparent
|
|
2759
|
+
* @return {string} 处理后的rgb(a)格式css色值
|
|
2760
|
+
*
|
|
2761
|
+
* @function parseWebkitFillColorAndStrokeColor 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
|
|
2762
|
+
* @param {string} color css色值
|
|
2763
|
+
* @return {string} 处理后的rgb(a)格式css色值,无则返回空字符串
|
|
2764
|
+
*
|
|
2765
|
+
* @function mixColors 计算混合颜色
|
|
2766
|
+
* @param {string} colors 用于计算的颜色数组
|
|
2767
|
+
* @param {string} type 使用的混合颜色算法,支持 mix(默认) | normal | multiply | screen | overlay | darken | lighten | colorDodge | colorBurn | hardLight | softLight | difference | exclusion | hue | saturation | color | luminosity
|
|
2768
|
+
* @return {Color Object | null} 混合结果
|
|
2769
|
+
*
|
|
2770
|
+
* @function getColorPerceivedBrightness 计算感知亮度
|
|
2771
|
+
* @param {RGB Array} rgb 要计算的颜色rgb数组,如:[255, 0, 0]
|
|
2772
|
+
* @return {number} 感知亮度
|
|
2773
|
+
*
|
|
2774
|
+
* @function adjustBrightnessTo 调整为指定感知亮度
|
|
2775
|
+
* @param {number} target 指定的感知亮度值
|
|
2776
|
+
* @param {RGB Array} rgb 要调整的颜色rgb数组,如:[255, 0, 0]
|
|
2777
|
+
* @return {Color Object} 调整后的颜色
|
|
2778
|
+
*
|
|
2779
|
+
*/
|
|
2780
|
+
|
|
2781
|
+
|
|
2782
|
+
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
|
|
2783
|
+
|
|
2784
|
+
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255, 0]; // 支持透明,暂定用白色透明度0来表示
|
|
2785
|
+
|
|
2786
|
+
// 常量
|
|
2787
|
+
|
|
2788
|
+
|
|
2789
|
+
var COLOR_NAME_REG = new RegExp(Object.keys(color_name__WEBPACK_IMPORTED_MODULE_1___default.a).map(function (colorName) {
|
|
2790
|
+
return "\\b".concat(colorName, "\\b");
|
|
2791
|
+
}).join('|'), 'ig'); // 生成正则表达式来匹配这些colorName
|
|
2792
|
+
// Color对象 => ColorBlend对象
|
|
2793
|
+
|
|
2794
|
+
var color2ColorBlend = function color2ColorBlend(color) {
|
|
2795
|
+
var obj = color.object();
|
|
2796
|
+
obj.a = obj.alpha || 1;
|
|
2797
|
+
delete obj.alpha;
|
|
2798
|
+
return obj;
|
|
2799
|
+
}; // ColorBlend对象 => Color对象
|
|
2800
|
+
|
|
2801
|
+
|
|
2802
|
+
var colorBlend2Color = function colorBlend2Color(colorBlend) {
|
|
2803
|
+
colorBlend.alpha = colorBlend.a;
|
|
2804
|
+
delete colorBlend.a;
|
|
2805
|
+
return ColorParser(colorBlend);
|
|
2806
|
+
}; // 实例化Color对象,传参非法时返回null
|
|
2807
|
+
|
|
2808
|
+
|
|
2809
|
+
var ColorParser = function ColorParser(color) {
|
|
2810
|
+
var res = null;
|
|
2811
|
+
|
|
2812
|
+
try {
|
|
2813
|
+
res = color instanceof color__WEBPACK_IMPORTED_MODULE_0___default.a ? color : color__WEBPACK_IMPORTED_MODULE_0___default()(color);
|
|
2814
|
+
} catch (e) {
|
|
2815
|
+
console.log("ignore the invalid color: `".concat(color, "`"));
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
return res;
|
|
2819
|
+
}; // 处理颜色,包括清除!important和转换英文定义颜色
|
|
2820
|
+
|
|
2821
|
+
var parseColorName = function parseColorName(color, supportTransparent) {
|
|
2822
|
+
return color.replace(_constant__WEBPACK_IMPORTED_MODULE_3__["IMPORTANT_REGEXP"], '').replace(COLOR_NAME_REG, function (match) {
|
|
2823
|
+
if (!supportTransparent && match === 'transparent') return match; // 如果不支持转换transparent,直接返回transparent
|
|
2824
|
+
|
|
2825
|
+
var color = color_name__WEBPACK_IMPORTED_MODULE_1___default.a[match.toLowerCase()];
|
|
2826
|
+
return "".concat(color.length > 3 ? 'rgba' : 'rgb', "(").concat(color.toString(), ")");
|
|
2827
|
+
});
|
|
2828
|
+
}; // 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
|
|
2829
|
+
|
|
2830
|
+
var parseWebkitFillColorAndStrokeColor = function parseWebkitFillColorAndStrokeColor(color) {
|
|
2831
|
+
var newValue = parseColorName(color);
|
|
2832
|
+
return _constant__WEBPACK_IMPORTED_MODULE_3__["COLOR_REGEXP"].test(newValue) ? newValue : '';
|
|
2833
|
+
}; // 计算混合颜色
|
|
2834
|
+
|
|
2835
|
+
var mixColors = function mixColors(colors) {
|
|
2836
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'mix';
|
|
2837
|
+
if (Object.prototype.toString.call(colors) !== '[object Array]' || colors.length < 1) return null;
|
|
2838
|
+
if (colors.length === 1) return colors[0];
|
|
2839
|
+
var color1 = ColorParser(colors.shift());
|
|
2840
|
+
var color2 = ColorParser(colors.shift());
|
|
2841
|
+
|
|
2842
|
+
while (color2) {
|
|
2843
|
+
if (!color1 && color2) {
|
|
2844
|
+
// 如果当前色值非法,混入色值合法,则直接使用混入色值
|
|
2845
|
+
color1 = color2;
|
|
2846
|
+
} else if (!color1 && !color2) {
|
|
2847
|
+
// 如果两个色值都非法,则使用下一批色值
|
|
2848
|
+
if (colors.length === 0) break;
|
|
2849
|
+
color1 = ColorParser(colors.shift());
|
|
2850
|
+
} else if (color1 && color2) {
|
|
2851
|
+
// 如果两个色值都合法,执行mix
|
|
2852
|
+
color1 = type === 'mix' ? color1.mix(color2, color2.alpha()) : colorBlend2Color(color_blend__WEBPACK_IMPORTED_MODULE_2__[type](color2ColorBlend(color1), color2ColorBlend(color2)));
|
|
2853
|
+
} // 如果当前色值合法,混入色值非法,无需处理
|
|
2854
|
+
|
|
2855
|
+
|
|
2856
|
+
if (colors.length === 0) break;
|
|
2857
|
+
color2 = ColorParser(colors.shift());
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
return color1 || null;
|
|
2861
|
+
}; // 计算感知亮度
|
|
2862
|
+
|
|
2863
|
+
var getColorPerceivedBrightness = function getColorPerceivedBrightness(rgb) {
|
|
2864
|
+
return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
|
2865
|
+
}; // 调整为指定感知亮度
|
|
2866
|
+
|
|
2867
|
+
var adjustBrightnessTo = function adjustBrightnessTo(target, rgb) {
|
|
2868
|
+
var relativeBrightnessRatio = target / getColorPerceivedBrightness(rgb);
|
|
2869
|
+
var newTextR = Math.min(255, rgb[0] * relativeBrightnessRatio);
|
|
2870
|
+
var newTextG = Math.min(255, rgb[1] * relativeBrightnessRatio);
|
|
2871
|
+
var newTextB = Math.min(255, rgb[2] * relativeBrightnessRatio);
|
|
2872
|
+
|
|
2873
|
+
if (newTextG === 0 || newTextR === 255 || newTextB === 255) {
|
|
2874
|
+
newTextG = (target * 1000 - newTextR * 299 - newTextB * 114) / 587;
|
|
2875
|
+
} else if (newTextR === 0) {
|
|
2876
|
+
newTextR = (target * 1000 - newTextG * 587 - newTextB * 114) / 299;
|
|
2877
|
+
} else if (newTextB === 0 || newTextG === 255) {
|
|
2878
|
+
newTextB = (target * 1000 - newTextR * 299 - newTextG * 587) / 114;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
return color__WEBPACK_IMPORTED_MODULE_0___default.a.rgb(newTextR, newTextG, newTextB);
|
|
2882
|
+
};
|
|
2883
|
+
|
|
2884
|
+
/***/ }),
|
|
2885
|
+
|
|
2678
2886
|
/***/ "./src/modules/config.js":
|
|
2679
2887
|
/*!*******************************!*\
|
|
2680
2888
|
!*** ./src/modules/config.js ***!
|
|
@@ -2695,6 +2903,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2695
2903
|
* @attr {string} mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
|
|
2696
2904
|
* @attr {Object} whitelist 节点白名单
|
|
2697
2905
|
* @attr {string Array} whitelist.tagName 标签名列表
|
|
2906
|
+
* @attr {string Array} whitelist.attribute 属性列表
|
|
2698
2907
|
* @attr {boolean} needJudgeFirstPage 是否需要判断首屏
|
|
2699
2908
|
* @attr {boolean} delayBgJudge 是否延迟背景判断
|
|
2700
2909
|
* @attr {DOM Object} container 延迟运行js时使用的容器
|
|
@@ -2708,28 +2917,46 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2708
2917
|
* @param {string} type 要处理的节点
|
|
2709
2918
|
* @param {Object} opt 传入的配置对象
|
|
2710
2919
|
* @param {string} key 配置名
|
|
2920
|
+
* @return void
|
|
2711
2921
|
*
|
|
2712
2922
|
*/
|
|
2923
|
+
// 常量
|
|
2713
2924
|
|
|
2714
2925
|
var config = {
|
|
2715
2926
|
hasInit: false,
|
|
2927
|
+
// 是否初始化过配置
|
|
2716
2928
|
// hooks
|
|
2717
2929
|
begin: null,
|
|
2930
|
+
// 开始处理时触发的回调
|
|
2718
2931
|
showFirstPage: null,
|
|
2932
|
+
// 首屏处理完成时触发的回调
|
|
2719
2933
|
error: null,
|
|
2934
|
+
// 发生error时触发的回调
|
|
2720
2935
|
mode: '',
|
|
2936
|
+
// 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
|
|
2721
2937
|
whitelist: {
|
|
2938
|
+
// 节点白名单
|
|
2722
2939
|
tagName: ['MPCPS', 'IFRAME'],
|
|
2723
|
-
|
|
2940
|
+
// 标签名列表
|
|
2941
|
+
attribute: [] // 属性列表
|
|
2942
|
+
|
|
2724
2943
|
},
|
|
2725
2944
|
needJudgeFirstPage: true,
|
|
2945
|
+
// 是否需要判断首屏
|
|
2726
2946
|
delayBgJudge: false,
|
|
2947
|
+
// 是否延迟背景判断
|
|
2727
2948
|
container: null,
|
|
2949
|
+
// 延迟运行js时使用的容器
|
|
2728
2950
|
cssSelectorsPrefix: '',
|
|
2951
|
+
// css选择器前缀
|
|
2729
2952
|
defaultLightTextColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_TEXTCOLOR"],
|
|
2953
|
+
// 非Dark Mode下字体颜色
|
|
2730
2954
|
defaultLightBgColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_BGCOLOR"],
|
|
2955
|
+
// 非Dark Mode下背景颜色
|
|
2731
2956
|
defaultDarkTextColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_TEXTCOLOR"],
|
|
2957
|
+
// Dark Mode下字体颜色
|
|
2732
2958
|
defaultDarkBgColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_BGCOLOR"],
|
|
2959
|
+
// Dark Mode下背景颜色
|
|
2733
2960
|
// 设置配置
|
|
2734
2961
|
set: function set(type, opt, key) {
|
|
2735
2962
|
var value = opt[key];
|
|
@@ -2763,7 +2990,7 @@ var config = {
|
|
|
2763
2990
|
/*!*********************************!*\
|
|
2764
2991
|
!*** ./src/modules/constant.js ***!
|
|
2765
2992
|
\*********************************/
|
|
2766
|
-
/*! exports provided: MEDIA_QUERY, CLASS_PREFIX, DM_CLASSNAME_REGEXP, HTML_CLASS, COLORATTR, BGCOLORATTR, ORIGINAL_COLORATTR, ORIGINAL_BGCOLORATTR, BGIMAGEATTR, BG_COLOR_DELIMITER, DEFAULT_LIGHT_TEXTCOLOR, DEFAULT_LIGHT_BGCOLOR, DEFAULT_DARK_TEXTCOLOR, DEFAULT_DARK_BGCOLOR, WHITE_LIKE_COLOR_BRIGHTNESS, MAX_LIMIT_BGCOLOR_BRIGHTNESS, MIN_LIMIT_OFFSET_BRIGHTNESS, HIGH_BGCOLOR_BRIGHTNESS, HIGH_BLACKWHITE_HSL_BRIGHTNESS, LOW_BLACKWHITE_HSL_BRIGHTNESS, IGNORE_ALPHA, PAGE_HEIGHT, CSS_PROP_SERIES, CSS_PROP_LIST, TABLE_NAME, IMPORTANT_REGEXP, SEMICOLON_PLACEHOLDER, SEMICOLON_PLACEHOLDER_REGEXP */
|
|
2993
|
+
/*! exports provided: MEDIA_QUERY, CLASS_PREFIX, DM_CLASSNAME_REGEXP, HTML_CLASS, COLORATTR, BGCOLORATTR, ORIGINAL_COLORATTR, ORIGINAL_BGCOLORATTR, BGIMAGEATTR, BG_COLOR_DELIMITER, DEFAULT_LIGHT_TEXTCOLOR, DEFAULT_LIGHT_BGCOLOR, DEFAULT_DARK_TEXTCOLOR, DEFAULT_DARK_BGCOLOR, WHITE_LIKE_COLOR_BRIGHTNESS, MAX_LIMIT_BGCOLOR_BRIGHTNESS, MIN_LIMIT_OFFSET_BRIGHTNESS, HIGH_BGCOLOR_BRIGHTNESS, HIGH_BLACKWHITE_HSL_BRIGHTNESS, LOW_BLACKWHITE_HSL_BRIGHTNESS, IGNORE_ALPHA, PAGE_HEIGHT, CSS_PROP_SERIES, CSS_PROP_LIST, TABLE_NAME, IMPORTANT_REGEXP, SEMICOLON_PLACEHOLDER, SEMICOLON_PLACEHOLDER_REGEXP, COLOR_REGEXP, COLOR_REGEXP_GLOBAL */
|
|
2767
2994
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
2768
2995
|
|
|
2769
2996
|
"use strict";
|
|
@@ -2796,6 +3023,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2796
3023
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "IMPORTANT_REGEXP", function() { return IMPORTANT_REGEXP; });
|
|
2797
3024
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SEMICOLON_PLACEHOLDER", function() { return SEMICOLON_PLACEHOLDER; });
|
|
2798
3025
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SEMICOLON_PLACEHOLDER_REGEXP", function() { return SEMICOLON_PLACEHOLDER_REGEXP; });
|
|
3026
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "COLOR_REGEXP", function() { return COLOR_REGEXP; });
|
|
3027
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "COLOR_REGEXP_GLOBAL", function() { return COLOR_REGEXP_GLOBAL; });
|
|
2799
3028
|
/**
|
|
2800
3029
|
* @name 常量
|
|
2801
3030
|
*
|
|
@@ -2866,6 +3095,8 @@ var IMPORTANT_REGEXP = / !important$/; // !important
|
|
|
2866
3095
|
var SEMICOLON_PLACEHOLDER = '<$#_SEMICOLON_#$>'; // 分号占位符
|
|
2867
3096
|
|
|
2868
3097
|
var SEMICOLON_PLACEHOLDER_REGEXP = /<\$#_SEMICOLON_#\$>/g;
|
|
3098
|
+
var COLOR_REGEXP = /\brgba?\([^)]+\)/i;
|
|
3099
|
+
var COLOR_REGEXP_GLOBAL = /\brgba?\([^)]+\)/ig;
|
|
2869
3100
|
|
|
2870
3101
|
/***/ }),
|
|
2871
3102
|
|
|
@@ -2922,11 +3153,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2922
3153
|
* @method addCss 加入css
|
|
2923
3154
|
* @param {string} css css样式
|
|
2924
3155
|
* @param {boolean} isFirstPageStyle 是否首屏样式
|
|
3156
|
+
* @return void
|
|
2925
3157
|
*
|
|
2926
3158
|
* @method writeStyle 写入样式表
|
|
2927
3159
|
* @param {boolean} isFirstPageStyle 是否首屏样式
|
|
3160
|
+
* @return void
|
|
2928
3161
|
*
|
|
2929
3162
|
*/
|
|
3163
|
+
// 常量
|
|
2930
3164
|
// Darkmode配置
|
|
2931
3165
|
|
|
2932
3166
|
|
|
@@ -2935,6 +3169,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
2935
3169
|
var CssUtils = /*#__PURE__*/function () {
|
|
2936
3170
|
// 首屏样式
|
|
2937
3171
|
// 非首屏样式
|
|
3172
|
+
// 是否运行过Dark Mode处理逻辑(写入过非首屏样式表则表示已运行过)
|
|
2938
3173
|
function CssUtils() {
|
|
2939
3174
|
_classCallCheck(this, CssUtils);
|
|
2940
3175
|
|
|
@@ -2943,25 +3178,29 @@ var CssUtils = /*#__PURE__*/function () {
|
|
|
2943
3178
|
_defineProperty(this, "_otherPageStyle", '');
|
|
2944
3179
|
|
|
2945
3180
|
_defineProperty(this, "isFinish", false);
|
|
2946
|
-
}
|
|
3181
|
+
} // 生成css键值对
|
|
3182
|
+
|
|
2947
3183
|
|
|
2948
3184
|
_createClass(CssUtils, [{
|
|
2949
3185
|
key: "genCssKV",
|
|
2950
3186
|
value: function genCssKV(key, val) {
|
|
2951
3187
|
return "".concat(key, ": ").concat(val, " !important;");
|
|
2952
|
-
}
|
|
3188
|
+
} // 生成css,包括css选择器
|
|
3189
|
+
|
|
2953
3190
|
}, {
|
|
2954
3191
|
key: "genCss",
|
|
2955
3192
|
value: function genCss(className, cssKV) {
|
|
2956
3193
|
return "".concat(_config__WEBPACK_IMPORTED_MODULE_1__["default"].mode === 'dark' ? "html.".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["HTML_CLASS"], " ") : '').concat(_config__WEBPACK_IMPORTED_MODULE_1__["default"].cssSelectorsPrefix && "".concat(_config__WEBPACK_IMPORTED_MODULE_1__["default"].cssSelectorsPrefix, " "), ".").concat(className, "{").concat(cssKV, "}");
|
|
2957
|
-
}
|
|
3194
|
+
} // 加入css
|
|
3195
|
+
|
|
2958
3196
|
}, {
|
|
2959
3197
|
key: "addCss",
|
|
2960
3198
|
value: function addCss(css) {
|
|
2961
3199
|
var isFirstPageStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2962
3200
|
this[isFirstPageStyle ? '_firstPageStyle' : '_otherPageStyle'] += css;
|
|
2963
3201
|
_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].addCss(isFirstPageStyle);
|
|
2964
|
-
}
|
|
3202
|
+
} // 写入样式表
|
|
3203
|
+
|
|
2965
3204
|
}, {
|
|
2966
3205
|
key: "writeStyle",
|
|
2967
3206
|
value: function writeStyle() {
|
|
@@ -3075,28 +3314,32 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
3075
3314
|
*/
|
|
3076
3315
|
// Darkmode配置
|
|
3077
3316
|
|
|
3317
|
+
// 获取某个节点及它的所有子节点
|
|
3078
3318
|
|
|
3079
3319
|
function getChildrenAndIt(el) {
|
|
3080
3320
|
var _ref;
|
|
3081
3321
|
|
|
3082
3322
|
return (_ref = [el]).concat.apply(_ref, _toConsumableArray(el.querySelectorAll('*')));
|
|
3083
3323
|
}
|
|
3084
|
-
;
|
|
3324
|
+
; // 判断某个节点里是否包含文字节点
|
|
3325
|
+
|
|
3085
3326
|
function hasTextNode(el) {
|
|
3086
|
-
|
|
3087
|
-
Array.prototype.forEach.call(el.childNodes,
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
});
|
|
3092
|
-
return cnt.length > 0;
|
|
3327
|
+
// let cnt = '';
|
|
3328
|
+
// Array.prototype.forEach.call(el.childNodes, child => {
|
|
3329
|
+
// if (child.nodeType === 3) {
|
|
3330
|
+
// cnt += child.nodeValue.replace(/\s/g, ''); // 不考虑空白字符
|
|
3331
|
+
// }
|
|
3332
|
+
// });
|
|
3333
|
+
// return cnt.length > 0;
|
|
3334
|
+
return el.textContent.replace(/\s/g, '').length > 0;
|
|
3093
3335
|
}
|
|
3094
3336
|
; // table的内部样式类对应的lm背景色
|
|
3095
3337
|
|
|
3096
3338
|
var tableClassObj = {
|
|
3097
3339
|
'ue-table-interlace-color-single': '#fcfcfc',
|
|
3098
3340
|
'ue-table-interlace-color-double': '#f7faff'
|
|
3099
|
-
};
|
|
3341
|
+
}; // 判断table相关元素有没有指定class
|
|
3342
|
+
|
|
3100
3343
|
function hasTableClass(el) {
|
|
3101
3344
|
var color = null;
|
|
3102
3345
|
Array.prototype.some.call(el.classList, function (className) {
|
|
@@ -3120,21 +3363,26 @@ function hasTableClass(el) {
|
|
|
3120
3363
|
*
|
|
3121
3364
|
* @method set 设置要处理的节点列表
|
|
3122
3365
|
* @param {DOM Object Array} els 要处理的节点列表
|
|
3366
|
+
* @return void
|
|
3123
3367
|
*
|
|
3124
3368
|
* @method get 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
|
|
3125
3369
|
* @return {DOM Object Array} 要处理的节点列表
|
|
3126
3370
|
*
|
|
3127
3371
|
* @method delay 将所有要处理的节点转移到延迟处理队列里
|
|
3372
|
+
* @return void
|
|
3128
3373
|
*
|
|
3129
3374
|
* @method hasDelay 判断是否包含延迟处理的节点
|
|
3130
3375
|
* @return {boolean} 判断结果
|
|
3131
3376
|
*
|
|
3132
3377
|
* @method addFirstPageNode 添加首屏节点
|
|
3133
3378
|
* @param {DOM Object} el 要添加的首屏节点
|
|
3379
|
+
* @return void
|
|
3134
3380
|
*
|
|
3135
3381
|
* @method showFirstPageNodes 显示所有首屏节点
|
|
3382
|
+
* @return void
|
|
3136
3383
|
*
|
|
3137
3384
|
* @method emptyFirstPageNodes 清空记录的首屏节点
|
|
3385
|
+
* @return void
|
|
3138
3386
|
*
|
|
3139
3387
|
*/
|
|
3140
3388
|
|
|
@@ -3153,19 +3401,22 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3153
3401
|
_defineProperty(this, "_delayEls", []);
|
|
3154
3402
|
|
|
3155
3403
|
_defineProperty(this, "showFirstPage", false);
|
|
3156
|
-
}
|
|
3404
|
+
} // 要处理的节点列表长度
|
|
3405
|
+
|
|
3157
3406
|
|
|
3158
3407
|
_createClass(DomUtils, [{
|
|
3159
3408
|
key: "length",
|
|
3160
3409
|
get: function get() {
|
|
3161
3410
|
return this._els.length;
|
|
3162
|
-
}
|
|
3411
|
+
} // 设置要处理的节点列表
|
|
3412
|
+
|
|
3163
3413
|
}, {
|
|
3164
3414
|
key: "set",
|
|
3165
3415
|
value: function set() {
|
|
3166
3416
|
var els = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3167
3417
|
this._els = els;
|
|
3168
|
-
}
|
|
3418
|
+
} // 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
|
|
3419
|
+
|
|
3169
3420
|
}, {
|
|
3170
3421
|
key: "get",
|
|
3171
3422
|
value: function get() {
|
|
@@ -3188,7 +3439,8 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3188
3439
|
}
|
|
3189
3440
|
|
|
3190
3441
|
return res;
|
|
3191
|
-
}
|
|
3442
|
+
} // 将所有要处理的节点转移到延迟处理队列里
|
|
3443
|
+
|
|
3192
3444
|
}, {
|
|
3193
3445
|
key: "delay",
|
|
3194
3446
|
value: function delay() {
|
|
@@ -3199,19 +3451,22 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3199
3451
|
}); // 转移到延迟处理的节点里
|
|
3200
3452
|
|
|
3201
3453
|
this._els = []; // 转移后清空列表
|
|
3202
|
-
}
|
|
3454
|
+
} // 判断是否包含延迟处理的节点
|
|
3455
|
+
|
|
3203
3456
|
}, {
|
|
3204
3457
|
key: "hasDelay",
|
|
3205
3458
|
value: function hasDelay() {
|
|
3206
3459
|
if (this._els.length) return false; // 有节点,即不含延迟处理的节点
|
|
3207
3460
|
|
|
3208
3461
|
return this._delayEls.length > 0 || _config__WEBPACK_IMPORTED_MODULE_0__["default"].container !== null; // 否则需要判断延迟节点的列表和容器
|
|
3209
|
-
}
|
|
3462
|
+
} // 添加首屏节点
|
|
3463
|
+
|
|
3210
3464
|
}, {
|
|
3211
3465
|
key: "addFirstPageNode",
|
|
3212
3466
|
value: function addFirstPageNode(el) {
|
|
3213
3467
|
this._firstPageEls.push(el);
|
|
3214
|
-
}
|
|
3468
|
+
} // 显示所有首屏节点
|
|
3469
|
+
|
|
3215
3470
|
}, {
|
|
3216
3471
|
key: "showFirstPageNodes",
|
|
3217
3472
|
value: function showFirstPageNodes() {
|
|
@@ -3221,7 +3476,8 @@ var DomUtils = /*#__PURE__*/function () {
|
|
|
3221
3476
|
|
|
3222
3477
|
|
|
3223
3478
|
this.showFirstPage = true; // 记录为已显示首屏
|
|
3224
|
-
}
|
|
3479
|
+
} // 清空记录的首屏节点
|
|
3480
|
+
|
|
3225
3481
|
}, {
|
|
3226
3482
|
key: "emptyFirstPageNodes",
|
|
3227
3483
|
value: function emptyFirstPageNodes() {
|
|
@@ -3261,6 +3517,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3261
3517
|
* @name 全局作用域
|
|
3262
3518
|
*
|
|
3263
3519
|
*/
|
|
3520
|
+
// 常量
|
|
3264
3521
|
// 插件系统
|
|
3265
3522
|
|
|
3266
3523
|
|
|
@@ -3307,7 +3564,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
3307
3564
|
*
|
|
3308
3565
|
* @class Plugin
|
|
3309
3566
|
*
|
|
3310
|
-
* @attr {number} loopTimes
|
|
3567
|
+
* @attr {number} loopTimes 已遍历次数(全部节点遍历结束算一次)
|
|
3311
3568
|
* @attr {boolean} isDarkmode 是否为Dark Mode
|
|
3312
3569
|
*
|
|
3313
3570
|
* @method addCss 添加样式
|
|
@@ -3325,18 +3582,21 @@ var cssNoMQ = [];
|
|
|
3325
3582
|
var Plugin = /*#__PURE__*/function () {
|
|
3326
3583
|
function Plugin() {
|
|
3327
3584
|
_classCallCheck(this, Plugin);
|
|
3328
|
-
}
|
|
3585
|
+
} // 遍历次数(全部节点遍历结束算一次)
|
|
3586
|
+
|
|
3329
3587
|
|
|
3330
3588
|
_createClass(Plugin, [{
|
|
3331
3589
|
key: "loopTimes",
|
|
3332
3590
|
get: function get() {
|
|
3333
3591
|
return _global__WEBPACK_IMPORTED_MODULE_0__["plugins"].loopTimes;
|
|
3334
|
-
}
|
|
3592
|
+
} // 是否为Dark Mode
|
|
3593
|
+
|
|
3335
3594
|
}, {
|
|
3336
3595
|
key: "isDarkmode",
|
|
3337
3596
|
get: function get() {
|
|
3338
3597
|
return _global__WEBPACK_IMPORTED_MODULE_0__["sdk"].isDarkmode;
|
|
3339
|
-
}
|
|
3598
|
+
} // 添加样式
|
|
3599
|
+
|
|
3340
3600
|
}, {
|
|
3341
3601
|
key: "addCss",
|
|
3342
3602
|
value: function addCss(className, kvList) {
|
|
@@ -3357,6 +3617,7 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
3357
3617
|
* @class Plugins
|
|
3358
3618
|
*
|
|
3359
3619
|
* @attr {number} length 已挂载的插件数量
|
|
3620
|
+
* @attr {number} loopTimes 已遍历次数(全部节点遍历结束算一次)
|
|
3360
3621
|
* @attr {string} firstPageStyle 首屏样式
|
|
3361
3622
|
* @attr {string} otherPageStyle 非首屏样式
|
|
3362
3623
|
* @attr {string} firstPageStyleNoMQ 首屏样式(不需要加媒体查询)
|
|
@@ -3364,15 +3625,19 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
3364
3625
|
*
|
|
3365
3626
|
* @method extend 挂载插件
|
|
3366
3627
|
* @param {Function} plugin 插件构造函数
|
|
3628
|
+
* @return void
|
|
3367
3629
|
*
|
|
3368
3630
|
* @method emit 执行插件钩子
|
|
3369
3631
|
* @param {string} name 钩子名称
|
|
3370
3632
|
* @param {Any} args 钩子参数
|
|
3633
|
+
* @return void
|
|
3371
3634
|
*
|
|
3372
3635
|
* @method addCss 写入插件样式
|
|
3373
3636
|
* @param {boolean} isFirstPageStyle 是否首屏样式
|
|
3637
|
+
* @return void
|
|
3374
3638
|
*
|
|
3375
3639
|
* @method resetCss 重置插件样式
|
|
3640
|
+
* @return void
|
|
3376
3641
|
*
|
|
3377
3642
|
*/
|
|
3378
3643
|
|
|
@@ -3380,7 +3645,7 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
3380
3645
|
var Plugins = /*#__PURE__*/function () {
|
|
3381
3646
|
// 已挂载的插件列表
|
|
3382
3647
|
// 已挂载的插件数量
|
|
3383
|
-
//
|
|
3648
|
+
// 已遍历次数(全部节点遍历结束算一次)
|
|
3384
3649
|
// 首屏样式
|
|
3385
3650
|
// 非首屏样式
|
|
3386
3651
|
// 首屏样式(不需要加媒体查询)
|
|
@@ -3401,7 +3666,8 @@ var Plugins = /*#__PURE__*/function () {
|
|
|
3401
3666
|
_defineProperty(this, "firstPageStyleNoMQ", '');
|
|
3402
3667
|
|
|
3403
3668
|
_defineProperty(this, "otherPageStyleNoMQ", '');
|
|
3404
|
-
}
|
|
3669
|
+
} // 挂载插件
|
|
3670
|
+
|
|
3405
3671
|
|
|
3406
3672
|
_createClass(Plugins, [{
|
|
3407
3673
|
key: "extend",
|
|
@@ -3409,7 +3675,8 @@ var Plugins = /*#__PURE__*/function () {
|
|
|
3409
3675
|
this._plugins.push(new (plugin(Plugin))());
|
|
3410
3676
|
|
|
3411
3677
|
this.length++;
|
|
3412
|
-
}
|
|
3678
|
+
} // 执行插件钩子
|
|
3679
|
+
|
|
3413
3680
|
}, {
|
|
3414
3681
|
key: "emit",
|
|
3415
3682
|
value: function emit(name) {
|
|
@@ -3420,7 +3687,8 @@ var Plugins = /*#__PURE__*/function () {
|
|
|
3420
3687
|
this._plugins.forEach(function (plugin) {
|
|
3421
3688
|
typeof plugin[name] === 'function' && plugin[name].apply(plugin, args);
|
|
3422
3689
|
});
|
|
3423
|
-
}
|
|
3690
|
+
} // 写入插件样式
|
|
3691
|
+
|
|
3424
3692
|
}, {
|
|
3425
3693
|
key: "addCss",
|
|
3426
3694
|
value: function addCss(isFirstPageStyle) {
|
|
@@ -3431,7 +3699,8 @@ var Plugins = /*#__PURE__*/function () {
|
|
|
3431
3699
|
this.otherPageStyle += cssNeedMQ.join('');
|
|
3432
3700
|
this.otherPageStyleNoMQ += cssNoMQ.join('');
|
|
3433
3701
|
}
|
|
3434
|
-
}
|
|
3702
|
+
} // 重置插件样式
|
|
3703
|
+
|
|
3435
3704
|
}, {
|
|
3436
3705
|
key: "resetCss",
|
|
3437
3706
|
value: function resetCss() {
|
|
@@ -3460,8 +3729,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3460
3729
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return SDK; });
|
|
3461
3730
|
/* harmony import */ var color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! color */ "./node_modules/color/index.js");
|
|
3462
3731
|
/* harmony import */ var color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(color__WEBPACK_IMPORTED_MODULE_0__);
|
|
3463
|
-
/* harmony import */ var
|
|
3464
|
-
/* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(color_name__WEBPACK_IMPORTED_MODULE_1__);
|
|
3732
|
+
/* harmony import */ var _color__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./color */ "./src/modules/color.js");
|
|
3465
3733
|
/* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
|
|
3466
3734
|
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
|
|
3467
3735
|
/* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
|
|
@@ -3499,30 +3767,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3499
3767
|
*
|
|
3500
3768
|
* @class SDK
|
|
3501
3769
|
*
|
|
3770
|
+
* @attr {boolean} isDarkmode 当前是否需要运行Darkmode处理
|
|
3771
|
+
*
|
|
3772
|
+
* @method init 初始化
|
|
3773
|
+
* @return void
|
|
3774
|
+
*
|
|
3502
3775
|
* @method convert 处理节点
|
|
3503
3776
|
* @param {DOM Object} el 要处理的节点
|
|
3504
3777
|
* @return {string} 处理后的css,包含css选择器
|
|
3505
3778
|
*
|
|
3779
|
+
* @method getContrast 获取两个颜色的对比度
|
|
3780
|
+
* @param {string} colorStr1 颜色1
|
|
3781
|
+
* @param {string} colorStr2 颜色2
|
|
3782
|
+
* @return {number} 颜色对比度,取值范围为`[1, 21]`
|
|
3783
|
+
*
|
|
3506
3784
|
*/
|
|
3507
|
-
//
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
var ColorParser = function ColorParser(color) {
|
|
3511
|
-
var res = null;
|
|
3512
|
-
|
|
3513
|
-
try {
|
|
3514
|
-
res = color__WEBPACK_IMPORTED_MODULE_0___default()(color);
|
|
3515
|
-
} catch (e) {
|
|
3516
|
-
console.log("ignore the invalid color: `".concat(color, "`"));
|
|
3517
|
-
}
|
|
3518
|
-
|
|
3519
|
-
return res;
|
|
3520
|
-
};
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
|
|
3785
|
+
// 颜色操作相关API
|
|
3524
3786
|
|
|
3525
|
-
|
|
3787
|
+
// 常量
|
|
3526
3788
|
|
|
3527
3789
|
// Darkmode配置
|
|
3528
3790
|
|
|
@@ -3530,103 +3792,6 @@ color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255,
|
|
|
3530
3792
|
// 节点相关操作工具API
|
|
3531
3793
|
|
|
3532
3794
|
|
|
3533
|
-
var colorNameReg = new RegExp(Object.keys(color_name__WEBPACK_IMPORTED_MODULE_1___default.a).map(function (colorName) {
|
|
3534
|
-
return "\\b".concat(colorName, "\\b");
|
|
3535
|
-
}).join('|'), 'ig'); // 生成正则表达式来匹配这些colorName
|
|
3536
|
-
|
|
3537
|
-
var colorReg = /\brgba?\([^)]+\)/i;
|
|
3538
|
-
var colorRegGlobal = /\brgba?\([^)]+\)/ig;
|
|
3539
|
-
|
|
3540
|
-
var removeImportant = function removeImportant(value) {
|
|
3541
|
-
return value.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"], '');
|
|
3542
|
-
}; // 清除!important
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
var parseColor = function parseColor(value, parseTransparent) {
|
|
3546
|
-
return removeImportant(value).replace(colorNameReg, function (match) {
|
|
3547
|
-
// 处理颜色,包括清除!important和转换英文定义颜色
|
|
3548
|
-
if (!parseTransparent && match === 'transparent') return match; // 如果不转换transparent,直接返回transparent
|
|
3549
|
-
|
|
3550
|
-
var color = color_name__WEBPACK_IMPORTED_MODULE_1___default.a[match.toLowerCase()];
|
|
3551
|
-
return "".concat(color.length > 3 ? 'rgba' : 'rgb', "(").concat(color.toString(), ")");
|
|
3552
|
-
});
|
|
3553
|
-
}; // 计算mix颜色
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
var mixColor = function mixColor(colors) {
|
|
3557
|
-
if (!colors || colors.length < 1) return '';
|
|
3558
|
-
if (colors.length === 1) return colors[0];
|
|
3559
|
-
var retColorStr = colors.shift();
|
|
3560
|
-
var nextColorStr = colors.shift();
|
|
3561
|
-
|
|
3562
|
-
while (nextColorStr) {
|
|
3563
|
-
var retColor = ColorParser(retColorStr);
|
|
3564
|
-
var nextColor = ColorParser(nextColorStr);
|
|
3565
|
-
|
|
3566
|
-
if (!retColor && nextColor) {
|
|
3567
|
-
// 如果当前色值非法,混入色值合法,则直接使用混入色值
|
|
3568
|
-
retColorStr = nextColorStr;
|
|
3569
|
-
} else if (!retColor && !nextColor) {
|
|
3570
|
-
// 如果两个色值都非法,则使用下一批色值
|
|
3571
|
-
retColorStr = colors.shift() || '';
|
|
3572
|
-
} else if (retColor && nextColor) {
|
|
3573
|
-
// 如果两个色值都合法,执行mix
|
|
3574
|
-
retColorStr = retColor.mix(nextColor, nextColor.alpha());
|
|
3575
|
-
} // 如果当前色值合法,混入色值非法,无需处理
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
nextColorStr = colors.shift();
|
|
3579
|
-
}
|
|
3580
|
-
|
|
3581
|
-
return retColorStr;
|
|
3582
|
-
}; // 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
var parseWebkitFillColorAndStrokeColor = function parseWebkitFillColorAndStrokeColor(value) {
|
|
3586
|
-
var newValue = parseColor(value);
|
|
3587
|
-
return colorReg.test(newValue) ? newValue : '';
|
|
3588
|
-
}; // 计算感知亮度
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
var getColorPerceivedBrightness = function getColorPerceivedBrightness(rgb) {
|
|
3592
|
-
return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
|
3593
|
-
}; // 调整为指定感知亮度
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
var adjustBrightnessByLimit = function adjustBrightnessByLimit(limitBright, rgb) {
|
|
3597
|
-
var relativeBrightnessRatio = limitBright / getColorPerceivedBrightness(rgb);
|
|
3598
|
-
var newTextR = Math.min(255, rgb[0] * relativeBrightnessRatio);
|
|
3599
|
-
var newTextG = Math.min(255, rgb[1] * relativeBrightnessRatio);
|
|
3600
|
-
var newTextB = Math.min(255, rgb[2] * relativeBrightnessRatio);
|
|
3601
|
-
|
|
3602
|
-
if (newTextG === 0 || newTextR === 255 || newTextB === 255) {
|
|
3603
|
-
newTextG = (limitBright * 1000 - newTextR * 299 - newTextB * 114) / 587;
|
|
3604
|
-
} else if (newTextR === 0) {
|
|
3605
|
-
newTextR = (limitBright * 1000 - newTextG * 587 - newTextB * 114) / 299;
|
|
3606
|
-
} else if (newTextB === 0 || newTextG === 255) {
|
|
3607
|
-
newTextB = (limitBright * 1000 - newTextR * 299 - newTextG * 587) / 114;
|
|
3608
|
-
}
|
|
3609
|
-
|
|
3610
|
-
return color__WEBPACK_IMPORTED_MODULE_0___default.a.rgb(newTextR, newTextG, newTextB);
|
|
3611
|
-
}; // 计算亮度,用作对比度计算
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
var getLuminanace = function getLuminanace(rgb) {
|
|
3615
|
-
var srgb = rgb.map(function (val) {
|
|
3616
|
-
val /= 255;
|
|
3617
|
-
return val <= 0.03928 ? val / 12.92 : Math.pow((val + 0.055) / 1.055, 2.4);
|
|
3618
|
-
});
|
|
3619
|
-
return srgb[0] * 0.2126 + srgb[1] * 0.7152 + srgb[2] * 0.0722;
|
|
3620
|
-
}; // 计算对比度 https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-procedure
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
var _getContrast = function getContrast(rgb1, rgb2) {
|
|
3624
|
-
var lum1 = getLuminanace(rgb1);
|
|
3625
|
-
var lum2 = getLuminanace(rgb2); // 亮色 / 暗色
|
|
3626
|
-
|
|
3627
|
-
if (lum1 < lum2) return (lum2 + 0.05) / (lum1 + 0.05);
|
|
3628
|
-
return (lum1 + 0.05) / (lum2 + 0.05);
|
|
3629
|
-
};
|
|
3630
3795
|
|
|
3631
3796
|
var SDK = /*#__PURE__*/function () {
|
|
3632
3797
|
// 索引值
|
|
@@ -3651,81 +3816,10 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3651
3816
|
_defineProperty(this, "_maxLimitOffsetBrightness", null);
|
|
3652
3817
|
|
|
3653
3818
|
_defineProperty(this, "isDarkmode", false);
|
|
3654
|
-
}
|
|
3655
|
-
|
|
3656
|
-
_createClass(SDK, [{
|
|
3657
|
-
key: "_adjustTextBrightness",
|
|
3658
|
-
value: function _adjustTextBrightness(textColor, bgColor) {
|
|
3659
|
-
var bgColorRgb = bgColor.rgb().array();
|
|
3660
|
-
var bgColorAlpha = bgColor.alpha();
|
|
3661
|
-
var bgColorPerceivedBrightness = getColorPerceivedBrightness(bgColorRgb);
|
|
3662
|
-
var bgColorWithOpacityPerceivedBrightness = bgColorPerceivedBrightness * bgColorAlpha + this._defaultDarkBgColorBrightness * (1 - bgColorAlpha);
|
|
3663
|
-
var textColorRgb = textColor.rgb().array();
|
|
3664
|
-
var textColorHSL = textColor.hsl().array();
|
|
3665
|
-
var textColorAlpha = textColor.alpha();
|
|
3666
|
-
var textPerceivedBrightness = getColorPerceivedBrightness(textColorRgb);
|
|
3667
|
-
var offsetPerceivedBrightness = Math.abs(bgColorWithOpacityPerceivedBrightness - textPerceivedBrightness); // 用户设置为高亮字体颜色(接近白色亮度),不处理,保持高亮
|
|
3668
|
-
|
|
3669
|
-
if (textPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) return textColor;
|
|
3670
|
-
|
|
3671
|
-
if (offsetPerceivedBrightness > this._maxLimitOffsetBrightness && bgColorWithOpacityPerceivedBrightness <= this._defaultDarkBgColorBrightness + 2) {
|
|
3672
|
-
return adjustBrightnessByLimit(this._maxLimitOffsetBrightness + bgColorWithOpacityPerceivedBrightness, textColorRgb).alpha(textColorAlpha);
|
|
3673
|
-
} // 如果感知亮度差大于阈值,无需调整
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
if (offsetPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]) return textColor;
|
|
3677
|
-
|
|
3678
|
-
if (bgColorWithOpacityPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BGCOLOR_BRIGHTNESS"]) {
|
|
3679
|
-
// 亮背景,调暗字体
|
|
3680
|
-
if (textColorHSL[2] > 90 - _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3681
|
-
// 优先调字体的亮度已带到降低感知亮度的目的
|
|
3682
|
-
textColorHSL[2] = 90 - textColorHSL[2];
|
|
3683
|
-
var tmpTextColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(textColorHSL)).alpha(textColorAlpha);
|
|
3684
|
-
return this._adjustTextBrightness(tmpTextColor, bgColor);
|
|
3685
|
-
}
|
|
3819
|
+
} // 调整明度
|
|
3686
3820
|
|
|
3687
|
-
return adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness - _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
|
|
3688
|
-
} else {
|
|
3689
|
-
// 暗背景,调亮字体
|
|
3690
|
-
if (textColorHSL[2] <= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3691
|
-
// 优先调字体的亮度已带到提高感知亮度的目的
|
|
3692
|
-
textColorHSL[2] = 90 - textColorHSL[2];
|
|
3693
3821
|
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
return this._adjustTextBrightness(_tmpTextColor, bgColor);
|
|
3697
|
-
}
|
|
3698
|
-
|
|
3699
|
-
return adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness + _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
}, {
|
|
3703
|
-
key: "_adjustBackgroundBrightness",
|
|
3704
|
-
value: function _adjustBackgroundBrightness(bgColor) {
|
|
3705
|
-
var bgColorRgb = bgColor.rgb().array();
|
|
3706
|
-
var bgColorHsl = bgColor.hsl().array();
|
|
3707
|
-
var bgColorAlpha = bgColor.alpha();
|
|
3708
|
-
var bgColorPerceivedBrightness = getColorPerceivedBrightness(bgColorRgb);
|
|
3709
|
-
var newColor = bgColor;
|
|
3710
|
-
|
|
3711
|
-
if (bgColorHsl[1] === 0 && bgColorHsl[2] > _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"] || bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) {
|
|
3712
|
-
// 饱和度为0(黑白灰色),亮度大于HIGH_BLACKWHITE_HSL_BRIGHTNESS或感知亮度大于WHITE_LIKE_COLOR_BRIGHTNESS(白色)时,做亮度取反处理
|
|
3713
|
-
newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl(0, 0, Math.min(100, 100 + this._defaultDarkBgColorHslBrightness - bgColorHsl[2]));
|
|
3714
|
-
} else if (bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"]) {
|
|
3715
|
-
// 感知亮度大于MAX_LIMIT_BGCOLOR_BRIGHTNESS,将感知亮度设为MAX_LIMIT_BGCOLOR_BRIGHTNESS
|
|
3716
|
-
newColor = adjustBrightnessByLimit(_constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"], bgColorRgb).alpha(bgColorAlpha); // const ratio = (MAX_LIMIT_BGCOLOR_BRIGHTNESS * 1000)
|
|
3717
|
-
// / (bgColorRgb[0] * 299 + bgColorRgb[1] * 587 + bgColorRgb[2] * 114);
|
|
3718
|
-
// newColor = Color.rgb(bgColorRgb[0] * ratio, bgColorRgb[1] * ratio, bgColorRgb[2] * ratio);
|
|
3719
|
-
} else if (bgColorHsl[2] < _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3720
|
-
// 亮度小于LOW_BLACKWHITE_HSL_BRIGHTNESS,将亮度设为LOW_BLACKWHITE_HSL_BRIGHTNESS,适当提高亮度
|
|
3721
|
-
bgColorHsl[2] = _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"];
|
|
3722
|
-
newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(bgColorHsl));
|
|
3723
|
-
}
|
|
3724
|
-
|
|
3725
|
-
return newColor.alpha(bgColorAlpha).rgb();
|
|
3726
|
-
} // 调整明度
|
|
3727
|
-
|
|
3728
|
-
}, {
|
|
3822
|
+
_createClass(SDK, [{
|
|
3729
3823
|
key: "_adjustBrightness",
|
|
3730
3824
|
value: function _adjustBrightness(color, el, options, isUpdate) {
|
|
3731
3825
|
// 背景:
|
|
@@ -3754,7 +3848,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3754
3848
|
|
|
3755
3849
|
if (!options.hasInlineColor) {
|
|
3756
3850
|
var parentTextColorStr = el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor;
|
|
3757
|
-
var parentTextColor = ColorParser(parentTextColorStr);
|
|
3851
|
+
var parentTextColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(parentTextColorStr);
|
|
3758
3852
|
|
|
3759
3853
|
if (parentTextColor) {
|
|
3760
3854
|
var ret = this._adjustBrightness(parentTextColor, el, {
|
|
@@ -3772,7 +3866,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3772
3866
|
} else if (options.isTextColor || options.isBorderColor) {
|
|
3773
3867
|
// 字体色、边框色
|
|
3774
3868
|
var parentElementBgColorStr = options.parentElementBgColorStr || options.isTextColor && el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor;
|
|
3775
|
-
var parentElementBgColor = ColorParser(parentElementBgColorStr); // 无背景图片
|
|
3869
|
+
var parentElementBgColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(parentElementBgColorStr); // 无背景图片
|
|
3776
3870
|
|
|
3777
3871
|
if (parentElementBgColor && !el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
|
|
3778
3872
|
newColor = this._adjustTextBrightness(color, parentElementBgColor);
|
|
@@ -3794,6 +3888,105 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3794
3888
|
newColor: newColor && color.toString() !== newColor.toString() && newColor.alpha(alpha).rgb(),
|
|
3795
3889
|
extStyle: extStyle
|
|
3796
3890
|
};
|
|
3891
|
+
} // 调整文本明度
|
|
3892
|
+
|
|
3893
|
+
}, {
|
|
3894
|
+
key: "_adjustTextBrightness",
|
|
3895
|
+
value: function _adjustTextBrightness(textColor, bgColor) {
|
|
3896
|
+
var bgColorRgb = bgColor.rgb().array();
|
|
3897
|
+
var bgColorAlpha = bgColor.alpha();
|
|
3898
|
+
var bgColorPerceivedBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(bgColorRgb);
|
|
3899
|
+
var bgColorWithOpacityPerceivedBrightness = bgColorPerceivedBrightness * bgColorAlpha + this._defaultDarkBgColorBrightness * (1 - bgColorAlpha);
|
|
3900
|
+
var textColorRgb = textColor.rgb().array();
|
|
3901
|
+
var textColorHSL = textColor.hsl().array();
|
|
3902
|
+
var textColorAlpha = textColor.alpha();
|
|
3903
|
+
var textPerceivedBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(textColorRgb);
|
|
3904
|
+
var offsetPerceivedBrightness = Math.abs(bgColorWithOpacityPerceivedBrightness - textPerceivedBrightness); // 用户设置为高亮字体颜色(接近白色亮度),不处理,保持高亮
|
|
3905
|
+
|
|
3906
|
+
if (textPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) return textColor;
|
|
3907
|
+
|
|
3908
|
+
if (offsetPerceivedBrightness > this._maxLimitOffsetBrightness && bgColorWithOpacityPerceivedBrightness <= this._defaultDarkBgColorBrightness + 2) {
|
|
3909
|
+
return Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(this._maxLimitOffsetBrightness + bgColorWithOpacityPerceivedBrightness, textColorRgb).alpha(textColorAlpha);
|
|
3910
|
+
} // 如果感知亮度差大于阈值,无需调整
|
|
3911
|
+
|
|
3912
|
+
|
|
3913
|
+
if (offsetPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]) return textColor;
|
|
3914
|
+
|
|
3915
|
+
if (bgColorWithOpacityPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BGCOLOR_BRIGHTNESS"]) {
|
|
3916
|
+
// 亮背景,调暗字体
|
|
3917
|
+
if (textColorHSL[2] > 90 - _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3918
|
+
// 优先调字体的亮度已带到降低感知亮度的目的
|
|
3919
|
+
textColorHSL[2] = 90 - textColorHSL[2];
|
|
3920
|
+
var tmpTextColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(textColorHSL)).alpha(textColorAlpha);
|
|
3921
|
+
return this._adjustTextBrightness(tmpTextColor, bgColor);
|
|
3922
|
+
}
|
|
3923
|
+
|
|
3924
|
+
return Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness - _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
|
|
3925
|
+
} else {
|
|
3926
|
+
// 暗背景,调亮字体
|
|
3927
|
+
if (textColorHSL[2] <= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3928
|
+
// 优先调字体的亮度已带到提高感知亮度的目的
|
|
3929
|
+
textColorHSL[2] = 90 - textColorHSL[2];
|
|
3930
|
+
|
|
3931
|
+
var _tmpTextColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(textColorHSL)).alpha(textColorAlpha);
|
|
3932
|
+
|
|
3933
|
+
return this._adjustTextBrightness(_tmpTextColor, bgColor);
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
return Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness + _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
|
|
3937
|
+
}
|
|
3938
|
+
} // 调整背景明度
|
|
3939
|
+
|
|
3940
|
+
}, {
|
|
3941
|
+
key: "_adjustBackgroundBrightness",
|
|
3942
|
+
value: function _adjustBackgroundBrightness(bgColor) {
|
|
3943
|
+
var bgColorRgb = bgColor.rgb().array();
|
|
3944
|
+
var bgColorHsl = bgColor.hsl().array();
|
|
3945
|
+
var bgColorAlpha = bgColor.alpha();
|
|
3946
|
+
var bgColorPerceivedBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(bgColorRgb);
|
|
3947
|
+
var newColor = bgColor;
|
|
3948
|
+
|
|
3949
|
+
if (bgColorHsl[1] === 0 && bgColorHsl[2] > _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"] || bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) {
|
|
3950
|
+
// 饱和度为0(黑白灰色),亮度大于HIGH_BLACKWHITE_HSL_BRIGHTNESS或感知亮度大于WHITE_LIKE_COLOR_BRIGHTNESS(白色)时,做亮度取反处理
|
|
3951
|
+
newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl(0, 0, Math.min(100, 100 + this._defaultDarkBgColorHslBrightness - bgColorHsl[2]));
|
|
3952
|
+
} else if (bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"]) {
|
|
3953
|
+
// 感知亮度大于MAX_LIMIT_BGCOLOR_BRIGHTNESS,将感知亮度设为MAX_LIMIT_BGCOLOR_BRIGHTNESS
|
|
3954
|
+
newColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(_constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"], bgColorRgb).alpha(bgColorAlpha); // const ratio = (MAX_LIMIT_BGCOLOR_BRIGHTNESS * 1000)
|
|
3955
|
+
// / (bgColorRgb[0] * 299 + bgColorRgb[1] * 587 + bgColorRgb[2] * 114);
|
|
3956
|
+
// newColor = Color.rgb(bgColorRgb[0] * ratio, bgColorRgb[1] * ratio, bgColorRgb[2] * ratio);
|
|
3957
|
+
} else if (bgColorHsl[2] < _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"]) {
|
|
3958
|
+
// 亮度小于LOW_BLACKWHITE_HSL_BRIGHTNESS,将亮度设为LOW_BLACKWHITE_HSL_BRIGHTNESS,适当提高亮度
|
|
3959
|
+
bgColorHsl[2] = _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"];
|
|
3960
|
+
newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(bgColorHsl));
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
return newColor.alpha(bgColorAlpha).rgb();
|
|
3964
|
+
} // 叠加渐变色到背景色中,并更新背景色相关属性值以及文本颜色
|
|
3965
|
+
|
|
3966
|
+
}, {
|
|
3967
|
+
key: "_updateBgWithGradient",
|
|
3968
|
+
value: function _updateBgWithGradient(gradientColor, el, className, cssKVList, hasInlineColor, isUpdate) {
|
|
3969
|
+
var newBgColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["mixColors"])([el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor, gradientColor], 'normal');
|
|
3970
|
+
var newOriginalBgColor = (el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightBgColor).split(_constant__WEBPACK_IMPORTED_MODULE_2__["BG_COLOR_DELIMITER"]).concat(gradientColor.toString()).join(_constant__WEBPACK_IMPORTED_MODULE_2__["BG_COLOR_DELIMITER"]);
|
|
3971
|
+
Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
3972
|
+
dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]] = newBgColor;
|
|
3973
|
+
dom[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]] = newOriginalBgColor;
|
|
3974
|
+
});
|
|
3975
|
+
var lastKV = cssKVList.slice(-1)[0];
|
|
3976
|
+
|
|
3977
|
+
if (lastKV[0] === 'color') {
|
|
3978
|
+
var ret = this._adjustBrightness(Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseColorName"])(lastKV[1])), el, {
|
|
3979
|
+
isBgColor: false,
|
|
3980
|
+
isTextShadow: false,
|
|
3981
|
+
isTextColor: true,
|
|
3982
|
+
isBorderColor: false,
|
|
3983
|
+
hasInlineColor: hasInlineColor
|
|
3984
|
+
}, isUpdate);
|
|
3985
|
+
|
|
3986
|
+
if (ret.newColor) return _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(className, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', ret.newColor));
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
return '';
|
|
3797
3990
|
}
|
|
3798
3991
|
}, {
|
|
3799
3992
|
key: "_try",
|
|
@@ -3804,18 +3997,20 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3804
3997
|
console.log('An error occurred when running the dark mode conversion algorithm\n', e);
|
|
3805
3998
|
typeof _config__WEBPACK_IMPORTED_MODULE_3__["default"].error === 'function' && _config__WEBPACK_IMPORTED_MODULE_3__["default"].error(e);
|
|
3806
3999
|
}
|
|
3807
|
-
}
|
|
4000
|
+
} // 初始化
|
|
4001
|
+
|
|
3808
4002
|
}, {
|
|
3809
4003
|
key: "init",
|
|
3810
4004
|
value: function init() {
|
|
3811
|
-
this._defaultDarkTextColorRgb = ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkTextColor).rgb().array();
|
|
3812
|
-
this._defaultDarkBgColorRgb = ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).rgb().array();
|
|
3813
|
-
this._defaultDarkBgColorHSL = ColorParser(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).hsl().array();
|
|
3814
|
-
this._defaultDarkTextColorBrightness = getColorPerceivedBrightness(this._defaultDarkTextColorRgb);
|
|
3815
|
-
this._defaultDarkBgColorBrightness = getColorPerceivedBrightness(this._defaultDarkBgColorRgb);
|
|
4005
|
+
this._defaultDarkTextColorRgb = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkTextColor).rgb().array();
|
|
4006
|
+
this._defaultDarkBgColorRgb = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).rgb().array();
|
|
4007
|
+
this._defaultDarkBgColorHSL = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).hsl().array();
|
|
4008
|
+
this._defaultDarkTextColorBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(this._defaultDarkTextColorRgb);
|
|
4009
|
+
this._defaultDarkBgColorBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(this._defaultDarkBgColorRgb);
|
|
3816
4010
|
this._defaultDarkBgColorHslBrightness = this._defaultDarkBgColorHSL[2];
|
|
3817
4011
|
this._maxLimitOffsetBrightness = this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness;
|
|
3818
|
-
}
|
|
4012
|
+
} // 处理节点
|
|
4013
|
+
|
|
3819
4014
|
}, {
|
|
3820
4015
|
key: "convert",
|
|
3821
4016
|
value: function convert(el, cssKVList, isUpdate) {
|
|
@@ -3906,7 +4101,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3906
4101
|
|
|
3907
4102
|
if (colorStr) {
|
|
3908
4103
|
// 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
|
|
3909
|
-
var color = ColorParser(colorStr);
|
|
4104
|
+
var color = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr);
|
|
3910
4105
|
|
|
3911
4106
|
if (color) {
|
|
3912
4107
|
cssKVList.unshift(['background-color', color.toString()]);
|
|
@@ -3923,7 +4118,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3923
4118
|
|
|
3924
4119
|
if (colorStr) {
|
|
3925
4120
|
// 有色值,则当做内联样式来处理
|
|
3926
|
-
var color = ColorParser(colorStr);
|
|
4121
|
+
var color = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr);
|
|
3927
4122
|
|
|
3928
4123
|
if (color) {
|
|
3929
4124
|
cssKVList.push(['color', color.toString()]);
|
|
@@ -3952,20 +4147,20 @@ var SDK = /*#__PURE__*/function () {
|
|
|
3952
4147
|
|
|
3953
4148
|
switch (key) {
|
|
3954
4149
|
case '-webkit-text-fill-color':
|
|
3955
|
-
webkitFillColor = parseWebkitFillColorAndStrokeColor(value);
|
|
4150
|
+
webkitFillColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(value);
|
|
3956
4151
|
break;
|
|
3957
4152
|
|
|
3958
4153
|
case '-webkit-text-stroke':
|
|
3959
4154
|
{
|
|
3960
4155
|
// 有-webkit-text-stroke时就不会有-webkit-text-stroke-color
|
|
3961
4156
|
var newValue = value.split(' ');
|
|
3962
|
-
newValue.length === 2 && (webkitStrokeColor = parseWebkitFillColorAndStrokeColor(newValue[1]));
|
|
4157
|
+
newValue.length === 2 && (webkitStrokeColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(newValue[1]));
|
|
3963
4158
|
break;
|
|
3964
4159
|
}
|
|
3965
4160
|
|
|
3966
4161
|
case '-webkit-text-stroke-color':
|
|
3967
4162
|
// 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
|
|
3968
|
-
webkitStrokeColor = parseWebkitFillColorAndStrokeColor(value);
|
|
4163
|
+
webkitStrokeColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(value);
|
|
3969
4164
|
break;
|
|
3970
4165
|
}
|
|
3971
4166
|
|
|
@@ -4030,31 +4225,31 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4030
4225
|
var extStyle = '';
|
|
4031
4226
|
var gradientMixColor; // 将英文定义颜色转换为rgb格式
|
|
4032
4227
|
|
|
4033
|
-
value =
|
|
4228
|
+
value = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseColorName"])(value, isGradient); // 渐变需要处理透明
|
|
4034
4229
|
|
|
4035
|
-
if (
|
|
4230
|
+
if (_constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP"].test(value)) {
|
|
4036
4231
|
if (isGradient) {
|
|
4037
4232
|
// 把原渐变色取出来
|
|
4038
|
-
var _matches =
|
|
4233
|
+
var _matches = _constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"].exec(value);
|
|
4039
4234
|
|
|
4040
4235
|
while (_matches) {
|
|
4041
4236
|
gradientColors.push(_matches[0]);
|
|
4042
|
-
_matches =
|
|
4237
|
+
_matches = _constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"].exec(value);
|
|
4043
4238
|
} // 计算出一个mix颜色
|
|
4044
4239
|
|
|
4045
4240
|
|
|
4046
|
-
gradientMixColor =
|
|
4241
|
+
gradientMixColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["mixColors"])(gradientColors);
|
|
4047
4242
|
}
|
|
4048
4243
|
|
|
4049
4244
|
var replaceIndex = 0;
|
|
4050
|
-
value = value.replace(
|
|
4245
|
+
value = value.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"], function (match) {
|
|
4051
4246
|
// 渐变色统一改成mix纯色
|
|
4052
4247
|
if (isGradient) {
|
|
4053
4248
|
match = gradientMixColor;
|
|
4054
4249
|
cssChange = true;
|
|
4055
4250
|
}
|
|
4056
4251
|
|
|
4057
|
-
var matchColor = ColorParser(match);
|
|
4252
|
+
var matchColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(match);
|
|
4058
4253
|
|
|
4059
4254
|
if ((matchColor === null || matchColor === void 0 ? void 0 : matchColor.alpha()) >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
|
|
4060
4255
|
// 忽略透明度低的色值
|
|
@@ -4070,7 +4265,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4070
4265
|
var retColor = !hasInlineBackgroundImage && ret.newColor;
|
|
4071
4266
|
extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
|
|
4072
4267
|
|
|
4073
|
-
if (isBgColor || textColorIdx
|
|
4268
|
+
if (isBgColor || textColorIdx >= 5) {
|
|
4074
4269
|
// 只处理color及之后的属性
|
|
4075
4270
|
var retColorStr = retColor ? retColor.toString() : match;
|
|
4076
4271
|
replaceIndex === 0 && Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
|
|
@@ -4080,11 +4275,10 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4080
4275
|
} else {
|
|
4081
4276
|
dom[_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"]] = retColorStr;
|
|
4082
4277
|
dom[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] = match;
|
|
4083
|
-
dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"], match);
|
|
4084
4278
|
} // 如果设置背景颜色,取消背景图片的影响
|
|
4085
4279
|
|
|
4086
4280
|
|
|
4087
|
-
var retColor = ColorParser(retColorStr);
|
|
4281
|
+
var retColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(retColorStr);
|
|
4088
4282
|
|
|
4089
4283
|
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"]]) {
|
|
4090
4284
|
delete dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]];
|
|
@@ -4111,7 +4305,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4111
4305
|
|
|
4112
4306
|
if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
|
|
4113
4307
|
cssChange = true;
|
|
4114
|
-
var imgBgColor =
|
|
4308
|
+
var imgBgColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["mixColors"])((el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightBgColor).split(_constant__WEBPACK_IMPORTED_MODULE_2__["BG_COLOR_DELIMITER"]), 'normal').toString(); // const imgBgColor = el[BGCOLORATTR] || config.defaultLightBgColor;
|
|
4115
4309
|
// 在背景图片下加一层原背景颜色:
|
|
4116
4310
|
// background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering);
|
|
4117
4311
|
// border-image不支持多层背景,需要添加background-color
|
|
@@ -4177,15 +4371,26 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4177
4371
|
}
|
|
4178
4372
|
|
|
4179
4373
|
if (cssChange) {
|
|
4180
|
-
!isUpdate && _constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] =
|
|
4374
|
+
!isUpdate && _constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] = oldValue.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"], '')); // 清除inline style的!important
|
|
4181
4375
|
|
|
4182
4376
|
if (isGradient) {
|
|
4183
4377
|
if (dmBgClassName) {
|
|
4184
|
-
//
|
|
4378
|
+
// 如果是文字底图,则直接加样式(其实理论上不会走到这里)
|
|
4185
4379
|
bgCss += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(dmBgClassName, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value));
|
|
4380
|
+
|
|
4381
|
+
if (/^background/.test(key) && !/url\([^)]*\)/i.test(value)) {
|
|
4382
|
+
// 是无背景图的渐变,需要重新计算背景色
|
|
4383
|
+
css += _this._updateBgWithGradient(gradientMixColor, el, dmBgClassName, cssKVList, hasInlineColor, isUpdate);
|
|
4384
|
+
}
|
|
4186
4385
|
} else {
|
|
4187
|
-
//
|
|
4188
|
-
_global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value))
|
|
4386
|
+
// 否则渐变入栈
|
|
4387
|
+
_global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value), function (item) {
|
|
4388
|
+
// 渐变入栈
|
|
4389
|
+
if (/^background/.test(key) && !/url\([^)]*\)/i.test(value)) {
|
|
4390
|
+
// 是无背景图的渐变,需要重新计算背景色
|
|
4391
|
+
css += _this._updateBgWithGradient(gradientMixColor, el, item.className, cssKVList, hasInlineColor, isUpdate);
|
|
4392
|
+
}
|
|
4393
|
+
});
|
|
4189
4394
|
}
|
|
4190
4395
|
} else {
|
|
4191
4396
|
cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value);
|
|
@@ -4214,6 +4419,7 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4214
4419
|
} else {
|
|
4215
4420
|
_global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].contains(el, function (item) {
|
|
4216
4421
|
css += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(item.className, item.cssKV);
|
|
4422
|
+
typeof item.cb === 'function' && item.cb(item);
|
|
4217
4423
|
});
|
|
4218
4424
|
}
|
|
4219
4425
|
}
|
|
@@ -4221,13 +4427,14 @@ var SDK = /*#__PURE__*/function () {
|
|
|
4221
4427
|
|
|
4222
4428
|
_global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit("afterConvertNode".concat(isUpdate ? 'ByUpdateStyle' : ''), el);
|
|
4223
4429
|
return css;
|
|
4224
|
-
}
|
|
4430
|
+
} // 获取两个颜色的对比度
|
|
4431
|
+
|
|
4225
4432
|
}, {
|
|
4226
4433
|
key: "getContrast",
|
|
4227
4434
|
value: function getContrast(colorStr1, colorStr2) {
|
|
4228
|
-
var color1 = ColorParser(colorStr1);
|
|
4229
|
-
var color2 = ColorParser(colorStr2);
|
|
4230
|
-
return color1 && color2 ?
|
|
4435
|
+
var color1 = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr1);
|
|
4436
|
+
var color2 = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr2);
|
|
4437
|
+
return color1 && color2 ? color1.contrast(color2) : 0;
|
|
4231
4438
|
}
|
|
4232
4439
|
}]);
|
|
4233
4440
|
|
|
@@ -4270,12 +4477,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
4270
4477
|
*
|
|
4271
4478
|
* @method push 文本节点入队
|
|
4272
4479
|
* @param {DOM Object} el 文本节点对象
|
|
4480
|
+
* @return void
|
|
4273
4481
|
*
|
|
4274
4482
|
* @method forEach 遍历,遍历过的文本节点出队
|
|
4275
4483
|
* @param {Function} callback 回调
|
|
4484
|
+
* @return void
|
|
4276
4485
|
*
|
|
4277
4486
|
* @method update 更新队列的节点对象,主要解决前后节点不一致的问题
|
|
4278
4487
|
* @param {DOM Object Array} els 要更新的节点对象列表
|
|
4488
|
+
* @return void
|
|
4279
4489
|
*
|
|
4280
4490
|
*/
|
|
4281
4491
|
// Darkmode配置
|
|
@@ -4292,7 +4502,8 @@ var TextNodeQueue = /*#__PURE__*/function () {
|
|
|
4292
4502
|
_defineProperty(this, "_idx", 0);
|
|
4293
4503
|
|
|
4294
4504
|
this._prefix = prefix;
|
|
4295
|
-
}
|
|
4505
|
+
} // 文本节点入队
|
|
4506
|
+
|
|
4296
4507
|
|
|
4297
4508
|
_createClass(TextNodeQueue, [{
|
|
4298
4509
|
key: "push",
|
|
@@ -4305,7 +4516,8 @@ var TextNodeQueue = /*#__PURE__*/function () {
|
|
|
4305
4516
|
className: className,
|
|
4306
4517
|
updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge
|
|
4307
4518
|
});
|
|
4308
|
-
}
|
|
4519
|
+
} // 遍历,遍历过的文本节点出队
|
|
4520
|
+
|
|
4309
4521
|
}, {
|
|
4310
4522
|
key: "forEach",
|
|
4311
4523
|
value: function forEach(callback) {
|
|
@@ -4322,7 +4534,8 @@ var TextNodeQueue = /*#__PURE__*/function () {
|
|
|
4322
4534
|
// 处理完之后删除部分节点
|
|
4323
4535
|
this._queue.splice(idxStack.shift(), 1);
|
|
4324
4536
|
}
|
|
4325
|
-
}
|
|
4537
|
+
} // 更新队列的节点对象,主要解决前后节点不一致的问题
|
|
4538
|
+
|
|
4326
4539
|
}, {
|
|
4327
4540
|
key: "update",
|
|
4328
4541
|
value: function update(els) {
|