mp-darkmode 1.0.9 → 1.1.0-beta.2

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
@@ -1510,12 +1510,13 @@ module.exports = {
1510
1510
  /* MIT license */
1511
1511
  var colorNames = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js");
1512
1512
  var swizzle = __webpack_require__(/*! simple-swizzle */ "./node_modules/simple-swizzle/index.js");
1513
+ var hasOwnProperty = Object.hasOwnProperty;
1513
1514
 
1514
1515
  var reverseNames = {};
1515
1516
 
1516
1517
  // create a list of reverse color names
1517
1518
  for (var name in colorNames) {
1518
- if (colorNames.hasOwnProperty(name)) {
1519
+ if (hasOwnProperty.call(colorNames, name)) {
1519
1520
  reverseNames[colorNames[name]] = name;
1520
1521
  }
1521
1522
  }
@@ -1558,9 +1559,9 @@ cs.get.rgb = function (string) {
1558
1559
 
1559
1560
  var abbr = /^#([a-f0-9]{3,4})$/i;
1560
1561
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
1561
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1562
- var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1563
- var keyword = /(\D+)/;
1562
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1563
+ var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1564
+ var keyword = /^(\w+)$/;
1564
1565
 
1565
1566
  var rgb = [0, 0, 0, 1];
1566
1567
  var match;
@@ -1578,7 +1579,7 @@ cs.get.rgb = function (string) {
1578
1579
  }
1579
1580
 
1580
1581
  if (hexAlpha) {
1581
- rgb[3] = Math.round((parseInt(hexAlpha, 16) / 255) * 100) / 100;
1582
+ rgb[3] = parseInt(hexAlpha, 16) / 255;
1582
1583
  }
1583
1584
  } else if (match = string.match(abbr)) {
1584
1585
  match = match[1];
@@ -1589,7 +1590,7 @@ cs.get.rgb = function (string) {
1589
1590
  }
1590
1591
 
1591
1592
  if (hexAlpha) {
1592
- rgb[3] = Math.round((parseInt(hexAlpha + hexAlpha, 16) / 255) * 100) / 100;
1593
+ rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
1593
1594
  }
1594
1595
  } else if (match = string.match(rgba)) {
1595
1596
  for (i = 0; i < 3; i++) {
@@ -1597,7 +1598,11 @@ cs.get.rgb = function (string) {
1597
1598
  }
1598
1599
 
1599
1600
  if (match[4]) {
1600
- rgb[3] = parseFloat(match[4]);
1601
+ if (match[5]) {
1602
+ rgb[3] = parseFloat(match[4]) * 0.01;
1603
+ } else {
1604
+ rgb[3] = parseFloat(match[4]);
1605
+ }
1601
1606
  }
1602
1607
  } else if (match = string.match(per)) {
1603
1608
  for (i = 0; i < 3; i++) {
@@ -1605,19 +1610,22 @@ cs.get.rgb = function (string) {
1605
1610
  }
1606
1611
 
1607
1612
  if (match[4]) {
1608
- rgb[3] = parseFloat(match[4]);
1613
+ if (match[5]) {
1614
+ rgb[3] = parseFloat(match[4]) * 0.01;
1615
+ } else {
1616
+ rgb[3] = parseFloat(match[4]);
1617
+ }
1609
1618
  }
1610
1619
  } else if (match = string.match(keyword)) {
1611
1620
  if (match[1] === 'transparent') {
1612
1621
  return [0, 0, 0, 0];
1613
1622
  }
1614
1623
 
1615
- rgb = colorNames[match[1]];
1616
-
1617
- if (!rgb) {
1624
+ if (!hasOwnProperty.call(colorNames, match[1])) {
1618
1625
  return null;
1619
1626
  }
1620
1627
 
1628
+ rgb = colorNames[match[1]];
1621
1629
  rgb[3] = 1;
1622
1630
 
1623
1631
  return rgb;
@@ -1638,12 +1646,12 @@ cs.get.hsl = function (string) {
1638
1646
  return null;
1639
1647
  }
1640
1648
 
1641
- var hsl = /^hsla?\(\s*([+-]?(?:\d*\.)?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1649
+ var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
1642
1650
  var match = string.match(hsl);
1643
1651
 
1644
1652
  if (match) {
1645
1653
  var alpha = parseFloat(match[4]);
1646
- var h = (parseFloat(match[1]) + 360) % 360;
1654
+ var h = ((parseFloat(match[1]) % 360) + 360) % 360;
1647
1655
  var s = clamp(parseFloat(match[2]), 0, 100);
1648
1656
  var l = clamp(parseFloat(match[3]), 0, 100);
1649
1657
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -1659,7 +1667,7 @@ cs.get.hwb = function (string) {
1659
1667
  return null;
1660
1668
  }
1661
1669
 
1662
- var hwb = /^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1670
+ var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
1663
1671
  var match = string.match(hwb);
1664
1672
 
1665
1673
  if (match) {
@@ -1738,7 +1746,7 @@ function clamp(num, min, max) {
1738
1746
  }
1739
1747
 
1740
1748
  function hexDouble(num) {
1741
- var str = num.toString(16).toUpperCase();
1749
+ var str = Math.round(num).toString(16).toUpperCase();
1742
1750
  return (str.length < 2) ? '0' + str : str;
1743
1751
  }
1744
1752
 
@@ -2304,7 +2312,7 @@ swizzle.wrap = function (fn) {
2304
2312
  /*!*************************!*\
2305
2313
  !*** ./src/darkmode.js ***!
2306
2314
  \*************************/
2307
- /*! exports provided: run, init, convertBg */
2315
+ /*! exports provided: run, init, convertBg, extend */
2308
2316
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
2309
2317
 
2310
2318
  "use strict";
@@ -2312,12 +2320,10 @@ __webpack_require__.r(__webpack_exports__);
2312
2320
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "run", function() { return run; });
2313
2321
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "init", function() { return init; });
2314
2322
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "convertBg", function() { return convertBg; });
2323
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "extend", function() { return extend; });
2315
2324
  /* harmony import */ var _modules_constant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/constant */ "./src/modules/constant.js");
2316
- /* harmony import */ var _modules_textNodeQueue__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/textNodeQueue */ "./src/modules/textNodeQueue.js");
2317
- /* harmony import */ var _modules_bgNodeStack__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/bgNodeStack */ "./src/modules/bgNodeStack.js");
2318
- /* harmony import */ var _modules_cssUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./modules/cssUtils */ "./src/modules/cssUtils.js");
2319
- /* harmony import */ var _modules_domUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./modules/domUtils */ "./src/modules/domUtils.js");
2320
- /* harmony import */ var _modules_sdk__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./modules/sdk */ "./src/modules/sdk.js");
2325
+ /* harmony import */ var _modules_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/config */ "./src/modules/config.js");
2326
+ /* harmony import */ var _modules_global__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/global */ "./src/modules/global.js");
2321
2327
  /**
2322
2328
  * @name Darkmode主入口
2323
2329
  *
@@ -2329,103 +2335,30 @@ __webpack_require__.r(__webpack_exports__);
2329
2335
  * @param {Function} opt.begin 开始处理时触发的回调
2330
2336
  * @param {Function} opt.showFirstPage 首屏处理完成时触发的回调
2331
2337
  * @param {Function} opt.error 发生error时触发的回调
2332
- * @param {String} opt.mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
2338
+ * @param {string} opt.mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
2333
2339
  * @param {Object} opt.whitelist 节点白名单
2334
2340
  * @param {Array} opt.whitelist.tagName 标签名列表
2335
- * @param {Boolean} opt.needJudgeFirstPage 是否需要判断首屏
2336
- * @param {Boolean} opt.delayBgJudge 是否延迟背景判断
2341
+ * @param {boolean} opt.needJudgeFirstPage 是否需要判断首屏
2342
+ * @param {boolean} opt.delayBgJudge 是否延迟背景判断
2337
2343
  * @param {DOM Object} opt.container 延迟运行js时使用的容器
2338
- * @param {String} opt.cssSelectorsPrefix css选择器前缀
2339
- * @param {String} opt.defaultLightTextColor 非Dark Mode下字体颜色
2340
- * @param {String} opt.defaultLightBgColor 非Dark Mode下背景颜色
2341
- * @param {String} opt.defaultDarkTextColor Dark Mode下字体颜色
2342
- * @param {String} opt.defaultDarkBgColor Dark Mode下背景颜色
2344
+ * @param {string} opt.cssSelectorsPrefix css选择器前缀
2345
+ * @param {string} opt.defaultLightTextColor 非Dark Mode下字体颜色
2346
+ * @param {string} opt.defaultLightBgColor 非Dark Mode下背景颜色
2347
+ * @param {string} opt.defaultDarkTextColor Dark Mode下字体颜色
2348
+ * @param {string} opt.defaultDarkBgColor Dark Mode下背景颜色
2343
2349
  *
2344
2350
  * @function convertBg 处理背景
2345
2351
  * @param {Dom Object Array} nodes 要处理的节点列表
2346
2352
  *
2353
+ * @function extend 挂载插件
2354
+ * @param {Array} pluginList 插件列表
2355
+ *
2347
2356
  */
2348
2357
 
2349
2358
  var classReg = new RegExp("".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "[^ ]+"), 'g'); // Darkmode配置
2350
2359
 
2351
- var config = {
2352
- hasInit: false,
2353
- // 是否初始化过配置
2354
- // hooks
2355
- begin: null,
2356
- // 开始处理时触发的回调
2357
- showFirstPage: null,
2358
- // 首屏处理完成时触发的回调
2359
- error: null,
2360
- // 发生error时触发的回调
2361
- mode: '',
2362
- // 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
2363
- whitelist: {
2364
- // 节点白名单
2365
- tagName: ['MPCPS', 'IFRAME'] // 标签名列表
2366
2360
 
2367
- },
2368
- needJudgeFirstPage: true,
2369
- // 需要判断首屏
2370
- delayBgJudge: false,
2371
- // 是否延迟背景判断
2372
- container: null,
2373
- // 延迟运行js时使用的容器
2374
- cssSelectorsPrefix: '',
2375
- // css选择器前缀
2376
- defaultLightTextColor: _modules_constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_TEXTCOLOR"],
2377
- // 非Dark Mode下字体颜色
2378
- defaultLightBgColor: _modules_constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_BGCOLOR"],
2379
- // 非Dark Mode下背景颜色
2380
- defaultDarkTextColor: _modules_constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_TEXTCOLOR"],
2381
- // Dark Mode下字体颜色
2382
- defaultDarkBgColor: _modules_constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_BGCOLOR"] // Dark Mode下背景颜色
2383
-
2384
- }; // 设置配置
2385
-
2386
- var setConfig = function setConfig(type, opt, key) {
2387
- var value = opt[key];
2388
-
2389
- switch (type) {
2390
- case 'boolean':
2391
- typeof value === 'boolean' && (config[key] = value);
2392
- break;
2393
-
2394
- case 'string':
2395
- typeof value === 'string' && value !== '' && (config[key] = value);
2396
- break;
2397
-
2398
- case 'function':
2399
- typeof value === 'function' && (config[key] = value);
2400
- break;
2401
-
2402
- case 'dom':
2403
- value instanceof HTMLElement && (config[key] = value);
2404
- break;
2405
-
2406
- default:
2407
- }
2408
- }; // 文本节点队列
2409
-
2410
-
2411
-
2412
- var tnQueue = new _modules_textNodeQueue__WEBPACK_IMPORTED_MODULE_1__["default"](config, "".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "text__")); // 需要判断位置的背景节点堆栈
2413
-
2414
-
2415
- var bgStack = new _modules_bgNodeStack__WEBPACK_IMPORTED_MODULE_2__["default"](config, "".concat(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "bg__")); // 样式相关操作工具对象
2416
-
2417
-
2418
- var cssUtils = new _modules_cssUtils__WEBPACK_IMPORTED_MODULE_3__["default"](config); // 节点相关操作工具对象
2419
-
2420
-
2421
- var domUtils = new _modules_domUtils__WEBPACK_IMPORTED_MODULE_4__["DomUtils"](config);
2422
-
2423
- var sdk = new _modules_sdk__WEBPACK_IMPORTED_MODULE_5__["default"]({
2424
- config: config,
2425
- tnQueue: tnQueue,
2426
- bgStack: bgStack,
2427
- cssUtils: cssUtils
2428
- }); // Dark Mode切换
2361
+ // Dark Mode切换
2429
2362
 
2430
2363
  var mql = null;
2431
2364
 
@@ -2433,24 +2366,25 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2433
2366
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
2434
2367
  type: 'dom'
