@antv/infographic 0.2.16 → 0.2.18

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 (131) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/infographic.min.js +121 -120
  4. package/dist/infographic.min.js.map +1 -1
  5. package/esm/constants/service.d.ts +1 -1
  6. package/esm/constants/service.js +1 -1
  7. package/esm/designs/structures/chart-line.js +7 -4
  8. package/esm/editor/interactions/dblclick-edit-text.js +3 -3
  9. package/esm/editor/managers/interaction.js +6 -4
  10. package/esm/editor/plugins/components/button.d.ts +2 -1
  11. package/esm/editor/plugins/components/button.js +4 -4
  12. package/esm/editor/plugins/components/color-picker.d.ts +1 -0
  13. package/esm/editor/plugins/components/color-picker.js +3 -3
  14. package/esm/editor/plugins/components/popover.d.ts +3 -1
  15. package/esm/editor/plugins/components/popover.js +29 -9
  16. package/esm/editor/plugins/edit-bar/edit-bar.d.ts +3 -1
  17. package/esm/editor/plugins/edit-bar/edit-bar.js +17 -7
  18. package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +6 -4
  19. package/esm/editor/plugins/edit-bar/edit-items/font-align.js +8 -5
  20. package/esm/editor/plugins/edit-bar/edit-items/font-color.js +7 -4
  21. package/esm/editor/plugins/edit-bar/edit-items/font-family.js +11 -9
  22. package/esm/editor/plugins/edit-bar/edit-items/font-size.js +8 -5
  23. package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +7 -4
  24. package/esm/editor/plugins/edit-bar/edit-items/types.d.ts +5 -1
  25. package/esm/editor/plugins/reset-viewbox.d.ts +4 -1
  26. package/esm/editor/plugins/reset-viewbox.js +12 -6
  27. package/esm/editor/utils/index.d.ts +1 -0
  28. package/esm/editor/utils/index.js +1 -0
  29. package/esm/editor/utils/root.d.ts +3 -0
  30. package/esm/editor/utils/root.js +18 -0
  31. package/esm/exporter/svg.js +229 -3
  32. package/esm/options/parser.js +8 -6
  33. package/esm/options/types.d.ts +3 -3
  34. package/esm/renderer/renderer.js +1 -1
  35. package/esm/resource/loaders/search.js +2 -6
  36. package/esm/runtime/options.js +1 -1
  37. package/esm/syntax/index.js +56 -10
  38. package/esm/syntax/mapper.js +20 -6
  39. package/esm/syntax/parser.js +9 -0
  40. package/esm/syntax/types.d.ts +1 -1
  41. package/esm/templates/registry.d.ts +1 -0
  42. package/esm/templates/registry.js +6 -0
  43. package/esm/templates/utils.d.ts +1 -0
  44. package/esm/templates/utils.js +68 -0
  45. package/esm/themes/built-in.js +3 -0
  46. package/esm/utils/padding.js +1 -1
  47. package/esm/utils/style.d.ts +3 -1
  48. package/esm/utils/style.js +27 -4
  49. package/esm/version.d.ts +1 -1
  50. package/esm/version.js +1 -1
  51. package/lib/constants/service.d.ts +1 -1
  52. package/lib/constants/service.js +1 -1
  53. package/lib/designs/structures/chart-line.js +7 -4
  54. package/lib/editor/interactions/dblclick-edit-text.js +3 -3
  55. package/lib/editor/managers/interaction.js +7 -5
  56. package/lib/editor/plugins/components/button.d.ts +2 -1
  57. package/lib/editor/plugins/components/button.js +4 -4
  58. package/lib/editor/plugins/components/color-picker.d.ts +1 -0
  59. package/lib/editor/plugins/components/color-picker.js +3 -3
  60. package/lib/editor/plugins/components/popover.d.ts +3 -1
  61. package/lib/editor/plugins/components/popover.js +32 -12
  62. package/lib/editor/plugins/edit-bar/edit-bar.d.ts +3 -1
  63. package/lib/editor/plugins/edit-bar/edit-bar.js +17 -7
  64. package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +6 -4
  65. package/lib/editor/plugins/edit-bar/edit-items/font-align.js +8 -5
  66. package/lib/editor/plugins/edit-bar/edit-items/font-color.js +7 -4
  67. package/lib/editor/plugins/edit-bar/edit-items/font-family.js +11 -9
  68. package/lib/editor/plugins/edit-bar/edit-items/font-size.js +8 -5
  69. package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +7 -4
  70. package/lib/editor/plugins/edit-bar/edit-items/types.d.ts +5 -1
  71. package/lib/editor/plugins/reset-viewbox.d.ts +4 -1
  72. package/lib/editor/plugins/reset-viewbox.js +12 -6
  73. package/lib/editor/utils/index.d.ts +1 -0
  74. package/lib/editor/utils/index.js +1 -0
  75. package/lib/editor/utils/root.d.ts +3 -0
  76. package/lib/editor/utils/root.js +22 -0
  77. package/lib/exporter/svg.js +229 -3
  78. package/lib/options/parser.js +7 -5
  79. package/lib/options/types.d.ts +3 -3
  80. package/lib/renderer/renderer.js +1 -1
  81. package/lib/resource/loaders/search.js +2 -6
  82. package/lib/runtime/options.js +1 -1
  83. package/lib/syntax/index.js +56 -10
  84. package/lib/syntax/mapper.js +20 -6
  85. package/lib/syntax/parser.js +9 -0
  86. package/lib/syntax/types.d.ts +1 -1
  87. package/lib/templates/registry.d.ts +1 -0
  88. package/lib/templates/registry.js +7 -0
  89. package/lib/templates/utils.d.ts +1 -0
  90. package/lib/templates/utils.js +71 -0
  91. package/lib/themes/built-in.js +3 -0
  92. package/lib/utils/padding.js +1 -1
  93. package/lib/utils/style.d.ts +3 -1
  94. package/lib/utils/style.js +27 -4
  95. package/lib/version.d.ts +1 -1
  96. package/lib/version.js +1 -1
  97. package/package.json +1 -1
  98. package/src/constants/service.ts +1 -1
  99. package/src/designs/structures/chart-line.tsx +8 -4
  100. package/src/editor/interactions/dblclick-edit-text.ts +3 -2
  101. package/src/editor/managers/interaction.ts +9 -7
  102. package/src/editor/plugins/components/button.ts +5 -2
  103. package/src/editor/plugins/components/color-picker.ts +4 -2
  104. package/src/editor/plugins/components/popover.ts +31 -12
  105. package/src/editor/plugins/edit-bar/edit-bar.ts +26 -11
  106. package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +7 -2
  107. package/src/editor/plugins/edit-bar/edit-items/font-align.ts +8 -3
  108. package/src/editor/plugins/edit-bar/edit-items/font-color.ts +7 -2
  109. package/src/editor/plugins/edit-bar/edit-items/font-family.ts +11 -7
  110. package/src/editor/plugins/edit-bar/edit-items/font-size.ts +8 -3
  111. package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +7 -2
  112. package/src/editor/plugins/edit-bar/edit-items/types.ts +6 -1
  113. package/src/editor/plugins/reset-viewbox.ts +17 -8
  114. package/src/editor/utils/index.ts +1 -0
  115. package/src/editor/utils/root.ts +26 -0
  116. package/src/exporter/svg.ts +274 -3
  117. package/src/options/parser.ts +7 -6
  118. package/src/options/types.ts +3 -3
  119. package/src/renderer/renderer.ts +1 -1
  120. package/src/resource/loaders/search.ts +2 -5
  121. package/src/runtime/options.ts +1 -1
  122. package/src/syntax/index.ts +71 -10
  123. package/src/syntax/mapper.ts +20 -6
  124. package/src/syntax/parser.ts +10 -0
  125. package/src/syntax/types.ts +1 -0
  126. package/src/templates/registry.ts +6 -0
  127. package/src/templates/utils.ts +111 -0
  128. package/src/themes/built-in.ts +4 -0
  129. package/src/utils/padding.ts +1 -1
  130. package/src/utils/style.ts +31 -4
  131. package/src/version.ts +1 -1
