refactor: decompose CSS, unify dark mode, extract shared modules

Structural cleanup based on thermo-nuclear code quality review:
- Extract shared color-picker.css and color-popover.css from badges.css (611→85 lines)
- Extract shared lib/presets.js for preset CRUD used by popup and popover
- Unify dark mode to single applyDarkModeClass on <html>, removing 4 scattered functions
- Fix stale closure in startPostObserver, data-driven reload key check
- Remove dead exports, getHelpers wrapper, duplicated colorToHex
- Replace DOM expando properties with state array in popup.js

Net: -318 lines of duplication, no file over 401 lines.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 01:39:25 -04:00
parent 80689c6f8d
commit 00507fe87c
15 changed files with 826 additions and 1012 deletions

View File

@@ -83,529 +83,3 @@ html.rt-badges-enabled .thing.link .flat-list li:has(> .comments) {
.rt-badge-gear:hover {
opacity: 1 !important;
}
/* --- Color popover --- */
.rt-color-popover {
position: absolute;
z-index: 10000;
background: #fff;
border: 1px solid #ccc;
border-radius: 6px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
padding: 12px;
width: 260px;
overflow-y: auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
font-size: 13px;
color: #1a1a1a;
display: none;
}
.rt-color-popover.rt-popover-visible {
display: block;
}
.rt-popover-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
padding-bottom: 6px;
border-bottom: 1px solid #eee;
}
.rt-popover-title {
font-weight: 600;
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 200px;
}
.rt-popover-close {
background: none;
border: none;
font-size: 16px;
cursor: pointer;
color: #999;
padding: 0 2px;
line-height: 1;
}
.rt-popover-close:hover {
color: #333;
}
.rt-popover-mode {
margin-bottom: 8px;
}
.rt-popover-mode select {
width: 100%;
padding: 3px 6px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 12px;
font-family: inherit;
}
.rt-popover-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
}
.rt-popover-row-label {
font-size: 12px;
flex-shrink: 0;
margin-right: 8px;
}
.rt-popover-row-inputs {
display: flex;
align-items: center;
gap: 4px;
}
.rt-popover-row .rt-color-swatch {
width: 28px;
height: 20px;
border: 1px solid #ccc;
border-radius: 3px;
cursor: pointer;
display: inline-block;
vertical-align: middle;
}
.rt-popover-row input[type="text"] {
width: 70px;
padding: 2px 4px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 12px;
font-family: monospace;
}
.rt-popover-row input[type="text"].rt-input-error {
border-color: #d9534f;
}
.rt-popover-preview {
margin: 8px 0;
padding: 6px 0;
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
text-align: center;
}
.rt-popover-footer {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 8px;
gap: 6px;
}
.rt-popover-footer-right {
display: flex;
gap: 6px;
}
.rt-btn-save {
background: #4a90d9;
color: #fff;
border: 1px solid #3a7bc8;
border-radius: 3px;
padding: 4px 12px;
font-size: 12px;
cursor: pointer;
}
.rt-btn-save:hover {
background: #3a7bc8;
}
.rt-btn-cancel {
background: #f0f0f0;
border: 1px solid #ccc;
border-radius: 3px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
}
.rt-btn-cancel:hover {
background: #e0e0e0;
}
.rt-btn-reset {
background: none;
border: 1px solid #ccc;
border-radius: 3px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
color: #666;
}
.rt-btn-reset:hover {
background: #f5f5f5;
color: #333;
}
/* --- Popover dark mode --- */
.rt-color-popover.rt-dark {
background: #2a2a2a;
border-color: #555;
color: #e0e0e0;
}
.rt-color-popover.rt-dark .rt-popover-header {
border-bottom-color: #444;
}
.rt-color-popover.rt-dark .rt-popover-close {
color: #888;
}
.rt-color-popover.rt-dark .rt-popover-close:hover {
color: #ccc;
}
.rt-color-popover.rt-dark .rt-popover-mode select {
background: #333;
border-color: #555;
color: #e0e0e0;
}
.rt-color-popover.rt-dark .rt-popover-row .rt-color-swatch {
border-color: #555;
}
.rt-color-popover.rt-dark .rt-popover-row input[type="text"] {
background: #333;
border-color: #555;
color: #e0e0e0;
}
.rt-color-popover.rt-dark .rt-popover-preview {
border-top-color: #444;
border-bottom-color: #444;
}
.rt-color-popover.rt-dark .rt-btn-save {
background: #4a90d9;
border-color: #3a7bc8;
}
.rt-color-popover.rt-dark .rt-btn-cancel {
background: #444;
border-color: #555;
color: #ccc;
}
.rt-color-popover.rt-dark .rt-btn-reset {
border-color: #555;
color: #999;
}
.rt-color-popover.rt-dark .rt-btn-reset:hover {
background: #333;
color: #ccc;
}
/* --- Preset badges --- */
.rt-popover-presets {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 0;
border-top: 1px solid #eee;
flex-wrap: wrap;
}
.rt-preset-list {
display: flex;
gap: 4px;
flex-wrap: wrap;
}
.rt-preset-badge {
display: inline-block;
position: relative;
border: 1px solid;
border-radius: 3px;
padding: 2px 6px;
font-size: 10px;
font-weight: bold;
cursor: pointer;
line-height: 1.4;
user-select: none;
}
.rt-preset-badge:hover {
filter: brightness(1.1);
}
.rt-preset-delete {
display: none;
position: absolute;
top: -6px;
right: -6px;
width: 14px;
height: 14px;
background: #d9534f;
color: white;
border-radius: 50%;
font-size: 10px;
line-height: 14px;
text-align: center;
cursor: pointer;
}
.rt-preset-badge:hover .rt-preset-delete {
display: block;
}
.rt-preset-add {
width: 22px;
height: 22px;
border: 1px dashed #ccc;
border-radius: 3px;
background: none;
color: #999;
font-size: 14px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
padding: 0;
}
.rt-preset-add:hover {
border-color: #999;
color: #666;
background: #f5f5f5;
}
.rt-color-popover.rt-dark .rt-popover-presets {
border-top-color: #444;
}
.rt-color-popover.rt-dark .rt-preset-add {
border-color: #555;
color: #888;
}
.rt-color-popover.rt-dark .rt-preset-add:hover {
border-color: #888;
color: #ccc;
background: #333;
}
/* --- Color Picker Widget --- */
.rt-color-picker {
margin: 8px 0;
font-size: 12px;
}
.rt-picker-tabs {
display: flex;
border-bottom: 1px solid #ccc;
margin-bottom: 8px;
}
.rt-picker-tab {
flex: 1;
padding: 4px 8px;
background: none;
border: none;
border-bottom: 2px solid transparent;
font-size: 11px;
font-family: inherit;
cursor: pointer;
color: #666;
}
.rt-picker-tab:hover {
color: #333;
}
.rt-picker-tab--active {
color: #1a1a1a;
border-bottom-color: #4a90d9;
font-weight: 600;
}
.rt-picker-panel {
max-height: 180px;
overflow-y: auto;
}
.rt-picker-grid--palette {
display: flex;
flex-direction: column;
gap: 2px;
}
.rt-picker-grid-row {
display: flex;
gap: 2px;
}
.rt-picker-swatch {
width: 16px;
height: 16px;
border-radius: 2px;
border: 1px solid rgba(0, 0, 0, 0.1);
cursor: pointer;
flex-shrink: 0;
}
.rt-picker-swatch:hover {
border-color: rgba(0, 0, 0, 0.4);
transform: scale(1.2);
z-index: 1;
position: relative;
}
.rt-picker-swatch--selected {
border: 2px solid #1a1a1a;
box-shadow: 0 0 0 1px white;
}
.rt-picker-grid--named {
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 2px 0;
}
.rt-picker-named-item {
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
width: 40px;
}
.rt-picker-named-item .rt-picker-swatch {
width: 24px;
height: 18px;
}
.rt-picker-named-label {
font-size: 8px;
color: #888;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
line-height: 1.2;
}
.rt-picker-panel--custom {
max-height: none;
overflow: visible;
}
.rt-picker-sv-wrap {
position: relative;
margin-bottom: 6px;
}
.rt-picker-sv {
display: block;
width: 100%;
border: 1px solid #ccc;
border-radius: 3px;
cursor: crosshair;
}
.rt-picker-sv-cursor {
position: absolute;
width: 10px;
height: 10px;
border: 2px solid white;
border-radius: 50%;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
pointer-events: none;
transform: translate(-50%, -50%);
}
.rt-picker-hue {
position: relative;
height: 14px;
border: 1px solid #ccc;
border-radius: 3px;
background: linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
cursor: crosshair;
}
.rt-picker-hue-indicator {
position: absolute;
top: -1px;
width: 2px;
height: calc(100% + 2px);
background: white;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
pointer-events: none;
transform: translateX(-50%);
}
/* Picker dark mode */
.rt-dark .rt-picker-tabs,
.rt-color-popover.rt-dark .rt-picker-tabs {
border-bottom-color: #555;
}
.rt-dark .rt-picker-tab,
.rt-color-popover.rt-dark .rt-picker-tab {
color: #999;
}
.rt-dark .rt-picker-tab:hover,
.rt-color-popover.rt-dark .rt-picker-tab:hover {
color: #ccc;
}
.rt-dark .rt-picker-tab--active,
.rt-color-popover.rt-dark .rt-picker-tab--active {
color: #e0e0e0;
border-bottom-color: #4a90d9;
}
.rt-dark .rt-picker-swatch,
.rt-color-popover.rt-dark .rt-picker-swatch {
border-color: rgba(255, 255, 255, 0.1);
}
.rt-dark .rt-picker-swatch:hover,
.rt-color-popover.rt-dark .rt-picker-swatch:hover {
border-color: rgba(255, 255, 255, 0.4);
}
.rt-dark .rt-picker-swatch--selected,
.rt-color-popover.rt-dark .rt-picker-swatch--selected {
border-color: #e0e0e0;
box-shadow: 0 0 0 1px #333;
}
.rt-dark .rt-picker-named-label,
.rt-color-popover.rt-dark .rt-picker-named-label {
color: #777;
}
.rt-dark .rt-picker-sv,
.rt-color-popover.rt-dark .rt-picker-sv {
border-color: #555;
}
.rt-dark .rt-picker-hue,
.rt-color-popover.rt-dark .rt-picker-hue {
border-color: #555;
}

