refactor: remove exact same-file css duplicates

This commit is contained in:
leefer
2026-08-02 14:42:44 +08:00
parent 48c6494e73
commit 656f28a96d
6 changed files with 222 additions and 112 deletions
+1 -1
View File
@@ -1834,7 +1834,7 @@ test("stylesheet layers do not repeat identical rules in the same cascade contex
visitRules(sheet.cssRules, href);
}
return Array.from(occurrences.entries())
.filter(([, paths]) => new Set(paths).size > 1)
.filter(([, paths]) => paths.length > 1)
.map(([rule, paths]) => ({ rule, paths }));
});
+215 -8
View File
@@ -29,11 +29,11 @@ RETIRED_FRONTEND_SOURCE_RANGES = (
)
AUDITED_FRONTEND_SOURCE_LINE_COUNT = 9283
# CR-12 and CR-13 remove only declarations repeated by a later stylesheet
# layer under the same cascade context. Entries are either an exact retired
# fragment or an exact (source, replacement) pair when surrounding context is
# needed to identify one nested occurrence. Every other byte remains part of
# the accepted CSS baseline.
# CR-12 through CR-14 remove only declarations repeated by a later rule under
# the same cascade context. Entries are either an exact retired fragment or an
# exact (source, replacement) pair. Optional trailing values declare the source
# count and how many leading occurrences to transform when an identical later
# copy must remain. Every other byte remains part of the accepted CSS baseline.
AUDITED_CSS_RETIREMENTS = {
"styles.css": (
".workspace-view.active-view {\n display: block;\n}\n\n",
@@ -117,6 +117,55 @@ AUDITED_CSS_RETIREMENTS = {
" .overview-strip .metric:nth-of-type(1) { grid-column: 2; grid-row: 1; }\n",
" .overview-strip .metric:nth-of-type(3) { grid-column: 2; grid-row: 2; }\n",
" .curated-strategy-list {\n grid-template-columns: 1fr;\n }\n\n",
" .quant-universe-grid { grid-template-columns: 1fr 1fr; }\n",
(
" .auction-workspace-layout { grid-template-columns: 1fr; }\n",
"",
2,
1,
),
(
" .auction-unified-table-frame { min-height: 360px; max-height: none; }\n",
"",
2,
1,
),
" .theme-library-layout { display: block; min-height: 0; }\n",
(
".brand-block {\n gap: 10px;\n}\n\n",
"",
2,
1,
),
(
" html,\n"
" body {\n"
" min-width: 320px;\n"
" width: 100%;\n"
" }\n\n",
"",
2,
1,
),
(
" .module-nav .module-tab .lucide {\n"
" width: 20px;\n"
" height: 20px;\n"
" }\n\n",
"",
2,
1,
),
(
" .sentiment-trend-panel {\n"
" border-right: 0;\n"
" border-bottom: 1px solid var(--border);\n"
" }\n\n",
"",
2,
1,
),
" .auction-dataset-segments { min-width: 430px; }\n",
),
"renovation.css": (
".overview-strip .sentiment-block { padding-left: 0; }\n",
@@ -124,6 +173,144 @@ AUDITED_CSS_RETIREMENTS = {
'.overview-strip[data-overview-expanded="true"] .metric-value '
"{ font-size: 18px; }\n\n"
),
(
".curated-strategy-list { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }\n",
"",
2,
1,
),
(
".sentiment-detail-toolbar { margin-top: 0; }\n\n",
"",
2,
1,
),
(
".sentiment-detail-toolbar { margin-top: 0; }\n",
"",
2,
1,
),
".review-workspace .workspace-section + .workspace-section { border-top: 1px solid var(--border); }\n\n",
(
" body,\n"
" body.sidebar-collapsed {\n"
" display: block;\n"
" min-height: 100dvh;\n"
" padding-bottom: calc(68px + env(safe-area-inset-bottom));\n"
" }\n\n",
"",
2,
1,
),
(
" .app-header {\n"
" width: 100%;\n"
" height: 108px;\n"
" min-height: 108px;\n"
" position: relative;\n"
" display: flex;\n"
" align-items: flex-start;\n"
" padding: 8px 10px 0;\n"
" }\n\n",
"",
2,
1,
),
(" .brand-block { height: 42px; }\n", "", 2, 1),
(" .brand-block h1 { font-size: 16px; }\n", "", 2, 1),
(
" .header-actions { position: absolute; inset: 56px 10px auto; display: flex; justify-content: space-between; gap: 6px; }\n",
"",
2,
1,
),
(
" .header-date-group { height: 42px; min-width: 0; flex: 1; }\n",
"",
2,
1,
),
(
" .header-date-group .date-input { width: 104px; flex: 1; }\n",
"",
2,
1,
),
(
" .header-actions > .icon-button { width: 40px; min-width: 40px; min-height: 42px; }\n",
"",
2,
1,
),
(
" .module-nav,\n"
" body.sidebar-collapsed .module-nav {\n"
" width: 100%;\n"
" height: calc(64px + env(safe-area-inset-bottom));\n"
" min-height: 64px;\n"
" position: fixed;\n"
" inset: auto 0 0;\n"
" z-index: 45;\n"
" display: grid;\n"
" grid-template-columns: repeat(5, minmax(0, 1fr));\n"
" align-items: stretch;\n"
" padding: 4px 4px max(4px, env(safe-area-inset-bottom));\n"
" overflow: hidden;\n"
" border-top: 1px solid var(--border);\n"
" border-right: 0;\n"
" background: rgba(255, 255, 255, .98);\n"
" box-shadow: 0 -5px 18px rgba(16, 24, 40, .08);\n"
" }\n\n",
"",
2,
1,
),
(
" .app-main { width: 100%; min-height: calc(100dvh - 176px); margin: 0; padding: 10px 8px 20px; }\n",
"",
2,
1,
),
(
" .workspace-view,\n"
' body[data-active-view="screenerView"] .workspace-view,\n'
' body[data-active-view="mentorView"] .workspace-view,\n'
' body[data-active-view="reviewWorkspaceView"] .workspace-view { padding: 0 0 76px; }\n',
"",
2,
1,
),
(".insight-rail { gap: 12px; }\n", "", 2, 1),
("#screenerView .screener-strategy-view { gap: 12px; }\n", "", 2, 1),
(".mentor-chat-form .button { min-height: 38px; }\n\n", "", 2, 1),
(
".review-workspace .notes-history-section { grid-area: notes; }\n",
"",
3,
2,
),
(
".sentiment-stage-guide-grid article.current strong,\n"
".sentiment-stage-guide-grid article.current small { color: var(--danger); }\n",
"",
2,
1,
),
(
".review-workspace {\n"
" grid-template-columns: minmax(0, 1fr) 360px;\n"
' grid-template-areas: "watch journal" "trades journal" "notes notes";\n'
" align-items: start;\n"
" gap: 12px;\n"
"}\n",
"",
2,
1,
),
(".review-workspace .watchlist-section { grid-area: watch; }\n", "", 2, 1),
(".review-workspace .journal-section { grid-area: journal; }\n", "", 2, 1),
(".review-workspace .trade-journal-section { grid-area: trades; }\n", "", 2, 1),
),
"redesign-v2.css": (
"#dragonView .dragon-operation-table .dragon-col-reason { width: auto; }\n",
@@ -148,6 +335,22 @@ AUDITED_CSS_RETIREMENTS = {
" .overview-strip .metric-wide { display: none; }\n"
" .overview-toggle { display: none; }\n"
),
(
(
" #screenerView .quant-summary-pane .quant-universe-grid,\n"
" #screenerView .quant-formula-summary,\n"
" #screenerView .quant-execution-actions { grid-template-columns: 1fr; }\n"
" #screenerView .quant-score-row,\n"
" #screenerView .quant-filter-row { grid-template-columns: 1fr; }\n"
" #screenerTrackingView { padding: 10px; }\n"
),
(
" #screenerView .quant-summary-pane .quant-universe-grid,\n"
" #screenerView .quant-formula-summary,\n"
" #screenerView .quant-execution-actions { grid-template-columns: 1fr; }\n"
" #screenerTrackingView { padding: 10px; }\n"
),
),
),
}
@@ -351,9 +554,13 @@ def assert_moved_asset_matches(
):
original = (ORIGINAL_STATIC / original_relative).read_text(encoding="utf-8")
for retired in AUDITED_CSS_RETIREMENTS.get(original_relative, ()):
source, replacement = retired if isinstance(retired, tuple) else (retired, "")
testcase.assertEqual(original.count(source), 1, source)
original = original.replace(source, replacement, 1)
source, replacement, *count_override = (
retired if isinstance(retired, tuple) else (retired, "")
)
expected_count = count_override[0] if count_override else 1
replacement_count = count_override[1] if len(count_override) > 1 else 1
testcase.assertEqual(original.count(source), expected_count, source)
original = original.replace(source, replacement, replacement_count)
for replacement in AUDITED_CSS_REPLACEMENTS.get(original_relative, ()):
source, target, *count_override = replacement
expected_count = count_override[0] if count_override else 1