@@ -0,0 +1,111 @@
1
+ function normalizeTemplateKey(type: string): string {
2
+ return type
3
+ .trim()
4
+ .toLowerCase()
5
+ .replace(/[_\s]+/g, '-')
6
+ .replace(/-+/g, '-');
7
+ }
8
+
9
+ function getLevenshteinDistance(source: string, target: string): number {
10
+ if (source === target) return 0;
11
+ if (!source.length) return target.length;
12
+ if (!target.length) return source.length;
13
+
14
+ const previous = Array.from(
15
+ { length: target.length + 1 },
16
+ (_, index) => index,
17
+ );
18
+ const current = new Array<number>(target.length + 1);
19
+
20
+ for (let sourceIndex = 1; sourceIndex <= source.length; sourceIndex += 1) {
21
+ current[0] = sourceIndex;
22
+ const sourceCode = source.charCodeAt(sourceIndex - 1);
23
+
24
+ for (let targetIndex = 1; targetIndex <= target.length; targetIndex += 1) {
25
+ const replaceCost =
26
+ sourceCode === target.charCodeAt(targetIndex - 1) ? 0 : 1;
27
+ current[targetIndex] = Math.min(
28
+ previous[targetIndex] + 1,
29
+ current[targetIndex - 1] + 1,
30
+ previous[targetIndex - 1] + replaceCost,
31
+ );
32
+ }
33
+
34
+ for (let index = 0; index < current.length; index += 1) {
35
+ previous[index] = current[index];
36
+ }
37
+ }
38
+
39
+ return previous[target.length];
40
+ }
41
+
42
+ function getCommonPrefixLength(source: string, target: string): number {
43
+ const limit = Math.min(source.length, target.length);
44
+ let index = 0;
45
+
46
+ while (
47
+ index < limit &&
48
+ source.charCodeAt(index) === target.charCodeAt(index)
49
+ ) {
50
+ index += 1;
51
+ }
52
+
53
+ return index;
54
+ }
55
+
56
+ function isBetterMatch(
57
+ bestMatch: string | undefined,
58
+ bestDistance: number,
59
+ bestPrefixLength: number,
60
+ candidateKey: string,
61
+ candidateDistance: number,
62
+ candidatePrefixLength: number,
63
+ ): boolean {
64
+ return (
65
+ candidateDistance < bestDistance ||
66
+ (candidateDistance === bestDistance &&
67
+ candidatePrefixLength > bestPrefixLength) ||
68
+ (candidateDistance === bestDistance &&
69
+ candidatePrefixLength === bestPrefixLength &&
70
+ (!bestMatch || candidateKey < bestMatch))
71
+ );
72
+ }
73
+
74
+ export function findClosestTemplateKey(
75
+ type: string,
76
+ keys: Iterable<string>,
77
+ ): string | undefined {
78
+ const normalizedType = normalizeTemplateKey(type);
79
+ if (!normalizedType) return undefined;
80
+
81
+ let bestMatch: string | undefined;
82
+ let bestDistance = Number.POSITIVE_INFINITY;
83
+ let bestPrefixLength = -1;
84
+
85
+ for (const key of keys) {
86
+ const normalizedKey = normalizeTemplateKey(key);
87
+ if (normalizedKey === normalizedType) {
88
+ return key;
89
+ }
90
+
91
+ const distance = getLevenshteinDistance(normalizedType, normalizedKey);
92
+ const prefixLength = getCommonPrefixLength(normalizedType, normalizedKey);
93
+
94
+ if (
95
+ isBetterMatch(
96
+ bestMatch,
97
+ bestDistance,
98
+ bestPrefixLength,
99
+ key,
100
+ distance,
101
+ prefixLength,
102
+ )
103
+ ) {
104
+ bestMatch = key;
105
+ bestDistance = distance;
106
+ bestPrefixLength = prefixLength;
107
+ }
108
+ }
109
+
110
+ return bestMatch;
111
+ }
@@ -1,5 +1,9 @@
1
1
  import { registerTheme } from './registry';
