马一丁

Update the mode switching button

@@ -520,7 +520,26 @@ class HTMLRenderer: @@ -520,7 +520,26 @@ class HTMLRenderer:
520 {self._render_tagline()} 520 {self._render_tagline()}
521 </div> 521 </div>
522 <div class="header-actions"> 522 <div class="header-actions">
  523 + <!-- 旧版日夜模式切换按钮(Web Component 风格):
523 <theme-button value="light" id="theme-toggle" size="1.5"></theme-button> 524 <theme-button value="light" id="theme-toggle" size="1.5"></theme-button>
  525 + -->
  526 + <button id="theme-toggle-btn" class="action-btn theme-toggle-btn" type="button">
  527 + <svg class="btn-icon sun-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  528 + <circle cx="12" cy="12" r="5"></circle>
  529 + <line x1="12" y1="1" x2="12" y2="3"></line>
  530 + <line x1="12" y1="21" x2="12" y2="23"></line>
  531 + <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
  532 + <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
  533 + <line x1="1" y1="12" x2="3" y2="12"></line>
  534 + <line x1="21" y1="12" x2="23" y2="12"></line>
  535 + <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
  536 + <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
  537 + </svg>
  538 + <svg class="btn-icon moon-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;">
  539 + <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
  540 + </svg>
  541 + <span class="theme-label">切换模式</span>
  542 + </button>
524 <button id="print-btn" class="action-btn print-btn" type="button"> 543 <button id="print-btn" class="action-btn print-btn" type="button">
525 <svg class="btn-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> 544 <svg class="btn-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
526 <polyline points="6 9 6 2 18 2 18 9"></polyline> 545 <polyline points="6 9 6 2 18 2 18 9"></polyline>
@@ -3345,6 +3364,24 @@ theme-button {{ /* 含义:主题切换组件;设置:在本块内调整相 @@ -3345,6 +3364,24 @@ theme-button {{ /* 含义:主题切换组件;设置:在本块内调整相
3345 flex-shrink: 0; /* 含义:flex-shrink 样式属性;设置:按需调整数值/颜色/变量 */ 3364 flex-shrink: 0; /* 含义:flex-shrink 样式属性;设置:按需调整数值/颜色/变量 */
3346 filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15)); /* 含义:滤镜效果;设置:按需调整数值/颜色/变量 */ 3365 filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15)); /* 含义:滤镜效果;设置:按需调整数值/颜色/变量 */
3347 }} /* 结束 .action-btn .btn-icon */ 3366 }} /* 结束 .action-btn .btn-icon */
  3367 +.theme-toggle-btn .sun-icon,
  3368 +.theme-toggle-btn .moon-icon {{ /* 含义:主题切换按钮图标样式;设置:在本块内调整相关属性 */
  3369 + transition: transform 0.3s ease, opacity 0.3s ease; /* 含义:过渡动画时长/属性;设置:按需调整数值/颜色/变量 */
  3370 +}} /* 结束 .theme-toggle-btn 图标 */
  3371 +.theme-toggle-btn .sun-icon {{ /* 含义:太阳图标样式;设置:在本块内调整相关属性 */
  3372 + color: #F59E0B; /* 含义:太阳图标颜色;设置:按需调整数值/颜色/变量 */
  3373 + stroke: #F59E0B; /* 含义:太阳图标描边颜色;设置:按需调整数值/颜色/变量 */
  3374 +}} /* 结束 .theme-toggle-btn .sun-icon */
  3375 +.theme-toggle-btn .moon-icon {{ /* 含义:月亮图标样式;设置:在本块内调整相关属性 */
  3376 + color: #6366F1; /* 含义:月亮图标颜色;设置:按需调整数值/颜色/变量 */
  3377 + stroke: #6366F1; /* 含义:月亮图标描边颜色;设置:按需调整数值/颜色/变量 */
  3378 +}} /* 结束 .theme-toggle-btn .moon-icon */
  3379 +.theme-toggle-btn:hover .sun-icon {{ /* 含义:悬停时太阳图标效果;设置:在本块内调整相关属性 */
  3380 + transform: rotate(15deg); /* 含义:旋转变换;设置:按需调整数值/颜色/变量 */
  3381 +}} /* 结束 .theme-toggle-btn:hover .sun-icon */
  3382 +.theme-toggle-btn:hover .moon-icon {{ /* 含义:悬停时月亮图标效果;设置:在本块内调整相关属性 */
  3383 + transform: rotate(-15deg) scale(1.1); /* 含义:旋转和缩放变换;设置:按需调整数值/颜色/变量 */
  3384 +}} /* 结束 .theme-toggle-btn:hover .moon-icon */
