@antv/infographic 0.2.11 → 0.2.13
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 +98 -94
- 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.d.ts +25 -0
- package/esm/designs/structures/chart-pie.js +186 -26
- 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/index.d.ts +1 -0
- package/esm/designs/utils/index.js +1 -0
- package/esm/designs/utils/item.js +3 -2
- package/esm/designs/utils/normalize-percent.d.ts +19 -0
- package/esm/designs/utils/normalize-percent.js +32 -0
- 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.d.ts +3 -0
- package/esm/editor/interactions/zoom-wheel.js +46 -22
- package/esm/editor/managers/command.js +45 -27
- package/esm/editor/managers/interaction.js +46 -33
- package/esm/editor/managers/state.js +9 -3
- 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 +91 -269
- package/esm/templates/chart-pie.d.ts +2 -0
- package/esm/templates/chart-pie.js +87 -0
- 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/utils/viewbox.d.ts +20 -0
- package/esm/utils/viewbox.js +10 -0
- 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.d.ts +25 -0
- package/lib/designs/structures/chart-pie.js +186 -25
- 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/index.d.ts +1 -0
- package/lib/designs/utils/index.js +1 -0
- package/lib/designs/utils/item.js +3 -2
- package/lib/designs/utils/normalize-percent.d.ts +19 -0
- package/lib/designs/utils/normalize-percent.js +35 -0
- 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.d.ts +3 -0
- package/lib/editor/interactions/zoom-wheel.js +45 -21
- package/lib/editor/managers/command.js +43 -25
- package/lib/editor/managers/interaction.js +46 -33
- package/lib/editor/managers/state.js +9 -3
- 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 +91 -269
- package/lib/templates/chart-pie.d.ts +2 -0
- package/lib/templates/chart-pie.js +90 -0
- 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/utils/viewbox.d.ts +20 -0
- package/lib/utils/viewbox.js +12 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -2
- package/src/designs/structures/chart-pie.tsx +259 -26
- package/src/designs/utils/index.ts +1 -0
- package/src/designs/utils/normalize-percent.ts +33 -0
- package/src/editor/interactions/zoom-wheel.ts +64 -22
- package/src/editor/managers/state.ts +10 -5
- package/src/templates/built-in.ts +2 -81
- package/src/templates/chart-pie.ts +89 -0
- package/src/utils/viewbox.ts +23 -0
- package/src/version.ts +1 -1
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.loadSearchResource = loadSearchResource;
|
|
4
13
|
const constants_1 = require("../../constants");
|
|
@@ -6,15 +15,16 @@ const utils_1 = require("../../utils");
|
|
|
6
15
|
const image_1 = require("./image");
|
|
7
16
|
const remote_1 = require("./remote");
|
|
8
17
|
const svg_1 = require("./svg");
|
|
9
|
-
const queryIcon =
|
|
18
|
+
const queryIcon = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
10
20
|
try {
|
|
11
21
|
const params = new URLSearchParams({ text: query, topK: '1' });
|
|
12
22
|
const url = `${constants_1.ICON_SERVICE_URL}?${params.toString()}`;
|
|
13
|
-
const response =
|
|
23
|
+
const response = yield (0, utils_1.fetchWithCache)(url);
|
|
14
24
|
if (!response.ok)
|
|
15
25
|
return null;
|
|
16
|
-
const result =
|
|
17
|
-
if (!result
|
|
26
|
+
const result = yield response.json();
|
|
27
|
+
if (!(result === null || result === void 0 ? void 0 : result.status) || !Array.isArray((_a = result.data) === null || _a === void 0 ? void 0 : _a.data))
|
|
18
28
|
return null;
|
|
19
29
|
return result.data.data[0] || null;
|
|
20
30
|
}
|
|
@@ -22,7 +32,7 @@ const queryIcon = async (query) => {
|
|
|
22
32
|
console.error(`Failed to query icon for "${query}":`, error);
|
|
23
33
|
return null;
|
|
24
34
|
}
|
|
25
|
-
};
|
|
35
|
+
});
|
|
26
36
|
function isDataURI(resource) {
|
|
27
37
|
return resource.startsWith('data:');
|
|
28
38
|
}
|
|
@@ -30,26 +40,29 @@ function looksLikeSVG(resource) {
|
|
|
30
40
|
const str = resource.trim();
|
|
31
41
|
return str.startsWith('<svg') || str.startsWith('<symbol');
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
function loadSearchResource(query, format) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var _a;
|
|
46
|
+
if (!query)
|
|
47
|
+
return null;
|
|
48
|
+
const result = yield queryIcon(query);
|
|
49
|
+
if (!result)
|
|
50
|
+
return null;
|
|
51
|
+
if (looksLikeSVG(result))
|
|
52
|
+
return (0, svg_1.loadSVGResource)(result);
|
|
53
|
+
if (isDataURI(result)) {
|
|
54
|
+
const mimeType = ((_a = result.match(/^data:([^;]+)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
55
|
+
const isBase64 = result.includes(';base64,');
|
|
56
|
+
if (mimeType === 'image/svg+xml' && !isBase64) {
|
|
57
|
+
const commaIndex = result.indexOf(',');
|
|
58
|
+
const svgText = commaIndex >= 0 ? result.slice(commaIndex + 1) : result;
|
|
59
|
+
return (0, svg_1.loadSVGResource)(svgText);
|
|
60
|
+
}
|
|
61
|
+
if (mimeType === 'image/svg+xml' && format === 'svg' && isBase64) {
|
|
62
|
+
return (0, image_1.loadImageBase64Resource)(result);
|
|
63
|
+
}
|
|
50
64
|
return (0, image_1.loadImageBase64Resource)(result);
|
|
51
65
|
}
|
|
52
|
-
return (0,
|
|
53
|
-
}
|
|
54
|
-
return (0, remote_1.loadRemoteResource)(result, format);
|
|
66
|
+
return (0, remote_1.loadRemoteResource)(result, format);
|
|
67
|
+
});
|
|
55
68
|
}
|
|
@@ -21,6 +21,7 @@ function inferFormatFromUrl(url) {
|
|
|
21
21
|
return undefined;
|
|
22
22
|
}
|
|
23
23
|
function parseRefResource(resource) {
|
|
24
|
+
var _a;
|
|
24
25
|
if (!resource.startsWith('ref:'))
|
|
25
26
|
return null;
|
|
26
27
|
const rest = resource.slice(4);
|
|
@@ -29,7 +30,7 @@ function parseRefResource(resource) {
|
|
|
29
30
|
return null;
|
|
30
31
|
let format;
|
|
31
32
|
if (restParts.length > 1 && KNOWN_FORMATS.has(restParts[0].toLowerCase())) {
|
|
32
|
-
format = restParts.shift()
|
|
33
|
+
format = (_a = restParts.shift()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
33
34
|
}
|
|
34
35
|
const payload = restParts.join(':');
|
|
35
36
|
if (!payload)
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -61,6 +70,7 @@ class Infographic {
|
|
|
61
70
|
this.performRender();
|
|
62
71
|
}
|
|
63
72
|
performRender() {
|
|
73
|
+
var _a;
|
|
64
74
|
const parsedOptions = this.parsedOptions;
|
|
65
75
|
if (!(0, utils_2.isCompleteParsedInfographicOptions)(parsedOptions)) {
|
|
66
76
|
this.emitter.emit('error', new Error('Incomplete options'));
|
|
@@ -70,8 +80,8 @@ class Infographic {
|
|
|
70
80
|
const template = this.compose(parsedOptions);
|
|
71
81
|
const renderer = new renderer_1.Renderer(parsedOptions, template);
|
|
72
82
|
this.node = renderer.render();
|
|
73
|
-
container
|
|
74
|
-
this.editor
|
|
83
|
+
container === null || container === void 0 ? void 0 : container.replaceChildren(this.node);
|
|
84
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
75
85
|
this.editor = undefined;
|
|
76
86
|
if (this.options.editable) {
|
|
77
87
|
this.editor = new editor_1.Editor(this.emitter, this.node, parsedOptions);
|
|
@@ -101,7 +111,7 @@ class Infographic {
|
|
|
101
111
|
const Title = title.component;
|
|
102
112
|
const Item = item.component;
|
|
103
113
|
const Items = items.map((it) => it.component);
|
|
104
|
-
const svg = (0, jsx_1.renderSVG)((0, jsx_runtime_1.jsx)(Structure, { data: data, Title: Title, Item: Item, Items: Items, options: parsedOptions,
|
|
114
|
+
const svg = (0, jsx_1.renderSVG)((0, jsx_runtime_1.jsx)(Structure, Object.assign({ data: data, Title: Title, Item: Item, Items: Items, options: parsedOptions }, structureProps)));
|
|
105
115
|
const template = (0, utils_1.parseSVG)(svg);
|
|
106
116
|
if (!template) {
|
|
107
117
|
throw new Error('Failed to parse SVG template');
|
|
@@ -125,14 +135,16 @@ class Infographic {
|
|
|
125
135
|
* @returns Data URL string of the exported infographic
|
|
126
136
|
* @description This method need to be called after `render()` and in a browser environment.
|
|
127
137
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
toDataURL(options) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
if (!this.node) {
|
|
141
|
+
throw new Error('Infographic is not rendered yet.');
|
|
142
|
+
}
|
|
143
|
+
if ((options === null || options === void 0 ? void 0 : options.type) === 'svg') {
|
|
144
|
+
return yield (0, exporter_1.exportToSVGString)(this.node, options);
|
|
145
|
+
}
|
|
146
|
+
return yield (0, exporter_1.exportToPNGString)(this.node, options);
|
|
147
|
+
});
|
|
136
148
|
}
|
|
137
149
|
on(event, listener) {
|
|
138
150
|
this.emitter.on(event, listener);
|
|
@@ -141,8 +153,9 @@ class Infographic {
|
|
|
141
153
|
this.emitter.off(event, listener);
|
|
142
154
|
}
|
|
143
155
|
destroy() {
|
|
144
|
-
|
|
145
|
-
this.
|
|
156
|
+
var _a, _b;
|
|
157
|
+
(_a = this.editor) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
158
|
+
(_b = this.node) === null || _b === void 0 ? void 0 : _b.remove();
|
|
146
159
|
this.node = null;
|
|
147
160
|
this.rendered = false;
|
|
148
161
|
this.emitter.emit('destroyed');
|
package/lib/runtime/utils.js
CHANGED
|
@@ -6,23 +6,20 @@ exports.isCompleteParsedInfographicOptions = isCompleteParsedInfographicOptions;
|
|
|
6
6
|
const lodash_es_1 = require("lodash-es");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
function mergeOptions(object, source) {
|
|
9
|
-
const base = {
|
|
10
|
-
...object,
|
|
11
|
-
...source,
|
|
12
|
-
};
|
|
9
|
+
const base = Object.assign(Object.assign({}, object), source);
|
|
13
10
|
if (object.design || source.design) {
|
|
14
|
-
base.design = {
|
|
11
|
+
base.design = Object.assign(Object.assign({}, object.design), source.design);
|
|
15
12
|
}
|
|
16
13
|
if (object.themeConfig || source.themeConfig) {
|
|
17
|
-
base.themeConfig = {
|
|
14
|
+
base.themeConfig = Object.assign(Object.assign({}, object.themeConfig), source.themeConfig);
|
|
18
15
|
}
|
|
19
16
|
if (object.svg || source.svg) {
|
|
20
|
-
base.svg = {
|
|
17
|
+
base.svg = Object.assign(Object.assign({}, object.svg), source.svg);
|
|
21
18
|
}
|
|
22
19
|
return base;
|
|
23
20
|
}
|
|
24
21
|
function cloneOptions(options) {
|
|
25
|
-
const cloned = {
|
|
22
|
+
const cloned = Object.assign({}, options);
|
|
26
23
|
if (cloned.data)
|
|
27
24
|
cloned.data = (0, lodash_es_1.cloneDeep)(cloned.data);
|
|
28
25
|
if (cloned.elements)
|
package/lib/ssr/renderer.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.renderToString = renderToString;
|
|
4
13
|
const exporter_1 = require("../exporter");
|
|
@@ -6,43 +15,41 @@ const renderer_1 = require("../renderer");
|
|
|
6
15
|
const runtime_1 = require("../runtime");
|
|
7
16
|
const utils_1 = require("../utils");
|
|
8
17
|
const dom_shim_1 = require("./dom-shim");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
function renderToString(options, init) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { document } = (0, dom_shim_1.setupDOM)();
|
|
21
|
+
const container = document.getElementById('container');
|
|
22
|
+
let infographic;
|
|
23
|
+
let timeoutId;
|
|
24
|
+
try {
|
|
25
|
+
infographic = new runtime_1.Infographic(Object.assign(Object.assign({}, init), { container, editable: false }));
|
|
26
|
+
const renderPromise = new Promise((resolve, reject) => {
|
|
27
|
+
infographic.on('loaded', (_a) => __awaiter(this, [_a], void 0, function* ({ node }) {
|
|
28
|
+
try {
|
|
29
|
+
const svg = yield (0, exporter_1.exportToSVG)(node, { embedResources: true });
|
|
30
|
+
resolve(svg.outerHTML);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
38
|
+
timeoutId = setTimeout(() => {
|
|
39
|
+
reject(new Error('SSR render timeout'));
|
|
40
|
+
}, 10000);
|
|
29
41
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
reject(new Error('SSR render timeout'));
|
|
34
|
-
}, 10000);
|
|
35
|
-
});
|
|
36
|
-
infographic.render(options);
|
|
37
|
-
const svg = await Promise.race([renderPromise, timeoutPromise]);
|
|
38
|
-
return injectXMLStylesheet(svg);
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
clearTimeout(timeoutId);
|
|
42
|
-
if (infographic) {
|
|
43
|
-
infographic.destroy();
|
|
42
|
+
infographic.render(options);
|
|
43
|
+
const svg = yield Promise.race([renderPromise, timeoutPromise]);
|
|
44
|
+
return injectXMLStylesheet(svg);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
finally {
|
|
47
|
+
clearTimeout(timeoutId);
|
|
48
|
+
if (infographic) {
|
|
49
|
+
infographic.destroy();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
46
53
|
}
|
|
47
54
|
function injectXMLStylesheet(svg) {
|
|
48
55
|
const matched = svg.matchAll(/font-family="([\S ]+?)"/g);
|
package/lib/syntax/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.parseSyntax = parseSyntax;
|
|
4
15
|
const mapper_1 = require("./mapper");
|
|
@@ -6,11 +17,12 @@ const parser_1 = require("./parser");
|
|
|
6
17
|
const relations_1 = require("./relations");
|
|
7
18
|
const schema_1 = require("./schema");
|
|
8
19
|
function normalizeItems(items) {
|
|
20
|
+
var _a;
|
|
9
21
|
const seen = new Set();
|
|
10
22
|
const normalized = [];
|
|
11
23
|
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
12
24
|
const item = items[index];
|
|
13
|
-
const id = item.id
|
|
25
|
+
const id = (_a = item.id) !== null && _a !== void 0 ? _a : item.label;
|
|
14
26
|
if (!id) {
|
|
15
27
|
normalized.push(item);
|
|
16
28
|
continue;
|
|
@@ -38,10 +50,11 @@ function resolveTemplate(node, errors) {
|
|
|
38
50
|
return undefined;
|
|
39
51
|
}
|
|
40
52
|
function parseSyntax(input) {
|
|
53
|
+
var _a;
|
|
41
54
|
const { ast, errors } = (0, parser_1.parseSyntaxToAst)(input);
|
|
42
55
|
const warnings = [];
|
|
43
56
|
const options = {};
|
|
44
|
-
const mergedEntries = {
|
|
57
|
+
const mergedEntries = Object.assign({}, ast.entries);
|
|
45
58
|
const infographicNode = ast.entries.infographic;
|
|
46
59
|
let templateFromInfographic;
|
|
47
60
|
if (infographicNode && infographicNode.kind === 'object') {
|
|
@@ -90,9 +103,9 @@ function parseSyntax(input) {
|
|
|
90
103
|
let relationsNode;
|
|
91
104
|
let dataNodeForMapping = dataNode;
|
|
92
105
|
if (dataNode.kind === 'object') {
|
|
93
|
-
const { relations,
|
|
106
|
+
const _b = dataNode.entries, { relations } = _b, rest = __rest(_b, ["relations"]);
|
|
94
107
|
relationsNode = relations;
|
|
95
|
-
dataNodeForMapping = {
|
|
108
|
+
dataNodeForMapping = Object.assign(Object.assign({}, dataNode), { entries: rest });
|
|
96
109
|
}
|
|
97
110
|
const data = (0, mapper_1.mapWithSchema)(dataNodeForMapping, schema_1.DataSchema, 'data', errors);
|
|
98
111
|
if (data)
|
|
@@ -100,7 +113,7 @@ function parseSyntax(input) {
|
|
|
100
113
|
if (relationsNode) {
|
|
101
114
|
const parsed = (0, relations_1.parseRelationsNode)(relationsNode, errors, 'data.relations');
|
|
102
115
|
if (parsed.relations.length > 0 || parsed.items.length > 0) {
|
|
103
|
-
const current = (options.data
|
|
116
|
+
const current = ((_a = options.data) !== null && _a !== void 0 ? _a : {});
|
|
104
117
|
const existingItems = Array.isArray(current.items)
|
|
105
118
|
? current.items
|
|
106
119
|
: [];
|
|
@@ -131,7 +144,7 @@ function parseSyntax(input) {
|
|
|
131
144
|
if (themeNode) {
|
|
132
145
|
const theme = (0, mapper_1.mapWithSchema)(themeNode, schema_1.ThemeSchema, 'theme', errors);
|
|
133
146
|
if (theme && typeof theme === 'object') {
|
|
134
|
-
const { type,
|
|
147
|
+
const _c = theme, { type } = _c, rest = __rest(_c, ["type"]);
|
|
135
148
|
if (typeof type === 'string' && type)
|
|
136
149
|
options.theme = type;
|
|
137
150
|
if (Object.keys(rest).length > 0) {
|
package/lib/syntax/mapper.js
CHANGED
|
@@ -270,7 +270,7 @@ function mapWithSchema(node, schema, path, errors) {
|
|
|
270
270
|
return result;
|
|
271
271
|
}
|
|
272
272
|
const inline = (0, parser_1.parseInlineKeyValue)(node.value);
|
|
273
|
-
if (inline
|
|
273
|
+
if ((inline === null || inline === void 0 ? void 0 : inline.value) !== undefined) {
|
|
274
274
|
if (schema.fields[inline.key]) {
|
|
275
275
|
const value = mapWithSchema(createValueNode(inline.value, node.line), schema.fields[inline.key], `${path}.${inline.key}`, errors);
|
|
276
276
|
if (value !== undefined)
|
|
@@ -297,7 +297,7 @@ function mapWithSchema(node, schema, path, errors) {
|
|
|
297
297
|
}
|
|
298
298
|
else {
|
|
299
299
|
const inline = (0, parser_1.parseInlineKeyValue)(node.value);
|
|
300
|
-
if (inline
|
|
300
|
+
if ((inline === null || inline === void 0 ? void 0 : inline.value) !== undefined) {
|
|
301
301
|
if (schema.fields[inline.key]) {
|
|
302
302
|
const value = mapWithSchema(createValueNode(inline.value, node.line), schema.fields[inline.key], `${path}.${inline.key}`, errors);
|
|
303
303
|
if (value !== undefined && result[inline.key] === undefined) {
|