@openshift-migration-advisor/shared-components 0.24.0 → 0.25.0-1701f64050d7
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/README.md +31 -0
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.js +2 -2
- package/dist/report/ChartDownloadButton.d.ts +11 -0
- package/dist/report/ChartDownloadButton.d.ts.map +1 -0
- package/dist/report/ChartDownloadButton.js +24 -0
- package/dist/report/ChartExportProvider.d.ts +23 -0
- package/dist/report/ChartExportProvider.d.ts.map +1 -0
- package/dist/report/ChartExportProvider.js +222 -0
- package/dist/report/ChartExportSurface.d.ts +12 -0
- package/dist/report/ChartExportSurface.d.ts.map +1 -0
- package/dist/report/ChartExportSurface.js +32 -0
- package/dist/report/ErrorTable.d.ts +18 -0
- package/dist/report/ErrorTable.d.ts.map +1 -0
- package/dist/report/ErrorTable.js +20 -0
- package/dist/report/FeatureStatusBadge.d.ts +7 -0
- package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
- package/dist/report/FeatureStatusBadge.js +13 -0
- package/dist/report/HostPowerStates.d.ts +8 -0
- package/dist/report/HostPowerStates.d.ts.map +1 -0
- package/dist/report/HostPowerStates.js +11 -0
- package/dist/report/HostsOverview.d.ts +13 -0
- package/dist/report/HostsOverview.d.ts.map +1 -0
- package/dist/report/HostsOverview.js +84 -0
- package/dist/report/InfrastructureSummary.d.ts +7 -0
- package/dist/report/InfrastructureSummary.d.ts.map +1 -0
- package/dist/report/InfrastructureSummary.js +9 -0
- package/dist/report/NetworkOverview.d.ts +31 -0
- package/dist/report/NetworkOverview.d.ts.map +1 -0
- package/dist/report/NetworkOverview.js +201 -0
- package/dist/report/OSDistribution.d.ts +0 -2
- package/dist/report/OSDistribution.d.ts.map +1 -1
- package/dist/report/OSDistribution.js +10 -15
- package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
- package/dist/report/OsSupportTiersHelpPopover.js +2 -31
- package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
- package/dist/report/OsUpgradeNotice.js +1 -5
- package/dist/report/OsUpgradeRecommendationPopover.d.ts +0 -1
- package/dist/report/OsUpgradeRecommendationPopover.d.ts.map +1 -1
- package/dist/report/OsUpgradeRecommendationPopover.js +4 -3
- package/dist/report/PowerStateCard.d.ts +16 -0
- package/dist/report/PowerStateCard.d.ts.map +1 -0
- package/dist/report/PowerStateCard.js +9 -0
- package/dist/report/ReportExportMenu.d.ts +19 -0
- package/dist/report/ReportExportMenu.d.ts.map +1 -0
- package/dist/report/ReportExportMenu.js +31 -0
- package/dist/report/ReportTable.d.ts +14 -0
- package/dist/report/ReportTable.d.ts.map +1 -0
- package/dist/report/ReportTable.js +23 -0
- package/dist/report/SupportTierBadge.d.ts +0 -1
- package/dist/report/SupportTierBadge.d.ts.map +1 -1
- package/dist/report/SupportTierBadge.js +1 -19
- package/dist/report/VCenterClusterDetails.d.ts +9 -0
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
- package/dist/report/VCenterClusterDetails.js +31 -0
- package/dist/report/VmPowerStates.d.ts +8 -0
- package/dist/report/VmPowerStates.d.ts.map +1 -0
- package/dist/report/VmPowerStates.js +11 -0
- package/dist/report/WarningsTable.d.ts +9 -0
- package/dist/report/WarningsTable.d.ts.map +1 -0
- package/dist/report/WarningsTable.js +20 -0
- package/dist/report/captureChartElement.d.ts +8 -0
- package/dist/report/captureChartElement.d.ts.map +1 -0
- package/dist/report/captureChartElement.js +284 -0
- package/dist/report/chartExport.d.ts +73 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +162 -0
- package/dist/report/chartExportContext.d.ts +32 -0
- package/dist/report/chartExportContext.d.ts.map +1 -0
- package/dist/report/chartExportContext.js +36 -0
- package/dist/report/chartExportFilenames.d.ts +4 -0
- package/dist/report/chartExportFilenames.d.ts.map +1 -0
- package/dist/report/chartExportFilenames.js +16 -0
- package/dist/report/constants.d.ts +4 -0
- package/dist/report/constants.d.ts.map +1 -1
- package/dist/report/constants.js +4 -0
- package/dist/report/dashboardStyles.d.ts +0 -4
- package/dist/report/dashboardStyles.d.ts.map +1 -1
- package/dist/report/dashboardStyles.js +0 -19
- package/dist/report/htmlExport.d.ts +9 -0
- package/dist/report/htmlExport.d.ts.map +1 -0
- package/dist/report/htmlExport.js +65 -0
- package/dist/report/index.d.ts +28 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +26 -0
- package/dist/report/infrastructureSummaryModel.d.ts +82 -0
- package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
- package/dist/report/infrastructureSummaryModel.js +139 -0
- package/dist/report/pdfExport.d.ts +3 -0
- package/dist/report/pdfExport.d.ts.map +1 -0
- package/dist/report/pdfExport.js +131 -0
- package/dist/report/pdfPage.d.ts +15 -0
- package/dist/report/pdfPage.d.ts.map +1 -0
- package/dist/report/pdfPage.js +44 -0
- package/dist/report/powerStates.d.ts +11 -0
- package/dist/report/powerStates.d.ts.map +1 -0
- package/dist/report/powerStates.js +113 -0
- package/dist/report/reportExportOptions.d.ts +17 -0
- package/dist/report/reportExportOptions.d.ts.map +1 -0
- package/dist/report/reportExportOptions.js +31 -0
- package/dist/report/zipChartPngs.d.ts +3 -0
- package/dist/report/zipChartPngs.d.ts.map +1 -0
- package/dist/report/zipChartPngs.js +8 -0
- package/package.json +7 -2
- package/src/charts/index.ts +1 -0
- package/src/forms/RadioButtonFormGroup.tsx +10 -3
- package/src/report/ChartDownloadButton.tsx +59 -0
- package/src/report/ChartExportProvider.tsx +392 -0
- package/src/report/ChartExportSurface.tsx +60 -0
- package/src/report/ErrorTable.tsx +85 -0
- package/src/report/FeatureStatusBadge.tsx +30 -0
- package/src/report/HostPowerStates.tsx +38 -0
- package/src/report/HostsOverview.tsx +185 -0
- package/src/report/InfrastructureSummary.tsx +73 -0
- package/src/report/NetworkOverview.tsx +405 -0
- package/src/report/OSDistribution.tsx +96 -99
- package/src/report/OsSupportTiersHelpPopover.tsx +32 -62
- package/src/report/OsUpgradeNotice.tsx +1 -7
- package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
- package/src/report/PowerStateCard.tsx +86 -0
- package/src/report/ReportExportMenu.tsx +119 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/SupportTierBadge.tsx +12 -38
- package/src/report/VCenterClusterDetails.tsx +233 -0
- package/src/report/VmPowerStates.tsx +38 -0
- package/src/report/WarningsTable.tsx +75 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +542 -0
- package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +126 -0
- package/src/report/__tests__/NetworkOverview.test.tsx +269 -0
- package/src/report/__tests__/OSDistribution.test.tsx +10 -11
- package/src/report/__tests__/captureChartElement.test.ts +132 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +282 -0
- package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
- package/src/report/__tests__/powerStates.test.ts +70 -0
- package/src/report/captureChartElement.ts +368 -0
- package/src/report/chartExport.ts +255 -0
- package/src/report/chartExportContext.tsx +92 -0
- package/src/report/chartExportFilenames.ts +21 -0
- package/src/report/constants.ts +4 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +154 -0
- package/src/report/infrastructureSummaryModel.ts +281 -0
- package/src/report/pdfExport.ts +233 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/powerStates.ts +169 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { css } from "@emotion/css";
|
|
3
|
+
import { Card, CardBody, CardTitle, Content, DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, Flex, FlexItem, Grid, GridItem, Label, LabelGroup, } from "@patternfly/react-core";
|
|
4
|
+
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
|
|
5
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
6
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
7
|
+
import { chartExportScrollProps } from "./chartExport.js";
|
|
8
|
+
import { FeatureStatusBadge } from "./FeatureStatusBadge.js";
|
|
9
|
+
const clusterDetailsTableScrollStyle = css `
|
|
10
|
+
max-height: 320px;
|
|
11
|
+
overflow: auto;
|
|
12
|
+
`;
|
|
13
|
+
const FeatureList = ({ items }) => (_jsx(DescriptionList, { isHorizontal: true, isCompact: true, children: items.map((item) => (_jsxs(DescriptionListGroup, { children: [_jsx(DescriptionListTerm, { children: item.label }), _jsx(DescriptionListDescription, { children: _jsx(FeatureStatusBadge, { status: item.status }) })] }, item.label))) }));
|
|
14
|
+
const AggregateClusterTable = ({ rows }) => (_jsxs(Table, { variant: "compact", borders: false, isStickyHeader: true, "data-testid": "vcenter-cluster-details-table", children: [_jsx(Thead, { children: _jsxs(Tr, { children: [_jsx(Th, { children: "Cluster name" }), _jsx(Th, { children: "Hosts" }), _jsx(Th, { children: "VMs" }), _jsx(Th, { children: "vMotion" }), _jsx(Th, { children: "DRS" }), _jsx(Th, { children: "vSAN" })] }) }), _jsx(Tbody, { children: rows.map((row) => (_jsxs(Tr, { children: [_jsx(Td, { dataLabel: "Cluster name", children: row.name }), _jsx(Td, { dataLabel: "Hosts", children: row.hosts }), _jsx(Td, { dataLabel: "VMs", children: row.vms }), _jsx(Td, { dataLabel: "vMotion", children: _jsx(FeatureStatusBadge, { status: row.vmotion }) }), _jsx(Td, { dataLabel: "DRS", children: _jsx(FeatureStatusBadge, { status: row.drs }) }), _jsx(Td, { dataLabel: "vSAN", children: _jsx(FeatureStatusBadge, { status: row.vsan }) })] }, row.id))) })] }));
|
|
15
|
+
const AggregateCluster = ({ rows }) => {
|
|
16
|
+
if (rows.length === 0) {
|
|
17
|
+
return _jsx(Content, { component: "p", children: "No vSphere clusters detected" });
|
|
18
|
+
}
|
|
19
|
+
return (_jsx("div", { className: clusterDetailsTableScrollStyle, "data-scroll-constrained": "true", ...chartExportScrollProps, children: _jsx(AggregateClusterTable, { rows: rows }) }));
|
|
20
|
+
};
|
|
21
|
+
const DetailedClusterView = ({ details, }) => (_jsxs(Grid, { hasGutter: true, children: [_jsx(GridItem, { children: _jsxs(DescriptionList, { isAutoFit: true, displaySize: "lg", children: [_jsxs(DescriptionListGroup, { children: [_jsx(DescriptionListTerm, { children: "Hosts" }), _jsx(DescriptionListDescription, { children: details.hosts })] }), _jsxs(DescriptionListGroup, { children: [_jsx(DescriptionListTerm, { children: "VMs" }), _jsx(DescriptionListDescription, { children: details.vms })] }), _jsxs(DescriptionListGroup, { children: [_jsx(DescriptionListTerm, { children: "Networks detected" }), _jsx(DescriptionListDescription, { children: details.networksDetected })] })] }) }), _jsx(GridItem, { md: 4, children: _jsxs(Card, { isFullHeight: true, children: [_jsx(CardTitle, { children: "Core infrastructure" }), _jsx(CardBody, { children: _jsx(FeatureList, { items: [
|
|
22
|
+
{ label: "vMotion", status: details.vmotion },
|
|
23
|
+
{ label: "DRS", status: details.drs },
|
|
24
|
+
{ label: "HA", status: details.ha },
|
|
25
|
+
] }) })] }) }), _jsx(GridItem, { md: 4, children: _jsxs(Card, { isFullHeight: true, children: [_jsx(CardTitle, { children: "vSAN capabilities" }), _jsx(CardBody, { children: _jsx(FeatureList, { items: [{ label: "vSAN", status: details.vsan }] }) })] }) }), _jsx(GridItem, { md: 4, children: _jsxs(Card, { isFullHeight: true, children: [_jsx(CardTitle, { children: "Network topology" }), _jsx(CardBody, { children: details.networks.length === 0 ? (_jsx(Content, { component: "p", children: "No networks detected" })) : (_jsxs(_Fragment, { children: [_jsxs(Content, { component: "p", children: [details.networksDetected, " ", details.networksDetected === 1
|
|
26
|
+
? "network detected"
|
|
27
|
+
: "networks detected"] }), _jsx(LabelGroup, { isCompact: true, numLabels: details.networks.length, "aria-label": "Detected networks", children: details.networks.map((network, index) => (_jsx(Label, { color: "blue", isCompact: true, children: network.displayName }, `${network.name}-${network.vlanId ?? index}`))) })] })) })] }) })] }));
|
|
28
|
+
const CLUSTER_DETAILS_CHART_ID = "vcenter-cluster-details";
|
|
29
|
+
const CLUSTER_DETAILS_TITLE = "vCenter cluster details";
|
|
30
|
+
export const VCenterClusterDetails = ({ isAggregateView, rows, details, }) => (_jsx(ChartExportSurface, { id: CLUSTER_DETAILS_CHART_ID, title: CLUSTER_DETAILS_TITLE, children: _jsxs(Card, { isFullHeight: true, children: [_jsx(CardTitle, { children: _jsxs(Flex, { justifyContent: { default: "justifyContentSpaceBetween" }, alignItems: { default: "alignItemsCenter" }, children: [_jsx(FlexItem, { children: CLUSTER_DETAILS_TITLE }), _jsx(ChartHeaderActions, { chartId: CLUSTER_DETAILS_CHART_ID, title: CLUSTER_DETAILS_TITLE })] }) }), _jsx(CardBody, { children: isAggregateView || !details ? (_jsx(AggregateCluster, { rows: rows })) : (_jsx(DetailedClusterView, { details: details })) })] }) }));
|
|
31
|
+
VCenterClusterDetails.displayName = "VCenterClusterDetails";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
import type { MigrationDonutChartLegendVariant } from "../charts/MigrationDonutChart.js";
|
|
3
|
+
export interface VmPowerStatesProps {
|
|
4
|
+
powerStates?: Record<string, number>;
|
|
5
|
+
legendVariant?: MigrationDonutChartLegendVariant;
|
|
6
|
+
}
|
|
7
|
+
export declare const VmPowerStates: FC<VmPowerStatesProps>;
|
|
8
|
+
//# sourceMappingURL=VmPowerStates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VmPowerStates.d.ts","sourceRoot":"","sources":["../../src/report/VmPowerStates.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AAKzF,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,aAAa,CAAC,EAAE,gCAAgC,CAAC;CAClD;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAsBhD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { VirtualMachineIcon } from "@patternfly/react-icons";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
5
|
+
import { PowerStateCard } from "./PowerStateCard.js";
|
|
6
|
+
import { buildVmPowerStateChart } from "./powerStates.js";
|
|
7
|
+
export const VmPowerStates = ({ powerStates, legendVariant, }) => {
|
|
8
|
+
const chart = useMemo(() => buildVmPowerStateChart(powerStates), [powerStates]);
|
|
9
|
+
return (_jsx(PowerStateCard, { id: "vm-power-states", title: "VM power states", icon: _jsx(VirtualMachineIcon, {}), emptyTitle: REPORT_CARD_EMPTY_STATE_TITLES.vmPowerStates, slices: chart.slices, legend: chart.legend, total: chart.total, subTitle: "VMs", legendVariant: legendVariant }));
|
|
10
|
+
};
|
|
11
|
+
VmPowerStates.displayName = "VmPowerStates";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { MigrationIssueLike } from "./ErrorTable.js";
|
|
3
|
+
export interface WarningsTableProps {
|
|
4
|
+
warnings: MigrationIssueLike[];
|
|
5
|
+
/** Optional drill-down callback invoked with an issue's `label`. */
|
|
6
|
+
onConcernClick?: (concernLabel: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const WarningsTable: React.FC<WarningsTableProps>;
|
|
9
|
+
//# sourceMappingURL=WarningsTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WarningsTable.d.ts","sourceRoot":"","sources":["../../src/report/WarningsTable.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,oEAAoE;IACpE,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgDtD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Card, CardBody, CardTitle, Flex, FlexItem, Icon, } from "@patternfly/react-core";
|
|
3
|
+
import { ExclamationTriangleIcon } from "@patternfly/react-icons";
|
|
4
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
5
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
6
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
7
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
8
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
9
|
+
import { ReportTable } from "./ReportTable.js";
|
|
10
|
+
export const WarningsTable = ({ warnings, onConcernClick, }) => {
|
|
11
|
+
const handleRowClick = (issue) => {
|
|
12
|
+
if (issue.label && onConcernClick) {
|
|
13
|
+
onConcernClick(issue.label);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const chartId = "warnings-table";
|
|
17
|
+
const chartTitle = "Warnings";
|
|
18
|
+
return (_jsx(ChartExportSurface, { id: chartId, title: chartTitle, children: _jsxs(Card, { className: dashboardStyles.card, children: [_jsx(CardTitle, { children: _jsxs(Flex, { justifyContent: { default: "justifyContentSpaceBetween" }, alignItems: { default: "alignItemsCenter" }, children: [_jsxs(FlexItem, { children: [_jsx(Icon, { status: "warning", children: _jsx(ExclamationTriangleIcon, {}) }), " ", "Warnings"] }), _jsx(ChartHeaderActions, { chartId: chartId, title: chartTitle })] }) }), _jsx(CardBody, { className: dashboardStyles.cardBodyScrollable, children: warnings.length === 0 ? (_jsx(CardEmptyState, { title: REPORT_CARD_EMPTY_STATE_TITLES.warnings })) : (_jsx("div", { children: _jsx(ReportTable, { data: warnings, columns: ["Description", "Total VMs"], fields: ["assessment", "count"], onRowClick: onConcernClick ? handleRowClick : undefined, clickableFields: onConcernClick ? ["assessment"] : [] }) })) })] }) }));
|
|
19
|
+
};
|
|
20
|
+
WarningsTable.displayName = "WarningsTable";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tab panels stay mounted with `hidden` / `display:none` when another tab is
|
|
3
|
+
* active. html2canvas then measures a 0×0 box. Reveal those ancestors off-screen
|
|
4
|
+
* for the duration of the capture, then restore.
|
|
5
|
+
*/
|
|
6
|
+
export declare function revealHiddenChartAncestors(element: HTMLElement): () => void;
|
|
7
|
+
export declare function captureChartElement(element: HTMLElement): Promise<HTMLCanvasElement>;
|
|
8
|
+
//# sourceMappingURL=captureChartElement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureChartElement.d.ts","sourceRoot":"","sources":["../../src/report/captureChartElement.ts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,IAAI,CAqD3E;AAiPD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAkC5B"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import html2canvas from "html2canvas-pro";
|
|
2
|
+
import { CHART_EXPORT_CAPTURING_ATTR, CHART_EXPORT_SCROLL_ATTR, shouldIgnoreChartExportElement, } from "./chartExport.js";
|
|
3
|
+
/** CSS-pixel scale; 2x made zip-all of ~15 live cards too slow. */
|
|
4
|
+
const CHART_CAPTURE_SCALE = 1;
|
|
5
|
+
const HIDDEN_LAYOUT_STYLE_KEYS = [
|
|
6
|
+
"display",
|
|
7
|
+
"position",
|
|
8
|
+
"left",
|
|
9
|
+
"top",
|
|
10
|
+
"width",
|
|
11
|
+
"maxHeight",
|
|
12
|
+
"overflow",
|
|
13
|
+
"zIndex",
|
|
14
|
+
];
|
|
15
|
+
function isDisplayNone(node) {
|
|
16
|
+
return window.getComputedStyle(node).display === "none";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Tab panels stay mounted with `hidden` / `display:none` when another tab is
|
|
20
|
+
* active. html2canvas then measures a 0×0 box. Reveal those ancestors off-screen
|
|
21
|
+
* for the duration of the capture, then restore.
|
|
22
|
+
*/
|
|
23
|
+
export function revealHiddenChartAncestors(element) {
|
|
24
|
+
const saved = [];
|
|
25
|
+
let node = element;
|
|
26
|
+
while (node && node !== document.documentElement) {
|
|
27
|
+
if (node.hidden || isDisplayNone(node)) {
|
|
28
|
+
saved.push({
|
|
29
|
+
node,
|
|
30
|
+
hidden: node.hidden,
|
|
31
|
+
styles: {
|
|
32
|
+
display: node.style.display,
|
|
33
|
+
position: node.style.position,
|
|
34
|
+
left: node.style.left,
|
|
35
|
+
top: node.style.top,
|
|
36
|
+
width: node.style.width,
|
|
37
|
+
maxHeight: node.style.maxHeight,
|
|
38
|
+
overflow: node.style.overflow,
|
|
39
|
+
zIndex: node.style.zIndex,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
node = node.parentElement;
|
|
44
|
+
}
|
|
45
|
+
if (saved.length === 0) {
|
|
46
|
+
return () => undefined;
|
|
47
|
+
}
|
|
48
|
+
const outermost = saved[saved.length - 1].node;
|
|
49
|
+
const parentWidth = outermost.parentElement?.clientWidth ?? 0;
|
|
50
|
+
const layoutWidth = parentWidth || document.documentElement.clientWidth || 1024;
|
|
51
|
+
for (const entry of saved) {
|
|
52
|
+
entry.node.hidden = false;
|
|
53
|
+
entry.node.style.display = "block";
|
|
54
|
+
entry.node.style.position = "fixed";
|
|
55
|
+
entry.node.style.left = "-10000px";
|
|
56
|
+
entry.node.style.top = "0";
|
|
57
|
+
entry.node.style.width = `${layoutWidth}px`;
|
|
58
|
+
entry.node.style.maxHeight = "none";
|
|
59
|
+
entry.node.style.overflow = "visible";
|
|
60
|
+
entry.node.style.zIndex = "-1";
|
|
61
|
+
}
|
|
62
|
+
return () => {
|
|
63
|
+
for (const entry of saved) {
|
|
64
|
+
entry.node.hidden = entry.hidden;
|
|
65
|
+
for (const key of HIDDEN_LAYOUT_STYLE_KEYS) {
|
|
66
|
+
entry.node.style[key] = entry.styles[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const PADDED_CAPTURE_SELECTOR = ".pf-v6-c-card__title, .pf-v6-c-card__header, .pf-v6-c-card__body";
|
|
72
|
+
const CARD_CAPTURE_SELECTOR = ".pf-v6-c-card";
|
|
73
|
+
const TRANSPARENT_FILLS = new Set(["", "transparent", "rgba(0, 0, 0, 0)"]);
|
|
74
|
+
function queryCards(root) {
|
|
75
|
+
const cards = Array.from(root.querySelectorAll(CARD_CAPTURE_SELECTOR));
|
|
76
|
+
if (root.matches(CARD_CAPTURE_SELECTOR)) {
|
|
77
|
+
cards.unshift(root);
|
|
78
|
+
}
|
|
79
|
+
return cards;
|
|
80
|
+
}
|
|
81
|
+
function resolvedFill(color) {
|
|
82
|
+
return TRANSPARENT_FILLS.has(color) ? "#ffffff" : color;
|
|
83
|
+
}
|
|
84
|
+
function applyComputedPadding(source, dest) {
|
|
85
|
+
const computed = window.getComputedStyle(source);
|
|
86
|
+
dest.style.paddingTop = computed.paddingTop;
|
|
87
|
+
dest.style.paddingRight = computed.paddingRight;
|
|
88
|
+
dest.style.paddingBottom = computed.paddingBottom;
|
|
89
|
+
dest.style.paddingLeft = computed.paddingLeft;
|
|
90
|
+
}
|
|
91
|
+
function readCardBorder(source) {
|
|
92
|
+
if (source.style.borderWidth && source.style.borderStyle) {
|
|
93
|
+
return {
|
|
94
|
+
width: source.style.borderWidth,
|
|
95
|
+
style: source.style.borderStyle,
|
|
96
|
+
color: source.style.borderColor,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const computed = window.getComputedStyle(source);
|
|
100
|
+
const before = window.getComputedStyle(source, "::before");
|
|
101
|
+
const width = before.borderTopWidth && before.borderTopWidth !== "0px"
|
|
102
|
+
? before.borderTopWidth
|
|
103
|
+
: computed.borderTopWidth;
|
|
104
|
+
const style = before.borderTopStyle && before.borderTopStyle !== "none"
|
|
105
|
+
? before.borderTopStyle
|
|
106
|
+
: computed.borderTopStyle;
|
|
107
|
+
const color = before.borderTopColor && before.borderTopColor !== "rgba(0, 0, 0, 0)"
|
|
108
|
+
? before.borderTopColor
|
|
109
|
+
: computed.borderTopColor;
|
|
110
|
+
if (width === "0px" || style === "none") {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return { width, style, color };
|
|
114
|
+
}
|
|
115
|
+
function applyCardChrome(source, dest) {
|
|
116
|
+
const computed = window.getComputedStyle(source);
|
|
117
|
+
dest.style.borderRadius = computed.borderRadius;
|
|
118
|
+
dest.style.backgroundColor = resolvedFill(computed.backgroundColor);
|
|
119
|
+
dest.style.overflow = "hidden";
|
|
120
|
+
const border = readCardBorder(source);
|
|
121
|
+
if (border) {
|
|
122
|
+
dest.style.borderWidth = border.width;
|
|
123
|
+
dest.style.borderStyle = border.style;
|
|
124
|
+
dest.style.borderColor = border.color;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function hideCardBeforePseudo() {
|
|
128
|
+
const style = document.createElement("style");
|
|
129
|
+
style.setAttribute("data-chart-export-hide-before", "");
|
|
130
|
+
style.textContent = `
|
|
131
|
+
[${CHART_EXPORT_CAPTURING_ATTR}] .pf-v6-c-card::before,
|
|
132
|
+
[${CHART_EXPORT_CAPTURING_ATTR}].pf-v6-c-card::before {
|
|
133
|
+
border: none !important;
|
|
134
|
+
box-shadow: none !important;
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
document.head.append(style);
|
|
138
|
+
return () => {
|
|
139
|
+
style.remove();
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function copyComputedPadding(node) {
|
|
143
|
+
const previous = {
|
|
144
|
+
paddingTop: node.style.paddingTop,
|
|
145
|
+
paddingRight: node.style.paddingRight,
|
|
146
|
+
paddingBottom: node.style.paddingBottom,
|
|
147
|
+
paddingLeft: node.style.paddingLeft,
|
|
148
|
+
};
|
|
149
|
+
applyComputedPadding(node, node);
|
|
150
|
+
return previous;
|
|
151
|
+
}
|
|
152
|
+
function copyCardChrome(node) {
|
|
153
|
+
const previous = {
|
|
154
|
+
borderRadius: node.style.borderRadius,
|
|
155
|
+
backgroundColor: node.style.backgroundColor,
|
|
156
|
+
overflow: node.style.getPropertyValue("overflow"),
|
|
157
|
+
overflowPriority: node.style.getPropertyPriority("overflow"),
|
|
158
|
+
borderWidth: node.style.borderWidth,
|
|
159
|
+
borderStyle: node.style.borderStyle,
|
|
160
|
+
borderColor: node.style.borderColor,
|
|
161
|
+
minHeight: node.style.minHeight,
|
|
162
|
+
height: node.style.height,
|
|
163
|
+
maxHeight: node.style.maxHeight,
|
|
164
|
+
};
|
|
165
|
+
applyCardChrome(node, node);
|
|
166
|
+
node.style.minHeight = "0px";
|
|
167
|
+
node.style.height = "auto";
|
|
168
|
+
node.style.maxHeight = "none";
|
|
169
|
+
return previous;
|
|
170
|
+
}
|
|
171
|
+
function applyComputedStylesToClone(sourceRoot, clonedRoot) {
|
|
172
|
+
const sourceCards = queryCards(sourceRoot);
|
|
173
|
+
const cloneCards = queryCards(clonedRoot);
|
|
174
|
+
sourceCards.forEach((source, index) => {
|
|
175
|
+
const dest = cloneCards[index];
|
|
176
|
+
if (dest) {
|
|
177
|
+
applyCardChrome(source, dest);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const sources = sourceRoot.querySelectorAll(PADDED_CAPTURE_SELECTOR);
|
|
181
|
+
const dests = clonedRoot.querySelectorAll(PADDED_CAPTURE_SELECTOR);
|
|
182
|
+
sources.forEach((source, index) => {
|
|
183
|
+
const dest = dests[index];
|
|
184
|
+
if (dest) {
|
|
185
|
+
applyComputedPadding(source, dest);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function prepareCaptureLayout(element) {
|
|
190
|
+
const expandNodes = [
|
|
191
|
+
element,
|
|
192
|
+
...Array.from(element.querySelectorAll(`[${CHART_EXPORT_SCROLL_ATTR}], .pf-v6-c-card__body`)),
|
|
193
|
+
];
|
|
194
|
+
const cards = queryCards(element);
|
|
195
|
+
const paddedNodes = Array.from(element.querySelectorAll(PADDED_CAPTURE_SELECTOR));
|
|
196
|
+
const previousExpand = expandNodes.map((node) => ({
|
|
197
|
+
node,
|
|
198
|
+
overflow: node.style.getPropertyValue("overflow"),
|
|
199
|
+
overflowPriority: node.style.getPropertyPriority("overflow"),
|
|
200
|
+
maxHeight: node.style.maxHeight,
|
|
201
|
+
height: node.style.height,
|
|
202
|
+
}));
|
|
203
|
+
const previousChrome = cards.map((node) => ({
|
|
204
|
+
node,
|
|
205
|
+
...copyCardChrome(node),
|
|
206
|
+
}));
|
|
207
|
+
const previousPadding = paddedNodes.map((node) => ({
|
|
208
|
+
node,
|
|
209
|
+
...copyComputedPadding(node),
|
|
210
|
+
}));
|
|
211
|
+
for (const node of expandNodes) {
|
|
212
|
+
node.style.setProperty("overflow", "visible", "important");
|
|
213
|
+
node.style.maxHeight = "none";
|
|
214
|
+
node.style.height = "auto";
|
|
215
|
+
}
|
|
216
|
+
return () => {
|
|
217
|
+
for (const entry of previousExpand) {
|
|
218
|
+
if (entry.overflow) {
|
|
219
|
+
entry.node.style.setProperty("overflow", entry.overflow, entry.overflowPriority);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
entry.node.style.removeProperty("overflow");
|
|
223
|
+
}
|
|
224
|
+
entry.node.style.maxHeight = entry.maxHeight;
|
|
225
|
+
entry.node.style.height = entry.height;
|
|
226
|
+
}
|
|
227
|
+
for (const entry of previousChrome) {
|
|
228
|
+
entry.node.style.borderRadius = entry.borderRadius;
|
|
229
|
+
entry.node.style.backgroundColor = entry.backgroundColor;
|
|
230
|
+
if (entry.overflow) {
|
|
231
|
+
entry.node.style.setProperty("overflow", entry.overflow, entry.overflowPriority);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
entry.node.style.removeProperty("overflow");
|
|
235
|
+
}
|
|
236
|
+
entry.node.style.borderWidth = entry.borderWidth;
|
|
237
|
+
entry.node.style.borderStyle = entry.borderStyle;
|
|
238
|
+
entry.node.style.borderColor = entry.borderColor;
|
|
239
|
+
entry.node.style.minHeight = entry.minHeight;
|
|
240
|
+
entry.node.style.height = entry.height;
|
|
241
|
+
entry.node.style.maxHeight = entry.maxHeight;
|
|
242
|
+
}
|
|
243
|
+
for (const entry of previousPadding) {
|
|
244
|
+
entry.node.style.paddingTop = entry.paddingTop;
|
|
245
|
+
entry.node.style.paddingRight = entry.paddingRight;
|
|
246
|
+
entry.node.style.paddingBottom = entry.paddingBottom;
|
|
247
|
+
entry.node.style.paddingLeft = entry.paddingLeft;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
export async function captureChartElement(element) {
|
|
252
|
+
const restoreHidden = revealHiddenChartAncestors(element);
|
|
253
|
+
const restoreLayout = prepareCaptureLayout(element);
|
|
254
|
+
element.setAttribute(CHART_EXPORT_CAPTURING_ATTR, "");
|
|
255
|
+
const restoreCardBefore = hideCardBeforePseudo();
|
|
256
|
+
try {
|
|
257
|
+
await new Promise((resolve) => {
|
|
258
|
+
requestAnimationFrame(() => resolve());
|
|
259
|
+
});
|
|
260
|
+
if (element.getBoundingClientRect().width < 1) {
|
|
261
|
+
await new Promise((resolve) => {
|
|
262
|
+
requestAnimationFrame(() => resolve());
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return html2canvas(element, {
|
|
266
|
+
useCORS: true,
|
|
267
|
+
backgroundColor: null,
|
|
268
|
+
logging: false,
|
|
269
|
+
scale: CHART_CAPTURE_SCALE,
|
|
270
|
+
imageTimeout: 0,
|
|
271
|
+
ignoreElements: (node) => node instanceof Element &&
|
|
272
|
+
shouldIgnoreChartExportElement(node, element),
|
|
273
|
+
onclone: (_clonedDoc, clonedElement) => {
|
|
274
|
+
applyComputedStylesToClone(element, clonedElement);
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
restoreCardBefore();
|
|
280
|
+
element.removeAttribute(CHART_EXPORT_CAPTURING_ATTR);
|
|
281
|
+
restoreLayout();
|
|
282
|
+
restoreHidden();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
export declare const CHART_EXPORT_HIDE_ATTR = "data-chart-export-hide";
|
|
3
|
+
export declare const CHART_EXPORT_SCROLL_ATTR = "data-chart-export-scroll";
|
|
4
|
+
export declare const CHART_EXPORT_CAPTURING_ATTR = "data-chart-capturing";
|
|
5
|
+
export declare const chartExportHideProps: {
|
|
6
|
+
readonly "data-chart-export-hide": "";
|
|
7
|
+
};
|
|
8
|
+
export declare const chartExportScrollProps: {
|
|
9
|
+
readonly "data-chart-export-scroll": "";
|
|
10
|
+
};
|
|
11
|
+
export declare const chartExportRootStyle: CSSProperties;
|
|
12
|
+
export type ChartExportMeta = {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
filename?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ChartExportView = {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
filename?: string;
|
|
21
|
+
};
|
|
22
|
+
export type RegisteredChart = {
|
|
23
|
+
id: string;
|
|
24
|
+
title: string;
|
|
25
|
+
filename: string;
|
|
26
|
+
element: HTMLElement;
|
|
27
|
+
exportViews?: ChartExportView[];
|
|
28
|
+
activeExportViewId?: string;
|
|
29
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export type ChartExportFile = {
|
|
32
|
+
filename: string;
|
|
33
|
+
blob: Blob;
|
|
34
|
+
};
|
|
35
|
+
export type ChartCaptureSource = {
|
|
36
|
+
id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
filename: string;
|
|
39
|
+
capture: () => Promise<HTMLCanvasElement>;
|
|
40
|
+
};
|
|
41
|
+
/** One label/value row rendered on a {@link PdfTextPage}. */
|
|
42
|
+
export type PdfTextPageItem = {
|
|
43
|
+
label: string;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A native-text PDF page appended after the captured chart images.
|
|
48
|
+
*
|
|
49
|
+
* Used for content that is not a chart/card (e.g. calculated recommendations)
|
|
50
|
+
* but still needs to be part of the exported PDF.
|
|
51
|
+
*/
|
|
52
|
+
export type PdfTextPage = {
|
|
53
|
+
title: string;
|
|
54
|
+
items: PdfTextPageItem[];
|
|
55
|
+
footer?: string;
|
|
56
|
+
};
|
|
57
|
+
export declare function releaseCanvas(canvas: HTMLCanvasElement): void;
|
|
58
|
+
export declare function waitForChartExportPaint(): Promise<void>;
|
|
59
|
+
export declare function chartExportViewsFromLabels(titlePrefix: string, labels: Record<string, string>): ChartExportView[];
|
|
60
|
+
export declare function toBulkChartCaptureSources(charts: RegisteredChart[], capture: (element: HTMLElement) => Promise<HTMLCanvasElement>, prepareElement?: (element: HTMLElement) => () => void): ChartCaptureSource[];
|
|
61
|
+
export declare function restoreChartExportViews(charts: RegisteredChart[]): Promise<void>;
|
|
62
|
+
export declare function sortRegisteredChartsByDocumentOrder(charts: RegisteredChart[]): RegisteredChart[];
|
|
63
|
+
export declare function canvasToBlob(canvas: HTMLCanvasElement): Promise<Blob>;
|
|
64
|
+
export declare function slugifyExportName(value: string): string;
|
|
65
|
+
export declare function chartPngFilename(title: string, id?: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* html2canvas clones the whole document for every capture. Ignore everything
|
|
68
|
+
* except the target card (and ancestors / stylesheet nodes) so zip-all does
|
|
69
|
+
* not re-render every other chart.
|
|
70
|
+
*/
|
|
71
|
+
export declare function shouldIgnoreChartExportElement(node: Element, captureRoot?: Element | null): boolean;
|
|
72
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|
|
73
|
+
//# sourceMappingURL=chartExport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartExport.d.ts","sourceRoot":"","sources":["../../src/report/chartExport.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export const CHART_EXPORT_HIDE_ATTR = "data-chart-export-hide";
|
|
2
|
+
export const CHART_EXPORT_SCROLL_ATTR = "data-chart-export-scroll";
|
|
3
|
+
export const CHART_EXPORT_CAPTURING_ATTR = "data-chart-capturing";
|
|
4
|
+
export const chartExportHideProps = {
|
|
5
|
+
[CHART_EXPORT_HIDE_ATTR]: "",
|
|
6
|
+
};
|
|
7
|
+
export const chartExportScrollProps = {
|
|
8
|
+
[CHART_EXPORT_SCROLL_ATTR]: "",
|
|
9
|
+
};
|
|
10
|
+
export const chartExportRootStyle = {
|
|
11
|
+
width: "100%",
|
|
12
|
+
height: "100%",
|
|
13
|
+
};
|
|
14
|
+
export function releaseCanvas(canvas) {
|
|
15
|
+
canvas.width = 0;
|
|
16
|
+
canvas.height = 0;
|
|
17
|
+
}
|
|
18
|
+
export function waitForChartExportPaint() {
|
|
19
|
+
if (typeof requestAnimationFrame !== "function") {
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
}
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
requestAnimationFrame(() => {
|
|
24
|
+
requestAnimationFrame(() => resolve());
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function chartExportViewsFromLabels(titlePrefix, labels) {
|
|
29
|
+
return Object.entries(labels).map(([id, label]) => ({
|
|
30
|
+
id,
|
|
31
|
+
title: `${titlePrefix} — ${label}`,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
function shouldCycleExportViews(chart) {
|
|
35
|
+
return Boolean(chart.exportViews && chart.exportViews.length > 1 && chart.setExportView);
|
|
36
|
+
}
|
|
37
|
+
function bulkExportViews(chart) {
|
|
38
|
+
if (shouldCycleExportViews(chart) && chart.exportViews) {
|
|
39
|
+
return chart.exportViews;
|
|
40
|
+
}
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
id: chart.id,
|
|
44
|
+
title: chart.title,
|
|
45
|
+
filename: chart.filename,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
export function toBulkChartCaptureSources(charts, capture, prepareElement) {
|
|
50
|
+
return charts.flatMap((chart) => {
|
|
51
|
+
const views = bulkExportViews(chart);
|
|
52
|
+
const cyclesViews = shouldCycleExportViews(chart);
|
|
53
|
+
return views.map((view) => ({
|
|
54
|
+
id: cyclesViews ? `${chart.id}--${view.id}` : chart.id,
|
|
55
|
+
title: view.title,
|
|
56
|
+
filename: view.filename ??
|
|
57
|
+
(cyclesViews
|
|
58
|
+
? chartPngFilename(view.title, `${chart.id}-${view.id}`)
|
|
59
|
+
: chart.filename),
|
|
60
|
+
capture: async () => {
|
|
61
|
+
const restore = prepareElement?.(chart.element);
|
|
62
|
+
try {
|
|
63
|
+
if (cyclesViews && chart.setExportView) {
|
|
64
|
+
await chart.setExportView(view.id);
|
|
65
|
+
}
|
|
66
|
+
return await capture(chart.element);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
restore?.();
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export async function restoreChartExportViews(charts) {
|
|
76
|
+
for (const chart of charts) {
|
|
77
|
+
if (shouldCycleExportViews(chart) &&
|
|
78
|
+
chart.setExportView &&
|
|
79
|
+
chart.activeExportViewId) {
|
|
80
|
+
try {
|
|
81
|
+
await chart.setExportView(chart.activeExportViewId);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error("Failed to restore the selected chart view:", error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export function sortRegisteredChartsByDocumentOrder(charts) {
|
|
90
|
+
return [...charts].sort((left, right) => {
|
|
91
|
+
if (left.element === right.element) {
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
const position = left.element.compareDocumentPosition(right.element);
|
|
95
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
96
|
+
return -1;
|
|
97
|
+
}
|
|
98
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export function canvasToBlob(canvas) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
if (canvas.width < 1 || canvas.height < 1) {
|
|
107
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
canvas.toBlob((blob) => {
|
|
111
|
+
if (blob) {
|
|
112
|
+
resolve(blob);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
reject(new Error("Failed to encode canvas as PNG"));
|
|
116
|
+
}, "image/png");
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export function slugifyExportName(value) {
|
|
120
|
+
const slug = value
|
|
121
|
+
.toLowerCase()
|
|
122
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
123
|
+
.replace(/^-|-$/g, "");
|
|
124
|
+
return slug || "chart";
|
|
125
|
+
}
|
|
126
|
+
export function chartPngFilename(title, id = "chart") {
|
|
127
|
+
return `${slugifyExportName(title) || slugifyExportName(id)}.png`;
|
|
128
|
+
}
|
|
129
|
+
const KEEP_TAGS = new Set(["HTML", "HEAD", "BODY", "STYLE", "LINK"]);
|
|
130
|
+
function isHiddenForChartExport(node) {
|
|
131
|
+
return (node.hasAttribute(CHART_EXPORT_HIDE_ATTR) ||
|
|
132
|
+
Boolean(node.closest(`[${CHART_EXPORT_HIDE_ATTR}]`)));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* html2canvas clones the whole document for every capture. Ignore everything
|
|
136
|
+
* except the target card (and ancestors / stylesheet nodes) so zip-all does
|
|
137
|
+
* not re-render every other chart.
|
|
138
|
+
*/
|
|
139
|
+
export function shouldIgnoreChartExportElement(node, captureRoot) {
|
|
140
|
+
if (!captureRoot) {
|
|
141
|
+
return isHiddenForChartExport(node);
|
|
142
|
+
}
|
|
143
|
+
if (KEEP_TAGS.has(node.tagName)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (node !== captureRoot &&
|
|
147
|
+
!captureRoot.contains(node) &&
|
|
148
|
+
!node.contains(captureRoot)) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return isHiddenForChartExport(node);
|
|
152
|
+
}
|
|
153
|
+
export function downloadBlob(blob, filename) {
|
|
154
|
+
const url = URL.createObjectURL(blob);
|
|
155
|
+
const link = document.createElement("a");
|
|
156
|
+
link.href = url;
|
|
157
|
+
link.download = filename;
|
|
158
|
+
document.body.appendChild(link);
|
|
159
|
+
link.click();
|
|
160
|
+
document.body.removeChild(link);
|
|
161
|
+
URL.revokeObjectURL(url);
|
|
162
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RefCallback } from "react";
|
|
2
|
+
import { type ChartExportMeta, type ChartExportView, type PdfTextPage, type RegisteredChart } from "./chartExport.js";
|
|
3
|
+
export type ChartExportFormat = "pdf" | "png" | "html";
|
|
4
|
+
export type ChartExportApi = {
|
|
5
|
+
downloadChart: (id: string) => Promise<void>;
|
|
6
|
+
downloadAll: () => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* @param extraPages - Native-text pages appended after the captured chart
|
|
9
|
+
* images (e.g. calculated recommendations that aren't rendered as charts).
|
|
10
|
+
*/
|
|
11
|
+
downloadPdf: (documentTitle: string, extraPages?: PdfTextPage[]) => Promise<void>;
|
|
12
|
+
downloadHtml: (documentTitle: string) => Promise<void>;
|
|
13
|
+
downloadingChartId: string | null;
|
|
14
|
+
exportingFormat: ChartExportFormat | null;
|
|
15
|
+
exportLoadingLabel: string | null;
|
|
16
|
+
isExportingAll: boolean;
|
|
17
|
+
isBusy: boolean;
|
|
18
|
+
exportError: string | null;
|
|
19
|
+
clearExportError: () => void;
|
|
20
|
+
};
|
|
21
|
+
export type ChartExportRegistry = {
|
|
22
|
+
register: (chart: RegisteredChart) => () => void;
|
|
23
|
+
};
|
|
24
|
+
export declare const ChartExportRegistryContext: import("react").Context<ChartExportRegistry | null>;
|
|
25
|
+
export declare const ChartExportApiContext: import("react").Context<ChartExportApi | null>;
|
|
26
|
+
export declare function useChartExport(): ChartExportApi | null;
|
|
27
|
+
export declare function useRegisterChart({ id, title, filename, exportViews, activeExportViewId, setExportView, }: ChartExportMeta & {
|
|
28
|
+
exportViews?: ChartExportView[];
|
|
29
|
+
activeExportViewId?: string;
|
|
30
|
+
setExportView?: (viewId: string) => Promise<void>;
|
|
31
|
+
}): RefCallback<HTMLElement>;
|
|
32
|
+
//# sourceMappingURL=chartExportContext.d.ts.map
|