mp-darkmode 1.2.0-beta.0 → 1.2.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 CHANGED
@@ -2402,15 +2402,17 @@ __webpack_require__.r(__webpack_exports__);
2402
2402
  * @return void
2403
2403
  *
2404
2404
  */
2405
+
2405
2406
  // 常量
2406
2407
 
2407
- var classReg = new RegExp("".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "[^ ]+"), 'g'); // Darkmode配置
2408
+ var classReg = new RegExp("".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "[^ ]+"), 'g');
2408
2409
 
2410
+ // Darkmode配置
2409
2411
 
2410
- // Dark Mode切换
2411
2412
 
2412
- var mql = null;
2413
2413
 
2414
+ // Dark Mode切换
2415
+ var mql = null;
2414
2416
  var switchToDarkmode = function switchToDarkmode(mqlObj) {
2415
2417
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
2416
2418
  type: 'dom'
@@ -2421,7 +2423,6 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2421
2423
 
2422
2424
  try {
2423
2425
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].mode ? _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].mode === 'dark' : mqlObj.matches;
2424
-
2425
2426
  if (opt.type === 'dom') {
2426
2427
  // 处理节点
2427
2428
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode && typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].begin === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].begin(_modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].hasDelay());
@@ -2439,24 +2440,20 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2439
2440
  var rect = node.getBoundingClientRect();
2440
2441
  var top = rect.top;
2441
2442
  var bottom = rect.bottom;
2442
-
2443
2443
  if (top <= 0 && bottom <= 0) {
2444
2444
  // 首屏前面
2445
2445
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node)); // 写入非首屏样式
2446
2446
  } else if (top > 0 && top < _modules_constant__WEBPACK_IMPORTED_MODULE_0__["PAGE_HEIGHT"] || bottom > 0 && bottom < _modules_constant__WEBPACK_IMPORTED_MODULE_0__["PAGE_HEIGHT"]) {
2447
2447
  // 首屏
2448
2448
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].addFirstPageNode(node); // 记录首屏节点
2449
-
2450
2449
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node), true); // 写入首屏样式
2451
2450
  } else {
2452
2451
  // 首屏后面,理论上,这里最多只会进来一次
2453
2452
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage = false; // 至此,不需要再判断首屏了
2454
- // 显示首屏
2455
2453
 
2454
+ // 显示首屏
2456
2455
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle(true); // 写入首屏样式表
2457
-
2458
2456
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].showFirstPageNodes(); // 显示首屏节点
2459
-
2460
2457
  typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage(); // 执行首屏回调
2461
2458
 
2462
2459
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node)); // 写入非首屏样式
@@ -2464,6 +2461,7 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2464
2461
  }
2465
2462
  }
2466
2463
  });
2464
+
2467
2465
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].loopTimes++;
2468
2466
  } else if (opt.type === 'bg') {
2469
2467
  // 处理背景
@@ -2481,16 +2479,15 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2481
2479
  }
2482
2480
 
2483
2481
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle(); // 写入非首屏样式表
2484
-
2485
2482
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].emptyFirstPageNodes(); // 清空记录的首屏节点
2486
2483
 
2487
2484
  if (!_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode) {
2488
2485
  // 非Dark Mode
2489
2486
  // 首次加载页面时为非Dark Mode,标记为不需要判断首屏
2490
- _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage = false; // 首次加载页面时为非Dark Mode,标记为不延迟判断背景
2487
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage = false;
2491
2488
 
2489
+ // 首次加载页面时为非Dark Mode,标记为不延迟判断背景
2492
2490
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].delayBgJudge = false;
2493
-
2494
2491
  if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].container === null && opt.type === 'dom' && _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].length) {
2495
2492
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].delay(); // 将节点转移到延迟处理队列里
2496
2493
  }
@@ -2499,9 +2496,9 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2499
2496
  console.log('An error occurred when running the dark mode conversion algorithm\n', e);
2500
2497
  typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error(e);
2501
2498
  }
2502
- }; // 初始化Dark Mode配置并运行Dark Mode处理
2503
-
2499
+ };
2504
2500
 
2501
+ // 初始化Dark Mode配置并运行Dark Mode处理
2505
2502
  function run(nodes, opt) {
2506
2503
  init(opt); // 初始化配置
2507
2504
 
@@ -2511,8 +2508,9 @@ function run(nodes, opt) {
2511
2508
  type: 'dom'
2512
2509
  });
2513
2510
  }
2514
- ; // 初始化Dark Mode配置
2511
+ ;
2515
2512
 
2513
+ // 初始化Dark Mode配置
2516
2514
  function init() {
2517
2515
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2518
2516
  if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].hasInit) return; // 只可设置一次配置
@@ -2521,7 +2519,6 @@ function init() {
2521
2519
 
2522
2520
  var tagName = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].whitelist.tagName;
2523
2521
  var attribute = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].whitelist.attribute;
2524
-
2525
2522
  if (opt.whitelist) {
2526
2523
  opt.whitelist.tagName instanceof Array && opt.whitelist.tagName.forEach(function (item) {
2527
2524
  item = item.toUpperCase();
@@ -2531,12 +2528,10 @@ function init() {
2531
2528
  attribute.indexOf(item) === -1 && attribute.push(item);
2532
2529
  });
2533
2530
  }
2534
-
2535
2531
  if (['dark', 'light'].indexOf(opt.mode) > -1) {
2536
2532
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'mode');
2537
2533
  opt.mode === 'dark' && document.getElementsByTagName('html')[0].classList.add(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["HTML_CLASS"]);
2538
2534
  }
2539
-
2540
2535
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'begin');
2541
2536
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'showFirstPage');
2542
2537
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'error');
@@ -2549,21 +2544,20 @@ function init() {
2549
2544
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultDarkTextColor');
2550
2545
  _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultDarkBgColor');
2551
2546
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].init();
2552
-
2553
2547
  if (!_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].mode && mql === null && window.matchMedia) {
2554
2548
  // 匹配媒体查询
2555
2549
  mql = window.matchMedia(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["MEDIA_QUERY"]);
2556
2550
  mql.addListener(switchToDarkmode); // 监听
2557
2551
  }
2558
2552
  }
2559
- ; // 处理背景
2560
2553
 
2554
+ ;
2555
+
2556
+ // 处理背景
2561
2557
  function convertBg(nodes) {
2562
2558
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].set(nodes);
2563
-
2564
2559
  if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].container !== null) {
2565
2560
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["bgStack"].update(nodes); // 更新背景堆栈
2566
-
2567
2561
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["tnQueue"].update(nodes); // 更新文字队列
2568
2562
  }
2569
2563
 
@@ -2572,23 +2566,25 @@ function convertBg(nodes) {
2572
2566
  type: 'bg'
2573
2567
  });
2574
2568
  }
2575
- ; // 更新节点Dark Mode样式
2569
+ ;
2576
2570
 
2571
+ // 更新节点Dark Mode样式
2577
2572
  function updateStyle(node, styles) {
2578
2573
  if (!_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].isFinish) return; // 没有运行过Dark Mode处理逻辑则无需运行
2579
-
2580
2574
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node, styles ? Object.keys(styles).map(function (key) {
2581
2575
  return [key, styles[key]];
2582
2576
  }) : undefined, true), false);
2583
2577
  _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle();
2584
2578
  }
2585
- ; // 获取两个颜色的对比度
2579
+ ;
2586
2580
 
2581
+ // 获取两个颜色的对比度
2587
2582
  function getContrast(color1, color2) {
2588
2583
  return _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].getContrast(color1, color2);
2589
2584
  }
2590
- ; // 挂载插件
2585
+ ;
2591
2586
 
2587
+ // 挂载插件
2592
2588
  function extend(pluginList) {
2593
2589
  pluginList.forEach(function (plugin) {
2594
2590
  return _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].extend(plugin);
@@ -2610,13 +2606,9 @@ __webpack_require__.r(__webpack_exports__);
2610
2606
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BgNodeStack; });
2611
2607
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
2612
2608
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2613
-
2614
2609
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2615
-
2616
2610
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2617
-
2618
2611
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2619
-
2620
2612
  /**
2621
2613
  * @name 需要判断位置的背景节点堆栈
2622
2614
  *
@@ -2640,30 +2632,27 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2640
2632
  * @return void
2641
2633
  *
2642
2634
  */
2643
- // Darkmode配置
2644
2635
 
2636
+ // Darkmode配置
2645
2637
 
2646
2638
  var BgNodeStack = /*#__PURE__*/function () {
2647
2639
  // 需要判断位置的背景堆栈,{ el, className, cssKV, updated, rect }
2648
2640
  // 索引值
2641
+
2649
2642
  function BgNodeStack(prefix) {
2650
2643
  _classCallCheck(this, BgNodeStack);
2651
-
2652
2644
  _defineProperty(this, "_stack", []);
2653
-
2654
2645
  _defineProperty(this, "_idx", 0);
2655
-
2656
2646
  this._prefix = prefix;
2657
2647
  this.classNameReg = new RegExp("".concat(this._prefix, "\\d+"));
2658
- } // 背景节点入栈
2659
-
2648
+ }
2660
2649
 
2650
+ // 背景节点入栈
2661
2651
  _createClass(BgNodeStack, [{
2662
2652
  key: "push",
2663
2653
  value: function push(el, cssKV, cb) {
2664
2654
  var className = "".concat(this._prefix).concat(this._idx++);
2665
2655
  el.classList.add(className);
2666
-
2667
2656
  this._stack.unshift({
2668
2657
  el: el,
2669
2658
  className: className,
@@ -2671,33 +2660,31 @@ var BgNodeStack = /*#__PURE__*/function () {
2671
2660
  updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge,
2672
2661
  cb: cb
2673
2662
  });
2674
- } // 判断节点是否在背景节点的区域
2663
+ }
2675
2664
 
2665
+ // 判断节点是否在背景节点的区域
2676
2666
  }, {
2677
2667
  key: "contains",
2678
2668
  value: function contains(el, callback) {
2679
2669
  var rect = el.getBoundingClientRect();
2680
2670
  var idxStack = [];
2681
-
2682
2671
  this._stack.forEach(function (item, i) {
2683
2672
  if (item.updated) {
2684
2673
  if (!item.rect) item.rect = item.el.getBoundingClientRect();
2685
2674
  var bgRect = item.rect;
2686
-
2687
2675
  if (!(rect.top >= bgRect.bottom || rect.bottom <= bgRect.top || rect.left >= bgRect.right || rect.right <= bgRect.left)) {
2688
2676
  // 表示节点在背景图内
2689
2677
  idxStack.unshift(i);
2690
2678
  }
2691
2679
  }
2692
2680
  });
2693
-
2694
2681
  while (idxStack.length) {
2695
2682
  var item = this._stack.splice(idxStack.shift(), 1)[0];
2696
-
2697
2683
  typeof callback === 'function' && callback(item);
2698
2684
  }
2699
- } // 更新堆栈的节点对象,主要解决前后节点不一致的问题
2685
+ }
2700
2686
 
2687
+ // 更新堆栈的节点对象,主要解决前后节点不一致的问题
2701
2688
  }, {
2702
2689
  key: "update",
2703
2690
  value: function update(els) {
@@ -2709,18 +2696,15 @@ var BgNodeStack = /*#__PURE__*/function () {
2709
2696
  item.updated = true;
2710
2697
  return true;
2711
2698
  }
2712
-
2713
2699
  return false;
2714
2700
  });
2715
2701
  }
