vconsole.min.d.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. * determines whether the passed value is a specific type
  20. * @param any value
  21. * @return boolean
  22. */
  23. export function isNumber(value: any): boolean;
  24. export function isBigInt(value: any): boolean;
  25. export function isString(value: any): boolean;
  26. export function isArray(value: any): boolean;
  27. export function isBoolean(value: any): boolean;
  28. export function isUndefined(value: any): boolean;
  29. export function isNull(value: any): boolean;
  30. export function isSymbol(value: any): boolean;
  31. export function isObject(value: any): boolean;
  32. export function isFunction(value: any): boolean;
  33. export function isElement(value: any): boolean;
  34. export function isWindow(value: any): boolean;
  35. /**
  36. * Get the prototype name of an object
  37. */
  38. export function getPrototypeName(value: any): string;
  39. /**
  40. * check whether an object is plain (using {})
  41. * @param object obj
  42. * @return boolean
  43. */
  44. export function isPlainObject(obj: any): boolean;
  45. /**
  46. * HTML encode a string
  47. * @param string text
  48. * @return string
  49. */
  50. export function htmlEncode(text: string): string;
  51. /**
  52. * Change invisible characters to visible characters
  53. */
  54. export function invisibleTextEncode(text: string): string;
  55. /**
  56. * Simple JSON stringify, stringify top level key-value
  57. */
  58. export function SimpleJSONStringify(stringObject: any): string;
  59. /**
  60. * rewrite JSON.stringify, catch unknown exception
  61. */
  62. export function JSONStringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
  63. export function getStringBytes(str: string): number;
  64. export function getBytesText(bytes: number): string;
  65. export function subString(str: string, len: number): string;
  66. export function circularReplacer(): (key: any, value: any) => any;
  67. /**
  68. * get an object's all keys ignore whether they are not enumerable
  69. */
  70. export function getObjAllKeys(obj: any): any[];
  71. /**
  72. * get an object's prototype name
  73. */
  74. export function getObjName(obj: any): string;
  75. /**
  76. * localStorage methods
  77. */
  78. export function setStorage(key: string, value: string): void;
  79. export function getStorage(key: string): string;
  80. }
  81. declare module "lib/mito" {
  82. /**
  83. * Mito.js
  84. * A simple template engine
  85. *
  86. * @author Maiz
  87. */
  88. export default class Mito {
  89. /**
  90. * Render `tpl` with `data` into a HTML string.
  91. */
  92. render<T extends true>(tpl: string, data: any, toString: T): string;
  93. /**
  94. * Render `tpl` with `data` into a HTML element.
  95. */
  96. render<T extends false>(tpl: string, data: any, toString?: T): Element;
  97. }
  98. }
  99. declare module "lib/query" {
  100. const $: {
  101. /**
  102. * get single element
  103. * @public
  104. */
  105. one: (selector: string, contextElement?: Element | Document) => HTMLElement;
  106. /**
  107. * get multiple elements
  108. * @public
  109. */
  110. all: (selector: string, contextElement?: Element | Document) => HTMLElement[];
  111. /**
  112. * add className(s) to an or multiple element(s)
  113. * @public
  114. */
  115. addClass: ($el: Element | Element[], className: string) => void;
  116. /**
  117. * remove className(s) from an or multiple element(s)
  118. * @public
  119. */
  120. removeClass: ($el: Element | Element[], className: string) => void;
  121. /**
  122. * see whether an element contains a className
  123. * @public
  124. */
  125. hasClass: ($el: Element, className: string) => boolean;
  126. /**
  127. * bind an event to element(s)
  128. * @public
  129. */
  130. bind: ($el: Element | Element[], eventType: any, fn: any, useCapture?: boolean) => void;
  131. /**
  132. * delegate an event to a parent element
  133. * @public
  134. * @param $el parent element
  135. * @param eventType name of the event
  136. * @param selector target's selector
  137. * @param fn callback function
  138. */
  139. delegate: ($el: Element, eventType: string, selector: string, fn: (event: Event, $target: HTMLElement) => void) => void;
  140. /**
  141. * Remove all child elements of an element.
  142. */
  143. removeChildren($el: Element): Element;
  144. /**
  145. * simply render a HTML template
  146. */
  147. render: {
  148. <T extends true>(tpl: string, data: any, toString: T): string;
  149. <T_1 extends false>(tpl: string, data: any, toString?: T_1): Element;
  150. };
  151. };
  152. /**
  153. * export
  154. */
  155. export default $;
  156. }
  157. declare module "lib/plugin" {
  158. type VConsolePluginEvent = (data?: any) => void;
  159. /**
  160. * vConsole Plugin Class
  161. */
  162. class VConsolePlugin {
  163. isReady: boolean;
  164. eventList: {
  165. [eventName: string]: VConsolePluginEvent;
  166. };
  167. protected _id: string;
  168. protected _name: string;
  169. protected _vConsole: any;
  170. constructor(...args: any[]);
  171. get id(): string;
  172. set id(value: string);
  173. get name(): string;
  174. set name(value: string);
  175. get vConsole(): any;
  176. set vConsole(value: any);
  177. /**
  178. * register an event
  179. * @public
  180. * @param string
  181. * @param function
  182. */
  183. on(eventName: string, callback: VConsolePluginEvent): this;
  184. /**
  185. * trigger an event
  186. */
  187. trigger(eventName: string, data?: any): this;
  188. protected getUniqueID(prefix?: string): string;
  189. }
  190. export default VConsolePlugin;
  191. }
  192. declare module "component/item_copy" {
  193. export default class VConsoleItemCopy {
  194. static html: string;
  195. /**
  196. * Delegate copy button `onClick` event on a perent element.
  197. */
  198. static delegate($el: Element, getCopyText: (id: string) => string): void;
  199. /**
  200. * Copy a text to clipboard
  201. */
  202. static copy(text: string): boolean;
  203. }
  204. }
  205. declare module "log/log" {
  206. import VConsolePlugin from "lib/plugin";
  207. type VConsoleLogArgs = any[];
  208. type VConsoleLogType = 'log' | 'info' | 'warn' | 'debug' | 'error';
  209. interface VConsoleLogItem {
  210. _id?: string;
  211. tabName?: 'default' | 'system';
  212. logType: VConsoleLogType;
  213. logs?: VConsoleLogArgs;
  214. content?: Element;
  215. noOrigin?: boolean;
  216. date?: number;
  217. style?: string;
  218. logClass?: string;
  219. }
  220. interface VConsoleLogView {
  221. _id: string;
  222. logType: VConsoleLogType;
  223. logText: string;
  224. hasContent: boolean;
  225. hasFold: boolean;
  226. count: number;
  227. }
  228. class VConsoleLogTab extends VConsolePlugin {
  229. tplTabbox: string;
  230. allowUnformattedLog: boolean;
  231. isReady: boolean;
  232. isShow: boolean;
  233. $tabbox: Element;
  234. console: {
  235. [method: string]: any;
  236. };
  237. logList: VConsoleLogItem[];
  238. cachedLogs: {
  239. [id: string]: string;
  240. };
  241. previousLog: VConsoleLogView;
  242. isInBottom: boolean;
  243. maxLogNumber: number;
  244. logNumber: number;
  245. constructor(...args: any[]);
  246. /**
  247. * when vConsole is ready,
  248. * this event will be triggered (after 'add' event)
  249. * @public
  250. */
  251. onInit(): void;
  252. /**
  253. * this event will make this plugin be registered as a tab
  254. * @public
  255. */
  256. onRenderTab(callback: Function): void;
  257. onAddTopBar(callback: Function): void;
  258. onAddTool(callback: Function): void;
  259. /**
  260. * after init
  261. * @public
  262. */
  263. onReady(): void;
  264. /**
  265. * before remove
  266. * @public
  267. */
  268. onRemove(): void;
  269. onShow(): void;
  270. onHide(): void;
  271. onShowConsole(): void;
  272. onUpdateOption(): void;
  273. updateMaxLogNumber(): void;
  274. limitMaxLogs(): void;
  275. showLogType(logType: string): void;
  276. autoScrollToBottom(): void;
  277. scrollToBottom(): void;
  278. /**
  279. * replace window.console with vConsole method
  280. */
  281. protected mockConsole(): void;
  282. clearLog(): void;
  283. beforeRenderLog($line: Element): void;
  284. /**
  285. * print log to origin console
  286. * @protected
  287. */
  288. printOriginLog(item: VConsoleLogItem): void;
  289. /**
  290. * print a log to log box
  291. */
  292. protected printLog(item: VConsoleLogItem): void;
  293. /**
  294. * Render the count of a repeated log
  295. */
  296. printRepeatLog(): void;
  297. /**
  298. * Render a new log
  299. */
  300. protected printNewLog(item: VConsoleLogItem, logs: VConsoleLogArgs): void;
  301. /**
  302. * generate the HTML element of a folded line
  303. */
  304. protected getFoldedLine(obj: any, outer?: string): Element;
  305. }
  306. export default VConsoleLogTab;
  307. }
  308. declare module "log/default" {
  309. import VConsoleLogTab from "log/log";
  310. class VConsoleDefaultTab extends VConsoleLogTab {
  311. private filterText;
  312. constructor(...args: any[]);
  313. onReady(): void;
  314. beforeRenderLog($line: Element): void;
  315. /**
  316. * replace window.console & window.onerror with vConsole method
  317. */
  318. protected mockConsole(): void;
  319. /**
  320. * Catch window.onerror
  321. */
  322. private catchWindowOnError;
  323. /**
  324. * Promise.reject has no rejection handler
  325. * about https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event
  326. */
  327. private catchUnhandledRejection;
  328. /**
  329. * Catch resource loading error: image, video, link, script
  330. */
  331. private catchResourceError;
  332. /**
  333. * Run a command
  334. */
  335. private evalCommand;
  336. private checkFilterInLine;
  337. }
  338. export default VConsoleDefaultTab;
  339. }
  340. declare module "log/system" {
  341. /**
  342. * vConsole System Tab
  343. */
  344. import VConsoleLogTab from "log/log";
  345. class VConsoleSystemTab extends VConsoleLogTab {
  346. constructor(...args: any[]);
  347. onInit(): void;
  348. printSystemInfo(): void;
  349. }
  350. export default VConsoleSystemTab;
  351. }
  352. declare module "network/network" {
  353. import VConsolePlugin from "lib/plugin";
  354. class VConsoleNetworkTab extends VConsolePlugin {
  355. private $tabbox;
  356. private $header;
  357. private reqList;
  358. private domList;
  359. private isShow;
  360. private isInBottom;
  361. private _xhrOpen;
  362. private _xhrSend;
  363. private _xhrSetRequestHeader;
  364. private _fetch;
  365. private _sendBeacon;
  366. constructor(...args: any[]);
  367. onRenderTab(callback: any): void;
  368. onAddTool(callback: any): void;
  369. onReady(): void;
  370. onRemove(): void;
  371. onShow(): void;
  372. onHide(): void;
  373. onShowConsole(): void;
  374. autoScrollToBottom(): void;
  375. scrollToBottom(): void;
  376. clearLog(): void;
  377. private renderHeader;
  378. /**
  379. * add or update a request item by request ID
  380. * @private
  381. */
  382. private updateRequest;
  383. /**
  384. * mock XMLHttpRequest
  385. * @private
  386. */
  387. private mockXHR;
  388. /**
  389. * mock fetch request
  390. * @private
  391. */
  392. private mockFetch;
  393. /**
  394. * mock navigator.sendBeacon
  395. * @private
  396. */
  397. private mockSendBeacon;
  398. private getFormattedBody;
  399. private getURL;
  400. }
  401. export default VConsoleNetworkTab;
  402. }
  403. declare module "element/node_view" {
  404. class NodeView {
  405. node: any;
  406. view: HTMLElement;
  407. constructor(node: any);
  408. get(): HTMLElement;
  409. _create(node: any, isRoot?: boolean): HTMLElement;
  410. _createTextNode(node: any, view: any): void;
  411. _createElementNode(node: any, view: any): void;
  412. }
  413. export default NodeView;
  414. }
  415. declare module "element/element" {
  416. import VConsolePlugin from "lib/plugin";
  417. class VConsoleElementsTab extends VConsolePlugin {
  418. isInited: boolean;
  419. node: {};
  420. $tabbox: Element;
  421. nodes: any[];
  422. activedElem: Element;
  423. observer: any;
  424. constructor(...args: any[]);
  425. onRenderTab(callback: any): void;
  426. onAddTool(callback: any): void;
  427. onShow(): void;
  428. onRemove(): void;
  429. onMutation(mutation: any): void;
  430. onChildRemove(mutation: any): void;
  431. onChildAdd(mutation: any): void;
  432. onAttributesChange(mutation: any): void;
  433. onCharacterDataChange(mutation: any): void;
  434. renderView(node: any, $related: any, renderMethod?: 'replace' | 'insertBefore'): HTMLElement;
  435. getNode(elem: any): any;
  436. _isIgnoredElement(elem: any): boolean;
  437. _isInVConsole(elem: any): boolean;
  438. }
  439. export default VConsoleElementsTab;
  440. }
  441. declare module "lib/sveltePlugin" {
  442. import VConsolePlugin from "lib/plugin";
  443. import { SvelteComponent } from 'svelte';
  444. export class VConsoleSveltePlugin<T extends {} = {}> extends VConsolePlugin {
  445. Comp: typeof SvelteComponent;
  446. comp?: SvelteComponent;
  447. initialProps: T;
  448. $dom: HTMLElement;
  449. constructor(id: string, name: string, Comp: typeof SvelteComponent, renderProps: T);
  450. onRenderTab(callback: any): void;
  451. onRemove(): void;
  452. }
  453. export default VConsoleSveltePlugin;
  454. }
  455. declare module "components/Storage/index" {
  456. export { default as StorageTab } from './Template.svelte';
  457. }
  458. declare module "storage/storage" {
  459. import VConsoleSveltePlugin from "lib/sveltePlugin";
  460. export default class VConsoleStorageTab extends VConsoleSveltePlugin {
  461. constructor(id: string, name: string, renderProps?: {
  462. propA: number;
  463. });
  464. }
  465. }
  466. declare module "core/core" {
  467. /**
  468. * vConsole core class
  469. */
  470. import * as tool from "lib/tool";
  471. import VConsolePlugin from "lib/plugin";
  472. import VConsoleLogPlugin from "log/log";
  473. import VConsoleDefaultPlugin from "log/default";
  474. import VConsoleSystemPlugin from "log/system";
  475. import VConsoleNetworkPlugin from "network/network";
  476. import VConsoleElementPlugin from "element/element";
  477. import VConsoleStoragePlugin from "storage/storage";
  478. interface VConsoleOptions {
  479. defaultPlugins?: ('system' | 'network' | 'element' | 'storage')[];
  480. maxLogNumber?: number;
  481. theme?: '' | 'dark' | 'light';
  482. disableLogScrolling?: boolean;
  483. onReady?: () => void;
  484. onClearLog?: () => void;
  485. }
  486. class VConsole {
  487. version: string;
  488. $dom: HTMLElement;
  489. isInited: boolean;
  490. option: VConsoleOptions;
  491. protected activedTab: string;
  492. protected tabList: any[];
  493. protected pluginList: {};
  494. protected switchPos: {
  495. hasMoved: boolean;
  496. x: number;
  497. y: number;
  498. startX: number;
  499. startY: number;
  500. endX: number;
  501. endY: number;
  502. };
  503. tool: typeof tool;
  504. $: {
  505. one: (selector: string, contextElement?: Element | Document) => HTMLElement;
  506. all: (selector: string, contextElement?: Element | Document) => HTMLElement[];
  507. addClass: ($el: Element | Element[], className: string) => void;
  508. removeClass: ($el: Element | Element[], className: string) => void;
  509. hasClass: ($el: Element, className: string) => boolean;
  510. bind: ($el: Element | Element[], eventType: any, fn: any, useCapture?: boolean) => void;
  511. delegate: ($el: Element, eventType: string, selector: string, fn: (event: Event, $target: HTMLElement) => void) => void;
  512. removeChildren($el: Element): Element;
  513. render: {
  514. <T extends true>(tpl: string, data: any, toString: T): string;
  515. <T_1 extends false>(tpl: string, data: any, toString?: T_1): Element;
  516. };
  517. };
  518. static VConsolePlugin: typeof VConsolePlugin;
  519. static VConsoleLogPlugin: typeof VConsoleLogPlugin;
  520. static VConsoleDefaultPlugin: typeof VConsoleDefaultPlugin;
  521. static VConsoleSystemPlugin: typeof VConsoleSystemPlugin;
  522. static VConsoleNetworkPlugin: typeof VConsoleNetworkPlugin;
  523. static VConsoleElementPlugin: typeof VConsoleElementPlugin;
  524. static VConsoleStoragePlugin: typeof VConsoleStoragePlugin;
  525. constructor(opt?: VConsoleOptions);
  526. /**
  527. * add built-in plugins
  528. * @private
  529. */
  530. private _addBuiltInPlugins;
  531. /**
  532. * render panel DOM
  533. * @private
  534. */
  535. private _render;
  536. /**
  537. * Update theme
  538. * @private
  539. */
  540. private _updateTheme;
  541. setSwitchPosition(switchX: number, switchY: number): void;
  542. /**
  543. * Get an safe [x, y] position for switch button
  544. * @private
  545. */
  546. private _getSwitchButtonSafeAreaXY;
  547. /**
  548. * simulate tap event by touchstart & touchend
  549. * @private
  550. */
  551. private _mockTap;
  552. /**
  553. * bind DOM events
  554. * @private
  555. */
  556. private _bindEvent;
  557. /**
  558. * auto run after initialization
  559. * @private
  560. */
  561. private _autoRun;
  562. /**
  563. * trigger a vConsole.option event
  564. */
  565. triggerEvent(eventName: string, param?: any): void;
  566. /**
  567. * init a plugin
  568. * @private
  569. */
  570. private _initPlugin;
  571. /**
  572. * trigger an event for each plugin
  573. * @private
  574. */
  575. private _triggerPluginsEvent;
  576. /**
  577. * trigger an event by plugin's name
  578. * @private
  579. */
  580. private _triggerPluginEvent;
  581. /**
  582. * add a new plugin
  583. * @public
  584. * @param object VConsolePlugin object
  585. * @return boolean
  586. */
  587. addPlugin(plugin: VConsolePlugin): boolean;
  588. /**
  589. * remove a plugin
  590. * @public
  591. * @param string pluginID
  592. * @return boolean
  593. */
  594. removePlugin(pluginID: string): boolean;
  595. /**
  596. * show console panel
  597. * @public
  598. */
  599. show(): void;
  600. /**
  601. * hide console panel
  602. * @public
  603. */
  604. hide(): void;
  605. /**
  606. * show switch button
  607. * @public
  608. */
  609. showSwitch(): void;
  610. /**
  611. * hide switch button
  612. */
  613. hideSwitch(): void;
  614. /**
  615. * show a tab
  616. * @public
  617. */
  618. showTab(tabID: string): void;
  619. /**
  620. * update option(s)
  621. * @public
  622. */
  623. setOption(keyOrObj: any, value?: any): void;
  624. /**
  625. * uninstall vConsole
  626. * @public
  627. */
  628. destroy(): void;
  629. }
  630. export default VConsole;
  631. }
  632. declare module "vconsole" {
  633. /**
  634. * A Front-End Console Panel for Mobile Webpage
  635. */
  636. import 'core-js/stable/symbol';
  637. import VConsole from "core/core";
  638. export { VConsole };
  639. export default VConsole;
  640. }
  641. declare module "components/Button/index" {
  642. export { default as Btn } from './Template.svelte';
  643. }
  644. declare module "lib/cookiesStorage" {
  645. import { CookieStorage as CookiesStorage } from 'cookie-storage';
  646. export const cookiesStorage: CookiesStorage;
  647. }
  648. declare module "components/Storage/utils" {
  649. interface IStorageItem {
  650. name: string;
  651. storage: Storage;
  652. }
  653. export const getAllStorages: () => IStorageItem[];
  654. }
  655. declare module "components/Tab/index" {
  656. export { default as Tabs } from './Tabs.svelte';
  657. export { default as TabList } from './TabList.svelte';
  658. export { default as TabPanel } from './TabPanel.svelte';
  659. export { default as Tab } from './Tab.svelte';
  660. export const TabsContext: {};
  661. }