@antv/infographic 0.2.11 → 0.2.13

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 (328) hide show
  1. package/dist/infographic.min.js +98 -94
  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.d.ts +25 -0
  51. package/esm/designs/structures/chart-pie.js +186 -26
  52. package/esm/designs/structures/chart-wordcloud.js +5 -14
  53. package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
  54. package/esm/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
  55. package/esm/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
  56. package/esm/designs/structures/compare-hierarchy-left-right.js +6 -5
  57. package/esm/designs/structures/compare-hierarchy-row.js +3 -2
  58. package/esm/designs/structures/compare-quadrant.js +2 -3
  59. package/esm/designs/structures/hierarchy-mindmap.js +19 -19
  60. package/esm/designs/structures/hierarchy-structure.js +1 -1
  61. package/esm/designs/structures/hierarchy-tree.js +15 -24
  62. package/esm/designs/structures/list-sector.js +5 -6
  63. package/esm/designs/structures/list-zigzag.js +2 -1
  64. package/esm/designs/structures/relation-dagre-flow.js +30 -35
  65. package/esm/designs/structures/relation-network.js +2 -2
  66. package/esm/designs/structures/sequence-funnel.js +1 -1
  67. package/esm/designs/structures/sequence-mountain.js +4 -4
  68. package/esm/designs/structures/sequence-pyramid.js +1 -1
  69. package/esm/designs/structures/sequence-zigzag-steps.js +2 -1
  70. package/esm/designs/utils/color.js +8 -4
  71. package/esm/designs/utils/index.d.ts +1 -0
  72. package/esm/designs/utils/index.js +1 -0
  73. package/esm/designs/utils/item.js +3 -2
  74. package/esm/designs/utils/normalize-percent.d.ts +19 -0
  75. package/esm/designs/utils/normalize-percent.js +32 -0
  76. package/esm/editor/commands/Batch.js +21 -8
  77. package/esm/editor/commands/UpdateElement.js +25 -22
  78. package/esm/editor/commands/UpdateOptions.js +23 -10
  79. package/esm/editor/commands/UpdateText.js +24 -11
  80. package/esm/editor/interactions/brush-select.js +27 -13
  81. package/esm/editor/interactions/click-select.js +13 -3
  82. package/esm/editor/interactions/dblclick-edit-text.js +36 -20
  83. package/esm/editor/interactions/drag-element.js +23 -9
  84. package/esm/editor/interactions/hotkey-history.js +17 -7
  85. package/esm/editor/interactions/select-highlight.js +5 -9
  86. package/esm/editor/interactions/zoom-wheel.d.ts +3 -0
  87. package/esm/editor/interactions/zoom-wheel.js +46 -22
  88. package/esm/editor/managers/command.js +45 -27
  89. package/esm/editor/managers/interaction.js +46 -33
  90. package/esm/editor/managers/state.js +9 -3
  91. package/esm/editor/plugins/edit-bar/components/color-picker.js +9 -6
  92. package/esm/editor/plugins/edit-bar/components/popover.js +15 -12
  93. package/esm/editor/plugins/edit-bar/components/select.js +10 -8
  94. package/esm/editor/plugins/edit-bar/edit-bar.js +7 -25
  95. package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
  96. package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  97. package/esm/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
  98. package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
  99. package/esm/editor/plugins/resize-element.js +6 -4
  100. package/esm/editor/utils/click-handler.js +6 -3
  101. package/esm/editor/utils/coordinate.js +2 -1
  102. package/esm/editor/utils/element.js +2 -1
  103. package/esm/editor/utils/event.js +2 -1
  104. package/esm/editor/utils/extension.js +1 -1
  105. package/esm/editor/utils/hotkey.js +2 -1
  106. package/esm/exporter/font.js +106 -90
  107. package/esm/exporter/png.js +49 -37
  108. package/esm/exporter/svg.js +55 -38
  109. package/esm/jsx/components/Ellipse.js +5 -4
  110. package/esm/jsx/components/Path.js +2 -4
  111. package/esm/jsx/components/Polygon.js +15 -6
  112. package/esm/jsx/components/Text.js +21 -41
  113. package/esm/jsx/renderer.js +15 -7
  114. package/esm/jsx/utils/bounds.js +18 -16
  115. package/esm/jsx/utils/children.js +2 -1
  116. package/esm/jsx/utils/clone.js +13 -2
  117. package/esm/jsx/utils/element.js +2 -1
  118. package/esm/options/parser.js +45 -46
  119. package/esm/renderer/composites/background.js +3 -2
  120. package/esm/renderer/composites/icon.js +14 -19
  121. package/esm/renderer/composites/illus.js +17 -22
  122. package/esm/renderer/composites/shape.js +4 -2
  123. package/esm/renderer/composites/svg.js +2 -1
  124. package/esm/renderer/composites/text.js +5 -3
  125. package/esm/renderer/fonts/loader.js +4 -3
  126. package/esm/renderer/fonts/registry.js +1 -1
  127. package/esm/renderer/palettes/utils.js +3 -2
  128. package/esm/renderer/renderer.js +7 -5
  129. package/esm/renderer/stylize/gradient.js +3 -2
  130. package/esm/renderer/stylize/pattern.js +15 -8
  131. package/esm/renderer/stylize/rough.js +1 -1
  132. package/esm/resource/load-tracker.js +22 -10
  133. package/esm/resource/loader.js +80 -67
  134. package/esm/resource/loaders/image.js +71 -59
  135. package/esm/resource/loaders/remote.js +26 -15
  136. package/esm/resource/loaders/search.js +38 -25
  137. package/esm/resource/utils/parser.js +2 -1
  138. package/esm/runtime/Infographic.js +26 -13
  139. package/esm/runtime/utils.js +5 -8
  140. package/esm/ssr/renderer.js +42 -35
  141. package/esm/syntax/index.js +19 -6
  142. package/esm/syntax/mapper.js +2 -2
  143. package/esm/templates/built-in.js +91 -269
  144. package/esm/templates/chart-pie.d.ts +2 -0
  145. package/esm/templates/chart-pie.js +87 -0
  146. package/esm/templates/hierarchy-mindmap.js +1 -5
  147. package/esm/templates/hierarchy-tree.js +1 -5
  148. package/esm/templates/relation-dagre-flow.js +4 -28
  149. package/esm/themes/generator.js +8 -14
  150. package/esm/utils/fetch.js +48 -35
  151. package/esm/utils/icon.js +1 -4
  152. package/esm/utils/is-browser.js +2 -2
  153. package/esm/utils/measure-text.js +2 -1
  154. package/esm/utils/padding.js +1 -1
  155. package/esm/utils/recognizer.js +2 -1
  156. package/esm/utils/text.js +14 -3
  157. package/esm/utils/viewbox.d.ts +20 -0
  158. package/esm/utils/viewbox.js +10 -0
  159. package/esm/version.d.ts +1 -1
  160. package/esm/version.js +1 -1
  161. package/lib/designs/components/Btn.js +15 -4
  162. package/lib/designs/components/BtnsGroup.js +1 -1
  163. package/lib/designs/components/Illus.js +15 -3
  164. package/lib/designs/components/ItemDesc.js +17 -11
  165. package/lib/designs/components/ItemIcon.js +17 -18
  166. package/lib/designs/components/ItemLabel.js +17 -11
  167. package/lib/designs/components/ItemValue.js +17 -12
  168. package/lib/designs/components/ItemsGroup.js +1 -1
  169. package/lib/designs/components/ShapesGroup.js +1 -1
  170. package/lib/designs/components/Title.js +2 -2
  171. package/lib/designs/decorations/simple-arrow.js +14 -2
  172. package/lib/designs/decorations/triangle.js +14 -2
  173. package/lib/designs/defs/DropShadow.js +13 -2
  174. package/lib/designs/defs/LinearGradient.js +1 -1
  175. package/lib/designs/items/BadgeCard.js +2 -2
  176. package/lib/designs/items/CandyCardLite.js +1 -1
  177. package/lib/designs/items/CapsuleItem.js +3 -3
  178. package/lib/designs/items/CircleNode.js +1 -1
  179. package/lib/designs/items/CircularProgress.js +3 -2
  180. package/lib/designs/items/CompactCard.js +1 -1
  181. package/lib/designs/items/DoneList.js +1 -1
  182. package/lib/designs/items/HorizontalIconArrow.js +2 -2
  183. package/lib/designs/items/HorizontalIconLine.js +2 -2
  184. package/lib/designs/items/IconBadge.js +4 -3
  185. package/lib/designs/items/IndexedCard.js +1 -1
  186. package/lib/designs/items/LCornerCard.js +1 -1
  187. package/lib/designs/items/LetterCard.js +4 -3
  188. package/lib/designs/items/LinedText.js +6 -5
  189. package/lib/designs/items/PillBadge.js +2 -2
  190. package/lib/designs/items/PlainText.js +4 -4
  191. package/lib/designs/items/ProgressCard.js +4 -4
  192. package/lib/designs/items/QuarterCircular.js +1 -1
  193. package/lib/designs/items/QuarterSimpleCard.js +1 -1
  194. package/lib/designs/items/RibbonCard.js +2 -2
  195. package/lib/designs/items/RoundedRectNode.js +2 -2
  196. package/lib/designs/items/SimpleCircleNode.js +1 -1
  197. package/lib/designs/items/SimpleHorizontalArrow.js +2 -2
  198. package/lib/designs/items/SimpleIllusItem.js +1 -1
  199. package/lib/designs/items/SimpleItem.js +3 -3
  200. package/lib/designs/items/SimpleVerticalArrow.js +2 -2
  201. package/lib/designs/items/UnderlineText.js +1 -1
  202. package/lib/designs/items/VerticalIconArrow.js +2 -2
  203. package/lib/designs/layouts/Align.js +22 -15
  204. package/lib/designs/layouts/Flex.js +23 -16
  205. package/lib/designs/structures/chart-bar.js +7 -5
  206. package/lib/designs/structures/chart-column.js +3 -2
  207. package/lib/designs/structures/chart-line.js +7 -5
  208. package/lib/designs/structures/chart-pie.d.ts +25 -0
  209. package/lib/designs/structures/chart-pie.js +186 -25
  210. package/lib/designs/structures/chart-wordcloud.js +5 -14
  211. package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-arrow.js +1 -1
  212. package/lib/designs/structures/compare-binary-horizontal/dividers/pros-cons-fold.js +1 -1
  213. package/lib/designs/structures/compare-binary-horizontal/dividers/types.js +2 -1
  214. package/lib/designs/structures/compare-hierarchy-left-right.js +6 -5
  215. package/lib/designs/structures/compare-hierarchy-row.js +3 -2
  216. package/lib/designs/structures/compare-quadrant.js +2 -3
  217. package/lib/designs/structures/hierarchy-mindmap.js +19 -19
  218. package/lib/designs/structures/hierarchy-structure.js +1 -1
  219. package/lib/designs/structures/hierarchy-tree.js +15 -24
  220. package/lib/designs/structures/list-sector.js +5 -6
  221. package/lib/designs/structures/list-zigzag.js +2 -1
  222. package/lib/designs/structures/relation-dagre-flow.js +30 -35
  223. package/lib/designs/structures/relation-network.js +2 -2
  224. package/lib/designs/structures/sequence-funnel.js +1 -1
  225. package/lib/designs/structures/sequence-mountain.js +4 -4
  226. package/lib/designs/structures/sequence-pyramid.js +1 -1
  227. package/lib/designs/structures/sequence-zigzag-steps.js +2 -1
  228. package/lib/designs/utils/color.js +8 -4
  229. package/lib/designs/utils/index.d.ts +1 -0
  230. package/lib/designs/utils/index.js +1 -0
  231. package/lib/designs/utils/item.js +3 -2
  232. package/lib/designs/utils/normalize-percent.d.ts +19 -0
  233. package/lib/designs/utils/normalize-percent.js +35 -0
  234. package/lib/editor/commands/Batch.js +21 -8
  235. package/lib/editor/commands/UpdateElement.js +25 -22
  236. package/lib/editor/commands/UpdateOptions.js +23 -10
  237. package/lib/editor/commands/UpdateText.js +24 -11
  238. package/lib/editor/interactions/brush-select.js +27 -13
  239. package/lib/editor/interactions/click-select.js +13 -3
  240. package/lib/editor/interactions/dblclick-edit-text.js +36 -20
  241. package/lib/editor/interactions/drag-element.js +23 -9
  242. package/lib/editor/interactions/hotkey-history.js +17 -7
  243. package/lib/editor/interactions/select-highlight.js +5 -9
  244. package/lib/editor/interactions/zoom-wheel.d.ts +3 -0
  245. package/lib/editor/interactions/zoom-wheel.js +45 -21
  246. package/lib/editor/managers/command.js +43 -25
  247. package/lib/editor/managers/interaction.js +46 -33
  248. package/lib/editor/managers/state.js +9 -3
  249. package/lib/editor/plugins/edit-bar/components/color-picker.js +9 -6
  250. package/lib/editor/plugins/edit-bar/components/popover.js +15 -12
  251. package/lib/editor/plugins/edit-bar/components/select.js +10 -8
  252. package/lib/editor/plugins/edit-bar/edit-bar.js +7 -25
  253. package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +5 -3
  254. package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
  255. package/lib/editor/plugins/edit-bar/edit-items/font-color.js +2 -2
  256. package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +2 -2
  257. package/lib/editor/plugins/resize-element.js +6 -4
  258. package/lib/editor/utils/click-handler.js +6 -3
  259. package/lib/editor/utils/coordinate.js +2 -1
  260. package/lib/editor/utils/element.js +2 -1
  261. package/lib/editor/utils/event.js +2 -1
  262. package/lib/editor/utils/extension.js +1 -1
  263. package/lib/editor/utils/hotkey.js +2 -1
  264. package/lib/exporter/font.js +106 -90
  265. package/lib/exporter/png.js +49 -37
  266. package/lib/exporter/svg.js +55 -38
  267. package/lib/jsx/components/Ellipse.js +5 -4
  268. package/lib/jsx/components/Path.js +2 -4
  269. package/lib/jsx/components/Polygon.js +15 -6
  270. package/lib/jsx/components/Text.js +21 -41
  271. package/lib/jsx/renderer.js +15 -7
  272. package/lib/jsx/utils/bounds.js +18 -16
  273. package/lib/jsx/utils/children.js +2 -1
  274. package/lib/jsx/utils/clone.js +13 -2
  275. package/lib/jsx/utils/element.js +2 -1
  276. package/lib/options/parser.js +45 -46
  277. package/lib/renderer/composites/background.js +3 -2
  278. package/lib/renderer/composites/icon.js +14 -19
  279. package/lib/renderer/composites/illus.js +17 -22
  280. package/lib/renderer/composites/shape.js +4 -2
  281. package/lib/renderer/composites/svg.js +2 -1
  282. package/lib/renderer/composites/text.js +5 -3
  283. package/lib/renderer/fonts/loader.js +4 -3
  284. package/lib/renderer/fonts/registry.js +1 -1
  285. package/lib/renderer/palettes/utils.js +3 -2
  286. package/lib/renderer/renderer.js +7 -5
  287. package/lib/renderer/stylize/gradient.js +3 -2
  288. package/lib/renderer/stylize/pattern.js +15 -8
  289. package/lib/renderer/stylize/rough.js +1 -1
  290. package/lib/resource/load-tracker.js +22 -10
  291. package/lib/resource/loader.js +80 -67
  292. package/lib/resource/loaders/image.js +71 -59
  293. package/lib/resource/loaders/remote.js +26 -15
  294. package/lib/resource/loaders/search.js +38 -25
  295. package/lib/resource/utils/parser.js +2 -1
  296. package/lib/runtime/Infographic.js +26 -13
  297. package/lib/runtime/utils.js +5 -8
  298. package/lib/ssr/renderer.js +42 -35
  299. package/lib/syntax/index.js +19 -6
  300. package/lib/syntax/mapper.js +2 -2
  301. package/lib/templates/built-in.js +91 -269
  302. package/lib/templates/chart-pie.d.ts +2 -0
  303. package/lib/templates/chart-pie.js +90 -0
  304. package/lib/templates/hierarchy-mindmap.js +1 -5
  305. package/lib/templates/hierarchy-tree.js +1 -5
  306. package/lib/templates/relation-dagre-flow.js +4 -28
  307. package/lib/themes/generator.js +8 -14
  308. package/lib/utils/fetch.js +48 -35
  309. package/lib/utils/icon.js +1 -4
  310. package/lib/utils/is-browser.js +2 -2
  311. package/lib/utils/measure-text.js +2 -1
  312. package/lib/utils/padding.js +1 -1
  313. package/lib/utils/recognizer.js +2 -1
  314. package/lib/utils/text.js +14 -3
  315. package/lib/utils/viewbox.d.ts +20 -0
  316. package/lib/utils/viewbox.js +12 -0
  317. package/lib/version.d.ts +1 -1
  318. package/lib/version.js +1 -1
  319. package/package.json +1 -2
  320. package/src/designs/structures/chart-pie.tsx +259 -26
  321. package/src/designs/utils/index.ts +1 -0
  322. package/src/designs/utils/normalize-percent.ts +33 -0
  323. package/src/editor/interactions/zoom-wheel.ts +64 -22
  324. package/src/editor/managers/state.ts +10 -5
  325. package/src/templates/built-in.ts +2 -81
  326. package/src/templates/chart-pie.ts +89 -0
  327. package/src/utils/viewbox.ts +23 -0
  328. package/src/version.ts +1 -1