2435
2368
  };
2436
- opt.force && (cssUtils.isFinish = false); // 如果是强制运行Dark Mode处理逻辑,则重置为未运行
2369
+ opt.force && (_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].isFinish = false); // 如果是强制运行Dark Mode处理逻辑,则重置为未运行
2437
2370
 
2438
- if (cssUtils.isFinish) return; // 已运行过Dark Mode处理逻辑则不再运行
2371
+ if (_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].isFinish) return; // 已运行过Dark Mode处理逻辑则不再运行
2439
2372
 
2440
2373
  try {
2441
- if (config.mode ? config.mode === 'dark' : mqlObj.matches) {
2442
- // Dark Mode
2443
- if (opt.type === 'dom') {
2444
- // 处理节点
2445
- typeof config.begin === 'function' && config.begin(domUtils.hasDelay());
2446
- Array.prototype.forEach.call(domUtils.get(), function (node) {
2447
- if (node.className && typeof node.className === 'string') {
2448
- node.className = node.className.replace(classReg, ''); // 过滤掉原有的Dark Mode class,避免外部复制文章时把文章内的Dark Mode class也复制过去导致新文章在Dark Mode下样式错乱
2449
- }
2374
+ _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;
2375
+
2376
+ if (opt.type === 'dom') {
2377
+ // 处理节点
2378
+ _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());
2379
+ Array.prototype.forEach.call(_modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].get(), function (node) {
2380
+ if (_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode && node.className && typeof node.className === 'string') {
2381
+ node.className = node.className.replace(classReg, ''); // 过滤掉原有的Dark Mode class,避免外部复制文章时把文章内的Dark Mode class也复制过去导致新文章在Dark Mode下样式错乱
2382
+ }
2450
2383
 
2451
- if (!config.needJudgeFirstPage) {
2384
+ if (_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode || _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].length) {
2385
+ if (!_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage) {
2452
2386
  // 不需要判断首屏
2453
- cssUtils.addCss(sdk.convert(node), false); // 写入非首屏样式
2387
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node), false); // 写入非首屏样式
2454
2388
  } else {
2455
2389
  // 判断首屏
2456
2390
  var rect = node.getBoundingClientRect();
@@ -2459,63 +2393,69 @@ var switchToDarkmode = function switchToDarkmode(mqlObj) {
2459
2393
 
2460
2394
  if (top <= 0 && bottom <= 0) {
2461
2395
  // 首屏前面
2462
- cssUtils.addCss(sdk.convert(node), false); // 写入非首屏样式
2396
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node), false); // 写入非首屏样式
2463
2397
  } else if (top > 0 && top < _modules_constant__WEBPACK_IMPORTED_MODULE_0__["PAGE_HEIGHT"] || bottom > 0 && bottom < _modules_constant__WEBPACK_IMPORTED_MODULE_0__["PAGE_HEIGHT"]) {
2464
2398
  // 首屏
2465
- domUtils.addFirstPageNode(node); // 记录首屏节点
2399
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].addFirstPageNode(node); // 记录首屏节点
2466
2400
 
2467
- cssUtils.addCss(sdk.convert(node), true); // 写入首屏样式
2401
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node), true); // 写入首屏样式
2468
2402
  } else {
2469
2403
  // 首屏后面,理论上,这里最多只会进来一次
2470
- config.needJudgeFirstPage = false; // 至此,不需要再判断首屏了
2404
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage = false; // 至此,不需要再判断首屏了
2471
2405
  // 显示首屏
2472
2406
 
2473
- cssUtils.writeStyle(true); // 写入首屏样式表
2407
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle(true); // 写入首屏样式表
2474
2408
 
2475
- domUtils.showFirstPageNodes(); // 显示首屏节点
2409
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].showFirstPageNodes(); // 显示首屏节点
2476
2410
 
2477
- typeof config.showFirstPage === 'function' && config.showFirstPage(); // 执行首屏回调
2411
+ typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage(); // 执行首屏回调
2478
2412
 
2479
- cssUtils.addCss(sdk.convert(node), false); // 写入非首屏样式
2413
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].convert(node), false); // 写入非首屏样式
2480
2414
  }
2481
2415
  }
2416
+ }
2417
+ });
2418
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].loopTimes++;
2419
+ } else if (opt.type === 'bg') {
2420
+ // 处理背景
2421
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode && _modules_global__WEBPACK_IMPORTED_MODULE_2__["tnQueue"].forEach(function (text) {
2422
+ return _modules_global__WEBPACK_IMPORTED_MODULE_2__["bgStack"].contains(text, function (bg) {
2423
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].addCss(_modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].genCss(bg.className, bg.cssKV), false); // 写入非首屏样式
2482
2424
  });
2483
- } else if (opt.type === 'bg') {
2484
- // 处理背景
2485
- tnQueue.forEach(function (text) {
2486
- return bgStack.contains(text, function (bg) {
2487
- cssUtils.addCss(cssUtils.genCss(bg.className, bg.cssKV), false); // 写入非首屏样式
2488
- });
2489
- });
2490
- }
2425
+ });
2426
+ }
2491
2427
 
2492
- if (config.needJudgeFirstPage || !config.needJudgeFirstPage && !domUtils.showFirstPage) {
2493
- // config.needJudgeFirstPage === ture,表示需要判断首屏但是正文长度没超过一屏
2494
- // config.needJudgeFirstPage === false && domUtils.showFirstPage === false,表示不需要判断首屏且没有做首屏优化
2495
- typeof config.showFirstPage === 'function' && config.showFirstPage();
2496
- }
2428
+ if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage || !_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage && !_modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].showFirstPage) {
2429
+ // config.needJudgeFirstPage === ture,表示需要判断首屏但是正文长度没超过一屏
2430
+ // config.needJudgeFirstPage === false && domUtils.showFirstPage === false,表示不需要判断首屏且没有做首屏优化
2431
+ typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].showFirstPage(); // 执行首屏回调
2432
+ }
2433
+
2434
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["cssUtils"].writeStyle(); // 写入非首屏样式表
2435
+
2436
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].emptyFirstPageNodes(); // 清空记录的首屏节点
2497
2437
 
2498
- cssUtils.writeStyle(); // 写入非首屏样式表
2499
- } else {
2438
+ if (!_modules_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode) {
2439
+ // 非Dark Mode
2500
2440
  // 首次加载页面时为非Dark Mode,标记为不需要判断首屏
2501
- config.needJudgeFirstPage = false; // 首次加载页面时为非Dark Mode,标记为不延迟判断背景
2441
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].needJudgeFirstPage = false; // 首次加载页面时为非Dark Mode,标记为不延迟判断背景
2502
2442
 
2503
- config.delayBgJudge = false;
2443
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].delayBgJudge = false;
2504
2444
 
2505
- if (config.container === null && opt.type === 'dom' && domUtils.len()) {
2506
- domUtils.delay(); // 将节点转移到延迟处理队列里
2445
+ if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].container === null && opt.type === 'dom' && _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].length) {
2446
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].delay(); // 将节点转移到延迟处理队列里
2507
2447
  }
2508
2448
  }
2509
2449
  } catch (e) {
2510
2450
  console.log('An error occurred when running the dark mode conversion algorithm\n', e);
2511
- typeof config.error === 'function' && config.error(e);
2451
+ typeof _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error === 'function' && _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].error(e);
2512
2452
  }
2513
2453
  };
2514
2454
 
2515
2455
  function run(nodes, opt) {
2516
2456
  init(opt); // 初始化配置
2517
2457
 
2518
- domUtils.set(nodes);
2458
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].set(nodes);
2519
2459
  switchToDarkmode(mql, {
2520
2460
  force: true,
2521
2461
  type: 'dom'
@@ -2524,34 +2464,34 @@ function run(nodes, opt) {
2524
2464
  ;
2525
2465
  function init() {
2526
2466
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2527
- if (config.hasInit) return; // 只可设置一次配置
2467
+ if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].hasInit) return; // 只可设置一次配置
2528
2468
 
2529
- config.hasInit = true; // 记录为配置已设置
2469
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].hasInit = true; // 记录为配置已设置
2530
2470
 
2531
- var tagName = config.whitelist.tagName;
2471
+ var tagName = _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].whitelist.tagName;
2532
2472
  opt.whitelist && opt.whitelist.tagName instanceof Array && opt.whitelist.tagName.forEach(function (item) {
2533
2473
  item = item.toUpperCase();
2534
2474
  tagName.indexOf(item) === -1 && tagName.push(item);
2535
2475
  });
2536
2476
 
2537
2477
  if (['dark', 'light'].indexOf(opt.mode) > -1) {
2538
- setConfig('string', opt, 'mode');
2478
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'mode');
2539
2479
  document.getElementsByTagName('html')[0].classList.add(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["HTML_CLASS"]);
2540
2480
  }
2541
2481
 
2542
- setConfig('function', opt, 'begin');
2543
- setConfig('function', opt, 'showFirstPage');
2544
- setConfig('function', opt, 'error');
2545
- setConfig('boolean', opt, 'needJudgeFirstPage');
2546
- setConfig('boolean', opt, 'delayBgJudge');
2547
- setConfig('dom', opt, 'container');
2548
- setConfig('string', opt, 'cssSelectorsPrefix');
2549
- setConfig('string', opt, 'defaultLightTextColor');
2550
- setConfig('string', opt, 'defaultLightBgColor');
2551
- setConfig('string', opt, 'defaultDarkTextColor');
2552
- setConfig('string', opt, 'defaultDarkBgColor');
2553
-
2554
- if (!config.mode && mql === null) {
2482
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'begin');
2483
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'showFirstPage');
2484
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('function', opt, 'error');
2485
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('boolean', opt, 'needJudgeFirstPage');
2486
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('boolean', opt, 'delayBgJudge');
2487
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('dom', opt, 'container');
2488
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'cssSelectorsPrefix');
2489
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultLightTextColor');
2490
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultLightBgColor');
2491
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultDarkTextColor');
2492
+ _modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].set('string', opt, 'defaultDarkBgColor');
2493
+
2494
+ if (!_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].mode && mql === null && window.matchMedia) {
2555
2495
  // 匹配媒体查询
2556
2496
  mql = window.matchMedia(_modules_constant__WEBPACK_IMPORTED_MODULE_0__["MEDIA_QUERY"]);
2557
2497
  mql.addListener(switchToDarkmode); // 监听
@@ -2559,12 +2499,12 @@ function init() {
2559
2499
  }
2560
2500
  ;
2561
2501
  function convertBg(nodes) {
2562
- domUtils.set(nodes);
2502
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["domUtils"].set(nodes);
2563
2503
 
2564
- if (config.container !== null) {
2565
- bgStack.update(nodes); // 更新背景堆栈
2504
+ if (_modules_config__WEBPACK_IMPORTED_MODULE_1__["default"].container !== null) {
2505
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["bgStack"].update(nodes); // 更新背景堆栈
2566
2506
 
2567
- tnQueue.update(nodes); // 更新文字队列
2507
+ _modules_global__WEBPACK_IMPORTED_MODULE_2__["tnQueue"].update(nodes); // 更新文字队列
2568
2508
  }
2569
2509
 
2570
2510
  switchToDarkmode(mql, {
@@ -2573,6 +2513,12 @@ function convertBg(nodes) {
2573
2513
  });
2574
2514
  }
2575
2515
  ;
2516
+ function extend(pluginList) {
2517
+ pluginList.forEach(function (plugin) {
2518
+ return _modules_global__WEBPACK_IMPORTED_MODULE_2__["plugins"].extend(plugin);
2519
+ });
2520
+ }
2521
+ ;
2576
2522
 
2577
2523
  /***/ }),
2578
2524
 
@@ -2586,11 +2532,12 @@ function convertBg(nodes) {
2586
2532
  "use strict";
2587
2533
  __webpack_require__.r(__webpack_exports__);
2588
2534
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return BgNodeStack; });
2535
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
2589
2536
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2590
2537
 
2591
2538
  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); } }
2592
2539
 
2593
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2540
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2594
2541
 
2595
2542
  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; }
2596
2543
 
@@ -2600,7 +2547,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2600
2547
  * @class BgNodeStack
2601
2548
  *
2602
2549
  * @constructor
2603
- * @param {Object} config Darkmode配置
2604
2550
  * @param {string} prefix 类名前缀
2605
2551
  *
2606
2552
  * @method push 背景节点入栈
@@ -2609,23 +2555,25 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2609
2555
  *
2610
2556
  * @method contains 判断节点是否在背景节点的区域