2716
2702
  });
2717
2703
  }
2718
2704
  }]);
2719
-
2720
2705
  return BgNodeStack;
2721
2706
  }();
2722
2707
 
2723
-
2724
2708
  ;
2725
2709
 
2726
2710
  /***/ }),
@@ -2779,45 +2763,44 @@ __webpack_require__.r(__webpack_exports__);
2779
2763
  */
2780
2764
 
2781
2765
 
2782
- color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
2783
2766
 
2767
+ color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补上这个colorName
2784
2768
  color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255, 0]; // 支持透明,暂定用白色透明度0来表示
2785
2769
 
2786
- // 常量
2787
2770
 
2771
+ // 常量
2788
2772
 
2789
2773
  var COLOR_NAME_REG = new RegExp(Object.keys(color_name__WEBPACK_IMPORTED_MODULE_1___default.a).map(function (colorName) {
2790
2774
  return "\\b".concat(colorName, "\\b");
2791
2775
  }).join('|'), 'ig'); // 生成正则表达式来匹配这些colorName
2792
- // Color对象 => ColorBlend对象
2793
2776
 
2777
+ // Color对象 => ColorBlend对象
2794
2778
  var color2ColorBlend = function color2ColorBlend(color) {
2795
2779
  var obj = color.object();
2796
2780
  obj.a = obj.alpha || 1;
2797
2781
  delete obj.alpha;
2798
2782
  return obj;
2799
- }; // ColorBlend对象 => Color对象
2800
-
2783
+ };
2801
2784
 
2785
+ // ColorBlend对象 => Color对象
2802
2786
  var colorBlend2Color = function colorBlend2Color(colorBlend) {
2803
2787
  colorBlend.alpha = colorBlend.a;
2804
2788
  delete colorBlend.a;
2805
2789
  return ColorParser(colorBlend);
2806
- }; // 实例化Color对象,传参非法时返回null
2807
-
2790
+ };
2808
2791
 
2792
+ // 实例化Color对象,传参非法时返回null
2809
2793
  var ColorParser = function ColorParser(color) {
2810
2794
  var res = null;
2811
-
2812
2795
  try {
2813
2796
  res = color instanceof color__WEBPACK_IMPORTED_MODULE_0___default.a ? color : color__WEBPACK_IMPORTED_MODULE_0___default()(color);
2814
2797
  } catch (e) {
2815
2798
  console.log("ignore the invalid color: `".concat(color, "`"));
2816
2799
  }
2817
-
2818
2800
  return res;
2819
- }; // 处理颜色,包括清除!important和转换英文定义颜色
2801
+ };
2820
2802
 
2803
+ // 处理颜色,包括清除!important和转换英文定义颜色
2821
2804
  var parseColorName = function parseColorName(color, supportTransparent) {
2822
2805
  return color.replace(_constant__WEBPACK_IMPORTED_MODULE_3__["IMPORTANT_REGEXP"], '').replace(COLOR_NAME_REG, function (match) {
2823
2806
  if (!supportTransparent && match === 'transparent') return match; // 如果不支持转换transparent,直接返回transparent
@@ -2825,20 +2808,21 @@ var parseColorName = function parseColorName(color, supportTransparent) {
2825
2808
  var color = color_name__WEBPACK_IMPORTED_MODULE_1___default.a[match.toLowerCase()];
2826
2809
  return "".concat(color.length > 3 ? 'rgba' : 'rgb', "(").concat(color.toString(), ")");
2827
2810
  });
2828
- }; // 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
2811
+ };
2829
2812
 
2813
+ // 处理-webkit-fill-color和-webkit-text-stroke-color,返回处理后的色值,无则返回空字符串
2830
2814
  var parseWebkitFillColorAndStrokeColor = function parseWebkitFillColorAndStrokeColor(color) {
2831
2815
  var newValue = parseColorName(color);
2832
2816
  return _constant__WEBPACK_IMPORTED_MODULE_3__["COLOR_REGEXP"].test(newValue) ? newValue : '';
2833
- }; // 计算混合颜色
2817
+ };
2834
2818
 
2819
+ // 计算混合颜色
2835
2820
  var mixColors = function mixColors(colors) {
2836
2821
  var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'mix';
2837
2822
  if (Object.prototype.toString.call(colors) !== '[object Array]' || colors.length < 1) return null;
2838
2823
  if (colors.length === 1) return colors[0];
2839
2824
  var color1 = ColorParser(colors.shift());
2840
2825
  var color2 = ColorParser(colors.shift());
2841
-
2842
2826
  while (color2) {
2843
2827
  if (!color1 && color2) {
2844
2828
  // 如果当前色值非法,混入色值合法,则直接使用混入色值
@@ -2852,24 +2836,23 @@ var mixColors = function mixColors(colors) {
2852
2836
  color1 = type === 'mix' ? color1.mix(color2, color2.alpha()) : colorBlend2Color(color_blend__WEBPACK_IMPORTED_MODULE_2__[type](color2ColorBlend(color1), color2ColorBlend(color2)));
2853
2837
  } // 如果当前色值合法,混入色值非法,无需处理
2854
2838
 
2855
-
2856
2839
  if (colors.length === 0) break;
2857
2840
  color2 = ColorParser(colors.shift());
2858
2841
  }
2859
-
2860
2842
  return color1 || null;
2861
- }; // 计算感知亮度
2843
+ };
2862
2844
 
2845
+ // 计算感知亮度
2863
2846
  var getColorPerceivedBrightness = function getColorPerceivedBrightness(rgb) {
2864
2847
  return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
2865
- }; // 调整为指定感知亮度
2848
+ };
2866
2849
 
