@marimo-team/islands 0.19.7-dev30 → 0.19.7-dev33
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/{ConnectedDataExplorerComponent-CukLYFVV.js → ConnectedDataExplorerComponent-DewsKLl2.js} +12 -12
- package/dist/{glide-data-editor-uGGDZv6S.js → glide-data-editor-DHsjQhtP.js} +1362 -1360
- package/dist/{label-DC2pbeUJ.js → label-C4PtQcza.js} +14 -22
- package/dist/main.js +32 -31
- package/dist/{spec-C9rnT0AN.js → spec-Dmb1KfK3.js} +24 -16
- package/dist/style.css +1 -1
- package/dist/{types-ZLLMdAtn.js → types-DBsIRhMX.js} +23 -23
- package/package.json +1 -1
- package/src/components/editor/actions/useNotebookActions.tsx +2 -2
- package/src/core/export/__tests__/hooks.test.ts +72 -33
- package/src/core/export/hooks.ts +17 -8
- package/src/plugins/impl/DataEditorPlugin.tsx +1 -1
- package/src/plugins/impl/data-editor/glide-data-editor.tsx +49 -33
- package/src/utils/__tests__/download.test.tsx +18 -18
- package/src/utils/download.ts +9 -11
- package/src/utils/html-to-image.ts +139 -0
package/src/utils/download.ts
CHANGED
|
@@ -70,16 +70,15 @@ function releaseBodyPrinting() {
|
|
|
70
70
|
* Prepare a cell element for screenshot capture.
|
|
71
71
|
*
|
|
72
72
|
* @param element - The cell output element to prepare
|
|
73
|
-
* @param
|
|
74
|
-
* This can cause layout shifts that cause the page to scroll.
|
|
73
|
+
* @param snappy - When true, avoids layout shifts and speeds up the capture.
|
|
75
74
|
* @returns A cleanup function to restore the element's original state
|
|
76
75
|
*/
|
|
77
76
|
function prepareCellElementForScreenshot(
|
|
78
77
|
element: HTMLElement,
|
|
79
|
-
|
|
78
|
+
snappy: boolean,
|
|
80
79
|
) {
|
|
81
80
|
element.classList.add("printing-output");
|
|
82
|
-
if (
|
|
81
|
+
if (!snappy) {
|
|
83
82
|
acquireBodyPrinting();
|
|
84
83
|
}
|
|
85
84
|
const originalOverflow = element.style.overflow;
|
|
@@ -87,7 +86,7 @@ function prepareCellElementForScreenshot(
|
|
|
87
86
|
|
|
88
87
|
return () => {
|
|
89
88
|
element.classList.remove("printing-output");
|
|
90
|
-
if (
|
|
89
|
+
if (!snappy) {
|
|
91
90
|
releaseBodyPrinting();
|
|
92
91
|
}
|
|
93
92
|
element.style.overflow = originalOverflow;
|
|
@@ -100,13 +99,12 @@ const THRESHOLD_TIME_MS = 500;
|
|
|
100
99
|
* Capture a cell output as a PNG data URL.
|
|
101
100
|
*
|
|
102
101
|
* @param cellId - The ID of the cell to capture
|
|
103
|
-
* @param
|
|
104
|
-
* This can cause layout shifts that cause the page to scroll.
|
|
102
|
+
* @param snappy - When true, uses a faster method to capture the image. Avoids layout shifts.
|
|
105
103
|
* @returns The PNG as a data URL, or undefined if the cell element wasn't found
|
|
106
104
|
*/
|
|
107
105
|
export async function getImageDataUrlForCell(
|
|
108
106
|
cellId: CellId,
|
|
109
|
-
|
|
107
|
+
snappy = false,
|
|
110
108
|
): Promise<string | undefined> {
|
|
111
109
|
const element = findElementForCell(cellId);
|
|
112
110
|
if (!element) {
|
|
@@ -118,11 +116,11 @@ export async function getImageDataUrlForCell(
|
|
|
118
116
|
return iframeDataUrl;
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
const cleanup = prepareCellElementForScreenshot(element,
|
|
119
|
+
const cleanup = prepareCellElementForScreenshot(element, snappy);
|
|
122
120
|
|
|
123
121
|
try {
|
|
124
122
|
const startTime = Date.now();
|
|
125
|
-
const dataUrl = await toPng(element);
|
|
123
|
+
const dataUrl = await toPng(element, undefined, snappy);
|
|
126
124
|
const timeTaken = Date.now() - startTime;
|
|
127
125
|
if (timeTaken > THRESHOLD_TIME_MS) {
|
|
128
126
|
Logger.debug(
|
|
@@ -159,7 +157,7 @@ export async function downloadCellOutputAsImage(
|
|
|
159
157
|
await downloadHTMLAsImage({
|
|
160
158
|
element,
|
|
161
159
|
filename,
|
|
162
|
-
prepare: () => prepareCellElementForScreenshot(element,
|
|
160
|
+
prepare: () => prepareCellElementForScreenshot(element, false),
|
|
163
161
|
});
|
|
164
162
|
}
|
|
165
163
|
|
|
@@ -4,6 +4,143 @@ import { Logger } from "./Logger";
|
|
|
4
4
|
|
|
5
5
|
export type HtmlToImageOptions = Parameters<typeof htmlToImageToPng>[1];
|
|
6
6
|
|
|
7
|
+
// For improved performance, we include these styles that are likely to be present on the element.
|
|
8
|
+
export const necessaryStyleProperties = [
|
|
9
|
+
// Sizing
|
|
10
|
+
"width",
|
|
11
|
+
"height",
|
|
12
|
+
"min-width",
|
|
13
|
+
"min-height",
|
|
14
|
+
"max-width",
|
|
15
|
+
"max-height",
|
|
16
|
+
"box-sizing",
|
|
17
|
+
"aspect-ratio",
|
|
18
|
+
|
|
19
|
+
// Display & Layout
|
|
20
|
+
"display",
|
|
21
|
+
"position",
|
|
22
|
+
"top",
|
|
23
|
+
"left",
|
|
24
|
+
"bottom",
|
|
25
|
+
"right",
|
|
26
|
+
"z-index",
|
|
27
|
+
"float",
|
|
28
|
+
"clear",
|
|
29
|
+
|
|
30
|
+
// Flexbox
|
|
31
|
+
"flex",
|
|
32
|
+
"flex-direction",
|
|
33
|
+
"flex-wrap",
|
|
34
|
+
"flex-grow",
|
|
35
|
+
"flex-shrink",
|
|
36
|
+
"flex-basis",
|
|
37
|
+
"align-items",
|
|
38
|
+
"align-self",
|
|
39
|
+
"justify-content",
|
|
40
|
+
"gap",
|
|
41
|
+
"order",
|
|
42
|
+
|
|
43
|
+
// Grid
|
|
44
|
+
"grid-template-columns",
|
|
45
|
+
"grid-template-rows",
|
|
46
|
+
"grid-column",
|
|
47
|
+
"grid-row",
|
|
48
|
+
"row-gap",
|
|
49
|
+
"column-gap",
|
|
50
|
+
|
|
51
|
+
// Spacing
|
|
52
|
+
"margin",
|
|
53
|
+
"margin-top",
|
|
54
|
+
"margin-right",
|
|
55
|
+
"margin-bottom",
|
|
56
|
+
"margin-left",
|
|
57
|
+
"padding",
|
|
58
|
+
"padding-top",
|
|
59
|
+
"padding-right",
|
|
60
|
+
"padding-bottom",
|
|
61
|
+
"padding-left",
|
|
62
|
+
|
|
63
|
+
// Typography
|
|
64
|
+
"font",
|
|
65
|
+
"font-family",
|
|
66
|
+
"font-size",
|
|
67
|
+
"font-weight",
|
|
68
|
+
"font-style",
|
|
69
|
+
"line-height",
|
|
70
|
+
"letter-spacing",
|
|
71
|
+
"word-spacing",
|
|
72
|
+
"text-align",
|
|
73
|
+
"text-decoration",
|
|
74
|
+
"text-transform",
|
|
75
|
+
"text-indent",
|
|
76
|
+
"text-shadow",
|
|
77
|
+
"white-space",
|
|
78
|
+
"text-wrap",
|
|
79
|
+
"word-break",
|
|
80
|
+
"text-overflow",
|
|
81
|
+
"vertical-align",
|
|
82
|
+
"color",
|
|
83
|
+
|
|
84
|
+
// Background
|
|
85
|
+
"background",
|
|
86
|
+
"background-color",
|
|
87
|
+
"background-image",
|
|
88
|
+
"background-size",
|
|
89
|
+
"background-position",
|
|
90
|
+
"background-repeat",
|
|
91
|
+
"background-clip",
|
|
92
|
+
|
|
93
|
+
// Borders
|
|
94
|
+
"border",
|
|
95
|
+
"border-width",
|
|
96
|
+
"border-style",
|
|
97
|
+
"border-color",
|
|
98
|
+
"border-top",
|
|
99
|
+
"border-right",
|
|
100
|
+
"border-bottom",
|
|
101
|
+
"border-left",
|
|
102
|
+
"border-radius",
|
|
103
|
+
"outline",
|
|
104
|
+
|
|
105
|
+
// Effects
|
|
106
|
+
"box-shadow",
|
|
107
|
+
"text-shadow",
|
|
108
|
+
"opacity",
|
|
109
|
+
"filter",
|
|
110
|
+
"backdrop-filter",
|
|
111
|
+
"mix-blend-mode",
|
|
112
|
+
"transform",
|
|
113
|
+
"clip-path",
|
|
114
|
+
|
|
115
|
+
// Overflow & Visibility
|
|
116
|
+
// We don't include overflow properties because they can include scrollbars
|
|
117
|
+
// "overflow",
|
|
118
|
+
// "overflow-x",
|
|
119
|
+
// "overflow-y",
|
|
120
|
+
"visibility",
|
|
121
|
+
|
|
122
|
+
// SVG
|
|
123
|
+
"fill",
|
|
124
|
+
"stroke",
|
|
125
|
+
"stroke-width",
|
|
126
|
+
|
|
127
|
+
// Images & Objects
|
|
128
|
+
"object-fit",
|
|
129
|
+
"object-position",
|
|
130
|
+
|
|
131
|
+
// Lists
|
|
132
|
+
"list-style",
|
|
133
|
+
"list-style-type",
|
|
134
|
+
|
|
135
|
+
// Tables
|
|
136
|
+
"border-collapse",
|
|
137
|
+
"border-spacing",
|
|
138
|
+
|
|
139
|
+
// Misc
|
|
140
|
+
"content",
|
|
141
|
+
"cursor",
|
|
142
|
+
];
|
|
143
|
+
|
|
7
144
|
/**
|
|
8
145
|
* Default options for html-to-image conversions.
|
|
9
146
|
* These handle common edge cases like filtering out toolbars and logging errors.
|
|
@@ -39,9 +176,11 @@ export const defaultHtmlToImageOptions: HtmlToImageOptions = {
|
|
|
39
176
|
export async function toPng(
|
|
40
177
|
element: HTMLElement,
|
|
41
178
|
options?: HtmlToImageOptions,
|
|
179
|
+
snappy?: boolean,
|
|
42
180
|
): Promise<string> {
|
|
43
181
|
return htmlToImageToPng(element, {
|
|
44
182
|
...defaultHtmlToImageOptions,
|
|
183
|
+
includeStyleProperties: snappy ? necessaryStyleProperties : undefined,
|
|
45
184
|
...options,
|
|
46
185
|
});
|
|
47
186
|
}
|