| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #!/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 '<style scoped>' in first:
- first = first.replace('<style scoped>', '<style scoped lang="scss">', 1)
- elif '<style>' in first:
- first = first.replace('<style>', '<style lang="scss">', 1)
- else:
- raise RuntimeError('%s: 无法识别的 style 标签形态: %s' % (page, first.strip()))
- print(' [lang] 补 lang="scss"')
- return first + '\n' + rest
- STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', 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'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|4A9BD7|63B3ED|F5FAFE|F0F8FF)(?![0-9A-Fa-f])', block, re.I)
- residual += re.findall(r'rgba\(91, ?155, ?213', block)
- if residual:
- raise RuntimeError('%s: 替换后仍有残留 %s' % (page, residual))
- src = src[:m.start()] + block + src[m.end():]
- io.open(page, 'w', encoding='utf-8', newline='').write(src)
- n_rep = sum(block.count('$brand-primary') + block.count('$uni-info') + block.count('$uni-primary-pale') for _ in [0])
- total += n_rep
- print(' 残留 0,写盘完成')
- print('四文件处理完毕')
- if __name__ == '__main__':
- sys.exit(main())
|