2850
+ // 调整为指定感知亮度
2867
2851
  var adjustBrightnessTo = function adjustBrightnessTo(target, rgb) {
2868
2852
  var relativeBrightnessRatio = target / getColorPerceivedBrightness(rgb);
2869
2853
  var newTextR = Math.min(255, rgb[0] * relativeBrightnessRatio);
2870
2854
  var newTextG = Math.min(255, rgb[1] * relativeBrightnessRatio);
2871
2855
  var newTextB = Math.min(255, rgb[2] * relativeBrightnessRatio);
2872
-
2873
2856
  if (newTextG === 0 || newTextR === 255 || newTextB === 255) {
2874
2857
  newTextG = (target * 1000 - newTextR * 299 - newTextB * 114) / 587;
2875
2858
  } else if (newTextR === 0) {
@@ -2877,7 +2860,6 @@ var adjustBrightnessTo = function adjustBrightnessTo(target, rgb) {
2877
2860
  } else if (newTextB === 0 || newTextG === 255) {
2878
2861
  newTextB = (target * 1000 - newTextR * 299 - newTextG * 587) / 114;
2879
2862
  }
2880
-
2881
2863
  return color__WEBPACK_IMPORTED_MODULE_0___default.a.rgb(newTextR, newTextG, newTextB);
2882
2864
  };
2883
2865
 
@@ -2920,11 +2902,13 @@ __webpack_require__.r(__webpack_exports__);
2920
2902
  * @return void
2921
2903
  *
2922
2904
  */
2905
+
2923
2906
  // 常量
2924
2907
 
2925
2908
  var config = {
2926
2909
  hasInit: false,
2927
2910
  // 是否初始化过配置
2911
+
2928
2912
  // hooks
2929
2913
  begin: null,
2930
2914
  // 开始处理时触发的回调
@@ -2932,6 +2916,7 @@ var config = {
2932
2916
  // 首屏处理完成时触发的回调
2933
2917
  error: null,
2934
2918
  // 发生error时触发的回调
2919
+
2935
2920
  mode: '',
2936
2921
  // 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
2937
2922
  whitelist: {
@@ -2939,8 +2924,8 @@ var config = {
2939
2924
  tagName: ['MPCPS', 'IFRAME'],
2940
2925
  // 标签名列表
2941
2926
  attribute: [] // 属性列表
2942
-
2943
2927
  },
2928
+
2944
2929
  needJudgeFirstPage: true,
2945
2930
  // 是否需要判断首屏
2946
2931
  delayBgJudge: false,
@@ -2960,24 +2945,19 @@ var config = {
2960
2945
  // 设置配置
2961
2946
  set: function set(type, opt, key) {
2962
2947
  var value = opt[key];
2963
-
2964
2948
  switch (type) {
2965
2949
  case 'boolean':
2966
2950
  typeof value === 'boolean' && (this[key] = value);
2967
2951
  break;
2968
-
2969
2952
  case 'string':
2970
2953
  typeof value === 'string' && value !== '' && (this[key] = value);
2971
2954
  break;
2972
-
2973
2955
  case 'function':
2974
2956
  typeof value === 'function' && (this[key] = value);
2975
2957
  break;
2976
-
2977
2958
  case 'dom':
2978
2959
  value instanceof HTMLElement && (this[key] = value);
2979
2960
  break;
2980
-
2981
2961
  default:
2982
2962
  }
2983
2963
  }
@@ -2990,7 +2970,7 @@ var config = {
2990
2970
  /*!*********************************!*\
2991
2971
  !*** ./src/modules/constant.js ***!
2992
2972
  \*********************************/
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 */
2973
+ /*! exports provided: MEDIA_QUERY, CLASS_PREFIX, DM_CLASSNAME_REGEXP, HTML_CLASS, COLORATTR, BGCOLORATTR, ORIGINAL_COLORATTR, ORIGINAL_BGCOLORATTR, BGIMAGEATTR, COMPLEMENTARY_BGIMAGECOLORATTR, 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 */
2994
2974
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
2995
2975
 
2996
2976
  "use strict";
@@ -3004,6 +2984,7 @@ __webpack_require__.r(__webpack_exports__);
3004
2984
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ORIGINAL_COLORATTR", function() { return ORIGINAL_COLORATTR; });
3005
2985
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ORIGINAL_BGCOLORATTR", function() { return ORIGINAL_BGCOLORATTR; });
3006
2986
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BGIMAGEATTR", function() { return BGIMAGEATTR; });
2987
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "COMPLEMENTARY_BGIMAGECOLORATTR", function() { return COMPLEMENTARY_BGIMAGECOLORATTR; });
3007
2988
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BG_COLOR_DELIMITER", function() { return BG_COLOR_DELIMITER; });
3008
2989
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_LIGHT_TEXTCOLOR", function() { return DEFAULT_LIGHT_TEXTCOLOR; });
3009
2990
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_LIGHT_BGCOLOR", function() { return DEFAULT_LIGHT_BGCOLOR; });
@@ -3029,35 +3010,27 @@ __webpack_require__.r(__webpack_exports__);
3029
3010
  * @name 常量
3030
3011
  *
3031
3012
  */
3013
+
3032
3014
  var MEDIA_QUERY = '(prefers-color-scheme: dark)'; // Dark Mode的CSS媒体查询
3033
3015
 
3034
3016
  var CLASS_PREFIX = 'js_darkmode__'; // Dark Mode class前缀
3035
-
3036
3017
  var DM_CLASSNAME_REGEXP = new RegExp("".concat(CLASS_PREFIX, "\\d+"));
3037
3018
  var HTML_CLASS = 'data_color_scheme_dark'; // 强制设置暗黑模式时给html加的class
3038
3019
 
3039
3020
  var RANDOM = "".concat(new Date() * 1).concat(Math.round(Math.random() * 10)); // 生成个随机数,格式为时间戳+随机数
3040
-
3041
3021
  var COLORATTR = "data-darkmode-color-".concat(RANDOM); // dm color,即算法生成的新色值,单个
3042
-
3043
3022
  var BGCOLORATTR = "data-darkmode-bgcolor-".concat(RANDOM); // dm bg-color,即算法生成的新色值,有多个,用BG_COLOR_DELIMITER分割
3044
-
3045
3023
  var ORIGINAL_COLORATTR = "data-darkmode-original-color-".concat(RANDOM); // lm color,即原色值,单个
3046
-
3047
3024
  var ORIGINAL_BGCOLORATTR = "data-darkmode-original-bgcolor-".concat(RANDOM); // lm bg-color,即原色值,有多个,用BG_COLOR_DELIMITER分割
3048
-
3049
3025
  var BGIMAGEATTR = "data-darkmode-bgimage-".concat(RANDOM);
3026
+ var COMPLEMENTARY_BGIMAGECOLORATTR = "data-darkmode-complementary-bgimagecolor-".concat(RANDOM); // 背景图片的补色色值,单个
3050
3027
  var BG_COLOR_DELIMITER = '|';
3051
3028
  var DEFAULT_LIGHT_TEXTCOLOR = '#191919'; // 非Dark Mode下字体颜色
3052
-
3053
3029
  var DEFAULT_LIGHT_BGCOLOR = '#fff'; // 非Dark Mode下背景颜色
3054
-
3055
3030
  var DEFAULT_DARK_TEXTCOLOR = '#a3a3a3'; // Dark Mode下字体颜色,前景色:rgba(255,255,255,0.6) 背景色:#191919
3056
-
3057
3031
  var DEFAULT_DARK_BGCOLOR = '#191919'; // Dark Mode下背景颜色
3058
3032
 
3059
3033
  var WHITE_LIKE_COLOR_BRIGHTNESS = 250; // 接近白色的感知亮度阈值
3060
-
3061
3034
  var MAX_LIMIT_BGCOLOR_BRIGHTNESS = 190;
3062
3035
  var MIN_LIMIT_OFFSET_BRIGHTNESS = 65;
3063
3036
  var HIGH_BGCOLOR_BRIGHTNESS = 100;
@@ -3071,8 +3044,10 @@ var CSS_PROP_SERIES = {
3071
3044
  BG_COLOR: ['background-color', 'background-image', 'background'],
3072
3045
  TEXT_SHADOW: ['text-shadow'],
3073
3046
  TEXT_COLOR: ['-webkit-text-stroke', '-webkit-text-stroke-color', 'text-decoration', 'text-decoration-color', 'text-emphasis-color', 'color', '-webkit-text-fill-color'],
3074
- BORDER_COLOR: ['border-image', '-webkit-border-image', 'border', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-block-color', 'border-block-start-color', 'border-block-end-color', 'border-inline-color', 'border-inline-start-color', 'border-inline-end-color', 'outline', 'outline-color', 'box-shadow', // TODO: 不知道为啥之前没处理,后面需要留意下
3075
- 'column-rule', 'column-rule-color'] // SVG_COLOR: [ // TODO: SVG后面再处理
3047
+ BORDER_COLOR: ['border-image', '-webkit-border-image', 'border', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-block-color', 'border-block-start-color', 'border-block-end-color', 'border-inline-color', 'border-inline-start-color', 'border-inline-end-color', 'outline', 'outline-color', 'box-shadow',
3048
+ // TODO: 不知道为啥之前没处理,后面需要留意下
3049
+ 'column-rule', 'column-rule-color']
3050
+ // SVG_COLOR: [ // TODO: SVG后面再处理
3076
3051
  // 'fill',
3077
3052
  // 'stroke',
3078
3053
  // 'stop-color',
@@ -3082,18 +3057,16 @@ var CSS_PROP_SERIES = {
3082
3057
  // FILTER: [ // TODO: filter后面再考虑要不要处理
3083
3058
  // 'filter'
3084
3059
  // ],
3085
-
3086
3060
  };
3061
+
3087
3062
  var CSS_PROP_LIST = Object.keys(CSS_PROP_SERIES).map(function (key) {
3088
3063
  return CSS_PROP_SERIES[key].join('|');
3089
3064
  }).join('|').split('|'); // 支持的css属性平铺列表
3090
-
3091
3065
  var TABLE_NAME = ['TABLE', 'TR', 'TD', 'TH']; // 支持bgcolor属性的table标签列表
3092
3066
 
3093
3067
  var IMPORTANT_REGEXP = / !important$/; // !important
3094
3068
 
3095
3069
  var SEMICOLON_PLACEHOLDER = '<$#_SEMICOLON_#$>'; // 分号占位符
3096
-
3097
3070
  var SEMICOLON_PLACEHOLDER_REGEXP = /<\$#_SEMICOLON_#\$>/g;
3098
3071
  var COLOR_REGEXP = /\brgba?\([^)]+\)/i;
3099
3072
  var COLOR_REGEXP_GLOBAL = /\brgba?\([^)]+\)/ig;
@@ -3114,25 +3087,15 @@ __webpack_require__.r(__webpack_exports__);
3114
3087
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
3115
3088
  /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3116
3089
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3117
-
3118
3090
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3119
-
3120
3091
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3121
-
3122
3092
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
3123
-
3124
3093
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
3125
-
3126
3094
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3127
-
3128
3095
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3129
-
3130
3096
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3131
-
3132
3097
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3133
-
3134
3098
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3135
-
3136
3099
  /**
3137
3100
  * @name 样式相关操作工具对象
3138
3101
  *
@@ -3160,54 +3123,57 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
3160
3123
  * @return void
3161
3124
  *
3162
3125
  */
3126
+
3163
3127
  // 常量
3164
- // Darkmode配置
3165
3128
 
3166
3129
 
3130
+ // Darkmode配置
3167
3131
 
3168
3132
 
3169
3133
  var CssUtils = /*#__PURE__*/function () {
3170
3134
  // 首屏样式
3171
3135
  // 非首屏样式
3136
+
3172
3137
  // 是否运行过Dark Mode处理逻辑(写入过非首屏样式表则表示已运行过)
3138
+
3173
3139
  function CssUtils() {
3174
3140
  _classCallCheck(this, CssUtils);
3175
-
3176
3141
  _defineProperty(this, "_firstPageStyle", '');
3177
-
3178
3142
  _defineProperty(this, "_otherPageStyle", '');
3179
-
3180
3143
  _defineProperty(this, "isFinish", false);
3181
- } // 生成css键值对
3182
-
3144
+ }
3183
3145
 
3146
+ // 生成css键值对
3184
3147
  _createClass(CssUtils, [{
3185
3148
  key: "genCssKV",
3186
3149
  value: function genCssKV(key, val) {
3187
3150
  return "".concat(key, ": ").concat(val, " !important;");
3188
- } // 生成css,包括css选择器
3151
+ }
3189
3152
 
3153
+ // 生成css,包括css选择器
3190
3154
  }, {
3191
3155
  key: "genCss",
3192
3156
  value: function genCss(className, cssKV) {
3193
3157
  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, "}");
3194
- } // 加入css
3158
+ }
3195
3159
 
3160
+ // 加入css
3196
3161
  }, {
3197
3162
  key: "addCss",
3198
3163
  value: function addCss(css) {
3199
3164
  var isFirstPageStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3200
3165
  this[isFirstPageStyle ? '_firstPageStyle' : '_otherPageStyle'] += css;
3201
3166
  _global__WEBPACK_IMPORTED_MODULE_2__["plugins"].addCss(isFirstPageStyle);
3202
- } // 写入样式表
3167
+ }
3203
3168
 
3169
+ // 写入样式表
3204
3170
  }, {
3205
3171
  key: "writeStyle",
3206
3172
  value: function writeStyle() {
3207
3173
  var isFirstPageStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3208
3174
  !isFirstPageStyle && _global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode && (this.isFinish = true); // 在Dark Mode下一旦写入了非首屏样式表,则认为已经运行过Dark Mode处理逻辑
3209
- // 获取样式表内容
3210
3175
 
3176
+ // 获取样式表内容
3211
3177
  var styles = (_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode ? [{
3212
3178
  target: this,
3213
3179
  key: ['_firstPageStyle', '_otherPageStyle'],
@@ -3222,13 +3188,11 @@ var CssUtils = /*#__PURE__*/function () {
3222
3188
  needMediaQuery: false
3223
3189
  }]).map(function (_ref) {
3224
3190
  var target = _ref.target,
3225
- _ref$key = _slicedToArray(_ref.key, 2),
3226
- first = _ref$key[0],
3227
- other = _ref$key[1],
3228
- needMediaQuery = _ref.needMediaQuery;
3229
-
3191
+ _ref$key = _slicedToArray(_ref.key, 2),
3192
+ first = _ref$key[0],
3193
+ other = _ref$key[1],
3194
+ needMediaQuery = _ref.needMediaQuery;
3230
3195
  var styleKey = '';
3231
-
3232
3196
  if (!isFirstPageStyle) {
3233
3197
  // 如果是写入非首屏样式表,则连同首屏样式一起写入
3234
3198
  target[other] = target[first] + target[other];
@@ -3237,26 +3201,21 @@ var CssUtils = /*#__PURE__*/function () {
3237
3201
  } else {
3238
3202
  styleKey = first;
3239
3203
  }
3240
-
3241
3204
  var style = target[styleKey];
3242
-
3243
3205
  if (style) {
3244
3206
  target[styleKey] = ''; // 写入样式表后清空内存中的数据
3245
-
3246
3207
  return _config__WEBPACK_IMPORTED_MODULE_1__["default"].mode === 'dark' || !needMediaQuery ? style : "@media ".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["MEDIA_QUERY"], " {").concat(style, "}");
3247
3208
  }
3248
-
3249
3209
  return '';
3250
- }).join(''); // 写入样式表
3210
+ }).join('');
3251
3211
 
3212
+ // 写入样式表
3252
3213
  styles && document.head.insertAdjacentHTML('beforeend', "<style type=\"text/css\">".concat(styles, "</style>"));
3253
3214
  }
3254
3215
  }]);
