react-cheminfo 0.28.0 → 0.30.0
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 +79 -26
- package/lib/chart/core/axisLabels.d.ts +82 -0
- package/lib/chart/core/axisLabels.d.ts.map +1 -0
- package/lib/chart/core/axisLabels.js +111 -0
- package/lib/chart/core/axisLabels.js.map +1 -0
- package/lib/chart/core/boxLayout.d.ts +53 -0
- package/lib/chart/core/boxLayout.d.ts.map +1 -0
- package/lib/chart/core/boxLayout.js +112 -0
- package/lib/chart/core/boxLayout.js.map +1 -0
- package/lib/chart/core/chartAxisScale.d.ts +23 -2
- package/lib/chart/core/chartAxisScale.d.ts.map +1 -1
- package/lib/chart/core/chartAxisScale.js +64 -13
- package/lib/chart/core/chartAxisScale.js.map +1 -1
- package/lib/chart/core/chartDomain.d.ts +160 -0
- package/lib/chart/core/chartDomain.d.ts.map +1 -0
- package/lib/chart/core/chartDomain.js +46 -0
- package/lib/chart/core/chartDomain.js.map +1 -0
- package/lib/chart/core/chartGeometry.d.ts +131 -0
- package/lib/chart/core/chartGeometry.d.ts.map +1 -0
- package/lib/chart/core/chartGeometry.js +101 -0
- package/lib/chart/core/chartGeometry.js.map +1 -0
- package/lib/chart/core/chartPane.d.ts +11 -0
- package/lib/chart/core/chartPane.d.ts.map +1 -0
- package/lib/chart/core/chartPane.js +11 -0
- package/lib/chart/core/chartPane.js.map +1 -0
- package/lib/chart/core/chartScale.d.ts +4 -1
- package/lib/chart/core/chartScale.d.ts.map +1 -1
- package/lib/chart/core/chartScale.js +8 -4
- package/lib/chart/core/chartScale.js.map +1 -1
- package/lib/chart/core/chartTheme.d.ts +156 -0
- package/lib/chart/core/chartTheme.d.ts.map +1 -0
- package/lib/chart/core/chartTheme.js +156 -0
- package/lib/chart/core/chartTheme.js.map +1 -0
- package/lib/chart/core/chartViewport.d.ts +32 -5
- package/lib/chart/core/chartViewport.d.ts.map +1 -1
- package/lib/chart/core/chartViewport.js +40 -11
- package/lib/chart/core/chartViewport.js.map +1 -1
- package/lib/chart/core/guidePlacement.d.ts +52 -0
- package/lib/chart/core/guidePlacement.d.ts.map +1 -0
- package/lib/chart/core/guidePlacement.js +52 -0
- package/lib/chart/core/guidePlacement.js.map +1 -0
- package/lib/chart/core/index.d.ts +29 -2
- package/lib/chart/core/index.d.ts.map +1 -1
- package/lib/chart/core/index.js +19 -2
- package/lib/chart/core/index.js.map +1 -1
- package/lib/chart/core/labelStack.d.ts +27 -0
- package/lib/chart/core/labelStack.d.ts.map +1 -0
- package/lib/chart/core/labelStack.js +62 -0
- package/lib/chart/core/labelStack.js.map +1 -0
- package/lib/chart/core/legendBox.d.ts +152 -0
- package/lib/chart/core/legendBox.d.ts.map +1 -0
- package/lib/chart/core/legendBox.js +169 -0
- package/lib/chart/core/legendBox.js.map +1 -0
- package/lib/chart/core/selectionGeometry.d.ts +45 -0
- package/lib/chart/core/selectionGeometry.d.ts.map +1 -0
- package/lib/chart/core/selectionGeometry.js +49 -0
- package/lib/chart/core/selectionGeometry.js.map +1 -0
- package/lib/chart/core/spectrumColor.d.ts +80 -0
- package/lib/chart/core/spectrumColor.d.ts.map +1 -0
- package/lib/chart/core/spectrumColor.js +120 -0
- package/lib/chart/core/spectrumColor.js.map +1 -0
- package/lib/chart/core/stackCapacity.d.ts +136 -0
- package/lib/chart/core/stackCapacity.d.ts.map +1 -0
- package/lib/chart/core/stackCapacity.js +153 -0
- package/lib/chart/core/stackCapacity.js.map +1 -0
- package/lib/chart/core/svgPoint.d.ts +62 -0
- package/lib/chart/core/svgPoint.d.ts.map +1 -0
- package/lib/chart/core/svgPoint.js +43 -0
- package/lib/chart/core/svgPoint.js.map +1 -0
- package/lib/chart/core/tracePath.d.ts +94 -0
- package/lib/chart/core/tracePath.d.ts.map +1 -0
- package/lib/chart/core/tracePath.js +191 -0
- package/lib/chart/core/tracePath.js.map +1 -0
- package/lib/chart/core/trackerReadout.d.ts +55 -0
- package/lib/chart/core/trackerReadout.d.ts.map +1 -0
- package/lib/chart/core/trackerReadout.js +53 -0
- package/lib/chart/core/trackerReadout.js.map +1 -0
- package/lib/chart/core/viewTransform.d.ts +167 -0
- package/lib/chart/core/viewTransform.d.ts.map +1 -0
- package/lib/chart/core/viewTransform.js +188 -0
- package/lib/chart/core/viewTransform.js.map +1 -0
- package/lib/chart/core/zoomDomain.d.ts +127 -0
- package/lib/chart/core/zoomDomain.d.ts.map +1 -0
- package/lib/chart/core/zoomDomain.js +175 -0
- package/lib/chart/core/zoomDomain.js.map +1 -0
- package/lib/chart/ui/Axes.d.ts +104 -0
- package/lib/chart/ui/Axes.d.ts.map +1 -0
- package/lib/chart/ui/Axes.js +155 -0
- package/lib/chart/ui/Axes.js.map +1 -0
- package/lib/chart/ui/AxisGuide.d.ts +60 -0
- package/lib/chart/ui/AxisGuide.d.ts.map +1 -0
- package/lib/chart/ui/AxisGuide.js +111 -0
- package/lib/chart/ui/AxisGuide.js.map +1 -0
- package/lib/chart/ui/ChartStack.d.ts +81 -0
- package/lib/chart/ui/ChartStack.d.ts.map +1 -0
- package/lib/chart/ui/ChartStack.js +42 -0
- package/lib/chart/ui/ChartStack.js.map +1 -0
- package/lib/chart/ui/ChartTracker.d.ts +36 -0
- package/lib/chart/ui/ChartTracker.d.ts.map +1 -0
- package/lib/chart/ui/ChartTracker.js +27 -0
- package/lib/chart/ui/ChartTracker.js.map +1 -0
- package/lib/chart/ui/PlotCaption.d.ts +44 -0
- package/lib/chart/ui/PlotCaption.d.ts.map +1 -0
- package/lib/chart/ui/PlotCaption.js +68 -0
- package/lib/chart/ui/PlotCaption.js.map +1 -0
- package/lib/chart/ui/SelectionRect.d.ts +27 -0
- package/lib/chart/ui/SelectionRect.d.ts.map +1 -0
- package/lib/chart/ui/SelectionRect.js +31 -0
- package/lib/chart/ui/SelectionRect.js.map +1 -0
- package/lib/chart/ui/TraceLegend.d.ts +99 -0
- package/lib/chart/ui/TraceLegend.d.ts.map +1 -0
- package/lib/chart/ui/TraceLegend.js +45 -0
- package/lib/chart/ui/TraceLegend.js.map +1 -0
- package/lib/chart/ui/chartGestures.d.ts +158 -0
- package/lib/chart/ui/chartGestures.d.ts.map +1 -0
- package/lib/chart/ui/chartGestures.js +145 -0
- package/lib/chart/ui/chartGestures.js.map +1 -0
- package/lib/chart/ui/chartStackLevel.d.ts +115 -0
- package/lib/chart/ui/chartStackLevel.d.ts.map +1 -0
- package/lib/chart/ui/chartStackLevel.js +96 -0
- package/lib/chart/ui/chartStackLevel.js.map +1 -0
- package/lib/chart/ui/chartSurface.d.ts +35 -0
- package/lib/chart/ui/chartSurface.d.ts.map +1 -0
- package/lib/chart/ui/chartSurface.js +58 -0
- package/lib/chart/ui/chartSurface.js.map +1 -0
- package/lib/chart/ui/index.d.ts +24 -0
- package/lib/chart/ui/index.d.ts.map +1 -1
- package/lib/chart/ui/index.js +13 -0
- package/lib/chart/ui/index.js.map +1 -1
- package/lib/chart/ui/useChartPointer.d.ts +124 -0
- package/lib/chart/ui/useChartPointer.d.ts.map +1 -0
- package/lib/chart/ui/useChartPointer.js +152 -0
- package/lib/chart/ui/useChartPointer.js.map +1 -0
- package/lib/chart/ui/useChartSize.d.ts +49 -0
- package/lib/chart/ui/useChartSize.d.ts.map +1 -0
- package/lib/chart/ui/useChartSize.js +91 -0
- package/lib/chart/ui/useChartSize.js.map +1 -0
- package/lib/chart/ui/useChartWindow.d.ts +147 -0
- package/lib/chart/ui/useChartWindow.d.ts.map +1 -0
- package/lib/chart/ui/useChartWindow.js +135 -0
- package/lib/chart/ui/useChartWindow.js.map +1 -0
- package/lib/chart/ui/useChartZoom.d.ts +88 -0
- package/lib/chart/ui/useChartZoom.d.ts.map +1 -0
- package/lib/chart/ui/useChartZoom.js +142 -0
- package/lib/chart/ui/useChartZoom.js.map +1 -0
- package/lib/chart/ui/useWheelListener.d.ts +30 -0
- package/lib/chart/ui/useWheelListener.d.ts.map +1 -0
- package/lib/chart/ui/useWheelListener.js +57 -0
- package/lib/chart/ui/useWheelListener.js.map +1 -0
- package/lib/chrome/ui/AccountButton.d.ts +76 -0
- package/lib/chrome/ui/AccountButton.d.ts.map +1 -0
- package/lib/chrome/ui/AccountButton.js +66 -0
- package/lib/chrome/ui/AccountButton.js.map +1 -0
- package/lib/chrome/ui/index.d.ts +2 -0
- package/lib/chrome/ui/index.d.ts.map +1 -1
- package/lib/chrome/ui/index.js +1 -0
- package/lib/chrome/ui/index.js.map +1 -1
- package/lib/clipboard/core/copyPng.d.ts +13 -0
- package/lib/clipboard/core/copyPng.d.ts.map +1 -0
- package/lib/clipboard/core/copyPng.js +19 -0
- package/lib/clipboard/core/copyPng.js.map +1 -0
- package/lib/clipboard/core/index.d.ts +1 -0
- package/lib/clipboard/core/index.d.ts.map +1 -1
- package/lib/clipboard/core/index.js +1 -0
- package/lib/clipboard/core/index.js.map +1 -1
- package/lib/clipboard/ui/ClickToCopy.d.ts +6 -0
- package/lib/clipboard/ui/ClickToCopy.d.ts.map +1 -1
- package/lib/clipboard/ui/ClickToCopy.js +3 -3
- package/lib/clipboard/ui/ClickToCopy.js.map +1 -1
- package/lib/core.d.ts +1 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +1 -0
- package/lib/core.js.map +1 -1
- package/lib/download/core/exportStyles.d.ts +22 -0
- package/lib/download/core/exportStyles.d.ts.map +1 -0
- package/lib/download/core/exportStyles.js +19 -0
- package/lib/download/core/exportStyles.js.map +1 -0
- package/lib/download/core/imageResolution.d.ts +88 -0
- package/lib/download/core/imageResolution.d.ts.map +1 -0
- package/lib/download/core/imageResolution.js +77 -0
- package/lib/download/core/imageResolution.js.map +1 -0
- package/lib/download/core/index.d.ts +13 -0
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +8 -0
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/core/pictureExport.d.ts +93 -0
- package/lib/download/core/pictureExport.d.ts.map +1 -0
- package/lib/download/core/pictureExport.js +116 -0
- package/lib/download/core/pictureExport.js.map +1 -0
- package/lib/download/core/stackedDrawing.d.ts +36 -0
- package/lib/download/core/stackedDrawing.d.ts.map +1 -0
- package/lib/download/core/stackedDrawing.js +98 -0
- package/lib/download/core/stackedDrawing.js.map +1 -0
- package/lib/download/core/svgBounds.d.ts +44 -0
- package/lib/download/core/svgBounds.d.ts.map +1 -0
- package/lib/download/core/svgBounds.js +69 -0
- package/lib/download/core/svgBounds.js.map +1 -0
- package/lib/download/core/svgNamespace.d.ts +9 -0
- package/lib/download/core/svgNamespace.d.ts.map +1 -0
- package/lib/download/core/svgNamespace.js +10 -0
- package/lib/download/core/svgNamespace.js.map +1 -0
- package/lib/download/core/svgToPng.d.ts +43 -0
- package/lib/download/core/svgToPng.d.ts.map +1 -0
- package/lib/download/core/svgToPng.js +79 -0
- package/lib/download/core/svgToPng.js.map +1 -0
- package/lib/download/core/svgToString.d.ts +45 -0
- package/lib/download/core/svgToString.d.ts.map +1 -0
- package/lib/download/core/svgToString.js +58 -0
- package/lib/download/core/svgToString.js.map +1 -0
- package/lib/download/ui/ExportDialogFrame.d.ts +46 -0
- package/lib/download/ui/ExportDialogFrame.d.ts.map +1 -0
- package/lib/download/ui/ExportDialogFrame.js +24 -0
- package/lib/download/ui/ExportDialogFrame.js.map +1 -0
- package/lib/download/ui/ExportImageDialog.d.ts +47 -0
- package/lib/download/ui/ExportImageDialog.d.ts.map +1 -0
- package/lib/download/ui/ExportImageDialog.js +25 -0
- package/lib/download/ui/ExportImageDialog.js.map +1 -0
- package/lib/download/ui/ExportNameField.d.ts +29 -0
- package/lib/download/ui/ExportNameField.d.ts.map +1 -0
- package/lib/download/ui/ExportNameField.js +99 -0
- package/lib/download/ui/ExportNameField.js.map +1 -0
- package/lib/download/ui/ExportPictureSection.d.ts +38 -0
- package/lib/download/ui/ExportPictureSection.d.ts.map +1 -0
- package/lib/download/ui/ExportPictureSection.js +48 -0
- package/lib/download/ui/ExportPictureSection.js.map +1 -0
- package/lib/download/ui/index.d.ts +10 -0
- package/lib/download/ui/index.d.ts.map +1 -1
- package/lib/download/ui/index.js +5 -0
- package/lib/download/ui/index.js.map +1 -1
- package/lib/download/ui/useDrawingBox.d.ts +23 -0
- package/lib/download/ui/useDrawingBox.d.ts.map +1 -0
- package/lib/download/ui/useDrawingBox.js +21 -0
- package/lib/download/ui/useDrawingBox.js.map +1 -0
- package/lib/error/core/describeSource.d.ts +17 -0
- package/lib/error/core/describeSource.d.ts.map +1 -0
- package/lib/error/core/describeSource.js +19 -0
- package/lib/error/core/describeSource.js.map +1 -0
- package/lib/error/core/index.d.ts +1 -0
- package/lib/error/core/index.d.ts.map +1 -1
- package/lib/error/core/index.js +1 -0
- package/lib/error/core/index.js.map +1 -1
- package/lib/help/ui/HelpBody.d.ts +10 -1
- package/lib/help/ui/HelpBody.d.ts.map +1 -1
- package/lib/help/ui/HelpBody.js +24 -1
- package/lib/help/ui/HelpBody.js.map +1 -1
- package/lib/help/ui/index.d.ts +1 -1
- package/lib/help/ui/index.d.ts.map +1 -1
- package/lib/help/ui/index.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/ir/core/analysisSpectra.d.ts +46 -0
- package/lib/ir/core/analysisSpectra.d.ts.map +1 -0
- package/lib/ir/core/analysisSpectra.js +187 -0
- package/lib/ir/core/analysisSpectra.js.map +1 -0
- package/lib/ir/core/assignBands.d.ts +83 -0
- package/lib/ir/core/assignBands.d.ts.map +1 -0
- package/lib/ir/core/assignBands.js +83 -0
- package/lib/ir/core/assignBands.js.map +1 -0
- package/lib/ir/core/bandAssignments.d.ts +47 -0
- package/lib/ir/core/bandAssignments.d.ts.map +1 -0
- package/lib/ir/core/bandAssignments.js +305 -0
- package/lib/ir/core/bandAssignments.js.map +1 -0
- package/lib/ir/core/bandLabelPlan.d.ts +93 -0
- package/lib/ir/core/bandLabelPlan.d.ts.map +1 -0
- package/lib/ir/core/bandLabelPlan.js +104 -0
- package/lib/ir/core/bandLabelPlan.js.map +1 -0
- package/lib/ir/core/detectIrFormat.d.ts +23 -0
- package/lib/ir/core/detectIrFormat.d.ts.map +1 -0
- package/lib/ir/core/detectIrFormat.js +133 -0
- package/lib/ir/core/detectIrFormat.js.map +1 -0
- package/lib/ir/core/downloadSpectra.d.ts +26 -0
- package/lib/ir/core/downloadSpectra.d.ts.map +1 -0
- package/lib/ir/core/downloadSpectra.js +37 -0
- package/lib/ir/core/downloadSpectra.js.map +1 -0
- package/lib/ir/core/fromJcamp.d.ts +35 -0
- package/lib/ir/core/fromJcamp.d.ts.map +1 -0
- package/lib/ir/core/fromJcamp.js +48 -0
- package/lib/ir/core/fromJcamp.js.map +1 -0
- package/lib/ir/core/fromSpc.d.ts +30 -0
- package/lib/ir/core/fromSpc.d.ts.map +1 -0
- package/lib/ir/core/fromSpc.js +40 -0
- package/lib/ir/core/fromSpc.js.map +1 -0
- package/lib/ir/core/index.d.ts +51 -0
- package/lib/ir/core/index.d.ts.map +1 -0
- package/lib/ir/core/index.js +35 -0
- package/lib/ir/core/index.js.map +1 -0
- package/lib/ir/core/irBand.d.ts +45 -0
- package/lib/ir/core/irBand.d.ts.map +1 -0
- package/lib/ir/core/irBand.js +30 -0
- package/lib/ir/core/irBand.js.map +1 -0
- package/lib/ir/core/irCommands.d.ts +168 -0
- package/lib/ir/core/irCommands.d.ts.map +1 -0
- package/lib/ir/core/irCommands.js +94 -0
- package/lib/ir/core/irCommands.js.map +1 -0
- package/lib/ir/core/irDomain.d.ts +63 -0
- package/lib/ir/core/irDomain.d.ts.map +1 -0
- package/lib/ir/core/irDomain.js +136 -0
- package/lib/ir/core/irDomain.js.map +1 -0
- package/lib/ir/core/irEditorApi.d.ts +42 -0
- package/lib/ir/core/irEditorApi.d.ts.map +1 -0
- package/lib/ir/core/irEditorApi.js +10 -0
- package/lib/ir/core/irEditorApi.js.map +1 -0
- package/lib/ir/core/irFormat.d.ts +42 -0
- package/lib/ir/core/irFormat.d.ts.map +1 -0
- package/lib/ir/core/irFormat.js +51 -0
- package/lib/ir/core/irFormat.js.map +1 -0
- package/lib/ir/core/irMode.d.ts +160 -0
- package/lib/ir/core/irMode.d.ts.map +1 -0
- package/lib/ir/core/irMode.js +175 -0
- package/lib/ir/core/irMode.js.map +1 -0
- package/lib/ir/core/irReducer.d.ts +101 -0
- package/lib/ir/core/irReducer.d.ts.map +1 -0
- package/lib/ir/core/irReducer.js +207 -0
- package/lib/ir/core/irReducer.js.map +1 -0
- package/lib/ir/core/irSidePanels.d.ts +22 -0
- package/lib/ir/core/irSidePanels.d.ts.map +1 -0
- package/lib/ir/core/irSidePanels.js +12 -0
- package/lib/ir/core/irSidePanels.js.map +1 -0
- package/lib/ir/core/irSpectrum.d.ts +140 -0
- package/lib/ir/core/irSpectrum.d.ts.map +1 -0
- package/lib/ir/core/irSpectrum.js +34 -0
- package/lib/ir/core/irSpectrum.js.map +1 -0
- package/lib/ir/core/irState.d.ts +119 -0
- package/lib/ir/core/irState.d.ts.map +1 -0
- package/lib/ir/core/irState.js +92 -0
- package/lib/ir/core/irState.js.map +1 -0
- package/lib/ir/core/loadIrSpectra.d.ts +36 -0
- package/lib/ir/core/loadIrSpectra.d.ts.map +1 -0
- package/lib/ir/core/loadIrSpectra.js +44 -0
- package/lib/ir/core/loadIrSpectra.js.map +1 -0
- package/lib/ir/core/nearestBand.d.ts +35 -0
- package/lib/ir/core/nearestBand.d.ts.map +1 -0
- package/lib/ir/core/nearestBand.js +47 -0
- package/lib/ir/core/nearestBand.js.map +1 -0
- package/lib/ir/core/pickBands.d.ts +70 -0
- package/lib/ir/core/pickBands.d.ts.map +1 -0
- package/lib/ir/core/pickBands.js +125 -0
- package/lib/ir/core/pickBands.js.map +1 -0
- package/lib/ir/core/spectrumJcamp.d.ts +58 -0
- package/lib/ir/core/spectrumJcamp.d.ts.map +1 -0
- package/lib/ir/core/spectrumJcamp.js +156 -0
- package/lib/ir/core/spectrumJcamp.js.map +1 -0
- package/lib/ir/core/toIrSpectrum.d.ts +59 -0
- package/lib/ir/core/toIrSpectrum.d.ts.map +1 -0
- package/lib/ir/core/toIrSpectrum.js +56 -0
- package/lib/ir/core/toIrSpectrum.js.map +1 -0
- package/lib/ir/ui/BandMarks.d.ts +52 -0
- package/lib/ir/ui/BandMarks.d.ts.map +1 -0
- package/lib/ir/ui/BandMarks.js +71 -0
- package/lib/ir/ui/BandMarks.js.map +1 -0
- package/lib/ir/ui/BandsPanel.d.ts +31 -0
- package/lib/ir/ui/BandsPanel.d.ts.map +1 -0
- package/lib/ir/ui/BandsPanel.js +94 -0
- package/lib/ir/ui/BandsPanel.js.map +1 -0
- package/lib/ir/ui/IrAboutDialog.d.ts +18 -0
- package/lib/ir/ui/IrAboutDialog.d.ts.map +1 -0
- package/lib/ir/ui/IrAboutDialog.js +32 -0
- package/lib/ir/ui/IrAboutDialog.js.map +1 -0
- package/lib/ir/ui/IrCanvas.d.ts +38 -0
- package/lib/ir/ui/IrCanvas.d.ts.map +1 -0
- package/lib/ir/ui/IrCanvas.js +41 -0
- package/lib/ir/ui/IrCanvas.js.map +1 -0
- package/lib/ir/ui/IrChart.d.ts +28 -0
- package/lib/ir/ui/IrChart.d.ts.map +1 -0
- package/lib/ir/ui/IrChart.js +114 -0
- package/lib/ir/ui/IrChart.js.map +1 -0
- package/lib/ir/ui/IrCommandProvider.d.ts +15 -0
- package/lib/ir/ui/IrCommandProvider.d.ts.map +1 -0
- package/lib/ir/ui/IrCommandProvider.js +14 -0
- package/lib/ir/ui/IrCommandProvider.js.map +1 -0
- package/lib/ir/ui/IrCommandTooltip.d.ts +16 -0
- package/lib/ir/ui/IrCommandTooltip.d.ts.map +1 -0
- package/lib/ir/ui/IrCommandTooltip.js +22 -0
- package/lib/ir/ui/IrCommandTooltip.js.map +1 -0
- package/lib/ir/ui/IrDocumentationDialog.d.ts +18 -0
- package/lib/ir/ui/IrDocumentationDialog.d.ts.map +1 -0
- package/lib/ir/ui/IrDocumentationDialog.js +68 -0
- package/lib/ir/ui/IrDocumentationDialog.js.map +1 -0
- package/lib/ir/ui/IrEditor.d.ts +60 -0
- package/lib/ir/ui/IrEditor.d.ts.map +1 -0
- package/lib/ir/ui/IrEditor.js +42 -0
- package/lib/ir/ui/IrEditor.js.map +1 -0
- package/lib/ir/ui/IrHeader.d.ts +13 -0
- package/lib/ir/ui/IrHeader.d.ts.map +1 -0
- package/lib/ir/ui/IrHeader.js +21 -0
- package/lib/ir/ui/IrHeader.js.map +1 -0
- package/lib/ir/ui/IrLogo.d.ts +20 -0
- package/lib/ir/ui/IrLogo.d.ts.map +1 -0
- package/lib/ir/ui/IrLogo.js +17 -0
- package/lib/ir/ui/IrLogo.js.map +1 -0
- package/lib/ir/ui/IrPointerTracker.d.ts +29 -0
- package/lib/ir/ui/IrPointerTracker.d.ts.map +1 -0
- package/lib/ir/ui/IrPointerTracker.js +47 -0
- package/lib/ir/ui/IrPointerTracker.js.map +1 -0
- package/lib/ir/ui/IrShell.d.ts +25 -0
- package/lib/ir/ui/IrShell.d.ts.map +1 -0
- package/lib/ir/ui/IrShell.js +178 -0
- package/lib/ir/ui/IrShell.js.map +1 -0
- package/lib/ir/ui/IrSidePanel.d.ts +26 -0
- package/lib/ir/ui/IrSidePanel.d.ts.map +1 -0
- package/lib/ir/ui/IrSidePanel.js +39 -0
- package/lib/ir/ui/IrSidePanel.js.map +1 -0
- package/lib/ir/ui/IrStateProvider.d.ts +19 -0
- package/lib/ir/ui/IrStateProvider.d.ts.map +1 -0
- package/lib/ir/ui/IrStateProvider.js +16 -0
- package/lib/ir/ui/IrStateProvider.js.map +1 -0
- package/lib/ir/ui/IrStatusBar.d.ts +14 -0
- package/lib/ir/ui/IrStatusBar.d.ts.map +1 -0
- package/lib/ir/ui/IrStatusBar.js +48 -0
- package/lib/ir/ui/IrStatusBar.js.map +1 -0
- package/lib/ir/ui/IrToolbar.d.ts +18 -0
- package/lib/ir/ui/IrToolbar.d.ts.map +1 -0
- package/lib/ir/ui/IrToolbar.js +32 -0
- package/lib/ir/ui/IrToolbar.js.map +1 -0
- package/lib/ir/ui/IrTraces.d.ts +63 -0
- package/lib/ir/ui/IrTraces.d.ts.map +1 -0
- package/lib/ir/ui/IrTraces.js +72 -0
- package/lib/ir/ui/IrTraces.js.map +1 -0
- package/lib/ir/ui/MetadataPanel.d.ts +15 -0
- package/lib/ir/ui/MetadataPanel.d.ts.map +1 -0
- package/lib/ir/ui/MetadataPanel.js +49 -0
- package/lib/ir/ui/MetadataPanel.js.map +1 -0
- package/lib/ir/ui/SpectraPanel.d.ts +20 -0
- package/lib/ir/ui/SpectraPanel.d.ts.map +1 -0
- package/lib/ir/ui/SpectraPanel.js +42 -0
- package/lib/ir/ui/SpectraPanel.js.map +1 -0
- package/lib/ir/ui/SpectrumRow.d.ts +26 -0
- package/lib/ir/ui/SpectrumRow.d.ts.map +1 -0
- package/lib/ir/ui/SpectrumRow.js +41 -0
- package/lib/ir/ui/SpectrumRow.js.map +1 -0
- package/lib/ir/ui/index.d.ts +56 -0
- package/lib/ir/ui/index.d.ts.map +1 -0
- package/lib/ir/ui/index.js +36 -0
- package/lib/ir/ui/index.js.map +1 -0
- package/lib/ir/ui/irActions.d.ts +52 -0
- package/lib/ir/ui/irActions.d.ts.map +1 -0
- package/lib/ir/ui/irActions.js +62 -0
- package/lib/ir/ui/irActions.js.map +1 -0
- package/lib/ir/ui/irChartProps.d.ts +116 -0
- package/lib/ir/ui/irChartProps.d.ts.map +1 -0
- package/lib/ir/ui/irChartProps.js +14 -0
- package/lib/ir/ui/irChartProps.js.map +1 -0
- package/lib/ir/ui/irCommandContext.d.ts +35 -0
- package/lib/ir/ui/irCommandContext.d.ts.map +1 -0
- package/lib/ir/ui/irCommandContext.js +44 -0
- package/lib/ir/ui/irCommandContext.js.map +1 -0
- package/lib/ir/ui/irStateContext.d.ts +26 -0
- package/lib/ir/ui/irStateContext.d.ts.map +1 -0
- package/lib/ir/ui/irStateContext.js +37 -0
- package/lib/ir/ui/irStateContext.js.map +1 -0
- package/lib/ir/ui/useIrEditor.d.ts +51 -0
- package/lib/ir/ui/useIrEditor.d.ts.map +1 -0
- package/lib/ir/ui/useIrEditor.js +88 -0
- package/lib/ir/ui/useIrEditor.js.map +1 -0
- package/lib/ir/ui/useIrPointer.d.ts +66 -0
- package/lib/ir/ui/useIrPointer.d.ts.map +1 -0
- package/lib/ir/ui/useIrPointer.js +53 -0
- package/lib/ir/ui/useIrPointer.js.map +1 -0
- package/lib/ir/ui/useIrShortcuts.d.ts +24 -0
- package/lib/ir/ui/useIrShortcuts.d.ts.map +1 -0
- package/lib/ir/ui/useIrShortcuts.js +73 -0
- package/lib/ir/ui/useIrShortcuts.js.map +1 -0
- package/lib/ir/ui/useIrZoom.d.ts +51 -0
- package/lib/ir/ui/useIrZoom.d.ts.map +1 -0
- package/lib/ir/ui/useIrZoom.js +46 -0
- package/lib/ir/ui/useIrZoom.js.map +1 -0
- package/lib/ir.d.ts +13 -0
- package/lib/ir.d.ts.map +1 -0
- package/lib/ir.js +13 -0
- package/lib/ir.js.map +1 -0
- package/lib/locales/de.json +3 -0
- package/lib/locales/en.json +3 -0
- package/lib/locales/es.json +3 -0
- package/lib/locales/fr.json +3 -0
- package/lib/panel/core/dialogStyles.d.ts +13 -0
- package/lib/panel/core/dialogStyles.d.ts.map +1 -0
- package/lib/panel/core/dialogStyles.js +11 -0
- package/lib/panel/core/dialogStyles.js.map +1 -0
- package/lib/panel/core/index.d.ts +19 -0
- package/lib/panel/core/index.d.ts.map +1 -0
- package/lib/panel/core/index.js +18 -0
- package/lib/panel/core/index.js.map +1 -0
- package/lib/panel/core/isEditingField.d.ts +17 -0
- package/lib/panel/core/isEditingField.d.ts.map +1 -0
- package/lib/panel/core/isEditingField.js +25 -0
- package/lib/panel/core/isEditingField.js.map +1 -0
- package/lib/panel/core/panelStyles.d.ts +242 -0
- package/lib/panel/core/panelStyles.d.ts.map +1 -0
- package/lib/panel/core/panelStyles.js +228 -0
- package/lib/panel/core/panelStyles.js.map +1 -0
- package/lib/panel/core/rowSpacers.d.ts +38 -0
- package/lib/panel/core/rowSpacers.d.ts.map +1 -0
- package/lib/panel/core/rowSpacers.js +31 -0
- package/lib/panel/core/rowSpacers.js.map +1 -0
- package/lib/panel/core/statusBar.d.ts +44 -0
- package/lib/panel/core/statusBar.d.ts.map +1 -0
- package/lib/panel/core/statusBar.js +40 -0
- package/lib/panel/core/statusBar.js.map +1 -0
- package/lib/panel/core/textFilter.d.ts +22 -0
- package/lib/panel/core/textFilter.d.ts.map +1 -0
- package/lib/panel/core/textFilter.js +32 -0
- package/lib/panel/core/textFilter.js.map +1 -0
- package/lib/panel/core/yieldToPainting.d.ts +17 -0
- package/lib/panel/core/yieldToPainting.d.ts.map +1 -0
- package/lib/panel/core/yieldToPainting.js +21 -0
- package/lib/panel/core/yieldToPainting.js.map +1 -0
- package/lib/panel/ui/AboutDialogFrame.d.ts +36 -0
- package/lib/panel/ui/AboutDialogFrame.d.ts.map +1 -0
- package/lib/panel/ui/AboutDialogFrame.js +43 -0
- package/lib/panel/ui/AboutDialogFrame.js.map +1 -0
- package/lib/panel/ui/ClearButton.d.ts +28 -0
- package/lib/panel/ui/ClearButton.d.ts.map +1 -0
- package/lib/panel/ui/ClearButton.js +23 -0
- package/lib/panel/ui/ClearButton.js.map +1 -0
- package/lib/panel/ui/DocumentationDialogFrame.d.ts +39 -0
- package/lib/panel/ui/DocumentationDialogFrame.d.ts.map +1 -0
- package/lib/panel/ui/DocumentationDialogFrame.js +29 -0
- package/lib/panel/ui/DocumentationDialogFrame.js.map +1 -0
- package/lib/panel/ui/FilterInput.d.ts +31 -0
- package/lib/panel/ui/FilterInput.d.ts.map +1 -0
- package/lib/panel/ui/FilterInput.js +23 -0
- package/lib/panel/ui/FilterInput.js.map +1 -0
- package/lib/panel/ui/HelpLabel.d.ts +24 -0
- package/lib/panel/ui/HelpLabel.d.ts.map +1 -0
- package/lib/panel/ui/HelpLabel.js +23 -0
- package/lib/panel/ui/HelpLabel.js.map +1 -0
- package/lib/panel/ui/PanelMessage.d.ts +41 -0
- package/lib/panel/ui/PanelMessage.d.ts.map +1 -0
- package/lib/panel/ui/PanelMessage.js +30 -0
- package/lib/panel/ui/PanelMessage.js.map +1 -0
- package/lib/panel/ui/PanelRail.d.ts +41 -0
- package/lib/panel/ui/PanelRail.d.ts.map +1 -0
- package/lib/panel/ui/PanelRail.js +12 -0
- package/lib/panel/ui/PanelRail.js.map +1 -0
- package/lib/panel/ui/Section.d.ts +25 -0
- package/lib/panel/ui/Section.d.ts.map +1 -0
- package/lib/panel/ui/Section.js +41 -0
- package/lib/panel/ui/Section.js.map +1 -0
- package/lib/panel/ui/SidePanelStack.d.ts +62 -0
- package/lib/panel/ui/SidePanelStack.d.ts.map +1 -0
- package/lib/panel/ui/SidePanelStack.js +40 -0
- package/lib/panel/ui/SidePanelStack.js.map +1 -0
- package/lib/panel/ui/SpectrumColorSwatch.d.ts +33 -0
- package/lib/panel/ui/SpectrumColorSwatch.d.ts.map +1 -0
- package/lib/panel/ui/SpectrumColorSwatch.js +76 -0
- package/lib/panel/ui/SpectrumColorSwatch.js.map +1 -0
- package/lib/panel/ui/index.d.ts +37 -0
- package/lib/panel/ui/index.d.ts.map +1 -0
- package/lib/panel/ui/index.js +24 -0
- package/lib/panel/ui/index.js.map +1 -0
- package/lib/panel/ui/useConfirmOnEnter.d.ts +19 -0
- package/lib/panel/ui/useConfirmOnEnter.d.ts.map +1 -0
- package/lib/panel/ui/useConfirmOnEnter.js +64 -0
- package/lib/panel/ui/useConfirmOnEnter.js.map +1 -0
- package/lib/panel/ui/useFilterBox.d.ts +23 -0
- package/lib/panel/ui/useFilterBox.d.ts.map +1 -0
- package/lib/panel/ui/useFilterBox.js +22 -0
- package/lib/panel/ui/useFilterBox.js.map +1 -0
- package/lib/panel/ui/useVirtualRows.d.ts +46 -0
- package/lib/panel/ui/useVirtualRows.d.ts.map +1 -0
- package/lib/panel/ui/useVirtualRows.js +56 -0
- package/lib/panel/ui/useVirtualRows.js.map +1 -0
- package/lib/panel/ui/useVirtualWindowRows.d.ts +40 -0
- package/lib/panel/ui/useVirtualWindowRows.d.ts.map +1 -0
- package/lib/panel/ui/useVirtualWindowRows.js +65 -0
- package/lib/panel/ui/useVirtualWindowRows.js.map +1 -0
- package/lib/structure/core/conformerBoltzmann.d.ts +56 -0
- package/lib/structure/core/conformerBoltzmann.d.ts.map +1 -0
- package/lib/structure/core/conformerBoltzmann.js +96 -0
- package/lib/structure/core/conformerBoltzmann.js.map +1 -0
- package/lib/structure/core/conformerEnergy.d.ts +69 -0
- package/lib/structure/core/conformerEnergy.d.ts.map +1 -0
- package/lib/structure/core/conformerEnergy.js +47 -0
- package/lib/structure/core/conformerEnergy.js.map +1 -0
- package/lib/structure/core/index.d.ts +3 -0
- package/lib/structure/core/index.d.ts.map +1 -1
- package/lib/structure/core/index.js +2 -0
- package/lib/structure/core/index.js.map +1 -1
- package/lib/structure/ui/ConformerTable.d.ts +73 -0
- package/lib/structure/ui/ConformerTable.d.ts.map +1 -0
- package/lib/structure/ui/ConformerTable.js +259 -0
- package/lib/structure/ui/ConformerTable.js.map +1 -0
- package/lib/structure/ui/conformerColumns.d.ts +30 -0
- package/lib/structure/ui/conformerColumns.d.ts.map +1 -0
- package/lib/structure/ui/conformerColumns.js +37 -0
- package/lib/structure/ui/conformerColumns.js.map +1 -0
- package/lib/ui.d.ts +5 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +3 -0
- package/lib/ui.js.map +1 -1
- package/package.json +8 -1
- package/src/chart/core/axisLabels.ts +117 -0
- package/src/chart/core/boxLayout.ts +126 -0
- package/src/chart/core/chartAxisScale.ts +92 -10
- package/src/chart/core/chartDomain.ts +185 -0
- package/src/chart/core/chartGeometry.ts +159 -0
- package/src/chart/core/chartPane.ts +10 -0
- package/src/chart/core/chartScale.ts +7 -4
- package/src/chart/core/chartTheme.ts +161 -0
- package/src/chart/core/chartViewport.ts +40 -13
- package/src/chart/core/guidePlacement.ts +66 -0
- package/src/chart/core/index.ts +121 -2
- package/src/chart/core/labelStack.ts +72 -0
- package/src/chart/core/legendBox.ts +263 -0
- package/src/chart/core/selectionGeometry.ts +68 -0
- package/src/chart/core/spectrumColor.ts +129 -0
- package/src/chart/core/stackCapacity.ts +162 -0
- package/src/chart/core/svgPoint.ts +77 -0
- package/src/chart/core/tracePath.ts +228 -0
- package/src/chart/core/trackerReadout.ts +78 -0
- package/src/chart/core/viewTransform.ts +287 -0
- package/src/chart/core/zoomDomain.ts +235 -0
- package/src/chart/ui/Axes.tsx +361 -0
- package/src/chart/ui/AxisGuide.tsx +187 -0
- package/src/chart/ui/ChartStack.tsx +130 -0
- package/src/chart/ui/ChartTracker.tsx +101 -0
- package/src/chart/ui/PlotCaption.tsx +108 -0
- package/src/chart/ui/SelectionRect.tsx +52 -0
- package/src/chart/ui/TraceLegend.tsx +193 -0
- package/src/chart/ui/chartGestures.ts +270 -0
- package/src/chart/ui/chartStackLevel.tsx +210 -0
- package/src/chart/ui/chartSurface.ts +66 -0
- package/src/chart/ui/index.ts +35 -0
- package/src/chart/ui/useChartPointer.ts +223 -0
- package/src/chart/ui/useChartSize.ts +115 -0
- package/src/chart/ui/useChartWindow.ts +240 -0
- package/src/chart/ui/useChartZoom.ts +255 -0
- package/src/chart/ui/useWheelListener.ts +62 -0
- package/src/chrome/ui/AccountButton.tsx +185 -0
- package/src/chrome/ui/index.ts +2 -0
- package/src/clipboard/core/copyPng.ts +20 -0
- package/src/clipboard/core/index.ts +1 -0
- package/src/clipboard/ui/ClickToCopy.tsx +9 -1
- package/src/core.ts +1 -0
- package/src/download/core/exportStyles.ts +20 -0
- package/src/download/core/imageResolution.ts +118 -0
- package/src/download/core/index.ts +34 -0
- package/src/download/core/pictureExport.ts +207 -0
- package/src/download/core/stackedDrawing.ts +108 -0
- package/src/download/core/svgBounds.ts +80 -0
- package/src/download/core/svgNamespace.ts +9 -0
- package/src/download/core/svgToPng.ts +121 -0
- package/src/download/core/svgToString.ts +95 -0
- package/src/download/ui/ExportDialogFrame.tsx +86 -0
- package/src/download/ui/ExportImageDialog.tsx +91 -0
- package/src/download/ui/ExportNameField.tsx +148 -0
- package/src/download/ui/ExportPictureSection.tsx +142 -0
- package/src/download/ui/index.ts +11 -0
- package/src/download/ui/useDrawingBox.ts +37 -0
- package/src/error/core/describeSource.ts +18 -0
- package/src/error/core/index.ts +1 -0
- package/src/help/ui/HelpBody.tsx +41 -2
- package/src/help/ui/index.ts +6 -1
- package/src/ir/core/analysisSpectra.ts +231 -0
- package/src/ir/core/assignBands.ts +144 -0
- package/src/ir/core/bandAssignments.ts +329 -0
- package/src/ir/core/bandLabelPlan.ts +194 -0
- package/src/ir/core/detectIrFormat.ts +139 -0
- package/src/ir/core/downloadSpectra.ts +57 -0
- package/src/ir/core/fromJcamp.ts +70 -0
- package/src/ir/core/fromSpc.ts +61 -0
- package/src/ir/core/index.ts +113 -0
- package/src/ir/core/irBand.ts +57 -0
- package/src/ir/core/irCommands.ts +154 -0
- package/src/ir/core/irDomain.ts +163 -0
- package/src/ir/core/irEditorApi.ts +44 -0
- package/src/ir/core/irFormat.ts +57 -0
- package/src/ir/core/irMode.ts +203 -0
- package/src/ir/core/irReducer.ts +273 -0
- package/src/ir/core/irSidePanels.ts +20 -0
- package/src/ir/core/irSpectrum.ts +155 -0
- package/src/ir/core/irState.ts +173 -0
- package/src/ir/core/loadIrSpectra.ts +79 -0
- package/src/ir/core/nearestBand.ts +57 -0
- package/src/ir/core/pickBands.ts +181 -0
- package/src/ir/core/spectrumJcamp.ts +178 -0
- package/src/ir/core/toIrSpectrum.ts +102 -0
- package/src/ir/ui/BandMarks.tsx +166 -0
- package/src/ir/ui/BandsPanel.tsx +271 -0
- package/src/ir/ui/IrAboutDialog.tsx +121 -0
- package/src/ir/ui/IrCanvas.tsx +91 -0
- package/src/ir/ui/IrChart.tsx +215 -0
- package/src/ir/ui/IrCommandProvider.tsx +32 -0
- package/src/ir/ui/IrCommandTooltip.tsx +36 -0
- package/src/ir/ui/IrDocumentationDialog.tsx +174 -0
- package/src/ir/ui/IrEditor.tsx +99 -0
- package/src/ir/ui/IrHeader.tsx +39 -0
- package/src/ir/ui/IrLogo.tsx +49 -0
- package/src/ir/ui/IrPointerTracker.tsx +102 -0
- package/src/ir/ui/IrShell.tsx +285 -0
- package/src/ir/ui/IrSidePanel.tsx +78 -0
- package/src/ir/ui/IrStateProvider.tsx +32 -0
- package/src/ir/ui/IrStatusBar.tsx +97 -0
- package/src/ir/ui/IrToolbar.tsx +102 -0
- package/src/ir/ui/IrTraces.tsx +134 -0
- package/src/ir/ui/MetadataPanel.tsx +88 -0
- package/src/ir/ui/SpectraPanel.tsx +114 -0
- package/src/ir/ui/SpectrumRow.tsx +127 -0
- package/src/ir/ui/index.ts +56 -0
- package/src/ir/ui/irActions.ts +103 -0
- package/src/ir/ui/irChartProps.ts +118 -0
- package/src/ir/ui/irCommandContext.tsx +62 -0
- package/src/ir/ui/irStateContext.ts +48 -0
- package/src/ir/ui/useIrEditor.ts +139 -0
- package/src/ir/ui/useIrPointer.ts +109 -0
- package/src/ir/ui/useIrShortcuts.ts +95 -0
- package/src/ir/ui/useIrZoom.ts +86 -0
- package/src/ir.ts +13 -0
- package/src/locales/de.json +3 -0
- package/src/locales/en.json +3 -0
- package/src/locales/es.json +3 -0
- package/src/locales/fr.json +3 -0
- package/src/panel/core/dialogStyles.ts +11 -0
- package/src/panel/core/index.ts +47 -0
- package/src/panel/core/isEditingField.ts +23 -0
- package/src/panel/core/panelStyles.ts +248 -0
- package/src/panel/core/rowSpacers.ts +50 -0
- package/src/panel/core/statusBar.ts +48 -0
- package/src/panel/core/textFilter.ts +33 -0
- package/src/panel/core/yieldToPainting.ts +20 -0
- package/src/panel/ui/AboutDialogFrame.tsx +100 -0
- package/src/panel/ui/ClearButton.tsx +42 -0
- package/src/panel/ui/DocumentationDialogFrame.tsx +86 -0
- package/src/panel/ui/FilterInput.tsx +60 -0
- package/src/panel/ui/HelpLabel.tsx +43 -0
- package/src/panel/ui/PanelMessage.tsx +64 -0
- package/src/panel/ui/PanelRail.tsx +64 -0
- package/src/panel/ui/Section.tsx +66 -0
- package/src/panel/ui/SidePanelStack.tsx +109 -0
- package/src/panel/ui/SpectrumColorSwatch.tsx +119 -0
- package/src/panel/ui/index.ts +47 -0
- package/src/panel/ui/useConfirmOnEnter.ts +68 -0
- package/src/panel/ui/useFilterBox.ts +35 -0
- package/src/panel/ui/useVirtualRows.ts +82 -0
- package/src/panel/ui/useVirtualWindowRows.ts +86 -0
- package/src/structure/core/conformerBoltzmann.ts +102 -0
- package/src/structure/core/conformerEnergy.ts +97 -0
- package/src/structure/core/index.ts +15 -0
- package/src/structure/ui/ConformerTable.tsx +429 -0
- package/src/structure/ui/conformerColumns.ts +55 -0
- package/src/ui.ts +13 -0
- package/styles/chrome.css +55 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** How big a picture is written out, as a multiple of the size it is drawn at. */
|
|
2
|
+
export interface ImageResolution {
|
|
3
|
+
/** Identifies the resolution in a picker. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** What the option reads. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** How many pixels each drawing unit becomes. */
|
|
8
|
+
scale: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The sizes a picture leaves the editor at.
|
|
13
|
+
*
|
|
14
|
+
* A drawing unit is about a screen pixel, so the multipliers read as what the
|
|
15
|
+
* picture is for rather than as numbers: what is on screen, the same again on a
|
|
16
|
+
* retina display, and the two steps up a figure needs to survive being printed
|
|
17
|
+
* or thrown on a wall.
|
|
18
|
+
*/
|
|
19
|
+
export const IMAGE_RESOLUTIONS = [
|
|
20
|
+
{ id: 'screen', label: 'Screen (1×)', scale: 1 },
|
|
21
|
+
{ id: 'retina', label: 'Retina (2×)', scale: 2 },
|
|
22
|
+
{ id: 'print', label: 'Print (4×)', scale: 4 },
|
|
23
|
+
{ id: 'poster', label: 'Poster (8×)', scale: 8 },
|
|
24
|
+
] as const satisfies readonly ImageResolution[];
|
|
25
|
+
|
|
26
|
+
/** One of the resolutions offered. */
|
|
27
|
+
export type ImageResolutionId = (typeof IMAGE_RESOLUTIONS)[number]['id'];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The resolution a picture is written out at unless another is picked: what is
|
|
31
|
+
* on screen, doubled, which is what a picture pasted into a document wants.
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_IMAGE_RESOLUTION = IMAGE_RESOLUTIONS[1];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Longest side a browser rasterizes reliably.
|
|
37
|
+
*
|
|
38
|
+
* Above roughly this, Safari and Chrome quietly hand back an empty canvas
|
|
39
|
+
* instead of refusing, so the picture would be saved blank.
|
|
40
|
+
*/
|
|
41
|
+
const MAXIMUM_SIDE = 8192;
|
|
42
|
+
|
|
43
|
+
/** Most pixels a rasterized picture is allowed to hold. */
|
|
44
|
+
const MAXIMUM_PIXELS = 32 * 1024 * 1024;
|
|
45
|
+
|
|
46
|
+
/** How big a picture comes out, in pixels. */
|
|
47
|
+
export interface ImageSize {
|
|
48
|
+
/** Width of the picture, in pixels. */
|
|
49
|
+
width: number;
|
|
50
|
+
/** Height of the picture, in pixels. */
|
|
51
|
+
height: number;
|
|
52
|
+
/**
|
|
53
|
+
* What each drawing unit was actually worth. Below the resolution that was
|
|
54
|
+
* asked for when it would have made a picture too big to rasterize.
|
|
55
|
+
*/
|
|
56
|
+
scale: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* How big a rectangle of the drawing comes out at a given resolution.
|
|
61
|
+
*
|
|
62
|
+
* The resolution is a wish rather than an instruction: a wide glycan asked for
|
|
63
|
+
* at 8× would run past what a browser can rasterize and come back blank, so the
|
|
64
|
+
* scale is brought down until the picture fits instead. The scale it settled on
|
|
65
|
+
* comes back with the size, so what will actually be written can be shown
|
|
66
|
+
* before it is.
|
|
67
|
+
* @param box - The rectangle being written out.
|
|
68
|
+
* @param box.width - How wide it is, in drawing units.
|
|
69
|
+
* @param box.height - How tall it is, in drawing units.
|
|
70
|
+
* @param scale - How many pixels each drawing unit should become.
|
|
71
|
+
* @returns The size, and the scale it was reached at.
|
|
72
|
+
*/
|
|
73
|
+
export function imageSize(
|
|
74
|
+
box: { width: number; height: number },
|
|
75
|
+
scale: number,
|
|
76
|
+
): ImageSize {
|
|
77
|
+
const wanted = Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
78
|
+
const width = Math.max(box.width, 1);
|
|
79
|
+
const height = Math.max(box.height, 1);
|
|
80
|
+
|
|
81
|
+
const limit = Math.min(
|
|
82
|
+
MAXIMUM_SIDE / width,
|
|
83
|
+
MAXIMUM_SIDE / height,
|
|
84
|
+
Math.sqrt(MAXIMUM_PIXELS / (width * height)),
|
|
85
|
+
);
|
|
86
|
+
const used = Math.min(wanted, limit);
|
|
87
|
+
// A picture held back by the limit is rounded down rather than to the nearest
|
|
88
|
+
// pixel, so rounding cannot put it back over what it was held to.
|
|
89
|
+
const toPixels = used < wanted ? Math.floor : Math.round;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
width: Math.max(1, toPixels(width * used)),
|
|
93
|
+
height: Math.max(1, toPixels(height * used)),
|
|
94
|
+
scale: used,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The resolution an identifier stands for.
|
|
100
|
+
* @param id - What was picked.
|
|
101
|
+
* @returns The resolution, falling back to the default one.
|
|
102
|
+
*/
|
|
103
|
+
export function imageResolution(id: string): ImageResolution {
|
|
104
|
+
return (
|
|
105
|
+
IMAGE_RESOLUTIONS.find((resolution) => resolution.id === id) ??
|
|
106
|
+
DEFAULT_IMAGE_RESOLUTION
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A size, written the way it is shown next to the resolution it comes from.
|
|
112
|
+
* @param size - The size to write, `null` when nothing is drawn.
|
|
113
|
+
* @returns The text, e.g. `1440 × 620 px`.
|
|
114
|
+
*/
|
|
115
|
+
export function formatImageSize(size: ImageSize | null): string {
|
|
116
|
+
if (!size) return 'nothing to export';
|
|
117
|
+
return `${size.width} × ${size.height} px`;
|
|
118
|
+
}
|
|
@@ -37,3 +37,37 @@ export {
|
|
|
37
37
|
figureSize,
|
|
38
38
|
} from './figureTarget.ts';
|
|
39
39
|
export { sanitizeFileName } from './sanitizeFileName.ts';
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
exportButtonsStyle,
|
|
43
|
+
exportNoteStyle,
|
|
44
|
+
exportSectionStyle,
|
|
45
|
+
} from './exportStyles.ts';
|
|
46
|
+
export type {
|
|
47
|
+
ImageResolution,
|
|
48
|
+
ImageResolutionId,
|
|
49
|
+
ImageSize,
|
|
50
|
+
} from './imageResolution.ts';
|
|
51
|
+
export {
|
|
52
|
+
DEFAULT_IMAGE_RESOLUTION,
|
|
53
|
+
IMAGE_RESOLUTIONS,
|
|
54
|
+
formatImageSize,
|
|
55
|
+
imageResolution,
|
|
56
|
+
imageSize,
|
|
57
|
+
} from './imageResolution.ts';
|
|
58
|
+
export type { PictureFrame, PictureOptions } from './pictureExport.ts';
|
|
59
|
+
export {
|
|
60
|
+
PICTURE_PADDING,
|
|
61
|
+
copyPicture,
|
|
62
|
+
pictureSize,
|
|
63
|
+
savePngPicture,
|
|
64
|
+
saveSvgPicture,
|
|
65
|
+
} from './pictureExport.ts';
|
|
66
|
+
export { drawingIn, stackDrawings } from './stackedDrawing.ts';
|
|
67
|
+
export type { SvgBox } from './svgBounds.ts';
|
|
68
|
+
export { CONTENT_ATTRIBUTE, contentBox, elementBox } from './svgBounds.ts';
|
|
69
|
+
export { SVG_NAMESPACE } from './svgNamespace.ts';
|
|
70
|
+
export type { PngOptions } from './svgToPng.ts';
|
|
71
|
+
export { svgToPng } from './svgToPng.ts';
|
|
72
|
+
export type { SvgDocumentOptions } from './svgToString.ts';
|
|
73
|
+
export { svgToString } from './svgToString.ts';
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { writeImageToClipboard } from '../../clipboard/core/copyPng.ts';
|
|
2
|
+
|
|
3
|
+
import { downloadBlob } from './downloadBlob.ts';
|
|
4
|
+
import { downloadText } from './downloadText.ts';
|
|
5
|
+
import type { ImageSize } from './imageResolution.ts';
|
|
6
|
+
import { imageSize } from './imageResolution.ts';
|
|
7
|
+
import type { SvgBox } from './svgBounds.ts';
|
|
8
|
+
import { contentBox, elementBox } from './svgBounds.ts';
|
|
9
|
+
import { svgToPng } from './svgToPng.ts';
|
|
10
|
+
import { svgToString } from './svgToString.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Room left around a drawing in a written-out picture, in drawing units.
|
|
14
|
+
*
|
|
15
|
+
* Enough that a name written under the bottom of the drawing, and the stroke
|
|
16
|
+
* around its outermost mark, are inside the picture rather than against its
|
|
17
|
+
* edge.
|
|
18
|
+
*/
|
|
19
|
+
export const PICTURE_PADDING = 12;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What the picture is of: the drawing, or the element it is drawn in.
|
|
23
|
+
*
|
|
24
|
+
* `content` measures the drawing and ignores the canvas around it, which is
|
|
25
|
+
* what a drawing surface wants — it is mostly empty space, panned and zoomed to
|
|
26
|
+
* wherever it was last left, and none of that belongs in a file. `element`
|
|
27
|
+
* takes the element as it is laid out, which is what a chart wants: its axes
|
|
28
|
+
* are drawn to the box it was given, so the box *is* the picture and measuring
|
|
29
|
+
* the marks inside it would crop the frame to wherever the data happens to
|
|
30
|
+
* reach.
|
|
31
|
+
*/
|
|
32
|
+
export type PictureFrame = 'content' | 'element';
|
|
33
|
+
|
|
34
|
+
export interface PictureOptions {
|
|
35
|
+
/**
|
|
36
|
+
* How many pixels each drawing unit becomes.
|
|
37
|
+
* @default 2
|
|
38
|
+
*/
|
|
39
|
+
scale?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The name saved files take, without their extension.
|
|
42
|
+
* @default 'picture'
|
|
43
|
+
*/
|
|
44
|
+
filename?: string;
|
|
45
|
+
/**
|
|
46
|
+
* What the picture is read out as, in place of the instructions the element
|
|
47
|
+
* carries for whoever is working it.
|
|
48
|
+
* @default 'Drawing'
|
|
49
|
+
*/
|
|
50
|
+
label?: string;
|
|
51
|
+
/**
|
|
52
|
+
* What the picture is of.
|
|
53
|
+
* @default 'content'
|
|
54
|
+
*/
|
|
55
|
+
frame?: PictureFrame;
|
|
56
|
+
/**
|
|
57
|
+
* Room left around the drawing, in drawing units. Ignored when the picture is
|
|
58
|
+
* the element, which is already the size it wants to be.
|
|
59
|
+
* @default PICTURE_PADDING
|
|
60
|
+
*/
|
|
61
|
+
padding?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* How big the drawing comes out at a resolution, before it is written out.
|
|
66
|
+
*
|
|
67
|
+
* What is measured is what the picture will be of rather than whatever is on
|
|
68
|
+
* screen, so the answer does not change when the window is resized or the
|
|
69
|
+
* drawing panned — the size shown next to the resolution is the size of the
|
|
70
|
+
* file that is about to be written.
|
|
71
|
+
* @param svg - The element, as it is rendered.
|
|
72
|
+
* @param scale - How many pixels each drawing unit becomes.
|
|
73
|
+
* @param options - What the picture is of.
|
|
74
|
+
* @returns The size, or `null` when nothing is drawn.
|
|
75
|
+
*/
|
|
76
|
+
export function pictureSize(
|
|
77
|
+
svg: SVGSVGElement | null,
|
|
78
|
+
scale: number,
|
|
79
|
+
options: Pick<PictureOptions, 'frame' | 'padding'> = {},
|
|
80
|
+
): ImageSize | null {
|
|
81
|
+
const box = svg && pictureBox(svg, options);
|
|
82
|
+
return box && imageSize(box, scale);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Put the drawing on the clipboard as a PNG.
|
|
87
|
+
*
|
|
88
|
+
* The rasterization is handed to the clipboard as a promise rather than awaited
|
|
89
|
+
* first: Safari only allows a clipboard write the click itself started.
|
|
90
|
+
* @param svg - The element, as it is rendered.
|
|
91
|
+
* @param options - How big to make it.
|
|
92
|
+
* @returns Whether it was copied. `false` when nothing is drawn, and in a
|
|
93
|
+
* browser whose clipboard takes text only.
|
|
94
|
+
*/
|
|
95
|
+
export async function copyPicture(
|
|
96
|
+
svg: SVGSVGElement | null,
|
|
97
|
+
options: PictureOptions = {},
|
|
98
|
+
): Promise<boolean> {
|
|
99
|
+
const written = describe(svg, options);
|
|
100
|
+
if (!written) return false;
|
|
101
|
+
return await writeImageToClipboard(svgToPng(written.svg, written.png));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Save the drawing as a PNG.
|
|
106
|
+
* @param svg - The element, as it is rendered.
|
|
107
|
+
* @param options - How big to make it, and what to call it.
|
|
108
|
+
* @returns Whether it was saved. `false` when nothing is drawn.
|
|
109
|
+
*/
|
|
110
|
+
export async function savePngPicture(
|
|
111
|
+
svg: SVGSVGElement | null,
|
|
112
|
+
options: PictureOptions = {},
|
|
113
|
+
): Promise<boolean> {
|
|
114
|
+
const written = describe(svg, options);
|
|
115
|
+
if (!written) return false;
|
|
116
|
+
downloadBlob(await svgToPng(written.svg, written.png), `${written.name}.png`);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Save the drawing as an SVG.
|
|
122
|
+
*
|
|
123
|
+
* The resolution is carried into the file as the size it opens at, but the
|
|
124
|
+
* shapes stay shapes: an SVG printed at any size is drawn again rather than
|
|
125
|
+
* enlarged, which is the reason to prefer it wherever it can go.
|
|
126
|
+
* @param svg - The element, as it is rendered.
|
|
127
|
+
* @param options - How big to make it, and what to call it.
|
|
128
|
+
* @returns Whether it was saved. `false` when nothing is drawn.
|
|
129
|
+
*/
|
|
130
|
+
export function saveSvgPicture(
|
|
131
|
+
svg: SVGSVGElement | null,
|
|
132
|
+
options: PictureOptions = {},
|
|
133
|
+
): boolean {
|
|
134
|
+
const written = describe(svg, options);
|
|
135
|
+
if (!written) return false;
|
|
136
|
+
downloadText(
|
|
137
|
+
svgToString(written.svg, written.png),
|
|
138
|
+
`${written.name}.svg`,
|
|
139
|
+
'image/svg+xml',
|
|
140
|
+
);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** What a picture is written from: the element, its rectangle and its size. */
|
|
145
|
+
interface WrittenPicture {
|
|
146
|
+
/** The element the picture is taken of. */
|
|
147
|
+
svg: SVGSVGElement;
|
|
148
|
+
/**
|
|
149
|
+
* The part of it to write out, and how big, as both writers take it. The
|
|
150
|
+
* rectangle is `null` for a picture of the element, which is written out
|
|
151
|
+
* through whatever `viewBox` it already carries.
|
|
152
|
+
*/
|
|
153
|
+
png: { box: SvgBox | null; width: number; height: number; label: string };
|
|
154
|
+
/** The name a file holding it takes, without its extension. */
|
|
155
|
+
name: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The rectangle a picture of the element would cover, in drawing units.
|
|
160
|
+
* @param svg - The element, as it is rendered.
|
|
161
|
+
* @param options - What the picture is of.
|
|
162
|
+
* @returns The rectangle, or `null` when nothing is drawn.
|
|
163
|
+
*/
|
|
164
|
+
function pictureBox(
|
|
165
|
+
svg: SVGSVGElement,
|
|
166
|
+
options: Pick<PictureOptions, 'frame' | 'padding'>,
|
|
167
|
+
): SvgBox | null {
|
|
168
|
+
const { frame = 'content', padding = PICTURE_PADDING } = options;
|
|
169
|
+
return frame === 'content' ? contentBox(svg, padding) : elementBox(svg);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Work out what a picture of the element would be.
|
|
174
|
+
* @param svg - The element, as it is rendered.
|
|
175
|
+
* @param options - How big to make it, and what to call it.
|
|
176
|
+
* @returns The element and the rectangle to write out, or `null` when nothing
|
|
177
|
+
* is drawn.
|
|
178
|
+
*/
|
|
179
|
+
function describe(
|
|
180
|
+
svg: SVGSVGElement | null,
|
|
181
|
+
options: PictureOptions,
|
|
182
|
+
): WrittenPicture | null {
|
|
183
|
+
const {
|
|
184
|
+
scale = 2,
|
|
185
|
+
filename = 'picture',
|
|
186
|
+
label = 'Drawing',
|
|
187
|
+
frame = 'content',
|
|
188
|
+
} = options;
|
|
189
|
+
if (!svg) return null;
|
|
190
|
+
|
|
191
|
+
const box = pictureBox(svg, options);
|
|
192
|
+
if (!box) return null;
|
|
193
|
+
|
|
194
|
+
const size = imageSize(box, scale);
|
|
195
|
+
return {
|
|
196
|
+
svg,
|
|
197
|
+
// A picture of the element keeps the `viewBox` the element was drawn with,
|
|
198
|
+
// which is the one thing that makes its own scaling come out right.
|
|
199
|
+
png: {
|
|
200
|
+
box: frame === 'content' ? box : null,
|
|
201
|
+
width: size.width,
|
|
202
|
+
height: size.height,
|
|
203
|
+
label,
|
|
204
|
+
},
|
|
205
|
+
name: filename,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { CHART_PANE_ATTRIBUTE } from '../../chart/core/chartPane.ts';
|
|
2
|
+
|
|
3
|
+
import { SVG_NAMESPACE } from './svgNamespace.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The drawing a picture of an editor is taken of, found in the box it sits in.
|
|
7
|
+
*
|
|
8
|
+
* A drawing is laid out again on every resize, so nothing is held onto but the
|
|
9
|
+
* box, and what is in it is read at the moment a button is pressed. The box is
|
|
10
|
+
* asked for rather than the whole editor because an editor is full of SVG —
|
|
11
|
+
* every icon in every toolbar is one — and the first found in it would be a
|
|
12
|
+
* picture of a magnifying glass.
|
|
13
|
+
*
|
|
14
|
+
* A box holding a stack of charts holds a drawing per pane, and the picture is
|
|
15
|
+
* all of them: with a run open, a chromatogram stands over the spectrum taken
|
|
16
|
+
* where its cursor is, and that pairing *is* the figure — a picture of the
|
|
17
|
+
* chromatogram alone, saved under the spectrum's name, is the wrong answer to
|
|
18
|
+
* every question it was asked. They are composed into one SVG here rather than
|
|
19
|
+
* rasterized separately, so the same writers save it, at any resolution, as
|
|
20
|
+
* either a PNG or a vector.
|
|
21
|
+
* @param box - The box the drawing sits in, `null` before it is mounted.
|
|
22
|
+
* @returns The drawing, the panes composed into one, or `null` when the box
|
|
23
|
+
* holds nothing that has been laid out.
|
|
24
|
+
*/
|
|
25
|
+
export function drawingIn(box: HTMLElement | null): SVGSVGElement | null {
|
|
26
|
+
if (box === null) return null;
|
|
27
|
+
|
|
28
|
+
const panes = box.querySelectorAll<HTMLElement>(
|
|
29
|
+
`[${CSS.escape(CHART_PANE_ATTRIBUTE)}]`,
|
|
30
|
+
);
|
|
31
|
+
if (panes.length === 0) return box.querySelector('svg');
|
|
32
|
+
|
|
33
|
+
return stackDrawings(paneDrawings(panes));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Compose several drawings into one, stacked in the order they were given.
|
|
38
|
+
*
|
|
39
|
+
* Each becomes a nested `<svg>` placed at the height the ones above it reached
|
|
40
|
+
* and sized as it is on screen, which is what keeps its own `viewBox` scaling
|
|
41
|
+
* right — a chart is drawn to the box it was given, so a pane copied at any
|
|
42
|
+
* other size would have its axes stretched away from its trace. The composite
|
|
43
|
+
* is never on the page, so it states its size in attributes: that is where
|
|
44
|
+
* `elementBox` reads it back from.
|
|
45
|
+
* @param drawings - What to stack, top to bottom.
|
|
46
|
+
* @returns The composite, the single drawing it was handed unchanged, or `null`
|
|
47
|
+
* when nothing among them has been laid out.
|
|
48
|
+
*/
|
|
49
|
+
export function stackDrawings(
|
|
50
|
+
drawings: readonly SVGSVGElement[],
|
|
51
|
+
): SVGSVGElement | null {
|
|
52
|
+
const first = drawings[0];
|
|
53
|
+
if (first === undefined) return null;
|
|
54
|
+
if (drawings.length === 1) return first;
|
|
55
|
+
|
|
56
|
+
const stacked = document.createElementNS(SVG_NAMESPACE, 'svg');
|
|
57
|
+
let width = 0;
|
|
58
|
+
let top = 0;
|
|
59
|
+
for (const drawing of drawings) {
|
|
60
|
+
const rect = drawing.getBoundingClientRect();
|
|
61
|
+
if (rect.width <= 0 || rect.height <= 0) continue;
|
|
62
|
+
|
|
63
|
+
const copy = drawing.cloneNode(true) as SVGSVGElement;
|
|
64
|
+
if (!copy.hasAttribute('viewBox')) {
|
|
65
|
+
copy.setAttribute(
|
|
66
|
+
'viewBox',
|
|
67
|
+
`0 0 ${round(rect.width)} ${round(rect.height)}`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
copy.setAttribute('x', '0');
|
|
71
|
+
copy.setAttribute('y', String(round(top)));
|
|
72
|
+
copy.setAttribute('width', String(round(rect.width)));
|
|
73
|
+
copy.setAttribute('height', String(round(rect.height)));
|
|
74
|
+
stacked.append(copy);
|
|
75
|
+
|
|
76
|
+
width = Math.max(width, rect.width);
|
|
77
|
+
top += rect.height;
|
|
78
|
+
}
|
|
79
|
+
if (top <= 0) return null;
|
|
80
|
+
|
|
81
|
+
stacked.setAttribute('width', String(round(width)));
|
|
82
|
+
stacked.setAttribute('height', String(round(top)));
|
|
83
|
+
stacked.setAttribute('viewBox', `0 0 ${round(width)} ${round(top)}`);
|
|
84
|
+
return stacked;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The drawing each pane of a stack holds.
|
|
89
|
+
* @param panes - The pane boxes, top to bottom.
|
|
90
|
+
* @returns One drawing per pane that holds one, in the order they are stacked.
|
|
91
|
+
*/
|
|
92
|
+
function paneDrawings(panes: Iterable<HTMLElement>): SVGSVGElement[] {
|
|
93
|
+
const found: SVGSVGElement[] = [];
|
|
94
|
+
for (const pane of panes) {
|
|
95
|
+
const drawing = pane.querySelector('svg');
|
|
96
|
+
if (drawing !== null) found.push(drawing);
|
|
97
|
+
}
|
|
98
|
+
return found;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A coordinate of the composite, short enough to read.
|
|
103
|
+
* @param value - The coordinate.
|
|
104
|
+
* @returns It, to two decimals.
|
|
105
|
+
*/
|
|
106
|
+
function round(value: number): number {
|
|
107
|
+
return Math.round(value * 100) / 100;
|
|
108
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** A rectangle of an SVG, in the units the drawing is laid out in. */
|
|
2
|
+
export interface SvgBox {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Marks the group holding what a drawing is of, as opposed to its canvas. */
|
|
10
|
+
export const CONTENT_ATTRIBUTE = 'data-export-content';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The rectangle the drawing itself occupies, rather than the one on screen.
|
|
14
|
+
*
|
|
15
|
+
* A canvas is mostly empty space to draw into: what is on screen is a window
|
|
16
|
+
* over it, wherever it was last panned to and however far it was zoomed. None
|
|
17
|
+
* of that belongs in a file, so a picture is written out from the drawing
|
|
18
|
+
* outwards — the group it is drawn in is measured, and the window is ignored.
|
|
19
|
+
* Whatever is written on it is measured with it, so a name hanging under the
|
|
20
|
+
* bottom of the drawing is not cut off.
|
|
21
|
+
*
|
|
22
|
+
* An SVG that marks no such group — a molecule depiction, which is drawn to the
|
|
23
|
+
* size of its box and nothing else — is measured whole. What is left out there
|
|
24
|
+
* is only the room the drawing already left around itself.
|
|
25
|
+
* @param svg - The element to measure, as it is rendered.
|
|
26
|
+
* @param padding - Room left around the symbols, in drawing units. Defaults to
|
|
27
|
+
* `0`.
|
|
28
|
+
* @returns The rectangle, or `null` when nothing is drawn or the element is not
|
|
29
|
+
* rendered — a measurement is only ever taken of something on screen.
|
|
30
|
+
*/
|
|
31
|
+
export function contentBox(svg: SVGSVGElement, padding = 0): SvgBox | null {
|
|
32
|
+
const marked = svg.querySelector(`[${CSS.escape(CONTENT_ATTRIBUTE)}]`);
|
|
33
|
+
const content = marked instanceof SVGGraphicsElement ? marked : svg;
|
|
34
|
+
|
|
35
|
+
const box = content.getBBox();
|
|
36
|
+
if (box.width <= 0 || box.height <= 0) return null;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
x: box.x - padding,
|
|
40
|
+
y: box.y - padding,
|
|
41
|
+
width: box.width + padding * 2,
|
|
42
|
+
height: box.height + padding * 2,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The rectangle the element itself covers, rather than the marks inside it.
|
|
48
|
+
*
|
|
49
|
+
* A chart is drawn to the box it was given — its axes reach the edges of it and
|
|
50
|
+
* its trace reaches wherever the data does — so the box is the picture, and
|
|
51
|
+
* measuring the marks would crop the frame off it. It is measured where it is
|
|
52
|
+
* on the page, and read off its own attributes where it is not: a picture of a
|
|
53
|
+
* stacked editor is composed out of the panes rather than being any one element
|
|
54
|
+
* on screen, so it never has a place on the page to be measured at and carries
|
|
55
|
+
* the size it was composed at instead.
|
|
56
|
+
* @param svg - The element to measure.
|
|
57
|
+
* @returns The rectangle, or `null` when it is neither laid out nor sized.
|
|
58
|
+
*/
|
|
59
|
+
export function elementBox(svg: SVGSVGElement): SvgBox | null {
|
|
60
|
+
const laidOut = svg.getBoundingClientRect();
|
|
61
|
+
if (laidOut.width > 0 && laidOut.height > 0) {
|
|
62
|
+
return { x: 0, y: 0, width: laidOut.width, height: laidOut.height };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const width = statedSide(svg, 'width');
|
|
66
|
+
const height = statedSide(svg, 'height');
|
|
67
|
+
if (width <= 0 || height <= 0) return null;
|
|
68
|
+
return { x: 0, y: 0, width, height };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A side the element states for itself, for one that is not on the page.
|
|
73
|
+
* @param svg - The element.
|
|
74
|
+
* @param name - Which side to read.
|
|
75
|
+
* @returns Its length in drawing units, `0` when it states none.
|
|
76
|
+
*/
|
|
77
|
+
function statedSide(svg: SVGSVGElement, name: 'width' | 'height'): number {
|
|
78
|
+
const stated = Number.parseFloat(svg.getAttribute(name) ?? '');
|
|
79
|
+
return Number.isFinite(stated) ? stated : 0;
|
|
80
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The namespace every SVG element is created in.
|
|
3
|
+
*
|
|
4
|
+
* `document.createElementNS` needs it to make an element the browser draws
|
|
5
|
+
* rather than an unknown tag, and a file written out needs it declared on the
|
|
6
|
+
* root or nothing will open it.
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line unicorn/prefer-https -- the SVG namespace is a fixed identifier, not a URL to fetch
|
|
9
|
+
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { SvgBox } from './svgBounds.ts';
|
|
2
|
+
import { svgToString } from './svgToString.ts';
|
|
3
|
+
|
|
4
|
+
/** How many device pixels a PNG gets per pixel the drawing is shown at. */
|
|
5
|
+
const DEFAULT_SCALE = 2;
|
|
6
|
+
|
|
7
|
+
export interface PngOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The rectangle of the drawing to rasterize, in drawing units.
|
|
10
|
+
* @default what the element is currently showing
|
|
11
|
+
*/
|
|
12
|
+
box?: SvgBox | null;
|
|
13
|
+
/**
|
|
14
|
+
* How wide the PNG is, in pixels.
|
|
15
|
+
* @default the width the element is drawn at, times `scale`
|
|
16
|
+
*/
|
|
17
|
+
width?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How tall the PNG is, in pixels.
|
|
20
|
+
* @default the height the element is drawn at, times `scale`
|
|
21
|
+
*/
|
|
22
|
+
height?: number;
|
|
23
|
+
/**
|
|
24
|
+
* How many device pixels to give each pixel of the drawing, when no size is
|
|
25
|
+
* given.
|
|
26
|
+
* @default 2
|
|
27
|
+
*/
|
|
28
|
+
scale?: number;
|
|
29
|
+
/**
|
|
30
|
+
* What the picture is read out as, in the document it is rasterized from.
|
|
31
|
+
* @default the label the element already carries
|
|
32
|
+
*/
|
|
33
|
+
label?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Rasterize a rendered SVG element to a PNG.
|
|
38
|
+
*
|
|
39
|
+
* This is the one place in the package a bitmap is made, and it is made only on
|
|
40
|
+
* the way out: everything is drawn as SVG so it stays sharp at any zoom, and a
|
|
41
|
+
* PNG exists for the places a vector cannot be pasted into. Asked for no size
|
|
42
|
+
* it is drawn at twice the size it is shown at, so it is still readable on a
|
|
43
|
+
* retina screen and survives being scaled up a little in a slide.
|
|
44
|
+
* @param svg - The element to rasterize, as it is rendered.
|
|
45
|
+
* @param options - What part of it to rasterize, and how big.
|
|
46
|
+
* @returns The PNG.
|
|
47
|
+
*/
|
|
48
|
+
export async function svgToPng(
|
|
49
|
+
svg: SVGSVGElement,
|
|
50
|
+
options: PngOptions = {},
|
|
51
|
+
): Promise<Blob> {
|
|
52
|
+
const { box = null, width, height, scale = DEFAULT_SCALE, label } = options;
|
|
53
|
+
|
|
54
|
+
const rendered = svg.getBoundingClientRect();
|
|
55
|
+
const pixelWidth = side(width ?? (box?.width ?? rendered.width) * scale);
|
|
56
|
+
const pixelHeight = side(height ?? (box?.height ?? rendered.height) * scale);
|
|
57
|
+
|
|
58
|
+
// The document is written at the size the PNG is asked for rather than blown
|
|
59
|
+
// up afterwards: the shapes are rasterized once, at the final size, so the
|
|
60
|
+
// symbols and their labels stay sharp however big the picture is.
|
|
61
|
+
const image = await loadImage(
|
|
62
|
+
svgToString(svg, { box, width: pixelWidth, height: pixelHeight, label }),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const canvas = document.createElement('canvas');
|
|
66
|
+
canvas.width = pixelWidth;
|
|
67
|
+
canvas.height = pixelHeight;
|
|
68
|
+
|
|
69
|
+
const context = canvas.getContext('2d');
|
|
70
|
+
if (!context) throw new Error('The browser gave no drawing context.');
|
|
71
|
+
// A PNG carries an alpha channel and the structure is drawn in black, so a
|
|
72
|
+
// background left transparent comes out black on black wherever it is pasted.
|
|
73
|
+
context.fillStyle = '#ffffff';
|
|
74
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
75
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
76
|
+
|
|
77
|
+
return await toPngBlob(canvas);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A side of the picture, in whole pixels.
|
|
82
|
+
* @param value - How long it is.
|
|
83
|
+
* @returns Whole pixels, never zero: a canvas sized zero rasterizes nothing.
|
|
84
|
+
*/
|
|
85
|
+
function side(value: number): number {
|
|
86
|
+
return Math.max(1, Math.round(value));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Load an SVG document as an image.
|
|
91
|
+
* @param source - The SVG document.
|
|
92
|
+
* @returns The image, already decoded, so it can be drawn straight away.
|
|
93
|
+
*/
|
|
94
|
+
async function loadImage(source: string): Promise<HTMLImageElement> {
|
|
95
|
+
const url = URL.createObjectURL(
|
|
96
|
+
new Blob([source], { type: 'image/svg+xml' }),
|
|
97
|
+
);
|
|
98
|
+
try {
|
|
99
|
+
const image = new Image();
|
|
100
|
+
image.src = url;
|
|
101
|
+
await image.decode();
|
|
102
|
+
return image;
|
|
103
|
+
} finally {
|
|
104
|
+
// The decoded image no longer needs the URL it came from.
|
|
105
|
+
URL.revokeObjectURL(url);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Read a canvas back as a PNG.
|
|
111
|
+
* @param canvas - What was drawn.
|
|
112
|
+
* @returns The PNG.
|
|
113
|
+
*/
|
|
114
|
+
async function toPngBlob(canvas: HTMLCanvasElement): Promise<Blob> {
|
|
115
|
+
return await new Promise<Blob>((resolve, reject) => {
|
|
116
|
+
canvas.toBlob((blob) => {
|
|
117
|
+
if (blob) resolve(blob);
|
|
118
|
+
else reject(new Error('The browser produced no PNG.'));
|
|
119
|
+
}, 'image/png');
|
|
120
|
+
});
|
|
121
|
+
}
|