@antv/infographic 0.2.11 → 0.2.12

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 (300) hide show
  1. package/dist/infographic.min.js +1 -1
  2. package/dist/infographic.min.js.map +1 -1
  3. package/esm/designs/components/Btn.js +15 -4
  4. package/esm/designs/components/BtnsGroup.js +1 -1
  5. package/esm/designs/components/Illus.js +15 -3
  6. package/esm/designs/components/ItemDesc.js +17 -11
  7. package/esm/designs/components/ItemIcon.js +17 -18
  8. package/esm/designs/components/ItemLabel.js +17 -11
  9. package/esm/designs/components/ItemValue.js +17 -12
  10. package/esm/designs/components/ItemsGroup.js +1 -1
  11. package/esm/designs/components/ShapesGroup.js +1 -1
  12. package/esm/designs/components/Title.js +2 -2
  13. package/esm/designs/decorations/simple-arrow.js +14 -2
  14. package/esm/designs/decorations/triangle.js +14 -2
  15. package/esm/designs/defs/DropShadow.js +13 -2
  16. package/esm/designs/defs/LinearGradient.js +1 -1
  17. package/esm/designs/items/BadgeCard.js +2 -2
  18. package/esm/designs/items/CandyCardLite.js +1 -1
  19. package/esm/designs/items/CapsuleItem.js +3 -3
  20. package/esm/designs/items/CircleNode.js +1 -1
  21. package/esm/designs/items/CircularProgress.js +3 -2
  22. package/esm/designs/items/CompactCard.js +1 -1
  23. package/esm/designs/items/DoneList.js +1 -1
  24. package/esm/designs/items/HorizontalIconArrow.js +2 -2
  25. package/esm/designs/items/HorizontalIconLine.js +2 -2
  26. package/esm/designs/items/IconBadge.js +4 -3
  27. package/esm/designs/items/IndexedCard.js +1 -1
  28. package/esm/designs/items/LCornerCard.js +1 -1
  29. package/esm/designs/items/LetterCard.js +4 -3
  30. package/esm/designs/items/LinedText.js +6 -5
  31. package/esm/designs/items/PillBadge.js +2 -2
  32. package/esm/designs/items/PlainText.js +4 -4
  33. package/esm/designs/items/ProgressCard.js +4 -4
  34. package/esm/designs/items/QuarterCircular.js +1 -1
  35. package/esm/designs/items/QuarterSimpleCard.js +1 -1
  36. package/esm/designs/items/RibbonCard.js +2 -2
  37. package/esm/designs/items/RoundedRectNode.js +2 -2
  38. package/esm/designs/items/SimpleCircleNode.js +1 -1
  39. package/esm/designs/items/SimpleHorizontalArrow.js +2 -2
  40. package/esm/designs/items/SimpleIllusItem.js +1 -1
  41. package/esm/designs/items/SimpleItem.js +3 -3
  42. package/esm/designs/items/SimpleVerticalArrow.js +2 -2
  43. package/esm/designs/items/UnderlineText.js +1 -1
  44. package/esm/designs/items/VerticalIconArrow.js +2 -2
  45. package/esm/designs/layouts/Align.js +22 -15
  46. package/esm/designs/layouts/Flex.js +23 -16
  47. package/esm/designs/structures/chart-bar.js +7 -5
  48. package/esm/designs/structures/chart-column.js +3 -2
  49. package/esm/designs/structures/chart-line.js +7 -5
  50. package/esm/designs/structures/chart-pie.js +4 -3
  51. package/esm/designs/structures/chart-wordcloud.js +5 -14
  52. package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
  53. package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
  54. package/esm/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
  55. package/esm/designs/structures/compare-hierarchy-left-right.js +6 -5
  56. package/esm/designs/structures/compare-hierarchy-row.js +3 -2
  57. package/esm/designs/structures/compare-quadrant.js +2 -3
  58. package/esm/designs/structures/hierarchy-mindmap.js +19 -19
  59. package/esm/designs/structures/hierarchy-structure.js +1 -1
  60. package/esm/designs/structures/hierarchy-tree.js +15 -24
  61. package/esm/designs/structures/list-sector.js +5 -6
  62. package/esm/designs/structures/list-zigzag.js +2 -1
  63. package/esm/designs/structures/relation-dagre-flow.js +30 -35
  64. package/esm/designs/structures/relation-network.js +2 -2
  65. package/esm/designs/structures/sequence-funnel.js +1 -1
  66. package/esm/designs/structures/sequence-mountain.js +4 -4
  67. package/esm/designs/structures/sequence-pyramid.js +1 -1
  68. package/esm/designs/structures/sequence-zigzag-steps.js +2 -1
  69. package/esm/designs/utils/color.js +8 -4
  70. package/esm/designs/utils/item.js +3 -2
  71. package/esm/editor/commands/Batch.js +21 -8
  72. package/esm/editor/commands/UpdateElement.js +25 -22
  73. package/esm/editor/commands/UpdateOptions.js +23 -10
  74. package/esm/editor/commands/UpdateText.js +24 -11
  75. package/esm/editor/interactions/brush-select.js +27 -13
  76. package/esm/editor/interactions/click-select.js +13 -3
  77. package/esm/editor/interactions/dblclick-edit-text.js +36 -20
  78. package/esm/editor/interactions/drag-element.js +23 -9
  79. package/esm/editor/interactions/hotkey-history.js +17 -7
  80. package/esm/editor/interactions/select-highlight.js +5 -9
  81. package/esm/editor/interactions/zoom-wheel.js +2 -1
  82. package/esm/editor/managers/command.js +45 -27
  83. package/esm/editor/managers/interaction.js +46 -33
  84. package/esm/editor/managers/state.js +1 -1
  85. package/esm/editor/plugins/edit-bar/components/color-picker.js +9 -6
  86. package/esm/editor/plugins/edit-bar/components/popover.js +15 -12
  87. package/esm/editor/plugins/edit-bar/components/select.js +10 -8
  88. package/esm/editor/plugins/edit-bar/edit-bar.js +7 -25
  89. package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
  90. package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  91. package/esm/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
  92. package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
  93. package/esm/editor/plugins/resize-element.js +6 -4
  94. package/esm/editor/utils/click-handler.js +6 -3
  95. package/esm/editor/utils/coordinate.js +2 -1
  96. package/esm/editor/utils/element.js +2 -1
  97. package/esm/editor/utils/event.js +2 -1
  98. package/esm/editor/utils/extension.js +1 -1
  99. package/esm/editor/utils/hotkey.js +2 -1
  100. package/esm/exporter/font.js +106 -90
  101. package/esm/exporter/png.js +49 -37
  102. package/esm/exporter/svg.js +55 -38
  103. package/esm/jsx/components/Ellipse.js +5 -4
  104. package/esm/jsx/components/Path.js +2 -4
  105. package/esm/jsx/components/Polygon.js +15 -6
  106. package/esm/jsx/components/Text.js +21 -41
  107. package/esm/jsx/renderer.js +15 -7
  108. package/esm/jsx/utils/bounds.js +18 -16
  109. package/esm/jsx/utils/children.js +2 -1
  110. package/esm/jsx/utils/clone.js +13 -2
  111. package/esm/jsx/utils/element.js +2 -1
  112. package/esm/options/parser.js +45 -46
  113. package/esm/renderer/composites/background.js +3 -2
  114. package/esm/renderer/composites/icon.js +14 -19
  115. package/esm/renderer/composites/illus.js +17 -22
  116. package/esm/renderer/composites/shape.js +4 -2
  117. package/esm/renderer/composites/svg.js +2 -1
  118. package/esm/renderer/composites/text.js +5 -3
  119. package/esm/renderer/fonts/loader.js +4 -3
  120. package/esm/renderer/fonts/registry.js +1 -1
  121. package/esm/renderer/palettes/utils.js +3 -2
  122. package/esm/renderer/renderer.js +7 -5
  123. package/esm/renderer/stylize/gradient.js +3 -2
  124. package/esm/renderer/stylize/pattern.js +15 -8
  125. package/esm/renderer/stylize/rough.js +1 -1
  126. package/esm/resource/load-tracker.js +22 -10
  127. package/esm/resource/loader.js +80 -67
  128. package/esm/resource/loaders/image.js +71 -59
  129. package/esm/resource/loaders/remote.js +26 -15
  130. package/esm/resource/loaders/search.js +38 -25
  131. package/esm/resource/utils/parser.js +2 -1
  132. package/esm/runtime/Infographic.js +26 -13
  133. package/esm/runtime/utils.js +5 -8
  134. package/esm/ssr/renderer.js +42 -35
  135. package/esm/syntax/index.js +19 -6
  136. package/esm/syntax/mapper.js +2 -2
  137. package/esm/templates/built-in.js +96 -200
  138. package/esm/templates/hierarchy-mindmap.js +1 -5
  139. package/esm/templates/hierarchy-tree.js +1 -5
  140. package/esm/templates/relation-dagre-flow.js +4 -28
  141. package/esm/themes/generator.js +8 -14
  142. package/esm/utils/fetch.js +48 -35
  143. package/esm/utils/icon.js +1 -4
  144. package/esm/utils/is-browser.js +2 -2
  145. package/esm/utils/measure-text.js +2 -1
  146. package/esm/utils/padding.js +1 -1
  147. package/esm/utils/recognizer.js +2 -1
  148. package/esm/utils/text.js +14 -3
  149. package/esm/version.d.ts +1 -1
  150. package/esm/version.js +1 -1
  151. package/lib/designs/components/Btn.js +15 -4
  152. package/lib/designs/components/BtnsGroup.js +1 -1
  153. package/lib/designs/components/Illus.js +15 -3
  154. package/lib/designs/components/ItemDesc.js +17 -11
  155. package/lib/designs/components/ItemIcon.js +17 -18
  156. package/lib/designs/components/ItemLabel.js +17 -11
  157. package/lib/designs/components/ItemValue.js +17 -12
  158. package/lib/designs/components/ItemsGroup.js +1 -1
  159. package/lib/designs/components/ShapesGroup.js +1 -1
  160. package/lib/designs/components/Title.js +2 -2
  161. package/lib/designs/decorations/simple-arrow.js +14 -2
  162. package/lib/designs/decorations/triangle.js +14 -2
  163. package/lib/designs/defs/DropShadow.js +13 -2
  164. package/lib/designs/defs/LinearGradient.js +1 -1
  165. package/lib/designs/items/BadgeCard.js +2 -2
  166. package/lib/designs/items/CandyCardLite.js +1 -1
  167. package/lib/designs/items/CapsuleItem.js +3 -3
  168. package/lib/designs/items/CircleNode.js +1 -1
  169. package/lib/designs/items/CircularProgress.js +3 -2
  170. package/lib/designs/items/CompactCard.js +1 -1
  171. package/lib/designs/items/DoneList.js +1 -1
  172. package/lib/designs/items/HorizontalIconArrow.js +2 -2
  173. package/lib/designs/items/HorizontalIconLine.js +2 -2
  174. package/lib/designs/items/IconBadge.js +4 -3
  175. package/lib/designs/items/IndexedCard.js +1 -1
  176. package/lib/designs/items/LCornerCard.js +1 -1
  177. package/lib/designs/items/LetterCard.js +4 -3
  178. package/lib/designs/items/LinedText.js +6 -5
  179. package/lib/designs/items/PillBadge.js +2 -2
  180. package/lib/designs/items/PlainText.js +4 -4
  181. package/lib/designs/items/ProgressCard.js +4 -4
  182. package/lib/designs/items/QuarterCircular.js +1 -1
  183. package/lib/designs/items/QuarterSimpleCard.js +1 -1
  184. package/lib/designs/items/RibbonCard.js +2 -2
  185. package/lib/designs/items/RoundedRectNode.js +2 -2
  186. package/lib/designs/items/SimpleCircleNode.js +1 -1
  187. package/lib/designs/items/SimpleHorizontalArrow.js +2 -2
  188. package/lib/designs/items/SimpleIllusItem.js +1 -1
  189. package/lib/designs/items/SimpleItem.js +3 -3
  190. package/lib/designs/items/SimpleVerticalArrow.js +2 -2
  191. package/lib/designs/items/UnderlineText.js +1 -1
  192. package/lib/designs/items/VerticalIconArrow.js +2 -2
  193. package/lib/designs/layouts/Align.js +22 -15
  194. package/lib/designs/layouts/Flex.js +23 -16
  195. package/lib/designs/structures/chart-bar.js +7 -5
  196. package/lib/designs/structures/chart-column.js +3 -2
  197. package/lib/designs/structures/chart-line.js +7 -5
  198. package/lib/designs/structures/chart-pie.js +4 -3
  199. package/lib/designs/structures/chart-wordcloud.js +5 -14
  200. package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
  201. package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
  202. package/lib/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
  203. package/lib/designs/structures/compare-hierarchy-left-right.js +6 -5
  204. package/lib/designs/structures/compare-hierarchy-row.js +3 -2
  205. package/lib/designs/structures/compare-quadrant.js +2 -3
  206. package/lib/designs/structures/hierarchy-mindmap.js +19 -19
  207. package/lib/designs/structures/hierarchy-structure.js +1 -1
  208. package/lib/designs/structures/hierarchy-tree.js +15 -24
  209. package/lib/designs/structures/list-sector.js +5 -6
  210. package/lib/designs/structures/list-zigzag.js +2 -1
  211. package/lib/designs/structures/relation-dagre-flow.js +30 -35
  212. package/lib/designs/structures/relation-network.js +2 -2
  213. package/lib/designs/structures/sequence-funnel.js +1 -1
  214. package/lib/designs/structures/sequence-mountain.js +4 -4
  215. package/lib/designs/structures/sequence-pyramid.js +1 -1
  216. package/lib/designs/structures/sequence-zigzag-steps.js +2 -1
  217. package/lib/designs/utils/color.js +8 -4
  218. package/lib/designs/utils/item.js +3 -2
  219. package/lib/editor/commands/Batch.js +21 -8
  220. package/lib/editor/commands/UpdateElement.js +25 -22
  221. package/lib/editor/commands/UpdateOptions.js +23 -10
  222. package/lib/editor/commands/UpdateText.js +24 -11
  223. package/lib/editor/interactions/brush-select.js +27 -13
  224. package/lib/editor/interactions/click-select.js +13 -3
  225. package/lib/editor/interactions/dblclick-edit-text.js +36 -20
  226. package/lib/editor/interactions/drag-element.js +23 -9
  227. package/lib/editor/interactions/hotkey-history.js +17 -7
  228. package/lib/editor/interactions/select-highlight.js +5 -9
  229. package/lib/editor/interactions/zoom-wheel.js +2 -1
  230. package/lib/editor/managers/command.js +43 -25
  231. package/lib/editor/managers/interaction.js +46 -33
  232. package/lib/editor/managers/state.js +1 -1
  233. package/lib/editor/plugins/edit-bar/components/color-picker.js +9 -6
  234. package/lib/editor/plugins/edit-bar/components/popover.js +15 -12
  235. package/lib/editor/plugins/edit-bar/components/select.js +10 -8
  236. package/lib/editor/plugins/edit-bar/edit-bar.js +7 -25
  237. package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
  238. package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  239. package/lib/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
  240. package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
  241. package/lib/editor/plugins/resize-element.js +6 -4
  242. package/lib/editor/utils/click-handler.js +6 -3
  243. package/lib/editor/utils/coordinate.js +2 -1
  244. package/lib/editor/utils/element.js +2 -1
  245. package/lib/editor/utils/event.js +2 -1
  246. package/lib/editor/utils/extension.js +1 -1
  247. package/lib/editor/utils/hotkey.js +2 -1
  248. package/lib/exporter/font.js +106 -90
  249. package/lib/exporter/png.js +49 -37
  250. package/lib/exporter/svg.js +55 -38
  251. package/lib/jsx/components/Ellipse.js +5 -4
  252. package/lib/jsx/components/Path.js +2 -4
  253. package/lib/jsx/components/Polygon.js +15 -6
  254. package/lib/jsx/components/Text.js +21 -41
  255. package/lib/jsx/renderer.js +15 -7
  256. package/lib/jsx/utils/bounds.js +18 -16
  257. package/lib/jsx/utils/children.js +2 -1
  258. package/lib/jsx/utils/clone.js +13 -2
  259. package/lib/jsx/utils/element.js +2 -1
  260. package/lib/options/parser.js +45 -46
  261. package/lib/renderer/composites/background.js +3 -2
  262. package/lib/renderer/composites/icon.js +14 -19
  263. package/lib/renderer/composites/illus.js +17 -22
  264. package/lib/renderer/composites/shape.js +4 -2
  265. package/lib/renderer/composites/svg.js +2 -1
  266. package/lib/renderer/composites/text.js +5 -3
  267. package/lib/renderer/fonts/loader.js +4 -3
  268. package/lib/renderer/fonts/registry.js +1 -1
  269. package/lib/renderer/palettes/utils.js +3 -2
  270. package/lib/renderer/renderer.js +7 -5
  271. package/lib/renderer/stylize/gradient.js +3 -2
  272. package/lib/renderer/stylize/pattern.js +15 -8
  273. package/lib/renderer/stylize/rough.js +1 -1
  274. package/lib/resource/load-tracker.js +22 -10
  275. package/lib/resource/loader.js +80 -67
  276. package/lib/resource/loaders/image.js +71 -59
  277. package/lib/resource/loaders/remote.js +26 -15
  278. package/lib/resource/loaders/search.js +38 -25
  279. package/lib/resource/utils/parser.js +2 -1
  280. package/lib/runtime/Infographic.js +26 -13
  281. package/lib/runtime/utils.js +5 -8
  282. package/lib/ssr/renderer.js +42 -35
  283. package/lib/syntax/index.js +19 -6
  284. package/lib/syntax/mapper.js +2 -2
  285. package/lib/templates/built-in.js +96 -200
  286. package/lib/templates/hierarchy-mindmap.js +1 -5
  287. package/lib/templates/hierarchy-tree.js +1 -5
  288. package/lib/templates/relation-dagre-flow.js +4 -28
  289. package/lib/themes/generator.js +8 -14
  290. package/lib/utils/fetch.js +48 -35
  291. package/lib/utils/icon.js +1 -4
  292. package/lib/utils/is-browser.js +2 -2
  293. package/lib/utils/measure-text.js +2 -1
  294. package/lib/utils/padding.js +1 -1
  295. package/lib/utils/recognizer.js +2 -1
  296. package/lib/utils/text.js +14 -3
  297. package/lib/version.d.ts +1 -1
  298. package/lib/version.js +1 -1
  299. package/package.json +1 -1
  300. package/src/version.ts +1 -1