3255
-
3256
3216
  return CssUtils;
3257
3217
  }();
3258
3218
 
3259
-
3260
3219
  ;
3261
3220
 
3262
3221
  /***/ }),
@@ -3277,25 +3236,15 @@ __webpack_require__.r(__webpack_exports__);
3277
3236
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
3278
3237
  /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3279
3238
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3280
-
3281
3239
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3282
-
3283
3240
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3284
-
3285
3241
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3286
-
3287
3242
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3288
-
3289
3243
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3290
-
3291
3244
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3292
-
3293
3245
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
3294
-
3295
3246
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3296
-
3297
3247
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
3298
-
3299
3248
  /**
3300
3249
  * @name 节点相关操作工具API
3301
3250
  *
@@ -3312,17 +3261,19 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
3312
3261
  * @return {string | null} 判断结果,如果有,返回class对应的lm色值,否则返回null
3313
3262
  *
3314
3263
  */
3264
+
3315
3265
  // Darkmode配置
3316
3266
 
3317
- // 获取某个节点及它的所有子节点
3318
3267
 
3268
+
3269
+ // 获取某个节点及它的所有子节点
3319
3270
  function getChildrenAndIt(el) {
3320
3271
  var _ref;
3321
-
3322
3272
  return (_ref = [el]).concat.apply(_ref, _toConsumableArray(el.querySelectorAll('*')));
3323
3273
  }
3324
- ; // 判断某个节点里是否包含文字节点
3274
+ ;
3325
3275
 
3276
+ // 判断某个节点里是否包含文字节点
3326
3277
  function hasTextNode(el) {
3327
3278
  // let cnt = '';
3328
3279
  // Array.prototype.forEach.call(el.childNodes, child => {
@@ -3333,13 +3284,14 @@ function hasTextNode(el) {
3333
3284
  // return cnt.length > 0;
3334
3285
  return el.textContent.replace(/\s/g, '').length > 0;
3335
3286
  }
3336
- ; // table的内部样式类对应的lm背景色
3287
+ ;
3337
3288
 
3289
+ // table的内部样式类对应的lm背景色
3338
3290
  var tableClassObj = {
3339
3291
  'ue-table-interlace-color-single': '#fcfcfc',
3340
3292
  'ue-table-interlace-color-double': '#f7faff'
3341
- }; // 判断table相关元素有没有指定class
3342
-
3293
+ };
3294
+ // 判断table相关元素有没有指定class
3343
3295
  function hasTableClass(el) {
3344
3296
  var color = null;
3345
3297
  Array.prototype.some.call(el.classList, function (className) {
@@ -3347,12 +3299,12 @@ function hasTableClass(el) {
3347
3299
  color = tableClassObj[className];
3348
3300
  return true;
3349
3301
  }
3350
-
3351
3302
  return false;
3352
3303
  });
3353
3304
  return color;
3354
3305
  }
3355
3306
  ;
3307
+
3356
3308
  /**
3357
3309
  * @name 节点相关操作工具对象
3358
3310
  *
@@ -3390,38 +3342,37 @@ var DomUtils = /*#__PURE__*/function () {
3390
3342
  // 要处理的节点列表
3391
3343
  // 首屏节点列表
3392
3344
  // 延迟处理的节点列表
3345
+
3393
3346
  // 是否已显示首屏
3347
+
3394
3348
  function DomUtils() {
3395
3349
  _classCallCheck(this, DomUtils);
3396
-
3397
3350
  _defineProperty(this, "_els", []);
3398
-
3399
3351
  _defineProperty(this, "_firstPageEls", []);
3400
-
3401
3352
  _defineProperty(this, "_delayEls", []);
3402
-
3403
3353
  _defineProperty(this, "showFirstPage", false);
3404
- } // 要处理的节点列表长度
3405
-
3354
+ }
3406
3355
 
3356
+ // 要处理的节点列表长度
3407
3357
  _createClass(DomUtils, [{
3408
3358
  key: "length",
3409
3359
  get: function get() {
3410
3360
  return this._els.length;
3411
- } // 设置要处理的节点列表
3361
+ }
3412
3362
 
3363
+ // 设置要处理的节点列表
3413
3364
  }, {
3414
3365
  key: "set",
3415
3366
  value: function set() {
3416
3367
  var els = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3417
3368
  this._els = els;
3418
- } // 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
3369
+ }
3419
3370
 
3371
+ // 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
3420
3372
  }, {
3421
3373
  key: "get",
3422
3374
  value: function get() {
3423
3375
  var res = [];
3424
-
3425
3376
  if (this._els.length) {
3426
3377
  // 有节点
3427
3378
  res = this._els;
@@ -3437,54 +3388,52 @@ var DomUtils = /*#__PURE__*/function () {
3437
3388
  res = _config__WEBPACK_IMPORTED_MODULE_0__["default"].container.querySelectorAll('*');
3438
3389
  }
3439
3390
  }
3440
-
3441
3391
  return res;
3442
- } // 将所有要处理的节点转移到延迟处理队列里
3392
+ }
3443
3393
 
3394
+ // 将所有要处理的节点转移到延迟处理队列里
3444
3395
  }, {
3445
3396
  key: "delay",
3446
3397
  value: function delay() {
3447
3398
  var _this = this;
3448
-
3449
3399
  Array.prototype.forEach.call(this._els, function (el) {
3450
3400
  return _this._delayEls.push(el);
3451
3401
  }); // 转移到延迟处理的节点里
3452
-
3453
3402
  this._els = []; // 转移后清空列表
3454
- } // 判断是否包含延迟处理的节点
3403
+ }
3455
3404
 
3405
+ // 判断是否包含延迟处理的节点
3456
3406
  }, {
3457
3407
  key: "hasDelay",
3458
3408
  value: function hasDelay() {
3459
3409
  if (this._els.length) return false; // 有节点,即不含延迟处理的节点
3460
-
3461
3410
  return this._delayEls.length > 0 || _config__WEBPACK_IMPORTED_MODULE_0__["default"].container !== null; // 否则需要判断延迟节点的列表和容器
3462
- } // 添加首屏节点
3411
+ }
3463
3412
 
3413
+ // 添加首屏节点
3464
3414
  }, {
3465
3415
  key: "addFirstPageNode",
3466
3416
  value: function addFirstPageNode(el) {
3467
3417
  this._firstPageEls.push(el);
3468
- } // 显示所有首屏节点
3418
+ }
3469
3419
 
3420
+ // 显示所有首屏节点
3470
3421
  }, {
3471
3422
  key: "showFirstPageNodes",
3472
3423
  value: function showFirstPageNodes() {
3473
3424
  this._firstPageEls.forEach(function (el) {
3474
3425
  return !el.style.visibility && (el.style.visibility = 'visible');
3475
3426
  }); // 显示首屏节点
3476
-
3477
-
3478
3427
  this.showFirstPage = true; // 记录为已显示首屏
3479
- } // 清空记录的首屏节点
3428
+ }
3480
3429
 
3430
+ // 清空记录的首屏节点
3481
3431
  }, {
3482
3432
  key: "emptyFirstPageNodes",
3483
3433
  value: function emptyFirstPageNodes() {
3484
3434
  this._firstPageEls = [];
3485
3435
  }
3486
3436
  }]);
3487
-
3488
3437
  return DomUtils;
3489
3438
  }();
3490
3439
  ;
@@ -3517,24 +3466,31 @@ __webpack_require__.r(__webpack_exports__);
3517
3466
  * @name 全局作用域
3518
3467
  *
3519
3468
  */
3469
+
3520
3470
  // 常量
3521
- // 插件系统
3522
3471
 
3523
3472
 
3524
- var plugins = new _plugins__WEBPACK_IMPORTED_MODULE_1__["default"](); // 文本节点队列
3473
+ // 插件系统
3474
+
3475
+ var plugins = new _plugins__WEBPACK_IMPORTED_MODULE_1__["default"]();
3525
3476
 
3477
+ // 文本节点队列
3526
3478
 
3527
- var tnQueue = new _textNodeQueue__WEBPACK_IMPORTED_MODULE_2__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "text__")); // 需要判断位置的背景节点堆栈
3479
+ var tnQueue = new _textNodeQueue__WEBPACK_IMPORTED_MODULE_2__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "text__"));
3528
3480
 
3481
+ // 需要判断位置的背景节点堆栈
3529
3482
 
3530
- var bgStack = new _bgNodeStack__WEBPACK_IMPORTED_MODULE_3__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "bg__")); // 样式相关操作工具对象
3483
+ var bgStack = new _bgNodeStack__WEBPACK_IMPORTED_MODULE_3__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "bg__"));
3531
3484
 
3485
+ // 样式相关操作工具对象
3532
3486
 
3533
- var cssUtils = new _cssUtils__WEBPACK_IMPORTED_MODULE_4__["default"](); // 节点相关操作工具对象
3487
+ var cssUtils = new _cssUtils__WEBPACK_IMPORTED_MODULE_4__["default"]();
3534
3488
 
3489
+ // 节点相关操作工具对象
3535
3490
 
3536
- var domUtils = new _domUtils__WEBPACK_IMPORTED_MODULE_5__["DomUtils"](); // sdk
3491
+ var domUtils = new _domUtils__WEBPACK_IMPORTED_MODULE_5__["DomUtils"]();
3537
3492
 
3493
+ // sdk
3538
3494
 
3539
3495
  var sdk = new _sdk__WEBPACK_IMPORTED_MODULE_6__["default"]();
3540
3496
 
@@ -3552,13 +3508,9 @@ __webpack_require__.r(__webpack_exports__);
3552
3508
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Plugins; });
3553
3509
  /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3554
3510
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3555
-
3556
3511
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3557
-
3558
3512
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3559
-
3560
3513
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3561
-
3562
3514
  /**
3563
3515
  * @name 插件基类
3564
3516
  *
@@ -3576,39 +3528,40 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
3576
3528
  *
3577
3529
  */
