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