@@ -28,8 +28,9 @@ const ALIGN_OPTIONS = [
28
28
  { icon: ELEMENT_ICONS.distributeV, action: 'V_DISTRIBUTE' },
29
29
  ];
30
30
  export const ElementAlign = (selection, _attrs, commander, options) => {
31
+ var _a;
31
32
  injectStyleOnce(GRID_STYLE_ID, GRID_STYLES);
32
- const enableDistribution = options?.enableDistribution ?? true;
33
+ const enableDistribution = (_a = options === null || options === void 0 ? void 0 : options.enableDistribution) !== null && _a !== void 0 ? _a : true;
33
34
  const content = createAlignContent((action) => alignSelection(selection, action, commander), enableDistribution);
34
35
  return Popover({
35
36
  target: IconButton({ icon: ELEMENT_ICONS.align }),
@@ -284,6 +285,7 @@ function getAttrInfo(element, bounds) {
284
285
  return { x, y, hasX, hasY, hasDataX, hasDataY };
285
286
  }
286
287
  function getTransformInfo(element) {
288
+ var _a;
287
289
  const transform = element.getAttribute('transform');
288
290
  if (transform === null)
289
291
  return null;
@@ -299,7 +301,7 @@ function getTransformInfo(element) {
299
301
  }
300
302
  const x = Number(match[1]) || 0;
301
303
  const y = match[2] !== undefined ? Number(match[2]) || 0 : 0;
302
- const start = match.index ?? 0;
304
+ const start = (_a = match.index) !== null && _a !== void 0 ? _a : 0;
303
305
  const before = transform.slice(0, start).trim();
304
306
  const after = transform.slice(start + match[0].length).trim();
305
307
  const rest = { before, after };
@@ -307,6 +309,6 @@ function getTransformInfo(element) {
307
309
  }
308
310
  function composeTransform(x, y, rest) {
309
311
  const translate = `translate(${x}, ${y})`;
310
- const parts = [rest?.before, translate, rest?.after].filter((part) => part && part.length);
312
+ const parts = [rest === null || rest === void 0 ? void 0 : rest.before, translate, rest === null || rest === void 0 ? void 0 : rest.after].filter((part) => part && part.length);
311
313
  return parts.join(' ');
312
314
  }
@@ -67,7 +67,7 @@ function createAlignContent(state, onAlignChange) {
67
67
  return;
68
68
  Object.assign(state, { [stateKey]: align });
69
69
  updateAllButtons();
70
- onAlignChange({ ...state });
70
+ onAlignChange(Object.assign({}, state));
71
71
  },
72
72
  activate: align === state[stateKey],
73
73
  });
@@ -11,9 +11,9 @@ export const FontColor = (selection, attrs, commander) => {
11
11
  const button = document.createElement('button');
12
12
  button.type = 'button';
13
13
  button.classList.add(FONT_COLOR_BUTTON_CLASS);
14
- setButtonColor(button, color ?? DEFAULT_COLOR, isMixed);
14
+ setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
15
15
  const picker = ColorPicker({
16
- value: color ?? DEFAULT_COLOR,
16
+ value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
17
17
  onChange: (nextColor) => {
18
18
  setButtonColor(button, nextColor, false);
19
19
  commander.executeBatch(selection.map((text) => new UpdateElementCommand(text, {
@@ -11,9 +11,9 @@ export const IconColor = (selection, attrs, commander) => {
11
11
  const button = document.createElement('button');
12
12
  button.type = 'button';
13
13
  button.classList.add(ICON_COLOR_BUTTON_CLASS);
14
- setButtonColor(button, color ?? DEFAULT_COLOR, isMixed);
14
+ setButtonColor(button, color !== null && color !== void 0 ? color : DEFAULT_COLOR, isMixed);
15
15
  const picker = ColorPicker({
16
- value: color ?? DEFAULT_COLOR,
16
+ value: color !== null && color !== void 0 ? color : DEFAULT_COLOR,
17
17
  onChange: (nextColor) => {
18
18
  setButtonColor(button, nextColor, false);
19
19
  commander.executeBatch(selection.map((icon) => new UpdateElementCommand(icon, {
@@ -205,7 +205,8 @@ export class ResizeElement extends Plugin {
205
205
  this.handles.forEach((handle) => (handle.style.display = 'none'));
206
206
  }
207
207
  removeContainer() {
208
- this.container?.remove();
208
+ var _a;
209
+ (_a = this.container) === null || _a === void 0 ? void 0 : _a.remove();
209
210
  this.container = undefined;
210
211
  this.outline = undefined;
211
212
  this.overlay = undefined;
@@ -224,7 +225,7 @@ export class ResizeElement extends Plugin {
224
225
  this.startPointer = point;
225
226
  const currentRect = this.getCurrentAttributes(this.target);
226
227
  this.startRect = currentRect;
227
- this.startAttrs = { ...currentRect };
228
+ this.startAttrs = Object.assign({}, currentRect);
228
229
  this.lastRect = currentRect;
229
230
  this.lastViewportRect = this.getViewportRect(this.target);
230
231
  window.addEventListener('pointermove', this.handlePointerMove);
@@ -256,8 +257,9 @@ export class ResizeElement extends Plugin {
256
257
  return { x, y, width, height };
257
258
  }
258
259
  clientToElement(element, x, y) {
259
- const matrix = element.getScreenCTM()?.inverse() ||
260
- this.editor.getDocument().getScreenCTM()?.inverse() ||
260
+ var _a, _b;
261
+ const matrix = ((_a = element.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse()) ||
262
+ ((_b = this.editor.getDocument().getScreenCTM()) === null || _b === void 0 ? void 0 : _b.inverse()) ||
261
263
  new DOMMatrix();
262
264
  return new DOMPoint(x, y).matrixTransform(matrix);
263
265
  }
@@ -1,5 +1,6 @@
1
1
  export class ClickHandler {
2
2
  constructor(element, options = {}) {
3
+ var _a;
3
4
  this.clickTimer = null;
4
5
  this.singleClickCallback = null;
5
6
  this.doubleClickCallback = null;
@@ -48,7 +49,7 @@ export class ClickHandler {
48
49
  };
49
50
  this.element = element;
50
51
  this.delay = options.delay || 300;
51
- this.dragThreshold = options.dragThreshold ?? 4;
52
+ this.dragThreshold = (_a = options.dragThreshold) !== null && _a !== void 0 ? _a : 4;
52
53
  this.init();
53
54
  }
54
55
  init() {
@@ -64,17 +65,19 @@ export class ClickHandler {
64
65
  if (this.clickTimer)
65
66
  clearTimeout(this.clickTimer);
66
67
  this.clickTimer = window.setTimeout(() => {
67
- this.singleClickCallback?.(e);
68
+ var _a;
69
+ (_a = this.singleClickCallback) === null || _a === void 0 ? void 0 : _a.call(this, e);
68
70
  }, this.delay);
69
71
  }
70
72
  handleDoubleClick(e) {
73
+ var _a;
71
74
  if (this.skipClick) {
72
75
  this.skipClick = false;
73
76
  return;
74
77
  }
75
78
  if (this.clickTimer)
76
79
  clearTimeout(this.clickTimer);
77
- this.doubleClickCallback?.(e);
80
+ (_a = this.doubleClickCallback) === null || _a === void 0 ? void 0 : _a.call(this, e);
78
81
  }
79
82
  onClick(callback) {
80
83
  this.singleClickCallback = callback;
@@ -2,7 +2,8 @@ export function getScreenCTM(svg) {
2
2
  return svg.getScreenCTM() || new DOMMatrix();
3
3
  }
4
4
  export function getInverseScreenCTM(svg) {
5
- return svg.getScreenCTM()?.inverse() || new DOMMatrix();
5
+ var _a;
6
+ return ((_a = svg.getScreenCTM()) === null || _a === void 0 ? void 0 : _a.inverse()) || new DOMMatrix();
6
7
  }
7
8
  export function viewportToClient(svg, x, y) {
8
9
  const svgPoint = new DOMPoint(x, y).matrixTransform(getScreenCTM(svg));
@@ -1,6 +1,7 @@
1
1
  import { getIconEntity, isIconElement } from '../../utils/index.js';
2
2
  export function getIndexesFromElement(element) {
3
- return (getElementEntity(element)?.dataset.indexes?.split(',').map(Number) || []);
3
+ var _a, _b;
4
+ return (((_b = (_a = getElementEntity(element)) === null || _a === void 0 ? void 0 : _a.dataset.indexes) === null || _b === void 0 ? void 0 : _b.split(',').map(Number)) || []);
4
5
  }
5
6
  function getElementEntity(element) {
6
7
  if (isIconElement(element))
@@ -32,6 +32,7 @@ export function getSelectableTarget(element) {
32
32
  return null;
33
33
  }
34
34
  const getRoughEventTarget = (element) => {
35
+ var _a;
35
36
  const is = (ele) => {
36
37
  if (!ele)
37
38
  return false;
@@ -41,7 +42,7 @@ const getRoughEventTarget = (element) => {
41
42
  return element.parentElement;
42
43
  }
43
44
  if (is(element.parentElement)) {
44
- return element.parentElement?.parentElement;
45
+ return (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
45
46
  }
46
47
  return null;
47
48
  };
@@ -3,7 +3,7 @@ export class Extension {
3
3
  this.extensions = new Map();
4
4
  }
5
5
  register(name, extension, options) {
6
- if (!options?.override && this.extensions.has(name)) {
6
+ if (!(options === null || options === void 0 ? void 0 : options.override) && this.extensions.has(name)) {
7
7
  throw new Error(`Extension "${name}" already registered`);
8
8
  }
9
9
  this.extensions.set(name, extension);
@@ -35,10 +35,11 @@ const normalizeCombo = (combo) => {
35
35
  return comboObj;
36
36
  };
37
37
  const matchCombo = (event, combo) => {
38
+ var _a;
38
39
  const key = event.key.toLowerCase();
39
40
  if (key !== combo.key)
40
41
  return false;
41
- const wantsMod = combo.mod ?? false;
42
+ const wantsMod = (_a = combo.mod) !== null && _a !== void 0 ? _a : false;
42
43
  const hasMeta = event.metaKey;
43
44
  const hasCtrl = event.ctrlKey;
44
45
  const hasMod = hasMeta || hasCtrl;
@@ -1,51 +1,62 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import postcss from 'postcss';
2
11
  import { getFontURLs, getWoff2BaseURL } from '../renderer/index.js';
3
12
  import { createElement, decodeFontFamily, fetchWithCache, join, normalizeFontWeightName, splitFontFamily, } from '../utils/index.js';
4
- export async function embedFonts(svg, embedResources = true) {
5
- // 1. 收集使用到的 font-family
6
- const usedFonts = collectUsedFonts(svg);
7
- if (usedFonts.size === 0)
8
- return;
9
- const parsedFontsFaces = [];
10
- // 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
11
- await Promise.all(Array.from(usedFonts).map(async (fontFamily) => {
12
- const loadedFonts = getActualLoadedFontFace(fontFamily);
13
- if (!loadedFonts.length)
14
- return;
15
- const cssFontFaces = await parseFontFamily(fontFamily);
16
- if (!cssFontFaces.length)
13
+ export function embedFonts(svg_1) {
14
+ return __awaiter(this, arguments, void 0, function* (svg, embedResources = true) {
15
+ // 1. 收集使用到的 font-family
16
+ const usedFonts = collectUsedFonts(svg);
17
+ if (usedFonts.size === 0)
17
18
  return;
18
- const processed = await Promise.all(cssFontFaces.map(async (rawFace) => {
19
- const fontFace = normalizeFontFace(rawFace);
20
- const unicodeRange = fontFace['unicode-range'].replace(/\s/g, '');
21
- const subset = loadedFonts.find((font) => font.unicodeRange &&
22
- font.unicodeRange.replace(/\s/g, '') === unicodeRange);
23
- // 如果找不到对应子集,就不处理这个 font-face
24
- if (!subset)
25
- return null;
26
- const baseURL = getWoff2BaseURL(fontFace['font-family'], normalizeFontWeightName(fontFace['font-weight']));
27
- if (!baseURL)
28
- return null;
29
- // 更宽松地从 src 中提取 .woff2 URL 片段
30
- const urlMatch = fontFace.src.match(/url\(["']?(.*?\.woff2)[^"']*["']?\)/);
31
- if (!urlMatch?.[1])
32
- return null;
33
- const woff2URL = join(baseURL, urlMatch[1]);
34
- if (embedResources) {
35
- const woff2DataUrl = await loadWoff2(woff2URL);
36
- fontFace.src = `url(${woff2DataUrl}) format('woff2')`;
37
- }
38
- else {
39
- fontFace.src = `url(${woff2URL}) format('woff2')`;
40
- }
41
- return fontFace;
42
- }));
43
- parsedFontsFaces.push(...(processed.filter(Boolean) || []));
44
- }));
45
- // 3. 创建 <style>@font-face...</style> 并插入 SVG
46
- if (parsedFontsFaces.length > 0) {
47
- insertFontStyle(svg, parsedFontsFaces);
48
- }
19
+ const parsedFontsFaces = [];
20
+ // 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
21
+ yield Promise.all(Array.from(usedFonts).map((fontFamily) => __awaiter(this, void 0, void 0, function* () {
22
+ const loadedFonts = getActualLoadedFontFace(fontFamily);
23
+ if (!loadedFonts.length)
24
+ return;
25
+ const cssFontFaces = yield parseFontFamily(fontFamily);
26
+ if (!cssFontFaces.length)
27
+ return;
28
+ const processed = yield Promise.all(cssFontFaces.map((rawFace) => __awaiter(this, void 0, void 0, function* () {
29
+ const fontFace = normalizeFontFace(rawFace);
30
+ const unicodeRange = fontFace['unicode-range'].replace(/\s/g, '');
31
+ const subset = loadedFonts.find((font) => font.unicodeRange &&
32
+ font.unicodeRange.replace(/\s/g, '') === unicodeRange);
33
+ // 如果找不到对应子集,就不处理这个 font-face
34
+ if (!subset)
35
+ return null;
36
+ const baseURL = getWoff2BaseURL(fontFace['font-family'], normalizeFontWeightName(fontFace['font-weight']));
37
+ if (!baseURL)
38
+ return null;
39
+ // 更宽松地从 src 中提取 .woff2 URL 片段
40
+ const urlMatch = fontFace.src.match(/url\(["']?(.*?\.woff2)[^"']*["']?\)/);
41
+ if (!(urlMatch === null || urlMatch === void 0 ? void 0 : urlMatch[1]))
42
+ return null;
43
+ const woff2URL = join(baseURL, urlMatch[1]);
44
+ if (embedResources) {
45
+ const woff2DataUrl = yield loadWoff2(woff2URL);
46
+ fontFace.src = `url(${woff2DataUrl}) format('woff2')`;
47
+ }
48
+ else {
49
+ fontFace.src = `url(${woff2URL}) format('woff2')`;
50
+ }
51
+ return fontFace;
52
+ })));
53
+ parsedFontsFaces.push(...(processed.filter(Boolean) || []));
54
+ })));
55
+ // 3. 创建 <style>@font-face...</style> 并插入 SVG
56
+ if (parsedFontsFaces.length > 0) {
57
+ insertFontStyle(svg, parsedFontsFaces);
58
+ }
59
+ });
49
60
  }
50
61
  /**
51
62
  * 收集 SVG 中用到的 font-family
@@ -71,33 +82,35 @@ function collectUsedFonts(svg) {
71
82
  /**
72
83
  * 解析给定 font-family 对应的 CSS @font-face
73
84
  */
74
- async function parseFontFamily(fontFamily) {
75
- const urls = getFontURLs(fontFamily);
76
- const fontFaces = [];
77
- await Promise.allSettled(urls.map(async (url) => {
78
- const cssText = await fetchWithCache(url)
79
- .then((res) => res.text())
80
- .catch(() => {
81
- console.error(`Failed to fetch font CSS: ${url}`);
82
- return null;
83
- });
84
- if (!cssText)
85
- return;
86
- try {
87
- const root = postcss.parse(cssText);
88
- root.walkAtRules('font-face', (rule) => {
89
- const fontFace = {};
90
- rule.walkDecls((decl) => {
91
- fontFace[decl.prop] = decl.value;
92
- });
93
- fontFaces.push(fontFace);
85
+ function parseFontFamily(fontFamily) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const urls = getFontURLs(fontFamily);
88
+ const fontFaces = [];
89
+ yield Promise.allSettled(urls.map((url) => __awaiter(this, void 0, void 0, function* () {
90
+ const cssText = yield fetchWithCache(url)
91
+ .then((res) => res.text())
92
+ .catch(() => {
93
+ console.error(`Failed to fetch font CSS: ${url}`);
94
+ return null;
94
95
  });
95
- }
96
- catch (error) {
97
- console.error(`Failed to parse CSS: ${url}`, error);
98
- }
99
- }));
100
- return fontFaces;
96
+ if (!cssText)
97
+ return;
98
+ try {
99
+ const root = postcss.parse(cssText);
100
+ root.walkAtRules('font-face', (rule) => {
101
+ const fontFace = {};
102
+ rule.walkDecls((decl) => {
103
+ fontFace[decl.prop] = decl.value;
104
+ });
105
+ fontFaces.push(fontFace);
106
+ });
107
+ }
108
+ catch (error) {
109
+ console.error(`Failed to parse CSS: ${url}`, error);
110
+ }
111
+ })));
112
+ return fontFaces;
113
+ });
101
114
  }
102
115
  /**
103
116
  * 从 document.fonts 中获取给定 family 且已加载的 FontFace
@@ -117,13 +130,14 @@ export function getActualLoadedFontFace(fontFamily) {
117
130
  * 将不完整的 FontFaceAttributes 补全为完整结构,给后续逻辑使用
118
131
  */
119
132
  function normalizeFontFace(face) {
133
+ var _a, _b, _c, _d, _e, _f;
120
134
  return {
121
- 'font-family': face['font-family'] ?? '',
122
- src: face.src ?? '',
123
- 'font-style': face['font-style'] ?? 'normal',
124
- 'font-display': face['font-display'] ?? 'swap',
125
- 'font-weight': face['font-weight'] ?? '400',
126
- 'unicode-range': face['unicode-range'] ?? 'U+0-FFFF',
135
+ 'font-family': (_a = face['font-family']) !== null && _a !== void 0 ? _a : '',
136
+ src: (_b = face.src) !== null && _b !== void 0 ? _b : '',
137
+ 'font-style': (_c = face['font-style']) !== null && _c !== void 0 ? _c : 'normal',
138
+ 'font-display': (_d = face['font-display']) !== null && _d !== void 0 ? _d : 'swap',
139
+ 'font-weight': (_e = face['font-weight']) !== null && _e !== void 0 ? _e : '400',
140
+ 'unicode-range': (_f = face['unicode-range']) !== null && _f !== void 0 ? _f : 'U+0-FFFF',
127
141
  };
128
142
  }
129
143
  /**
@@ -173,19 +187,21 @@ function insertFontStyle(svg, fontFaces) {
173
187
  /**
174
188
  * 加载 woff2 并转为 DataURL
175
189
  */
176
- async function loadWoff2(url) {
177
- const response = await fetchWithCache(url);
178
- if (!response.ok) {
179
- throw new Error(`Failed to load font: ${url}`);
180
- }
181
- const blob = await response.blob();
182
- const dataUrl = await new Promise((resolve, reject) => {
183
- const reader = new FileReader();
184
- reader.onloadend = () => {
185
- resolve(reader.result);
186
- };
187
- reader.onerror = reject;
188
- reader.readAsDataURL(blob);
190
+ function loadWoff2(url) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ const response = yield fetchWithCache(url);
193
+ if (!response.ok) {
194
+ throw new Error(`Failed to load font: ${url}`);
195
+ }
196
+ const blob = yield response.blob();
197
+ const dataUrl = yield new Promise((resolve, reject) => {
198
+ const reader = new FileReader();
199
+ reader.onloadend = () => {
200
+ resolve(reader.result);
201
+ };
202
+ reader.onerror = reject;
203
+ reader.readAsDataURL(blob);
204
+ });
205
+ return dataUrl;
189
206
  });
190
- return dataUrl;
191
207
  }
@@ -1,42 +1,54 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { getViewBox } from '../utils/index.js';
2
11
  import { exportToSVG } from './svg.js';
3
- export async function exportToPNGString(svg, options = {}) {
4
- const { dpr = globalThis.devicePixelRatio ?? 2 } = options;
5
- const node = await exportToSVG(svg);
6
- const { width, height } = getViewBox(node);
7
- return new Promise((resolve, reject) => {
8
- try {
9
- const canvas = document.createElement('canvas');
10
- canvas.width = width * dpr;
11
- canvas.height = height * dpr;
12
- const ctx = canvas.getContext('2d');
13
- if (!ctx) {
14
- reject(new Error('Failed to get canvas context'));
15
- return;
12
+ export function exportToPNGString(svg_1) {
13
+ return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
14
+ var _a;
15
+ const { dpr = (_a = globalThis.devicePixelRatio) !== null && _a !== void 0 ? _a : 2 } = options;
16
+ const node = yield exportToSVG(svg);
17
+ const { width, height } = getViewBox(node);
18
+ return new Promise((resolve, reject) => {
19
+ try {
20
+ const canvas = document.createElement('canvas');
21
+ canvas.width = width * dpr;
22
+ canvas.height = height * dpr;
23
+ const ctx = canvas.getContext('2d');
24
+ if (!ctx) {
25
+ reject(new Error('Failed to get canvas context'));
26
+ return;
27
+ }
28
+ // 应用 DPR 缩放
29
+ ctx.scale(dpr, dpr);
30
+ ctx.imageSmoothingEnabled = true;
31
+ ctx.imageSmoothingQuality = 'high';
32
+ node.setAttribute('width', String(width));
33
+ node.setAttribute('height', String(height));
34
+ const updatedSvgData = new XMLSerializer().serializeToString(node);
35
+ const svgURL = 'data:image/svg+xml;charset=utf-8,' +
36
+ encodeURIComponent(updatedSvgData);
37
+ const img = new Image();
38
+ img.onload = function () {
39
+ ctx.clearRect(0, 0, width, height);
40
+ ctx.drawImage(img, 0, 0, width, height);
41
+ const pngURL = canvas.toDataURL('image/png');
42
+ resolve(pngURL);
43
+ };
44
+ img.onerror = function (error) {
45
+ reject(new Error('Image load failed: ' + error));
46
+ };
47
+ img.src = svgURL;
48
+ }
49
+ catch (error) {
50
+ reject(error);
16
51
  }
17
- // 应用 DPR 缩放
18
- ctx.scale(dpr, dpr);
19
- ctx.imageSmoothingEnabled = true;
20
- ctx.imageSmoothingQuality = 'high';
21
- node.setAttribute('width', String(width));
22
- node.setAttribute('height', String(height));
23
- const updatedSvgData = new XMLSerializer().serializeToString(node);
24
- const svgURL = 'data:image/svg+xml;charset=utf-8,' +
25
- encodeURIComponent(updatedSvgData);
26
- const img = new Image();
27
- img.onload = function () {
28
- ctx.clearRect(0, 0, width, height);
29
- ctx.drawImage(img, 0, 0, width, height);
30
- const pngURL = canvas.toDataURL('image/png');
31
- resolve(pngURL);
32
- };
33
- img.onerror = function (error) {
34
- reject(new Error('Image load failed: ' + error));
35
- };
36
- img.src = svgURL;
37
- }
38
- catch (error) {
39
- reject(error);
40
- }
52
+ });
41
53
  });
42
54
  }