2611
2557
  * @param {Dom Object} el 要判断的节点对象(非背景节点)
2612
- * @param {function} callback 如果在背景节点区域内,则执行该回调函数
2558
+ * @param {Function} callback 如果在背景节点区域内,则执行该回调函数
2613
2559
  *
2614
2560
  * @method update 更新堆栈的节点对象,主要解决前后节点不一致的问题
2615
2561
  * @param {Dom Object Array} nodes 要更新的节点对象列表
2616
2562
  *
2617
2563
  */
2564
+ // Darkmode配置
2565
+
2566
+
2618
2567
  var BgNodeStack = /*#__PURE__*/function () {
2619
2568
  // 需要判断位置的背景堆栈,{ el, className, cssKV, updated, rect }
2620
2569
  // 索引值
2621
- function BgNodeStack(config, prefix) {
2570
+ function BgNodeStack(prefix) {
2622
2571
  _classCallCheck(this, BgNodeStack);
2623
2572
 
2624
2573
  _defineProperty(this, "_stack", []);
2625
2574
 
2626
2575
  _defineProperty(this, "_idx", 0);
2627
2576
 
2628
- this._config = config;
2629
2577
  this._prefix = prefix;
2630
2578
  }
2631
2579
 
@@ -2639,7 +2587,7 @@ var BgNodeStack = /*#__PURE__*/function () {
2639
2587
  el: el,
2640
2588
  className: className,
2641
2589
  cssKV: cssKV,
2642
- updated: !this._config.delayBgJudge
2590
+ updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge
2643
2591
  });
2644
2592
  }
2645
2593
  }, {
@@ -2693,6 +2641,89 @@ var BgNodeStack = /*#__PURE__*/function () {
2693
2641
 
2694
2642
  /***/ }),
2695
2643
 
2644
+ /***/ "./src/modules/config.js":
2645
+ /*!*******************************!*\
2646
+ !*** ./src/modules/config.js ***!
2647
+ \*******************************/
2648
+ /*! exports provided: default */
2649
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
2650
+
2651
+ "use strict";
2652
+ __webpack_require__.r(__webpack_exports__);
2653
+ /* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
2654
+ /**
2655
+ * @name Darkmode配置
2656
+ *
2657
+ * @attr {boolean} hasInit 是否初始化过配置
2658
+ * @attr {Function} begin 开始处理时触发的回调
2659
+ * @attr {Function} showFirstPage 首屏处理完成时触发的回调
2660
+ * @attr {Function} error 发生error时触发的回调
2661
+ * @attr {string} mode 强制指定的颜色模式(dark|light), 指定了就不监听系统颜色
2662
+ * @attr {Object} whitelist 节点白名单
2663
+ * @attr {string Array} whitelist.tagName 标签名列表
2664
+ * @attr {boolean} needJudgeFirstPage 是否需要判断首屏
2665
+ * @attr {boolean} delayBgJudge 是否延迟背景判断
2666
+ * @attr {DOM Object} container 延迟运行js时使用的容器
2667
+ * @attr {string} cssSelectorsPrefix css选择器前缀
2668
+ * @attr {string} defaultLightTextColor 非Dark Mode下字体颜色
2669
+ * @attr {string} defaultLightBgColor 非Dark Mode下背景颜色
2670
+ * @attr {string} defaultDarkTextColor Dark Mode下字体颜色
2671
+ * @attr {string} defaultDarkBgColor Dark Mode下背景颜色
2672
+ *
2673
+ * @method set 设置配置
2674
+ * @param {string} type 要处理的节点
2675
+ * @param {Object} opt 传入的配置对象
2676
+ * @param {string} key 配置名
2677
+ *
2678
+ */
2679
+
2680
+ var config = {
2681
+ hasInit: false,
2682
+ // hooks
2683
+ begin: null,
2684
+ showFirstPage: null,
2685
+ error: null,
2686
+ mode: '',
2687
+ whitelist: {
2688
+ tagName: ['MPCPS', 'IFRAME']
2689
+ },
2690
+ needJudgeFirstPage: true,
2691
+ delayBgJudge: false,
2692
+ container: null,
2693
+ cssSelectorsPrefix: '',
2694
+ defaultLightTextColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_TEXTCOLOR"],
2695
+ defaultLightBgColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_LIGHT_BGCOLOR"],
2696
+ defaultDarkTextColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_TEXTCOLOR"],
2697
+ defaultDarkBgColor: _constant__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_DARK_BGCOLOR"],
2698
+ // 设置配置
2699
+ set: function set(type, opt, key) {
2700
+ var value = opt[key];
2701
+
2702
+ switch (type) {
2703
+ case 'boolean':
2704
+ typeof value === 'boolean' && (this[key] = value);
2705
+ break;
2706
+
2707
+ case 'string':
2708
+ typeof value === 'string' && value !== '' && (this[key] = value);
2709
+ break;
2710
+
2711
+ case 'function':
2712
+ typeof value === 'function' && (this[key] = value);
2713
+ break;
2714
+
2715
+ case 'dom':
2716
+ value instanceof HTMLElement && (this[key] = value);
2717
+ break;
2718
+
2719
+ default:
2720
+ }
2721
+ }
2722
+ };
2723
+ /* harmony default export */ __webpack_exports__["default"] = (config);
2724
+
2725
+ /***/ }),
2726
+
2696
2727
  /***/ "./src/modules/constant.js":
2697
2728
  /*!*********************************!*\
2698
2729
  !*** ./src/modules/constant.js ***!
@@ -2749,7 +2780,7 @@ var DEFAULT_DARK_TEXTCOLOR = '#a3a3a3'; // 前景色:rgba(255,255,255,0.6) 背
2749
2780
 
2750
2781
  var DEFAULT_DARK_BGCOLOR = '#191919'; // Dark Mode下背景颜色
2751
2782
 
2752
- var GRAY_MASK_COLOR = 'rgba(0,0,0,0.1)'; // 灰色蒙层色值
2783
+ var GRAY_MASK_COLOR = 'rgba(0,0,0,0.2)'; // 灰色蒙层色值
2753
2784
 
2754
2785
  var WHITE_LIKE_COLOR_BRIGHTNESS = 250; // 接近白色的感知亮度阈值
2755
2786
 
@@ -2776,11 +2807,25 @@ var IMPORTANT_REGEXP = / !important$/; // !important
2776
2807
  __webpack_require__.r(__webpack_exports__);
2777
2808
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return CssUtils; });
2778
2809
  /* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
2810
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
2811
+ /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
2812
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2813
+
2814
+ 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."); }
2815
+
2816
+ 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); }
2817
+
2818
+ 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; }
2819
+
2820
+ 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; }
2821
+
2822
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2823
+
2779
2824
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2780
2825
 
2781
2826
  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); } }
2782
2827
 
2783
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2828
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2784
2829
 
2785
2830
  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; }
2786
2831
 
@@ -2789,9 +2834,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2789
2834
  *
2790
2835
  * @class CssUtils
2791
2836
  *
2792
- * @constructor
2793
- * @param {Object} config Darkmode配置
2794
- *
2795
2837
  * @attr {boolean} isFinish 是否运行过Dark Mode处理逻辑(写入过非首屏样式表则表示已运行过)
2796
2838
  *
2797
2839
  * @method genCssKV 生成css键值对
@@ -2812,12 +2854,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
2812
2854
  * @param {boolean} isFirstPageStyle 是否首屏样式
2813
2855
  *
2814
2856
  */
2857
+ // Darkmode配置
2858
+
2859
+
2815
2860
 
2816
2861
 
2817
2862
  var CssUtils = /*#__PURE__*/function () {
2818
2863
  // 首屏样式
2819
2864
  // 非首屏样式
2820
- function CssUtils(config) {
2865
+ function CssUtils() {
2821
2866
  _classCallCheck(this, CssUtils);
2822
2867
 
2823
2868
  _defineProperty(this, "_firstPageStyle", '');
@@ -2825,8 +2870,6 @@ var CssUtils = /*#__PURE__*/function () {
2825
2870
  _defineProperty(this, "_otherPageStyle", '');
2826
2871
 
2827
2872
  _defineProperty(this, "isFinish", false);
2828
-
2829
- this._config = config;
2830
2873
  }
2831
2874
 
2832
2875
  _createClass(CssUtils, [{
@@ -2837,34 +2880,62 @@ var CssUtils = /*#__PURE__*/function () {
2837
2880
  }, {
2838
2881
  key: "genCss",
2839
2882
  value: function genCss(className, cssKV) {
2840
- return "".concat(this._config.mode === 'dark' ? "html.".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["HTML_CLASS"], " ") : '').concat(this._config.cssSelectorsPrefix && "".concat(this._config.cssSelectorsPrefix, " "), ".").concat(className, "{").concat(cssKV, "}");
2883
+ 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, "}");
2841
2884
  }
2842
2885
  }, {
2843
2886
  key: "addCss",
2844
2887
  value: function addCss(css, isFirstPageStyle) {
2845
2888
  this[isFirstPageStyle ? '_firstPageStyle' : '_otherPageStyle'] += css;
2889
+ _global__WEBPACK_IMPORTED_MODULE_2__["plugins"].addCss(isFirstPageStyle);
2846
2890
  }
2847
2891
  }, {
2848
2892
  key: "writeStyle",
2849
2893
  value: function writeStyle(isFirstPageStyle) {
2850
- var styleKey = '';
2851
-
2852
- if (!isFirstPageStyle) {
2853
- // 如果是写入非首屏样式表,则连同首屏样式一起写入
2854
- this._otherPageStyle = this._firstPageStyle + this._otherPageStyle;
2855
- this._firstPageStyle = '';
2856
- styleKey = '_otherPageStyle';
2857
- this.isFinish = true;
2858
- } else {
2859
- styleKey = '_firstPageStyle';
2860
- }
2894
+ !isFirstPageStyle && _global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode && (this.isFinish = true); // 在Dark Mode下一旦写入了非首屏样式表,则认为已经运行过Dark Mode处理逻辑
2895
+ // 获取样式表内容
2896
+
2897
+ var styles = (_global__WEBPACK_IMPORTED_MODULE_2__["sdk"].isDarkmode ? [{
2898
+ target: this,
2899
+ key: ['_firstPageStyle', '_otherPageStyle'],
2900
+ needMediaQuery: true
2901
+ }] : []).concat([{
2902
+ target: _global__WEBPACK_IMPORTED_MODULE_2__["plugins"],
2903
+ key: ['firstPageStyle', 'otherPageStyle'],
2904
+ needMediaQuery: true
2905
+ }, {
2906
+ target: _global__WEBPACK_IMPORTED_MODULE_2__["plugins"],
2907
+ key: ['firstPageStyleNoMQ', 'otherPageStyleNoMQ'],
2908
+ needMediaQuery: false
2909
+ }]).map(function (_ref) {
2910
+ var target = _ref.target,
2911
+ _ref$key = _slicedToArray(_ref.key, 2),
2912
+ first = _ref$key[0],
2913
+ other = _ref$key[1],
2914
+ needMediaQuery = _ref.needMediaQuery;
2915
+
2916
+ var styleKey = '';
2917
+
2918
+ if (!isFirstPageStyle) {
2919
+ // 如果是写入非首屏样式表,则连同首屏样式一起写入
2920
+ target[other] = target[first] + target[other];
2921
+ target[first] = '';
2922
+ styleKey = other;
2923
+ } else {
2924
+ styleKey = first;
2925
+ }
2861
2926
 
2862
- var style = this[styleKey];
2927
+ var style = target[styleKey];
2863
2928
 
2864
- if (style) {
2865
- document.head.insertAdjacentHTML('beforeend', "<style type=\"text/css\">".concat(this._config.mode === 'dark' ? style : "@media ".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["MEDIA_QUERY"], " {").concat(style, "}"), "</style>"));
2866
- this[styleKey] = ''; // 写入样式表后清空内存中的数据
2867
- }
2929
+ if (style) {
2930
+ target[styleKey] = ''; // 写入样式表后清空内存中的数据
2931
+
2932
+ return _config__WEBPACK_IMPORTED_MODULE_1__["default"].mode === 'dark' || !needMediaQuery ? style : "@media ".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["MEDIA_QUERY"], " {").concat(style, "}");
2933
+ }
2934
+
2935
+ return '';
2936
+ }).join(''); // 写入样式表
2937
+
2938
+ styles && document.head.insertAdjacentHTML('beforeend', "<style type=\"text/css\">".concat(styles, "</style>"));
2868
2939
  }
2869
2940
  }]);
2870
2941
 
