feat(core): implement Plan #62 efficiency, deduplication, caching & hook optimizations
This commit is contained in:
1 parent
d4b7502501
commit
9b587d6351
20 files changed
+176
-195
No files matched your search
@@ -30,12 +30,15 @@ from typing import Any
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from hyperstitionstud_io import __version__ as CURRENT_VERSION
|
||||
from hyperstitionstud_io.config import load_json_cached, load_workspace_config
|
||||
from hyperstitionstud_io.config import count_file_lines_cached, load_json_cached, load_workspace_config
|
||||
from hyperstitionstud_io.glossary import ReadOnlyIsolationGuard
|
||||
from hyperstitionstud_io.ipld import compute_dag_json_cidv1
|
||||
from hyperstitionstud_io.publishing.fonts import (
|
||||
GROUP3_PALETTE,
|
||||
draw_bounded_box_text,
|
||||
draw_bounded_kv_row,
|
||||
draw_group3_chamfered_plate,
|
||||
fit_pillow_text_to_width,
|
||||
load_pillow_font,
|
||||
)
|
||||
|
||||
@@ -126,17 +129,15 @@ def _fit_font_for_width(
|
||||
min_size: int = 8,
|
||||
bold: bool = False,
|
||||
) -> tuple[Any, int, int]:
|
||||
font_file = FONT_MONO_B if bold else FONT_MONO
|
||||
for sz in range(preferred_size, min_size - 1, -1):
|
||||
f = _fnt(font_file, sz)
|
||||
tb = d.textbbox((0, 0), text, font=f)
|
||||
w = int(tb[2] - tb[0])
|
||||
h = int(tb[3] - tb[1])
|
||||
if w <= max_width:
|
||||
return f, w, h
|
||||
f = _fnt(font_file, min_size)
|
||||
tb = d.textbbox((0, 0), text, font=f)
|
||||
return f, int(tb[2] - tb[0]), int(tb[3] - tb[1])
|
||||
return fit_pillow_text_to_width(
|
||||
d,
|
||||
text,
|
||||
max_width,
|
||||
preferred_size=preferred_size,
|
||||
min_size=min_size,
|
||||
bold=bold,
|
||||
font_filename=FONT_MONO_B if bold else FONT_MONO,
|
||||
)
|
||||
|
||||
|
||||
def _draw_box_text(
|
||||
@@ -152,18 +153,19 @@ def _draw_box_text(
|
||||
bold: bool = False,
|
||||
y_pos: int | None = None,
|
||||
) -> tuple[int, int, int, int]:
|
||||
bx1, by1, bx2, by2 = box
|
||||
avail_w = max(16, (bx2 - bx1) - 2 * pad_x)
|
||||
f, tw, th = _fit_font_for_width(d, text, avail_w, preferred_size=preferred_size, min_size=min_size, bold=bold)
|
||||
if align == "center":
|
||||
tx = bx1 + max(pad_x, ((bx2 - bx1) - tw) // 2)
|
||||
elif align == "right":
|
||||
tx = max(bx1 + pad_x, bx2 - pad_x - tw)
|
||||
else:
|
||||
tx = bx1 + pad_x
|
||||
ty = y_pos if y_pos is not None else (by1 + max(2, ((by2 - by1) - th) // 2 - 1))
|
||||
d.text((tx, ty), text, font=f, fill=fill)
|
||||
return d.texts[-1][2]
|
||||
return draw_bounded_box_text(
|
||||
d,
|
||||
box,
|
||||
text,
|
||||
fill,
|
||||
pad_x=pad_x,
|
||||
align=align,
|
||||
preferred_size=preferred_size,
|
||||
min_size=min_size,
|
||||
bold=bold,
|
||||
y_pos=y_pos,
|
||||
font_filename=FONT_MONO_B if bold else FONT_MONO,
|
||||
)
|
||||
|
||||
|
||||
def _draw_kv_row(
|
||||
@@ -181,22 +183,20 @@ def _draw_kv_row(
|
||||
val_bold: bool = False,
|
||||
min_val_x: int | None = None,
|
||||
) -> None:
|
||||
bx1, by1, bx2, by2 = box
|
||||
d.rectangle([bx1, by1, bx2, by2], fill=fill_bg, outline=outline)
|
||||
total_inner = (bx2 - bx1) - 16
|
||||
kf, kw, kh = _fit_font_for_width(d, key_text, max(40, int(total_inner * 0.52)), preferred_size=key_size, min_size=8, bold=True)
|
||||
ky = by1 + max(2, ((by2 - by1) - kh) // 2 - 1)
|
||||
kx = bx1 + 8
|
||||
d.text((kx, ky), key_text, font=kf, fill=key_fill)
|
||||
key_tb = d.texts[-1][2]
|
||||
|
||||
vx_start = max(key_tb[2] + 8, min_val_x if min_val_x is not None else (key_tb[2] + 10))
|
||||
avail_val_w = max(24, (bx2 - 6) - vx_start)
|
||||
vf, vw, vh = _fit_font_for_width(d, val_text, avail_val_w, preferred_size=val_size, min_size=8, bold=val_bold)
|
||||
if vx_start + vw > bx2 - 6:
|
||||
vx_start = max(key_tb[2] + 6, (bx2 - 6) - vw)
|
||||
vy = by1 + max(2, ((by2 - by1) - vh) // 2 - 1)
|
||||
d.text((vx_start, vy), val_text, font=vf, fill=val_fill)
|
||||
draw_bounded_kv_row(
|
||||
d,
|
||||
box,
|
||||
key_text,
|
||||
val_text,
|
||||
fill_bg=fill_bg,
|
||||
outline=outline,
|
||||
key_fill=key_fill,
|
||||
val_fill=val_fill,
|
||||
key_size=key_size,
|
||||
val_size=val_size,
|
||||
val_bold=val_bold,
|
||||
min_val_x=min_val_x,
|
||||
)
|
||||
|
||||
|
||||
def verify_closeup_geometry(tracked_by_filename: dict[str, _TrackedCanvasDraw]) -> dict[str, Any]:
|
||||
@@ -408,7 +408,7 @@ def introspect_live_ui_elements(workspace_root: str | Path | None = None) -> dic
|
||||
}
|
||||
|
||||
db_txt_p = calc_dir / "db.txt"
|
||||
db_entries_count = sum(1 for _ in db_txt_p.open(encoding="utf-8")) if db_txt_p.is_file() else 231615
|
||||
db_entries_count = count_file_lines_cached(db_txt_p) if db_txt_p.is_file() else 231615
|
||||
|
||||
ci_rep_p = ci_dir / "ci-audit-report.json"
|
||||
ci_obj = load_json_cached(ci_rep_p, copy_result=False) if ci_rep_p.is_file() else {}
|
||||
@@ -486,7 +486,7 @@ def render_all_quadrant_closeups(
|
||||
prev_fp = ""
|
||||
if manifest_path.is_file():
|
||||
try:
|
||||
prev_obj = json.loads(manifest_path.read_text(encoding="utf-8"))
|
||||
prev_obj = load_json_cached(manifest_path, copy_result=False)
|
||||
prev_fp = prev_obj.get("ui_elements_fingerprint_sha256", "")
|
||||
except Exception:
|
||||
prev_fp = ""
|
||||
|
||||
Reference in new issue
Block a user