@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.
Files changed (241) hide show
  1. package/README.md +12 -5
  2. package/README.zh-CN.md +12 -5
  3. package/dist/infographic.min.js +180 -171
  4. package/dist/infographic.min.js.map +1 -1
  5. package/esm/designs/structures/index.d.ts +1 -0
  6. package/esm/designs/structures/index.js +1 -0
  7. package/esm/designs/structures/relation-dagre-flow.js +4 -139
  8. package/esm/designs/structures/sequence-interaction.d.ts +54 -0
  9. package/esm/designs/structures/sequence-interaction.js +440 -0
  10. package/esm/designs/utils/geometry.d.ts +44 -0
  11. package/esm/designs/utils/geometry.js +244 -0
  12. package/esm/designs/utils/index.d.ts +1 -0
  13. package/esm/designs/utils/index.js +1 -0
  14. package/esm/editor/commands/UpdateOptions.d.ts +4 -4
  15. package/esm/editor/commands/UpdateOptions.js +6 -3
  16. package/esm/editor/editor.d.ts +5 -1
  17. package/esm/editor/editor.js +16 -5
  18. package/esm/editor/index.d.ts +1 -0
  19. package/esm/editor/index.js +1 -0
  20. package/esm/editor/interactions/brush-select.d.ts +0 -1
  21. package/esm/editor/interactions/brush-select.js +2 -10
  22. package/esm/editor/interactions/drag-canvas.d.ts +35 -0
  23. package/esm/editor/interactions/drag-canvas.js +161 -0
  24. package/esm/editor/interactions/drag-element.js +4 -3
  25. package/esm/editor/interactions/index.d.ts +1 -0
  26. package/esm/editor/interactions/index.js +1 -0
  27. package/esm/editor/interactions/zoom-wheel.d.ts +9 -0
  28. package/esm/editor/interactions/zoom-wheel.js +32 -15
  29. package/esm/editor/managers/index.d.ts +1 -0
  30. package/esm/editor/managers/index.js +1 -0
  31. package/esm/editor/managers/state.d.ts +4 -2
  32. package/esm/editor/managers/state.js +14 -13
  33. package/esm/editor/managers/sync-registry.d.ts +16 -0
  34. package/esm/editor/managers/sync-registry.js +51 -0
  35. package/esm/editor/plugins/{edit-bar/components → components}/button.js +1 -1
  36. package/esm/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
  37. package/esm/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
  38. package/esm/editor/plugins/{edit-bar/components → components}/icons.js +1 -0
  39. package/esm/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
  40. package/esm/editor/plugins/{edit-bar/components → components}/select.js +1 -1
  41. package/esm/editor/plugins/core-sync.d.ts +8 -0
  42. package/esm/editor/plugins/core-sync.js +30 -0
  43. package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
  44. package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  45. package/esm/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
  46. package/esm/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
  47. package/esm/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
  48. package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
  49. package/esm/editor/plugins/edit-bar/index.d.ts +2 -2
  50. package/esm/editor/plugins/edit-bar/index.js +1 -1
  51. package/esm/editor/plugins/index.d.ts +2 -0
  52. package/esm/editor/plugins/index.js +2 -0
  53. package/esm/editor/plugins/reset-viewbox.d.ts +33 -0
  54. package/esm/editor/plugins/reset-viewbox.js +186 -0
  55. package/esm/editor/types/editor.d.ts +14 -0
  56. package/esm/editor/types/index.d.ts +1 -0
  57. package/esm/editor/types/interaction.d.ts +9 -0
  58. package/esm/editor/types/state.d.ts +4 -2
  59. package/esm/editor/types/sync.d.ts +27 -0
  60. package/esm/editor/types/sync.js +1 -0
  61. package/esm/editor/utils/data.js +3 -1
  62. package/esm/editor/utils/event.d.ts +1 -0
  63. package/esm/editor/utils/event.js +8 -0
  64. package/esm/editor/utils/index.d.ts +1 -0
  65. package/esm/editor/utils/index.js +1 -0
  66. package/esm/editor/utils/object.d.ts +15 -0
  67. package/esm/editor/utils/object.js +77 -0
  68. package/esm/index.d.ts +4 -3
  69. package/esm/index.js +3 -2
  70. package/esm/options/types.d.ts +7 -0
  71. package/esm/runtime/Infographic.js +20 -7
  72. package/esm/runtime/options.js +7 -2
  73. package/esm/syntax/index.js +40 -20
  74. package/esm/syntax/relations.js +26 -2
  75. package/esm/syntax/schema.js +1 -0
  76. package/esm/templates/built-in.js +27 -2
  77. package/esm/templates/sequence-interaction.d.ts +2 -0
  78. package/esm/templates/sequence-interaction.js +76 -0
  79. package/esm/types/data.d.ts +1 -0
  80. package/esm/utils/index.d.ts +1 -0
  81. package/esm/utils/index.js +1 -0
  82. package/esm/utils/measure-text.js +40 -9
  83. package/esm/utils/padding.d.ts +1 -0
  84. package/esm/utils/padding.js +6 -2
  85. package/esm/utils/types.d.ts +16 -0
  86. package/esm/utils/types.js +12 -0
  87. package/esm/version.d.ts +1 -1
  88. package/esm/version.js +1 -1
  89. package/lib/designs/structures/index.d.ts +1 -0
  90. package/lib/designs/structures/index.js +1 -0
  91. package/lib/designs/structures/relation-dagre-flow.js +5 -140
  92. package/lib/designs/structures/sequence-interaction.d.ts +54 -0
  93. package/lib/designs/structures/sequence-interaction.js +444 -0
  94. package/lib/designs/utils/geometry.d.ts +44 -0
  95. package/lib/designs/utils/geometry.js +256 -0
  96. package/lib/designs/utils/index.d.ts +1 -0
  97. package/lib/designs/utils/index.js +1 -0
  98. package/lib/editor/commands/UpdateOptions.d.ts +4 -4
  99. package/lib/editor/commands/UpdateOptions.js +6 -3
  100. package/lib/editor/editor.d.ts +5 -1
  101. package/lib/editor/editor.js +16 -5
  102. package/lib/editor/index.d.ts +1 -0
  103. package/lib/editor/index.js +1 -0
  104. package/lib/editor/interactions/brush-select.d.ts +0 -1
  105. package/lib/editor/interactions/brush-select.js +1 -9
  106. package/lib/editor/interactions/drag-canvas.d.ts +35 -0
  107. package/lib/editor/interactions/drag-canvas.js +165 -0
  108. package/lib/editor/interactions/drag-element.js +4 -3
  109. package/lib/editor/interactions/index.d.ts +1 -0
  110. package/lib/editor/interactions/index.js +3 -1
  111. package/lib/editor/interactions/zoom-wheel.d.ts +9 -0
  112. package/lib/editor/interactions/zoom-wheel.js +32 -15
  113. package/lib/editor/managers/index.d.ts +1 -0
  114. package/lib/editor/managers/index.js +1 -0
  115. package/lib/editor/managers/state.d.ts +4 -2
  116. package/lib/editor/managers/state.js +12 -11
  117. package/lib/editor/managers/sync-registry.d.ts +16 -0
  118. package/lib/editor/managers/sync-registry.js +55 -0
  119. package/lib/editor/plugins/{edit-bar/components → components}/button.js +1 -1
  120. package/lib/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
  121. package/lib/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
  122. package/lib/editor/plugins/{edit-bar/components → components}/icons.js +2 -1
  123. package/lib/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
  124. package/lib/editor/plugins/{edit-bar/components → components}/select.js +1 -1
  125. package/lib/editor/plugins/core-sync.d.ts +8 -0
  126. package/lib/editor/plugins/core-sync.js +34 -0
  127. package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
  128. package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  129. package/lib/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
  130. package/lib/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
  131. package/lib/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
  132. package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
  133. package/lib/editor/plugins/edit-bar/index.d.ts +2 -2
  134. package/lib/editor/plugins/edit-bar/index.js +1 -1
  135. package/lib/editor/plugins/index.d.ts +2 -0
  136. package/lib/editor/plugins/index.js +5 -1
  137. package/lib/editor/plugins/reset-viewbox.d.ts +33 -0
  138. package/lib/editor/plugins/reset-viewbox.js +190 -0
  139. package/lib/editor/types/editor.d.ts +14 -0
  140. package/lib/editor/types/index.d.ts +1 -0
  141. package/lib/editor/types/interaction.d.ts +9 -0
  142. package/lib/editor/types/state.d.ts +4 -2
  143. package/lib/editor/types/sync.d.ts +27 -0
  144. package/lib/editor/types/sync.js +2 -0
  145. package/lib/editor/utils/data.js +3 -1
  146. package/lib/editor/utils/event.d.ts +1 -0
  147. package/lib/editor/utils/event.js +9 -0
  148. package/lib/editor/utils/index.d.ts +1 -0
  149. package/lib/editor/utils/index.js +1 -0
  150. package/lib/editor/utils/object.d.ts +15 -0
  151. package/lib/editor/utils/object.js +80 -0
  152. package/lib/index.d.ts +4 -3
  153. package/lib/index.js +9 -2
  154. package/lib/options/types.d.ts +7 -0
  155. package/lib/runtime/Infographic.js +19 -6
  156. package/lib/runtime/options.js +6 -1
  157. package/lib/syntax/index.js +40 -20
  158. package/lib/syntax/relations.js +26 -2
  159. package/lib/syntax/schema.js +1 -0
  160. package/lib/templates/built-in.js +27 -2
  161. package/lib/templates/sequence-interaction.d.ts +2 -0
  162. package/lib/templates/sequence-interaction.js +79 -0
  163. package/lib/types/data.d.ts +1 -0
  164. package/lib/utils/index.d.ts +1 -0
  165. package/lib/utils/index.js +1 -0
  166. package/lib/utils/measure-text.js +39 -8
  167. package/lib/utils/padding.d.ts +1 -0
  168. package/lib/utils/padding.js +7 -2
  169. package/lib/utils/types.d.ts +16 -0
  170. package/lib/utils/types.js +13 -0
  171. package/lib/version.d.ts +1 -1
  172. package/lib/version.js +1 -1
  173. package/package.json +1 -1
  174. package/src/designs/structures/index.ts +1 -0
  175. package/src/designs/structures/relation-dagre-flow.tsx +14 -178
  176. package/src/designs/structures/sequence-interaction.tsx +885 -0
  177. package/src/designs/utils/geometry.tsx +315 -0
  178. package/src/designs/utils/index.ts +1 -0
  179. package/src/editor/commands/UpdateOptions.ts +11 -6
  180. package/src/editor/editor.ts +26 -5
  181. package/src/editor/index.ts +1 -0
  182. package/src/editor/interactions/brush-select.ts +2 -8
  183. package/src/editor/interactions/drag-canvas.ts +203 -0
  184. package/src/editor/interactions/drag-element.ts +5 -4
  185. package/src/editor/interactions/index.ts +1 -0
  186. package/src/editor/interactions/zoom-wheel.ts +49 -13
  187. package/src/editor/managers/index.ts +1 -0
  188. package/src/editor/managers/state.ts +21 -21
  189. package/src/editor/managers/sync-registry.ts +66 -0
  190. package/src/editor/plugins/{edit-bar/components → components}/button.ts +1 -1
  191. package/src/editor/plugins/{edit-bar/components → components}/color-picker.ts +1 -1
  192. package/src/editor/plugins/{edit-bar/components → components}/icons.ts +4 -0
  193. package/src/editor/plugins/{edit-bar/components → components}/popover.ts +2 -2
  194. package/src/editor/plugins/{edit-bar/components → components}/select.ts +1 -1
  195. package/src/editor/plugins/core-sync.ts +44 -0
  196. package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +2 -2
  197. package/src/editor/plugins/edit-bar/edit-items/font-align.ts +1 -1
  198. package/src/editor/plugins/edit-bar/edit-items/font-color.ts +1 -1
  199. package/src/editor/plugins/edit-bar/edit-items/font-family.ts +1 -1
  200. package/src/editor/plugins/edit-bar/edit-items/font-size.ts +3 -3
  201. package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +1 -1
  202. package/src/editor/plugins/edit-bar/index.ts +2 -2
  203. package/src/editor/plugins/index.ts +2 -0
  204. package/src/editor/plugins/reset-viewbox.ts +258 -0
  205. package/src/editor/types/editor.ts +18 -0
  206. package/src/editor/types/index.ts +1 -0
  207. package/src/editor/types/interaction.ts +31 -0
  208. package/src/editor/types/state.ts +14 -2
  209. package/src/editor/types/sync.ts +33 -0
  210. package/src/editor/utils/data.ts +2 -1
  211. package/src/editor/utils/event.ts +7 -0
  212. package/src/editor/utils/index.ts +1 -0
  213. package/src/editor/utils/object.ts +116 -0
  214. package/src/index.ts +26 -2
  215. package/src/options/types.ts +11 -0
  216. package/src/runtime/Infographic.tsx +27 -17
  217. package/src/runtime/options.ts +8 -1
  218. package/src/syntax/index.ts +51 -18
  219. package/src/syntax/relations.ts +29 -2
  220. package/src/syntax/schema.ts +1 -0
  221. package/src/templates/built-in.ts +30 -0
  222. package/src/templates/sequence-interaction.ts +101 -0
  223. package/src/types/data.ts +1 -0
  224. package/src/utils/index.ts +1 -0
  225. package/src/utils/measure-text.ts +41 -9
  226. package/src/utils/padding.ts +10 -2
  227. package/src/utils/types.ts +61 -0
  228. package/src/version.ts +1 -1
  229. /package/esm/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
  230. /package/esm/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
  231. /package/esm/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
  232. /package/esm/editor/plugins/{edit-bar/components → components}/index.js +0 -0
  233. /package/esm/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
  234. /package/esm/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
  235. /package/lib/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
  236. /package/lib/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
  237. /package/lib/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
  238. /package/lib/editor/plugins/{edit-bar/components → components}/index.js +0 -0
  239. /package/lib/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
  240. /package/lib/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
  241. /package/src/editor/plugins/{edit-bar/components → components}/index.ts +0 -0
