Skip to content

Commit a3fb5a7

Browse files
committed
[frontend] switch from html2canvas to html-to-image
1 parent 712f5a1 commit a3fb5a7

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@mercuryworkshop/epoxy-transport": "^2.1.27",
1919
"@mercuryworkshop/scramjet": "workspace:scramjet",
2020
"dreamland": "workspace:dreamland",
21+
"html-to-image": "^1.11.13",
2122
"html2canvas": "^1.4.1",
2223
"monaco-editor": "^0.52.2",
2324
"vite-plugin-static-copy": "^3.1.0"

frontend/src/Tab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export class Tab extends StatefulClass {
9191
};
9292
}
9393
deserialize(de: SerializedTab) {
94-
if (de.id >= id) id = de.id + 1;
95-
this.id = de.id;
94+
// if (de.id >= id) id = de.id + 1;
95+
// this.id = de.id;
9696
this.title = de.title;
9797
this.history.deserialize(de.history);
9898
console.log(this.history.states[this.history.index].url);

frontend/src/browser.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ export class Browser extends StatefulClass {
6969
console.log(tab);
7070
tab.deserialize(detab);
7171
}
72-
this.activetab = this.tabs.find((t) => t.id == de.activetab)!;
72+
this.activetab = this.tabs[0]; // TODO
73+
// this.activetab = this.tabs.find((t) => t.id == de.activetab)!;
7374
console.log(this.activetab, this.activetab.url);
7475
}
7576

frontend/src/components/Shell.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { css, type Component } from "dreamland/core";
22
import { browser } from "../main";
33
import { forceScreenshot, popTab, pushTab } from "../browser";
44
import type { Tab } from "../Tab";
5-
import html2canvas from "html2canvas";
5+
import { toBlob } from "html-to-image";
66

77
export const Shell: Component<{
88
tabs: Tab[];
@@ -20,6 +20,7 @@ export const Shell: Component<{
2020
<div
2121
class="container"
2222
data-tab={tab.id}
23+
id={"tab" + tab.id}
2324
class:active={use(this.activetab).map((t) => t === tab)}
2425
class:showframe={use(tab.internalpage).map((t) => !t)}
2526
>
@@ -57,6 +58,8 @@ export const Shell: Component<{
5758
</div>
5859
</div>
5960
);
61+
62+
setInterval(() => forceScreenshot(tab), 1000);
6063
});
6164
popTab.listen((tab) => {
6265
const container = cx.root.querySelector(`[data-tab="${tab.id}"]`);
@@ -69,10 +72,7 @@ export const Shell: Component<{
6972
) as HTMLElement;
7073
if (!container) throw new Error(`No container found for tab ${tab.id}`);
7174

72-
const canvas = await html2canvas(
73-
container.children[0].contentDocument.body
74-
);
75-
tab.screenshot = canvas.toDataURL();
75+
tab.screenshot = URL.createObjectURL(await toBlob(container));
7676
});
7777

7878
return <div></div>;

frontend/src/components/TabStrip.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export const DragTab: Component<{
7070
>
7171
<div class="tooltip">
7272
<span>{use(this.tab.title)}</span>
73-
<img src={use(this.tab.screenshot)} />
73+
<img src={use(this.tab.screenshot)} class="img" />
74+
{/* <div
75+
style={use`background: -moz-element(#tab${this.tab.id})`}
76+
class="img"
77+
></div> */}
7478
</div>
7579
<div
7680
class="dragroot"
@@ -117,7 +121,8 @@ DragTab.style = css`
117121
top: 5em;
118122
left: 0;
119123
z-index: 1000;
120-
background: var(--aboutbrowser-tooltip-bg);
124+
background: white;
125+
border: 5px solid red;
121126
width: 20em;
122127
/* height: 10em; */
123128
flex-direction: column;
@@ -127,8 +132,9 @@ DragTab.style = css`
127132
:scope:hover .tooltip {
128133
display: flex;
129134
}
130-
.tooltip img {
135+
.tooltip .img {
131136
width: 100%;
137+
/* height: 5em; */
132138
}
133139
134140
.main {

0 commit comments

Comments
 (0)