txw/txw-mhzc-web/scripts/migrate-home-styles.mjs
2026-05-24 10:55:36 +08:00

147 lines
8.1 KiB
JavaScript

import fs from 'fs';
const path = 'e:/develop/code/txw/txw-mhzc-web/src/pages/index/views/home2/index.vue';
let s = fs.readFileSync(path, 'utf8');
const start = s.indexOf('<style lang="less" scoped>');
const end = s.indexOf('</style>', start);
if (start < 0 || end < 0) throw new Error('style block not found');
let css = s.slice(start, end);
const reps = [
[/#f5f7fa\b/g, '@home-color-page-bg'],
[/#003b1a\b/gi, '@home-color-primary-dark'],
[/#556659\b/gi, '@home-color-text-body'],
[/#1a1a2e\b/gi, '@home-color-text-title'],
[/#999999\b/g, '@home-color-text-muted'],
[/\b#999\b/g, '@home-color-text-muted'],
[/#333333\b/g, '@home-color-text-dark'],
[/\b#333\b/g, '@home-color-text-dark'],
[/#666666\b/g, '@home-color-text-secondary'],
[/\b#666\b/g, '@home-color-text-secondary'],
[/#222222\b/g, '@home-color-text-partner'],
[/\b#222\b/g, '@home-color-text-partner'],
[/#000000\b/g, '@home-color-black'],
[/\b#000\b/g, '@home-color-black'],
[/#ffffff\b/gi, '@home-color-white'],
[/\b#fff\b/gi, '@home-color-white'],
[/#00b96b\b/gi, '@home-color-primary-green'],
[/#00a25d\b/gi, '@home-color-primary-green-dark'],
[/#2e7d32\b/gi, '@home-color-secondary-green'],
[/#e6efe6\b/gi, '@home-color-tab-bg'],
[/#008cff\b/gi, '@home-color-accent-blue'],
[/#2196f3\b/gi, '@home-color-btn-blue-to'],
[/#99d2fe\b/gi, '@home-color-btn-blue-from'],
[/#007242\b/gi, '@home-color-cta-btn-from'],
[/#00d87d\b/gi, '@home-color-cta-btn-to'],
[/#f0f7f2\b/gi, '@home-color-footer-bg'],
[/'PingFang SC', 'Microsoft YaHei', sans-serif/g, '@home-font-family'],
[/'PingFang SC', sans-serif/g, '@home-font-family'],
[/font-family: PingFang SC;/g, 'font-family: @home-font-family;'],
[/font-family: 'PingFang SC';/g, 'font-family: @home-font-family;'],
[/linear-gradient\(180deg, #00b96b 0%, #00a25d 100%\)/g, '@home-gradient-search-btn'],
[/linear-gradient\(180deg, rgba\(245, 247, 250, 0\) 0%, rgba\(245, 247, 250\) 100%\)/g, '@home-gradient-hero-fade'],
[/linear-gradient\(180deg, rgba\(245, 247, 250, 0\) 0%, rgba\(245, 247, 250, 1\) 100%\)/g, '@home-gradient-hero-fade'],
[/linear-gradient\(90deg, #ffffff 0%, #e6efff 36\.06%, #e6efff 62\.5%, #ffffff 100%\)/g, '@home-gradient-core-tag'],
[/linear-gradient\(0deg, rgba\(255, 255, 255, 0\.9\) 0%, rgba\(255, 255, 255, 0\.4\) 100%\)/g, '@home-gradient-ability-card'],
[/linear-gradient\(180deg, #99d2fe 0%, #2196f3 100%\)/g, '@home-gradient-export-btn'],
[/linear-gradient\(90deg, #007242 0%, #00d87d 100%\)/g, '@home-gradient-cta-btn'],
[/0 8px 12px rgba\(0, 0, 0, 0\.08\)/g, '@home-shadow-search'],
[/0 8px 12px rgba\(127, 179, 213, 0\.2\)/g, '@home-shadow-card-blue'],
[/0 8px 12px rgba\(0, 185, 107, 0\.1\)/g, '@home-shadow-card-green'],
[/0 8px 20px rgba\(0, 209, 121, 0\.3\)/g, '@home-shadow-card-green-strong'],
[/0 2px 5px rgba\(0, 0, 0, 0\.1\)/g, '@home-shadow-news-item'],
[/0 2px 10px rgba\(0, 0, 0, 0\.1\)/g, '@home-shadow-news-item'],
[/0px 4px 8px 0px rgba\(0, 185, 107, 0\.06\)/g, '@home-shadow-partner-logo'],
[/0 4px 12px rgba\(255, 255, 255, 1\)/g, '@home-shadow-title-sub'],
[/0 0 8px rgba\(255, 255, 255, 1\)/g, '@home-shadow-card-title'],
[/0 0 8px #ffffff/g, '@home-shadow-card-title'],
[/0 4px 12px #ffffff/g, '@home-shadow-title-sub'],
[/rgba\(255, 255, 255, 0\.7\)/g, '@home-color-white-70'],
[/rgba\(255, 255, 255, 0\.6\)/g, '@home-color-white-60'],
[/background: rgba\(245, 247, 250, 1\)/g, 'background: @home-color-page-bg'],
[/background: rgba\(222, 243, 255, 0\.75\)/g, '@home-color-card-blue-btn-primary-bg'],
[/background: rgba\(222, 243, 255, 0\.95\)/g, 'fade(@home-color-card-blue-btn-primary-bg, 95%)'],
[/background: rgba\(222, 243, 255, 0\.5\)/g, '@home-color-card-blue-btn-secondary-bg'],
[/border: 1px solid rgba\(0, 141, 213, 0\.4\)/g, 'border: 1px solid @home-color-card-blue-btn-secondary-border'],
[/background: rgba\(255, 255, 255, 0\.35\)/g, '@home-color-card-chain-bg'],
[/background: rgba\(255, 255, 255, 0\.4\)/g, '@home-color-card-chain-btn-secondary-bg'],
[/border: 1px solid rgba\(0, 0, 0, 0\.2\)/g, 'border: 1px solid @home-color-card-chain-btn-secondary-border'],
[/background: rgba\(232, 255, 234, 0\.5\)/g, '@home-color-card-green-btn-secondary-bg'],
[/border: 1px solid rgba\(0, 180, 42, 0\.4\)/g, 'border: 1px solid @home-color-card-green-btn-secondary-border'],
];
for (const [re, rep] of reps) css = css.replace(re, rep);
const numReps = [
['max-width: 867px', 'max-width: @home-hero-title-width'],
['max-width: 600px', 'max-width: @home-search-box-width'],
['width: 92px', 'width: @home-search-btn-width'],
['height: 300px', 'height: @home-hero-fade-height'],
['padding: 8px 8px 8px 16px', 'padding: @home-search-box-padding'],
['padding: 2px 8px', 'padding: @home-search-tag-padding'],
['padding: 0 0 24px', 'padding: 0 0 @home-space-24'],
['gap: 36px', 'gap: @home-feature-cards-gap'],
['gap: 32px', 'gap: @home-space-32'],
['gap: 16px', 'gap: @home-space-16'],
['gap: 12px', 'gap: @home-search-tag-gap'],
['gap: 28px', 'gap: @home-export-card-gap'],
['gap: 14px', 'gap: @home-core-col-gap'],
['gap: 42px', 'gap: @home-section-gap'],
['gap: 52px', 'gap: @home-space-52'],
['gap: 56px', 'gap: @home-space-56'],
['font-size: 56px', 'font-size: @home-font-size-56'],
['font-size: 40px', 'font-size: @home-font-size-40'],
['font-size: 32px', 'font-size: @home-font-size-32'],
['font-size: 28px', 'font-size: @home-font-size-28'],
['font-size: 24px', 'font-size: @home-font-size-24'],
['font-size: 22px', 'font-size: @home-font-size-22'],
['font-size: 20px', 'font-size: @home-font-size-20'],
['font-size: 16px', 'font-size: @home-font-size-16'],
['font-size: 14px', 'font-size: @home-font-size-14'],
['font-size: 12px', 'font-size: @home-font-size-12'],
['line-height: 38px', 'line-height: @home-line-height-38'],
['line-height: 28px', 'line-height: @home-line-height-28'],
['line-height: 26px', 'line-height: @home-line-height-26'],
['line-height: 22px', 'line-height: @home-line-height-22'],
['line-height: 20px', 'line-height: @home-line-height-20'],
['font-weight: 600', 'font-weight: @home-font-weight-semibold'],
['font-weight: 500', 'font-weight: @home-font-weight-medium'],
['font-weight: 400', 'font-weight: @home-font-weight-regular'],
['border-radius: 16px', 'border-radius: @home-radius-xl'],
['border-radius: 12px', 'border-radius: @home-radius-lg'],
['border-radius: 10px', 'border-radius: @home-radius-md'],
['border-radius: 8px', 'border-radius: @home-radius-sm'],
['border-radius: 4px', 'border-radius: @home-radius-xs'],
['border-radius: 24px', 'border-radius: @home-radius-pill'],
['backdrop-filter: blur(20px)', 'backdrop-filter: blur(@home-blur-tag)'],
['backdrop-filter: blur(10px)', 'backdrop-filter: blur(@home-blur-md)'],
['backdrop-filter: blur(8px)', 'backdrop-filter: blur(@home-blur-sm)'],
['backdrop-filter: blur(4px)', 'backdrop-filter: blur(@home-blur-ability)'],
['width: 145px', 'width: @home-news-thumb-width'],
['width: 282px', 'width: @home-partner-logo-card-width'],
['height: 89px', 'height: @home-partner-logo-card-height'],
['height: 66px', 'height: @home-cta-btn-height'],
['width: 360px', 'width: @home-cta-btn-width'],
['width: 77px', 'width: @home-export-btn-size'],
['height: 77px', 'height: @home-export-btn-size'],
['min-height: 119px', 'min-height: @home-export-card-height'],
['max-width: 628px', 'max-width: @home-export-list-width'],
['padding: 0 30px', 'padding: 0 @home-core-grid-padding-x'],
['column-gap: 13px', 'column-gap: @home-ability-grid-col-gap'],
['row-gap: 70px', 'row-gap: @home-ability-grid-row-gap'],
['min-height: 330px', 'min-height: @home-ability-grid-min-height'],
['padding: 16px 16px 16px 32px', 'padding: @home-ability-card-padding'],
];
for (const [from, to] of numReps) css = css.replaceAll(from, to);
// Fix double-replaced height on search btn line-height
css = css.replace(
/line-height: @home-search-btn-height;\s*\n\s*font-family: @home-font-family;/g,
'line-height: @home-search-btn-height;\n font-family: @home-font-family;'
);
s = s.slice(0, start) + css + s.slice(end);
fs.writeFileSync(path, s);
console.log('migration complete');