screengraft 0.45.0 → 0.46.0
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.
- package/package.json +1 -1
- package/scripts/detect.py +14 -2
- package/skills/inject-screenshot/SKILL.md +1 -1
- package/ui/index.html +55 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screengraft",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Put a UI screenshot or screen recording onto a photographed device screen with the perspective exactly right \u2014 a homography you confirm by hand, not a generative guess.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mockup",
|
package/scripts/detect.py
CHANGED
|
@@ -260,10 +260,22 @@ def approx_quad(contour):
|
|
|
260
260
|
|
|
261
261
|
|
|
262
262
|
def order_quad(pts: np.ndarray) -> np.ndarray:
|
|
263
|
-
"""Order 4 points TL, TR, BR, BL as they appear in the
|
|
263
|
+
"""Order 4 points TL, TR, BR, BL as they appear in the IMAGE.
|
|
264
|
+
|
|
265
|
+
Corner 0 is where the screenshot's top-left lands, so this decides the
|
|
266
|
+
screenshot's orientation -- and this function cannot decide it well: on a
|
|
267
|
+
phone photographed at ~45 degrees the corner nearest the image's top-left
|
|
268
|
+
is the screen's physical bottom-left, so a quad right to 1% put the
|
|
269
|
+
screenshot a quarter turn out (12 Sep 2026). A rule "the top edge of
|
|
270
|
+
a portrait quad is its higher short edge" was tried here and is wrong for
|
|
271
|
+
every landscape screen, because which edge is the top depends on the
|
|
272
|
+
SCREENSHOT's aspect, which only the workbench knows. So this stays
|
|
273
|
+
geometric and the workbench turns the order to match the screenshot
|
|
274
|
+
(`orientQuad` in ui/index.html, plus a Rotate 90 degrees control).
|
|
275
|
+
"""
|
|
264
276
|
c = pts.mean(axis=0)
|
|
265
277
|
ang = np.arctan2(pts[:, 1] - c[1], pts[:, 0] - c[0])
|
|
266
|
-
pts = pts[np.argsort(ang)] #
|
|
278
|
+
pts = pts[np.argsort(ang)] # clockwise as seen on screen (y down)
|
|
267
279
|
start = int(np.argmin(pts.sum(axis=1))) # closest to the image's top-left
|
|
268
280
|
return np.roll(pts, -start, axis=0)
|
|
269
281
|
|
|
@@ -5,7 +5,7 @@ description: Injects a UI screenshot OR a screen recording onto a photographed d
|
|
|
5
5
|
|
|
6
6
|
# Inject a screenshot onto a photographed device
|
|
7
7
|
|
|
8
|
-
**What ships (v0.
|
|
8
|
+
**What ships (v0.46):** a local browser UI (`scripts/ui.py`) that walks the designer through the whole job — pick the photo and the screen source, which may be an image **or a video** (recent Desktop/Downloads images, drag-drop, browse, path, or a **Figma frame link**), auto-detect the screen as a starting position — and when detection cannot tell which region is a screen, **Point at screen**: one click inside it and the detector uses that point — or, if this photograph has been fitted before, **the fit it was saved with comes back** as the starting position instead of a detection, recognised by the photo's own pixels so a rename or a drag-drop still match — and every save also writes a **portable `.fit.json` beside the mockup** that can be dropped back onto the page later, which is how a fit survives a re-export, another machine, or someone else's hands — then **match the four edges** (drag an edge's middle to slide it, near an end to pivot; corners still draggable) with canvas navigation that follows the usual conventions — **hold ⌘ and scroll to zoom to the pointer, hold space and drag to pan** — and a rectified strip loupe. The fit and the composite sit **side by side and always have** — the result pane re-renders as you drag, which is how a corner gets judged, so it is the layout rather than a mode you can switch off. Then an on-by-default realism pass that colour-matches the source to the photo's light, **Save** (or **Render**, for a video) into the project folder (`--out-dir`), and a **Send to Claude** button that reaches you through the plugin's own MCP server. The UI is a hand port of the project's Figma design file — dark only.
|
|
9
9
|
|
|
10
10
|
The geometry is exact (`warp.py`); the detection is advisory (`detect.py`) and the human corrects it. **When a detection is wrong and you want to know why**, ask for the candidate list: `POST /api/detect {"trace": true}` writes `<session>/candidates.json`, or run `python3 scripts/detect.py --photo P --out-corners /tmp/c.json --trace /tmp/t.json` (add `--click X,Y`). Every candidate quad is in there with its score and whether it was accepted, rejected, never reached, or filtered out by the click — which is what separates "the screen was never proposed" from "it was proposed and something else won".
|
|
11
11
|
|
package/ui/index.html
CHANGED
|
@@ -984,6 +984,7 @@
|
|
|
984
984
|
<span class="stepper"><button class="sm" data-jump="0">TL</button><button class="sm" data-jump="1">TR</button><button class="sm" data-jump="2">BR</button><button class="sm" data-jump="3">BL</button></span>
|
|
985
985
|
<button class="sm" id="redetect">Re-detect</button>
|
|
986
986
|
<button class="sm" id="pointat" title="Click once inside the screen and the detector will use that point. The detectors usually do find the screen — they just cannot tell which region IS one, and that is the part you can answer instantly.">Point at screen</button>
|
|
987
|
+
<button class="sm" id="rotatequad" title="Turn the screenshot a quarter turn inside the same four edges. The edges stay where they are; only which one is the top changes. Use this when the phone lies on its side and the screenshot lands sideways.">Rotate 90°</button>
|
|
987
988
|
<button class="sm" id="resetquad" title="Put the four edges back to a rectangle in the middle of the photo. Use this if a corner has ended up off the picture where you cannot grab it.">Reset</button>
|
|
988
989
|
</span>
|
|
989
990
|
</div>
|
|
@@ -1568,7 +1569,10 @@ function setChosen(role, path, size, el, meta){
|
|
|
1568
1569
|
// screenshot to put inside it, which is what maybeStart() waits for.
|
|
1569
1570
|
if (role==='photo'){ st.photo = path; st.corners = null;
|
|
1570
1571
|
st.remembered = (meta && meta.remembered) || null; }
|
|
1571
|
-
else { st.shot = path; st.video = meta && meta.video ? meta : null; syncVideoUI();
|
|
1572
|
+
else { st.shot = path; st.shotSize = size; st.video = meta && meta.video ? meta : null; syncVideoUI();
|
|
1573
|
+
// A detected quad is re-oriented for the new screenshot; a remembered or
|
|
1574
|
+
// hand-placed one is somebody's decision and is left alone.
|
|
1575
|
+
if (st.corners && st.quadFrom === 'detected' && orientQuad()){ draw(); drawStrip(); autoPreview(); } }
|
|
1572
1576
|
closePop();
|
|
1573
1577
|
maybeStart();
|
|
1574
1578
|
}
|
|
@@ -1931,6 +1935,7 @@ async function pointAt(x, y){
|
|
|
1931
1935
|
const r = await api('/api/detect', {click: [x, y]});
|
|
1932
1936
|
if (r.found){
|
|
1933
1937
|
st.corners = r.corners; st.measured = r.corner_radius; st.quadFrom = 'detected';
|
|
1938
|
+
orientQuad();
|
|
1934
1939
|
s.className = 'status ok';
|
|
1935
1940
|
s.textContent = `Screen found from your click (${r.method})`;
|
|
1936
1941
|
if (!st.type) setType(r.type_guess || 'phone');
|
|
@@ -1961,6 +1966,7 @@ async function detect(){
|
|
|
1961
1966
|
const r = await api('/api/detect', {});
|
|
1962
1967
|
if (r.found){
|
|
1963
1968
|
st.corners = r.corners; st.measured = r.corner_radius; st.quadFrom = 'detected';
|
|
1969
|
+
orientQuad();
|
|
1964
1970
|
const corroborated = r.confidence === 'corroborated';
|
|
1965
1971
|
s.className = 'status ' + (corroborated ? 'ok' : 'warn');
|
|
1966
1972
|
s.textContent = corroborated ? `Both detectors agree (${r.method})`
|
|
@@ -2029,6 +2035,54 @@ function defaultQuad(){
|
|
|
2029
2035
|
return [[w*.3,h*.2],[w*.7,h*.2],[w*.7,h*.8],[w*.3,h*.8]];
|
|
2030
2036
|
}
|
|
2031
2037
|
$('#redetect').onclick = detect;
|
|
2038
|
+
// Rotate: the same four points, the list started one place later. Corner 0 is
|
|
2039
|
+
// where the screenshot's top-left goes, so this turns the screenshot a quarter
|
|
2040
|
+
// turn clockwise inside an unchanged quad. Needed because detection orders
|
|
2041
|
+
// corners by where they sit in the PHOTO (nearest the image's top-left first),
|
|
2042
|
+
// and on a phone lying at 45° that is the screen's bottom-left — the quad was
|
|
2043
|
+
// right to 1% and the screenshot would have landed sideways (12 Sep 2026).
|
|
2044
|
+
// Dragging four corners to their neighbours' places was the only way.
|
|
2045
|
+
// The saved fit and the sidecar carry the corners in order, so a rotated fit
|
|
2046
|
+
// comes back rotated; nothing else changes.
|
|
2047
|
+
function turnQuad(){
|
|
2048
|
+
st.corners = [1, 2, 3, 0].map(i => st.corners[i].slice());
|
|
2049
|
+
if (pick && pick.kind === 'corner') pick = {kind: 'corner', i: (pick.i + 3) % 4};
|
|
2050
|
+
else if (pick && pick.kind === 'edge') pick = {kind: 'edge', i: (pick.i + 3) % 4};
|
|
2051
|
+
}
|
|
2052
|
+
function rotateQuad(){
|
|
2053
|
+
if (!st.corners) return;
|
|
2054
|
+
turnQuad();
|
|
2055
|
+
draw(); drawStrip(); autoPreview();
|
|
2056
|
+
}
|
|
2057
|
+
$('#rotatequad').onclick = rotateQuad;
|
|
2058
|
+
// The automatic half. Detection orders corners geometrically and cannot know
|
|
2059
|
+
// which edge is the top: that depends on the SCREENSHOT. A portrait screenshot
|
|
2060
|
+
// goes on the quad the long way, a landscape one the wide way. So once both
|
|
2061
|
+
// are known, if the quad's top edge is clearly the wrong kind for the
|
|
2062
|
+
// screenshot, turn the order until it is the right kind — the higher of the
|
|
2063
|
+
// two candidate top edges, so an upright photo is unchanged. A rule of this
|
|
2064
|
+
// shape was first put in detect.py's order_quad and was wrong for every
|
|
2065
|
+
// landscape screen; the aspect of the screenshot is the missing fact and only
|
|
2066
|
+
// this page has it. Near-square quads (under 1.25) are left alone — perspective
|
|
2067
|
+
// can make either kind of edge the longer one. Returns whether it turned.
|
|
2068
|
+
const ORIENT_ASPECT = 1.25;
|
|
2069
|
+
function orientQuad(){
|
|
2070
|
+
if (!st.corners || !st.shotSize) return false;
|
|
2071
|
+
const C = st.corners;
|
|
2072
|
+
const len = i => Math.hypot(C[(i+1)%4][0]-C[i][0], C[(i+1)%4][1]-C[i][1]);
|
|
2073
|
+
const a = (len(0) + len(2)) / 2, b = (len(1) + len(3)) / 2; // edges 0/2 vs 1/3
|
|
2074
|
+
if (Math.max(a, b) < ORIENT_ASPECT * Math.max(Math.min(a, b), 1e-6)) return false;
|
|
2075
|
+
const shotPortrait = st.shotSize[1] > st.shotSize[0];
|
|
2076
|
+
const topShouldBeShort = shotPortrait;
|
|
2077
|
+
const topIsShort = a < b;
|
|
2078
|
+
if (topIsShort === topShouldBeShort) return false;
|
|
2079
|
+
// Two candidate top edges (1 and 3, the other pair); the higher one in the
|
|
2080
|
+
// image is the top. Turn once to make edge 1 the top, twice more for edge 3.
|
|
2081
|
+
const midY = i => (C[i][1] + C[(i+1)%4][1]) / 2;
|
|
2082
|
+
const turns = midY(1) <= midY(3) ? 1 : 3;
|
|
2083
|
+
for (let k = 0; k < turns; k++) turnQuad();
|
|
2084
|
+
return true;
|
|
2085
|
+
}
|
|
2032
2086
|
$('#resetquad').onclick = () => {
|
|
2033
2087
|
if (!img.naturalWidth) return;
|
|
2034
2088
|
st.corners = defaultQuad(); st.quadFrom = 'default';
|