@@ -9,12 +9,50 @@ import type { IInteraction, InteractionInitOptions } from '../types';
9
9
  import { clientToViewport } from '../utils';
10
10
  import { Interaction } from './base';
11
11
 
12
- const MIN_VIEWBOX_SIZE = 20;
13
- const MAX_VIEWBOX_SIZE = 2000;
12
+ export interface ZoomWheelOptions {
13
+ minViewBoxSize?: number;
14
+ maxViewBoxSize?: number;
15
+ }
16
+
14
17
  const ZOOM_FACTOR = 1.1;
15
18
 
16
19
  export class ZoomWheel extends Interaction implements IInteraction {
17
20
  name = 'zoom-wheel';
21
+ private minViewBoxSize = 20;
22
+ private maxViewBoxSize = 20000;
23
+
24
+ constructor(options?: ZoomWheelOptions) {
25
+ super();
26
+ if (options?.minViewBoxSize !== undefined) {
27
+ this.minViewBoxSize = options.minViewBoxSize;
28
+ }
29
+ if (options?.maxViewBoxSize !== undefined) {
30
+ this.maxViewBoxSize = options.maxViewBoxSize;
31
+ }
32
+ }
33
+
34
+ private initialViewBox: string | null = null;
35
+
36
+ private handleKeyUp = (event: KeyboardEvent) => {
37
+ const isZoomModifierHeld = event.ctrlKey || event.metaKey || event.shiftKey;
38
+
39
+ if (!isZoomModifierHeld && this.initialViewBox) {
40
+ const currentViewBox = viewBoxToString(
41
+ getViewBox(this.editor.getDocument()),
42
+ );
43
+
44
+ if (currentViewBox !== this.initialViewBox) {
45
+ const command = new UpdateOptionsCommand(
46
+ { viewBox: currentViewBox },
47
+ { viewBox: this.initialViewBox },
48
+ );
49
+ void this.commander.execute(command);
50
+ }
51
+
52
+ this.initialViewBox = null;
53
+ document.removeEventListener('keyup', this.handleKeyUp);
54
+ }
55
+ };
18
56
 
19
57
  private wheelListener = (event: WheelEvent) => {
20
58
  if (!this.shouldZoom(event)) return;
@@ -32,19 +70,16 @@ export class ZoomWheel extends Interaction implements IInteraction {
32
70
  const newHeight = height * factor;
33
71
 
34
72
  if (
35
- !inRange(newWidth, MIN_VIEWBOX_SIZE, MAX_VIEWBOX_SIZE) ||
36
- !inRange(newHeight, MIN_VIEWBOX_SIZE, MAX_VIEWBOX_SIZE)
73
+ !inRange(newWidth, this.minViewBoxSize, this.maxViewBoxSize) ||
74
+ !inRange(newHeight, this.minViewBoxSize, this.maxViewBoxSize)
37
75
  )
38
76
  return;
39
77
 
40
- // TODO: Remove after implementing the reset UI plugin
41
- if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
42
- const command = new UpdateOptionsCommand({
43
- viewBox: undefined,
44
- });
45
- void this.commander.execute(command);
46
- return;
78
+ if (this.initialViewBox === null) {
79
+ this.initialViewBox = viewBoxToString(viewBox);
80
+ document.addEventListener('keyup', this.handleKeyUp);
47
81
  }
82
+
48
83
  const pivot =
49
84
  (event.ctrlKey || event.metaKey) && !event.shiftKey
50
85
  ? this.getMousePoint(svg, event)
@@ -52,10 +87,9 @@ export class ZoomWheel extends Interaction implements IInteraction {
52
87
 
53
88
  const newViewBox = calculateZoomedViewBox(viewBox, factor, pivot);
54
89
 
55
- const command = new UpdateOptionsCommand({
90
+ this.state.updateOptions({
56
91
  viewBox: viewBoxToString(newViewBox),
57
92
  });
58
- void this.commander.execute(command);
59
93
  };
60
94
 
61
95
  private getMousePoint = (svg: SVGSVGElement, event: WheelEvent) => {
@@ -79,6 +113,7 @@ export class ZoomWheel extends Interaction implements IInteraction {
79
113
 
80
114
  const isMouseZoom = event.ctrlKey || event.metaKey;
81
115
  const isCenterZoom = event.shiftKey;
116
+ if (isMouseZoom && isCenterZoom) return false;
82
117
 
83
118
  return isMouseZoom || isCenterZoom;
84
119
  };
@@ -90,5 +125,6 @@ export class ZoomWheel extends Interaction implements IInteraction {
90
125
 
91
126
  destroy() {
92
127
  document.removeEventListener('wheel', this.wheelListener);
128
+ document.removeEventListener('keyup', this.handleKeyUp);
93
129
  }
94
130
  }
@@ -2,3 +2,4 @@ export * from './command';
2
2
  export * from './interaction';
3
3
  export * from './plugin';
4
4
  export * from './state';
5
+ export * from './sync-registry';
@@ -1,13 +1,10 @@
1
1
  import { ElementTypeEnum } from '../../constants';
2
- import type { ParsedInfographicOptions } from '../../options';
2
+ import type {
3
+ ParsedInfographicOptions,
4
+ UpdatableInfographicOptions,
5
+ } from '../../options';
3
6
  import type { Element, IEventEmitter, ItemDatum } from '../../types';
4
- import {
5
- getDatumByIndexes,
6
- getElementRole,
7
- isIconElement,
8
- parsePadding,
9
- setSVGPadding,
10
- } from '../../utils';
7
+ import { getDatumByIndexes, getElementRole, isIconElement } from '../../utils';
11
8
  import type {
12
9
  ElementProps,
13
10
  ICommandManager,
@@ -17,6 +14,7 @@ import type {
17
14
  StateManagerInitOptions,
18
15
  } from '../types';
19
16
  import {
17
+ applyOptionUpdates,
20
18
  buildItemPath,
21
19
  getChildrenDataByIndexes,
22
20
  getIndexesFromElement,
@@ -56,6 +54,7 @@ export class StateManager implements IStateManager {
56
54
 
57
55
  updateItemDatum(indexes: number[], datum: Partial<ItemDatum>): void {
58
56
  const item = getDatumByIndexes(this.options.data, indexes);
57
+ if (item == null || indexes.length === 0) return;
59
58
  Object.assign(item, datum);
60
59
  this.emitter.emit('options:data:item:update', { indexes, datum });
61
60
  this.emitter.emit('options:change', {
@@ -111,19 +110,19 @@ export class StateManager implements IStateManager {
111
110
  this.updateBuiltInElement(element, props);
112
111
  }
113
112
 
114
- updateOptions(options: ParsedInfographicOptions) {
115
- this.options = { ...this.options, ...options };
116
- if (this.options.viewBox) {
117
- this.editor.getDocument().setAttribute('viewBox', this.options.viewBox);
118
- } else {
119
- this.editor.getDocument().removeAttribute('viewBox');
120
- if (this.options.padding !== undefined) {
121
- setSVGPadding(
122
- this.editor.getDocument(),
123
- parsePadding(this.options.padding),
124
- );
125
- }
126
- }
113
+ updateOptions(
114
+ options: UpdatableInfographicOptions,
115
+ execOptions?: { bubbleUp?: boolean },
116
+ ) {
117
+ const { bubbleUp = false } = execOptions || {};
118
+
119
+ applyOptionUpdates(this.options, options, '', {
120
+ bubbleUp,
121
+ collector: (path, newVal, oldVal) => {
122
+ this.editor.syncRegistry.trigger(path, newVal, oldVal);
123
+ },
124
+ });
125
+
127
126
  this.emitter.emit('options:change', {
128
127
  type: 'options:change',
129
128
  changes: [
@@ -156,6 +155,7 @@ export class StateManager implements IStateManager {
156
155
  const indexes = isItemElement ? getIndexesFromElement(element) : undefined;
157
156
  if (isItemElement) {
158
157
  const datum = getDatumByIndexes(data, indexes!);
158
+ if (datum == null) return;
159
159
  const key = role.replace('item-', '');
160
160
  datum.attributes ||= {};
161
161
  datum.attributes[key] ||= {};
@@ -0,0 +1,66 @@
1
+ import { get } from 'lodash-es';
2
+ import type { InfographicOptionPath } from '../../options';
3
+ import { ISyncRegistry, SyncHandler } from '../types';
4
+
5
+ type OptionsGetter = () => any;
6
+
7
+ export class SyncRegistry implements ISyncRegistry {
8
+ private handlers = new Map<string, Set<SyncHandler>>();
9
+ // lock to prevent recursive updates
10
+ private isDispatching = false;
11
+ private isDestroyed = false;
12
+
13
+ constructor(private getOptions: OptionsGetter) {}
14
+
15
+ register(
16
+ path: InfographicOptionPath | (string & {}),
17
+ handler: SyncHandler,
18
+ options?: { immediate?: boolean },
19
+ ): () => void {
20
+ if (!this.handlers.has(path)) {
21
+ this.handlers.set(path, new Set());
22
+ }
23
+ this.handlers.get(path)!.add(handler);
24
+
25
+ if (options?.immediate) {
26
+ const currentVal = get(this.getOptions(), path);
27
+ handler(currentVal, undefined);
28
+ }
29
+
30
+ return () => {
31
+ const set = this.handlers.get(path);
32
+ if (set) {
33
+ set.delete(handler);
34
+ if (set.size === 0) {
35
+ this.handlers.delete(path);
36
+ }
37
+ }
38
+ };
39
+ }
40
+ trigger(path: string, newVal: any, oldVal: any): void {
41
+ if (this.isDestroyed || this.isDispatching) {
42
+ if (this.isDispatching) {
43
+ console.warn(
44
+ `[SyncRegistry] Recursive update detected on ${path}. Skipped to prevent loop.`,
45
+ );
46
+ }
47
+ return;
48
+ }
49
+
50
+ const handlers = this.handlers.get(path);
51
+
52
+ if (handlers) {
53
+ this.isDispatching = true;
54
+ try {
55
+ handlers.forEach((fn) => fn(newVal, oldVal));
56
+ } finally {
57
+ this.isDispatching = false;
58
+ }
59
+ }
60
+ }
61
+
62
+ destroy() {
63
+ this.isDestroyed = true;
64
+ this.handlers.clear();
65
+ }
66
+ }
@@ -1,4 +1,4 @@
1
- import { injectStyleOnce } from '../../../../utils';
1
+ import { injectStyleOnce } from '../../../utils';
2
2
  import type { Icon } from './icons';
3
3
 
4
4
  export type Button = HTMLButtonElement & IconButtonHandle;
@@ -1,6 +1,6 @@
1
1
  import { parse } from 'culori';
2
2
 
3
- import { injectStyleOnce } from '../../../../utils';
3
+ import { injectStyleOnce } from '../../../utils';
4
4
 
5
5
  export type ColorPickerProps = {
6
6
  value?: string;
@@ -54,6 +54,10 @@ export const TEXT_ICONS = {
54
54
  ),
55
55
  };
56
56
 
57
+ export const RESET_ICON = createIcon(
58
+ `<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"/>`,
59
+ );
60
+
57
61
  export const ELEMENT_ICONS = {
58
62
  align: createIcon(
59
63
  `<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>`,
@@ -1,5 +1,5 @@
1
- import { COMPONENT_ROLE } from '../../../../constants';
2
- import { injectStyleOnce, setElementRole } from '../../../../utils';
1
+ import { COMPONENT_ROLE } from '../../../constants';
2
+ import { injectStyleOnce, setElementRole } from '../../../utils';
3
3
 
4
4
  export type PopoverPlacement = 'top' | 'bottom' | 'left' | 'right';
5
5
  export type PopoverPlacementPreference = PopoverPlacement | PopoverPlacement[];
@@ -1,4 +1,4 @@
1
- import { injectStyleOnce } from '../../../../utils';
1
+ import { injectStyleOnce } from '../../../utils';
2
2
 
3
3
  export type SelectValue = string;
4
4
 
@@ -0,0 +1,44 @@
1
+ import { parsePadding, setSVGPadding } from '../../utils';
2
+ import type { IPlugin, PluginInitOptions } from '../types';
3
+ import { Plugin } from './base';
4
+
5
+ export class CoreSyncPlugin extends Plugin implements IPlugin {
6
+ name = 'core-sync';
7
+
8
+ private unregisters: (() => void)[] = [];
9
+
10
+ init(options: PluginInitOptions) {
11
+ super.init(options);
12
+ const svg = this.editor.getDocument();
13
+
14
+ // viewBox Sync
15
+ this.unregisters.push(
16
+ this.editor.registerSync(
17
+ 'viewBox',
18
+ (val) => {
19
+ if (val) {
20
+ svg.setAttribute('viewBox', val);
21
+ } else {
22
+ svg.removeAttribute('viewBox');
23
+ }
24
+ },
25
+ { immediate: true },
26
+ ),
27
+ );
28
+
29
+ // padding Sync
30
+ this.unregisters.push(
31
+ this.editor.registerSync(
32
+ 'padding',
33
+ (val) => {
34
+ if (val !== undefined) setSVGPadding(svg, parsePadding(val));
35
+ },
36
+ { immediate: true },
37
+ ),
38
+ );
39
+ }
40
+
41
+ destroy() {
42
+ this.unregisters.forEach((fn) => fn());
43
+ }
44
+ }
@@ -8,8 +8,8 @@ import {
8
8
  import { UpdateElementCommand } from '../../../commands';
9
9
  import type { ICommandManager, Selection } from '../../../types';
10
10
  import { getElementViewportBounds } from '../../../utils';
11
- import { ELEMENT_ICONS, IconButton, Popover } from '../components';
12
- import type { Icon } from '../components/icons';
11
+ import { ELEMENT_ICONS, IconButton, Popover } from '../../components';
12
+ import type { Icon } from '../../components/icons';
13
13
  import type { EditItem } from './types';
14
14
 
15
15
  const GRID_CLASS = 'infographic-align-grid';
@@ -5,7 +5,7 @@ import type {
5
5
  } from '../../../../types';
6
6
  import { injectStyleOnce } from '../../../../utils';
7
7
  import { UpdateElementCommand } from '../../../commands';
8
- import { Button, IconButton, Popover, TEXT_ICONS } from '../components';
8
+ import { Button, IconButton, Popover, TEXT_ICONS } from '../../components';
9
9
  import type { EditItem } from './types';
10
10
 
11
11
  // 常量定义
@@ -1,7 +1,7 @@
1
1
  import type { TextAttributes } from '../../../../types';
2
2
  import { hasColor, injectStyleOnce } from '../../../../utils';
3
3
  import { UpdateElementCommand } from '../../../commands';
4
- import { ColorPicker, Popover } from '../components';
4
+ import { ColorPicker, Popover } from '../../components';
5
5
  import type { EditItem } from './types';
6
6
 
7
7
  const FONT_COLOR_BUTTON_CLASS = 'infographic-font-color-btn';
@@ -6,7 +6,7 @@ import {
6
6
  injectStyleOnce,
7
7
  } from '../../../../utils';
8
8
  import { UpdateElementCommand } from '../../../commands';
9
- import { IconButton, Popover, TEXT_ICONS } from '../components';
9
+ import { IconButton, Popover, TEXT_ICONS } from '../../components';
10
10
  import type { EditItem } from './types';
11
11
 
12
12
  const FONT_LIST_CLASS = 'infographic-font-family-list';
@@ -1,9 +1,9 @@
1
1
  import type { TextAttributes } from '../../../../types';
2
2
  import { injectStyleOnce } from '../../../../utils';
3
3
  import { UpdateElementCommand } from '../../../commands';
4
- import { IconButton, Popover, TEXT_ICONS } from '../components';
5
- import type { Button } from '../components/button';
6
- import type { Icon } from '../components/icons';
4
+ import { IconButton, Popover, TEXT_ICONS } from '../../components';
5
+ import type { Button } from '../../components/button';
6
+ import type { Icon } from '../../components/icons';
7
7
  import type { EditItem } from './types';
8
8
 
9
9
  const FONT_SIZE_CLASS = 'infographic-font-size-grid';
@@ -1,7 +1,7 @@
1
1
  import type { IconAttributes } from '../../../../types';
2
2
  import { hasColor, injectStyleOnce } from '../../../../utils';
3
3
  import { UpdateElementCommand } from '../../../commands';
4
- import { ColorPicker, Popover } from '../components';
4
+ import { ColorPicker, Popover } from '../../components';
5
5
  import type { EditItem } from './types';
6
6
 
7
7
  const ICON_COLOR_BUTTON_CLASS = 'infographic-icon-color-btn';
@@ -1,4 +1,4 @@
1
- export { ColorPicker, Popover, Select } from './components';
1
+ export { ColorPicker, Popover, Select } from '../components';
2
2
  export { EditBar } from './edit-bar';
3
3
 
4
4
  export type {
@@ -14,5 +14,5 @@ export type {
14
14
  SelectOption,
15
15
  SelectProps,
16
16
  SelectValue,
17
- } from './components';
17
+ } from '../components';
18
18
  export type { EditBarOptions } from './edit-bar';
@@ -1,3 +1,5 @@
1
1
  export { Plugin } from './base';
2
+ export { CoreSyncPlugin } from './core-sync';
2
3
  export * from './edit-bar';
4
+ export { ResetViewBox } from './reset-viewbox';
3
5
  export { ResizeElement } from './resize-element';