Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@
"default": "container",
"enum": [
"container",
"snippet"
"snippet",
"clipboard"
],
"enumDescriptions": [
"Shoot with the container.",
"Shoot with the snippet alone. If you want transparent padding, use `container` with `\"polacode.transparentBackground\": true`"
"Shoot with the snippet alone. If you want transparent padding, use `container` with `\"polacode.transparentBackground\": true`",
"Shoot to clipboard"
]
}
}
Expand All @@ -77,4 +79,4 @@
"@types/node": "^11.12.0",
"@types/vscode": "^1.32.0"
}
}
}
43 changes: 38 additions & 5 deletions webview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@
vscode.setState({ innerHTML })
})

obturateur.addEventListener('click', () => {
if (target === 'container') {
shootAll()
obturateur.addEventListener("click", () => {
if (target === "container") {
shootAll();
} else if (target === "clipboard") {
shootClipboard();
} else {
shootSnippet()
shootSnippet();
}
})
});

function shootAll() {
const width = snippetContainerNode.offsetWidth * 2
Expand Down Expand Up @@ -188,6 +190,37 @@
})
}

function shootClipboard() {
const width = snippetContainerNode.offsetWidth * 2;
const height = snippetContainerNode.offsetHeight * 2;
const config = {
width,
height,
style: {
transform: "scale(2)",
"transform-origin": "center",
background: getRgba(backgroundColor, transparentBackground),
},
};

// Hide resizer before capture
snippetNode.style.resize = "none";
snippetContainerNode.style.resize = "none";

domtoimage.toBlob(snippetContainerNode, config).then((blob) => {
snippetNode.style.resize = "";
snippetContainerNode.style.resize = "";

var data = [new ClipboardItem({ "image/png": blob })];

navigator.clipboard.write(data).then(
() => {
shoot(data);
}
);
});
}

let isInAnimation = false

obturateur.addEventListener('mouseover', () => {
Expand Down