happy-dom 10.11.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (169) hide show
  1. package/.eslintrc.cjs +1 -1
  2. package/cjs/console/VirtualConsole.cjs +351 -0
  3. package/cjs/console/VirtualConsole.cjs.map +1 -0
  4. package/cjs/console/VirtualConsole.d.ts +163 -0
  5. package/cjs/console/VirtualConsole.d.ts.map +1 -0
  6. package/cjs/console/VirtualConsolePrinter.cjs +101 -0
  7. package/cjs/console/VirtualConsolePrinter.cjs.map +1 -0
  8. package/cjs/console/VirtualConsolePrinter.d.ts +55 -0
  9. package/cjs/console/VirtualConsolePrinter.d.ts.map +1 -0
  10. package/cjs/console/enums/VirtualConsoleLogLevelEnum.cjs +16 -0
  11. package/cjs/console/enums/VirtualConsoleLogLevelEnum.cjs.map +1 -0
  12. package/cjs/console/enums/VirtualConsoleLogLevelEnum.d.ts +13 -0
  13. package/cjs/console/enums/VirtualConsoleLogLevelEnum.d.ts.map +1 -0
  14. package/cjs/console/enums/VirtualConsoleLogTypeEnum.cjs +30 -0
  15. package/cjs/console/enums/VirtualConsoleLogTypeEnum.cjs.map +1 -0
  16. package/cjs/console/enums/VirtualConsoleLogTypeEnum.d.ts +23 -0
  17. package/cjs/console/enums/VirtualConsoleLogTypeEnum.d.ts.map +1 -0
  18. package/cjs/console/types/IVirtualConsoleLogEntry.cjs +3 -0
  19. package/cjs/console/types/IVirtualConsoleLogEntry.cjs.map +1 -0
  20. package/cjs/console/types/IVirtualConsoleLogEntry.d.ts +10 -0
  21. package/cjs/console/types/IVirtualConsoleLogEntry.d.ts.map +1 -0
  22. package/cjs/console/types/IVirtualConsoleLogGroup.cjs +3 -0
  23. package/cjs/console/types/IVirtualConsoleLogGroup.cjs.map +1 -0
  24. package/cjs/console/types/IVirtualConsoleLogGroup.d.ts +7 -0
  25. package/cjs/console/types/IVirtualConsoleLogGroup.d.ts.map +1 -0
  26. package/cjs/console/types/IVirtualConsolePrinter.cjs +3 -0
  27. package/cjs/console/types/IVirtualConsolePrinter.cjs.map +1 -0
  28. package/cjs/console/types/IVirtualConsolePrinter.d.ts +52 -0
  29. package/cjs/console/types/IVirtualConsolePrinter.d.ts.map +1 -0
  30. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.cjs +97 -0
  31. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.cjs.map +1 -0
  32. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.d.ts +35 -0
  33. package/cjs/console/utilities/VirtualConsoleLogEntryStringifier.d.ts.map +1 -0
  34. package/cjs/css/CSSParser.cjs +34 -13
  35. package/cjs/css/CSSParser.cjs.map +1 -1
  36. package/cjs/css/CSSParser.d.ts +8 -0
  37. package/cjs/css/CSSParser.d.ts.map +1 -1
  38. package/cjs/event/EventTarget.cjs +23 -5
  39. package/cjs/event/EventTarget.cjs.map +1 -1
  40. package/cjs/event/EventTarget.d.ts.map +1 -1
  41. package/cjs/nodes/element/Element.cjs.map +1 -1
  42. package/cjs/nodes/element/Element.d.ts +1 -1
  43. package/cjs/nodes/element/Element.d.ts.map +1 -1
  44. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs +8 -31
  45. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs.map +1 -1
  46. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts +0 -7
  47. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  48. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +2 -1
  49. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
  50. package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  51. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs +10 -55
  52. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs.map +1 -1
  53. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts +0 -14
  54. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  55. package/cjs/window/GlobalWindow.cjs +1 -9
  56. package/cjs/window/GlobalWindow.cjs.map +1 -1
  57. package/cjs/window/GlobalWindow.d.ts +1 -7
  58. package/cjs/window/GlobalWindow.d.ts.map +1 -1
  59. package/cjs/window/IHappyDOMOptions.d.ts +2 -0
  60. package/cjs/window/IHappyDOMOptions.d.ts.map +1 -1
  61. package/cjs/window/IWindow.d.ts +2 -7
  62. package/cjs/window/IWindow.d.ts.map +1 -1
  63. package/cjs/window/VMGlobalPropertyScript.cjs +1 -0
  64. package/cjs/window/VMGlobalPropertyScript.cjs.map +1 -1
  65. package/cjs/window/VMGlobalPropertyScript.d.ts +1 -1
  66. package/cjs/window/VMGlobalPropertyScript.d.ts.map +1 -1
  67. package/cjs/window/Window.cjs +51 -64
  68. package/cjs/window/Window.cjs.map +1 -1
  69. package/cjs/window/Window.d.ts +6 -23
  70. package/cjs/window/Window.d.ts.map +1 -1
  71. package/cjs/window/WindowErrorUtility.cjs +84 -0
  72. package/cjs/window/WindowErrorUtility.cjs.map +1 -0
  73. package/cjs/window/WindowErrorUtility.d.ts +38 -0
  74. package/cjs/window/WindowErrorUtility.d.ts.map +1 -0
  75. package/lib/console/VirtualConsole.d.ts +163 -0
  76. package/lib/console/VirtualConsole.d.ts.map +1 -0
  77. package/lib/console/VirtualConsole.js +322 -0
  78. package/lib/console/VirtualConsole.js.map +1 -0
  79. package/lib/console/VirtualConsolePrinter.d.ts +55 -0
  80. package/lib/console/VirtualConsolePrinter.d.ts.map +1 -0
  81. package/lib/console/VirtualConsolePrinter.js +95 -0
  82. package/lib/console/VirtualConsolePrinter.js.map +1 -0
  83. package/lib/console/enums/VirtualConsoleLogLevelEnum.d.ts +13 -0
  84. package/lib/console/enums/VirtualConsoleLogLevelEnum.d.ts.map +1 -0
  85. package/lib/console/enums/VirtualConsoleLogLevelEnum.js +14 -0
  86. package/lib/console/enums/VirtualConsoleLogLevelEnum.js.map +1 -0
  87. package/lib/console/enums/VirtualConsoleLogTypeEnum.d.ts +23 -0
  88. package/lib/console/enums/VirtualConsoleLogTypeEnum.d.ts.map +1 -0
  89. package/lib/console/enums/VirtualConsoleLogTypeEnum.js +28 -0
  90. package/lib/console/enums/VirtualConsoleLogTypeEnum.js.map +1 -0
  91. package/lib/console/types/IVirtualConsoleLogEntry.d.ts +10 -0
  92. package/lib/console/types/IVirtualConsoleLogEntry.d.ts.map +1 -0
  93. package/lib/console/types/IVirtualConsoleLogEntry.js +2 -0
  94. package/lib/console/types/IVirtualConsoleLogEntry.js.map +1 -0
  95. package/lib/console/types/IVirtualConsoleLogGroup.d.ts +7 -0
  96. package/lib/console/types/IVirtualConsoleLogGroup.d.ts.map +1 -0
  97. package/lib/console/types/IVirtualConsoleLogGroup.js +2 -0
  98. package/lib/console/types/IVirtualConsoleLogGroup.js.map +1 -0
  99. package/lib/console/types/IVirtualConsolePrinter.d.ts +52 -0
  100. package/lib/console/types/IVirtualConsolePrinter.d.ts.map +1 -0
  101. package/lib/console/types/IVirtualConsolePrinter.js +2 -0
  102. package/lib/console/types/IVirtualConsolePrinter.js.map +1 -0
  103. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.d.ts +35 -0
  104. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.d.ts.map +1 -0
  105. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.js +91 -0
  106. package/lib/console/utilities/VirtualConsoleLogEntryStringifier.js.map +1 -0
  107. package/lib/css/CSSParser.d.ts +8 -0
  108. package/lib/css/CSSParser.d.ts.map +1 -1
  109. package/lib/css/CSSParser.js +34 -13
  110. package/lib/css/CSSParser.js.map +1 -1
  111. package/lib/event/EventTarget.d.ts.map +1 -1
  112. package/lib/event/EventTarget.js +23 -5
  113. package/lib/event/EventTarget.js.map +1 -1
  114. package/lib/nodes/element/Element.d.ts +1 -1
  115. package/lib/nodes/element/Element.d.ts.map +1 -1
  116. package/lib/nodes/element/Element.js.map +1 -1
  117. package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts +0 -7
  118. package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  119. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +8 -31
  120. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -1
  121. package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  122. package/lib/nodes/html-script-element/HTMLScriptElement.js +2 -1
  123. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  124. package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts +0 -14
  125. package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  126. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js +10 -55
  127. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -1
  128. package/lib/window/GlobalWindow.d.ts +1 -7
  129. package/lib/window/GlobalWindow.d.ts.map +1 -1
  130. package/lib/window/GlobalWindow.js +1 -9
  131. package/lib/window/GlobalWindow.js.map +1 -1
  132. package/lib/window/IHappyDOMOptions.d.ts +2 -0
  133. package/lib/window/IHappyDOMOptions.d.ts.map +1 -1
  134. package/lib/window/IWindow.d.ts +2 -7
  135. package/lib/window/IWindow.d.ts.map +1 -1
  136. package/lib/window/VMGlobalPropertyScript.d.ts +1 -1
  137. package/lib/window/VMGlobalPropertyScript.d.ts.map +1 -1
  138. package/lib/window/VMGlobalPropertyScript.js +1 -0
  139. package/lib/window/VMGlobalPropertyScript.js.map +1 -1
  140. package/lib/window/Window.d.ts +6 -23
  141. package/lib/window/Window.d.ts.map +1 -1
  142. package/lib/window/Window.js +51 -64
  143. package/lib/window/Window.js.map +1 -1
  144. package/lib/window/WindowErrorUtility.d.ts +38 -0
  145. package/lib/window/WindowErrorUtility.d.ts.map +1 -0
  146. package/lib/window/WindowErrorUtility.js +78 -0
  147. package/lib/window/WindowErrorUtility.js.map +1 -0
  148. package/package.json +2 -2
  149. package/src/console/VirtualConsole.ts +356 -0
  150. package/src/console/VirtualConsolePrinter.ts +107 -0
  151. package/src/console/enums/VirtualConsoleLogLevelEnum.ts +12 -0
  152. package/src/console/enums/VirtualConsoleLogTypeEnum.ts +29 -0
  153. package/src/console/types/IVirtualConsoleLogEntry.ts +10 -0
  154. package/src/console/types/IVirtualConsoleLogGroup.ts +6 -0
  155. package/src/console/types/IVirtualConsolePrinter.ts +58 -0
  156. package/src/console/utilities/VirtualConsoleLogEntryStringifier.ts +100 -0
  157. package/src/css/CSSParser.ts +35 -14
  158. package/src/event/EventTarget.ts +27 -5
  159. package/src/nodes/element/Element.ts +1 -1
  160. package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +13 -35
  161. package/src/nodes/html-script-element/HTMLScriptElement.ts +4 -1
  162. package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +19 -62
  163. package/src/window/GlobalWindow.ts +1 -10
  164. package/src/window/IHappyDOMOptions.ts +1 -0
  165. package/src/window/IWindow.ts +2 -8
  166. package/src/window/VMGlobalPropertyScript.ts +1 -0
  167. package/src/window/Window.ts +77 -70
  168. package/src/window/WindowErrorUtility.ts +94 -0
  169. package/tsconfig.json +2 -3