@@ -2889,11 +2960,13 @@ __webpack_require__.r(__webpack_exports__);
2889
2960
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasTextNode", function() { return hasTextNode; });
2890
2961
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasTableClass", function() { return hasTableClass; });
2891
2962
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DomUtils", function() { return DomUtils; });
2963
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
2964
+ /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
2892
2965
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2893
2966
 
2894
2967
  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); } }
2895
2968
 
2896
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2969
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2897
2970
 
2898
2971
  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; }
2899
2972
 
@@ -2901,9 +2974,9 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
2901
2974
 
2902
2975
  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."); }
2903
2976
 
2904
- 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(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
2977
+ 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); }
2905
2978
 
2906
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
2979
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
2907
2980
 
2908
2981
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
2909
2982
 
@@ -2925,6 +2998,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
2925
2998
  * @return {string | null} 判断结果,如果有,返回class对应的lm色值,否则返回null
2926
2999
  *
2927
3000
  */
3001
+ // Darkmode配置
3002
+
3003
+
2928
3004
  function getChildrenAndIt(dom) {
2929
3005
  var _ref;
2930
3006
 
@@ -2964,18 +3040,13 @@ function hasTableClass(dom) {
2964
3040
  *
2965
3041
  * @class DomUtils
2966
3042
  *
2967
- * @constructor
2968
- * @param {Object} config Darkmode配置
2969
- *
3043
+ * @attr {number} length 要处理的节点列表长度
2970
3044
  * @attr {boolean} showFirstPage 是否已显示首屏
2971
3045
  *
2972
3046
  * @method set 设置要处理的节点列表
2973
3047
  * @param {Dom Object Array} nodes 要处理的节点列表
2974
3048
  *
2975
- * @method len 获取要处理的节点列表长度
2976
- * @return {number} 长度
2977
- *
2978
- * @method get 获取要处理的节点列表长度(包含延迟节点、容器节点等逻辑)
3049
+ * @method get 获取要处理的节点列表(包含延迟节点、容器节点等逻辑)
2979
3050
  * @return {Dom Object Array} 要处理的节点列表
2980
3051
  *
2981
3052
  * @method delay 将所有要处理的节点转移到延迟处理队列里
@@ -2988,6 +3059,8 @@ function hasTableClass(dom) {
2988
3059
  *
2989
3060
  * @method showFirstPageNodes 显示所有首屏节点
2990
3061
  *
3062
+ * @method emptyFirstPageNodes 清空记录的首屏节点
3063
+ *
2991
3064
  */
2992
3065
 
2993
3066
  var DomUtils = /*#__PURE__*/function () {
@@ -2995,7 +3068,7 @@ var DomUtils = /*#__PURE__*/function () {
2995
3068
  // 首屏节点列表
2996
3069
  // 延迟处理的节点列表
2997
3070
  // 是否已显示首屏
2998
- function DomUtils(config) {
3071
+ function DomUtils() {
2999
3072
  _classCallCheck(this, DomUtils);
3000
3073
 
3001
3074
  _defineProperty(this, "_nodes", []);
@@ -3005,21 +3078,19 @@ var DomUtils = /*#__PURE__*/function () {
3005
3078
  _defineProperty(this, "_delayNodes", []);
3006
3079
 
3007
3080
  _defineProperty(this, "showFirstPage", false);
3008
-
3009
- this._config = config;
3010
3081
  }
3011
3082
 
3012
3083
  _createClass(DomUtils, [{
3084
+ key: "length",
3085
+ get: function get() {
3086
+ return this._nodes.length;
3087
+ }
3088
+ }, {
3013
3089
  key: "set",
3014
3090
  value: function set() {
3015
3091
  var nodes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
3016
3092
  this._nodes = nodes;
3017
3093
  }
3018
- }, {
3019
- key: "len",
3020
- value: function len() {
3021
- return this._nodes.length;
3022
- }
3023
3094
  }, {
3024
3095
  key: "get",
3025
3096
  value: function get() {
@@ -3028,16 +3099,16 @@ var DomUtils = /*#__PURE__*/function () {
3028
3099
  if (this._nodes.length) {
3029
3100
  // 有节点
3030
3101
  res = this._nodes;
3031
- this._nodes = [];
3102
+ _global__WEBPACK_IMPORTED_MODULE_1__["sdk"].isDarkmode && (this._nodes = []);
3032
3103
  } else {
3033
3104
  // 如果没有节点
3034
3105
  if (this._delayNodes.length) {
3035
3106
  // 有延迟节点,则使用延迟节点
3036
3107
  res = this._delayNodes;
3037
3108
  this._delayNodes = [];
3038
- } else if (this._config.container) {
3109
+ } else if (_config__WEBPACK_IMPORTED_MODULE_0__["default"].container) {
3039
3110
  // 没有延迟节点,但有容器,重新获取容器内的节点
3040
- res = this._config.container.querySelectorAll('*');
3111
+ res = _config__WEBPACK_IMPORTED_MODULE_0__["default"].container.querySelectorAll('*');
3041
3112
  }
3042
3113
  }
3043
3114
 
@@ -3072,10 +3143,13 @@ var DomUtils = /*#__PURE__*/function () {
3072
3143
  }); // 显示首屏节点
3073
3144
 
3074
3145
 
3075
- this._firstPageNodes = []; // 处理完之后清空列表
3076
-
3077
3146
  this.showFirstPage = true; // 记录为已显示首屏
3078
3147
  }
3148
+ }, {
3149
+ key: "emptyFirstPageNodes",
3150
+ value: function emptyFirstPageNodes() {
3151
+ this._firstPageNodes = [];
3152
+ }
3079
3153
  }]);
3080
3154
 
3081
3155
  return DomUtils;
@@ -3084,6 +3158,219 @@ var DomUtils = /*#__PURE__*/function () {
3084
3158
 
3085
3159
  /***/ }),
3086
3160
 
3161
+ /***/ "./src/modules/global.js":
3162
+ /*!*******************************!*\
3163
+ !*** ./src/modules/global.js ***!
3164
+ \*******************************/
3165
+ /*! exports provided: plugins, tnQueue, bgStack, cssUtils, domUtils, sdk */
3166
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
3167
+
3168
+ "use strict";
3169
+ __webpack_require__.r(__webpack_exports__);
3170
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "plugins", function() { return plugins; });
3171
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "tnQueue", function() { return tnQueue; });
3172
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bgStack", function() { return bgStack; });
3173
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "cssUtils", function() { return cssUtils; });
3174
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "domUtils", function() { return domUtils; });
3175
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sdk", function() { return sdk; });
3176
+ /* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
3177
+ /* harmony import */ var _plugins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./plugins */ "./src/modules/plugins.js");
3178
+ /* harmony import */ var _textNodeQueue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./textNodeQueue */ "./src/modules/textNodeQueue.js");
3179
+ /* harmony import */ var _bgNodeStack__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./bgNodeStack */ "./src/modules/bgNodeStack.js");
3180
+ /* harmony import */ var _cssUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./cssUtils */ "./src/modules/cssUtils.js");
3181
+ /* harmony import */ var _domUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./domUtils */ "./src/modules/domUtils.js");
3182
+ /* harmony import */ var _sdk__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./sdk */ "./src/modules/sdk.js");
3183
+ /**
3184
+ * @name 全局作用域
3185
+ *
3186
+ */
3187
+ // 插件系统
3188
+
3189
+
3190
+ var plugins = new _plugins__WEBPACK_IMPORTED_MODULE_1__["default"](); // 文本节点队列
3191
+
3192
+
3193
+ var tnQueue = new _textNodeQueue__WEBPACK_IMPORTED_MODULE_2__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "text__")); // 需要判断位置的背景节点堆栈
3194
+
3195
+
3196
+ var bgStack = new _bgNodeStack__WEBPACK_IMPORTED_MODULE_3__["default"]("".concat(_constant__WEBPACK_IMPORTED_MODULE_0__["CLASS_PREFIX"], "bg__")); // 样式相关操作工具对象
3197
+
3198
+
3199
+ var cssUtils = new _cssUtils__WEBPACK_IMPORTED_MODULE_4__["default"](); // 节点相关操作工具对象
3200
+
3201
+
3202
+ var domUtils = new _domUtils__WEBPACK_IMPORTED_MODULE_5__["DomUtils"](); // sdk
3203
+
3204
+
3205
+ var sdk = new _sdk__WEBPACK_IMPORTED_MODULE_6__["default"]();
3206
+
3207
+ /***/ }),
3208
+
3209
+ /***/ "./src/modules/plugins.js":
3210
+ /*!********************************!*\
3211
+ !*** ./src/modules/plugins.js ***!
3212
+ \********************************/
3213
+ /*! exports provided: default */
3214
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
3215
+
3216
+ "use strict";
3217
+ __webpack_require__.r(__webpack_exports__);
3218
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Plugins; });
3219
+ /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3220
+ 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; }
3221
+
3222
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3223
+
3224
+ 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); } }
3225
+
3226
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3227
+
3228
+ /**
3229
+ * @name 插件基类
3230
+ *
3231
+ * @class Plugin
3232
+ *
3233
+ * @attr {number} loopTimes 遍历次数(全部节点遍历结束算一次)
3234
+ * @attr {boolean} isDarkmode 是否为Dark Mode
3235
+ *
3236
+ * @method addCss 添加样式
3237
+ * @param {string} className DOM节点类名
3238
+ * @param {Array} kvList css键值对列表
3239
+ * @param {string} kvList[0].key css属性
3240
+ * @param {string} kvList[0].value css值
3241
+ * @param {boolean} needMediaQuery 是否需要添加Dark Mode媒体查询
3242
+ *
3243
+ */
3244
+
3245
+ var cssNeedMQ = [];
3246
+ var cssNoMQ = [];
3247
+
3248
+ var Plugin = /*#__PURE__*/function () {
3249
+ function Plugin() {
3250
+ _classCallCheck(this, Plugin);
3251
+ }
3252
+
3253
+ _createClass(Plugin, [{
3254
+ key: "loopTimes",
3255
+ get: function get() {
3256
+ return _global__WEBPACK_IMPORTED_MODULE_0__["plugins"].loopTimes;
3257
+ }
3258
+ }, {
3259
+ key: "isDarkmode",
3260
+ get: function get() {
3261
+ return _global__WEBPACK_IMPORTED_MODULE_0__["sdk"].isDarkmode;
3262
+ }
3263
+ }, {
3264
+ key: "addCss",
3265
+ value: function addCss(className, kvList) {
3266
+ var needMediaQuery = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3267
+ (needMediaQuery ? cssNeedMQ : cssNoMQ).push(_global__WEBPACK_IMPORTED_MODULE_0__["cssUtils"].genCss(className, kvList.map(function (_ref) {
3268
+ var key = _ref.key,
3269
+ value = _ref.value;
3270
+ return _global__WEBPACK_IMPORTED_MODULE_0__["cssUtils"].genCssKV(key, value);
3271
+ }).join('')));
3272
+ }
3273
+ }]);
3274
+
3275
+ return Plugin;
3276
+ }();
3277
+ /**
3278
+ * @name 插件系统
3279
+ *
3280
+ * @class Plugins
3281
+ *
3282
+ * @attr {number} length 已挂载的插件数量
3283
+ * @attr {string} firstPageStyle 首屏样式
3284
+ * @attr {string} otherPageStyle 非首屏样式
3285
+ * @attr {string} firstPageStyleNoMQ 首屏样式(不需要加媒体查询)
3286
+ * @attr {string} otherPageStyleNoMQ 非首屏样式(不需要加媒体查询)
3287
+ *
3288
+ * @method extend 挂载插件
3289
+ * @param {Function} plugin 插件构造函数
3290
+ *
3291
+ * @method emit 执行插件钩子
3292
+ * @param {string} name 钩子名称
3293
+ * @param {Any} args 钩子参数
3294
+ *
3295
+ * @method addCss 写入插件样式
3296
+ * @param {boolean} isFirstPageStyle 是否首屏样式
3297
+ *
3298
+ * @method resetCss 重置插件样式
3299
+ *
3300
+ */
3301
+
3302
+
3303
+ var Plugins = /*#__PURE__*/function () {
3304
+ // 已挂载的插件列表
3305
+ // 已挂载的插件数量
3306
+ // 已遍历次数
3307
+ // 首屏样式
3308
+ // 非首屏样式
3309
+ // 首屏样式(不需要加媒体查询)
3310
+ // 非首屏样式(不需要加媒体查询)
3311
+ function Plugins() {
3312
+ _classCallCheck(this, Plugins);
3313
+
3314
+ _defineProperty(this, "_plugins", []);
3315
+
3316
+ _defineProperty(this, "length", 0);
3317
+
3318
+ _defineProperty(this, "loopTimes", 0);
3319
+
3320
+ _defineProperty(this, "firstPageStyle", '');
3321
+
3322
+ _defineProperty(this, "otherPageStyle", '');
3323
+
3324
+ _defineProperty(this, "firstPageStyleNoMQ", '');
3325
+
3326
+ _defineProperty(this, "otherPageStyleNoMQ", '');
3327
+ }
3328
+
3329
+ _createClass(Plugins, [{
3330
+ key: "extend",
3331
+ value: function extend(plugin) {
3332
+ this._plugins.push(new (plugin(Plugin))());
3333
+
3334
+ this.length++;
3335
+ }
3336
+ }, {
3337
+ key: "emit",
3338
+ value: function emit(name) {
3339
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3340
+ args[_key - 1] = arguments[_key];
3341
+ }
3342
+
3343
+ this._plugins.forEach(function (plugin) {
3344
+ typeof plugin[name] === 'function' && plugin[name].apply(plugin, args);
3345
+ });
3346
+ }
3347
+ }, {
3348
+ key: "addCss",
3349
+ value: function addCss(isFirstPageStyle) {
3350
+ if (isFirstPageStyle) {
3351
+ this.firstPageStyle += cssNeedMQ.join('');
3352
+ this.firstPageStyleNoMQ += cssNoMQ.join('');
3353
+ } else {
3354
+ this.otherPageStyle += cssNeedMQ.join('');
3355
+ this.otherPageStyleNoMQ += cssNoMQ.join('');
3356
+ }
3357
+ }
3358
+ }, {
3359
+ key: "resetCss",
3360
+ value: function resetCss() {
3361
+ cssNeedMQ = [];
3362
+ cssNoMQ = [];
3363
+ }
3364
+ }]);
3365
+
3366
+ return Plugins;
3367
+ }();
3368
+
3369
+
3370
+ ;
3371
+
3372
+ /***/ }),
3373
+
3087
3374
  /***/ "./src/modules/sdk.js":
