#!/usr/bin/env python # -*- coding: utf-8 -*- """C-2a-3 旧蓝分流·health 集群收尾:gut-flora 三兄弟 + feedback-popup + 五零星页 主族为 #4A9BD7(旧蓝-500 变体,页面级 raw hex;$brand-legacy-blue 令牌引用归 C-2b) 三分法: 选中态/主按钮/装饰竖线/页面 accent 链接 -> $brand-primary 浅蓝底信息徽章(level-tag/quote-label/badge-question)-> $uni-info(保徽章 coherent) report-header 渐变 -> 站点标准 hero($brand-primary -> $brand-primary-dark) JS/模板数据色(防撞色策略,不走 style 验证): gut-flora-detail 九系色板 #4A9BD7x2 -> #0EA5E9(保蓝色槽位;翻橙会与 #FF8C42 撞色) report-blocks-renderer 模板兜底 '#4A9BD7' -> '#F97316' health-report 四系色板头位 '#5B9BD5' -> '#F97316'(与 #FF9800 有列表间距不撞色) """ import io import re import sys ORANGE = '$brand-primary' ORANGE_DARK = '$brand-primary-dark' INFO = '$uni-info' PAGES = { 'pages/health/gut-flora-detail.vue': { 'blocks': [], 'global': [ ('linear-gradient(135deg, #4A9BD7, #6366F1)', 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)), ('rgba(74,155,215,0.4)', 'rgba(249,115,22,0.4)'), ('#4A9BD7', ORANGE), ], }, 'pages/health/gut-flora-species-detail.vue': { 'blocks': [ ('.flora-level-tag', [('color: #4A9BD7', 'color: ' + INFO)]), ], 'global': [ ('#4A9BD7', ORANGE), ], }, 'pages/health/gut-flora-risks-detail.vue': { 'blocks': [], 'global': [ ('#4A9BD7', ORANGE), ], }, 'pages/health/components/feedback-popup.vue': { 'blocks': [ ('.fb-quote-label', [('color: #4A9BD7', 'color: ' + INFO)]), ], 'global': [ ('#4A9BD7', ORANGE), ], }, 'pages/health/plan-list.vue': { 'blocks': [], 'global': [ ('#4A9BD7', ORANGE), ], }, 'pages/health/my-feedback.vue': { 'blocks': [], 'global': [ ('color: #4A9BD7', 'color: ' + INFO), ], }, 'pages/health/indicator-quicklook.vue': { 'blocks': [], 'global': [ ('#4A9BD7', ORANGE), ], }, } # JS/模板数据色(整文件 targeted,带计数断言;style 块已无旧蓝后执行) SCRIPT_SUBS = [ ('pages/health/gut-flora-detail.vue', "'#4A9BD7'", "'#0EA5E9'", 2), ('pages/health/report-blocks-renderer.vue', "'#4A9BD7'", "'#F97316'", 1), ('pages/body-detail/health-report.vue', "'#5B9BD5'", "'#F97316'", 1), ] RESIDUAL_RE = re.compile(r'(?]*>[\s\S]*?', re.M) def apply_block_rules(block, rules, page): for sel, pairs in rules: lines = block.split('\n') idx = None for i, ln in enumerate(lines): t = ln.strip() if t.startswith(sel) and (t.endswith('{') or t.endswith('}')): idx = i break if idx is None: raise RuntimeError('%s: 选择器未找到 %s' % (page, sel)) line = lines[idx] if line.strip().endswith('}'): # 单行块:选择器与声明同行,仅在行内替换(保留原格式) for old, new in pairs: n = line.count(old) if n != 1: raise RuntimeError('%s: 单行块 hit=%d %s :: %s' % (page, n, sel, old)) line = line.replace(old, new, 1) print(' [block·单行] %-22s %-22s -> %s' % (sel, old, new)) lines[idx] = line else: end = None for j in range(idx + 1, len(lines)): if lines[j].strip() == '}': end = j break if end is None: raise RuntimeError('%s: 块未闭合 %s' % (page, sel)) body = lines[idx + 1:end] for old, new in pairs: btxt = '\n'.join(body) n = btxt.count(old) if n != 1: raise RuntimeError('%s: 块内替换 hit=%d %s :: %s' % (page, n, sel, old)) body = btxt.replace(old, new, 1).split('\n') print(' [block] %-22s %-22s -> %s' % (sel, old, new)) lines[idx + 1:end] = body block = '\n'.join(lines) return block def apply_global(block, pairs, page): for old, new in pairs: n = block.count(old) if n == 0: raise RuntimeError('%s: 全局替换 hit=0 :: %s' % (page, old)) block = block.replace(old, new) print(' %-46s -> %-26s x%d' % (old, new, n)) return block def fix_lang(block, page): first, rest = block.split('\n', 1) if 'lang="scss"' not in first: if '