@antv/infographic 0.2.13 → 0.2.14
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 +123 -116
- package/dist/infographic.min.js.map +1 -1
- 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 +15 -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 +13 -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 +26 -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 +70 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +3 -2
- package/esm/options/types.d.ts +1 -0
- package/esm/runtime/options.js +7 -2
- package/esm/templates/built-in.js +24 -0
- package/esm/utils/measure-text.js +9 -6
- package/esm/utils/padding.d.ts +1 -0
- package/esm/utils/padding.js +6 -2
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- 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 +15 -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 +13 -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 +26 -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 +73 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +9 -2
- package/lib/options/types.d.ts +1 -0
- package/lib/runtime/options.js +6 -1
- package/lib/templates/built-in.js +24 -0
- package/lib/utils/measure-text.js +9 -6
- package/lib/utils/padding.d.ts +1 -0
- package/lib/utils/padding.js +7 -2
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- 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 +65 -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 +17 -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 +31 -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 +106 -0
- package/src/index.ts +26 -2
- package/src/options/types.ts +4 -0
- package/src/runtime/options.ts +8 -1
- package/src/templates/built-in.ts +28 -0
- package/src/utils/measure-text.ts +6 -6
- package/src/utils/padding.ts +10 -2
- 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
|
@@ -6,13 +6,26 @@ const viewbox_1 = require("../../utils/viewbox");
|
|
|
6
6
|
const commands_1 = require("../commands");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const base_1 = require("./base");
|
|
9
|
-
const MIN_VIEWBOX_SIZE = 20;
|
|
10
|
-
const MAX_VIEWBOX_SIZE = 2000;
|
|
11
9
|
const ZOOM_FACTOR = 1.1;
|
|
12
10
|
class ZoomWheel extends base_1.Interaction {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super();
|
|
15
13
|
this.name = 'zoom-wheel';
|
|
14
|
+
this.minViewBoxSize = 20;
|
|
15
|
+
this.maxViewBoxSize = 20000;
|
|
16
|
+
this.initialViewBox = null;
|
|
17
|
+
this.handleKeyUp = (event) => {
|
|
18
|
+
const isZoomModifierHeld = event.ctrlKey || event.metaKey || event.shiftKey;
|
|
19
|
+
if (!isZoomModifierHeld && this.initialViewBox) {
|
|
20
|
+
const currentViewBox = (0, viewbox_1.viewBoxToString)((0, viewbox_1.getViewBox)(this.editor.getDocument()));
|
|
21
|
+
if (currentViewBox !== this.initialViewBox) {
|
|
22
|
+
const command = new commands_1.UpdateOptionsCommand({ viewBox: currentViewBox }, { viewBox: this.initialViewBox });
|
|
23
|
+
void this.commander.execute(command);
|
|
24
|
+
}
|
|
25
|
+
this.initialViewBox = null;
|
|
26
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
16
29
|
this.wheelListener = (event) => {
|
|
17
30
|
if (!this.shouldZoom(event))
|
|
18
31
|
return;
|
|
@@ -25,25 +38,20 @@ class ZoomWheel extends base_1.Interaction {
|
|
|
25
38
|
const { width, height } = viewBox;
|
|
26
39
|
const newWidth = width * factor;
|
|
27
40
|
const newHeight = height * factor;
|
|
28
|
-
if (!(0, lodash_es_1.inRange)(newWidth,
|
|
29
|
-
!(0, lodash_es_1.inRange)(newHeight,
|
|
30
|
-
return;
|
|
31
|
-
// TODO: Remove after implementing the reset UI plugin
|
|
32
|
-
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
|
|
33
|
-
const command = new commands_1.UpdateOptionsCommand({
|
|
34
|
-
viewBox: undefined,
|
|
35
|
-
});
|
|
36
|
-
void this.commander.execute(command);
|
|
41
|
+
if (!(0, lodash_es_1.inRange)(newWidth, this.minViewBoxSize, this.maxViewBoxSize) ||
|
|
42
|
+
!(0, lodash_es_1.inRange)(newHeight, this.minViewBoxSize, this.maxViewBoxSize))
|
|
37
43
|
return;
|
|
44
|
+
if (this.initialViewBox === null) {
|
|
45
|
+
this.initialViewBox = (0, viewbox_1.viewBoxToString)(viewBox);
|
|
46
|
+
document.addEventListener('keyup', this.handleKeyUp);
|
|
38
47
|
}
|
|
39
48
|
const pivot = (event.ctrlKey || event.metaKey) && !event.shiftKey
|
|
40
49
|
? this.getMousePoint(svg, event)
|
|
41
50
|
: this.getCenterPoint(viewBox);
|
|
42
51
|
const newViewBox = (0, viewbox_1.calculateZoomedViewBox)(viewBox, factor, pivot);
|
|
43
|
-
|
|
52
|
+
this.state.updateOptions({
|
|
44
53
|
viewBox: (0, viewbox_1.viewBoxToString)(newViewBox),
|
|
45
54
|
});
|
|
46
|
-
void this.commander.execute(command);
|
|
47
55
|
};
|
|
48
56
|
this.getMousePoint = (svg, event) => {
|
|
49
57
|
return (0, utils_1.clientToViewport)(svg, event.clientX, event.clientY);
|
|
@@ -60,8 +68,16 @@ class ZoomWheel extends base_1.Interaction {
|
|
|
60
68
|
return false;
|
|
61
69
|
const isMouseZoom = event.ctrlKey || event.metaKey;
|
|
62
70
|
const isCenterZoom = event.shiftKey;
|
|
71
|
+
if (isMouseZoom && isCenterZoom)
|
|
72
|
+
return false;
|
|
63
73
|
return isMouseZoom || isCenterZoom;
|
|
64
74
|
};
|
|
75
|
+
if ((options === null || options === void 0 ? void 0 : options.minViewBoxSize) !== undefined) {
|
|
76
|
+
this.minViewBoxSize = options.minViewBoxSize;
|
|
77
|
+
}
|
|
78
|
+
if ((options === null || options === void 0 ? void 0 : options.maxViewBoxSize) !== undefined) {
|
|
79
|
+
this.maxViewBoxSize = options.maxViewBoxSize;
|
|
80
|
+
}
|
|
65
81
|
}
|
|
66
82
|
init(options) {
|
|
67
83
|
super.init(options);
|
|
@@ -69,6 +85,7 @@ class ZoomWheel extends base_1.Interaction {
|
|
|
69
85
|
}
|
|
70
86
|
destroy() {
|
|
71
87
|
document.removeEventListener('wheel', this.wheelListener);
|
|
88
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
exports.ZoomWheel = ZoomWheel;
|
|
@@ -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 { ElementProps, ICommandManager, IEditor, IStateManager, StateManagerInitOptions } from '../types';
|
|
4
4
|
export declare class StateManager implements IStateManager {
|
|
@@ -12,7 +12,9 @@ export declare class StateManager implements IStateManager {
|
|
|
12
12
|
removeItemDatum(indexes: number[], count?: number): void;
|
|
13
13
|
updateData(key: string, value: any): void;
|
|
14
14
|
updateElement(element: Element, props: Partial<ElementProps>): void;
|
|
15
|
-
updateOptions(options:
|
|
15
|
+
updateOptions(options: UpdatableInfographicOptions, execOptions?: {
|
|
16
|
+
bubbleUp?: boolean;
|
|
17
|
+
}): void;
|
|
16
18
|
getOptions(): ParsedInfographicOptions;
|
|
17
19
|
/**
|
|
18
20
|
* 不包含文本内容、图标类型更新
|
|
@@ -28,6 +28,8 @@ class StateManager {
|
|
|
28
28
|
}
|
|
29
29
|
updateItemDatum(indexes, datum) {
|
|
30
30
|
const item = (0, utils_1.getDatumByIndexes)(this.options.data, indexes);
|
|
31
|
+
if (item == null || indexes.length === 0)
|
|
32
|
+
return;
|
|
31
33
|
Object.assign(item, datum);
|
|
32
34
|
this.emitter.emit('options:data:item:update', { indexes, datum });
|
|
33
35
|
this.emitter.emit('options:change', {
|
|
@@ -77,17 +79,14 @@ class StateManager {
|
|
|
77
79
|
updateElement(element, props) {
|
|
78
80
|
this.updateBuiltInElement(element, props);
|
|
79
81
|
}
|
|
80
|
-
updateOptions(options) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(0, utils_1.setSVGPadding)(this.editor.getDocument(), (0, utils_1.parsePadding)(this.options.padding));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
82
|
+
updateOptions(options, execOptions) {
|
|
83
|
+
const { bubbleUp = false } = execOptions || {};
|
|
84
|
+
(0, utils_2.applyOptionUpdates)(this.options, options, '', {
|
|
85
|
+
bubbleUp,
|
|
86
|
+
collector: (path, newVal, oldVal) => {
|
|
87
|
+
this.editor.syncRegistry.trigger(path, newVal, oldVal);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
91
90
|
this.emitter.emit('options:change', {
|
|
92
91
|
type: 'options:change',
|
|
93
92
|
changes: [
|
|
@@ -118,6 +117,8 @@ class StateManager {
|
|
|
118
117
|
const indexes = isItemElement ? (0, utils_2.getIndexesFromElement)(element) : undefined;
|
|
119
118
|
if (isItemElement) {
|
|
120
119
|
const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
|
|
120
|
+
if (datum == null)
|
|
121
|
+
return;
|
|
121
122
|
const key = role.replace('item-', '');
|
|
122
123
|
datum.attributes || (datum.attributes = {});
|
|
123
124
|
(_a = datum.attributes)[key] || (_a[key] = {});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ISyncRegistry, SyncHandler } from '../types';
|
|
2
|
+
type OptionsGetter = () => any;
|
|
3
|
+
export declare class SyncRegistry implements ISyncRegistry {
|
|
4
|
+
private getOptions;
|
|
5
|
+
private handlers;
|
|
6
|
+
private isDispatching;
|
|
7
|
+
private isDestroyed;
|
|
8
|
+
constructor(getOptions: OptionsGetter);
|
|
9
|
+
register(path: string, handler: SyncHandler, options?: {
|
|
10
|
+
immediate?: boolean;
|
|
11
|
+
}): () => void;
|
|
12
|
+
trigger(path: string, newVal: any, oldVal: any): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SyncRegistry = void 0;
|
|
4
|
+
const lodash_es_1 = require("lodash-es");
|
|
5
|
+
class SyncRegistry {
|
|
6
|
+
constructor(getOptions) {
|
|
7
|
+
this.getOptions = getOptions;
|
|
8
|
+
this.handlers = new Map();
|
|
9
|
+
// lock to prevent recursive updates
|
|
10
|
+
this.isDispatching = false;
|
|
11
|
+
this.isDestroyed = false;
|
|
12
|
+
}
|
|
13
|
+
register(path, handler, options) {
|
|
14
|
+
if (!this.handlers.has(path)) {
|
|
15
|
+
this.handlers.set(path, new Set());
|
|
16
|
+
}
|
|
17
|
+
this.handlers.get(path).add(handler);
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.immediate) {
|
|
19
|
+
const currentVal = (0, lodash_es_1.get)(this.getOptions(), path);
|
|
20
|
+
handler(currentVal, undefined);
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
const set = this.handlers.get(path);
|
|
24
|
+
if (set) {
|
|
25
|
+
set.delete(handler);
|
|
26
|
+
if (set.size === 0) {
|
|
27
|
+
this.handlers.delete(path);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
trigger(path, newVal, oldVal) {
|
|
33
|
+
if (this.isDestroyed || this.isDispatching) {
|
|
34
|
+
if (this.isDispatching) {
|
|
35
|
+
console.warn(`[SyncRegistry] Recursive update detected on ${path}. Skipped to prevent loop.`);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const handlers = this.handlers.get(path);
|
|
40
|
+
if (handlers) {
|
|
41
|
+
this.isDispatching = true;
|
|
42
|
+
try {
|
|
43
|
+
handlers.forEach((fn) => fn(newVal, oldVal));
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
this.isDispatching = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
this.isDestroyed = true;
|
|
52
|
+
this.handlers.clear();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.SyncRegistry = SyncRegistry;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IconButton = void 0;
|
|
4
|
-
const utils_1 = require("
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
5
|
const IconButton = ({ icon, onClick, activate = false, }) => {
|
|
6
6
|
ensureIconButtonStyle();
|
|
7
7
|
const button = document.createElement('button');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ColorPicker = ColorPicker;
|
|
4
4
|
const culori_1 = require("culori");
|
|
5
|
-
const utils_1 = require("
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
6
|
const COLOR_PICKER_CLASS = 'infographic-color-picker';
|
|
7
7
|
const COLOR_PICKER_SWATCHES_CLASS = `${COLOR_PICKER_CLASS}__swatches`;
|
|
8
8
|
const COLOR_PICKER_SWATCH_CLASS = `${COLOR_PICKER_CLASS}__swatch`;
|
|
@@ -13,6 +13,7 @@ export declare const TEXT_ICONS: {
|
|
|
13
13
|
alignCenter: ({ fill }?: IconProps) => HTMLElement;
|
|
14
14
|
alignMiddle: ({ fill }?: IconProps) => HTMLElement;
|
|
15
15
|
};
|
|
16
|
+
export declare const RESET_ICON: ({ fill }?: IconProps) => HTMLElement;
|
|
16
17
|
export declare const ELEMENT_ICONS: {
|
|
17
18
|
align: ({ fill }?: IconProps) => HTMLElement;
|
|
18
19
|
alignTop: ({ fill }?: IconProps) => HTMLElement;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ELEMENT_ICONS = exports.TEXT_ICONS = void 0;
|
|
3
|
+
exports.ELEMENT_ICONS = exports.RESET_ICON = exports.TEXT_ICONS = void 0;
|
|
4
4
|
const createIcon = (children, { viewBox = '0 0 1024 1024', size = '1.5em' } = {}) => ({ fill = 'currentColor' } = {}) => {
|
|
5
5
|
const html = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}" width="${size}" height="${size}" fill="${fill}">
|
|
6
6
|
${children.trim()}
|
|
@@ -19,6 +19,7 @@ exports.TEXT_ICONS = {
|
|
|
19
19
|
alignCenter: createIcon(`<path d="M768 800.339c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.995l-0.53 0.005H256c-17.673 0-32-14.327-32-32 0-17.497 14.042-31.713 31.47-31.996l0.53-0.004h512z m128-213.226c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.996l0.53-0.004h768zM768 373.887c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.996l-0.53 0.004H256c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.996l0.53-0.004h512z m128-213.226c17.673 0 32 14.327 32 32 0 17.497-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.995l0.53-0.005h768z"></path>`),
|
|
20
20
|
alignMiddle: createIcon(`<path d="M534.246 617.448l0.377 0.371 128 127.952c12.5 12.494 12.503 32.755 0.009 45.255-12.37 12.374-32.352 12.501-44.878 0.38l-0.377-0.372-73.38-73.352V939c0 17.673-14.326 32-32 32-17.496 0-31.712-14.042-31.995-31.47l-0.004-0.53-0.001-221.314-73.374 73.348c-12.374 12.37-32.356 12.49-44.878 0.363l-0.377-0.371c-12.37-12.375-12.49-32.356-0.362-44.878l0.37-0.377 128-127.952c12.372-12.366 32.347-12.49 44.87-0.37zM896 480.508c17.673 0 32 14.327 32 32 0 17.497-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.995l0.53-0.005h768zM511.998 54c17.496 0 31.713 14.042 31.996 31.47l0.004 0.53-0.001 221.314 73.38-73.349c12.499-12.494 32.76-12.49 45.255 0.009 12.37 12.374 12.49 32.356 0.362 44.878l-0.37 0.377-128 127.951c-12.372 12.366-32.347 12.49-44.87 0.371l-0.377-0.37-128-127.952c-12.5-12.495-12.503-32.756-0.009-45.255 12.37-12.374 32.352-12.502 44.878-0.38l0.377 0.371 73.374 73.346V86c0-17.673 14.328-32 32-32z"></path>`),
|
|
21
21
|
};
|
|
22
|
+
exports.RESET_ICON = createIcon(`<path d="M502.714987 58.258904l-126.531056-54.617723a52.797131 52.797131 0 0 0-41.873587 96.855428A447.865322 447.865322 0 0 0 392.02307 946.707184a61.535967 61.535967 0 0 0 13.83649 1.820591 52.797131 52.797131 0 0 0 13.65443-103.773672 342.453118 342.453118 0 0 1-31.678278-651.771485l-8.374718 19.480321a52.615072 52.615072 0 0 0 27.855039 69.182448 51.522718 51.522718 0 0 0 20.572675 4.369418A52.797131 52.797131 0 0 0 476.498481 254.882703L530.205907 127.441352a52.979191 52.979191 0 0 0-27.49092-69.182448zM962.960326 509.765407A448.775617 448.775617 0 0 0 643.992829 68.090094a52.797131 52.797131 0 1 0-30.403866 101.042786A342.635177 342.635177 0 0 1 674.578753 801.059925a52.615072 52.615072 0 0 0-92.30395-50.612422l-71.913335 117.246043a52.433013 52.433013 0 0 0 17.295612 72.82363l117.063985 72.823629a52.797131 52.797131 0 1 0 54.617722-89.755123l-16.021198-10.013249A448.593558 448.593558 0 0 0 962.960326 509.765407z" p-id="1630"/>`);
|
|
22
23
|
exports.ELEMENT_ICONS = {
|
|
23
24
|
align: createIcon(`<path d="M555.188 715.059c17.673 0 32 14.327 32 32V875c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V747.059c0-17.673 14.327-32 32-32z m-32.001 63.999H203V843h320.187v-63.942zM854 416.529c17.673 0 32 14.327 32 32v127.942c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V448.529c0-17.673 14.327-32 32-32z m-32 64H203v63.941h619v-63.941zM683.25 118c17.673 0 32 14.327 32 32v127.941c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V150c0-17.673 14.327-32 32-32z m-32 64H203v63.941h448.25V182z"></path>`),
|
|
24
25
|
alignTop: createIcon(`
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Popover = Popover;
|
|
4
|
-
const constants_1 = require("
|
|
5
|
-
const utils_1 = require("
|
|
4
|
+
const constants_1 = require("../../../constants");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
6
|
const POPOVER_CLASS = 'infographic-edit-popover';
|
|
7
7
|
const POPOVER_CONTENT_CLASS = `${POPOVER_CLASS}__content`;
|
|
8
8
|
const POPOVER_ARROW_CLASS = `${POPOVER_CLASS}__arrow`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Select = Select;
|
|
4
|
-
const utils_1 = require("
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
5
|
const SELECT_CLASS = 'infographic-edit-select';
|
|
6
6
|
const SELECT_STYLE_ID = 'infographic-edit-select-style';
|
|
7
7
|
const OPTION_CLASS = `${SELECT_CLASS}__option`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPlugin, PluginInitOptions } from '../types';
|
|
2
|
+
import { Plugin } from './base';
|
|
3
|
+
export declare class CoreSyncPlugin extends Plugin implements IPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
private unregisters;
|
|
6
|
+
init(options: PluginInitOptions): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreSyncPlugin = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
class CoreSyncPlugin extends base_1.Plugin {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.name = 'core-sync';
|
|
10
|
+
this.unregisters = [];
|
|
11
|
+
}
|
|
12
|
+
init(options) {
|
|
13
|
+
super.init(options);
|
|
14
|
+
const svg = this.editor.getDocument();
|
|
15
|
+
// viewBox Sync
|
|
16
|
+
this.unregisters.push(this.editor.registerSync('viewBox', (val) => {
|
|
17
|
+
if (val) {
|
|
18
|
+
svg.setAttribute('viewBox', val);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
svg.removeAttribute('viewBox');
|
|
22
|
+
}
|
|
23
|
+
}, { immediate: true }));
|
|
24
|
+
// padding Sync
|
|
25
|
+
this.unregisters.push(this.editor.registerSync('padding', (val) => {
|
|
26
|
+
if (val !== undefined)
|
|
27
|
+
(0, utils_1.setSVGPadding)(svg, (0, utils_1.parsePadding)(val));
|
|
28
|
+
}, { immediate: true }));
|
|
29
|
+
}
|
|
30
|
+
destroy() {
|
|
31
|
+
this.unregisters.forEach((fn) => fn());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.CoreSyncPlugin = CoreSyncPlugin;
|
|
@@ -5,7 +5,7 @@ const jsx_1 = require("../../../../jsx");
|
|
|
5
5
|
const utils_1 = require("../../../../utils");
|
|
6
6
|
const commands_1 = require("../../../commands");
|
|
7
7
|
const utils_2 = require("../../../utils");
|
|
8
|
-
const components_1 = require("
|
|
8
|
+
const components_1 = require("../../components");
|
|
9
9
|
const GRID_CLASS = 'infographic-align-grid';
|
|
10
10
|
const GRID_COMPACT_CLASS = `${GRID_CLASS}--compact`;
|
|
11
11
|
const GRID_STYLE_ID = 'infographic-align-grid-style';
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FontAlign = void 0;
|
|
4
4
|
const utils_1 = require("../../../../utils");
|
|
5
5
|
const commands_1 = require("../../../commands");
|
|
6
|
-
const components_1 = require("
|
|
6
|
+
const components_1 = require("../../components");
|
|
7
7
|
// 常量定义
|
|
8
8
|
const GRID_CLASS = 'infographic-font-align-grid';
|
|
9
9
|
const GRID_STYLE_ID = 'infographic-font-align-grid-style';
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FontColor = void 0;
|
|
4
4
|
const utils_1 = require("../../../../utils");
|
|
5
5
|
const commands_1 = require("../../../commands");
|
|
6
|
-
const components_1 = require("
|
|
6
|
+
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';
|
|
@@ -4,7 +4,7 @@ exports.FontFamily = void 0;
|
|
|
4
4
|
const renderer_1 = require("../../../../renderer");
|
|
5
5
|
const utils_1 = require("../../../../utils");
|
|
6
6
|
const commands_1 = require("../../../commands");
|
|
7
|
-
const components_1 = require("
|
|
7
|
+
const components_1 = require("../../components");
|
|
8
8
|
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';
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FontSize = void 0;
|
|
4
4
|
const utils_1 = require("../../../../utils");
|
|
5
5
|
const commands_1 = require("../../../commands");
|
|
6
|
-
const components_1 = require("
|
|
6
|
+
const components_1 = require("../../components");
|
|
7
7
|
const FONT_SIZE_CLASS = 'infographic-font-size-grid';
|
|
8
8
|
const FONT_SIZE_STYLE_ID = 'infographic-font-size-grid-style';
|
|
9
9
|
const FONT_SIZE_OPTIONS = [
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IconColor = void 0;
|
|
4
4
|
const utils_1 = require("../../../../utils");
|
|
5
5
|
const commands_1 = require("../../../commands");
|
|
6
|
-
const components_1 = require("
|
|
6
|
+
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';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ColorPicker, Popover, Select } from '
|
|
1
|
+
export { ColorPicker, Popover, Select } from '../components';
|
|
2
2
|
export { EditBar } from './edit-bar';
|
|
3
|
-
export type { ColorPickerHandle, ColorPickerProps, IconButtonHandle, IconButtonProps, IconProps, PopoverHandle, PopoverPlacement, PopoverProps, SelectHandle, SelectOption, SelectProps, SelectValue, } from '
|
|
3
|
+
export type { ColorPickerHandle, ColorPickerProps, IconButtonHandle, IconButtonProps, IconProps, PopoverHandle, PopoverPlacement, PopoverProps, SelectHandle, SelectOption, SelectProps, SelectValue, } from '../components';
|
|
4
4
|
export type { EditBarOptions } from './edit-bar';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EditBar = exports.Select = exports.Popover = exports.ColorPicker = void 0;
|
|
4
|
-
var components_1 = require("
|
|
4
|
+
var components_1 = require("../components");
|
|
5
5
|
Object.defineProperty(exports, "ColorPicker", { enumerable: true, get: function () { return components_1.ColorPicker; } });
|
|
6
6
|
Object.defineProperty(exports, "Popover", { enumerable: true, get: function () { return components_1.Popover; } });
|
|
7
7
|
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return components_1.Select; } });
|
|
@@ -14,9 +14,13 @@ 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.ResizeElement = exports.Plugin = void 0;
|
|
17
|
+
exports.ResizeElement = exports.ResetViewBox = exports.CoreSyncPlugin = exports.Plugin = void 0;
|
|
18
18
|
var base_1 = require("./base");
|
|
19
19
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return base_1.Plugin; } });
|
|
20
|
+
var core_sync_1 = require("./core-sync");
|
|
21
|
+
Object.defineProperty(exports, "CoreSyncPlugin", { enumerable: true, get: function () { return core_sync_1.CoreSyncPlugin; } });
|
|
20
22
|
__exportStar(require("./edit-bar"), exports);
|
|
23
|
+
var reset_viewbox_1 = require("./reset-viewbox");
|
|
24
|
+
Object.defineProperty(exports, "ResetViewBox", { enumerable: true, get: function () { return reset_viewbox_1.ResetViewBox; } });
|
|
21
25
|
var resize_element_1 = require("./resize-element");
|
|
22
26
|
Object.defineProperty(exports, "ResizeElement", { enumerable: true, get: function () { return resize_element_1.ResizeElement; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IPlugin, PluginInitOptions } from '../types';
|
|
2
|
+
import { Plugin } from './base';
|
|
3
|
+
export interface ResetViewBoxOptions {
|
|
4
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
5
|
+
className?: string;
|
|
6
|
+
getContainer?: HTMLElement | (() => HTMLElement);
|
|
7
|
+
}
|
|
8
|
+
export declare class ResetViewBox extends Plugin implements IPlugin {
|
|
9
|
+
private options?;
|
|
10
|
+
name: string;
|
|
11
|
+
private originViewBox;
|
|
12
|
+
private resetButton?;
|
|
13
|
+
private viewBoxChanged;
|
|
14
|
+
private unregisterSync?;
|
|
15
|
+
constructor(options?: ResetViewBoxOptions | undefined);
|
|
16
|
+
init(options: PluginInitOptions): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
private handleResize;
|
|
19
|
+
private updateOriginViewBox;
|
|
20
|
+
private handleViewBoxChange;
|
|
21
|
+
protected getOrCreateResetButton: () => HTMLButtonElement;
|
|
22
|
+
/** Get CSS transform scale of an element */
|
|
23
|
+
private getTransformScale;
|
|
24
|
+
/** Find the nearest stable overflow container */
|
|
25
|
+
private findStableContainer;
|
|
26
|
+
private placeButton;
|
|
27
|
+
private updatePosition;
|
|
28
|
+
private resetViewBox;
|
|
29
|
+
private showButton;
|
|
30
|
+
private hideButton;
|
|
31
|
+
private removeButton;
|
|
32
|
+
private ensureButtonStyle;
|
|
33
|
+
}
|