3348 body.exporting {{ /* 含义:body.exporting 样式区域;设置:在本块内调整相关属性 */ 3385 body.exporting {{ /* 含义:body.exporting 样式区域;设置:在本块内调整相关属性 */
3349 cursor: progress; /* 含义:鼠标指针样式;设置:按需调整数值/颜色/变量 */ 3386 cursor: progress; /* 含义:鼠标指针样式;设置:按需调整数值/颜色/变量 */
3350 }} /* 结束 body.exporting */ 3387 }} /* 结束 body.exporting */
@@ -4546,7 +4583,8 @@ img, canvas, svg {{ /* 含义:媒体元素尺寸限制;设置:在本块内 @@ -4546,7 +4583,8 @@ img, canvas, svg {{ /* 含义:媒体元素尺寸限制;设置:在本块内
4546 document.documentElement.classList.remove('no-js'); 4583 document.documentElement.classList.remove('no-js');
4547 document.documentElement.classList.add('js-ready'); 4584 document.documentElement.classList.add('js-ready');
4548 4585
4549 -/* ========== Theme Button Web Component ========== */ 4586 +/* ========== Theme Button Web Component (已注释,改用 action-btn 风格) ========== */
  4587 +/*
4550 (() => { 4588 (() => {
4551 const themeButtonFunc = (root, initTheme, changeTheme) => { 4589 const themeButtonFunc = (root, initTheme, changeTheme) => {
4552 const checkbox = root.querySelector('.theme-checkbox'); 4590 const checkbox = root.querySelector('.theme-checkbox');
@@ -4642,7 +4680,8 @@ document.documentElement.classList.add('js-ready'); @@ -4642,7 +4680,8 @@ document.documentElement.classList.add('js-ready');
4642 } 4680 }
4643 customElements.define("theme-button", ThemeButton); 4681 customElements.define("theme-button", ThemeButton);
4644 })(); 4682 })();
4645 - /* ========== End Theme Button Web Component ========== */ 4683 +*/
  4684 +/* ========== End Theme Button Web Component ========== */
4646 4685
4647 const chartRegistry = []; 4686 const chartRegistry = [];
4648 const wordCloudRegistry = new Map(); 4687 const wordCloudRegistry = new Map();
@@ -5782,15 +5821,46 @@ document.addEventListener('DOMContentLoaded', () => { @@ -5782,15 +5821,46 @@ document.addEventListener('DOMContentLoaded', () => {
5782 } 5821 }
5783 }); 5822 });
5784 }, 260); 5823 }, 260);
5785 - const themeBtn = document.getElementById('theme-toggle');  
5786 - if (themeBtn) {  
5787 - // 主题按钮:detail = 'light'/'dark',同步 body class 与图表/词云配色  
5788 - themeBtn.addEventListener('change', (e) => {  
5789 - if (e.detail === 'dark') { 5824 + // 旧版 Web Component 主题按钮(已注释)
  5825 + // const themeBtn = document.getElementById('theme-toggle');
  5826 + // if (themeBtn) {
  5827 + // themeBtn.addEventListener('change', (e) => {
  5828 + // if (e.detail === 'dark') {
  5829 + // document.body.classList.add('dark-mode');
  5830 + // } else {
  5831 + // document.body.classList.remove('dark-mode');
  5832 + // }
  5833 + // chartRegistry.forEach(applyChartTheme);
  5834 + // rerenderWordclouds();
  5835 + // });
  5836 + // }
  5837 +
  5838 + // 新版 action-btn 风格主题按钮
  5839 + const themeBtnNew = document.getElementById('theme-toggle-btn');
  5840 + if (themeBtnNew) {
  5841 + const sunIcon = themeBtnNew.querySelector('.sun-icon');
  5842 + const moonIcon = themeBtnNew.querySelector('.moon-icon');
  5843 + let isDark = document.body.classList.contains('dark-mode');
  5844 +
  5845 + const updateThemeUI = () => {
  5846 + if (isDark) {
  5847 + sunIcon.style.display = 'none';
  5848 + moonIcon.style.display = 'block';
  5849 + } else {
  5850 + sunIcon.style.display = 'block';
  5851 + moonIcon.style.display = 'none';
  5852 + }
  5853 + };
  5854 + updateThemeUI();
  5855 +
  5856 + themeBtnNew.addEventListener('click', () => {
  5857 + isDark = !isDark;
  5858 + if (isDark) {
5790 document.body.classList.add('dark-mode'); 5859 document.body.classList.add('dark-mode');
5791 } else { 5860 } else {
5792 document.body.classList.remove('dark-mode'); 5861 document.body.classList.remove('dark-mode');
5793 } 5862 }
  5863 + updateThemeUI();
5794 chartRegistry.forEach(applyChartTheme); 5864 chartRegistry.forEach(applyChartTheme);
5795 rerenderWordclouds(); 5865 rerenderWordclouds();
5796 }); 5866 });