webcode-tk 1.2.6__tar.gz → 1.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/PKG-INFO +2 -2
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/pyproject.toml +2 -2
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/__init__.py +6 -1
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/contrast_tools.py +55 -4
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/css_tools.py +8 -1
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/LICENSE.rst +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/README.rst +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/animation_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/cascade_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/color_keywords.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/color_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/font_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/html_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/sample_report.json +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/utils.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/ux_tools.py +0 -0
- {webcode_tk-1.2.6 → webcode_tk-1.2.7}/webcode_tk/validator_tools.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "webcode-tk"
|
|
3
|
-
version = "1.2.
|
|
4
|
-
description = ""
|
|
3
|
+
version = "1.2.7"
|
|
4
|
+
description = "A set of tools for inspecting HTML and CSS code"
|
|
5
5
|
authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
|
|
6
6
|
keywords = ["html", "validation", "css", ]
|
|
7
7
|
license = "MIT"
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
- **`color_tools`**: processes CSS color related properties and values.
|
|
18
18
|
|
|
19
|
+
- **`contrast_tools`**: calculates contrast results taking into account how
|
|
20
|
+
the background is invisible, but still affects contrast on elements
|
|
21
|
+
even if those elements do not have a background color explicitly
|
|
22
|
+
applied. It also only checks elements with text in the innerHTML.
|
|
23
|
+
|
|
19
24
|
- **`css_tools`**: creates Stylesheet objects that store CSS information.
|
|
20
25
|
|
|
21
26
|
- **`font_tools`**: A collection of functions used to process font-related
|
|
@@ -35,4 +40,4 @@
|
|
|
35
40
|
- **`validator_tools`**: sends HTML or CSS code to the W3C Validator to check
|
|
36
41
|
for errors.
|
|
37
42
|
"""
|
|
38
|
-
__version__ = "1.2.
|
|
43
|
+
__version__ = "1.2.7"
|
|
@@ -158,7 +158,8 @@ def generate_contrast_report(
|
|
|
158
158
|
msg = f"{result}: in {current_file}, the {element} failed WCAG "
|
|
159
159
|
msg += f"{wcag_level} contrast requirements (ratio: "
|
|
160
160
|
msg += f"{actual_ratio}, required: {target_ratio})."
|
|
161
|
-
project_files[current_file]
|
|
161
|
+
if msg not in project_files[current_file]:
|
|
162
|
+
project_files[current_file].append(msg)
|
|
162
163
|
|
|
163
164
|
# Check for html docs with no fails.
|
|
164
165
|
for file in project_files:
|
|
@@ -182,6 +183,7 @@ def generate_contrast_report(
|
|
|
182
183
|
msg = f"fail: in {file}, {error_msg.strip()}"
|
|
183
184
|
else:
|
|
184
185
|
msg = f"pass: {file} passes color contrast."
|
|
186
|
+
|
|
185
187
|
report.append(msg)
|
|
186
188
|
return report
|
|
187
189
|
|
|
@@ -402,6 +404,9 @@ def analyze_css(
|
|
|
402
404
|
filename = html_doc["filename"]
|
|
403
405
|
soup = html_doc["soup"]
|
|
404
406
|
|
|
407
|
+
# Check to see if background color was set globally
|
|
408
|
+
global_bg = detect_document_background(project_path, filename)
|
|
409
|
+
|
|
405
410
|
# Check for CSS sources and create warnings if needed
|
|
406
411
|
warnings = []
|
|
407
412
|
|
|
@@ -417,7 +422,7 @@ def analyze_css(
|
|
|
417
422
|
)
|
|
418
423
|
|
|
419
424
|
# Step 1: Apply default styles to all elements
|
|
420
|
-
default_styles = apply_browser_defaults(soup)
|
|
425
|
+
default_styles = apply_browser_defaults(soup, default_bg=global_bg)
|
|
421
426
|
|
|
422
427
|
# Find CSS rules specific to this HTML document
|
|
423
428
|
doc_css_rules = get_css_rules_for_document(filename, css_files)
|
|
@@ -468,6 +473,47 @@ def analyze_css(
|
|
|
468
473
|
return doc_results
|
|
469
474
|
|
|
470
475
|
|
|
476
|
+
def detect_document_background(project_path: str, filename: str) -> str:
|
|
477
|
+
"""
|
|
478
|
+
Detect global background color from CSS rules for this document.
|
|
479
|
+
|
|
480
|
+
Args:
|
|
481
|
+
project_path: Path to project root
|
|
482
|
+
filename: Name of current HTML file
|
|
483
|
+
|
|
484
|
+
Returns:
|
|
485
|
+
str: Background color hex value, or DEFAULT_GLOBAL_BACKGROUND if
|
|
486
|
+
none found
|
|
487
|
+
"""
|
|
488
|
+
# Get global colors for entire project
|
|
489
|
+
global_colors = css_tools.get_project_global_colors(project_path)
|
|
490
|
+
|
|
491
|
+
# Find entry for this specific HTML file
|
|
492
|
+
for file_path, color_data_list in global_colors.items():
|
|
493
|
+
# Match filename (handle both full path and just filename)
|
|
494
|
+
if filename in file_path:
|
|
495
|
+
# color_data_list is a list of dicts with global selector info
|
|
496
|
+
if isinstance(color_data_list, dict):
|
|
497
|
+
color_data_list = [
|
|
498
|
+
color_data_list,
|
|
499
|
+
]
|
|
500
|
+
for color_data in color_data_list:
|
|
501
|
+
# Look for body selector specifically
|
|
502
|
+
if color_data.get("selector") == "body":
|
|
503
|
+
bg_color = color_data.get("background-color")
|
|
504
|
+
if bg_color:
|
|
505
|
+
return bg_color
|
|
506
|
+
|
|
507
|
+
# Also check for html or * selectors
|
|
508
|
+
if color_data.get("selector") in ["html", "*"]:
|
|
509
|
+
bg_color = color_data.get("background-color")
|
|
510
|
+
if bg_color:
|
|
511
|
+
return bg_color
|
|
512
|
+
|
|
513
|
+
# No global background found, use default white
|
|
514
|
+
return DEFAULT_GLOBAL_BACKGROUND
|
|
515
|
+
|
|
516
|
+
|
|
471
517
|
def has_any_css_sources(soup: BeautifulSoup) -> bool:
|
|
472
518
|
"""
|
|
473
519
|
Check if HTML document has any CSS sources (external or internal).
|
|
@@ -495,7 +541,9 @@ def has_any_css_sources(soup: BeautifulSoup) -> bool:
|
|
|
495
541
|
return False
|
|
496
542
|
|
|
497
543
|
|
|
498
|
-
def apply_browser_defaults(
|
|
544
|
+
def apply_browser_defaults(
|
|
545
|
+
soup: BeautifulSoup, default_bg: str = DEFAULT_GLOBAL_BACKGROUND
|
|
546
|
+
) -> dict:
|
|
499
547
|
"""
|
|
500
548
|
Apply browser default styles to all elements with text content.
|
|
501
549
|
|
|
@@ -516,7 +564,7 @@ def apply_browser_defaults(soup: BeautifulSoup) -> dict:
|
|
|
516
564
|
"is_default": True,
|
|
517
565
|
},
|
|
518
566
|
"background-color": {
|
|
519
|
-
"value":
|
|
567
|
+
"value": default_bg,
|
|
520
568
|
"specificity": default_specificity,
|
|
521
569
|
"source": "default",
|
|
522
570
|
"is_default": True,
|
|
@@ -1627,4 +1675,7 @@ if __name__ == "__main__":
|
|
|
1627
1675
|
project_path = "tests/test_files/large_project/"
|
|
1628
1676
|
project_path = "tests/test_files/contrast_tool_test/"
|
|
1629
1677
|
contrast_results = generate_contrast_report(project_path, "AAA")
|
|
1678
|
+
project_path = "tests/test_files/contrast_tool_test/"
|
|
1679
|
+
global_colors = css_tools.get_project_global_colors(project_path)
|
|
1680
|
+
print(global_colors)
|
|
1630
1681
|
print(contrast_results)
|
|
@@ -2458,7 +2458,10 @@ def get_global_color_report(project_dir: str, level="aaa") -> list:
|
|
|
2458
2458
|
if global_color_data:
|
|
2459
2459
|
for item in global_color_data:
|
|
2460
2460
|
file, result = get_color_data(filename, item, level)
|
|
2461
|
-
|
|
2461
|
+
if "fail" in result:
|
|
2462
|
+
passes.append(f"fail: {file} {result}")
|
|
2463
|
+
else:
|
|
2464
|
+
passes.append(f"pass: {file} {result}")
|
|
2462
2465
|
if passes:
|
|
2463
2466
|
details = ""
|
|
2464
2467
|
for detail in passes:
|
|
@@ -2877,3 +2880,7 @@ if __name__ == "__main__":
|
|
|
2877
2880
|
rulesets = get_element_rulesets(
|
|
2878
2881
|
"tests/test_files/cascade_complexities", "figure"
|
|
2879
2882
|
)
|
|
2883
|
+
passing_global_colors = get_global_color_report(project_folder)
|
|
2884
|
+
project_path = "tests/test_files/contrast_tool_test/"
|
|
2885
|
+
global_colors = get_global_color_report(project_path)
|
|
2886
|
+
print(global_colors)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|