@luci-dev/capture 0.5.4 → 0.5.6
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/README.md +13 -0
- package/dist/luci-capture.js +120 -51
- package/dist/ui/devSettings.d.ts.map +1 -1
- package/dist/ui/devSettings.js +2 -2
- package/dist/ui/devSettings.js.map +1 -1
- package/dist/ui/picker.d.ts +5 -0
- package/dist/ui/picker.d.ts.map +1 -1
- package/dist/ui/picker.js +12 -0
- package/dist/ui/picker.js.map +1 -1
- package/dist/ui/styles.d.ts +1 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/dist/ui/styles.js +50 -12
- package/dist/ui/styles.js.map +1 -1
- package/dist/ui/toolbar.d.ts.map +1 -1
- package/dist/ui/toolbar.js +14 -7
- package/dist/ui/toolbar.js.map +1 -1
- package/package.json +3 -3
- package/dist/ui/screenshot.d.ts +0 -39
- package/dist/ui/screenshot.d.ts.map +0 -1
- package/dist/ui/screenshot.js +0 -59
- package/dist/ui/screenshot.js.map +0 -1
package/dist/ui/screenshot.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reference screenshots (FR22): a cropped picture of the picked element, saved beside its file for
|
|
3
|
-
* looking at only (the values in the file come from the page, not from the picture). The shell
|
|
4
|
-
* takes a screenshot of the visible page with Luci hidden; this crops it to the element.
|
|
5
|
-
*/
|
|
6
|
-
import { dataUrlBytes, dataUrlType } from './zip.js';
|
|
7
|
-
export const THUMB_SIZE = 640;
|
|
8
|
-
/** Where a box and the viewport meet, or null when the box is out of view. */
|
|
9
|
-
export function visiblePart(box, viewport) {
|
|
10
|
-
const left = Math.max(0, box.left);
|
|
11
|
-
const top = Math.max(0, box.top);
|
|
12
|
-
const right = Math.min(viewport.width, box.left + box.width);
|
|
13
|
-
const bottom = Math.min(viewport.height, box.top + box.height);
|
|
14
|
-
return right - left >= 1 && bottom - top >= 1 ? { left, top, width: right - left, height: bottom - top } : null;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Crop a screenshot of the viewport to a box. Decoded from its bytes, not through an <img>, which
|
|
18
|
-
* a page's Content Security Policy can block. The screenshot's scale (device pixels per CSS px) is
|
|
19
|
-
* its width over the viewport's.
|
|
20
|
-
*/
|
|
21
|
-
export async function cropScreenshot(doc, screenshot, box, viewport) {
|
|
22
|
-
const part = visiblePart(box, viewport);
|
|
23
|
-
if (!part)
|
|
24
|
-
throw new Error('the element is not in view');
|
|
25
|
-
const bitmap = await createImageBitmap(new Blob([dataUrlBytes(screenshot)], { type: dataUrlType(screenshot) }));
|
|
26
|
-
try {
|
|
27
|
-
const scale = bitmap.width / viewport.width;
|
|
28
|
-
const sx = Math.round(part.left * scale);
|
|
29
|
-
const sy = Math.round(part.top * scale);
|
|
30
|
-
const width = Math.max(1, Math.min(bitmap.width - sx, Math.round(part.width * scale)));
|
|
31
|
-
const height = Math.max(1, Math.min(bitmap.height - sy, Math.round(part.height * scale)));
|
|
32
|
-
const draw = (w, h, type) => {
|
|
33
|
-
const canvas = doc.createElement('canvas');
|
|
34
|
-
canvas.width = w;
|
|
35
|
-
canvas.height = h;
|
|
36
|
-
const ctx = canvas.getContext('2d');
|
|
37
|
-
ctx.fillStyle = '#fff';
|
|
38
|
-
ctx.fillRect(0, 0, w, h);
|
|
39
|
-
ctx.drawImage(bitmap, sx, sy, width, height, 0, 0, w, h);
|
|
40
|
-
return canvas.toDataURL(type, 0.85);
|
|
41
|
-
};
|
|
42
|
-
const fit = Math.min(1, THUMB_SIZE / Math.max(width, height));
|
|
43
|
-
const tw = Math.max(1, Math.round(width * fit));
|
|
44
|
-
const th = Math.max(1, Math.round(height * fit));
|
|
45
|
-
return {
|
|
46
|
-
png: draw(width, height, 'image/png'),
|
|
47
|
-
thumb: { dataUrl: draw(tw, th, 'image/jpeg'), width: tw, height: th },
|
|
48
|
-
width,
|
|
49
|
-
height,
|
|
50
|
-
partial: part.width < box.width - 1 || part.height < box.height - 1
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
bitmap.close();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** The reference file's name beside a capture file: "x.token.image-img-16-9.design.md" -> "x.token.image-img-16-9.png". */
|
|
58
|
-
export const referenceFileName = (captureFileName, ext = 'png') => captureFileName.replace(/\.design\.md$/, '') + `.${ext}`;
|
|
59
|
-
//# sourceMappingURL=screenshot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../src/ui/screenshot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAarD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAK9B,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,QAA2C;IAC/E,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/D,OAAO,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,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