vconsole.min.d.ts 36 KB

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