@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.cjs
CHANGED
|
@@ -44,12 +44,13 @@ var MAX_DISMISSED_VERSIONS = 3;
|
|
|
44
44
|
var STANDALONE_APP_ID = "__standalone__";
|
|
45
45
|
var DEFAULT_PRIMARY_COLOR = "#1677ff";
|
|
46
46
|
var THEME_RETRY_MAX = 3;
|
|
47
|
-
var THEME_WATCH_DEBOUNCE_MS =
|
|
47
|
+
var THEME_WATCH_DEBOUNCE_MS = 32;
|
|
48
|
+
var THEME_BTN_BG_SETTLE_MS = 180;
|
|
48
49
|
var PLACEMENT_STYLES = {
|
|
49
|
-
topLeft: "top:
|
|
50
|
-
topRight: "top:
|
|
51
|
-
bottomLeft: "bottom:
|
|
52
|
-
bottomRight: "bottom:
|
|
50
|
+
topLeft: "top:24px;left:24px",
|
|
51
|
+
topRight: "top:24px;right:24px",
|
|
52
|
+
bottomLeft: "bottom:24px;left:24px",
|
|
53
|
+
bottomRight: "bottom:24px;right:24px"
|
|
53
54
|
};
|
|
54
55
|
var DEFAULT_CHECK_INTERVAL = 10 * 60 * 1e3;
|
|
55
56
|
|
|
@@ -379,18 +380,18 @@ function ensureNotificationAnchor() {
|
|
|
379
380
|
var PRESET_LOCALE = {
|
|
380
381
|
zh_CN: {
|
|
381
382
|
title: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
382
|
-
description: "\
|
|
383
|
+
description: "\u7CFB\u7EDF\u5DF2\u53D1\u5E03\u65B0\u7248\u672C\uFF0C\u5237\u65B0\u9875\u9762\u540E\u751F\u6548\u3002",
|
|
383
384
|
forcedTitle: "\u53D1\u73B0\u65B0\u7248\u672C",
|
|
384
|
-
forcedDescription: "\
|
|
385
|
-
buttonText: "\u5237\u65B0",
|
|
385
|
+
forcedDescription: "\u7CFB\u7EDF\u5DF2\u53D1\u5E03\u65B0\u7248\u672C\uFF0C\u5237\u65B0\u9875\u9762\u540E\u751F\u6548\u3002",
|
|
386
|
+
buttonText: "\u7ACB\u5373\u5237\u65B0",
|
|
386
387
|
dismissButtonText: "\u7A0D\u540E"
|
|
387
388
|
},
|
|
388
389
|
en_US: {
|
|
389
|
-
title: "
|
|
390
|
-
description: "
|
|
391
|
-
forcedTitle: "
|
|
392
|
-
forcedDescription: "
|
|
393
|
-
buttonText: "Refresh",
|
|
390
|
+
title: "New version available",
|
|
391
|
+
description: "Refresh the page for it to take effect.",
|
|
392
|
+
forcedTitle: "New version available",
|
|
393
|
+
forcedDescription: "Refresh the page for it to take effect.",
|
|
394
|
+
buttonText: "Refresh now",
|
|
394
395
|
dismissButtonText: "Later"
|
|
395
396
|
}
|
|
396
397
|
};
|
|
@@ -413,9 +414,9 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
413
414
|
--update-bg: #ffffff;
|
|
414
415
|
--update-text: rgba(0, 0, 0, 0.88);
|
|
415
416
|
--update-text-secondary: rgba(0, 0, 0, 0.65);
|
|
416
|
-
--update-
|
|
417
|
-
--update-
|
|
418
|
-
--update-btn-hover-bg: rgba(0, 0, 0, 0.
|
|
417
|
+
--update-icon-color: rgba(0, 0, 0, 0.45);
|
|
418
|
+
--update-icon-hover: rgba(0, 0, 0, 0.88);
|
|
419
|
+
--update-btn-hover-bg: rgba(0, 0, 0, 0.06);
|
|
419
420
|
--update-primary: #1677ff;
|
|
420
421
|
--update-primary-hover: #4096ff;
|
|
421
422
|
--update-mask: rgba(0, 0, 0, 0.45);
|
|
@@ -427,8 +428,8 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
427
428
|
--update-bg: #1f1f1f;
|
|
428
429
|
--update-text: rgba(255, 255, 255, 0.85);
|
|
429
430
|
--update-text-secondary: rgba(255, 255, 255, 0.65);
|
|
430
|
-
--update-
|
|
431
|
-
--update-
|
|
431
|
+
--update-icon-color: rgba(255, 255, 255, 0.45);
|
|
432
|
+
--update-icon-hover: rgba(255, 255, 255, 0.85);
|
|
432
433
|
--update-btn-hover-bg: rgba(255, 255, 255, 0.08);
|
|
433
434
|
--update-primary: #1668dc;
|
|
434
435
|
--update-primary-hover: #3c89e8;
|
|
@@ -449,7 +450,7 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
449
450
|
}
|
|
450
451
|
|
|
451
452
|
.cdfrd-update-notice:not(.cdfrd-update-notice--forced) {
|
|
452
|
-
width:
|
|
453
|
+
width: 316px;
|
|
453
454
|
}
|
|
454
455
|
|
|
455
456
|
.cdfrd-update-notice-panel {
|
|
@@ -461,91 +462,113 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
461
462
|
border-radius: 8px;
|
|
462
463
|
background: var(--update-bg);
|
|
463
464
|
color: var(--update-text);
|
|
464
|
-
border: 1px solid var(--update-border);
|
|
465
465
|
box-shadow: var(--update-shadow);
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
.cdfrd-update-notice-header {
|
|
469
|
-
display: flex;
|
|
470
|
-
align-items: flex-start;
|
|
471
|
-
gap: 8px;
|
|
472
|
-
margin-bottom: 4px;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
468
|
.cdfrd-update-notice-title {
|
|
476
|
-
|
|
477
|
-
|
|
469
|
+
margin: 0;
|
|
470
|
+
padding-right: 28px;
|
|
478
471
|
font-size: 16px;
|
|
479
472
|
font-weight: 600;
|
|
480
473
|
line-height: 1.5;
|
|
481
474
|
color: var(--update-text);
|
|
475
|
+
overflow: hidden;
|
|
476
|
+
white-space: nowrap;
|
|
477
|
+
text-overflow: ellipsis;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.cdfrd-update-notice-desc {
|
|
481
|
+
margin: 4px 0 0;
|
|
482
|
+
padding-right: 28px;
|
|
483
|
+
font-size: 14px;
|
|
484
|
+
line-height: 1.5714;
|
|
485
|
+
color: var(--update-text-secondary);
|
|
486
|
+
display: -webkit-box;
|
|
487
|
+
-webkit-box-orient: vertical;
|
|
488
|
+
-webkit-line-clamp: 3;
|
|
489
|
+
overflow: hidden;
|
|
490
|
+
text-overflow: ellipsis;
|
|
482
491
|
}
|
|
483
492
|
|
|
493
|
+
/* Close \u2014 slightly larger than default antd notice close */
|
|
484
494
|
.cdfrd-update-notice-close {
|
|
485
|
-
|
|
495
|
+
position: absolute;
|
|
496
|
+
top: 14px;
|
|
497
|
+
right: 16px;
|
|
498
|
+
z-index: 1;
|
|
486
499
|
cursor: pointer;
|
|
487
|
-
width:
|
|
488
|
-
height:
|
|
500
|
+
width: 28px;
|
|
501
|
+
height: 28px;
|
|
489
502
|
padding: 0;
|
|
490
503
|
border: none;
|
|
491
504
|
border-radius: 4px;
|
|
492
505
|
background: transparent;
|
|
493
|
-
color: var(--update-
|
|
494
|
-
font-size:
|
|
495
|
-
line-height:
|
|
506
|
+
color: var(--update-icon-color);
|
|
507
|
+
font-size: 20px;
|
|
508
|
+
line-height: 28px;
|
|
509
|
+
text-align: center;
|
|
496
510
|
}
|
|
497
511
|
|
|
498
512
|
.cdfrd-update-notice-close:hover {
|
|
499
|
-
color: var(--update-
|
|
513
|
+
color: var(--update-icon-hover);
|
|
500
514
|
background: var(--update-btn-hover-bg);
|
|
501
515
|
}
|
|
502
516
|
|
|
503
|
-
|
|
504
|
-
font-size: 14px;
|
|
505
|
-
line-height: 1.5714;
|
|
506
|
-
color: var(--update-text-secondary);
|
|
507
|
-
margin: 0 0 12px;
|
|
508
|
-
}
|
|
509
|
-
|
|
517
|
+
/* Actions \u2014 float right, margin-top (antd Semantic DOM: actions) */
|
|
510
518
|
.cdfrd-update-notice-actions {
|
|
511
519
|
display: flex;
|
|
512
520
|
align-items: center;
|
|
513
521
|
justify-content: flex-end;
|
|
522
|
+
flex-wrap: wrap;
|
|
514
523
|
gap: 8px;
|
|
524
|
+
margin-top: 12px;
|
|
515
525
|
}
|
|
516
526
|
|
|
517
527
|
.cdfrd-update-notice-btn {
|
|
518
528
|
cursor: pointer;
|
|
519
529
|
font-size: 14px;
|
|
520
530
|
line-height: 1.5714;
|
|
521
|
-
height:
|
|
522
|
-
padding:
|
|
523
|
-
border:
|
|
524
|
-
border-radius:
|
|
525
|
-
background:
|
|
526
|
-
color: var(--update-text);
|
|
531
|
+
height: 24px;
|
|
532
|
+
padding: 0 7px;
|
|
533
|
+
border: none;
|
|
534
|
+
border-radius: 4px;
|
|
535
|
+
background: transparent;
|
|
527
536
|
box-sizing: border-box;
|
|
537
|
+
max-width: 120px;
|
|
538
|
+
overflow: hidden;
|
|
539
|
+
white-space: nowrap;
|
|
540
|
+
text-overflow: ellipsis;
|
|
528
541
|
transition: all 0.2s;
|
|
529
542
|
}
|
|
530
543
|
|
|
531
|
-
|
|
544
|
+
/* Text / link button \u2014 weakened secondary action (antd Button type="link" size="small") */
|
|
545
|
+
.cdfrd-update-notice-btn-link {
|
|
546
|
+
height: auto;
|
|
547
|
+
padding: 0 4px;
|
|
532
548
|
color: var(--update-primary);
|
|
533
|
-
|
|
549
|
+
background: transparent;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
.cdfrd-update-notice-btn-link:hover {
|
|
553
|
+
color: var(--update-primary-hover);
|
|
554
|
+
background: transparent;
|
|
534
555
|
}
|
|
535
556
|
|
|
536
557
|
.cdfrd-update-notice-btn-primary {
|
|
558
|
+
height: 24px;
|
|
559
|
+
padding: 0 7px;
|
|
537
560
|
background: var(--update-primary);
|
|
538
|
-
border-color: var(--update-primary);
|
|
539
561
|
color: #fff;
|
|
562
|
+
font-size: 14px;
|
|
563
|
+
border-radius: 4px;
|
|
540
564
|
}
|
|
541
565
|
|
|
542
566
|
.cdfrd-update-notice-btn-primary:hover {
|
|
543
567
|
background: var(--update-primary-hover);
|
|
544
|
-
border-color: var(--update-primary-hover);
|
|
545
568
|
color: #fff;
|
|
546
569
|
}
|
|
547
570
|
|
|
548
|
-
/* Forced
|
|
571
|
+
/* Forced update \u2014 centered card, still notification-like */
|
|
549
572
|
.cdfrd-update-notice--forced {
|
|
550
573
|
inset: 0;
|
|
551
574
|
max-width: none;
|
|
@@ -560,23 +583,27 @@ var DEFAULT_NOTICE_CSS = `
|
|
|
560
583
|
}
|
|
561
584
|
|
|
562
585
|
.cdfrd-update-notice--forced .cdfrd-update-notice-panel {
|
|
563
|
-
width:
|
|
586
|
+
width: max-content;
|
|
587
|
+
max-width: min(336px, calc(100vw - 48px));
|
|
564
588
|
padding: 20px 24px;
|
|
565
|
-
border: none;
|
|
566
|
-
text-align: left;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
.cdfrd-update-notice--forced .cdfrd-update-notice-title {
|
|
570
|
-
margin-bottom: 8px;
|
|
571
589
|
}
|
|
572
590
|
|
|
591
|
+
.cdfrd-update-notice--forced .cdfrd-update-notice-title,
|
|
573
592
|
.cdfrd-update-notice--forced .cdfrd-update-notice-desc {
|
|
574
|
-
|
|
593
|
+
padding-right: 0;
|
|
575
594
|
}
|
|
576
595
|
|
|
577
596
|
.cdfrd-update-notice--forced .cdfrd-update-notice-actions {
|
|
578
|
-
margin-top:
|
|
579
|
-
justify-content:
|
|
597
|
+
margin-top: 16px;
|
|
598
|
+
justify-content: center;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.cdfrd-update-notice--forced .cdfrd-update-notice-btn-primary {
|
|
602
|
+
width: auto;
|
|
603
|
+
height: 24px;
|
|
604
|
+
padding: 0 7px;
|
|
605
|
+
border-radius: 4px;
|
|
606
|
+
font-size: 14px;
|
|
580
607
|
}
|
|
581
608
|
`.trim();
|
|
582
609
|
|
|
@@ -597,6 +624,26 @@ var ANT_PRIMARY_VARS = [
|
|
|
597
624
|
"--ant-primary-color",
|
|
598
625
|
"--colorPrimary"
|
|
599
626
|
];
|
|
627
|
+
var ANT_BG_VARS = [
|
|
628
|
+
"--ant-color-bg-elevated",
|
|
629
|
+
"--ant-color-bg-container",
|
|
630
|
+
"--ant-color-bg-base",
|
|
631
|
+
"--ant-bg-color"
|
|
632
|
+
];
|
|
633
|
+
var SURFACE_SELECTORS = [
|
|
634
|
+
".ant-modal-content",
|
|
635
|
+
".ant-notification-notice",
|
|
636
|
+
".ant-popover-inner",
|
|
637
|
+
".ant-card",
|
|
638
|
+
".ant-input",
|
|
639
|
+
".ant-btn-default"
|
|
640
|
+
];
|
|
641
|
+
var SURFACE_PROBE_CLASSES = [
|
|
642
|
+
"ant-modal-content",
|
|
643
|
+
"ant-btn ant-btn-default",
|
|
644
|
+
"ant-input"
|
|
645
|
+
];
|
|
646
|
+
var DARK_LUMINANCE_THRESHOLD = 0.45;
|
|
600
647
|
function isInvalidColor(color) {
|
|
601
648
|
if (!color) return true;
|
|
602
649
|
const c = color.trim().toLowerCase();
|
|
@@ -729,6 +776,138 @@ function resolvePrimaryColorLazy(config, theme, onDone, maxAttempts = THEME_RETR
|
|
|
729
776
|
};
|
|
730
777
|
run();
|
|
731
778
|
}
|
|
779
|
+
function parseRgbChannels(color) {
|
|
780
|
+
const trimmed = color.trim();
|
|
781
|
+
const rgb = trimmed.match(
|
|
782
|
+
/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*[\d.]+)?\s*\)$/i
|
|
783
|
+
);
|
|
784
|
+
if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])];
|
|
785
|
+
const hex = trimmed.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
786
|
+
if (!hex) return null;
|
|
787
|
+
const h = hex[1];
|
|
788
|
+
if (h.length === 3) {
|
|
789
|
+
return [
|
|
790
|
+
parseInt(h[0] + h[0], 16),
|
|
791
|
+
parseInt(h[1] + h[1], 16),
|
|
792
|
+
parseInt(h[2] + h[2], 16)
|
|
793
|
+
];
|
|
794
|
+
}
|
|
795
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
796
|
+
}
|
|
797
|
+
function relativeLuminance(r, g, b) {
|
|
798
|
+
const toLinear = (c) => {
|
|
799
|
+
const s = c / 255;
|
|
800
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
801
|
+
};
|
|
802
|
+
return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
803
|
+
}
|
|
804
|
+
function themeFromBackgroundColor(color) {
|
|
805
|
+
if (isInvalidColor(color)) return null;
|
|
806
|
+
const channels = parseRgbChannels(color);
|
|
807
|
+
if (!channels) return null;
|
|
808
|
+
return relativeLuminance(...channels) < DARK_LUMINANCE_THRESHOLD ? "dark" : "light";
|
|
809
|
+
}
|
|
810
|
+
function tryResolveDomThemeHint() {
|
|
811
|
+
if (typeof document === "undefined") return null;
|
|
812
|
+
const roots = [document.documentElement, document.body].filter(Boolean);
|
|
813
|
+
for (const el2 of roots) {
|
|
814
|
+
const dataTheme = el2.dataset.theme || el2.getAttribute("data-theme") || el2.dataset.demoTheme || el2.getAttribute("data-demo-theme");
|
|
815
|
+
if (dataTheme === "dark" || dataTheme === "light") return dataTheme;
|
|
816
|
+
}
|
|
817
|
+
for (const el2 of roots) {
|
|
818
|
+
if (el2.classList.contains("dark") || el2.classList.contains("ant-theme-dark")) return "dark";
|
|
819
|
+
if (el2.classList.contains("light") || el2.classList.contains("ant-theme-light")) return "light";
|
|
820
|
+
}
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
function readBgVarFromElement(el2) {
|
|
824
|
+
try {
|
|
825
|
+
const style = getComputedStyle(el2);
|
|
826
|
+
for (const name of ANT_BG_VARS) {
|
|
827
|
+
const value = style.getPropertyValue(name)?.trim();
|
|
828
|
+
if (!isInvalidColor(value)) return value;
|
|
829
|
+
}
|
|
830
|
+
} catch {
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
function readCssVariableBg() {
|
|
836
|
+
if (typeof document === "undefined") return null;
|
|
837
|
+
for (const root of [document.documentElement, document.body]) {
|
|
838
|
+
if (!root) continue;
|
|
839
|
+
const value = readBgVarFromElement(root);
|
|
840
|
+
if (value) return value;
|
|
841
|
+
}
|
|
842
|
+
const seeds = document.querySelectorAll(
|
|
843
|
+
'.ant-btn-primary, .ant-btn, .ant-modal-content, .ant-input, [class*="css-var"]'
|
|
844
|
+
);
|
|
845
|
+
for (const seed of seeds) {
|
|
846
|
+
let el2 = seed;
|
|
847
|
+
while (el2) {
|
|
848
|
+
const value = readBgVarFromElement(el2);
|
|
849
|
+
if (value) return value;
|
|
850
|
+
el2 = el2.parentElement;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
function readExistingSurfaceBg() {
|
|
856
|
+
if (typeof document === "undefined") return null;
|
|
857
|
+
for (const selector of SURFACE_SELECTORS) {
|
|
858
|
+
const node = document.querySelector(selector);
|
|
859
|
+
if (!node) continue;
|
|
860
|
+
try {
|
|
861
|
+
const color = getComputedStyle(node).backgroundColor;
|
|
862
|
+
if (!isInvalidColor(color)) return color;
|
|
863
|
+
} catch {
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return null;
|
|
867
|
+
}
|
|
868
|
+
function probeSurfaceBg() {
|
|
869
|
+
if (typeof document === "undefined" || !document.body) return null;
|
|
870
|
+
beginSuppressThemeWatch();
|
|
871
|
+
try {
|
|
872
|
+
const seed = document.querySelector(
|
|
873
|
+
".ant-btn-primary, .ant-btn, .ant-input, .ant-modal-content"
|
|
874
|
+
);
|
|
875
|
+
const hashClasses = seed ? Array.from(seed.classList).filter((c) => c.startsWith("css-") || c.includes("css-var")) : [];
|
|
876
|
+
const mountAt = seed?.closest('[class*="css-var"]') || seed?.parentElement || document.body;
|
|
877
|
+
for (const className of SURFACE_PROBE_CLASSES) {
|
|
878
|
+
const tag = className.includes("ant-btn") ? "button" : className.includes("ant-input") ? "input" : "div";
|
|
879
|
+
const node = document.createElement(tag);
|
|
880
|
+
node.className = [className, ...hashClasses].filter(Boolean).join(" ");
|
|
881
|
+
node.setAttribute("aria-hidden", "true");
|
|
882
|
+
node.style.cssText = "position:absolute;left:0;top:0;opacity:0;pointer-events:none;width:0;height:0;overflow:hidden;";
|
|
883
|
+
mountAt.appendChild(node);
|
|
884
|
+
const color = getComputedStyle(node).backgroundColor;
|
|
885
|
+
node.remove();
|
|
886
|
+
if (!isInvalidColor(color)) return color;
|
|
887
|
+
}
|
|
888
|
+
return null;
|
|
889
|
+
} catch {
|
|
890
|
+
return null;
|
|
891
|
+
} finally {
|
|
892
|
+
endSuppressThemeWatch();
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function tryResolveAntdSurfaceBg(options) {
|
|
896
|
+
try {
|
|
897
|
+
const allowProbe = options?.allowProbe !== false;
|
|
898
|
+
const fromVar = readCssVariableBg();
|
|
899
|
+
if (fromVar) return fromVar;
|
|
900
|
+
const fromSurface = readExistingSurfaceBg();
|
|
901
|
+
if (fromSurface) return fromSurface;
|
|
902
|
+
if (allowProbe) return probeSurfaceBg();
|
|
903
|
+
return null;
|
|
904
|
+
} catch {
|
|
905
|
+
return null;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function tryResolveAntdThemeMode(options) {
|
|
909
|
+
return tryResolveDomThemeHint() ?? themeFromBackgroundColor(tryResolveAntdSurfaceBg(options));
|
|
910
|
+
}
|
|
732
911
|
function isUpdateNoticeMutationTarget(node) {
|
|
733
912
|
if (!node || node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
734
913
|
const el2 = node;
|
|
@@ -748,7 +927,7 @@ function mutationsOnlyAffectNotice(mutations) {
|
|
|
748
927
|
return false;
|
|
749
928
|
});
|
|
750
929
|
}
|
|
751
|
-
function watchThemeChanges(config, getTheme, onChange) {
|
|
930
|
+
function watchThemeChanges(config, getTheme, onChange, onThemeMode) {
|
|
752
931
|
if (typeof document === "undefined") {
|
|
753
932
|
return () => void 0;
|
|
754
933
|
}
|
|
@@ -760,39 +939,70 @@ function watchThemeChanges(config, getTheme, onChange) {
|
|
|
760
939
|
return () => void 0;
|
|
761
940
|
}
|
|
762
941
|
let last = "";
|
|
942
|
+
let lastThemeMode = null;
|
|
763
943
|
let btnBgCandidate = "";
|
|
764
944
|
let debounceTimer;
|
|
765
945
|
let settleTimer;
|
|
946
|
+
let rafPending = false;
|
|
766
947
|
const clearTimers = () => {
|
|
767
948
|
if (debounceTimer !== void 0) clearTimeout(debounceTimer);
|
|
768
949
|
if (settleTimer !== void 0) clearTimeout(settleTimer);
|
|
769
950
|
debounceTimer = void 0;
|
|
770
951
|
settleTimer = void 0;
|
|
952
|
+
rafPending = false;
|
|
771
953
|
};
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
954
|
+
const applyThemeModeIfChanged = (mode) => {
|
|
955
|
+
if (!mode || mode === lastThemeMode) return;
|
|
956
|
+
lastThemeMode = mode;
|
|
957
|
+
if (mode !== getTheme()) {
|
|
958
|
+
onThemeMode?.(mode);
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
const applyPrimaryIfChanged = (found, opts) => {
|
|
775
962
|
const { color, source } = found;
|
|
776
963
|
if (color === last) {
|
|
777
964
|
btnBgCandidate = "";
|
|
778
|
-
return;
|
|
965
|
+
return false;
|
|
779
966
|
}
|
|
780
|
-
if (source === "btnBg" &&
|
|
781
|
-
btnBgCandidate
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
settleTimer =
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
967
|
+
if (source === "btnBg" && !opts?.allowUnsettledBtnBg) {
|
|
968
|
+
if (color !== btnBgCandidate) {
|
|
969
|
+
btnBgCandidate = color;
|
|
970
|
+
if (settleTimer !== void 0) clearTimeout(settleTimer);
|
|
971
|
+
settleTimer = setTimeout(() => {
|
|
972
|
+
settleTimer = void 0;
|
|
973
|
+
evaluate({ settlePass: true });
|
|
974
|
+
}, THEME_BTN_BG_SETTLE_MS);
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
788
977
|
}
|
|
789
978
|
last = color;
|
|
790
979
|
btnBgCandidate = "";
|
|
791
980
|
onChange(color);
|
|
981
|
+
return true;
|
|
982
|
+
};
|
|
983
|
+
const evaluate = (opts) => {
|
|
984
|
+
let mode = tryResolveAntdThemeMode({ allowProbe: false });
|
|
985
|
+
if (!mode) mode = tryResolveAntdThemeMode({ allowProbe: true });
|
|
986
|
+
applyThemeModeIfChanged(mode);
|
|
987
|
+
const found = tryResolveAntdPrimaryDetailed({ allowProbe: false });
|
|
988
|
+
if (!found) return;
|
|
989
|
+
applyPrimaryIfChanged(found, { allowUnsettledBtnBg: opts?.settlePass === true });
|
|
792
990
|
};
|
|
793
991
|
const schedule = (mutations) => {
|
|
794
992
|
if (suppressThemeWatch > 0) return;
|
|
795
993
|
if (mutations && mutationsOnlyAffectNotice(mutations)) return;
|
|
994
|
+
if (!rafPending) {
|
|
995
|
+
rafPending = true;
|
|
996
|
+
scheduleFrame(() => {
|
|
997
|
+
rafPending = false;
|
|
998
|
+
if (suppressThemeWatch > 0) return;
|
|
999
|
+
applyThemeModeIfChanged(tryResolveAntdThemeMode({ allowProbe: false }));
|
|
1000
|
+
const found = tryResolveAntdPrimaryDetailed({ allowProbe: false });
|
|
1001
|
+
if (found?.source === "cssVar") {
|
|
1002
|
+
applyPrimaryIfChanged(found);
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
796
1006
|
if (debounceTimer !== void 0) clearTimeout(debounceTimer);
|
|
797
1007
|
debounceTimer = setTimeout(() => {
|
|
798
1008
|
debounceTimer = void 0;
|
|
@@ -801,7 +1011,13 @@ function watchThemeChanges(config, getTheme, onChange) {
|
|
|
801
1011
|
}, THEME_WATCH_DEBOUNCE_MS);
|
|
802
1012
|
};
|
|
803
1013
|
const observer = new MutationObserver((mutations) => schedule(mutations));
|
|
804
|
-
const attrFilter = [
|
|
1014
|
+
const attrFilter = [
|
|
1015
|
+
"class",
|
|
1016
|
+
"style",
|
|
1017
|
+
"data-theme",
|
|
1018
|
+
"data-demo-theme",
|
|
1019
|
+
"data-update-notice-theme"
|
|
1020
|
+
];
|
|
805
1021
|
observer.observe(document.documentElement, {
|
|
806
1022
|
attributes: true,
|
|
807
1023
|
attributeFilter: attrFilter
|
|
@@ -858,6 +1074,18 @@ function applyPrimaryColor(primary) {
|
|
|
858
1074
|
endSuppressThemeWatch();
|
|
859
1075
|
}
|
|
860
1076
|
}
|
|
1077
|
+
function applySurfaceBackground(bg) {
|
|
1078
|
+
beginSuppressThemeWatch();
|
|
1079
|
+
try {
|
|
1080
|
+
document.querySelectorAll(".cdfrd-update-notice").forEach((node) => {
|
|
1081
|
+
const el2 = node;
|
|
1082
|
+
if (bg) el2.style.setProperty("--update-bg", bg);
|
|
1083
|
+
else el2.style.removeProperty("--update-bg");
|
|
1084
|
+
});
|
|
1085
|
+
} finally {
|
|
1086
|
+
endSuppressThemeWatch();
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
861
1089
|
function closeDefaultNotice() {
|
|
862
1090
|
document.querySelector(".cdfrd-update-notice")?.remove();
|
|
863
1091
|
visible = false;
|
|
@@ -909,18 +1137,12 @@ function showDefaultNotice(options) {
|
|
|
909
1137
|
actions.appendChild(refreshBtn);
|
|
910
1138
|
panel.appendChild(actions);
|
|
911
1139
|
} else {
|
|
912
|
-
|
|
913
|
-
header.appendChild(el("div", "cdfrd-update-notice-title", copy.title));
|
|
914
|
-
const closeBtn = el("button", `cdfrd-update-notice-close ${NOTIFICATION_CLOSE_BTN_CLASS}`, "\xD7");
|
|
915
|
-
closeBtn.setAttribute("type", "button");
|
|
916
|
-
closeBtn.setAttribute("aria-label", "close");
|
|
917
|
-
header.appendChild(closeBtn);
|
|
918
|
-
panel.appendChild(header);
|
|
1140
|
+
panel.appendChild(el("div", "cdfrd-update-notice-title", copy.title));
|
|
919
1141
|
panel.appendChild(el("div", "cdfrd-update-notice-desc", copy.description));
|
|
920
1142
|
const actions = el("div", "cdfrd-update-notice-actions");
|
|
921
1143
|
const dismissBtn = el(
|
|
922
1144
|
"button",
|
|
923
|
-
`cdfrd-update-notice-btn ${NOTIFICATION_DISMISS_BTN_CLASS}`,
|
|
1145
|
+
`cdfrd-update-notice-btn cdfrd-update-notice-btn-link ${NOTIFICATION_DISMISS_BTN_CLASS}`,
|
|
924
1146
|
copy.dismissButtonText
|
|
925
1147
|
);
|
|
926
1148
|
dismissBtn.setAttribute("type", "button");
|
|
@@ -933,6 +1155,10 @@ function showDefaultNotice(options) {
|
|
|
933
1155
|
refreshBtn.setAttribute("type", "button");
|
|
934
1156
|
actions.appendChild(refreshBtn);
|
|
935
1157
|
panel.appendChild(actions);
|
|
1158
|
+
const closeBtn = el("button", `cdfrd-update-notice-close ${NOTIFICATION_CLOSE_BTN_CLASS}`, "\xD7");
|
|
1159
|
+
closeBtn.setAttribute("type", "button");
|
|
1160
|
+
closeBtn.setAttribute("aria-label", "close");
|
|
1161
|
+
panel.appendChild(closeBtn);
|
|
936
1162
|
}
|
|
937
1163
|
wrap.appendChild(panel);
|
|
938
1164
|
let anchor = document.body.querySelector(`:scope > .cdfrd-update-notice-anchor`);
|
|
@@ -1045,6 +1271,24 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1045
1271
|
}
|
|
1046
1272
|
this.refreshPrimaryColor(gen);
|
|
1047
1273
|
}
|
|
1274
|
+
/** Sync light/dark panel tokens + surface bg from Antd when detectable. */
|
|
1275
|
+
syncAntdThemeMode(allowProbe = true) {
|
|
1276
|
+
const adapter = this.getActiveThemeAdapter();
|
|
1277
|
+
if ((adapter?.type ?? "antd") !== "antd") {
|
|
1278
|
+
applySurfaceBackground(null);
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
const bg = tryResolveAntdSurfaceBg({ allowProbe });
|
|
1282
|
+
const bgMode = themeFromBackgroundColor(bg);
|
|
1283
|
+
const domMode = tryResolveDomThemeHint();
|
|
1284
|
+
const mode = domMode ?? bgMode;
|
|
1285
|
+
if (mode && mode !== this.theme) {
|
|
1286
|
+
this.theme = mode;
|
|
1287
|
+
applyTheme(mode);
|
|
1288
|
+
}
|
|
1289
|
+
const surfaceOk = Boolean(bg && bgMode && mode && bgMode === mode);
|
|
1290
|
+
applySurfaceBackground(surfaceOk ? bg : null);
|
|
1291
|
+
}
|
|
1048
1292
|
notifyUpdate(_runtime, _version) {
|
|
1049
1293
|
void _runtime;
|
|
1050
1294
|
void _version;
|
|
@@ -1053,6 +1297,7 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1053
1297
|
ensureNotificationAnchor();
|
|
1054
1298
|
const adapter = runtime.options.themeAdapter ?? this.themeAdapter;
|
|
1055
1299
|
const gen = this.primaryResolveGen;
|
|
1300
|
+
this.syncAntdThemeMode(true);
|
|
1056
1301
|
resolvePrimaryColorLazy(adapter, this.theme, (color) => {
|
|
1057
1302
|
if (gen !== this.primaryResolveGen) return;
|
|
1058
1303
|
this.primaryColor = color;
|
|
@@ -1078,6 +1323,7 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1078
1323
|
runtime.dismissVersion(version);
|
|
1079
1324
|
}
|
|
1080
1325
|
});
|
|
1326
|
+
this.syncAntdThemeMode(true);
|
|
1081
1327
|
});
|
|
1082
1328
|
return true;
|
|
1083
1329
|
}
|
|
@@ -1092,11 +1338,22 @@ var UpdateNoticeManager = class _UpdateNoticeManager {
|
|
|
1092
1338
|
startThemeWatch() {
|
|
1093
1339
|
this.stopWatchTheme?.();
|
|
1094
1340
|
const adapter = this.getActiveThemeAdapter();
|
|
1095
|
-
this.stopWatchTheme = watchThemeChanges(
|
|
1096
|
-
|
|
1097
|
-
this.
|
|
1098
|
-
|
|
1099
|
-
|
|
1341
|
+
this.stopWatchTheme = watchThemeChanges(
|
|
1342
|
+
adapter,
|
|
1343
|
+
() => this.theme,
|
|
1344
|
+
(color) => {
|
|
1345
|
+
this.primaryResolveGen += 1;
|
|
1346
|
+
this.primaryColor = color;
|
|
1347
|
+
applyPrimaryColor(color);
|
|
1348
|
+
this.syncAntdThemeMode(true);
|
|
1349
|
+
},
|
|
1350
|
+
(theme) => {
|
|
1351
|
+
if (theme === this.theme) return;
|
|
1352
|
+
this.theme = theme;
|
|
1353
|
+
applyTheme(theme);
|
|
1354
|
+
this.syncAntdThemeMode(true);
|
|
1355
|
+
}
|
|
1356
|
+
);
|
|
1100
1357
|
}
|
|
1101
1358
|
destroy() {
|
|
1102
1359
|
this.stopWatchTheme?.();
|