mcruft-deckcraft 0.1.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,98 @@
1
+ # this_file: packages/mcruft_deckcraft/src/mcruft_deckcraft/__init__.py
2
+ import json
3
+ import math
4
+ from pathlib import Path
5
+
6
+ from mcruft.engines.base import Capability
7
+ from mcruft.engines.cli import CliEngine, page_indexes, pixel_scale
8
+ from mcruft.report import Loss, Policy, Report
9
+
10
+ try:
11
+ from .__version__ import __version__ as __version__
12
+ except ImportError:
13
+ from importlib.metadata import version
14
+
15
+ __version__ = version("mcruft-deckcraft")
16
+
17
+
18
+ CONVERSIONS = [("pptx", "deckcraft"), ("deckcraft", "pptx"), ("pptx", "pdf"), ("pptx", "md")]
19
+
20
+
21
+ class DeckcraftEngine(CliEngine):
22
+ PRODUCT = "deckcraft"
23
+ MIN_VERSION = "0.10.0"
24
+
25
+ def capabilities(self) -> list[Capability]:
26
+ routes = [("convert", src, dst, "editable") for src, dst in CONVERSIONS]
27
+ routes += [
28
+ ("export_pages", src, dst, policy)
29
+ for src in ("pptx", "deckcraft")
30
+ for dst, policy in (("pdf", "editable"), ("png", "fidelity"))
31
+ ]
32
+ routes += [
33
+ ("build_deck", "png", "pptx", "fidelity"),
34
+ ("inspect", "deckcraft", "deckcraft", "editable"),
35
+ ]
36
+ return [Capability(*row, f"{self.PRODUCT}-cli {self.MIN_VERSION}") for row in routes]
37
+
38
+ def inspect(self, path: Path) -> list[tuple[float, float]]:
39
+ path = Path(path)
40
+ if path.suffix.lower() != ".deckcraft":
41
+ return super().inspect(path)
42
+ info = json.loads(self.call(["info", path]))
43
+ return [tuple(map(float, info["slideSize"]))] * len(info["slides"])
44
+
45
+ def run(self, op: str, src: Path, dst: Path, *, policy: Policy, **opts) -> Report:
46
+ src, dst = Path(src), Path(dst)
47
+ self.check_route(op, src, dst, policy)
48
+ report = self.report(op, policy, [dst])
49
+ if op == "build_deck":
50
+ images = [Path(p).absolute() for p in opts.get("images") or []]
51
+ if not images:
52
+ raise ValueError("build_deck requires at least one image")
53
+ width, height = opts.get("size", (960, 540))
54
+ if not all(math.isfinite(v) and v > 0 for v in (width, height)):
55
+ raise ValueError("Slide dimensions must be finite and positive")
56
+ args = ["run", "--cmd", "design.slideSize=" + json.dumps({"w": width, "h": height})]
57
+ for image in images:
58
+ args += [
59
+ "--cmd",
60
+ 'slide.new={"layout":"blank"}',
61
+ "--cmd",
62
+ "insert.picture="
63
+ + json.dumps({"path": str(image), "rect": [0, 0, width, height]}),
64
+ ]
65
+ args += ["--cmd", 'slide.delete={"index":0}', "--save", dst]
66
+ report.losses.append(Loss("raster", "slides are images"))
67
+ elif op == "export_pages":
68
+ info = json.loads(self.call(["info", src]))
69
+ pages = page_indexes(opts.get("pages"), len(info["slides"]))
70
+ if dst.suffix.lower() == ".png":
71
+ scale = pixel_scale(opts.get("dpi", 150))
72
+ report.outputs = []
73
+ for page in pages:
74
+ out = dst.with_name(f"{dst.stem}-{page:04d}.png")
75
+ self.call(
76
+ ["render", src, "--slide", str(page), "--scale", str(scale), out], report
77
+ )
78
+ report.outputs.append(out)
79
+ report.losses.append(Loss("raster", "slides rasterised"))
80
+ return report
81
+ args = [
82
+ "run",
83
+ "--in",
84
+ src,
85
+ "--export",
86
+ dst,
87
+ "--export-params",
88
+ json.dumps({"slides": pages}),
89
+ ]
90
+ else:
91
+ args = ["convert", src, dst]
92
+ if dst.suffix.lower() == ".pdf":
93
+ report.losses.append(Loss("raster", "slide art rasterised"))
94
+ self.call(args, report)
95
+ return report
96
+
97
+
98
+ engine = DeckcraftEngine()
@@ -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.1.1'
22
+ __version_tuple__ = version_tuple = (0, 1, 1)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcruft-deckcraft
3
+ Version: 0.1.1
4
+ Summary: DeckCraft engine for mcruft
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.12
7
+ Requires-Dist: mcruft
8
+ Provides-Extra: bundled
9
+ Requires-Dist: mcruft-deckcraft-bin; extra == 'bundled'
@@ -0,0 +1,6 @@
1
+ mcruft_deckcraft/__init__.py,sha256=zVD4_YZiq9mlZMPttFyLOjCpVTzAvx9E2IHJv-15oXg,3909
2
+ mcruft_deckcraft/__version__.py,sha256=mEr1FdwwZVMovyM6vpPg2W8zwa1u1f4KdymTrLcqf9U,520
3
+ mcruft_deckcraft-0.1.1.dist-info/METADATA,sha256=JxHNnLigBCAVmPKbE0ilhYcVtVNXyBtHr-tupSsIEMs,254
4
+ mcruft_deckcraft-0.1.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
5
+ mcruft_deckcraft-0.1.1.dist-info/entry_points.txt,sha256=GjCPxDBaviLZMejAx0ODVhPzSzCv1QbrNZrjOTFFNnU,53
6
+ mcruft_deckcraft-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [mcruft.engines]
2
+ deckcraft = mcruft_deckcraft:engine