3578
3530
 
3531
+
3579
3532
  var cssNeedMQ = [];
3580
3533
  var cssNoMQ = [];
3581
-
3582
3534
  var Plugin = /*#__PURE__*/function () {
3583
3535
  function Plugin() {
3584
3536
  _classCallCheck(this, Plugin);
3585
- } // 遍历次数(全部节点遍历结束算一次)
3586
-
3537
+ }
3587
3538
 
3539
+ // 遍历次数(全部节点遍历结束算一次)
3588
3540
  _createClass(Plugin, [{
3589
3541
  key: "loopTimes",
3590
3542
  get: function get() {
3591
3543
  return _global__WEBPACK_IMPORTED_MODULE_0__["plugins"].loopTimes;
3592
- } // 是否为Dark Mode
3544
+ }
3593
3545
 
3546
+ // 是否为Dark Mode
3594
3547
  }, {
3595
3548
  key: "isDarkmode",
3596
3549
  get: function get() {
3597
3550
  return _global__WEBPACK_IMPORTED_MODULE_0__["sdk"].isDarkmode;
3598
- } // 添加样式
3551
+ }
3599
3552
 
3553
+ // 添加样式
3600
3554
  }, {
3601
3555
  key: "addCss",
3602
3556
  value: function addCss(className, kvList) {
3603
3557
  var needMediaQuery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3604
3558
  (needMediaQuery ? cssNeedMQ : cssNoMQ).push(_global__WEBPACK_IMPORTED_MODULE_0__["cssUtils"].genCss(className, kvList.map(function (_ref) {
3605
3559
  var key = _ref.key,
3606
- value = _ref.value;
3560
+ value = _ref.value;
3607
3561
  return _global__WEBPACK_IMPORTED_MODULE_0__["cssUtils"].genCssKV(key, value);
3608
3562
  }).join('')));
3609
3563
  }
3610
3564
  }]);
3611
-
3612
3565
  return Plugin;
3613
3566
  }();
3614
3567
  /**
@@ -3640,55 +3593,48 @@ var Plugin = /*#__PURE__*/function () {
3640
3593
  * @return void
3641
3594
  *
3642
3595
  */
3643
-
3644
-
3645
3596
  var Plugins = /*#__PURE__*/function () {
3646
3597
  // 已挂载的插件列表
3598
+
3647
3599
  // 已挂载的插件数量
3648
3600
  // 已遍历次数(全部节点遍历结束算一次)
3649
3601
  // 首屏样式
3650
3602
  // 非首屏样式
3651
3603
  // 首屏样式(不需要加媒体查询)
3652
3604
  // 非首屏样式(不需要加媒体查询)
3605
+
3653
3606
  function Plugins() {
3654
3607
  _classCallCheck(this, Plugins);
3655
-
3656
3608
  _defineProperty(this, "_plugins", []);
3657
-
3658
3609
  _defineProperty(this, "length", 0);
3659
-
3660
3610
  _defineProperty(this, "loopTimes", 0);
3661
-
3662
3611
  _defineProperty(this, "firstPageStyle", '');
3663
-
3664
3612
  _defineProperty(this, "otherPageStyle", '');
3665
-
3666
3613
  _defineProperty(this, "firstPageStyleNoMQ", '');
3667
-
3668
3614
  _defineProperty(this, "otherPageStyleNoMQ", '');
3669
- } // 挂载插件
3670
-
3615
+ }
3671
3616
 
3617
+ // 挂载插件
3672
3618
  _createClass(Plugins, [{
3673
3619
  key: "extend",
3674
3620
  value: function extend(plugin) {
3675
3621
  this._plugins.push(new (plugin(Plugin))());
3676
-
3677
3622
  this.length++;
3678
- } // 执行插件钩子
3623
+ }
3679
3624
 
3625
+ // 执行插件钩子
3680
3626
  }, {
3681
3627
  key: "emit",
3682
3628
  value: function emit(name) {
3683
3629
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3684
3630
  args[_key - 1] = arguments[_key];
3685
3631
  }
3686
-
3687
3632
  this._plugins.forEach(function (plugin) {
3688
3633
  typeof plugin[name] === 'function' && plugin[name].apply(plugin, args);
3689
3634
  });
3690
- } // 写入插件样式
3635
+ }
3691
3636
 
3637
+ // 写入插件样式
3692
3638
  }, {
3693
3639
  key: "addCss",
3694
3640
  value: function addCss(isFirstPageStyle) {
@@ -3699,8 +3645,9 @@ var Plugins = /*#__PURE__*/function () {
3699
3645
  this.otherPageStyle += cssNeedMQ.join('');
3700
3646
  this.otherPageStyleNoMQ += cssNoMQ.join('');
3701
3647
  }
3702
- } // 重置插件样式
3648
+ }
3703
3649
 
3650
+ // 重置插件样式
3704
3651
  }, {
3705
3652
  key: "resetCss",
3706
3653
  value: function resetCss() {
@@ -3708,11 +3655,9 @@ var Plugins = /*#__PURE__*/function () {
3708
3655
  cssNoMQ = [];
3709
3656
  }
3710
3657
  }]);
3711
-
3712
3658
  return Plugins;
3713
3659
  }();
3714
3660
 
3715
-
3716
3661
  ;
3717
3662
 
3718
3663
  /***/ }),
@@ -3735,33 +3680,19 @@ __webpack_require__.r(__webpack_exports__);
3735
3680
  /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3736
3681
  /* harmony import */ var _domUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./domUtils */ "./src/modules/domUtils.js");
3737
3682
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3738
-
3739
3683
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3740
-
3741
3684
  function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
3742
-
3743
3685
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3744
-
3745
3686
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3746
-
3747
3687
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3748
-
3749
3688
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3750
-
3751
3689
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
3752
-
3753
3690
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3754
-
3755
3691
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
3756
-
3757
3692
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3758
-
3759
3693
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3760
-
3761
3694
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3762
-
3763
3695
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3764
-
3765
3696
  /**
3766
3697
  * @name 算法SDK
3767
3698
  *
@@ -3782,43 +3713,39 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
3782
3713
  * @return {number} 颜色对比度,取值范围为`[1, 21]`
3783
3714
  *
3784
3715
  */
3716
+
3785
3717
  // 颜色操作相关API
3786
3718
 
3787
- // 常量
3788
3719
 
3789
- // Darkmode配置
3720
+
3721
+ // 常量
3790
3722
 
3791
3723
 
3792
- // 节点相关操作工具API
3724
+ // Darkmode配置
3793
3725
 
3794
3726
 
3795
3727
 
3728
+ // 节点相关操作工具API
3729
+
3796
3730
  var SDK = /*#__PURE__*/function () {
3797
3731
  // 索引值
3732
+
3798
3733
  // 当前是否需要运行Darkmode处理
3734
+
3799
3735
  function SDK() {
3800
3736
  _classCallCheck(this, SDK);
3801
-
3802
3737
  _defineProperty(this, "_idx", 0);
3803
-
3804
3738
  _defineProperty(this, "_defaultDarkTextColorRgb", null);
3805
-
3806
3739
  _defineProperty(this, "_defaultDarkBgColorRgb", null);
3807
-
3808
3740
  _defineProperty(this, "_defaultDarkBgColorHSL", null);
3809
-
3810
3741
  _defineProperty(this, "_defaultDarkTextColorBrightness", null);
3811
-
3812
3742
  _defineProperty(this, "_defaultDarkBgColorBrightness", null);
3813
-
3814
3743
  _defineProperty(this, "_defaultDarkBgColorHslBrightness", null);
3815
-
3816
3744
  _defineProperty(this, "_maxLimitOffsetBrightness", null);
3817
-
3818
3745
  _defineProperty(this, "isDarkmode", false);
3819
- } // 调整明度
3820
-
3746
+ }
3821
3747
 
3748
+ // 调整明度
3822
3749
  _createClass(SDK, [{
3823
3750
  key: "_adjustBrightness",
3824
3751
  value: function _adjustBrightness(color, el, options, isUpdate) {
@@ -3828,34 +3755,46 @@ var SDK = /*#__PURE__*/function () {
3828
3755
  // 黑白灰色(h=0,s=0)亮度大于HIGH_BLACKWHITE_HSL_BRIGHTNESS时,做取反处理;
3829
3756
  // 感知亮度大于MAX_LIMIT_BGCOLOR_BRIGHTNESS,取MAX_LIMIT_BGCOLOR_BRIGHTNESS;
3830
3757
  // 其他亮度小于LOW_BLACKWHITE_HSL_BRIGHTNESS时,设为LOW_BLACKWHITE_HSL_BRIGHTNESS。
3758
+
3831
3759
  // 字体、边框:
3832
3760
  // 处理原则:根据调整后的背景颜色和最小亮度差值算出字体颜色,接近白色字体颜色保持不变,带背景图片子元素字体颜色不变
3833
3761
  // 处理方法:亮度小于HIGH_BLACKWHITE_HSL_BRIGHTNESS时,用(90%-该亮度),大于等于HIGH_BLACKWHITE_HSL_BRIGHTNESS则保持不变;
3762
+
3834
3763
  // 字体阴影
3835
3764
  // 处理方法:按照背景的处理方法来处理
3765
+
3836
3766
  var alpha = color.alpha();
3837
3767
  var newColor;
3838
3768
  var extStyle = '';
3839
-
3840
3769
  if (options.isBgColor) {
3841
3770
  // 背景色
3842
- // 如果设置背景颜色,取消背景图片的影响
3843
- if (el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]] && alpha >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
3844
- delete el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]];
3771
+ if (alpha >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
3772
+ // 如果设置背景颜色,取消背景图片的影响
3773
+ if (el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) delete el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]];
3774
+
3775
+ // 如果有背景图片补色
3776
+ if (el[_constant__WEBPACK_IMPORTED_MODULE_2__["COMPLEMENTARY_BGIMAGECOLORATTR"]]) {
3777
+ // 背景图片补色和当前背景色一致,则无需处理
3778
+ if (el[_constant__WEBPACK_IMPORTED_MODULE_2__["COMPLEMENTARY_BGIMAGECOLORATTR"]] === color.toString()) return {
3779
+ newColor: '',
3780
+ extStyle: extStyle
3781
+ };
3782
+
3783
+ // 否则取消背景图片补色的影响
3784
+ Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
3785
+ delete dom[_constant__WEBPACK_IMPORTED_MODULE_2__["COMPLEMENTARY_BGIMAGECOLORATTR"]];
3786
+ });
3787
+ }
3845
3788
  }
3846
-
3847
3789
  newColor = this._adjustBackgroundBrightness(color);
