@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
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderSVG = renderSVG;
4
4
  const fonts_1 = require("../fonts");
5
5
  function renderSVG(svg, options) {
6
+ var _a;
6
7
  const { themeConfig } = options;
7
- const { 'font-family': fontFamily = fonts_1.DEFAULT_FONT } = themeConfig.base?.text || {};
8
+ const { 'font-family': fontFamily = fonts_1.DEFAULT_FONT } = ((_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.text) || {};
8
9
  svg.setAttribute('font-family', fontFamily);
9
10
  }
@@ -19,6 +19,7 @@ function renderText(node, text, attrs = {}) {
19
19
  return renderedText;
20
20
  }
21
21
  function renderItemText(type, node, options) {
22
+ var _a, _b, _c;
22
23
  const textShape = node.nodeName === 'text' ? node : null;
23
24
  if (!textShape)
24
25
  return null;
@@ -26,13 +27,14 @@ function renderItemText(type, node, options) {
26
27
  const indexes = (0, utils_1.getItemIndexes)(node.dataset.indexes || '0');
27
28
  const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
28
29
  const text = String((0, lodash_es_1.get)(datum, type, ''));
29
- const dataAttrs = datum?.attributes?.[type];
30
- const attrs = Object.assign({}, themeConfig.base?.text, themeConfig.item?.[type], dataAttrs);
30
+ const dataAttrs = (_a = datum === null || datum === void 0 ? void 0 : datum.attributes) === null || _a === void 0 ? void 0 : _a[type];
31
+ const attrs = Object.assign({}, (_b = themeConfig.base) === null || _b === void 0 ? void 0 : _b.text, (_c = themeConfig.item) === null || _c === void 0 ? void 0 : _c[type], dataAttrs);
31
32
  const staticAttrs = (0, utils_2.parseDynamicAttributes)(textShape, attrs);
32
33
  return renderText(node, node.textContent || text, staticAttrs);
33
34
  }
34
35
  function renderStaticText(text, options) {
35
- const attrs = options.themeConfig.base?.text || {};
36
+ var _a;
37
+ const attrs = ((_a = options.themeConfig.base) === null || _a === void 0 ? void 0 : _a.text) || {};
36
38
  (0, utils_1.setAttributes)(text, attrs);
37
39
  if (attrs['font-family']) {
38
40
  text.setAttribute('font-family', (0, utils_1.encodeFontFamily)(attrs['font-family']));
@@ -61,12 +61,13 @@ function isLinkLoaded(link) {
61
61
  try {
62
62
  return !!link.sheet;
63
63
  }
64
- catch {
64
+ catch (_a) {
65
65
  return false;
66
66
  }
67
67
  }
68
68
  function getFontLoadPromise(target, id, link) {
69
- const existing = FONT_PROMISE_MAP.get(target)?.get(id);
69
+ var _a;
70
+ const existing = (_a = FONT_PROMISE_MAP.get(target)) === null || _a === void 0 ? void 0 : _a.get(id);
70
71
  if (existing)
71
72
  return existing;
72
73
  if (!link || isLinkLoaded(link)) {
@@ -84,7 +85,7 @@ function getFontLoadPromise(target, id, link) {
84
85
  }
85
86
  function loadFont(svg, font) {
86
87
  const doc = svg.ownerDocument;
87
- const target = doc?.head || document.head;
88
+ const target = (doc === null || doc === void 0 ? void 0 : doc.head) || document.head;
88
89
  if (!target)
89
90
  return;
90
91
  if (!FONT_LOAD_MAP.has(target))
@@ -42,7 +42,7 @@ function setDefaultFont(font) {
42
42
  * 字体准备说明:https://chinese-font.netlify.app/zh-cn/post/simple_tutorial
43
43
  */
44
44
  function registerFont(font) {
45
- const f = { ...font };
45
+ const f = Object.assign({}, font);
46
46
  FONT_REGISTRY.set(f.fontFamily, f);
47
47
  f.fontFamily = (0, font_1.encodeFontFamily)(f.fontFamily);
48
48
  return f;
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPaletteColor = void 0;
4
4
  const registry_1 = require("./registry");
5
5
  const getPaletteColor = (args = [], indexes, total) => {
6
+ var _a;
6
7
  const palette = typeof args === 'string' ? (0, registry_1.getPalette)(args) || [] : args;
7
- const index = indexes[0] ?? 0;
8
+ const index = (_a = indexes[0]) !== null && _a !== void 0 ? _a : 0;
8
9
  if (typeof palette === 'function') {
9
10
  const ratio = total ? index / total : 0;
10
- return palette(ratio, index, total ?? 0);
11
+ return palette(ratio, index, total !== null && total !== void 0 ? total : 0);
11
12
  }
12
13
  if (Array.isArray(palette)) {
13
14
  if (palette.length === 0)
@@ -72,21 +72,23 @@ function renderTemplate(svg, options) {
72
72
  (0, composites_1.renderBackground)(svg, options);
73
73
  }
74
74
  function fill(svg, options) {
75
+ var _a;
75
76
  const { themeConfig, data } = options;
76
- (0, composites_1.renderBaseElement)(svg, themeConfig.base?.global);
77
+ (0, composites_1.renderBaseElement)(svg, (_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.global);
77
78
  const elements = svg.querySelectorAll(`[data-element-type]`);
78
79
  elements.forEach((element) => {
80
+ var _a, _b, _c, _d, _e, _f, _g;
79
81
  const id = element.id || '';
80
82
  if ((0, utils_1.isTitle)(element)) {
81
- const modified = (0, composites_1.renderText)(element, data.title || '', Object.assign({}, themeConfig.base?.text, themeConfig.title, data.attributes?.title));
83
+ const modified = (0, composites_1.renderText)(element, data.title || '', Object.assign({}, (_a = themeConfig.base) === null || _a === void 0 ? void 0 : _a.text, themeConfig.title, (_b = data.attributes) === null || _b === void 0 ? void 0 : _b.title));
82
84
  return upsert(element, modified);
83
85
  }
84
86
  if ((0, utils_1.isDesc)(element)) {
85
- const modified = (0, composites_1.renderText)(element, data.desc || '', Object.assign({}, themeConfig.base?.text, themeConfig.desc, data.attributes?.desc));
87
+ const modified = (0, composites_1.renderText)(element, data.desc || '', Object.assign({}, (_c = themeConfig.base) === null || _c === void 0 ? void 0 : _c.text, themeConfig.desc, (_d = data.attributes) === null || _d === void 0 ? void 0 : _d.desc));
86
88
  return upsert(element, modified);
87
89
  }
88
90
  if ((0, utils_1.isIllus)(element)) {
89
- const modified = (0, composites_1.renderIllus)(svg, element, data.illus?.[id], undefined, data.attributes?.illus);
91
+ const modified = (0, composites_1.renderIllus)(svg, element, (_e = data.illus) === null || _e === void 0 ? void 0 : _e[id], undefined, (_f = data.attributes) === null || _f === void 0 ? void 0 : _f.illus);
90
92
  return upsert(element, modified);
91
93
  }
92
94
  if ((0, utils_1.isShapesGroup)(element)) {
@@ -101,7 +103,7 @@ function fill(svg, options) {
101
103
  if ((0, utils_1.isBtnsGroup)(element)) {
102
104
  return (0, composites_1.renderButtonsGroup)(svg, element);
103
105
  }
104
- if (element.dataset.elementType?.startsWith('item-')) {
106
+ if ((_g = element.dataset.elementType) === null || _g === void 0 ? void 0 : _g.startsWith('item-')) {
105
107
  const indexes = (0, utils_1.getItemIndexes)(element.dataset.indexes || '0');
106
108
  const itemType = element.dataset.elementType.replace('item-', '');
107
109
  const datum = (0, utils_1.getDatumByIndexes)(data, indexes);
@@ -64,10 +64,11 @@ function upsertGradient(svg, id, gradient) {
64
64
  defs.appendChild(gradient);
65
65
  }
66
66
  function inferGradientConfig(currentColor, config) {
67
- if (config.colors?.length || !currentColor)
67
+ var _a;
68
+ if (((_a = config.colors) === null || _a === void 0 ? void 0 : _a.length) || !currentColor)
68
69
  return config;
69
70
  const tc = (0, tinycolor2_1.default)(currentColor);
70
- const inferConfig = { ...config };
71
+ const inferConfig = Object.assign({}, config);
71
72
  inferConfig.colors = tc.isDark()
72
73
  ? [currentColor, tc.lighten(20).toHexString()]
73
74
  : [tc.darken(20).toHexString(), currentColor];
@@ -32,6 +32,17 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __rest = (this && this.__rest) || function (s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ };
35
46
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
47
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
48
  };
@@ -55,21 +66,17 @@ function applyPatternStyle(node, svg, options) {
55
66
  const config = options.themeConfig.stylize;
56
67
  if (!config || config.type !== 'pattern')
57
68
  return;
58
- const { pattern, ...restConfig } = config;
69
+ const { pattern } = config, restConfig = __rest(config, ["pattern"]);
59
70
  const generator = PATTERNS.get(pattern);
60
71
  if (!generator) {
61
72
  return console.warn(`Pattern ${pattern} not found`);
62
73
  }
63
74
  const { fill } = (0, utils_1.getAttributes)(node, ['fill', 'stroke']);
64
75
  const color = fill;
65
- const style = {
66
- backgroundColor: color
76
+ const style = Object.assign({ backgroundColor: color
67
77
  ? (0, tinycolor2_1.default)(color).setAlpha(0.5).toRgbString()
68
- : color,
69
- foregroundColor: color,
70
- ...restConfig,
71
- };
72
- const id = getPatternId({ ...config, ...style });
78
+ : color, foregroundColor: color }, restConfig);
79
+ const id = getPatternId(Object.assign(Object.assign({}, config), style));
73
80
  upsertPattern(svg, id, generator(style));
74
81
  if ((0, utils_1.hasColor)(fill)) {
75
82
  node.setAttribute('fill', `url(#${id})`);
@@ -113,7 +113,7 @@ function createRoughShape(rc, node, config) {
113
113
  ], true);
114
114
  // 分离形状属性、RoughJS选项和SVG属性
115
115
  const shapeAttrs = {};
116
- const roughOptions = { ...config };
116
+ const roughOptions = Object.assign({}, config);
117
117
  const svgAttributes = {};
118
118
  // 处理形状特定的属性
119
119
  attrs.forEach((attr) => {
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.getSvgLoadPromises = getSvgLoadPromises;
4
13
  exports.getSvgLoadPromise = getSvgLoadPromise;
@@ -10,7 +19,8 @@ function getSvgLoadPromises(svg) {
10
19
  return map ? Array.from(map.values()) : [];
11
20
  }
12
21
  function getSvgLoadPromise(svg, key) {
13
- return SVG_LOAD_PROMISE_MAP.get(svg)?.get(key);
22
+ var _a;
23
+ return (_a = SVG_LOAD_PROMISE_MAP.get(svg)) === null || _a === void 0 ? void 0 : _a.get(key);
14
24
  }
15
25
  function trackSvgLoadPromise(svg, key, promise) {
16
26
  let map = SVG_LOAD_PROMISE_MAP.get(svg);
@@ -30,13 +40,15 @@ function trackSvgLoadPromise(svg, key, promise) {
30
40
  });
31
41
  return promise;
32
42
  }
33
- async function waitForSvgLoads(svg) {
34
- await Promise.resolve();
35
- while (true) {
36
- const promises = getSvgLoadPromises(svg);
37
- if (!promises.length)
38
- break;
39
- await Promise.allSettled(promises);
40
- await Promise.resolve();
41
- }
43
+ function waitForSvgLoads(svg) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield Promise.resolve();
46
+ while (true) {
47
+ const promises = getSvgLoadPromises(svg);
48
+ if (!promises.length)
49
+ break;
50
+ yield Promise.allSettled(promises);
51
+ yield Promise.resolve();
52
+ }
53
+ });
42
54
  }
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.waitForSvgLoads = exports.getSvgLoadPromises = void 0;
4
13
  exports.loadResource = loadResource;
@@ -7,47 +16,49 @@ const load_tracker_1 = require("./load-tracker");
7
16
  const loaders_1 = require("./loaders");
8
17
  const registry_1 = require("./registry");
9
18
  const utils_2 = require("./utils");
10
- async function getResource(scene, config, datum) {
11
- const cfg = (0, utils_2.parseResourceConfig)(config);
12
- if (!cfg)
13
- return null;
14
- cfg.scene || (cfg.scene = scene);
15
- const { source, data, format, encoding } = cfg;
16
- let resource = null;
17
- try {
18
- if (source === 'inline') {
19
- const isDataURI = data.startsWith('data:');
20
- if (format === 'svg' && encoding === 'raw') {
21
- resource = (0, loaders_1.loadSVGResource)(data);
19
+ function getResource(scene, config, datum) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const cfg = (0, utils_2.parseResourceConfig)(config);
22
+ if (!cfg)
23
+ return null;
24
+ cfg.scene || (cfg.scene = scene);
25
+ const { source, data, format, encoding } = cfg;
26
+ let resource = null;
27
+ try {
28
+ if (source === 'inline') {
29
+ const isDataURI = data.startsWith('data:');
30
+ if (format === 'svg' && encoding === 'raw') {
31
+ resource = (0, loaders_1.loadSVGResource)(data);
32
+ }
33
+ else if (format === 'svg' && isDataURI) {
34
+ resource = yield (0, loaders_1.loadImageBase64Resource)(data);
35
+ }
36
+ else if (isDataURI || format === 'image') {
37
+ resource = yield (0, loaders_1.loadImageBase64Resource)(data);
38
+ }
39
+ else {
40
+ resource = (0, loaders_1.loadSVGResource)(data);
41
+ }
22
42
  }
23
- else if (format === 'svg' && isDataURI) {
24
- resource = await (0, loaders_1.loadImageBase64Resource)(data);
43
+ else if (source === 'remote') {
44
+ resource = yield (0, loaders_1.loadRemoteResource)(data, format);
25
45
  }
26
- else if (isDataURI || format === 'image') {
27
- resource = await (0, loaders_1.loadImageBase64Resource)(data);
46
+ else if (source === 'search') {
47
+ resource = yield (0, loaders_1.loadSearchResource)(data, format);
28
48
  }
29
49
  else {
30
- resource = (0, loaders_1.loadSVGResource)(data);
50
+ const customLoader = (0, registry_1.getCustomResourceLoader)();
51
+ if (customLoader)
52
+ resource = yield customLoader(cfg);
31
53
  }
32
54
  }
33
- else if (source === 'remote') {
34
- resource = await (0, loaders_1.loadRemoteResource)(data, format);
35
- }
36
- else if (source === 'search') {
37
- resource = await (0, loaders_1.loadSearchResource)(data, format);
38
- }
39
- else {
40
- const customLoader = (0, registry_1.getCustomResourceLoader)();
41
- if (customLoader)
42
- resource = await customLoader(cfg);
55
+ catch (_a) {
56
+ resource = null;
43
57
  }
44
- }
45
- catch {
46
- resource = null;
47
- }
48
- if (resource)
49
- return resource;
50
- return await (0, loaders_1.loadSearchResource)(getFallbackQuery(cfg, scene, datum), format);
58
+ if (resource)
59
+ return resource;
60
+ return yield (0, loaders_1.loadSearchResource)(getFallbackQuery(cfg, scene, datum), format);
61
+ });
51
62
  }
52
63
  const RESOURCE_MAP = new Map();
53
64
  const RESOURCE_LOAD_MAP = new WeakMap();
@@ -55,39 +66,41 @@ const RESOURCE_LOAD_MAP = new WeakMap();
55
66
  * load resource into svg defs
56
67
  * @returns resource ref id
57
68
  */
58
- async function loadResource(svg, scene, config, datum) {
59
- if (!svg)
60
- return null;
61
- const cfg = (0, utils_2.parseResourceConfig)(config);
62
- if (!cfg)
63
- return null;
64
- const id = (0, utils_2.getResourceId)(cfg);
65
- const promiseKey = `resource:${id}`;
66
- const loadedMap = RESOURCE_LOAD_MAP.get(svg);
67
- if (loadedMap?.has(id))
68
- return id;
69
- const existingPromise = (0, load_tracker_1.getSvgLoadPromise)(svg, promiseKey);
70
- if (existingPromise)
71
- return await existingPromise;
72
- const loadPromise = (async () => {
73
- const resource = RESOURCE_MAP.has(id)
74
- ? RESOURCE_MAP.get(id) || null
75
- : await getResource(scene, cfg, datum);
76
- if (!resource)
69
+ function loadResource(svg, scene, config, datum) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (!svg)
77
72
  return null;
78
- if (!RESOURCE_LOAD_MAP.has(svg))
79
- RESOURCE_LOAD_MAP.set(svg, new Map());
80
- const map = RESOURCE_LOAD_MAP.get(svg);
81
- if (map.has(id))
73
+ const cfg = (0, utils_2.parseResourceConfig)(config);
74
+ if (!cfg)
75
+ return null;
76
+ const id = (0, utils_2.getResourceId)(cfg);
77
+ const promiseKey = `resource:${id}`;
78
+ const loadedMap = RESOURCE_LOAD_MAP.get(svg);
79
+ if (loadedMap === null || loadedMap === void 0 ? void 0 : loadedMap.has(id))
80
+ return id;
81
+ const existingPromise = (0, load_tracker_1.getSvgLoadPromise)(svg, promiseKey);
82
+ if (existingPromise)
83
+ return yield existingPromise;
84
+ const loadPromise = (() => __awaiter(this, void 0, void 0, function* () {
85
+ const resource = RESOURCE_MAP.has(id)
86
+ ? RESOURCE_MAP.get(id) || null
87
+ : yield getResource(scene, cfg, datum);
88
+ if (!resource)
89
+ return null;
90
+ if (!RESOURCE_LOAD_MAP.has(svg))
91
+ RESOURCE_LOAD_MAP.set(svg, new Map());
92
+ const map = RESOURCE_LOAD_MAP.get(svg);
93
+ if (map.has(id))
94
+ return id;
95
+ const defs = (0, utils_1.getOrCreateDefs)(svg);
96
+ resource.id = id;
97
+ defs.appendChild(resource);
98
+ map.set(id, resource);
82
99
  return id;
83
- const defs = (0, utils_1.getOrCreateDefs)(svg);
84
- resource.id = id;
85
- defs.appendChild(resource);
86
- map.set(id, resource);
87
- return id;
88
- })();
89
- (0, load_tracker_1.trackSvgLoadPromise)(svg, promiseKey, loadPromise);
90
- return await loadPromise;
100
+ }))();
101
+ (0, load_tracker_1.trackSvgLoadPromise)(svg, promiseKey, loadPromise);
102
+ return yield loadPromise;
103
+ });
91
104
  }
92
105
  var load_tracker_2 = require("./load-tracker");
93
106
  Object.defineProperty(exports, "getSvgLoadPromises", { enumerable: true, get: function () { return load_tracker_2.getSvgLoadPromises; } });
@@ -95,8 +108,8 @@ Object.defineProperty(exports, "waitForSvgLoads", { enumerable: true, get: funct
95
108
  function getFallbackQuery(cfg, scene, datum) {
96
109
  const defaultQuery = scene === 'illus' ? 'illustration' : 'icon';
97
110
  const datumQuery = normalizeQuery(cfg.data) ||
98
- normalizeQuery(datum?.label) ||
99
- normalizeQuery(datum?.desc);
111
+ normalizeQuery(datum === null || datum === void 0 ? void 0 : datum.label) ||
112
+ normalizeQuery(datum === null || datum === void 0 ? void 0 : datum.desc);
100
113
  if (datumQuery)
101
114
  return datumQuery;
102
115
  const data = normalizeQuery(cfg.data);
@@ -1,73 +1,85 @@
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.loadImageBase64Resource = loadImageBase64Resource;
4
13
  const utils_1 = require("../../utils");
5
14
  function isImageBase64Resource(resource) {
6
15
  return resource.startsWith('data:');
7
16
  }
8
- async function loadImageBase64Resource(data) {
9
- if (!data || !isImageBase64Resource(data))
10
- return null;
11
- const mimeType = data.match(/^data:([^;]+)/)?.[1];
12
- if (!mimeType)
13
- return null;
14
- const analysis = () => {
15
- return new Promise((resolve, reject) => {
16
- const img = new Image();
17
- img.onload = () => {
18
- const width = img.naturalWidth;
19
- const height = img.naturalHeight;
20
- const canvas = document.createElement('canvas');
21
- const ctx = canvas.getContext('2d');
22
- if (!ctx) {
23
- return resolve({ width, height, hasAlpha: false });
24
- }
25
- // skip analysis for jpeg/jpg/webp/gif
26
- if (['image/jpeg', 'image/jpg', 'image/webp', 'image/gif'].includes(mimeType)) {
27
- return resolve({ width, height, hasAlpha: false });
28
- }
29
- canvas.width = width;
30
- canvas.height = height;
31
- ctx.drawImage(img, 0, 0);
32
- let hasAlpha = false;
33
- const step = 10;
34
- for (let x = 0; x < width; x += step) {
35
- if (hasAlpha)
36
- break;
37
- for (let y = 0; y < height; y += step) {
38
- const imageData = ctx.getImageData(x, y, 1, 1);
39
- if (imageData.data[3] < 255) {
40
- hasAlpha = true;
17
+ function loadImageBase64Resource(data) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
+ if (!data || !isImageBase64Resource(data))
21
+ return null;
22
+ const mimeType = (_a = data.match(/^data:([^;]+)/)) === null || _a === void 0 ? void 0 : _a[1];
23
+ if (!mimeType)
24
+ return null;
25
+ const analysis = () => {
26
+ return new Promise((resolve, reject) => {
27
+ const img = new Image();
28
+ img.onload = () => {
29
+ const width = img.naturalWidth;
30
+ const height = img.naturalHeight;
31
+ const canvas = document.createElement('canvas');
32
+ const ctx = canvas.getContext('2d');
33
+ if (!ctx) {
34
+ return resolve({ width, height, hasAlpha: false });
35
+ }
36
+ // skip analysis for jpeg/jpg/webp/gif
37
+ if (['image/jpeg', 'image/jpg', 'image/webp', 'image/gif'].includes(mimeType)) {
38
+ return resolve({ width, height, hasAlpha: false });
39
+ }
40
+ canvas.width = width;
41
+ canvas.height = height;
42
+ ctx.drawImage(img, 0, 0);
43
+ let hasAlpha = false;
44
+ const step = 10;
45
+ for (let x = 0; x < width; x += step) {
46
+ if (hasAlpha)
41
47
  break;
48
+ for (let y = 0; y < height; y += step) {
49
+ const imageData = ctx.getImageData(x, y, 1, 1);
50
+ if (imageData.data[3] < 255) {
51
+ hasAlpha = true;
52
+ break;
53
+ }
42
54
  }
43
55
  }
44
- }
45
- resolve({ width, height, hasAlpha });
46
- };
47
- img.onerror = () => reject(new Error('Failed to analysis image'));
48
- img.src = data;
49
- });
50
- };
51
- const { width, height, hasAlpha } = await analysis();
52
- const getPreserveAspectRatio = () => {
53
- if (hasAlpha)
54
- return 'xMidYMid meet';
55
- if (mimeType?.includes('image/gif') || mimeType?.includes('image/svg')) {
56
- return 'xMidYMid meet';
57
- }
58
- const minDimension = Math.min(width, height);
59
- if (minDimension <= 200)
60
- return 'xMidYMid meet';
61
- const aspectRatio = width / height;
62
- if (aspectRatio >= 0.6 && aspectRatio <= 1.67)
63
- return 'xMidYMid meet';
64
- if (aspectRatio < 0.3 || aspectRatio > 3.33)
65
- return 'xMidYMid meet';
66
- return 'xMidYMid slice';
67
- };
68
- const preserveAspectRatio = getPreserveAspectRatio();
69
- return (0, utils_1.parseSVG)(`
56
+ resolve({ width, height, hasAlpha });
57
+ };
58
+ img.onerror = () => reject(new Error('Failed to analysis image'));
59
+ img.src = data;
60
+ });
61
+ };
62
+ const { width, height, hasAlpha } = yield analysis();
63
+ const getPreserveAspectRatio = () => {
64
+ if (hasAlpha)
65
+ return 'xMidYMid meet';
66
+ if ((mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('image/gif')) || (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('image/svg'))) {
67
+ return 'xMidYMid meet';
68
+ }
69
+ const minDimension = Math.min(width, height);
70
+ if (minDimension <= 200)
71
+ return 'xMidYMid meet';
72
+ const aspectRatio = width / height;
73
+ if (aspectRatio >= 0.6 && aspectRatio <= 1.67)
74
+ return 'xMidYMid meet';
75
+ if (aspectRatio < 0.3 || aspectRatio > 3.33)
76
+ return 'xMidYMid meet';
77
+ return 'xMidYMid slice';
78
+ };
79
+ const preserveAspectRatio = getPreserveAspectRatio();
80
+ return (0, utils_1.parseSVG)(`
70
81
  <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="${preserveAspectRatio}">
71
82
  <image href="${data}" width="${width}" height="${height}" />
72
83
  </symbol>`);
84
+ });
73
85
  }
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.loadRemoteResource = loadRemoteResource;
4
13
  const utils_1 = require("../../utils");
@@ -8,7 +17,7 @@ function isRemoteResource(resource) {
8
17
  try {
9
18
  return Boolean(new URL(resource));
10
19
  }
11
- catch {
20
+ catch (_a) {
12
21
  return false;
13
22
  }
14
23
  }
@@ -20,20 +29,22 @@ function shouldParseAsSVG(contentType, format) {
20
29
  return true;
21
30
  return false;
22
31
  }
23
- async function loadRemoteResource(resource, format) {
24
- if (!resource || !isRemoteResource(resource))
25
- return null;
26
- const response = await (0, utils_1.fetchWithCache)(resource);
27
- if (!response.ok)
28
- throw new Error('Failed to load resource');
29
- const contentType = response.headers.get('Content-Type') || '';
30
- if (shouldParseAsSVG(contentType, format)) {
31
- const svgText = await response.text();
32
- return (0, svg_1.loadSVGResource)(svgText);
33
- }
34
- const blob = await response.blob();
35
- const base64 = await blobToBase64(blob);
36
- return (0, image_1.loadImageBase64Resource)(base64);
32
+ function loadRemoteResource(resource, format) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (!resource || !isRemoteResource(resource))
35
+ return null;
36
+ const response = yield (0, utils_1.fetchWithCache)(resource);
37
+ if (!response.ok)
38
+ throw new Error('Failed to load resource');
39
+ const contentType = response.headers.get('Content-Type') || '';
40
+ if (shouldParseAsSVG(contentType, format)) {
41
+ const svgText = yield response.text();
42
+ return (0, svg_1.loadSVGResource)(svgText);
43
+ }
44
+ const blob = yield response.blob();
45
+ const base64 = yield blobToBase64(blob);
46
+ return (0, image_1.loadImageBase64Resource)(base64);
47
+ });
37
48
  }
38
49
  function blobToBase64(blob) {
39
50
  return new Promise((resolve, reject) => {