@antv/infographic 0.2.17 → 0.2.18
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/infographic.min.js +99 -99
- package/dist/infographic.min.js.map +1 -1
- package/esm/constants/service.d.ts +1 -1
- package/esm/constants/service.js +1 -1
- package/esm/designs/structures/chart-line.js +5 -3
- package/esm/editor/interactions/dblclick-edit-text.js +3 -3
- package/esm/editor/managers/interaction.js +6 -4
- package/esm/editor/plugins/components/button.d.ts +2 -1
- package/esm/editor/plugins/components/button.js +4 -4
- package/esm/editor/plugins/components/color-picker.d.ts +1 -0
- package/esm/editor/plugins/components/color-picker.js +3 -3
- package/esm/editor/plugins/components/popover.d.ts +3 -1
- package/esm/editor/plugins/components/popover.js +29 -9
- package/esm/editor/plugins/edit-bar/edit-bar.d.ts +3 -1
- package/esm/editor/plugins/edit-bar/edit-bar.js +17 -7
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +6 -4
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +8 -5
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +7 -4
- package/esm/editor/plugins/edit-bar/edit-items/font-family.js +11 -9
- package/esm/editor/plugins/edit-bar/edit-items/font-size.js +8 -5
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +7 -4
- package/esm/editor/plugins/edit-bar/edit-items/types.d.ts +5 -1
- package/esm/editor/plugins/reset-viewbox.d.ts +4 -1
- package/esm/editor/plugins/reset-viewbox.js +12 -6
- package/esm/editor/utils/index.d.ts +1 -0
- package/esm/editor/utils/index.js +1 -0
- package/esm/editor/utils/root.d.ts +3 -0
- package/esm/editor/utils/root.js +18 -0
- package/esm/exporter/svg.js +63 -3
- package/esm/resource/loaders/search.js +0 -3
- package/esm/templates/utils.js +11 -6
- package/esm/utils/padding.js +1 -1
- package/esm/utils/style.d.ts +3 -1
- package/esm/utils/style.js +27 -4
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/constants/service.d.ts +1 -1
- package/lib/constants/service.js +1 -1
- package/lib/designs/structures/chart-line.js +5 -3
- package/lib/editor/interactions/dblclick-edit-text.js +3 -3
- package/lib/editor/managers/interaction.js +7 -5
- package/lib/editor/plugins/components/button.d.ts +2 -1
- package/lib/editor/plugins/components/button.js +4 -4
- package/lib/editor/plugins/components/color-picker.d.ts +1 -0
- package/lib/editor/plugins/components/color-picker.js +3 -3
- package/lib/editor/plugins/components/popover.d.ts +3 -1
- package/lib/editor/plugins/components/popover.js +32 -12
- package/lib/editor/plugins/edit-bar/edit-bar.d.ts +3 -1
- package/lib/editor/plugins/edit-bar/edit-bar.js +17 -7
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +6 -4
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +8 -5
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +7 -4
- package/lib/editor/plugins/edit-bar/edit-items/font-family.js +11 -9
- package/lib/editor/plugins/edit-bar/edit-items/font-size.js +8 -5
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +7 -4
- package/lib/editor/plugins/edit-bar/edit-items/types.d.ts +5 -1
- package/lib/editor/plugins/reset-viewbox.d.ts +4 -1
- package/lib/editor/plugins/reset-viewbox.js +12 -6
- package/lib/editor/utils/index.d.ts +1 -0
- package/lib/editor/utils/index.js +1 -0
- package/lib/editor/utils/root.d.ts +3 -0
- package/lib/editor/utils/root.js +22 -0
- package/lib/exporter/svg.js +63 -3
- package/lib/resource/loaders/search.js +0 -3
- package/lib/templates/utils.js +11 -6
- package/lib/utils/padding.js +1 -1
- package/lib/utils/style.d.ts +3 -1
- package/lib/utils/style.js +27 -4
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/constants/service.ts +1 -1
- package/src/designs/structures/chart-line.tsx +5 -3
- package/src/editor/interactions/dblclick-edit-text.ts +3 -2
- package/src/editor/managers/interaction.ts +9 -7
- package/src/editor/plugins/components/button.ts +5 -2
- package/src/editor/plugins/components/color-picker.ts +4 -2
- package/src/editor/plugins/components/popover.ts +31 -12
- package/src/editor/plugins/edit-bar/edit-bar.ts +26 -11
- package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +7 -2
- package/src/editor/plugins/edit-bar/edit-items/font-align.ts +8 -3
- package/src/editor/plugins/edit-bar/edit-items/font-color.ts +7 -2
- package/src/editor/plugins/edit-bar/edit-items/font-family.ts +11 -7
- package/src/editor/plugins/edit-bar/edit-items/font-size.ts +8 -3
- package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +7 -2
- package/src/editor/plugins/edit-bar/edit-items/types.ts +6 -1
- package/src/editor/plugins/reset-viewbox.ts +17 -8
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/utils/root.ts +26 -0
- package/src/exporter/svg.ts +80 -3
- package/src/resource/loaders/search.ts +0 -3
- package/src/templates/utils.ts +30 -6
- package/src/utils/padding.ts +1 -1
- package/src/utils/style.ts +31 -4
- package/src/version.ts +1 -1
|
@@ -4,6 +4,7 @@ exports.EditBar = void 0;
|
|
|
4
4
|
const constants_1 = require("../../../constants");
|
|
5
5
|
const jsx_1 = require("../../../jsx");
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
|
+
const utils_2 = require("../../utils");
|
|
7
8
|
const base_1 = require("../base");
|
|
8
9
|
const edit_items_1 = require("./edit-items");
|
|
9
10
|
class EditBar extends base_1.Plugin {
|
|
@@ -112,29 +113,31 @@ class EditBar extends base_1.Plugin {
|
|
|
112
113
|
}
|
|
113
114
|
(0, utils_1.setElementRole)(container, constants_1.COMPONENT_ROLE);
|
|
114
115
|
this.container = container;
|
|
115
|
-
const
|
|
116
|
-
const resolvedContainer = typeof getContainer === 'function' ? getContainer() : getContainer;
|
|
117
|
-
const containerParent = resolvedContainer !== null && resolvedContainer !== void 0 ? resolvedContainer : document.body;
|
|
116
|
+
const containerParent = this.resolveOverlayRoot();
|
|
118
117
|
containerParent === null || containerParent === void 0 ? void 0 : containerParent.appendChild(container);
|
|
119
118
|
return container;
|
|
120
119
|
}
|
|
121
120
|
getTextEditItems(text) {
|
|
122
121
|
const { attributes = {} } = (0, utils_1.getTextElementProps)(text);
|
|
123
|
-
|
|
122
|
+
const root = this.resolveOverlayRoot();
|
|
123
|
+
return [edit_items_1.FontColor, edit_items_1.FontSize, edit_items_1.FontAlign, edit_items_1.FontFamily].map((item) => item([text], attributes, this.commander, { root }));
|
|
124
124
|
}
|
|
125
125
|
getTextCollectionEditItems(selection) {
|
|
126
126
|
const attrs = (0, utils_1.getCommonAttrs)(selection.map((text) => (0, utils_1.getTextElementProps)(text).attributes || {}));
|
|
127
|
-
const
|
|
127
|
+
const root = this.resolveOverlayRoot();
|
|
128
|
+
const items = [edit_items_1.FontColor, edit_items_1.FontSize, edit_items_1.FontAlign, edit_items_1.FontFamily].map((item) => item(selection, attrs, this.commander, { root }));
|
|
128
129
|
const commonItems = this.getElementCollectionEditItems(selection);
|
|
129
130
|
return [...items, ...commonItems];
|
|
130
131
|
}
|
|
131
132
|
getIconEditItems(selection) {
|
|
132
133
|
const attrs = (0, utils_1.getIconAttrs)(selection[0]);
|
|
133
|
-
|
|
134
|
+
const root = this.resolveOverlayRoot();
|
|
135
|
+
return [edit_items_1.IconColor].map((item) => item(selection, attrs, this.commander, { root }));
|
|
134
136
|
}
|
|
135
137
|
getIconCollectionEditItems(selection) {
|
|
136
138
|
const attrs = (0, utils_1.getCommonAttrs)(selection.map((icon) => (0, utils_1.getIconAttrs)(icon)));
|
|
137
|
-
|
|
139
|
+
const root = this.resolveOverlayRoot();
|
|
140
|
+
return [edit_items_1.IconColor].map((item) => item(selection, attrs, this.commander, { root }));
|
|
138
141
|
}
|
|
139
142
|
getGeometryEditItems(_selection) {
|
|
140
143
|
return [];
|
|
@@ -146,12 +149,19 @@ class EditBar extends base_1.Plugin {
|
|
|
146
149
|
getElementCollectionEditItems(selection) {
|
|
147
150
|
if (selection.length <= 1)
|
|
148
151
|
return [];
|
|
152
|
+
const root = this.resolveOverlayRoot();
|
|
149
153
|
return [
|
|
150
154
|
(0, edit_items_1.ElementAlign)(selection, {}, this.commander, {
|
|
151
155
|
enableDistribution: selection.length > 2,
|
|
156
|
+
root,
|
|
152
157
|
}),
|
|
153
158
|
];
|
|
154
159
|
}
|
|
160
|
+
resolveOverlayRoot() {
|
|
161
|
+
const { getContainer } = this.options || {};
|
|
162
|
+
const resolvedContainer = typeof getContainer === 'function' ? getContainer() : getContainer;
|
|
163
|
+
return resolvedContainer !== null && resolvedContainer !== void 0 ? resolvedContainer : (0, utils_2.getOverlayContainer)(this.editor.getDocument());
|
|
164
|
+
}
|
|
155
165
|
placeEditBar(container, selection) {
|
|
156
166
|
var _a;
|
|
157
167
|
if (selection.length === 0)
|
|
@@ -32,18 +32,19 @@ const ALIGN_OPTIONS = [
|
|
|
32
32
|
];
|
|
33
33
|
const ElementAlign = (selection, _attrs, commander, options) => {
|
|
34
34
|
var _a;
|
|
35
|
-
(0, utils_1.injectStyleOnce)(GRID_STYLE_ID, GRID_STYLES);
|
|
35
|
+
(0, utils_1.injectStyleOnce)(GRID_STYLE_ID, GRID_STYLES, options === null || options === void 0 ? void 0 : options.root);
|
|
36
36
|
const enableDistribution = (_a = options === null || options === void 0 ? void 0 : options.enableDistribution) !== null && _a !== void 0 ? _a : true;
|
|
37
|
-
const content = createAlignContent((action) => alignSelection(selection, action, commander), enableDistribution);
|
|
37
|
+
const content = createAlignContent((action) => alignSelection(selection, action, commander), enableDistribution, options === null || options === void 0 ? void 0 : options.root);
|
|
38
38
|
return (0, components_1.Popover)({
|
|
39
|
-
target: (0, components_1.IconButton)({ icon: components_1.ELEMENT_ICONS.align }),
|
|
39
|
+
target: (0, components_1.IconButton)({ icon: components_1.ELEMENT_ICONS.align, root: options === null || options === void 0 ? void 0 : options.root }),
|
|
40
40
|
content,
|
|
41
|
+
getContainer: options === null || options === void 0 ? void 0 : options.root,
|
|
41
42
|
placement: 'top',
|
|
42
43
|
offset: 12,
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
exports.ElementAlign = ElementAlign;
|
|
46
|
-
function createAlignContent(onSelect, enableDistribution) {
|
|
47
|
+
function createAlignContent(onSelect, enableDistribution, root) {
|
|
47
48
|
const content = document.createElement('div');
|
|
48
49
|
content.classList.add(GRID_CLASS);
|
|
49
50
|
if (!enableDistribution)
|
|
@@ -53,6 +54,7 @@ function createAlignContent(onSelect, enableDistribution) {
|
|
|
53
54
|
: ALIGN_OPTIONS.filter(({ action }) => action !== 'H_DISTRIBUTE' && action !== 'V_DISTRIBUTE');
|
|
54
55
|
visibleOptions.forEach(({ icon, action }) => {
|
|
55
56
|
const button = (0, components_1.IconButton)({
|
|
57
|
+
root,
|
|
56
58
|
icon,
|
|
57
59
|
onClick: () => onSelect(action),
|
|
58
60
|
});
|
|
@@ -25,13 +25,14 @@ const GRID_STYLES = `
|
|
|
25
25
|
gap: 2px;
|
|
26
26
|
}
|
|
27
27
|
`;
|
|
28
|
-
const FontAlign = (selection, attrs, commander) => {
|
|
29
|
-
|
|
28
|
+
const FontAlign = (selection, attrs, commander, options) => {
|
|
29
|
+
const root = options === null || options === void 0 ? void 0 : options.root;
|
|
30
|
+
(0, utils_1.injectStyleOnce)(GRID_STYLE_ID, GRID_STYLES, root);
|
|
30
31
|
const state = {
|
|
31
32
|
horizontal: attrs['data-horizontal-align'],
|
|
32
33
|
vertical: attrs['data-vertical-align'],
|
|
33
34
|
};
|
|
34
|
-
const button = (0, components_1.IconButton)({ icon: components_1.TEXT_ICONS.align });
|
|
35
|
+
const button = (0, components_1.IconButton)({ icon: components_1.TEXT_ICONS.align, root });
|
|
35
36
|
const content = createAlignContent(state, (align) => {
|
|
36
37
|
const attributes = {};
|
|
37
38
|
if (align.horizontal)
|
|
@@ -43,16 +44,17 @@ const FontAlign = (selection, attrs, commander) => {
|
|
|
43
44
|
commander.executeBatch(selection.map((text) => new commands_1.UpdateElementCommand(text, {
|
|
44
45
|
attributes,
|
|
45
46
|
})));
|
|
46
|
-
});
|
|
47
|
+
}, root);
|
|
47
48
|
return (0, components_1.Popover)({
|
|
48
49
|
target: button,
|
|
49
50
|
content,
|
|
51
|
+
getContainer: root,
|
|
50
52
|
placement: 'top',
|
|
51
53
|
offset: 12,
|
|
52
54
|
});
|
|
53
55
|
};
|
|
54
56
|
exports.FontAlign = FontAlign;
|
|
55
|
-
function createAlignContent(state, onAlignChange) {
|
|
57
|
+
function createAlignContent(state, onAlignChange, root) {
|
|
56
58
|
const content = document.createElement('div');
|
|
57
59
|
content.classList.add(GRID_CLASS);
|
|
58
60
|
const buttons = {};
|
|
@@ -65,6 +67,7 @@ function createAlignContent(state, onAlignChange) {
|
|
|
65
67
|
const createButtons = (options, stateKey) => {
|
|
66
68
|
options.forEach(({ icon, align }) => {
|
|
67
69
|
const button = (0, components_1.IconButton)({
|
|
70
|
+
root,
|
|
68
71
|
icon,
|
|
69
72
|
onClick: () => {
|
|
70
73
|
if (state[stateKey] === align)
|
|
@@ -7,8 +7,9 @@ const components_1 = require("../../components");
|
|
|
7
7
|
const FONT_COLOR_BUTTON_CLASS = 'infographic-font-color-btn';
|
|
8
8
|
const FONT_COLOR_STYLE_ID = 'infographic-font-color-style';
|
|
9
9
|
const DEFAULT_COLOR = '#1f1f1f';
|
|
10
|
-
const FontColor = (selection, attrs, commander) => {
|
|
11
|
-
|
|
10
|
+
const FontColor = (selection, attrs, commander, options) => {
|
|
11
|
+
const root = options === null || options === void 0 ? void 0 : options.root;
|
|
12
|
+
ensureFontColorStyles(root);
|
|
12
13
|
const color = normalizeColor(attrs.fill);
|
|
13
14
|
const isMixed = attrs.fill === undefined && selection.length > 1;
|
|
14
15
|
const button = document.createElement('button');
|
|
@@ -16,6 +17,7 @@ const FontColor = (selection, attrs, commander) => {
|
|
|
16
17
|
button.classList.add(FONT_COLOR_BUTTON_CLASS);
|
|
17
18
|
setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
|
|
18
19
|
const picker = (0, components_1.ColorPicker)({
|
|
20
|
+
root,
|
|
19
21
|
value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
|
|
20
22
|
onChange: (nextColor) => {
|
|
21
23
|
setButtonColor(button, nextColor, false);
|
|
@@ -27,6 +29,7 @@ const FontColor = (selection, attrs, commander) => {
|
|
|
27
29
|
return (0, components_1.Popover)({
|
|
28
30
|
target: button,
|
|
29
31
|
content: picker,
|
|
32
|
+
getContainer: root,
|
|
30
33
|
placement: ['top', 'bottom'],
|
|
31
34
|
offset: 12,
|
|
32
35
|
trigger: 'hover',
|
|
@@ -48,7 +51,7 @@ function setButtonColor(button, color, mixed) {
|
|
|
48
51
|
else
|
|
49
52
|
button.removeAttribute('data-mixed');
|
|
50
53
|
}
|
|
51
|
-
function ensureFontColorStyles() {
|
|
54
|
+
function ensureFontColorStyles(target) {
|
|
52
55
|
(0, utils_1.injectStyleOnce)(FONT_COLOR_STYLE_ID, `
|
|
53
56
|
.${FONT_COLOR_BUTTON_CLASS} {
|
|
54
57
|
position: relative;
|
|
@@ -77,5 +80,5 @@ function ensureFontColorStyles() {
|
|
|
77
80
|
#f5f5f5 12px
|
|
78
81
|
);
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
`, target);
|
|
81
84
|
}
|
|
@@ -9,22 +9,23 @@ const FONT_LIST_CLASS = 'infographic-font-family-list';
|
|
|
9
9
|
const FONT_OPTION_CLASS = `${FONT_LIST_CLASS}__option`;
|
|
10
10
|
const FONT_LIST_STYLE_ID = 'infographic-font-family-list-style';
|
|
11
11
|
const DEFAULT_FONT_LABEL = '默认';
|
|
12
|
-
const FontFamily = (selection, attrs, commander) => {
|
|
13
|
-
|
|
12
|
+
const FontFamily = (selection, attrs, commander, editItemOptions) => {
|
|
13
|
+
const root = editItemOptions === null || editItemOptions === void 0 ? void 0 : editItemOptions.root;
|
|
14
|
+
ensureFontFamilyListStyle(root);
|
|
14
15
|
const fonts = (0, renderer_1.getFonts)();
|
|
15
16
|
const current = normalizeFontFamily(attrs['font-family']);
|
|
16
|
-
const
|
|
17
|
+
const fontOptions = fonts.map((font) => ({
|
|
17
18
|
label: font.name || font.fontFamily,
|
|
18
19
|
value: font.fontFamily,
|
|
19
20
|
}));
|
|
20
|
-
if (!
|
|
21
|
-
|
|
21
|
+
if (!fontOptions.some((option) => normalizeFontFamily(option.value) === current)) {
|
|
22
|
+
fontOptions.unshift({
|
|
22
23
|
label: DEFAULT_FONT_LABEL,
|
|
23
24
|
value: current,
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
let selected = current;
|
|
27
|
-
const content = createFontList(
|
|
28
|
+
const content = createFontList(fontOptions, selected, (value) => {
|
|
28
29
|
if (selected === value)
|
|
29
30
|
return;
|
|
30
31
|
selected = value;
|
|
@@ -32,10 +33,11 @@ const FontFamily = (selection, attrs, commander) => {
|
|
|
32
33
|
attributes: { 'font-family': (0, utils_1.decodeFontFamily)(value) },
|
|
33
34
|
})));
|
|
34
35
|
});
|
|
35
|
-
const button = (0, components_1.IconButton)({ icon: components_1.TEXT_ICONS.fontFamily });
|
|
36
|
+
const button = (0, components_1.IconButton)({ icon: components_1.TEXT_ICONS.fontFamily, root });
|
|
36
37
|
const popover = (0, components_1.Popover)({
|
|
37
38
|
target: button,
|
|
38
39
|
content,
|
|
40
|
+
getContainer: root,
|
|
39
41
|
placement: ['top', 'bottom'],
|
|
40
42
|
offset: 12,
|
|
41
43
|
trigger: 'hover',
|
|
@@ -85,7 +87,7 @@ function normalizeFontFamily(font) {
|
|
|
85
87
|
return (0, utils_1.encodeFontFamily)(font.join(', '));
|
|
86
88
|
return (0, utils_1.encodeFontFamily)(String(font));
|
|
87
89
|
}
|
|
88
|
-
function ensureFontFamilyListStyle() {
|
|
90
|
+
function ensureFontFamilyListStyle(target) {
|
|
89
91
|
(0, utils_1.injectStyleOnce)(FONT_LIST_STYLE_ID, `
|
|
90
92
|
.${FONT_LIST_CLASS} {
|
|
91
93
|
display: flex;
|
|
@@ -115,5 +117,5 @@ function ensureFontFamilyListStyle() {
|
|
|
115
117
|
background: #e6f4ff;
|
|
116
118
|
color: #0958d9;
|
|
117
119
|
}
|
|
118
|
-
|
|
120
|
+
`, target);
|
|
119
121
|
}
|
|
@@ -21,24 +21,26 @@ const FONT_SIZE_STYLES = `
|
|
|
21
21
|
gap: 2px;
|
|
22
22
|
}
|
|
23
23
|
`;
|
|
24
|
-
const FontSize = (selection, attrs, commander) => {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const FontSize = (selection, attrs, commander, options) => {
|
|
25
|
+
const root = options === null || options === void 0 ? void 0 : options.root;
|
|
26
|
+
(0, utils_1.injectStyleOnce)(FONT_SIZE_STYLE_ID, FONT_SIZE_STYLES, root);
|
|
27
|
+
const button = (0, components_1.IconButton)({ icon: components_1.TEXT_ICONS.fontSize, root });
|
|
27
28
|
const currentSize = normalizeFontSize(attrs['font-size']);
|
|
28
29
|
const content = createFontSizeContent(currentSize, (size) => {
|
|
29
30
|
commander.executeBatch(selection.map((text) => new commands_1.UpdateElementCommand(text, {
|
|
30
31
|
attributes: { 'font-size': size },
|
|
31
32
|
})));
|
|
32
|
-
});
|
|
33
|
+
}, root);
|
|
33
34
|
return (0, components_1.Popover)({
|
|
34
35
|
target: button,
|
|
35
36
|
content,
|
|
37
|
+
getContainer: root,
|
|
36
38
|
placement: 'top',
|
|
37
39
|
offset: 12,
|
|
38
40
|
});
|
|
39
41
|
};
|
|
40
42
|
exports.FontSize = FontSize;
|
|
41
|
-
function createFontSizeContent(defaultSize, onSizeChange) {
|
|
43
|
+
function createFontSizeContent(defaultSize, onSizeChange, root) {
|
|
42
44
|
const content = document.createElement('div');
|
|
43
45
|
content.classList.add(FONT_SIZE_CLASS);
|
|
44
46
|
let selected = defaultSize;
|
|
@@ -51,6 +53,7 @@ function createFontSizeContent(defaultSize, onSizeChange) {
|
|
|
51
53
|
};
|
|
52
54
|
FONT_SIZE_OPTIONS.forEach(({ label, value }) => {
|
|
53
55
|
const button = (0, components_1.IconButton)({
|
|
56
|
+
root,
|
|
54
57
|
icon: createLabelIcon(label),
|
|
55
58
|
onClick: () => {
|
|
56
59
|
if (selected === value)
|
|
@@ -7,8 +7,9 @@ const components_1 = require("../../components");
|
|
|
7
7
|
const ICON_COLOR_BUTTON_CLASS = 'infographic-icon-color-btn';
|
|
8
8
|
const ICON_COLOR_STYLE_ID = 'infographic-icon-color-style';
|
|
9
9
|
const DEFAULT_COLOR = '#1f1f1f';
|
|
10
|
-
const IconColor = (selection, attrs, commander) => {
|
|
11
|
-
|
|
10
|
+
const IconColor = (selection, attrs, commander, options) => {
|
|
11
|
+
const root = options === null || options === void 0 ? void 0 : options.root;
|
|
12
|
+
ensureIconColorStyles(root);
|
|
12
13
|
const color = normalizeColor(attrs.fill);
|
|
13
14
|
const isMixed = attrs.fill === undefined && selection.length > 1;
|
|
14
15
|
const button = document.createElement('button');
|
|
@@ -16,6 +17,7 @@ const IconColor = (selection, attrs, commander) => {
|
|
|
16
17
|
button.classList.add(ICON_COLOR_BUTTON_CLASS);
|
|
17
18
|
setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
|
|
18
19
|
const picker = (0, components_1.ColorPicker)({
|
|
20
|
+
root,
|
|
19
21
|
value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
|
|
20
22
|
onChange: (nextColor) => {
|
|
21
23
|
setButtonColor(button, nextColor, false);
|
|
@@ -27,6 +29,7 @@ const IconColor = (selection, attrs, commander) => {
|
|
|
27
29
|
return (0, components_1.Popover)({
|
|
28
30
|
target: button,
|
|
29
31
|
content: picker,
|
|
32
|
+
getContainer: root,
|
|
30
33
|
placement: ['top', 'bottom'],
|
|
31
34
|
offset: 12,
|
|
32
35
|
trigger: 'hover',
|
|
@@ -48,7 +51,7 @@ function setButtonColor(button, color, mixed) {
|
|
|
48
51
|
else
|
|
49
52
|
button.removeAttribute('data-mixed');
|
|
50
53
|
}
|
|
51
|
-
function ensureIconColorStyles() {
|
|
54
|
+
function ensureIconColorStyles(target) {
|
|
52
55
|
(0, utils_1.injectStyleOnce)(ICON_COLOR_STYLE_ID, `
|
|
53
56
|
.${ICON_COLOR_BUTTON_CLASS} {
|
|
54
57
|
position: relative;
|
|
@@ -77,5 +80,5 @@ function ensureIconColorStyles() {
|
|
|
77
80
|
#f5f5f5 12px
|
|
78
81
|
);
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
`, target);
|
|
81
84
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { BaseAttributes } from '../../../../types';
|
|
2
2
|
import type { ICommandManager, Selection } from '../../../types';
|
|
3
|
-
export type
|
|
3
|
+
export type EditItemOptions = {
|
|
4
|
+
root?: HTMLElement | ShadowRoot;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export type EditItem<T extends BaseAttributes = BaseAttributes> = (selection: Selection, attrs: T, commander: ICommandManager, options?: EditItemOptions) => HTMLElement;
|
|
@@ -3,8 +3,9 @@ import { Plugin } from './base';
|
|
|
3
3
|
export interface ResetViewBoxOptions {
|
|
4
4
|
style?: Partial<CSSStyleDeclaration>;
|
|
5
5
|
className?: string;
|
|
6
|
-
getContainer?:
|
|
6
|
+
getContainer?: OverlayRoot | (() => OverlayRoot);
|
|
7
7
|
}
|
|
8
|
+
type OverlayRoot = HTMLElement | ShadowRoot;
|
|
8
9
|
export declare class ResetViewBox extends Plugin implements IPlugin {
|
|
9
10
|
private options?;
|
|
10
11
|
name: string;
|
|
@@ -29,5 +30,7 @@ export declare class ResetViewBox extends Plugin implements IPlugin {
|
|
|
29
30
|
private showButton;
|
|
30
31
|
private hideButton;
|
|
31
32
|
private removeButton;
|
|
33
|
+
private resolveOverlayRoot;
|
|
32
34
|
private ensureButtonStyle;
|
|
33
35
|
}
|
|
36
|
+
export {};
|
|
@@ -4,6 +4,7 @@ exports.ResetViewBox = void 0;
|
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
const commands_1 = require("../commands");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
7
8
|
const base_1 = require("./base");
|
|
8
9
|
const components_1 = require("./components");
|
|
9
10
|
const icons_1 = require("./components/icons");
|
|
@@ -36,9 +37,12 @@ class ResetViewBox extends base_1.Plugin {
|
|
|
36
37
|
if (this.resetButton)
|
|
37
38
|
return this.resetButton;
|
|
38
39
|
const { style, className } = this.options || {};
|
|
40
|
+
const containerParent = this.resolveOverlayRoot();
|
|
41
|
+
this.ensureButtonStyle(containerParent);
|
|
39
42
|
const button = (0, components_1.IconButton)({
|
|
40
43
|
icon: icons_1.RESET_ICON,
|
|
41
44
|
onClick: this.resetViewBox,
|
|
45
|
+
root: containerParent,
|
|
42
46
|
});
|
|
43
47
|
button.classList.add(RESET_BUTTON_CLASS);
|
|
44
48
|
if (className) {
|
|
@@ -49,9 +53,6 @@ class ResetViewBox extends base_1.Plugin {
|
|
|
49
53
|
}
|
|
50
54
|
(0, utils_1.setElementRole)(button, constants_1.COMPONENT_ROLE);
|
|
51
55
|
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
56
|
containerParent === null || containerParent === void 0 ? void 0 : containerParent.appendChild(button);
|
|
56
57
|
return button;
|
|
57
58
|
};
|
|
@@ -142,7 +143,7 @@ class ResetViewBox extends base_1.Plugin {
|
|
|
142
143
|
init(options) {
|
|
143
144
|
super.init(options);
|
|
144
145
|
// Initialize originViewBox
|
|
145
|
-
this.ensureButtonStyle();
|
|
146
|
+
this.ensureButtonStyle(this.resolveOverlayRoot());
|
|
146
147
|
this.updateOriginViewBox();
|
|
147
148
|
this.unregisterSync = this.editor.registerSync('viewBox', this.handleViewBoxChange);
|
|
148
149
|
window.addEventListener('resize', this.handleResize);
|
|
@@ -164,7 +165,12 @@ class ResetViewBox extends base_1.Plugin {
|
|
|
164
165
|
const { padding } = this.state.getOptions();
|
|
165
166
|
this.originViewBox = (0, utils_1.getBoundViewBox)(svg, (0, utils_1.parsePadding)(padding));
|
|
166
167
|
}
|
|
167
|
-
|
|
168
|
+
resolveOverlayRoot() {
|
|
169
|
+
const { getContainer } = this.options || {};
|
|
170
|
+
const resolvedContainer = typeof getContainer === 'function' ? getContainer() : getContainer;
|
|
171
|
+
return resolvedContainer !== null && resolvedContainer !== void 0 ? resolvedContainer : (0, utils_2.getOverlayContainer)(this.editor.getDocument());
|
|
172
|
+
}
|
|
173
|
+
ensureButtonStyle(target) {
|
|
168
174
|
(0, utils_1.injectStyleOnce)(RESET_BUTTON_STYLE_ID, `
|
|
169
175
|
button.${RESET_BUTTON_CLASS} {
|
|
170
176
|
visibility: hidden;
|
|
@@ -182,7 +188,7 @@ class ResetViewBox extends base_1.Plugin {
|
|
|
182
188
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
183
189
|
cursor: pointer;
|
|
184
190
|
}
|
|
185
|
-
|
|
191
|
+
`, target);
|
|
186
192
|
}
|
|
187
193
|
}
|
|
188
194
|
exports.ResetViewBox = ResetViewBox;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOverlayContainer = getOverlayContainer;
|
|
4
|
+
exports.eventPathContains = eventPathContains;
|
|
5
|
+
function getConnectedRoot(node) {
|
|
6
|
+
if (!(node === null || node === void 0 ? void 0 : node.isConnected))
|
|
7
|
+
return document;
|
|
8
|
+
const root = node.getRootNode();
|
|
9
|
+
return root instanceof ShadowRoot ? root : document;
|
|
10
|
+
}
|
|
11
|
+
function getOverlayContainer(node) {
|
|
12
|
+
const root = getConnectedRoot(node);
|
|
13
|
+
return root instanceof ShadowRoot ? root : document.body;
|
|
14
|
+
}
|
|
15
|
+
function eventPathContains(event, node) {
|
|
16
|
+
const path = typeof event.composedPath === 'function' ? event.composedPath() : [];
|
|
17
|
+
if (path.length > 0) {
|
|
18
|
+
return path.some((current) => current === node || (current instanceof Node && node.contains(current)));
|
|
19
|
+
}
|
|
20
|
+
const target = event.target;
|
|
21
|
+
return target instanceof Node && (target === node || node.contains(target));
|
|
22
|
+
}
|
package/lib/exporter/svg.js
CHANGED
|
@@ -26,7 +26,10 @@ function getExportViewBox(svg) {
|
|
|
26
26
|
return (0, utils_1.getViewBox)(svg);
|
|
27
27
|
const width = parseAbsoluteLength(svg.getAttribute('width'));
|
|
28
28
|
const height = parseAbsoluteLength(svg.getAttribute('height'));
|
|
29
|
-
if (width
|
|
29
|
+
if (!Number.isNaN(width) &&
|
|
30
|
+
width > 0 &&
|
|
31
|
+
!Number.isNaN(height) &&
|
|
32
|
+
height > 0) {
|
|
30
33
|
return { x: 0, y: 0, width, height };
|
|
31
34
|
}
|
|
32
35
|
const rect = svg.getBoundingClientRect();
|
|
@@ -218,8 +221,9 @@ function embedIcons(svg) {
|
|
|
218
221
|
const existsSymbol = svg.querySelector(href);
|
|
219
222
|
if (!existsSymbol) {
|
|
220
223
|
const symbolElement = document.querySelector(href);
|
|
221
|
-
if (symbolElement)
|
|
224
|
+
if (symbolElement) {
|
|
222
225
|
defs.appendChild(symbolElement.cloneNode(true));
|
|
226
|
+
}
|
|
223
227
|
}
|
|
224
228
|
});
|
|
225
229
|
});
|
|
@@ -427,6 +431,8 @@ function collectDefElements(svg, ids) {
|
|
|
427
431
|
};
|
|
428
432
|
while (queue.length) {
|
|
429
433
|
const id = queue.shift();
|
|
434
|
+
if (!id)
|
|
435
|
+
continue;
|
|
430
436
|
if (visited.has(id))
|
|
431
437
|
continue;
|
|
432
438
|
visited.add(id);
|
|
@@ -441,11 +447,65 @@ function collectDefElements(svg, ids) {
|
|
|
441
447
|
}
|
|
442
448
|
return collected;
|
|
443
449
|
}
|
|
450
|
+
// Fallback implementation based on the CSS.escape algorithm
|
|
451
|
+
function cssEscape(value) {
|
|
452
|
+
const string = String(value);
|
|
453
|
+
const length = string.length;
|
|
454
|
+
let result = '';
|
|
455
|
+
if (length === 0) {
|
|
456
|
+
return '';
|
|
457
|
+
}
|
|
458
|
+
for (let i = 0; i < length; i++) {
|
|
459
|
+
const codeUnit = string.charCodeAt(i);
|
|
460
|
+
// Null character
|
|
461
|
+
if (codeUnit === 0x0000) {
|
|
462
|
+
result += '\uFFFD';
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
// Control characters or DEL
|
|
466
|
+
if ((codeUnit >= 0x0001 && codeUnit <= 0x001f) || codeUnit === 0x007f) {
|
|
467
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
// Escape if first character is a digit
|
|
471
|
+
if (i === 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) {
|
|
472
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
// Escape if second character is a digit and first is a hyphen
|
|
476
|
+
if (i === 1 &&
|
|
477
|
+
codeUnit >= 0x0030 &&
|
|
478
|
+
codeUnit <= 0x0039 &&
|
|
479
|
+
string.charCodeAt(0) === 0x002d) {
|
|
480
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
// If the character is the first and is a hyphen followed by end of string, escape it
|
|
484
|
+
if (i === 0 && length === 1 && codeUnit === 0x002d) {
|
|
485
|
+
result += '\\' + string.charAt(i);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
// Characters that are safe to use unescaped
|
|
489
|
+
if (codeUnit >= 0x0080 ||
|
|
490
|
+
(codeUnit >= 0x0030 && codeUnit <= 0x0039) || // 0-9
|
|
491
|
+
(codeUnit >= 0x0041 && codeUnit <= 0x005a) || // A-Z
|
|
492
|
+
(codeUnit >= 0x0061 && codeUnit <= 0x007a) || // a-z
|
|
493
|
+
codeUnit === 0x002d || // -
|
|
494
|
+
codeUnit === 0x005f // _
|
|
495
|
+
) {
|
|
496
|
+
result += string.charAt(i);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
// All other characters
|
|
500
|
+
result += '\\' + string.charAt(i);
|
|
501
|
+
}
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
444
504
|
function escapeCssId(id) {
|
|
445
505
|
if (globalThis.CSS && typeof globalThis.CSS.escape === 'function') {
|
|
446
506
|
return globalThis.CSS.escape(id);
|
|
447
507
|
}
|
|
448
|
-
return id
|
|
508
|
+
return cssEscape(id);
|
|
449
509
|
}
|
|
450
510
|
function removeDefs(svg) {
|
|
451
511
|
const defsList = Array.from(svg.querySelectorAll('defs'));
|
|
@@ -57,9 +57,6 @@ function loadSearchResource(query, format) {
|
|
|
57
57
|
const svgText = commaIndex >= 0 ? result.slice(commaIndex + 1) : result;
|
|
58
58
|
return (0, svg_1.loadSVGResource)(svgText);
|
|
59
59
|
}
|
|
60
|
-
if (mimeType === 'image/svg+xml' && format === 'svg' && isBase64) {
|
|
61
|
-
return (0, image_1.loadImageBase64Resource)(result);
|
|
62
|
-
}
|
|
63
60
|
return (0, image_1.loadImageBase64Resource)(result);
|
|
64
61
|
}
|
|
65
62
|
return (0, remote_1.loadRemoteResource)(result, format);
|
package/lib/templates/utils.js
CHANGED
|
@@ -33,11 +33,20 @@ function getLevenshteinDistance(source, target) {
|
|
|
33
33
|
function getCommonPrefixLength(source, target) {
|
|
34
34
|
const limit = Math.min(source.length, target.length);
|
|
35
35
|
let index = 0;
|
|
36
|
-
while (index < limit &&
|
|
36
|
+
while (index < limit &&
|
|
37
|
+
source.charCodeAt(index) === target.charCodeAt(index)) {
|
|
37
38
|
index += 1;
|
|
38
39
|
}
|
|
39
40
|
return index;
|
|
40
41
|
}
|
|
42
|
+
function isBetterMatch(bestMatch, bestDistance, bestPrefixLength, candidateKey, candidateDistance, candidatePrefixLength) {
|
|
43
|
+
return (candidateDistance < bestDistance ||
|
|
44
|
+
(candidateDistance === bestDistance &&
|
|
45
|
+
candidatePrefixLength > bestPrefixLength) ||
|
|
46
|
+
(candidateDistance === bestDistance &&
|
|
47
|
+
candidatePrefixLength === bestPrefixLength &&
|
|
48
|
+
(!bestMatch || candidateKey < bestMatch)));
|
|
49
|
+
}
|
|
41
50
|
function findClosestTemplateKey(type, keys) {
|
|
42
51
|
const normalizedType = normalizeTemplateKey(type);
|
|
43
52
|
if (!normalizedType)
|
|
@@ -52,11 +61,7 @@ function findClosestTemplateKey(type, keys) {
|
|
|
52
61
|
}
|
|
53
62
|
const distance = getLevenshteinDistance(normalizedType, normalizedKey);
|
|
54
63
|
const prefixLength = getCommonPrefixLength(normalizedType, normalizedKey);
|
|
55
|
-
if (distance
|
|
56
|
-
(distance === bestDistance && prefixLength > bestPrefixLength) ||
|
|
57
|
-
(distance === bestDistance &&
|
|
58
|
-
prefixLength === bestPrefixLength &&
|
|
59
|
-
(!bestMatch || key < bestMatch))) {
|
|
64
|
+
if (isBetterMatch(bestMatch, bestDistance, bestPrefixLength, key, distance, prefixLength)) {
|
|
60
65
|
bestMatch = key;
|
|
61
66
|
bestDistance = distance;
|
|
62
67
|
bestPrefixLength = prefixLength;
|
package/lib/utils/padding.js
CHANGED
package/lib/utils/style.d.ts
CHANGED