@monkey2582/thinconsole 1.3.6 → 1.3.8
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/en.thinConsole.min.js +1 -1
- package/package.json +1 -1
- package/thinConsole.d.ts +308 -389
- package/thinConsole.min.js +1 -1
package/thinConsole.d.ts
CHANGED
|
@@ -1,321 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// Class + namespace merge: class provides the value & constructor,
|
|
6
|
-
// namespace provides additional types accessible as thinConsole.X
|
|
7
|
-
declare class thinConsole {
|
|
8
|
-
constructor(options?: thinConsole.Options);
|
|
9
|
-
|
|
10
|
-
// ---- Instance properties ----
|
|
11
|
-
version: string;
|
|
12
|
-
options: Required<
|
|
13
|
-
Omit<thinConsole.Options, "filters"> & { filters: thinConsole.Filter[] | null }
|
|
14
|
-
>;
|
|
15
|
-
currentTab: string;
|
|
16
|
-
currentTheme: "light" | "dark";
|
|
17
|
-
selectedElement: Node | null;
|
|
18
|
-
logs: thinConsole.LogEntry[];
|
|
19
|
-
networkRequests: thinConsole.NetworkRequest[];
|
|
20
|
-
maxLog: number;
|
|
21
|
-
/** Maximum number of network requests to retain (default: 1000) */
|
|
22
|
-
maxNetwork: number;
|
|
23
|
-
|
|
24
|
-
// ---- Instance methods ----
|
|
25
|
-
show(tab?: string): thinConsole;
|
|
26
|
-
hide(): thinConsole;
|
|
27
|
-
destroy(): void;
|
|
28
|
-
switchTab(tab: string): void;
|
|
29
|
-
showNotification(message: string, type?: string): void;
|
|
30
|
-
toggleSearch(visible?: boolean): void;
|
|
31
|
-
toggleMute(): void;
|
|
32
|
-
clearAllLogs(silent?: boolean): void;
|
|
33
|
-
startElementPicker(): void;
|
|
34
|
-
deleteElement(element: Node): void;
|
|
35
|
-
copyElementHTML(element: Element): void;
|
|
36
|
-
expandToElement(element: Node): void;
|
|
37
|
-
getShadowRoot(element: Element): thinConsole.ShadowRootInfo | null;
|
|
38
|
-
registerPlugin(id: string, pluginClass: any): thinConsole;
|
|
39
|
-
disablePlugin(id: string): thinConsole;
|
|
40
|
-
enablePlugin(id: string): thinConsole;
|
|
41
|
-
destroyPlugin(id: string): void;
|
|
1
|
+
/**
|
|
2
|
+
* thinConsole - A lightweight web debugging console
|
|
3
|
+
* @version 1.3.7
|
|
4
|
+
*/
|
|
42
5
|
|
|
43
|
-
|
|
44
|
-
* Override existing icons or add new ones.
|
|
45
|
-
* Icons are shared globally — overrides affect all panels.
|
|
46
|
-
*
|
|
47
|
-
* @param icons Object mapping icon names to "viewBox|path.d" strings
|
|
48
|
-
* @throws Error if `icons` is not an object, or any value doesn't contain "|"
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* tC.applyIcon({
|
|
52
|
-
* "my-icon": "0 0 24 24|M10 2L4 8",
|
|
53
|
-
* "info-circle": "0 0 512 512|..." // override existing
|
|
54
|
-
* })
|
|
55
|
-
*/
|
|
56
|
-
applyIcon(icons: Record<string, string>): void;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Set the icon for a filter button by its filter ID.
|
|
60
|
-
* The icon name must already exist in the icon map
|
|
61
|
-
* (use `applyIcon` to add new icons first).
|
|
62
|
-
*
|
|
63
|
-
* @param filterId The filter button's id (data-type, data-ls-type, data-orig, or data-net-filter)
|
|
64
|
-
* @param iconName An existing icon name from the icon map
|
|
65
|
-
* @returns true if the filter was found and updated, false otherwise
|
|
66
|
-
* @throws Error if the icon name doesn't exist
|
|
67
|
-
*/
|
|
68
|
-
setFilterIcon(filterId: string, iconName: string): boolean;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Create a sandboxed proxy of the thinConsole instance.
|
|
72
|
-
* Blocks get/set/delete on `options` and `pluginOption` properties.
|
|
73
|
-
* All other methods are available with proper `this` binding.
|
|
74
|
-
* Used internally when instantiating plugins.
|
|
75
|
-
* @param tC The real thinConsole instance
|
|
76
|
-
* @returns Sandboxed proxy
|
|
77
|
-
*/
|
|
78
|
-
createSandbox(tC: thinConsole): thinConsole.Sandbox;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
triggerGlobalHook(name: thinConsole.HookName, ...args: any[]): thinConsole;
|
|
82
|
-
renderJSONTree(
|
|
83
|
-
obj: any,
|
|
84
|
-
key?: string,
|
|
85
|
-
path?: string,
|
|
86
|
-
chain?: any[],
|
|
87
|
-
noProto?: boolean
|
|
88
|
-
): string;
|
|
89
|
-
renderHTMLTree(
|
|
90
|
-
element: Node,
|
|
91
|
-
key?: string,
|
|
92
|
-
path?: string,
|
|
93
|
-
depth?: number
|
|
94
|
-
): string;
|
|
95
|
-
renderElementTree(element: Node, depth: number): string;
|
|
96
|
-
escapeHtml(str: string): string;
|
|
97
|
-
captureConsole(type: string, ...args: any[]): void;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Format a count number into compact display.
|
|
101
|
-
* - <= 999: returns the number as-is
|
|
102
|
-
* - 1000-99999: returns K format with 1 decimal (e.g. "1K", "1.1K")
|
|
103
|
-
* - >= 100000: returns "XK+" (e.g. "100K+")
|
|
104
|
-
* @param n The exact count
|
|
105
|
-
* @param plusK If true, append "+" for K values (used by network/storage)
|
|
106
|
-
* @returns Object with filterCount (display string/number) and exactCount (raw number)
|
|
107
|
-
*/
|
|
108
|
-
_fmtCount(n: number, plusK?: boolean): thinConsole.FilterCountResult;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Unified filter count updater for both built-in (console) and plugin tabs.
|
|
112
|
-
* @param container Filter button container (filterButtons or plugin view container)
|
|
113
|
-
* @param counts Count lookup object (type -> number | FilterCountResult)
|
|
114
|
-
* @param isPlugin If true, use plugin rendering (icon + orig); else console (cached HTML)
|
|
115
|
-
*/
|
|
116
|
-
_updateFilterCounts(
|
|
117
|
-
container: HTMLElement | NodeListOf<Element> | null,
|
|
118
|
-
counts: Record<string, number | thinConsole.FilterCountResult> | null,
|
|
119
|
-
isPlugin: boolean
|
|
120
|
-
): void;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Apply custom CSS inside the Shadow DOM scope.
|
|
124
|
-
* Plugin authors use this to add styles that won't leak to the host page
|
|
125
|
-
* and won't be affected by host page styles.
|
|
126
|
-
* @param css CSS string to inject into the shadow root
|
|
127
|
-
* @returns The created <style> element (can be removed later if needed)
|
|
128
|
-
*/
|
|
129
|
-
applyCSS(css: string): HTMLStyleElement;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Create a virtual scrolling list for efficient rendering of large datasets.
|
|
133
|
-
* Only visible items (plus a small buffer) are rendered in the DOM.
|
|
134
|
-
* Internally uses vsInit + vsUpdate + vsRender for the same smooth scrolling
|
|
135
|
-
* experience as the built-in console, localStorage, and network panels.
|
|
136
|
-
*
|
|
137
|
-
* @param container The scrollable container element (plugin's own container)
|
|
138
|
-
* @param options Configuration object
|
|
139
|
-
* @param options.renderItem Function that creates a DOM element (or HTML string) for a data item
|
|
140
|
-
* @param options.initialData Initial array of data items (default: [])
|
|
141
|
-
* @param options.itemHeight Estimated item height in px (auto-measured if omitted)
|
|
142
|
-
* @param options.emptyHTML HTML to show when items array is empty (default: "")
|
|
143
|
-
* @param options.trackBy Key extraction function for precise item identity comparison
|
|
144
|
-
* (default: item => item.id). Avoids unnecessary full re-renders when data
|
|
145
|
-
* changes only partially.
|
|
146
|
-
* @returns Virtual list controller with update/render/destroy methods
|
|
147
|
-
*/
|
|
148
|
-
createVirtualList(
|
|
149
|
-
container: HTMLElement,
|
|
150
|
-
options: {
|
|
151
|
-
renderItem: (item: any) => HTMLElement | string;
|
|
152
|
-
initialData?: any[];
|
|
153
|
-
itemHeight?: number;
|
|
154
|
-
emptyHTML?: string;
|
|
155
|
-
trackBy?: (item: any) => string | number;
|
|
156
|
-
}
|
|
157
|
-
): {
|
|
158
|
-
/** Update items (and optionally change renderFn). Empty items shows emptyHTML. */
|
|
159
|
-
update(items: any[], renderFn?: (item: any) => HTMLElement | string): void;
|
|
160
|
-
/** Force re-render (e.g. after tree expand/collapse or resize) */
|
|
161
|
-
render(): void;
|
|
162
|
-
/** Cleanup: remove scroll listener, delete _vs state, prevent memory leaks */
|
|
163
|
-
destroy(): void;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Initialize virtual scrolling infrastructure for a container.
|
|
168
|
-
* Creates spacer elements, content element, and scroll listener.
|
|
169
|
-
* Merges isNearBottom logic as an inline internal check.
|
|
170
|
-
* @param container The container element to apply virtual scrolling to
|
|
171
|
-
*/
|
|
172
|
-
vsInit(container: HTMLElement): void;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Core render loop for a virtual scroll container.
|
|
176
|
-
* Calculates visible range, measures heights, renders items, updates spacers.
|
|
177
|
-
* Merges vsRefreshHeights: re-measures rendered children on each call,
|
|
178
|
-
* and updates spacers even when visible range is unchanged.
|
|
179
|
-
* @param container The virtual scroll container
|
|
180
|
-
*/
|
|
181
|
-
vsRender(container: HTMLElement): void;
|
|
6
|
+
declare namespace thinConsole {
|
|
182
7
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* - If opts.force: full reset (scroll to top, re-render).
|
|
189
|
-
* - If user is at bottom: re-render and auto-scroll to bottom.
|
|
190
|
-
* - If items grew (same first item key): incremental bottom spacer update.
|
|
191
|
-
* - Otherwise: full re-render preserving scroll position.
|
|
192
|
-
*
|
|
193
|
-
* @param container The virtual scroll container
|
|
194
|
-
* @param items The array of items to display
|
|
195
|
-
* @param renderItem Function to render an item as HTML string (null when items is empty)
|
|
196
|
-
* @param avgHeight Average item height (optional)
|
|
197
|
-
* @param opts Options: { force?, emptyHTML?, trackBy?, preserveScroll? }
|
|
198
|
-
*/
|
|
199
|
-
vsUpdate(
|
|
200
|
-
container: HTMLElement,
|
|
201
|
-
items: any[],
|
|
202
|
-
renderItem: ((item: any, index: number) => string) | null,
|
|
203
|
-
avgHeight?: number,
|
|
204
|
-
opts?: {
|
|
205
|
-
/** Force full reset (scroll to top, re-render) */
|
|
206
|
-
force?: boolean;
|
|
207
|
-
/** HTML to show when items array is empty */
|
|
208
|
-
emptyHTML?: string;
|
|
209
|
-
/** Key extraction function for item identity (default: item => item.id).
|
|
210
|
-
* Stored in _vs after first call; used to detect if first item changed. */
|
|
211
|
-
trackBy?: (item: any) => string | number;
|
|
212
|
-
/** Preserve current scroll position (don't scroll to top or bottom).
|
|
213
|
-
* Useful when loading more data or inserting items at the top. */
|
|
214
|
-
preserveScroll?: boolean;
|
|
215
|
-
}
|
|
216
|
-
): void;
|
|
217
|
-
|
|
218
|
-
/** Shadow DOM host element (style isolation root) */
|
|
219
|
-
host: HTMLDivElement;
|
|
220
|
-
/** Shadow root for style isolation */
|
|
221
|
-
shadowRoot: ShadowRoot;
|
|
222
|
-
|
|
223
|
-
// ---- Static properties ----
|
|
224
|
-
static readonly version: string;
|
|
225
|
-
static tC: thinConsole | null;
|
|
226
|
-
static plugins: Record<string, any>;
|
|
227
|
-
static hooks: Record<thinConsole.HookName, thinConsole.HookCallback[]>;
|
|
228
|
-
|
|
229
|
-
// ---- Static methods ----
|
|
230
|
-
static show(tab?: string): typeof thinConsole;
|
|
231
|
-
static hide(): typeof thinConsole;
|
|
232
|
-
static destroy(): void;
|
|
233
|
-
static log(...args: any[]): typeof thinConsole;
|
|
234
|
-
static info(...args: any[]): typeof thinConsole;
|
|
235
|
-
static warn(...args: any[]): typeof thinConsole;
|
|
236
|
-
static error(...args: any[]): typeof thinConsole;
|
|
237
|
-
static addPlugin(id: string, pluginClass: any): typeof thinConsole;
|
|
238
|
-
static addTabs(
|
|
239
|
-
tabs: thinConsole.TabConfig | thinConsole.TabConfig[]
|
|
240
|
-
): typeof thinConsole;
|
|
241
|
-
static addHook(
|
|
242
|
-
name: thinConsole.HookName,
|
|
243
|
-
callback: thinConsole.HookCallback
|
|
244
|
-
): typeof thinConsole;
|
|
245
|
-
static removeHook(
|
|
246
|
-
name: thinConsole.HookName,
|
|
247
|
-
callback: thinConsole.HookCallback
|
|
248
|
-
): typeof thinConsole;
|
|
249
|
-
static setFilterCounts(
|
|
250
|
-
counts: Record<string, number | thinConsole.FilterCountResult>
|
|
251
|
-
): typeof thinConsole;
|
|
252
|
-
}
|
|
8
|
+
/** Position configuration for the floating button */
|
|
9
|
+
interface Position {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
253
13
|
|
|
254
|
-
|
|
255
|
-
|
|
14
|
+
/** Custom filter configuration */
|
|
15
|
+
interface FilterConfig {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
256
19
|
|
|
20
|
+
/** Constructor options */
|
|
257
21
|
interface Options {
|
|
258
|
-
/** Button text (max 11 chars,
|
|
22
|
+
/** Button text (max 11 chars, default "thinConsole") */
|
|
259
23
|
text?: string;
|
|
260
|
-
/** Button background color */
|
|
24
|
+
/** Button background color (default "#007aff") */
|
|
261
25
|
color?: string;
|
|
262
|
-
/** Button width (
|
|
26
|
+
/** Button width (default "auto") */
|
|
263
27
|
width?: string;
|
|
264
|
-
/** Button height (
|
|
28
|
+
/** Button height (default "auto") */
|
|
265
29
|
height?: string;
|
|
266
|
-
/** Theme
|
|
267
|
-
theme?:
|
|
268
|
-
/** Enable
|
|
30
|
+
/** Theme: "light", "dark", "auto", or custom theme name (default "auto") */
|
|
31
|
+
theme?: string;
|
|
32
|
+
/** Enable plugins (default true) */
|
|
269
33
|
plugins?: boolean;
|
|
270
|
-
/** List of disabled plugin
|
|
34
|
+
/** List of disabled plugin names (default []) */
|
|
271
35
|
disabledPlugins?: string[];
|
|
272
|
-
/** Enable JS
|
|
36
|
+
/** Enable JS execution (default true) */
|
|
273
37
|
jsExecute?: boolean;
|
|
274
|
-
/**
|
|
275
|
-
pos?:
|
|
276
|
-
/**
|
|
38
|
+
/** Button position, null = saved/dragged (default null) */
|
|
39
|
+
pos?: Position | null;
|
|
40
|
+
/** Max number of log entries (default 100000) */
|
|
277
41
|
maxLog?: number;
|
|
278
|
-
/**
|
|
42
|
+
/** Max number of network requests (default 1000) */
|
|
279
43
|
maxNetwork?: number;
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
|
|
284
|
-
* Values are passed through as-is (only object check).
|
|
285
|
-
* Plugins can access their options via `this.tC.options.pluginOption[this.id]`.
|
|
286
|
-
*/
|
|
287
|
-
pluginOption?: Record<string, Record<string, any>>;
|
|
44
|
+
/** Per-plugin options keyed by plugin name (default {}) */
|
|
45
|
+
pluginOption?: Record<string, object>;
|
|
46
|
+
/** Custom log filters (default null = builtin) */
|
|
47
|
+
filters?: FilterConfig[] | null;
|
|
288
48
|
}
|
|
289
49
|
|
|
290
|
-
interface
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
50
|
+
/** Storage backend interface (local / session / cookie) */
|
|
51
|
+
interface StorageBackend {
|
|
52
|
+
get(key: string): string | null;
|
|
53
|
+
set(key: string, value: string, days?: number): void;
|
|
54
|
+
remove(key: string): void;
|
|
55
|
+
clear(): void;
|
|
56
|
+
length(): number;
|
|
57
|
+
key(index: number): string | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface StorageAccessor {
|
|
61
|
+
local: StorageBackend;
|
|
62
|
+
session: StorageBackend;
|
|
63
|
+
cookie: StorageBackend;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Custom theme configuration */
|
|
67
|
+
interface ThemeConfig {
|
|
68
|
+
vars: Record<string, string>;
|
|
69
|
+
icons?: Record<string, string>;
|
|
294
70
|
}
|
|
295
71
|
|
|
72
|
+
/** Header button configuration */
|
|
73
|
+
interface HeaderButton {
|
|
74
|
+
icon: string;
|
|
75
|
+
fn?: () => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Hook names and their handler arrays */
|
|
79
|
+
interface HookMap {
|
|
80
|
+
beforeRender: HookHandler[];
|
|
81
|
+
afterRender: HookHandler[];
|
|
82
|
+
beforeLog: HookHandler[];
|
|
83
|
+
afterLog: HookHandler[];
|
|
84
|
+
beforeOpen: HookHandler[];
|
|
85
|
+
afterOpen: HookHandler[];
|
|
86
|
+
beforeClose: HookHandler[];
|
|
87
|
+
afterClose: HookHandler[];
|
|
88
|
+
beforeClear: HookHandler[];
|
|
89
|
+
afterClear: HookHandler[];
|
|
90
|
+
pluginMount: HookHandler[];
|
|
91
|
+
pluginUnmount: HookHandler[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type HookHandler = (...args: any[]) => void;
|
|
95
|
+
|
|
96
|
+
/** Custom tab configuration */
|
|
296
97
|
interface TabConfig {
|
|
297
98
|
id: string;
|
|
298
99
|
name: string;
|
|
299
100
|
icon?: string;
|
|
300
|
-
|
|
101
|
+
render?(container: HTMLElement): void;
|
|
301
102
|
html?: string;
|
|
302
|
-
|
|
303
|
-
render?: (container: HTMLElement) => void;
|
|
304
|
-
/** Called when the tab is shown */
|
|
305
|
-
onShow?: () => void;
|
|
103
|
+
onShow?(): void;
|
|
306
104
|
}
|
|
307
105
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
name: string;
|
|
311
|
-
icon: string;
|
|
312
|
-
plugin?: tCPlugin;
|
|
313
|
-
onShow?: () => void;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// ============= Data Interfaces =============
|
|
317
|
-
|
|
318
|
-
interface NetworkRequest {
|
|
106
|
+
/** Network request record */
|
|
107
|
+
interface NetRequest {
|
|
319
108
|
id: number;
|
|
320
109
|
url: string;
|
|
321
110
|
method: string;
|
|
@@ -324,123 +113,253 @@ declare namespace thinConsole {
|
|
|
324
113
|
reqHeaders: Record<string, string>;
|
|
325
114
|
reqBody: any;
|
|
326
115
|
resHeaders: Record<string, string>;
|
|
327
|
-
resBody:
|
|
116
|
+
resBody: string | null;
|
|
328
117
|
startTime: number;
|
|
329
118
|
endTime: number;
|
|
330
119
|
duration: number;
|
|
331
|
-
error:
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
interface LogEntry {
|
|
335
|
-
id: number;
|
|
336
|
-
type: string;
|
|
337
|
-
args: any[];
|
|
338
|
-
time: number;
|
|
339
|
-
stack?: string;
|
|
340
|
-
subType?: string;
|
|
341
|
-
extra?: any;
|
|
120
|
+
error: string | null;
|
|
342
121
|
}
|
|
343
122
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
123
|
+
/** Sandbox proxy that exposes instance API to plugins safely */
|
|
124
|
+
interface Sandbox {
|
|
125
|
+
tC: ThinConsole;
|
|
126
|
+
pluginOption: Record<string, object>;
|
|
127
|
+
readonly __isSandbox: boolean;
|
|
347
128
|
}
|
|
348
129
|
|
|
349
|
-
// ============= Filter Count =============
|
|
350
|
-
|
|
351
130
|
/**
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* (
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* by `_fmtCount()`. For extension/plugin tabs, developers can pass
|
|
361
|
-
* custom objects via `setFilterCounts()` to control both values.
|
|
131
|
+
* Base plugin class. Extend this to create a class-based plugin.
|
|
132
|
+
* ```ts
|
|
133
|
+
* class MyPlugin extends tCPlugin {
|
|
134
|
+
* init() { /* ... *\/ }
|
|
135
|
+
* addTab() { return { id: "my", name: "My Tab" }; }
|
|
136
|
+
* }
|
|
137
|
+
* thinConsole.addPlugin("my", MyPlugin);
|
|
138
|
+
* ```
|
|
362
139
|
*/
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// ============= Hooks =============
|
|
369
|
-
|
|
370
|
-
type HookName =
|
|
371
|
-
| "beforeRender"
|
|
372
|
-
| "afterRender"
|
|
373
|
-
| "beforeLog"
|
|
374
|
-
| "afterLog"
|
|
375
|
-
| "beforeOpen"
|
|
376
|
-
| "afterOpen"
|
|
377
|
-
| "beforeClose"
|
|
378
|
-
| "afterClose"
|
|
379
|
-
| "beforeClear"
|
|
380
|
-
| "afterClear"
|
|
381
|
-
| "pluginMount"
|
|
382
|
-
| "pluginUnmount";
|
|
383
|
-
|
|
384
|
-
type HookCallback = (...args: any[]) => void;
|
|
385
|
-
|
|
386
|
-
// ============= Virtual List =============
|
|
387
|
-
|
|
388
|
-
// ============= Plugin Base Class =============
|
|
389
|
-
|
|
390
|
-
class tCPlugin {
|
|
391
|
-
/**
|
|
392
|
-
* @param tC A sandboxed thinConsole instance. The sandbox blocks
|
|
393
|
-
* access to `options` and `pluginOption` on tC, preventing plugins
|
|
394
|
-
* from reading or modifying global configuration. Plugins should
|
|
395
|
-
* use `this.pluginOption` for their own config instead.
|
|
396
|
-
*/
|
|
397
|
-
constructor(tC: thinConsole.Sandbox);
|
|
398
|
-
/** Sandboxed thinConsole instance (options/pluginOption blocked) */
|
|
399
|
-
tC: thinConsole.Sandbox;
|
|
400
|
-
/**
|
|
401
|
-
* This plugin's isolated config from options.pluginOption[pluginId].
|
|
402
|
-
* Set automatically before init() is called.
|
|
403
|
-
* Must be an object — non-object values are replaced with {}.
|
|
404
|
-
* Mutable: plugins can freely read and modify their own config.
|
|
405
|
-
* Default: {} if not configured or not an object.
|
|
406
|
-
*/
|
|
407
|
-
pluginOption: Record<string, any>;
|
|
408
|
-
/** Plugin ID (auto-derived from class name, lowercased) */
|
|
140
|
+
class Plugin {
|
|
141
|
+
protected tC: ThinConsole;
|
|
142
|
+
pluginOption: Record<string, object>;
|
|
409
143
|
id: string;
|
|
410
|
-
|
|
144
|
+
constructor(tC: ThinConsole);
|
|
411
145
|
init(): void;
|
|
412
|
-
/** Whether the current language is Chinese */
|
|
413
146
|
iszh(): boolean;
|
|
414
|
-
/** Whether the current language is English */
|
|
415
147
|
isen(): boolean;
|
|
416
|
-
/** Whether running on a mobile device */
|
|
417
148
|
isMobile(): boolean;
|
|
418
|
-
/** Render plugin content into container — override in subclass */
|
|
419
149
|
render(container: HTMLElement): void;
|
|
420
|
-
/** Called when plugin tab becomes visible — override in subclass */
|
|
421
150
|
onShow(): void;
|
|
422
|
-
/** Called when plugin tab becomes hidden — override in subclass */
|
|
423
151
|
onHide(): void;
|
|
424
|
-
/** Cleanup when plugin is destroyed — override in subclass */
|
|
425
152
|
destroy(): void;
|
|
426
|
-
/** Define a tab for this plugin — override in subclass */
|
|
427
|
-
addTab?(): PluginTab;
|
|
428
153
|
}
|
|
429
154
|
|
|
430
|
-
/**
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
155
|
+
/** ThinConsole instance */
|
|
156
|
+
class ThinConsole {
|
|
157
|
+
constructor(options?: Options);
|
|
158
|
+
|
|
159
|
+
/** Version string */
|
|
160
|
+
readonly version: string;
|
|
161
|
+
|
|
162
|
+
/** Current options (sanitized) */
|
|
163
|
+
readonly options: Options;
|
|
164
|
+
|
|
165
|
+
/** Current tab id */
|
|
166
|
+
currentTab: string;
|
|
167
|
+
|
|
168
|
+
/** Current theme id */
|
|
169
|
+
currentTheme: string;
|
|
170
|
+
|
|
171
|
+
/** Max log entries */
|
|
172
|
+
maxLog: number;
|
|
173
|
+
|
|
174
|
+
/** Max network request records */
|
|
175
|
+
maxNetwork: number;
|
|
176
|
+
|
|
177
|
+
/** Currently selected element */
|
|
178
|
+
selectedElement: Element | null;
|
|
179
|
+
|
|
180
|
+
/** Initialize the console (creates button + overlay) */
|
|
181
|
+
init(): void;
|
|
182
|
+
|
|
183
|
+
/** Show the console overlay, optionally switching to a tab */
|
|
184
|
+
show(tab?: string): this;
|
|
185
|
+
|
|
186
|
+
/** Hide the console overlay */
|
|
187
|
+
hide(): this;
|
|
188
|
+
|
|
189
|
+
/** Destroy the instance and remove all DOM elements */
|
|
190
|
+
destroy(): void;
|
|
191
|
+
|
|
192
|
+
/** Destroy and recreate with new options */
|
|
193
|
+
setOption(options: Options): this;
|
|
194
|
+
|
|
195
|
+
/** Switch to a tab by id */
|
|
196
|
+
switchTab(tab: string): void;
|
|
197
|
+
|
|
198
|
+
/** Show a toast notification */
|
|
199
|
+
showNotification(message: string, type?: string): void;
|
|
200
|
+
|
|
201
|
+
/** Toggle mute state for console logs */
|
|
202
|
+
toggleMute(): void;
|
|
203
|
+
|
|
204
|
+
/** Toggle search bar visibility */
|
|
205
|
+
toggleSearch(): void;
|
|
206
|
+
|
|
207
|
+
/** Run code from the title input */
|
|
208
|
+
runCode(): void;
|
|
209
|
+
|
|
210
|
+
/** Copy a log entry */
|
|
211
|
+
copyLog(id: string, plain?: boolean, raw?: boolean): void;
|
|
212
|
+
|
|
213
|
+
/** Clear all logs */
|
|
214
|
+
clearAllLogs(all?: boolean): void;
|
|
215
|
+
|
|
216
|
+
/** Add a localStorage item (opens editor) */
|
|
217
|
+
addLSItem(): void;
|
|
218
|
+
|
|
219
|
+
/** Edit a localStorage item by key */
|
|
220
|
+
editLSItem(key: string): void;
|
|
221
|
+
|
|
222
|
+
/** Save the current localStorage editor content */
|
|
223
|
+
saveLSItem(): void;
|
|
224
|
+
|
|
225
|
+
/** Remove a localStorage item by key */
|
|
226
|
+
removeLSItem(key: string): void;
|
|
227
|
+
|
|
228
|
+
/** Start the element picker mode */
|
|
229
|
+
startElementPicker(): void;
|
|
230
|
+
|
|
231
|
+
/** Expand the element tree to reveal a specific element */
|
|
232
|
+
expandToElement(el: Element): void;
|
|
233
|
+
|
|
234
|
+
/** Copy an element's HTML */
|
|
235
|
+
copyElementHTML(el: Element): void;
|
|
236
|
+
|
|
237
|
+
/** Delete an element from the DOM */
|
|
238
|
+
deleteElement(el: Element): void;
|
|
239
|
+
|
|
240
|
+
/** Start observing DOM mutations for element tree updates */
|
|
241
|
+
startElementObserver(): void;
|
|
242
|
+
|
|
243
|
+
/** Stop the element mutation observer */
|
|
244
|
+
stopElementObserver(): void;
|
|
245
|
+
|
|
246
|
+
/** Re-render current tab content */
|
|
247
|
+
renderContent(): void;
|
|
248
|
+
|
|
249
|
+
/** Capture XHR and fetch network requests */
|
|
250
|
+
captureNetworkRequests(): void;
|
|
251
|
+
|
|
252
|
+
/** Render the network request list */
|
|
253
|
+
renderNetworkList(): void;
|
|
254
|
+
|
|
255
|
+
/** Clear network requests (respects active filter) */
|
|
256
|
+
clearNetworkRequests(): void;
|
|
257
|
+
|
|
258
|
+
/** Send a new network request from the request editor */
|
|
259
|
+
sendNewRequest(): void;
|
|
260
|
+
|
|
261
|
+
/** Show network request detail panel */
|
|
262
|
+
showNetDetail(id: number): void;
|
|
263
|
+
|
|
264
|
+
/** Resend a previous network request */
|
|
265
|
+
resendRequest(req: NetRequest): void;
|
|
266
|
+
|
|
267
|
+
/** Apply custom icon overrides */
|
|
268
|
+
applyIcon(icons: Record<string, string>): void;
|
|
269
|
+
|
|
270
|
+
/** Set the icon for a specific filter button */
|
|
271
|
+
setFilterIcon(filterId: string, iconId: string): boolean;
|
|
272
|
+
|
|
273
|
+
/** Disable a plugin by name */
|
|
274
|
+
disablePlugin(name: string): this;
|
|
275
|
+
|
|
276
|
+
/** Enable a previously disabled plugin */
|
|
277
|
+
enablePlugin(name: string): this;
|
|
278
|
+
|
|
279
|
+
/** Trigger a global hook with arguments */
|
|
280
|
+
triggerGlobalHook(name: keyof HookMap, ...args: any[]): void;
|
|
281
|
+
|
|
282
|
+
/** Load a single plugin by name */
|
|
283
|
+
loadSinglePlugin(name: string): this;
|
|
284
|
+
|
|
285
|
+
/** Create a sandbox proxy for plugin isolation */
|
|
286
|
+
createSandbox(target: ThinConsole): Sandbox;
|
|
287
|
+
|
|
288
|
+
/** Escape HTML special characters */
|
|
289
|
+
escapeHtml(str: string): string;
|
|
290
|
+
|
|
291
|
+
/** Safe JSON stringify with circular reference handling */
|
|
292
|
+
safeStringify(value: any, indent?: number, json?: boolean): string;
|
|
293
|
+
|
|
294
|
+
/** Get the icon SVG string */
|
|
295
|
+
icon(name: string, className?: string): string;
|
|
296
|
+
|
|
297
|
+
/** Storage accessor (local, session, cookie) */
|
|
298
|
+
readonly storage: StorageAccessor;
|
|
442
299
|
}
|
|
300
|
+
|
|
301
|
+
// ---- Static API ----
|
|
302
|
+
|
|
303
|
+
/** Current singleton instance, or null */
|
|
304
|
+
const tC: ThinConsole | null;
|
|
305
|
+
|
|
306
|
+
/** Registered plugins (class-based) */
|
|
307
|
+
const plugins: Record<string, typeof Plugin>;
|
|
308
|
+
|
|
309
|
+
/** Registered themes */
|
|
310
|
+
const themes: Record<string, ThemeConfig>;
|
|
311
|
+
|
|
312
|
+
/** Registered header buttons (max 5) */
|
|
313
|
+
const headerButtons: HeaderButton[];
|
|
314
|
+
|
|
315
|
+
/** Global hook arrays */
|
|
316
|
+
const hooks: HookMap;
|
|
317
|
+
|
|
318
|
+
/** Register a custom theme */
|
|
319
|
+
function addTheme(
|
|
320
|
+
name: string,
|
|
321
|
+
styles: string,
|
|
322
|
+
icons?: Record<string, string>
|
|
323
|
+
): typeof thinConsole;
|
|
324
|
+
|
|
325
|
+
/** Add a header button (max 5) */
|
|
326
|
+
function addHeader(icon: string, fn?: () => void): typeof thinConsole;
|
|
327
|
+
|
|
328
|
+
/** Set options (destroys and recreates the singleton) */
|
|
329
|
+
function setOption(options: Options): typeof thinConsole;
|
|
330
|
+
|
|
331
|
+
/** Show the console overlay (static convenience) */
|
|
332
|
+
function show(tab?: string): typeof thinConsole;
|
|
333
|
+
|
|
334
|
+
/** Hide the console overlay (static convenience) */
|
|
335
|
+
function hide(): typeof thinConsole;
|
|
336
|
+
|
|
337
|
+
/** Destroy the singleton (static convenience) */
|
|
338
|
+
function destroy(): typeof thinConsole;
|
|
339
|
+
|
|
340
|
+
/** console.log passthrough (static convenience) */
|
|
341
|
+
function log(...args: any[]): typeof thinConsole;
|
|
342
|
+
|
|
343
|
+
/** console.info passthrough (static convenience) */
|
|
344
|
+
function info(...args: any[]): typeof thinConsole;
|
|
345
|
+
|
|
346
|
+
/** console.warn passthrough (static convenience) */
|
|
347
|
+
function warn(...args: any[]): typeof thinConsole;
|
|
348
|
+
|
|
349
|
+
/** console.error passthrough (static convenience) */
|
|
350
|
+
function error(...args: any[]): typeof thinConsole;
|
|
351
|
+
|
|
352
|
+
/** Register a plugin (class or function) */
|
|
353
|
+
function addPlugin(name: string, plugin: typeof Plugin | ((tC: Sandbox) => void)): typeof thinConsole;
|
|
354
|
+
|
|
355
|
+
/** Add custom tabs */
|
|
356
|
+
function addTabs(tabs: TabConfig | TabConfig[]): typeof thinConsole;
|
|
443
357
|
}
|
|
444
358
|
|
|
359
|
+
/** The Plugin base class, also available as window.tCPlugin */
|
|
360
|
+
declare const tCPlugin: typeof thinConsole.Plugin;
|
|
361
|
+
|
|
362
|
+
/** Main constructor: create or reuse the singleton */
|
|
363
|
+
declare function thinConsole(options?: thinConsole.Options): thinConsole.ThinConsole;
|
|
364
|
+
|
|
445
365
|
export = thinConsole;
|
|
446
|
-
export as namespace thinConsole;
|