3848
-
3849
3790
  if (!options.hasInlineColor) {
3850
3791
  var parentTextColorStr = el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor;
3851
3792
  var parentTextColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(parentTextColorStr);
3852
-
3853
3793
  if (parentTextColor) {
3854
3794
  var ret = this._adjustBrightness(parentTextColor, el, {
3855
3795
  isTextColor: true,
3856
3796
  parentElementBgColorStr: newColor || color
3857
3797
  }, isUpdate);
3858
-
3859
3798
  if (ret.newColor) {
3860
3799
  extStyle += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', ret.newColor);
3861
3800
  } else {
@@ -3866,8 +3805,9 @@ var SDK = /*#__PURE__*/function () {
3866
3805
  } else if (options.isTextColor || options.isBorderColor) {
3867
3806
  // 字体色、边框色
3868
3807
  var parentElementBgColorStr = options.parentElementBgColorStr || options.isTextColor && el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor;
3869
- var parentElementBgColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(parentElementBgColorStr); // 无背景图片
3808
+ var parentElementBgColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(parentElementBgColorStr);
3870
3809
 
3810
+ // 无背景图片
3871
3811
  if (parentElementBgColor && !el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
3872
3812
  newColor = this._adjustTextBrightness(color, parentElementBgColor);
3873
3813
  _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit("afterConvertTextColor".concat(isUpdate ? 'ByUpdateStyle' : ''), el, {
@@ -3888,8 +3828,9 @@ var SDK = /*#__PURE__*/function () {
3888
3828
  newColor: newColor && color.toString() !== newColor.toString() && newColor.alpha(alpha).rgb(),
3889
3829
  extStyle: extStyle
3890
3830
  };
3891
- } // 调整文本明度
3831
+ }
3892
3832
 
3833
+ // 调整文本明度
3893
3834
  }, {
3894
3835
  key: "_adjustTextBrightness",
3895
3836
  value: function _adjustTextBrightness(textColor, bgColor) {
@@ -3901,17 +3842,16 @@ var SDK = /*#__PURE__*/function () {
3901
3842
  var textColorHSL = textColor.hsl().array();
3902
3843
  var textColorAlpha = textColor.alpha();
3903
3844
  var textPerceivedBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(textColorRgb);
3904
- var offsetPerceivedBrightness = Math.abs(bgColorWithOpacityPerceivedBrightness - textPerceivedBrightness); // 用户设置为高亮字体颜色(接近白色亮度),不处理,保持高亮
3845
+ var offsetPerceivedBrightness = Math.abs(bgColorWithOpacityPerceivedBrightness - textPerceivedBrightness);
3905
3846
 
3847
+ // 用户设置为高亮字体颜色(接近白色亮度),不处理,保持高亮
3906
3848
  if (textPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) return textColor;
3907
-
3908
3849
  if (offsetPerceivedBrightness > this._maxLimitOffsetBrightness && bgColorWithOpacityPerceivedBrightness <= this._defaultDarkBgColorBrightness + 2) {
3909
3850
  return Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(this._maxLimitOffsetBrightness + bgColorWithOpacityPerceivedBrightness, textColorRgb).alpha(textColorAlpha);
3910
- } // 如果感知亮度差大于阈值,无需调整
3911
-
3851
+ }
3912
3852
 
3853
+ // 如果感知亮度差大于阈值,无需调整
3913
3854
  if (offsetPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]) return textColor;
3914
-
3915
3855
  if (bgColorWithOpacityPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BGCOLOR_BRIGHTNESS"]) {
3916
3856
  // 亮背景,调暗字体
3917
3857
  if (textColorHSL[2] > 90 - _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
@@ -3920,23 +3860,20 @@ var SDK = /*#__PURE__*/function () {
3920
3860
  var tmpTextColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(textColorHSL)).alpha(textColorAlpha);
3921
3861
  return this._adjustTextBrightness(tmpTextColor, bgColor);
3922
3862
  }
3923
-
3924
3863
  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
3864
  } else {
3926
3865
  // 暗背景,调亮字体
3927
3866
  if (textColorHSL[2] <= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
3928
3867
  // 优先调字体的亮度已带到提高感知亮度的目的
3929
3868
  textColorHSL[2] = 90 - textColorHSL[2];
3930
-
3931
3869
  var _tmpTextColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(textColorHSL)).alpha(textColorAlpha);
3932
-
3933
3870
  return this._adjustTextBrightness(_tmpTextColor, bgColor);
3934
3871
  }
3935
-
3936
3872
  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
3873
  }
3938
- } // 调整背景明度
3874
+ }
3939
3875
 
3876
+ // 调整背景明度
3940
3877
  }, {
3941
3878
  key: "_adjustBackgroundBrightness",
3942
3879
  value: function _adjustBackgroundBrightness(bgColor) {
@@ -3945,13 +3882,13 @@ var SDK = /*#__PURE__*/function () {
3945
3882
  var bgColorAlpha = bgColor.alpha();
3946
3883
  var bgColorPerceivedBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(bgColorRgb);
3947
3884
  var newColor = bgColor;
3948
-
3949
3885
  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
3886
  // 饱和度为0(黑白灰色),亮度大于HIGH_BLACKWHITE_HSL_BRIGHTNESS或感知亮度大于WHITE_LIKE_COLOR_BRIGHTNESS(白色)时,做亮度取反处理
3951
3887
  newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl(0, 0, Math.min(100, 100 + this._defaultDarkBgColorHslBrightness - bgColorHsl[2]));
3952
3888
  } else if (bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"]) {
3953
3889
  // 感知亮度大于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)
3890
+ newColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["adjustBrightnessTo"])(_constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"], bgColorRgb).alpha(bgColorAlpha);
3891
+ // const ratio = (MAX_LIMIT_BGCOLOR_BRIGHTNESS * 1000)
3955
3892
  // / (bgColorRgb[0] * 299 + bgColorRgb[1] * 587 + bgColorRgb[2] * 114);
3956
3893
  // newColor = Color.rgb(bgColorRgb[0] * ratio, bgColorRgb[1] * ratio, bgColorRgb[2] * ratio);
3957
3894
  } else if (bgColorHsl[2] < _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"]) {
@@ -3959,10 +3896,10 @@ var SDK = /*#__PURE__*/function () {
3959
3896
  bgColorHsl[2] = _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"];
3960
3897
  newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl.apply(color__WEBPACK_IMPORTED_MODULE_0___default.a, _toConsumableArray(bgColorHsl));
3961
3898
  }
3962
-
3963
3899
  return newColor.alpha(bgColorAlpha).rgb();
3964
- } // 叠加渐变色到背景色中,并更新背景色相关属性值以及文本颜色
3900
+ }
3965
3901
 
3902
+ // 叠加渐变色到背景色中,并更新背景色相关属性值以及文本颜色
3966
3903
  }, {
3967
3904
  key: "_updateBgWithGradient",
3968
3905
  value: function _updateBgWithGradient(gradientColor, el, className, cssKVList, hasInlineColor, isUpdate) {
@@ -3973,7 +3910,6 @@ var SDK = /*#__PURE__*/function () {
3973
3910
  dom[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]] = newOriginalBgColor;
3974
3911
  });
3975
3912
  var lastKV = cssKVList.slice(-1)[0];
3976
-
3977
3913
  if (lastKV[0] === 'color') {
3978
3914
  var ret = this._adjustBrightness(Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseColorName"])(lastKV[1])), el, {
3979
3915
  isBgColor: false,
@@ -3982,10 +3918,8 @@ var SDK = /*#__PURE__*/function () {
3982
3918
  isBorderColor: false,
3983
3919
  hasInlineColor: hasInlineColor
3984
3920
  }, isUpdate);
3985
-
3986
3921
  if (ret.newColor) return _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(className, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', ret.newColor));
3987
3922
  }
3988
-
3989
3923
  return '';
3990
3924
  }
3991
3925
  }, {
@@ -3997,8 +3931,9 @@ var SDK = /*#__PURE__*/function () {
3997
3931
  console.log('An error occurred when running the dark mode conversion algorithm\n', e);
3998
3932
  typeof _config__WEBPACK_IMPORTED_MODULE_3__["default"].error === 'function' && _config__WEBPACK_IMPORTED_MODULE_3__["default"].error(e);
3999
3933
  }
4000
- } // 初始化
3934
+ }
4001
3935
 
3936
+ // 初始化
4002
3937
  }, {
4003
3938
  key: "init",
4004
3939
  value: function init() {
@@ -4009,17 +3944,16 @@ var SDK = /*#__PURE__*/function () {
4009
3944
  this._defaultDarkBgColorBrightness = Object(_color__WEBPACK_IMPORTED_MODULE_1__["getColorPerceivedBrightness"])(this._defaultDarkBgColorRgb);
4010
3945
  this._defaultDarkBgColorHslBrightness = this._defaultDarkBgColorHSL[2];
4011
3946
  this._maxLimitOffsetBrightness = this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness;
4012
- } // 处理节点
3947
+ }
4013
3948
 
3949
+ // 处理节点
4014
3950
  }, {
4015
3951
  key: "convert",
4016
3952
  value: function convert(el, cssKVList, isUpdate) {
4017
3953
  var _this = this;
4018
-
4019
3954
  _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].resetCss();
4020
3955
  _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit("beforeConvertNode".concat(isUpdate ? 'ByUpdateStyle' : ''), el);
4021
3956
  var css = ''; // css
4022
-
4023
3957
  var bgCss = ''; // 文字底图css
4024
3958
 
4025
3959
  if (this.isDarkmode || isUpdate) {
@@ -4029,7 +3963,6 @@ var SDK = /*#__PURE__*/function () {
4029
3963
  return el.hasAttribute(attribute);
4030
3964
  })) return '';
4031
3965
  var styles = el.style;
4032
-
4033
3966
  if (!cssKVList) {
4034
3967
  // 没有传入cssKVList就从内联样式中提取
4035
3968
  // styles.cssText 读出来的颜色统一是rgba格式,除了用英文定义颜色(如:black、white)
@@ -4041,43 +3974,36 @@ var SDK = /*#__PURE__*/function () {
4041
3974
  });
4042
3975
  });
4043
3976
  }
4044
-
4045
3977
  var hasInlineColor = false; // 是否有自定义字体颜色
4046
-
4047
3978
  var hasInlineBackground = false;
4048
3979
  var hasInlineBackgroundImage = false;
4049
3980
  var elBackgroundPositionAttr = null;
4050
3981
  var elBackgroundSizeAttr = null;