3088
3375
  /*!****************************!*\
3089
3376
  !*** ./src/modules/sdk.js ***!
@@ -3099,12 +3386,14 @@ __webpack_require__.r(__webpack_exports__);
3099
3386
  /* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js");
3100
3387
  /* harmony import */ var color_name__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(color_name__WEBPACK_IMPORTED_MODULE_1__);
3101
3388
  /* harmony import */ var _constant__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./constant */ "./src/modules/constant.js");
3102
- /* harmony import */ var _domUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./domUtils */ "./src/modules/domUtils.js");
3389
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
3390
+ /* harmony import */ var _global__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./global */ "./src/modules/global.js");
3391
+ /* harmony import */ var _domUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./domUtils */ "./src/modules/domUtils.js");
3103
3392
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3104
3393
 
3105
3394
  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."); }
3106
3395
 
3107
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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; }
3396
+ 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; }
3108
3397
 
3109
3398
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3110
3399
 
@@ -3112,9 +3401,9 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
3112
3401
 
3113
3402
  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."); }
3114
3403
 
3115
- 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(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3404
+ 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); }
3116
3405
 
3117
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
3406
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
3118
3407
 
3119
3408
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
3120
3409
 
@@ -3124,7 +3413,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
3124
3413
 
3125
3414
  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); } }
3126
3415
 
3127
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
3416
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3128
3417
 
3129
3418
  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; }
3130
3419
 
@@ -3133,13 +3422,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
3133
3422
  *
3134
3423
  * @class SDK
3135
3424
  *
3136
- * @constructor
3137
- * @param {Object} obj
3138
- * @param {Object} obj.config Darkmode配置
3139
- * @param {Object} obj.tnQueue 文本队列
3140
- * @param {Object} obj.bgStack 背景堆栈
3141
- * @param {Object} obj.cssUtils 样式工具
3142
- *
3143
3425
  * @method convert 处理节点
3144
3426
  * @param {DOM Object} el 要处理的节点
3145
3427
  * @return {string} 处理后的css,包含css选择器
@@ -3152,6 +3434,9 @@ color_name__WEBPACK_IMPORTED_MODULE_1___default.a.windowtext = [0, 0, 0]; // 补
3152
3434
 
3153
3435
  color_name__WEBPACK_IMPORTED_MODULE_1___default.a.transparent = [255, 255, 255, 0]; // 支持透明,暂定用白色透明度0来表示
3154
3436
 
3437
+ // Darkmode配置
3438
+
3439
+
3155
3440
  // 节点相关操作工具API
3156
3441
 
3157
3442
 
@@ -3203,52 +3488,52 @@ var parseWebkitFillColorAndStrokeColor = function parseWebkitFillColorAndStrokeC
3203
3488
 
3204
3489
  var getColorPerceivedBrightness = function getColorPerceivedBrightness(rgb) {
3205
3490
  return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
3491
+ }; // 调整为指定感知亮度
3492
+
3493
+
3494
+ var adjustBrightnessByLimit = function adjustBrightnessByLimit(limitBright, rgb) {
3495
+ var relativeBrightnessRatio = limitBright / getColorPerceivedBrightness(rgb);
3496
+ var newTextR = Math.min(255, rgb[0] * relativeBrightnessRatio);
3497
+ var newTextG = Math.min(255, rgb[1] * relativeBrightnessRatio);
3498
+ var newTextB = Math.min(255, rgb[2] * relativeBrightnessRatio);
3499
+
3500
+ if (newTextG === 0 || newTextR === 255 || newTextB === 255) {
3501
+ newTextG = (limitBright * 1000 - newTextR * 299 - newTextB * 114) / 587;
3502
+ } else if (newTextR === 0) {
3503
+ newTextR = (limitBright * 1000 - newTextG * 587 - newTextB * 114) / 299;
3504
+ } else if (newTextB === 0 || newTextG === 255) {
3505
+ newTextB = (limitBright * 1000 - newTextR * 299 - newTextG * 587) / 114;
3506
+ }
3507
+
3508
+ return color__WEBPACK_IMPORTED_MODULE_0___default.a.rgb(newTextR, newTextG, newTextB);
3206
3509
  };
3207
3510
 
