webcode-tk 0.6.9__tar.gz → 0.7.1__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-0.6.9 → webcode_tk-0.7.1}/PKG-INFO +2 -1
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/pyproject.toml +1 -1
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/__init__.py +1 -1
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/color_tools.py +14 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/css_tools.py +99 -1
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/LICENSE.rst +0 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/README.rst +0 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/color_keywords.py +0 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/html_tools.py +0 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/ux_tools.py +0 -0
- {webcode_tk-0.6.9 → webcode_tk-0.7.1}/webcode_tk/validator_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: webcode-tk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary:
|
|
5
5
|
Home-page: https://github.com/HundredVisionsGuy/webcode-tk
|
|
6
6
|
License: MIT
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
19
|
Requires-Dist: MechanicalSoup (>=1.1.0,<2.0.0)
|
|
19
20
|
Requires-Dist: bs4 (>=0.0.1,<0.0.2)
|
|
20
21
|
Requires-Dist: file-clerk (>=1.0.9,<2.0.0)
|
|
@@ -452,11 +452,25 @@ def is_color_value(val: str) -> bool:
|
|
|
452
452
|
is_valid = True
|
|
453
453
|
elif is_rgb(val):
|
|
454
454
|
is_valid = True
|
|
455
|
+
elif is_keyword(val):
|
|
456
|
+
is_valid = True
|
|
455
457
|
else:
|
|
456
458
|
is_valid = False
|
|
457
459
|
return is_valid
|
|
458
460
|
|
|
459
461
|
|
|
462
|
+
def is_keyword(val: str) -> bool:
|
|
463
|
+
"""checks to see if a value is a color keyword or not
|
|
464
|
+
|
|
465
|
+
Args:
|
|
466
|
+
val: the CSS value in question.
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
is_keyword: if the value is a color keyword or not."""
|
|
470
|
+
is_keyword = val in color_keywords.get_all_keywords()
|
|
471
|
+
return is_keyword
|
|
472
|
+
|
|
473
|
+
|
|
460
474
|
def get_relative_luminance(val: int) -> float:
|
|
461
475
|
"""Returns the relative brightness of a color channel normalized
|
|
462
476
|
to 0 for black and 1 for all white.
|
|
@@ -508,11 +508,13 @@ class Declaration:
|
|
|
508
508
|
self.property = ""
|
|
509
509
|
self.value = ""
|
|
510
510
|
self.invalid_message = ""
|
|
511
|
+
self.is_color = False
|
|
511
512
|
# validate before trying to set the declaration.
|
|
512
513
|
try:
|
|
513
514
|
self.validate_declaration()
|
|
514
515
|
self.is_valid = True
|
|
515
516
|
self.set_declaration()
|
|
517
|
+
self.is_color_property()
|
|
516
518
|
except ValueError as e:
|
|
517
519
|
self.is_valid = False
|
|
518
520
|
self.invalid_message = str(e)
|
|
@@ -632,6 +634,12 @@ class Declaration:
|
|
|
632
634
|
declaration = self.property + ": " + self.value
|
|
633
635
|
return declaration
|
|
634
636
|
|
|
637
|
+
def is_color_property(self):
|
|
638
|
+
value = self.value
|
|
639
|
+
if value[-1] == ";":
|
|
640
|
+
value = value[:-1]
|
|
641
|
+
self.is_color = color_tools.is_color_value(value)
|
|
642
|
+
|
|
635
643
|
|
|
636
644
|
def restore_braces(split: list) -> list:
|
|
637
645
|
"""restore the missing braces removed by the .split() method
|
|
@@ -1230,7 +1238,7 @@ def get_colors_from_gradient(gradient: str) -> list:
|
|
|
1230
1238
|
|
|
1231
1239
|
|
|
1232
1240
|
def get_color_codes_of_type(color_type: str, gradient: str) -> list:
|
|
1233
|
-
"""returns all color codes of a particular type
|
|
1241
|
+
"""returns all color codes of a particular type from a gradient
|
|
1234
1242
|
|
|
1235
1243
|
Args:
|
|
1236
1244
|
color_type: the type of color code it might be (hex, rgb, hsl,
|
|
@@ -1537,6 +1545,96 @@ def adjust_overrides(file_path: str, rules: dict) -> dict:
|
|
|
1537
1545
|
return adjusted_rule
|
|
1538
1546
|
|
|
1539
1547
|
|
|
1548
|
+
def get_all_color_rules(stylesheet: Stylesheet) -> list:
|
|
1549
|
+
"""Gets all color-based rules from a stylesheet.
|
|
1550
|
+
|
|
1551
|
+
Args:
|
|
1552
|
+
stylesheet: Stylesheet object.
|
|
1553
|
+
|
|
1554
|
+
Returns:
|
|
1555
|
+
rules: a list of color-based rules"""
|
|
1556
|
+
rules = []
|
|
1557
|
+
for ruleset in stylesheet.rulesets:
|
|
1558
|
+
declaration_block = ruleset.declaration_block
|
|
1559
|
+
declarations = declaration_block.declarations
|
|
1560
|
+
for declaration in declarations:
|
|
1561
|
+
property = declaration.property
|
|
1562
|
+
if property == "color" or "background" in property:
|
|
1563
|
+
selector = ruleset.selector
|
|
1564
|
+
value = declaration.value
|
|
1565
|
+
if property == "background":
|
|
1566
|
+
background_color = get_background_color(declaration)
|
|
1567
|
+
if not background_color:
|
|
1568
|
+
continue
|
|
1569
|
+
else:
|
|
1570
|
+
value = background_color
|
|
1571
|
+
rules.append((selector, property, value))
|
|
1572
|
+
return rules
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
def get_background_color(declaration: Declaration) -> Union[str, None]:
|
|
1576
|
+
"""Returns a color value from a declaration with a property of background
|
|
1577
|
+
|
|
1578
|
+
Args:
|
|
1579
|
+
declaration: the declaration we want to test.
|
|
1580
|
+
|
|
1581
|
+
Returns:
|
|
1582
|
+
color_value: either a valid color value, None, or gradient - if it's a
|
|
1583
|
+
gradient"""
|
|
1584
|
+
color_value = None
|
|
1585
|
+
is_rgb = color_tools.is_rgb(declaration.value)
|
|
1586
|
+
if is_rgb:
|
|
1587
|
+
return declaration.value
|
|
1588
|
+
values = declaration.value.split()
|
|
1589
|
+
for val in values:
|
|
1590
|
+
color = color_tools.is_color_value(val)
|
|
1591
|
+
if color:
|
|
1592
|
+
color_value = val
|
|
1593
|
+
break
|
|
1594
|
+
is_keyword = val in color_tools.color_keywords.get_all_keywords()
|
|
1595
|
+
if is_keyword:
|
|
1596
|
+
color_value = val
|
|
1597
|
+
break
|
|
1598
|
+
gradient = is_gradient(val)
|
|
1599
|
+
if gradient:
|
|
1600
|
+
color_value = "gradient"
|
|
1601
|
+
break
|
|
1602
|
+
return color_value
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
def condense_the_rules(rules):
|
|
1606
|
+
condensed = []
|
|
1607
|
+
for rule in rules:
|
|
1608
|
+
file, sel, prop, val = rule
|
|
1609
|
+
color = {}
|
|
1610
|
+
background = {}
|
|
1611
|
+
declaration = get_bg_or_color(prop)
|
|
1612
|
+
if declaration.get("type") == "color":
|
|
1613
|
+
color = declaration
|
|
1614
|
+
elif declaration.get("type") == "background":
|
|
1615
|
+
background = declaration
|
|
1616
|
+
if not condensed:
|
|
1617
|
+
condensed.append([file, sel, color, background, val])
|
|
1618
|
+
else:
|
|
1619
|
+
for rule in condensed:
|
|
1620
|
+
cur_file, cur_sel, cur_col, cur_bg_col, cur_val = rule
|
|
1621
|
+
if file == cur_file and sel == cur_sel:
|
|
1622
|
+
# add the property that is missing (if it is missing)
|
|
1623
|
+
print("It's time to work.")
|
|
1624
|
+
return condensed
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
def get_bg_or_color(prop):
|
|
1628
|
+
declaration = {"type": {}, "declaration": {}}
|
|
1629
|
+
if prop == "color":
|
|
1630
|
+
declaration["type"] = "color"
|
|
1631
|
+
declaration["declaration"] = {"color": prop}
|
|
1632
|
+
if "background" in prop:
|
|
1633
|
+
declaration["type"] = "background"
|
|
1634
|
+
declaration["declaration"] = {"background": prop}
|
|
1635
|
+
return declaration
|
|
1636
|
+
|
|
1637
|
+
|
|
1540
1638
|
if __name__ == "__main__":
|
|
1541
1639
|
insane_gradient = """
|
|
1542
1640
|
-moz-radial-gradient(0% 200%, ellipse cover,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|