From 21d839e602fa556024c49588c721498732b5a896 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 17:24:13 -0800 Subject: [PATCH] Opening zoom: a fit within the opening check's 0.05 px of the floor opens fitted The kit zoomed to the 8 px floor whenever a fit fell more than 0.4% short (0.032 px), while the opening check counts fitted text within 0.05 px of the floor as at it and fails a canvas that zooms there. graph/nuget-update at 390px fits at 7.956 px since #197, so it opened at zoom 1.0056 and the check failed it on main. The kit's slack is now the check's tolerance. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/renderers/kit/src/zoom.ts | 11 +++++++++-- packages/renderers/kit/test/layout.test.mjs | 3 +++ .../renderers/testing/src/checks/frame/opening.ts | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/renderers/kit/src/zoom.ts b/packages/renderers/kit/src/zoom.ts index 81ffe19a..6ae50834 100644 --- a/packages/renderers/kit/src/zoom.ts +++ b/packages/renderers/kit/src/zoom.ts @@ -1,4 +1,5 @@ import {defineControls} from '@githubnext/projections-renderer-sdk/protocol' +import {openingFloorPx} from '@githubnext/projections-renderer-sdk/presentation' /** * Zoom actions the host draws for a scalable stage (see `useStageZoom`); pass @@ -46,8 +47,14 @@ export {openingFloorPx} from '@githubnext/projections-renderer-sdk/presentation' export {contentStart} from './content-start.js' export type {ContentBox} from './content-start.js' -/** How far (as a share) a fit may fall below the floor and still open fitted: zooming a hair would only scroll a pixel. */ -const floorSlack = 0.004 +/** + * How far (CSS px) a fit's smallest text may fall below `openingFloorPx` and still open fitted: zooming a hair would + * only scroll a pixel. It is the built-in opening check's `floorTolerance` (`checks/frame/opening.ts` in the renderer + * testing package), which counts such a fit as at the floor, so the kit never opens zoomed where the check says fitted. + */ +const floorTolerancePx = 0.05 +/** `floorTolerancePx` as a share of the fit's zoom to the floor. */ +const floorSlack = floorTolerancePx / (openingFloorPx - floorTolerancePx) /** * The zoom multiple a stage fitted at `fit` opens at, given the scale `floor` at which its smallest text reaches diff --git a/packages/renderers/kit/test/layout.test.mjs b/packages/renderers/kit/test/layout.test.mjs index c1d0df38..8169fb03 100644 --- a/packages/renderers/kit/test/layout.test.mjs +++ b/packages/renderers/kit/test/layout.test.mjs @@ -763,6 +763,9 @@ test('a stage opens fitted unless that draws text below the floor, then at the f assert.equal(openingZoom(1, floor), 1, 'text drawn at 12 px opens fitted') assert.equal(openingZoom(floor, floor), 1, 'text exactly at the floor opens fitted') assert.equal(openingZoom(floor * 0.999, floor), 1, 'a hair below the floor still opens fitted') + // graph/nuget-update at 390px: fitted text 7.956 px, within the opening check's tolerance, so it opens fitted. + assert.equal(openingZoom(floor / 1.005587, floor), 1, 'text within 0.05 px of the floor (the opening check tolerance) opens fitted') + assert.ok(openingZoom(floor * (7.9 / 8), floor) > 1, 'text further below the floor than the tolerance zooms to it') assert.ok(Math.abs(openingZoom(0.2, floor) * 0.2 * 12 - 8) < 1e-4, 'a small fit opens where the smallest text is 8 px') assert.equal(openingZoom(0.5, 0), 1, 'no text measured yet: fitted') // The top row's leftmost box, 12 units clear, at the view's top left, never the empty room the bounds begin with. diff --git a/packages/renderers/testing/src/checks/frame/opening.ts b/packages/renderers/testing/src/checks/frame/opening.ts index aacd60fa..30e16618 100644 --- a/packages/renderers/testing/src/checks/frame/opening.ts +++ b/packages/renderers/testing/src/checks/frame/opening.ts @@ -6,7 +6,7 @@ import {Skip, Passed, limit, label, type Checks} from '../support.js' /** The frame a zoomable renderer must open fitted in: about a VS Code tab at full width, and a phone. */ const openingFrame = {height: 650, phoneHeight: 700} -/** Rounding slack in a measured text size, CSS px. */ +/** Rounding slack in a measured text size, CSS px: the kit's `openingZoom` opens fitted within it too (its `floorTolerancePx`). */ const floorTolerance = 0.05 /** * How far above the floor a canvas opened at it may draw its smallest visible text: the floor also counts text that