3208
3511
  var SDK = /*#__PURE__*/function () {
3209
3512
  // 索引值
3210
- function SDK(_ref) {
3211
- var config = _ref.config,
3212
- tnQueue = _ref.tnQueue,
3213
- bgStack = _ref.bgStack,
3214
- cssUtils = _ref.cssUtils;
3215
-
3513
+ // 当前是否需要运行Darkmode处理
3514
+ function SDK() {
3216
3515
  _classCallCheck(this, SDK);
3217
3516
 
3218
3517
  _defineProperty(this, "_idx", 0);
3219
3518
 
3220
- this._config = config;
3221
- this._tnQueue = tnQueue;
3222
- this._bgStack = bgStack;
3223
- this._cssUtils = cssUtils;
3224
- this._defaultDarkTextColorRgb = color__WEBPACK_IMPORTED_MODULE_0___default()(this._config.defaultDarkTextColor).rgb().array();
3225
- this._defaultDarkBgColorRgb = color__WEBPACK_IMPORTED_MODULE_0___default()(this._config.defaultDarkBgColor).rgb().array();
3226
- this._defaultDarkBgColorHSL = color__WEBPACK_IMPORTED_MODULE_0___default()(this._config.defaultDarkBgColor).hsl().array();
3227
- this._defaultDarkTextColorBrightness = getColorPerceivedBrightness(this._defaultDarkTextColorRgb);
3228
- this._defaultDarkBgColorBrightness = getColorPerceivedBrightness(this._defaultDarkBgColorRgb);
3229
- this._defaultDarkBgColorHslBrightness = this._defaultDarkBgColorHSL[2];
3230
- this._maxLimitOffsetBrightness = this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness;
3519
+ _defineProperty(this, "_defaultDarkTextColorRgb", color__WEBPACK_IMPORTED_MODULE_0___default()(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkTextColor).rgb().array());
3520
+
3521
+ _defineProperty(this, "_defaultDarkBgColorRgb", color__WEBPACK_IMPORTED_MODULE_0___default()(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).rgb().array());
3522
+
3523
+ _defineProperty(this, "_defaultDarkBgColorHSL", color__WEBPACK_IMPORTED_MODULE_0___default()(_config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor).hsl().array());
3524
+
3525
+ _defineProperty(this, "_defaultDarkTextColorBrightness", getColorPerceivedBrightness(this._defaultDarkTextColorRgb));
3526
+
3527
+ _defineProperty(this, "_defaultDarkBgColorBrightness", getColorPerceivedBrightness(this._defaultDarkBgColorRgb));
3528
+
3529
+ _defineProperty(this, "_defaultDarkBgColorHslBrightness", this._defaultDarkBgColorHSL[2]);
3530
+
3531
+ _defineProperty(this, "_maxLimitOffsetBrightness", this._defaultDarkTextColorBrightness - this._defaultDarkBgColorBrightness);
3532
+
3533
+ _defineProperty(this, "isDarkmode", false);
3231
3534
  }
3232
3535
 
3233
3536
  _createClass(SDK, [{
3234
- key: "_adjustBrightnessByLimit",
3235
- value: function _adjustBrightnessByLimit(limitBright, rgb) {
3236
- var relativeBrightnessRatio = limitBright / getColorPerceivedBrightness(rgb);
3237
- var newTextR = Math.min(255, rgb[0] * relativeBrightnessRatio);
3238
- var newTextG = Math.min(255, rgb[1] * relativeBrightnessRatio);
3239
- var newTextB = Math.min(255, rgb[2] * relativeBrightnessRatio);
3240
-
3241
- if (newTextG === 0 || newTextR === 255 || newTextB === 255) {
3242
- newTextG = (limitBright * 1000 - newTextR * 299 - newTextB * 114) / 587;
3243
- } else if (newTextR === 0) {
3244
- newTextR = (limitBright * 1000 - newTextG * 587 - newTextB * 114) / 299;
3245
- } else if (newTextB === 0 || newTextG === 255) {
3246
- newTextB = (limitBright * 1000 - newTextR * 299 - newTextG * 587) / 114;
3247
- }
3248
-
3249
- return color__WEBPACK_IMPORTED_MODULE_0___default.a.rgb(newTextR, newTextG, newTextB);
3250
- }
3251
- }, {
3252
3537
  key: "_adjustTextBrightness",
3253
3538
  value: function _adjustTextBrightness(textColor, bgColor) {
3254
3539
  var bgColorRgb = bgColor.rgb().array();
@@ -3264,7 +3549,7 @@ var SDK = /*#__PURE__*/function () {
3264
3549
  if (textPerceivedBrightness >= _constant__WEBPACK_IMPORTED_MODULE_2__["WHITE_LIKE_COLOR_BRIGHTNESS"]) return textColor;
3265
3550
 
3266
3551
  if (offsetPerceivedBrightness > this._maxLimitOffsetBrightness && bgColorWithOpacityPerceivedBrightness <= this._defaultDarkBgColorBrightness + 2) {
3267
- return this._adjustBrightnessByLimit(this._maxLimitOffsetBrightness + bgColorWithOpacityPerceivedBrightness, textColorRgb).alpha(textColorAlpha);
3552
+ return adjustBrightnessByLimit(this._maxLimitOffsetBrightness + bgColorWithOpacityPerceivedBrightness, textColorRgb).alpha(textColorAlpha);
3268
3553
  } // 如果感知亮度差大于阈值,无需调整
3269
3554
 
3270
3555
 
@@ -3279,7 +3564,7 @@ var SDK = /*#__PURE__*/function () {
3279
3564
  return this._adjustTextBrightness(tmpTextColor, bgColor);
3280
3565
  }
3281
3566
 
3282
- return this._adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness - _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
3567
+ return adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness - _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
3283
3568
  } else {
3284
3569
  // 暗背景,调亮字体
3285
3570
  if (textColorHSL[2] <= _constant__WEBPACK_IMPORTED_MODULE_2__["HIGH_BLACKWHITE_HSL_BRIGHTNESS"]) {
@@ -3291,7 +3576,7 @@ var SDK = /*#__PURE__*/function () {
3291
3576
  return this._adjustTextBrightness(_tmpTextColor, bgColor);
3292
3577
  }
3293
3578
 
3294
- return this._adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness + _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
3579
+ return adjustBrightnessByLimit(Math.min(this._maxLimitOffsetBrightness, bgColorWithOpacityPerceivedBrightness + _constant__WEBPACK_IMPORTED_MODULE_2__["MIN_LIMIT_OFFSET_BRIGHTNESS"]), textColorRgb).alpha(textColorAlpha);
3295
3580
  }
3296
3581
  }
3297
3582
  }, {
@@ -3308,7 +3593,7 @@ var SDK = /*#__PURE__*/function () {
3308
3593
  newColor = color__WEBPACK_IMPORTED_MODULE_0___default.a.hsl(0, 0, Math.min(100, 100 + this._defaultDarkBgColorHslBrightness - bgColorHsl[2]));
3309
3594
  } else if (bgColorPerceivedBrightness > _constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"]) {
3310
3595
  // 感知亮度大于MAX_LIMIT_BGCOLOR_BRIGHTNESS,将感知亮度设为MAX_LIMIT_BGCOLOR_BRIGHTNESS
3311
- newColor = this._adjustBrightnessByLimit(_constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"], bgColorRgb).alpha(bgColorAlpha); // const ratio = (MAX_LIMIT_BGCOLOR_BRIGHTNESS * 1000)
3596
+ newColor = adjustBrightnessByLimit(_constant__WEBPACK_IMPORTED_MODULE_2__["MAX_LIMIT_BGCOLOR_BRIGHTNESS"], bgColorRgb).alpha(bgColorAlpha); // const ratio = (MAX_LIMIT_BGCOLOR_BRIGHTNESS * 1000)
3312
3597
  // / (bgColorRgb[0] * 299 + bgColorRgb[1] * 587 + bgColorRgb[2] * 114);
3313
3598
  // newColor = Color.rgb(bgColorRgb[0] * ratio, bgColorRgb[1] * ratio, bgColorRgb[2] * ratio);
3314
3599
  } else if (bgColorHsl[2] < _constant__WEBPACK_IMPORTED_MODULE_2__["LOW_BLACKWHITE_HSL_BRIGHTNESS"]) {
@@ -3348,8 +3633,7 @@ var SDK = /*#__PURE__*/function () {
3348
3633
  newColor = this._adjustBackgroundBrightness(color);
3349
3634
 
3350
3635
  if (!options.hasInlineColor) {
3351
- var parentTextColor = el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"]) || this._config.defaultLightTextColor;
3352
-
3636
+ var parentTextColor = el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"]) || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor;
3353
3637
  var parentBgColorStr = newColor || color; // el.setAttribute(BGCOLORATTR, newColor || color)
3354
3638
 
3355
3639
  var ret = this._adjustBrightness(color__WEBPACK_IMPORTED_MODULE_0___default()(parentTextColor), el, {
@@ -3358,19 +3642,23 @@ var SDK = /*#__PURE__*/function () {
3358
3642
  });
3359
3643
 
3360
3644
  if (ret.newColor) {
3361
- extStyle += this._cssUtils.genCssKV('color', ret.newColor);
3645
+ extStyle += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', ret.newColor);
3362
3646
  } else {
3363
- extStyle += this._cssUtils.genCssKV('color', parentTextColor);
3647
+ extStyle += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', parentTextColor);
3364
3648
  }
3365
3649
  }
3366
3650
  } else if (options.isTextColor || options.isBorderColor) {
3367
3651
  // 字体色、边框色
3368
- var parentElementBgColorStr = options.parentElementBgColorStr || options.isTextColor && el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]) || this._config.defaultDarkBgColor;
3369
-
3652
+ var parentElementBgColorStr = options.parentElementBgColorStr || options.isTextColor && el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"]) || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultDarkBgColor;
3370
3653
  var parentElementBgColor = color__WEBPACK_IMPORTED_MODULE_0___default()(parentElementBgColorStr); // 无背景图片
3371
3654
 
3372
3655
  if (!el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"])) {
3373
3656
  newColor = this._adjustTextBrightness(color, parentElementBgColor);
3657
+ _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit('afterConvertTextColor', el, {
3658
+ // fontColor: color,
3659
+ fontColor: newColor,
3660
+ bgColor: parentElementBgColor
3661
+ });
3374
3662
  }
3375
3663
  } else if (options.isTextShadow) {
3376
3664
  // 字体阴影
@@ -3389,7 +3677,7 @@ var SDK = /*#__PURE__*/function () {
3389
3677
  return func();
3390
3678
  } catch (e) {
3391
3679
  console.log('An error occurred when running the dark mode conversion algorithm\n', e);
3392
- typeof this._config.error === 'function' && this._config.error(e);
3680
+ typeof _config__WEBPACK_IMPORTED_MODULE_3__["default"].error === 'function' && _config__WEBPACK_IMPORTED_MODULE_3__["default"].error(e);
3393
3681
  }
3394
3682
  }
3395
3683
  }, {
@@ -3397,334 +3685,333 @@ var SDK = /*#__PURE__*/function () {
3397
3685
  value: function convert(el) {
3398
3686
  var _this = this;
3399
3687
 
3400
- var nodeName = el.nodeName;
3401
- if (this._config.whitelist.tagName.indexOf(nodeName) > -1) return '';
3402
- var styles = el.style;
3403
- var cssKV = ''; // css键值对
3404
-
3688
+ _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].resetCss();
3689
+ _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit('beforeConvertNode', el);
3405
3690
  var css = ''; // css
3406
3691
 
3407
- var hasInlineColor = false; // 是否有自定义字体颜色
3692
+ if (this.isDarkmode) {
3693
+ var nodeName = el.nodeName;
3694
+ if (_config__WEBPACK_IMPORTED_MODULE_3__["default"].whitelist.tagName.indexOf(nodeName) > -1) return '';
3695
+ var styles = el.style;
3696
+ var cssKV = ''; // css键值对
3408
3697
 
3409
- var hasInlineBackground = false;
3410
- var hasInlineBackgroundImage = false;
3411
- var elBackgroundPositionAttr;
3412
- var elBackgroundSizeAttr; // styles.cssText 读出来的颜色统一是rgba格式,除了用英文定义颜色(如:black、white)
3698
+ var hasInlineColor = false; // 是否有自定义字体颜色
3413
3699
 
3414
- var cssKVList = (styles.cssText && styles.cssText.split(';') || []).map(function (cssStr) {
3415
- // 将cssStr转换为[key, value],并清除各个元素的前后空白字符
3416
- var splitIdx = cssStr.indexOf(':');
3417
- return [cssStr.slice(0, splitIdx).toLowerCase(), cssStr.slice(splitIdx + 1)].map(function (item) {
3418
- return (item || '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
3419
- });
3420
- }).filter(function (_ref2) {
3421
- var _ref3 = _slicedToArray(_ref2, 2),
3422
- key = _ref3[0],
3423
- value = _ref3[1];
3424
-
3425
- if (key === 'color') {
3426
- hasInlineColor = true;
3427
- } else if (/background/i.test(key)) {
3428
- hasInlineBackground = true;
3429
-
3430
- if (key === 'background-position') {
3431
- elBackgroundPositionAttr = value;
3432
- } else if (key === 'background-size') {
3433
- elBackgroundSizeAttr = value;
3434
- }
3435
- }
3436
-
3437
- if ((/background/i.test(key) || /^(-webkit-)?border-image/.test(key)) && /url\([^)]*\)/i.test(value)) {
3438
- hasInlineBackgroundImage = true;
3439
- } // 过滤掉一些key
3700
+ var hasInlineBackground = false;
3701
+ var hasInlineBackgroundImage = false;
3702
+ var elBackgroundPositionAttr;
3703
+ var elBackgroundSizeAttr; // styles.cssText 读出来的颜色统一是rgba格式,除了用英文定义颜色(如:black、white)
3440
3704
 
3705
+ var cssKVList = (styles.cssText && styles.cssText.split(';') || []).map(function (cssStr) {
3706
+ // 将cssStr转换为[key, value],并清除各个元素的前后空白字符
3707
+ var splitIdx = cssStr.indexOf(':');
3708
+ return [cssStr.slice(0, splitIdx).toLowerCase(), cssStr.slice(splitIdx + 1)].map(function (item) {
3709
+ return (item || '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
3710
+ });
3711
+ }).filter(function (_ref) {
3712
+ var _ref2 = _slicedToArray(_ref, 2),
3713
+ key = _ref2[0],
3714
+ value = _ref2[1];
3441
3715
 
3442
- return ['-webkit-border-image', 'border-image', 'color', 'background-color', 'background-image', 'background', 'border', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', '-webkit-text-fill-color', '-webkit-text-stroke', '-webkit-text-stroke-color', 'text-shadow'].indexOf(key) > -1;
3443
- }).sort(function (_ref4, _ref5) {
3444
- var _ref6 = _slicedToArray(_ref4, 1),
3445
- key1 = _ref6[0];
3716
+ if (key === 'color') {
3717
+ hasInlineColor = true;
3718
+ } else if (/background/i.test(key)) {
3719
+ hasInlineBackground = true;
3446
3720
 
3447
- var _ref7 = _slicedToArray(_ref5, 1),
3448
- key2 = _ref7[0];
3721
+ if (key === 'background-position') {
3722
+ elBackgroundPositionAttr = value;
3723
+ } else if (key === 'background-size') {
3724
+ elBackgroundSizeAttr = value;
3725
+ }
3726
+ }
3449
3727
 
3450
- // color属性放在最后
3451
- if (key1 === 'color') {
3452
- return 1;
3453
- } else if (key1 === 'background-image' && key2 === 'background-color') {
3454
- // 确保 background-image 在 background-color 后面
3455
- return 1;
3456
- } else if (key2.indexOf('-webkit-text') === 0) {
3457
- // 把-webkit-text的属性放在最前面
3458
- return 1;
3459
- }
3728
+ if ((/background/i.test(key) || /^(-webkit-)?border-image/.test(key)) && /url\([^)]*\)/i.test(value)) {
3729
+ hasInlineBackgroundImage = true;
3730
+ } // 过滤掉一些key
3460
3731
 
3461
- return -1;
3462
- });
3463
3732
 
3464
- if (_constant__WEBPACK_IMPORTED_MODULE_2__["TABLE_NAME"].indexOf(nodeName) > -1 && !hasInlineBackground) {
3465
- // 如果table没有内联样式
3466
- this._try(function () {
3467
- var color = Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["hasTableClass"])(el); // 获取class对应的lm色值
3733
+ return ['-webkit-border-image', 'border-image', 'color', 'background-color', 'background-image', 'background', 'border', 'border-top', 'border-right', 'border-bottom', 'border-left', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', '-webkit-text-fill-color', '-webkit-text-stroke', '-webkit-text-stroke-color', 'text-shadow'].indexOf(key) > -1;
3734
+ }).sort(function (_ref3, _ref4) {
3735
+ var _ref5 = _slicedToArray(_ref3, 1),
3736
+ key1 = _ref5[0];
3468
3737
 
3469
- if (!color) color = el.getAttribute('bgcolor'); // 如果没有class则获取bgcolor的色值
3738
+ var _ref6 = _slicedToArray(_ref4, 1),
3739
+ key2 = _ref6[0];
3470
3740
 
3471
- if (color) {
3472
- // 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
3473
- cssKVList.unshift(['background-color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
3474
- hasInlineBackground = true;
3741
+ // color属性放在最后
3742
+ if (key1 === 'color') {
3743
+ return 1;
3744
+ } else if (key1 === 'background-image' && key2 === 'background-color') {
3745
+ // 确保 background-image 在 background-color 后面
3746
+ return 1;
3747
+ } else if (key2.indexOf('-webkit-text') === 0) {
3748
+ // 把-webkit-text的属性放在最前面
3749
+ return 1;
3475
3750
  }
3476
- });
3477
- }
3478
3751
 
3479
- if (nodeName === 'FONT' && !hasInlineColor) {
3480
- // 如果是font标签且没有内联样式
3481
- this._try(function () {
3482
- var color = el.getAttribute('color'); // 获取color的色值
3483
-
3484
- if (color) {
3485
- // 有色值,则当做内联样式来处理
3486
- cssKVList.push(['color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
3487
- hasInlineColor = true;
3488
- }
3752
+ return -1;
3489
3753
  });
3490
- } // 处理-webkit-text相关样式
3491
-
3492
3754
 
3493
- var webkitFillColor = '';
3494
- var webkitStrokeColor = '';
3495
- var webkitTextLen = 0;
3496
- cssKVList.some(function (_ref8, idx) {
3497
- var _ref9 = _slicedToArray(_ref8, 2),
3498
- key = _ref9[0],
3499
- value = _ref9[1];
3755
+ if (_constant__WEBPACK_IMPORTED_MODULE_2__["TABLE_NAME"].indexOf(nodeName) > -1 && !hasInlineBackground) {
3756
+ // 如果table没有内联样式
3757
+ this._try(function () {
3758
+ var color = Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["hasTableClass"])(el); // 获取class对应的lm色值
3500
3759
 
3501
- return _this._try(function () {
3502
- if (key.indexOf('-webkit-text') !== 0) {
3503
- // 遍历到非-webkit-text样式
3504
- webkitTextLen = idx; // 记录-webkit-text相关样式的长度
3760
+ if (!color) color = el.getAttribute('bgcolor'); // 如果没有class则获取bgcolor的色值
3505
3761
 
3506
- return true; // 结束遍历
3507
- }
3508
-
3509
- switch (key) {
3510
- case '-webkit-text-fill-color':
3511
- webkitFillColor = parseWebkitFillColorAndStrokeColor(value);
3512
- break;
3762
+ if (color) {
3763
+ // 有色值(class对应的lm色值或者是bgcolor色值),则当做内联样式来处理
3764
+ cssKVList.unshift(['background-color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
3765
+ hasInlineBackground = true;
3766
+ }
3767
+ });
3768
+ }
3513
3769
 
3514
- case '-webkit-text-stroke':
3515
- {
3516
- // 有-webkit-text-stroke时就不会有-webkit-text-stroke-color
3517
- var newValue = value.split(' ');
3518
- newValue.length === 2 && (webkitStrokeColor = parseWebkitFillColorAndStrokeColor(newValue[1]));
3519
- break;
3520
- }
3770
+ if (nodeName === 'FONT' && !hasInlineColor) {
3771
+ // 如果是font标签且没有内联样式
3772
+ this._try(function () {
3773
+ var color = el.getAttribute('color'); // 获取color的色值
3521
3774
 
3522
- case '-webkit-text-stroke-color':
3523
- // 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
3524
- webkitStrokeColor = parseWebkitFillColorAndStrokeColor(value);
3525
- break;
3526
- }
3775
+ if (color) {
3776
+ // 有色值,则当做内联样式来处理
3777
+ cssKVList.push(['color', color__WEBPACK_IMPORTED_MODULE_0___default()(color).toString()]);
3778
+ hasInlineColor = true;
3779
+ }
3780
+ });
3781
+ } // 处理-webkit-text相关样式
3527
3782
 
3528
- return false; // 继续遍历
3529
- });
3530
- });
3531
3783
 
3532
- if (webkitFillColor) {
3533
- // 有-webkit-text-fill-color,当做color对待
3534
- if (hasInlineColor) {
3535
- // 本来有color,替换为-webkit-text-fill-color
3536
- cssKVList[cssKVList.length - 1] = ['-webkit-text-fill-color', webkitFillColor];
3537
- } else {
3538
- // 没有color,push一个-webkit-text-fill-color
3539
- cssKVList.push(['-webkit-text-fill-color', webkitFillColor]);
3540
- hasInlineColor = true;
3541
- }
3542
- }
3784
+ var webkitFillColor = '';
3785
+ var webkitStrokeColor = '';
3786
+ var webkitTextLen = 0;
3787
+ cssKVList.some(function (_ref7, idx) {
3788
+ var _ref8 = _slicedToArray(_ref7, 2),
3789
+ key = _ref8[0],
3790
+ value = _ref8[1];
3543
3791
 
3544
- if (webkitTextLen) {
3545
- cssKVList.splice(0, webkitTextLen); // 删掉-webkit-text相关样式
3792
+ return _this._try(function () {
3793
+ if (key.indexOf('-webkit-text') !== 0) {
3794
+ // 遍历到非-webkit-text样式
3795
+ webkitTextLen = idx; // 记录-webkit-text相关样式的长度
3546
3796
 
3547
- webkitStrokeColor && cssKVList.unshift(['-webkit-text-stroke-color', webkitStrokeColor]); // 如果有-webkit-text-stroke-color,则插入到最前面
3548
- }
3797
+ return true; // 结束遍历
3798
+ }
3549
3799
 
3550
- cssKVList.forEach(function (_ref10) {
3551
- var _ref11 = _slicedToArray(_ref10, 2),
3552
- key = _ref11[0],
3553
- value = _ref11[1];
3800
+ switch (key) {
3801
+ case '-webkit-text-fill-color':
3802
+ webkitFillColor = parseWebkitFillColorAndStrokeColor(value);
3803
+ break;
3554
3804
 
3555
- return _this._try(function () {
3556
- var oldValue = value;
3557
- var cssChange = false; // 找出色值来处理
3805
+ case '-webkit-text-stroke':
3806
+ {
3807
+ // 有-webkit-text-stroke时就不会有-webkit-text-stroke-color
3808
+ var newValue = value.split(' ');
3809
+ newValue.length === 2 && (webkitStrokeColor = parseWebkitFillColorAndStrokeColor(newValue[1]));
3810
+ break;
3811
+ }
3558
3812
 
3559
- var isBgColor = /^background/.test(key);
3560
- var isTextShadow = key === 'text-shadow';
3561
- var textColorIdx = ['-webkit-text-stroke-color', 'color', '-webkit-text-fill-color'].indexOf(key);
3562
- var isBorderColor = /^border/.test(key);
3563
- var isGradient = /gradient/.test(value);
3564
- var gradientColors = [];
3565
- var extStyle = '';
3566
- var gradientMixColor; // 将英文定义颜色转换为rgb格式
3813
+ case '-webkit-text-stroke-color':
3814
+ // 有-webkit-text-stroke-color时就不会有-webkit-text-stroke
3815
+ webkitStrokeColor = parseWebkitFillColorAndStrokeColor(value);
3816
+ break;
3817
+ }
3567
3818
 
3568
- value = parseColor(value, isGradient); // 渐变需要处理透明
3819
+ return false; // 继续遍历
3820
+ });
3821
+ });
3569
3822
 
3570
- if (colorReg.test(value)) {
3571
- if (isGradient) {
3572
- // 把原渐变色取出来
3573
- var matches = colorRegGlobal.exec(value);
3823
+ if (webkitFillColor) {
3824
+ // 有-webkit-text-fill-color,当做color对待
3825
+ if (hasInlineColor) {
3826
+ // 本来有color,替换为-webkit-text-fill-color
3827
+ cssKVList[cssKVList.length - 1] = ['-webkit-text-fill-color', webkitFillColor];
3828
+ } else {
3829
+ // 没有color,push一个-webkit-text-fill-color
3830
+ cssKVList.push(['-webkit-text-fill-color', webkitFillColor]);
3831
+ hasInlineColor = true;
3832
+ }
3833
+ }
3574
3834
 
3575
- while (matches) {
3576
- gradientColors.push(matches[0]);
3577
- matches = colorRegGlobal.exec(value);
3578
- } // 计算出一个mix颜色
3835
+ if (webkitTextLen) {
3836
+ cssKVList.splice(0, webkitTextLen); // 删掉-webkit-text相关样式
3579
3837
 
3838
+ webkitStrokeColor && cssKVList.unshift(['-webkit-text-stroke-color', webkitStrokeColor]); // 如果有-webkit-text-stroke-color,则插入到最前面
3839
+ }
3580
3840
 
3581
- gradientMixColor = mixColor(gradientColors);
3582
- }
3841
+ cssKVList.forEach(function (_ref9) {
3842
+ var _ref10 = _slicedToArray(_ref9, 2),
3843
+ key = _ref10[0],
3844
+ value = _ref10[1];
3583
3845
 
3584
- var replaceIndex = 0;
3585
- value = value.replace(colorRegGlobal, function (match) {
3586
- // 渐变色统一改成mix纯色
3587
- if (isGradient) {
3588
- match = gradientMixColor;
3589
- cssChange = true;
3590
- } // 使用颜色处理算法
3846
+ return _this._try(function () {
3847
+ var oldValue = value;
3848
+ var cssChange = false; // 找出色值来处理
3591
3849
 
3850
+ var isBgColor = /^background/.test(key);
3851
+ var isTextShadow = key === 'text-shadow';
3852
+ var textColorIdx = ['-webkit-text-stroke-color', 'color', '-webkit-text-fill-color'].indexOf(key);
3853
+ var isBorderColor = /^border/.test(key);
3854
+ var isGradient = /gradient/.test(value);
3855
+ var gradientColors = [];
3856
+ var extStyle = '';
3857
+ var gradientMixColor; // 将英文定义颜色转换为rgb格式
3592
3858
 
3593
- var ret = _this._adjustBrightness(color__WEBPACK_IMPORTED_MODULE_0___default()(match), el, {
3594
- isBgColor: isBgColor,
3595
- isTextShadow: isTextShadow,
3596
- isTextColor: textColorIdx > -1,
3597
- isBorderColor: isBorderColor,
3598
- hasInlineColor: hasInlineColor
3599
- });
3859
+ value = parseColor(value, isGradient); // 渐变需要处理透明
3600
3860
 
3601
- var retColor = !hasInlineBackgroundImage && ret.newColor;
3602
- extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
3861
+ if (colorReg.test(value)) {
3862
+ if (isGradient) {
3863
+ // 把原渐变色取出来
3864
+ var matches = colorRegGlobal.exec(value);
3603
3865
 
3604
- if (isBgColor || textColorIdx > 0) {
3605
- // 不处理-webkit-text-stroke-color
3606
- var attrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"];
3607
- var originalAttrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"];
3608
- var retColorStr = retColor ? retColor.toString() : match;
3609
- replaceIndex === 0 && Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
3610
- var originalAttrValue = dom.getAttribute(originalAttrName) || _this._config.defaultLightBgColor;
3866
+ while (matches) {
3867
+ gradientColors.push(matches[0]);
3868
+ matches = colorRegGlobal.exec(value);
3869
+ } // 计算出一个mix颜色
3611
3870
 
3612
- dom.setAttribute(attrName, retColorStr);
3613
- dom.setAttribute(originalAttrName, originalAttrValue.split(BG_COLOR_DELIMITER).concat(match).join(BG_COLOR_DELIMITER)); // 如果设置背景颜色,取消背景图片的影响
3614
3871
 
3615
- if (isBgColor && color__WEBPACK_IMPORTED_MODULE_0___default()(retColorStr).alpha() >= 0.05 && dom.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"])) {
3616
- dom.removeAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]);
3617
- }
3618
- });
3872
+ gradientMixColor = mixColor(gradientColors);
3619
3873
  }
3620
3874
 
3621
- retColor && (cssChange = true);
3622
- replaceIndex += 1;
3623
- return retColor || match;
3624
- }).replace(/\s?!\s?important/ig, '');
3625
- }
3626
-
3627
- if (extStyle) {
3628
- cssKV += extStyle;
3629
- }
3875
+ var replaceIndex = 0;
3876
+ value = value.replace(colorRegGlobal, function (match) {
3877
+ // 渐变色统一改成mix纯色
3878
+ if (isGradient) {
3879
+ match = gradientMixColor;
3880
+ cssChange = true;
3881
+ } // 使用颜色处理算法
3882
+
3883
+
3884
+ var ret = _this._adjustBrightness(color__WEBPACK_IMPORTED_MODULE_0___default()(match), el, {
3885
+ isBgColor: isBgColor,
3886
+ isTextShadow: isTextShadow,
3887
+ isTextColor: textColorIdx > -1,
3888
+ isBorderColor: isBorderColor,
3889
+ hasInlineColor: hasInlineColor
3890
+ });
3630
3891
 
3631
- if (!(el instanceof SVGElement)) {
3632
- // 先不处理SVG
3633
- // 背景图片、边框图片
3634
- var isBackgroundAttr = /^background/.test(key);
3635
- var isBorderImageAttr = /^(-webkit-)?border-image/.test(key);
3636
-
3637
- if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
3638
- cssChange = true;
3639
- var imgBgColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]) || _this._config.defaultLightBgColor).split(BG_COLOR_DELIMITER)); // 在背景图片下加一层原背景颜色:
3640
- // background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering);
3641
- // border-image不支持多层背景,需要添加background-color
3642
-
3643
- value = value.replace(/^(.*?)url\(([^)]*)\)(.*)$/i, function (matches) {
3644
- var newValue = matches;
3645
- var newBackgroundPositionValue = '';
3646
- var newBackgroundSizeValue = '';
3647
- var tmpCssKvStr = '';
3648
-
3649
- if (el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]) !== '1') {
3650
- // 避免重复setAttribute
3651
- Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
3652
- return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"], '1');
3892
+ var retColor = !hasInlineBackgroundImage && ret.newColor;
3893
+ extStyle += ret.extStyle; // 对背景颜色和文字颜色做继承传递,用于文字亮度计算
3894
+
3895
+ if (isBgColor || textColorIdx > 0) {
3896
+ // 不处理-webkit-text-stroke-color
3897
+ var attrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"];
3898
+ var originalAttrName = isBgColor ? _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"] : _constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"];
3899
+ var retColorStr = retColor ? retColor.toString() : match;
3900
+ replaceIndex === 0 && Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
3901
+ var originalAttrValue = dom.getAttribute(originalAttrName) || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightBgColor;
3902
+ dom.setAttribute(attrName, retColorStr);
3903
+ dom.setAttribute(originalAttrName, originalAttrValue.split(BG_COLOR_DELIMITER).concat(match).join(BG_COLOR_DELIMITER)); // 如果设置背景颜色,取消背景图片的影响
3904
+
3905
+ if (isBgColor && color__WEBPACK_IMPORTED_MODULE_0___default()(retColorStr).alpha() >= 0.05 && dom.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"])) {
3906
+ dom.removeAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]);
3907
+ }
3653
3908
  });
3654
- } // background-image
3909
+ }
3655
3910
 
3911
+ retColor && (cssChange = true);
3912
+ replaceIndex += 1;
3913
+ return retColor || match;
3914
+ }).replace(/\s?!\s?important/ig, '');
3915
+ }
3656
3916
 
3657
- if (isBackgroundAttr) {
3658
- newValue = "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),").concat(matches);
3659
- tmpCssKvStr = _this._cssUtils.genCssKV(key, "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"));
3917
+ extStyle && (cssKV += extStyle);
3660
3918
 
3661
- if (elBackgroundPositionAttr) {
3662
- newBackgroundPositionValue = "top left,".concat(elBackgroundPositionAttr);
3663
- cssKV += _this._cssUtils.genCssKV('background-position', "".concat(newBackgroundPositionValue));
3664
- tmpCssKvStr += _this._cssUtils.genCssKV('background-position', "".concat(newBackgroundPositionValue, ",top left"));
3665
- }
3919
+ if (!(el instanceof SVGElement)) {
3920
+ // 先不处理SVG
3921
+ // 背景图片、边框图片
3922
+ var isBackgroundAttr = /^background/.test(key);
3923
+ var isBorderImageAttr = /^(-webkit-)?border-image/.test(key);
3666
3924
 
3667
- if (elBackgroundSizeAttr) {
3668
- newBackgroundSizeValue = "100%,".concat(elBackgroundSizeAttr);
3669
- cssKV += _this._cssUtils.genCssKV('background-size', "".concat(newBackgroundSizeValue));
3670
- tmpCssKvStr += _this._cssUtils.genCssKV('background-size', "".concat(newBackgroundSizeValue, ",100%"));
3925
+ if ((isBackgroundAttr || isBorderImageAttr) && /url\([^)]*\)/i.test(value)) {
3926
+ cssChange = true;
3927
+ var imgBgColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_BGCOLORATTR"]) || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightBgColor).split(BG_COLOR_DELIMITER)); // 在背景图片下加一层原背景颜色:
3928
+ // background-image使用多层背景(注意background-position也要多加一层 https://www.w3.org/TR/css-backgrounds-3/#layering)
3929
+ // border-image不支持多层背景,需要添加background-color
3930
+
3931
+ value = value.replace(/^(.*?)url\(([^)]*)\)(.*)$/i, function (matches) {
3932
+ var newValue = matches;
3933
+ var newBackgroundPositionValue = '';
3934
+ var newBackgroundSizeValue = '';
3935
+ var tmpCssKvStr = '';
3936
+
3937
+ if (el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"]) !== '1') {
3938
+ // 避免重复setAttribute
3939
+ Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
3940
+ return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["BGIMAGEATTR"], '1');
3941
+ });
3942
+ } // background-image
3943
+
3944
+
3945
+ if (isBackgroundAttr) {
3946
+ newValue = "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),").concat(matches);
3947
+ tmpCssKvStr = _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, "".concat(newValue, ",linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"));
3948
+
3949
+ if (elBackgroundPositionAttr) {
3950
+ newBackgroundPositionValue = "top left,".concat(elBackgroundPositionAttr);
3951
+ cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-position', "".concat(newBackgroundPositionValue));
3952
+ tmpCssKvStr += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-position', "".concat(newBackgroundPositionValue, ",top left"));
3953
+ }
3954
+
3955
+ if (elBackgroundSizeAttr) {
3956
+ newBackgroundSizeValue = "100%,".concat(elBackgroundSizeAttr);
3957
+ cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-size', "".concat(newBackgroundSizeValue));
3958
+ tmpCssKvStr += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-size', "".concat(newBackgroundSizeValue, ",100%"));
3959
+ }
3960
+
3961
+ _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, tmpCssKvStr); // 背景图入栈
3962
+ } else {
3963
+ // border-image元素,如果当前元素没有背景颜色,补背景颜色
3964
+ !hasInlineBackground && _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('background-image', "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"))); // 背景图入栈
3671
3965
  }
3672
3966
 
3673
- _this._bgStack.push(el, tmpCssKvStr); // 背景图入栈
3967
+ return newValue;
3968
+ }); // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
3674
3969
 
3675
- } else {
3676
- // border-image元素,如果当前元素没有背景颜色,补背景颜色
3677
- !hasInlineBackground && _this._bgStack.push(el, _this._cssUtils.genCssKV('background-image', "linear-gradient(".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], ", ").concat(_constant__WEBPACK_IMPORTED_MODULE_2__["GRAY_MASK_COLOR"], "),linear-gradient(").concat(imgBgColor, ", ").concat(imgBgColor, ")"))); // 背景图入栈
3970
+ if (!hasInlineColor) {
3971
+ var textColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]) || _config__WEBPACK_IMPORTED_MODULE_3__["default"].defaultLightTextColor).split(BG_COLOR_DELIMITER));
3972
+ cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV('color', textColor);
3973
+ Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["getChildrenAndIt"])(el).forEach(function (dom) {
3974
+ return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"], textColor);
3975
+ });
3678
3976
  }