2
2
 
3
+ registerTheme('light', {
4
+ colorBg: '#ffffff',
5
+ });
6
+
3
7
  registerTheme('dark', {
4
8
  colorBg: '#1F1F1F',
5
9
  base: {
@@ -27,7 +27,7 @@ export function setSVGPadding(svg: SVGSVGElement, padding: ParsedPadding) {
27
27
  if (isNode) {
28
28
  setSVGPaddingInNode(svg, padding);
29
29
  } else {
30
- if (document.contains(svg)) {
30
+ if (svg.isConnected) {
31
31
  setSVGPaddingInBrowser(svg, padding);
32
32
  } else {
33
33
  try {
@@ -1,8 +1,35 @@
1
- export function injectStyleOnce(id: string, styles: string) {
2
- if (document.getElementById(id)) return;
1
+ type StyleTarget = Document | ShadowRoot | Node | null | undefined;
3
2
 
4
- const style = document.createElement('style');
3
+ function resolveStyleRoot(target?: StyleTarget): Document | ShadowRoot {
4
+ if (!target) return document;
5
+ if (target instanceof Document || target instanceof ShadowRoot) return target;
6
+ if (!target.isConnected) return document;
7
+
8
+ const root = target.getRootNode();
9
+ return root instanceof ShadowRoot ? root : document;
10
+ }
11
+
12
+ function hasStyle(root: Document | ShadowRoot, id: string) {
13
+ if (root instanceof Document) return Boolean(root.getElementById(id));
14
+ return Boolean(root.querySelector(`#${id}`));
15
+ }
16
+
17
+ export function injectStyleOnce(
18
+ id: string,
19
+ styles: string,
20
+ target?: StyleTarget,
21
+ ) {
22
+ const root = resolveStyleRoot(target);
23
+ if (hasStyle(root, id)) return;
24
+
25
+ const doc = root instanceof Document ? root : (root.ownerDocument ?? document);
26
+ const style = doc.createElement('style');
5
27
  style.id = id;
6
28
  style.textContent = styles;
7
- document.head.appendChild(style);
29
+
30
+ if (root instanceof Document) {
31
+ root.head.appendChild(style);
32
+ } else {
33
+ root.appendChild(style);
34
+ }
8
35
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.2.16';
1
+ export const VERSION = '0.2.18';