@@ -0,0 +1,163 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import IVirtualConsolePrinter from './types/IVirtualConsolePrinter.js';
3
+ /**
4
+ * Virtual Console.
5
+ *
6
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Console
7
+ */
8
+ export default class VirtualConsole implements Console {
9
+ Console: NodeJS.ConsoleConstructor;
10
+ private _printer;
11
+ private _count;
12
+ private _time;
13
+ private _groupID;
14
+ private _groups;
15
+ /**
16
+ * Constructor.
17
+ *
18
+ * @param printer Console printer.
19
+ */
20
+ constructor(printer: IVirtualConsolePrinter);
21
+ /**
22
+ * Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
23
+ *
24
+ * @param assertion Assertion.
25
+ * @param args Arguments.
26
+ */
27
+ assert(assertion: boolean, ...args: Array<object | string>): void;
28
+ /**
29
+ * Clears the console.
30
+ */
31
+ clear(): void;
32
+ /**
33
+ * Logs the number of times that this particular call to count() has been called.
34
+ *
35
+ * @param [label='default'] Label.
36
+ */
37
+ count(label?: string): void;
38
+ /**
39
+ * Resets the counter.
40
+ *
41
+ * @param [label='default'] Label.
42
+ */
43
+ countReset(label?: string): void;
44
+ /**
45
+ * Outputs a message to the web console at the "debug" log level.
46
+ *
47
+ * @param args Arguments.
48
+ */
49
+ debug(...args: Array<object | string>): void;
50
+ /**
51
+ * Displays an interactive list of the properties of the specified JavaScript object.
52
+ *
53
+ * @param data Data.
54
+ */
55
+ dir(data: object): void;
56
+ /**
57
+ * Displays an interactive tree of the descendant elements of the specified XML/HTML element.
58
+ *
59
+ * @param data Data.
60
+ */
61
+ dirxml(data: object): void;
62
+ /**
63
+ * Outputs an error message to the console.
64
+ *
65
+ * @param args Arguments.
66
+ */
67
+ error(...args: Array<object | string>): void;
68
+ /**
69
+ * Alias for error().
70
+ *
71
+ * @deprecated
72
+ * @alias error()
73
+ * @param args Arguments.
74
+ */
75
+ exception(...args: Array<object | string>): void;
76
+ /**
77
+ * Creates a new inline group in the console, causing any subsequent console messages to be indented by an additional level, until console.groupEnd() is called.
78
+ *
79
+ * @param [label] Label.
80
+ */
81
+ group(label?: string): void;
82
+ /**
83
+ * Creates a new inline group in the console, but prints it as collapsed, requiring the use of a disclosure button to expand it.
84
+ *
85
+ * @param [label] Label.
86
+ */
87
+ groupCollapsed(label?: string): void;
88
+ /**
89
+ * Exits the current inline group in the console.
90
+ */
91
+ groupEnd(): void;
92
+ /**
93
+ *
94
+ * @param args
95
+ */
96
+ info(...args: Array<object | string>): void;
97
+ /**
98
+ * Outputs a message to the console.
99
+ *
100
+ * @param args Arguments.
101
+ */
102
+ log(...args: Array<object | string>): void;
103
+ /**
104
+ * Starts recording a performance profile.
105
+ *
106
+ * TODO: Implement this.
107
+ */
108
+ profile(): void;
109
+ /**
110
+ * Stops recording a performance profile.
111
+ *
112
+ * TODO: Implement this.
113
+ */
114
+ profileEnd(): void;
115
+ /**
116
+ * Displays tabular data as a table.
117
+ *
118
+ * @param data Data.
119
+ */
120
+ table(data: {
121
+ [key: string]: number | string | boolean;
122
+ } | string[]): void;
123
+ /**
124
+ * Starts a timer you can use to track how long an operation takes.
125
+ *
126
+ * @param [label=default] Label.
127
+ */
128
+ time(label?: string): void;
129
+ /**
130
+ * Stops a timer that was previously started by calling console.time().
131
+ * The method logs the elapsed time in milliseconds.
132
+ *
133
+ * @param [label=default] Label.
134
+ */
135
+ timeEnd(label?: string): void;
136
+ /**
137
+ * Logs the current value of a timer that was previously started by calling console.time().
138
+ * The method logs the elapsed time in milliseconds.
139
+ *
140
+ * @param [label=default] Label.
141
+ * @param [args] Arguments.
142
+ */
143
+ timeLog(label?: string, ...args: Array<object | string>): void;
144
+ /**
145
+ * Adds a single marker to the browser's Performance tool.
146
+ *
147
+ * TODO: Implement this.
148
+ */
149
+ timeStamp(): void;
150
+ /**
151
+ * Outputs a stack trace to the console.
152
+ *
153
+ * @param args Arguments.
154
+ */
155
+ trace(...args: Array<object | string>): void;
156
+ /**
157
+ * Outputs a warning message to the console.
158
+ *
159
+ * @param args Arguments.
160
+ */
161
+ warn(...args: Array<object | string>): void;
162
+ }
163
+ //# sourceMappingURL=VirtualConsole.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsole.d.ts","sourceRoot":"","sources":["../../src/console/VirtualConsole.ts"],"names":[],"mappings":";AAAA,OAAO,sBAAsB,MAAM,mCAAmC,CAAC;AAMvE;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,OAAO;IAG9C,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC;IAE1C,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,C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IG;IACI,KAAK,CAAC,IAAI,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,MAAM,EAAE,GAAG,IAAI;IASjF;;;;OAIG;IACI,IAAI,CAAC,KAAK,SAAY,GAAG,IAAI;IAIpC;;;;;OAKG;IACI,OAAO,CAAC,KAAK,SAAY,GAAG,IAAI;IAavC;;;;;;OAMG;IACI,OAAO,CAAC,KAAK,SAAY,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;IAaxE;;;;OAIG;IACI,SAAS,IAAI,IAAI;IAIxB;;;;OAIG;IACI,KAAK,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;IASnD;;;;OAIG;IACI,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI;CAQlD"}
@@ -0,0 +1,322 @@
1
+ import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
2
+ import VirtualConsoleLogTypeEnum from './enums/VirtualConsoleLogTypeEnum.js';
3
+ import * as PerfHooks from 'perf_hooks';
4
+ /**
5
+ * Virtual Console.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Console
8
+ */
9
+ export default class VirtualConsole {
10
+ /**
11
+ * Constructor.
12
+ *
13
+ * @param printer Console printer.
14
+ */
15
+ constructor(printer) {
16
+ this._count = {};
17
+ this._time = {};
18
+ this._groupID = 0;
19
+ this._groups = [];
20
+ this._printer = printer;
21
+ }
22
+ /**
23
+ * Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.
24
+ *
25
+ * @param assertion Assertion.
26
+ * @param args Arguments.
27
+ */
28
+ assert(assertion, ...args) {
29
+ if (!assertion) {
30
+ this._printer.print({
31
+ type: VirtualConsoleLogTypeEnum.assert,
32
+ level: VirtualConsoleLogLevelEnum.error,
33
+ message: ['Assertion failed:', ...args],
34
+ group: this._groups[this._groups.length - 1] || null
35
+ });
36
+ }
37
+ }
38
+ /**
39
+ * Clears the console.
40
+ */
41
+ clear() {
42
+ this._printer.clear();
43
+ }
44
+ /**
45
+ * Logs the number of times that this particular call to count() has been called.
46
+ *
47
+ * @param [label='default'] Label.
48
+ */
49
+ count(label = 'default') {
50
+ if (!this._count[label]) {
51
+ this._count[label] = 0;
52
+ }
53
+ this._count[label]++;
54
+ this._printer.print({
55
+ type: VirtualConsoleLogTypeEnum.count,
56
+ level: VirtualConsoleLogLevelEnum.info,
57
+ message: [`${label}: ${this._count[label]}`],
58
+ group: this._groups[this._groups.length - 1] || null
59
+ });
60
+ }
61
+ /**
62
+ * Resets the counter.
63
+ *
64
+ * @param [label='default'] Label.
65
+ */
66
+ countReset(label = 'default') {
67
+ delete this._count[label];
68
+ this._printer.print({
69
+ type: VirtualConsoleLogTypeEnum.countReset,
70
+ level: VirtualConsoleLogLevelEnum.warn,
71
+ message: [`${label}: 0`],
72
+ group: this._groups[this._groups.length - 1] || null
73
+ });
74
+ }
75
+ /**
76
+ * Outputs a message to the web console at the "debug" log level.
77
+ *
78
+ * @param args Arguments.
79
+ */
80
+ debug(...args) {
81
+ this._printer.print({
82
+ type: VirtualConsoleLogTypeEnum.debug,
83
+ level: VirtualConsoleLogLevelEnum.log,
84
+ message: args,
85
+ group: this._groups[this._groups.length - 1] || null
86
+ });
87
+ }
88
+ /**
89
+ * Displays an interactive list of the properties of the specified JavaScript object.
90
+ *
91
+ * @param data Data.
92
+ */
93
+ dir(data) {
94
+ this._printer.print({
95
+ type: VirtualConsoleLogTypeEnum.dir,
96
+ level: VirtualConsoleLogLevelEnum.log,
97
+ message: [data],
98
+ group: this._groups[this._groups.length - 1] || null
99
+ });
100
+ }
101
+ /**
102
+ * Displays an interactive tree of the descendant elements of the specified XML/HTML element.
103
+ *
104
+ * @param data Data.
105
+ */
106
+ dirxml(data) {
107
+ this._printer.print({
108
+ type: VirtualConsoleLogTypeEnum.dirxml,
109
+ level: VirtualConsoleLogLevelEnum.log,
110
+ message: [data],
111
+ group: this._groups[this._groups.length - 1] || null
112
+ });
113
+ }
114
+ /**
115
+ * Outputs an error message to the console.
116
+ *
117
+ * @param args Arguments.
118
+ */
119
+ error(...args) {
120
+ this._printer.print({
121
+ type: VirtualConsoleLogTypeEnum.error,
122
+ level: VirtualConsoleLogLevelEnum.error,
123
+ message: args,
124
+ group: this._groups[this._groups.length - 1] || null
125
+ });
126
+ }
127
+ /**
128
+ * Alias for error().
129
+ *
130
+ * @deprecated
131
+ * @alias error()
132
+ * @param args Arguments.
133
+ */
134
+ exception(...args) {
135
+ this.error(...args);
136
+ }
137
+ /**
138
+ * Creates a new inline group in the console, causing any subsequent console messages to be indented by an additional level, until console.groupEnd() is called.
139
+ *
140
+ * @param [label] Label.
141
+ */
142
+ group(label) {
143
+ this._groupID++;
144
+ const group = {
145
+ id: this._groupID,
146
+ label: label || 'default',
147
+ collapsed: false,
148
+ parent: this._groups[this._groups.length - 1] || null
149
+ };
150
+ this._groups.push(group);
151
+ this._printer.print({
152
+ type: VirtualConsoleLogTypeEnum.group,
153
+ level: VirtualConsoleLogLevelEnum.log,
154
+ message: [label || 'default'],
155
+ group
156
+ });
157
+ }
158
+ /**
159
+ * Creates a new inline group in the console, but prints it as collapsed, requiring the use of a disclosure button to expand it.
160
+ *
161
+ * @param [label] Label.
162
+ */
163
+ groupCollapsed(label) {
164
+ this._groupID++;
165
+ const group = {
166
+ id: this._groupID,
167
+ label: label || 'default',
168
+ collapsed: true,
169
+ parent: this._groups[this._groups.length - 1] || null
170
+ };
171
+ this._groups.push(group);
172
+ this._printer.print({
173
+ type: VirtualConsoleLogTypeEnum.groupCollapsed,
174
+ level: VirtualConsoleLogLevelEnum.log,
175
+ message: [label || 'default'],
176
+ group
177
+ });
178
+ }
179
+ /**
180
+ * Exits the current inline group in the console.
181
+ */
182
+ groupEnd() {
183
+ if (this._groups.length === 0) {
184
+ return;
185
+ }
186
+ this._groups.pop();
187
+ }
188
+ /**
189
+ *
190
+ * @param args
191
+ */
192
+ info(...args) {
193
+ this._printer.print({
194
+ type: VirtualConsoleLogTypeEnum.info,
195
+ level: VirtualConsoleLogLevelEnum.info,
196
+ message: args,
197
+ group: this._groups[this._groups.length - 1] || null
198
+ });
199
+ }
200
+ /**
201
+ * Outputs a message to the console.
202
+ *
203
+ * @param args Arguments.
204
+ */
205
+ log(...args) {
206
+ this._printer.print({
207
+ type: VirtualConsoleLogTypeEnum.log,
208
+ level: VirtualConsoleLogLevelEnum.log,
209
+ message: args,
210
+ group: this._groups[this._groups.length - 1] || null
211
+ });
212
+ }
213
+ /**
214
+ * Starts recording a performance profile.
215
+ *
216
+ * TODO: Implement this.
217
+ */
218
+ profile() {
219
+ throw new Error('Method not implemented.');
220
+ }
221
+ /**
222
+ * Stops recording a performance profile.
223
+ *
224
+ * TODO: Implement this.
225
+ */
226
+ profileEnd() {
227
+ throw new Error('Method not implemented.');
228
+ }
229
+ /**
230
+ * Displays tabular data as a table.
231
+ *
232
+ * @param data Data.
233
+ */
234
+ table(data) {
235
+ this._printer.print({
236
+ type: VirtualConsoleLogTypeEnum.table,
237
+ level: VirtualConsoleLogLevelEnum.log,
238
+ message: [data],
239
+ group: this._groups[this._groups.length - 1] || null
240
+ });
241
+ }
242
+ /**
243
+ * Starts a timer you can use to track how long an operation takes.
244
+ *
245
+ * @param [label=default] Label.
246
+ */
247
+ time(label = 'default') {
248
+ this._time[label] = PerfHooks.performance.now();
249
+ }
250
+ /**
251
+ * Stops a timer that was previously started by calling console.time().
252
+ * The method logs the elapsed time in milliseconds.
253
+ *
254
+ * @param [label=default] Label.
255
+ */
256
+ timeEnd(label = 'default') {
257
+ const time = this._time[label];
258
+ if (time) {
259
+ const duration = PerfHooks.performance.now() - time;
260
+ this._printer.print({
261
+ type: VirtualConsoleLogTypeEnum.timeEnd,
262
+ level: VirtualConsoleLogLevelEnum.info,
263
+ message: [`${label}: ${duration}ms - timer ended`],
264
+ group: this._groups[this._groups.length - 1] || null
265
+ });
266
+ }
267
+ }
268
+ /**
269
+ * Logs the current value of a timer that was previously started by calling console.time().
270
+ * The method logs the elapsed time in milliseconds.
271
+ *
272
+ * @param [label=default] Label.
273
+ * @param [args] Arguments.
274
+ */
275
+ timeLog(label = 'default', ...args) {
276
+ const time = this._time[label];
277
+ if (time) {
278
+ const duration = PerfHooks.performance.now() - time;
279
+ this._printer.print({
280
+ type: VirtualConsoleLogTypeEnum.timeLog,
281
+ level: VirtualConsoleLogLevelEnum.info,
282
+ message: [`${label}: ${duration}ms`, ...args],
283
+ group: this._groups[this._groups.length - 1] || null
284
+ });
285
+ }
286
+ }
287
+ /**
288
+ * Adds a single marker to the browser's Performance tool.
289
+ *
290
+ * TODO: Implement this.
291
+ */
292
+ timeStamp() {
293
+ throw new Error('Method not implemented.');
294
+ }
295
+ /**
296
+ * Outputs a stack trace to the console.
297
+ *
298
+ * @param args Arguments.
299
+ */
300
+ trace(...args) {
301
+ this._printer.print({
302
+ type: VirtualConsoleLogTypeEnum.trace,
303
+ level: VirtualConsoleLogLevelEnum.log,
304
+ message: [...args, new Error('stack').stack.replace('Error: stack', '')],
305
+ group: this._groups[this._groups.length - 1] || null
306
+ });
307
+ }
308
+ /**
309
+ * Outputs a warning message to the console.
310
+ *
311
+ * @param args Arguments.
312
+ */
313
+ warn(...args) {
314
+ this._printer.print({
315
+ type: VirtualConsoleLogTypeEnum.warn,
316
+ level: VirtualConsoleLogLevelEnum.warn,
317
+ message: args,
318
+ group: this._groups[this._groups.length - 1] || null
319
+ });
320
+ }
321
+ }
322
+ //# sourceMappingURL=VirtualConsole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsole.js","sourceRoot":"","sources":["../../src/console/VirtualConsole.ts"],"names":[],"mappings":"AACA,OAAO,0BAA0B,MAAM,uCAAuC,CAAC;AAC/E,OAAO,yBAAyB,MAAM,sCAAsC,CAAC;AAE7E,OAAO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C,IAAI,IAAI;SACpD,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,GAAG,IAA4B;QAC1C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YACnB,IAAI,EAAE,yBAAyB,CAAC,IAAI;YACpC,KAAK,EAAE,0BAA0B,CAAC,IAAI;YACtC,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI;SACpD,CAAC,CAAC;IACJ,CAAC;CACD"}
@@ -0,0 +1,55 @@
1
+ import IVirtualConsoleLogEntry from './types/IVirtualConsoleLogEntry.js';
2
+ import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
3
+ import Event from '../event/Event.js';
4
+ import IVirtualConsolePrinter from './types/IVirtualConsolePrinter.js';
5
+ /**
6
+ * Virtual console printer.
7
+ */
8
+ export default class VirtualConsolePrinter implements IVirtualConsolePrinter {
9
+ private _logEntries;
10
+ private _listeners;
11
+ /**
12
+ * Writes to the output.
13
+ *
14
+ * @param logEntry Log entry.
15
+ */
16
+ print(logEntry: IVirtualConsoleLogEntry): void;
17
+ /**
18
+ * Clears the output.
19
+ */
20
+ clear(): void;
21
+ /**
22
+ * Adds an event listener.
23
+ *
24
+ * @param eventType Event type ("print" or "clear").
25
+ * @param listener Listener.
26
+ */
27
+ addEventListener(eventType: 'print' | 'clear', listener: (event: Event) => void): void;
28
+ /**
29
+ * Removes an event listener.
30
+ *
31
+ * @param eventType Event type ("print" or "clear").
32
+ * @param listener Listener.
33
+ */
34
+ removeEventListener(eventType: 'print' | 'clear', listener: (event: Event) => void): void;
35
+ /**
36
+ * Dispatches an event.
37
+ *
38
+ * @param event Event.
39
+ */
40
+ dispatchEvent(event: Event): void;
41
+ /**
42
+ * Reads the buffer.
43
+ *
44
+ * @returns Console log entries.
45
+ */
46
+ read(): IVirtualConsoleLogEntry[];
47
+ /**
48
+ * Returns the buffer as a string.
49
+ *
50
+ * @param [logLevel] Log level.
51
+ * @returns Buffer as a string of concatenated log entries.
52
+ */
53
+ readAsString(logLevel?: VirtualConsoleLogLevelEnum): string;
54
+ }
55
+ //# sourceMappingURL=VirtualConsolePrinter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsolePrinter.d.ts","sourceRoot":"","sources":["../../src/console/VirtualConsolePrinter.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AACzE,OAAO,0BAA0B,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,MAAM,mBAAmB,CAAC;AAEtC,OAAO,sBAAsB,MAAM,mCAAmC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,sBAAsB;IAC3E,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,UAAU,CAGW;IAE7B;;;;OAIG;IACI,KAAK,CAAC,QAAQ,EAAE,uBAAuB,GAAG,IAAI;IAKrD;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;;OAKG;IACI,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAO7F;;;;;OAKG;IACI,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAUhG;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IASxC;;;;OAIG;IACI,IAAI,IAAI,uBAAuB,EAAE;IAMxC;;;;;OAKG;IACI,YAAY,CAClB,QAAQ,GAAE,0BAA2D,GACnE,MAAM;CAUT"}
@@ -0,0 +1,95 @@
1
+ import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
2
+ import Event from '../event/Event.js';
3
+ import VirtualConsoleLogEntryStringifier from './utilities/VirtualConsoleLogEntryStringifier.js';
4
+ /**
5
+ * Virtual console printer.
6
+ */
7
+ export default class VirtualConsolePrinter {
8
+ constructor() {
9
+ this._logEntries = [];
10
+ this._listeners = { print: [], clear: [] };
11
+ }
12
+ /**
13
+ * Writes to the output.
14
+ *
15
+ * @param logEntry Log entry.
16
+ */
17
+ print(logEntry) {
18
+ this._logEntries.push(logEntry);
19
+ this.dispatchEvent(new Event('print'));
20
+ }
21
+ /**
22
+ * Clears the output.
23
+ */
24
+ clear() {
25
+ this._logEntries = [];
26
+ this.dispatchEvent(new Event('clear'));
27
+ }
28
+ /**
29
+ * Adds an event listener.
30
+ *
31
+ * @param eventType Event type ("print" or "clear").
32
+ * @param listener Listener.
33
+ */
34
+ addEventListener(eventType, listener) {
35
+ if (!this._listeners[eventType]) {
36
+ throw new Error(`Event type "${eventType}" is not supported.`);
37
+ }
38
+ this._listeners[eventType].push(listener);
39
+ }
40
+ /**
41
+ * Removes an event listener.
42
+ *
43
+ * @param eventType Event type ("print" or "clear").
44
+ * @param listener Listener.
45
+ */
46
+ removeEventListener(eventType, listener) {
47
+ if (!this._listeners[eventType]) {
48
+ throw new Error(`Event type "${eventType}" is not supported.`);
49
+ }
50
+ const index = this._listeners[eventType].indexOf(listener);
51
+ if (index !== -1) {
52
+ this._listeners[eventType].splice(index, 1);
53
+ }
54
+ }
55
+ /**
56
+ * Dispatches an event.
57
+ *
58
+ * @param event Event.
59
+ */
60
+ dispatchEvent(event) {
61
+ if (!this._listeners[event.type]) {
62
+ throw new Error(`Event type "${event.type}" is not supported.`);
63
+ }
64
+ for (const listener of this._listeners[event.type]) {
65
+ listener(event);
66
+ }
67
+ }
68
+ /**
69
+ * Reads the buffer.
70
+ *
71
+ * @returns Console log entries.
72
+ */
73
+ read() {
74
+ const logEntries = this._logEntries;
75
+ this._logEntries = [];
76
+ return logEntries;
77
+ }
78
+ /**
79
+ * Returns the buffer as a string.
80
+ *
81
+ * @param [logLevel] Log level.
82
+ * @returns Buffer as a string of concatenated log entries.
83
+ */
84
+ readAsString(logLevel = VirtualConsoleLogLevelEnum.log) {
85
+ const logEntries = this.read();
86
+ let output = '';
87
+ for (const logEntry of logEntries) {
88
+ if (logEntry.level >= logLevel) {
89
+ output += VirtualConsoleLogEntryStringifier.toString(logEntry);
90
+ }
91
+ }
92
+ return output;
93
+ }
94
+ }
95
+ //# sourceMappingURL=VirtualConsolePrinter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsolePrinter.js","sourceRoot":"","sources":["../../src/console/VirtualConsolePrinter.ts"],"names":[],"mappings":"AACA,OAAO,0BAA0B,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,iCAAiC,MAAM,kDAAkD,CAAC;AAGjG;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAqB;IAA1C;QACS,gBAAW,GAA8B,EAAE,CAAC;QAC5C,eAAU,GAGd,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IA4F9B,CAAC;IA1FA;;;;OAIG;IACI,KAAK,CAAC,QAAiC;QAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,KAAK;QACX,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,SAA4B,EAAE,QAAgC;QACrF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,eAAe,SAAS,qBAAqB,CAAC,CAAC;SAC/D;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AI,QAAQ,EAAE;gBAC/B,MAAM,IAAI,iCAAiC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aAC/D;SACD;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Virtual console log level.
3
+ *
4
+ * @see https://console.spec.whatwg.org/#loglevel-severity
5
+ */
6
+ declare enum VirtualConsoleLogLevelEnum {
7
+ log = 0,
8
+ info = 1,
9
+ warn = 2,
10
+ error = 3
11
+ }
12
+ export default VirtualConsoleLogLevelEnum;
13
+ //# sourceMappingURL=VirtualConsoleLogLevelEnum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualConsoleLogLevelEnum.d.ts","sourceRoot":"","sources":["../../../src/console/enums/VirtualConsoleLogLevelEnum.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,aAAK,0BAA0B;IAC9B,GAAG,IAAI;IACP,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACT;AACD,eAAe,0BAA0B,CAAC"}