@pairdraw/web-capture 0.0.0-stage → 0.16.1
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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/capturer.d.ts +56 -0
- package/dist/capturer.d.ts.map +1 -0
- package/dist/capturer.js +3 -0
- package/dist/chunks/capturer/clipboard.js +575 -0
- package/dist/chunks/capturer/clipboard.js.map +1 -0
- package/dist/chunks/capturer/fonts.js +25 -0
- package/dist/chunks/capturer/fonts.js.map +1 -0
- package/dist/chunks/capturer/images.js +113 -0
- package/dist/chunks/capturer/images.js.map +1 -0
- package/dist/chunks/capturer/index.js +445 -0
- package/dist/chunks/capturer/index.js.map +1 -0
- package/dist/chunks/design-document.js +251 -0
- package/dist/chunks/design-document.js.map +1 -0
- package/dist/chunks/index.js +125 -0
- package/dist/chunks/index.js.map +1 -0
- package/dist/clipboard.d.ts +106 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/package.json +55 -4
- package/src/capturer/clipboard.ts +59 -0
- package/src/capturer/fonts.ts +30 -0
- package/src/capturer/images.ts +153 -0
- package/src/capturer/index.ts +170 -0
- package/src/capturer/page.ts +51 -0
- package/src/capturer/svg.ts +79 -0
- package/src/capturer/walk.ts +283 -0
- package/src/clipboard.ts +85 -0
- package/src/design-document.ts +267 -0
- package/src/format.ts +17 -0
- package/src/html.ts +44 -0
- package/src/index.ts +41 -0
- package/src/limits.ts +23 -0
- package/src/parse.ts +165 -0
- package/src/record.ts +10 -0
- package/src/sanitize.ts +134 -0
- package/src/schema.ts +75 -0
- package/src/styles.ts +163 -0
- package/src/types.ts +28 -0
- package/src/urls.ts +27 -0
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
function convertElement(element, parentBox) {
|
|
206
|
+
const { displayed, children } = layoutOf(element);
|
|
207
|
+
const inline = isInline(displayed);
|
|
208
|
+
const split = splitMargins(displayed);
|
|
209
|
+
const { margins } = split;
|
|
210
|
+
const style = displayed.display === "inline" && INLINE_TEXT_TAGS.has(element.tagName) ? omit(split.style, ["display"]) : split.style;
|
|
211
|
+
const converted = {
|
|
212
|
+
type: "element",
|
|
213
|
+
tagName: element.tagName,
|
|
214
|
+
attrs: { ...element.attrs },
|
|
215
|
+
computedStyle: style,
|
|
216
|
+
children
|
|
217
|
+
};
|
|
218
|
+
if (isAbsolute(style)) {
|
|
219
|
+
placeAbsolute(style, margins, element.box, parentBox);
|
|
220
|
+
return converted;
|
|
221
|
+
}
|
|
222
|
+
return SIDES.some((side) => margins[side] > 0) && !inline ? marginBox(converted, margins) : converted;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The capture as the styled DOM layers are built from. The root keeps the size it had on the
|
|
226
|
+
* page and drops its own position and margins, so it lands where a paste puts it.
|
|
227
|
+
*/
|
|
228
|
+
function webCaptureDesignDocument(capture) {
|
|
229
|
+
const { root } = capture;
|
|
230
|
+
const { displayed, children } = layoutOf(root);
|
|
231
|
+
const style = omit(splitMargins(displayed).style, ["position", ...SIDES]);
|
|
232
|
+
if (root.box) {
|
|
233
|
+
style.width = px(root.box.width);
|
|
234
|
+
style.height = px(root.box.height);
|
|
235
|
+
style["box-sizing"] = "border-box";
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
type: "document",
|
|
239
|
+
children: [{
|
|
240
|
+
type: "element",
|
|
241
|
+
tagName: root.tagName,
|
|
242
|
+
attrs: { ...root.attrs },
|
|
243
|
+
computedStyle: style,
|
|
244
|
+
children
|
|
245
|
+
}]
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { webCaptureDesignDocument };
|
|
250
|
+
|
|
251
|
+
//# sourceMappingURL=design-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\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 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,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,IAAI;CAAC;CAAK;CAAK;CAAQ;CAAM;CAAK;CAAS;CAAQ;CAAU;AAAG,CAAC;AAE9F,SAAS,OAAO,OAAmC;CACjD,IAAI,CAAC,OAAO,SAAS,IAAI,GAAG,OAAO;CACnC,MAAM,SAAS,OAAO,WAAW,KAAK;CACtC,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS;AAC5C;AAEA,SAAS,GAAG,OAAuB;CACjC,OAAO,GAAG,KAAK,MAAM,QAAQ,GAAG,IAAI,IAAI;AAC1C;AAEA,MAAM,UAAU,MAAM,KAAK,SAAS,UAAU,MAAe;;AAG7D,SAAS,aAAa,OAA+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K,CAAC;CAExE,IAAI,KAAK,KAAK;EACZ,MAAM,QAAQ,GAAG,KAAK,IAAI,KAAK;EAC/B,MAAM,SAAS,GAAG,KAAK,IAAI,MAAM;EACjC,MAAM,gBAAgB;CACxB;CACA,OAAO;EACL,MAAM;EACN,UAAU,CACR;GACE,MAAM;GACN,SAAS,KAAK;GACd,OAAO,EAAE,GAAG,KAAK,MAAM;GACvB,eAAe;GACf;EACF,CACF;CACF;AACF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { safeImageSource, safeLinkURL } from "./capturer/clipboard.js";
|
|
2
|
+
//#region src/sanitize.ts
|
|
3
|
+
/** Elements that run code, load other documents, or change how the rest is read. */
|
|
4
|
+
const REMOVED_TAGS = [
|
|
5
|
+
"script",
|
|
6
|
+
"iframe",
|
|
7
|
+
"frame",
|
|
8
|
+
"frameset",
|
|
9
|
+
"object",
|
|
10
|
+
"embed",
|
|
11
|
+
"applet",
|
|
12
|
+
"portal",
|
|
13
|
+
"base",
|
|
14
|
+
"link",
|
|
15
|
+
"meta",
|
|
16
|
+
"noscript",
|
|
17
|
+
"template",
|
|
18
|
+
"animate",
|
|
19
|
+
"animatemotion",
|
|
20
|
+
"animatetransform",
|
|
21
|
+
"set",
|
|
22
|
+
"foreignobject",
|
|
23
|
+
"math",
|
|
24
|
+
"mglyph",
|
|
25
|
+
"malignmark"
|
|
26
|
+
];
|
|
27
|
+
/** Attributes that name URLs; each keeps only what `safeLinkURL` or `safeImageSource` allow. */
|
|
28
|
+
const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
29
|
+
"href",
|
|
30
|
+
"xlink:href",
|
|
31
|
+
"action",
|
|
32
|
+
"formaction",
|
|
33
|
+
"cite"
|
|
34
|
+
]);
|
|
35
|
+
const IMAGE_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
36
|
+
"src",
|
|
37
|
+
"poster",
|
|
38
|
+
"background"
|
|
39
|
+
]);
|
|
40
|
+
/** Attributes dropped outright: inline documents, pings, and alternate image candidates. */
|
|
41
|
+
const REMOVED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
42
|
+
"srcdoc",
|
|
43
|
+
"ping",
|
|
44
|
+
"srcset",
|
|
45
|
+
"http-equiv",
|
|
46
|
+
"imagesrcset"
|
|
47
|
+
]);
|
|
48
|
+
const CSS_IMPORT = /@import[^;]*;?/gi;
|
|
49
|
+
/**
|
|
50
|
+
* Parses of the output a sanitize may take. Serialized HTML can parse into a different tree
|
|
51
|
+
* (mutation XSS), so each pass reads the previous output; HTML that has not settled by the last
|
|
52
|
+
* pass is refused.
|
|
53
|
+
*/
|
|
54
|
+
const MAX_SANITIZE_PASSES = 4;
|
|
55
|
+
/** Sets an attribute to a cleaned value, or removes it; true when that changed it. */
|
|
56
|
+
function replaceAttribute(element, name, value, url) {
|
|
57
|
+
if (url === value) return false;
|
|
58
|
+
if (url) element.setAttribute(name, url);
|
|
59
|
+
else element.removeAttribute(name);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/** Cleans an element's attributes; true when any was removed or rewritten. */
|
|
63
|
+
function cleanAttributes(element, baseURL) {
|
|
64
|
+
let changed = false;
|
|
65
|
+
for (const { name, value } of Array.from(element.attributes)) {
|
|
66
|
+
const lower = name.toLowerCase();
|
|
67
|
+
if (lower.startsWith("on") || REMOVED_ATTRIBUTES.has(lower)) {
|
|
68
|
+
element.removeAttribute(name);
|
|
69
|
+
changed = true;
|
|
70
|
+
} else if (LINK_ATTRIBUTES.has(lower)) changed = replaceAttribute(element, name, value, safeLinkURL(value, baseURL)) || changed;
|
|
71
|
+
else if (IMAGE_ATTRIBUTES.has(lower)) changed = replaceAttribute(element, name, value, safeImageSource(value, baseURL)) || changed;
|
|
72
|
+
}
|
|
73
|
+
return changed;
|
|
74
|
+
}
|
|
75
|
+
/** One parse of the HTML, cleaned and serialized, and whether cleaning changed anything. */
|
|
76
|
+
function sanitizePass(html, parser, baseURL) {
|
|
77
|
+
const document = parser.parseFromString(html, "text/html");
|
|
78
|
+
const removed = [...document.querySelectorAll(REMOVED_TAGS.join(","))];
|
|
79
|
+
for (const element of removed) element.remove();
|
|
80
|
+
let changed = removed.length > 0;
|
|
81
|
+
for (const element of document.querySelectorAll("*")) changed = cleanAttributes(element, baseURL) || changed;
|
|
82
|
+
return {
|
|
83
|
+
html: `${[...document.querySelectorAll("style")].map((style) => {
|
|
84
|
+
const css = style.textContent.replaceAll(CSS_IMPORT, "");
|
|
85
|
+
if (css !== style.textContent) {
|
|
86
|
+
style.textContent = css;
|
|
87
|
+
changed = true;
|
|
88
|
+
}
|
|
89
|
+
return document.body.contains(style) ? "" : style.outerHTML;
|
|
90
|
+
}).join("")}${document.body.innerHTML}`,
|
|
91
|
+
changed
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* HTML from outside, such as a web page's clipboard fragment, made safe to style in the app's
|
|
96
|
+
* own document: no scripts, event handlers, frames, MathML, or script URLs, and no stylesheets
|
|
97
|
+
* loaded from elsewhere. The parser builds an inert document, so nothing runs while it is
|
|
98
|
+
* cleaned. The result is a fixed point: parsing it again finds nothing to clean and serializes
|
|
99
|
+
* to the same HTML, so a later parse cannot grow elements the cleaning never saw. Returns an
|
|
100
|
+
* empty string for HTML above `MAX_WEB_HTML_LENGTH`, HTML that never settles, or without a
|
|
101
|
+
* parser.
|
|
102
|
+
*/
|
|
103
|
+
function sanitizeWebHTML(html, options = {}) {
|
|
104
|
+
if (html.length > 8388608) return "";
|
|
105
|
+
const parser = options.parser ?? (typeof DOMParser === "undefined" ? void 0 : new DOMParser());
|
|
106
|
+
if (!parser) return "";
|
|
107
|
+
let current = html;
|
|
108
|
+
for (let pass = 0; pass < MAX_SANITIZE_PASSES; pass++) {
|
|
109
|
+
const next = sanitizePass(current, parser, options.baseURL);
|
|
110
|
+
if (!next.changed && next.html === current) return current;
|
|
111
|
+
current = next.html;
|
|
112
|
+
}
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
/** Whether HTML draws anything: text other than whitespace, or an image. */
|
|
116
|
+
function hasWebContent(html, options = {}) {
|
|
117
|
+
const parser = options.parser ?? (typeof DOMParser === "undefined" ? void 0 : new DOMParser());
|
|
118
|
+
if (!parser) return false;
|
|
119
|
+
const document = parser.parseFromString(html, "text/html");
|
|
120
|
+
return document.body.textContent.trim().length > 0 || document.body.querySelector("img, svg, picture, video, canvas") !== null;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { hasWebContent, sanitizeWebHTML };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/sanitize.ts"],"sourcesContent":["import { MAX_WEB_HTML_LENGTH } from './limits'\nimport { safeImageSource, safeLinkURL } from './urls'\n\n/** Elements that run code, load other documents, or change how the rest is read. */\nconst REMOVED_TAGS = [\n 'script',\n 'iframe',\n 'frame',\n 'frameset',\n 'object',\n 'embed',\n 'applet',\n 'portal',\n 'base',\n 'link',\n 'meta',\n 'noscript',\n 'template',\n 'animate',\n 'animatemotion',\n 'animatetransform',\n 'set',\n 'foreignobject',\n // MathML and its table-breaking leaves are where re-parsing turns style text into elements.\n 'math',\n 'mglyph',\n 'malignmark'\n]\n\n/** Attributes that name URLs; each keeps only what `safeLinkURL` or `safeImageSource` allow. */\nconst LINK_ATTRIBUTES = new Set(['href', 'xlink:href', 'action', 'formaction', 'cite'])\nconst IMAGE_ATTRIBUTES = new Set(['src', 'poster', 'background'])\n/** Attributes dropped outright: inline documents, pings, and alternate image candidates. */\nconst REMOVED_ATTRIBUTES = new Set(['srcdoc', 'ping', 'srcset', 'http-equiv', 'imagesrcset'])\n\nconst CSS_IMPORT = /@import[^;]*;?/gi\n\n/**\n * Parses of the output a sanitize may take. Serialized HTML can parse into a different tree\n * (mutation XSS), so each pass reads the previous output; HTML that has not settled by the last\n * pass is refused.\n */\nconst MAX_SANITIZE_PASSES = 4\n\nexport interface SanitizeWebHTMLOptions {\n /** The parser to read the HTML with; the global `DOMParser` by default. */\n parser?: Pick<DOMParser, 'parseFromString'>\n /** The address relative links and images resolve against. */\n baseURL?: string\n}\n\n/** Sets an attribute to a cleaned value, or removes it; true when that changed it. */\nfunction replaceAttribute(element: Element, name: string, value: string, url: string | null) {\n if (url === value) return false\n if (url) element.setAttribute(name, url)\n else element.removeAttribute(name)\n return true\n}\n\n/** Cleans an element's attributes; true when any was removed or rewritten. */\nfunction cleanAttributes(element: Element, baseURL: string | undefined): boolean {\n let changed = false\n // A copy, since removing attributes changes the live list.\n for (const { name, value } of Array.from(element.attributes)) {\n const lower = name.toLowerCase()\n if (lower.startsWith('on') || REMOVED_ATTRIBUTES.has(lower)) {\n element.removeAttribute(name)\n changed = true\n } else if (LINK_ATTRIBUTES.has(lower)) {\n changed = replaceAttribute(element, name, value, safeLinkURL(value, baseURL)) || changed\n } else if (IMAGE_ATTRIBUTES.has(lower)) {\n changed = replaceAttribute(element, name, value, safeImageSource(value, baseURL)) || changed\n }\n }\n return changed\n}\n\n/** One parse of the HTML, cleaned and serialized, and whether cleaning changed anything. */\nfunction sanitizePass(\n html: string,\n parser: Pick<DOMParser, 'parseFromString'>,\n baseURL: string | undefined\n): { html: string; changed: boolean } {\n const document = parser.parseFromString(html, 'text/html')\n const removed = [...document.querySelectorAll(REMOVED_TAGS.join(','))]\n for (const element of removed) element.remove()\n let changed = removed.length > 0\n for (const element of document.querySelectorAll('*')) {\n changed = cleanAttributes(element, baseURL) || changed\n }\n const styles = [...document.querySelectorAll('style')].map((style) => {\n const css = style.textContent.replaceAll(CSS_IMPORT, '')\n if (css !== style.textContent) {\n style.textContent = css\n changed = true\n }\n // Styles in the head would be lost with it; the importer reads them from the body.\n return document.body.contains(style) ? '' : style.outerHTML\n })\n return { html: `${styles.join('')}${document.body.innerHTML}`, changed }\n}\n\n/**\n * HTML from outside, such as a web page's clipboard fragment, made safe to style in the app's\n * own document: no scripts, event handlers, frames, MathML, or script URLs, and no stylesheets\n * loaded from elsewhere. The parser builds an inert document, so nothing runs while it is\n * cleaned. The result is a fixed point: parsing it again finds nothing to clean and serializes\n * to the same HTML, so a later parse cannot grow elements the cleaning never saw. Returns an\n * empty string for HTML above `MAX_WEB_HTML_LENGTH`, HTML that never settles, or without a\n * parser.\n */\nexport function sanitizeWebHTML(html: string, options: SanitizeWebHTMLOptions = {}): string {\n if (html.length > MAX_WEB_HTML_LENGTH) return ''\n const parser = options.parser ?? (typeof DOMParser === 'undefined' ? undefined : new DOMParser())\n if (!parser) return ''\n let current = html\n for (let pass = 0; pass < MAX_SANITIZE_PASSES; pass++) {\n const next = sanitizePass(current, parser, options.baseURL)\n if (!next.changed && next.html === current) return current\n current = next.html\n }\n return ''\n}\n\n/** Whether HTML draws anything: text other than whitespace, or an image. */\nexport function hasWebContent(html: string, options: Pick<SanitizeWebHTMLOptions, 'parser'> = {}) {\n const parser = options.parser ?? (typeof DOMParser === 'undefined' ? undefined : new DOMParser())\n if (!parser) return false\n const document = parser.parseFromString(html, 'text/html')\n return (\n document.body.textContent.trim().length > 0 ||\n document.body.querySelector('img, svg, picture, video, canvas') !== null\n )\n}\n"],"mappings":";;;AAIA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;AACF;;AAGA,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAQ;CAAc;CAAU;CAAc;AAAM,CAAC;AACtF,MAAM,mCAAmB,IAAI,IAAI;CAAC;CAAO;CAAU;AAAY,CAAC;;AAEhE,MAAM,qCAAqB,IAAI,IAAI;CAAC;CAAU;CAAQ;CAAU;CAAc;AAAa,CAAC;AAE5F,MAAM,aAAa;;;;;;AAOnB,MAAM,sBAAsB;;AAU5B,SAAS,iBAAiB,SAAkB,MAAc,OAAe,KAAoB;CAC3F,IAAI,QAAQ,OAAO,OAAO;CAC1B,IAAI,KAAK,QA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AgB,gBAAgB,MAAc,UAAkC,CAAC,GAAW;CAC1F,IAAI,KAAK,SAAA,SAA8B,OAAO;CAC9C,MAAM,SAAS,QAAQ,WAAW,OAAO,cAAc,cAAc,KAAA,IAAY,IAAI,UAAU;CAC/F,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,UAAU;CACd,KAAK,IAAI,OAAO,GAAG,OAAO,qBAAqB,QAAQ;EACrD,MAAM,OAAO,aAAa,SAAS,QAAQ,QAAQ,OAAO;EAC1D,IAAI,CAAC,KAAK,WAAW,KAAK,SAAS,SAAS,OAAO;EACnD,UAAU,KAAK;CACjB;CACA,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAc,UAAkD,CAAC,GAAG;CAChG,MAAM,SAAS,QAAQ,WAAW,OAAO,cAAc,cAAc,KAAA,IAAY,IAAI,UAAU;CAC/F,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,WAAW,OAAO,gBAAgB,MAAM,WAAW;CACzD,OACE,SAAS,KAAK,YAAY,KAAK,CAAC,CAAC,SAAS,KAC1C,SAAS,KAAK,cAAc,kCAAkC,MAAM;AAExE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
/** Where an element sat on the page, in CSS pixels from the top left of the captured root. */
|
|
4
|
+
interface WebCaptureBox {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
/** A run of text as the page held it; the importer collapses whitespace as CSS does. */
|
|
11
|
+
interface WebCaptureText {
|
|
12
|
+
type: 'text';
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An element with the styles the page computed for it. The shape is the styled DOM that
|
|
17
|
+
* `@pairdraw/dom-css` builds layers from, so a capture needs no CSS runtime to import.
|
|
18
|
+
*/
|
|
19
|
+
interface WebCaptureElement {
|
|
20
|
+
type: 'element';
|
|
21
|
+
tagName: string;
|
|
22
|
+
attrs: Record<string, string>;
|
|
23
|
+
computedStyle: Record<string, string>;
|
|
24
|
+
box?: WebCaptureBox;
|
|
25
|
+
children: WebCaptureNode[];
|
|
26
|
+
}
|
|
27
|
+
type WebCaptureNode = WebCaptureElement | WebCaptureText;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/schema.d.ts
|
|
30
|
+
declare const webCaptureFontSchema: v.ObjectSchema<{
|
|
31
|
+
readonly family: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
32
|
+
readonly weight: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
33
|
+
readonly style: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
34
|
+
}, undefined>;
|
|
35
|
+
declare const webCaptureViewportSchema: v.ObjectSchema<{
|
|
36
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
37
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
38
|
+
readonly devicePixelRatio: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
39
|
+
}, undefined>;
|
|
40
|
+
/** A page or element captured with the styles the browser computed for it. */
|
|
41
|
+
declare const webCaptureSchema: v.ObjectSchema<{
|
|
42
|
+
readonly format: v.LiteralSchema<"pairdraw/web-capture", undefined>;
|
|
43
|
+
readonly version: v.LiteralSchema<1, undefined>;
|
|
44
|
+
/** Whether a whole page or one element of it was captured. */
|
|
45
|
+
readonly scope: v.PicklistSchema<["page", "element"], undefined>;
|
|
46
|
+
readonly source: v.ObjectSchema<{
|
|
47
|
+
readonly url: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>, undefined>;
|
|
48
|
+
readonly title: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>, undefined>;
|
|
49
|
+
}, undefined>;
|
|
50
|
+
/** When the capture was made, as an ISO 8601 timestamp. */
|
|
51
|
+
readonly capturedAt: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
52
|
+
readonly viewport: v.ObjectSchema<{
|
|
53
|
+
readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
54
|
+
readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
55
|
+
readonly devicePixelRatio: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
56
|
+
}, undefined>;
|
|
57
|
+
readonly root: v.GenericSchema<unknown, WebCaptureElement>;
|
|
58
|
+
readonly fonts: v.ArraySchema<v.ObjectSchema<{
|
|
59
|
+
readonly family: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
60
|
+
readonly weight: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
61
|
+
readonly style: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 4096, undefined>]>;
|
|
62
|
+
}, undefined>, undefined>;
|
|
63
|
+
/** Whether the capturer stopped at its element limit, leaving later content out. */
|
|
64
|
+
readonly truncated: v.BooleanSchema<undefined>;
|
|
65
|
+
}, undefined>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/format.d.ts
|
|
68
|
+
/** A page or element captured with the styles the browser computed for it. */
|
|
69
|
+
type WebCapture = v.InferOutput<typeof webCaptureSchema>;
|
|
70
|
+
type WebCaptureFont = v.InferOutput<typeof webCaptureFontSchema>;
|
|
71
|
+
type WebCaptureViewport = v.InferOutput<typeof webCaptureViewportSchema>;
|
|
72
|
+
/** Why a capture could not be read. */
|
|
73
|
+
type WebCaptureReadError = 'invalid' | 'too-large' | 'unsupported-version';
|
|
74
|
+
type WebCaptureReadResult = {
|
|
75
|
+
ok: true;
|
|
76
|
+
capture: WebCapture;
|
|
77
|
+
} | {
|
|
78
|
+
ok: false;
|
|
79
|
+
error: WebCaptureReadError;
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/clipboard.d.ts
|
|
83
|
+
/**
|
|
84
|
+
* Clipboard HTML carries a capture between these markers, as Base64 of the DEFLATE-compressed
|
|
85
|
+
* JSON, the way Figma and Pairdraw carry their layers in an HTML comment.
|
|
86
|
+
*/
|
|
87
|
+
declare const WEB_CAPTURE_CLIPBOARD_START = "<!--(pairdraw-web-capture)";
|
|
88
|
+
declare const WEB_CAPTURE_CLIPBOARD_END = "(/pairdraw-web-capture)-->";
|
|
89
|
+
interface WebCaptureClipboardPayload {
|
|
90
|
+
/** The capture in markers, followed by its content as styled HTML for other applications. */
|
|
91
|
+
html: string;
|
|
92
|
+
/** The page's title and address, for applications that only read text. */
|
|
93
|
+
text: string;
|
|
94
|
+
}
|
|
95
|
+
/** What the clipboard holds after copying a capture: the capture itself and a readable copy. */
|
|
96
|
+
declare function encodeWebCaptureClipboard(captured: WebCapture): WebCaptureClipboardPayload;
|
|
97
|
+
/** Whether clipboard HTML holds a complete capture marker. */
|
|
98
|
+
declare function hasWebCaptureClipboardMarker(html: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* The capture clipboard HTML holds, or null when it holds none. Clipboard HTML is writable by
|
|
101
|
+
* any page, so the payload is size-limited, validated, and normalized before it is returned.
|
|
102
|
+
*/
|
|
103
|
+
declare function readWebCaptureClipboard(html: string): WebCaptureReadResult | null;
|
|
104
|
+
//#endregion
|
|
105
|
+
export { WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WebCapture, WebCaptureBox, WebCaptureClipboardPayload, WebCaptureElement, WebCaptureFont, WebCaptureNode, WebCaptureReadError, WebCaptureReadResult, WebCaptureText, WebCaptureViewport, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, readWebCaptureClipboard, webCaptureSchema };
|
|
106
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/types.ts","../src/schema.ts","../src/format.ts","../src/clipboard.ts"],"mappings":";;;UACiB;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;;;;;;UAOe;EACf;EACA;EACA,OAAO;EACP,eAAe;EACf,MAAM;EACN,UAAU;;KAGA,iBAAiB,oBAAoB;;;cCgBpC,sBAAoB,EAAA;;;;;cAMpB,0BAAwB,EAAA;;;;;;cAYxB,kBAAgB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCxDjB,aAAa,EAAE,mBAAmB;KAElC,iBAAiB,EAAE,mBAAmB;KAEtC,qBAAqB,EAAE,mBAAmB;;KAG1C;KAEA;EACN;EAAU,SAAS;;EACnB;EAAW,OAAO;;;;;;;;cCHX;cACA;UAKI;;EAEf;;EAEA;;;iBAIc,0BAA0B,UAAU,aAAa;;iBAkBjD,6BAA6B;;;;;iBA8B7B,wBAAwB,eAAe"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WebCapture, WebCaptureBox, WebCaptureClipboardPayload, WebCaptureElement, WebCaptureFont, WebCaptureNode, WebCaptureReadError, WebCaptureReadResult, WebCaptureText, WebCaptureViewport, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, readWebCaptureClipboard, webCaptureSchema } from "./clipboard.js";
|
|
2
|
+
//#region src/design-document.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* An element of the styled DOM `@pairdraw/dom-css` builds layers from. The shape matches its
|
|
5
|
+
* `DesignElement`, so a capture imports through `sceneGraphFromStyledHTML` without a CSS runtime.
|
|
6
|
+
*/
|
|
7
|
+
interface WebCaptureDesignElement {
|
|
8
|
+
type: 'element';
|
|
9
|
+
tagName: string;
|
|
10
|
+
attrs: Record<string, string>;
|
|
11
|
+
computedStyle: Record<string, string>;
|
|
12
|
+
children: WebCaptureDesignNode[];
|
|
13
|
+
}
|
|
14
|
+
type WebCaptureDesignNode = WebCaptureDesignElement | WebCaptureText;
|
|
15
|
+
/** The styled DOM of a capture, matching `@pairdraw/dom-css`'s `DesignDocument`. */
|
|
16
|
+
interface WebCaptureDesignDocument {
|
|
17
|
+
type: 'document';
|
|
18
|
+
children: WebCaptureDesignNode[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The capture as the styled DOM layers are built from. The root keeps the size it had on the
|
|
22
|
+
* page and drops its own position and margins, so it lands where a paste puts it.
|
|
23
|
+
*/
|
|
24
|
+
declare function webCaptureDesignDocument(capture: WebCapture): WebCaptureDesignDocument;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/html.d.ts
|
|
27
|
+
interface WebCaptureHTMLOptions {
|
|
28
|
+
/** Keep inlined images; without them an image keeps only its size and description. */
|
|
29
|
+
images?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The capture as static HTML whose elements carry their computed styles inline, for
|
|
33
|
+
* applications that read clipboard HTML but not the capture itself.
|
|
34
|
+
*/
|
|
35
|
+
declare function webCaptureToHTML(capture: WebCapture, options?: WebCaptureHTMLOptions): string;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/limits.d.ts
|
|
38
|
+
/** The capture format identifier that clipboard payloads and files carry. */
|
|
39
|
+
declare const WEB_CAPTURE_FORMAT = "pairdraw/web-capture";
|
|
40
|
+
/** The capture format version this package writes and reads. */
|
|
41
|
+
declare const WEB_CAPTURE_VERSION = 1;
|
|
42
|
+
/** Elements one capture holds at most; a capturer stops descending once it reaches this. */
|
|
43
|
+
declare const MAX_CAPTURE_ELEMENTS = 20000;
|
|
44
|
+
/** How deep a capture nests; deeper elements are left out, as browsers rarely draw them. */
|
|
45
|
+
declare const MAX_CAPTURE_DEPTH = 256;
|
|
46
|
+
/** Bytes one inlined image may take; a larger image stays a link the importer records. */
|
|
47
|
+
declare const MAX_CAPTURE_IMAGE_BYTES: number;
|
|
48
|
+
/** Bytes all inlined images of a capture take together. */
|
|
49
|
+
declare const MAX_CAPTURE_IMAGES_BYTES: number;
|
|
50
|
+
/** Characters of serialized capture JSON a reader accepts, images included. */
|
|
51
|
+
declare const MAX_CAPTURE_JSON_LENGTH: number;
|
|
52
|
+
/** Characters of plain web HTML a paste styles; a larger fragment is refused. */
|
|
53
|
+
declare const MAX_WEB_HTML_LENGTH: number;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/parse.d.ts
|
|
56
|
+
/**
|
|
57
|
+
* A capture as an import may use it: only the attributes and properties layers read, links
|
|
58
|
+
* limited to http, https, and mailto, images limited to raster data URLs and http(s) addresses,
|
|
59
|
+
* and at most `MAX_CAPTURE_ELEMENTS` elements. Captures come from any page, so every reader
|
|
60
|
+
* goes through this.
|
|
61
|
+
*/
|
|
62
|
+
declare function normalizeWebCapture(capture: WebCapture): WebCapture;
|
|
63
|
+
/** Reads a capture that is already a value, such as one a capturer handed over. */
|
|
64
|
+
declare function readWebCapture(value: unknown): WebCaptureReadResult;
|
|
65
|
+
/** Reads a capture serialized as JSON, as files and clipboard payloads hold it. */
|
|
66
|
+
declare function parseWebCapture(text: string): WebCaptureReadResult;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/sanitize.d.ts
|
|
69
|
+
interface SanitizeWebHTMLOptions {
|
|
70
|
+
/** The parser to read the HTML with; the global `DOMParser` by default. */
|
|
71
|
+
parser?: Pick<DOMParser, 'parseFromString'>;
|
|
72
|
+
/** The address relative links and images resolve against. */
|
|
73
|
+
baseURL?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* HTML from outside, such as a web page's clipboard fragment, made safe to style in the app's
|
|
77
|
+
* own document: no scripts, event handlers, frames, MathML, or script URLs, and no stylesheets
|
|
78
|
+
* loaded from elsewhere. The parser builds an inert document, so nothing runs while it is
|
|
79
|
+
* cleaned. The result is a fixed point: parsing it again finds nothing to clean and serializes
|
|
80
|
+
* to the same HTML, so a later parse cannot grow elements the cleaning never saw. Returns an
|
|
81
|
+
* empty string for HTML above `MAX_WEB_HTML_LENGTH`, HTML that never settles, or without a
|
|
82
|
+
* parser.
|
|
83
|
+
*/
|
|
84
|
+
declare function sanitizeWebHTML(html: string, options?: SanitizeWebHTMLOptions): string;
|
|
85
|
+
/** Whether HTML draws anything: text other than whitespace, or an image. */
|
|
86
|
+
declare function hasWebContent(html: string, options?: Pick<SanitizeWebHTMLOptions, 'parser'>): boolean;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/styles.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* The computed properties a capture keeps for each element: those `@pairdraw/dom-css` builds
|
|
91
|
+
* layers from, plus margins, which a capture turns into spacing when it is imported.
|
|
92
|
+
*/
|
|
93
|
+
declare const CAPTURED_STYLE_PROPERTIES: readonly ["align-items", "align-self", "aspect-ratio", "background-color", "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
|
+
type CapturedStyleProperty = (typeof CAPTURED_STYLE_PROPERTIES)[number];
|
|
95
|
+
/** Whether a capture keeps this property; others are dropped when a capture is read. */
|
|
96
|
+
declare function isCapturedStyleProperty(property: string): property is CapturedStyleProperty;
|
|
97
|
+
/**
|
|
98
|
+
* The style without values that change nothing on import: defaults, borders without a style,
|
|
99
|
+
* offsets of boxes in normal flow, and decoration details of undecorated text.
|
|
100
|
+
*/
|
|
101
|
+
declare function withoutImpliedValues(style: Record<string, string>): Record<string, string>;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/urls.d.ts
|
|
104
|
+
/** A link a layer may keep: http, https, or mailto, resolved against the page; never script. */
|
|
105
|
+
declare function safeLinkURL(value: string, base?: string): string | null;
|
|
106
|
+
/** An image source a layer may keep: an inlined raster image, or an http(s) address. */
|
|
107
|
+
declare function safeImageSource(value: string, base?: string): string | null;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { CAPTURED_STYLE_PROPERTIES, type CapturedStyleProperty, MAX_CAPTURE_DEPTH, MAX_CAPTURE_ELEMENTS, MAX_CAPTURE_IMAGES_BYTES, MAX_CAPTURE_IMAGE_BYTES, MAX_CAPTURE_JSON_LENGTH, MAX_WEB_HTML_LENGTH, type SanitizeWebHTMLOptions, WEB_CAPTURE_CLIPBOARD_END, WEB_CAPTURE_CLIPBOARD_START, WEB_CAPTURE_FORMAT, WEB_CAPTURE_VERSION, type WebCapture, type WebCaptureBox, type WebCaptureClipboardPayload, type WebCaptureDesignDocument, type WebCaptureDesignElement, type WebCaptureDesignNode, type WebCaptureElement, type WebCaptureFont, type WebCaptureHTMLOptions, type WebCaptureNode, type WebCaptureReadError, type WebCaptureReadResult, type WebCaptureText, type WebCaptureViewport, encodeWebCaptureClipboard, hasWebCaptureClipboardMarker, hasWebContent, isCapturedStyleProperty, normalizeWebCapture, parseWebCapture, readWebCapture, readWebCaptureClipboard, safeImageSource, safeLinkURL, sanitizeWebHTML, webCaptureDesignDocument, webCaptureSchema, webCaptureToHTML, withoutImpliedValues };
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;;;;;;iBA6NI,yBAAyB,SAAS,aAAa;;;UC5O9C;;EAEf;;;;;;iBA+Bc,iBAAiB,SAAS,YAAY,UAAS;;;;cCxClD;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;cAGA;;;;;;;;;iBCoHG,oBAAoB,SAAS,aAAa;;iBAQ1C,eAAe,iBAAiB;;iBAahC,gBAAgB,eAAe;;;UCnH9B;;EAEf,SAAS,KAAK;;EAEd;;;;;;;;;;;iBA+Dc,gBAAgB,cAAc,UAAS;;iBAcvC,cAAc,cAAc,UAAS,KAAK;;;;;;;cCvH7C;KAuED,gCAAgC;;iBAK5B,wBAAwB,mBAAmB,YAAY;;;;;iBAuDvD,qBAAqB,OAAO,yBAAyB;;;;iBC1HrD,YAAY,eAAe;;iBAM3B,gBAAgB,eAAe"}
|