4051
3982
  cssKVList = cssKVList.filter(function (_ref) {
4052
3983
  var _ref2 = _slicedToArray(_ref, 2),
4053
- key = _ref2[0],
4054
- value = _ref2[1];
4055
-
3984
+ key = _ref2[0],
3985
+ value = _ref2[1];
4056
3986
  if (key === 'color') {
4057
3987
  hasInlineColor = true;
4058
3988
  } else if (/background/i.test(key)) {
4059
3989
  hasInlineBackground = true;
4060
-
4061
3990
  if (key === 'background-position') {
4062
3991
  elBackgroundPositionAttr = value;
4063
3992
  } else if (key === 'background-size') {
4064
3993
  elBackgroundSizeAttr = value;
4065
3994
  }
4066
3995
  }
4067
-
4068
3996
  if ((/background/i.test(key) || /^(-webkit-)?border-image/.test(key)) && /url\([^)]*\)/i.test(value)) {
4069
3997
  hasInlineBackgroundImage = true;
4070
- } // 过滤掉一些key
4071
-
3998
+ }
4072
3999
 
4000
+ // 过滤掉一些key
4073
4001
  return _constant__WEBPACK_IMPORTED_MODULE_2__["CSS_PROP_LIST"].indexOf(key) > -1;
4074
4002
  }).sort(function (_ref3, _ref4) {
4075
4003
  var _ref5 = _slicedToArray(_ref3, 1),
4076
- key1 = _ref5[0];
4077
-
4004
+ key1 = _ref5[0];
4078
4005
  var _ref6 = _slicedToArray(_ref4, 1),
4079
- key2 = _ref6[0];
4080
-
4006
+ key2 = _ref6[0];
4081
4007
  // color属性放在最后
4082
4008
  if (key1 === 'color') {
4083
4009
  return 1;
@@ -4088,21 +4014,16 @@ var SDK = /*#__PURE__*/function () {
4088
4014
  // 把-webkit-text的属性放在最前面
4089
4015
  return 1;
4090
4016
  }
4091
-
4092
4017
  return -1;
4093
4018
  });
4094
-
4095
4019
  if (_constant__WEBPACK_IMPORTED_MODULE_2__["TABLE_NAME"].indexOf(nodeName) > -1 && !hasInlineBackground) {
4096
4020
  // 如果table没有内联样式
4097
4021
  this._try(function () {
4098
4022
  var colorStr = Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["hasTableClass"])(el); // 获取class对应的lm色值
4099
-
4100
4023
  if (!colorStr) colorStr = el.getAttribute('bgcolor'); // 如果没有class则获取bgcolor的色值
4101
-
4102
4024
  if (colorStr) {
4103
4025
  // 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
4104
4026
  var color = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr);
4105
-
4106
4027
  if (color) {
4107
4028
  cssKVList.unshift(['background-color', color.toString()]);
4108
4029
  hasInlineBackground = true;
@@ -4110,38 +4031,33 @@ var SDK = /*#__PURE__*/function () {
4110
4031
  }
4111
4032
  });
4112
4033
  }
4113
-
4114
4034
  if (nodeName === 'FONT' && !hasInlineColor) {
4115
4035
  // 如果是font标签且没有内联文本颜色样式
4116
4036
  this._try(function () {
4117
4037
  var colorStr = el.getAttribute('color'); // 获取color的色值
4118
-
4119
4038
  if (colorStr) {
4120
4039
  // 有色值,则当做内联样式来处理
4121
4040
  var color = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(colorStr);
4122
-
4123
4041
  if (color) {
4124
4042
  cssKVList.push(['color', color.toString()]);
4125
4043
  hasInlineColor = true;
4126
4044
  }
4127
4045
  }
4128
4046
  });
4129
- } // 处理-webkit-text相关样式
4130
-
4047
+ }
4131
4048
 
4049
+ // 处理-webkit-text相关样式
4132
4050
  var webkitFillColor = '';
4133
4051
  var webkitStrokeColor = '';
4134
4052
  var webkitTextLen = 0;
4135
4053
  cssKVList.some(function (_ref7, idx) {
4136
4054
  var _ref8 = _slicedToArray(_ref7, 2),
4137
- key = _ref8[0],
4138
- value = _ref8[1];
4139
-
4055
+ key = _ref8[0],
4056
+ value = _ref8[1];
4140
4057
  return _this._try(function () {
4141
4058
  if (key.indexOf('-webkit-text') !== 0) {
4142
4059
  // 遍历到非-webkit-text样式
4143
4060
  webkitTextLen = idx; // 记录-webkit-text相关样式的长度
4144
-
4145
4061
  return true; // 结束遍历
4146
4062
  }
4147
4063
 
@@ -4149,7 +4065,6 @@ var SDK = /*#__PURE__*/function () {
4149
4065
  case '-webkit-text-fill-color':
4150
4066
  webkitFillColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(value);
4151
4067
  break;
4152
-
4153
4068
  case '-webkit-text-stroke':
4154
4069
  {
4155
4070
  // 有-webkit-text-stroke时就不会有-webkit-text-stroke-color
@@ -4157,13 +4072,11 @@ var SDK = /*#__PURE__*/function () {
4157
4072
  newValue.length === 2 && (webkitStrokeColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(newValue[1]));
4158
4073
  break;
4159
4074
  }
4160
-
4161
4075
  case '-webkit-text-stroke-color':
4162
4076
  // 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
4163
4077
  webkitStrokeColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseWebkitFillColorAndStrokeColor"])(value);
4164
4078
  break;
4165
4079
  }
4166
-
4167
4080
  return false; // 继续遍历
4168
4081
  });
4169
4082
  });
@@ -4179,43 +4092,36 @@ var SDK = /*#__PURE__*/function () {
4179
4092
  hasInlineColor = true;
4180
4093
  }
4181
4094
  }
4182
-
4183
4095
  if (webkitTextLen) {
4184
4096
  cssKVList.splice(0, webkitTextLen); // 删掉-webkit-text相关样式
4185
-
4186
4097
  webkitStrokeColor && cssKVList.unshift(['-webkit-text-stroke-color', webkitStrokeColor]); // 如果有-webkit-text-stroke-color,则插入到最前面
4187
4098
  }
4188
4099
 
4189
4100
  var dmClassName = '';
4190
4101
  var dmBgClassName = '';
4191
-
4192
4102
  if (isUpdate && el.className && typeof el.className === 'string') {
4193
4103
  // 先提取dm className
4194
4104
  var matches = el.className.match(_constant__WEBPACK_IMPORTED_MODULE_2__["DM_CLASSNAME_REGEXP"]);
4195
-
4196
4105
  if (matches) {
4197
4106
  dmClassName = matches[0];
4198
- } // 再提取dm bg className
4199
-
4107
+ }
4200
4108
 
4109
+ // 再提取dm bg className
4201
4110
  matches = el.className.match(_global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].classNameReg);
4202
-
4203
4111
  if (matches) {
4204
4112
  dmBgClassName = matches[0];
4205
4113
  }
4206
4114
  }
4207
-
4208
4115
  var cssKV = ''; // css键值对
4209
-
4210
4116
  cssKVList.forEach(function (_ref9) {
4211
4117
  var _ref10 = _slicedToArray(_ref9, 2),
4212
- key = _ref10[0],
4213
- value = _ref10[1];
4214
-
4118
+ key = _ref10[0],
4119
+ value = _ref10[1];
4215
4120
  return _this._try(function () {
4216
4121
  var oldValue = value;
4217
- var cssChange = false; // 找出色值来处理
4122
+ var cssChange = false;
4218
4123
 
4124
+ // 找出色值来处理
4219
4125
  var isBgColor = _constant__WEBPACK_IMPORTED_MODULE_2__["CSS_PROP_SERIES"].BG_COLOR.indexOf(key) > -1;
4220
4126
  var isTextShadow = _constant__WEBPACK_IMPORTED_MODULE_2__["CSS_PROP_SERIES"].TEXT_SHADOW.indexOf(key) > -1;
4221
4127
  var textColorIdx = _constant__WEBPACK_IMPORTED_MODULE_2__["CSS_PROP_SERIES"].TEXT_COLOR.indexOf(key);
@@ -4223,24 +4129,23 @@ var SDK = /*#__PURE__*/function () {
4223
4129
  var isGradient = /gradient/.test(value);
4224
4130
  var gradientColors = [];
4225
4131
  var extStyle = '';
4226
- var gradientMixColor; // 将英文定义颜色转换为rgb格式
4132
+ var gradientMixColor;
4227
4133
 
4134
+ // 将英文定义颜色转换为rgb格式
4228
4135
  value = Object(_color__WEBPACK_IMPORTED_MODULE_1__["parseColorName"])(value, isGradient); // 渐变需要处理透明
4229
4136
 
4230
4137
  if (_constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP"].test(value)) {
4231
4138
  if (isGradient) {
4232
4139
  // 把原渐变色取出来
4233
4140
  var _matches = _constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"].exec(value);
4234
-
4235
4141
  while (_matches) {
4236
4142
  gradientColors.push(_matches[0]);
4237
4143
  _matches = _constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"].exec(value);
4238
- } // 计算出一个mix颜色
4239
-
4144
+ }
4240
4145
 
4146
+ // 计算出一个mix颜色
4241
4147
  gradientMixColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["mixColors"])(gradientColors);
4242
4148
  }
4243
-
4244
4149
  var replaceIndex = 0;
4245
4150
  value = value.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["COLOR_REGEXP_GLOBAL"], function (match) {
4246
4151
  // 渐变色统一改成mix纯色
@@ -4248,9 +4153,7 @@ var SDK = /*#__PURE__*/function () {
4248
4153
  match = gradientMixColor;
4249
4154
  cssChange = true;
4250
4155
  }
4251
-
4252
4156
  var matchColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(match);
4253
-
4254
4157
  if ((matchColor === null || matchColor === void 0 ? void 0 : matchColor.alpha()) >= _constant__WEBPACK_IMPORTED_MODULE_2__["IGNORE_ALPHA"]) {
4255
4158
  // 忽略透明度低的色值
4256
4159
  // 使用颜色处理算法
@@ -4261,10 +4164,10 @@ var SDK = /*#__PURE__*/function () {
4261
4164
  isBorderColor: isBorderColor,
4262
4165
  hasInlineColor: hasInlineColor
4263
4166
  }, isUpdate);
4264
-
4265
4167
  var retColor = !hasInlineBackgroundImage && ret.newColor;
4266
- extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
4168
+ extStyle += ret.extStyle;
4267
4169
 
4170
+ // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
4268
4171
  if (isBgColor || textColorIdx >= 5) {
4269
4172
  // 只处理color及之后的属性
4270
4173
  var retColorStr = retColor ? retColor.toString() : match;
@@ -4275,78 +4178,75 @@ var SDK = /*#__PURE__*/function () {
4275
4178
  } else {
4276
4179
  dom[_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"]] = retColorStr;
4277
4180
  dom[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] = match;
4278
- } // 如果设置背景颜色,取消背景图片的影响
4279
-
4181
+ }
4280
4182
 
4183
+ // 如果设置背景颜色,取消背景图片的影响
4281
4184
  var retColor = Object(_color__WEBPACK_IMPORTED_MODULE_1__["ColorParser"])(retColorStr);
4282
-
4283
4185
  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"]]) {
4284
4186
  delete dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]];
4285
4187
  }
4286
4188
  });
4287
4189
  }