3679
-
3680
- return newValue;
3681
- }); // 没有设置自定义字体颜色,则使用非 Dark Mode 下默认字体颜色
3682
-
3683
- if (!hasInlineColor) {
3684
- var textColor = mixColor((el.getAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["ORIGINAL_COLORATTR"]) || _this._config.defaultLightTextColor).split(BG_COLOR_DELIMITER));
3685
- cssKV += _this._cssUtils.genCssKV('color', textColor);
3686
- Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["getChildrenAndIt"])(el).forEach(function (dom) {
3687
- return dom.setAttribute(_constant__WEBPACK_IMPORTED_MODULE_2__["COLORATTR"], textColor);
3688
- });
3689
3977
  }
3690
3978
  }
3691
- }
3692
-
3693
- if (cssChange) {
3694
- _constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] = removeImportant(oldValue)); // 清除inline style的!important
3695
3979
 
3696
- if (isGradient) {
3697
- _this._bgStack.push(el, _this._cssUtils.genCssKV(key, value)); // 渐变入栈
3980
+ if (cssChange) {
3981
+ _constant__WEBPACK_IMPORTED_MODULE_2__["IMPORTANT_REGEXP"].test(oldValue) && (styles[key] = removeImportant(oldValue)); // 清除inline style的!important
3698
3982
 
3699
- } else {
3700
- cssKV += _this._cssUtils.genCssKV(key, value);
3983
+ if (isGradient) {
3984
+ _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].push(el, _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value)); // 渐变入栈
3985
+ } else {
3986
+ cssKV += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCssKV(key, value);
3987
+ }
3701
3988
  }
