@antv/infographic 0.2.15 → 0.2.17
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.
- package/README.md +27 -0
- package/README.zh-CN.md +27 -0
- package/dist/infographic.min.js +130 -129
- package/dist/infographic.min.js.map +1 -1
- package/esm/constants/service.d.ts +1 -1
- package/esm/constants/service.js +1 -1
- package/esm/designs/structures/chart-line.js +2 -1
- package/esm/designs/structures/sequence-interaction.js +36 -15
- package/esm/designs/structures/sequence-timeline.d.ts +1 -0
- package/esm/designs/structures/sequence-timeline.js +4 -2
- package/esm/exporter/png.js +2 -2
- package/esm/exporter/svg.js +176 -2
- package/esm/exporter/types.d.ts +10 -0
- package/esm/options/parser.js +8 -6
- package/esm/options/types.d.ts +3 -3
- package/esm/renderer/renderer.js +1 -1
- package/esm/resource/loaders/search.js +2 -3
- package/esm/runtime/options.js +1 -1
- package/esm/syntax/index.js +56 -10
- package/esm/syntax/mapper.js +20 -6
- package/esm/syntax/parser.js +89 -3
- package/esm/syntax/types.d.ts +1 -1
- package/esm/templates/built-in.js +2 -2
- package/esm/templates/registry.d.ts +1 -0
- package/esm/templates/registry.js +6 -0
- package/esm/templates/utils.d.ts +1 -0
- package/esm/templates/utils.js +63 -0
- package/esm/themes/built-in.js +3 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/constants/service.d.ts +1 -1
- package/lib/constants/service.js +1 -1
- package/lib/designs/structures/chart-line.js +2 -1
- package/lib/designs/structures/sequence-interaction.js +36 -15
- package/lib/designs/structures/sequence-timeline.d.ts +1 -0
- package/lib/designs/structures/sequence-timeline.js +4 -2
- package/lib/exporter/png.js +2 -2
- package/lib/exporter/svg.js +176 -2
- package/lib/exporter/types.d.ts +10 -0
- package/lib/options/parser.js +7 -5
- package/lib/options/types.d.ts +3 -3
- package/lib/renderer/renderer.js +1 -1
- package/lib/resource/loaders/search.js +2 -3
- package/lib/runtime/options.js +1 -1
- package/lib/syntax/index.js +56 -10
- package/lib/syntax/mapper.js +20 -6
- package/lib/syntax/parser.js +89 -3
- package/lib/syntax/types.d.ts +1 -1
- package/lib/templates/built-in.js +2 -2
- package/lib/templates/registry.d.ts +1 -0
- package/lib/templates/registry.js +7 -0
- package/lib/templates/utils.d.ts +1 -0
- package/lib/templates/utils.js +66 -0
- package/lib/themes/built-in.js +3 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/constants/service.ts +1 -1
- package/src/designs/structures/chart-line.tsx +3 -1
- package/src/designs/structures/sequence-interaction.tsx +92 -46
- package/src/designs/structures/sequence-timeline.tsx +18 -15
- package/src/exporter/png.ts +3 -2
- package/src/exporter/svg.ts +209 -2
- package/src/exporter/types.ts +10 -0
- package/src/options/parser.ts +7 -6
- package/src/options/types.ts +3 -3
- package/src/renderer/renderer.ts +1 -1
- package/src/resource/loaders/search.ts +2 -2
- package/src/runtime/options.ts +1 -1
- package/src/syntax/index.ts +71 -10
- package/src/syntax/mapper.ts +20 -6
- package/src/syntax/parser.ts +111 -3
- package/src/syntax/types.ts +1 -0
- package/src/templates/built-in.ts +2 -2
- package/src/templates/registry.ts +6 -0
- package/src/templates/utils.ts +87 -0
- package/src/themes/built-in.ts +4 -0
- package/src/version.ts +1 -1
package/lib/options/parser.js
CHANGED
|
@@ -16,15 +16,17 @@ exports.parseData = parseData;
|
|
|
16
16
|
const lodash_es_1 = require("lodash-es");
|
|
17
17
|
const designs_1 = require("../designs");
|
|
18
18
|
const renderer_1 = require("../renderer");
|
|
19
|
+
const registry_1 = require("../templates/registry");
|
|
19
20
|
const themes_1 = require("../themes");
|
|
20
21
|
const utils_1 = require("../utils");
|
|
21
22
|
function parseOptions(options) {
|
|
22
23
|
const { container = '#container', padding = 0, template, design, theme, themeConfig, data } = options, restOptions = __rest(options, ["container", "padding", "template", "design", "theme", "themeConfig", "data"]);
|
|
24
|
+
const resolvedTemplate = template ? (0, registry_1.resolveTemplateKey)(template) : undefined;
|
|
23
25
|
const parsedContainer = typeof container === 'string'
|
|
24
26
|
? document.querySelector(container) || document.createElement('div')
|
|
25
27
|
: container;
|
|
26
|
-
const templateOptions =
|
|
27
|
-
? (0,
|
|
28
|
+
const templateOptions = resolvedTemplate
|
|
29
|
+
? (0, registry_1.getTemplate)(resolvedTemplate)
|
|
28
30
|
: undefined;
|
|
29
31
|
const mergedThemeConfig = (0, lodash_es_1.merge)({}, templateOptions === null || templateOptions === void 0 ? void 0 : templateOptions.themeConfig, themeConfig);
|
|
30
32
|
const resolvedThemeConfig = theme || themeConfig || (templateOptions === null || templateOptions === void 0 ? void 0 : templateOptions.themeConfig)
|
|
@@ -39,11 +41,11 @@ function parseOptions(options) {
|
|
|
39
41
|
Object.assign(parsed, restTemplateOptions);
|
|
40
42
|
}
|
|
41
43
|
Object.assign(parsed, restOptions);
|
|
42
|
-
const parsedData = parseData(data,
|
|
44
|
+
const parsedData = parseData(data, resolvedTemplate);
|
|
43
45
|
if (parsedData)
|
|
44
46
|
parsed.data = parsedData;
|
|
45
|
-
if (
|
|
46
|
-
parsed.template =
|
|
47
|
+
if (resolvedTemplate)
|
|
48
|
+
parsed.template = resolvedTemplate;
|
|
47
49
|
if ((templateOptions === null || templateOptions === void 0 ? void 0 : templateOptions.design) || design) {
|
|
48
50
|
const designOptions = Object.assign(Object.assign({}, (resolvedThemeConfig
|
|
49
51
|
? Object.assign(Object.assign({}, options), { themeConfig: resolvedThemeConfig }) : options)), { data: parsedData || data });
|
package/lib/options/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type { ThemeConfig } from '../themes';
|
|
|
4
4
|
import type { Data, Padding, ParsedData } from '../types';
|
|
5
5
|
import type { Path } from '../utils';
|
|
6
6
|
export interface InfographicOptions {
|
|
7
|
-
/**
|
|
8
|
-
container?: string |
|
|
7
|
+
/** 容器,可以是选择器、Element 或 ShadowRoot */
|
|
8
|
+
container?: string | Element | ShadowRoot;
|
|
9
9
|
/** 宽度 */
|
|
10
10
|
width?: number | string;
|
|
11
11
|
/** 高度 */
|
|
@@ -34,7 +34,7 @@ export interface InfographicOptions {
|
|
|
34
34
|
elements?: ElementProps[];
|
|
35
35
|
}
|
|
36
36
|
export interface ParsedInfographicOptions {
|
|
37
|
-
container:
|
|
37
|
+
container: Element | ShadowRoot;
|
|
38
38
|
width?: number | string;
|
|
39
39
|
height?: number | string;
|
|
40
40
|
padding?: Padding;
|
package/lib/renderer/renderer.js
CHANGED
|
@@ -16,7 +16,6 @@ const image_1 = require("./image");
|
|
|
16
16
|
const remote_1 = require("./remote");
|
|
17
17
|
const svg_1 = require("./svg");
|
|
18
18
|
const queryIcon = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
var _a;
|
|
20
19
|
try {
|
|
21
20
|
const params = new URLSearchParams({ text: query, topK: '1' });
|
|
22
21
|
const url = `${constants_1.ICON_SERVICE_URL}?${params.toString()}`;
|
|
@@ -24,9 +23,9 @@ const queryIcon = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
24
23
|
if (!response.ok)
|
|
25
24
|
return null;
|
|
26
25
|
const result = yield response.json();
|
|
27
|
-
if (!(result === null || result === void 0 ? void 0 : result.
|
|
26
|
+
if (!(result === null || result === void 0 ? void 0 : result.success) || !Array.isArray(result.data))
|
|
28
27
|
return null;
|
|
29
|
-
return result.data
|
|
28
|
+
return result.data[0] || null;
|
|
30
29
|
}
|
|
31
30
|
catch (error) {
|
|
32
31
|
console.error(`Failed to query icon for "${query}":`, error);
|
package/lib/runtime/options.js
CHANGED
package/lib/syntax/index.js
CHANGED
|
@@ -16,6 +16,15 @@ const mapper_1 = require("./mapper");
|
|
|
16
16
|
const parser_1 = require("./parser");
|
|
17
17
|
const relations_1 = require("./relations");
|
|
18
18
|
const schema_1 = require("./schema");
|
|
19
|
+
const ALLOWED_ROOT_KEYS = new Set([
|
|
20
|
+
'infographic',
|
|
21
|
+
'template',
|
|
22
|
+
'design',
|
|
23
|
+
'data',
|
|
24
|
+
'theme',
|
|
25
|
+
'width',
|
|
26
|
+
'height',
|
|
27
|
+
]);
|
|
19
28
|
function normalizeItems(items) {
|
|
20
29
|
var _a;
|
|
21
30
|
const seen = new Set();
|
|
@@ -36,6 +45,13 @@ function normalizeItems(items) {
|
|
|
36
45
|
}
|
|
37
46
|
return normalized.reverse();
|
|
38
47
|
}
|
|
48
|
+
function assignMissingNodeIds(items) {
|
|
49
|
+
items.forEach((item) => {
|
|
50
|
+
if (!item.id && item.label) {
|
|
51
|
+
item.id = item.label;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
39
55
|
function resolveTemplate(node, errors) {
|
|
40
56
|
if (!node)
|
|
41
57
|
return undefined;
|
|
@@ -49,12 +65,42 @@ function resolveTemplate(node, errors) {
|
|
|
49
65
|
}
|
|
50
66
|
return undefined;
|
|
51
67
|
}
|
|
68
|
+
function inferTemplateFromBareFirstLine(entries, warnings) {
|
|
69
|
+
if ('infographic' in entries || 'template' in entries) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const [firstEntry] = Object.entries(entries);
|
|
73
|
+
if (!firstEntry)
|
|
74
|
+
return undefined;
|
|
75
|
+
const [key, node] = firstEntry;
|
|
76
|
+
if (ALLOWED_ROOT_KEYS.has(key) || node.kind !== 'object') {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (node.value !== undefined || Object.keys(node.entries).length > 0) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
warnings.push({
|
|
83
|
+
path: 'template',
|
|
84
|
+
line: node.line,
|
|
85
|
+
code: 'implicit_template',
|
|
86
|
+
message: 'Inferred template from a bare first line. Prefix it with "infographic" or "template" to make the syntax explicit.',
|
|
87
|
+
raw: key,
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
template: key,
|
|
91
|
+
inferredKey: key,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
52
94
|
function parseSyntax(input) {
|
|
53
95
|
var _a;
|
|
54
96
|
const { ast, errors } = (0, parser_1.parseSyntaxToAst)(input);
|
|
55
97
|
const warnings = [];
|
|
56
98
|
const options = {};
|
|
57
99
|
const mergedEntries = Object.assign({}, ast.entries);
|
|
100
|
+
const inferredTemplate = inferTemplateFromBareFirstLine(ast.entries, warnings);
|
|
101
|
+
if (inferredTemplate) {
|
|
102
|
+
delete mergedEntries[inferredTemplate.inferredKey];
|
|
103
|
+
}
|
|
58
104
|
const infographicNode = ast.entries.infographic;
|
|
59
105
|
let templateFromInfographic;
|
|
60
106
|
if (infographicNode && infographicNode.kind === 'object') {
|
|
@@ -65,17 +111,8 @@ function parseSyntax(input) {
|
|
|
65
111
|
mergedEntries[key] = value;
|
|
66
112
|
});
|
|
67
113
|
}
|
|
68
|
-
const allowedRootKeys = new Set([
|
|
69
|
-
'infographic',
|
|
70
|
-
'template',
|
|
71
|
-
'design',
|
|
72
|
-
'data',
|
|
73
|
-
'theme',
|
|
74
|
-
'width',
|
|
75
|
-
'height',
|
|
76
|
-
]);
|
|
77
114
|
Object.keys(mergedEntries).forEach((key) => {
|
|
78
|
-
if (!
|
|
115
|
+
if (!ALLOWED_ROOT_KEYS.has(key)) {
|
|
79
116
|
errors.push({
|
|
80
117
|
path: key,
|
|
81
118
|
line: mergedEntries[key].line,
|
|
@@ -92,6 +129,9 @@ function parseSyntax(input) {
|
|
|
92
129
|
if (!options.template && templateFromInfographic) {
|
|
93
130
|
options.template = templateFromInfographic;
|
|
94
131
|
}
|
|
132
|
+
if (!options.template && inferredTemplate) {
|
|
133
|
+
options.template = inferredTemplate.template;
|
|
134
|
+
}
|
|
95
135
|
const designNode = mergedEntries.design;
|
|
96
136
|
if (designNode) {
|
|
97
137
|
const design = (0, mapper_1.mapWithSchema)(designNode, schema_1.DesignSchema, 'design', errors);
|
|
@@ -114,6 +154,12 @@ function parseSyntax(input) {
|
|
|
114
154
|
const parsed = (0, relations_1.parseRelationsNode)(relationsNode, errors, 'data.relations');
|
|
115
155
|
if (parsed.relations.length > 0 || parsed.items.length > 0) {
|
|
116
156
|
const current = ((_a = options.data) !== null && _a !== void 0 ? _a : {});
|
|
157
|
+
if (Array.isArray(current.items)) {
|
|
158
|
+
assignMissingNodeIds(current.items);
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(current.nodes)) {
|
|
161
|
+
assignMissingNodeIds(current.nodes);
|
|
162
|
+
}
|
|
117
163
|
// 优先使用已存在的数据列表 (sequences, lists, etc.)
|
|
118
164
|
const dataKeys = Object.keys(schema_1.DataSchema.fields).filter((key) => key !== 'items' && key !== 'relations');
|
|
119
165
|
let hasStructuredData = false;
|
package/lib/syntax/mapper.js
CHANGED
|
@@ -12,11 +12,20 @@ function createValueNode(value, line) {
|
|
|
12
12
|
}
|
|
13
13
|
const HEX_COLOR_PATTERN = /^(#[0-9a-f]{8}|#[0-9a-f]{6}|#[0-9a-f]{4}|#[0-9a-f]{3})/i;
|
|
14
14
|
const FUNCTION_COLOR_PATTERN = /^((?:rgb|rgba|hsl|hsla)\([^)]*\))/i;
|
|
15
|
+
function normalizeBooleanLiteral(value) {
|
|
16
|
+
const trimmed = value.trim();
|
|
17
|
+
if (/^true$/i.test(trimmed))
|
|
18
|
+
return 'true';
|
|
19
|
+
if (/^false$/i.test(trimmed))
|
|
20
|
+
return 'false';
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
15
23
|
function parseScalar(value) {
|
|
16
24
|
const trimmed = value.trim();
|
|
17
|
-
|
|
25
|
+
const normalizedBoolean = normalizeBooleanLiteral(trimmed);
|
|
26
|
+
if (normalizedBoolean === 'true')
|
|
18
27
|
return true;
|
|
19
|
-
if (
|
|
28
|
+
if (normalizedBoolean === 'false')
|
|
20
29
|
return false;
|
|
21
30
|
if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
22
31
|
return parseFloat(trimmed);
|
|
@@ -182,11 +191,12 @@ function mapWithSchema(node, schema, path, errors) {
|
|
|
182
191
|
addError(errors, node, path, 'schema_mismatch', 'Expected boolean value.');
|
|
183
192
|
return undefined;
|
|
184
193
|
}
|
|
185
|
-
|
|
194
|
+
const normalizedBoolean = normalizeBooleanLiteral(value);
|
|
195
|
+
if (!normalizedBoolean) {
|
|
186
196
|
addError(errors, node, path, 'invalid_value', 'Invalid boolean value.', value);
|
|
187
197
|
return undefined;
|
|
188
198
|
}
|
|
189
|
-
return
|
|
199
|
+
return normalizedBoolean === 'true';
|
|
190
200
|
}
|
|
191
201
|
case 'enum': {
|
|
192
202
|
const value = readScalar(node);
|
|
@@ -194,11 +204,15 @@ function mapWithSchema(node, schema, path, errors) {
|
|
|
194
204
|
addError(errors, node, path, 'schema_mismatch', 'Expected enum value.');
|
|
195
205
|
return undefined;
|
|
196
206
|
}
|
|
197
|
-
|
|
207
|
+
const normalizedBoolean = normalizeBooleanLiteral(value);
|
|
208
|
+
const enumValue = normalizedBoolean && schema.values.includes(normalizedBoolean)
|
|
209
|
+
? normalizedBoolean
|
|
210
|
+
: value;
|
|
211
|
+
if (!schema.values.includes(enumValue)) {
|
|
198
212
|
addError(errors, node, path, 'invalid_value', 'Invalid enum value.', value);
|
|
199
213
|
return undefined;
|
|
200
214
|
}
|
|
201
|
-
return
|
|
215
|
+
return enumValue;
|
|
202
216
|
}
|
|
203
217
|
case 'array': {
|
|
204
218
|
if (node.kind === 'array') {
|
package/lib/syntax/parser.js
CHANGED
|
@@ -27,6 +27,13 @@ function getIndentInfo(line) {
|
|
|
27
27
|
function stripComments(content) {
|
|
28
28
|
return content.trimEnd();
|
|
29
29
|
}
|
|
30
|
+
function isCommentLine(content) {
|
|
31
|
+
const trimmed = content.trimStart();
|
|
32
|
+
return trimmed.startsWith('#') || trimmed.startsWith('//');
|
|
33
|
+
}
|
|
34
|
+
function isCodeFenceLine(content) {
|
|
35
|
+
return /^```[\w-]*\s*$/.test(content.trim());
|
|
36
|
+
}
|
|
30
37
|
function looksLikeRelationExpression(text) {
|
|
31
38
|
return /[<>=o.x-]{2,}/.test(text);
|
|
32
39
|
}
|
|
@@ -44,6 +51,81 @@ function parseKeyValue(raw) {
|
|
|
44
51
|
}
|
|
45
52
|
return { key: text, value: undefined };
|
|
46
53
|
}
|
|
54
|
+
function isUnsafeObjectKey(key) {
|
|
55
|
+
return key === '__proto__' || key === 'constructor' || key === 'prototype';
|
|
56
|
+
}
|
|
57
|
+
function assignObjectEntry(parent, rawKey, node, line, errors) {
|
|
58
|
+
if (!rawKey.includes('.')) {
|
|
59
|
+
if (isUnsafeObjectKey(rawKey)) {
|
|
60
|
+
errors.push({
|
|
61
|
+
path: rawKey,
|
|
62
|
+
line,
|
|
63
|
+
code: 'bad_syntax',
|
|
64
|
+
message: `Invalid key part: ${rawKey}`,
|
|
65
|
+
raw: rawKey,
|
|
66
|
+
});
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
parent.entries[rawKey] = node;
|
|
70
|
+
return { parent, key: rawKey };
|
|
71
|
+
}
|
|
72
|
+
const parts = rawKey.split('.');
|
|
73
|
+
if (parts.some((part) => !part)) {
|
|
74
|
+
errors.push({
|
|
75
|
+
path: rawKey,
|
|
76
|
+
line,
|
|
77
|
+
code: 'bad_syntax',
|
|
78
|
+
message: 'Invalid dotted key path.',
|
|
79
|
+
raw: rawKey,
|
|
80
|
+
});
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
let current = parent;
|
|
84
|
+
for (let index = 0; index < parts.length - 1; index += 1) {
|
|
85
|
+
const part = parts[index];
|
|
86
|
+
if (isUnsafeObjectKey(part)) {
|
|
87
|
+
errors.push({
|
|
88
|
+
path: rawKey,
|
|
89
|
+
line,
|
|
90
|
+
code: 'bad_syntax',
|
|
91
|
+
message: `Invalid key part in dotted path: ${part}`,
|
|
92
|
+
raw: rawKey,
|
|
93
|
+
});
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const existing = current.entries[part];
|
|
97
|
+
if (!existing) {
|
|
98
|
+
const container = createObjectNode(line);
|
|
99
|
+
current.entries[part] = container;
|
|
100
|
+
current = container;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (existing.kind !== 'object') {
|
|
104
|
+
errors.push({
|
|
105
|
+
path: parts.slice(0, index + 1).join('.'),
|
|
106
|
+
line,
|
|
107
|
+
code: 'bad_syntax',
|
|
108
|
+
message: 'Cannot assign dotted key under a list value.',
|
|
109
|
+
raw: rawKey,
|
|
110
|
+
});
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
current = existing;
|
|
114
|
+
}
|
|
115
|
+
const finalKey = parts[parts.length - 1];
|
|
116
|
+
if (isUnsafeObjectKey(finalKey)) {
|
|
117
|
+
errors.push({
|
|
118
|
+
path: rawKey,
|
|
119
|
+
line,
|
|
120
|
+
code: 'bad_syntax',
|
|
121
|
+
message: `Invalid key part in dotted path: ${finalKey}`,
|
|
122
|
+
raw: rawKey,
|
|
123
|
+
});
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
current.entries[finalKey] = node;
|
|
127
|
+
return { parent: current, key: finalKey };
|
|
128
|
+
}
|
|
47
129
|
function createObjectNode(line, value) {
|
|
48
130
|
return { kind: 'object', line, value, entries: {} };
|
|
49
131
|
}
|
|
@@ -62,6 +144,8 @@ function parseSyntaxToAst(input) {
|
|
|
62
144
|
if (!line.trim())
|
|
63
145
|
return;
|
|
64
146
|
const { indent, content } = getIndentInfo(line);
|
|
147
|
+
if (isCommentLine(content) || isCodeFenceLine(content))
|
|
148
|
+
return;
|
|
65
149
|
const stripped = stripComments(content);
|
|
66
150
|
if (!stripped.trim())
|
|
67
151
|
return;
|
|
@@ -175,12 +259,14 @@ function parseSyntaxToAst(input) {
|
|
|
175
259
|
return;
|
|
176
260
|
}
|
|
177
261
|
const node = createObjectNode(lineNumber, parsed.value);
|
|
178
|
-
parentNode
|
|
262
|
+
const assigned = assignObjectEntry(parentNode, parsed.key, node, lineNumber, errors);
|
|
263
|
+
if (!assigned)
|
|
264
|
+
return;
|
|
179
265
|
stack.push({
|
|
180
266
|
indent,
|
|
181
267
|
node,
|
|
182
|
-
parent:
|
|
183
|
-
key:
|
|
268
|
+
parent: assigned.parent,
|
|
269
|
+
key: assigned.key,
|
|
184
270
|
});
|
|
185
271
|
});
|
|
186
272
|
return { ast: root, errors };
|
package/lib/syntax/types.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface ArrayNode {
|
|
|
16
16
|
line: number;
|
|
17
17
|
items: SyntaxNode[];
|
|
18
18
|
}
|
|
19
|
-
export type SyntaxErrorCode = 'unknown_key' | 'schema_mismatch' | 'invalid_value' | 'bad_indent' | 'bad_list' | 'bad_syntax';
|
|
19
|
+
export type SyntaxErrorCode = 'implicit_template' | 'unknown_key' | 'schema_mismatch' | 'invalid_value' | 'bad_indent' | 'bad_list' | 'bad_syntax';
|
|
20
20
|
export interface SyntaxError {
|
|
21
21
|
path: string;
|
|
22
22
|
line: number;
|
|
@@ -183,7 +183,7 @@ const BUILT_IN_TEMPLATES = Object.assign(Object.assign(Object.assign(Object.assi
|
|
|
183
183
|
}, 'sequence-timeline-plain-text': {
|
|
184
184
|
design: {
|
|
185
185
|
title: 'default',
|
|
186
|
-
structure: { type: 'sequence-timeline' },
|
|
186
|
+
structure: { type: 'sequence-timeline', showStepLabels: false },
|
|
187
187
|
items: [{ type: 'plain-text' }],
|
|
188
188
|
},
|
|
189
189
|
}, 'sequence-timeline-rounded-rect-node': {
|
|
@@ -201,7 +201,7 @@ const BUILT_IN_TEMPLATES = Object.assign(Object.assign(Object.assign(Object.assi
|
|
|
201
201
|
}, 'sequence-timeline-simple': {
|
|
202
202
|
design: {
|
|
203
203
|
title: 'default',
|
|
204
|
-
structure: { type: 'sequence-timeline', gap: 20 },
|
|
204
|
+
structure: { type: 'sequence-timeline', gap: 20, showStepLabels: false },
|
|
205
205
|
items: [{ type: 'simple', positionV: 'middle' }],
|
|
206
206
|
},
|
|
207
207
|
}, 'sequence-cylinders-3d-simple': {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TemplateOptions } from './types';
|
|
2
2
|
export declare function registerTemplate(type: string, template: TemplateOptions): void;
|
|
3
|
+
export declare function resolveTemplateKey(type: string): string | undefined;
|
|
3
4
|
export declare function getTemplate(type: string): TemplateOptions | undefined;
|
|
4
5
|
export declare function getTemplates(): string[];
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerTemplate = registerTemplate;
|
|
4
|
+
exports.resolveTemplateKey = resolveTemplateKey;
|
|
4
5
|
exports.getTemplate = getTemplate;
|
|
5
6
|
exports.getTemplates = getTemplates;
|
|
7
|
+
const utils_1 = require("./utils");
|
|
6
8
|
const TEMPLATE_REGISTRY = new Map();
|
|
7
9
|
function registerTemplate(type, template) {
|
|
8
10
|
TEMPLATE_REGISTRY.set(type, template);
|
|
9
11
|
}
|
|
12
|
+
function resolveTemplateKey(type) {
|
|
13
|
+
if (TEMPLATE_REGISTRY.has(type))
|
|
14
|
+
return type;
|
|
15
|
+
return (0, utils_1.findClosestTemplateKey)(type, TEMPLATE_REGISTRY.keys());
|
|
16
|
+
}
|
|
10
17
|
function getTemplate(type) {
|
|
11
18
|
return TEMPLATE_REGISTRY.get(type);
|
|
12
19
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findClosestTemplateKey(type: string, keys: Iterable<string>): string | undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findClosestTemplateKey = findClosestTemplateKey;
|
|
4
|
+
function normalizeTemplateKey(type) {
|
|
5
|
+
return type
|
|
6
|
+
.trim()
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.replace(/[_\s]+/g, '-')
|
|
9
|
+
.replace(/-+/g, '-');
|
|
10
|
+
}
|
|
11
|
+
function getLevenshteinDistance(source, target) {
|
|
12
|
+
if (source === target)
|
|
13
|
+
return 0;
|
|
14
|
+
if (!source.length)
|
|
15
|
+
return target.length;
|
|
16
|
+
if (!target.length)
|
|
17
|
+
return source.length;
|
|
18
|
+
const previous = Array.from({ length: target.length + 1 }, (_, index) => index);
|
|
19
|
+
const current = new Array(target.length + 1);
|
|
20
|
+
for (let sourceIndex = 1; sourceIndex <= source.length; sourceIndex += 1) {
|
|
21
|
+
current[0] = sourceIndex;
|
|
22
|
+
const sourceCode = source.charCodeAt(sourceIndex - 1);
|
|
23
|
+
for (let targetIndex = 1; targetIndex <= target.length; targetIndex += 1) {
|
|
24
|
+
const replaceCost = sourceCode === target.charCodeAt(targetIndex - 1) ? 0 : 1;
|
|
25
|
+
current[targetIndex] = Math.min(previous[targetIndex] + 1, current[targetIndex - 1] + 1, previous[targetIndex - 1] + replaceCost);
|
|
26
|
+
}
|
|
27
|
+
for (let index = 0; index < current.length; index += 1) {
|
|
28
|
+
previous[index] = current[index];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return previous[target.length];
|
|
32
|
+
}
|
|
33
|
+
function getCommonPrefixLength(source, target) {
|
|
34
|
+
const limit = Math.min(source.length, target.length);
|
|
35
|
+
let index = 0;
|
|
36
|
+
while (index < limit && source[index] === target[index]) {
|
|
37
|
+
index += 1;
|
|
38
|
+
}
|
|
39
|
+
return index;
|
|
40
|
+
}
|
|
41
|
+
function findClosestTemplateKey(type, keys) {
|
|
42
|
+
const normalizedType = normalizeTemplateKey(type);
|
|
43
|
+
if (!normalizedType)
|
|
44
|
+
return undefined;
|
|
45
|
+
let bestMatch;
|
|
46
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
47
|
+
let bestPrefixLength = -1;
|
|
48
|
+
for (const key of keys) {
|
|
49
|
+
const normalizedKey = normalizeTemplateKey(key);
|
|
50
|
+
if (normalizedKey === normalizedType) {
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
const distance = getLevenshteinDistance(normalizedType, normalizedKey);
|
|
54
|
+
const prefixLength = getCommonPrefixLength(normalizedType, normalizedKey);
|
|
55
|
+
if (distance < bestDistance ||
|
|
56
|
+
(distance === bestDistance && prefixLength > bestPrefixLength) ||
|
|
57
|
+
(distance === bestDistance &&
|
|
58
|
+
prefixLength === bestPrefixLength &&
|
|
59
|
+
(!bestMatch || key < bestMatch))) {
|
|
60
|
+
bestMatch = key;
|
|
61
|
+
bestDistance = distance;
|
|
62
|
+
bestPrefixLength = prefixLength;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return bestMatch;
|
|
66
|
+
}
|
package/lib/themes/built-in.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const registry_1 = require("./registry");
|
|
4
|
+
(0, registry_1.registerTheme)('light', {
|
|
5
|
+
colorBg: '#ffffff',
|
|
6
|
+
});
|
|
4
7
|
(0, registry_1.registerTheme)('dark', {
|
|
5
8
|
colorBg: '#1F1F1F',
|
|
6
9
|
base: {
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.
|
|
1
|
+
export declare const VERSION = "0.2.17";
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
package/src/constants/service.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ICON_SERVICE_URL = 'https://
|
|
1
|
+
export const ICON_SERVICE_URL = 'https://lab.weavefox.cn/api/v1/infographic/icon';
|
|
@@ -121,6 +121,8 @@ export const ChartLine: ComponentType<ChartLineProps> = (props) => {
|
|
|
121
121
|
const tickElements: JSXElement[] = [];
|
|
122
122
|
|
|
123
123
|
const ticksY = scaleY.ticks(6);
|
|
124
|
+
const formatTickY = scaleY.tickFormat(6);
|
|
125
|
+
|
|
124
126
|
ticksY.forEach((tick) => {
|
|
125
127
|
const yPos = chartOriginY + scaleY(tick);
|
|
126
128
|
gridElements.push(
|
|
@@ -145,7 +147,7 @@ export const ChartLine: ComponentType<ChartLineProps> = (props) => {
|
|
|
145
147
|
fontSize={12}
|
|
146
148
|
fill={axisColor}
|
|
147
149
|
>
|
|
148
|
-
{
|
|
150
|
+
{formatTickY(tick)}
|
|
149
151
|
</Text>,
|
|
150
152
|
);
|
|
151
153
|
});
|