MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getClip

Function getClip

test/e2e/doc-shots.test.ts:155–226  ·  view source on GitHub ↗
(
  page: Page,
  locator: Locator,
  marginRem?: number,
  frameLocator?: Locator,
)

Source from the content-addressed store, hash-verified

153};
154
155const getClip = async (
156 page: Page,
157 locator: Locator,
158 marginRem?: number,
159 frameLocator?: Locator,
160): Promise<{x: number; y: number; width: number; height: number}> => {
161 await locator.scrollIntoViewIfNeeded();
162 const box = await locator.boundingBox();
163 if (box == null) {
164 throw new Error('Unable to determine doc shot bounds');
165 }
166 const margin =
167 (marginRem ?? 0) *
168 (await locator.evaluate((element) =>
169 parseFloat(
170 getComputedStyle(element.ownerDocument.documentElement).fontSize,
171 ),
172 ));
173 const deviceScaleFactor = await page.evaluate(() => window.devicePixelRatio);
174 const frameBox = await frameLocator?.boundingBox();
175 const documentBounds =
176 frameBox == null
177 ? await page.evaluate(() => {
178 const {documentElement, body} = document;
179 return {
180 height: Math.max(
181 documentElement.clientHeight,
182 documentElement.scrollHeight,
183 body?.scrollHeight ?? 0,
184 ),
185 width: Math.max(
186 documentElement.clientWidth,
187 documentElement.scrollWidth,
188 body?.scrollWidth ?? 0,
189 ),
190 x: 0,
191 y: 0,
192 };
193 })
194 : {
195 height: frameBox.height - 3,
196 width: frameBox.width - 2,
197 x: frameBox.x + 1,
198 y: frameBox.y + 1,
199 };
200 const left = Math.round(Math.max(box.x - margin, 0) * deviceScaleFactor);
201 const top = Math.round(Math.max(box.y - margin, 0) * deviceScaleFactor);
202 const right = Math.round(
203 Math.min(
204 box.x + box.width + margin,
205 documentBounds.x + documentBounds.width,
206 ) * deviceScaleFactor,
207 );
208 const bottom = Math.round(
209 Math.min(
210 box.y + box.height + margin,
211 documentBounds.y + documentBounds.height,
212 ) * deviceScaleFactor,

Callers 1

expectDocShotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…