-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrow-config.ts
187 lines (158 loc) · 3.82 KB
/
row-config.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { parseFromRawInfoGenerator } from '@bluelovers/auto1111-pnginfo';
import { logger } from './logger';
import { other_syntax_lang, syntaxHighlighter } from './highlighter';
type IDecodeFn = (value: string, key: string) => string | PromiseLike<string>
interface ISyntaxHighlighterFn
{
<T extends any>(code: T, opts?: IRowConfigOptions, key?: string): string | PromiseLike<string>
// (code: string, opts?: IRowConfigOptions, key?: string): string | PromiseLike<string>
(code: any, opts?: IRowConfigOptions, key?: string): string | PromiseLike<string>
}
export interface IRowConfigOptions
{
full?: boolean,
syntaxHighlighter?: boolean | ISyntaxHighlighterFn,
syntaxLang?: 'prompt' | 'json5' | 'javascript',
syntaxTheme?: 'dark' | 'dracula' | 'material-theme',
formatFn?: IDecodeFn,
decode?: boolean | IDecodeFn,
disableEscapeHTML?: boolean,
}
export const RowConfigMap = new Map<string, IRowConfigOptions>();
export const RowConfigMapRegExp = new Map<RegExp, IRowConfigOptions>();
[
'Positive Prompt',
'Negative Prompt',
].forEach(key => RowConfigMap.set(key, {
full: true,
syntaxHighlighter: true,
}));
[
'sv_prompt',
'sv_negative',
'Template',
'Template Generated',
'Wildcard Prompt',
].forEach(key => RowConfigMap.set(key, {
full: true,
syntaxHighlighter: true,
decode: true,
}));
[
'Template Generated Grid',
//'Dynamic Prompts',
].forEach(key => RowConfigMap.set(key, {
full: true,
decode: true,
async syntaxHighlighter(ls: string[])
{
ls = await Promise.all([ls].flat().map(value =>
{
return syntaxHighlighter(value);
}))
return ls.join('<hr class="shiki_infotext_hr"/>');
},
formatFn(value, key)
{
if (key === 'Template Generated Grid')
{
//return JSON.stringify(value, null, 2)
}
return value
}
}));
/*
[
///^ControlNet \d+$/
].forEach(key => RowConfigMapRegExp.set(key, {
full: true,
decode: true,
syntaxHighlighter: true,
syntaxLang: 'json5',
formatFn(value, key)
{
let map = parseFromRawInfo(value);
return JSON.stringify(map)
}
}));
*/
[
'TI hashes',
'Lora hashes',
].forEach(key => RowConfigMap.set(key, {
decode: decodeHashs,
disableEscapeHTML: true,
}));
[
'Model hash',
'Model',
'VAE hash',
'VAE',
'ADetailer model',
].forEach(key => RowConfigMap.set(key, {
decode: simpleSearch,
disableEscapeHTML: true,
}));
[
/^ADetailer model \d+\w*$/,
].forEach(key => RowConfigMapRegExp.set(key, {
decode: simpleSearch,
disableEscapeHTML: true,
}));
[
'Hashes',
'Civitai resources',
'Civitai metadata',
].forEach(key => RowConfigMap.set(key, {
decode: true,
disableEscapeHTML: true,
formatFn(value, key)
{
return _decodeHashsCore(Object.entries(value))
}
}));
[
'Dynamic Prompts',
].forEach(key => RowConfigMap.set(key, {
decode: true,
syntaxHighlighter: true,
syntaxLang: other_syntax_lang,
formatFn(value, key)
{
return JSON.stringify(value)
}
}));
function simpleSearch(value: string)
{
return `<span>${value}</span> ${_search(value)}`
}
function _search(query: unknown, text = '🔎')
{
const href = `https://civitai.com/search/models?sortBy=models_v9&query=${query}`;
return `<a href="${href}" target="_blank">${text}</a>`
}
function decodeHashs(input: string)
{
return _decodeHashsCore(parseFromRawInfoGenerator(JSON.parse(input)))
}
function _decodeHashsCore(input: [string, string][] | Generator<any>)
{
const list: string[] = [];
for (const [key, value] of input)
{
list.push(`<div>${_search(key, '🔍')} <span style="color:#C3E88D">${key}</span>: <span style="color:#FF9CAC">${value}</span> ${_search(value)}</div>`)
}
return list.join('')
}
function mergeMapRegExp()
{
let ls: string[] = [];
for (let re of RowConfigMapRegExp.keys())
{
ls.push(re.source);
}
const re = ls.length ? new RegExp(ls.join('|')) : null;
logger.debug('RowConfigMapRegExpCached', re);
return re
}
export const RowConfigMapRegExpCached = mergeMapRegExp();