@antv/infographic 0.2.11 → 0.2.12
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/dist/infographic.min.js +1 -1
- package/dist/infographic.min.js.map +1 -1
- package/esm/designs/components/Btn.js +15 -4
- package/esm/designs/components/BtnsGroup.js +1 -1
- package/esm/designs/components/Illus.js +15 -3
- package/esm/designs/components/ItemDesc.js +17 -11
- package/esm/designs/components/ItemIcon.js +17 -18
- package/esm/designs/components/ItemLabel.js +17 -11
- package/esm/designs/components/ItemValue.js +17 -12
- package/esm/designs/components/ItemsGroup.js +1 -1
- package/esm/designs/components/ShapesGroup.js +1 -1
- package/esm/designs/components/Title.js +2 -2
- package/esm/designs/decorations/simple-arrow.js +14 -2
- package/esm/designs/decorations/triangle.js +14 -2
- package/esm/designs/defs/DropShadow.js +13 -2
- package/esm/designs/defs/LinearGradient.js +1 -1
- package/esm/designs/items/BadgeCard.js +2 -2
- package/esm/designs/items/CandyCardLite.js +1 -1
- package/esm/designs/items/CapsuleItem.js +3 -3
- package/esm/designs/items/CircleNode.js +1 -1
- package/esm/designs/items/CircularProgress.js +3 -2
- package/esm/designs/items/CompactCard.js +1 -1
- package/esm/designs/items/DoneList.js +1 -1
- package/esm/designs/items/HorizontalIconArrow.js +2 -2
- package/esm/designs/items/HorizontalIconLine.js +2 -2
- package/esm/designs/items/IconBadge.js +4 -3
- package/esm/designs/items/IndexedCard.js +1 -1
- package/esm/designs/items/LCornerCard.js +1 -1
- package/esm/designs/items/LetterCard.js +4 -3
- package/esm/designs/items/LinedText.js +6 -5
- package/esm/designs/items/PillBadge.js +2 -2
- package/esm/designs/items/PlainText.js +4 -4
- package/esm/designs/items/ProgressCard.js +4 -4
- package/esm/designs/items/QuarterCircular.js +1 -1
- package/esm/designs/items/QuarterSimpleCard.js +1 -1
- package/esm/designs/items/RibbonCard.js +2 -2
- package/esm/designs/items/RoundedRectNode.js +2 -2
- package/esm/designs/items/SimpleCircleNode.js +1 -1
- package/esm/designs/items/SimpleHorizontalArrow.js +2 -2
- package/esm/designs/items/SimpleIllusItem.js +1 -1
- package/esm/designs/items/SimpleItem.js +3 -3
- package/esm/designs/items/SimpleVerticalArrow.js +2 -2
- package/esm/designs/items/UnderlineText.js +1 -1
- package/esm/designs/items/VerticalIconArrow.js +2 -2
- package/esm/designs/layouts/Align.js +22 -15
- package/esm/designs/layouts/Flex.js +23 -16
- package/esm/designs/structures/chart-bar.js +7 -5
- package/esm/designs/structures/chart-column.js +3 -2
- package/esm/designs/structures/chart-line.js +7 -5
- package/esm/designs/structures/chart-pie.js +4 -3
- package/esm/designs/structures/chart-wordcloud.js +5 -14
- package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
- package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
- package/esm/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
- package/esm/designs/structures/compare-hierarchy-left-right.js +6 -5
- package/esm/designs/structures/compare-hierarchy-row.js +3 -2
- package/esm/designs/structures/compare-quadrant.js +2 -3
- package/esm/designs/structures/hierarchy-mindmap.js +19 -19
- package/esm/designs/structures/hierarchy-structure.js +1 -1
- package/esm/designs/structures/hierarchy-tree.js +15 -24
- package/esm/designs/structures/list-sector.js +5 -6
- package/esm/designs/structures/list-zigzag.js +2 -1
- package/esm/designs/structures/relation-dagre-flow.js +30 -35
- package/esm/designs/structures/relation-network.js +2 -2
- package/esm/designs/structures/sequence-funnel.js +1 -1
- package/esm/designs/structures/sequence-mountain.js +4 -4
- package/esm/designs/structures/sequence-pyramid.js +1 -1
- package/esm/designs/structures/sequence-zigzag-steps.js +2 -1
- package/esm/designs/utils/color.js +8 -4
- package/esm/designs/utils/item.js +3 -2
- package/esm/editor/commands/Batch.js +21 -8
- package/esm/editor/commands/UpdateElement.js +25 -22
- package/esm/editor/commands/UpdateOptions.js +23 -10
- package/esm/editor/commands/UpdateText.js +24 -11
- package/esm/editor/interactions/brush-select.js +27 -13
- package/esm/editor/interactions/click-select.js +13 -3
- package/esm/editor/interactions/dblclick-edit-text.js +36 -20
- package/esm/editor/interactions/drag-element.js +23 -9
- package/esm/editor/interactions/hotkey-history.js +17 -7
- package/esm/editor/interactions/select-highlight.js +5 -9
- package/esm/editor/interactions/zoom-wheel.js +2 -1
- package/esm/editor/managers/command.js +45 -27
- package/esm/editor/managers/interaction.js +46 -33
- package/esm/editor/managers/state.js +1 -1
- package/esm/editor/plugins/edit-bar/components/color-picker.js +9 -6
- package/esm/editor/plugins/edit-bar/components/popover.js +15 -12
- package/esm/editor/plugins/edit-bar/components/select.js +10 -8
- package/esm/editor/plugins/edit-bar/edit-bar.js +7 -25
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
- package/esm/editor/plugins/resize-element.js +6 -4
- package/esm/editor/utils/click-handler.js +6 -3
- package/esm/editor/utils/coordinate.js +2 -1
- package/esm/editor/utils/element.js +2 -1
- package/esm/editor/utils/event.js +2 -1
- package/esm/editor/utils/extension.js +1 -1
- package/esm/editor/utils/hotkey.js +2 -1
- package/esm/exporter/font.js +106 -90
- package/esm/exporter/png.js +49 -37
- package/esm/exporter/svg.js +55 -38
- package/esm/jsx/components/Ellipse.js +5 -4
- package/esm/jsx/components/Path.js +2 -4
- package/esm/jsx/components/Polygon.js +15 -6
- package/esm/jsx/components/Text.js +21 -41
- package/esm/jsx/renderer.js +15 -7
- package/esm/jsx/utils/bounds.js +18 -16
- package/esm/jsx/utils/children.js +2 -1
- package/esm/jsx/utils/clone.js +13 -2
- package/esm/jsx/utils/element.js +2 -1
- package/esm/options/parser.js +45 -46
- package/esm/renderer/composites/background.js +3 -2
- package/esm/renderer/composites/icon.js +14 -19
- package/esm/renderer/composites/illus.js +17 -22
- package/esm/renderer/composites/shape.js +4 -2
- package/esm/renderer/composites/svg.js +2 -1
- package/esm/renderer/composites/text.js +5 -3
- package/esm/renderer/fonts/loader.js +4 -3
- package/esm/renderer/fonts/registry.js +1 -1
- package/esm/renderer/palettes/utils.js +3 -2
- package/esm/renderer/renderer.js +7 -5
- package/esm/renderer/stylize/gradient.js +3 -2
- package/esm/renderer/stylize/pattern.js +15 -8
- package/esm/renderer/stylize/rough.js +1 -1
- package/esm/resource/load-tracker.js +22 -10
- package/esm/resource/loader.js +80 -67
- package/esm/resource/loaders/image.js +71 -59
- package/esm/resource/loaders/remote.js +26 -15
- package/esm/resource/loaders/search.js +38 -25
- package/esm/resource/utils/parser.js +2 -1
- package/esm/runtime/Infographic.js +26 -13
- package/esm/runtime/utils.js +5 -8
- package/esm/ssr/renderer.js +42 -35
- package/esm/syntax/index.js +19 -6
- package/esm/syntax/mapper.js +2 -2
- package/esm/templates/built-in.js +96 -200
- package/esm/templates/hierarchy-mindmap.js +1 -5
- package/esm/templates/hierarchy-tree.js +1 -5
- package/esm/templates/relation-dagre-flow.js +4 -28
- package/esm/themes/generator.js +8 -14
- package/esm/utils/fetch.js +48 -35
- package/esm/utils/icon.js +1 -4
- package/esm/utils/is-browser.js +2 -2
- package/esm/utils/measure-text.js +2 -1
- package/esm/utils/padding.js +1 -1
- package/esm/utils/recognizer.js +2 -1
- package/esm/utils/text.js +14 -3
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/designs/components/Btn.js +15 -4
- package/lib/designs/components/BtnsGroup.js +1 -1
- package/lib/designs/components/Illus.js +15 -3
- package/lib/designs/components/ItemDesc.js +17 -11
- package/lib/designs/components/ItemIcon.js +17 -18
- package/lib/designs/components/ItemLabel.js +17 -11
- package/lib/designs/components/ItemValue.js +17 -12
- package/lib/designs/components/ItemsGroup.js +1 -1
- package/lib/designs/components/ShapesGroup.js +1 -1
- package/lib/designs/components/Title.js +2 -2
- package/lib/designs/decorations/simple-arrow.js +14 -2
- package/lib/designs/decorations/triangle.js +14 -2
- package/lib/designs/defs/DropShadow.js +13 -2
- package/lib/designs/defs/LinearGradient.js +1 -1
- package/lib/designs/items/BadgeCard.js +2 -2
- package/lib/designs/items/CandyCardLite.js +1 -1
- package/lib/designs/items/CapsuleItem.js +3 -3
- package/lib/designs/items/CircleNode.js +1 -1
- package/lib/designs/items/CircularProgress.js +3 -2
- package/lib/designs/items/CompactCard.js +1 -1
- package/lib/designs/items/DoneList.js +1 -1
- package/lib/designs/items/HorizontalIconArrow.js +2 -2
- package/lib/designs/items/HorizontalIconLine.js +2 -2
- package/lib/designs/items/IconBadge.js +4 -3
- package/lib/designs/items/IndexedCard.js +1 -1
- package/lib/designs/items/LCornerCard.js +1 -1
- package/lib/designs/items/LetterCard.js +4 -3
- package/lib/designs/items/LinedText.js +6 -5
- package/lib/designs/items/PillBadge.js +2 -2
- package/lib/designs/items/PlainText.js +4 -4
- package/lib/designs/items/ProgressCard.js +4 -4
- package/lib/designs/items/QuarterCircular.js +1 -1
- package/lib/designs/items/QuarterSimpleCard.js +1 -1
- package/lib/designs/items/RibbonCard.js +2 -2
- package/lib/designs/items/RoundedRectNode.js +2 -2
- package/lib/designs/items/SimpleCircleNode.js +1 -1
- package/lib/designs/items/SimpleHorizontalArrow.js +2 -2
- package/lib/designs/items/SimpleIllusItem.js +1 -1
- package/lib/designs/items/SimpleItem.js +3 -3
- package/lib/designs/items/SimpleVerticalArrow.js +2 -2
- package/lib/designs/items/UnderlineText.js +1 -1
- package/lib/designs/items/VerticalIconArrow.js +2 -2
- package/lib/designs/layouts/Align.js +22 -15
- package/lib/designs/layouts/Flex.js +23 -16
- package/lib/designs/structures/chart-bar.js +7 -5
- package/lib/designs/structures/chart-column.js +3 -2
- package/lib/designs/structures/chart-line.js +7 -5
- package/lib/designs/structures/chart-pie.js +4 -3
- package/lib/designs/structures/chart-wordcloud.js +5 -14
- package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
- package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
- package/lib/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
- package/lib/designs/structures/compare-hierarchy-left-right.js +6 -5
- package/lib/designs/structures/compare-hierarchy-row.js +3 -2
- package/lib/designs/structures/compare-quadrant.js +2 -3
- package/lib/designs/structures/hierarchy-mindmap.js +19 -19
- package/lib/designs/structures/hierarchy-structure.js +1 -1
- package/lib/designs/structures/hierarchy-tree.js +15 -24
- package/lib/designs/structures/list-sector.js +5 -6
- package/lib/designs/structures/list-zigzag.js +2 -1
- package/lib/designs/structures/relation-dagre-flow.js +30 -35
- package/lib/designs/structures/relation-network.js +2 -2
- package/lib/designs/structures/sequence-funnel.js +1 -1
- package/lib/designs/structures/sequence-mountain.js +4 -4
- package/lib/designs/structures/sequence-pyramid.js +1 -1
- package/lib/designs/structures/sequence-zigzag-steps.js +2 -1
- package/lib/designs/utils/color.js +8 -4
- package/lib/designs/utils/item.js +3 -2
- package/lib/editor/commands/Batch.js +21 -8
- package/lib/editor/commands/UpdateElement.js +25 -22
- package/lib/editor/commands/UpdateOptions.js +23 -10
- package/lib/editor/commands/UpdateText.js +24 -11
- package/lib/editor/interactions/brush-select.js +27 -13
- package/lib/editor/interactions/click-select.js +13 -3
- package/lib/editor/interactions/dblclick-edit-text.js +36 -20
- package/lib/editor/interactions/drag-element.js +23 -9
- package/lib/editor/interactions/hotkey-history.js +17 -7
- package/lib/editor/interactions/select-highlight.js +5 -9
- package/lib/editor/interactions/zoom-wheel.js +2 -1
- package/lib/editor/managers/command.js +43 -25
- package/lib/editor/managers/interaction.js +46 -33
- package/lib/editor/managers/state.js +1 -1
- package/lib/editor/plugins/edit-bar/components/color-picker.js +9 -6
- package/lib/editor/plugins/edit-bar/components/popover.js +15 -12
- package/lib/editor/plugins/edit-bar/components/select.js +10 -8
- package/lib/editor/plugins/edit-bar/edit-bar.js +7 -25
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
- package/lib/editor/plugins/resize-element.js +6 -4
- package/lib/editor/utils/click-handler.js +6 -3
- package/lib/editor/utils/coordinate.js +2 -1
- package/lib/editor/utils/element.js +2 -1
- package/lib/editor/utils/event.js +2 -1
- package/lib/editor/utils/extension.js +1 -1
- package/lib/editor/utils/hotkey.js +2 -1
- package/lib/exporter/font.js +106 -90
- package/lib/exporter/png.js +49 -37
- package/lib/exporter/svg.js +55 -38
- package/lib/jsx/components/Ellipse.js +5 -4
- package/lib/jsx/components/Path.js +2 -4
- package/lib/jsx/components/Polygon.js +15 -6
- package/lib/jsx/components/Text.js +21 -41
- package/lib/jsx/renderer.js +15 -7
- package/lib/jsx/utils/bounds.js +18 -16
- package/lib/jsx/utils/children.js +2 -1
- package/lib/jsx/utils/clone.js +13 -2
- package/lib/jsx/utils/element.js +2 -1
- package/lib/options/parser.js +45 -46
- package/lib/renderer/composites/background.js +3 -2
- package/lib/renderer/composites/icon.js +14 -19
- package/lib/renderer/composites/illus.js +17 -22
- package/lib/renderer/composites/shape.js +4 -2
- package/lib/renderer/composites/svg.js +2 -1
- package/lib/renderer/composites/text.js +5 -3
- package/lib/renderer/fonts/loader.js +4 -3
- package/lib/renderer/fonts/registry.js +1 -1
- package/lib/renderer/palettes/utils.js +3 -2
- package/lib/renderer/renderer.js +7 -5
- package/lib/renderer/stylize/gradient.js +3 -2
- package/lib/renderer/stylize/pattern.js +15 -8
- package/lib/renderer/stylize/rough.js +1 -1
- package/lib/resource/load-tracker.js +22 -10
- package/lib/resource/loader.js +80 -67
- package/lib/resource/loaders/image.js +71 -59
- package/lib/resource/loaders/remote.js +26 -15
- package/lib/resource/loaders/search.js +38 -25
- package/lib/resource/utils/parser.js +2 -1
- package/lib/runtime/Infographic.js +26 -13
- package/lib/runtime/utils.js +5 -8
- package/lib/ssr/renderer.js +42 -35
- package/lib/syntax/index.js +19 -6
- package/lib/syntax/mapper.js +2 -2
- package/lib/templates/built-in.js +96 -200
- package/lib/templates/hierarchy-mindmap.js +1 -5
- package/lib/templates/hierarchy-tree.js +1 -5
- package/lib/templates/relation-dagre-flow.js +4 -28
- package/lib/themes/generator.js +8 -14
- package/lib/utils/fetch.js +48 -35
- package/lib/utils/icon.js +1 -4
- package/lib/utils/is-browser.js +2 -2
- package/lib/utils/measure-text.js +2 -1
- package/lib/utils/padding.js +1 -1
- package/lib/utils/recognizer.js +2 -1
- package/lib/utils/text.js +14 -3
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/version.ts +1 -1
package/esm/exporter/svg.js
CHANGED
|
@@ -1,39 +1,54 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { createElement, getElementByRole, getViewBox, setAttributes, setElementRole, traverse, } from '../utils/index.js';
|
|
2
11
|
import { embedFonts } from './font.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { embedResources = true, removeIds = false } = options;
|
|
10
|
-
const clonedSVG = svg.cloneNode(true);
|
|
11
|
-
const { width, height } = getViewBox(svg);
|
|
12
|
-
setAttributes(clonedSVG, { width, height });
|
|
13
|
-
if (removeIds) {
|
|
14
|
-
inlineUseElements(clonedSVG);
|
|
15
|
-
inlineDefsReferences(clonedSVG);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
await embedIcons(clonedSVG);
|
|
19
|
-
}
|
|
20
|
-
await embedFonts(clonedSVG, embedResources);
|
|
21
|
-
cleanSVG(clonedSVG);
|
|
22
|
-
return clonedSVG;
|
|
12
|
+
export function exportToSVGString(svg_1) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
|
|
14
|
+
const node = yield exportToSVG(svg, options);
|
|
15
|
+
const str = new XMLSerializer().serializeToString(node);
|
|
16
|
+
return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(str);
|
|
17
|
+
});
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const symbolElement = document.querySelector(href);
|
|
34
|
-
if (symbolElement)
|
|
35
|
-
defs.appendChild(symbolElement.cloneNode(true));
|
|
19
|
+
export function exportToSVG(svg_1) {
|
|
20
|
+
return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
|
|
21
|
+
const { embedResources = true, removeIds = false } = options;
|
|
22
|
+
const clonedSVG = svg.cloneNode(true);
|
|
23
|
+
const { width, height } = getViewBox(svg);
|
|
24
|
+
setAttributes(clonedSVG, { width, height });
|
|
25
|
+
if (removeIds) {
|
|
26
|
+
inlineUseElements(clonedSVG);
|
|
27
|
+
inlineDefsReferences(clonedSVG);
|
|
36
28
|
}
|
|
29
|
+
else {
|
|
30
|
+
yield embedIcons(clonedSVG);
|
|
31
|
+
}
|
|
32
|
+
yield embedFonts(clonedSVG, embedResources);
|
|
33
|
+
cleanSVG(clonedSVG);
|
|
34
|
+
return clonedSVG;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function embedIcons(svg) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const icons = svg.querySelectorAll('use');
|
|
40
|
+
const defs = getDefs(svg);
|
|
41
|
+
icons.forEach((icon) => {
|
|
42
|
+
const href = icon.getAttribute('href');
|
|
43
|
+
if (!href)
|
|
44
|
+
return;
|
|
45
|
+
const existsSymbol = svg.querySelector(href);
|
|
46
|
+
if (!existsSymbol) {
|
|
47
|
+
const symbolElement = document.querySelector(href);
|
|
48
|
+
if (symbolElement)
|
|
49
|
+
defs.appendChild(symbolElement.cloneNode(true));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
37
52
|
});
|
|
38
53
|
}
|
|
39
54
|
const iconRole = 'icon-defs';
|
|
@@ -64,7 +79,8 @@ function inlineUseElements(svg) {
|
|
|
64
79
|
});
|
|
65
80
|
}
|
|
66
81
|
function getUseHref(use) {
|
|
67
|
-
|
|
82
|
+
var _a;
|
|
83
|
+
return (_a = use.getAttribute('href')) !== null && _a !== void 0 ? _a : use.getAttribute('xlink:href');
|
|
68
84
|
}
|
|
69
85
|
function resolveUseTarget(svg, href) {
|
|
70
86
|
const localTarget = svg.querySelector(href);
|
|
@@ -112,10 +128,11 @@ function materializeElement(use, source) {
|
|
|
112
128
|
return wrapper;
|
|
113
129
|
}
|
|
114
130
|
function buildUseTransform(use) {
|
|
131
|
+
var _a;
|
|
115
132
|
const x = use.getAttribute('x');
|
|
116
133
|
const y = use.getAttribute('y');
|
|
117
|
-
const translate = x || y ? `translate(${x
|
|
118
|
-
const transform = use.getAttribute('transform')
|
|
134
|
+
const translate = x || y ? `translate(${x !== null && x !== void 0 ? x : 0} ${y !== null && y !== void 0 ? y : 0})` : '';
|
|
135
|
+
const transform = (_a = use.getAttribute('transform')) !== null && _a !== void 0 ? _a : '';
|
|
119
136
|
if (translate && transform)
|
|
120
137
|
return `${translate} ${transform}`;
|
|
121
138
|
return translate || transform || null;
|
|
@@ -269,13 +286,13 @@ function cleanSVG(svg) {
|
|
|
269
286
|
}
|
|
270
287
|
function removeBtnGroup(svg) {
|
|
271
288
|
const btnGroup = getElementByRole(svg, "btns-group" /* ElementTypeEnum.BtnsGroup */);
|
|
272
|
-
btnGroup
|
|
289
|
+
btnGroup === null || btnGroup === void 0 ? void 0 : btnGroup.remove();
|
|
273
290
|
const btnIconDefs = getElementByRole(svg, 'btn-icon-defs');
|
|
274
|
-
btnIconDefs
|
|
291
|
+
btnIconDefs === null || btnIconDefs === void 0 ? void 0 : btnIconDefs.remove();
|
|
275
292
|
}
|
|
276
293
|
function removeTransientContainer(svg) {
|
|
277
294
|
const transientContainer = svg.querySelector('[data-element-type=transient-container]');
|
|
278
|
-
transientContainer
|
|
295
|
+
transientContainer === null || transientContainer === void 0 ? void 0 : transientContainer.remove();
|
|
279
296
|
}
|
|
280
297
|
function removeUselessAttrs(svg) {
|
|
281
298
|
const groups = svg.querySelectorAll('g');
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export function Ellipse(props) {
|
|
2
|
+
var _a, _b, _c, _d;
|
|
2
3
|
const { x = 0, y = 0, width = 0, height = 0 } = props;
|
|
3
|
-
props.cx
|
|
4
|
-
props.cy
|
|
5
|
-
props.rx
|
|
6
|
-
props.ry
|
|
4
|
+
(_a = props.cx) !== null && _a !== void 0 ? _a : (props.cx = x + width / 2);
|
|
5
|
+
(_b = props.cy) !== null && _b !== void 0 ? _b : (props.cy = y + height / 2);
|
|
6
|
+
(_c = props.rx) !== null && _c !== void 0 ? _c : (props.rx = width / 2);
|
|
7
|
+
(_d = props.ry) !== null && _d !== void 0 ? _d : (props.ry = height / 2);
|
|
7
8
|
const node = {
|
|
8
9
|
type: 'ellipse',
|
|
9
10
|
props,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export function Path(props) {
|
|
2
2
|
const { x, y } = props;
|
|
3
|
-
const finalProps = {
|
|
4
|
-
...props,
|
|
5
|
-
};
|
|
3
|
+
const finalProps = Object.assign({}, props);
|
|
6
4
|
if (x !== undefined || y !== undefined) {
|
|
7
|
-
finalProps.transform = `translate(${x
|
|
5
|
+
finalProps.transform = `translate(${x !== null && x !== void 0 ? x : 0}, ${y !== null && y !== void 0 ? y : 0})`;
|
|
8
6
|
}
|
|
9
7
|
const node = {
|
|
10
8
|
type: 'path',
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
export function Polygon(_a) {
|
|
13
|
+
var { points = [] } = _a, props = __rest(_a, ["points"]);
|
|
2
14
|
const { x, y } = props;
|
|
3
15
|
const pointsStr = points.map(({ x, y }) => `${x},${y}`).join(' ');
|
|
4
|
-
const finalProps = {
|
|
5
|
-
...props,
|
|
6
|
-
points: pointsStr,
|
|
7
|
-
};
|
|
16
|
+
const finalProps = Object.assign(Object.assign({}, props), { points: pointsStr });
|
|
8
17
|
if (x !== undefined || y !== undefined) {
|
|
9
18
|
finalProps.transform =
|
|
10
|
-
`translate(${x
|
|
19
|
+
`translate(${x !== null && x !== void 0 ? x : 0}, ${y !== null && y !== void 0 ? y : 0})` + (finalProps.transform || '');
|
|
11
20
|
}
|
|
12
21
|
const node = {
|
|
13
22
|
type: 'polygon',
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { measureText } from '../../utils/index.js';
|
|
2
13
|
export function Text(props) {
|
|
3
|
-
const { id, x = 0, y = 0, width: w, height: h, alignHorizontal = 'left', alignVertical = 'top', children, fontSize = 14, fontFamily, fontStyle, fontWeight, textDecoration, letterSpacing, wordSpacing, opacity, fill = 'black', lineHeight, wordWrap, backgroundColor = 'none', backgroundOpacity = 1, backgroundRadius = 0,
|
|
14
|
+
const { id, x = 0, y = 0, width: w, height: h, alignHorizontal = 'left', alignVertical = 'top', children, fontSize = 14, fontFamily, fontStyle, fontWeight, textDecoration, letterSpacing, wordSpacing, opacity, fill = 'black', lineHeight, wordWrap, backgroundColor = 'none', backgroundOpacity = 1, backgroundRadius = 0 } = props, restProps = __rest(props, ["id", "x", "y", "width", "height", "alignHorizontal", "alignVertical", "children", "fontSize", "fontFamily", "fontStyle", "fontWeight", "textDecoration", "letterSpacing", "wordSpacing", "opacity", "fill", "lineHeight", "wordWrap", "backgroundColor", "backgroundOpacity", "backgroundRadius"]);
|
|
4
15
|
let width = w;
|
|
5
16
|
let height = h;
|
|
6
17
|
let textX = 0;
|
|
@@ -27,12 +38,8 @@ export function Text(props) {
|
|
|
27
38
|
? height
|
|
28
39
|
: 0;
|
|
29
40
|
}
|
|
30
|
-
const dataAttrs = Object.entries({
|
|
31
|
-
|
|
32
|
-
height,
|
|
33
|
-
...(lineHeight !== undefined && { 'line-height': lineHeight }),
|
|
34
|
-
...(wordWrap !== undefined && { 'data-word-wrap': wordWrap }),
|
|
35
|
-
}).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
41
|
+
const dataAttrs = Object.entries(Object.assign(Object.assign({ width,
|
|
42
|
+
height }, (lineHeight !== undefined && { 'line-height': lineHeight })), (wordWrap !== undefined && { 'data-word-wrap': wordWrap }))).reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), {});
|
|
36
43
|
const textAnchor = alignHorizontal === 'center'
|
|
37
44
|
? 'middle'
|
|
38
45
|
: alignHorizontal === 'right'
|
|
@@ -43,37 +50,13 @@ export function Text(props) {
|
|
|
43
50
|
: alignVertical === 'bottom'
|
|
44
51
|
? 'baseline'
|
|
45
52
|
: 'hanging';
|
|
46
|
-
const textProps = {
|
|
47
|
-
'data-
|
|
48
|
-
width,
|
|
49
|
-
height,
|
|
50
|
-
x: textX,
|
|
51
|
-
y: textY,
|
|
52
|
-
'data-x': 0,
|
|
53
|
-
'data-y': 0,
|
|
54
|
-
fill,
|
|
53
|
+
const textProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ 'data-element-type': 'text', width,
|
|
54
|
+
height, x: textX, y: textY, 'data-x': 0, 'data-y': 0, fill,
|
|
55
55
|
fontSize,
|
|
56
56
|
textAnchor,
|
|
57
|
-
dominantBaseline,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
children,
|
|
61
|
-
...dataAttrs,
|
|
62
|
-
...restProps,
|
|
63
|
-
...(fontFamily && { fontFamily }),
|
|
64
|
-
...(fontStyle && { fontStyle }),
|
|
65
|
-
...(fontWeight && { fontWeight }),
|
|
66
|
-
...(textDecoration && textDecoration !== 'none' && { textDecoration }),
|
|
67
|
-
...(letterSpacing && { letterSpacing }),
|
|
68
|
-
...(wordSpacing && { wordSpacing }),
|
|
69
|
-
...(opacity !== undefined && opacity !== 1 && { opacity }),
|
|
70
|
-
};
|
|
71
|
-
const containerProps = {
|
|
72
|
-
...(x !== 0 || y !== 0 ? { x, y, transform: `translate(${x}, ${y})` } : {}),
|
|
73
|
-
width,
|
|
74
|
-
height,
|
|
75
|
-
...(id && { id }),
|
|
76
|
-
};
|
|
57
|
+
dominantBaseline, 'data-horizontal-align': alignHorizontal.toUpperCase(), 'data-vertical-align': alignVertical.toUpperCase(), children }, dataAttrs), restProps), (fontFamily && { fontFamily })), (fontStyle && { fontStyle })), (fontWeight && { fontWeight })), (textDecoration && textDecoration !== 'none' && { textDecoration })), (letterSpacing && { letterSpacing })), (wordSpacing && { wordSpacing })), (opacity !== undefined && opacity !== 1 && { opacity }));
|
|
58
|
+
const containerProps = Object.assign(Object.assign(Object.assign({}, (x !== 0 || y !== 0 ? { x, y, transform: `translate(${x}, ${y})` } : {})), { width,
|
|
59
|
+
height }), (id && { id }));
|
|
77
60
|
const hasBackground = backgroundColor && backgroundColor !== 'none';
|
|
78
61
|
const rectProps = hasBackground
|
|
79
62
|
? {
|
|
@@ -90,12 +73,9 @@ export function Text(props) {
|
|
|
90
73
|
: undefined;
|
|
91
74
|
return {
|
|
92
75
|
type: 'g',
|
|
93
|
-
props: {
|
|
94
|
-
...containerProps,
|
|
95
|
-
children: [
|
|
76
|
+
props: Object.assign(Object.assign({}, containerProps), { children: [
|
|
96
77
|
...(rectProps ? [{ type: 'rect', props: rectProps }] : []),
|
|
97
78
|
{ type: 'text', props: textProps },
|
|
98
|
-
],
|
|
99
|
-
},
|
|
79
|
+
] }),
|
|
100
80
|
};
|
|
101
81
|
}
|
package/esm/jsx/renderer.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { DefsSymbol } from './components/index.js';
|
|
2
13
|
import { Fragment } from './jsx-runtime.js';
|
|
3
14
|
import { isLayoutComponent, performLayout } from './layout.js';
|
|
@@ -97,14 +108,11 @@ export function renderSVG(element, props = {}) {
|
|
|
97
108
|
const content = Array.isArray(processed)
|
|
98
109
|
? processed.map((el) => render(el, context)).join('')
|
|
99
110
|
: render(processed, context);
|
|
100
|
-
const { x, y, width, height, style,
|
|
101
|
-
const finalProps = {
|
|
102
|
-
...rest,
|
|
103
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
104
|
-
};
|
|
111
|
+
const { x, y, width, height, style } = props, rest = __rest(props, ["x", "y", "width", "height", "style"]);
|
|
112
|
+
const finalProps = Object.assign(Object.assign({}, rest), { xmlns: 'http://www.w3.org/2000/svg' });
|
|
105
113
|
if (!finalProps.viewBox) {
|
|
106
114
|
if (width && height) {
|
|
107
|
-
finalProps.viewBox = `${x
|
|
115
|
+
finalProps.viewBox = `${x !== null && x !== void 0 ? x : 0} ${y !== null && y !== void 0 ? y : 0} ${width !== null && width !== void 0 ? width : 0} ${height !== null && height !== void 0 ? height : 0}`;
|
|
108
116
|
}
|
|
109
117
|
else {
|
|
110
118
|
const bounds = getElementBounds(processed);
|
|
@@ -129,7 +137,7 @@ export function renderSVG(element, props = {}) {
|
|
|
129
137
|
function renderAttrs(props) {
|
|
130
138
|
if (!props)
|
|
131
139
|
return '';
|
|
132
|
-
const { children,
|
|
140
|
+
const { children } = props, attributes = __rest(props, ["children"]);
|
|
133
141
|
return Object.entries(attributes)
|
|
134
142
|
.filter(([, value]) => value !== undefined && value !== null)
|
|
135
143
|
.map(([key, value]) => {
|
package/esm/jsx/utils/bounds.js
CHANGED
|
@@ -37,6 +37,7 @@ export function getCombinedBounds(list) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
export function getElementBounds(node) {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
40
41
|
if (!node)
|
|
41
42
|
return zero();
|
|
42
43
|
if (Array.isArray(node)) {
|
|
@@ -51,8 +52,8 @@ export function getElementBounds(node) {
|
|
|
51
52
|
return getElementBounds(layoutResult);
|
|
52
53
|
}
|
|
53
54
|
if (typeof type === 'function') {
|
|
54
|
-
const externalX = props.x
|
|
55
|
-
const externalY = props.y
|
|
55
|
+
const externalX = (_a = props.x) !== null && _a !== void 0 ? _a : 0;
|
|
56
|
+
const externalY = (_b = props.y) !== null && _b !== void 0 ? _b : 0;
|
|
56
57
|
const externalWidth = props.width;
|
|
57
58
|
const externalHeight = props.height;
|
|
58
59
|
if (isNumber(externalWidth) && isNumber(externalHeight)) {
|
|
@@ -68,8 +69,8 @@ export function getElementBounds(node) {
|
|
|
68
69
|
return {
|
|
69
70
|
x: externalX,
|
|
70
71
|
y: externalY,
|
|
71
|
-
width: externalWidth
|
|
72
|
-
height: externalHeight
|
|
72
|
+
width: externalWidth !== null && externalWidth !== void 0 ? externalWidth : 0,
|
|
73
|
+
height: externalHeight !== null && externalHeight !== void 0 ? externalHeight : 0,
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
76
|
if (Array.isArray(renderedResult)) {
|
|
@@ -84,8 +85,8 @@ export function getElementBounds(node) {
|
|
|
84
85
|
height: externalHeight,
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
|
-
const width = innerBounds.width !== 0 ? innerBounds.width : (externalWidth
|
|
88
|
-
const height = innerBounds.height !== 0 ? innerBounds.height : (externalHeight
|
|
88
|
+
const width = innerBounds.width !== 0 ? innerBounds.width : (externalWidth !== null && externalWidth !== void 0 ? externalWidth : 0);
|
|
89
|
+
const height = innerBounds.height !== 0 ? innerBounds.height : (externalHeight !== null && externalHeight !== void 0 ? externalHeight : 0);
|
|
89
90
|
return {
|
|
90
91
|
x: externalX + innerBounds.x,
|
|
91
92
|
y: externalY + innerBounds.y,
|
|
@@ -134,8 +135,8 @@ export function getElementBounds(node) {
|
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
const width = innerBounds.width !== 0 ? innerBounds.width : (externalWidth
|
|
138
|
-
const height = innerBounds.height !== 0 ? innerBounds.height : (externalHeight
|
|
138
|
+
const width = innerBounds.width !== 0 ? innerBounds.width : (externalWidth !== null && externalWidth !== void 0 ? externalWidth : 0);
|
|
139
|
+
const height = innerBounds.height !== 0 ? innerBounds.height : (externalHeight !== null && externalHeight !== void 0 ? externalHeight : 0);
|
|
139
140
|
return {
|
|
140
141
|
x: innerHasSamePosition ? innerBounds.x : externalX + innerBounds.x,
|
|
141
142
|
y: innerHasSamePosition ? innerBounds.y : externalY + innerBounds.y,
|
|
@@ -146,12 +147,12 @@ export function getElementBounds(node) {
|
|
|
146
147
|
return {
|
|
147
148
|
x: externalX,
|
|
148
149
|
y: externalY,
|
|
149
|
-
width: externalWidth
|
|
150
|
-
height: externalHeight
|
|
150
|
+
width: externalWidth !== null && externalWidth !== void 0 ? externalWidth : 0,
|
|
151
|
+
height: externalHeight !== null && externalHeight !== void 0 ? externalHeight : 0,
|
|
151
152
|
};
|
|
152
153
|
}
|
|
153
|
-
const x = props.x
|
|
154
|
-
const y = props.y
|
|
154
|
+
const x = (_c = props.x) !== null && _c !== void 0 ? _c : 0;
|
|
155
|
+
const y = (_d = props.y) !== null && _d !== void 0 ? _d : 0;
|
|
155
156
|
const width = isNumber(props.width) ? props.width : undefined;
|
|
156
157
|
const height = isNumber(props.height) ? props.height : undefined;
|
|
157
158
|
if (isNumber(width) && isNumber(height)) {
|
|
@@ -173,8 +174,8 @@ export function getElementBounds(node) {
|
|
|
173
174
|
return {
|
|
174
175
|
x,
|
|
175
176
|
y,
|
|
176
|
-
width: width
|
|
177
|
-
height: height
|
|
177
|
+
width: width !== null && width !== void 0 ? width : 0,
|
|
178
|
+
height: height !== null && height !== void 0 ? height : 0,
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
export function getElementsBounds(elements) {
|
|
@@ -194,7 +195,7 @@ export function getElementsBounds(elements) {
|
|
|
194
195
|
return getCombinedBounds(list);
|
|
195
196
|
}
|
|
196
197
|
function isPassthrough(innerElement, externalProps) {
|
|
197
|
-
if (!innerElement
|
|
198
|
+
if (!(innerElement === null || innerElement === void 0 ? void 0 : innerElement.props) || !externalProps) {
|
|
198
199
|
return false;
|
|
199
200
|
}
|
|
200
201
|
const inner = innerElement.props;
|
|
@@ -229,8 +230,9 @@ function isPassthrough(innerElement, externalProps) {
|
|
|
229
230
|
return false;
|
|
230
231
|
}
|
|
231
232
|
function getChildrenFromElement(element) {
|
|
233
|
+
var _a;
|
|
232
234
|
// React 风格:只从 props.children 获取子元素
|
|
233
|
-
const children = element.props
|
|
235
|
+
const children = (_a = element.props) === null || _a === void 0 ? void 0 : _a.children;
|
|
234
236
|
if (!children) {
|
|
235
237
|
return [];
|
|
236
238
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { nodeToRenderableNodes } from './element.js';
|
|
2
2
|
export function getRenderableChildrenOf(element) {
|
|
3
|
+
var _a;
|
|
3
4
|
if (element === null ||
|
|
4
5
|
element === undefined ||
|
|
5
6
|
typeof element === 'boolean') {
|
|
@@ -8,7 +9,7 @@ export function getRenderableChildrenOf(element) {
|
|
|
8
9
|
if (Array.isArray(element))
|
|
9
10
|
return nodeToRenderableNodes(element);
|
|
10
11
|
if (typeof element === 'object') {
|
|
11
|
-
return nodeToRenderableNodes(element.props
|
|
12
|
+
return nodeToRenderableNodes((_a = element.props) === null || _a === void 0 ? void 0 : _a.children);
|
|
12
13
|
}
|
|
13
14
|
return [element];
|
|
14
15
|
}
|
package/esm/jsx/utils/clone.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
export const cloneElement = (element, props) => {
|
|
2
|
-
const { type, props: originalProps,
|
|
3
|
-
return { type, props: {
|
|
13
|
+
const { type, props: originalProps } = element, rest = __rest(element, ["type", "props"]);
|
|
14
|
+
return Object.assign({ type, props: Object.assign(Object.assign({}, originalProps), props) }, rest);
|
|
4
15
|
};
|
package/esm/jsx/utils/element.js
CHANGED
|
@@ -4,6 +4,7 @@ export function nodeToElements(node) {
|
|
|
4
4
|
return nodeToRenderableNodes(node).filter(isJSXElement);
|
|
5
5
|
}
|
|
6
6
|
export function nodeToRenderableNodes(node, result = []) {
|
|
7
|
+
var _a;
|
|
7
8
|
if (!node || typeof node === 'boolean') {
|
|
8
9
|
return result;
|
|
9
10
|
}
|
|
@@ -12,7 +13,7 @@ export function nodeToRenderableNodes(node, result = []) {
|
|
|
12
13
|
}
|
|
13
14
|
else {
|
|
14
15
|
if (isFragment(node)) {
|
|
15
|
-
const children = node.props
|
|
16
|
+
const children = (_a = node.props) === null || _a === void 0 ? void 0 : _a.children;
|
|
16
17
|
(Array.isArray(children) ? children : [children])
|
|
17
18
|
.filter(Boolean)
|
|
18
19
|
.forEach((child) => {
|