#!/usr/bin/env python # -*- coding: utf-8 -*- """C-2a-4a 旧蓝分流·跨面长尾第一批:teacher 7 + profile 6 + 散页 5 = 18 文件 30 处 三分法同 C-2a-3;徽章配浅蓝底(#EAF4FC/#f0f7ff)→ $uni-info 保 coherent; vis-option.active 选中态浅底 #E8F4FD → $uni-primary-pale(与橙边框成套); JS/模板数据色按各自上下文(FamilyRelationGraph home 槽 / DimensionArticles 渐变槽)。 """ import io import re import sys ORANGE = '$brand-primary' ORANGE_DARK = '$brand-primary-dark' ORANGE_LIGHT = '$brand-primary-light' INFO = '$uni-info' PALE = '$uni-primary-pale' GRAD_DARK = 'linear-gradient(135deg, #5B9BD5, #3A7CC4)' GRAD_DARK2 = 'linear-gradient(135deg, #5B9BD5, #3A7CC2)' GRAD_LIGHT = 'linear-gradient(135deg, #5B9BD5, #8FC5E8)' PAGES = { # ---- teacher 集群 ---- 'pages/teacher/review-family.vue': { 'blocks': [('.badge', [('color: #4A9BD7', 'color: ' + INFO)])], 'global': [('#4A9BD7', ORANGE)], 'script': [], }, 'pages/teacher/review-workbench.vue': { 'blocks': [('.badge', [('color: #4A9BD7', 'color: ' + INFO)])], 'global': [], 'script': [], }, 'pages/teacher/plan-detail.vue': { 'blocks': [], 'global': [('#4A9BD7', ORANGE)], 'script': [], }, 'pages/teacher/plan-list.vue': { 'blocks': [], 'global': [('#4A9BD7', ORANGE)], 'script': [], }, 'pages/teacher/plan-create.vue': { 'blocks': [], 'global': [('#4A9BD7', ORANGE)], 'script': [], }, 'pages/teacher/index.vue': { 'blocks': [], 'global': [('#5B9BD5', ORANGE)], 'script': [], }, 'pages/teacher/families.vue': { 'blocks': [], 'global': [('#4A9BD7', ORANGE)], 'script': [], }, # ---- profile 集群 ---- 'pages/profile-extra/gates.vue': { 'blocks': [], 'global': [('#5B9BD5', ORANGE)], 'script': [], }, 'pages/profile/report-detail.vue': { 'blocks': [], 'global': [('#5B9BD5', ORANGE)], 'script': [], }, 'pages/profile/components/ProfileMenu.vue': { 'blocks': [], 'global': [('#5B9BD5', INFO)], # style 块仅 intent-reselect-link 一处(链接→info) 'script': [('color="#5B9BD5"', 'color="#F97316"', 1)], # 模板 switch 组件色 }, 'pages/profile-extra/coupons.vue': { 'blocks': [], 'global': [ ('color: #5B9BD5', 'color: ' + INFO), # card-scope 徽章(配 #f0f7ff 浅蓝底) ('background: #5B9BD5', 'background: ' + ORANGE), # member-guide-btn 主按钮 ], 'script': [], }, 'pages/profile/report-management.vue': { 'blocks': [], 'global': [('#5B9BD5', ORANGE)], 'script': [], }, 'pages/profile/index.vue': { 'blocks': [], 'global': [(GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK))], 'script': [], }, # ---- 散页 ---- 'pages/home-pages/member-home-detail.vue': { 'blocks': [], 'global': [ (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)), ('#5B9BD5', ORANGE), ], 'script': [], }, 'pages/article-center/article-edit.vue': { 'blocks': [], 'global': [ ('#E8F4FD', PALE), # vis-option.active 选中态浅底(与橙边框成套) ('#5B9BD5', ORANGE), ], 'script': [], }, 'components/gate-lock.vue': { 'blocks': [], 'global': [(GRAD_DARK2, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK))], 'script': [], }, 'components/FamilyRelationGraph.vue': { 'blocks': [], 'global': [], 'script': [("home: '#5B9BD5',", "home: '#F97316',", 1)], }, 'components/DimensionArticles.vue': { 'blocks': [], 'global': [], 'script': [(GRAD_LIGHT, "'linear-gradient(135deg, %s, %s)'" % (ORANGE, ORANGE_LIGHT), 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·单行] %-16s %-20s -> %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] %-16s %-20s -> %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(' %-44s -> %-24s 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 '