@cdfrd/publish-notification-plugin 0.1.1 → 0.1.3
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/index.cjs +348 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +348 -91
- package/dist/index.js.map +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,12 +12,13 @@ var MAX_DISMISSED_VERSIONS = 3;
|
|
|
12
12
|
var STANDALONE_APP_ID = "__standalone__";
|
|
13
13
|
var DEFAULT_PRIMARY_COLOR = "#1677ff";
|
|
14
14
|
var THEME_RETRY_MAX = 3;
|
|
15
|
-
var THEME_WATCH_DEBOUNCE_MS =
|
|
15
|
+
var THEME_WATCH_DEBOUNCE_MS = 32;
|
|
16
|
+
var THEME_BTN_BG_SETTLE_MS = 180;
|
|
16
17
|
var PLACEMENT_STYLES = {
|
|
17
|
-
topLeft: "top:
|
|
18
|
-
topRight: "top:
|
|
19
|
-
bottomLeft: "bottom:
|
|
20
|
-
bottomRight: "bottom:
|
|
18
|
+
topLeft: "top:24px;left:24px",
|
|
19
|
+
topRight: "top:24px;right:24px",
|
|
20
|
+
bottomLeft: "bottom:24px;left:24px",
|
|
21
|
+
bottomRight: "bottom:24px;right:24px"
|
|
21
22
|
};
|
|
22
23
|
var DEFAULT_CHECK_INTERVAL = 10 * 60 * 1e3;
|
|
23
24
|
|
|
@@ -346,18 +347,18 @@ function ensureNotificationAnchor() {
|
|
|
346
347
|
var PRESET_LOCALE = {
|
|
347
348
|
zh_CN: {
|
|
348
349
|
title: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
349
|
-
description: "\
|
|
350
|
+
description: "\u7CFB\u7EDF\u5DF2\u53D1\u5E03\u65B0\u7248\u672C\uFF0C\u5237\u65B0\u9875\u9762\u540E\u751F\u6548\u3002",
|
|
350
351
|
forcedTitle: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
351
|
-
forcedDescription: "\
|
|
352
|
-
buttonText: "\u5237\u65B0",
|
|
352
|
+
forcedDescription: "\u7CFB\u7EDF\u5DF2\u53D1\u5E03\u65B0\u7248\u672C\uFF0C\u5237\u65B0\u9875\u9762\u540E\u751F\u6548\u3002",
|
|
353
|
+
buttonText: "\u7ACB\u5373\u5237\u65B0",
|
|
353
354
|
dismissButtonText: "\u7A0D\u540E"
|
|
354
355
|
},
|
|
355
356
|
en_US: {
|
|
356
|
-
title: "
|
|
357
|
-
description: "
|
|
358
|
-
forcedTitle: "
|
|
359
|
-
forcedDescription: "
|
|
360
|
-
buttonText: "Refresh",
|
|
357
|
+
title: "New version available",
|
|
358
|
+
description: "Refresh the page for it to take effect.",
|
|
359
|
+
forcedTitle: "New version available",
|
|
360
|
+
forcedDescription: "Refresh the page for it to take effect.",
|
|
361
|
+
buttonText: "Refresh now",
|
|
361
362
|
dismissButtonText: "Later"
|
|
362
363
|
}
|
|
363
364
|
};
|
|
@@ -380,9 +381,9 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
380
381
|
--update-bg: #ffffff;
|
|
381
382
|
--update-text: rgba(0, 0, 0, 0.88);
|
|
382
383
|
--update-text-secondary: rgba(0, 0, 0, 0.65);
|
|
383
|
-
--update-
|
|
384
|
-
--update-
|
|
385
|
-
--update-btn-hover-bg: rgba(0, 0, 0, 0.
|
|
384
|
+
--update-icon-color: rgba(0, 0, 0, 0.45);
|
|
385
|
+
--update-icon-hover: rgba(0, 0, 0, 0.88);
|
|
386
|
+
--update-btn-hover-bg: rgba(0, 0, 0, 0.06);
|
|
386
387
|
--update-primary: #1677ff;
|
|
387
388
|
--update-primary-hover: #4096ff;
|
|
388
389
|
--update-mask: rgba(0, 0, 0, 0.45);
|
|
@@ -394,8 +395,8 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
394
395
|
--update-bg: #1f1f1f;
|
|
395
396
|
--update-text: rgba(255, 255, 255, 0.85);
|
|
396
397
|
--update-text-secondary: rgba(255, 255, 255, 0.65);
|
|
397
|
-
--update-
|
|
398
|
-
--update-
|
|
398
|
+
--update-icon-color: rgba(255, 255, 255, 0.45);
|
|
399
|
+
--update-icon-hover: rgba(255, 255, 255, 0.85);
|
|
399
400
|
--update-btn-hover-bg: rgba(255, 255, 255, 0.08);
|
|
400
401
|
--update-primary: #1668dc;
|
|
401
402
|
--update-primary-hover: #3c89e8;
|
|
@@ -416,7 +417,7 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
.cdfrd-update-notice:not(.cdfrd-update-notice--forced) {
|
|
419
|
-
width:
|
|
420
|
+
width: 316px;
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
.cdfrd-update-notice-panel {
|
|
@@ -428,91 +429,113 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
428
429
|
border-radius: 8px;
|
|
429
430
|
background: var(--update-bg);
|
|
430
431
|
color: var(--update-text);
|
|
431
|
-
border: 1px solid var(--update-border);
|
|
432
432
|
box-shadow: var(--update-shadow);
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
.cdfrd-update-notice-header {
|
|
436
|
-
display: flex;
|
|
437
|
-
align-items: flex-start;
|
|
438
|
-
gap: 8px;
|
|
439
|
-
margin-bottom: 4px;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
435
|
.cdfrd-update-notice-title {
|
|
443
|
-
|
|
444
|
-
|
|
436
|
+
margin: 0;
|
|
437
|
+
padding-right: 28px;
|
|
445
438
|
font-size: 16px;
|
|
446
439
|
font-weight: 600;
|
|
447
440
|
line-height: 1.5;
|
|
448
441
|
color: var(--update-text);
|
|
442
|
+
overflow: hidden;
|
|
443
|
+
white-space: nowrap;
|
|
444
|
+
text-overflow: ellipsis;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
.cdfrd-update-notice-desc {
|
|
448
|
+
margin: 4px 0 0;
|
|
449
|
+
padding-right: 28px;
|
|
450
|
+
font-size: 14px;
|
|
451
|
+
line-height: 1.5714;
|
|
452
|
+
color: var(--update-text-secondary);
|
|
453
|
+
display: -webkit-box;
|
|
454
|
+
-webkit-box-orient: vertical;
|
|
455
|
+
-webkit-line-clamp: 3;
|
|
456
|
+
overflow: hidden;
|
|
457
|
+
text-overflow: ellipsis;
|
|
449
458
|
}
|
|
450
459
|
|
|
460
|
+
/* Close \u2014 slightly larger than default antd notice close */
|
|
451
461
|
.cdfrd-update-notice-close {
|
|
452
|
-
|
|
462
|
+
position: absolute;
|
|
463
|
+
top: 14px;
|
|
464
|
+
right: 16px;
|
|
465
|
+
z-index: 1;
|
|
453
466
|
cursor: pointer;
|
|
454
|
-
width:
|
|
455
|
-
height:
|
|
467
|
+
width: 28px;
|
|
468
|
+
height: 28px;
|
|
456
469
|
padding: 0;
|
|
457
470
|
border: none;
|
|
458
471
|
border-radius: 4px;
|
|
459
472
|
background: transparent;
|
|
460
|
-
color: var(--update-
|
|
461
|
-
font-size:
|
|
462
|
-
line-height:
|
|
473
|
+
color: var(--update-icon-color);
|
|
474
|
+
font-size: 20px;
|
|
475
|
+
line-height: 28px;
|
|
476
|
+
text-align: center;
|
|
463
477
|
}
|
|
464
478
|
|
|
465
479
|
.cdfrd-update-notice-close:hover {
|
|
466
|
-
color: var(--update-
|
|
480
|
+
color: var(--update-icon-hover);
|
|
467
481
|
background: var(--update-btn-hover-bg);
|
|
468
482
|
}
|
|
469
483
|
|
|
470
|
-
|
|
471
|
-
font-size: 14px;
|
|
472
|
-
line-height: 1.5714;
|
|
473
|
-
color: var(--update-text-secondary);
|
|
474
|
-
margin: 0 0 12px;
|
|
475
|
-
}
|
|
476
|
-
|
|
484
|
+
/* Actions \u2014 float right, margin-top (antd Semantic DOM: actions) */
|
|
477
485
|
.cdfrd-update-notice-actions {
|
|
478
486
|
display: flex;
|
|
479
487
|
align-items: center;
|
|
480
488
|
justify-content: flex-end;
|
|
489
|
+
flex-wrap: wrap;
|
|
481
490
|
gap: 8px;
|
|
491
|
+
margin-top: 12px;
|
|
482
492
|
}
|
|
483
493
|
|
|
484
494
|
.cdfrd-update-notice-btn {
|
|
485
495
|
cursor: pointer;
|
|
486
496
|
font-size: 14px;
|
|
487
497
|
line-height: 1.5714;
|
|
488
|
-
height:
|
|
489
|
-
padding:
|
|
490
|
-
border:
|
|
491
|
-
border-radius:
|
|
492
|
-
background:
|
|
493
|
-
color: var(--update-text);
|
|
498
|
+
height: 24px;
|
|
499
|
+
padding: 0 7px;
|
|
500
|
+
border: none;
|
|
501
|
+
border-radius: 4px;
|
|
502
|
+
background: transparent;
|
|
494
503
|
box-sizing: border-box;
|
|
504
|
+
max-width: 120px;
|
|
505
|
+
overflow: hidden;
|
|
506
|
+
white-space: nowrap;
|
|
507
|
+
text-overflow: ellipsis;
|
|
495
508
|
transition: all 0.2s;
|
|
496
509
|
}
|
|
497
510
|
|
|
498
|
-
|
|
511
|
+
/* Text / link button \u2014 weakened secondary action (antd Button type="link" size="small") */
|
|
512
|
+
.cdfrd-update-notice-btn-link {
|
|
513
|
+
height: auto;
|
|
514
|
+
padding: 0 4px;
|
|
499
515
|
color: var(--update-primary);
|
|
500
|
-
|
|
516
|
+
background: transparent;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.cdfrd-update-notice-btn-link:hover {
|
|
520
|
+
color: var(--update-primary-hover);
|
|
521
|
+
background: transparent;
|
|
501
522
|
}
|
|
502
523
|
|
|
503
524
|
.cdfrd-update-notice-btn-primary {
|
|
525
|
+
height: 24px;
|
|
526
|
+
padding: 0 7px;
|
|
504
527
|
background: var(--update-primary);
|
|
505
|
-
border-color: var(--update-primary);
|
|
506
528
|
color: #fff;
|
|
529
|
+
font-size: 14px;
|
|
530
|
+
border-radius: 4px;
|
|
507
531
|
}
|
|
508
532
|
|
|
509
533
|
.cdfrd-update-notice-btn-primary:hover {
|
|
510
534
|
background: var(--update-primary-hover);
|
|
511
|
-
border-color: var(--update-primary-hover);
|
|
512
535
|
color: #fff;
|
|
513
536
|
}
|
|
514
537
|
|
|
515
|
-
/* Forced
|
|
538
|
+
/* Forced update \u2014 centered card, still notification-like */
|
|
516
539
|
.cdfrd-update-notice--forced {
|
|
517
540
|
inset: 0;
|
|
518
541
|
max-width: none;
|
|
@@ -527,23 +550,27 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
527
550
|
}
|
|
528
551
|
|
|
529
552
|
.cdfrd-update-notice--forced .cdfrd-update-notice-panel {
|
|
530
|
-
width:
|
|
553
|
+
width: max-content;
|
|
554
|
+
max-width: min(336px, calc(100vw - 48px));
|
|
531
555
|
padding: 20px 24px;
|
|
532
|
-
border: none;
|
|
533
|
-
text-align: left;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
.cdfrd-update-notice--forced .cdfrd-update-notice-title {
|
|
537
|
-
margin-bottom: 8px;
|
|
538
556
|
}
|
|
539
557
|
|
|
558
|
+
.cdfrd-update-notice--forced .cdfrd-update-notice-title,
|
|
540
559
|
.cdfrd-update-notice--forced .cdfrd-update-notice-desc {
|
|
541
|
-
|
|
560
|
+
padding-right: 0;
|
|
542
561
|
}
|
|
543
562
|
|
|
544
563
|
.cdfrd-update-notice--forced .cdfrd-update-notice-actions {
|
|
545
|
-
margin-top:
|
|
546
|
-
justify-content:
|
|
564
|
+
margin-top: 16px;
|
|
565
|
+
justify-content: center;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.cdfrd-update-notice--forced .cdfrd-update-notice-btn-primary {
|
|
569
|
+
width: auto;
|
|
570
|
+
height: 24px;
|
|
571
|
+
padding: 0 7px;
|
|
572
|
+
border-radius: 4px;
|
|
573
|
+
font-size: 14px;
|
|
547
574
|
}
|
|
548
575
|
`.trim();
|
|
549
576
|
|
|
@@ -564,6 +591,26 @@ var ANT_PRIMARY_VARS = [
|
|
|
564
591
|
"--ant-primary-color",
|
|
565
592
|
"--colorPrimary"
|
|
566
593
|
];
|
|
594
|
+
var ANT_BG_VARS = [
|
|
595
|
+
"--ant-color-bg-elevated",
|
|
596
|
+
"--ant-color-bg-container",
|
|
597
|
+
"--ant-color-bg-base",
|
|
598
|
+
"--ant-bg-color"
|
|
599
|
+
];
|
|
600
|
+
var SURFACE_SELECTORS = [
|
|
601
|
+
".ant-modal-content",
|
|
602
|
+
".ant-notification-notice",
|
|
603
|
+
".ant-popover-inner",
|
|
604
|
+
".ant-card",
|
|
605
|
+
".ant-input",
|
|
606
|
+
".ant-btn-default"
|
|
607
|
+
];
|
|
608
|
+
var SURFACE_PROBE_CLASSES = [
|
|
609
|
+
"ant-modal-content",
|
|
610
|
+
"ant-btn ant-btn-default",
|
|
611
|
+
"ant-input"
|
|
612
|
+
];
|
|
613
|
+
var DARK_LUMINANCE_THRESHOLD = 0.45;
|
|
567
614
|
function isInvalidColor(color) {
|
|
568
615
|
if (!color) return true;
|
|
569
616
|
const c = color.trim().toLowerCase();
|
|
@@ -696,6 +743,138 @@ function resolvePrimaryColorLazy(config, theme, onDone, maxAttempts = THEME_RETR
|
|
|
696
743
|
};
|
|
697
744
|
run();
|
|
698
745
|
}
|
|
746
|
+
function parseRgbChannels(color) {
|
|
747
|
+
const trimmed = color.trim();
|
|
748
|
+
const rgb = trimmed.match(
|
|
749
|
+
/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*[\d.]+)?\s*\)$/i
|
|
750
|
+
);
|
|
751
|
+
if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])];
|
|
752
|
+
const hex = trimmed.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
753
|
+
if (!hex) return null;
|
|
754
|
+
const h = hex[1];
|
|
755
|
+
if (h.length === 3) {
|
|
756
|
+
return [
|
|
757
|
+
parseInt(h[0] + h[0], 16),
|
|
758
|
+
parseInt(h[1] + h[1], 16),
|
|
759
|
+
parseInt(h[2] + h[2], 16)
|
|
760
|
+
];
|
|
761
|
+
}
|
|
762
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
763
|
+
}
|
|
764
|
+
function relativeLuminance(r, g, b) {
|
|
765
|
+
const toLinear = (c) => {
|
|
766
|
+
const s = c / 255;
|
|
767
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
768
|
+
};
|
|
769
|
+
return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
770
|
+
}
|
|
771
|
+
function themeFromBackgroundColor(color) {
|
|
772
|
+
if (isInvalidColor(color)) return null;
|
|
773
|
+
const channels = parseRgbChannels(color);
|
|
774
|
+
if (!channels) return null;
|
|
775
|
+
return relativeLuminance(...channels) < DARK_LUMINANCE_THRESHOLD ? "dark" : "light";
|
|
776
|
+
}
|
|
777
|
+
function tryResolveDomThemeHint() {
|
|
778
|
+
if (typeof document === "undefined") return null;
|
|
779
|
+
const roots = [document.documentElement, document.body].filter(Boolean);
|
|
780
|
+
for (const el2 of roots) {
|
|
781
|
+
const dataTheme = el2.dataset.theme || el2.getAttribute("data-theme") || el2.dataset.demoTheme || el2.getAttribute("data-demo-theme");
|
|
782
|
+
if (dataTheme === "dark" || dataTheme === "light") return dataTheme;
|
|
783
|
+
}
|
|
784
|
+
for (const el2 of roots) {
|
|
785
|
+
if (el2.classList.contains("dark") || el2.classList.contains("ant-theme-dark")) return "dark";
|
|
786
|
+
if (el2.classList.contains("light") || el2.classList.contains("ant-theme-light")) return "light";
|
|
787
|
+
}
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
function readBgVarFromElement(el2) {
|
|
791
|
+
try {
|
|
792
|
+
const style = getComputedStyle(el2);
|
|
793
|
+
for (const name of ANT_BG_VARS) {
|
|
794
|
+
const value = style.getPropertyValue(name)?.trim();
|
|
795
|
+
if (!isInvalidColor(value)) return value;
|
|
796
|
+
}
|
|
797
|
+
} catch {
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
function readCssVariableBg() {
|
|
803
|
+
if (typeof document === "undefined") return null;
|
|
804
|
+
for (const root of [document.documentElement, document.body]) {
|
|
805
|
+
if (!root) continue;
|
|
806
|
+
const value = readBgVarFromElement(root);
|
|
807
|
+
if (value) return value;
|
|
808
|
+
}
|
|
809
|
+
const seeds = document.querySelectorAll(
|
|
810
|
+
'.ant-btn-primary, .ant-btn, .ant-modal-content, .ant-input, [class*="css-var"]'
|
|
811
|
+
);
|
|
812
|
+
for (const seed of seeds) {
|
|
813
|
+
let el2 = seed;
|
|
814
|
+
while (el2) {
|
|
815
|
+
const value = readBgVarFromElement(el2);
|
|
816
|
+
if (value) return value;
|
|
817
|
+
el2 = el2.parentElement;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return null;
|
|
821
|
+
}
|
|
822
|
+
function readExistingSurfaceBg() {
|
|
823
|
+
if (typeof document === "undefined") return null;
|
|
824
|
+
for (const selector of SURFACE_SELECTORS) {
|
|
825
|
+
const node = document.querySelector(selector);
|
|
826
|
+
if (!node) continue;
|
|
827
|
+
try {
|
|
828
|
+
const color = getComputedStyle(node).backgroundColor;
|
|
829
|
+
if (!isInvalidColor(color)) return color;
|
|
830
|
+
} catch {
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
function probeSurfaceBg() {
|
|
836
|
+
if (typeof document === "undefined" || !document.body) return null;
|
|
837
|
+
beginSuppressThemeWatch();
|
|
838
|
+
try {
|
|
839
|
+
const seed = document.querySelector(
|
|
840
|
+
".ant-btn-primary, .ant-btn, .ant-input, .ant-modal-content"
|
|
841
|
+
);
|
|
842
|
+
const hashClasses = seed ? Array.from(seed.classList).filter((c) => c.startsWith("css-") || c.includes("css-var")) : [];
|
|
843
|
+
const mountAt = seed?.closest('[class*="css-var"]') || seed?.parentElement || document.body;
|
|
844
|
+
for (const className of SURFACE_PROBE_CLASSES) {
|
|
845
|
+
const tag = className.includes("ant-btn") ? "button" : className.includes("ant-input") ? "input" : "div";
|
|
846
|
+
const node = document.createElement(tag);
|
|
847
|
+
node.className = [className, ...hashClasses].filter(Boolean).join(" ");
|
|
848
|
+
node.setAttribute("aria-hidden", "true");
|
|
849
|
+
node.style.cssText = "position:absolute;left:0;top:0;opacity:0;pointer-events:none;width:0;height:0;overflow:hidden;";
|
|
850
|
+
mountAt.appendChild(node);
|
|
851
|
+
const color = getComputedStyle(node).backgroundColor;
|
|
852
|
+
node.remove();
|
|
853
|
+
if (!isInvalidColor(color)) return color;
|
|
854
|
+
}
|
|
855
|
+
return null;
|
|
856
|
+
} catch {
|
|
857
|
+
return null;
|
|
858
|
+
} finally {
|
|
859
|
+
endSuppressThemeWatch();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function tryResolveAntdSurfaceBg(options) {
|
|
863
|
+
try {
|
|
864
|
+
const allowProbe = options?.allowProbe !== false;
|
|
865
|
+
const fromVar = readCssVariableBg();
|
|
866
|
+
if (fromVar) return fromVar;
|
|
867
|
+
const fromSurface = readExistingSurfaceBg();
|
|
868
|
+
if (fromSurface) return fromSurface;
|
|
869
|
+
if (allowProbe) return probeSurfaceBg();
|
|
870
|
+
return null;
|
|
871
|
+
} catch {
|
|
872
|
+
return null;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
function tryResolveAntdThemeMode(options) {
|
|
876
|
+
return tryResolveDomThemeHint() ?? themeFromBackgroundColor(tryResolveAntdSurfaceBg(options));
|
|
877
|
+
}
|
|
699
878
|
function isUpdateNoticeMutationTarget(node) {
|
|
700
879
|
if (!node || node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
701
880
|
const el2 = node;
|
|
@@ -715,7 +894,7 @@ function mutationsOnlyAffectNotice(mutations) {
|
|
|
715
894
|
return false;
|
|
716
895
|
});
|
|
717
896
|
}
|
|
718
|
-
function watchThemeChanges(config, getTheme, onChange) {
|
|
897
|
+
function watchThemeChanges(config, getTheme, onChange, onThemeMode) {
|
|
719
898
|
if (typeof document === "undefined") {
|
|
720
899
|
return () => void 0;
|
|
721
900
|
}
|
|
@@ -727,39 +906,70 @@ function watchThemeChanges(config, getTheme, onChange) {
|
|
|
727
906
|
return () => void 0;
|
|
728
907
|
}
|
|
729
908
|
let last = "";
|
|
909
|
+
let lastThemeMode = null;
|
|
730
910
|
let btnBgCandidate = "";
|
|
731
911
|
let debounceTimer;
|
|
732
912
|
let settleTimer;
|
|
913
|
+
let rafPending = false;
|
|
733
914
|
const clearTimers = () => {
|
|
734
915
|
if (debounceTimer !== void 0) clearTimeout(debounceTimer);
|
|
735
916
|
if (settleTimer !== void 0) clearTimeout(settleTimer);
|
|
736
917
|
debounceTimer = void 0;
|
|
737
918
|
settleTimer = void 0;
|
|
919
|
+
rafPending = false;
|
|
738
920
|
};
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
921
|
+
const applyThemeModeIfChanged = (mode) => {
|
|
922
|
+
if (!mode || mode === lastThemeMode) return;
|
|
923
|
+
lastThemeMode = mode;
|
|
924
|
+
if (mode !== getTheme()) {
|
|
925
|
+
onThemeMode?.(mode);
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
const applyPrimaryIfChanged = (found, opts) => {
|
|
742
929
|
const { color, source } = found;
|
|
743
930
|
if (color === last) {
|
|
744
931
|
btnBgCandidate = "";
|
|
745
|
-
return;
|
|
932
|
+
return false;
|
|
746
933
|
}
|
|
747
|
-
if (source === "btnBg" &&
|
|
748
|
-
btnBgCandidate
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
settleTimer =
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
934
|
+
if (source === "btnBg" && !opts?.allowUnsettledBtnBg) {
|
|
935
|
+
if (color !== btnBgCandidate) {
|
|
936
|
+
btnBgCandidate = color;
|
|
937
|
+
if (settleTimer !== void 0) clearTimeout(settleTimer);
|
|
938
|
+
settleTimer = setTimeout(() => {
|
|
939
|
+
settleTimer = void 0;
|
|
940
|
+
evaluate({ settlePass: true });
|
|
941
|
+
}, THEME_BTN_BG_SETTLE_MS);
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
755
944
|
}
|
|
756
945
|
last = color;
|
|
757
946
|
btnBgCandidate = "";
|
|
758
947
|
onChange(color);
|
|
948
|
+
return true;
|
|
949
|
+
};
|
|
950
|
+
const evaluate = (opts) => {
|
|
951
|
+
let mode = tryResolveAntdThemeMode({ allowProbe: false });
|
|
952
|
+
if (!mode) mode = tryResolveAntdThemeMode({ allowProbe: true });
|
|
953
|
+
applyThemeModeIfChanged(mode);
|
|
954
|
+
const found = tryResolveAntdPrimaryDetailed({ allowProbe: false });
|
|
955
|
+
if (!found) return;
|
|
956
|
+
applyPrimaryIfChanged(found, { allowUnsettledBtnBg: opts?.settlePass === true });
|
|
759
957
|
};
|
|
760
958
|
const schedule = (mutations) => {
|
|
761
959
|
if (suppressThemeWatch > 0) return;
|
|
762
960
|
if (mutations && mutationsOnlyAffectNotice(mutations)) return;
|
|
961
|
+
if (!rafPending) {
|
|
962
|
+
rafPending = true;
|
|
963
|
+
scheduleFrame(() => {
|
|
964
|
+
rafPending = false;
|
|
965
|
+
if (suppressThemeWatch > 0) return;
|
|
966
|
+
applyThemeModeIfChanged(tryResolveAntdThemeMode({ allowProbe: false }));
|
|
967
|
+
const found = tryResolveAntdPrimaryDetailed({ allowProbe: false });
|
|
968
|
+
if (found?.source === "cssVar") {
|
|
969
|
+
applyPrimaryIfChanged(found);
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
}
|
|
763
973
|
if (debounceTimer !== void 0) clearTimeout(debounceTimer);
|
|
764
974
|
debounceTimer = setTimeout(() => {
|
|
765
975
|
debounceTimer = void 0;
|
|
@@ -768,7 +978,13 @@ function watchThemeChanges(config, getTheme, onChange) {
|
|
|
768
978
|
}, THEME_WATCH_DEBOUNCE_MS);
|
|
769
979
|
};
|
|
770
980
|
const observer = new MutationObserver((mutations) => schedule(mutations));
|
|
771
|
-
const attrFilter = [
|
|
981
|
+
const attrFilter = [
|
|
982
|
+
"class",
|
|
983
|
+
"style",
|
|
984
|
+
"data-theme",
|
|
985
|
+
"data-demo-theme",
|
|
986
|
+
"data-update-notice-theme"
|
|
987
|
+
];
|
|
772
988
|
observer.observe(document.documentElement, {
|
|
773
989
|
attributes: true,
|
|
774
990
|
attributeFilter: attrFilter
|
|
@@ -825,6 +1041,18 @@ function applyPrimaryColor(primary) {
|
|
|
825
1041
|
endSuppressThemeWatch();
|
|
826
1042
|
}
|
|
827
1043
|
}
|
|
1044
|
+
function applySurfaceBackground(bg) {
|
|
1045
|
+
beginSuppressThemeWatch();
|
|
1046
|
+
try {
|
|
1047
|
+
document.querySelectorAll(".cdfrd-update-notice").forEach((node) => {
|
|
1048
|
+
const el2 = node;
|
|
1049
|
+
if (bg) el2.style.setProperty("--update-bg", bg);
|
|
1050
|
+
else el2.style.removeProperty("--update-bg");
|
|
1051
|
+
});
|
|
1052
|
+
} finally {
|
|
1053
|
+
endSuppressThemeWatch();
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
828
1056
|
function closeDefaultNotice() {
|
|
829
1057
|
document.querySelector(".cdfrd-update-notice")?.remove();
|
|
830
1058
|
visible = false;
|
|
@@ -876,18 +1104,12 @@ function showDefaultNotice(options) {
|
|
|
876
1104
|
actions.appendChild(refreshBtn);
|
|
877
1105
|
panel.appendChild(actions);
|
|
878
1106
|
} else {
|
|
879
|
-
|
|
880
|
-
header.appendChild(el("div", "cdfrd-update-notice-title", copy.title));
|
|
881
|
-
const closeBtn = el("button", `cdfrd-update-notice-close ${NOTIFICATION_CLOSE_BTN_CLASS}`, "\xD7");
|
|
882
|
-
closeBtn.setAttribute("type", "button");
|
|
883
|
-
closeBtn.setAttribute("aria-label", "close");
|
|
884
|
-
header.appendChild(closeBtn);
|
|
885
|
-
panel.appendChild(header);
|
|
1107
|
+
panel.appendChild(el("div", "cdfrd-update-notice-title", copy.title));
|
|
886
1108
|
panel.appendChild(el("div", "cdfrd-update-notice-desc", copy.description));
|
|
887
1109
|
const actions = el("div", "cdfrd-update-notice-actions");
|
|
888
1110
|
const dismissBtn = el(
|
|
889
1111
|
"button",
|
|
890
|
-
`cdfrd-update-notice-btn ${NOTIFICATION_DISMISS_BTN_CLASS}`,
|
|
1112
|
+
`cdfrd-update-notice-btn cdfrd-update-notice-btn-link ${NOTIFICATION_DISMISS_BTN_CLASS}`,
|
|
891
1113
|
copy.dismissButtonText
|
|
892
1114
|
);
|
|
893
1115
|
dismissBtn.setAttribute("type", "button");
|
|
@@ -900,6 +1122,10 @@ function showDefaultNotice(options) {
|
|
|
900
1122
|
refreshBtn.setAttribute("type", "button");
|
|
901
1123
|
actions.appendChild(refreshBtn);
|
|
902
1124
|
panel.appendChild(actions);
|
|
1125
|
+
const closeBtn = el("button", `cdfrd-update-notice-close ${NOTIFICATION_CLOSE_BTN_CLASS}`, "\xD7");
|
|
1126
|
+
closeBtn.setAttribute("type", "button");
|
|
1127
|
+
closeBtn.setAttribute("aria-label", "close");
|
|
1128
|
+
panel.appendChild(closeBtn);
|
|
903
1129
|
}
|
|
904
1130
|
wrap.appendChild(panel);
|
|
905
1131
|
let anchor = document.body.querySelector(`:scope > .cdfrd-update-notice-anchor`);
|
|
@@ -1012,6 +1238,24 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1012
1238
|
}
|
|
1013
1239
|
this.refreshPrimaryColor(gen);
|
|
1014
1240
|
}
|
|
1241
|
+
/** Sync light/dark panel tokens + surface bg from Antd when detectable. */
|
|
1242
|
+
syncAntdThemeMode(allowProbe = true) {
|
|
1243
|
+
const adapter = this.getActiveThemeAdapter();
|
|
1244
|
+
if ((adapter?.type ?? "antd") !== "antd") {
|
|
1245
|
+
applySurfaceBackground(null);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
const bg = tryResolveAntdSurfaceBg({ allowProbe });
|
|
1249
|
+
const bgMode = themeFromBackgroundColor(bg);
|
|
1250
|
+
const domMode = tryResolveDomThemeHint();
|
|
1251
|
+
const mode = domMode ?? bgMode;
|
|
1252
|
+
if (mode && mode !== this.theme) {
|
|
1253
|
+
this.theme = mode;
|
|
1254
|
+
applyTheme(mode);
|
|
1255
|
+
}
|
|
1256
|
+
const surfaceOk = Boolean(bg && bgMode && mode && bgMode === mode);
|
|
1257
|
+
applySurfaceBackground(surfaceOk ? bg : null);
|
|
1258
|
+
}
|
|
1015
1259
|
notifyUpdate(_runtime, _version) {
|
|
1016
1260
|
void _runtime;
|
|
1017
1261
|
void _version;
|
|
@@ -1020,6 +1264,7 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1020
1264
|
ensureNotificationAnchor();
|
|
1021
1265
|
const adapter = runtime.options.themeAdapter ?? this.themeAdapter;
|
|
1022
1266
|
const gen = this.primaryResolveGen;
|
|
1267
|
+
this.syncAntdThemeMode(true);
|
|
1023
1268
|
resolvePrimaryColorLazy(adapter, this.theme, (color) => {
|
|
1024
1269
|
if (gen !== this.primaryResolveGen) return;
|
|
1025
1270
|
this.primaryColor = color;
|
|
@@ -1045,6 +1290,7 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1045
1290
|
runtime.dismissVersion(version);
|
|
1046
1291
|
}
|
|
1047
1292
|
});
|
|
1293
|
+
this.syncAntdThemeMode(true);
|
|
1048
1294
|
});
|
|
1049
1295
|
return true;
|
|
1050
1296
|
}
|
|
@@ -1059,11 +1305,22 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1059
1305
|
startThemeWatch() {
|
|
1060
1306
|
this.stopWatchTheme?.();
|
|
1061
1307
|
const adapter = this.getActiveThemeAdapter();
|
|
1062
|
-
this.stopWatchTheme = watchThemeChanges(
|
|
1063
|
-
|
|
1064
|
-
this.
|
|
1065
|
-
|
|
1066
|
-
|
|
1308
|
+
this.stopWatchTheme = watchThemeChanges(
|
|
1309
|
+
adapter,
|
|
1310
|
+
() => this.theme,
|
|
1311
|
+
(color) => {
|
|
1312
|
+
this.primaryResolveGen += 1;
|
|
1313
|
+
this.primaryColor = color;
|
|
1314
|
+
applyPrimaryColor(color);
|
|
1315
|
+
this.syncAntdThemeMode(true);
|
|
1316
|
+
},
|
|
1317
|
+
(theme) => {
|
|
1318
|
+
if (theme === this.theme) return;
|
|
1319
|
+
this.theme = theme;
|
|
1320
|
+
applyTheme(theme);
|
|
1321
|
+
this.syncAntdThemeMode(true);
|
|
1322
|
+
}
|
|
1323
|
+
);
|
|
1067
1324
|
}
|
|
1068
1325
|
destroy() {
|
|
1069
1326
|
this.stopWatchTheme?.();
|