dashlab 0.3.6__tar.gz → 0.3.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.
- {dashlab-0.3.6 → dashlab-0.3.7}/PKG-INFO +1 -1
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/_version.py +1 -1
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/utils.py +22 -7
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/PKG-INFO +1 -1
- {dashlab-0.3.6 → dashlab-0.3.7}/LICENSE +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/README.md +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/__init__.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/_internal.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/base.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/core.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/patches.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/animator.css +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/animator.js +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/fscreen.css +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/fscreen.js +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/listw.css +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/listw.js +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/widgets.py +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/SOURCES.txt +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/dependency_links.txt +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/requires.txt +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/top_level.txt +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/pyproject.toml +0 -0
- {dashlab-0.3.6 → dashlab-0.3.7}/setup.cfg +0 -0
|
@@ -2,6 +2,7 @@ import inspect, re, sys, textwrap
|
|
|
2
2
|
import ipywidgets as ipw
|
|
3
3
|
|
|
4
4
|
from contextlib import contextmanager
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
from IPython.core.ultratb import AutoFormattedTB
|
|
6
7
|
from ipywidgets import DOMWidget
|
|
7
8
|
|
|
@@ -94,6 +95,19 @@ def _validate_key(key):
|
|
|
94
95
|
key = key.replace(f'{match}',match.replace(',','$'),1) # Make safe from splitting with comma
|
|
95
96
|
return key
|
|
96
97
|
|
|
98
|
+
def _handle_raw_css(value):
|
|
99
|
+
"Handle raw CSS from string or Path object."
|
|
100
|
+
if not isinstance(value, (str, Path)):
|
|
101
|
+
raise TypeError("Raw CSS value for empty key must be string or file path!")
|
|
102
|
+
|
|
103
|
+
if isinstance(value, Path):
|
|
104
|
+
value = value.read_text()
|
|
105
|
+
elif Path(value).is_file():
|
|
106
|
+
value = Path(value).read_text()
|
|
107
|
+
|
|
108
|
+
value = '\n'.join(line.strip() for line in value.splitlines()) # Clean extra spaces
|
|
109
|
+
return value
|
|
110
|
+
|
|
97
111
|
def _build_css(selector, props):
|
|
98
112
|
"""
|
|
99
113
|
CSS is formatted using a `props` nested dictionary to simplify the process.
|
|
@@ -103,8 +117,8 @@ def _build_css(selector, props):
|
|
|
103
117
|
- All nested selectors are joined with space, so code`'.A': {'.B': ... }` becomes code['css']`.A .B {...}` in CSS.
|
|
104
118
|
- A '^' in start of a selector joins to parent selector without space, so code`'.A': {'^:hover': ...}` becomes code['css']`.A:hover {...}` in CSS. You can also use code`'.A:hover'` directly but it will restrict other nested keys to hover only.
|
|
105
119
|
- A list/tuple of values for a key in dict generates CSS fallback, so code`'.A': {'font-size': ('20px','2em')}` becomes code['css']`.A {font-size: 20px; font-size: 2em;}` in CSS.
|
|
106
|
-
- An empty key with a string value injects
|
|
107
|
-
This can be used to inject complex CSS like `@import`, `@
|
|
120
|
+
- An empty key with a string/path value injects raw CSS wrapped in nested code['css']`&`, so code`'.A': {'': 'raw css here'}` becomes code['css']`& { .A { raw css here } }` in CSS.
|
|
121
|
+
This, however, can NOT be used to inject complex CSS like `@import`, `@layer` etc. `:root` is replaced with `&` to make variables local to the selector at given nesting level.
|
|
108
122
|
|
|
109
123
|
Read about specificity of CSS selectors [here](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity).
|
|
110
124
|
"""
|
|
@@ -115,11 +129,12 @@ def _build_css(selector, props):
|
|
|
115
129
|
|
|
116
130
|
for key, value in props.items():
|
|
117
131
|
key = _validate_key(key) # Just validate key
|
|
118
|
-
if not key.strip()
|
|
119
|
-
|
|
120
|
-
value = value
|
|
121
|
-
|
|
122
|
-
content += (
|
|
132
|
+
if not key.strip(): # Empty key with string value is direct CSS
|
|
133
|
+
# We can't handle complex @import, @charset here since that neede to be at root level, and we have scattered styles everywhere
|
|
134
|
+
value = _handle_raw_css(value)
|
|
135
|
+
value = value.replace(':root','&') # Take external root to this scope only
|
|
136
|
+
content += (" ".join(selector) + " {\n\t & {\n") # nested scope with added spcificity
|
|
137
|
+
content += (textwrap.indent(value, '\t\t') + "\n\t}\n}\n")
|
|
123
138
|
continue
|
|
124
139
|
|
|
125
140
|
if isinstance(value, dict):
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|