GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — deckmill/measure_chrome.py at master · ishan-parihar/deckmill

Expand file tree

/

measure_chrome.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
161 lines (152 loc) · 6.53 KB
/

measure_chrome.py

Copy path

File metadata and controls

161 lines (152 loc) · 6.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
"""Measure slide chrome geometry: where the header/footer bands and corner text
sit vs the .slide-body (the ONLY place slide types render) and the composition
bounds. Dumps JSON to stdout.
Architecture (banded chrome):
.slide (420x525 base)
.slide-composition (420x525)
.slide-header (36px band: brand left, topic right)
.slide-body (flex:1 — slide types render ONLY here)
.slide-footer (40px band: url left, progress, hashtags right)
.swipe-arrow
"""
import json
import re
import subprocess
import sys
import tempfile
from pathlib import Path
REPO = Path(__file__).parent
CAROUSEL = REPO / "dist" / "typology_carousel.html"
# Find a chrome binary
CHROME = None
for cand in [
"google-chrome", "google-chrome-stable", "chromium", "chromium-browser",
"/usr/bin/google-chrome", "/usr/bin/chromium",
str(Path.home() / ".cache" / "ms-playwright" / "chromium-*/chrome-linux/chrome"),
]:
import glob
if "*" in cand:
hits = glob.glob(cand)
if hits:
CHROME = hits[0]
break
else:
r = subprocess.run(["which", cand], capture_output=True, text=True)
if r.returncode == 0:
CHROME = cand
break
if not CHROME:
print("no chrome found", file=sys.stderr)
sys.exit(2)
html = CAROUSEL.read_text()
# Inject measurement script just before </body>
measure_js = r"""
<script>
window.__chromeMeasure = () => {
const slides = document.querySelectorAll('.slide');
const out = [];
const HDR = 36, FTR = 40; // banded chrome heights (base px)
slides.forEach((s, i) => {
if (i > 40) return; // sample first 41 slides
const comp = s.querySelector('.slide-composition');
const header = s.querySelector('.slide-header');
const body = s.querySelector('.slide-body');
const footer = s.querySelector('.slide-footer');
const content = s.querySelector('.slide-content');
const brand = s.querySelector('.overlay__brand');
const topic = s.querySelector('.overlay__topic');
const url = s.querySelector('.overlay__url');
const hashtags = s.querySelector('.overlay__hashtags');
const progress = s.querySelector('.breadcrumb-progress') || s.querySelector('.progress-line');
const sr = s.getBoundingClientRect();
const scale = sr.width / 420;
const rect = (el) => {
if (!el) return null;
const r = el.getBoundingClientRect();
return {top: Math.round((r.top - sr.top) / scale), bottom: Math.round((r.bottom - sr.top) / scale),
left: Math.round((r.left - sr.left) / scale), right: Math.round((r.right - sr.left) / scale),
w: Math.round(r.width / scale), h: Math.round(r.height / scale)};
};
const contentPad = content ? getComputedStyle(content) : null;
// Body-region text elements (inside .slide-body only — chrome is excluded
// by construction since chrome lives in the header/footer bands).
const textEls = [];
if (body) {
body.querySelectorAll('p,h1,h2,h3,h4,h5,h6,blockquote,span,li,strong,em').forEach((el) => {
const t = (el.textContent || '').trim();
if (!t) return;
if (el.closest('.swipe-arrow')) return;
const r = el.getBoundingClientRect();
if (r.width < 4 || r.height < 4) return;
textEls.push({tag: el.tagName.toLowerCase(), top: Math.round((r.top - sr.top) / scale), bottom: Math.round((r.bottom - sr.top) / scale), h: Math.round(r.height / scale), txt: t.slice(0, 32)});
});
}
const bodyRect = body ? rect(body) : null;
const bodyTop = bodyRect ? bodyRect.top : HDR;
const bodyBottom = bodyRect ? bodyRect.bottom : (sr.height / scale - FTR);
const bodyText = textEls.length ? textEls : null;
const firstTextTop = bodyText ? Math.min(...bodyText.map(e => e.top)) : null;
const lastTextBottom = bodyText ? Math.max(...bodyText.map(e => e.bottom)) : null;
// Chrome collisions: body text that escapes the body region (into bands).
const headerCollision = bodyText ? bodyText.filter(e => e.top < bodyTop).length : 0;
const footerCollision = bodyText ? bodyText.filter(e => e.bottom > bodyBottom).length : 0;
const topDead = firstTextTop !== null ? firstTextTop - bodyTop : null;
const bottomDead = lastTextBottom !== null ? bodyBottom - lastTextBottom : null;
out.push({
i,
slide: {w: Math.round(sr.width), h: Math.round(sr.height)},
comp: rect(comp),
header: rect(header), body: bodyRect, footer: rect(footer),
content: rect(content),
contentPadding: contentPad ? {t: contentPad.paddingTop, b: contentPad.paddingBottom, l: contentPad.paddingLeft, r: contentPad.paddingRight} : null,
brand: rect(brand), topic: rect(topic), url: rect(url), hashtags: rect(hashtags),
progress: rect(progress),
bodyRegion: {top: bodyTop, bottom: bodyBottom, h: Math.round(bodyBottom - bodyTop)},
bodyTextCount: bodyText ? bodyText.length : 0,
headerCollision, footerCollision,
topDead, bottomDead,
textSample: bodyText ? bodyText.slice(0, 4) : null,
});
});
return out;
};
window.__chromeData = null;
</script>
"""
html = html.replace("</body>", measure_js + "\n<script>window.__chromeData = window.__chromeMeasure();"
+ "\ndocument.body.appendChild(Object.assign(document.createElement('div'), {id: 'chrome-data', textContent: JSON.stringify(window.__chromeData)}));"
+ "</script>\n</body>")
# Render the data into a DOM node and dump it.
tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
tmp.write(html.encode())
tmp.close()
dump_js = """
const data = window.__chromeData;
if (!data) { console.log('NO_DATA'); process.exit(3); }
console.log('CHROME_DATA_START');
console.log(JSON.stringify(data));
console.log('CHROME_DATA_END');
process.exit(0);
"""
script = tmp.name.replace(".html", "_dump.js")
Path(script).write_text(dump_js)
cmd = [
CHROME, "--headless=new", "--no-sandbox", "--disable-gpu",
"--disable-dev-shm-usage", "--virtual-time-budget=3000",
"--run-all-compositor-stages-before-draw", "--dump-dom",
"--allow-file-access-from-files", "file://" + tmp.name,
]
r = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
dom = r.stdout
m = re.search(r'<div id="chrome-data">(.*?)</div>', dom, re.S)
if m:
# The JSON is embedded as text content; unescape basic entities.
raw = m.group(1).replace("&quot;", "\"").replace("&amp;", "&").replace("&#39;", "'")
print(raw)
else:
print("NO_MEASUREMENT", file=sys.stderr)
print(dom[-2000:], file=sys.stderr)
sys.exit(4)
Path(script).unlink(missing_ok=True)
Path(tmp.name).unlink(missing_ok=True)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.