4288
-
4289
4190
  retColor && (cssChange = true);
4290
4191
  replaceIndex++;
4291
4192
  return retColor || match;
4292
4193
  }
4293
-
4294
4194
  return match;
4295
4195
  }).replace(/\s?!\s?important/ig, '');
4296
4196
  }
4297
-
4298
4197
  extStyle && (cssKV += extStyle);
4299
-
4300
4198
  if (!(el instanceof SVGElement)) {
4301
4199
  // 先不处理SVG
4302
4200
  // 背景图片、边框图片
4303
4201
  var isBackgroundAttr = /^background/.test(key);
4304
4202
  var isBorderImageAttr = /^(-webkit-)?border-image/.test(key);
4305
-
4306
4203
  if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
4307
4204
  cssChange = true;
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;
4205
+ 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();
4206
+ // const imgBgColor = el[BGCOLORATTR] || config.defaultLightBgColor;
4207
+
4309
4208
  // 在背景图片下加一层原背景颜色:
4310
4209
  // background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering);
4311
4210
  // border-image不支持多层背景,需要添加background-color
4312
-
4313
4211
  value = value.replace(/^(.*?)url\(([^)]*)\)(.*)$/i, function (matches) {
4314
4212
  var newValue = matches;
4315
4213
  var tmpCssKvStr = '';
4316
-
4317
4214
  if (!el[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]]) {
4318
4215
  // 避免重复set
4319
4216
  Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
4320
4217
  dom[_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]] = true;
4321
4218
  });
4322
- } // background-image
4323
-
4219
+ }
4324
4220
 
4221
+ // background-image
4325
4222
  if (isBackgroundAttr) {
4326
4223
  tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, imgBgColor ? "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")") : newValue);
4327
-
4328
4224
  if (elBackgroundPositionAttr) {
4329
4225
  cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-position', elBackgroundPositionAttr);
4330
4226
  tmpCssKvStr += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-position', imgBgColor ? "".concat(elBackgroundPositionAttr, ",top left") : elBackgroundPositionAttr);
4331
4227
  }
4332
-
4333
4228
  if (elBackgroundSizeAttr) {
4334
4229
  cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-size', elBackgroundSizeAttr);
4335
4230
  tmpCssKvStr += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-size', imgBgColor ? "".concat(elBackgroundSizeAttr, ",100%") : elBackgroundSizeAttr);
4336
4231
  }
4337
-
4338
4232
  if (dmBgClassName) {
4339
4233
  // 如果是文字底图,则直接加样式
4340
4234
  bgCss += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(dmBgClassName, tmpCssKvStr);
4235
+ Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
4236
+ dom[_constant__WEBPACK_IMPORTED_MODULE_2__["COMPLEMENTARY_BGIMAGECOLORATTR"]] = imgBgColor || newValue;
4237
+ });
4341
4238
  } else {
4342
4239
  // 否则背景图入栈
4343
- _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, tmpCssKvStr);
4240
+ _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, tmpCssKvStr, function () {
4241
+ Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
4242
+ dom[_constant__WEBPACK_IMPORTED_MODULE_2__["COMPLEMENTARY_BGIMAGECOLORATTR"]] = imgBgColor || newValue;
4243
+ });
4244
+ });
4344
4245
  }
4345
4246
  } else {
4346
4247
  // border-image元素,如果当前元素没有背景颜色,补背景颜色
4347
4248
  if (imgBgColor && !hasInlineBackground) {
4348
4249
  tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-image', "linear-gradient(".concat(imgBgColor, ", ").concat(imgBgColor, ")"));
4349
-
4350
4250
  if (dmBgClassName) {
4351
4251
  // 如果是文字底图,则直接加样式
4352
4252
  bgCss += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(dmBgClassName, tmpCssKvStr);
@@ -4358,8 +4258,9 @@ var SDK = /*#__PURE__*/function () {
4358
4258
  }
4359
4259
 
4360
4260
  return newValue;
4361
- }); // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
4261
+ });
4362
4262
 
4263
+ // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
4363
4264
  if (!hasInlineColor) {
4364
4265
  var textColor = el[_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]] || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor;
4365
4266
  cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', textColor);
@@ -4369,15 +4270,12 @@ var SDK = /*#__PURE__*/function () {
4369
4270
  }
4370
4271
  }
4371
4272
  }
4372
-
4373
4273
  if (cssChange) {
4374
4274
  !isUpdate && _constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] = oldValue.replace(_constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"], '')); // 清除inline style的!important
4375
-
4376
4275
  if (isGradient) {
4377
4276
  if (dmBgClassName) {
4378
4277
  // 如果是文字底图,则直接加样式(其实理论上不会走到这里)
4379
4278
  bgCss += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(dmBgClassName, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value));
4380
-
4381
4279
  if (/^background/.test(key) && !/url\([^)]*\)/i.test(value)) {
4382
4280
  // 是无背景图的渐变,需要重新计算背景色
4383
4281
  css += _this._updateBgWithGradient(gradientMixColor, el, dmBgClassName, cssKVList, hasInlineColor, isUpdate);
@@ -4398,17 +4296,14 @@ var SDK = /*#__PURE__*/function () {
4398
4296
  }
4399
4297
  });
4400
4298
  });
4401
-
4402
4299
  if (cssKV) {
4403
4300
  // 有处理过或者是背景图片就加class以及css
4404
4301
  if (!dmClassName) {
4405
4302
  dmClassName = "".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["CLASS_PREFIX"]).concat(this._idx++);
4406
4303
  el.classList.add(dmClassName);
4407
4304
  }
4408
-
4409
4305
  css += cssKV ? _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(dmClassName, cssKV) : '';
4410
4306
  }
4411
-
4412
4307
  css += bgCss; // 追加文字底图样式,要在添加cssKV之后添加,避免被覆盖
4413
4308
 
4414
4309
  if (!isUpdate && Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["hasTextNode"])(el)) {
@@ -4424,11 +4319,11 @@ var SDK = /*#__PURE__*/function () {
4424
4319
  }
4425
4320
  }
4426
4321
  }
4427
-
4428
4322
  _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit("afterConvertNode".concat(isUpdate ? 'ByUpdateStyle' : ''), el);
4429
4323
  return css;
4430
- } // 获取两个颜色的对比度
4324
+ }
4431
4325
 
4326
+ // 获取两个颜色的对比度
4432
4327
  }, {
4433
4328
  key: "getContrast",
4434
4329
  value: function getContrast(colorStr1, colorStr2) {
@@ -4437,11 +4332,9 @@ var SDK = /*#__PURE__*/function () {
4437
4332
  return color1 && color2 ? color1.contrast(color2) : 0;
4438
4333
  }
4439
4334
  }]);
4440
-
4441
4335
  return SDK;
4442
4336
  }();
4443
4337
 
4444
-
4445
4338
  ;
4446
4339
 
4447
4340
  /***/ }),
@@ -4458,15 +4351,10 @@ __webpack_require__.r(__webpack_exports__);
4458
4351
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TextNodeQueue; });
4459
4352
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
4460
4353
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4461
-
4462
4354
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4463
-
4464
4355
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4465
-
4466
4356
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4467
-
4468
4357
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4469
-
4470
4358
  /**
4471
4359
  * @name 文本节点队列
4472
4360
  *
@@ -4488,54 +4376,51 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4488
4376
  * @return void
4489
4377
  *
4490
4378
  */
4491
- // Darkmode配置
4492
4379
 
4380
+ // Darkmode配置
4493
4381
 
4494
4382
  var TextNodeQueue = /*#__PURE__*/function () {
4495
4383
  // 文本节点队列,{ el, className, updated }
4496
4384
  // 索引值
4385
+
4497
4386
  function TextNodeQueue(prefix) {
4498
4387
  _classCallCheck(this, TextNodeQueue);
4499
-
4500
4388
  _defineProperty(this, "_queue", []);
4501
-
4502
4389
  _defineProperty(this, "_idx", 0);
4503
-
4504
4390
  this._prefix = prefix;
4505
- } // 文本节点入队
4506
-
4391
+ }
4507
4392
 
4393
+ // 文本节点入队
4508
4394
  _createClass(TextNodeQueue, [{
4509
4395
  key: "push",
4510
4396
  value: function push(el) {
4511
4397
  var className = "".concat(this._prefix).concat(this._idx++);
4512
4398
  el.classList.add(className);
4513
-
4514
4399
  this._queue.push({
4515
4400
  el: el,
4516
4401
  className: className,
4517
4402
  updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge
4518
4403
  });
4519
- } // 遍历,遍历过的文本节点出队
4404
+ }
4520
4405
 
4406
+ // 遍历,遍历过的文本节点出队
4521
4407
  }, {
4522
4408
  key: "forEach",
4523
4409
  value: function forEach(callback) {
4524
4410
  var idxStack = [];
4525
-
4526
4411
  this._queue.forEach(function (item, idx) {
4527
4412
  if (item.updated) {
4528
4413
  idxStack.unshift(idx);
4529
4414
  _typeof(callback) && callback(item.el);
4530
4415
  }
4531
4416
  });
4532
-
4533
4417
  while (idxStack.length) {
4534
4418
  // 处理完之后删除部分节点
4535
4419
  this._queue.splice(idxStack.shift(), 1);
4536
4420
  }
4537
- } // 更新队列的节点对象,主要解决前后节点不一致的问题
4421
+ }
4538
4422
 
4423
+ // 更新队列的节点对象,主要解决前后节点不一致的问题
4539
4424
  }, {
4540
4425
  key: "update",
4541
4426
  value: function update(els) {
@@ -4547,18 +4432,15 @@ var TextNodeQueue = /*#__PURE__*/function () {
4547
4432
  item.updated = true;
4548
4433
  return true;
4549
4434
  }
4550
-
4551
4435
  return false;
4552
4436
  });
4553
4437
  }
4554
4438
  });
4555
4439
  }
4556
4440
  }]);
4557
-
4558
4441
  return TextNodeQueue;
4559
4442
  }();
4560
4443
 
4561
-
4562
4444
  ;
4563
4445
 
4564
4446
  /***/ })