vconsole.min.d.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. declare module "lib/tool" {
  2. /**
  3. * Utility Functions
  4. */
  5. /**
  6. * get formatted date by timestamp
  7. */
  8. export function getDate(time: number): {
  9. time: number;
  10. year: number;
  11. month: string | number;
  12. day: string | number;
  13. hour: string | number;
  14. minute: string | number;
  15. second: string | number;
  16. millisecond: string | number;
  17. };
  18. /**
  19. * Determine whether a value is of a specific type.
  20. */
  21. export function isNumber(value: any): boolean;
  22. export function isBigInt(value: any): boolean;
  23. export function isString(value: any): boolean;
  24. export function isArray(value: any): boolean;
  25. export function isBoolean(value: any): boolean;
  26. export function isUndefined(value: any): boolean;
  27. export function isNull(value: any): boolean;
  28. export function isSymbol(value: any): boolean;
  29. export function isObject(value: any): boolean;
  30. export function isFunction(value: any): boolean;
  31. export function isElement(value: any): boolean;
  32. export function isWindow(value: any): boolean;
  33. export function isIterable(value: any): boolean;
  34. /**
  35. * Get the prototype name of an object
  36. */
  37. export function getPrototypeName(value: any): string;
  38. /**
  39. * Get an object's constructor name.
  40. */
  41. export function getObjName(obj: any): string;
  42. /**
  43. * check whether an object is plain (using {})
  44. * @param object obj
  45. * @return boolean
  46. */
  47. export function isPlainObject(obj: any): boolean;
  48. /**
  49. * Escape HTML to XSS-safe text.
  50. */
  51. export function htmlEncode(text: string | number): string;
  52. /**
  53. * Convert a text's invisible characters to visible characters.
  54. */
  55. export function getVisibleText(text: string): string;
  56. /**
  57. * A safe `JSON.stringify` method.
  58. */
  59. export function safeJSONStringify(obj: any, opt?: {
  60. maxDepth?: number;
  61. keyMaxLen?: number;
  62. pretty?: boolean;
  63. }): string;
  64. /**
  65. * Call original `JSON.stringify` and catch unknown exceptions.
  66. */
  67. export function JSONStringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
  68. export function getStringBytes(str: string): number;
  69. export function getBytesText(bytes: number): string;
  70. export function subString(str: string, len: number): string;
  71. /**
  72. * Sore an `string[]` by string.
  73. */
  74. export function sortArray(arr: string[]): string[];
  75. /**
  76. * Get enumerable keys of an object or array.
  77. */
  78. export function getEnumerableKeys(obj: any): string[];
  79. /**
  80. * Get enumerable and non-enumerable keys of an object or array.
  81. */
  82. export function getEnumerableAndNonEnumerableKeys(obj: any): string[];
  83. /**
  84. * Get non-enumerable keys of an object or array.
  85. */
  86. export function getNonEnumerableKeys(obj: any): string[];
  87. export function getSymbolKeys(obj: any): symbol[];
  88. /**
  89. * localStorage methods
  90. */
  91. export function setStorage(key: string, value: string): void;
  92. export function getStorage(key: string): string;
  93. /**
  94. * Generate a 6-digit unique string with prefix `"__vc_" + ${prefix}`
  95. */
  96. export function getUniqueID(prefix?: string): string;
  97. }
  98. declare module "lib/query" {
  99. const $: {
  100. /**
  101. * get single element
  102. * @public
  103. */
  104. one: (selector: string, contextElement?: Element | Document) => HTMLElement;
  105. /**
  106. * get multiple elements
  107. * @public
  108. */
  109. all: (selector: string, contextElement?: Element | Document) => HTMLElement[];
  110. /**
  111. * add className(s) to an or multiple element(s)
  112. * @public
  113. */
  114. addClass: ($el: Element | Element[], className: string) => void;
  115. /**
  116. * remove className(s) from an or multiple element(s)
  117. * @public
  118. */
  119. removeClass: ($el: Element | Element[], className: string) => void;
  120. /**
  121. * see whether an element contains a className
  122. * @public
  123. */
  124. hasClass: ($el: Element, className: string) => boolean;
  125. /**
  126. * bind an event to element(s)
  127. * @public
  128. */
  129. bind: ($el: Element | Element[], eventType: any, fn: any, useCapture?: boolean) => void;
  130. /**
  131. * delegate an event to a parent element
  132. * @public
  133. * @param $el parent element
  134. * @param eventType name of the event
  135. * @param selector target's selector
  136. * @param fn callback function
  137. */
  138. delegate: ($el: Element, eventType: string, selector: string, fn: (event: Event, $target: HTMLElement) => void) => void;
  139. /**
  140. * Remove all child elements of an element.
  141. */
  142. removeChildren($el: Element): Element;
  143. };
  144. /**
  145. * export
  146. */
  147. export default $;
  148. }
  149. declare module "lib/model" {
  150. type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
  151. export class VConsoleModel {
  152. static singleton: {
  153. [ctorName: string]: VConsoleModel;
  154. };
  155. protected _onDataUpdateCallbacks: Function[];
  156. /**
  157. * Get a singleton of a model.
  158. */
  159. static getSingleton<T extends VConsoleModel>(ctor: AConstructorTypeOf<T>, ctorName: string): T;
  160. }
  161. export default VConsoleModel;
  162. }
  163. declare module "lib/pluginExporter" {
  164. import type { VConsoleModel } from "lib/model";
  165. export class VConsolePluginExporter {
  166. protected model: VConsoleModel;
  167. protected pluginId: string;
  168. constructor(pluginId: string);
  169. destroy(): void;
  170. }
  171. }
  172. declare module "lib/plugin" {
  173. import { VConsolePluginExporter } from "lib/pluginExporter";
  174. import type { VConsole } from "core/core";
  175. export type IVConsolePluginEvent = (data?: any) => void;
  176. export type IVConsolePluginEventName = 'init' | 'renderTab' | 'addTopBar' | 'addTool' | 'ready' | 'remove' | 'updateOption' | 'showConsole' | 'hideConsole' | 'show' | 'hide';
  177. export interface IVConsoleTopbarOptions {
  178. name: string;
  179. className: string;
  180. actived?: boolean;
  181. data?: {
  182. [key: string]: string;
  183. };
  184. onClick?: (e: Event, data?: any) => any;
  185. }
  186. export interface IVConsoleToolbarOptions {
  187. name: string;
  188. global?: boolean;
  189. data?: {
  190. [key: string]: string;
  191. };
  192. onClick?: (e: Event, data?: any) => any;
  193. }
  194. /**
  195. * vConsole Plugin Base Class
  196. */
  197. export class VConsolePlugin {
  198. isReady: boolean;
  199. eventMap: Map<IVConsolePluginEventName, IVConsolePluginEvent>;
  200. exporter?: VConsolePluginExporter;
  201. protected _id: string;
  202. protected _name: string;
  203. protected _vConsole: VConsole;
  204. constructor(...args: any[]);
  205. get id(): string;
  206. set id(value: string);
  207. get name(): string;
  208. set name(value: string);
  209. get vConsole(): VConsole;
  210. set vConsole(value: VConsole);
  211. /**
  212. * Register an event
  213. * @public
  214. * @param IVConsolePluginEventName
  215. * @param IVConsolePluginEvent
  216. */
  217. on(eventName: IVConsolePluginEventName, callback: IVConsolePluginEvent): this;
  218. onRemove(): void;
  219. /**
  220. * Trigger an event.
  221. */
  222. trigger(eventName: IVConsolePluginEventName, data?: any): this;
  223. protected bindExporter(): void;
  224. protected unbindExporter(): void;
  225. protected getUniqueID(prefix?: string): string;
  226. }
  227. export default VConsolePlugin;
  228. }
  229. declare module "lib/sveltePlugin" {
  230. import VConsolePlugin from "lib/plugin";
  231. import { SvelteComponent } from 'svelte';
  232. export class VConsoleSveltePlugin<T extends {} = {}> extends VConsolePlugin {
  233. CompClass: typeof SvelteComponent;
  234. compInstance?: SvelteComponent;
  235. initialProps: T;
  236. constructor(id: string, name: string, CompClass: typeof SvelteComponent, initialProps: T);
  237. onReady(): void;
  238. onRenderTab(callback: any): void;
  239. onRemove(): void;
  240. }
  241. }
  242. declare module "core/core.model" {
  243. export const contentStore: {
  244. subscribe: (this: void, run: import("svelte/store").Subscriber<{
  245. updateTime: number;
  246. }>, invalidate?: (value?: {
  247. updateTime: number;
  248. }) => void) => import("svelte/store").Unsubscriber;
  249. set: (this: void, value: {
  250. updateTime: number;
  251. }) => void;
  252. update: (this: void, updater: import("svelte/store").Updater<{
  253. updateTime: number;
  254. }>) => void;
  255. updateTime: () => void;
  256. };
  257. }
  258. declare module "log/logTool" {
  259. import type { IVConsoleLog, IVConsoleLogData } from "log/log.model";
  260. /**
  261. * Get a value's text content and its type.
  262. */
  263. export const getValueTextAndType: (val: any, wrapString?: boolean) => {
  264. text: any;
  265. valueType: string;
  266. };
  267. /**
  268. * A simple parser to get `[` or `]` information.
  269. */
  270. export const getLastIdentifier: (text: string) => {
  271. front: {
  272. text: string;
  273. pos: number;
  274. before: string;
  275. after: string;
  276. };
  277. back: {
  278. text: string;
  279. pos: number;
  280. before: string;
  281. after: string;
  282. };
  283. };
  284. export const isMatchedFilterText: (log: IVConsoleLog, filterText: string) => boolean;
  285. /**
  286. * Styling log output (`%c`), or string substitutions (`%s`, `%d`, `%o`).
  287. * Apply to the first log only.
  288. */
  289. export const getLogDatasWithFormatting: (origDatas: any[]) => IVConsoleLogData[];
  290. /**
  291. * An empty class for rendering views.
  292. */
  293. export class VConsoleUninvocatableObject {
  294. }
  295. }
  296. declare module "log/log.store" {
  297. import type { Writable } from 'svelte/store';
  298. import type { IVConsoleLog } from "log/log.model";
  299. export interface IVConsoleLogStore {
  300. logList: IVConsoleLog[];
  301. }
  302. /**
  303. * Log Store Factory
  304. */
  305. export class VConsoleLogStore {
  306. static storeMap: {
  307. [pluginId: string]: Writable<IVConsoleLogStore>;
  308. };
  309. /**
  310. * Create a store.
  311. */
  312. static create(pluginId: string): Writable<IVConsoleLogStore>;
  313. /**
  314. * Delete a store.
  315. */
  316. static delete(pluginId: string): void;
  317. /**
  318. * Get a store by pluginId,
  319. */
  320. static get(pluginId: string): Writable<IVConsoleLogStore>;
  321. /**
  322. * Get a store's raw data.
  323. */
  324. static getRaw(pluginId: string): IVConsoleLogStore;
  325. /**
  326. * Get all stores.
  327. */
  328. static getAll(): {
  329. [pluginId: string]: Writable<IVConsoleLogStore>;
  330. };
  331. }
  332. }
  333. declare module "log/log.model" {
  334. import { VConsoleModel } from "lib/model";
  335. /**********************************
  336. * Interfaces
  337. **********************************/
  338. export type IConsoleLogMethod = 'log' | 'info' | 'debug' | 'warn' | 'error';
  339. export interface IVConsoleLogData {
  340. origData: any;
  341. style?: string;
  342. }
  343. export interface IVConsoleLog {
  344. _id: string;
  345. type: IConsoleLogMethod;
  346. cmdType?: 'input' | 'output';
  347. repeated?: number;
  348. date: number;
  349. data: IVConsoleLogData[];
  350. }
  351. export type IVConsoleLogListMap = {
  352. [pluginId: string]: IVConsoleLog[];
  353. };
  354. export type IVConsoleLogFilter = {
  355. [pluginId: string]: string;
  356. };
  357. export interface IVConsoleAddLogOptions {
  358. noOrig?: boolean;
  359. cmdType?: 'input' | 'output';
  360. }
  361. /**********************************
  362. * Stores
  363. **********************************/
  364. /**********************************
  365. * Model
  366. **********************************/
  367. export class VConsoleLogModel extends VConsoleModel {
  368. readonly LOG_METHODS: IConsoleLogMethod[];
  369. ADDED_LOG_PLUGIN_ID: string[];
  370. maxLogNumber: number;
  371. protected logCounter: number;
  372. protected pluginPattern: RegExp;
  373. /**
  374. * The original `window.console` methods.
  375. */
  376. origConsole: {
  377. [method: string]: Function;
  378. };
  379. /**
  380. * Bind a Log plugin.
  381. * When binding first plugin, `window.console` will be hooked.
  382. */
  383. bindPlugin(pluginId: string): boolean;
  384. /**
  385. * Unbind a Log plugin.
  386. * When no binded plugin exists, hooked `window.console` will be recovered.
  387. */
  388. unbindPlugin(pluginId: string): boolean;
  389. /**
  390. * Hook `window.console` with vConsole log method.
  391. * Methods will be hooked only once.
  392. */
  393. mockConsole(): void;
  394. /**
  395. * Recover `window.console`.
  396. */
  397. unmockConsole(): void;
  398. /**
  399. * Call origin `window.console[method](...args)`
  400. */
  401. callOriginalConsole(method: string, ...args: any[]): void;
  402. /**
  403. * Remove all logs.
  404. */
  405. clearLog(): void;
  406. /**
  407. * Remove a plugin's logs.
  408. */
  409. clearPluginLog(pluginId: string): void;
  410. /**
  411. * Add a vConsole log.
  412. */
  413. addLog(item?: {
  414. type: IConsoleLogMethod;
  415. origData: any[];
  416. }, opt?: IVConsoleAddLogOptions): void;
  417. /**
  418. * Execute a JS command.
  419. */
  420. evalCommand(cmd: string): void;
  421. protected _extractPluginIdByLog(log: IVConsoleLog): string;
  422. protected _isRepeatedLog(pluginId: string, log: IVConsoleLog): boolean;
  423. protected _updateLastLogRepeated(pluginId: string): void;
  424. protected _pushLogList(pluginId: string, log: IVConsoleLog): void;
  425. protected _limitLogListLength(): void;
  426. }
  427. }
  428. declare module "log/log.exporter" {
  429. import { VConsolePluginExporter } from "lib/pluginExporter";
  430. import { VConsoleLogModel } from "log/log.model";
  431. import type { IConsoleLogMethod } from "log/log.model";
  432. export class VConsoleLogExporter extends VConsolePluginExporter {
  433. model: VConsoleLogModel;
  434. log(...args: any[]): void;
  435. info(...args: any[]): void;
  436. debug(...args: any[]): void;
  437. warn(...args: any[]): void;
  438. error(...args: any[]): void;
  439. clear(): void;
  440. protected addLog(method: IConsoleLogMethod, ...args: any[]): void;
  441. }
  442. }
  443. declare module "log/log" {
  444. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  445. import { VConsoleLogModel } from "log/log.model";
  446. /**
  447. * vConsole Log Plugin (base class).
  448. */
  449. export class VConsoleLogPlugin extends VConsoleSveltePlugin {
  450. model: VConsoleLogModel;
  451. isReady: boolean;
  452. isShow: boolean;
  453. isInBottom: boolean;
  454. constructor(id: string, name: string);
  455. onReady(): void;
  456. onRemove(): void;
  457. onAddTopBar(callback: Function): void;
  458. onAddTool(callback: Function): void;
  459. onUpdateOption(): void;
  460. }
  461. export default VConsoleLogPlugin;
  462. }
  463. declare module "log/default" {
  464. import { VConsoleLogPlugin } from "log/log";
  465. export class VConsoleDefaultPlugin extends VConsoleLogPlugin {
  466. protected onErrorHandler: any;
  467. protected resourceErrorHandler: any;
  468. protected rejectionHandler: any;
  469. onReady(): void;
  470. onRemove(): void;
  471. /**
  472. * Catch window errors.
  473. */
  474. protected bindErrors(): void;
  475. /**
  476. * Not catch window errors.
  477. */
  478. protected unbindErrors(): void;
  479. /**
  480. * Catch `window.onerror`.
  481. */
  482. protected catchWindowOnError(): void;
  483. /**
  484. * Catch resource loading error: image, video, link, script.
  485. */
  486. protected catchResourceError(): void;
  487. /**
  488. * Catch `Promise.reject`.
  489. * @reference https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event
  490. */
  491. private catchUnhandledRejection;
  492. }
  493. export default VConsoleDefaultPlugin;
  494. }
  495. declare module "log/system" {
  496. import { VConsoleLogPlugin } from "log/log";
  497. export class VConsoleSystemPlugin extends VConsoleLogPlugin {
  498. onReady(): void;
  499. printSystemInfo(): void;
  500. }
  501. export default VConsoleSystemPlugin;
  502. }
  503. declare module "network/requestItem" {
  504. export type VConsoleRequestMethod = '' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
  505. export class VConsoleNetworkRequestItem {
  506. id: string;
  507. name?: string;
  508. method: VConsoleRequestMethod;
  509. url: string;
  510. status: number | string;
  511. statusText?: string;
  512. readyState?: XMLHttpRequest['readyState'];
  513. header: {
  514. [key: string]: string;
  515. };
  516. responseType: XMLHttpRequest['responseType'];
  517. requestType: 'xhr' | 'fetch' | 'ping' | 'custom';
  518. requestHeader: HeadersInit;
  519. response: any;
  520. startTime: number;
  521. endTime: number;
  522. costTime?: number;
  523. getData: {
  524. [key: string]: string;
  525. };
  526. postData: {
  527. [key: string]: string;
  528. } | string;
  529. actived: boolean;
  530. constructor();
  531. }
  532. export class VConsoleNetworkRequestItemProxy extends VConsoleNetworkRequestItem {
  533. static Handler: {
  534. get(item: VConsoleNetworkRequestItemProxy, prop: string): any;
  535. set(item: VConsoleNetworkRequestItemProxy, prop: string, value: any): boolean;
  536. };
  537. protected _response?: any;
  538. constructor(item: VConsoleNetworkRequestItem);
  539. }
  540. export const RequestItemHelper: {
  541. /**
  542. * Generate `getData` by url.
  543. */
  544. genGetDataByUrl(url: string, getData?: {}): {};
  545. /**
  546. * Generate formatted response data by responseType.
  547. */
  548. genResonseByResponseType(responseType: string, response: any): any;
  549. };
  550. }
  551. declare module "network/network.model" {
  552. import { VConsoleModel } from "lib/model";
  553. import { VConsoleNetworkRequestItem } from "network/requestItem";
  554. /**
  555. * Network Store
  556. */
  557. export const requestList: import("svelte/store").Writable<{
  558. [id: string]: VConsoleNetworkRequestItem;
  559. }>;
  560. /**
  561. * Network Model
  562. */
  563. export class VConsoleNetworkModel extends VConsoleModel {
  564. maxNetworkNumber: number;
  565. protected itemCounter: number;
  566. private _xhrOpen;
  567. private _xhrSend;
  568. private _xhrSetRequestHeader;
  569. private _fetch;
  570. private _sendBeacon;
  571. constructor();
  572. unMock(): void;
  573. clearLog(): void;
  574. /**
  575. * Add or update a request item by request ID.
  576. */
  577. updateRequest(id: string, data: VConsoleNetworkRequestItem): void;
  578. /**
  579. * mock XMLHttpRequest
  580. * @private
  581. */
  582. private mockXHR;
  583. /**
  584. * mock fetch request
  585. * @private
  586. */
  587. private mockFetch;
  588. /**
  589. * mock navigator.sendBeacon
  590. * @private
  591. */
  592. private mockSendBeacon;
  593. private getFormattedBody;
  594. private getURL;
  595. protected limitListLength(): void;
  596. }
  597. export default VConsoleNetworkModel;
  598. }
  599. declare module "network/network.exporter" {
  600. import { VConsolePluginExporter } from "lib/pluginExporter";
  601. import { VConsoleNetworkModel } from "network/network.model";
  602. import { VConsoleNetworkRequestItem, VConsoleNetworkRequestItemProxy } from "network/requestItem";
  603. export class VConsoleNetworkExporter extends VConsolePluginExporter {
  604. model: VConsoleNetworkModel;
  605. add(item: VConsoleNetworkRequestItem): VConsoleNetworkRequestItemProxy;
  606. update(id: string, item: VConsoleNetworkRequestItem): void;
  607. clear(): void;
  608. }
  609. }
  610. declare module "network/network" {
  611. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  612. import { VConsoleNetworkModel } from "network/network.model";
  613. import { VConsoleNetworkExporter } from "network/network.exporter";
  614. export class VConsoleNetworkPlugin extends VConsoleSveltePlugin {
  615. model: VConsoleNetworkModel;
  616. exporter: VConsoleNetworkExporter;
  617. constructor(id: string, name: string, renderProps?: {});
  618. onReady(): void;
  619. onAddTool(callback: any): void;
  620. onRemove(): void;
  621. onUpdateOption(): void;
  622. }
  623. }
  624. declare module "element/element.model" {
  625. export interface IVConsoleNode {
  626. nodeType: typeof Node.prototype.nodeType;
  627. nodeName: typeof Node.prototype.nodeName;
  628. textContent: typeof Node.prototype.textContent;
  629. id: typeof Element.prototype.id;
  630. className: typeof Element.prototype.className;
  631. attributes: {
  632. [name: string]: string;
  633. }[];
  634. childNodes: IVConsoleNode[];
  635. _isExpand?: boolean;
  636. _isActived?: boolean;
  637. _isSingleLine?: boolean;
  638. _isNullEndTag?: boolean;
  639. }
  640. /**
  641. * Element Store
  642. */
  643. export const rootNode: import("svelte/store").Writable<IVConsoleNode>;
  644. export const activedNode: import("svelte/store").Writable<IVConsoleNode>;
  645. }
  646. declare module "element/element" {
  647. import MutationObserver from 'mutation-observer';
  648. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  649. import type { IVConsoleNode } from "element/element.model";
  650. /**
  651. * vConsole Element Panel
  652. */
  653. export class VConsoleElementPlugin extends VConsoleSveltePlugin {
  654. protected isInited: boolean;
  655. protected observer: MutationObserver;
  656. protected nodeMap: WeakMap<Node, IVConsoleNode>;
  657. constructor(id: string, name: string, renderProps?: {});
  658. onShow(): void;
  659. onRemove(): void;
  660. onAddTool(callback: any): void;
  661. protected _init(): void;
  662. protected _handleMutation(mutation: MutationRecord): void;
  663. protected _onChildRemove(mutation: MutationRecord): void;
  664. protected _onChildAdd(mutation: MutationRecord): void;
  665. protected _onAttributesChange(mutation: MutationRecord): void;
  666. protected _onCharacterDataChange(mutation: MutationRecord): void;
  667. /**
  668. * Generate an VNode for rendering views. VNode will be updated if existing.
  669. * VNode will be stored in a WeakMap.
  670. */
  671. protected _generateVNode(elem: Node): IVConsoleNode;
  672. protected _updateVNodeAttributes(elem: Node): void;
  673. /**
  674. * Expand the actived node.
  675. * If the node is collapsed, expand it.
  676. * If the node is expanded, expand it's child nodes.
  677. */
  678. protected _expandActivedNode(): void;
  679. /**
  680. * Collapse the actived node.
  681. * If the node is expanded, and has expanded child nodes, collapse it's child nodes.
  682. * If the node is expanded, and has no expanded child node, collapse it self.
  683. * If the node is collapsed, do nothing.
  684. */
  685. protected _collapseActivedNode(): void;
  686. protected _isIgnoredNode(elem: Node): boolean;
  687. protected _isInVConsole(elem: Element): boolean;
  688. protected _refreshStore(): void;
  689. }
  690. }
  691. declare module "storage/cookieStorage" {
  692. import { CookieStorage } from 'cookie-storage';
  693. import type { CookieOptions } from 'cookie-storage/lib/cookie-options';
  694. export class VConsoleCookieStorage extends CookieStorage {
  695. /**
  696. * Deep remove a cookie.
  697. */
  698. removeItem(key: string, cookieOptions?: CookieOptions): void;
  699. /**
  700. * Deep clear all cookies.
  701. */
  702. clear(): void;
  703. }
  704. }
  705. declare module "storage/storage.model" {
  706. import { VConsoleCookieStorage } from "storage/cookieStorage";
  707. import { VConsoleModel } from "lib/model";
  708. interface IStorageItem {
  709. name: string;
  710. storage: Storage;
  711. }
  712. export class VConsoleStorageModel extends VConsoleModel {
  713. protected cookiesStorage: VConsoleCookieStorage;
  714. protected storages: IStorageItem[];
  715. /**
  716. * Get the singleton of storage list.
  717. */
  718. getAllStorages(): IStorageItem[];
  719. }
  720. }
  721. declare module "storage/storage" {
  722. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  723. import { VConsoleStorageModel } from "storage/storage.model";
  724. export class VConsoleStoragePlugin extends VConsoleSveltePlugin {
  725. protected model: VConsoleStorageModel;
  726. constructor(id: string, name: string, renderProps?: {});
  727. onShow(): void;
  728. onAddTopBar(callback: Function): void;
  729. onAddTool(callback: Function): void;
  730. }
  731. }
  732. declare module "core/core" {
  733. /**
  734. * vConsole core class
  735. */
  736. import type { SvelteComponent } from 'svelte';
  737. import { VConsolePlugin } from "lib/plugin";
  738. import { VConsoleLogPlugin } from "log/log";
  739. import { VConsoleDefaultPlugin } from "log/default";
  740. import { VConsoleSystemPlugin } from "log/system";
  741. import { VConsoleNetworkPlugin } from "network/network";
  742. import { VConsoleElementPlugin } from "element/element";
  743. import { VConsoleStoragePlugin } from "storage/storage";
  744. import { VConsoleLogExporter } from "log/log.exporter";
  745. import { VConsoleNetworkExporter } from "network/network.exporter";
  746. interface VConsoleOptions {
  747. target?: string | HTMLElement;
  748. defaultPlugins?: ('system' | 'network' | 'element' | 'storage')[];
  749. maxLogNumber?: number;
  750. maxNetworkNumber?: number;
  751. theme?: '' | 'dark' | 'light';
  752. disableLogScrolling?: boolean;
  753. onReady?: () => void;
  754. onClearLog?: () => void;
  755. }
  756. export class VConsole {
  757. version: string;
  758. isInited: boolean;
  759. option: VConsoleOptions;
  760. protected compInstance: SvelteComponent;
  761. protected pluginList: {
  762. [id: string]: VConsolePlugin;
  763. };
  764. log: VConsoleLogExporter;
  765. system: VConsoleLogExporter;
  766. network: VConsoleNetworkExporter;
  767. static VConsolePlugin: typeof VConsolePlugin;
  768. static VConsoleLogPlugin: typeof VConsoleLogPlugin;
  769. static VConsoleDefaultPlugin: typeof VConsoleDefaultPlugin;
  770. static VConsoleSystemPlugin: typeof VConsoleSystemPlugin;
  771. static VConsoleNetworkPlugin: typeof VConsoleNetworkPlugin;
  772. static VConsoleElementPlugin: typeof VConsoleElementPlugin;
  773. static VConsoleStoragePlugin: typeof VConsoleStoragePlugin;
  774. constructor(opt?: VConsoleOptions);
  775. /**
  776. * Add built-in plugins.
  777. */
  778. private _addBuiltInPlugins;
  779. /**
  780. * Init svelte component.
  781. */
  782. private _initComponent;
  783. private _updateComponentByOptions;
  784. /**
  785. * Update the position of Switch button.
  786. */
  787. setSwitchPosition(x: number, y: number): void;
  788. /**
  789. * Auto run after initialization.
  790. * @private
  791. */
  792. private _autoRun;
  793. private _showFirstPluginWhenEmpty;
  794. /**
  795. * Trigger a `vConsole.option` event.
  796. */
  797. triggerEvent(eventName: string, param?: any): void;
  798. /**
  799. * Init a plugin.
  800. */
  801. private _initPlugin;
  802. /**
  803. * Trigger an event for each plugin.
  804. */
  805. private _triggerPluginsEvent;
  806. /**
  807. * Trigger an event by plugin's id.
  808. * @private
  809. */
  810. private _triggerPluginEvent;
  811. /**
  812. * Add a new plugin.
  813. */
  814. addPlugin(plugin: VConsolePlugin): boolean;
  815. /**
  816. * Remove a plugin.
  817. */
  818. removePlugin(pluginID: string): boolean;
  819. /**
  820. * Show console panel.
  821. */
  822. show(): void;
  823. /**
  824. * Hide console panel.
  825. */
  826. hide(): void;
  827. /**
  828. * Show switch button
  829. */
  830. showSwitch(): void;
  831. /**
  832. * Hide switch button.
  833. */
  834. hideSwitch(): void;
  835. /**
  836. * Show a plugin panel.
  837. */
  838. showPlugin(pluginId: string): void;
  839. /**
  840. * Update option(s).
  841. */
  842. setOption(keyOrObj: any, value?: any): void;
  843. /**
  844. * Remove vConsole.
  845. */
  846. destroy(): void;
  847. }
  848. export default VConsole;
  849. }
  850. declare module "vconsole" {
  851. /**
  852. * A Front-End Console Panel for Mobile Webpage
  853. */
  854. import 'core-js/stable/symbol';
  855. import { VConsole } from "core/core";
  856. export default VConsole;
  857. }
  858. declare module "lib/mito" {
  859. /**
  860. * Mito.js
  861. * A simple template engine
  862. *
  863. * @author Maiz
  864. */
  865. export default class Mito {
  866. /**
  867. * Render `tpl` with `data` into a HTML string.
  868. */
  869. render<T extends true>(tpl: string, data: any, toString: T): string;
  870. /**
  871. * Render `tpl` with `data` into a HTML element.
  872. */
  873. render<T extends false>(tpl: string, data: any, toString?: T): Element;
  874. }
  875. }