@antv/infographic 0.1.3 → 0.2.0
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 +54 -40
- package/README.zh-CN.md +52 -36
- package/dist/infographic.min.js +110 -105
- package/dist/infographic.min.js.map +1 -1
- package/esm/constants/element.d.ts +1 -1
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +1 -0
- package/esm/constants/service.d.ts +1 -0
- package/esm/constants/service.js +1 -0
- package/esm/designs/components/Illus.js +1 -1
- package/esm/designs/structures/chart-wordcloud.d.ts +11 -0
- package/esm/designs/structures/chart-wordcloud.js +156 -0
- package/esm/designs/structures/hierarchy-tree.d.ts +2 -0
- package/esm/designs/structures/hierarchy-tree.js +179 -50
- package/esm/designs/structures/index.d.ts +2 -0
- package/esm/designs/structures/index.js +2 -0
- package/esm/designs/structures/sequence-stairs-front.d.ts +8 -0
- package/esm/designs/structures/sequence-stairs-front.js +116 -0
- package/esm/designs/types.d.ts +8 -0
- package/esm/editor/managers/state.js +1 -1
- package/esm/exporter/font.js +4 -9
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/options/parser.d.ts +1 -1
- package/esm/options/parser.js +33 -15
- package/esm/renderer/composites/icon.js +1 -1
- package/esm/renderer/composites/illus.js +1 -1
- package/esm/resource/loader.d.ts +2 -2
- package/esm/resource/loader.js +22 -11
- package/esm/resource/loaders/index.d.ts +1 -0
- package/esm/resource/loaders/index.js +1 -0
- package/esm/resource/loaders/remote.d.ts +1 -1
- package/esm/resource/loaders/remote.js +12 -3
- package/esm/resource/loaders/search.d.ts +1 -0
- package/esm/resource/loaders/search.js +52 -0
- package/esm/resource/types/index.d.ts +1 -0
- package/esm/resource/types/resource.d.ts +8 -1
- package/esm/resource/types/scene.d.ts +1 -0
- package/esm/resource/utils/data-uri.js +20 -11
- package/esm/resource/utils/parser.js +92 -1
- package/esm/resource/utils/ref.js +2 -2
- package/esm/runtime/Infographic.d.ts +10 -6
- package/esm/runtime/Infographic.js +66 -17
- package/esm/runtime/utils.d.ts +4 -2
- package/esm/runtime/utils.js +33 -13
- package/esm/syntax/index.d.ts +3 -0
- package/esm/syntax/index.js +101 -0
- package/esm/syntax/mapper.d.ts +3 -0
- package/esm/syntax/mapper.js +334 -0
- package/esm/syntax/parser.d.ts +14 -0
- package/esm/syntax/parser.js +142 -0
- package/esm/syntax/schema.d.ts +6 -0
- package/esm/syntax/schema.js +86 -0
- package/esm/syntax/types.d.ts +68 -0
- package/esm/syntax/types.js +1 -0
- package/esm/templates/built-in.js +4 -0
- package/esm/templates/hierarchy-tree.js +25 -11
- package/esm/templates/sequence-stairs.d.ts +2 -0
- package/esm/templates/sequence-stairs.js +42 -0
- package/esm/templates/word-cloud.d.ts +2 -0
- package/esm/templates/word-cloud.js +19 -0
- package/esm/themes/types.d.ts +1 -1
- package/esm/utils/design.d.ts +2 -0
- package/esm/utils/design.js +10 -0
- package/esm/utils/fetch.d.ts +1 -0
- package/esm/utils/fetch.js +61 -0
- package/esm/utils/font.js +11 -1
- package/esm/utils/index.d.ts +2 -0
- package/esm/utils/index.js +2 -0
- package/lib/constants/element.d.ts +1 -1
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/constants/service.d.ts +1 -0
- package/lib/constants/service.js +4 -0
- package/lib/designs/components/Illus.js +1 -1
- package/lib/designs/structures/chart-wordcloud.d.ts +11 -0
- package/lib/designs/structures/chart-wordcloud.js +160 -0
- package/lib/designs/structures/hierarchy-tree.d.ts +2 -0
- package/lib/designs/structures/hierarchy-tree.js +179 -50
- package/lib/designs/structures/index.d.ts +2 -0
- package/lib/designs/structures/index.js +2 -0
- package/lib/designs/structures/sequence-stairs-front.d.ts +8 -0
- package/lib/designs/structures/sequence-stairs-front.js +120 -0
- package/lib/designs/types.d.ts +8 -0
- package/lib/editor/managers/state.js +1 -1
- package/lib/exporter/font.js +3 -8
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -1
- package/lib/options/parser.d.ts +1 -1
- package/lib/options/parser.js +32 -14
- package/lib/renderer/composites/icon.js +1 -1
- package/lib/renderer/composites/illus.js +1 -1
- package/lib/resource/loader.d.ts +2 -2
- package/lib/resource/loader.js +21 -10
- package/lib/resource/loaders/index.d.ts +1 -0
- package/lib/resource/loaders/index.js +1 -0
- package/lib/resource/loaders/remote.d.ts +1 -1
- package/lib/resource/loaders/remote.js +12 -3
- package/lib/resource/loaders/search.d.ts +1 -0
- package/lib/resource/loaders/search.js +55 -0
- package/lib/resource/types/index.d.ts +1 -0
- package/lib/resource/types/resource.d.ts +8 -1
- package/lib/resource/types/scene.d.ts +1 -0
- package/lib/resource/utils/data-uri.js +20 -11
- package/lib/resource/utils/parser.js +92 -1
- package/lib/resource/utils/ref.js +2 -2
- package/lib/runtime/Infographic.d.ts +10 -6
- package/lib/runtime/Infographic.js +65 -16
- package/lib/runtime/utils.d.ts +4 -2
- package/lib/runtime/utils.js +35 -13
- package/lib/syntax/index.d.ts +3 -0
- package/lib/syntax/index.js +104 -0
- package/lib/syntax/mapper.d.ts +3 -0
- package/lib/syntax/mapper.js +341 -0
- package/lib/syntax/parser.d.ts +14 -0
- package/lib/syntax/parser.js +146 -0
- package/lib/syntax/schema.d.ts +6 -0
- package/lib/syntax/schema.js +89 -0
- package/lib/syntax/types.d.ts +68 -0
- package/lib/syntax/types.js +2 -0
- package/lib/templates/built-in.js +4 -0
- package/lib/templates/hierarchy-tree.js +25 -11
- package/lib/templates/sequence-stairs.d.ts +2 -0
- package/lib/templates/sequence-stairs.js +45 -0
- package/lib/templates/word-cloud.d.ts +2 -0
- package/lib/templates/word-cloud.js +22 -0
- package/lib/themes/types.d.ts +1 -1
- package/lib/utils/design.d.ts +2 -0
- package/lib/utils/design.js +13 -0
- package/lib/utils/fetch.d.ts +1 -0
- package/lib/utils/fetch.js +67 -0
- package/lib/utils/font.js +11 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +2 -0
- package/package.json +14 -2
- package/src/constants/element.ts +1 -1
- package/src/constants/index.ts +1 -0
- package/src/constants/service.ts +1 -0
- package/src/designs/components/Illus.tsx +1 -1
- package/src/designs/structures/chart-wordcloud.tsx +278 -0
- package/src/designs/structures/hierarchy-tree.tsx +212 -59
- package/src/designs/structures/index.ts +2 -0
- package/src/designs/structures/sequence-stairs-front.tsx +291 -0
- package/src/designs/types.ts +9 -0
- package/src/editor/managers/state.ts +1 -1
- package/src/exporter/font.ts +4 -9
- package/src/index.ts +2 -0
- package/src/options/parser.ts +57 -28
- package/src/renderer/composites/icon.ts +1 -1
- package/src/renderer/composites/illus.ts +1 -1
- package/src/resource/loader.ts +22 -8
- package/src/resource/loaders/index.ts +1 -0
- package/src/resource/loaders/remote.ts +11 -3
- package/src/resource/loaders/search.ts +53 -0
- package/src/resource/types/index.ts +2 -1
- package/src/resource/types/resource.ts +12 -1
- package/src/resource/types/scene.ts +1 -0
- package/src/resource/utils/data-uri.ts +20 -11
- package/src/resource/utils/parser.ts +103 -2
- package/src/resource/utils/ref.ts +2 -2
- package/src/runtime/Infographic.tsx +103 -22
- package/src/runtime/utils.ts +38 -16
- package/src/syntax/index.ts +124 -0
- package/src/syntax/mapper.ts +496 -0
- package/src/syntax/parser.ts +171 -0
- package/src/syntax/schema.ts +112 -0
- package/src/syntax/types.ts +100 -0
- package/src/templates/built-in.ts +4 -0
- package/src/templates/hierarchy-tree.ts +34 -11
- package/src/templates/sequence-stairs.ts +44 -0
- package/src/templates/word-cloud.ts +21 -0
- package/src/themes/types.ts +1 -1
- package/src/utils/design.ts +14 -0
- package/src/utils/fetch.ts +90 -0
- package/src/utils/font.ts +11 -1
- package/src/utils/index.ts +2 -0
- package/esm/resource/types/font.d.ts +0 -12
- package/lib/resource/types/font.d.ts +0 -12
- package/src/resource/types/font.ts +0 -23
- /package/esm/resource/types/{font.js → scene.js} +0 -0
- /package/lib/resource/types/{font.js → scene.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ObjectSchema, SchemaNode } from './types';
|
|
2
|
+
|
|
3
|
+
const string = (): SchemaNode => ({ kind: 'string' });
|
|
4
|
+
const number = (): SchemaNode => ({ kind: 'number' });
|
|
5
|
+
// const boolean = (): SchemaNode => ({ kind: 'boolean' });
|
|
6
|
+
const enumOf = (values: string[]): SchemaNode => ({ kind: 'enum', values });
|
|
7
|
+
const color = (options: { soft?: boolean } = {}): SchemaNode => ({
|
|
8
|
+
kind: 'color',
|
|
9
|
+
soft: options.soft,
|
|
10
|
+
});
|
|
11
|
+
const array = (item: SchemaNode, split: 'space' | 'comma' | 'any' = 'any') => ({
|
|
12
|
+
kind: 'array' as const,
|
|
13
|
+
item,
|
|
14
|
+
split,
|
|
15
|
+
});
|
|
16
|
+
const object = (
|
|
17
|
+
fields: Record<string, SchemaNode>,
|
|
18
|
+
options: { allowUnknown?: boolean; shorthandKey?: string } = {},
|
|
19
|
+
): ObjectSchema => ({
|
|
20
|
+
kind: 'object',
|
|
21
|
+
fields,
|
|
22
|
+
allowUnknown: options.allowUnknown,
|
|
23
|
+
shorthandKey: options.shorthandKey,
|
|
24
|
+
});
|
|
25
|
+
const union = (...variants: SchemaNode[]): SchemaNode => ({
|
|
26
|
+
kind: 'union',
|
|
27
|
+
variants,
|
|
28
|
+
});
|
|
29
|
+
const palette = (): SchemaNode => ({ kind: 'palette' });
|
|
30
|
+
|
|
31
|
+
const nullableColorFields = {
|
|
32
|
+
fill: color({ soft: true }),
|
|
33
|
+
stroke: color({ soft: true }),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const textStyleSchema = object(nullableColorFields, { allowUnknown: true });
|
|
37
|
+
const shapeStyleSchema = object(nullableColorFields, { allowUnknown: true });
|
|
38
|
+
|
|
39
|
+
const itemDatumSchema: ObjectSchema = object({}, { allowUnknown: true });
|
|
40
|
+
itemDatumSchema.fields = {
|
|
41
|
+
label: string(),
|
|
42
|
+
value: union(number(), string()),
|
|
43
|
+
desc: string(),
|
|
44
|
+
icon: string(),
|
|
45
|
+
children: array(itemDatumSchema),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const ThemeSchema = object(
|
|
49
|
+
{
|
|
50
|
+
type: string(),
|
|
51
|
+
colorBg: color(),
|
|
52
|
+
colorPrimary: color(),
|
|
53
|
+
palette: palette(),
|
|
54
|
+
title: textStyleSchema,
|
|
55
|
+
desc: textStyleSchema,
|
|
56
|
+
shape: shapeStyleSchema,
|
|
57
|
+
base: object({
|
|
58
|
+
global: object({}, { allowUnknown: true }),
|
|
59
|
+
shape: shapeStyleSchema,
|
|
60
|
+
text: textStyleSchema,
|
|
61
|
+
}),
|
|
62
|
+
stylize: object(
|
|
63
|
+
{
|
|
64
|
+
type: enumOf(['rough', 'pattern']),
|
|
65
|
+
roughness: number(),
|
|
66
|
+
bowing: number(),
|
|
67
|
+
fillWeight: number(),
|
|
68
|
+
hachureGap: number(),
|
|
69
|
+
pattern: string(),
|
|
70
|
+
backgroundColor: color(),
|
|
71
|
+
foregroundColor: color(),
|
|
72
|
+
scale: number(),
|
|
73
|
+
},
|
|
74
|
+
{ shorthandKey: 'type' },
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
{ shorthandKey: 'type' },
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const designNodeSchema = object(
|
|
81
|
+
{},
|
|
82
|
+
{ allowUnknown: true, shorthandKey: 'type' },
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export const DesignSchema = object({
|
|
86
|
+
structure: designNodeSchema,
|
|
87
|
+
item: designNodeSchema,
|
|
88
|
+
items: array(designNodeSchema),
|
|
89
|
+
title: designNodeSchema,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const DataSchema = object({
|
|
93
|
+
title: string(),
|
|
94
|
+
desc: string(),
|
|
95
|
+
items: array(itemDatumSchema),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const TemplateSchema = object(
|
|
99
|
+
{
|
|
100
|
+
type: string(),
|
|
101
|
+
},
|
|
102
|
+
{ shorthandKey: 'type' },
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
export const RootSchema = object({
|
|
106
|
+
template: TemplateSchema,
|
|
107
|
+
design: DesignSchema,
|
|
108
|
+
data: DataSchema,
|
|
109
|
+
theme: ThemeSchema,
|
|
110
|
+
width: union(number(), string()),
|
|
111
|
+
height: union(number(), string()),
|
|
112
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { InfographicOptions } from '../options';
|
|
2
|
+
|
|
3
|
+
export type SyntaxNode = ValueNode | ObjectNode | ArrayNode;
|
|
4
|
+
|
|
5
|
+
export interface ValueNode {
|
|
6
|
+
kind: 'value';
|
|
7
|
+
line: number;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ObjectNode {
|
|
12
|
+
kind: 'object';
|
|
13
|
+
line: number;
|
|
14
|
+
value?: string;
|
|
15
|
+
entries: Record<string, SyntaxNode>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ArrayNode {
|
|
19
|
+
kind: 'array';
|
|
20
|
+
line: number;
|
|
21
|
+
items: SyntaxNode[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type SyntaxErrorCode =
|
|
25
|
+
| 'unknown_key'
|
|
26
|
+
| 'schema_mismatch'
|
|
27
|
+
| 'invalid_value'
|
|
28
|
+
| 'bad_indent'
|
|
29
|
+
| 'bad_list'
|
|
30
|
+
| 'bad_syntax';
|
|
31
|
+
|
|
32
|
+
export interface SyntaxError {
|
|
33
|
+
path: string;
|
|
34
|
+
line: number;
|
|
35
|
+
code: SyntaxErrorCode;
|
|
36
|
+
message: string;
|
|
37
|
+
raw?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SyntaxParseResult {
|
|
41
|
+
options: Partial<InfographicOptions>;
|
|
42
|
+
errors: SyntaxError[];
|
|
43
|
+
warnings: SyntaxError[];
|
|
44
|
+
ast?: ObjectNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SchemaNode =
|
|
48
|
+
| StringSchema
|
|
49
|
+
| NumberSchema
|
|
50
|
+
| BooleanSchema
|
|
51
|
+
| EnumSchema
|
|
52
|
+
| ArraySchema
|
|
53
|
+
| ObjectSchema
|
|
54
|
+
| UnionSchema
|
|
55
|
+
| PaletteSchema
|
|
56
|
+
| ColorSchema;
|
|
57
|
+
|
|
58
|
+
export interface StringSchema {
|
|
59
|
+
kind: 'string';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface NumberSchema {
|
|
63
|
+
kind: 'number';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface BooleanSchema {
|
|
67
|
+
kind: 'boolean';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface EnumSchema {
|
|
71
|
+
kind: 'enum';
|
|
72
|
+
values: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ArraySchema {
|
|
76
|
+
kind: 'array';
|
|
77
|
+
item: SchemaNode;
|
|
78
|
+
split?: 'space' | 'comma' | 'any';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ObjectSchema {
|
|
82
|
+
kind: 'object';
|
|
83
|
+
fields: Record<string, SchemaNode>;
|
|
84
|
+
allowUnknown?: boolean;
|
|
85
|
+
shorthandKey?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface UnionSchema {
|
|
89
|
+
kind: 'union';
|
|
90
|
+
variants: SchemaNode[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface PaletteSchema {
|
|
94
|
+
kind: 'palette';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ColorSchema {
|
|
98
|
+
kind: 'color';
|
|
99
|
+
soft?: boolean;
|
|
100
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { hierarchyMindmapTemplates } from './hierarchy-mindmap';
|
|
2
2
|
import { hierarchyTreeTemplates } from './hierarchy-tree';
|
|
3
3
|
import { registerTemplate } from './registry';
|
|
4
|
+
import { sequenceStairsTemplates } from './sequence-stairs';
|
|
4
5
|
import type { TemplateOptions } from './types';
|
|
6
|
+
import { wordCloudTemplate } from './word-cloud';
|
|
5
7
|
|
|
6
8
|
const BUILT_IN_TEMPLATES: Record<string, TemplateOptions> = {
|
|
7
9
|
'compare-hierarchy-left-right-circle-node-pill-badge': {
|
|
@@ -803,6 +805,8 @@ const BUILT_IN_TEMPLATES: Record<string, TemplateOptions> = {
|
|
|
803
805
|
},
|
|
804
806
|
...hierarchyTreeTemplates,
|
|
805
807
|
...hierarchyMindmapTemplates,
|
|
808
|
+
...sequenceStairsTemplates,
|
|
809
|
+
...wordCloudTemplate,
|
|
806
810
|
};
|
|
807
811
|
|
|
808
812
|
Object.entries(BUILT_IN_TEMPLATES).forEach(([name, options]) => {
|
|
@@ -52,19 +52,42 @@ const items: string[] = [
|
|
|
52
52
|
export const hierarchyTreeTemplates: Record<string, TemplateOptions> = {};
|
|
53
53
|
|
|
54
54
|
const structureName = 'hierarchy-tree';
|
|
55
|
+
const orientationConfigs: Array<{
|
|
56
|
+
key: string;
|
|
57
|
+
orientation?: HierarchyTreeProps['orientation'];
|
|
58
|
+
}> = [
|
|
59
|
+
{ key: '' },
|
|
60
|
+
{ key: 'bt', orientation: 'bottom-top' },
|
|
61
|
+
{ key: 'lr', orientation: 'left-right' },
|
|
62
|
+
{ key: 'rl', orientation: 'right-left' },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const createTemplateName = (
|
|
66
|
+
oriKey: string,
|
|
67
|
+
name: string,
|
|
68
|
+
item: string,
|
|
69
|
+
): string => {
|
|
70
|
+
return oriKey
|
|
71
|
+
? `${structureName}-${oriKey}-${name}-${item}`
|
|
72
|
+
: `${structureName}-${name}-${item}`;
|
|
73
|
+
};
|
|
74
|
+
|
|
55
75
|
for (const item of items) {
|
|
56
76
|
for (const [name, structureProps] of Object.entries(structures)) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
for (const { key, orientation } of orientationConfigs) {
|
|
78
|
+
const templateName = createTemplateName(key, name, item);
|
|
79
|
+
hierarchyTreeTemplates[templateName] = {
|
|
80
|
+
design: {
|
|
81
|
+
structure: {
|
|
82
|
+
type: 'hierarchy-tree',
|
|
83
|
+
...(orientation ? { orientation } : {}),
|
|
84
|
+
...structureProps,
|
|
85
|
+
},
|
|
86
|
+
item: {
|
|
87
|
+
type: item,
|
|
88
|
+
},
|
|
66
89
|
},
|
|
67
|
-
}
|
|
68
|
-
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
69
92
|
}
|
|
70
93
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TemplateOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export const sequenceStairsTemplates: Record<string, TemplateOptions> = {
|
|
4
|
+
'sequence-stairs-front-pill-badge': {
|
|
5
|
+
design: {
|
|
6
|
+
title: 'default',
|
|
7
|
+
structure: {
|
|
8
|
+
type: 'sequence-stairs-front',
|
|
9
|
+
},
|
|
10
|
+
items: [
|
|
11
|
+
{
|
|
12
|
+
type: 'pill-badge',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
'sequence-stairs-front-compact-card': {
|
|
18
|
+
design: {
|
|
19
|
+
title: 'default',
|
|
20
|
+
structure: {
|
|
21
|
+
type: 'sequence-stairs-front',
|
|
22
|
+
},
|
|
23
|
+
items: [
|
|
24
|
+
{
|
|
25
|
+
type: 'compact-card',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
'sequence-stairs-front-simple': {
|
|
31
|
+
design: {
|
|
32
|
+
title: 'default',
|
|
33
|
+
structure: {
|
|
34
|
+
type: 'sequence-stairs-front',
|
|
35
|
+
},
|
|
36
|
+
items: [
|
|
37
|
+
{
|
|
38
|
+
type: 'simple',
|
|
39
|
+
usePaletteColor: true,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TemplateOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export const wordCloudTemplate: Record<string, TemplateOptions> = {
|
|
4
|
+
'chart-wordcloud-rotate': {
|
|
5
|
+
design: {
|
|
6
|
+
structure: {
|
|
7
|
+
type: 'chart-wordcloud',
|
|
8
|
+
},
|
|
9
|
+
item: 'simple',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
'chart-wordcloud': {
|
|
13
|
+
design: {
|
|
14
|
+
structure: {
|
|
15
|
+
type: 'chart-wordcloud',
|
|
16
|
+
enableRotate: false,
|
|
17
|
+
},
|
|
18
|
+
item: 'simple',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
package/src/themes/types.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface ThemeConfig {
|
|
|
29
29
|
palette?: Palette;
|
|
30
30
|
title?: TextAttributes;
|
|
31
31
|
desc?: TextAttributes;
|
|
32
|
-
shape?:
|
|
32
|
+
shape?: ShapeAttributes;
|
|
33
33
|
item?: {
|
|
34
34
|
icon?: DynamicAttributes<IconAttributes>;
|
|
35
35
|
label?: DynamicAttributes<TextAttributes>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NullableParsedDesignsOptions,
|
|
3
|
+
ParsedDesignsOptions,
|
|
4
|
+
} from '../designs';
|
|
5
|
+
|
|
6
|
+
export function isNonNullableParsedDesignsOptions(
|
|
7
|
+
options: NullableParsedDesignsOptions,
|
|
8
|
+
): options is ParsedDesignsOptions {
|
|
9
|
+
const { structure, item, items } = options;
|
|
10
|
+
if (!structure) return false;
|
|
11
|
+
if (!item) return false;
|
|
12
|
+
if (items.some((it) => !it)) return false;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import flru from 'flru';
|
|
2
|
+
|
|
3
|
+
type FetchFunction = (
|
|
4
|
+
input: RequestInfo | URL,
|
|
5
|
+
init?: RequestInit,
|
|
6
|
+
) => Promise<Response>;
|
|
7
|
+
|
|
8
|
+
interface CachedResponseEntry {
|
|
9
|
+
body: ArrayBuffer;
|
|
10
|
+
init: ResponseInit;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const nativeFetch: FetchFunction = globalThis.fetch;
|
|
14
|
+
|
|
15
|
+
const CACHE_MAX_ENTRIES = 1024;
|
|
16
|
+
|
|
17
|
+
const responseCache = flru<CachedResponseEntry>(CACHE_MAX_ENTRIES);
|
|
18
|
+
const pendingRequests = new Map<string, Promise<CachedResponseEntry>>();
|
|
19
|
+
|
|
20
|
+
function buildHeadersKey(request: Request) {
|
|
21
|
+
const entries = Array.from(request.headers.entries());
|
|
22
|
+
if (entries.length === 0) return '';
|
|
23
|
+
|
|
24
|
+
entries.sort(([nameA], [nameB]) =>
|
|
25
|
+
nameA.toLowerCase().localeCompare(nameB.toLowerCase()),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return entries
|
|
29
|
+
.map(([name, value]) => `${name.toLowerCase()}:${value}`)
|
|
30
|
+
.join('|');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildCacheKey(request: Request) {
|
|
34
|
+
const headersKey = buildHeadersKey(request);
|
|
35
|
+
return headersKey
|
|
36
|
+
? `${request.method}:${request.url}:${headersKey}`
|
|
37
|
+
: `${request.method}:${request.url}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildResponse(entry: CachedResponseEntry) {
|
|
41
|
+
return new Response(entry.body.slice(0), entry.init);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function fetchAndCache(request: Request, key: string) {
|
|
45
|
+
try {
|
|
46
|
+
const response = await nativeFetch(request);
|
|
47
|
+
const body = await response.arrayBuffer();
|
|
48
|
+
const entry: CachedResponseEntry = {
|
|
49
|
+
body,
|
|
50
|
+
init: {
|
|
51
|
+
status: response.status,
|
|
52
|
+
statusText: response.statusText,
|
|
53
|
+
headers: Array.from(response.headers.entries()),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (response.ok) {
|
|
58
|
+
responseCache.set(key, entry);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return entry;
|
|
62
|
+
} finally {
|
|
63
|
+
pendingRequests.delete(key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function fetchWithCache(
|
|
68
|
+
input: RequestInfo | URL,
|
|
69
|
+
init?: RequestInit,
|
|
70
|
+
) {
|
|
71
|
+
const request = new Request(input, init);
|
|
72
|
+
if (request.method !== 'GET') {
|
|
73
|
+
return nativeFetch(request);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const key = buildCacheKey(request);
|
|
77
|
+
|
|
78
|
+
if (responseCache.has(key)) {
|
|
79
|
+
return buildResponse(responseCache.get(key)!);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let pending = pendingRequests.get(key);
|
|
83
|
+
if (!pending) {
|
|
84
|
+
pending = fetchAndCache(request, key);
|
|
85
|
+
pendingRequests.set(key, pending);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const entry = await pending;
|
|
89
|
+
return buildResponse(entry);
|
|
90
|
+
}
|
package/src/utils/font.ts
CHANGED
|
@@ -14,21 +14,31 @@ export function encodeFontFamily(font: string) {
|
|
|
14
14
|
const FontWeightNameMap: Record<string, FontWeightName> = {
|
|
15
15
|
'100': 'thin',
|
|
16
16
|
hairline: 'thin',
|
|
17
|
+
thin: 'thin',
|
|
17
18
|
'200': 'extralight',
|
|
18
19
|
ultralight: 'extralight',
|
|
20
|
+
extralight: 'extralight',
|
|
19
21
|
'300': 'light',
|
|
22
|
+
light: 'light',
|
|
20
23
|
'400': 'regular',
|
|
21
24
|
normal: 'regular',
|
|
25
|
+
regular: 'regular',
|
|
22
26
|
'500': 'medium',
|
|
27
|
+
medium: 'medium',
|
|
23
28
|
'600': 'semibold',
|
|
24
29
|
demibold: 'semibold',
|
|
30
|
+
semibold: 'semibold',
|
|
25
31
|
'700': 'bold',
|
|
32
|
+
bold: 'bold',
|
|
26
33
|
'800': 'extrabold',
|
|
27
|
-
ultrabold: '
|
|
34
|
+
ultrabold: 'extrabold',
|
|
35
|
+
extrabold: 'extrabold',
|
|
28
36
|
'900': 'black',
|
|
29
37
|
heavy: 'black',
|
|
38
|
+
black: 'black',
|
|
30
39
|
'950': 'extrablack',
|
|
31
40
|
ultrablack: 'extrablack',
|
|
41
|
+
extrablack: 'extrablack',
|
|
32
42
|
};
|
|
33
43
|
|
|
34
44
|
export function normalizeFontWeightName(
|
package/src/utils/index.ts
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
|
|
3
|
-
*/
|
|
4
|
-
export type FontWeightName = 'thin' | 'extralight' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 'extrablack';
|
|
5
|
-
export interface Font {
|
|
6
|
-
font: string;
|
|
7
|
-
name: string;
|
|
8
|
-
/** 字体 CDN */
|
|
9
|
-
fontWeight: {
|
|
10
|
-
[keys in FontWeightName]?: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
|
|
3
|
-
*/
|
|
4
|
-
export type FontWeightName = 'thin' | 'extralight' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 'extrablack';
|
|
5
|
-
export interface Font {
|
|
6
|
-
font: string;
|
|
7
|
-
name: string;
|
|
8
|
-
/** 字体 CDN */
|
|
9
|
-
fontWeight: {
|
|
10
|
-
[keys in FontWeightName]?: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
|
|
3
|
-
*/
|
|
4
|
-
export type FontWeightName =
|
|
5
|
-
| 'thin'
|
|
6
|
-
| 'extralight'
|
|
7
|
-
| 'light'
|
|
8
|
-
| 'regular'
|
|
9
|
-
| 'medium'
|
|
10
|
-
| 'semibold'
|
|
11
|
-
| 'bold'
|
|
12
|
-
| 'extrabold'
|
|
13
|
-
| 'black'
|
|
14
|
-
| 'extrablack';
|
|
15
|
-
|
|
16
|
-
export interface Font {
|
|
17
|
-
font: string;
|
|
18
|
-
name: string;
|
|
19
|
-
/** 字体 CDN */
|
|
20
|
-
fontWeight: {
|
|
21
|
-
[keys in FontWeightName]?: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
File without changes
|
|
File without changes
|