@pairdraw/web-capture 0.19.1 → 0.20.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/dist/chunks/capturer/clipboard.js +409 -8
- package/dist/chunks/capturer/clipboard.js.map +1 -1
- package/dist/chunks/capturer/index.js +60 -11
- package/dist/chunks/capturer/index.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/package.json +1 -1
- package/src/capturer/index.ts +22 -14
- package/src/capturer/walk.ts +54 -0
- package/src/design-document.ts +47 -0
- package/src/html.ts +68 -9
- package/src/styles.ts +2 -0
- package/dist/chunks/design-document.js +0 -310
- package/dist/chunks/design-document.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","names":[],"sources":["../../../src/record.ts","../../../src/html.ts","../../../src/limits.ts","../../../src/schema.ts","../../../src/styles.ts","../../../src/urls.ts","../../../src/parse.ts","../../../src/clipboard.ts","../../../src/capturer/clipboard.ts"],"sourcesContent":["/**\n * The value a style or attribute record sets for `key`, or undefined when it sets none. Records\n * are typed as setting every key, which they do not.\n */\nexport function ownValue(\n record: Readonly<Record<string, string>>,\n key: string\n): string | undefined {\n return Object.hasOwn(record, key) ? record[key] : undefined\n}\n","import { escapeAttribute, escapeText } from 'entities'\n\nimport type { WebCapture } from './format'\nimport { ownValue } from './record'\nimport type { WebCaptureElement, WebCaptureNode } from './types'\n\nconst VOID_TAGS = new Set(['area', 'br', 'col', 'hr', 'img', 'input', 'source', 'wbr'])\n\nexport interface WebCaptureHTMLOptions {\n /** Keep inlined images; without them an image keeps only its size and description. */\n images?: boolean\n}\n\nfunction styleAttribute(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([property, value]) => `${property}: ${value}`)\n .join('; ')\n}\n\nfunction attributes(element: WebCaptureElement, options: WebCaptureHTMLOptions): string {\n const attrs: Record<string, string> = { ...element.attrs }\n if (options.images === false && ownValue(attrs, 'src')?.startsWith('data:')) delete attrs.src\n const style = styleAttribute(element.computedStyle)\n if (style) attrs.style = style\n return Object.entries(attrs)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('')\n}\n\nfunction serialize(node: WebCaptureNode, options: WebCaptureHTMLOptions): string {\n if (node.type === 'text') return escapeText(node.text)\n const open = `<${node.tagName}${attributes(node, options)}>`\n if (VOID_TAGS.has(node.tagName)) return open\n const children = node.children.map((child) => serialize(child, options)).join('')\n return `${open}${children}</${node.tagName}>`\n}\n\n/**\n * The capture as static HTML whose elements carry their computed styles inline, for\n * applications that read clipboard HTML but not the capture itself.\n */\nexport function webCaptureToHTML(capture: WebCapture, options: WebCaptureHTMLOptions = {}): string {\n return serialize(capture.root, options)\n}\n","/** The capture format identifier that clipboard payloads and files carry. */\nexport const WEB_CAPTURE_FORMAT = 'pairdraw/web-capture'\n\n/** The capture format version this package writes and reads. */\nexport const WEB_CAPTURE_VERSION = 1\n\n/** Elements one capture holds at most; a capturer stops descending once it reaches this. */\nexport const MAX_CAPTURE_ELEMENTS = 20_000\n\n/** How deep a capture nests; deeper elements are left out, as browsers rarely draw them. */\nexport const MAX_CAPTURE_DEPTH = 256\n\n/** Bytes one inlined image may take; a larger image stays a link the importer records. */\nexport const MAX_CAPTURE_IMAGE_BYTES = 8 * 1024 * 1024\n\n/** Bytes all inlined images of a capture take together. */\nexport const MAX_CAPTURE_IMAGES_BYTES = 48 * 1024 * 1024\n\n/** Characters of serialized capture JSON a reader accepts, images included. */\nexport const MAX_CAPTURE_JSON_LENGTH = 96 * 1024 * 1024\n\n/** Characters of plain web HTML a paste styles; a larger fragment is refused. */\nexport const MAX_WEB_HTML_LENGTH = 8 * 1024 * 1024\n","import * as v from 'valibot'\n\nimport { MAX_CAPTURE_JSON_LENGTH, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION } from './limits'\nimport type { WebCaptureElement, WebCaptureNode } from './types'\n\nconst finiteSchema = v.pipe(v.number(), v.finite())\nconst sizeSchema = v.pipe(v.number(), v.finite(), v.minValue(0))\nconst shortStringSchema = v.pipe(v.string(), v.maxLength(4096))\n\nconst webCaptureBoxSchema = v.object({\n x: finiteSchema,\n y: finiteSchema,\n width: sizeSchema,\n height: sizeSchema\n})\n\nconst webCaptureTextSchema = v.object({\n type: v.literal('text'),\n text: v.pipe(v.string(), v.maxLength(1_000_000))\n})\n\n/** HTML and SVG tag names, lowercase as a capturer writes them. */\nconst tagNameSchema = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9-]{0,63}$/))\n/** Attribute names; which of them an import keeps is decided when a capture is read. */\nconst attributeNameSchema = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9:_-]{0,63}$/))\n/** Attribute values hold inlined images as data URLs, so they may be large. */\nconst attributeValueSchema = v.pipe(v.string(), v.maxLength(MAX_CAPTURE_JSON_LENGTH))\nconst propertyNameSchema = v.pipe(v.string(), v.regex(/^-?[a-z][a-z-]{0,63}$/))\n\nconst webCaptureElementSchema: v.GenericSchema<unknown, WebCaptureElement> = v.object({\n type: v.literal('element'),\n tagName: tagNameSchema,\n attrs: v.record(attributeNameSchema, attributeValueSchema),\n computedStyle: v.record(propertyNameSchema, shortStringSchema),\n box: v.optional(webCaptureBoxSchema),\n children: v.array(v.lazy(() => webCaptureNodeSchema))\n})\n\nconst webCaptureNodeSchema: v.GenericSchema<unknown, WebCaptureNode> = v.union([\n webCaptureTextSchema,\n webCaptureElementSchema\n])\n\nexport const webCaptureFontSchema = v.object({\n family: shortStringSchema,\n weight: shortStringSchema,\n style: shortStringSchema\n})\n\nexport const webCaptureViewportSchema = v.object({\n width: sizeSchema,\n height: sizeSchema,\n devicePixelRatio: v.pipe(v.number(), v.finite(), v.minValue(0))\n})\n\nconst webCaptureSourceSchema = v.object({\n url: v.optional(shortStringSchema),\n title: v.optional(shortStringSchema)\n})\n\n/** A page or element captured with the styles the browser computed for it. */\nexport const webCaptureSchema = v.object({\n format: v.literal(WEB_CAPTURE_FORMAT),\n version: v.literal(WEB_CAPTURE_VERSION),\n /** Whether a whole page or one element of it was captured. */\n scope: v.picklist(['page', 'element']),\n source: webCaptureSourceSchema,\n /** When the capture was made, as an ISO 8601 timestamp. */\n capturedAt: shortStringSchema,\n viewport: webCaptureViewportSchema,\n root: webCaptureElementSchema,\n fonts: v.array(webCaptureFontSchema),\n /** Whether the capturer stopped at its element limit, leaving later content out. */\n truncated: v.boolean()\n})\n","import { ownValue } from './record'\n\n/**\n * The computed properties a capture keeps for each element: those `@pairdraw/dom-css` builds\n * layers from, plus margins, which a capture turns into spacing when it is imported.\n */\nexport const CAPTURED_STYLE_PROPERTIES = [\n 'align-items',\n 'align-self',\n 'aspect-ratio',\n 'background-color',\n 'background-image',\n 'background-position',\n 'background-repeat',\n 'background-size',\n 'border-bottom-color',\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-bottom-style',\n 'border-bottom-width',\n 'border-left-color',\n 'border-left-style',\n 'border-left-width',\n 'border-right-color',\n 'border-right-style',\n 'border-right-width',\n 'border-top-color',\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-top-style',\n 'border-top-width',\n 'bottom',\n 'box-shadow',\n 'box-sizing',\n 'color',\n 'column-gap',\n 'display',\n 'flex-direction',\n 'flex-wrap',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'gap',\n 'height',\n 'justify-content',\n 'left',\n 'letter-spacing',\n 'line-height',\n 'margin-bottom',\n 'margin-left',\n 'margin-right',\n 'margin-top',\n 'max-height',\n 'max-width',\n 'min-height',\n 'min-width',\n 'object-fit',\n 'opacity',\n 'overflow',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'position',\n 'right',\n 'row-gap',\n 'text-align',\n 'text-decoration-color',\n 'text-decoration-line',\n 'text-decoration-style',\n 'text-decoration-thickness',\n 'text-indent',\n 'text-shadow',\n 'text-transform',\n 'text-underline-offset',\n 'top',\n 'white-space',\n 'width'\n] as const\n\nexport type CapturedStyleProperty = (typeof CAPTURED_STYLE_PROPERTIES)[number]\n\nconst CAPTURED = new Set<string>(CAPTURED_STYLE_PROPERTIES)\n\n/** Whether a capture keeps this property; others are dropped when a capture is read. */\nexport function isCapturedStyleProperty(property: string): property is CapturedStyleProperty {\n return CAPTURED.has(property)\n}\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\n/**\n * Values the importer reads exactly as it reads a missing property, so leaving them out only\n * makes the capture smaller. Inherited text properties are always kept: a nested run reads\n * a missing one from its parent, which differs from the value the page computed.\n */\nconst IMPLIED_VALUES: Partial<Record<CapturedStyleProperty, readonly string[]>> = {\n 'align-items': ['normal'],\n 'align-self': ['auto'],\n 'aspect-ratio': ['auto'],\n 'background-color': ['rgba(0, 0, 0, 0)', 'transparent'],\n 'background-image': ['none'],\n 'background-position': ['0% 0%'],\n 'background-repeat': ['repeat'],\n 'background-size': ['auto'],\n 'box-shadow': ['none'],\n 'column-gap': ['normal'],\n 'flex-direction': ['row'],\n 'flex-wrap': ['nowrap'],\n gap: ['normal'],\n height: ['auto'],\n 'justify-content': ['normal'],\n 'max-height': ['none'],\n 'max-width': ['none'],\n 'min-height': ['auto', '0px'],\n 'min-width': ['auto', '0px'],\n 'object-fit': ['fill'],\n opacity: ['1'],\n overflow: ['visible'],\n 'row-gap': ['normal'],\n 'text-indent': ['0px'],\n width: ['auto']\n}\n\nconst ZERO_LENGTH_PROPERTIES = [\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-top-left-radius',\n 'border-top-right-radius',\n ...SIDES.map((side) => `padding-${side}` as const),\n ...SIDES.map((side) => `margin-${side}` as const)\n]\n\nconst TEXT_DECORATION_DETAILS = [\n 'text-decoration-color',\n 'text-decoration-style',\n 'text-decoration-thickness',\n 'text-underline-offset'\n]\n\n/**\n * The style without values that change nothing on import: defaults, borders without a style,\n * offsets of boxes in normal flow, and decoration details of undecorated text.\n */\nexport function withoutImpliedValues(style: Record<string, string>): Record<string, string> {\n const dropped = new Set<string>()\n for (const [property, values] of Object.entries(IMPLIED_VALUES)) {\n if (values.includes(ownValue(style, property) ?? '')) dropped.add(property)\n }\n for (const property of ZERO_LENGTH_PROPERTIES) {\n if (style[property] === '0px') dropped.add(property)\n }\n for (const side of SIDES) {\n const borderStyle = ownValue(style, `border-${side}-style`)\n if (borderStyle !== undefined && borderStyle !== 'none' && borderStyle !== 'hidden') continue\n for (const part of ['style', 'width', 'color']) dropped.add(`border-${side}-${part}`)\n }\n // Sticky boxes sit in normal flow until the page scrolls, which a still capture never does.\n const position = ownValue(style, 'position')\n const inFlow = position === undefined || position === 'static' || position === 'sticky'\n if (inFlow) dropped.add('position')\n for (const side of SIDES) {\n if (inFlow || style[side] === 'auto') dropped.add(side)\n }\n const decoration = ownValue(style, 'text-decoration-line')\n if (decoration === undefined || decoration === 'none') {\n for (const property of TEXT_DECORATION_DETAILS) dropped.add(property)\n }\n return Object.fromEntries(Object.entries(style).filter(([property]) => !dropped.has(property)))\n}\n","const LINK_PROTOCOLS = new Set(['http:', 'https:', 'mailto:'])\nconst IMAGE_PROTOCOLS = new Set(['http:', 'https:'])\n/** Raster images the canvas decodes; SVG is rasterized by the capturer instead. */\nconst DATA_IMAGE =\n /^data:image\\/(?:png|jpeg|gif|webp|avif|bmp|x-icon|vnd\\.microsoft\\.icon);base64,/i\n\nfunction resolve(value: string, base: string | undefined): URL | null {\n try {\n return new URL(value.trim(), base)\n } catch {\n return null\n }\n}\n\n/** A link a layer may keep: http, https, or mailto, resolved against the page; never script. */\nexport function safeLinkURL(value: string, base?: string): string | null {\n const url = resolve(value, base)\n return url && LINK_PROTOCOLS.has(url.protocol) ? url.href : null\n}\n\n/** An image source a layer may keep: an inlined raster image, or an http(s) address. */\nexport function safeImageSource(value: string, base?: string): string | null {\n const trimmed = value.trim()\n if (DATA_IMAGE.test(trimmed)) return trimmed\n const url = resolve(trimmed, base)\n return url && IMAGE_PROTOCOLS.has(url.protocol) ? url.href : null\n}\n","import * as v from 'valibot'\n\nimport type { WebCapture, WebCaptureReadResult } from './format'\nimport {\n MAX_CAPTURE_DEPTH,\n MAX_CAPTURE_ELEMENTS,\n MAX_CAPTURE_JSON_LENGTH,\n WEB_CAPTURE_FORMAT,\n WEB_CAPTURE_VERSION\n} from './limits'\nimport { webCaptureSchema } from './schema'\nimport { isCapturedStyleProperty } from './styles'\nimport type { WebCaptureElement, WebCaptureNode } from './types'\nimport { safeImageSource, safeLinkURL } from './urls'\n\n/** Read first, so a capture from a newer capturer is told apart from a damaged one. */\nconst captureHeaderSchema = v.looseObject({\n format: v.literal(WEB_CAPTURE_FORMAT),\n version: v.number()\n})\n\n/** Attributes a layer can use: names, links, images, control kinds, and accessible labels. */\nconst KEPT_ATTRIBUTES = new Set([\n 'id',\n 'class',\n 'href',\n 'src',\n 'alt',\n 'title',\n 'type',\n 'role',\n 'aria-label',\n 'lang',\n 'dir'\n])\n\n/** Elements that never draw, whatever a capture claims. */\nconst DROPPED_TAGS = new Set([\n 'script',\n 'style',\n 'link',\n 'meta',\n 'head',\n 'title',\n 'template',\n 'noscript',\n 'iframe',\n 'frame',\n 'object',\n 'embed',\n 'base'\n])\n\n/**\n * JSON nesting a capture within `MAX_CAPTURE_DEPTH` takes: an object and a `children` array per\n * element, the capture around the root, and the records of the deepest element, with room to\n * spare. Deeper values are refused before validation, whose recursion they could overflow.\n */\nconst MAX_JSON_NESTING = 2 * MAX_CAPTURE_DEPTH + 16\n\n/** Whether a value nests deeper than `limit`, walked without recursion; a cycle counts as deep. */\nfunction nestsDeeperThan(value: unknown, limit: number): boolean {\n const pending: { value: unknown; depth: number }[] = [{ value, depth: 0 }]\n for (let next = pending.pop(); next; next = pending.pop()) {\n if (typeof next.value !== 'object' || next.value === null) continue\n if (next.depth >= limit) return true\n const depth = next.depth + 1\n for (const child of Object.values(next.value)) pending.push({ value: child, depth })\n }\n return false\n}\n\ninterface Budget {\n elements: number\n truncated: boolean\n}\n\nfunction keptAttributes(\n attrs: Record<string, string>,\n base: string | undefined\n): Record<string, string> {\n const kept: Record<string, string> = {}\n for (const [name, value] of Object.entries(attrs)) {\n if (!KEPT_ATTRIBUTES.has(name)) continue\n if (name === 'href') {\n const href = safeLinkURL(value, base)\n if (href) kept.href = href\n } else if (name === 'src') {\n const src = safeImageSource(value, base)\n if (src) kept.src = src\n } else {\n kept[name] = value\n }\n }\n return kept\n}\n\n/** The `url(...)` sources of a value, with the spans they occupy. */\nconst BACKGROUND_URL = /url\\(\\s*(['\"]?)(.*?)\\1\\s*\\)/g\n\n/**\n * A `background-image` list with every `url(...)` source limited to what an image layer may\n * keep; a layer whose source is unsafe is dropped, and a list left empty paints nothing.\n * Gradient layers carry no address and pass through as written.\n */\nfunction keptBackgroundImage(value: string, base: string | undefined): string | null {\n const layers: string[] = []\n let cursor = 0\n let dropped = false\n for (const match of value.matchAll(BACKGROUND_URL)) {\n const source = safeImageSource(match[2], base)\n if (source) layers.push(value.slice(cursor, match.index) + `url(\"${source}\")`)\n else dropped = true\n cursor = match.index + match[0].length\n }\n if (cursor === 0 && !dropped) return value\n layers.push(value.slice(cursor))\n // Split at top-level commas only: a gradient's own commas stay inside its parentheses.\n const kept: string[] = []\n let depth = 0\n let current = ''\n for (const character of layers.join('')) {\n if (character === '(') depth++\n else if (character === ')') depth--\n if (character === ',' && depth === 0) {\n kept.push(current)\n current = ''\n continue\n }\n current += character\n }\n kept.push(current)\n const painted = kept\n .map((layer) => layer.trim())\n .filter((layer) => layer.length > 0 && layer !== 'none')\n return painted.length > 0 ? painted.join(', ') : null\n}\n\nfunction keptStyle(\n style: Record<string, string>,\n base: string | undefined\n): Record<string, string> {\n const kept: Record<string, string> = {}\n for (const [property, value] of Object.entries(style)) {\n if (!isCapturedStyleProperty(property)) continue\n if (property === 'background-image') {\n const image = keptBackgroundImage(value, base)\n if (image) kept[property] = image\n continue\n }\n kept[property] = value\n }\n return kept\n}\n\nfunction normalizeElement(\n element: WebCaptureElement,\n base: string | undefined,\n depth: number,\n budget: Budget\n): WebCaptureElement {\n const children: WebCaptureNode[] = []\n for (const child of element.children) {\n if (child.type === 'text') {\n children.push(child)\n continue\n }\n if (DROPPED_TAGS.has(child.tagName)) continue\n if (depth + 1 > MAX_CAPTURE_DEPTH || budget.elements >= MAX_CAPTURE_ELEMENTS) {\n budget.truncated = true\n continue\n }\n budget.elements++\n children.push(normalizeElement(child, base, depth + 1, budget))\n }\n return {\n type: 'element',\n tagName: element.tagName,\n attrs: keptAttributes(element.attrs, base),\n ...(element.box ? { box: element.box } : {}),\n computedStyle: keptStyle(element.computedStyle, base),\n children\n }\n}\n\n/**\n * A capture as an import may use it: only the attributes and properties layers read, links\n * limited to http, https, and mailto, images limited to raster data URLs and http(s) addresses,\n * and at most `MAX_CAPTURE_ELEMENTS` elements. Captures come from any page, so every reader\n * goes through this.\n */\nexport function normalizeWebCapture(capture: WebCapture): WebCapture {\n const budget: Budget = { elements: 1, truncated: false }\n const base = capture.source.url\n const root = normalizeElement(capture.root, base, 0, budget)\n return { ...capture, root, truncated: capture.truncated || budget.truncated }\n}\n\n/** Reads a capture that is already a value, such as one a capturer handed over. */\nexport function readWebCapture(value: unknown): WebCaptureReadResult {\n if (nestsDeeperThan(value, MAX_JSON_NESTING)) return { ok: false, error: 'invalid' }\n const header = v.safeParse(captureHeaderSchema, value)\n if (!header.success) return { ok: false, error: 'invalid' }\n if (header.output.version !== WEB_CAPTURE_VERSION) {\n return { ok: false, error: 'unsupported-version' }\n }\n const parsed = v.safeParse(webCaptureSchema, value)\n if (!parsed.success) return { ok: false, error: 'invalid' }\n return { ok: true, capture: normalizeWebCapture(parsed.output) }\n}\n\n/** Reads a capture serialized as JSON, as files and clipboard payloads hold it. */\nexport function parseWebCapture(text: string): WebCaptureReadResult {\n if (text.length > MAX_CAPTURE_JSON_LENGTH) return { ok: false, error: 'too-large' }\n const json = v.safeParse(v.pipe(v.string(), v.parseJson()), text)\n if (!json.success) return { ok: false, error: 'invalid' }\n return readWebCapture(json.output)\n}\n","import { compact } from 'es-toolkit'\nimport { Inflate, deflateSync, strToU8 } from 'fflate'\nimport { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport type { WebCapture, WebCaptureReadResult } from './format'\nimport { webCaptureToHTML } from './html'\nimport { MAX_CAPTURE_JSON_LENGTH } from './limits'\nimport { normalizeWebCapture, parseWebCapture } from './parse'\n\n/**\n * Clipboard HTML carries a capture between these markers, as Base64 of the DEFLATE-compressed\n * JSON, the way Figma and Pairdraw carry their layers in an HTML comment.\n */\nexport const WEB_CAPTURE_CLIPBOARD_START = '<!--(pairdraw-web-capture)'\nexport const WEB_CAPTURE_CLIPBOARD_END = '(/pairdraw-web-capture)-->'\n\n/** Compressed bytes inflated per step, so an oversized payload stops early. */\nconst INFLATE_STEP = 16 * 1024\n\nexport interface WebCaptureClipboardPayload {\n /** The capture in markers, followed by its content as styled HTML for other applications. */\n html: string\n /** The page's title and address, for applications that only read text. */\n text: string\n}\n\n/** What the clipboard holds after copying a capture: the capture itself and a readable copy. */\nexport function encodeWebCaptureClipboard(captured: WebCapture): WebCaptureClipboardPayload {\n const capture = normalizeWebCapture(captured)\n const compressed = deflateSync(strToU8(JSON.stringify(capture)), { level: 6 })\n const marker = `${WEB_CAPTURE_CLIPBOARD_START}${fromUint8Array(compressed)}${WEB_CAPTURE_CLIPBOARD_END}`\n const html = `<meta charset=\"utf-8\">${marker}${webCaptureToHTML(capture, { images: false })}`\n const text = compact([capture.source.title, capture.source.url]).join('\\n')\n return { html, text }\n}\n\nfunction markedPayload(html: string): string | null {\n const start = html.indexOf(WEB_CAPTURE_CLIPBOARD_START)\n if (start === -1) return null\n const from = start + WEB_CAPTURE_CLIPBOARD_START.length\n const end = html.indexOf(WEB_CAPTURE_CLIPBOARD_END, from)\n return end === -1 ? null : html.slice(from, end)\n}\n\n/** Whether clipboard HTML holds a complete capture marker. */\nexport function hasWebCaptureClipboardMarker(html: string): boolean {\n return markedPayload(html) !== null\n}\n\n/** Inflates at most `MAX_CAPTURE_JSON_LENGTH` bytes of text. */\nfunction inflateText(bytes: Uint8Array): { text: string } | 'invalid' | 'too-large' {\n const decoder = new TextDecoder()\n // An object, since the inflate callback changes it where control flow analysis cannot see.\n const state = { text: '', length: 0, overflow: false }\n const inflate = new Inflate((chunk) => {\n state.length += chunk.length\n if (state.length > MAX_CAPTURE_JSON_LENGTH) state.overflow = true\n else state.text += decoder.decode(chunk, { stream: true })\n })\n try {\n for (let offset = 0; offset < bytes.length; offset += INFLATE_STEP) {\n if (state.overflow) break\n const end = offset + INFLATE_STEP\n inflate.push(bytes.subarray(offset, end), end >= bytes.length)\n }\n } catch {\n return 'invalid'\n }\n return state.overflow ? 'too-large' : { text: state.text + decoder.decode() }\n}\n\n/**\n * The capture clipboard HTML holds, or null when it holds none. Clipboard HTML is writable by\n * any page, so the payload is size-limited, validated, and normalized before it is returned.\n */\nexport function readWebCaptureClipboard(html: string): WebCaptureReadResult | null {\n const payload = markedPayload(html)\n if (payload === null) return null\n const encoded = payload.trim()\n if (encoded.length > MAX_CAPTURE_JSON_LENGTH) return { ok: false, error: 'too-large' }\n if (!isValid(encoded)) return { ok: false, error: 'invalid' }\n const inflated = inflateText(toUint8Array(encoded))\n if (typeof inflated === 'string') return { ok: false, error: inflated }\n return parseWebCapture(inflated.text)\n}\n","import { encodeWebCaptureClipboard, type WebCaptureClipboardPayload } from '#web-capture/clipboard'\nimport type { WebCapture } from '#web-capture/format'\n\n/** The part of the asynchronous clipboard a capture write uses. */\nexport type CaptureClipboard = Pick<Clipboard, 'write'>\n\nexport interface WriteCaptureClipboardOptions {\n /** The clipboard to write; the page's own by default. */\n clipboard?: CaptureClipboard\n /** Builds a clipboard item; the page's `ClipboardItem` by default. */\n createItem?: (items: Record<string, Promise<Blob>>) => ClipboardItem\n}\n\n/** Thrown when the page has no asynchronous clipboard, which only secure pages offer. */\nexport class CaptureClipboardUnavailableError extends Error {\n constructor() {\n super('Copying a capture needs a page served over HTTPS')\n this.name = 'CaptureClipboardUnavailableError'\n }\n}\n\nfunction isPayload(\n value: WebCapture | WebCaptureClipboardPayload\n): value is WebCaptureClipboardPayload {\n return 'html' in value && 'text' in value\n}\n\n/**\n * Copies a capture so it pastes into a Pairdraw canvas, as HTML for Pairdraw and other\n * applications and as the page's title and address for plain text. Pass the capture's promise\n * straight from the click that asked for it: the write starts inside that click and resolves\n * its data later, so a capture that takes a while still counts as the click's own.\n */\nexport async function writeWebCaptureClipboard(\n capture:\n | WebCapture\n | WebCaptureClipboardPayload\n | Promise<WebCapture | WebCaptureClipboardPayload>,\n options: WriteCaptureClipboardOptions = {}\n): Promise<void> {\n const clipboard =\n options.clipboard ?? (typeof navigator === 'undefined' ? undefined : navigator.clipboard)\n const createItem =\n options.createItem ??\n (typeof ClipboardItem === 'undefined'\n ? undefined\n : (items: Record<string, Promise<Blob>>) => new ClipboardItem(items))\n // `navigator.clipboard` is missing outside secure contexts.\n if (!clipboard || !createItem) throw new CaptureClipboardUnavailableError()\n const payload = Promise.resolve(capture).then((value) =>\n isPayload(value) ? value : encodeWebCaptureClipboard(value)\n )\n await clipboard.write([\n createItem({\n 'text/html': payload.then((value) => new Blob([value.html], { type: 'text/html' })),\n 'text/plain': payload.then((value) => new Blob([value.text], { type: 'text/plain' }))\n })\n ])\n}\n"],"mappings":";;;;;;;;;;AAIA,SAAgB,SACd,QACA,KACoB;CACpB,OAAO,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA;AACpD;;;ACHA,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAQ;CAAM;CAAO;CAAM;CAAO;CAAS;CAAU;AAAK,CAAC;AAOtF,SAAS,eAAe,OAAuC;CAC7D,OAAO,OAAO,QAAQ,KAAK,CAAC,CACzB,KAAK,CAAC,UAAU,WAAW,GAAG,SAAS,IAAI,OAAO,CAAC,CACnD,KAAK,IAAI;AACd;AAEA,SAAS,WAAW,SAA4B,SAAwC;CACtF,MAAM,QAAgC,EAAE,GAAG,QAAQ,MAAM;CACzD,IAAI,QAAQ,WAAW,SAAS,SAAS,O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AQ,OAAO,GAAG,OAAO;EAAE,IAAI;EAAO,OAAO;CAAU;CAC5D,MAAM,WAAW,YAAY,aAAa,OAAO,CAAC;CAClD,IAAI,OAAO,aAAa,UAAU,OAAO;EAAE,IAAI;EAAO,OAAO;CAAS;CACtE,OAAO,gBAAgB,SAAS,IAAI;AACtC;;;;ACtEA,IAAa,mCAAb,cAAsD,MAAM;CAC1D,cAAc;EACZ,MAAM,kDAAkD;EACxD,KAAK,OAAO;CACd;AACF;AAEA,SAAS,UACP,OACqC;CACrC,OAAO,UAAU,SAAS,UAAU;AACtC;;;;;;;AAQA,eAAsB,yBACpB,SAIA,UAAwC,CAAC,GAC1B;CACf,MAAM,YACJ,QAAQ,cAAc,OAAO,cAAc,cAAc,KAAA,IAAY,UAAU;CACjF,MAAM,aACJ,QAAQ,eACP,OAAO,kBAAkB,cACtB,KAAA,KACC,UAAyC,IAAI,cAAc,KAAK;CAEvE,IAAI,CAAC,aAAa,CAAC,YAAY,MAAM,IAAI,iCAAiC;CAC1E,MAAM,UAAU,QAAQ,QAAQ,OAAO,CAAC,CAAC,MAAM,UAC7C,UAAU,KAAK,IAAI,QAAQ,0BAA0B,KAAK,CAC5D;CACA,MAAM,UAAU,MAAM,CACpB,WAAW;EACT,aAAa,QAAQ,MAAM,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,MAAM,YAAY,CAAC,CAAC;EAClF,cAAc,QAAQ,MAAM,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC,CAAC;CACtF,CAAC,CACH,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"clipboard.js","names":["SIDES"],"sources":["../../../src/record.ts","../../../src/design-document.ts","../../../src/html.ts","../../../src/limits.ts","../../../src/schema.ts","../../../src/styles.ts","../../../src/urls.ts","../../../src/parse.ts","../../../src/clipboard.ts","../../../src/capturer/clipboard.ts"],"sourcesContent":["/**\n * The value a style or attribute record sets for `key`, or undefined when it sets none. Records\n * are typed as setting every key, which they do not.\n */\nexport function ownValue(\n record: Readonly<Record<string, string>>,\n key: string\n): string | undefined {\n return Object.hasOwn(record, key) ? record[key] : undefined\n}\n","import { omit } from 'es-toolkit'\n\nimport type { WebCapture } from './format'\nimport { ownValue } from './record'\nimport type { WebCaptureBox, WebCaptureElement, WebCaptureNode, WebCaptureText } from './types'\n\n/**\n * An element of the styled DOM `@pairdraw/dom-css` builds layers from. The shape matches its\n * `DesignElement`, so a capture imports through `sceneGraphFromStyledHTML` without a CSS runtime.\n */\nexport interface WebCaptureDesignElement {\n type: 'element'\n tagName: string\n attrs: Record<string, string>\n computedStyle: Record<string, string>\n children: WebCaptureDesignNode[]\n}\n\nexport type WebCaptureDesignNode = WebCaptureDesignElement | WebCaptureText\n\n/** The styled DOM of a capture, matching `@pairdraw/dom-css`'s `DesignDocument`. */\nexport interface WebCaptureDesignDocument {\n type: 'document'\n children: WebCaptureDesignNode[]\n}\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\ntype Side = (typeof SIDES)[number]\n\n/**\n * Displays the importer has no layout for, mapped to the closest one it has. A grid of\n * fixed-size cells wraps as a row of them does, and a table row is a row of its cells.\n */\nconst DISPLAY_FALLBACKS: Record<string, Record<string, string>> = {\n grid: { display: 'flex', 'flex-direction': 'row', 'flex-wrap': 'wrap' },\n 'inline-grid': { display: 'inline-flex', 'flex-direction': 'row', 'flex-wrap': 'wrap' },\n 'table-row': { display: 'flex', 'flex-direction': 'row', 'flex-wrap': 'nowrap' },\n table: { display: 'block' },\n 'inline-table': { display: 'inline-block' },\n 'table-row-group': { display: 'block' },\n 'table-header-group': { display: 'block' },\n 'table-footer-group': { display: 'block' },\n 'table-cell': { display: 'block' },\n 'table-caption': { display: 'block' },\n 'list-item': { display: 'block' },\n 'flow-root': { display: 'block' }\n}\n\n/**\n * Inline text tags the importer lays out inline when they say nothing of their display. Left\n * without one, a run such as a link or a bold word stays text instead of a box around text.\n */\nconst INLINE_TEXT_TAGS = new Set(['a', 'b', 'code', 'em', 'i', 'small', 'span', 'strong', 'u'])\n\nfunction pixels(value: string | undefined): number {\n if (!value?.endsWith('px')) return 0\n const parsed = Number.parseFloat(value)\n return Number.isFinite(parsed) ? parsed : 0\n}\n\nfunction px(value: number): string {\n return `${Math.round(value * 100) / 100}px`\n}\n\nconst MARGINS = SIDES.map((side) => `margin-${side}` as const)\n\n/** The element's margins in pixels, and its style without them. */\nfunction splitMargins(style: Record<string, string>) {\n const margins = { top: 0, right: 0, bottom: 0, left: 0 }\n for (const side of SIDES) margins[side] = pixels(style[`margin-${side}`])\n return { margins, style: omit(style, MARGINS) }\n}\n\nfunction isAbsolute(style: Record<string, string>): boolean {\n return style.position === 'absolute' || style.position === 'fixed'\n}\n\nfunction isInline(style: Record<string, string>): boolean {\n return (ownValue(style, 'display') ?? '').startsWith('inline')\n}\n\n/**\n * Places an absolute box in its parent layer. CSS measures `left` and `top` from the containing\n * block, which may be a further ancestor or the viewport, so the recorded boxes place it where\n * the page drew it. Without them, it sits at its offset plus its margin, as CSS places it.\n */\nfunction placeAbsolute(\n style: Record<string, string>,\n margins: Record<Side, number>,\n box: WebCaptureBox | undefined,\n parentBox: WebCaptureBox | undefined\n): void {\n if (box && parentBox) {\n style.left = px(box.x - parentBox.x)\n style.top = px(box.y - parentBox.y)\n return\n }\n if (ownValue(style, 'left') !== undefined) style.left = px(pixels(style.left) + margins.left)\n if (ownValue(style, 'top') !== undefined) style.top = px(pixels(style.top) + margins.top)\n}\n\n/**\n * A box in normal flow keeps the room its margins took inside a transparent box padded by them.\n * Negative margins, which pull neighbours over each other, are dropped.\n */\nfunction marginBox(\n element: WebCaptureDesignElement,\n margins: Record<Side, number>\n): WebCaptureDesignElement {\n const style: Record<string, string> = { display: 'block' }\n for (const side of SIDES) {\n if (margins[side] > 0) style[`padding-${side}`] = px(margins[side])\n }\n const alignSelf = ownValue(element.computedStyle, 'align-self')\n if (alignSelf === undefined) {\n return { type: 'element', tagName: 'div', attrs: {}, computedStyle: style, children: [element] }\n }\n // The box is the flex item now, so it aligns itself as the element did.\n style['align-self'] = alignSelf\n const child = { ...element, computedStyle: omit(element.computedStyle, ['align-self']) }\n return { type: 'element', tagName: 'div', attrs: {}, computedStyle: style, children: [child] }\n}\n\nfunction convertChildren(\n children: readonly WebCaptureNode[],\n parentBox: WebCaptureBox | undefined\n): WebCaptureDesignNode[] {\n return children.map((child): WebCaptureDesignNode =>\n child.type === 'text' ? child : convertElement(child, parentBox)\n )\n}\n\nconst GRID_DISPLAYS = new Set(['grid', 'inline-grid'])\n\ntype BoxedElement = WebCaptureElement & { box: WebCaptureBox }\n\nfunction hasBox(element: WebCaptureElement): element is BoxedElement {\n return element.box !== undefined\n}\n\n/**\n * A grid whose items can stay where the page drew them: the capture recorded the grid's box and\n * every item's, and the grid holds no loose text. Null otherwise, and for anything but a grid.\n */\nfunction placeableGrid(\n element: WebCaptureElement\n): { box: WebCaptureBox; items: BoxedElement[] } | null {\n if (!GRID_DISPLAYS.has(ownValue(element.computedStyle, 'display') ?? '') || !hasBox(element)) {\n return null\n }\n const items: BoxedElement[] = []\n for (const child of element.children) {\n if (child.type === 'text') {\n if (child.text.trim().length > 0) return null\n } else if (hasBox(child)) {\n items.push(child)\n } else {\n return null\n }\n }\n return { box: element.box, items }\n}\n\n/**\n * Auto layout has no grid tracks, so a grid keeps its drawn size and its items become absolute\n * boxes where the page drew them. Their margins already moved their boxes.\n */\nfunction gridStyle(style: Record<string, string>, box: WebCaptureBox): Record<string, string> {\n return {\n ...omit(style, ['gap', 'row-gap', 'column-gap']),\n display: style.display === 'inline-grid' ? 'inline-block' : 'block',\n width: px(box.width),\n height: px(box.height),\n 'box-sizing': 'border-box'\n }\n}\n\nconst PLACEMENT = [...MARGINS, 'position', ...SIDES]\n\nfunction placeGridItem(item: BoxedElement, grid: WebCaptureBox): WebCaptureDesignElement {\n // Without margins or a position of its own, the item converts to itself, not a margin box.\n const converted = convertElement({ ...item, computedStyle: omit(item.computedStyle, PLACEMENT) })\n converted.computedStyle = {\n ...converted.computedStyle,\n position: 'absolute',\n left: px(item.box.x - grid.x),\n top: px(item.box.y - grid.y),\n width: px(item.box.width),\n height: px(item.box.height),\n 'box-sizing': 'border-box'\n }\n return converted\n}\n\n/**\n * The style an element is laid out with, the closest display the importer has standing in for\n * one it lacks, and its converted children.\n */\nfunction layoutOf(element: WebCaptureElement) {\n const grid = placeableGrid(element)\n if (grid) {\n return {\n displayed: gridStyle(element.computedStyle, grid.box),\n children: grid.items.map((item) => placeGridItem(item, grid.box))\n }\n }\n const display = ownValue(element.computedStyle, 'display') ?? ''\n return {\n displayed: { ...element.computedStyle, ...DISPLAY_FALLBACKS[display] },\n children: convertChildren(element.children, element.box)\n }\n}\n\n/** Input types Chrome paints as a small intrinsic glyph, whatever box `width` gives them. */\nconst GLYPH_INPUT_TYPES: Record<string, true> = { checkbox: true, radio: true }\n\n/**\n * A checkbox or radio wider than its glyph: Chrome honors the width for layout but paints only\n * a small square centered in the box (`input { width: 100% }` in a flex label). Import the\n * square at the glyph's size, centered in a box that keeps the room the wide element took, so\n * following content stays where the page put it. Null when the box already fits the glyph.\n */\nfunction glyphBox(\n element: WebCaptureElement,\n converted: WebCaptureDesignElement,\n margins: Record<Side, number>,\n parentBox: WebCaptureBox | undefined\n): WebCaptureDesignElement | null {\n const box = element.box\n if (\n element.tagName !== 'input' ||\n !Object.hasOwn(GLYPH_INPUT_TYPES, element.attrs.type) ||\n !box ||\n box.width <= 0 ||\n box.height <= 0\n ) {\n return null\n }\n const side = Math.min(box.width, box.height)\n if (box.width - side < 1) return null\n const style = converted.computedStyle\n // The wrapper takes the placement, so the square must not be positioned or margined itself.\n const absolute = isAbsolute(style)\n style.width = px(side)\n style.height = px(side)\n style['box-sizing'] = 'border-box'\n delete style.position\n delete style.left\n delete style.top\n delete style.right\n delete style.bottom\n const wrapper: Record<string, string> = {\n display: 'flex',\n 'justify-content': 'center',\n 'align-items': 'center',\n width: px(box.width),\n height: px(box.height),\n 'box-sizing': 'border-box'\n }\n const alignSelf = ownValue(style, 'align-self')\n if (alignSelf !== undefined) {\n wrapper['align-self'] = alignSelf\n delete style['align-self']\n }\n const wrapped: WebCaptureDesignElement = {\n type: 'element',\n tagName: 'div',\n attrs: {},\n computedStyle: wrapper,\n children: [converted]\n }\n if (absolute) {\n wrapper.position = element.computedStyle.position === 'fixed' ? 'fixed' : 'absolute'\n for (const key of ['left', 'top']) {\n const value = ownValue(element.computedStyle, key)\n if (value !== undefined) wrapper[key] = value\n }\n placeAbsolute(wrapper, margins, box, parentBox)\n return wrapped\n }\n return SIDES.some((side) => margins[side] > 0) ? marginBox(wrapped, margins) : wrapped\n}\n\n/** What a box records of its size and border, which a word box drawn as a run of text drops. */\nconst WORD_BOX_PROPERTIES = [\n 'display',\n 'width',\n 'height',\n 'min-width',\n 'max-width',\n 'min-height',\n 'max-height',\n 'box-sizing',\n ...SIDES.flatMap((side) => ['style', 'width', 'color'].map((part) => `border-${side}-${part}`))\n]\n\n/** Properties that make a box draw something besides its text, or change where its text sits. */\nconst DRAWN_BOX_PROPERTIES = [\n 'background-color',\n 'background-image',\n 'box-shadow',\n 'opacity',\n 'overflow',\n ...SIDES.map((side) => `padding-${side}` as const)\n]\n\n/**\n * An inline-block that holds one line of text and draws nothing else, as pages that fade words\n * in box each word. It reads as a run of the text around it, not a box: kept as a box, every word\n * becomes a layer of its own and wraps at its own width.\n */\nfunction isWordBox(element: WebCaptureElement, style: Record<string, string>): boolean {\n if (style.display !== 'inline-block' || !INLINE_TEXT_TAGS.has(element.tagName)) return false\n if (!element.children.every((child) => child.type === 'text')) return false\n if (DRAWN_BOX_PROPERTIES.some((property) => ownValue(style, property) !== undefined)) return false\n if (SIDES.some((side) => pixels(style[`margin-${side}`]) !== 0)) return false\n if (SIDES.some((side) => pixels(style[`border-${side}-width`]) > 0)) return false\n const lineHeight = pixels(style['line-height']) || pixels(style['font-size']) * 1.5\n return element.box !== undefined && element.box.height < lineHeight * 1.5\n}\n\nfunction convertElement(\n element: WebCaptureElement,\n parentBox?: WebCaptureBox\n): WebCaptureDesignElement {\n const { displayed, children } = layoutOf(element)\n if (isWordBox(element, displayed)) {\n return {\n type: 'element',\n tagName: element.tagName,\n attrs: { ...element.attrs },\n computedStyle: omit(displayed, [...WORD_BOX_PROPERTIES, ...MARGINS]),\n children\n }\n }\n const inline = isInline(displayed)\n const split = splitMargins(displayed)\n const { margins } = split\n const style =\n displayed.display === 'inline' && INLINE_TEXT_TAGS.has(element.tagName)\n ? omit(split.style, ['display'])\n : split.style\n const converted: WebCaptureDesignElement = {\n type: 'element',\n tagName: element.tagName,\n attrs: { ...element.attrs },\n computedStyle: style,\n children\n }\n const glyph = glyphBox(element, converted, margins, parentBox)\n if (glyph) return glyph\n if (isAbsolute(style)) {\n placeAbsolute(style, margins, element.box, parentBox)\n return converted\n }\n const spaced = SIDES.some((side) => margins[side] > 0)\n return spaced && !inline ? marginBox(converted, margins) : converted\n}\n\n/**\n * The capture as the styled DOM layers are built from. The root keeps the size it had on the\n * page and drops its own position and margins, so it lands where a paste puts it.\n */\nexport function webCaptureDesignDocument(capture: WebCapture): WebCaptureDesignDocument {\n const { root } = capture\n const { displayed, children } = layoutOf(root)\n const style = omit(splitMargins(displayed).style, ['position', ...SIDES])\n // The box a capture records is the border box, padding and borders included.\n if (root.box) {\n style.width = px(root.box.width)\n style.height = px(root.box.height)\n style['box-sizing'] = 'border-box'\n }\n return {\n type: 'document',\n children: [\n {\n type: 'element',\n tagName: root.tagName,\n attrs: { ...root.attrs },\n computedStyle: style,\n children\n }\n ]\n }\n}\n","import { escapeAttribute, escapeText } from 'entities'\n\nimport {\n webCaptureDesignDocument,\n type WebCaptureDesignElement,\n type WebCaptureDesignNode\n} from './design-document'\nimport type { WebCapture } from './format'\nimport { ownValue } from './record'\n\nconst VOID_TAGS = new Set(['area', 'br', 'col', 'hr', 'img', 'input', 'source', 'wbr'])\n\n/** Tags whose start ends an open `<p>` when HTML is parsed, which would lift them out of it. */\nconst CLOSES_PARAGRAPH = new Set([\n 'address',\n 'article',\n 'aside',\n 'blockquote',\n 'details',\n 'div',\n 'dl',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hgroup',\n 'hr',\n 'main',\n 'menu',\n 'nav',\n 'ol',\n 'p',\n 'pre',\n 'section',\n 'table',\n 'ul'\n])\n\n/**\n * The tag an element is written with. A script can put a block inside a `<p>`, as the capture's\n * own spacers around a margined box do, but parsing would end the paragraph there; a `<div>`\n * holds it in place, and the element's styles say how it lays out either way.\n */\nfunction writtenTag(element: WebCaptureDesignElement): string {\n const holdsBlock = element.children.some(\n (child) => child.type === 'element' && CLOSES_PARAGRAPH.has(child.tagName)\n )\n return element.tagName === 'p' && holdsBlock ? 'div' : element.tagName\n}\n\nexport interface WebCaptureHTMLOptions {\n /** Keep inlined images; without them an image keeps only its size and description. */\n images?: boolean\n}\n\nfunction styleAttribute(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([property, value]) => `${property}: ${value}`)\n .join('; ')\n}\n\nfunction attributes(element: WebCaptureDesignElement, options: WebCaptureHTMLOptions): string {\n const attrs: Record<string, string> = { ...element.attrs }\n if (options.images === false && ownValue(attrs, 'src')?.startsWith('data:')) delete attrs.src\n // A captured field holds the text it showed; an `<input>` holds it as its value.\n if (element.tagName === 'input') {\n const text = element.children.map((child) => (child.type === 'text' ? child.text : '')).join('')\n if (text) attrs.value = text\n }\n const style = styleAttribute(element.computedStyle)\n if (style) attrs.style = style\n return Object.entries(attrs)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('')\n}\n\nfunction serialize(node: WebCaptureDesignNode, options: WebCaptureHTMLOptions): string {\n if (node.type === 'text') return escapeText(node.text)\n const tag = writtenTag(node)\n const open = `<${tag}${attributes(node, options)}>`\n if (VOID_TAGS.has(tag)) return open\n const children = node.children.map((child) => serialize(child, options)).join('')\n return `${open}${children}</${tag}>`\n}\n\n/**\n * The capture as static HTML whose elements carry their styles inline, for applications that\n * read clipboard HTML but not the capture itself, and for importing it as HTML. It is the styled\n * DOM a paste builds layers from, so the HTML importer reads the capture as the paste does.\n */\nexport function webCaptureToHTML(capture: WebCapture, options: WebCaptureHTMLOptions = {}): string {\n return webCaptureDesignDocument(capture)\n .children.map((node) => serialize(node, options))\n .join('')\n}\n","/** The capture format identifier that clipboard payloads and files carry. */\nexport const WEB_CAPTURE_FORMAT = 'pairdraw/web-capture'\n\n/** The capture format version this package writes and reads. */\nexport const WEB_CAPTURE_VERSION = 1\n\n/** Elements one capture holds at most; a capturer stops descending once it reaches this. */\nexport const MAX_CAPTURE_ELEMENTS = 20_000\n\n/** How deep a capture nests; deeper elements are left out, as browsers rarely draw them. */\nexport const MAX_CAPTURE_DEPTH = 256\n\n/** Bytes one inlined image may take; a larger image stays a link the importer records. */\nexport const MAX_CAPTURE_IMAGE_BYTES = 8 * 1024 * 1024\n\n/** Bytes all inlined images of a capture take together. */\nexport const MAX_CAPTURE_IMAGES_BYTES = 48 * 1024 * 1024\n\n/** Characters of serialized capture JSON a reader accepts, images included. */\nexport const MAX_CAPTURE_JSON_LENGTH = 96 * 1024 * 1024\n\n/** Characters of plain web HTML a paste styles; a larger fragment is refused. */\nexport const MAX_WEB_HTML_LENGTH = 8 * 1024 * 1024\n","import * as v from 'valibot'\n\nimport { MAX_CAPTURE_JSON_LENGTH, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION } from './limits'\nimport type { WebCaptureElement, WebCaptureNode } from './types'\n\nconst finiteSchema = v.pipe(v.number(), v.finite())\nconst sizeSchema = v.pipe(v.number(), v.finite(), v.minValue(0))\nconst shortStringSchema = v.pipe(v.string(), v.maxLength(4096))\n\nconst webCaptureBoxSchema = v.object({\n x: finiteSchema,\n y: finiteSchema,\n width: sizeSchema,\n height: sizeSchema\n})\n\nconst webCaptureTextSchema = v.object({\n type: v.literal('text'),\n text: v.pipe(v.string(), v.maxLength(1_000_000))\n})\n\n/** HTML and SVG tag names, lowercase as a capturer writes them. */\nconst tagNameSchema = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9-]{0,63}$/))\n/** Attribute names; which of them an import keeps is decided when a capture is read. */\nconst attributeNameSchema = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9:_-]{0,63}$/))\n/** Attribute values hold inlined images as data URLs, so they may be large. */\nconst attributeValueSchema = v.pipe(v.string(), v.maxLength(MAX_CAPTURE_JSON_LENGTH))\nconst propertyNameSchema = v.pipe(v.string(), v.regex(/^-?[a-z][a-z-]{0,63}$/))\n\nconst webCaptureElementSchema: v.GenericSchema<unknown, WebCaptureElement> = v.object({\n type: v.literal('element'),\n tagName: tagNameSchema,\n attrs: v.record(attributeNameSchema, attributeValueSchema),\n computedStyle: v.record(propertyNameSchema, shortStringSchema),\n box: v.optional(webCaptureBoxSchema),\n children: v.array(v.lazy(() => webCaptureNodeSchema))\n})\n\nconst webCaptureNodeSchema: v.GenericSchema<unknown, WebCaptureNode> = v.union([\n webCaptureTextSchema,\n webCaptureElementSchema\n])\n\nexport const webCaptureFontSchema = v.object({\n family: shortStringSchema,\n weight: shortStringSchema,\n style: shortStringSchema\n})\n\nexport const webCaptureViewportSchema = v.object({\n width: sizeSchema,\n height: sizeSchema,\n devicePixelRatio: v.pipe(v.number(), v.finite(), v.minValue(0))\n})\n\nconst webCaptureSourceSchema = v.object({\n url: v.optional(shortStringSchema),\n title: v.optional(shortStringSchema)\n})\n\n/** A page or element captured with the styles the browser computed for it. */\nexport const webCaptureSchema = v.object({\n format: v.literal(WEB_CAPTURE_FORMAT),\n version: v.literal(WEB_CAPTURE_VERSION),\n /** Whether a whole page or one element of it was captured. */\n scope: v.picklist(['page', 'element']),\n source: webCaptureSourceSchema,\n /** When the capture was made, as an ISO 8601 timestamp. */\n capturedAt: shortStringSchema,\n viewport: webCaptureViewportSchema,\n root: webCaptureElementSchema,\n fonts: v.array(webCaptureFontSchema),\n /** Whether the capturer stopped at its element limit, leaving later content out. */\n truncated: v.boolean()\n})\n","import { ownValue } from './record'\n\n/**\n * The computed properties a capture keeps for each element: those `@pairdraw/dom-css` builds\n * layers from, plus margins, which a capture turns into spacing when it is imported.\n */\nexport const CAPTURED_STYLE_PROPERTIES = [\n 'align-items',\n 'align-self',\n 'aspect-ratio',\n 'background-color',\n 'background-image',\n 'background-position',\n 'background-repeat',\n 'background-size',\n 'border-bottom-color',\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-bottom-style',\n 'border-bottom-width',\n 'border-left-color',\n 'border-left-style',\n 'border-left-width',\n 'border-right-color',\n 'border-right-style',\n 'border-right-width',\n 'border-top-color',\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-top-style',\n 'border-top-width',\n 'bottom',\n 'box-shadow',\n 'box-sizing',\n 'color',\n 'column-gap',\n 'display',\n 'flex-direction',\n 'flex-wrap',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'gap',\n 'height',\n 'justify-content',\n 'left',\n 'letter-spacing',\n 'line-height',\n 'margin-bottom',\n 'margin-left',\n 'margin-right',\n 'margin-top',\n 'max-height',\n 'max-width',\n 'min-height',\n 'min-width',\n 'object-fit',\n 'opacity',\n 'order',\n 'overflow',\n 'padding-bottom',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'position',\n 'right',\n 'row-gap',\n 'text-align',\n 'text-decoration-color',\n 'text-decoration-line',\n 'text-decoration-style',\n 'text-decoration-thickness',\n 'text-indent',\n 'text-shadow',\n 'text-transform',\n 'text-underline-offset',\n 'top',\n 'white-space',\n 'width'\n] as const\n\nexport type CapturedStyleProperty = (typeof CAPTURED_STYLE_PROPERTIES)[number]\n\nconst CAPTURED = new Set<string>(CAPTURED_STYLE_PROPERTIES)\n\n/** Whether a capture keeps this property; others are dropped when a capture is read. */\nexport function isCapturedStyleProperty(property: string): property is CapturedStyleProperty {\n return CAPTURED.has(property)\n}\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n\n/**\n * Values the importer reads exactly as it reads a missing property, so leaving them out only\n * makes the capture smaller. Inherited text properties are always kept: a nested run reads\n * a missing one from its parent, which differs from the value the page computed.\n */\nconst IMPLIED_VALUES: Partial<Record<CapturedStyleProperty, readonly string[]>> = {\n 'align-items': ['normal'],\n 'align-self': ['auto'],\n 'aspect-ratio': ['auto'],\n 'background-color': ['rgba(0, 0, 0, 0)', 'transparent'],\n 'background-image': ['none'],\n 'background-position': ['0% 0%'],\n 'background-repeat': ['repeat'],\n 'background-size': ['auto'],\n 'box-shadow': ['none'],\n 'column-gap': ['normal'],\n 'flex-direction': ['row'],\n 'flex-wrap': ['nowrap'],\n gap: ['normal'],\n height: ['auto'],\n 'justify-content': ['normal'],\n 'max-height': ['none'],\n 'max-width': ['none'],\n 'min-height': ['auto', '0px'],\n 'min-width': ['auto', '0px'],\n 'object-fit': ['fill'],\n opacity: ['1'],\n order: ['0'],\n overflow: ['visible'],\n 'row-gap': ['normal'],\n 'text-indent': ['0px'],\n width: ['auto']\n}\n\nconst ZERO_LENGTH_PROPERTIES = [\n 'border-bottom-left-radius',\n 'border-bottom-right-radius',\n 'border-top-left-radius',\n 'border-top-right-radius',\n ...SIDES.map((side) => `padding-${side}` as const),\n ...SIDES.map((side) => `margin-${side}` as const)\n]\n\nconst TEXT_DECORATION_DETAILS = [\n 'text-decoration-color',\n 'text-decoration-style',\n 'text-decoration-thickness',\n 'text-underline-offset'\n]\n\n/**\n * The style without values that change nothing on import: defaults, borders without a style,\n * offsets of boxes in normal flow, and decoration details of undecorated text.\n */\nexport function withoutImpliedValues(style: Record<string, string>): Record<string, string> {\n const dropped = new Set<string>()\n for (const [property, values] of Object.entries(IMPLIED_VALUES)) {\n if (values.includes(ownValue(style, property) ?? '')) dropped.add(property)\n }\n for (const property of ZERO_LENGTH_PROPERTIES) {\n if (style[property] === '0px') dropped.add(property)\n }\n for (const side of SIDES) {\n const borderStyle = ownValue(style, `border-${side}-style`)\n if (borderStyle !== undefined && borderStyle !== 'none' && borderStyle !== 'hidden') continue\n for (const part of ['style', 'width', 'color']) dropped.add(`border-${side}-${part}`)\n }\n // Sticky boxes sit in normal flow until the page scrolls, which a still capture never does.\n const position = ownValue(style, 'position')\n const inFlow = position === undefined || position === 'static' || position === 'sticky'\n if (inFlow) dropped.add('position')\n for (const side of SIDES) {\n if (inFlow || style[side] === 'auto') dropped.add(side)\n }\n const decoration = ownValue(style, 'text-decoration-line')\n if (decoration === undefined || decoration === 'none') {\n for (const property of TEXT_DECORATION_DETAILS) dropped.add(property)\n }\n return Object.fromEntries(Object.entries(style).filter(([property]) => !dropped.has(property)))\n}\n","const LINK_PROTOCOLS = new Set(['http:', 'https:', 'mailto:'])\nconst IMAGE_PROTOCOLS = new Set(['http:', 'https:'])\n/** Raster images the canvas decodes; SVG is rasterized by the capturer instead. */\nconst DATA_IMAGE =\n /^data:image\\/(?:png|jpeg|gif|webp|avif|bmp|x-icon|vnd\\.microsoft\\.icon);base64,/i\n\nfunction resolve(value: string, base: string | undefined): URL | null {\n try {\n return new URL(value.trim(), base)\n } catch {\n return null\n }\n}\n\n/** A link a layer may keep: http, https, or mailto, resolved against the page; never script. */\nexport function safeLinkURL(value: string, base?: string): string | null {\n const url = resolve(value, base)\n return url && LINK_PROTOCOLS.has(url.protocol) ? url.href : null\n}\n\n/** An image source a layer may keep: an inlined raster image, or an http(s) address. */\nexport function safeImageSource(value: string, base?: string): string | null {\n const trimmed = value.trim()\n if (DATA_IMAGE.test(trimmed)) return trimmed\n const url = resolve(trimmed, base)\n return url && IMAGE_PROTOCOLS.has(url.protocol) ? url.href : null\n}\n","import * as v from 'valibot'\n\nimport type { WebCapture, WebCaptureReadResult } from './format'\nimport {\n MAX_CAPTURE_DEPTH,\n MAX_CAPTURE_ELEMENTS,\n MAX_CAPTURE_JSON_LENGTH,\n WEB_CAPTURE_FORMAT,\n WEB_CAPTURE_VERSION\n} from './limits'\nimport { webCaptureSchema } from './schema'\nimport { isCapturedStyleProperty } from './styles'\nimport type { WebCaptureElement, WebCaptureNode } from './types'\nimport { safeImageSource, safeLinkURL } from './urls'\n\n/** Read first, so a capture from a newer capturer is told apart from a damaged one. */\nconst captureHeaderSchema = v.looseObject({\n format: v.literal(WEB_CAPTURE_FORMAT),\n version: v.number()\n})\n\n/** Attributes a layer can use: names, links, images, control kinds, and accessible labels. */\nconst KEPT_ATTRIBUTES = new Set([\n 'id',\n 'class',\n 'href',\n 'src',\n 'alt',\n 'title',\n 'type',\n 'role',\n 'aria-label',\n 'lang',\n 'dir'\n])\n\n/** Elements that never draw, whatever a capture claims. */\nconst DROPPED_TAGS = new Set([\n 'script',\n 'style',\n 'link',\n 'meta',\n 'head',\n 'title',\n 'template',\n 'noscript',\n 'iframe',\n 'frame',\n 'object',\n 'embed',\n 'base'\n])\n\n/**\n * JSON nesting a capture within `MAX_CAPTURE_DEPTH` takes: an object and a `children` array per\n * element, the capture around the root, and the records of the deepest element, with room to\n * spare. Deeper values are refused before validation, whose recursion they could overflow.\n */\nconst MAX_JSON_NESTING = 2 * MAX_CAPTURE_DEPTH + 16\n\n/** Whether a value nests deeper than `limit`, walked without recursion; a cycle counts as deep. */\nfunction nestsDeeperThan(value: unknown, limit: number): boolean {\n const pending: { value: unknown; depth: number }[] = [{ value, depth: 0 }]\n for (let next = pending.pop(); next; next = pending.pop()) {\n if (typeof next.value !== 'object' || next.value === null) continue\n if (next.depth >= limit) return true\n const depth = next.depth + 1\n for (const child of Object.values(next.value)) pending.push({ value: child, depth })\n }\n return false\n}\n\ninterface Budget {\n elements: number\n truncated: boolean\n}\n\nfunction keptAttributes(\n attrs: Record<string, string>,\n base: string | undefined\n): Record<string, string> {\n const kept: Record<string, string> = {}\n for (const [name, value] of Object.entries(attrs)) {\n if (!KEPT_ATTRIBUTES.has(name)) continue\n if (name === 'href') {\n const href = safeLinkURL(value, base)\n if (href) kept.href = href\n } else if (name === 'src') {\n const src = safeImageSource(value, base)\n if (src) kept.src = src\n } else {\n kept[name] = value\n }\n }\n return kept\n}\n\n/** The `url(...)` sources of a value, with the spans they occupy. */\nconst BACKGROUND_URL = /url\\(\\s*(['\"]?)(.*?)\\1\\s*\\)/g\n\n/**\n * A `background-image` list with every `url(...)` source limited to what an image layer may\n * keep; a layer whose source is unsafe is dropped, and a list left empty paints nothing.\n * Gradient layers carry no address and pass through as written.\n */\nfunction keptBackgroundImage(value: string, base: string | undefined): string | null {\n const layers: string[] = []\n let cursor = 0\n let dropped = false\n for (const match of value.matchAll(BACKGROUND_URL)) {\n const source = safeImageSource(match[2], base)\n if (source) layers.push(value.slice(cursor, match.index) + `url(\"${source}\")`)\n else dropped = true\n cursor = match.index + match[0].length\n }\n if (cursor === 0 && !dropped) return value\n layers.push(value.slice(cursor))\n // Split at top-level commas only: a gradient's own commas stay inside its parentheses.\n const kept: string[] = []\n let depth = 0\n let current = ''\n for (const character of layers.join('')) {\n if (character === '(') depth++\n else if (character === ')') depth--\n if (character === ',' && depth === 0) {\n kept.push(current)\n current = ''\n continue\n }\n current += character\n }\n kept.push(current)\n const painted = kept\n .map((layer) => layer.trim())\n .filter((layer) => layer.length > 0 && layer !== 'none')\n return painted.length > 0 ? painted.join(', ') : null\n}\n\nfunction keptStyle(\n style: Record<string, string>,\n base: string | undefined\n): Record<string, string> {\n const kept: Record<string, string> = {}\n for (const [property, value] of Object.entries(style)) {\n if (!isCapturedStyleProperty(property)) continue\n if (property === 'background-image') {\n const image = keptBackgroundImage(value, base)\n if (image) kept[property] = image\n continue\n }\n kept[property] = value\n }\n return kept\n}\n\nfunction normalizeElement(\n element: WebCaptureElement,\n base: string | undefined,\n depth: number,\n budget: Budget\n): WebCaptureElement {\n const children: WebCaptureNode[] = []\n for (const child of element.children) {\n if (child.type === 'text') {\n children.push(child)\n continue\n }\n if (DROPPED_TAGS.has(child.tagName)) continue\n if (depth + 1 > MAX_CAPTURE_DEPTH || budget.elements >= MAX_CAPTURE_ELEMENTS) {\n budget.truncated = true\n continue\n }\n budget.elements++\n children.push(normalizeElement(child, base, depth + 1, budget))\n }\n return {\n type: 'element',\n tagName: element.tagName,\n attrs: keptAttributes(element.attrs, base),\n ...(element.box ? { box: element.box } : {}),\n computedStyle: keptStyle(element.computedStyle, base),\n children\n }\n}\n\n/**\n * A capture as an import may use it: only the attributes and properties layers read, links\n * limited to http, https, and mailto, images limited to raster data URLs and http(s) addresses,\n * and at most `MAX_CAPTURE_ELEMENTS` elements. Captures come from any page, so every reader\n * goes through this.\n */\nexport function normalizeWebCapture(capture: WebCapture): WebCapture {\n const budget: Budget = { elements: 1, truncated: false }\n const base = capture.source.url\n const root = normalizeElement(capture.root, base, 0, budget)\n return { ...capture, root, truncated: capture.truncated || budget.truncated }\n}\n\n/** Reads a capture that is already a value, such as one a capturer handed over. */\nexport function readWebCapture(value: unknown): WebCaptureReadResult {\n if (nestsDeeperThan(value, MAX_JSON_NESTING)) return { ok: false, error: 'invalid' }\n const header = v.safeParse(captureHeaderSchema, value)\n if (!header.success) return { ok: false, error: 'invalid' }\n if (header.output.version !== WEB_CAPTURE_VERSION) {\n return { ok: false, error: 'unsupported-version' }\n }\n const parsed = v.safeParse(webCaptureSchema, value)\n if (!parsed.success) return { ok: false, error: 'invalid' }\n return { ok: true, capture: normalizeWebCapture(parsed.output) }\n}\n\n/** Reads a capture serialized as JSON, as files and clipboard payloads hold it. */\nexport function parseWebCapture(text: string): WebCaptureReadResult {\n if (text.length > MAX_CAPTURE_JSON_LENGTH) return { ok: false, error: 'too-large' }\n const json = v.safeParse(v.pipe(v.string(), v.parseJson()), text)\n if (!json.success) return { ok: false, error: 'invalid' }\n return readWebCapture(json.output)\n}\n","import { compact } from 'es-toolkit'\nimport { Inflate, deflateSync, strToU8 } from 'fflate'\nimport { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport type { WebCapture, WebCaptureReadResult } from './format'\nimport { webCaptureToHTML } from './html'\nimport { MAX_CAPTURE_JSON_LENGTH } from './limits'\nimport { normalizeWebCapture, parseWebCapture } from './parse'\n\n/**\n * Clipboard HTML carries a capture between these markers, as Base64 of the DEFLATE-compressed\n * JSON, the way Figma and Pairdraw carry their layers in an HTML comment.\n */\nexport const WEB_CAPTURE_CLIPBOARD_START = '<!--(pairdraw-web-capture)'\nexport const WEB_CAPTURE_CLIPBOARD_END = '(/pairdraw-web-capture)-->'\n\n/** Compressed bytes inflated per step, so an oversized payload stops early. */\nconst INFLATE_STEP = 16 * 1024\n\nexport interface WebCaptureClipboardPayload {\n /** The capture in markers, followed by its content as styled HTML for other applications. */\n html: string\n /** The page's title and address, for applications that only read text. */\n text: string\n}\n\n/** What the clipboard holds after copying a capture: the capture itself and a readable copy. */\nexport function encodeWebCaptureClipboard(captured: WebCapture): WebCaptureClipboardPayload {\n const capture = normalizeWebCapture(captured)\n const compressed = deflateSync(strToU8(JSON.stringify(capture)), { level: 6 })\n const marker = `${WEB_CAPTURE_CLIPBOARD_START}${fromUint8Array(compressed)}${WEB_CAPTURE_CLIPBOARD_END}`\n const html = `<meta charset=\"utf-8\">${marker}${webCaptureToHTML(capture, { images: false })}`\n const text = compact([capture.source.title, capture.source.url]).join('\\n')\n return { html, text }\n}\n\nfunction markedPayload(html: string): string | null {\n const start = html.indexOf(WEB_CAPTURE_CLIPBOARD_START)\n if (start === -1) return null\n const from = start + WEB_CAPTURE_CLIPBOARD_START.length\n const end = html.indexOf(WEB_CAPTURE_CLIPBOARD_END, from)\n return end === -1 ? null : html.slice(from, end)\n}\n\n/** Whether clipboard HTML holds a complete capture marker. */\nexport function hasWebCaptureClipboardMarker(html: string): boolean {\n return markedPayload(html) !== null\n}\n\n/** Inflates at most `MAX_CAPTURE_JSON_LENGTH` bytes of text. */\nfunction inflateText(bytes: Uint8Array): { text: string } | 'invalid' | 'too-large' {\n const decoder = new TextDecoder()\n // An object, since the inflate callback changes it where control flow analysis cannot see.\n const state = { text: '', length: 0, overflow: false }\n const inflate = new Inflate((chunk) => {\n state.length += chunk.length\n if (state.length > MAX_CAPTURE_JSON_LENGTH) state.overflow = true\n else state.text += decoder.decode(chunk, { stream: true })\n })\n try {\n for (let offset = 0; offset < bytes.length; offset += INFLATE_STEP) {\n if (state.overflow) break\n const end = offset + INFLATE_STEP\n inflate.push(bytes.subarray(offset, end), end >= bytes.length)\n }\n } catch {\n return 'invalid'\n }\n return state.overflow ? 'too-large' : { text: state.text + decoder.decode() }\n}\n\n/**\n * The capture clipboard HTML holds, or null when it holds none. Clipboard HTML is writable by\n * any page, so the payload is size-limited, validated, and normalized before it is returned.\n */\nexport function readWebCaptureClipboard(html: string): WebCaptureReadResult | null {\n const payload = markedPayload(html)\n if (payload === null) return null\n const encoded = payload.trim()\n if (encoded.length > MAX_CAPTURE_JSON_LENGTH) return { ok: false, error: 'too-large' }\n if (!isValid(encoded)) return { ok: false, error: 'invalid' }\n const inflated = inflateText(toUint8Array(encoded))\n if (typeof inflated === 'string') return { ok: false, error: inflated }\n return parseWebCapture(inflated.text)\n}\n","import { encodeWebCaptureClipboard, type WebCaptureClipboardPayload } from '#web-capture/clipboard'\nimport type { WebCapture } from '#web-capture/format'\n\n/** The part of the asynchronous clipboard a capture write uses. */\nexport type CaptureClipboard = Pick<Clipboard, 'write'>\n\nexport interface WriteCaptureClipboardOptions {\n /** The clipboard to write; the page's own by default. */\n clipboard?: CaptureClipboard\n /** Builds a clipboard item; the page's `ClipboardItem` by default. */\n createItem?: (items: Record<string, Promise<Blob>>) => ClipboardItem\n}\n\n/** Thrown when the page has no asynchronous clipboard, which only secure pages offer. */\nexport class CaptureClipboardUnavailableError extends Error {\n constructor() {\n super('Copying a capture needs a page served over HTTPS')\n this.name = 'CaptureClipboardUnavailableError'\n }\n}\n\nfunction isPayload(\n value: WebCapture | WebCaptureClipboardPayload\n): value is WebCaptureClipboardPayload {\n return 'html' in value && 'text' in value\n}\n\n/**\n * Copies a capture so it pastes into a Pairdraw canvas, as HTML for Pairdraw and other\n * applications and as the page's title and address for plain text. Pass the capture's promise\n * straight from the click that asked for it: the write starts inside that click and resolves\n * its data later, so a capture that takes a while still counts as the click's own.\n */\nexport async function writeWebCaptureClipboard(\n capture:\n | WebCapture\n | WebCaptureClipboardPayload\n | Promise<WebCapture | WebCaptureClipboardPayload>,\n options: WriteCaptureClipboardOptions = {}\n): Promise<void> {\n const clipboard =\n options.clipboard ?? (typeof navigator === 'undefined' ? undefined : navigator.clipboard)\n const createItem =\n options.createItem ??\n (typeof ClipboardItem === 'undefined'\n ? undefined\n : (items: Record<string, Promise<Blob>>) => new ClipboardItem(items))\n // `navigator.clipboard` is missing outside secure contexts.\n if (!clipboard || !createItem) throw new CaptureClipboardUnavailableError()\n const payload = Promise.resolve(capture).then((value) =>\n isPayload(value) ? value : encodeWebCaptureClipboard(value)\n )\n await clipboard.write([\n createItem({\n 'text/html': payload.then((value) => new Blob([value.html], { type: 'text/html' })),\n 'text/plain': payload.then((value) => new Blob([value.text], { type: 'text/plain' }))\n })\n ])\n}\n"],"mappings":";;;;;;;;;;AAIA,SAAgB,SACd,QACA,KACoB;CACpB,OAAO,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA;AACpD;;;ACiBA,MAAMA,UAAQ;CAAC;CAAO;CAAS;CAAU;AAAM;;;;;AAO/C,MAAM,oBAA4D;CAChE,MAAM;EAAE,SAAS;EAAQ,kBAAkB;EAAO,aAAa;CAAO;CACtE,eAAe;EAAE,SAAS;EAAe,kBAAkB;EAAO,aAAa;CAAO;CACtF,aAAa;EAAE,SAAS;EAAQ,kBAAkB;EAAO,aAAa;CAAS;CAC/E,OAAO,EAAE,SAAS,QAAQ;CAC1B,gBAAgB,EAAE,SAAS,eAAe;CAC1C,mBAAmB,EAAE,SAAS,QAAQ;CACtC,sBAAsB,EAAE,SAAS,QAAQ;CACzC,sBAAsB,EAAE,SAAS,QAAQ;CACzC,cAAc,EAAE,SAAS,QAAQ;CACjC,iBAAiB,EAAE,SAAS,QAAQ;CACpC,aAAa,EAAE,SAAS,QAAQ;CAChC,aAAa,EAAE,SAAS,QAAQ;AAClC;;;;;AAMA,MAAM,mCAAmB,IAAI,IA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AY,CAAC,CAAC;EAClF,cAAc,QAAQ,MAAM,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC,CAAC;CACtF,CAAC,CACH,CAAC;AACH"}
|
|
@@ -26,7 +26,7 @@ const PRESENTATION_PROPERTIES = [
|
|
|
26
26
|
];
|
|
27
27
|
/** Elements whose styles are copied; very large drawings keep the rest as they are. */
|
|
28
28
|
const MAX_STYLED_ELEMENTS = 4e3;
|
|
29
|
-
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
29
|
+
const SVG_NAMESPACE$1 = "http://www.w3.org/2000/svg";
|
|
30
30
|
function inlineStyles(view, original, copy) {
|
|
31
31
|
const style = view.getComputedStyle(original);
|
|
32
32
|
const declarations = PRESENTATION_PROPERTIES.flatMap((property) => {
|
|
@@ -61,11 +61,11 @@ function standaloneSVGMarkup(view, svg, size) {
|
|
|
61
61
|
}
|
|
62
62
|
const symbols = referencedSymbols(svg, svg.ownerDocument);
|
|
63
63
|
if (symbols.length > 0) {
|
|
64
|
-
const defs = svg.ownerDocument.createElementNS(SVG_NAMESPACE, "defs");
|
|
64
|
+
const defs = svg.ownerDocument.createElementNS(SVG_NAMESPACE$1, "defs");
|
|
65
65
|
for (const symbol of symbols) defs.append(symbol.cloneNode(true));
|
|
66
66
|
copy.prepend(defs);
|
|
67
67
|
}
|
|
68
|
-
copy.setAttribute("xmlns", SVG_NAMESPACE);
|
|
68
|
+
copy.setAttribute("xmlns", SVG_NAMESPACE$1);
|
|
69
69
|
copy.setAttribute("width", String(size.width));
|
|
70
70
|
copy.setAttribute("height", String(size.height));
|
|
71
71
|
return new view.XMLSerializer().serializeToString(copy);
|
|
@@ -268,6 +268,50 @@ function captureBackground(style, node, context) {
|
|
|
268
268
|
inlineSource(context, image, () => context.images.inline(url));
|
|
269
269
|
node.children.unshift(image);
|
|
270
270
|
}
|
|
271
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
272
|
+
/** An SVG that paints `color` through the alpha of the mask image at `url`, as CSS masks do. */
|
|
273
|
+
function maskedColorMarkup(view, url, color, size, fit) {
|
|
274
|
+
const document = view.document;
|
|
275
|
+
const svg = document.createElementNS(SVG_NAMESPACE, "svg");
|
|
276
|
+
svg.setAttribute("xmlns", SVG_NAMESPACE);
|
|
277
|
+
svg.setAttribute("width", String(size.width));
|
|
278
|
+
svg.setAttribute("height", String(size.height));
|
|
279
|
+
const mask = document.createElementNS(SVG_NAMESPACE, "mask");
|
|
280
|
+
mask.setAttribute("id", "icon");
|
|
281
|
+
mask.setAttribute("style", "mask-type: alpha");
|
|
282
|
+
const image = document.createElementNS(SVG_NAMESPACE, "image");
|
|
283
|
+
image.setAttribute("href", url);
|
|
284
|
+
image.setAttribute("width", "100%");
|
|
285
|
+
image.setAttribute("height", "100%");
|
|
286
|
+
image.setAttribute("preserveAspectRatio", fit === "cover" ? "xMidYMid slice" : "xMidYMid meet");
|
|
287
|
+
mask.append(image);
|
|
288
|
+
const rect = document.createElementNS(SVG_NAMESPACE, "rect");
|
|
289
|
+
rect.setAttribute("width", "100%");
|
|
290
|
+
rect.setAttribute("height", "100%");
|
|
291
|
+
rect.setAttribute("fill", color);
|
|
292
|
+
rect.setAttribute("mask", "url(#icon)");
|
|
293
|
+
svg.append(mask, rect);
|
|
294
|
+
return new view.XMLSerializer().serializeToString(svg);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* A box painted through a mask, as CSS icon sets draw icons: its background color shows only
|
|
298
|
+
* where the mask image is opaque. Layers have no masks, so the box becomes an image of the
|
|
299
|
+
* colored shape rather than a box of solid color. Only an inline mask image can be drawn.
|
|
300
|
+
*/
|
|
301
|
+
function captureMask(style, node, context) {
|
|
302
|
+
const mask = style.getPropertyValue("mask-image") || style.getPropertyValue("-webkit-mask-image");
|
|
303
|
+
const url = BACKGROUND_URL.exec(mask)?.[2];
|
|
304
|
+
if (!url || node.tagName === "img" || node.children.length > 0) return;
|
|
305
|
+
const color = node.computedStyle["background-color"];
|
|
306
|
+
node.tagName = "img";
|
|
307
|
+
delete node.computedStyle["background-color"];
|
|
308
|
+
const box = node.box;
|
|
309
|
+
if (!color || !url.startsWith("data:") || !box || box.width <= 0 || box.height <= 0) return;
|
|
310
|
+
const size = imageSize(box);
|
|
311
|
+
const fit = style.getPropertyValue("mask-size") || style.getPropertyValue("-webkit-mask-size");
|
|
312
|
+
const markup = maskedColorMarkup(context.view, url, color, size, fit);
|
|
313
|
+
inlineSource(context, node, () => context.images.rasterizeSVG(markup, size));
|
|
314
|
+
}
|
|
271
315
|
function captureChildren(element, context, depth) {
|
|
272
316
|
return renderedChildren(element, context.view).flatMap((child) => {
|
|
273
317
|
if (child.nodeType === 3) {
|
|
@@ -306,6 +350,7 @@ function walkElement(element, context, depth = 0) {
|
|
|
306
350
|
};
|
|
307
351
|
if (!captureReplaced(element, node, context)) node.children = captureChildren(element, context, depth);
|
|
308
352
|
if (hasDirectText(element) || node.children.some((child) => child.type === "text")) context.fonts.add(style);
|
|
353
|
+
captureMask(style, node, context);
|
|
309
354
|
captureBackground(style, node, context);
|
|
310
355
|
return [node];
|
|
311
356
|
}
|
|
@@ -406,16 +451,20 @@ function isTransparent(color) {
|
|
|
406
451
|
async function capturePage(document = globalThis.document, options = {}) {
|
|
407
452
|
options.signal?.throwIfAborted();
|
|
408
453
|
const view = windowOf(document);
|
|
409
|
-
const
|
|
410
|
-
const
|
|
454
|
+
const body = document.body;
|
|
455
|
+
const documentElement = document.documentElement;
|
|
456
|
+
const target = body ?? documentElement;
|
|
457
|
+
if (!target) throw new Error("The page has nothing to capture");
|
|
458
|
+
const page = documentElement ?? target;
|
|
459
|
+
const pageRect = page.getBoundingClientRect();
|
|
411
460
|
const context = createContext(view, {
|
|
412
461
|
x: pageRect.left,
|
|
413
462
|
y: pageRect.top
|
|
414
463
|
}, options);
|
|
415
|
-
const root = rootElement(
|
|
416
|
-
const bodyStyle = view.getComputedStyle(body);
|
|
464
|
+
const root = rootElement(target, context);
|
|
465
|
+
const bodyStyle = body ? view.getComputedStyle(body) : null;
|
|
417
466
|
const style = root.computedStyle;
|
|
418
|
-
for (const side of [
|
|
467
|
+
if (bodyStyle) for (const side of [
|
|
419
468
|
"top",
|
|
420
469
|
"right",
|
|
421
470
|
"bottom",
|
|
@@ -426,9 +475,9 @@ async function capturePage(document = globalThis.document, options = {}) {
|
|
|
426
475
|
if (margin + padding > 0) style[`padding-${side}`] = `${margin + padding}px`;
|
|
427
476
|
delete style[`margin-${side}`];
|
|
428
477
|
}
|
|
429
|
-
style["background-color"] = [bodyStyle, view.getComputedStyle(
|
|
430
|
-
const width =
|
|
431
|
-
const height = Math.max(
|
|
478
|
+
style["background-color"] = [bodyStyle, view.getComputedStyle(page)].map((computed) => computed?.getPropertyValue("background-color")).find((color) => color !== void 0 && !isTransparent(color)) ?? "rgb(255, 255, 255)";
|
|
479
|
+
const width = page.clientWidth || pageRect.width;
|
|
480
|
+
const height = Math.max(page.scrollHeight, view.innerHeight);
|
|
432
481
|
style.width = `${width}px`;
|
|
433
482
|
style.height = `${height}px`;
|
|
434
483
|
style["box-sizing"] = "border-box";
|
|
@@ -1 +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', 'type', '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;EAC7C,OAAO,QAAQ,CAAC,GAAG,SAAS,GAAG,OAAO,IAAI,CAAC;CAC7C,CAAC;CACD,IAAI,aAAa,SAAS,GAAG,KAAK,aAAa,SAAS,aAAa,KAAK,GAAG,CAAC;AAChF;;AAGA,SAAS,kBAAkB,KAAoB,UAA+B;CAC5E,MAAM,0BAAU,IAAI,IAAa;CACjC,KAAK,MAAM,OAAO,IAAI,iBAAiB,KAAK,GAAG;EAC7C,MAAM,YAAY,IAAI,aAAa,MAAM,KAAK,IAAI,aAAa,YAAY,KAAK;EAChF,IAAI,CAAC,UAAU,WAAW,GAAG,GAAG;EAChC,MAAM,SAAS,SAAS,eAAe,UAAU,MAAM,CAAC,CAAC;EACzD,IAAI,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG,QAAQ,IAAI,MAAM;CACzD;CACA,OAAO,CAAC,GAAG,OAAO;AACpB;;;;;AAMA,SAAgB,oBACd,MACA,KACA,MACQ;CACR,MAAM,OAAO,IAAI,UAAU,IAAI;CAC/B,IAAI,EAAE,gBAAgB,KAAK,gBAAgB,OAAO;CAClD,MAAM,YAAY,CAAC,KAAK,GAAG,IAAI,iBAAiB,GAAG,CAAC;CACpD,MAAM,SAAS,CAAC,MAAM,GAAG,KAAK,iBAAiB,GAAG,CAAC;CACnD,KAAK,MAAM,CAA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AAO,MAAM,UAAU;CACzB;CAIA,MAAM,sBAHa,CAAC,WAAW,KAAK,iBAAiB,eAAe,CAAC,CAAC,CACnE,KAAK,aAAa,SAAS,iBAAiB,kBAAkB,CAAC,CAAC,CAChE,MAAM,UAAU,CAAC,cAAc,KAAK,CACF,KAAK;CAE1C,MAAM,QAAQ,gBAAgB,eAAe,SAAS;CACtD,MAAM,SAAS,KAAK,IAAI,gBAAgB,cAAc,KAAK,WAAW;CACtE,MAAM,QAAQ,GAAG,MAAM;CACvB,MAAM,SAAS,GAAG,OAAO;CACzB,MAAM,gBAAgB;CACtB,KAAK,MAAM;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO;CACvC,OAAO,OAAO,SAAS,MAAM,QAAQ,OAAO;AAC9C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["SVG_NAMESPACE"],"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', 'type', '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\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg'\n\n/** An SVG that paints `color` through the alpha of the mask image at `url`, as CSS masks do. */\nfunction maskedColorMarkup(\n view: CaptureWindow,\n url: string,\n color: string,\n size: { width: number; height: number },\n fit: string\n): string {\n const document = view.document\n const svg = document.createElementNS(SVG_NAMESPACE, 'svg')\n svg.setAttribute('xmlns', SVG_NAMESPACE)\n svg.setAttribute('width', String(size.width))\n svg.setAttribute('height', String(size.height))\n const mask = document.createElementNS(SVG_NAMESPACE, 'mask')\n mask.setAttribute('id', 'icon')\n mask.setAttribute('style', 'mask-type: alpha')\n const image = document.createElementNS(SVG_NAMESPACE, 'image')\n image.setAttribute('href', url)\n image.setAttribute('width', '100%')\n image.setAttribute('height', '100%')\n image.setAttribute('preserveAspectRatio', fit === 'cover' ? 'xMidYMid slice' : 'xMidYMid meet')\n mask.append(image)\n const rect = document.createElementNS(SVG_NAMESPACE, 'rect')\n rect.setAttribute('width', '100%')\n rect.setAttribute('height', '100%')\n rect.setAttribute('fill', color)\n rect.setAttribute('mask', 'url(#icon)')\n svg.append(mask, rect)\n return new view.XMLSerializer().serializeToString(svg)\n}\n\n/**\n * A box painted through a mask, as CSS icon sets draw icons: its background color shows only\n * where the mask image is opaque. Layers have no masks, so the box becomes an image of the\n * colored shape rather than a box of solid color. Only an inline mask image can be drawn.\n */\nfunction captureMask(style: CSSStyleDeclaration, node: WebCaptureElement, context: WalkContext) {\n const mask = style.getPropertyValue('mask-image') || style.getPropertyValue('-webkit-mask-image')\n const url = BACKGROUND_URL.exec(mask)?.[2]\n if (!url || node.tagName === 'img' || node.children.length > 0) return\n const color = node.computedStyle['background-color']\n node.tagName = 'img'\n delete node.computedStyle['background-color']\n const box = node.box\n if (!color || !url.startsWith('data:') || !box || box.width <= 0 || box.height <= 0) return\n const size = imageSize(box)\n const fit = style.getPropertyValue('mask-size') || style.getPropertyValue('-webkit-mask-size')\n const markup = maskedColorMarkup(context.view, url, color, size, fit)\n inlineSource(context, node, () => context.images.rasterizeSVG(markup, size))\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 captureMask(style, node, context)\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 // lib.dom types both as always present, but a frameset page has no body and a document can\n // lack a root element.\n const body = document.body as HTMLElement | null\n const documentElement = document.documentElement as HTMLElement | null\n const target = body ?? documentElement\n if (!target) throw new Error('The page has nothing to capture')\n const page = documentElement ?? target\n const pageRect = page.getBoundingClientRect()\n const context = createContext(view, { x: pageRect.left, y: pageRect.top }, options)\n const root = rootElement(target, context)\n const bodyStyle = body ? view.getComputedStyle(body) : null\n const style = root.computedStyle\n if (bodyStyle) {\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 }\n const background = [bodyStyle, view.getComputedStyle(page)]\n .map((computed) => computed?.getPropertyValue('background-color'))\n .find((color) => color !== undefined && !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 = page.clientWidth || pageRect.width\n const height = Math.max(page.scrollHeight, view.innerHeight)\n style.width = `${width}px`\n style.height = `${height}px`\n style['box-siz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EAAM,GAAG,SAAS;CAAI,GAAG,OAAO;CAClF,MAAM,OAAO,YAAY,QAAQ,OAAO;CACxC,MAAM,YAAY,OAAO,KAAK,iBAAiB,IAAI,IAAI;CACvD,MAAM,QAAQ,KAAK;CACnB,IAAI,WACF,KAAK,MAAM,QAAQ;EAAC;EAAO;EAAS;EAAU;CAAM,GAAY;EAC9D,MAAM,SAAS,OAAO,WAAW,UAAU,iBAAiB,UAAU,MAAM,CAAC,KAAK;EAClF,MAAM,UAAU,OAAO,WAAW,UAAU,iBAAiB,WAAW,MAAM,CAAC,KAAK;EACpF,IAAI,SAAS,UAAU,GAAG,MAAM,WAAW,UAAU,GAAG,SAAS,QAAQ;EACzE,OAAO,MAAM,UAAU;CACzB;CAKF,MAAM,sBAHa,CAAC,WAAW,KAAK,iBAAiB,IAAI,CAAC,CAAC,CACxD,KAAK,aAAa,UAAU,iBAAiB,kBAAkB,CAAC,CAAC,CACjE,MAAM,UAAU,UAAU,KAAA,KAAa,CAAC,cAAc,KAAK,CACzB,KAAK;CAE1C,MAAM,QAAQ,KAAK,eAAe,SAAS;CAC3C,MAAM,SAAS,KAAK,IAAI,KAAK,cAAc,KAAK,WAAW;CAC3D,MAAM,QAAQ,GAAG,MAAM;CACvB,MAAM,SAAS,GAAG,OAAO;CACzB,MAAM,gBAAgB;CACtB,KAAK,MAAM;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO;CACvC,OAAO,OAAO,SAAS,MAAM,QAAQ,OAAO;AAC9C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,8 +29,9 @@ interface WebCaptureHTMLOptions {
|
|
|
29
29
|
images?: boolean;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* The capture as static HTML whose elements carry their
|
|
33
|
-
*
|
|
32
|
+
* The capture as static HTML whose elements carry their styles inline, for applications that
|
|
33
|
+
* read clipboard HTML but not the capture itself, and for importing it as HTML. It is the styled
|
|
34
|
+
* DOM a paste builds layers from, so the HTML importer reads the capture as the paste does.
|
|
34
35
|
*/
|
|
35
36
|
declare function webCaptureToHTML(capture: WebCapture, options?: WebCaptureHTMLOptions): string;
|
|
36
37
|
//#endregion
|
|
@@ -90,7 +91,7 @@ declare function hasWebContent(html: string, options?: Pick<SanitizeWebHTMLOptio
|
|
|
90
91
|
* The computed properties a capture keeps for each element: those `@pairdraw/dom-css` builds
|
|
91
92
|
* layers from, plus margins, which a capture turns into spacing when it is imported.
|
|
92
93
|
*/
|
|
93
|
-
declare const CAPTURED_STYLE_PROPERTIES: readonly ["align-items", "align-self", "aspect-ratio", "background-color", "background-image", "background-position", "background-repeat", "background-size", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-left-color", "border-left-style", "border-left-width", "border-right-color", "border-right-style", "border-right-width", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "bottom", "box-shadow", "box-sizing", "color", "column-gap", "display", "flex-direction", "flex-wrap", "font-family", "font-size", "font-style", "font-weight", "gap", "height", "justify-content", "left", "letter-spacing", "line-height", "margin-bottom", "margin-left", "margin-right", "margin-top", "max-height", "max-width", "min-height", "min-width", "object-fit", "opacity", "overflow", "padding-bottom", "padding-left", "padding-right", "padding-top", "position", "right", "row-gap", "text-align", "text-decoration-color", "text-decoration-line", "text-decoration-style", "text-decoration-thickness", "text-indent", "text-shadow", "text-transform", "text-underline-offset", "top", "white-space", "width"];
|
|
94
|
+
declare const CAPTURED_STYLE_PROPERTIES: readonly ["align-items", "align-self", "aspect-ratio", "background-color", "background-image", "background-position", "background-repeat", "background-size", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-left-color", "border-left-style", "border-left-width", "border-right-color", "border-right-style", "border-right-width", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "bottom", "box-shadow", "box-sizing", "color", "column-gap", "display", "flex-direction", "flex-wrap", "font-family", "font-size", "font-style", "font-weight", "gap", "height", "justify-content", "left", "letter-spacing", "line-height", "margin-bottom", "margin-left", "margin-right", "margin-top", "max-height", "max-width", "min-height", "min-width", "object-fit", "opacity", "order", "overflow", "padding-bottom", "padding-left", "padding-right", "padding-top", "position", "right", "row-gap", "text-align", "text-decoration-color", "text-decoration-line", "text-decoration-style", "text-decoration-thickness", "text-indent", "text-shadow", "text-transform", "text-underline-offset", "top", "white-space", "width"];
|
|
94
95
|
type CapturedStyleProperty = (typeof CAPTURED_STYLE_PROPERTIES)[number];
|
|
95
96
|
/** Whether a capture keeps this property; others are dropped when a capture is read. */
|
|
96
97
|
declare function isCapturedStyleProperty(property: string): property is CapturedStyleProperty;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/design-document.ts","../src/html.ts","../src/limits.ts","../src/parse.ts","../src/sanitize.ts","../src/styles.ts","../src/urls.ts"],"mappings":";;;;;;UAUiB;EACf;EACA;EACA,OAAO;EACP,eAAe;EACf,UAAU;;KAGA,uBAAuB,0BAA0B;;UAG5C;EACf;EACA,UAAU;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/design-document.ts","../src/html.ts","../src/limits.ts","../src/parse.ts","../src/sanitize.ts","../src/styles.ts","../src/urls.ts"],"mappings":";;;;;;UAUiB;EACf;EACA;EACA,OAAO;EACP,eAAe;EACf,UAAU;;KAGA,uBAAuB,0BAA0B;;UAG5C;EACf;EACA,UAAU;;;;;;iBAoVI,yBAAyB,SAAS,aAAa;;;UCjT9C;;EAEf;;;;;;;iBAsCc,iBAAiB,SAAS,YAAY,UAAS;;;;cCjGlD;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;;;;;;;;iBCyKG,oBAAoB,SAAS,aAAa;;iBAQ1C,eAAe,iBAAiB;;iBAahC,gBAAgB,eAAe;;;UCxK9B;;EAEf,SAAS,KAAK;;EAEd;;;;;;;;;;;iBA+Dc,gBAAgB,cAAc,UAAS;;iBAcvC,cAAc,cAAc,UAAS,KAAK;;;;;;;cCvH7C;KA4ED,gCAAgC;;iBAK5B,wBAAwB,mBAAmB,YAAY;;;;;iBA4DvD,qBAAqB,OAAO,yBAAyB;;;;iBCpIrD,YAAY,eAAe;;iBAM3B,gBAAgB,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CAPTURED_STYLE_PROPERTIES, MAX_CAPTURE_DEPTH, MAX_CAPTURE_ELEMENTS, MAX_CAPTURE_IMAGES_BYTES, MAX_CAPTURE_IMAGE_BYTES, MAX_CAPTURE_JSON_LENGTH, MAX_WEB_HTML_LENGTH, WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, isCapturedStyleProperty, normalizeWebCapture, parseWebCapture, readWebCapture, readWebCaptureClipboard, safeImageSource, safeLinkURL, webCaptureSchema, webCaptureToHTML, withoutImpliedValues } from "./chunks/capturer/clipboard.js";
|
|
2
|
-
import { webCaptureDesignDocument } from "./chunks/design-document.js";
|
|
1
|
+
import { CAPTURED_STYLE_PROPERTIES, MAX_CAPTURE_DEPTH, MAX_CAPTURE_ELEMENTS, MAX_CAPTURE_IMAGES_BYTES, MAX_CAPTURE_IMAGE_BYTES, MAX_CAPTURE_JSON_LENGTH, MAX_WEB_HTML_LENGTH, WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, isCapturedStyleProperty, normalizeWebCapture, parseWebCapture, readWebCapture, readWebCaptureClipboard, safeImageSource, safeLinkURL, webCaptureDesignDocument, webCaptureSchema, webCaptureToHTML, withoutImpliedValues } from "./chunks/capturer/clipboard.js";
|
|
3
2
|
import { hasWebContent, sanitizeWebHTML } from "./chunks/index.js";
|
|
4
3
|
export { CAPTURED_STYLE_PROPERTIES, MAX_CAPTURE_DEPTH, MAX_CAPTURE_ELEMENTS, MAX_CAPTURE_IMAGES_BYTES, MAX_CAPTURE_IMAGE_BYTES, MAX_CAPTURE_JSON_LENGTH, MAX_WEB_HTML_LENGTH, WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, hasWebContent, isCapturedStyleProperty, normalizeWebCapture, parseWebCapture, readWebCapture, readWebCaptureClipboard, safeImageSource, safeLinkURL, sanitizeWebHTML, webCaptureDesignDocument, webCaptureSchema, webCaptureToHTML, withoutImpliedValues };
|