@antv/infographic 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +12 -5
  2. package/README.zh-CN.md +12 -5
  3. package/dist/infographic.min.js +155 -153
  4. package/dist/infographic.min.js.map +1 -1
  5. package/esm/designs/structures/index.d.ts +1 -0
  6. package/esm/designs/structures/index.js +1 -0
  7. package/esm/designs/structures/relation-dagre-flow.js +4 -139
  8. package/esm/designs/structures/sequence-interaction.d.ts +54 -0
  9. package/esm/designs/structures/sequence-interaction.js +440 -0
  10. package/esm/designs/utils/geometry.d.ts +44 -0
  11. package/esm/designs/utils/geometry.js +244 -0
  12. package/esm/designs/utils/index.d.ts +1 -0
  13. package/esm/designs/utils/index.js +1 -0
  14. package/esm/editor/managers/sync-registry.d.ts +2 -1
  15. package/esm/editor/types/editor.d.ts +2 -1
  16. package/esm/editor/types/sync.d.ts +2 -1
  17. package/esm/editor/utils/object.js +46 -39
  18. package/esm/options/types.d.ts +6 -0
  19. package/esm/runtime/Infographic.js +20 -7
  20. package/esm/syntax/index.js +40 -20
  21. package/esm/syntax/relations.js +26 -2
  22. package/esm/syntax/schema.js +1 -0
  23. package/esm/templates/built-in.js +3 -2
  24. package/esm/templates/sequence-interaction.d.ts +2 -0
  25. package/esm/templates/sequence-interaction.js +76 -0
  26. package/esm/types/data.d.ts +1 -0
  27. package/esm/utils/index.d.ts +1 -0
  28. package/esm/utils/index.js +1 -0
  29. package/esm/utils/measure-text.js +31 -3
  30. package/esm/utils/types.d.ts +16 -0
  31. package/esm/utils/types.js +12 -0
  32. package/esm/version.d.ts +1 -1
  33. package/esm/version.js +1 -1
  34. package/lib/designs/structures/index.d.ts +1 -0
  35. package/lib/designs/structures/index.js +1 -0
  36. package/lib/designs/structures/relation-dagre-flow.js +5 -140
  37. package/lib/designs/structures/sequence-interaction.d.ts +54 -0
  38. package/lib/designs/structures/sequence-interaction.js +444 -0
  39. package/lib/designs/utils/geometry.d.ts +44 -0
  40. package/lib/designs/utils/geometry.js +256 -0
  41. package/lib/designs/utils/index.d.ts +1 -0
  42. package/lib/designs/utils/index.js +1 -0
  43. package/lib/editor/managers/sync-registry.d.ts +2 -1
  44. package/lib/editor/types/editor.d.ts +2 -1
  45. package/lib/editor/types/sync.d.ts +2 -1
  46. package/lib/editor/utils/object.js +45 -38
  47. package/lib/options/types.d.ts +6 -0
  48. package/lib/runtime/Infographic.js +19 -6
  49. package/lib/syntax/index.js +40 -20
  50. package/lib/syntax/relations.js +26 -2
  51. package/lib/syntax/schema.js +1 -0
  52. package/lib/templates/built-in.js +3 -2
  53. package/lib/templates/sequence-interaction.d.ts +2 -0
  54. package/lib/templates/sequence-interaction.js +79 -0
  55. package/lib/types/data.d.ts +1 -0
  56. package/lib/utils/index.d.ts +1 -0
  57. package/lib/utils/index.js +1 -0
  58. package/lib/utils/measure-text.js +30 -2
  59. package/lib/utils/types.d.ts +16 -0
  60. package/lib/utils/types.js +13 -0
  61. package/lib/version.d.ts +1 -1
  62. package/lib/version.js +1 -1
  63. package/package.json +1 -1
  64. package/src/designs/structures/index.ts +1 -0
  65. package/src/designs/structures/relation-dagre-flow.tsx +14 -178
  66. package/src/designs/structures/sequence-interaction.tsx +885 -0
  67. package/src/designs/utils/geometry.tsx +315 -0
  68. package/src/designs/utils/index.ts +1 -0
  69. package/src/editor/managers/sync-registry.ts +2 -1
  70. package/src/editor/types/editor.ts +2 -1
  71. package/src/editor/types/sync.ts +3 -1
  72. package/src/editor/utils/object.ts +50 -40
  73. package/src/options/types.ts +7 -0
  74. package/src/runtime/Infographic.tsx +27 -17
  75. package/src/syntax/index.ts +51 -18
  76. package/src/syntax/relations.ts +29 -2
  77. package/src/syntax/schema.ts +1 -0
  78. package/src/templates/built-in.ts +2 -0
  79. package/src/templates/sequence-interaction.ts +101 -0
  80. package/src/types/data.ts +1 -0
  81. package/src/utils/index.ts +1 -0
  82. package/src/utils/measure-text.ts +35 -3
  83. package/src/utils/types.ts +61 -0
  84. package/src/version.ts +1 -1
