mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-14 00:33:36 -07:00
bitview: fix screenshot in ios
This commit is contained in:
@@ -1,12 +1,37 @@
|
||||
import { domToBlob } from "./4.6.6/dist/index.mjs";
|
||||
|
||||
/**
|
||||
* @param {Element} element
|
||||
* @param {Object} args
|
||||
* @param {Element} args.element
|
||||
* @param {string} args.name
|
||||
* @param {string} args.title
|
||||
* @param {Env} args.env
|
||||
*/
|
||||
export async function screenshot(element) {
|
||||
export async function screenshot({ element, name, title, env }) {
|
||||
const blob = await domToBlob(element, {
|
||||
scale: 2,
|
||||
});
|
||||
|
||||
if (env.ios) {
|
||||
const file = new File(
|
||||
[blob],
|
||||
`bitview-${name}-${new Date().toJSON().split(".")[0]}.png`,
|
||||
{
|
||||
type: "image/png",
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
await navigator.share({
|
||||
files: [file],
|
||||
title: `Bitview screenshot: ${title}`,
|
||||
});
|
||||
return;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, "_blank");
|
||||
setTimeout(() => URL.revokeObjectURL(url), 100);
|
||||
|
||||
@@ -19,6 +19,7 @@ const CANDLE = "candle";
|
||||
* @param {Utilities} args.utils
|
||||
* @param {WebSockets} args.webSockets
|
||||
* @param {Elements} args.elements
|
||||
* @param {Env} args.env
|
||||
* @param {VecsResources} args.vecsResources
|
||||
* @param {VecIdToIndexes} args.vecIdToIndexes
|
||||
* @param {Packages} args.packages
|
||||
@@ -30,6 +31,7 @@ export function init({
|
||||
option,
|
||||
signals,
|
||||
utils,
|
||||
env,
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
@@ -97,33 +99,41 @@ export function init({
|
||||
},
|
||||
});
|
||||
|
||||
const chartBottomRightCanvas = Array.from(
|
||||
chart.inner.chartElement().getElementsByTagName("tr"),
|
||||
).at(-1)?.lastChild?.firstChild?.firstChild;
|
||||
if (chartBottomRightCanvas) {
|
||||
const charts = elements.charts;
|
||||
const domain = window.document.createElement("p");
|
||||
domain.innerText = `${window.location.host}`;
|
||||
domain.id = "domain";
|
||||
const screenshotButton = window.document.createElement("button");
|
||||
screenshotButton.id = "screenshot";
|
||||
const camera = "[ ◉¯]";
|
||||
screenshotButton.innerHTML = camera;
|
||||
screenshotButton.title = "Screenshot";
|
||||
chartBottomRightCanvas.replaceWith(screenshotButton);
|
||||
screenshotButton.addEventListener("click", () => {
|
||||
packages.modernScreenshot().then(async ({ screenshot }) => {
|
||||
charts.dataset.screenshot = "true";
|
||||
charts.append(domain);
|
||||
seriesTypeField.hidden = true;
|
||||
try {
|
||||
await screenshot(charts);
|
||||
} catch {}
|
||||
charts.removeChild(domain);
|
||||
seriesTypeField.hidden = false;
|
||||
charts.dataset.screenshot = "false";
|
||||
console.log(env.ios, "canShare" in navigator);
|
||||
if (!(env.ios && !("canShare" in navigator))) {
|
||||
const chartBottomRightCanvas = Array.from(
|
||||
chart.inner.chartElement().getElementsByTagName("tr"),
|
||||
).at(-1)?.lastChild?.firstChild?.firstChild;
|
||||
if (chartBottomRightCanvas) {
|
||||
const charts = elements.charts;
|
||||
const domain = window.document.createElement("p");
|
||||
domain.innerText = `${window.location.host}`;
|
||||
domain.id = "domain";
|
||||
const screenshotButton = window.document.createElement("button");
|
||||
screenshotButton.id = "screenshot";
|
||||
const camera = "[ ◉¯]";
|
||||
screenshotButton.innerHTML = camera;
|
||||
screenshotButton.title = "Screenshot";
|
||||
chartBottomRightCanvas.replaceWith(screenshotButton);
|
||||
screenshotButton.addEventListener("click", () => {
|
||||
packages.modernScreenshot().then(async ({ screenshot }) => {
|
||||
charts.dataset.screenshot = "true";
|
||||
charts.append(domain);
|
||||
seriesTypeField.hidden = true;
|
||||
try {
|
||||
await screenshot({
|
||||
element: charts,
|
||||
env,
|
||||
name: option().path.join("-"),
|
||||
title: option().title,
|
||||
});
|
||||
} catch {}
|
||||
charts.removeChild(domain);
|
||||
seriesTypeField.hidden = false;
|
||||
charts.dataset.screenshot = "false";
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
chart.inner.timeScale().subscribeVisibleLogicalRangeChange(
|
||||
|
||||
@@ -2303,6 +2303,7 @@ function main() {
|
||||
option: /** @type {Accessor<ChartOption>} */ (
|
||||
chartOption
|
||||
),
|
||||
env,
|
||||
signals,
|
||||
utils,
|
||||
webSockets,
|
||||
|
||||
Reference in New Issue
Block a user