#!/usr/bin/env python # -*- coding: utf-8 -*- """C-2a-2 旧蓝分流执行器:meal-config / article-detail / discover / reminder-config 三分法(docs/beautification-plan.md L103-105): 链接/信息提示 -> $uni-info;主行动按钮/选中态 -> $brand-primary 族;装饰性底纹 -> 最近语义令牌 本批判定: meal-config tab-active/member-selected/add-member-entry/meal-count=选中态与入口 -> 橙; tip-text 提示卡 -> info;两条渐变整条同族翻(#8FC5E8->$brand-primary-light 防渐变断裂) article-detail spinner/meta/badge/listen 簇 -> info + rgba(14,165,233,x);retry-btn solid 主按钮 -> 橙 discover 旧蓝=商品价格/选中 chip/横幅的页面主 accent(电商风)-> 全橙 reminder-config switch-on/channel-selected/channel-check/timing-active=选中态 -> 橙; channel-tip-text/tip-text=信息提示 -> info;timing-active name 选中文字 -> 橙深档 配套浅底:#F0F7FF 仅翻与已翻选中态成套者(add-member-entry:active / timing-active)-> $uni-primary-pale """ import io import re import sys ORANGE = '$brand-primary' ORANGE_LIGHT = '$brand-primary-light' ORANGE_DARK = '$brand-primary-dark' INFO = '$uni-info' PALE = '$uni-primary-pale' GRAD_LIGHT = 'linear-gradient(135deg, #5B9BD5, #8FC5E8)' GRAD_DARK = 'linear-gradient(135deg, #5B9BD5, #3A7CC4)' def rgba_orange(a): return 'rgba(249, 115, 22, %s)' % a def rgba_info(a): return 'rgba(14, 165, 233, %s)' % a PAGES = { 'pages/diet/meal-config.vue': { 'blocks': [ ('.tip-text', [('color: #3A7CC4', 'color: ' + INFO)]), ], 'global': [ (GRAD_LIGHT, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_LIGHT)), (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)), ('rgba(91, 155, 213, 0.3)', rgba_orange('0.3')), ('rgba(91, 155, 213, 0.08)', rgba_orange('0.08')), ('#5B9BD5', ORANGE), ('#F0F7FF', PALE), ], }, 'pages/article-center/article-detail.vue': { 'blocks': [], 'global': [ ('border-top-color: #5B9BD5', 'border-top-color: ' + INFO), ('background: #5B9BD5', 'background: ' + ORANGE), ('#5B9BD5', INFO), ('rgba(91,155,213,0.08)', rgba_info('0.08')), ('rgba(91,155,213,0.1)', rgba_info('0.1')), ('rgba(91,155,213,0.2)', rgba_info('0.2')), ], }, 'pages/discover/index.vue': { 'blocks': [], 'global': [ (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)), ('rgba(91,155,213,0.1)', rgba_orange('0.1')), ('#5B9BD5', ORANGE), ], }, 'pages/reminder-config/index.vue': { 'blocks': [ ('.channel-tip-text', [('color: #5B9BD5', 'color: ' + INFO)]), ('.timing-active .timing-name', [('color: #3A7CC4', 'color: ' + ORANGE_DARK)]), ('.tip-text', [('color: #3A7CC4', 'color: ' + INFO)]), ], 'global': [ (GRAD_LIGHT, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_LIGHT)), (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)), ('rgba(91, 155, 213, 0.08)', rgba_orange('0.08')), ('rgba(91, 155, 213, 0.3)', rgba_orange('0.3')), ('#F0F7FF', PALE), ('#5B9BD5', ORANGE), ], }, } 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('{'): idx = i break if idx is None: raise RuntimeError('%s: 选择器未找到 %s' % (page, sel)) 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(要求 1)%s :: %s' % (page, n, sel, old)) body = btxt.replace(old, new, 1).split('\n') print(' [block] %-28s %-24s -> %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 '', re.M) def main(): total = 0 for page, cfg in PAGES.items(): src = io.open(page, encoding='utf-8').read() m = STYLE_RE.search(src) if not m: raise RuntimeError('%s: 未找到 style 块' % page) block = m.group(0) print('== %s ==' % page) block = apply_block_rules(block, cfg['blocks'], page) block = apply_global(block, cfg['global'], page) block = fix_lang(block, page) # 残留自查 residual = re.findall(r'(?