vconsole.min.d.ts 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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. standardJSON?: boolean;
  101. }): string;
  102. /**
  103. * Call original `JSON.stringify` and catch unknown exceptions.
  104. */
  105. export function JSONStringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
  106. /**
  107. * Get the bytes of a string.
  108. * @example 'a' = 1
  109. * @example '好' = 3
  110. */
  111. export function getStringBytes(str: string): number;
  112. /**
  113. * Convert bytes number to 'MB' or 'KB' string.
  114. */
  115. export function getBytesText(bytes: number): string;
  116. /**
  117. * Get a string within a limited max length.
  118. * The byte size of the string will be appended to the string when reached the limit.
  119. * @return 'some string...(3.1 MB)'
  120. */
  121. export function getStringWithinLength(str: string, maxLen: number): string;
  122. /**
  123. * Sore an `string[]` by string.
  124. */
  125. export function sortArray(arr: string[]): string[];
  126. /**
  127. * Get enumerable keys of an object or array.
  128. */
  129. export function getEnumerableKeys(obj: any): string[];
  130. /**
  131. * Get enumerable and non-enumerable keys of an object or array.
  132. */
  133. export function getEnumerableAndNonEnumerableKeys(obj: any): string[];
  134. /**
  135. * Get non-enumerable keys of an object or array.
  136. */
  137. export function getNonEnumerableKeys(obj: any): string[];
  138. export function getSymbolKeys(obj: any): symbol[];
  139. /**
  140. * localStorage methods
  141. */
  142. export function setStorage(key: string, value: string): void;
  143. export function getStorage(key: string): string;
  144. /**
  145. * Generate a 6-digit unique string with prefix `"__vc_" + ${prefix}`
  146. */
  147. export function getUniqueID(prefix?: string): string;
  148. /**
  149. * Determine whether it is inside a WeChat Miniprogram.
  150. */
  151. export function isWxEnv(): boolean;
  152. /**
  153. * Call a WeChat Miniprogram method. E.g: `wx.getStorageSync()`.
  154. */
  155. export function callWx(method: string, ...args: any[]): any;
  156. }
  157. declare module "lib/query" {
  158. const $: {
  159. /**
  160. * get single element
  161. * @public
  162. */
  163. one: (selector: string, contextElement?: Element | Document) => HTMLElement;
  164. /**
  165. * get multiple elements
  166. * @public
  167. */
  168. all: (selector: string, contextElement?: Element | Document) => HTMLElement[];
  169. /**
  170. * add className(s) to an or multiple element(s)
  171. * @public
  172. */
  173. addClass: ($el: Element | Element[], className: string) => void;
  174. /**
  175. * remove className(s) from an or multiple element(s)
  176. * @public
  177. */
  178. removeClass: ($el: Element | Element[], className: string) => void;
  179. /**
  180. * see whether an element contains a className
  181. * @public
  182. */
  183. hasClass: ($el: Element, className: string) => boolean;
  184. /**
  185. * bind an event to element(s)
  186. * @public
  187. */
  188. bind: ($el: Element | Element[], eventType: any, fn: any, useCapture?: boolean) => void;
  189. /**
  190. * delegate an event to a parent element
  191. * @public
  192. * @param $el parent element
  193. * @param eventType name of the event
  194. * @param selector target's selector
  195. * @param fn callback function
  196. */
  197. delegate: ($el: Element, eventType: string, selector: string, fn: (event: Event, $target: HTMLElement) => void) => void;
  198. /**
  199. * Remove all child elements of an element.
  200. */
  201. removeChildren($el: Element): Element;
  202. };
  203. /**
  204. * export
  205. */
  206. export default $;
  207. }
  208. declare module "lib/model" {
  209. type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
  210. export class VConsoleModel {
  211. static singleton: {
  212. [ctorName: string]: VConsoleModel;
  213. };
  214. protected _onDataUpdateCallbacks: Function[];
  215. /**
  216. * Get a singleton of a model.
  217. */
  218. static getSingleton<T extends VConsoleModel>(ctor: AConstructorTypeOf<T>, ctorName: string): T;
  219. }
  220. export default VConsoleModel;
  221. }
  222. declare module "lib/pluginExporter" {
  223. import type { VConsoleModel } from "lib/model";
  224. export class VConsolePluginExporter {
  225. protected model: VConsoleModel;
  226. protected pluginId: string;
  227. constructor(pluginId: string);
  228. destroy(): void;
  229. }
  230. }
  231. declare module "lib/plugin" {
  232. import { VConsolePluginExporter } from "lib/pluginExporter";
  233. import type { VConsole } from "core/core";
  234. export type IVConsolePluginEvent = (data?: any) => void;
  235. export type IVConsolePluginEventName = 'init' | 'renderTab' | 'addTopBar' | 'addTool' | 'ready' | 'remove' | 'updateOption' | 'showConsole' | 'hideConsole' | 'show' | 'hide';
  236. export interface IVConsoleTopbarOptions {
  237. name: string;
  238. className: string;
  239. actived?: boolean;
  240. data?: {
  241. [key: string]: string;
  242. };
  243. onClick?: (e: Event, data?: any) => any;
  244. }
  245. export interface IVConsoleToolbarOptions {
  246. name: string;
  247. global?: boolean;
  248. data?: {
  249. [key: string]: string;
  250. };
  251. onClick?: (e: Event, data?: any) => any;
  252. }
  253. export interface IVConsoleTabOptions {
  254. fixedHeight?: boolean;
  255. }
  256. /**
  257. * vConsole Plugin Base Class
  258. */
  259. export class VConsolePlugin {
  260. isReady: boolean;
  261. eventMap: Map<IVConsolePluginEventName, IVConsolePluginEvent>;
  262. exporter?: VConsolePluginExporter;
  263. protected _id: string;
  264. protected _name: string;
  265. protected _vConsole: VConsole;
  266. constructor(...args: any[]);
  267. get id(): string;
  268. set id(value: string);
  269. get name(): string;
  270. set name(value: string);
  271. get vConsole(): VConsole;
  272. set vConsole(value: VConsole);
  273. /**
  274. * Register an event
  275. * @public
  276. * @param IVConsolePluginEventName
  277. * @param IVConsolePluginEvent
  278. */
  279. on(eventName: IVConsolePluginEventName, callback: IVConsolePluginEvent): this;
  280. onRemove(): void;
  281. /**
  282. * Trigger an event.
  283. */
  284. trigger(eventName: IVConsolePluginEventName, data?: any): this;
  285. protected bindExporter(): void;
  286. protected unbindExporter(): void;
  287. protected getUniqueID(prefix?: string): string;
  288. }
  289. export default VConsolePlugin;
  290. }
  291. declare module "lib/sveltePlugin" {
  292. import VConsolePlugin from "lib/plugin";
  293. import { SvelteComponent } from "vendor/svelte";
  294. export class VConsoleSveltePlugin<T extends {} = {}> extends VConsolePlugin {
  295. CompClass: typeof SvelteComponent;
  296. compInstance?: SvelteComponent;
  297. initialProps: T;
  298. constructor(id: string, name: string, CompClass: typeof SvelteComponent, initialProps: T);
  299. onReady(): void;
  300. onRenderTab(callback: any): void;
  301. onRemove(): void;
  302. }
  303. }
  304. declare module "core/core.model" {
  305. export const contentStore: {
  306. subscribe: (this: void, run: import("vendor/svelte/store").Subscriber<{
  307. updateTime: number;
  308. }>, invalidate?: (value?: {
  309. updateTime: number;
  310. }) => void) => import("vendor/svelte/store").Unsubscriber;
  311. set: (this: void, value: {
  312. updateTime: number;
  313. }) => void;
  314. update: (this: void, updater: import("vendor/svelte/store").Updater<{
  315. updateTime: number;
  316. }>) => void;
  317. updateTime: () => void;
  318. };
  319. }
  320. declare module "log/logTool" {
  321. import type { IVConsoleLog, IVConsoleLogData } from "log/log.model";
  322. /**
  323. * Get a value's text content and its type.
  324. */
  325. export const getValueTextAndType: (val: any, wrapString?: boolean) => {
  326. text: any;
  327. valueType: string;
  328. };
  329. /**
  330. * A simple parser to get `[` or `]` information.
  331. */
  332. export const getLastIdentifier: (text: string) => {
  333. front: {
  334. text: string;
  335. pos: number;
  336. before: string;
  337. after: string;
  338. };
  339. back: {
  340. text: string;
  341. pos: number;
  342. before: string;
  343. after: string;
  344. };
  345. };
  346. export const isMatchedFilterText: (log: IVConsoleLog, filterText: string) => boolean;
  347. /**
  348. * Styling log output (`%c`), or string substitutions (`%s`, `%d`, `%o`).
  349. * Apply to the first log only.
  350. */
  351. export const getLogDatasWithFormatting: (origDatas: any[]) => IVConsoleLogData[];
  352. /**
  353. * An empty class for rendering views.
  354. */
  355. export class VConsoleUninvocatableObject {
  356. }
  357. }
  358. declare module "log/log.store" {
  359. import type { Writable } from "vendor/svelte/store";
  360. import type { IVConsoleLog } from "log/log.model";
  361. export interface IVConsoleLogStore {
  362. logList: IVConsoleLog[];
  363. }
  364. /**
  365. * Log Store Factory
  366. */
  367. export class VConsoleLogStore {
  368. static storeMap: {
  369. [pluginId: string]: Writable<IVConsoleLogStore>;
  370. };
  371. /**
  372. * Create a store.
  373. */
  374. static create(pluginId: string): Writable<IVConsoleLogStore>;
  375. /**
  376. * Delete a store.
  377. */
  378. static delete(pluginId: string): void;
  379. /**
  380. * Get a store by pluginId,
  381. */
  382. static get(pluginId: string): Writable<IVConsoleLogStore>;
  383. /**
  384. * Get a store's raw data.
  385. */
  386. static getRaw(pluginId: string): IVConsoleLogStore;
  387. /**
  388. * Get all stores.
  389. */
  390. static getAll(): {
  391. [pluginId: string]: Writable<IVConsoleLogStore>;
  392. };
  393. }
  394. }
  395. declare module "log/log.model" {
  396. import { VConsoleModel } from "lib/model";
  397. /**********************************
  398. * Interfaces
  399. **********************************/
  400. export type IConsoleLogMethod = 'log' | 'info' | 'debug' | 'warn' | 'error';
  401. export interface IVConsoleLogData {
  402. origData: any;
  403. style?: string;
  404. }
  405. export interface IVConsoleLog {
  406. _id: string;
  407. type: IConsoleLogMethod;
  408. cmdType?: 'input' | 'output';
  409. repeated: number;
  410. toggle: Record<string, boolean>;
  411. date: number;
  412. data: IVConsoleLogData[];
  413. groupLevel: number;
  414. groupLabel?: symbol;
  415. groupHeader?: 0 | 1 | 2;
  416. groupCollapsed?: boolean;
  417. }
  418. export type IVConsoleLogListMap = {
  419. [pluginId: string]: IVConsoleLog[];
  420. };
  421. export type IVConsoleLogFilter = {
  422. [pluginId: string]: string;
  423. };
  424. export interface IVConsoleAddLogOptions {
  425. noOrig?: boolean;
  426. cmdType?: 'input' | 'output';
  427. }
  428. /**********************************
  429. * Stores
  430. **********************************/
  431. /**********************************
  432. * Model
  433. **********************************/
  434. export class VConsoleLogModel extends VConsoleModel {
  435. readonly LOG_METHODS: IConsoleLogMethod[];
  436. ADDED_LOG_PLUGIN_ID: string[];
  437. maxLogNumber: number;
  438. protected logCounter: number;
  439. protected groupLevel: number;
  440. protected groupLabelCollapsedStack: {
  441. label: symbol;
  442. collapsed: boolean;
  443. }[];
  444. protected pluginPattern: RegExp;
  445. protected logQueue: IVConsoleLog[];
  446. protected flushLogScheduled: boolean;
  447. /**
  448. * The original `window.console` methods.
  449. */
  450. origConsole: {
  451. [method: string]: Function;
  452. };
  453. /**
  454. * Bind a Log plugin.
  455. * When binding first plugin, `window.console` will be hooked.
  456. */
  457. bindPlugin(pluginId: string): boolean;
  458. /**
  459. * Unbind a Log plugin.
  460. * When no binded plugin exists, hooked `window.console` will be recovered.
  461. */
  462. unbindPlugin(pluginId: string): boolean;
  463. /**
  464. * Hook `window.console` with vConsole log method.
  465. * Methods will be hooked only once.
  466. */
  467. mockConsole(): void;
  468. protected _mockConsoleLog(): void;
  469. protected _mockConsoleTime(): void;
  470. protected _mockConsoleGroup(): void;
  471. protected _mockConsoleClear(): void;
  472. /**
  473. * Recover `window.console`.
  474. */
  475. unmockConsole(): void;
  476. /**
  477. * Call origin `window.console[method](...args)`
  478. */
  479. callOriginalConsole(method: string, ...args: any[]): void;
  480. /**
  481. * Remove all logs.
  482. */
  483. clearLog(): void;
  484. /**
  485. * Remove a plugin's logs.
  486. */
  487. clearPluginLog(pluginId: string): void;
  488. /**
  489. * Add a vConsole log.
  490. */
  491. addLog(item?: {
  492. type: IConsoleLogMethod;
  493. origData: any[];
  494. isGroupHeader?: 0 | 1 | 2;
  495. isGroupCollapsed?: boolean;
  496. }, opt?: IVConsoleAddLogOptions): void;
  497. /**
  498. * Execute a JS command.
  499. */
  500. evalCommand(cmd: string): void;
  501. protected _signalLog(log: IVConsoleLog): void;
  502. protected _flushLogs(): void;
  503. protected _extractPluginIdByLog(log: IVConsoleLog): string;
  504. protected _isRepeatedLog(logList: IVConsoleLog[], log: IVConsoleLog): boolean;
  505. protected _updateLastLogRepeated(logList: IVConsoleLog[]): IVConsoleLog[];
  506. protected _limitLogListLength(logList: IVConsoleLog[]): IVConsoleLog[];
  507. }
  508. }
  509. declare module "log/log.exporter" {
  510. import { VConsolePluginExporter } from "lib/pluginExporter";
  511. import { VConsoleLogModel } from "log/log.model";
  512. import type { IConsoleLogMethod } from "log/log.model";
  513. export class VConsoleLogExporter extends VConsolePluginExporter {
  514. model: VConsoleLogModel;
  515. log(...args: any[]): void;
  516. info(...args: any[]): void;
  517. debug(...args: any[]): void;
  518. warn(...args: any[]): void;
  519. error(...args: any[]): void;
  520. clear(): void;
  521. protected addLog(method: IConsoleLogMethod, ...args: any[]): void;
  522. }
  523. }
  524. declare module "log/log" {
  525. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  526. import { VConsoleLogModel } from "log/log.model";
  527. /**
  528. * vConsole Log Plugin (base class).
  529. */
  530. export class VConsoleLogPlugin extends VConsoleSveltePlugin {
  531. model: VConsoleLogModel;
  532. isReady: boolean;
  533. isShow: boolean;
  534. isInBottom: boolean;
  535. constructor(id: string, name: string);
  536. onReady(): void;
  537. onRemove(): void;
  538. onAddTopBar(callback: Function): void;
  539. onAddTool(callback: Function): void;
  540. onUpdateOption(): void;
  541. }
  542. export default VConsoleLogPlugin;
  543. }
  544. declare module "log/default" {
  545. import { VConsoleLogPlugin } from "log/log";
  546. export class VConsoleDefaultPlugin extends VConsoleLogPlugin {
  547. protected onErrorHandler: any;
  548. protected resourceErrorHandler: any;
  549. protected rejectionHandler: any;
  550. onReady(): void;
  551. onRemove(): void;
  552. /**
  553. * Catch window errors.
  554. */
  555. protected bindErrors(): void;
  556. /**
  557. * Not catch window errors.
  558. */
  559. protected unbindErrors(): void;
  560. /**
  561. * Catch `window.onerror`.
  562. */
  563. protected catchWindowOnError(): void;
  564. /**
  565. * Catch resource loading error: image, video, link, script.
  566. */
  567. protected catchResourceError(): void;
  568. /**
  569. * Catch `Promise.reject`.
  570. * @reference https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event
  571. */
  572. private catchUnhandledRejection;
  573. }
  574. export default VConsoleDefaultPlugin;
  575. }
  576. declare module "log/system" {
  577. import { VConsoleLogPlugin } from "log/log";
  578. export class VConsoleSystemPlugin extends VConsoleLogPlugin {
  579. onReady(): void;
  580. printSystemInfo(): void;
  581. }
  582. export default VConsoleSystemPlugin;
  583. }
  584. declare module "network/helper" {
  585. import type { VConsoleNetworkRequestItem } from "network/requestItem";
  586. export type IOnUpdateCallback = (item: VConsoleNetworkRequestItem) => void;
  587. /**
  588. * Generate `getData` by url.
  589. */
  590. export const genGetDataByUrl: (url: string, getData?: {}) => {};
  591. /**
  592. * Generate formatted response data by responseType.
  593. */
  594. export const genResonseByResponseType: (responseType: string, response: any) => string;
  595. /**
  596. * Generate formatted response body by XMLHttpRequestBodyInit.
  597. */
  598. export const genFormattedBody: (body?: BodyInit) => string | {
  599. [key: string]: string;
  600. };
  601. /**
  602. * Get formatted URL object by string.
  603. */
  604. export const getURL: (urlString?: string) => URL;
  605. }
  606. declare module "network/requestItem" {
  607. export type VConsoleRequestMethod = '' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
  608. export class VConsoleNetworkRequestItem {
  609. id: string;
  610. name?: string;
  611. method: VConsoleRequestMethod;
  612. url: string;
  613. status: number | string;
  614. statusText?: string;
  615. cancelState?: 0 | 1 | 2 | 3;
  616. readyState?: XMLHttpRequest['readyState'];
  617. header: {
  618. [key: string]: string;
  619. };
  620. responseType: XMLHttpRequest['responseType'];
  621. requestType: 'xhr' | 'fetch' | 'ping' | 'custom';
  622. requestHeader: HeadersInit;
  623. response: any;
  624. responseSize: number;
  625. responseSizeText: string;
  626. startTime: number;
  627. startTimeText: string;
  628. endTime: number;
  629. costTime?: number;
  630. getData: {
  631. [key: string]: string;
  632. };
  633. postData: {
  634. [key: string]: string;
  635. } | string;
  636. actived: boolean;
  637. noVConsole?: boolean;
  638. constructor();
  639. }
  640. export class VConsoleNetworkRequestItemProxy extends VConsoleNetworkRequestItem {
  641. static Handler: {
  642. get(item: VConsoleNetworkRequestItemProxy, prop: string): any;
  643. set(item: VConsoleNetworkRequestItemProxy, prop: string, value: any): boolean;
  644. };
  645. protected _response?: any;
  646. constructor(item: VConsoleNetworkRequestItem);
  647. }
  648. }
  649. declare module "network/xhr.proxy" {
  650. import { VConsoleNetworkRequestItem } from "network/requestItem";
  651. import type { IOnUpdateCallback } from "network/helper";
  652. export class XHRProxyHandler<T extends XMLHttpRequest> implements ProxyHandler<T> {
  653. XMLReq: XMLHttpRequest;
  654. item: VConsoleNetworkRequestItem;
  655. protected onUpdateCallback: IOnUpdateCallback;
  656. constructor(XMLReq: XMLHttpRequest, onUpdateCallback: IOnUpdateCallback);
  657. get(target: T, key: string): any;
  658. set(target: T, key: string, value: any): boolean;
  659. onReadyStateChange(): void;
  660. onAbort(): void;
  661. onTimeout(): void;
  662. protected triggerUpdate(): void;
  663. protected getOpen(target: T): (...args: any[]) => any;
  664. protected getSend(target: T): (...args: any[]) => any;
  665. protected getSetRequestHeader(target: T): (...args: any[]) => any;
  666. protected setOnReadyStateChange(target: T, key: string, value: any): boolean;
  667. protected setOnAbort(target: T, key: string, value: any): boolean;
  668. protected setOnTimeout(target: T, key: string, value: any): boolean;
  669. /**
  670. * Update item's properties according to readyState.
  671. */
  672. protected updateItemByReadyState(): void;
  673. }
  674. export class XHRProxy {
  675. static origXMLHttpRequest: {
  676. new (): XMLHttpRequest;
  677. prototype: XMLHttpRequest;
  678. readonly DONE: number;
  679. readonly HEADERS_RECEIVED: number;
  680. readonly LOADING: number;
  681. readonly OPENED: number;
  682. readonly UNSENT: number;
  683. };
  684. static create(onUpdateCallback: IOnUpdateCallback): {
  685. new (): XMLHttpRequest;
  686. prototype: XMLHttpRequest;
  687. readonly DONE: number;
  688. readonly HEADERS_RECEIVED: number;
  689. readonly LOADING: number;
  690. readonly OPENED: number;
  691. readonly UNSENT: number;
  692. };
  693. }
  694. }
  695. declare module "network/fetch.proxy" {
  696. import { VConsoleNetworkRequestItem } from "network/requestItem";
  697. import type { IOnUpdateCallback } from "network/helper";
  698. export class ResponseProxyHandler<T extends Response> implements ProxyHandler<T> {
  699. resp: Response;
  700. item: VConsoleNetworkRequestItem;
  701. protected onUpdateCallback: IOnUpdateCallback;
  702. constructor(resp: T, item: VConsoleNetworkRequestItem, onUpdateCallback: IOnUpdateCallback);
  703. set(target: T, key: string, value: any): boolean;
  704. get(target: T, key: string): any;
  705. protected mockReader(): void;
  706. }
  707. export class FetchProxyHandler<T extends typeof fetch> implements ProxyHandler<T> {
  708. protected onUpdateCallback: IOnUpdateCallback;
  709. constructor(onUpdateCallback: IOnUpdateCallback);
  710. apply(target: T, thisArg: typeof window, argsList: any): Promise<Response>;
  711. protected beforeFetch(item: VConsoleNetworkRequestItem, input: RequestInfo, init?: RequestInit): void;
  712. protected afterFetch(item: any): (resp: Response) => Response;
  713. protected handleResponseBody(resp: Response, item: VConsoleNetworkRequestItem): Promise<ArrayBuffer> | Promise<string>;
  714. }
  715. export class FetchProxy {
  716. static origFetch: typeof fetch;
  717. static create(onUpdateCallback: IOnUpdateCallback): typeof fetch;
  718. }
  719. }
  720. declare module "network/beacon.proxy" {
  721. import type { IOnUpdateCallback } from "network/helper";
  722. export class BeaconProxyHandler<T extends typeof navigator.sendBeacon> implements ProxyHandler<T> {
  723. protected onUpdateCallback: IOnUpdateCallback;
  724. constructor(onUpdateCallback: IOnUpdateCallback);
  725. apply(target: T, thisArg: T, argsList: any[]): any;
  726. }
  727. export class BeaconProxy {
  728. static origSendBeacon: (url: string | URL, data?: BodyInit) => boolean;
  729. static create(onUpdateCallback: IOnUpdateCallback): any;
  730. }
  731. }
  732. declare module "network/network.model" {
  733. import { VConsoleModel } from "lib/model";
  734. import { VConsoleNetworkRequestItem } from "network/requestItem";
  735. /**
  736. * Network Store
  737. */
  738. export const requestList: import("vendor/svelte/store").Writable<{
  739. [id: string]: VConsoleNetworkRequestItem;
  740. }>;
  741. /**
  742. * Network Model
  743. */
  744. export class VConsoleNetworkModel extends VConsoleModel {
  745. maxNetworkNumber: number;
  746. protected itemCounter: number;
  747. constructor();
  748. unMock(): void;
  749. clearLog(): void;
  750. /**
  751. * Add or update a request item by request ID.
  752. */
  753. updateRequest(id: string, data: VConsoleNetworkRequestItem): void;
  754. /**
  755. * mock XMLHttpRequest
  756. * @private
  757. */
  758. private mockXHR;
  759. /**
  760. * mock fetch request
  761. * @private
  762. */
  763. private mockFetch;
  764. /**
  765. * mock navigator.sendBeacon
  766. * @private
  767. */
  768. private mockSendBeacon;
  769. protected limitListLength(): void;
  770. }
  771. export default VConsoleNetworkModel;
  772. }
  773. declare module "network/network.exporter" {
  774. import { VConsolePluginExporter } from "lib/pluginExporter";
  775. import { VConsoleNetworkModel } from "network/network.model";
  776. import { VConsoleNetworkRequestItem, VConsoleNetworkRequestItemProxy } from "network/requestItem";
  777. export class VConsoleNetworkExporter extends VConsolePluginExporter {
  778. model: VConsoleNetworkModel;
  779. add(item: VConsoleNetworkRequestItem): VConsoleNetworkRequestItemProxy;
  780. update(id: string, item: VConsoleNetworkRequestItem): void;
  781. clear(): void;
  782. }
  783. }
  784. declare module "network/network" {
  785. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  786. import { VConsoleNetworkModel } from "network/network.model";
  787. import { VConsoleNetworkExporter } from "network/network.exporter";
  788. export class VConsoleNetworkPlugin extends VConsoleSveltePlugin {
  789. model: VConsoleNetworkModel;
  790. exporter: VConsoleNetworkExporter;
  791. constructor(id: string, name: string, renderProps?: {});
  792. onReady(): void;
  793. onAddTool(callback: any): void;
  794. onRemove(): void;
  795. onUpdateOption(): void;
  796. }
  797. }
  798. declare module "element/element.model" {
  799. export interface IVConsoleNode {
  800. nodeType: typeof Node.prototype.nodeType;
  801. nodeName: typeof Node.prototype.nodeName;
  802. textContent: typeof Node.prototype.textContent;
  803. id: typeof Element.prototype.id;
  804. className: typeof Element.prototype.className;
  805. attributes: {
  806. [name: string]: string;
  807. }[];
  808. childNodes: IVConsoleNode[];
  809. _isExpand?: boolean;
  810. _isActived?: boolean;
  811. _isSingleLine?: boolean;
  812. _isNullEndTag?: boolean;
  813. }
  814. /**
  815. * Element Store
  816. */
  817. export const rootNode: import("vendor/svelte/store").Writable<IVConsoleNode>;
  818. export const activedNode: import("vendor/svelte/store").Writable<IVConsoleNode>;
  819. }
  820. declare module "element/element" {
  821. import MutationObserver from "vendor/mutation-observer";
  822. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  823. import type { IVConsoleNode } from "element/element.model";
  824. /**
  825. * vConsole Element Panel
  826. */
  827. export class VConsoleElementPlugin extends VConsoleSveltePlugin {
  828. protected isInited: boolean;
  829. protected observer: MutationObserver;
  830. protected nodeMap: WeakMap<Node, IVConsoleNode>;
  831. constructor(id: string, name: string, renderProps?: {});
  832. onShow(): void;
  833. onRemove(): void;
  834. onAddTool(callback: any): void;
  835. protected _init(): void;
  836. protected _handleMutation(mutation: MutationRecord): void;
  837. protected _onChildRemove(mutation: MutationRecord): void;
  838. protected _onChildAdd(mutation: MutationRecord): void;
  839. protected _onAttributesChange(mutation: MutationRecord): void;
  840. protected _onCharacterDataChange(mutation: MutationRecord): void;
  841. /**
  842. * Generate an VNode for rendering views. VNode will be updated if existing.
  843. * VNode will be stored in a WeakMap.
  844. */
  845. protected _generateVNode(elem: Node): IVConsoleNode;
  846. protected _updateVNodeAttributes(elem: Node): void;
  847. /**
  848. * Expand the actived node.
  849. * If the node is collapsed, expand it.
  850. * If the node is expanded, expand it's child nodes.
  851. */
  852. protected _expandActivedNode(): void;
  853. /**
  854. * Collapse the actived node.
  855. * If the node is expanded, and has expanded child nodes, collapse it's child nodes.
  856. * If the node is expanded, and has no expanded child node, collapse it self.
  857. * If the node is collapsed, do nothing.
  858. */
  859. protected _collapseActivedNode(): void;
  860. protected _isIgnoredNode(elem: Node): boolean;
  861. protected _isInVConsole(elem: Element): boolean;
  862. protected _refreshStore(): void;
  863. }
  864. }
  865. declare module "storage/storage.cookie" {
  866. import type { IStorage } from "storage/storage.model";
  867. export interface CookieOptions {
  868. path?: string | null;
  869. domain?: string | null;
  870. expires?: Date | null;
  871. secure?: boolean;
  872. sameSite?: 'Strict' | 'Lax' | 'None';
  873. }
  874. export class CookieStorage implements IStorage {
  875. get length(): number;
  876. /**
  877. * Returns sorted keys.
  878. */
  879. get keys(): string[];
  880. key(index: number): string;
  881. setItem(key: string, data: string, cookieOptions?: CookieOptions): void;
  882. getItem(key: string): string;
  883. removeItem(key: string, cookieOptions?: CookieOptions): void;
  884. clear(): void;
  885. }
  886. }
  887. declare module "storage/storage.wx" {
  888. import type { IStorage } from "storage/storage.model";
  889. export class WxStorage implements IStorage {
  890. keys: string[];
  891. currentSize: number;
  892. limitSize: number;
  893. get length(): number;
  894. key(index: number): string;
  895. /**
  896. * Prepare for async data.
  897. */
  898. prepare(): Promise<boolean>;
  899. getItem(key: string): Promise<string>;
  900. setItem(key: string, data: any): Promise<void>;
  901. removeItem(key: string): Promise<void>;
  902. clear(): Promise<void>;
  903. }
  904. }
  905. declare module "storage/storage.model" {
  906. import type { VConsoleAvailableStorage } from "core/options.interface";
  907. import { VConsoleModel } from "lib/model";
  908. export interface IStorage {
  909. length: number;
  910. key: (index: number) => string | null;
  911. getItem: (key: string) => string | null | Promise<string | null>;
  912. setItem: (key: string, data: any) => void | Promise<void>;
  913. removeItem: (key: string) => void | Promise<void>;
  914. clear: () => void | Promise<void>;
  915. prepare?: () => Promise<boolean>;
  916. }
  917. /**
  918. * Storage Store
  919. */
  920. export const storageStore: {
  921. updateTime: import("vendor/svelte/store").Writable<number>;
  922. activedName: import("vendor/svelte/store").Writable<VConsoleAvailableStorage>;
  923. defaultStorages: import("vendor/svelte/store").Writable<VConsoleAvailableStorage[]>;
  924. };
  925. export class VConsoleStorageModel extends VConsoleModel {
  926. protected storage: Map<VConsoleAvailableStorage, IStorage>;
  927. constructor();
  928. get activedStorage(): IStorage;
  929. getItem(key: string): Promise<string>;
  930. setItem(key: string, data: any): Promise<void>;
  931. removeItem(key: string): Promise<void>;
  932. clear(): Promise<void>;
  933. refresh(): void;
  934. /**
  935. * Get key-value data.
  936. */
  937. getEntries(): Promise<[string, string][]>;
  938. updateEnabledStorages(): void;
  939. protected promisify<T extends string | void>(ret: T | Promise<T>): T | Promise<T>;
  940. protected deleteStorage(key: VConsoleAvailableStorage): void;
  941. }
  942. }
  943. declare module "storage/storage" {
  944. import { VConsoleSveltePlugin } from "lib/sveltePlugin";
  945. import { VConsoleStorageModel } from "storage/storage.model";
  946. export class VConsoleStoragePlugin extends VConsoleSveltePlugin {
  947. protected model: VConsoleStorageModel;
  948. protected onAddTopBarCallback: Function;
  949. constructor(id: string, name: string, renderProps?: {});
  950. onReady(): void;
  951. onShow(): void;
  952. onAddTopBar(callback: Function): void;
  953. onAddTool(callback: Function): void;
  954. onUpdateOption(): void;
  955. protected updateTopBar(): void;
  956. }
  957. }
  958. declare module "core/core" {
  959. /**
  960. * vConsole core class
  961. */
  962. import type { SvelteComponent } from "vendor/svelte";
  963. import type { VConsoleOptions } from "core/options.interface";
  964. import { VConsolePlugin } from "lib/plugin";
  965. import { VConsoleLogPlugin } from "log/log";
  966. import { VConsoleDefaultPlugin } from "log/default";
  967. import { VConsoleSystemPlugin } from "log/system";
  968. import { VConsoleNetworkPlugin } from "network/network";
  969. import { VConsoleElementPlugin } from "element/element";
  970. import { VConsoleStoragePlugin } from "storage/storage";
  971. import { VConsoleLogExporter } from "log/log.exporter";
  972. import { VConsoleNetworkExporter } from "network/network.exporter";
  973. export class VConsole {
  974. version: string;
  975. isInited: boolean;
  976. option: VConsoleOptions;
  977. protected compInstance: SvelteComponent;
  978. protected pluginList: {
  979. [id: string]: VConsolePlugin;
  980. };
  981. log: VConsoleLogExporter;
  982. system: VConsoleLogExporter;
  983. network: VConsoleNetworkExporter;
  984. static VConsolePlugin: typeof VConsolePlugin;
  985. static VConsoleLogPlugin: typeof VConsoleLogPlugin;
  986. static VConsoleDefaultPlugin: typeof VConsoleDefaultPlugin;
  987. static VConsoleSystemPlugin: typeof VConsoleSystemPlugin;
  988. static VConsoleNetworkPlugin: typeof VConsoleNetworkPlugin;
  989. static VConsoleElementPlugin: typeof VConsoleElementPlugin;
  990. static VConsoleStoragePlugin: typeof VConsoleStoragePlugin;
  991. constructor(opt?: VConsoleOptions);
  992. /**
  993. * Get singleton instance.
  994. **/
  995. static get instance(): VConsole | undefined;
  996. /**
  997. * Set singleton instance.
  998. **/
  999. static set instance(value: VConsole | undefined);
  1000. /**
  1001. * Add built-in plugins.
  1002. */
  1003. private _addBuiltInPlugins;
  1004. /**
  1005. * Init svelte component.
  1006. */
  1007. private _initComponent;
  1008. private _updateComponentByOptions;
  1009. /**
  1010. * Update the position of Switch button.
  1011. */
  1012. setSwitchPosition(x: number, y: number): void;
  1013. /**
  1014. * Auto run after initialization.
  1015. * @private
  1016. */
  1017. private _autoRun;
  1018. private _showFirstPluginWhenEmpty;
  1019. /**
  1020. * Trigger a `vConsole.option` event.
  1021. */
  1022. triggerEvent(eventName: string, param?: any): void;
  1023. /**
  1024. * Init a plugin.
  1025. */
  1026. private _initPlugin;
  1027. /**
  1028. * Trigger an event for each plugin.
  1029. */
  1030. private _triggerPluginsEvent;
  1031. /**
  1032. * Trigger an event by plugin's id.
  1033. * @private
  1034. */
  1035. private _triggerPluginEvent;
  1036. /**
  1037. * Sorting plugin list by option `pluginOrder`.
  1038. * Plugin not listed in `pluginOrder` will be put last.
  1039. */
  1040. private _reorderPluginList;
  1041. /**
  1042. * Add a new plugin.
  1043. */
  1044. addPlugin(plugin: VConsolePlugin): boolean;
  1045. /**
  1046. * Remove a plugin.
  1047. */
  1048. removePlugin(pluginID: string): boolean;
  1049. /**
  1050. * Show console panel.
  1051. */
  1052. show(): void;
  1053. /**
  1054. * Hide console panel.
  1055. */
  1056. hide(): void;
  1057. /**
  1058. * Show switch button
  1059. */
  1060. showSwitch(): void;
  1061. /**
  1062. * Hide switch button.
  1063. */
  1064. hideSwitch(): void;
  1065. /**
  1066. * Show a plugin panel.
  1067. */
  1068. showPlugin(pluginId: string): void;
  1069. /**
  1070. * Update option(s).
  1071. * @example `setOption('log.maxLogNumber', 20)`: set 'maxLogNumber' field only.
  1072. * @example `setOption({ log: { maxLogNumber: 20 }})`: overwrite 'log' object.
  1073. */
  1074. setOption(keyOrObj: any, value?: any): void;
  1075. /**
  1076. * Remove vConsole.
  1077. */
  1078. destroy(): void;
  1079. }
  1080. }
  1081. declare module "vconsole" {
  1082. /**
  1083. * A Front-End Console Panel for Mobile Webpage
  1084. */
  1085. import "vendor/core-js/stable/symbol";
  1086. import 'core-js/stable/promise';
  1087. import { VConsole } from "core/core";
  1088. export default VConsole;
  1089. }
  1090. declare module "component/recycleScroller/recycleManager" {
  1091. const createRecycleManager: () => (itemCount: number, start: number, end: number) => {
  1092. key: number;
  1093. index: number;
  1094. show: boolean;
  1095. }[];
  1096. export default createRecycleManager;
  1097. }
  1098. declare module "component/recycleScroller/scroll/friction" {
  1099. /** *
  1100. * Friction physics simulation. Friction is actually just a simple
  1101. * power curve; the only trick is taking the natural log of the
  1102. * initial drag so that we can express the answer in terms of time.
  1103. */
  1104. class Friction {
  1105. private _drag;
  1106. private _dragLog;
  1107. private _x;
  1108. private _v;
  1109. private _startTime;
  1110. constructor(drag: number);
  1111. set(x: number, v: number, t?: number): void;
  1112. x(t: number): number;
  1113. dx(t: number): number;
  1114. done(t: number): boolean;
  1115. }
  1116. export default Friction;
  1117. }
  1118. declare module "component/recycleScroller/scroll/linear" {
  1119. class Linear {
  1120. private _x;
  1121. private _endX;
  1122. private _v;
  1123. private _startTime;
  1124. private _endTime;
  1125. set(x: number, endX: number, dt: number, t?: number): void;
  1126. x(t: number): number;
  1127. dx(t: number): number;
  1128. done(t: number): boolean;
  1129. }
  1130. export default Linear;
  1131. }
  1132. declare module "component/recycleScroller/scroll/spring" {
  1133. class Spring {
  1134. private _solver;
  1135. private _solution;
  1136. private _endPosition;
  1137. private _startTime;
  1138. constructor(mass: number, springConstant: number, damping: number);
  1139. x(t: number): number;
  1140. dx(t: number): number;
  1141. set(endPosition: number, x: number, velocity: number, t?: number): void;
  1142. done(t: number): boolean;
  1143. }
  1144. export default Spring;
  1145. }
  1146. declare module "component/recycleScroller/scroll/scroll" {
  1147. /** *
  1148. * Scroll combines Friction and Spring to provide the
  1149. * classic "flick-with-bounce" behavior.
  1150. */
  1151. class Scroll {
  1152. private _enableSpring;
  1153. private _getExtend;
  1154. private _friction;
  1155. private _spring;
  1156. private _toEdge;
  1157. constructor(getExtend: () => number, _enableSpring: boolean);
  1158. set(x: number, v: number, t?: number): void;
  1159. x(t: number): number;
  1160. dx(t: number): number;
  1161. done(t: number): boolean;
  1162. }
  1163. export default Scroll;
  1164. }
  1165. declare module "component/recycleScroller/scroll/touchTracker" {
  1166. export interface TrackerHandler {
  1167. onTouchStart(): void;
  1168. onTouchMove(x: number, y: number): void;
  1169. onTouchEnd(x: number, y: number, velocityX: number, velocityY: number): void;
  1170. onTouchCancel(): void;
  1171. onWheel(x: number, y: number): void;
  1172. }
  1173. class TouchTracker {
  1174. private _handler;
  1175. private _touchId;
  1176. private _startX;
  1177. private _startY;
  1178. private _historyX;
  1179. private _historyY;
  1180. private _historyTime;
  1181. private _wheelDeltaX;
  1182. private _wheelDeltaY;
  1183. constructor(_handler: TrackerHandler);
  1184. private _getTouchDelta;
  1185. private _onTouchMove;
  1186. private _onWheel;
  1187. handleTouchStart: (e: TouchEvent) => void;
  1188. handleTouchMove: (e: TouchEvent) => void;
  1189. handleTouchEnd: (e: TouchEvent) => void;
  1190. handleTouchCancel: (e: TouchEvent) => void;
  1191. handleWheel: (e: WheelEvent) => void;
  1192. }
  1193. export default TouchTracker;
  1194. }
  1195. declare module "component/recycleScroller/scroll/scrollHandler" {
  1196. import { TrackerHandler } from "component/recycleScroller/scroll/touchTracker";
  1197. class ScrollHandler implements TrackerHandler {
  1198. private _updatePosition;
  1199. private _scrollModel;
  1200. private _linearModel;
  1201. private _startPosition;
  1202. private _position;
  1203. private _animate;
  1204. private _getExtent;
  1205. constructor(getExtent: () => number, _updatePosition: (pos: number) => void);
  1206. onTouchStart(): void;
  1207. onTouchMove(dx: number, dy: number): void;
  1208. onTouchEnd(dx: number, dy: number, velocityX: number, velocityY: number): void;
  1209. onTouchCancel(): void;
  1210. onWheel(x: number, y: number): void;
  1211. getPosition(): number;
  1212. updatePosition(position: number): void;
  1213. scrollTo(position: number, duration?: number): void;
  1214. }
  1215. export default ScrollHandler;
  1216. }