@pairdraw/web-capture 0.0.0-stage → 0.16.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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/capturer.d.ts +56 -0
  4. package/dist/capturer.d.ts.map +1 -0
  5. package/dist/capturer.js +3 -0
  6. package/dist/chunks/capturer/clipboard.js +575 -0
  7. package/dist/chunks/capturer/clipboard.js.map +1 -0
  8. package/dist/chunks/capturer/fonts.js +25 -0
  9. package/dist/chunks/capturer/fonts.js.map +1 -0
  10. package/dist/chunks/capturer/images.js +113 -0
  11. package/dist/chunks/capturer/images.js.map +1 -0
  12. package/dist/chunks/capturer/index.js +445 -0
  13. package/dist/chunks/capturer/index.js.map +1 -0
  14. package/dist/chunks/design-document.js +251 -0
  15. package/dist/chunks/design-document.js.map +1 -0
  16. package/dist/chunks/index.js +125 -0
  17. package/dist/chunks/index.js.map +1 -0
  18. package/dist/clipboard.d.ts +106 -0
  19. package/dist/clipboard.d.ts.map +1 -0
  20. package/dist/index.d.ts +110 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +4 -0
  23. package/package.json +43 -4
  24. package/src/capturer/clipboard.ts +59 -0
  25. package/src/capturer/fonts.ts +30 -0
  26. package/src/capturer/images.ts +153 -0
  27. package/src/capturer/index.ts +170 -0
  28. package/src/capturer/page.ts +51 -0
  29. package/src/capturer/svg.ts +79 -0
  30. package/src/capturer/walk.ts +283 -0
  31. package/src/clipboard.ts +85 -0
  32. package/src/design-document.ts +267 -0
  33. package/src/format.ts +17 -0
  34. package/src/html.ts +44 -0
  35. package/src/index.ts +41 -0
  36. package/src/limits.ts +23 -0
  37. package/src/parse.ts +165 -0
  38. package/src/record.ts +10 -0
  39. package/src/sanitize.ts +134 -0
  40. package/src/schema.ts +75 -0
  41. package/src/styles.ts +163 -0
  42. package/src/types.ts +28 -0
  43. package/src/urls.ts +27 -0