3702
- }
3989
+ });
3703
3990
  });
3704
- });
3705
-
3706
- if (cssKV) {
3707
- // 有处理过或者是背景图片就加class以及css
3708
- el.setAttribute('data-style', styles.cssText); // 备份内联样式到data-style里,供编辑器做反处理
3709
3991
 
3710
- var className = "".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["CLASS_PREFIX"]).concat(this._idx++);
3711
- el.classList.add(className);
3712
- css += cssKV ? this._cssUtils.genCss(className, cssKV) : '';
3713
- }
3992
+ if (cssKV) {
3993
+ // 有处理过或者是背景图片就加class以及css
3994
+ el.setAttribute('data-style', styles.cssText); // 备份内联样式到data-style里,供编辑器做反处理
3714
3995
 
3715
- if (Object(_domUtils__WEBPACK_IMPORTED_MODULE_3__["hasTextNode"])(el)) {
3716
- // 如果节点里有文本,要判断是否在背景图里
3717
- if (this._config.delayBgJudge) {
3718
- // 延迟背景判断
3719
- this._tnQueue.push(el); // 文字入队
3996
+ var className = "".concat(_constant__WEBPACK_IMPORTED_MODULE_2__["CLASS_PREFIX"]).concat(this._idx++);
3997
+ el.classList.add(className);
3998
+ css += cssKV ? _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(className, cssKV) : '';
3999
+ }
3720
4000
 
3721
- } else {
3722
- this._bgStack.contains(el, function (item) {
3723
- css += _this._cssUtils.genCss(item.className, item.cssKV);
3724
- });
4001
+ if (Object(_domUtils__WEBPACK_IMPORTED_MODULE_5__["hasTextNode"])(el)) {
4002
+ // 如果节点里有文本,要判断是否在背景图里
4003
+ if (_config__WEBPACK_IMPORTED_MODULE_3__["default"].delayBgJudge) {
4004
+ // 延迟背景判断
4005
+ _global__WEBPACK_IMPORTED_MODULE_4__["tnQueue"].push(el); // 文字入队
4006
+ } else {
4007
+ _global__WEBPACK_IMPORTED_MODULE_4__["bgStack"].contains(el, function (item) {
4008
+ css += _global__WEBPACK_IMPORTED_MODULE_4__["cssUtils"].genCss(item.className, item.cssKV);
4009
+ });
4010
+ }
3725
4011
  }
3726
4012
  }
3727
4013
 
4014
+ _global__WEBPACK_IMPORTED_MODULE_4__["plugins"].emit('afterConvertNode', el);
3728
4015
  return css;
3729
4016
  }
3730
4017
  }]);
@@ -3747,13 +4034,14 @@ var SDK = /*#__PURE__*/function () {
3747
4034
  "use strict";
3748
4035
  __webpack_require__.r(__webpack_exports__);
3749
4036
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TextNodeQueue; });
3750
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4037
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config */ "./src/modules/config.js");
4038
+ 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); }
3751
4039
 
3752
4040
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3753
4041
 
3754
4042
  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); } }
3755
4043
 
3756
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
4044
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3757
4045
 
3758
4046
  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; }
3759
4047
 
@@ -3763,30 +4051,31 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
3763
4051
  * @class TextNodeQueue
3764
4052
  *
3765
4053
  * @constructor
3766
- * @param {Object} config Darkmode配置
3767
4054
  * @param {string} prefix 类名前缀
3768
4055
  *
3769
4056
  * @method push 文本节点入队
3770
4057
  * @param {Dom Object} el 文本节点对象
3771
4058
  *
3772
4059
  * @method forEach 遍历,遍历过的文本节点出队
3773
- * @param {function} callback 回调
4060
+ * @param {Function} callback 回调
3774
4061
  *
3775
4062
  * @method update 更新队列的节点对象,主要解决前后节点不一致的问题
3776
4063
  * @param {Dom Object Array} nodes 要更新的节点对象列表
3777
4064
  *
3778
4065
  */
4066
+ // Darkmode配置
4067
+
4068
+
3779
4069
  var TextNodeQueue = /*#__PURE__*/function () {
3780
4070
  // 文本节点队列,{ el, className, updated }
3781
4071
  // 索引值
3782
- function TextNodeQueue(config, prefix) {
4072
+ function TextNodeQueue(prefix) {
3783
4073
  _classCallCheck(this, TextNodeQueue);
3784
4074
 
3785
4075
  _defineProperty(this, "_queue", []);
3786
4076
 
3787
4077
  _defineProperty(this, "_idx", 0);
3788
4078
 
3789
- this._config = config;
3790
4079
  this._prefix = prefix;
3791
4080
  }
3792
4081
 
@@ -3799,7 +4088,7 @@ var TextNodeQueue = /*#__PURE__*/function () {
3799
4088
  this._queue.push({
3800
4089
  el: el,
3801
4090
  className: className,
3802
- updated: !this._config.delayBgJudge
4091
+ updated: !_config__WEBPACK_IMPORTED_MODULE_0__["default"].delayBgJudge
3803
4092
  });
3804
4093
  }
3805
4094
  }, {