dash-capture 0.0.1__py3-none-any.whl

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.
@@ -0,0 +1,45 @@
1
+ # Copyright (c) Simon Niederberger.
2
+ # Distributed under the terms of the MIT License.
3
+
4
+
5
+ from importlib.metadata import PackageNotFoundError, version
6
+
7
+ try:
8
+ __version__ = version("dash-capture")
9
+ except PackageNotFoundError:
10
+ __version__ = "unknown"
11
+
12
+
13
+ from dash_capture.capture import (
14
+ BatchBinding,
15
+ CaptureBinding,
16
+ FromPlotly,
17
+ capture_batch,
18
+ capture_binding,
19
+ capture_element,
20
+ capture_graph,
21
+ )
22
+ from dash_capture.strategies import (
23
+ CaptureStrategy,
24
+ canvas_strategy,
25
+ html2canvas_strategy,
26
+ plotly_strategy,
27
+ )
28
+
29
+ __all__ = [
30
+ # low-level
31
+ "BatchBinding",
32
+ "CaptureBinding",
33
+ "capture_batch",
34
+ "capture_binding",
35
+ # high-level (wizard)
36
+ "capture_graph",
37
+ "capture_element",
38
+ # strategies
39
+ "CaptureStrategy",
40
+ "plotly_strategy",
41
+ "html2canvas_strategy",
42
+ "canvas_strategy",
43
+ # hooks
44
+ "FromPlotly",
45
+ ]
@@ -0,0 +1,45 @@
1
+ """Auto-include vendored html2canvas.min.js.
2
+
3
+ When ``capture_element`` uses html2canvas_strategy, the JS library is
4
+ automatically served via a Dash ``html.Script`` tag. No CDN needed.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ from dash import html
12
+
13
+ _ASSETS_DIR = Path(__file__).parent / "assets"
14
+ _LOADED = False
15
+
16
+
17
+ def html2canvas_script() -> html.Script:
18
+ """Return a ``html.Script`` tag with the vendored html2canvas code.
19
+
20
+ The script is loaded inline to avoid needing an external CDN.
21
+ Call this once in your app layout::
22
+
23
+ app.layout = html.Div([
24
+ html2canvas_script(),
25
+ ...
26
+ ])
27
+
28
+ Or use ``capture_element()`` which includes it automatically.
29
+ """
30
+ js_path = _ASSETS_DIR / "html2canvas.min.js"
31
+ if not js_path.exists():
32
+ raise FileNotFoundError(
33
+ f"html2canvas.min.js not found at {js_path}. "
34
+ "The vendored file may be missing from the package installation."
35
+ )
36
+ return html.Script(js_path.read_text())
37
+
38
+
39
+ def ensure_html2canvas(children: list) -> list:
40
+ """Prepend html2canvas script to children list if not already present."""
41
+ global _LOADED
42
+ if not _LOADED:
43
+ _LOADED = True
44
+ return [html2canvas_script(), *children]
45
+ return children
dash_capture/_ids.py ADDED
@@ -0,0 +1,25 @@
1
+ # Copyright (c) Simon Niederberger.
2
+ # Distributed under the terms of the MIT License.
3
+
4
+
5
+ class _IdGenerator:
6
+ """Package-wide unique Dash component ID generator.
7
+
8
+ Generates IDs of the form ``_dcap_<prefix>_<n>`` where *n* is a
9
+ monotonically increasing integer, unique across the entire dash-capture
10
+ package.
11
+
12
+ Use the package-level singleton :data:`id_generator`.
13
+ """
14
+
15
+ def __init__(self) -> None:
16
+ self._counter = 0
17
+
18
+ def __call__(self, prefix: str = "") -> str:
19
+ self._counter += 1
20
+ return (
21
+ f"_dcap_{prefix}_{self._counter}" if prefix else f"_dcap_{self._counter}"
22
+ )
23
+
24
+
25
+ id_generator = _IdGenerator()
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.0.1'
22
+ __version_tuple__ = version_tuple = (0, 0, 1)
23
+
24
+ __commit_id__ = commit_id = None