@@ -3,8 +3,8 @@ import { mapWithSchema } from './mapper';
3
3
  import { RelationSchema } from './schema';
4
4
  import type { SyntaxError, SyntaxNode } from './types';
5
5
 
6
- const RELATION_TOKEN = /[<>=o.x-]{2,}/;
7
- const ARROW_TOKEN = /[<>=o.x-]{2,}/g;
6
+ const RELATION_TOKEN = /(?:[<>o.x-]{2,}|[<>=]{2,})/;
7
+ const ARROW_TOKEN = /(?:[<>o.x-]{2,}|[<>=]{2,})/g;
8
8
 
9
9
  interface ParsedNode {
10
10
  id: string;
@@ -125,6 +125,33 @@ function readEdge(text: string, startIndex: number): ParsedEdge | null {
125
125
  let directionToken = arrowToken;
126
126
  let index = arrowEnd;
127
127
 
128
+ // Detect split bidirectional arrow pattern: <- label ->
129
+ {
130
+ const leftHasLeft = directionToken.includes('<');
131
+ const leftHasRight = directionToken.includes('>');
132
+ if (leftHasLeft && !leftHasRight) {
133
+ const lookahead = new RegExp(ARROW_TOKEN.source, 'g');
134
+ lookahead.lastIndex = arrowEnd;
135
+ const rightMatch = lookahead.exec(text);
136
+ if (
137
+ rightMatch &&
138
+ rightMatch[0].includes('>') &&
139
+ !rightMatch[0].includes('<')
140
+ ) {
141
+ const middleText = text.slice(arrowEnd, rightMatch.index).trim();
142
+ if (middleText) {
143
+ const splitLabel = normalizeLabel(middleText);
144
+ return {
145
+ label: splitLabel || label,
146
+ direction: 'both',
147
+ reverse: false,
148
+ nextIndex: rightMatch.index + rightMatch[0].length,
149
+ };
150
+ }
151
+ }
152
+ }
153
+ }
154
+
128
155
  index = skipSpaces(text, index);
129
156
  if (text[index] === '|') {
130
157
  const pipeEnd = text.indexOf('|', index + 1);
@@ -60,6 +60,7 @@ export const RelationSchema: ObjectSchema = object(
60
60
  direction: enumOf(['forward', 'both', 'none']),
61
61
  showArrow: enumOf(['true', 'false']),
62
62
  arrowType: enumOf(['arrow', 'triangle', 'diamond']),
63
+ lineStyle: enumOf(['solid', 'dashed']),
63
64
  },
64
65
  { allowUnknown: true },
65
66
  );
@@ -6,6 +6,7 @@ import { hierarchyTreeTemplates } from './hierarchy-tree';
6
6
  import { listZigzagTemplates } from './list-zigzag';
7
7
  import { registerTemplate } from './registry';
8
8
  import { relationDagreFlowTemplates } from './relation-dagre-flow';
9
+ import { sequenceInteractionTemplates } from './sequence-interaction';
9
10
  import { sequenceStairsTemplates } from './sequence-stairs';
10
11
  import type { TemplateOptions } from './types';
11
12
  import { wordCloudTemplate } from './word-cloud';
@@ -752,6 +753,7 @@ const BUILT_IN_TEMPLATES: Record<string, TemplateOptions> = {
752
753
  ...wordCloudTemplate,
753
754
  ...listZigzagTemplates,
754
755
  ...relationDagreFlowTemplates,
756
+ ...sequenceInteractionTemplates,
755
757
  ...hierarchyStructureTemplates,
756
758
  };
757
759
 
@@ -0,0 +1,101 @@
1
+ import type { TemplateOptions } from './types';
2
+
3
+ // 多样化的节点样式
4
+ const items = {
5
+ 'badge-card': {
6
+ type: 'badge-card',
7
+ width: 160,
8
+ height: 60,
9
+ },
10
+ 'compact-card': {
11
+ type: 'compact-card',
12
+ width: 180,
13
+ height: 60,
14
+ },
15
+ 'capsule-item': {
16
+ type: 'capsule-item',
17
+ width: 150,
18
+ height: 60,
19
+ },
20
+ 'rounded-rect-node': {
21
+ type: 'rounded-rect-node',
22
+ width: 140,
23
+ height: 60,
24
+ },
25
+ } as const;
26
+
27
+ // 基础结构属性
28
+ const baseStructureAttrs = {
29
+ type: 'sequence-interaction',
30
+ showLaneHeader: true,
31
+ arrowType: 'triangle',
32
+ } as const;
33
+
34
+ // 箭头样式配置
35
+ const arrowStyles = {
36
+ default: {},
37
+ dashed: {
38
+ edgeStyle: 'dashed',
39
+ },
40
+ animated: {
41
+ edgeStyle: 'dashed',
42
+ animated: true,
43
+ },
44
+ } as const;
45
+
46
+ // 结构布局配置
47
+ const structures = {
48
+ // 默认:带生命线
49
+ default: {
50
+ ...baseStructureAttrs,
51
+ showLifeline: true,
52
+ nodeGap: 40,
53
+ },
54
+ // 紧凑:更小间距
55
+ compact: {
56
+ ...baseStructureAttrs,
57
+ showLifeline: true,
58
+ nodeGap: 20,
59
+ },
60
+ // 宽松:更大间距
61
+ wide: {
62
+ ...baseStructureAttrs,
63
+ showLifeline: true,
64
+ nodeGap: 60,
65
+ },
66
+ } as const;
67
+
68
+ export const sequenceInteractionTemplates: Record<string, TemplateOptions> = {};
69
+
70
+ // 排除某些不合适的组合
71
+ const omit: string[] = [
72
+ // 后续如果有不合适的可以排除掉
73
+ ];
74
+
75
+ Object.entries(structures).forEach(([strKey, strAttrs]) => {
76
+ Object.entries(arrowStyles).forEach(([arrowKey, arrowAttrs]) => {
77
+ Object.entries(items).forEach(([itemKey, itemAttrs]) => {
78
+ const parts = [strKey];
79
+ if (arrowKey !== 'default') {
80
+ parts.push(arrowKey);
81
+ }
82
+ parts.push(itemKey);
83
+
84
+ const appendix = parts.join('-');
85
+ if (omit.includes(appendix)) return;
86
+
87
+ const templateKey = `sequence-interaction-${appendix}`;
88
+
89
+ sequenceInteractionTemplates[templateKey] = {
90
+ design: {
91
+ title: 'default',
92
+ structure: {
93
+ ...strAttrs,
94
+ ...arrowAttrs,
95
+ },
96
+ item: itemAttrs,
97
+ },
98
+ };
99
+ });
100
+ });
101
+ });
package/src/types/data.ts CHANGED
@@ -56,6 +56,7 @@ export interface RelationEdgeDatum extends BaseDatum {
56
56
  direction?: 'forward' | 'both' | 'none';
57
57
  showArrow?: boolean;
58
58
  arrowType?: 'arrow' | 'triangle' | 'diamond';
59
+ lineStyle?: 'solid' | 'dashed';
59
60
  }
60
61
 
61
62
  /**
@@ -17,5 +17,6 @@ export * from './recognizer';
17
17
  export * from './style';
18
18
  export * from './svg';
19
19
  export * from './text';
20
+ export * from './types';
20
21
  export * from './uuid';
21
22
  export * from './viewbox';
@@ -1,10 +1,15 @@
1
1
  import { measureText as measure, registerFont } from 'measury';
2
+ import Tegakizatsu from 'measury/fonts/851tegakizatsu-Regular';
2
3
  import AlibabaPuHuiTi from 'measury/fonts/AlibabaPuHuiTi-Regular';
4
+ import Arial from 'measury/fonts/Arial-Regular';
5
+ import LXGWWenKai from 'measury/fonts/LXGWWenKai-Regular';
6
+ import SourceHanSans from 'measury/fonts/SourceHanSans-Regular';
7
+ import SourceHanSerif from 'measury/fonts/SourceHanSerif-Regular';
3
8
  import { JSXNode, TextProps } from '../jsx';
4
9
  import { DEFAULT_FONT } from '../renderer';
5
- import { encodeFontFamily } from './font';
10
+ import { decodeFontFamily, encodeFontFamily } from './font';
6
11
 
7
- let FONT_EXTEND_FACTOR = 1.01;
12
+ let FONT_EXTEND_FACTOR = 1.015;
8
13
 
9
14
  export const setFontExtendFactor = (factor: number) => {
10
15
  FONT_EXTEND_FACTOR = factor;
@@ -12,6 +17,28 @@ export const setFontExtendFactor = (factor: number) => {
12
17
 
13
18
  registerFont(AlibabaPuHuiTi);
14
19
 
20
+ // Lazy-register extra measury fonts on first use (SSR only needs glyph data).
21
+ const EXTRA_MEASURY_FONTS: Record<string, Parameters<typeof registerFont>[0]> =
22
+ {
23
+ '851tegakizatsu': Tegakizatsu,
24
+ Arial: Arial,
25
+ 'LXGW WenKai': LXGWWenKai,
26
+ 'Source Han Sans': SourceHanSans,
27
+ 'Source Han Serif': SourceHanSerif,
28
+ };
29
+ const registeredMeasuryFonts = new Set<string>();
30
+
31
+ function ensureMeasuryFont(fontFamily: string) {
32
+ // decodeFontFamily: '"851tegakizatsu", sans-serif' → '851tegakizatsu, sans-serif'
33
+ // split by comma and take the first family name
34
+ const primary = decodeFontFamily(fontFamily)?.split(',')[0]?.trim();
35
+ if (!primary || registeredMeasuryFonts.has(primary)) return;
36
+ const data = EXTRA_MEASURY_FONTS[primary];
37
+ if (!data) return;
38
+ registerFont(data);
39
+ registeredMeasuryFonts.add(primary);
40
+ }
41
+
15
42
  let canvasContext: CanvasRenderingContext2D | null | undefined = undefined;
16
43
  let measureSpan: HTMLSpanElement | null = null;
17
44
 
@@ -121,13 +148,18 @@ export function measureText(
121
148
  } = attrs;
122
149
 
123
150
  const content = text.toString();
151
+ ensureMeasuryFont(fontFamily);
124
152
  const options = {
125
153
  fontFamily,
126
154
  fontSize: parseFloat(fontSize.toString()),
127
155
  fontWeight,
128
156
  lineHeight,
129
157
  };
130
- const fallback = () => measure(content, options);
158
+ const fallback = () =>
159
+ measure(content, {
160
+ ...options,
161
+ fontFamily: decodeFontFamily(fontFamily),
162
+ });
131
163
  const metrics = measureTextInBrowser(content, options) ?? fallback();
132
164
 
133
165
  // 额外添加 1% 宽高
@@ -0,0 +1,61 @@
1
+ // =============================================================================
2
+ // Path Helper Types (路径生成工具类型)
3
+ //
4
+ // 作用:递归提取对象的所有可选路径(点语法),用于 SyncRegistry 等场景的类型安全与补全。
5
+ //
6
+ // [Input]:
7
+ // type Obj = { a: { b: { c: string } }, d: number };
8
+ //
9
+ // [Output]:
10
+ // "a" | "a.b" | "a.b.c" | "d"
11
+ // =============================================================================
12
+
13
+ // 1. 递归深度控制:定义一个元组,用于递减深度 (D -> D-1)
14
+ // Prev[3] => 2, Prev[2] => 1, ... Prev[0] => never
15
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
16
+
17
+ // 2. 终止节点类型:遇到这些类型停止递归
18
+ // 包括基本类型、数组、函数等,只深入遍历普通对象
19
+ type StopType =
20
+ | string
21
+ | number
22
+ | boolean
23
+ | symbol
24
+ | undefined
25
+ | null
26
+ | ((...args: any[]) => any)
27
+ | Array<any>;
28
+
29
+ // 3. 辅助:拼接两个路径片段 (K.P)
30
+ type Join<K, P> = K extends string | number
31
+ ? P extends string | number
32
+ ? `${K}${'' extends P ? '' : '.'}${P}`
33
+ : never
34
+ : never;
35
+
36
+ // 4. 辅助:提取对象中明确定义的 Key (过滤掉索引签名 [key: string]: any)
37
+ // 使用 Key Remapping (TS 4.1+) 技术
38
+ type ValidKey<T> = keyof {
39
+ [K in keyof T as string extends K
40
+ ? never
41
+ : number extends K
42
+ ? never
43
+ : K]: any;
44
+ };
45
+
46
+ /**
47
+ * 递归生成 T 的所有点语法路径 (例如 "design.structure" 或 "data.items")
48
+ * @template T 目标对象类型
49
+ * @template D 递归深度限制,默认 3 层 (足以覆盖大多数配置嵌套)
50
+ */
51
+ export type Path<T, D extends number = 3> = [D] extends [never]
52
+ ? never // A. 达到最大深度,终止
53
+ : T extends StopType
54
+ ? never // B. 遇到终止类型,终止
55
+ : {
56
+ // C. 遍历所有有效的 Key,并移除可选修饰符 (-?) 以处理 undefined
57
+ [K in ValidKey<T>]-?: K extends string | number
58
+ ? // 生成: 当前路径 K 或 "K + 子路径"
59
+ K | Join<K, Path<NonNullable<T[K]>, Prev[D]>>
60
+ : never;
61
+ }[ValidKey<T>]; // D. 提取所有生成路径的联合类型
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.2.14';
1
+ export const VERSION = '0.2.15';