View File

@@ -0,0 +1,259 @@
/* --- Color Picker Widget --- */
.rt-color-picker {
margin: 8px 0;
font-size: 12px;
}
.rt-picker-tabs {
display: flex;
border-bottom: 1px solid #ccc;
margin-bottom: 8px;
}
.rt-picker-tab {
flex: 1;
padding: 4px 8px;
background: none;
border: none;
border-bottom: 2px solid transparent;
font-size: 11px;
font-family: inherit;
cursor: pointer;
color: #666;
}
.rt-picker-tab:hover {
color: #333;
}
.rt-picker-tab--active {
color: #1a1a1a;
border-bottom-color: #4a90d9;
font-weight: 600;
}
.rt-picker-panel {
max-height: 180px;
overflow-y: auto;
}
.rt-picker-grid--palette {
display: flex;
flex-direction: column;
gap: 2px;
}
.rt-picker-grid-row {
display: flex;
gap: 2px;
}
.rt-picker-swatch {
width: 16px;
height: 16px;
border-radius: 2px;
border: 1px solid rgba(0, 0, 0, 0.1);
cursor: pointer;
flex-shrink: 0;
}
.rt-picker-swatch:hover {
border-color: rgba(0, 0, 0, 0.4);
transform: scale(1.2);
z-index: 1;
position: relative;
}
.rt-picker-swatch--selected {
border: 2px solid #1a1a1a;
box-shadow: 0 0 0 1px white;
}
.rt-picker-grid--named {
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 2px 0;
}
.rt-picker-named-item {
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
width: 40px;
}
.rt-picker-named-item .rt-picker-swatch {
width: 24px;
height: 18px;
}
.rt-picker-named-label {
font-size: 8px;
color: #888;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
line-height: 1.2;
}
.rt-picker-panel--custom {
max-height: none;
overflow: visible;
}
.rt-picker-sv-wrap {
position: relative;
margin-bottom: 6px;
}
.rt-picker-sv {
display: block;
width: 100%;
border: 1px solid #ccc;
border-radius: 3px;
cursor: crosshair;
}
.rt-picker-sv-cursor {
position: absolute;
width: 10px;
height: 10px;
border: 2px solid white;
border-radius: 50%;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
pointer-events: none;
transform: translate(-50%, -50%);
}
.rt-picker-hue {
position: relative;
height: 14px;
border: 1px solid #ccc;
border-radius: 3px;
background: linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
cursor: crosshair;
}
.rt-picker-hue-indicator {
position: absolute;
top: -1px;
width: 2px;
height: calc(100% + 2px);
background: white;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
pointer-events: none;
transform: translateX(-50%);
}
/* --- Preset badges --- */
.rt-preset-list {
display: flex;
gap: 4px;
flex-wrap: wrap;
}
.rt-preset-badge {
display: inline-block;
position: relative;
border: 1px solid;
border-radius: 3px;
padding: 2px 6px;
font-size: 10px;
font-weight: bold;
cursor: pointer;
line-height: 1.4;
user-select: none;
}
.rt-preset-badge:hover {
filter: brightness(1.1);
}
.rt-preset-delete {
display: none;
position: absolute;
top: -6px;
right: -6px;
width: 14px;
height: 14px;
background: #d9534f;
color: white;
border-radius: 50%;
font-size: 10px;
line-height: 14px;
text-align: center;
cursor: pointer;
}
.rt-preset-badge:hover .rt-preset-delete {
display: block;
}
.rt-preset-add {
width: 22px;
height: 22px;
border: 1px dashed #ccc;
border-radius: 3px;
background: none;
color: #999;
font-size: 14px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
padding: 0;
}
.rt-preset-add:hover {
border-color: #999;
color: #666;
background: #f5f5f5;
}
/* --- Picker dark mode --- */
.rt-dark .rt-picker-tabs {
border-bottom-color: #555;
}
.rt-dark .rt-picker-tab {
color: #999;
}
.rt-dark .rt-picker-tab:hover {
color: #ccc;
}
.rt-dark .rt-picker-tab--active {
color: #e0e0e0;
border-bottom-color: #4a90d9;
}
.rt-dark .rt-picker-swatch {
border-color: rgba(255, 255, 255, 0.1);
}
.rt-dark .rt-picker-swatch:hover {
border-color: rgba(255, 255, 255, 0.4);
}
.rt-dark .rt-picker-swatch--selected {
border-color: #e0e0e0;
box-shadow: 0 0 0 1px #333;
}
.rt-dark .rt-picker-named-label {
color: #777;
}
.rt-dark .rt-picker-sv {
border-color: #555;
}
.rt-dark .rt-picker-hue {
border-color: #555;
}

