-
Notifications
You must be signed in to change notification settings - Fork 501
/
common.ts
113 lines (107 loc) · 2.21 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
export interface IPureNode {
/**
* HTML of the node content.
*/
content: string;
/**
* Additional data created on transformation.
*/
payload?: {
[key: string]: unknown;
/**
* The folding status of this node.
*
* 0 - not folded
* 1 - folded
* 2 - folded along with all its child nodes
*/
fold?: number;
};
children: IPureNode[];
}
export interface INode extends IPureNode {
/**
* Store temporary data that helps rendering.
*/
state: INodeState;
children: INode[];
}
export interface INodeState {
/**
* An auto-increment unique ID for each node.
*/
id: number;
/**
* A dot separated sequence of the node and its ancestors.
*/
path: string;
/**
* The unique identifier of a node, supposed to be based on content.
*/
key: string;
depth: number;
el: HTMLElement;
x0: number;
y0: number;
size: [width: number, height: number];
}
export type JSScriptItem = {
type: 'script';
loaded?: Promise<void>;
data: {
src?: string;
textContent?: string;
async?: boolean;
defer?: boolean;
};
};
export type JSIIFEItem = {
type: 'iife';
loaded?: Promise<void>;
data: {
fn: (...args: unknown[]) => void;
getParams?: (context: unknown) => void | unknown[];
};
};
export type JSItem = JSScriptItem | JSIIFEItem;
export type CSSStyleItem = {
type: 'style';
loaded?: Promise<void>;
data: string;
};
export type CSSStylesheetItem = {
type: 'stylesheet';
loaded?: Promise<void>;
data: {
href: string;
};
};
export type CSSItem = CSSStyleItem | CSSStylesheetItem;
export interface IDeferred<T> {
promise: Promise<T>;
resolve: (value: T) => void;
reject: (error?: unknown) => void;
}
export interface IMarkmapOptions {
id?: string;
autoFit: boolean;
color: (node: INode) => string;
duration: number;
embedGlobalCSS: boolean;
fitRatio: number;
maxWidth: number;
nodeMinHeight: number;
paddingX: number;
scrollForPan: boolean;
spacingHorizontal: number;
spacingVertical: number;
initialExpandLevel: number;
zoom: boolean;
pan: boolean;
toggleRecursively: boolean;
style?: (id: string) => string;
}
export interface IAssets {
styles?: CSSItem[];
scripts?: JSItem[];
}