@@ -36,6 +36,7 @@ function getSelectableTarget(element) {
36
36
  return null;
37
37
  }
38
38
  const getRoughEventTarget = (element) => {
39
+ var _a;
39
40
  const is = (ele) => {
40
41
  if (!ele)
41
42
  return false;
@@ -45,7 +46,7 @@ const getRoughEventTarget = (element) => {
45
46
  return element.parentElement;
46
47
  }
47
48
  if (is(element.parentElement)) {
48
- return element.parentElement?.parentElement;
49
+ return (_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement;
49
50
  }
50
51
  return null;
51
52
  };
@@ -6,7 +6,7 @@ class Extension {
6
6
  this.extensions = new Map();
7
7
  }
8
8
  register(name, extension, options) {
9
- if (!options?.override && this.extensions.has(name)) {
9
+ if (!(options === null || options === void 0 ? void 0 : options.override) && this.extensions.has(name)) {
10
10
  throw new Error(`Extension "${name}" already registered`);
11
11
  }
12
12
  this.extensions.set(name, extension);
@@ -38,10 +38,11 @@ const normalizeCombo = (combo) => {
38
38
  return comboObj;
39
39
  };
40
40
  const matchCombo = (event, combo) => {
41
+ var _a;
41
42
  const key = event.key.toLowerCase();
42
43
  if (key !== combo.key)
43
44
  return false;
44
- const wantsMod = combo.mod ?? false;
45
+ const wantsMod = (_a = combo.mod) !== null && _a !== void 0 ? _a : false;
45
46
  const hasMeta = event.metaKey;
46
47
  const hasCtrl = event.ctrlKey;
47
48
  const hasMod = hasMeta || hasCtrl;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -8,51 +17,53 @@ exports.getActualLoadedFontFace = getActualLoadedFontFace;
8
17
  const postcss_1 = __importDefault(require("postcss"));
9
18
  const renderer_1 = require("../renderer");
10
19
  const utils_1 = require("../utils");
11
- async function embedFonts(svg, embedResources = true) {
12
- // 1. 收集使用到的 font-family
13
- const usedFonts = collectUsedFonts(svg);
14
- if (usedFonts.size === 0)
15
- return;
16
- const parsedFontsFaces = [];
17
- // 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
18
- await Promise.all(Array.from(usedFonts).map(async (fontFamily) => {
19
- const loadedFonts = getActualLoadedFontFace(fontFamily);
20
- if (!loadedFonts.length)
21
- return;
22
- const cssFontFaces = await parseFontFamily(fontFamily);
23
- if (!cssFontFaces.length)
20
+ function embedFonts(svg_1) {
21
+ return __awaiter(this, arguments, void 0, function* (svg, embedResources = true) {
22
+ // 1. 收集使用到的 font-family
23
+ const usedFonts = collectUsedFonts(svg);
24
+ if (usedFonts.size === 0)
24
25
  return;
25
- const processed = await Promise.all(cssFontFaces.map(async (rawFace) => {
26
- const fontFace = normalizeFontFace(rawFace);
27
- const unicodeRange = fontFace['unicode-range'].replace(/\s/g, '');
28
- const subset = loadedFonts.find((font) => font.unicodeRange &&
29
- font.unicodeRange.replace(/\s/g, '') === unicodeRange);
30
- // 如果找不到对应子集,就不处理这个 font-face
31
- if (!subset)
32
- return null;
33
- const baseURL = (0, renderer_1.getWoff2BaseURL)(fontFace['font-family'], (0, utils_1.normalizeFontWeightName)(fontFace['font-weight']));
34
- if (!baseURL)
35
- return null;
36
- // 更宽松地从 src 中提取 .woff2 URL 片段
37
- const urlMatch = fontFace.src.match(/url\(["']?(.*?\.woff2)[^"']*["']?\)/);
38
- if (!urlMatch?.[1])
39
- return null;
40
- const woff2URL = (0, utils_1.join)(baseURL, urlMatch[1]);
41
- if (embedResources) {
42
- const woff2DataUrl = await loadWoff2(woff2URL);
43
- fontFace.src = `url(${woff2DataUrl}) format('woff2')`;
44
- }
45
- else {
46
- fontFace.src = `url(${woff2URL}) format('woff2')`;
47
- }
48
- return fontFace;
49
- }));
50
- parsedFontsFaces.push(...(processed.filter(Boolean) || []));
51
- }));
52
- // 3. 创建 <style>@font-face...</style> 并插入 SVG
53
- if (parsedFontsFaces.length > 0) {
54
- insertFontStyle(svg, parsedFontsFaces);
55
- }
26
+ const parsedFontsFaces = [];
27
+ // 2. 对每个使用到的字体,解析 CSS + 结合 document.fonts 的实际加载子集
28
+ yield Promise.all(Array.from(usedFonts).map((fontFamily) => __awaiter(this, void 0, void 0, function* () {
29
+ const loadedFonts = getActualLoadedFontFace(fontFamily);
30
+ if (!loadedFonts.length)
31
+ return;
32
+ const cssFontFaces = yield parseFontFamily(fontFamily);
33
+ if (!cssFontFaces.length)
34
+ return;
35
+ const processed = yield Promise.all(cssFontFaces.map((rawFace) => __awaiter(this, void 0, void 0, function* () {
36
+ const fontFace = normalizeFontFace(rawFace);
37
+ const unicodeRange = fontFace['unicode-range'].replace(/\s/g, '');
38
+ const subset = loadedFonts.find((font) => font.unicodeRange &&
39
+ font.unicodeRange.replace(/\s/g, '') === unicodeRange);
40
+ // 如果找不到对应子集,就不处理这个 font-face
41
+ if (!subset)
42
+ return null;
43
+ const baseURL = (0, renderer_1.getWoff2BaseURL)(fontFace['font-family'], (0, utils_1.normalizeFontWeightName)(fontFace['font-weight']));
44
+ if (!baseURL)
45
+ return null;
46
+ // 更宽松地从 src 中提取 .woff2 URL 片段
47
+ const urlMatch = fontFace.src.match(/url\(["']?(.*?\.woff2)[^"']*["']?\)/);
48
+ if (!(urlMatch === null || urlMatch === void 0 ? void 0 : urlMatch[1]))
49
+ return null;
50
+ const woff2URL = (0, utils_1.join)(baseURL, urlMatch[1]);
51
+ if (embedResources) {
52
+ const woff2DataUrl = yield loadWoff2(woff2URL);
53
+ fontFace.src = `url(${woff2DataUrl}) format('woff2')`;
54
+ }
55
+ else {
56
+ fontFace.src = `url(${woff2URL}) format('woff2')`;
57
+ }
58
+ return fontFace;
59
+ })));
60
+ parsedFontsFaces.push(...(processed.filter(Boolean) || []));
61
+ })));
62
+ // 3. 创建 <style>@font-face...</style> 并插入 SVG
63
+ if (parsedFontsFaces.length > 0) {
64
+ insertFontStyle(svg, parsedFontsFaces);
65
+ }
66
+ });
56
67
  }
57
68
  /**
58
69
  * 收集 SVG 中用到的 font-family
@@ -78,33 +89,35 @@ function collectUsedFonts(svg) {
78
89
  /**
79
90
  * 解析给定 font-family 对应的 CSS @font-face
80
91
  */
81
- async function parseFontFamily(fontFamily) {
82
- const urls = (0, renderer_1.getFontURLs)(fontFamily);
83
- const fontFaces = [];
84
- await Promise.allSettled(urls.map(async (url) => {
85
- const cssText = await (0, utils_1.fetchWithCache)(url)
86
- .then((res) => res.text())
87
- .catch(() => {
88
- console.error(`Failed to fetch font CSS: ${url}`);
89
- return null;
90
- });
91
- if (!cssText)
92
- return;
93
- try {
94
- const root = postcss_1.default.parse(cssText);
95
- root.walkAtRules('font-face', (rule) => {
96
- const fontFace = {};
97
- rule.walkDecls((decl) => {
98
- fontFace[decl.prop] = decl.value;
99
- });
100
- fontFaces.push(fontFace);
92
+ function parseFontFamily(fontFamily) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const urls = (0, renderer_1.getFontURLs)(fontFamily);
95
+ const fontFaces = [];
96
+ yield Promise.allSettled(urls.map((url) => __awaiter(this, void 0, void 0, function* () {
97
+ const cssText = yield (0, utils_1.fetchWithCache)(url)
98
+ .then((res) => res.text())
99
+ .catch(() => {
100
+ console.error(`Failed to fetch font CSS: ${url}`);
101
+ return null;
101
102
  });
102
- }
103
- catch (error) {
104
- console.error(`Failed to parse CSS: ${url}`, error);
105
- }
106
- }));
107
- return fontFaces;
103
+ if (!cssText)
104
+ return;
105
+ try {
106
+ const root = postcss_1.default.parse(cssText);
107
+ root.walkAtRules('font-face', (rule) => {
108
+ const fontFace = {};
109
+ rule.walkDecls((decl) => {
110
+ fontFace[decl.prop] = decl.value;
111
+ });
112
+ fontFaces.push(fontFace);
113
+ });
114
+ }
115
+ catch (error) {
116
+ console.error(`Failed to parse CSS: ${url}`, error);
117
+ }
118
+ })));
119
+ return fontFaces;
120
+ });
108
121
  }
109
122
  /**
110
123
  * 从 document.fonts 中获取给定 family 且已加载的 FontFace
@@ -124,13 +137,14 @@ function getActualLoadedFontFace(fontFamily) {
124
137
  * 将不完整的 FontFaceAttributes 补全为完整结构,给后续逻辑使用
125
138
  */
126
139
  function normalizeFontFace(face) {
140
+ var _a, _b, _c, _d, _e, _f;
127
141
  return {
128
- 'font-family': face['font-family'] ?? '',
129
- src: face.src ?? '',
130
- 'font-style': face['font-style'] ?? 'normal',
131
- 'font-display': face['font-display'] ?? 'swap',
132
- 'font-weight': face['font-weight'] ?? '400',
133
- 'unicode-range': face['unicode-range'] ?? 'U+0-FFFF',
142
+ 'font-family': (_a = face['font-family']) !== null && _a !== void 0 ? _a : '',
143
+ src: (_b = face.src) !== null && _b !== void 0 ? _b : '',
144
+ 'font-style': (_c = face['font-style']) !== null && _c !== void 0 ? _c : 'normal',
145
+ 'font-display': (_d = face['font-display']) !== null && _d !== void 0 ? _d : 'swap',
146
+ 'font-weight': (_e = face['font-weight']) !== null && _e !== void 0 ? _e : '400',
147
+ 'unicode-range': (_f = face['unicode-range']) !== null && _f !== void 0 ? _f : 'U+0-FFFF',
134
148
  };
135
149
  }
136
150
  /**
@@ -180,19 +194,21 @@ function insertFontStyle(svg, fontFaces) {
180
194
  /**
181
195
  * 加载 woff2 并转为 DataURL
182
196
  */
183
- async function loadWoff2(url) {
184
- const response = await (0, utils_1.fetchWithCache)(url);
185
- if (!response.ok) {
186
- throw new Error(`Failed to load font: ${url}`);
187
- }
188
- const blob = await response.blob();
189
- const dataUrl = await new Promise((resolve, reject) => {
190
- const reader = new FileReader();
191
- reader.onloadend = () => {
192
- resolve(reader.result);
193
- };
194
- reader.onerror = reject;
195
- reader.readAsDataURL(blob);
197
+ function loadWoff2(url) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ const response = yield (0, utils_1.fetchWithCache)(url);
200
+ if (!response.ok) {
201
+ throw new Error(`Failed to load font: ${url}`);
202
+ }
203
+ const blob = yield response.blob();
204
+ const dataUrl = yield new Promise((resolve, reject) => {
205
+ const reader = new FileReader();
206
+ reader.onloadend = () => {
207
+ resolve(reader.result);
208
+ };
209
+ reader.onerror = reject;
210
+ reader.readAsDataURL(blob);
211
+ });
212
+ return dataUrl;
196
213
  });
197
- return dataUrl;
198
214
  }
@@ -1,45 +1,57 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.exportToPNGString = exportToPNGString;
4
13
  const utils_1 = require("../utils");
5
14
  const svg_1 = require("./svg");
6
- async function exportToPNGString(svg, options = {}) {
7
- const { dpr = globalThis.devicePixelRatio ?? 2 } = options;
8
- const node = await (0, svg_1.exportToSVG)(svg);
9
- const { width, height } = (0, utils_1.getViewBox)(node);
10
- return new Promise((resolve, reject) => {
11
- try {
12
- const canvas = document.createElement('canvas');
13
- canvas.width = width * dpr;
14
- canvas.height = height * dpr;
15
- const ctx = canvas.getContext('2d');
16
- if (!ctx) {
17
- reject(new Error('Failed to get canvas context'));
18
- return;
15
+ function exportToPNGString(svg_2) {
16
+ return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
17
+ var _a;
18
+ const { dpr = (_a = globalThis.devicePixelRatio) !== null && _a !== void 0 ? _a : 2 } = options;
19
+ const node = yield (0, svg_1.exportToSVG)(svg);
20
+ const { width, height } = (0, utils_1.getViewBox)(node);
21
+ return new Promise((resolve, reject) => {
22
+ try {
23
+ const canvas = document.createElement('canvas');
24
+ canvas.width = width * dpr;
25
+ canvas.height = height * dpr;
26
+ const ctx = canvas.getContext('2d');
27
+ if (!ctx) {
28
+ reject(new Error('Failed to get canvas context'));
29
+ return;
30
+ }
31
+ // 应用 DPR 缩放
32
+ ctx.scale(dpr, dpr);
33
+ ctx.imageSmoothingEnabled = true;
34
+ ctx.imageSmoothingQuality = 'high';
35
+ node.setAttribute('width', String(width));
36
+ node.setAttribute('height', String(height));
37
+ const updatedSvgData = new XMLSerializer().serializeToString(node);
38
+ const svgURL = 'data:image/svg+xml;charset=utf-8,' +
39
+ encodeURIComponent(updatedSvgData);
40
+ const img = new Image();
41
+ img.onload = function () {
42
+ ctx.clearRect(0, 0, width, height);
43
+ ctx.drawImage(img, 0, 0, width, height);
44
+ const pngURL = canvas.toDataURL('image/png');
45
+ resolve(pngURL);
46
+ };
47
+ img.onerror = function (error) {
48
+ reject(new Error('Image load failed: ' + error));
49
+ };
50
+ img.src = svgURL;
51
+ }
52
+ catch (error) {
53
+ reject(error);
19
54
  }
20
- // 应用 DPR 缩放
21
- ctx.scale(dpr, dpr);
22
- ctx.imageSmoothingEnabled = true;
23
- ctx.imageSmoothingQuality = 'high';
24
- node.setAttribute('width', String(width));
25
- node.setAttribute('height', String(height));
26
- const updatedSvgData = new XMLSerializer().serializeToString(node);
27
- const svgURL = 'data:image/svg+xml;charset=utf-8,' +
28
- encodeURIComponent(updatedSvgData);
29
- const img = new Image();
30
- img.onload = function () {
31
- ctx.clearRect(0, 0, width, height);
32
- ctx.drawImage(img, 0, 0, width, height);
33
- const pngURL = canvas.toDataURL('image/png');
34
- resolve(pngURL);
35
- };
36
- img.onerror = function (error) {
37
- reject(new Error('Image load failed: ' + error));
38
- };
39
- img.src = svgURL;
40
- }
41
- catch (error) {
42
- reject(error);
43
- }
55
+ });
44
56
  });
45
57
  }
@@ -1,43 +1,58 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.exportToSVGString = exportToSVGString;
4
13
  exports.exportToSVG = exportToSVG;
5
14
  const utils_1 = require("../utils");
6
15
  const font_1 = require("./font");
7
- async function exportToSVGString(svg, options = {}) {
8
- const node = await exportToSVG(svg, options);
9
- const str = new XMLSerializer().serializeToString(node);
10
- return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(str);
11
- }
12
- async function exportToSVG(svg, options = {}) {
13
- const { embedResources = true, removeIds = false } = options;
14
- const clonedSVG = svg.cloneNode(true);
15
- const { width, height } = (0, utils_1.getViewBox)(svg);
16
- (0, utils_1.setAttributes)(clonedSVG, { width, height });
17
- if (removeIds) {
18
- inlineUseElements(clonedSVG);
19
- inlineDefsReferences(clonedSVG);
20
- }
21
- else {
22
- await embedIcons(clonedSVG);
23
- }
24
- await (0, font_1.embedFonts)(clonedSVG, embedResources);
25
- cleanSVG(clonedSVG);
26
- return clonedSVG;
16
+ function exportToSVGString(svg_1) {
17
+ return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
18
+ const node = yield exportToSVG(svg, options);
19
+ const str = new XMLSerializer().serializeToString(node);
20
+ return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(str);
21
+ });
27
22
  }
28
- async function embedIcons(svg) {
29
- const icons = svg.querySelectorAll('use');
30
- const defs = getDefs(svg);
31
- icons.forEach((icon) => {
32
- const href = icon.getAttribute('href');
33
- if (!href)
34
- return;
35
- const existsSymbol = svg.querySelector(href);
36
- if (!existsSymbol) {
37
- const symbolElement = document.querySelector(href);
38
- if (symbolElement)
39
- defs.appendChild(symbolElement.cloneNode(true));
23
+ function exportToSVG(svg_1) {
24
+ return __awaiter(this, arguments, void 0, function* (svg, options = {}) {
25
+ const { embedResources = true, removeIds = false } = options;
26
+ const clonedSVG = svg.cloneNode(true);
27
+ const { width, height } = (0, utils_1.getViewBox)(svg);
28
+ (0, utils_1.setAttributes)(clonedSVG, { width, height });
29
+ if (removeIds) {
30
+ inlineUseElements(clonedSVG);
31
+ inlineDefsReferences(clonedSVG);
40
32
  }
33
+ else {
34
+ yield embedIcons(clonedSVG);
35
+ }
36
+ yield (0, font_1.embedFonts)(clonedSVG, embedResources);
37
+ cleanSVG(clonedSVG);
38
+ return clonedSVG;
39
+ });
40
+ }
41
+ function embedIcons(svg) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const icons = svg.querySelectorAll('use');
44
+ const defs = getDefs(svg);
45
+ icons.forEach((icon) => {
46
+ const href = icon.getAttribute('href');
47
+ if (!href)
48
+ return;
49
+ const existsSymbol = svg.querySelector(href);
50
+ if (!existsSymbol) {
51
+ const symbolElement = document.querySelector(href);
52
+ if (symbolElement)
53
+ defs.appendChild(symbolElement.cloneNode(true));
54
+ }
55
+ });
41
56
  });
42
57
  }
43
58
  const iconRole = 'icon-defs';
@@ -68,7 +83,8 @@ function inlineUseElements(svg) {
68
83
  });
69
84
  }
70
85
  function getUseHref(use) {
71
- return use.getAttribute('href') ?? use.getAttribute('xlink:href');
86
+ var _a;
87
+ return (_a = use.getAttribute('href')) !== null && _a !== void 0 ? _a : use.getAttribute('xlink:href');
72
88
  }
73
89
  function resolveUseTarget(svg, href) {
74
90
  const localTarget = svg.querySelector(href);
@@ -116,10 +132,11 @@ function materializeElement(use, source) {
116
132
  return wrapper;
117
133
  }
118
134
  function buildUseTransform(use) {
135
+ var _a;
119
136
  const x = use.getAttribute('x');
120
137
  const y = use.getAttribute('y');
121
- const translate = x || y ? `translate(${x ?? 0} ${y ?? 0})` : '';
122
- const transform = use.getAttribute('transform') ?? '';
138
+ const translate = x || y ? `translate(${x !== null && x !== void 0 ? x : 0} ${y !== null && y !== void 0 ? y : 0})` : '';
139
+ const transform = (_a = use.getAttribute('transform')) !== null && _a !== void 0 ? _a : '';
123
140
  if (translate && transform)
124
141
  return `${translate} ${transform}`;
125
142
  return translate || transform || null;
@@ -273,13 +290,13 @@ function cleanSVG(svg) {
273
290
  }
274
291
  function removeBtnGroup(svg) {
275
292
  const btnGroup = (0, utils_1.getElementByRole)(svg, "btns-group" /* ElementTypeEnum.BtnsGroup */);
276
- btnGroup?.remove();
293
+ btnGroup === null || btnGroup === void 0 ? void 0 : btnGroup.remove();
277
294
  const btnIconDefs = (0, utils_1.getElementByRole)(svg, 'btn-icon-defs');
278
- btnIconDefs?.remove();
295
+ btnIconDefs === null || btnIconDefs === void 0 ? void 0 : btnIconDefs.remove();
279
296
  }
280
297
  function removeTransientContainer(svg) {
281
298
  const transientContainer = svg.querySelector('[data-element-type=transient-container]');
282
- transientContainer?.remove();
299
+ transientContainer === null || transientContainer === void 0 ? void 0 : transientContainer.remove();
283
300
  }
284
301
  function removeUselessAttrs(svg) {
285
302
  const groups = svg.querySelectorAll('g');
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Ellipse = Ellipse;
4
4
  function Ellipse(props) {
5
+ var _a, _b, _c, _d;
5
6
  const { x = 0, y = 0, width = 0, height = 0 } = props;
6
- props.cx ?? (props.cx = x + width / 2);
7
- props.cy ?? (props.cy = y + height / 2);
8
- props.rx ?? (props.rx = width / 2);
9
- props.ry ?? (props.ry = height / 2);
7
+ (_a = props.cx) !== null && _a !== void 0 ? _a : (props.cx = x + width / 2);
8
+ (_b = props.cy) !== null && _b !== void 0 ? _b : (props.cy = y + height / 2);
9
+ (_c = props.rx) !== null && _c !== void 0 ? _c : (props.rx = width / 2);
10
+ (_d = props.ry) !== null && _d !== void 0 ? _d : (props.ry = height / 2);
10
11
  const node = {
11
12
  type: 'ellipse',
12
13
  props,
@@ -3,11 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Path = Path;
4
4
  function Path(props) {
5
5
  const { x, y } = props;
6
- const finalProps = {
7
- ...props,
8
- };
6
+ const finalProps = Object.assign({}, props);
9
7
  if (x !== undefined || y !== undefined) {
10
- finalProps.transform = `translate(${x ?? 0}, ${y ?? 0})`;
8
+ finalProps.transform = `translate(${x !== null && x !== void 0 ? x : 0}, ${y !== null && y !== void 0 ? y : 0})`;
11
9
  }
12
10
  const node = {
13
11
  type: 'path',
@@ -1,16 +1,25 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.Polygon = Polygon;
4
- function Polygon({ points = [], ...props }) {
15
+ function Polygon(_a) {
16
+ var { points = [] } = _a, props = __rest(_a, ["points"]);
5
17
  const { x, y } = props;
6
18
  const pointsStr = points.map(({ x, y }) => `${x},${y}`).join(' ');
7
- const finalProps = {
8
- ...props,
9
- points: pointsStr,
10
- };
19
+ const finalProps = Object.assign(Object.assign({}, props), { points: pointsStr });
11
20
  if (x !== undefined || y !== undefined) {
12
21
  finalProps.transform =
13
- `translate(${x ?? 0}, ${y ?? 0})` + (finalProps.transform || '');
22
+ `translate(${x !== null && x !== void 0 ? x : 0}, ${y !== null && y !== void 0 ? y : 0})` + (finalProps.transform || '');
14
23
  }
15
24
  const node = {
16
25
  type: 'polygon',