72 lines
3.0 KiB
Python
72 lines
3.0 KiB
Python
"""Dependency-free candidate arithmetic only; writes JSON to stdout, no rendering."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def rgb(value):
|
|
return tuple(int(value[i:i + 2], 16) / 255 for i in (0, 2, 4))
|
|
|
|
|
|
def luminance(color):
|
|
return sum(w * (v / 12.92 if v <= .04045 else ((v + .055) / 1.055) ** 2.4)
|
|
for w, v in zip((.2126, .7152, .0722), color))
|
|
|
|
|
|
def ratio(first, second):
|
|
low, high = sorted((luminance(first), luminance(second)))
|
|
return (high + .05) / (low + .05)
|
|
|
|
|
|
BG = (.945, .956, .969)
|
|
WHITE = rgb('FFFFFF')
|
|
CANDIDATES = {
|
|
'S1_keep_BG': (BG, '7A8C85', {
|
|
'keyword': '29123A', 'identifier': '031F32', 'string': '032215',
|
|
'number': '331404', 'comment': '1A1D20', 'error': '3E060F',
|
|
'punctuation_and_whitespace': '191D23', 'fallback_and_caret': '1A1E22',
|
|
}),
|
|
'S2_white_editor': (WHITE, '80958B', {
|
|
'keyword': '331748', 'identifier': '04273D', 'string': '042A1B',
|
|
'number': '3F1A06', 'comment': '212529', 'error': '4C0914',
|
|
'punctuation_and_whitespace': '20252C', 'fallback_and_caret': '212529',
|
|
}),
|
|
}
|
|
|
|
result = {'kind': 'proposed opaque source colors; no native or compiled evidence',
|
|
'candidates': {}, 'input_hashes': []}
|
|
for name, (surface, selection_hex, tokens) in CANDIDATES.items():
|
|
selection = rgb(selection_hex)
|
|
pairs = [{'class': cls, 'hex': value,
|
|
'normal_ratio': ratio(rgb(value), surface),
|
|
'selected_ratio': ratio(rgb(value), selection)}
|
|
for cls, value in tokens.items()]
|
|
fill_ratio = ratio(selection, surface)
|
|
assert fill_ratio >= 3
|
|
assert all(p['normal_ratio'] >= 4.5 and p['selected_ratio'] >= 4.5 for p in pairs)
|
|
result['candidates'][name] = {
|
|
'surface_rgb': surface, 'selection_hex': selection_hex,
|
|
'selection_surface_ratio': fill_ratio, 'tokens': pairs,
|
|
}
|
|
result['range_aware_hypothesis'] = {
|
|
'selection_hex': '00665C', 'selected_foreground_hex': 'FFFFFF',
|
|
'fill_BG_ratio': ratio(rgb('00665C'), BG),
|
|
'selected_text_ratio': ratio(WHITE, rgb('00665C')),
|
|
'stale_selected_text_on_blurred_white_surface': ratio(WHITE, WHITE),
|
|
}
|
|
result['wrong_fallback_controls'] = {
|
|
name: ratio(rgb('202C3A'), rgb(selection))
|
|
for name, (_, selection, _) in CANDIDATES.items()
|
|
}
|
|
paths = [Path(__file__), Path('crates/oa-desktop/src/highlight.rs'),
|
|
Path('crates/oa-desktop/src/style.rs'), Path('crates/oa-desktop/src/views.rs')]
|
|
registry = Path('.local/toolchain/cargo/registry/src/index.crates.io-1949cf8c6b5b557f')
|
|
paths += [registry / path for path in (
|
|
'iced_widget-0.14.2/src/text_editor.rs', 'iced_core-0.14.0/src/text/highlighter.rs',
|
|
'iced_graphics-0.14.0/src/text/editor.rs', 'cosmic-text-0.15.0/src/edit/mod.rs',
|
|
'iced_core-0.14.0/src/theme.rs', 'iced_core-0.14.0/src/theme/palette.rs')]
|
|
for path in paths:
|
|
result['input_hashes'].append({'path': str(path),
|
|
'sha256': hashlib.sha256(path.read_bytes()).hexdigest()})
|
|
print(json.dumps(result, indent=2))
|