react-cheminfo 0.30.0 → 0.32.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 +21 -0
- 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/downloadFigure.d.ts +7 -5
- package/lib/download/core/downloadFigure.d.ts.map +1 -1
- package/lib/download/core/downloadFigure.js +7 -6
- package/lib/download/core/downloadFigure.js.map +1 -1
- package/lib/download/core/figureLayout.d.ts +55 -0
- package/lib/download/core/figureLayout.d.ts.map +1 -0
- package/lib/download/core/figureLayout.js +89 -0
- package/lib/download/core/figureLayout.js.map +1 -0
- package/lib/download/core/figureScale.d.ts +9 -0
- package/lib/download/core/figureScale.d.ts.map +1 -1
- package/lib/download/core/figureScale.js +10 -0
- package/lib/download/core/figureScale.js.map +1 -1
- package/lib/download/core/figureSettle.d.ts +51 -0
- package/lib/download/core/figureSettle.d.ts.map +1 -0
- package/lib/download/core/figureSettle.js +81 -0
- package/lib/download/core/figureSettle.js.map +1 -0
- package/lib/download/core/figureSvg.d.ts +7 -1
- package/lib/download/core/figureSvg.d.ts.map +1 -1
- package/lib/download/core/figureSvg.js +1 -0
- package/lib/download/core/figureSvg.js.map +1 -1
- package/lib/download/core/figureSvgDocument.d.ts +7 -0
- package/lib/download/core/figureSvgDocument.d.ts.map +1 -1
- package/lib/download/core/figureSvgDocument.js +11 -2
- package/lib/download/core/figureSvgDocument.js.map +1 -1
- package/lib/download/core/index.d.ts +5 -1
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +3 -1
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/ui/FigureDownload.d.ts +18 -4
- package/lib/download/ui/FigureDownload.d.ts.map +1 -1
- package/lib/download/ui/FigureDownload.js +35 -9
- package/lib/download/ui/FigureDownload.js.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.d.ts +17 -7
- package/lib/download/ui/FigureDownloadPanel.d.ts.map +1 -1
- package/lib/download/ui/FigureDownloadPanel.js +30 -22
- package/lib/download/ui/FigureDownloadPanel.js.map +1 -1
- package/lib/download/ui/FigureSizeField.d.ts +27 -0
- package/lib/download/ui/FigureSizeField.d.ts.map +1 -0
- package/lib/download/ui/FigureSizeField.js +87 -0
- package/lib/download/ui/FigureSizeField.js.map +1 -0
- package/lib/download/ui/FigureSizeRows.d.ts +34 -0
- package/lib/download/ui/FigureSizeRows.d.ts.map +1 -0
- package/lib/download/ui/FigureSizeRows.js +54 -0
- package/lib/download/ui/FigureSizeRows.js.map +1 -0
- package/lib/download/ui/index.d.ts +2 -0
- package/lib/download/ui/index.d.ts.map +1 -1
- package/lib/download/ui/index.js.map +1 -1
- package/lib/download/ui/useFigureRedraw.d.ts +27 -0
- package/lib/download/ui/useFigureRedraw.d.ts.map +1 -0
- package/lib/download/ui/useFigureRedraw.js +78 -0
- package/lib/download/ui/useFigureRedraw.js.map +1 -0
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +13 -3
- package/lib/locales/en.json +13 -3
- package/lib/locales/es.json +13 -3
- package/lib/locales/fr.json +13 -3
- package/lib/number/core/index.d.ts +2 -0
- package/lib/number/core/index.d.ts.map +1 -0
- package/lib/number/core/index.js +2 -0
- package/lib/number/core/index.js.map +1 -0
- package/lib/number/core/numberText.d.ts +46 -0
- package/lib/number/core/numberText.d.ts.map +1 -0
- package/lib/number/core/numberText.js +88 -0
- package/lib/number/core/numberText.js.map +1 -0
- package/lib/number/ui/NumberInput.d.ts +113 -0
- package/lib/number/ui/NumberInput.d.ts.map +1 -0
- package/lib/number/ui/NumberInput.js +100 -0
- package/lib/number/ui/NumberInput.js.map +1 -0
- package/lib/number/ui/index.d.ts +3 -0
- package/lib/number/ui/index.d.ts.map +1 -0
- package/lib/number/ui/index.js +2 -0
- package/lib/number/ui/index.js.map +1 -0
- package/lib/overlay/ui/OverlayValueMenu.d.ts.map +1 -1
- package/lib/overlay/ui/OverlayValueMenu.js +7 -1
- package/lib/overlay/ui/OverlayValueMenu.js.map +1 -1
- package/lib/periodic/ui/ElementCell.d.ts +10 -0
- package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
- package/lib/periodic/ui/ElementCell.js +124 -14
- package/lib/periodic/ui/ElementCell.js.map +1 -1
- package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
- package/lib/periodic/ui/PeriodicTable.js +46 -19
- package/lib/periodic/ui/PeriodicTable.js.map +1 -1
- package/lib/periodic/ui/PeriodicTableChrome.js +2 -2
- package/lib/periodic/ui/PeriodicTableChrome.js.map +1 -1
- package/lib/spectra/ui/NumberField.d.ts +2 -5
- package/lib/spectra/ui/NumberField.d.ts.map +1 -1
- package/lib/spectra/ui/NumberField.js +4 -54
- package/lib/spectra/ui/NumberField.js.map +1 -1
- package/lib/ui.d.ts +1 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +1 -0
- package/lib/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/core.ts +1 -0
- package/src/download/core/downloadFigure.ts +12 -9
- package/src/download/core/figureLayout.ts +114 -0
- package/src/download/core/figureScale.ts +13 -0
- package/src/download/core/figureSettle.ts +112 -0
- package/src/download/core/figureSvg.ts +8 -1
- package/src/download/core/figureSvgDocument.ts +19 -2
- package/src/download/core/index.ts +13 -0
- package/src/download/ui/FigureDownload.tsx +88 -35
- package/src/download/ui/FigureDownloadPanel.tsx +45 -22
- package/src/download/ui/FigureSizeField.tsx +153 -0
- package/src/download/ui/FigureSizeRows.tsx +108 -0
- package/src/download/ui/index.ts +2 -0
- package/src/download/ui/useFigureRedraw.tsx +115 -0
- package/src/locales/de.json +13 -3
- package/src/locales/en.json +13 -3
- package/src/locales/es.json +13 -3
- package/src/locales/fr.json +13 -3
- package/src/number/core/index.ts +6 -0
- package/src/number/core/numberText.ts +91 -0
- package/src/number/ui/NumberInput.tsx +300 -0
- package/src/number/ui/index.ts +7 -0
- package/src/overlay/ui/OverlayValueMenu.tsx +7 -1
- package/src/periodic/ui/ElementCell.tsx +153 -14
- package/src/periodic/ui/PeriodicTable.tsx +51 -22
- package/src/periodic/ui/PeriodicTableChrome.tsx +2 -2
- package/src/spectra/ui/NumberField.tsx +11 -58
- package/src/ui.ts +1 -0
package/README.md
CHANGED
|
@@ -97,6 +97,7 @@ through a wildcard subpath exactly as `react-science` serves its own.
|
|
|
97
97
|
| **Pedagogy** | `parseGlossaryMarkers`, `localStorageProgressStore`, `progressSummary`, `finishValidation` | `GlossaryText`, `SyntaxTooltip`, `HintLadder`, `ExerciseActions`, `ExerciseProgressHeader`, `TutorialStepStrip`, `ReferenceGrid`, `TestCaseList` |
|
|
98
98
|
| **Clipboard & files** | `writeToClipboard`, `downloadBlob`, `downloadText`, `sanitizeFileName`, `toDelimited`, `readDelimited`, `downloadFigure`, `figureSvg`, `figurePng`, `figureSize` | `ClickToCopy`, `CopyButton`, `CopyableValue`, `CodeBlock`, `DelimitedTextDialog`, `FigureDownload` |
|
|
99
99
|
| **Formatting & colour** | `formatInteger`, `formatDecimal`, `formatBytes`, `pluralize`, `readableInk`, `contrastRatio`, `COLOR_SCALES`, `resolveColorScale`, `formatColorScale`, `colorAt`, `swatchAt`, `sampleScale`, `colorScaleGradient`, `rgbToHsv` | `ColorScaleLegend`, `ColorScaleSelect`, `ColorScaleEditor`, `ColorScaleBar` |
|
|
100
|
+
| **Number entry** | `readNumber`, `numberText`, `isPartialNumber`, `stepNumber` | `NumberInput` |
|
|
100
101
|
| **Widgets** | `CREDITS`, `credits` | `ErrorBoundary`, `CollapsibleSection`, `CapsuleFilter`, `HelpTooltip`, `CreditsList` |
|
|
101
102
|
| **Hooks & state** | `createWorkerChannel`, `persistBucket`, `persistSignalBucket` | `useDebouncedValue`, `useContainerSize`, `useListKeyboardNavigation`, `useDisclosure` |
|
|
102
103
|
| **Chemistry** | `atomicOrbitalsOf`, `configurationOf`, `classifyMolfile`, `readStructure`, `toMolfileExport` | `AtomicOrbitalViewer` (`/orbital`), `StructureEditor`, `Structure` (`/structure`) |
|
|
@@ -571,6 +572,26 @@ resolved first — a `var(--border)` that left the site would draw a chart with
|
|
|
571
572
|
axes. And the chrome floating over the picture is left behind: an `OverlayLayer`
|
|
572
573
|
marks itself, so the cog in the corner never lands in the middle of the scatter.
|
|
573
574
|
|
|
575
|
+
The resolution applies to both formats: a PNG is painted with that many more
|
|
576
|
+
pixels, and an SVG, drawn the same, opens that many times larger. Neither
|
|
577
|
+
changes the figure's shape. Pass **`renderFigure`** and the panel also offers a
|
|
578
|
+
size: as shown, 4:3, 16:9, a journal column (8.5 cm, where
|
|
579
|
+
the text prints at the size it reads on screen) or a width × height typed in.
|
|
580
|
+
The figure is then drawn again off the page at that size, so its axes and labels
|
|
581
|
+
are laid out for the new shape rather than stretched, and saved once it has
|
|
582
|
+
stopped moving. Draw exactly what is on screen; only the box changes.
|
|
583
|
+
|
|
584
|
+
```tsx
|
|
585
|
+
<FigureDownload
|
|
586
|
+
targetId="spectrum"
|
|
587
|
+
fileName="spectrum"
|
|
588
|
+
renderFigure={(size) => <Spectrum width={size.width} height={size.height} />}
|
|
589
|
+
/>
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
A chart that measures its own container can ignore `size`: the copy is mounted
|
|
593
|
+
in a box of exactly that size.
|
|
594
|
+
|
|
574
595
|
`downloadFigure(target, options)`, `figureSvg` and `figurePng` are the same thing
|
|
575
596
|
without the button, for a site saving a figure from its own menu.
|
|
576
597
|
|
package/lib/core.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './error/core/index.ts';
|
|
|
12
12
|
export * from './format/core/index.ts';
|
|
13
13
|
export * from './i18n/core/index.ts';
|
|
14
14
|
export * from './language/core/index.ts';
|
|
15
|
+
export * from './number/core/index.ts';
|
|
15
16
|
export * from './orbital/core/index.ts';
|
|
16
17
|
export * from './overlay/core/index.ts';
|
|
17
18
|
export * from './panel/core/index.ts';
|
package/lib/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
package/lib/core.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from "./error/core/index.js";
|
|
|
12
12
|
export * from "./format/core/index.js";
|
|
13
13
|
export * from "./i18n/core/index.js";
|
|
14
14
|
export * from "./language/core/index.js";
|
|
15
|
+
export * from "./number/core/index.js";
|
|
15
16
|
export * from "./orbital/core/index.js";
|
|
16
17
|
export * from "./overlay/core/index.js";
|
|
17
18
|
export * from "./panel/core/index.js";
|
package/lib/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC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Ac,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,+EAA+E;AAC/E,2EAA2E;AAC3E,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,0EAA0E;AAC1E,8EAA8E;AAC9E,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Which of the two formats a reader wants is not a question the figure can
|
|
5
5
|
* answer for them: an SVG is the one to put in a paper, where it stays sharp
|
|
6
6
|
* at any size and can still be edited, and a PNG is the one every chat window,
|
|
7
|
-
* slide deck and issue tracker actually accepts. So both are offered
|
|
8
|
-
* resolution
|
|
7
|
+
* slide deck and issue tracker actually accepts. So both are offered. The
|
|
8
|
+
* resolution paints a PNG with more pixels, and makes an SVG open larger.
|
|
9
9
|
*/
|
|
10
10
|
import type { FigureSvgOptions } from './figureSvg.ts';
|
|
11
11
|
/** Which file a figure is saved as. */
|
|
@@ -18,9 +18,11 @@ export interface DownloadFigureOptions extends FigureSvgOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
format?: FigureFormat;
|
|
20
20
|
/**
|
|
21
|
-
* How many pixels are painted per pixel on screen. An SVG
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* How many pixels are painted per pixel on screen. An SVG is drawn the same
|
|
22
|
+
* and opens this many times larger, which is the size a slide or a word
|
|
23
|
+
* processor places it at.
|
|
24
|
+
* @default 2 for a PNG, 1 for an SVG — which then opens at the size it has
|
|
25
|
+
* on screen
|
|
24
26
|
*/
|
|
25
27
|
scale?: number;
|
|
26
28
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFigure.d.ts","sourceRoot":"","sources":["../../../src/download/core/downloadFigure.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvD,uCAAuC;AACvC,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC,6BAA6B;AAC7B,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB
|
|
1
|
+
{"version":3,"file":"downloadFigure.d.ts","sourceRoot":"","sources":["../../../src/download/core/downloadFigure.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvD,uCAAuC;AACvC,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC,6BAA6B;AAC7B,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAKD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Which of the two formats a reader wants is not a question the figure can
|
|
5
5
|
* answer for them: an SVG is the one to put in a paper, where it stays sharp
|
|
6
6
|
* at any size and can still be edited, and a PNG is the one every chat window,
|
|
7
|
-
* slide deck and issue tracker actually accepts. So both are offered
|
|
8
|
-
* resolution
|
|
7
|
+
* slide deck and issue tracker actually accepts. So both are offered. The
|
|
8
|
+
* resolution paints a PNG with more pixels, and makes an SVG open larger.
|
|
9
9
|
*/
|
|
10
10
|
import { downloadBlob } from "./downloadBlob.js";
|
|
11
11
|
import { figurePng } from "./figurePng.js";
|
|
12
|
-
import {
|
|
12
|
+
import { defaultFigureScale } from "./figureScale.js";
|
|
13
13
|
import { FIGURE_SVG_TYPE, figureSvg } from "./figureSvg.js";
|
|
14
14
|
import { sanitizeFileName } from "./sanitizeFileName.js";
|
|
15
15
|
/** What a figure is called when the caller does not say. */
|
|
@@ -21,15 +21,16 @@ const DEFAULT_FILE_NAME = 'figure';
|
|
|
21
21
|
* @throws {Error} When the box holds no figure, or the browser cannot paint it.
|
|
22
22
|
*/
|
|
23
23
|
export async function downloadFigure(target, options = {}) {
|
|
24
|
-
const { format = 'png',
|
|
25
|
-
const
|
|
26
|
-
const figure = figureSvg(target, { background });
|
|
24
|
+
const { format = 'png', fileName = DEFAULT_FILE_NAME, background } = options;
|
|
25
|
+
const scale = options.scale ?? defaultFigureScale(format);
|
|
27
26
|
const name = sanitizeFileName(fileName, DEFAULT_FILE_NAME);
|
|
28
27
|
if (format === 'svg') {
|
|
28
|
+
const figure = figureSvg(target, { background, scale });
|
|
29
29
|
const blob = new Blob([figure.markup], { type: FIGURE_SVG_TYPE });
|
|
30
30
|
downloadBlob(blob, `${name}.svg`);
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
+
const figure = figureSvg(target, { background });
|
|
33
34
|
downloadBlob(await figurePng(figure, scale), `${name}.png`);
|
|
34
35
|
}
|
|
35
36
|
//# sourceMappingURL=downloadFigure.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFigure.js","sourceRoot":"","sources":["../../../src/download/core/downloadFigure.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;A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MAAM,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape a figure is drawn at before it is saved.
|
|
3
|
+
*
|
|
4
|
+
* A saved figure is the drawing the reader is looking at, so its proportions
|
|
5
|
+
* are the proportions of the box it sits in. The resolution scales that
|
|
6
|
+
* drawing — more pixels for a PNG, a larger page for an SVG — but leaves its
|
|
7
|
+
* shape, and the size of its words against its axes, exactly as they were. A
|
|
8
|
+
* figure for a slide or for a journal column wants another shape, and the only
|
|
9
|
+
* way to give it one is to draw it again at that size, so its axes and labels
|
|
10
|
+
* are laid out for the new box rather than stretched into it.
|
|
11
|
+
*/
|
|
12
|
+
import type { FigurePixels } from './figureScale.ts';
|
|
13
|
+
/** The shapes a figure can be drawn at for a file. */
|
|
14
|
+
export type FigureLayout = 'screen' | 'standard' | 'wide' | 'column' | 'custom';
|
|
15
|
+
/** The shapes, in the order they are offered. */
|
|
16
|
+
export declare const FIGURE_LAYOUTS: readonly ["screen", "standard", "wide", "column", "custom"];
|
|
17
|
+
/**
|
|
18
|
+
* How wide a journal's single column is, in CSS pixels: 8.5 cm at 96 pixels
|
|
19
|
+
* per inch. A figure laid out at that width prints its text at the size it is
|
|
20
|
+
* read at on screen, a 12 px label becoming a 9 pt one.
|
|
21
|
+
*/
|
|
22
|
+
export declare const FIGURE_COLUMN_WIDTH = 321;
|
|
23
|
+
/** The narrowest side a figure is drawn at, below which no chart has room for its axes. */
|
|
24
|
+
export declare const FIGURE_LAYOUT_MIN = 120;
|
|
25
|
+
/** The widest side a figure is drawn at: past it the page would be laying out a poster. */
|
|
26
|
+
export declare const FIGURE_LAYOUT_MAX = 4096;
|
|
27
|
+
/**
|
|
28
|
+
* The size a figure is drawn at, in the shape the reader picked.
|
|
29
|
+
*
|
|
30
|
+
* The two slide shapes keep the width of the figure on screen and change its
|
|
31
|
+
* height, since the width is what a page already gave it. The journal column
|
|
32
|
+
* does the reverse: its width is fixed by the journal, and the figure keeps
|
|
33
|
+
* the proportions it has on screen.
|
|
34
|
+
* @param layout - The shape picked.
|
|
35
|
+
* @param screen - The figure as it is drawn on the page.
|
|
36
|
+
* @param custom - The size typed in, read only for `custom`. Defaults to the
|
|
37
|
+
* figure on screen.
|
|
38
|
+
* @returns The size to draw it at, in whole pixels.
|
|
39
|
+
*/
|
|
40
|
+
export declare function figureLayoutSize(layout: FigureLayout, screen: FigurePixels, custom?: FigurePixels): FigurePixels;
|
|
41
|
+
/**
|
|
42
|
+
* One side, held to the range a figure can be drawn at.
|
|
43
|
+
* @param value - What was asked for, typed or computed.
|
|
44
|
+
* @returns A whole number of pixels, inside the range.
|
|
45
|
+
*/
|
|
46
|
+
export declare function figureLayoutSide(value: number): number;
|
|
47
|
+
/**
|
|
48
|
+
* Whether a figure is drawn again for the file, rather than copied as it is.
|
|
49
|
+
* @param layout - The shape picked.
|
|
50
|
+
* @param screen - The figure as it is drawn on the page.
|
|
51
|
+
* @param custom - The size typed in.
|
|
52
|
+
* @returns Whether the size differs from the one on screen.
|
|
53
|
+
*/
|
|
54
|
+
export declare function figureLayoutRedraws(layout: FigureLayout, screen: FigurePixels, custom?: FigurePixels): boolean;
|
|
55
|
+
//# sourceMappingURL=figureLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureLayout.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureLayout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,sDAAsD;AACtD,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEhF,iDAAiD;AACjD,eAAO,MAAM,cAAc,6DAMiB,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,GAAE,YAAqB,GAC5B,YAAY,CAkBd;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,YAAY,GACpB,OAAO,CAGT"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape a figure is drawn at before it is saved.
|
|
3
|
+
*
|
|
4
|
+
* A saved figure is the drawing the reader is looking at, so its proportions
|
|
5
|
+
* are the proportions of the box it sits in. The resolution scales that
|
|
6
|
+
* drawing — more pixels for a PNG, a larger page for an SVG — but leaves its
|
|
7
|
+
* shape, and the size of its words against its axes, exactly as they were. A
|
|
8
|
+
* figure for a slide or for a journal column wants another shape, and the only
|
|
9
|
+
* way to give it one is to draw it again at that size, so its axes and labels
|
|
10
|
+
* are laid out for the new box rather than stretched into it.
|
|
11
|
+
*/
|
|
12
|
+
/** The shapes, in the order they are offered. */
|
|
13
|
+
export const FIGURE_LAYOUTS = [
|
|
14
|
+
'screen',
|
|
15
|
+
'standard',
|
|
16
|
+
'wide',
|
|
17
|
+
'column',
|
|
18
|
+
'custom',
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* How wide a journal's single column is, in CSS pixels: 8.5 cm at 96 pixels
|
|
22
|
+
* per inch. A figure laid out at that width prints its text at the size it is
|
|
23
|
+
* read at on screen, a 12 px label becoming a 9 pt one.
|
|
24
|
+
*/
|
|
25
|
+
export const FIGURE_COLUMN_WIDTH = 321;
|
|
26
|
+
/** The narrowest side a figure is drawn at, below which no chart has room for its axes. */
|
|
27
|
+
export const FIGURE_LAYOUT_MIN = 120;
|
|
28
|
+
/** The widest side a figure is drawn at: past it the page would be laying out a poster. */
|
|
29
|
+
export const FIGURE_LAYOUT_MAX = 4096;
|
|
30
|
+
/**
|
|
31
|
+
* The size a figure is drawn at, in the shape the reader picked.
|
|
32
|
+
*
|
|
33
|
+
* The two slide shapes keep the width of the figure on screen and change its
|
|
34
|
+
* height, since the width is what a page already gave it. The journal column
|
|
35
|
+
* does the reverse: its width is fixed by the journal, and the figure keeps
|
|
36
|
+
* the proportions it has on screen.
|
|
37
|
+
* @param layout - The shape picked.
|
|
38
|
+
* @param screen - The figure as it is drawn on the page.
|
|
39
|
+
* @param custom - The size typed in, read only for `custom`. Defaults to the
|
|
40
|
+
* figure on screen.
|
|
41
|
+
* @returns The size to draw it at, in whole pixels.
|
|
42
|
+
*/
|
|
43
|
+
export function figureLayoutSize(layout, screen, custom = screen) {
|
|
44
|
+
switch (layout) {
|
|
45
|
+
case 'standard':
|
|
46
|
+
return sized(screen.width, (screen.width * 3) / 4);
|
|
47
|
+
case 'wide':
|
|
48
|
+
return sized(screen.width, (screen.width * 9) / 16);
|
|
49
|
+
case 'column':
|
|
50
|
+
return sized(FIGURE_COLUMN_WIDTH, (FIGURE_COLUMN_WIDTH * screen.height) / Math.max(screen.width, 1));
|
|
51
|
+
case 'custom':
|
|
52
|
+
return sized(custom.width, custom.height);
|
|
53
|
+
case 'screen':
|
|
54
|
+
return { width: screen.width, height: screen.height };
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`unknown figure layout: ${String(layout)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One side, held to the range a figure can be drawn at.
|
|
61
|
+
* @param value - What was asked for, typed or computed.
|
|
62
|
+
* @returns A whole number of pixels, inside the range.
|
|
63
|
+
*/
|
|
64
|
+
export function figureLayoutSide(value) {
|
|
65
|
+
if (!Number.isFinite(value))
|
|
66
|
+
return FIGURE_LAYOUT_MIN;
|
|
67
|
+
return Math.min(FIGURE_LAYOUT_MAX, Math.max(FIGURE_LAYOUT_MIN, Math.round(value)));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether a figure is drawn again for the file, rather than copied as it is.
|
|
71
|
+
* @param layout - The shape picked.
|
|
72
|
+
* @param screen - The figure as it is drawn on the page.
|
|
73
|
+
* @param custom - The size typed in.
|
|
74
|
+
* @returns Whether the size differs from the one on screen.
|
|
75
|
+
*/
|
|
76
|
+
export function figureLayoutRedraws(layout, screen, custom) {
|
|
77
|
+
const drawn = figureLayoutSize(layout, screen, custom);
|
|
78
|
+
return drawn.width !== screen.width || drawn.height !== screen.height;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A size, both sides held to the range.
|
|
82
|
+
* @param width - The width asked for.
|
|
83
|
+
* @param height - The height asked for.
|
|
84
|
+
* @returns The size.
|
|
85
|
+
*/
|
|
86
|
+
function sized(width, height) {
|
|
87
|
+
return { width: figureLayoutSide(width), height: figureLayoutSide(height) };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=figureLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureLayout.js","sourceRoot":"","sources":["../../../src/download/core/figureLayout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,iDAAiD;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ;IACR,UAAU;IACV,MAAM;IACN,QAAQ;IACR,QAAQ;CACkC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC;;;;;;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oB,EACpB,MAAqB;IAErB,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;AACxE,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,KAAa,EAAE,MAAc;IAC1C,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;AAC9E,CAAC"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* pixel count is the consequence, and is written out beside it so nobody has
|
|
8
8
|
* to work it out.
|
|
9
9
|
*/
|
|
10
|
+
import type { FigureFormat } from './downloadFigure.ts';
|
|
10
11
|
/** The size of a saved figure, in pixels. */
|
|
11
12
|
export interface FigurePixels {
|
|
12
13
|
/** Its width. */
|
|
@@ -24,6 +25,14 @@ export declare const FIGURE_SCALES: readonly number[];
|
|
|
24
25
|
* of these files end up.
|
|
25
26
|
*/
|
|
26
27
|
export declare const DEFAULT_FIGURE_SCALE = 2;
|
|
28
|
+
/**
|
|
29
|
+
* The multiple a figure is saved at in this format unless the reader says
|
|
30
|
+
* otherwise. An SVG stays sharp however large it is shown, so it opens at the
|
|
31
|
+
* size it has on screen; a PNG is painted twice over, for a slide.
|
|
32
|
+
* @param format - The file being written.
|
|
33
|
+
* @returns The multiple.
|
|
34
|
+
*/
|
|
35
|
+
export declare function defaultFigureScale(format: FigureFormat): number;
|
|
27
36
|
/**
|
|
28
37
|
* The longest side a browser will paint into one canvas.
|
|
29
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureScale.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureScale.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,6CAA6C;AAC7C,MAAM,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;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAM5E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAK1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAE/D"}
|
|
@@ -17,6 +17,16 @@ export const FIGURE_SCALES = [1, 2, 3, 4];
|
|
|
17
17
|
* of these files end up.
|
|
18
18
|
*/
|
|
19
19
|
export const DEFAULT_FIGURE_SCALE = 2;
|
|
20
|
+
/**
|
|
21
|
+
* The multiple a figure is saved at in this format unless the reader says
|
|
22
|
+
* otherwise. An SVG stays sharp however large it is shown, so it opens at the
|
|
23
|
+
* size it has on screen; a PNG is painted twice over, for a slide.
|
|
24
|
+
* @param format - The file being written.
|
|
25
|
+
* @returns The multiple.
|
|
26
|
+
*/
|
|
27
|
+
export function defaultFigureScale(format) {
|
|
28
|
+
return format === 'svg' ? 1 : DEFAULT_FIGURE_SCALE;
|
|
29
|
+
}
|
|
20
30
|
/**
|
|
21
31
|
* The longest side a browser will paint into one canvas.
|
|
22
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureScale.js","sourceRoot":"","sources":["../../../src/download/core/figureScale.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"figureScale.js","sourceRoot":"","sources":["../../../src/download/core/figureScale.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,aAAa,GAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,M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
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowing when a figure drawn for a file has finished drawing.
|
|
3
|
+
*
|
|
4
|
+
* A chart mounted off the page to be saved at another size does not arrive in
|
|
5
|
+
* one piece: it may render once at a guessed size, measure its box, and render
|
|
6
|
+
* again, and a chart behind a lazy import arrives whenever its chunk does. So
|
|
7
|
+
* nothing here waits a fixed time. The figure is watched frame by frame, and
|
|
8
|
+
* it is taken the moment it has stood still for two frames running.
|
|
9
|
+
*/
|
|
10
|
+
/** How the wait is run. */
|
|
11
|
+
export interface FigureSettleOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Stops the wait, for a panel closed or a page left while the figure is
|
|
14
|
+
* still drawing.
|
|
15
|
+
* @default undefined — the wait runs to its end
|
|
16
|
+
*/
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
/**
|
|
19
|
+
* How many frames the figure is given to settle before the save is given
|
|
20
|
+
* up, about ten seconds at sixty frames a second. It is how a figure that
|
|
21
|
+
* never draws is reported, not how long a slow one is expected to take.
|
|
22
|
+
* @default 600
|
|
23
|
+
*/
|
|
24
|
+
maxFrames?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves at the next frame.
|
|
27
|
+
* @default the browser's `requestAnimationFrame`
|
|
28
|
+
*/
|
|
29
|
+
nextFrame?: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wait until the figure mounted in a box has finished drawing.
|
|
33
|
+
* @param element - The box the figure is being drawn in.
|
|
34
|
+
* @param options - See {@link FigureSettleOptions}.
|
|
35
|
+
* @returns Resolves once the figure has stood still.
|
|
36
|
+
* @throws {Error} When the wait is stopped, or the figure never settles.
|
|
37
|
+
*/
|
|
38
|
+
export declare function whenFigureSettles(element: Element, options?: FigureSettleOptions): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Wait until a reading of the figure comes back the same frames in a row.
|
|
41
|
+
*
|
|
42
|
+
* The reading is whatever says the figure has changed — for a drawing on the
|
|
43
|
+
* page, how many times it was touched and the size it came out at — and
|
|
44
|
+
* `null` while there is nothing drawn yet.
|
|
45
|
+
* @param read - Takes the reading.
|
|
46
|
+
* @param options - See {@link FigureSettleOptions}.
|
|
47
|
+
* @returns Resolves once the reading has held.
|
|
48
|
+
* @throws {Error} When the wait is stopped, or the reading never holds.
|
|
49
|
+
*/
|
|
50
|
+
export declare function settle(read: () => string | null, options?: FigureSettleOptions): Promise<void>;
|
|
51
|
+
//# sourceMappingURL=figureSettle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureSettle.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSettle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,2BAA2B;AAC3B,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAQD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,MAAM,MAAM,GAAG,IAAI,EACzB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowing when a figure drawn for a file has finished drawing.
|
|
3
|
+
*
|
|
4
|
+
* A chart mounted off the page to be saved at another size does not arrive in
|
|
5
|
+
* one piece: it may render once at a guessed size, measure its box, and render
|
|
6
|
+
* again, and a chart behind a lazy import arrives whenever its chunk does. So
|
|
7
|
+
* nothing here waits a fixed time. The figure is watched frame by frame, and
|
|
8
|
+
* it is taken the moment it has stood still for two frames running.
|
|
9
|
+
*/
|
|
10
|
+
import { figureSize } from "./figureTarget.js";
|
|
11
|
+
/** How many frames in a row the figure has to hold still. */
|
|
12
|
+
const STILL_FRAMES = 2;
|
|
13
|
+
/** What {@link FigureSettleOptions.maxFrames} is unless the caller says. */
|
|
14
|
+
const DEFAULT_MAX_FRAMES = 600;
|
|
15
|
+
/**
|
|
16
|
+
* Wait until the figure mounted in a box has finished drawing.
|
|
17
|
+
* @param element - The box the figure is being drawn in.
|
|
18
|
+
* @param options - See {@link FigureSettleOptions}.
|
|
19
|
+
* @returns Resolves once the figure has stood still.
|
|
20
|
+
* @throws {Error} When the wait is stopped, or the figure never settles.
|
|
21
|
+
*/
|
|
22
|
+
export async function whenFigureSettles(element, options = {}) {
|
|
23
|
+
let changes = 0;
|
|
24
|
+
const observer = new MutationObserver(() => {
|
|
25
|
+
changes++;
|
|
26
|
+
});
|
|
27
|
+
observer.observe(element, {
|
|
28
|
+
subtree: true,
|
|
29
|
+
childList: true,
|
|
30
|
+
attributes: true,
|
|
31
|
+
characterData: true,
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
await settle(() => {
|
|
35
|
+
const size = figureSize(element);
|
|
36
|
+
return size === null ? null : `${changes}:${size.width}×${size.height}`;
|
|
37
|
+
}, options);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
observer.disconnect();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wait until a reading of the figure comes back the same frames in a row.
|
|
45
|
+
*
|
|
46
|
+
* The reading is whatever says the figure has changed — for a drawing on the
|
|
47
|
+
* page, how many times it was touched and the size it came out at — and
|
|
48
|
+
* `null` while there is nothing drawn yet.
|
|
49
|
+
* @param read - Takes the reading.
|
|
50
|
+
* @param options - See {@link FigureSettleOptions}.
|
|
51
|
+
* @returns Resolves once the reading has held.
|
|
52
|
+
* @throws {Error} When the wait is stopped, or the reading never holds.
|
|
53
|
+
*/
|
|
54
|
+
export async function settle(read, options = {}) {
|
|
55
|
+
const { signal, maxFrames = DEFAULT_MAX_FRAMES } = options;
|
|
56
|
+
const { nextFrame = animationFrame } = options;
|
|
57
|
+
let last = null;
|
|
58
|
+
let still = 0;
|
|
59
|
+
for (let frame = 0; frame < maxFrames; frame++) {
|
|
60
|
+
// eslint-disable-next-line no-await-in-loop -- each frame is compared with the one before it
|
|
61
|
+
await nextFrame();
|
|
62
|
+
if (signal?.aborted)
|
|
63
|
+
throw new Error('The figure was not saved.');
|
|
64
|
+
const reading = read();
|
|
65
|
+
still = reading !== null && reading === last ? still + 1 : 0;
|
|
66
|
+
if (still >= STILL_FRAMES)
|
|
67
|
+
return;
|
|
68
|
+
last = reading;
|
|
69
|
+
}
|
|
70
|
+
throw new Error('The figure did not finish drawing, so nothing was saved.');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The next frame the browser paints.
|
|
74
|
+
* @returns Resolves at that frame.
|
|
75
|
+
*/
|
|
76
|
+
function animationFrame() {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
requestAnimationFrame(() => resolve());
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=figureSettle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureSettle.js","sourceRoot":"","sources":["../../../src/download/core/figureSettle.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAwB/C,6DAA6D;AAC7D,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,4EAA4E;AAC5E,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAgB,EAChB,UAA+B,EAAE;IAEjC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,QAAQ,GAAG,IAAI,gBA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C,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,IAAI,KAAK,IAAI,YAAY;YAAE,OAAO;QAClC,IAAI,GAAG,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,qBAAqB,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -14,12 +14,18 @@ export interface FigureSvgOptions {
|
|
|
14
14
|
* @default the surface the figure is drawn on, which is the page's own
|
|
15
15
|
*/
|
|
16
16
|
background?: string;
|
|
17
|
+
/**
|
|
18
|
+
* How many times the figure on screen the document says it is. The drawing
|
|
19
|
+
* is unchanged; only the size the file opens at grows.
|
|
20
|
+
* @default 1
|
|
21
|
+
*/
|
|
22
|
+
scale?: number;
|
|
17
23
|
}
|
|
18
24
|
/** A figure, as the file that leaves the page. */
|
|
19
25
|
export interface FigureSvg {
|
|
20
26
|
/** The whole SVG document, tokens resolved. */
|
|
21
27
|
markup: string;
|
|
22
|
-
/** Its width in pixels, at the size the figure was drawn. */
|
|
28
|
+
/** Its width in pixels, at the size the figure was drawn on screen. */
|
|
23
29
|
width: number;
|
|
24
30
|
/** Its height. */
|
|
25
31
|
height: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureSvg.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,gCAAgC;AAChC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"figureSvg.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,gCAAgC;AAChC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,kDAAkD;AAClD,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gFAAgF;AAChF,eAAO,MAAM,eAAe,gCAAgC,CAAC;AAQ7D;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,GAAE,gBAAqB,GAC7B,SAAS,CA4CX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureSvg.js","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"figureSvg.js","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa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ureSvgDocumentOptions {
|
|
|
51
51
|
* @default undefined — the reader's own default
|
|
52
52
|
*/
|
|
53
53
|
fontSize?: number;
|
|
54
|
+
/**
|
|
55
|
+
* How many times the figure on screen the document says it is. Only the
|
|
56
|
+
* size it opens at changes — the drawing keeps its own coordinates, so every
|
|
57
|
+
* line and every word grows together and stays as sharp as before.
|
|
58
|
+
* @default 1
|
|
59
|
+
*/
|
|
60
|
+
scale?: number;
|
|
54
61
|
}
|
|
55
62
|
/**
|
|
56
63
|
* Every drawing of a figure, in one standalone SVG document.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureSvgDocument.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvgDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,wEAAwE;AACxE,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;IACV,gEAAgE;IAChE,CAAC,EAAE,MAAM,CAAC;IACV;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"figureSvgDocument.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvgDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,wEAAwE;AACxE,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;IACV,gEAAgE;IAChE,CAAC,EAAE,MAAM,CAAC;IACV;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAsBR"}
|
|
@@ -21,7 +21,8 @@ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
|
21
21
|
* @returns The document, ready to be saved or rendered.
|
|
22
22
|
*/
|
|
23
23
|
export function figureSvgDocument(pieces, options) {
|
|
24
|
-
const { width, height, background, fontFamily, fontSize } = options;
|
|
24
|
+
const { width, height, background, fontFamily, fontSize, scale } = options;
|
|
25
|
+
const factor = positiveOrOne(scale);
|
|
25
26
|
const box = `0 0 ${round(width)} ${round(height)}`;
|
|
26
27
|
const style = documentStyle(fontFamily, fontSize);
|
|
27
28
|
let inside = background === undefined || background === ''
|
|
@@ -34,7 +35,7 @@ export function figureSvgDocument(pieces, options) {
|
|
|
34
35
|
`${piece.markup}</g>`;
|
|
35
36
|
}
|
|
36
37
|
return (`<?xml version="1.0" encoding="UTF-8"?>` +
|
|
37
|
-
`<svg xmlns="${SVG_NAMESPACE}" width="${round(width)}" height="${round(height)}" viewBox="${box}"${style}>` +
|
|
38
|
+
`<svg xmlns="${SVG_NAMESPACE}" width="${round(width * factor)}" height="${round(height * factor)}" viewBox="${box}"${style}>` +
|
|
38
39
|
`${inside}</svg>`);
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
@@ -55,6 +56,14 @@ function documentStyle(fontFamily, fontSize) {
|
|
|
55
56
|
? ''
|
|
56
57
|
: ` style="${escapeAttribute(rules.join(';'))}"`;
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* A multiple that makes sense, or one.
|
|
61
|
+
* @param value - The multiple asked for.
|
|
62
|
+
* @returns It, where it is a positive number; one otherwise.
|
|
63
|
+
*/
|
|
64
|
+
function positiveOrOne(value) {
|
|
65
|
+
return value !== undefined && Number.isFinite(value) && value > 0 ? value : 1;
|
|
66
|
+
}
|
|
58
67
|
/**
|
|
59
68
|
* A number as an attribute reads it: whole pixels where it is one, and two
|
|
60
69
|
* decimals otherwise, because a serialized figure carrying sixteen digits per
|