View File

@@ -0,0 +1,256 @@
/* --- Color popover --- */
.rt-color-popover {
position: absolute;
z-index: 10000;
background: #fff;
border: 1px solid #ccc;
border-radius: 6px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
padding: 12px;
width: 260px;
overflow-y: auto;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
font-size: 13px;
color: #1a1a1a;
display: none;
}
.rt-color-popover.rt-popover-visible {
display: block;
}
.rt-popover-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
padding-bottom: 6px;
border-bottom: 1px solid #eee;
}
.rt-popover-title {
font-weight: 600;
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 200px;
}
.rt-popover-close {
background: none;
border: none;
font-size: 16px;
cursor: pointer;
color: #999;
padding: 0 2px;
line-height: 1;
}
.rt-popover-close:hover {
color: #333;
}
.rt-popover-mode {
margin-bottom: 8px;
}
.rt-popover-mode select {
width: 100%;
padding: 3px 6px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 12px;
font-family: inherit;
}
.rt-popover-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
}
.rt-popover-row-label {
font-size: 12px;
flex-shrink: 0;
margin-right: 8px;
}
.rt-popover-row-inputs {
display: flex;
align-items: center;
gap: 4px;
}
.rt-popover-row .rt-color-swatch {
width: 28px;
height: 20px;
border: 1px solid #ccc;
border-radius: 3px;
cursor: pointer;
display: inline-block;
vertical-align: middle;
}
.rt-popover-row input[type="text"] {
width: 70px;
padding: 2px 4px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 12px;
font-family: monospace;
}
.rt-popover-row input[type="text"].rt-input-error {
border-color: #d9534f;
}
.rt-popover-preview {
margin: 8px 0;
padding: 6px 0;
border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
text-align: center;
}
.rt-popover-footer {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 8px;
gap: 6px;
}
.rt-popover-footer-right {
display: flex;
gap: 6px;
}
.rt-btn-save {
background: #4a90d9;
color: #fff;
border: 1px solid #3a7bc8;
border-radius: 3px;
padding: 4px 12px;
font-size: 12px;
cursor: pointer;
}
.rt-btn-save:hover {
background: #3a7bc8;
}
.rt-btn-cancel {
background: #f0f0f0;
border: 1px solid #ccc;
border-radius: 3px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
}
.rt-btn-cancel:hover {
background: #e0e0e0;
}
.rt-btn-reset {
background: none;
border: 1px solid #ccc;
border-radius: 3px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
color: #666;
}
.rt-btn-reset:hover {
background: #f5f5f5;
color: #333;
}
/* --- Popover preset container --- */
.rt-popover-presets {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 0;
border-top: 1px solid #eee;
flex-wrap: wrap;
}
/* --- Popover dark mode --- */
.rt-dark .rt-color-popover {
background: #2a2a2a;
border-color: #555;
color: #e0e0e0;
}
.rt-dark .rt-popover-header {
border-bottom-color: #444;
}
.rt-dark .rt-popover-close {
color: #888;
}
.rt-dark .rt-popover-close:hover {
color: #ccc;
}
.rt-dark .rt-popover-mode select {
background: #333;
border-color: #555;
color: #e0e0e0;
}
.rt-dark .rt-popover-row .rt-color-swatch {
border-color: #555;
}
.rt-dark .rt-popover-row input[type="text"] {
background: #333;
border-color: #555;
color: #e0e0e0;
}
.rt-dark .rt-popover-preview {
border-top-color: #444;
border-bottom-color: #444;
}
.rt-dark .rt-btn-save {
background: #4a90d9;
border-color: #3a7bc8;
}
.rt-dark .rt-btn-cancel {
background: #444;
border-color: #555;
color: #ccc;
}
.rt-dark .rt-btn-reset {
border-color: #555;
color: #999;
}
.rt-dark .rt-btn-reset:hover {
background: #333;
color: #ccc;
}
.rt-dark .rt-popover-presets {
border-top-color: #444;
}
.rt-dark .rt-preset-add {
border-color: #555;
color: #888;
}
.rt-dark .rt-preset-add:hover {
border-color: #888;
color: #ccc;
background: #333;
}