@pairdraw/web-capture 0.19.1 → 0.19.2

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.
@@ -143,25 +143,33 @@ export async function capturePage(
143
143
  ): Promise<WebCapture> {
144
144
  options.signal?.throwIfAborted()
145
145
  const view = windowOf(document)
146
- const { body, documentElement } = document
147
- const pageRect = documentElement.getBoundingClientRect()
146
+ // lib.dom types both as always present, but a frameset page has no body and a document can
147
+ // lack a root element.
148
+ const body = document.body as HTMLElement | null
149
+ const documentElement = document.documentElement as HTMLElement | null
150
+ const target = body ?? documentElement
151
+ if (!target) throw new Error('The page has nothing to capture')
152
+ const page = documentElement ?? target
153
+ const pageRect = page.getBoundingClientRect()
148
154
  const context = createContext(view, { x: pageRect.left, y: pageRect.top }, options)
149
- const root = rootElement(body, context)
150
- const bodyStyle = view.getComputedStyle(body)
155
+ const root = rootElement(target, context)
156
+ const bodyStyle = body ? view.getComputedStyle(body) : null
151
157
  const style = root.computedStyle
152
- for (const side of ['top', 'right', 'bottom', 'left'] as const) {
153
- const margin = Number.parseFloat(bodyStyle.getPropertyValue(`margin-${side}`)) || 0
154
- const padding = Number.parseFloat(bodyStyle.getPropertyValue(`padding-${side}`)) || 0
155
- if (margin + padding > 0) style[`padding-${side}`] = `${margin + padding}px`
156
- delete style[`margin-${side}`]
158
+ if (bodyStyle) {
159
+ for (const side of ['top', 'right', 'bottom', 'left'] as const) {
160
+ const margin = Number.parseFloat(bodyStyle.getPropertyValue(`margin-${side}`)) || 0
161
+ const padding = Number.parseFloat(bodyStyle.getPropertyValue(`padding-${side}`)) || 0
162
+ if (margin + padding > 0) style[`padding-${side}`] = `${margin + padding}px`
163
+ delete style[`margin-${side}`]
164
+ }
157
165
  }
158
- const background = [bodyStyle, view.getComputedStyle(documentElement)]
159
- .map((computed) => computed.getPropertyValue('background-color'))
160
- .find((color) => !isTransparent(color))
166
+ const background = [bodyStyle, view.getComputedStyle(page)]
167
+ .map((computed) => computed?.getPropertyValue('background-color'))
168
+ .find((color) => color !== undefined && !isTransparent(color))
161
169
  style['background-color'] = background ?? 'rgb(255, 255, 255)'
162
170
  // The page's size, not the body's, which may be shorter than the window.
163
- const width = documentElement.clientWidth || pageRect.width
164
- const height = Math.max(documentElement.scrollHeight, view.innerHeight)
171
+ const width = page.clientWidth || pageRect.width
172
+ const height = Math.max(page.scrollHeight, view.innerHeight)
165
173
  style.width = `${width}px`
166
174
  style.height = `${height}px`
167
175
  style['box-sizing'] = 'border-box'
@@ -238,6 +238,59 @@ function captureBackground(
238
238
  node.children.unshift(image)
239
239
  }
240
240
 
241
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg'
242
+
243
+ /** An SVG that paints `color` through the alpha of the mask image at `url`, as CSS masks do. */
244
+ function maskedColorMarkup(
245
+ view: CaptureWindow,
246
+ url: string,
247
+ color: string,
248
+ size: { width: number; height: number },
249
+ fit: string
250
+ ): string {
251
+ const document = view.document
252
+ const svg = document.createElementNS(SVG_NAMESPACE, 'svg')
253
+ svg.setAttribute('xmlns', SVG_NAMESPACE)
254
+ svg.setAttribute('width', String(size.width))
255
+ svg.setAttribute('height', String(size.height))
256
+ const mask = document.createElementNS(SVG_NAMESPACE, 'mask')
257
+ mask.setAttribute('id', 'icon')
258
+ mask.setAttribute('style', 'mask-type: alpha')
259
+ const image = document.createElementNS(SVG_NAMESPACE, 'image')
260
+ image.setAttribute('href', url)
261
+ image.setAttribute('width', '100%')
262
+ image.setAttribute('height', '100%')
263
+ image.setAttribute('preserveAspectRatio', fit === 'cover' ? 'xMidYMid slice' : 'xMidYMid meet')
264
+ mask.append(image)
265
+ const rect = document.createElementNS(SVG_NAMESPACE, 'rect')
266
+ rect.setAttribute('width', '100%')
267
+ rect.setAttribute('height', '100%')
268
+ rect.setAttribute('fill', color)
269
+ rect.setAttribute('mask', 'url(#icon)')
270
+ svg.append(mask, rect)
271
+ return new view.XMLSerializer().serializeToString(svg)
272
+ }
273
+
274
+ /**
275
+ * A box painted through a mask, as CSS icon sets draw icons: its background color shows only
276
+ * where the mask image is opaque. Layers have no masks, so the box becomes an image of the
277
+ * colored shape rather than a box of solid color. Only an inline mask image can be drawn.
278
+ */
279
+ function captureMask(style: CSSStyleDeclaration, node: WebCaptureElement, context: WalkContext) {
280
+ const mask = style.getPropertyValue('mask-image') || style.getPropertyValue('-webkit-mask-image')
281
+ const url = BACKGROUND_URL.exec(mask)?.[2]
282
+ if (!url || node.tagName === 'img' || node.children.length > 0) return
283
+ const color = node.computedStyle['background-color']
284
+ node.tagName = 'img'
285
+ delete node.computedStyle['background-color']
286
+ const box = node.box
287
+ if (!color || !url.startsWith('data:') || !box || box.width <= 0 || box.height <= 0) return
288
+ const size = imageSize(box)
289
+ const fit = style.getPropertyValue('mask-size') || style.getPropertyValue('-webkit-mask-size')
290
+ const markup = maskedColorMarkup(context.view, url, color, size, fit)
291
+ inlineSource(context, node, () => context.images.rasterizeSVG(markup, size))
292
+ }
293
+
241
294
  function captureChildren(element: Element, context: WalkContext, depth: number): WebCaptureNode[] {
242
295
  return renderedChildren(element, context.view).flatMap((child) => {
243
296
  if (child.nodeType === 3) {
@@ -278,6 +331,7 @@ export function walkElement(element: Element, context: WalkContext, depth = 0):
278
331
  if (hasDirectText(element) || node.children.some((child) => child.type === 'text')) {
279
332
  context.fonts.add(style)
280
333
  }
334
+ captureMask(style, node, context)
281
335
  captureBackground(style, node, context)
282
336
  return [node]
283
337
  }
@@ -281,11 +281,58 @@ function glyphBox(
281
281
  return SIDES.some((side) => margins[side] > 0) ? marginBox(wrapped, margins) : wrapped
282
282
  }
283
283
 
284
+ /** What a box records of its size and border, which a word box drawn as a run of text drops. */
285
+ const WORD_BOX_PROPERTIES = [
286
+ 'display',
287
+ 'width',
288
+ 'height',
289
+ 'min-width',
290
+ 'max-width',
291
+ 'min-height',
292
+ 'max-height',
293
+ 'box-sizing',
294
+ ...SIDES.flatMap((side) => ['style', 'width', 'color'].map((part) => `border-${side}-${part}`))
295
+ ]
296
+
297
+ /** Properties that make a box draw something besides its text, or change where its text sits. */
298
+ const DRAWN_BOX_PROPERTIES = [
299
+ 'background-color',
300
+ 'background-image',
301
+ 'box-shadow',
302
+ 'opacity',
303
+ 'overflow',
304
+ ...SIDES.map((side) => `padding-${side}` as const)
305
+ ]
306
+
307
+ /**
308
+ * An inline-block that holds one line of text and draws nothing else, as pages that fade words
309
+ * in box each word. It reads as a run of the text around it, not a box: kept as a box, every word
310
+ * becomes a layer of its own and wraps at its own width.
311
+ */
312
+ function isWordBox(element: WebCaptureElement, style: Record<string, string>): boolean {
313
+ if (style.display !== 'inline-block' || !INLINE_TEXT_TAGS.has(element.tagName)) return false
314
+ if (!element.children.every((child) => child.type === 'text')) return false
315
+ if (DRAWN_BOX_PROPERTIES.some((property) => ownValue(style, property) !== undefined)) return false
316
+ if (SIDES.some((side) => pixels(style[`margin-${side}`]) !== 0)) return false
317
+ if (SIDES.some((side) => pixels(style[`border-${side}-width`]) > 0)) return false
318
+ const lineHeight = pixels(style['line-height']) || pixels(style['font-size']) * 1.5
319
+ return element.box !== undefined && element.box.height < lineHeight * 1.5
320
+ }
321
+
284
322
  function convertElement(
285
323
  element: WebCaptureElement,
286
324
  parentBox?: WebCaptureBox
287
325
  ): WebCaptureDesignElement {
288
326
  const { displayed, children } = layoutOf(element)
327
+ if (isWordBox(element, displayed)) {
328
+ return {
329
+ type: 'element',
330
+ tagName: element.tagName,
331
+ attrs: { ...element.attrs },
332
+ computedStyle: omit(displayed, [...WORD_BOX_PROPERTIES, ...MARGINS]),
333
+ children
334
+ }
335
+ }
289
336
  const inline = isInline(displayed)
290
337
  const split = splitMargins(displayed)
291
338
  const { margins } = split
package/src/html.ts CHANGED
@@ -1,11 +1,61 @@
1
1
  import { escapeAttribute, escapeText } from 'entities'
2
2
 
3
+ import {
4
+ webCaptureDesignDocument,
5
+ type WebCaptureDesignElement,
6
+ type WebCaptureDesignNode
7
+ } from './design-document'
3
8
  import type { WebCapture } from './format'
4
9
  import { ownValue } from './record'
5
- import type { WebCaptureElement, WebCaptureNode } from './types'
6
10
 
7
11
  const VOID_TAGS = new Set(['area', 'br', 'col', 'hr', 'img', 'input', 'source', 'wbr'])
8
12
 
13
+ /** Tags whose start ends an open `<p>` when HTML is parsed, which would lift them out of it. */
14
+ const CLOSES_PARAGRAPH = new Set([
15
+ 'address',
16
+ 'article',
17
+ 'aside',
18
+ 'blockquote',
19
+ 'details',
20
+ 'div',
21
+ 'dl',
22
+ 'fieldset',
23
+ 'figcaption',
24
+ 'figure',
25
+ 'footer',
26
+ 'form',
27
+ 'h1',
28
+ 'h2',
29
+ 'h3',
30
+ 'h4',
31
+ 'h5',
32
+ 'h6',
33
+ 'header',
34
+ 'hgroup',
35
+ 'hr',
36
+ 'main',
37
+ 'menu',
38
+ 'nav',
39
+ 'ol',
40
+ 'p',
41
+ 'pre',
42
+ 'section',
43
+ 'table',
44
+ 'ul'
45
+ ])
46
+
47
+ /**
48
+ * The tag an element is written with. A script can put a block inside a `<p>`, as the capture's
49
+ * own spacers around a margined box do, but parsing would end the paragraph there; a `<div>`
50
+ * holds it in place, and the element's styles say how it lays out either way.
51
+ */
52
+ function writtenTag(element: WebCaptureDesignElement): string {
53
+ const holdsBlock = element.children.some(
54
+ (child) => child.type === 'element' && CLOSES_PARAGRAPH.has(child.tagName)
55
+ )
56
+ return element.tagName === 'p' && holdsBlock ? 'div' : element.tagName
57
+ }
58
+
9
59
  export interface WebCaptureHTMLOptions {
10
60
  /** Keep inlined images; without them an image keeps only its size and description. */
11
61
  images?: boolean
@@ -17,9 +67,14 @@ function styleAttribute(style: Record<string, string>): string {
17
67
  .join('; ')
18
68
  }
19
69
 
20
- function attributes(element: WebCaptureElement, options: WebCaptureHTMLOptions): string {
70
+ function attributes(element: WebCaptureDesignElement, options: WebCaptureHTMLOptions): string {
21
71
  const attrs: Record<string, string> = { ...element.attrs }
22
72
  if (options.images === false && ownValue(attrs, 'src')?.startsWith('data:')) delete attrs.src
73
+ // A captured field holds the text it showed; an `<input>` holds it as its value.
74
+ if (element.tagName === 'input') {
75
+ const text = element.children.map((child) => (child.type === 'text' ? child.text : '')).join('')
76
+ if (text) attrs.value = text
77
+ }
23
78
  const style = styleAttribute(element.computedStyle)
24
79
  if (style) attrs.style = style
25
80
  return Object.entries(attrs)
@@ -27,18 +82,22 @@ function attributes(element: WebCaptureElement, options: WebCaptureHTMLOptions):
27
82
  .join('')
28
83
  }
29
84
 
30
- function serialize(node: WebCaptureNode, options: WebCaptureHTMLOptions): string {
85
+ function serialize(node: WebCaptureDesignNode, options: WebCaptureHTMLOptions): string {
31
86
  if (node.type === 'text') return escapeText(node.text)
32
- const open = `<${node.tagName}${attributes(node, options)}>`
33
- if (VOID_TAGS.has(node.tagName)) return open
87
+ const tag = writtenTag(node)
88
+ const open = `<${tag}${attributes(node, options)}>`
89
+ if (VOID_TAGS.has(tag)) return open
34
90
  const children = node.children.map((child) => serialize(child, options)).join('')
35
- return `${open}${children}</${node.tagName}>`
91
+ return `${open}${children}</${tag}>`
36
92
  }
37
93
 
38
94
  /**
39
- * The capture as static HTML whose elements carry their computed styles inline, for
40
- * applications that read clipboard HTML but not the capture itself.
95
+ * The capture as static HTML whose elements carry their styles inline, for applications that
96
+ * read clipboard HTML but not the capture itself, and for importing it as HTML. It is the styled
97
+ * DOM a paste builds layers from, so the HTML importer reads the capture as the paste does.
41
98
  */
42
99
  export function webCaptureToHTML(capture: WebCapture, options: WebCaptureHTMLOptions = {}): string {
43
- return serialize(capture.root, options)
100
+ return webCaptureDesignDocument(capture)
101
+ .children.map((node) => serialize(node, options))
102
+ .join('')
44
103
  }
package/src/styles.ts CHANGED
@@ -57,6 +57,7 @@ export const CAPTURED_STYLE_PROPERTIES = [
57
57
  'min-width',
58
58
  'object-fit',
59
59
  'opacity',
60
+ 'order',
60
61
  'overflow',
61
62
  'padding-bottom',
62
63
  'padding-left',
@@ -117,6 +118,7 @@ const IMPLIED_VALUES: Partial<Record<CapturedStyleProperty, readonly string[]>>
117
118
  'min-width': ['auto', '0px'],
118
119
  'object-fit': ['fill'],
119
120
  opacity: ['1'],
121
+ order: ['0'],
120
122
  overflow: ['visible'],
121
123
  'row-gap': ['normal'],
122
124
  'text-indent': ['0px'],
@@ -1,310 +0,0 @@
1
- import { ownValue } from "./capturer/clipboard.js";
2
- import { omit } from "es-toolkit";
3
- //#region src/design-document.ts
4
- const SIDES = [
5
- "top",
6
- "right",
7
- "bottom",
8
- "left"
9
- ];
10
- /**
11
- * Displays the importer has no layout for, mapped to the closest one it has. A grid of
12
- * fixed-size cells wraps as a row of them does, and a table row is a row of its cells.
13
- */
14
- const DISPLAY_FALLBACKS = {
15
- grid: {
16
- display: "flex",
17
- "flex-direction": "row",
18
- "flex-wrap": "wrap"
19
- },
20
- "inline-grid": {
21
- display: "inline-flex",
22
- "flex-direction": "row",
23
- "flex-wrap": "wrap"
24
- },
25
- "table-row": {
26
- display: "flex",
27
- "flex-direction": "row",
28
- "flex-wrap": "nowrap"
29
- },
30
- table: { display: "block" },
31
- "inline-table": { display: "inline-block" },
32
- "table-row-group": { display: "block" },
33
- "table-header-group": { display: "block" },
34
- "table-footer-group": { display: "block" },
35
- "table-cell": { display: "block" },
36
- "table-caption": { display: "block" },
37
- "list-item": { display: "block" },
38
- "flow-root": { display: "block" }
39
- };
40
- /**
41
- * Inline text tags the importer lays out inline when they say nothing of their display. Left
42
- * without one, a run such as a link or a bold word stays text instead of a box around text.
43
- */
44
- const INLINE_TEXT_TAGS = /* @__PURE__ */ new Set([
45
- "a",
46
- "b",
47
- "code",
48
- "em",
49
- "i",
50
- "small",
51
- "span",
52
- "strong",
53
- "u"
54
- ]);
55
- function pixels(value) {
56
- if (!value?.endsWith("px")) return 0;
57
- const parsed = Number.parseFloat(value);
58
- return Number.isFinite(parsed) ? parsed : 0;
59
- }
60
- function px(value) {
61
- return `${Math.round(value * 100) / 100}px`;
62
- }
63
- const MARGINS = SIDES.map((side) => `margin-${side}`);
64
- /** The element's margins in pixels, and its style without them. */
65
- function splitMargins(style) {
66
- const margins = {
67
- top: 0,
68
- right: 0,
69
- bottom: 0,
70
- left: 0
71
- };
72
- for (const side of SIDES) margins[side] = pixels(style[`margin-${side}`]);
73
- return {
74
- margins,
75
- style: omit(style, MARGINS)
76
- };
77
- }
78
- function isAbsolute(style) {
79
- return style.position === "absolute" || style.position === "fixed";
80
- }
81
- function isInline(style) {
82
- return (ownValue(style, "display") ?? "").startsWith("inline");
83
- }
84
- /**
85
- * Places an absolute box in its parent layer. CSS measures `left` and `top` from the containing
86
- * block, which may be a further ancestor or the viewport, so the recorded boxes place it where
87
- * the page drew it. Without them, it sits at its offset plus its margin, as CSS places it.
88
- */
89
- function placeAbsolute(style, margins, box, parentBox) {
90
- if (box && parentBox) {
91
- style.left = px(box.x - parentBox.x);
92
- style.top = px(box.y - parentBox.y);
93
- return;
94
- }
95
- if (ownValue(style, "left") !== void 0) style.left = px(pixels(style.left) + margins.left);
96
- if (ownValue(style, "top") !== void 0) style.top = px(pixels(style.top) + margins.top);
97
- }
98
- /**
99
- * A box in normal flow keeps the room its margins took inside a transparent box padded by them.
100
- * Negative margins, which pull neighbours over each other, are dropped.
101
- */
102
- function marginBox(element, margins) {
103
- const style = { display: "block" };
104
- for (const side of SIDES) if (margins[side] > 0) style[`padding-${side}`] = px(margins[side]);
105
- const alignSelf = ownValue(element.computedStyle, "align-self");
106
- if (alignSelf === void 0) return {
107
- type: "element",
108
- tagName: "div",
109
- attrs: {},
110
- computedStyle: style,
111
- children: [element]
112
- };
113
- style["align-self"] = alignSelf;
114
- return {
115
- type: "element",
116
- tagName: "div",
117
- attrs: {},
118
- computedStyle: style,
119
- children: [{
120
- ...element,
121
- computedStyle: omit(element.computedStyle, ["align-self"])
122
- }]
123
- };
124
- }
125
- function convertChildren(children, parentBox) {
126
- return children.map((child) => child.type === "text" ? child : convertElement(child, parentBox));
127
- }
128
- const GRID_DISPLAYS = /* @__PURE__ */ new Set(["grid", "inline-grid"]);
129
- function hasBox(element) {
130
- return element.box !== void 0;
131
- }
132
- /**
133
- * A grid whose items can stay where the page drew them: the capture recorded the grid's box and
134
- * every item's, and the grid holds no loose text. Null otherwise, and for anything but a grid.
135
- */
136
- function placeableGrid(element) {
137
- if (!GRID_DISPLAYS.has(ownValue(element.computedStyle, "display") ?? "") || !hasBox(element)) return null;
138
- const items = [];
139
- for (const child of element.children) if (child.type === "text") {
140
- if (child.text.trim().length > 0) return null;
141
- } else if (hasBox(child)) items.push(child);
142
- else return null;
143
- return {
144
- box: element.box,
145
- items
146
- };
147
- }
148
- /**
149
- * Auto layout has no grid tracks, so a grid keeps its drawn size and its items become absolute
150
- * boxes where the page drew them. Their margins already moved their boxes.
151
- */
152
- function gridStyle(style, box) {
153
- return {
154
- ...omit(style, [
155
- "gap",
156
- "row-gap",
157
- "column-gap"
158
- ]),
159
- display: style.display === "inline-grid" ? "inline-block" : "block",
160
- width: px(box.width),
161
- height: px(box.height),
162
- "box-sizing": "border-box"
163
- };
164
- }
165
- const PLACEMENT = [
166
- ...MARGINS,
167
- "position",
168
- ...SIDES
169
- ];
170
- function placeGridItem(item, grid) {
171
- const converted = convertElement({
172
- ...item,
173
- computedStyle: omit(item.computedStyle, PLACEMENT)
174
- });
175
- converted.computedStyle = {
176
- ...converted.computedStyle,
177
- position: "absolute",
178
- left: px(item.box.x - grid.x),
179
- top: px(item.box.y - grid.y),
180
- width: px(item.box.width),
181
- height: px(item.box.height),
182
- "box-sizing": "border-box"
183
- };
184
- return converted;
185
- }
186
- /**
187
- * The style an element is laid out with, the closest display the importer has standing in for
188
- * one it lacks, and its converted children.
189
- */
190
- function layoutOf(element) {
191
- const grid = placeableGrid(element);
192
- if (grid) return {
193
- displayed: gridStyle(element.computedStyle, grid.box),
194
- children: grid.items.map((item) => placeGridItem(item, grid.box))
195
- };
196
- const display = ownValue(element.computedStyle, "display") ?? "";
197
- return {
198
- displayed: {
199
- ...element.computedStyle,
200
- ...DISPLAY_FALLBACKS[display]
201
- },
202
- children: convertChildren(element.children, element.box)
203
- };
204
- }
205
- /** Input types Chrome paints as a small intrinsic glyph, whatever box `width` gives them. */
206
- const GLYPH_INPUT_TYPES = {
207
- checkbox: true,
208
- radio: true
209
- };
210
- /**
211
- * A checkbox or radio wider than its glyph: Chrome honors the width for layout but paints only
212
- * a small square centered in the box (`input { width: 100% }` in a flex label). Import the
213
- * square at the glyph's size, centered in a box that keeps the room the wide element took, so
214
- * following content stays where the page put it. Null when the box already fits the glyph.
215
- */
216
- function glyphBox(element, converted, margins, parentBox) {
217
- const box = element.box;
218
- if (element.tagName !== "input" || !Object.hasOwn(GLYPH_INPUT_TYPES, element.attrs.type) || !box || box.width <= 0 || box.height <= 0) return null;
219
- const side = Math.min(box.width, box.height);
220
- if (box.width - side < 1) return null;
221
- const style = converted.computedStyle;
222
- const absolute = isAbsolute(style);
223
- style.width = px(side);
224
- style.height = px(side);
225
- style["box-sizing"] = "border-box";
226
- delete style.position;
227
- delete style.left;
228
- delete style.top;
229
- delete style.right;
230
- delete style.bottom;
231
- const wrapper = {
232
- display: "flex",
233
- "justify-content": "center",
234
- "align-items": "center",
235
- width: px(box.width),
236
- height: px(box.height),
237
- "box-sizing": "border-box"
238
- };
239
- const alignSelf = ownValue(style, "align-self");
240
- if (alignSelf !== void 0) {
241
- wrapper["align-self"] = alignSelf;
242
- delete style["align-self"];
243
- }
244
- const wrapped = {
245
- type: "element",
246
- tagName: "div",
247
- attrs: {},
248
- computedStyle: wrapper,
249
- children: [converted]
250
- };
251
- if (absolute) {
252
- wrapper.position = element.computedStyle.position === "fixed" ? "fixed" : "absolute";
253
- for (const key of ["left", "top"]) {
254
- const value = ownValue(element.computedStyle, key);
255
- if (value !== void 0) wrapper[key] = value;
256
- }
257
- placeAbsolute(wrapper, margins, box, parentBox);
258
- return wrapped;
259
- }
260
- return SIDES.some((side) => margins[side] > 0) ? marginBox(wrapped, margins) : wrapped;
261
- }
262
- function convertElement(element, parentBox) {
263
- const { displayed, children } = layoutOf(element);
264
- const inline = isInline(displayed);
265
- const split = splitMargins(displayed);
266
- const { margins } = split;
267
- const style = displayed.display === "inline" && INLINE_TEXT_TAGS.has(element.tagName) ? omit(split.style, ["display"]) : split.style;
268
- const converted = {
269
- type: "element",
270
- tagName: element.tagName,
271
- attrs: { ...element.attrs },
272
- computedStyle: style,
273
- children
274
- };
275
- const glyph = glyphBox(element, converted, margins, parentBox);
276
- if (glyph) return glyph;
277
- if (isAbsolute(style)) {
278
- placeAbsolute(style, margins, element.box, parentBox);
279
- return converted;
280
- }
281
- return SIDES.some((side) => margins[side] > 0) && !inline ? marginBox(converted, margins) : converted;
282
- }
283
- /**
284
- * The capture as the styled DOM layers are built from. The root keeps the size it had on the
285
- * page and drops its own position and margins, so it lands where a paste puts it.
286
- */
287
- function webCaptureDesignDocument(capture) {
288
- const { root } = capture;
289
- const { displayed, children } = layoutOf(root);
290
- const style = omit(splitMargins(displayed).style, ["position", ...SIDES]);
291
- if (root.box) {
292
- style.width = px(root.box.width);
293
- style.height = px(root.box.height);
294
- style["box-sizing"] = "border-box";
295
- }
296
- return {
297
- type: "document",
298
- children: [{
299
- type: "element",
300
- tagName: root.tagName,
301
- attrs: { ...root.attrs },
302
- computedStyle: style,
303
- children
304
- }]
305
- };
306
- }
307
- //#endregion
308
- export { webCaptureDesignDocument };
309
-
310
- //# sourceMappingURL=design-document.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"design-document.js","names":[],"sources":["../../src/design-document.ts"],"sourcesContent":["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\nfunction convertElement(\n element: WebCaptureElement,\n parentBox?: WebCaptureBox\n): WebCaptureDesignElement {\n const { displayed, children } = layoutOf(element)\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"],"mappings":";;;AA0BA,MAAM,QAAQ;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,QAA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