@@ -0,0 +1,445 @@
1
+ import { CAPTURED_STYLE_PROPERTIES, WEB_CAPTURE_FORMAT, normalizeWebCapture, withoutImpliedValues } from "./clipboard.js";
2
+ import { createFontCollector } from "./fonts.js";
3
+ import { createImageInliner } from "./images.js";
4
+ //#region src/capturer/svg.ts
5
+ /**
6
+ * Presentation properties an icon usually takes from the page's stylesheets or `currentColor`,
7
+ * which a standalone SVG loses. They are written onto the copy as inline styles.
8
+ */
9
+ const PRESENTATION_PROPERTIES = [
10
+ "fill",
11
+ "fill-opacity",
12
+ "fill-rule",
13
+ "stroke",
14
+ "stroke-width",
15
+ "stroke-opacity",
16
+ "stroke-linecap",
17
+ "stroke-linejoin",
18
+ "stroke-dasharray",
19
+ "opacity",
20
+ "color",
21
+ "font-family",
22
+ "font-size",
23
+ "font-weight",
24
+ "display",
25
+ "visibility"
26
+ ];
27
+ /** Elements whose styles are copied; very large drawings keep the rest as they are. */
28
+ const MAX_STYLED_ELEMENTS = 4e3;
29
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
30
+ function inlineStyles(view, original, copy) {
31
+ const style = view.getComputedStyle(original);
32
+ const declarations = PRESENTATION_PROPERTIES.flatMap((property) => {
33
+ const value = style.getPropertyValue(property);
34
+ return value ? [`${property}:${value}`] : [];
35
+ });
36
+ if (declarations.length > 0) copy.setAttribute("style", declarations.join(";"));
37
+ }
38
+ /** A `<use>` pointing at an icon sprite elsewhere in the page needs that sprite in the copy. */
39
+ function referencedSymbols(svg, document) {
40
+ const symbols = /* @__PURE__ */ new Set();
41
+ for (const use of svg.querySelectorAll("use")) {
42
+ const reference = use.getAttribute("href") ?? use.getAttribute("xlink:href") ?? "";
43
+ if (!reference.startsWith("#")) continue;
44
+ const target = document.getElementById(reference.slice(1));
45
+ if (target && !svg.contains(target)) symbols.add(target);
46
+ }
47
+ return [...symbols];
48
+ }
49
+ /**
50
+ * The SVG as standalone markup that draws as it did on the page: its computed presentation
51
+ * styles inlined, sprites it references copied in, and its drawn size set.
52
+ */
53
+ function standaloneSVGMarkup(view, svg, size) {
54
+ const copy = svg.cloneNode(true);
55
+ if (!(copy instanceof view.SVGSVGElement)) return "";
56
+ const originals = [svg, ...svg.querySelectorAll("*")];
57
+ const copies = [copy, ...copy.querySelectorAll("*")];
58
+ for (const [index, original] of originals.slice(0, MAX_STYLED_ELEMENTS).entries()) {
59
+ const target = copies.at(index);
60
+ if (target) inlineStyles(view, original, target);
61
+ }
62
+ const symbols = referencedSymbols(svg, svg.ownerDocument);
63
+ if (symbols.length > 0) {
64
+ const defs = svg.ownerDocument.createElementNS(SVG_NAMESPACE, "defs");
65
+ for (const symbol of symbols) defs.append(symbol.cloneNode(true));
66
+ copy.prepend(defs);
67
+ }
68
+ copy.setAttribute("xmlns", SVG_NAMESPACE);
69
+ copy.setAttribute("width", String(size.width));
70
+ copy.setAttribute("height", String(size.height));
71
+ return new view.XMLSerializer().serializeToString(copy);
72
+ }
73
+ //#endregion
74
+ //#region src/capturer/walk.ts
75
+ /** Elements that never draw, or draw another document a page cannot read. */
76
+ const SKIPPED_TAGS = /* @__PURE__ */ new Set([
77
+ "script",
78
+ "style",
79
+ "link",
80
+ "meta",
81
+ "head",
82
+ "title",
83
+ "template",
84
+ "noscript",
85
+ "base",
86
+ "iframe",
87
+ "frame",
88
+ "object",
89
+ "embed",
90
+ "source",
91
+ "track",
92
+ "param"
93
+ ]);
94
+ const KEPT_ATTRIBUTES = [
95
+ "id",
96
+ "class",
97
+ "alt",
98
+ "title",
99
+ "role",
100
+ "aria-label",
101
+ "lang",
102
+ "dir"
103
+ ];
104
+ /** Input types whose value is text a person reads in the field. */
105
+ const TEXT_INPUT_TYPES = /* @__PURE__ */ new Set([
106
+ "",
107
+ "text",
108
+ "email",
109
+ "search",
110
+ "url",
111
+ "tel",
112
+ "number",
113
+ "password"
114
+ ]);
115
+ const BACKGROUND_URL = /url\(\s*(['"]?)(.*?)\1\s*\)/;
116
+ function boxOf(element, origin) {
117
+ const rect = element.getBoundingClientRect();
118
+ return {
119
+ x: rect.left - origin.x,
120
+ y: rect.top - origin.y,
121
+ width: rect.width,
122
+ height: rect.height
123
+ };
124
+ }
125
+ function attributesOf(element, view) {
126
+ const attrs = {};
127
+ for (const name of KEPT_ATTRIBUTES) {
128
+ const value = element.getAttribute(name);
129
+ if (value !== null && value !== "") attrs[name] = value;
130
+ }
131
+ if (element instanceof view.HTMLAnchorElement && element.hasAttribute("href") && element.href) attrs.href = element.href;
132
+ return attrs;
133
+ }
134
+ function readStyle(style) {
135
+ const computed = {};
136
+ for (const property of CAPTURED_STYLE_PROPERTIES) {
137
+ const value = style.getPropertyValue(property);
138
+ if (value) computed[property] = value;
139
+ }
140
+ const visibility = style.getPropertyValue("visibility");
141
+ if (visibility === "hidden" || visibility === "collapse") computed.opacity = "0";
142
+ return withoutImpliedValues(computed);
143
+ }
144
+ function hasDirectText(element) {
145
+ return [...element.childNodes].some((child) => child.nodeType === 3 && (child.textContent ?? "").trim().length > 0);
146
+ }
147
+ /** The nodes an element draws: its shadow tree with slots filled when it has an open one. */
148
+ function renderedChildren(element, view) {
149
+ return [...element.shadowRoot ? element.shadowRoot.childNodes : element.childNodes].flatMap((child) => {
150
+ if (child instanceof view.HTMLSlotElement) {
151
+ const assigned = child.assignedNodes({ flatten: true });
152
+ return assigned.length > 0 ? assigned : [...child.childNodes];
153
+ }
154
+ return [child];
155
+ });
156
+ }
157
+ function controlText(element, view) {
158
+ if (element instanceof view.HTMLTextAreaElement) return element.value || element.placeholder || null;
159
+ if (element instanceof view.HTMLSelectElement) return element.selectedOptions.item(0)?.text ?? null;
160
+ if (element instanceof view.HTMLInputElement) {
161
+ if (!TEXT_INPUT_TYPES.has(element.type)) return element.type === "button" || element.type === "submit" ? element.value : null;
162
+ if (element.type === "password" && element.value) return "•".repeat(element.value.length);
163
+ return element.value || element.placeholder || null;
164
+ }
165
+ return null;
166
+ }
167
+ /** Reads an image in the background and writes it as the element's source. */
168
+ function inlineSource(context, node, read) {
169
+ context.pending.push(read().then((source) => {
170
+ if (source) node.attrs.src = source;
171
+ }));
172
+ }
173
+ function imageSize(box) {
174
+ return {
175
+ width: Math.round(box.width),
176
+ height: Math.round(box.height)
177
+ };
178
+ }
179
+ /** What a canvas shows, or null when it drew another site's image, which taints it. */
180
+ function canvasDataURL(canvas) {
181
+ try {
182
+ return canvas.toDataURL("image/png");
183
+ } catch {
184
+ return null;
185
+ }
186
+ }
187
+ function captureReplaced(element, node, context) {
188
+ const { view } = context;
189
+ const box = node.box ?? {
190
+ x: 0,
191
+ y: 0,
192
+ width: 0,
193
+ height: 0
194
+ };
195
+ if (element instanceof view.SVGSVGElement) {
196
+ node.tagName = "img";
197
+ if (box.width > 0 && box.height > 0) {
198
+ const markup = standaloneSVGMarkup(view, element, imageSize(box));
199
+ inlineSource(context, node, () => context.images.rasterizeSVG(markup, imageSize(box)));
200
+ }
201
+ return true;
202
+ }
203
+ if (element instanceof view.HTMLImageElement) {
204
+ const source = element.currentSrc || element.src;
205
+ if (source) {
206
+ node.attrs.src = source;
207
+ inlineSource(context, node, () => context.images.inline(source, imageSize(box)));
208
+ }
209
+ return true;
210
+ }
211
+ if (element instanceof view.HTMLCanvasElement) {
212
+ node.tagName = "img";
213
+ const drawn = canvasDataURL(element);
214
+ const source = drawn && context.images.accept(drawn);
215
+ if (source) node.attrs.src = source;
216
+ return true;
217
+ }
218
+ if (element instanceof view.HTMLVideoElement) {
219
+ node.tagName = "img";
220
+ const poster = element.poster;
221
+ if (poster) inlineSource(context, node, () => context.images.inline(poster, imageSize(box)));
222
+ return true;
223
+ }
224
+ const text = controlText(element, view);
225
+ if (text !== null) {
226
+ node.children = [{
227
+ type: "text",
228
+ text
229
+ }];
230
+ return true;
231
+ }
232
+ return false;
233
+ }
234
+ /**
235
+ * A background image becomes an image: the element itself when it holds nothing else, or an
236
+ * image layer behind its content otherwise, since layers have no background images.
237
+ */
238
+ function captureBackground(style, node, context) {
239
+ const url = BACKGROUND_URL.exec(style.getPropertyValue("background-image"))?.[2];
240
+ const box = node.box;
241
+ if (!url || !box || box.width <= 0 || box.height <= 0) return;
242
+ const fit = style.getPropertyValue("background-size") === "contain" ? "contain" : "cover";
243
+ if (node.tagName !== "img" && node.children.length === 0) {
244
+ node.tagName = "img";
245
+ node.computedStyle["object-fit"] = fit;
246
+ inlineSource(context, node, () => context.images.inline(url));
247
+ return;
248
+ }
249
+ if (node.tagName === "img") return;
250
+ const image = {
251
+ type: "element",
252
+ tagName: "img",
253
+ attrs: {},
254
+ computedStyle: {
255
+ ...Object.fromEntries(Object.entries(node.computedStyle).filter(([property]) => property.endsWith("-radius"))),
256
+ display: "block",
257
+ position: "absolute",
258
+ left: "0px",
259
+ top: "0px",
260
+ width: `${box.width}px`,
261
+ height: `${box.height}px`,
262
+ "object-fit": fit
263
+ },
264
+ box,
265
+ children: []
266
+ };
267
+ inlineSource(context, image, () => context.images.inline(url));
268
+ node.children.unshift(image);
269
+ }
270
+ function captureChildren(element, context, depth) {
271
+ return renderedChildren(element, context.view).flatMap((child) => {
272
+ if (child.nodeType === 3) {
273
+ const text = child.textContent ?? "";
274
+ return text.length > 0 ? [{
275
+ type: "text",
276
+ text
277
+ }] : [];
278
+ }
279
+ return child instanceof context.view.Element ? walkElement(child, context, depth + 1) : [];
280
+ });
281
+ }
282
+ /**
283
+ * The element as a capture holds it, with its descendants; several nodes when it has no box
284
+ * of its own (`display: contents`) and none when it is not displayed.
285
+ */
286
+ function walkElement(element, context, depth = 0) {
287
+ const tagName = element.localName.toLowerCase();
288
+ if (SKIPPED_TAGS.has(tagName)) return [];
289
+ const style = context.view.getComputedStyle(element);
290
+ const display = style.getPropertyValue("display");
291
+ if (display === "none") return [];
292
+ if (display === "contents") return captureChildren(element, context, depth);
293
+ if (depth > 256 || context.elements >= context.maxElements) {
294
+ context.truncated = true;
295
+ return [];
296
+ }
297
+ context.elements++;
298
+ const node = {
299
+ type: "element",
300
+ tagName,
301
+ attrs: attributesOf(element, context.view),
302
+ computedStyle: readStyle(style),
303
+ box: boxOf(element, context.origin),
304
+ children: []
305
+ };
306
+ if (!captureReplaced(element, node, context)) node.children = captureChildren(element, context, depth);
307
+ if (hasDirectText(element) || node.children.some((child) => child.type === "text")) context.fonts.add(style);
308
+ captureBackground(style, node, context);
309
+ return [node];
310
+ }
311
+ //#endregion
312
+ //#region src/capturer/index.ts
313
+ const NO_IMAGES = {
314
+ inline: async () => null,
315
+ rasterizeSVG: async () => null,
316
+ accept: () => null
317
+ };
318
+ function windowOf(document) {
319
+ const view = document.defaultView;
320
+ if (!view) throw new TypeError("Capturing needs a document shown in a window");
321
+ return view;
322
+ }
323
+ function createContext(view, origin, options) {
324
+ return {
325
+ view,
326
+ origin,
327
+ maxElements: options.maxElements ?? 2e4,
328
+ elements: 0,
329
+ truncated: false,
330
+ images: options.inlineImages === false ? NO_IMAGES : createImageInliner(view, {
331
+ fetchImage: options.fetchImage,
332
+ maxImageBytes: options.maxImageBytes,
333
+ maxTotalBytes: options.maxTotalImageBytes,
334
+ signal: options.signal
335
+ }),
336
+ fonts: createFontCollector(),
337
+ pending: []
338
+ };
339
+ }
340
+ async function finish(context, root, scope, options) {
341
+ await Promise.all(context.pending);
342
+ options.signal?.throwIfAborted();
343
+ const { view } = context;
344
+ return normalizeWebCapture({
345
+ format: WEB_CAPTURE_FORMAT,
346
+ version: 1,
347
+ scope,
348
+ source: {
349
+ url: view.location.href || void 0,
350
+ title: view.document.title || void 0
351
+ },
352
+ capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
353
+ viewport: {
354
+ width: view.innerWidth,
355
+ height: view.innerHeight,
356
+ devicePixelRatio: view.devicePixelRatio || 1
357
+ },
358
+ root,
359
+ fonts: context.fonts.list(),
360
+ truncated: context.truncated
361
+ });
362
+ }
363
+ /** The single root a walk returns; an element without a box of its own gets one around it. */
364
+ function rootElement(element, context) {
365
+ const nodes = walkElement(element, context);
366
+ const first = nodes.at(0);
367
+ if (nodes.length === 1 && first?.type === "element") return first;
368
+ if (nodes.length === 0) throw new Error("The element is not displayed");
369
+ const rect = element.getBoundingClientRect();
370
+ return {
371
+ type: "element",
372
+ tagName: "div",
373
+ attrs: {},
374
+ computedStyle: { display: "block" },
375
+ box: {
376
+ x: 0,
377
+ y: 0,
378
+ width: rect.width,
379
+ height: rect.height
380
+ },
381
+ children: nodes
382
+ };
383
+ }
384
+ /**
385
+ * Captures one element of a live page with the styles the browser computed for it, its
386
+ * images inlined as data URLs. Runs in the page, as a content script or a capturer SDK does.
387
+ */
388
+ async function captureElement(element, options = {}) {
389
+ options.signal?.throwIfAborted();
390
+ const view = windowOf(element.ownerDocument);
391
+ const rect = element.getBoundingClientRect();
392
+ const context = createContext(view, {
393
+ x: rect.left,
394
+ y: rect.top
395
+ }, options);
396
+ return finish(context, rootElement(element, context), "element", options);
397
+ }
398
+ function isTransparent(color) {
399
+ return color === "" || color === "transparent" || color === "rgba(0, 0, 0, 0)";
400
+ }
401
+ /**
402
+ * Captures a whole page: the body at the page's full scroll size, on the background the page
403
+ * shows, with the body's margins kept as space around its content.
404
+ */
405
+ async function capturePage(document = globalThis.document, options = {}) {
406
+ options.signal?.throwIfAborted();
407
+ const view = windowOf(document);
408
+ const { body, documentElement } = document;
409
+ const pageRect = documentElement.getBoundingClientRect();
410
+ const context = createContext(view, {
411
+ x: pageRect.left,
412
+ y: pageRect.top
413
+ }, options);
414
+ const root = rootElement(body, context);
415
+ const bodyStyle = view.getComputedStyle(body);
416
+ const style = root.computedStyle;
417
+ for (const side of [
418
+ "top",
419
+ "right",
420
+ "bottom",
421
+ "left"
422
+ ]) {
423
+ const margin = Number.parseFloat(bodyStyle.getPropertyValue(`margin-${side}`)) || 0;
424
+ const padding = Number.parseFloat(bodyStyle.getPropertyValue(`padding-${side}`)) || 0;
425
+ if (margin + padding > 0) style[`padding-${side}`] = `${margin + padding}px`;
426
+ delete style[`margin-${side}`];
427
+ }
428
+ style["background-color"] = [bodyStyle, view.getComputedStyle(documentElement)].map((computed) => computed.getPropertyValue("background-color")).find((color) => !isTransparent(color)) ?? "rgb(255, 255, 255)";
429
+ const width = documentElement.clientWidth || pageRect.width;
430
+ const height = Math.max(documentElement.scrollHeight, view.innerHeight);
431
+ style.width = `${width}px`;
432
+ style.height = `${height}px`;
433
+ style["box-sizing"] = "border-box";
434
+ root.box = {
435
+ x: 0,
436
+ y: 0,
437
+ width,
438
+ height
439
+ };
440
+ return finish(context, root, "page", options);
441
+ }
442
+ //#endregion
443
+ export { captureElement, capturePage };
444
+
445
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/capturer/svg.ts","../../../src/capturer/walk.ts","../../../src/capturer/index.ts"],"sourcesContent":["import type { CaptureWindow, ImageSize } from './images'\n\n/**\n * Presentation properties an icon usually takes from the page's stylesheets or `currentColor`,\n * which a standalone SVG loses. They are written onto the copy as inline styles.\n */\nconst PRESENTATION_PROPERTIES = [\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'stroke',\n 'stroke-width',\n 'stroke-opacity',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-dasharray',\n 'opacity',\n 'color',\n 'font-family',\n 'font-size',\n 'font-weight',\n 'display',\n 'visibility'\n]\n\n/** Elements whose styles are copied; very large drawings keep the rest as they are. */\nconst MAX_STYLED_ELEMENTS = 4000\n\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg'\n\nfunction inlineStyles(view: CaptureWindow, original: Element, copy: Element): void {\n const style = view.getComputedStyle(original)\n const declarations = PRESENTATION_PROPERTIES.flatMap((property) => {\n const value = style.getPropertyValue(property)\n return value ? [`${property}:${value}`] : []\n })\n if (declarations.length > 0) copy.setAttribute('style', declarations.join(';'))\n}\n\n/** A `<use>` pointing at an icon sprite elsewhere in the page needs that sprite in the copy. */\nfunction referencedSymbols(svg: SVGSVGElement, document: Document): Element[] {\n const symbols = new Set<Element>()\n for (const use of svg.querySelectorAll('use')) {\n const reference = use.getAttribute('href') ?? use.getAttribute('xlink:href') ?? ''\n if (!reference.startsWith('#')) continue\n const target = document.getElementById(reference.slice(1))\n if (target && !svg.contains(target)) symbols.add(target)\n }\n return [...symbols]\n}\n\n/**\n * The SVG as standalone markup that draws as it did on the page: its computed presentation\n * styles inlined, sprites it references copied in, and its drawn size set.\n */\nexport function standaloneSVGMarkup(\n view: CaptureWindow,\n svg: SVGSVGElement,\n size: ImageSize\n): string {\n const copy = svg.cloneNode(true)\n if (!(copy instanceof view.SVGSVGElement)) return ''\n const originals = [svg, ...svg.querySelectorAll('*')]\n const copies = [copy, ...copy.querySelectorAll('*')]\n for (const [index, original] of originals.slice(0, MAX_STYLED_ELEMENTS).entries()) {\n const target = copies.at(index)\n if (target) inlineStyles(view, original, target)\n }\n const symbols = referencedSymbols(svg, svg.ownerDocument)\n if (symbols.length > 0) {\n const defs = svg.ownerDocument.createElementNS(SVG_NAMESPACE, 'defs')\n for (const symbol of symbols) defs.append(symbol.cloneNode(true))\n copy.prepend(defs)\n }\n copy.setAttribute('xmlns', SVG_NAMESPACE)\n copy.setAttribute('width', String(size.width))\n copy.setAttribute('height', String(size.height))\n return new view.XMLSerializer().serializeToString(copy)\n}\n","import { MAX_CAPTURE_DEPTH } from '#web-capture/limits'\nimport { CAPTURED_STYLE_PROPERTIES, withoutImpliedValues } from '#web-capture/styles'\nimport type { WebCaptureBox, WebCaptureElement, WebCaptureNode } from '#web-capture/types'\n\nimport type { FontCollector } from './fonts'\nimport type { CaptureWindow, ImageInliner } from './images'\nimport { standaloneSVGMarkup } from './svg'\n\n/** What a walk shares: the page, where the root sits, its budget, and work left to finish. */\nexport interface WalkContext {\n view: CaptureWindow\n origin: Pick<WebCaptureBox, 'x' | 'y'>\n maxElements: number\n elements: number\n truncated: boolean\n images: ImageInliner\n fonts: FontCollector\n /** Images still being read, each writing its element's source when done. */\n pending: Promise<void>[]\n}\n\n/** Elements that never draw, or draw another document a page cannot read. */\nconst SKIPPED_TAGS = new Set([\n 'script',\n 'style',\n 'link',\n 'meta',\n 'head',\n 'title',\n 'template',\n 'noscript',\n 'base',\n 'iframe',\n 'frame',\n 'object',\n 'embed',\n 'source',\n 'track',\n 'param'\n])\n\nconst KEPT_ATTRIBUTES = ['id', 'class', 'alt', 'title', 'role', 'aria-label', 'lang', 'dir']\n\n/** Input types whose value is text a person reads in the field. */\nconst TEXT_INPUT_TYPES = new Set([\n '',\n 'text',\n 'email',\n 'search',\n 'url',\n 'tel',\n 'number',\n 'password'\n])\n\nconst BACKGROUND_URL = /url\\(\\s*(['\"]?)(.*?)\\1\\s*\\)/\n\nfunction boxOf(element: Element, origin: WalkContext['origin']): WebCaptureBox {\n const rect = element.getBoundingClientRect()\n return {\n x: rect.left - origin.x,\n y: rect.top - origin.y,\n width: rect.width,\n height: rect.height\n }\n}\n\nfunction attributesOf(element: Element, view: CaptureWindow): Record<string, string> {\n const attrs: Record<string, string> = {}\n for (const name of KEPT_ATTRIBUTES) {\n const value = element.getAttribute(name)\n if (value !== null && value !== '') attrs[name] = value\n }\n // The resolved address, not the attribute as written, which may be relative.\n if (element instanceof view.HTMLAnchorElement && element.hasAttribute('href') && element.href) {\n attrs.href = element.href\n }\n return attrs\n}\n\nfunction readStyle(style: CSSStyleDeclaration): Record<string, string> {\n const computed: Record<string, string> = {}\n for (const property of CAPTURED_STYLE_PROPERTIES) {\n const value = style.getPropertyValue(property)\n if (value) computed[property] = value\n }\n // A hidden box keeps its room but draws nothing, as a transparent layer does.\n const visibility = style.getPropertyValue('visibility')\n if (visibility === 'hidden' || visibility === 'collapse') computed.opacity = '0'\n return withoutImpliedValues(computed)\n}\n\nfunction hasDirectText(element: Element): boolean {\n return [...element.childNodes].some(\n (child) => child.nodeType === 3 && (child.textContent ?? '').trim().length > 0\n )\n}\n\n/** The nodes an element draws: its shadow tree with slots filled when it has an open one. */\nfunction renderedChildren(element: Element, view: CaptureWindow): Node[] {\n const source = element.shadowRoot ? element.shadowRoot.childNodes : element.childNodes\n return [...source].flatMap((child) => {\n if (child instanceof view.HTMLSlotElement) {\n const assigned = child.assignedNodes({ flatten: true })\n return assigned.length > 0 ? assigned : [...child.childNodes]\n }\n return [child]\n })\n}\n\nfunction controlText(element: Element, view: CaptureWindow): string | null {\n if (element instanceof view.HTMLTextAreaElement) {\n return element.value || element.placeholder || null\n }\n if (element instanceof view.HTMLSelectElement) {\n return element.selectedOptions.item(0)?.text ?? null\n }\n if (element instanceof view.HTMLInputElement) {\n if (!TEXT_INPUT_TYPES.has(element.type)) {\n return element.type === 'button' || element.type === 'submit' ? element.value : null\n }\n if (element.type === 'password' && element.value) return '•'.repeat(element.value.length)\n return element.value || element.placeholder || null\n }\n return null\n}\n\n/** Reads an image in the background and writes it as the element's source. */\nfunction inlineSource(\n context: WalkContext,\n node: WebCaptureElement,\n read: () => Promise<string | null>\n): void {\n context.pending.push(\n read().then((source) => {\n if (source) node.attrs.src = source\n return undefined\n })\n )\n}\n\nfunction imageSize(box: WebCaptureBox) {\n return { width: Math.round(box.width), height: Math.round(box.height) }\n}\n\n/** What a canvas shows, or null when it drew another site's image, which taints it. */\nfunction canvasDataURL(canvas: HTMLCanvasElement): string | null {\n try {\n return canvas.toDataURL('image/png')\n } catch {\n return null\n }\n}\n\nfunction captureReplaced(element: Element, node: WebCaptureElement, context: WalkContext): boolean {\n const { view } = context\n const box = node.box ?? { x: 0, y: 0, width: 0, height: 0 }\n if (element instanceof view.SVGSVGElement) {\n node.tagName = 'img'\n if (box.width > 0 && box.height > 0) {\n const markup = standaloneSVGMarkup(view, element, imageSize(box))\n inlineSource(context, node, () => context.images.rasterizeSVG(markup, imageSize(box)))\n }\n return true\n }\n if (element instanceof view.HTMLImageElement) {\n const source = element.currentSrc || element.src\n if (source) {\n // The address stays when the image cannot be inlined; the importer records it.\n node.attrs.src = source\n inlineSource(context, node, () => context.images.inline(source, imageSize(box)))\n }\n return true\n }\n if (element instanceof view.HTMLCanvasElement) {\n node.tagName = 'img'\n const drawn = canvasDataURL(element)\n const source = drawn && context.images.accept(drawn)\n if (source) node.attrs.src = source\n return true\n }\n if (element instanceof view.HTMLVideoElement) {\n node.tagName = 'img'\n const poster = element.poster\n if (poster) inlineSource(context, node, () => context.images.inline(poster, imageSize(box)))\n return true\n }\n const text = controlText(element, view)\n if (text !== null) {\n node.children = [{ type: 'text', text }]\n return true\n }\n return false\n}\n\n/**\n * A background image becomes an image: the element itself when it holds nothing else, or an\n * image layer behind its content otherwise, since layers have no background images.\n */\nfunction captureBackground(\n style: CSSStyleDeclaration,\n node: WebCaptureElement,\n context: WalkContext\n) {\n const match = BACKGROUND_URL.exec(style.getPropertyValue('background-image'))\n const url = match?.[2]\n const box = node.box\n if (!url || !box || box.width <= 0 || box.height <= 0) return\n const fit = style.getPropertyValue('background-size') === 'contain' ? 'contain' : 'cover'\n if (node.tagName !== 'img' && node.children.length === 0) {\n node.tagName = 'img'\n node.computedStyle['object-fit'] = fit\n inlineSource(context, node, () => context.images.inline(url))\n return\n }\n if (node.tagName === 'img') return\n const radii = Object.fromEntries(\n Object.entries(node.computedStyle).filter(([property]) => property.endsWith('-radius'))\n )\n const image: WebCaptureElement = {\n type: 'element',\n tagName: 'img',\n attrs: {},\n computedStyle: {\n ...radii,\n display: 'block',\n position: 'absolute',\n left: '0px',\n top: '0px',\n width: `${box.width}px`,\n height: `${box.height}px`,\n 'object-fit': fit\n },\n box,\n children: []\n }\n inlineSource(context, image, () => context.images.inline(url))\n node.children.unshift(image)\n}\n\nfunction captureChildren(element: Element, context: WalkContext, depth: number): WebCaptureNode[] {\n return renderedChildren(element, context.view).flatMap((child) => {\n if (child.nodeType === 3) {\n const text = child.textContent ?? ''\n return text.length > 0 ? [{ type: 'text' as const, text }] : []\n }\n return child instanceof context.view.Element ? walkElement(child, context, depth + 1) : []\n })\n}\n\n/**\n * The element as a capture holds it, with its descendants; several nodes when it has no box\n * of its own (`display: contents`) and none when it is not displayed.\n */\nexport function walkElement(element: Element, context: WalkContext, depth = 0): WebCaptureNode[] {\n const tagName = element.localName.toLowerCase()\n if (SKIPPED_TAGS.has(tagName)) return []\n const style = context.view.getComputedStyle(element)\n const display = style.getPropertyValue('display')\n if (display === 'none') return []\n if (display === 'contents') return captureChildren(element, context, depth)\n if (depth > MAX_CAPTURE_DEPTH || context.elements >= context.maxElements) {\n context.truncated = true\n return []\n }\n context.elements++\n const node: WebCaptureElement = {\n type: 'element',\n tagName,\n attrs: attributesOf(element, context.view),\n computedStyle: readStyle(style),\n box: boxOf(element, context.origin),\n children: []\n }\n if (!captureReplaced(element, node, context)) {\n node.children = captureChildren(element, context, depth)\n }\n if (hasDirectText(element) || node.children.some((child) => child.type === 'text')) {\n context.fonts.add(style)\n }\n captureBackground(style, node, context)\n return [node]\n}\n","import type { WebCapture } from '#web-capture/format'\nimport { MAX_CAPTURE_ELEMENTS, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION } from '#web-capture/limits'\nimport { normalizeWebCapture } from '#web-capture/parse'\nimport type { WebCaptureElement } from '#web-capture/types'\n\nimport { createFontCollector } from './fonts'\nimport {\n createImageInliner,\n type CaptureImageFetcher,\n type CaptureWindow,\n type ImageInliner\n} from './images'\nimport { walkElement, type WalkContext } from './walk'\n\nexport {\n CaptureClipboardUnavailableError,\n writeWebCaptureClipboard,\n type CaptureClipboard,\n type WriteCaptureClipboardOptions\n} from './clipboard'\nexport type { CaptureImageFetcher } from './images'\n\nexport interface CaptureOptions {\n /** Elements to capture at most; the capture is marked truncated when the page has more. */\n maxElements?: number\n /** Carry images inside the capture as data URLs (the default), or keep only their addresses. */\n inlineImages?: boolean\n /** Reads images the page cannot, such as another site's without CORS headers. */\n fetchImage?: CaptureImageFetcher\n /** Bytes one inlined image may take. */\n maxImageBytes?: number\n /** Bytes all inlined images may take together. */\n maxTotalImageBytes?: number\n signal?: AbortSignal\n}\n\nconst NO_IMAGES: ImageInliner = {\n inline: async () => null,\n rasterizeSVG: async () => null,\n accept: () => null\n}\n\nfunction windowOf(document: Document): CaptureWindow {\n const view = document.defaultView\n if (!view) throw new TypeError('Capturing needs a document shown in a window')\n return view\n}\n\nfunction createContext(\n view: CaptureWindow,\n origin: WalkContext['origin'],\n options: CaptureOptions\n): WalkContext {\n return {\n view,\n origin,\n maxElements: options.maxElements ?? MAX_CAPTURE_ELEMENTS,\n elements: 0,\n truncated: false,\n images:\n options.inlineImages === false\n ? NO_IMAGES\n : createImageInliner(view, {\n fetchImage: options.fetchImage,\n maxImageBytes: options.maxImageBytes,\n maxTotalBytes: options.maxTotalImageBytes,\n signal: options.signal\n }),\n fonts: createFontCollector(),\n pending: []\n }\n}\n\nasync function finish(\n context: WalkContext,\n root: WebCaptureElement,\n scope: WebCapture['scope'],\n options: CaptureOptions\n): Promise<WebCapture> {\n await Promise.all(context.pending)\n options.signal?.throwIfAborted()\n const { view } = context\n return normalizeWebCapture({\n format: WEB_CAPTURE_FORMAT,\n version: WEB_CAPTURE_VERSION,\n scope,\n source: { url: view.location.href || undefined, title: view.document.title || undefined },\n capturedAt: new Date().toISOString(),\n viewport: {\n width: view.innerWidth,\n height: view.innerHeight,\n devicePixelRatio: view.devicePixelRatio || 1\n },\n root,\n fonts: context.fonts.list(),\n truncated: context.truncated\n })\n}\n\n/** The single root a walk returns; an element without a box of its own gets one around it. */\nfunction rootElement(element: Element, context: WalkContext): WebCaptureElement {\n const nodes = walkElement(element, context)\n const first = nodes.at(0)\n if (nodes.length === 1 && first?.type === 'element') return first\n if (nodes.length === 0) throw new Error('The element is not displayed')\n const rect = element.getBoundingClientRect()\n return {\n type: 'element',\n tagName: 'div',\n attrs: {},\n computedStyle: { display: 'block' },\n box: { x: 0, y: 0, width: rect.width, height: rect.height },\n children: nodes\n }\n}\n\n/**\n * Captures one element of a live page with the styles the browser computed for it, its\n * images inlined as data URLs. Runs in the page, as a content script or a capturer SDK does.\n */\nexport async function captureElement(\n element: Element,\n options: CaptureOptions = {}\n): Promise<WebCapture> {\n options.signal?.throwIfAborted()\n const view = windowOf(element.ownerDocument)\n const rect = element.getBoundingClientRect()\n const context = createContext(view, { x: rect.left, y: rect.top }, options)\n return finish(context, rootElement(element, context), 'element', options)\n}\n\nfunction isTransparent(color: string): boolean {\n return color === '' || color === 'transparent' || color === 'rgba(0, 0, 0, 0)'\n}\n\n/**\n * Captures a whole page: the body at the page's full scroll size, on the background the page\n * shows, with the body's margins kept as space around its content.\n */\nexport async function capturePage(\n document: Document = globalThis.document,\n options: CaptureOptions = {}\n): Promise<WebCapture> {\n options.signal?.throwIfAborted()\n const view = windowOf(document)\n const { body, documentElement } = document\n const pageRect = documentElement.getBoundingClientRect()\n const context = createContext(view, { x: pageRect.left, y: pageRect.top }, options)\n const root = rootElement(body, context)\n const bodyStyle = view.getComputedStyle(body)\n const style = root.computedStyle\n for (const side of ['top', 'right', 'bottom', 'left'] as const) {\n const margin = Number.parseFloat(bodyStyle.getPropertyValue(`margin-${side}`)) || 0\n const padding = Number.parseFloat(bodyStyle.getPropertyValue(`padding-${side}`)) || 0\n if (margin + padding > 0) style[`padding-${side}`] = `${margin + padding}px`\n delete style[`margin-${side}`]\n }\n const background = [bodyStyle, view.getComputedStyle(documentElement)]\n .map((computed) => computed.getPropertyValue('background-color'))\n .find((color) => !isTransparent(color))\n style['background-color'] = background ?? 'rgb(255, 255, 255)'\n // The page's size, not the body's, which may be shorter than the window.\n const width = documentElement.clientWidth || pageRect.width\n const height = Math.max(documentElement.scrollHeight, view.innerHeight)\n style.width = `${width}px`\n style.height = `${height}px`\n style['box-sizing'] = 'border-box'\n root.box = { x: 0, y: 0, width, height }\n return finish(context, root, 'page', options)\n}\n"],"mappings":";;;;;;;;AAMA,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,sBAAsB;AAE5B,MAAM,gBAAgB;AAEtB,SAAS,aAAa,MAAqB,UAAmB,MAAqB;CACjF,MAAM,QAAQ,KAAK,iBAAiB,QAAQ;CAC5C,MAAM,eAAe,wBAAwB,SAAS,aAAa;EACjE,MAAM,QAAQ,MAAM,iBAAiB,QAAQ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