react-cheminfo 0.46.0 → 0.48.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 +69 -0
- package/lib/chart/core/chartDomain.d.ts +14 -0
- package/lib/chart/core/chartDomain.d.ts.map +1 -1
- package/lib/chart/core/chartDomain.js +1 -0
- package/lib/chart/core/chartDomain.js.map +1 -1
- package/lib/chart/core/selectionGeometry.d.ts +4 -2
- package/lib/chart/core/selectionGeometry.d.ts.map +1 -1
- package/lib/chart/core/selectionGeometry.js +4 -2
- package/lib/chart/core/selectionGeometry.js.map +1 -1
- package/lib/chart/core/zoomDomain.d.ts +11 -1
- package/lib/chart/core/zoomDomain.d.ts.map +1 -1
- package/lib/chart/core/zoomDomain.js +25 -5
- package/lib/chart/core/zoomDomain.js.map +1 -1
- package/lib/chart/ui/chartGestures.d.ts +26 -1
- package/lib/chart/ui/chartGestures.d.ts.map +1 -1
- package/lib/chart/ui/chartGestures.js +21 -0
- package/lib/chart/ui/chartGestures.js.map +1 -1
- package/lib/chart/ui/index.d.ts +1 -1
- package/lib/chart/ui/index.d.ts.map +1 -1
- package/lib/chart/ui/index.js +1 -1
- package/lib/chart/ui/index.js.map +1 -1
- package/lib/chart/ui/useChartZoom.d.ts.map +1 -1
- package/lib/chart/ui/useChartZoom.js +17 -1
- package/lib/chart/ui/useChartZoom.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/cssPaint.d.ts +27 -0
- package/lib/download/core/cssPaint.d.ts.map +1 -0
- package/lib/download/core/cssPaint.js +63 -0
- package/lib/download/core/cssPaint.js.map +1 -0
- package/lib/download/core/drawingMarkup.d.ts +11 -0
- package/lib/download/core/drawingMarkup.d.ts.map +1 -0
- package/lib/download/core/drawingMarkup.js +32 -0
- package/lib/download/core/drawingMarkup.js.map +1 -0
- package/lib/download/core/figureHtml.d.ts +25 -0
- package/lib/download/core/figureHtml.d.ts.map +1 -0
- package/lib/download/core/figureHtml.js +174 -0
- package/lib/download/core/figureHtml.js.map +1 -0
- package/lib/download/core/figureHtmlMarkup.d.ts +107 -0
- package/lib/download/core/figureHtmlMarkup.d.ts.map +1 -0
- package/lib/download/core/figureHtmlMarkup.js +75 -0
- package/lib/download/core/figureHtmlMarkup.js.map +1 -0
- package/lib/download/core/figureSvg.d.ts.map +1 -1
- package/lib/download/core/figureSvg.js +16 -35
- package/lib/download/core/figureSvg.js.map +1 -1
- package/lib/download/core/figureSvgDocument.d.ts +3 -3
- package/lib/download/core/figureSvgDocument.d.ts.map +1 -1
- package/lib/download/core/figureTarget.d.ts +14 -3
- package/lib/download/core/figureTarget.d.ts.map +1 -1
- package/lib/download/core/figureTarget.js +42 -3
- package/lib/download/core/figureTarget.js.map +1 -1
- package/lib/download/core/index.d.ts +1 -1
- package/lib/download/core/index.d.ts.map +1 -1
- package/lib/download/core/index.js +1 -1
- package/lib/download/core/index.js.map +1 -1
- package/lib/download/core/textLines.d.ts +27 -0
- package/lib/download/core/textLines.d.ts.map +1 -0
- package/lib/download/core/textLines.js +51 -0
- package/lib/download/core/textLines.js.map +1 -0
- package/lib/ecosystem/core/lookup.d.ts +2 -1
- package/lib/ecosystem/core/lookup.d.ts.map +1 -1
- package/lib/ecosystem/core/lookup.js +10 -3
- package/lib/ecosystem/core/lookup.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +2 -2
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.d.ts +9 -0
- package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -0
- package/lib/ecosystem/core/unlistedSites.js +35 -0
- package/lib/ecosystem/core/unlistedSites.js.map +1 -0
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +7 -0
- package/lib/ecosystem/ui/glyphs.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/irMode.d.ts.map +1 -1
- package/lib/ir/core/irMode.js +6 -1
- package/lib/ir/core/irMode.js.map +1 -1
- package/lib/locales/de.json +56 -1
- package/lib/locales/en.json +56 -1
- package/lib/locales/es.json +56 -1
- package/lib/locales/fr.json +56 -1
- package/lib/locales/it.json +56 -1
- package/lib/periodic/core/index.d.ts +1 -1
- package/lib/periodic/core/index.d.ts.map +1 -1
- package/lib/periodic/core/layout.d.ts +11 -0
- package/lib/periodic/core/layout.d.ts.map +1 -1
- package/lib/periodic/core/layout.js.map +1 -1
- package/lib/periodic/ui/ElementCell.d.ts +6 -2
- package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
- package/lib/periodic/ui/ElementCell.js +2 -2
- package/lib/periodic/ui/ElementCell.js.map +1 -1
- package/lib/periodic/ui/PeriodicTable.d.ts +3 -98
- package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
- package/lib/periodic/ui/PeriodicTable.js +9 -84
- package/lib/periodic/ui/PeriodicTable.js.map +1 -1
- package/lib/periodic/ui/PeriodicTableChrome.d.ts +13 -3
- package/lib/periodic/ui/PeriodicTableChrome.d.ts.map +1 -1
- package/lib/periodic/ui/PeriodicTableChrome.js +10 -20
- package/lib/periodic/ui/PeriodicTableChrome.js.map +1 -1
- package/lib/periodic/ui/SelectAllCorner.d.ts +23 -0
- package/lib/periodic/ui/SelectAllCorner.d.ts.map +1 -0
- package/lib/periodic/ui/SelectAllCorner.js +40 -0
- package/lib/periodic/ui/SelectAllCorner.js.map +1 -0
- package/lib/periodic/ui/headerStyles.d.ts +17 -0
- package/lib/periodic/ui/headerStyles.d.ts.map +1 -0
- package/lib/periodic/ui/headerStyles.js +19 -0
- package/lib/periodic/ui/headerStyles.js.map +1 -0
- package/lib/periodic/ui/periodicTableProps.d.ts +115 -0
- package/lib/periodic/ui/periodicTableProps.d.ts.map +1 -0
- package/lib/periodic/ui/periodicTableProps.js +8 -0
- package/lib/periodic/ui/periodicTableProps.js.map +1 -0
- package/lib/periodic/ui/tableLayout.d.ts +26 -0
- package/lib/periodic/ui/tableLayout.d.ts.map +1 -0
- package/lib/periodic/ui/tableLayout.js +86 -0
- package/lib/periodic/ui/tableLayout.js.map +1 -0
- package/lib/split/ui/SplitColumn.d.ts +29 -0
- package/lib/split/ui/SplitColumn.d.ts.map +1 -0
- package/lib/split/ui/SplitColumn.js +19 -0
- package/lib/split/ui/SplitColumn.js.map +1 -0
- package/lib/split/ui/SplitRow.d.ts +14 -53
- package/lib/split/ui/SplitRow.d.ts.map +1 -1
- package/lib/split/ui/SplitRow.js +8 -90
- package/lib/split/ui/SplitRow.js.map +1 -1
- package/lib/split/ui/index.d.ts +3 -0
- package/lib/split/ui/index.d.ts.map +1 -1
- package/lib/split/ui/index.js +1 -0
- package/lib/split/ui/index.js.map +1 -1
- package/lib/split/ui/splitPanes.d.ts +84 -0
- package/lib/split/ui/splitPanes.d.ts.map +1 -0
- package/lib/split/ui/splitPanes.js +125 -0
- package/lib/split/ui/splitPanes.js.map +1 -0
- package/lib/taxonomy/core/index.d.ts +8 -0
- package/lib/taxonomy/core/index.d.ts.map +1 -0
- package/lib/taxonomy/core/index.js +5 -0
- package/lib/taxonomy/core/index.js.map +1 -0
- package/lib/taxonomy/core/lineage.d.ts +83 -0
- package/lib/taxonomy/core/lineage.d.ts.map +1 -0
- package/lib/taxonomy/core/lineage.js +126 -0
- package/lib/taxonomy/core/lineage.js.map +1 -0
- package/lib/taxonomy/core/ncbi.d.ts +8 -0
- package/lib/taxonomy/core/ncbi.d.ts.map +1 -0
- package/lib/taxonomy/core/ncbi.js +10 -0
- package/lib/taxonomy/core/ncbi.js.map +1 -0
- package/lib/taxonomy/core/organismName.d.ts +28 -0
- package/lib/taxonomy/core/organismName.d.ts.map +1 -0
- package/lib/taxonomy/core/organismName.js +188 -0
- package/lib/taxonomy/core/organismName.js.map +1 -0
- package/lib/taxonomy/core/organismWords.d.ts +20 -0
- package/lib/taxonomy/core/organismWords.d.ts.map +1 -0
- package/lib/taxonomy/core/organismWords.js +86 -0
- package/lib/taxonomy/core/organismWords.js.map +1 -0
- package/lib/taxonomy/core/ranks.d.ts +51 -0
- package/lib/taxonomy/core/ranks.d.ts.map +1 -0
- package/lib/taxonomy/core/ranks.js +123 -0
- package/lib/taxonomy/core/ranks.js.map +1 -0
- package/lib/taxonomy/ui/OrganismName.d.ts +28 -0
- package/lib/taxonomy/ui/OrganismName.d.ts.map +1 -0
- package/lib/taxonomy/ui/OrganismName.js +28 -0
- package/lib/taxonomy/ui/OrganismName.js.map +1 -0
- package/lib/taxonomy/ui/TaxonLineage.d.ts +67 -0
- package/lib/taxonomy/ui/TaxonLineage.d.ts.map +1 -0
- package/lib/taxonomy/ui/TaxonLineage.js +45 -0
- package/lib/taxonomy/ui/TaxonLineage.js.map +1 -0
- package/lib/taxonomy/ui/index.d.ts +6 -0
- package/lib/taxonomy/ui/index.d.ts.map +1 -0
- package/lib/taxonomy/ui/index.js +4 -0
- package/lib/taxonomy/ui/index.js.map +1 -0
- package/lib/taxonomy/ui/rankLabel.d.ts +17 -0
- package/lib/taxonomy/ui/rankLabel.d.ts.map +1 -0
- package/lib/taxonomy/ui/rankLabel.js +77 -0
- package/lib/taxonomy/ui/rankLabel.js.map +1 -0
- 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/chart/core/chartDomain.ts +15 -0
- package/src/chart/core/selectionGeometry.ts +4 -2
- package/src/chart/core/zoomDomain.ts +37 -5
- package/src/chart/ui/chartGestures.ts +41 -1
- package/src/chart/ui/index.ts +1 -1
- package/src/chart/ui/useChartZoom.ts +25 -1
- package/src/core.ts +1 -0
- package/src/download/core/cssPaint.ts +71 -0
- package/src/download/core/drawingMarkup.ts +35 -0
- package/src/download/core/figureHtml.ts +214 -0
- package/src/download/core/figureHtmlMarkup.ts +187 -0
- package/src/download/core/figureSvg.ts +17 -38
- package/src/download/core/figureSvgDocument.ts +3 -3
- package/src/download/core/figureTarget.ts +41 -8
- package/src/download/core/index.ts +1 -0
- package/src/download/core/textLines.ts +67 -0
- package/src/ecosystem/core/lookup.ts +11 -3
- package/src/ecosystem/core/types.ts +4 -2
- package/src/ecosystem/core/unlistedSites.ts +37 -0
- package/src/ecosystem/ui/glyphs.tsx +44 -0
- package/src/ir/core/irMode.ts +6 -1
- package/src/locales/de.json +56 -1
- package/src/locales/en.json +56 -1
- package/src/locales/es.json +56 -1
- package/src/locales/fr.json +56 -1
- package/src/locales/it.json +56 -1
- package/src/periodic/core/index.ts +1 -1
- package/src/periodic/core/layout.ts +12 -0
- package/src/periodic/ui/ElementCell.tsx +8 -4
- package/src/periodic/ui/PeriodicTable.tsx +27 -197
- package/src/periodic/ui/PeriodicTableChrome.tsx +23 -20
- package/src/periodic/ui/SelectAllCorner.tsx +65 -0
- package/src/periodic/ui/headerStyles.ts +23 -0
- package/src/periodic/ui/periodicTableProps.ts +117 -0
- package/src/periodic/ui/tableLayout.ts +96 -0
- package/src/split/ui/SplitColumn.tsx +35 -0
- package/src/split/ui/SplitRow.tsx +16 -208
- package/src/split/ui/index.ts +3 -0
- package/src/split/ui/splitPanes.tsx +283 -0
- package/src/taxonomy/core/index.ts +20 -0
- package/src/taxonomy/core/lineage.ts +161 -0
- package/src/taxonomy/core/ncbi.ts +9 -0
- package/src/taxonomy/core/organismName.ts +217 -0
- package/src/taxonomy/core/organismWords.ts +86 -0
- package/src/taxonomy/core/ranks.ts +134 -0
- package/src/taxonomy/ui/OrganismName.tsx +59 -0
- package/src/taxonomy/ui/TaxonLineage.tsx +183 -0
- package/src/taxonomy/ui/index.ts +5 -0
- package/src/taxonomy/ui/rankLabel.ts +81 -0
- package/src/ui.ts +1 -0
- package/styles/chrome.css +135 -6
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a computed style says is painted, read the way a figure file needs it.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A colour, or nothing where the page paints nothing with it.
|
|
6
|
+
* @param color - A computed colour, as `getComputedStyle` writes it.
|
|
7
|
+
* @returns The colour, or undefined where it is transparent.
|
|
8
|
+
*/
|
|
9
|
+
export function visibleColor(color) {
|
|
10
|
+
const value = color.trim();
|
|
11
|
+
if (value === '' || value === 'transparent')
|
|
12
|
+
return undefined;
|
|
13
|
+
if (ZERO_ALPHA_COMMAS.test(value) || ZERO_ALPHA_SLASH.test(value)) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The dashes a CSS line style is drawn with.
|
|
20
|
+
* @param style - The computed `border-*-style` or `outline-style`.
|
|
21
|
+
* @param width - The line's width, in pixels.
|
|
22
|
+
* @returns The dashes and gaps in pixels — empty for a solid line — or
|
|
23
|
+
* undefined where no line is drawn. `auto` is a focus ring, which is the
|
|
24
|
+
* state of the pointer rather than a part of the figure.
|
|
25
|
+
*/
|
|
26
|
+
export function lineDash(style, width) {
|
|
27
|
+
if (!(width > 0))
|
|
28
|
+
return undefined;
|
|
29
|
+
switch (style) {
|
|
30
|
+
case 'none':
|
|
31
|
+
case 'hidden':
|
|
32
|
+
case 'auto':
|
|
33
|
+
case '':
|
|
34
|
+
return undefined;
|
|
35
|
+
case 'dashed':
|
|
36
|
+
return [width * 3, width * 3];
|
|
37
|
+
case 'dotted':
|
|
38
|
+
return [width, width];
|
|
39
|
+
default:
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A corner radius in pixels.
|
|
45
|
+
* @param radius - The computed `border-*-radius`, in pixels or as a share.
|
|
46
|
+
* @param width - The box's width, which a share is taken of.
|
|
47
|
+
* @param height - Its height.
|
|
48
|
+
* @returns The radius, in pixels.
|
|
49
|
+
*/
|
|
50
|
+
export function cornerRadius(radius, width, height) {
|
|
51
|
+
const value = Number.parseFloat(radius);
|
|
52
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
53
|
+
return 0;
|
|
54
|
+
if (radius.trim().endsWith('%')) {
|
|
55
|
+
return (Math.min(width, height) * value) / 100;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
/** `rgba(r, g, b, 0)`, which is what a transparent ground computes to. */
|
|
60
|
+
const ZERO_ALPHA_COMMAS = /^rgba\((?:[^,]+,){3}\s*0(?:\.0*)?\)$/;
|
|
61
|
+
/** `rgb(r g b / 0)` and `color(srgb r g b / 0)`. */
|
|
62
|
+
const ZERO_ALPHA_SLASH = /\/\s*0(?:\.0*)?%?\)$/;
|
|
63
|
+
//# sourceMappingURL=cssPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssPaint.js","sourceRoot":"","sources":["../../../src/download/core/cssPaint.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,aAAa;QAAE,OAAO,SAAS,CAAC;IAC9D,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAClE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAa,EACb,KAAa;IAEb,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACnC,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,EAAE;YACL,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAChC,KAAK,QAAQ;YACX,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACxB;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,KAAa,EACb,MAAc;IAEd,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACpD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AAEjE,oDAAoD;AACpD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One drawing, serialized with every token it names written out.
|
|
3
|
+
*
|
|
4
|
+
* The copy is taken first and read from the original, because the values are a
|
|
5
|
+
* property of where the figure sits on the page: a detached clone inherits
|
|
6
|
+
* nothing and would resolve every token to an empty string.
|
|
7
|
+
* @param drawing - The drawing, as it sits on the page.
|
|
8
|
+
* @returns Its markup.
|
|
9
|
+
*/
|
|
10
|
+
export declare function drawingMarkup(drawing: SVGSVGElement): string;
|
|
11
|
+
//# sourceMappingURL=drawingMarkup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawingMarkup.d.ts","sourceRoot":"","sources":["../../../src/download/core/drawingMarkup.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAI5D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { cssTokenNames, resolveCssTokens } from "./cssTokens.js";
|
|
2
|
+
/**
|
|
3
|
+
* One drawing, serialized with every token it names written out.
|
|
4
|
+
*
|
|
5
|
+
* The copy is taken first and read from the original, because the values are a
|
|
6
|
+
* property of where the figure sits on the page: a detached clone inherits
|
|
7
|
+
* nothing and would resolve every token to an empty string.
|
|
8
|
+
* @param drawing - The drawing, as it sits on the page.
|
|
9
|
+
* @returns Its markup.
|
|
10
|
+
*/
|
|
11
|
+
export function drawingMarkup(drawing) {
|
|
12
|
+
const clone = drawing.cloneNode(true);
|
|
13
|
+
const markup = new XMLSerializer().serializeToString(clone);
|
|
14
|
+
return resolveCssTokens(markup, tokenValues(drawing, cssTokenNames(markup)));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What each token the markup names is worth where the figure is drawn.
|
|
18
|
+
* @param drawing - The drawing, as it sits on the page.
|
|
19
|
+
* @param names - The tokens it asks for.
|
|
20
|
+
* @returns The values, keyed by token name.
|
|
21
|
+
*/
|
|
22
|
+
function tokenValues(drawing, names) {
|
|
23
|
+
const values = {};
|
|
24
|
+
if (names.length === 0)
|
|
25
|
+
return values;
|
|
26
|
+
const styles = window.getComputedStyle(drawing);
|
|
27
|
+
for (const name of names) {
|
|
28
|
+
values[name] = styles.getPropertyValue(name);
|
|
29
|
+
}
|
|
30
|
+
return values;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=drawingMarkup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drawingMarkup.js","sourceRoot":"","sources":["../../../src/download/core/drawingMarkup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,OAAsB;IAClD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAkB,CAAC;IACvD,MAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAClB,OAAsB,EACtB,KAAwB;IAExB,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A part of a figure the page draws in HTML, painted from where the browser put
|
|
3
|
+
* it.
|
|
4
|
+
*
|
|
5
|
+
* Some figures are not drawings: a periodic table is a grid of buttons, because
|
|
6
|
+
* every cell has to be reachable by Tab and read by a screen reader. Saved as
|
|
7
|
+
* SVG it still has to look like the table the reader saw, so each box, each
|
|
8
|
+
* line round it and each line of words is measured off the page and painted
|
|
9
|
+
* again — never re-derived from the styles that made it, so the copy cannot
|
|
10
|
+
* drift from the screen.
|
|
11
|
+
*
|
|
12
|
+
* What is painted: a box's ground, its border (as drawn on its top edge), its
|
|
13
|
+
* corner, its outline, its opacity, every line of its words in their colour,
|
|
14
|
+
* size, weight and style, and any `<svg>` inside it. What is not: images,
|
|
15
|
+
* gradients, shadows, filters and generated `::before` / `::after` content.
|
|
16
|
+
* Chrome inside the part — `data-figure="chrome"` — is left behind.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* One part of a figure drawn in HTML, as SVG markup.
|
|
20
|
+
* @param part - The element the part is drawn in.
|
|
21
|
+
* @param documentFont - The font family the saved document is set in.
|
|
22
|
+
* @returns The markup, in the part's own coordinates: the caller places it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function figureHtml(part: Element, documentFont: string): string;
|
|
25
|
+
//# sourceMappingURL=figureHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureHtml.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureHtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAqBH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAStE"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A part of a figure the page draws in HTML, painted from where the browser put
|
|
3
|
+
* it.
|
|
4
|
+
*
|
|
5
|
+
* Some figures are not drawings: a periodic table is a grid of buttons, because
|
|
6
|
+
* every cell has to be reachable by Tab and read by a screen reader. Saved as
|
|
7
|
+
* SVG it still has to look like the table the reader saw, so each box, each
|
|
8
|
+
* line round it and each line of words is measured off the page and painted
|
|
9
|
+
* again — never re-derived from the styles that made it, so the copy cannot
|
|
10
|
+
* drift from the screen.
|
|
11
|
+
*
|
|
12
|
+
* What is painted: a box's ground, its border (as drawn on its top edge), its
|
|
13
|
+
* corner, its outline, its opacity, every line of its words in their colour,
|
|
14
|
+
* size, weight and style, and any `<svg>` inside it. What is not: images,
|
|
15
|
+
* gradients, shadows, filters and generated `::before` / `::after` content.
|
|
16
|
+
* Chrome inside the part — `data-figure="chrome"` — is left behind.
|
|
17
|
+
*/
|
|
18
|
+
import { cornerRadius, lineDash, visibleColor } from "./cssPaint.js";
|
|
19
|
+
import { drawingMarkup } from "./drawingMarkup.js";
|
|
20
|
+
import { figureHtmlMarkup } from "./figureHtmlMarkup.js";
|
|
21
|
+
import { lineBoxes } from "./textLines.js";
|
|
22
|
+
/** Chrome inside the part, which is not part of the picture. */
|
|
23
|
+
const CHROME = '[data-figure="chrome"]';
|
|
24
|
+
/**
|
|
25
|
+
* One part of a figure drawn in HTML, as SVG markup.
|
|
26
|
+
* @param part - The element the part is drawn in.
|
|
27
|
+
* @param documentFont - The font family the saved document is set in.
|
|
28
|
+
* @returns The markup, in the part's own coordinates: the caller places it.
|
|
29
|
+
*/
|
|
30
|
+
export function figureHtml(part, documentFont) {
|
|
31
|
+
const context = {
|
|
32
|
+
origin: part.getBoundingClientRect(),
|
|
33
|
+
documentFont,
|
|
34
|
+
range: document.createRange(),
|
|
35
|
+
};
|
|
36
|
+
const paints = [];
|
|
37
|
+
paintElement(part, context, paints);
|
|
38
|
+
return figureHtmlMarkup(paints);
|
|
39
|
+
}
|
|
40
|
+
function paintElement(element, context, into) {
|
|
41
|
+
if (element.matches(CHROME))
|
|
42
|
+
return;
|
|
43
|
+
const styles = window.getComputedStyle(element);
|
|
44
|
+
if (styles.display === 'none')
|
|
45
|
+
return;
|
|
46
|
+
const visible = styles.visibility === 'visible';
|
|
47
|
+
const box = element.getBoundingClientRect();
|
|
48
|
+
if (element instanceof SVGSVGElement) {
|
|
49
|
+
if (!visible || box.width <= 0 || box.height <= 0)
|
|
50
|
+
return;
|
|
51
|
+
into.push({
|
|
52
|
+
kind: 'drawing',
|
|
53
|
+
markup: drawingMarkup(element),
|
|
54
|
+
x: box.left - context.origin.left,
|
|
55
|
+
y: box.top - context.origin.top,
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const own = [];
|
|
60
|
+
if (visible)
|
|
61
|
+
paintGround(box, styles, context, own);
|
|
62
|
+
for (const child of element.childNodes) {
|
|
63
|
+
if (child instanceof Text) {
|
|
64
|
+
if (visible)
|
|
65
|
+
paintText(child, styles, context, own);
|
|
66
|
+
}
|
|
67
|
+
else if (child instanceof Element) {
|
|
68
|
+
paintElement(child, context, own);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (visible)
|
|
72
|
+
paintOutline(box, styles, context, own);
|
|
73
|
+
if (own.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
const opacity = Number.parseFloat(styles.opacity);
|
|
76
|
+
if (Number.isFinite(opacity) && opacity < 1) {
|
|
77
|
+
into.push({ kind: 'group', opacity, children: own });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const paint of own)
|
|
81
|
+
into.push(paint);
|
|
82
|
+
}
|
|
83
|
+
function paintGround(box, styles, context, into) {
|
|
84
|
+
if (box.width <= 0 || box.height <= 0)
|
|
85
|
+
return;
|
|
86
|
+
const x = box.left - context.origin.left;
|
|
87
|
+
const y = box.top - context.origin.top;
|
|
88
|
+
const radius = cornerRadius(styles.borderTopLeftRadius, box.width, box.height);
|
|
89
|
+
const fill = visibleColor(styles.backgroundColor);
|
|
90
|
+
if (fill !== undefined) {
|
|
91
|
+
into.push({
|
|
92
|
+
kind: 'box',
|
|
93
|
+
x,
|
|
94
|
+
y,
|
|
95
|
+
width: box.width,
|
|
96
|
+
height: box.height,
|
|
97
|
+
radius,
|
|
98
|
+
fill,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// A border lies inside the box, where a stroke straddles its line: the
|
|
102
|
+
// stroke is drawn half a width in, over the ground the page drew under it.
|
|
103
|
+
const width = Number.parseFloat(styles.borderTopWidth);
|
|
104
|
+
const dash = lineDash(styles.borderTopStyle, width);
|
|
105
|
+
const stroke = visibleColor(styles.borderTopColor);
|
|
106
|
+
if (dash === undefined || stroke === undefined)
|
|
107
|
+
return;
|
|
108
|
+
const half = width / 2;
|
|
109
|
+
into.push({
|
|
110
|
+
kind: 'box',
|
|
111
|
+
x: x + half,
|
|
112
|
+
y: y + half,
|
|
113
|
+
width: box.width - width,
|
|
114
|
+
height: box.height - width,
|
|
115
|
+
radius: Math.max(0, radius - half),
|
|
116
|
+
stroke,
|
|
117
|
+
strokeWidth: width,
|
|
118
|
+
dash,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function paintOutline(box, styles, context, into) {
|
|
122
|
+
const width = Number.parseFloat(styles.outlineWidth);
|
|
123
|
+
const dash = lineDash(styles.outlineStyle, width);
|
|
124
|
+
const stroke = visibleColor(styles.outlineColor);
|
|
125
|
+
if (dash === undefined || stroke === undefined)
|
|
126
|
+
return;
|
|
127
|
+
const offset = Number.parseFloat(styles.outlineOffset) || 0;
|
|
128
|
+
const grow = offset + width / 2;
|
|
129
|
+
const radius = cornerRadius(styles.borderTopLeftRadius, box.width, box.height);
|
|
130
|
+
into.push({
|
|
131
|
+
kind: 'box',
|
|
132
|
+
x: box.left - context.origin.left - grow,
|
|
133
|
+
y: box.top - context.origin.top - grow,
|
|
134
|
+
width: box.width + grow * 2,
|
|
135
|
+
height: box.height + grow * 2,
|
|
136
|
+
radius: radius > 0 ? Math.max(0, radius + grow) : 0,
|
|
137
|
+
stroke,
|
|
138
|
+
strokeWidth: width,
|
|
139
|
+
dash,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function paintText(node, styles, context, into) {
|
|
143
|
+
const color = visibleColor(styles.color);
|
|
144
|
+
if (color === undefined || node.data.trim() === '')
|
|
145
|
+
return;
|
|
146
|
+
const fontSize = Number.parseFloat(styles.fontSize);
|
|
147
|
+
const fontStyle = styles.fontStyle === 'normal' ? undefined : styles.fontStyle;
|
|
148
|
+
const fontFamily = styles.fontFamily === context.documentFont ? undefined : styles.fontFamily;
|
|
149
|
+
for (const line of lineBoxes(node, context.range)) {
|
|
150
|
+
const words = transformed(node.data.slice(line.start, line.end).replaceAll(/\s+/g, ' ').trim(), styles.textTransform);
|
|
151
|
+
if (words === '')
|
|
152
|
+
continue;
|
|
153
|
+
into.push({
|
|
154
|
+
kind: 'text',
|
|
155
|
+
text: words,
|
|
156
|
+
x: line.left - context.origin.left,
|
|
157
|
+
y: (line.top + line.bottom) / 2 - context.origin.top,
|
|
158
|
+
width: line.right - line.left,
|
|
159
|
+
color,
|
|
160
|
+
fontSize,
|
|
161
|
+
fontWeight: styles.fontWeight,
|
|
162
|
+
fontStyle,
|
|
163
|
+
fontFamily,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function transformed(words, transform) {
|
|
168
|
+
if (transform === 'uppercase')
|
|
169
|
+
return words.toUpperCase();
|
|
170
|
+
if (transform === 'lowercase')
|
|
171
|
+
return words.toLowerCase();
|
|
172
|
+
return words;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=figureHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureHtml.js","sourceRoot":"","sources":["../../../src/download/core/figureHtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,gEAAgE;AAChE,MAAM,MAAM,GAAG,wBAAwB,CAAC;AAYxC;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa,EAAE,YAAoB;IAC5D,MAAM,OAAO,GAAiB;QAC5B,MAAM,EAAE,IAAI,CAAC,qBAAqB,EAAE;QACpC,YAAY;QACZ,KAAK,EAAE,QAAQ,CAAC,WAAW,EAAE;KAC9B,CAAC;IACF,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACpC,OAAO,gBAA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HTML, written out as SVG.
|
|
3
|
+
*
|
|
4
|
+
* The part is measured off the page first (`figureHtml.ts`); what reaches this
|
|
5
|
+
* module is already a list of boxes, runs of words and drawings with where each
|
|
6
|
+
* one sits, so the file it becomes can be read — and tested — without a page.
|
|
7
|
+
*/
|
|
8
|
+
/** A box the browser painted: a ground, a line round it, or both. */
|
|
9
|
+
export interface HtmlPaintBox {
|
|
10
|
+
/** What it is. */
|
|
11
|
+
kind: 'box';
|
|
12
|
+
/** Its left edge, in pixels from the left of the part. */
|
|
13
|
+
x: number;
|
|
14
|
+
/** Its top edge, in pixels from the top of the part. */
|
|
15
|
+
y: number;
|
|
16
|
+
/** Its width, in pixels. */
|
|
17
|
+
width: number;
|
|
18
|
+
/** Its height. */
|
|
19
|
+
height: number;
|
|
20
|
+
/**
|
|
21
|
+
* How round its corners are, in pixels.
|
|
22
|
+
* @default 0
|
|
23
|
+
*/
|
|
24
|
+
radius?: number;
|
|
25
|
+
/**
|
|
26
|
+
* What fills it.
|
|
27
|
+
* @default undefined — it is not filled
|
|
28
|
+
*/
|
|
29
|
+
fill?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The colour of the line round it, centred on its edge.
|
|
32
|
+
* @default undefined — no line is drawn
|
|
33
|
+
*/
|
|
34
|
+
stroke?: string;
|
|
35
|
+
/**
|
|
36
|
+
* How heavy that line is, in pixels.
|
|
37
|
+
* @default 1
|
|
38
|
+
*/
|
|
39
|
+
strokeWidth?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The line's dashes and gaps, in pixels.
|
|
42
|
+
* @default undefined — a solid line
|
|
43
|
+
*/
|
|
44
|
+
dash?: readonly number[];
|
|
45
|
+
}
|
|
46
|
+
/** One line of words, set where the browser set it. */
|
|
47
|
+
export interface HtmlPaintText {
|
|
48
|
+
/** What it is. */
|
|
49
|
+
kind: 'text';
|
|
50
|
+
/** What it says, its spaces already collapsed. */
|
|
51
|
+
text: string;
|
|
52
|
+
/** Its left edge, in pixels from the left of the part. */
|
|
53
|
+
x: number;
|
|
54
|
+
/** The middle of its line, in pixels from the top of the part. */
|
|
55
|
+
y: number;
|
|
56
|
+
/**
|
|
57
|
+
* How wide the browser drew it. The words are fitted to it, so a run the
|
|
58
|
+
* page condensed stays condensed and a reader opening the file with another
|
|
59
|
+
* font gets the same layout.
|
|
60
|
+
*/
|
|
61
|
+
width: number;
|
|
62
|
+
/** Its colour. */
|
|
63
|
+
color: string;
|
|
64
|
+
/** Its size, in pixels. */
|
|
65
|
+
fontSize: number;
|
|
66
|
+
/** Its weight. */
|
|
67
|
+
fontWeight: string;
|
|
68
|
+
/**
|
|
69
|
+
* Its style.
|
|
70
|
+
* @default undefined — upright
|
|
71
|
+
*/
|
|
72
|
+
fontStyle?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Its type, where it is not the one the document is set in.
|
|
75
|
+
* @default undefined — the document's own
|
|
76
|
+
*/
|
|
77
|
+
fontFamily?: string;
|
|
78
|
+
}
|
|
79
|
+
/** A drawing inside the part, already an SVG of its own. */
|
|
80
|
+
export interface HtmlPaintDrawing {
|
|
81
|
+
/** What it is. */
|
|
82
|
+
kind: 'drawing';
|
|
83
|
+
/** The `<svg>` element as it was serialized, tokens already resolved. */
|
|
84
|
+
markup: string;
|
|
85
|
+
/** Its left edge, in pixels from the left of the part. */
|
|
86
|
+
x: number;
|
|
87
|
+
/** Its top edge, in pixels from the top of the part. */
|
|
88
|
+
y: number;
|
|
89
|
+
}
|
|
90
|
+
/** Everything inside an element the page drew faded. */
|
|
91
|
+
export interface HtmlPaintGroup {
|
|
92
|
+
/** What it is. */
|
|
93
|
+
kind: 'group';
|
|
94
|
+
/** How opaque the whole of it is, from 0 to 1. */
|
|
95
|
+
opacity: number;
|
|
96
|
+
/** What it holds, in the order it is painted. */
|
|
97
|
+
children: readonly HtmlPaint[];
|
|
98
|
+
}
|
|
99
|
+
/** One thing painted from a part of the page. */
|
|
100
|
+
export type HtmlPaint = HtmlPaintBox | HtmlPaintText | HtmlPaintDrawing | HtmlPaintGroup;
|
|
101
|
+
/**
|
|
102
|
+
* The part, as the markup that goes into the saved figure.
|
|
103
|
+
* @param paints - What was measured, in the order it is painted.
|
|
104
|
+
* @returns The markup, in the part's own coordinates: the caller places it.
|
|
105
|
+
*/
|
|
106
|
+
export declare function figureHtmlMarkup(paints: readonly HtmlPaint[]): string;
|
|
107
|
+
//# sourceMappingURL=figureHtmlMarkup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureHtmlMarkup.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureHtmlMarkup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,kBAAkB;IAClB,IAAI,EAAE,KAAK,CAAC;IACZ,0DAA0D;IAC1D,CAAC,EAAE,MAAM,CAAC;IACV,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;IACV,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,CAAC,EAAE,MAAM,CAAC;IACV,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;IACV;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,CAAC,EAAE,MAAM,CAAC;IACV,wDAAwD;IACxD,CAAC,EAAE,MAAM,CAAC;CACX;AAED,wDAAwD;AACxD,MAAM,WAAW,cAAc;IAC7B,kBAAkB;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,SAAS,SAAS,EAAE,CAAC;CAChC;AAED,iDAAiD;AACjD,MAAM,MAAM,SAAS,GACnB,YAAY,GAAG,aAAa,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAIrE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A part of a figure drawn in HTML, written out as SVG.
|
|
3
|
+
*
|
|
4
|
+
* The part is measured off the page first (`figureHtml.ts`); what reaches this
|
|
5
|
+
* module is already a list of boxes, runs of words and drawings with where each
|
|
6
|
+
* one sits, so the file it becomes can be read — and tested — without a page.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The part, as the markup that goes into the saved figure.
|
|
10
|
+
* @param paints - What was measured, in the order it is painted.
|
|
11
|
+
* @returns The markup, in the part's own coordinates: the caller places it.
|
|
12
|
+
*/
|
|
13
|
+
export function figureHtmlMarkup(paints) {
|
|
14
|
+
let markup = '';
|
|
15
|
+
for (const paint of paints)
|
|
16
|
+
markup += paintMarkup(paint);
|
|
17
|
+
return markup;
|
|
18
|
+
}
|
|
19
|
+
function paintMarkup(paint) {
|
|
20
|
+
switch (paint.kind) {
|
|
21
|
+
case 'box':
|
|
22
|
+
return boxMarkup(paint);
|
|
23
|
+
case 'text':
|
|
24
|
+
return textMarkup(paint);
|
|
25
|
+
case 'drawing':
|
|
26
|
+
return `<g transform="translate(${round(paint.x)} ${round(paint.y)})">${paint.markup}</g>`;
|
|
27
|
+
case 'group':
|
|
28
|
+
return `<g opacity="${round(paint.opacity)}">${figureHtmlMarkup(paint.children)}</g>`;
|
|
29
|
+
default:
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function boxMarkup(box) {
|
|
34
|
+
const { x, y, width, height, fill, stroke, dash } = box;
|
|
35
|
+
const { radius = 0, strokeWidth = 1 } = box;
|
|
36
|
+
if (fill === undefined && stroke === undefined)
|
|
37
|
+
return '';
|
|
38
|
+
const line = stroke === undefined
|
|
39
|
+
? ''
|
|
40
|
+
: ` stroke="${attribute(stroke)}" stroke-width="${round(strokeWidth)}"${dash === undefined || dash.length === 0
|
|
41
|
+
? ''
|
|
42
|
+
: ` stroke-dasharray="${dash.map(round).join(' ')}"`}`;
|
|
43
|
+
return (`<rect x="${round(x)}" y="${round(y)}"` +
|
|
44
|
+
` width="${round(Math.max(0, width))}" height="${round(Math.max(0, height))}"${radius > 0 ? ` rx="${round(radius)}"` : ''} fill="${attribute(fill ?? 'none')}"${line}/>`);
|
|
45
|
+
}
|
|
46
|
+
function textMarkup(run) {
|
|
47
|
+
if (run.text === '')
|
|
48
|
+
return '';
|
|
49
|
+
const style = run.fontStyle === undefined || run.fontStyle === 'normal'
|
|
50
|
+
? ''
|
|
51
|
+
: ` font-style="${attribute(run.fontStyle)}"`;
|
|
52
|
+
const family = run.fontFamily === undefined
|
|
53
|
+
? ''
|
|
54
|
+
: ` font-family="${attribute(run.fontFamily)}"`;
|
|
55
|
+
return (`<text x="${round(run.x)}" y="${round(run.y)}" dominant-baseline="central"` +
|
|
56
|
+
` textLength="${round(run.width)}" lengthAdjust="spacingAndGlyphs"` +
|
|
57
|
+
` fill="${attribute(run.color)}" font-size="${round(run.fontSize)}px"` +
|
|
58
|
+
` font-weight="${attribute(run.fontWeight)}"${style}${family}>` +
|
|
59
|
+
`${text(run.text)}</text>`);
|
|
60
|
+
}
|
|
61
|
+
function attribute(value) {
|
|
62
|
+
return text(value).replaceAll('"', '"');
|
|
63
|
+
}
|
|
64
|
+
function text(value) {
|
|
65
|
+
return value
|
|
66
|
+
.replaceAll('&', '&')
|
|
67
|
+
.replaceAll('<', '<')
|
|
68
|
+
.replaceAll('>', '>');
|
|
69
|
+
}
|
|
70
|
+
function round(value) {
|
|
71
|
+
if (!Number.isFinite(value))
|
|
72
|
+
return 0;
|
|
73
|
+
return Math.round(value * 100) / 100;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=figureHtmlMarkup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figureHtmlMarkup.js","sourceRoot":"","sources":["../../../src/download/core/figureHtmlMarkup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAqGH;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA4B;IAC3D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAgB;IACnC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,KAAK;YACR,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,MAAM;YACT,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,SAAS;YACZ,OAAO,2BAA2B,KAAK,CAAC,KAAK,CAAC,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E,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,KAAK,CAAC,KAAa;IAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureSvg.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"figureSvg.d.ts","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgBH,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;AAe7D;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,GAAE,gBAAqB,GAC7B,SAAS,CAuDX"}
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* page resolves to nothing. And the type, which a chart inherits from the page
|
|
7
7
|
* around it and would otherwise be reset to whatever opens the file.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { drawingMarkup } from "./drawingMarkup.js";
|
|
10
|
+
import { figureHtml } from "./figureHtml.js";
|
|
10
11
|
import { figureLegendMarkup } from "./figureLegend.js";
|
|
11
12
|
import { figureSvgDocument } from "./figureSvgDocument.js";
|
|
12
|
-
import { figureBounds, figureDrawings, figureElement, figureLegends, } from "./figureTarget.js";
|
|
13
|
+
import { figureBounds, figureDrawings, figureElement, figureLegends, figurePaintings, } from "./figureTarget.js";
|
|
13
14
|
/** What a saved SVG figure is, for the file and for the renderer reading it. */
|
|
14
15
|
export const FIGURE_SVG_TYPE = 'image/svg+xml;charset=utf-8';
|
|
15
16
|
/** The token a figure's own ground is named by. */
|
|
@@ -26,10 +27,12 @@ const FALLBACK_SURFACE = '#ffffff';
|
|
|
26
27
|
export function figureSvg(target, options = {}) {
|
|
27
28
|
const element = figureElement(target);
|
|
28
29
|
const drawings = figureDrawings(element);
|
|
29
|
-
|
|
30
|
+
const paintings = figurePaintings(element);
|
|
31
|
+
if (drawings.length === 0 && paintings.length === 0) {
|
|
30
32
|
throw new Error('That part of the page holds no figure to save.');
|
|
31
33
|
}
|
|
32
|
-
const bounds = figureBounds(drawings);
|
|
34
|
+
const bounds = figureBounds([...drawings, ...paintings]);
|
|
35
|
+
const styles = window.getComputedStyle(element);
|
|
33
36
|
const pieces = [];
|
|
34
37
|
for (const drawing of drawings) {
|
|
35
38
|
const box = drawing.getBoundingClientRect();
|
|
@@ -39,6 +42,15 @@ export function figureSvg(target, options = {}) {
|
|
|
39
42
|
y: box.top - bounds.top,
|
|
40
43
|
});
|
|
41
44
|
}
|
|
45
|
+
for (const part of paintings) {
|
|
46
|
+
const box = part.getBoundingClientRect();
|
|
47
|
+
pieces.push({
|
|
48
|
+
markup: figureHtml(part, styles.fontFamily),
|
|
49
|
+
x: box.left - bounds.left,
|
|
50
|
+
y: box.top - bounds.top,
|
|
51
|
+
kind: 'html',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
42
54
|
for (const legend of figureLegends(element)) {
|
|
43
55
|
const box = legend.getBoundingClientRect();
|
|
44
56
|
if (box.width <= 0 || box.height <= 0)
|
|
@@ -50,7 +62,6 @@ export function figureSvg(target, options = {}) {
|
|
|
50
62
|
kind: 'legend',
|
|
51
63
|
});
|
|
52
64
|
}
|
|
53
|
-
const styles = window.getComputedStyle(element);
|
|
54
65
|
const markup = figureSvgDocument(pieces, {
|
|
55
66
|
width: bounds.width,
|
|
56
67
|
height: bounds.height,
|
|
@@ -148,36 +159,6 @@ function textRuns(legend) {
|
|
|
148
159
|
}
|
|
149
160
|
return runs;
|
|
150
161
|
}
|
|
151
|
-
/**
|
|
152
|
-
* One drawing, serialized with every token it names written out.
|
|
153
|
-
*
|
|
154
|
-
* The copy is taken first and read from the original, because the values are a
|
|
155
|
-
* property of where the figure sits on the page: a detached clone inherits
|
|
156
|
-
* nothing and would resolve every token to an empty string.
|
|
157
|
-
* @param drawing - The drawing, as it sits on the page.
|
|
158
|
-
* @returns Its markup.
|
|
159
|
-
*/
|
|
160
|
-
function drawingMarkup(drawing) {
|
|
161
|
-
const clone = drawing.cloneNode(true);
|
|
162
|
-
const markup = new XMLSerializer().serializeToString(clone);
|
|
163
|
-
return resolveCssTokens(markup, tokenValues(drawing, cssTokenNames(markup)));
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* What each token the markup names is worth where the figure is drawn.
|
|
167
|
-
* @param drawing - The drawing, as it sits on the page.
|
|
168
|
-
* @param names - The tokens it asks for.
|
|
169
|
-
* @returns The values, keyed by token name.
|
|
170
|
-
*/
|
|
171
|
-
function tokenValues(drawing, names) {
|
|
172
|
-
const values = {};
|
|
173
|
-
if (names.length === 0)
|
|
174
|
-
return values;
|
|
175
|
-
const styles = window.getComputedStyle(drawing);
|
|
176
|
-
for (const name of names) {
|
|
177
|
-
values[name] = styles.getPropertyValue(name);
|
|
178
|
-
}
|
|
179
|
-
return values;
|
|
180
|
-
}
|
|
181
162
|
/**
|
|
182
163
|
* The ground the figure is standing on.
|
|
183
164
|
* @param styles - The computed style of the box it is mounted in.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figureSvg.js","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"figureSvg.js","sourceRoot":"","sources":["../../../src/download/core/figureSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,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,EACb,eAAe,GAChB,MAAM,mBAAmB,CAAC;AA4B3B,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAS7D,mDAAmD;AACnD,MAAM,aAAa,GAAG,WAAW,CAAC;AAElC,uEAAuE;AACvE,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,MAAwB,EACxB,UAA4B,EAAE;IAE9B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,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