@antv/infographic 0.2.13 → 0.2.15
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 +12 -5
- package/README.zh-CN.md +12 -5
- package/dist/infographic.min.js +180 -171
- package/dist/infographic.min.js.map +1 -1
- package/esm/designs/structures/index.d.ts +1 -0
- package/esm/designs/structures/index.js +1 -0
- package/esm/designs/structures/relation-dagre-flow.js +4 -139
- package/esm/designs/structures/sequence-interaction.d.ts +54 -0
- package/esm/designs/structures/sequence-interaction.js +440 -0
- package/esm/designs/utils/geometry.d.ts +44 -0
- package/esm/designs/utils/geometry.js +244 -0
- package/esm/designs/utils/index.d.ts +1 -0
- package/esm/designs/utils/index.js +1 -0
- package/esm/editor/commands/UpdateOptions.d.ts +4 -4
- package/esm/editor/commands/UpdateOptions.js +6 -3
- package/esm/editor/editor.d.ts +5 -1
- package/esm/editor/editor.js +16 -5
- package/esm/editor/index.d.ts +1 -0
- package/esm/editor/index.js +1 -0
- package/esm/editor/interactions/brush-select.d.ts +0 -1
- package/esm/editor/interactions/brush-select.js +2 -10
- package/esm/editor/interactions/drag-canvas.d.ts +35 -0
- package/esm/editor/interactions/drag-canvas.js +161 -0
- package/esm/editor/interactions/drag-element.js +4 -3
- package/esm/editor/interactions/index.d.ts +1 -0
- package/esm/editor/interactions/index.js +1 -0
- package/esm/editor/interactions/zoom-wheel.d.ts +9 -0
- package/esm/editor/interactions/zoom-wheel.js +32 -15
- package/esm/editor/managers/index.d.ts +1 -0
- package/esm/editor/managers/index.js +1 -0
- package/esm/editor/managers/state.d.ts +4 -2
- package/esm/editor/managers/state.js +14 -13
- package/esm/editor/managers/sync-registry.d.ts +16 -0
- package/esm/editor/managers/sync-registry.js +51 -0
- package/esm/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/icons.js +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/esm/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/esm/editor/plugins/core-sync.d.ts +8 -0
- package/esm/editor/plugins/core-sync.js +30 -0
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/esm/editor/plugins/edit-bar/index.d.ts +2 -2
- package/esm/editor/plugins/edit-bar/index.js +1 -1
- package/esm/editor/plugins/index.d.ts +2 -0
- package/esm/editor/plugins/index.js +2 -0
- package/esm/editor/plugins/reset-viewbox.d.ts +33 -0
- package/esm/editor/plugins/reset-viewbox.js +186 -0
- package/esm/editor/types/editor.d.ts +14 -0
- package/esm/editor/types/index.d.ts +1 -0
- package/esm/editor/types/interaction.d.ts +9 -0
- package/esm/editor/types/state.d.ts +4 -2
- package/esm/editor/types/sync.d.ts +27 -0
- package/esm/editor/types/sync.js +1 -0
- package/esm/editor/utils/data.js +3 -1
- package/esm/editor/utils/event.d.ts +1 -0
- package/esm/editor/utils/event.js +8 -0
- package/esm/editor/utils/index.d.ts +1 -0
- package/esm/editor/utils/index.js +1 -0
- package/esm/editor/utils/object.d.ts +15 -0
- package/esm/editor/utils/object.js +77 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +3 -2
- package/esm/options/types.d.ts +7 -0
- package/esm/runtime/Infographic.js +20 -7
- package/esm/runtime/options.js +7 -2
- package/esm/syntax/index.js +40 -20
- package/esm/syntax/relations.js +26 -2
- package/esm/syntax/schema.js +1 -0
- package/esm/templates/built-in.js +27 -2
- package/esm/templates/sequence-interaction.d.ts +2 -0
- package/esm/templates/sequence-interaction.js +76 -0
- package/esm/types/data.d.ts +1 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/measure-text.js +40 -9
- package/esm/utils/padding.d.ts +1 -0
- package/esm/utils/padding.js +6 -2
- package/esm/utils/types.d.ts +16 -0
- package/esm/utils/types.js +12 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/designs/structures/index.d.ts +1 -0
- package/lib/designs/structures/index.js +1 -0
- package/lib/designs/structures/relation-dagre-flow.js +5 -140
- package/lib/designs/structures/sequence-interaction.d.ts +54 -0
- package/lib/designs/structures/sequence-interaction.js +444 -0
- package/lib/designs/utils/geometry.d.ts +44 -0
- package/lib/designs/utils/geometry.js +256 -0
- package/lib/designs/utils/index.d.ts +1 -0
- package/lib/designs/utils/index.js +1 -0
- package/lib/editor/commands/UpdateOptions.d.ts +4 -4
- package/lib/editor/commands/UpdateOptions.js +6 -3
- package/lib/editor/editor.d.ts +5 -1
- package/lib/editor/editor.js +16 -5
- package/lib/editor/index.d.ts +1 -0
- package/lib/editor/index.js +1 -0
- package/lib/editor/interactions/brush-select.d.ts +0 -1
- package/lib/editor/interactions/brush-select.js +1 -9
- package/lib/editor/interactions/drag-canvas.d.ts +35 -0
- package/lib/editor/interactions/drag-canvas.js +165 -0
- package/lib/editor/interactions/drag-element.js +4 -3
- package/lib/editor/interactions/index.d.ts +1 -0
- package/lib/editor/interactions/index.js +3 -1
- package/lib/editor/interactions/zoom-wheel.d.ts +9 -0
- package/lib/editor/interactions/zoom-wheel.js +32 -15
- package/lib/editor/managers/index.d.ts +1 -0
- package/lib/editor/managers/index.js +1 -0
- package/lib/editor/managers/state.d.ts +4 -2
- package/lib/editor/managers/state.js +12 -11
- package/lib/editor/managers/sync-registry.d.ts +16 -0
- package/lib/editor/managers/sync-registry.js +55 -0
- package/lib/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/lib/editor/plugins/{edit-bar/components → components}/icons.js +2 -1
- package/lib/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/lib/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/lib/editor/plugins/core-sync.d.ts +8 -0
- package/lib/editor/plugins/core-sync.js +34 -0
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/lib/editor/plugins/edit-bar/index.d.ts +2 -2
- package/lib/editor/plugins/edit-bar/index.js +1 -1
- package/lib/editor/plugins/index.d.ts +2 -0
- package/lib/editor/plugins/index.js +5 -1
- package/lib/editor/plugins/reset-viewbox.d.ts +33 -0
- package/lib/editor/plugins/reset-viewbox.js +190 -0
- package/lib/editor/types/editor.d.ts +14 -0
- package/lib/editor/types/index.d.ts +1 -0
- package/lib/editor/types/interaction.d.ts +9 -0
- package/lib/editor/types/state.d.ts +4 -2
- package/lib/editor/types/sync.d.ts +27 -0
- package/lib/editor/types/sync.js +2 -0
- package/lib/editor/utils/data.js +3 -1
- package/lib/editor/utils/event.d.ts +1 -0
- package/lib/editor/utils/event.js +9 -0
- package/lib/editor/utils/index.d.ts +1 -0
- package/lib/editor/utils/index.js +1 -0
- package/lib/editor/utils/object.d.ts +15 -0
- package/lib/editor/utils/object.js +80 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +9 -2
- package/lib/options/types.d.ts +7 -0
- package/lib/runtime/Infographic.js +19 -6
- package/lib/runtime/options.js +6 -1
- package/lib/syntax/index.js +40 -20
- package/lib/syntax/relations.js +26 -2
- package/lib/syntax/schema.js +1 -0
- package/lib/templates/built-in.js +27 -2
- package/lib/templates/sequence-interaction.d.ts +2 -0
- package/lib/templates/sequence-interaction.js +79 -0
- package/lib/types/data.d.ts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/measure-text.js +39 -8
- package/lib/utils/padding.d.ts +1 -0
- package/lib/utils/padding.js +7 -2
- package/lib/utils/types.d.ts +16 -0
- package/lib/utils/types.js +13 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/designs/structures/index.ts +1 -0
- package/src/designs/structures/relation-dagre-flow.tsx +14 -178
- package/src/designs/structures/sequence-interaction.tsx +885 -0
- package/src/designs/utils/geometry.tsx +315 -0
- package/src/designs/utils/index.ts +1 -0
- package/src/editor/commands/UpdateOptions.ts +11 -6
- package/src/editor/editor.ts +26 -5
- package/src/editor/index.ts +1 -0
- package/src/editor/interactions/brush-select.ts +2 -8
- package/src/editor/interactions/drag-canvas.ts +203 -0
- package/src/editor/interactions/drag-element.ts +5 -4
- package/src/editor/interactions/index.ts +1 -0
- package/src/editor/interactions/zoom-wheel.ts +49 -13
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/managers/state.ts +21 -21
- package/src/editor/managers/sync-registry.ts +66 -0
- package/src/editor/plugins/{edit-bar/components → components}/button.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/color-picker.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/icons.ts +4 -0
- package/src/editor/plugins/{edit-bar/components → components}/popover.ts +2 -2
- package/src/editor/plugins/{edit-bar/components → components}/select.ts +1 -1
- package/src/editor/plugins/core-sync.ts +44 -0
- package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +2 -2
- package/src/editor/plugins/edit-bar/edit-items/font-align.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-color.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-family.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-size.ts +3 -3
- package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +1 -1
- package/src/editor/plugins/edit-bar/index.ts +2 -2
- package/src/editor/plugins/index.ts +2 -0
- package/src/editor/plugins/reset-viewbox.ts +258 -0
- package/src/editor/types/editor.ts +18 -0
- package/src/editor/types/index.ts +1 -0
- package/src/editor/types/interaction.ts +31 -0
- package/src/editor/types/state.ts +14 -2
- package/src/editor/types/sync.ts +33 -0
- package/src/editor/utils/data.ts +2 -1
- package/src/editor/utils/event.ts +7 -0
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/utils/object.ts +116 -0
- package/src/index.ts +26 -2
- package/src/options/types.ts +11 -0
- package/src/runtime/Infographic.tsx +27 -17
- package/src/runtime/options.ts +8 -1
- package/src/syntax/index.ts +51 -18
- package/src/syntax/relations.ts +29 -2
- package/src/syntax/schema.ts +1 -0
- package/src/templates/built-in.ts +30 -0
- package/src/templates/sequence-interaction.ts +101 -0
- package/src/types/data.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/measure-text.ts +41 -9
- package/src/utils/padding.ts +10 -2
- package/src/utils/types.ts +61 -0
- package/src/version.ts +1 -1
- /package/esm/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/src/editor/plugins/{edit-bar/components → components}/index.ts +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResetViewBox = void 0;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const commands_1 = require("../commands");
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
const components_1 = require("./components");
|
|
9
|
+
const icons_1 = require("./components/icons");
|
|
10
|
+
const MARGIN_X = 25;
|
|
11
|
+
const MARGIN_Y = 25;
|
|
12
|
+
const BUTTON_SIZE = 40;
|
|
13
|
+
class ResetViewBox extends base_1.Plugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super();
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.name = 'reset-viewBox';
|
|
18
|
+
this.viewBoxChanged = false;
|
|
19
|
+
this.handleResize = () => {
|
|
20
|
+
this.updateOriginViewBox();
|
|
21
|
+
this.updatePosition();
|
|
22
|
+
};
|
|
23
|
+
this.handleViewBoxChange = (viewBox) => {
|
|
24
|
+
const svg = this.editor.getDocument();
|
|
25
|
+
this.viewBoxChanged = viewBox !== this.originViewBox;
|
|
26
|
+
if (!this.viewBoxChanged) {
|
|
27
|
+
if (this.resetButton)
|
|
28
|
+
this.hideButton(this.resetButton);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const button = this.getOrCreateResetButton();
|
|
32
|
+
this.placeButton(button, svg);
|
|
33
|
+
this.showButton(button);
|
|
34
|
+
};
|
|
35
|
+
this.getOrCreateResetButton = () => {
|
|
36
|
+
if (this.resetButton)
|
|
37
|
+
return this.resetButton;
|
|
38
|
+
const { style, className } = this.options || {};
|
|
39
|
+
const button = (0, components_1.IconButton)({
|
|
40
|
+
icon: icons_1.RESET_ICON,
|
|
41
|
+
onClick: this.resetViewBox,
|
|
42
|
+
});
|
|
43
|
+
button.classList.add(RESET_BUTTON_CLASS);
|
|
44
|
+
if (className) {
|
|
45
|
+
button.classList.add(className);
|
|
46
|
+
}
|
|
47
|
+
if (style) {
|
|
48
|
+
Object.assign(button.style, style);
|
|
49
|
+
}
|
|
50
|
+
(0, utils_1.setElementRole)(button, constants_1.COMPONENT_ROLE);
|
|
51
|
+
this.resetButton = button;
|
|
52
|
+
const { getContainer } = this.options || {};
|
|
53
|
+
const resolvedContainer = typeof getContainer === 'function' ? getContainer() : getContainer;
|
|
54
|
+
const containerParent = resolvedContainer !== null && resolvedContainer !== void 0 ? resolvedContainer : document.body;
|
|
55
|
+
containerParent === null || containerParent === void 0 ? void 0 : containerParent.appendChild(button);
|
|
56
|
+
return button;
|
|
57
|
+
};
|
|
58
|
+
/** Get CSS transform scale of an element */
|
|
59
|
+
this.getTransformScale = (element) => {
|
|
60
|
+
const rect = element.getBoundingClientRect();
|
|
61
|
+
const scaleX = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
|
|
62
|
+
const scaleY = element.offsetHeight > 0 ? rect.height / element.offsetHeight : 1;
|
|
63
|
+
return { scaleX, scaleY };
|
|
64
|
+
};
|
|
65
|
+
/** Find the nearest stable overflow container */
|
|
66
|
+
this.findStableContainer = (svg) => {
|
|
67
|
+
let current = svg.parentElement;
|
|
68
|
+
while (current) {
|
|
69
|
+
if (current instanceof HTMLElement) {
|
|
70
|
+
const style = window.getComputedStyle(current);
|
|
71
|
+
// Look for overflow container or positioned element as stable reference
|
|
72
|
+
if ((style.overflow && style.overflow !== 'visible') ||
|
|
73
|
+
(style.overflowX && style.overflowX !== 'visible') ||
|
|
74
|
+
(style.overflowY && style.overflowY !== 'visible')) {
|
|
75
|
+
return current;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
current = current.parentElement;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
this.placeButton = (button, svg) => {
|
|
83
|
+
var _a;
|
|
84
|
+
if (!svg.isConnected)
|
|
85
|
+
return;
|
|
86
|
+
const svgRect = svg.getBoundingClientRect();
|
|
87
|
+
const offsetParent = (_a = button.offsetParent) !== null && _a !== void 0 ? _a : document.documentElement;
|
|
88
|
+
// Use stable container bounds to clamp button position when SVG overflows
|
|
89
|
+
const stableContainer = this.findStableContainer(svg);
|
|
90
|
+
const containerRect = stableContainer === null || stableContainer === void 0 ? void 0 : stableContainer.getBoundingClientRect();
|
|
91
|
+
// Prefer SVG bounds, but clamp to container if SVG overflows
|
|
92
|
+
const effectiveRect = containerRect
|
|
93
|
+
? {
|
|
94
|
+
right: Math.min(svgRect.right, containerRect.right),
|
|
95
|
+
bottom: Math.min(svgRect.bottom, containerRect.bottom),
|
|
96
|
+
}
|
|
97
|
+
: svgRect;
|
|
98
|
+
if (offsetParent === document.body ||
|
|
99
|
+
offsetParent === document.documentElement) {
|
|
100
|
+
const scrollX = window.scrollX || document.documentElement.scrollLeft;
|
|
101
|
+
const scrollY = window.scrollY || document.documentElement.scrollTop;
|
|
102
|
+
const left = scrollX + effectiveRect.right - MARGIN_X - BUTTON_SIZE;
|
|
103
|
+
const top = scrollY + effectiveRect.bottom - MARGIN_Y - BUTTON_SIZE;
|
|
104
|
+
button.style.left = `${left}px`;
|
|
105
|
+
button.style.top = `${top}px`;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const parentRect = offsetParent.getBoundingClientRect();
|
|
109
|
+
// Compensate for parent transform scale
|
|
110
|
+
const { scaleX, scaleY } = this.getTransformScale(offsetParent);
|
|
111
|
+
// Convert to offsetParent local coordinates
|
|
112
|
+
const left = (effectiveRect.right - parentRect.left) / scaleX - MARGIN_X - BUTTON_SIZE;
|
|
113
|
+
const top = (effectiveRect.bottom - parentRect.top) / scaleY - MARGIN_Y - BUTTON_SIZE;
|
|
114
|
+
button.style.left = `${left}px`;
|
|
115
|
+
button.style.top = `${top}px`;
|
|
116
|
+
};
|
|
117
|
+
this.updatePosition = () => {
|
|
118
|
+
if (this.resetButton && this.viewBoxChanged) {
|
|
119
|
+
this.placeButton(this.resetButton, this.editor.getDocument());
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
this.resetViewBox = () => {
|
|
123
|
+
const command = new commands_1.UpdateOptionsCommand({
|
|
124
|
+
viewBox: this.originViewBox,
|
|
125
|
+
});
|
|
126
|
+
void this.commander.execute(command);
|
|
127
|
+
};
|
|
128
|
+
this.showButton = (button) => {
|
|
129
|
+
button.style.display = 'flex';
|
|
130
|
+
button.style.visibility = 'visible';
|
|
131
|
+
};
|
|
132
|
+
this.hideButton = (button) => {
|
|
133
|
+
button.style.display = 'none';
|
|
134
|
+
};
|
|
135
|
+
this.removeButton = () => {
|
|
136
|
+
var _a;
|
|
137
|
+
this.viewBoxChanged = false;
|
|
138
|
+
(_a = this.resetButton) === null || _a === void 0 ? void 0 : _a.remove();
|
|
139
|
+
this.resetButton = undefined;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
init(options) {
|
|
143
|
+
super.init(options);
|
|
144
|
+
// Initialize originViewBox
|
|
145
|
+
this.ensureButtonStyle();
|
|
146
|
+
this.updateOriginViewBox();
|
|
147
|
+
this.unregisterSync = this.editor.registerSync('viewBox', this.handleViewBoxChange);
|
|
148
|
+
window.addEventListener('resize', this.handleResize);
|
|
149
|
+
}
|
|
150
|
+
destroy() {
|
|
151
|
+
var _a;
|
|
152
|
+
(_a = this.unregisterSync) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
153
|
+
window.removeEventListener('resize', this.handleResize);
|
|
154
|
+
this.removeButton();
|
|
155
|
+
}
|
|
156
|
+
updateOriginViewBox() {
|
|
157
|
+
const svg = this.editor.getDocument();
|
|
158
|
+
// In Node env or before render, fallback to current viewBox attribute
|
|
159
|
+
if (!svg.getBBox) {
|
|
160
|
+
this.originViewBox = (0, utils_1.viewBoxToString)((0, utils_1.getViewBox)(svg));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// In Browser, calculate fit
|
|
164
|
+
const { padding } = this.state.getOptions();
|
|
165
|
+
this.originViewBox = (0, utils_1.getBoundViewBox)(svg, (0, utils_1.parsePadding)(padding));
|
|
166
|
+
}
|
|
167
|
+
ensureButtonStyle() {
|
|
168
|
+
(0, utils_1.injectStyleOnce)(RESET_BUTTON_STYLE_ID, `
|
|
169
|
+
button.${RESET_BUTTON_CLASS} {
|
|
170
|
+
visibility: hidden;
|
|
171
|
+
position: absolute;
|
|
172
|
+
display: flex;
|
|
173
|
+
justify-content: center;
|
|
174
|
+
align-items: center;
|
|
175
|
+
width: ${BUTTON_SIZE}px;
|
|
176
|
+
height: ${BUTTON_SIZE}px;
|
|
177
|
+
border-radius: 50%;
|
|
178
|
+
padding: 4px;
|
|
179
|
+
background-color: #fff;
|
|
180
|
+
border: 1px solid #e5e7eb;
|
|
181
|
+
z-index: 1000;
|
|
182
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
}
|
|
185
|
+
`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.ResetViewBox = ResetViewBox;
|
|
189
|
+
const RESET_BUTTON_CLASS = 'infographic-reset-viewbox-btn';
|
|
190
|
+
const RESET_BUTTON_STYLE_ID = 'infographic-reset-viewbox-btn-style';
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import type { InfographicOptionPath } from '../../options';
|
|
2
|
+
import type { ICommandManager } from './command';
|
|
3
|
+
import type { IInteractionManager } from './interaction';
|
|
4
|
+
import type { IPluginManager } from './plugin';
|
|
5
|
+
import type { IStateManager } from './state';
|
|
6
|
+
import type { ISyncRegistry, SyncHandler } from './sync';
|
|
1
7
|
export interface IEditor {
|
|
8
|
+
commander: ICommandManager;
|
|
9
|
+
interaction: IInteractionManager;
|
|
10
|
+
plugin: IPluginManager;
|
|
11
|
+
state: IStateManager;
|
|
12
|
+
syncRegistry: ISyncRegistry;
|
|
2
13
|
getDocument(): SVGSVGElement;
|
|
14
|
+
registerSync(path: InfographicOptionPath | (string & {}), handler: SyncHandler, options?: {
|
|
15
|
+
immediate?: boolean;
|
|
16
|
+
}): () => void;
|
|
3
17
|
destroy(): void;
|
|
4
18
|
}
|
|
@@ -3,6 +3,11 @@ import type { ICommandManager } from './command';
|
|
|
3
3
|
import type { IEditor } from './editor';
|
|
4
4
|
import type { Selection } from './selection';
|
|
5
5
|
import type { IStateManager } from './state';
|
|
6
|
+
/**
|
|
7
|
+
* Union type of common key codes, using (string & {}) trick to provide completion suggestions without limiting specific strings
|
|
8
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
|
|
9
|
+
*/
|
|
10
|
+
export type KeyCode = 'Space' | 'ShiftLeft' | 'ShiftRight' | 'ControlLeft' | 'ControlRight' | 'AltLeft' | 'AltRight' | 'MetaLeft' | 'MetaRight' | 'CapsLock' | 'Tab' | 'Enter' | 'Escape' | 'ArrowUp' | 'ArrowDown' | 'ArrowLeft' | 'ArrowRight' | `Key${string}` | `Digit${number}` | (string & {});
|
|
6
11
|
export interface IInteraction {
|
|
7
12
|
name: string;
|
|
8
13
|
init(options: InteractionInitOptions): void;
|
|
@@ -17,6 +22,10 @@ export interface SelectionChangePayload {
|
|
|
17
22
|
removed: Selection;
|
|
18
23
|
mode: SelectMode;
|
|
19
24
|
}
|
|
25
|
+
export interface viewBoxChangePayload {
|
|
26
|
+
type: 'viewBox:change';
|
|
27
|
+
viewBox: string | undefined;
|
|
28
|
+
}
|
|
20
29
|
export interface IInteractionManager {
|
|
21
30
|
isActive(): boolean;
|
|
22
31
|
select(items: Selection, mode: SelectMode): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParsedInfographicOptions } from '../../options';
|
|
1
|
+
import type { ParsedInfographicOptions, UpdatableInfographicOptions } from '../../options';
|
|
2
2
|
import type { Element, IEventEmitter, ItemDatum } from '../../types';
|
|
3
3
|
import type { ICommandManager } from './command';
|
|
4
4
|
import type { IEditor } from './editor';
|
|
@@ -21,7 +21,9 @@ export interface IStateManager {
|
|
|
21
21
|
removeItemDatum(indexes: number[], count?: number): void;
|
|
22
22
|
updateData(key: string, value: any): void;
|
|
23
23
|
updateElement(element: Element, props: Partial<ElementProps>): void;
|
|
24
|
-
updateOptions(options:
|
|
24
|
+
updateOptions(options: UpdatableInfographicOptions, execOptions?: {
|
|
25
|
+
bubbleUp?: boolean;
|
|
26
|
+
}): void;
|
|
25
27
|
getOptions(): ParsedInfographicOptions;
|
|
26
28
|
destroy(): void;
|
|
27
29
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InfographicOptionPath } from '../../options';
|
|
2
|
+
/**
|
|
3
|
+
* Sync callback
|
|
4
|
+
* @param newValue The new value after modification
|
|
5
|
+
* @param oldValue The old value before modification. Note: This value is undefined when triggered by parent path bubbling notification (i.e., listening to a non-leaf node).
|
|
6
|
+
*/
|
|
7
|
+
export type SyncHandler = (newValue: any, oldValue: any) => void;
|
|
8
|
+
export interface ISyncRegistry {
|
|
9
|
+
/**
|
|
10
|
+
* Register synchronization logic
|
|
11
|
+
* @param path Configuration path, such as 'design.background'
|
|
12
|
+
* @param handler Sync callback
|
|
13
|
+
* @param options.immediate Whether to execute immediately (used for view initialization)
|
|
14
|
+
* @returns unregister function
|
|
15
|
+
*/
|
|
16
|
+
register(path: InfographicOptionPath | (string & {}), handler: SyncHandler, options?: {
|
|
17
|
+
immediate?: boolean;
|
|
18
|
+
}): () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Trigger synchronization (usually called by StateManager)
|
|
21
|
+
* @param path Configuration path
|
|
22
|
+
* @param newVal New value
|
|
23
|
+
* @param oldVal Old value
|
|
24
|
+
*/
|
|
25
|
+
trigger(path: string, newVal: any, oldVal: any): void;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
package/lib/editor/utils/data.js
CHANGED
|
@@ -8,8 +8,10 @@ const utils_1 = require("../../utils");
|
|
|
8
8
|
*/
|
|
9
9
|
function getChildrenDataByIndexes(data, indexes) {
|
|
10
10
|
if (indexes.length === 0)
|
|
11
|
-
return data.
|
|
11
|
+
return data.items;
|
|
12
12
|
const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
|
|
13
|
+
if (datum == null)
|
|
14
|
+
return [];
|
|
13
15
|
datum.children || (datum.children = []);
|
|
14
16
|
return datum.children;
|
|
15
17
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Element } from '../../types';
|
|
2
2
|
export declare function getEventTarget(element: SVGElement | null): Element | null;
|
|
3
3
|
export declare function getSelectableTarget(element: SVGElement | null): Element | null;
|
|
4
|
+
export declare function isTextSelectionTarget(target: EventTarget | null): boolean;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEventTarget = getEventTarget;
|
|
4
4
|
exports.getSelectableTarget = getSelectableTarget;
|
|
5
|
+
exports.isTextSelectionTarget = isTextSelectionTarget;
|
|
5
6
|
const utils_1 = require("../../utils");
|
|
6
7
|
function getEventTarget(element) {
|
|
7
8
|
if (!element)
|
|
@@ -66,3 +67,11 @@ const getIconEventTarget = (element) => {
|
|
|
66
67
|
}
|
|
67
68
|
return null;
|
|
68
69
|
};
|
|
70
|
+
function isTextSelectionTarget(target) {
|
|
71
|
+
if (!(target instanceof HTMLElement))
|
|
72
|
+
return false;
|
|
73
|
+
if (target.isContentEditable)
|
|
74
|
+
return true;
|
|
75
|
+
const tag = target.tagName.toLowerCase();
|
|
76
|
+
return tag === 'input' || tag === 'textarea';
|
|
77
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ApplyOptionUpdatesOptions {
|
|
2
|
+
/** Whether to notify parent paths of changes (bubbling) */
|
|
3
|
+
bubbleUp?: boolean;
|
|
4
|
+
/** Callback triggered whenever a property value changes */
|
|
5
|
+
collector?: (path: string, newVal: any, oldVal: any) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Recursively applies properties from 'source' to 'target' and collects changes.
|
|
9
|
+
*
|
|
10
|
+
* @param target - The object to be updated
|
|
11
|
+
* @param source - The source object containing partial updates
|
|
12
|
+
* @param basePath - Current path prefix for nested properties
|
|
13
|
+
* @param options - Configuration options
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyOptionUpdates(target: any, source: any, basePath?: string, options?: ApplyOptionUpdatesOptions): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyOptionUpdates = applyOptionUpdates;
|
|
4
|
+
const lodash_es_1 = require("lodash-es");
|
|
5
|
+
/**
|
|
6
|
+
* Recursively applies properties from 'source' to 'target' and collects changes.
|
|
7
|
+
*
|
|
8
|
+
* @param target - The object to be updated
|
|
9
|
+
* @param source - The source object containing partial updates
|
|
10
|
+
* @param basePath - Current path prefix for nested properties
|
|
11
|
+
* @param options - Configuration options
|
|
12
|
+
*/
|
|
13
|
+
function applyOptionUpdates(target, source, basePath = '', options) {
|
|
14
|
+
const { bubbleUp = false, collector } = options !== null && options !== void 0 ? options : {};
|
|
15
|
+
const hasChange = applyOptionUpdatesInternal(target, source, basePath, collector, bubbleUp);
|
|
16
|
+
if (basePath === '' && hasChange && bubbleUp && collector) {
|
|
17
|
+
collector('', (0, lodash_es_1.cloneDeep)(target), undefined);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Internal recursive function.
|
|
22
|
+
* Returns true if any change occurred within this branch (or its children).
|
|
23
|
+
*/
|
|
24
|
+
function applyOptionUpdatesInternal(target, source, basePath, collector, bubbleUp) {
|
|
25
|
+
let hasChange = false;
|
|
26
|
+
Object.keys(source).forEach((key) => {
|
|
27
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const fullPath = basePath ? `${basePath}.${key}` : key;
|
|
31
|
+
const updateValue = source[key];
|
|
32
|
+
const oldValue = target[key];
|
|
33
|
+
let childChanged = false;
|
|
34
|
+
if (updateValue === undefined) {
|
|
35
|
+
// Handle deletion: Only delete and notify if the key actually exists
|
|
36
|
+
if (key in target) {
|
|
37
|
+
delete target[key];
|
|
38
|
+
collector === null || collector === void 0 ? void 0 : collector(fullPath, undefined, oldValue);
|
|
39
|
+
childChanged = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if ((0, lodash_es_1.isPlainObject)(updateValue)) {
|
|
43
|
+
// Handle nested object
|
|
44
|
+
const oldValueIsObject = (0, lodash_es_1.isPlainObject)(target[key]);
|
|
45
|
+
if (!oldValueIsObject) {
|
|
46
|
+
target[key] = {};
|
|
47
|
+
}
|
|
48
|
+
const grandChildChanged = applyOptionUpdatesInternal(target[key], updateValue, fullPath, collector, bubbleUp);
|
|
49
|
+
if (!oldValueIsObject) {
|
|
50
|
+
// Overwriting a primitive with an object is always a change.
|
|
51
|
+
childChanged = true;
|
|
52
|
+
// If the object was empty (grandChildChanged is false), we still need to report it.
|
|
53
|
+
if (!grandChildChanged) {
|
|
54
|
+
collector === null || collector === void 0 ? void 0 : collector(fullPath, target[key], oldValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
childChanged = grandChildChanged;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Handle primitive update
|
|
63
|
+
target[key] = updateValue;
|
|
64
|
+
if (!(0, lodash_es_1.isEqual)(updateValue, oldValue)) {
|
|
65
|
+
collector === null || collector === void 0 ? void 0 : collector(fullPath, updateValue, oldValue);
|
|
66
|
+
childChanged = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (childChanged) {
|
|
70
|
+
hasChange = true;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// Bubbling: Notify if any child changed in this branch
|
|
74
|
+
// The recursion naturally ensures this happens in "deepest-first" (post-order) sequence.
|
|
75
|
+
if (hasChange && bubbleUp && basePath !== '') {
|
|
76
|
+
// Current target is now fully updated for this scope.
|
|
77
|
+
collector === null || collector === void 0 ? void 0 : collector(basePath, (0, lodash_es_1.cloneDeep)(target), undefined);
|
|
78
|
+
}
|
|
79
|
+
return hasChange;
|
|
80
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './designs';
|
|
2
2
|
export { getItemProps, getThemeColors } from './designs/utils';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
3
|
+
export { BatchCommand, UpdateElementCommand, UpdateOptionsCommand, UpdateTextCommand, } from './editor/commands';
|
|
4
|
+
export { BrushSelect, ClickSelect, DblClickEditText, DragCanvas, DragElement, HotkeyHistory, Interaction, SelectHighlight, ZoomWheel, } from './editor/interactions';
|
|
5
|
+
export { EditBar, Plugin, ResetViewBox, ResizeElement } from './editor/plugins';
|
|
5
6
|
export { exportToSVG } from './exporter';
|
|
6
7
|
export { Defs, Ellipse, Fragment, Group, Path, Polygon, Rect, Text, cloneElement, createFragment, createLayout, getCombinedBounds, getElementBounds, getElementsBounds, jsx, jsxDEV, jsxs, renderSVG, } from './jsx';
|
|
7
8
|
export { getFont, getFonts, getPalette, getPaletteColor, getPalettes, registerFont, registerPalette, registerPattern, setDefaultFont, } from './renderer';
|
|
@@ -12,7 +13,7 @@ export { getTemplate, getTemplates, registerTemplate } from './templates';
|
|
|
12
13
|
export { getTheme, getThemes, registerTheme } from './themes';
|
|
13
14
|
export { parseSVG, setFontExtendFactor } from './utils';
|
|
14
15
|
export { VERSION } from './version';
|
|
15
|
-
export type { EditBarOptions } from './editor';
|
|
16
|
+
export type { EditBarOptions, ICommand, ICommandManager, IEditor, IInteraction, IInteractionManager, IPlugin, IPluginManager, IStateManager, ISyncRegistry, InteractionInitOptions, KeyCode, PluginInitOptions, SelectMode, Selection, SyncHandler, } from './editor';
|
|
16
17
|
export type { ExportOptions, PNGExportOptions, SVGExportOptions, } from './exporter';
|
|
17
18
|
export type { Bounds, ComponentType, DefsProps, EllipseProps, FragmentProps, GroupProps, JSXElement, JSXElementConstructor, JSXNode, PathProps, Point, PolygonProps, RectProps, RenderableNode, SVGAttributes, SVGProps, TextProps, WithChildren, } from './jsx';
|
|
18
19
|
export type { InfographicOptions, ParsedInfographicOptions } from './options';
|
package/lib/index.js
CHANGED
|
@@ -14,16 +14,22 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.VERSION = exports.setFontExtendFactor = exports.parseSVG = exports.registerTheme = void 0;
|
|
17
|
+
exports.Infographic = exports.registerResourceLoader = exports.loadSVGResource = exports.setDefaultFont = exports.registerPattern = exports.registerPalette = exports.registerFont = exports.getPalettes = exports.getPaletteColor = exports.getPalette = exports.getFonts = exports.getFont = exports.renderSVG = exports.jsxs = exports.jsxDEV = exports.jsx = exports.getElementsBounds = exports.getElementBounds = exports.getCombinedBounds = exports.createLayout = exports.createFragment = exports.cloneElement = exports.Text = exports.Rect = exports.Polygon = exports.Path = exports.Group = exports.Fragment = exports.Ellipse = exports.Defs = exports.exportToSVG = exports.ResizeElement = exports.ResetViewBox = exports.Plugin = exports.EditBar = exports.ZoomWheel = exports.SelectHighlight = exports.Interaction = exports.HotkeyHistory = exports.DragElement = exports.DragCanvas = exports.DblClickEditText = exports.ClickSelect = exports.BrushSelect = exports.UpdateTextCommand = exports.UpdateOptionsCommand = exports.UpdateElementCommand = exports.BatchCommand = exports.getThemeColors = exports.getItemProps = void 0;
|
|
18
|
+
exports.VERSION = exports.setFontExtendFactor = exports.parseSVG = exports.registerTheme = exports.getThemes = exports.getTheme = exports.registerTemplate = exports.getTemplates = exports.getTemplate = exports.parseSyntax = void 0;
|
|
19
19
|
__exportStar(require("./designs"), exports);
|
|
20
20
|
var utils_1 = require("./designs/utils");
|
|
21
21
|
Object.defineProperty(exports, "getItemProps", { enumerable: true, get: function () { return utils_1.getItemProps; } });
|
|
22
22
|
Object.defineProperty(exports, "getThemeColors", { enumerable: true, get: function () { return utils_1.getThemeColors; } });
|
|
23
|
+
var commands_1 = require("./editor/commands");
|
|
24
|
+
Object.defineProperty(exports, "BatchCommand", { enumerable: true, get: function () { return commands_1.BatchCommand; } });
|
|
25
|
+
Object.defineProperty(exports, "UpdateElementCommand", { enumerable: true, get: function () { return commands_1.UpdateElementCommand; } });
|
|
26
|
+
Object.defineProperty(exports, "UpdateOptionsCommand", { enumerable: true, get: function () { return commands_1.UpdateOptionsCommand; } });
|
|
27
|
+
Object.defineProperty(exports, "UpdateTextCommand", { enumerable: true, get: function () { return commands_1.UpdateTextCommand; } });
|
|
23
28
|
var interactions_1 = require("./editor/interactions");
|
|
24
29
|
Object.defineProperty(exports, "BrushSelect", { enumerable: true, get: function () { return interactions_1.BrushSelect; } });
|
|
25
30
|
Object.defineProperty(exports, "ClickSelect", { enumerable: true, get: function () { return interactions_1.ClickSelect; } });
|
|
26
31
|
Object.defineProperty(exports, "DblClickEditText", { enumerable: true, get: function () { return interactions_1.DblClickEditText; } });
|
|
32
|
+
Object.defineProperty(exports, "DragCanvas", { enumerable: true, get: function () { return interactions_1.DragCanvas; } });
|
|
27
33
|
Object.defineProperty(exports, "DragElement", { enumerable: true, get: function () { return interactions_1.DragElement; } });
|
|
28
34
|
Object.defineProperty(exports, "HotkeyHistory", { enumerable: true, get: function () { return interactions_1.HotkeyHistory; } });
|
|
29
35
|
Object.defineProperty(exports, "Interaction", { enumerable: true, get: function () { return interactions_1.Interaction; } });
|
|
@@ -32,6 +38,7 @@ Object.defineProperty(exports, "ZoomWheel", { enumerable: true, get: function ()
|
|
|
32
38
|
var plugins_1 = require("./editor/plugins");
|
|
33
39
|
Object.defineProperty(exports, "EditBar", { enumerable: true, get: function () { return plugins_1.EditBar; } });
|
|
34
40
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugins_1.Plugin; } });
|
|
41
|
+
Object.defineProperty(exports, "ResetViewBox", { enumerable: true, get: function () { return plugins_1.ResetViewBox; } });
|
|
35
42
|
Object.defineProperty(exports, "ResizeElement", { enumerable: true, get: function () { return plugins_1.ResizeElement; } });
|
|
36
43
|
var exporter_1 = require("./exporter");
|
|
37
44
|
Object.defineProperty(exports, "exportToSVG", { enumerable: true, get: function () { return exporter_1.exportToSVG; } });
|
package/lib/options/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DesignOptions, ParsedDesignsOptions } from '../designs';
|
|
|
2
2
|
import type { ElementProps, IInteraction, IPlugin } from '../editor';
|
|
3
3
|
import type { ThemeConfig } from '../themes';
|
|
4
4
|
import type { Data, Padding, ParsedData } from '../types';
|
|
5
|
+
import type { Path } from '../utils';
|
|
5
6
|
export interface InfographicOptions {
|
|
6
7
|
/** 容器,可以是选择器或者 HTMLElement */
|
|
7
8
|
container?: string | HTMLElement;
|
|
@@ -49,6 +50,7 @@ export interface ParsedInfographicOptions {
|
|
|
49
50
|
interactions?: IInteraction[];
|
|
50
51
|
shapes?: ElementProps[];
|
|
51
52
|
}
|
|
53
|
+
export type UpdatableInfographicOptions = Partial<Omit<ParsedInfographicOptions, 'container'>>;
|
|
52
54
|
interface SVGOptions {
|
|
53
55
|
style?: Record<string, string | number>;
|
|
54
56
|
attributes?: Record<string, string | number | boolean>;
|
|
@@ -57,4 +59,9 @@ interface SVGOptions {
|
|
|
57
59
|
/** 是否启用背景 */
|
|
58
60
|
background?: boolean;
|
|
59
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* All valid property paths for Infographic Options.
|
|
64
|
+
* Use this to validate paths in SyncRegistry and other places.
|
|
65
|
+
*/
|
|
66
|
+
export type InfographicOptionPath = Path<UpdatableInfographicOptions>;
|
|
60
67
|
export {};
|
|
@@ -105,18 +105,31 @@ class Infographic {
|
|
|
105
105
|
* Compose the SVG template
|
|
106
106
|
*/
|
|
107
107
|
compose(parsedOptions) {
|
|
108
|
-
|
|
108
|
+
var _a, _b;
|
|
109
|
+
const { design, data, themeConfig } = parsedOptions;
|
|
109
110
|
const { title, item, items, structure } = design;
|
|
110
111
|
const { component: Structure, props: structureProps } = structure;
|
|
111
112
|
const Title = title.component;
|
|
112
113
|
const Item = item.component;
|
|
113
114
|
const Items = items.map((it) => it.component);
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
// Apply theme font-family before measurement so measureText uses the correct font
|
|
116
|
+
const themeFontFamily = (_b = (_a = themeConfig === null || themeConfig === void 0 ? void 0 : themeConfig.base) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b['font-family'];
|
|
117
|
+
const previousDefaultFont = renderer_1.DEFAULT_FONT;
|
|
118
|
+
if (themeFontFamily)
|
|
119
|
+
(0, renderer_1.setDefaultFont)(themeFontFamily);
|
|
120
|
+
try {
|
|
121
|
+
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)));
|
|
122
|
+
const template = (0, utils_1.parseSVG)(svg);
|
|
123
|
+
if (!template) {
|
|
124
|
+
throw new Error('Failed to parse SVG template');
|
|
125
|
+
}
|
|
126
|
+
return template;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
// Restore previous default font
|
|
130
|
+
if (themeFontFamily)
|
|
131
|
+
(0, renderer_1.setDefaultFont)(previousDefaultFont);
|
|
118
132
|
}
|
|
119
|
-
return template;
|
|
120
133
|
}
|
|
121
134
|
getTypes() {
|
|
122
135
|
const parsedOptions = this.parsedOptions;
|
package/lib/runtime/options.js
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_OPTIONS = void 0;
|
|
4
4
|
const editor_1 = require("../editor");
|
|
5
|
-
const createDefaultPlugins = () => [
|
|
5
|
+
const createDefaultPlugins = () => [
|
|
6
|
+
new editor_1.EditBar(),
|
|
7
|
+
new editor_1.ResizeElement(),
|
|
8
|
+
new editor_1.ResetViewBox(),
|
|
9
|
+
];
|
|
6
10
|
const createDefaultInteractions = () => [
|
|
11
|
+
new editor_1.DragCanvas(),
|
|
7
12
|
new editor_1.DblClickEditText(),
|
|
8
13
|
new editor_1.BrushSelect(),
|
|
9
14
|
new editor_1.ClickSelect(),
|
package/lib/syntax/index.js
CHANGED
|
@@ -114,27 +114,47 @@ function parseSyntax(input) {
|
|
|
114
114
|
const parsed = (0, relations_1.parseRelationsNode)(relationsNode, errors, 'data.relations');
|
|
115
115
|
if (parsed.relations.length > 0 || parsed.items.length > 0) {
|
|
116
116
|
const current = ((_a = options.data) !== null && _a !== void 0 ? _a : {});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
parsed.items.forEach((item) => {
|
|
127
|
-
const existing = itemMap.get(item.id);
|
|
128
|
-
if (existing) {
|
|
129
|
-
if (!existing.label && item.label)
|
|
130
|
-
existing.label = item.label;
|
|
117
|
+
// 优先使用已存在的数据列表 (sequences, lists, etc.)
|
|
118
|
+
const dataKeys = Object.keys(schema_1.DataSchema.fields).filter((key) => key !== 'items' && key !== 'relations');
|
|
119
|
+
let hasStructuredData = false;
|
|
120
|
+
// 尝试找到一个非空的数据源
|
|
121
|
+
for (const key of dataKeys) {
|
|
122
|
+
if (Array.isArray(current[key]) && current[key].length > 0) {
|
|
123
|
+
hasStructuredData = true;
|
|
124
|
+
break;
|
|
131
125
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
}
|
|
127
|
+
// 如果 items 已包含层级结构数据(带 children),也视为结构化数据
|
|
128
|
+
if (!hasStructuredData &&
|
|
129
|
+
Array.isArray(current.items) &&
|
|
130
|
+
current.items.length > 0 &&
|
|
131
|
+
current.items.some((item) => Array.isArray(item.children) && item.children.length > 0)) {
|
|
132
|
+
hasStructuredData = true;
|
|
133
|
+
}
|
|
134
|
+
// 如果没有找到其他数据源,才尝试合并 items
|
|
135
|
+
if (!hasStructuredData) {
|
|
136
|
+
const existingItems = Array.isArray(current.items)
|
|
137
|
+
? current.items
|
|
138
|
+
: [];
|
|
139
|
+
const normalizedItems = normalizeItems(existingItems);
|
|
140
|
+
const itemMap = new Map();
|
|
141
|
+
normalizedItems.forEach((item) => {
|
|
142
|
+
if (item.id)
|
|
143
|
+
itemMap.set(item.id, item);
|
|
144
|
+
});
|
|
145
|
+
parsed.items.forEach((item) => {
|
|
146
|
+
const existing = itemMap.get(item.id);
|
|
147
|
+
if (existing) {
|
|
148
|
+
if (!existing.label && item.label)
|
|
149
|
+
existing.label = item.label;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
normalizedItems.push(item);
|
|
153
|
+
itemMap.set(item.id, item);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
current.items = normalizedItems;
|
|
157
|
+
}
|
|
138
158
|
current.relations = parsed.relations;
|
|
139
159
|
options.data = current;
|
|
140
160
|
}
|