@marimo-team/islands 0.19.7-dev1 → 0.19.7-dev15

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.
@@ -59,34 +59,51 @@ function releaseBodyPrinting() {
59
59
  }
60
60
  }
61
61
 
62
- /*
62
+ /**
63
63
  * Prepare a cell element for screenshot capture.
64
- * Returns a cleanup function that should be called when the screenshot is complete.
64
+ *
65
+ * @param element - The cell output element to prepare
66
+ * @param enablePrintMode - When true, adds a 'printing' class to the body.
67
+ * This can cause layout shifts that cause the page to scroll.
68
+ * @returns A cleanup function to restore the element's original state
65
69
  */
66
- function prepareCellElementForScreenshot(element: HTMLElement) {
70
+ function prepareCellElementForScreenshot(
71
+ element: HTMLElement,
72
+ enablePrintMode: boolean,
73
+ ) {
67
74
  element.classList.add("printing-output");
68
- acquireBodyPrinting();
75
+ if (enablePrintMode) {
76
+ acquireBodyPrinting();
77
+ }
69
78
  const originalOverflow = element.style.overflow;
70
79
  element.style.overflow = "auto";
71
80
 
72
81
  return () => {
73
82
  element.classList.remove("printing-output");
74
- releaseBodyPrinting();
83
+ if (enablePrintMode) {
84
+ releaseBodyPrinting();
85
+ }
75
86
  element.style.overflow = originalOverflow;
76
87
  };
77
88
  }
78
89
 
79
90
  /**
80
91
  * Capture a cell output as a PNG data URL.
92
+ *
93
+ * @param cellId - The ID of the cell to capture
94
+ * @param enablePrintMode - When true, enables print mode which adds a 'printing' class to the body.
95
+ * This can cause layout shifts that cause the page to scroll.
96
+ * @returns The PNG as a data URL, or undefined if the cell element wasn't found
81
97
  */
82
98
  export async function getImageDataUrlForCell(
83
99
  cellId: CellId,
100
+ enablePrintMode = true,
84
101
  ): Promise<string | undefined> {
85
102
  const element = findElementForCell(cellId);
86
103
  if (!element) {
87
104
  return;
88
105
  }
89
- const cleanup = prepareCellElementForScreenshot(element);
106
+ const cleanup = prepareCellElementForScreenshot(element, enablePrintMode);
90
107
 
91
108
  try {
92
109
  return await toPng(element);
@@ -110,7 +127,7 @@ export async function downloadCellOutputAsImage(
110
127
  await downloadHTMLAsImage({
111
128
  element,
112
129
  filename,
113
- prepare: prepareCellElementForScreenshot,
130
+ prepare: () => prepareCellElementForScreenshot(element, true),
114
131
  });
115
132
  }
116
133
 
@@ -127,7 +144,6 @@ export async function downloadHTMLAsImage(opts: {
127
144
 
128
145
  let cleanup: (() => void) | undefined;
129
146
  if (prepare) {
130
- // Let the prepare function handle adding classes (e.g., body.printing)
131
147
  cleanup = prepare(element);
132
148
  } else {
133
149
  // When no prepare function is provided (e.g., downloading full notebook),