webpack-dev-service 0.1.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/client/cjs/client.cjs +128 -0
  4. package/client/cjs/events.cjs +64 -0
  5. package/client/cjs/hot.cjs +111 -0
  6. package/client/cjs/index.cjs +15 -0
  7. package/client/cjs/main.cjs +53 -0
  8. package/client/cjs/ui/overlay.cjs +236 -0
  9. package/client/cjs/ui/progress.cjs +94 -0
  10. package/client/cjs/ui/utils/ansi/index.cjs +443 -0
  11. package/client/cjs/ui/utils/ansi/regx.cjs +70 -0
  12. package/client/cjs/ui/utils/ansi/utils.cjs +27 -0
  13. package/client/cjs/ui/utils/index.cjs +126 -0
  14. package/client/esm/client.js +126 -0
  15. package/client/esm/events.js +60 -0
  16. package/client/esm/hot.js +106 -0
  17. package/client/esm/index.js +10 -0
  18. package/client/esm/main.js +51 -0
  19. package/client/esm/ui/overlay.js +234 -0
  20. package/client/esm/ui/progress.js +92 -0
  21. package/client/esm/ui/utils/ansi/index.js +441 -0
  22. package/client/esm/ui/utils/ansi/regx.js +66 -0
  23. package/client/esm/ui/utils/ansi/utils.js +24 -0
  24. package/client/esm/ui/utils/index.js +120 -0
  25. package/global.d.ts +14 -0
  26. package/package.json +121 -0
  27. package/server/cjs/dev.cjs +50 -0
  28. package/server/cjs/hot.cjs +216 -0
  29. package/server/cjs/index.cjs +33 -0
  30. package/server/esm/dev.js +42 -0
  31. package/server/esm/hot.js +207 -0
  32. package/server/esm/index.js +25 -0
  33. package/types/client/client.d.ts +13 -0
  34. package/types/client/events.d.ts +35 -0
  35. package/types/client/hot.d.ts +27 -0
  36. package/types/client/index.d.ts +4 -0
  37. package/types/client/main.d.ts +4 -0
  38. package/types/client/message.d.ts +39 -0
  39. package/types/client/ui/overlay.d.ts +19 -0
  40. package/types/client/ui/progress.d.ts +15 -0
  41. package/types/client/ui/utils/ansi/enum.d.ts +12 -0
  42. package/types/client/ui/utils/ansi/index.d.ts +18 -0
  43. package/types/client/ui/utils/ansi/interface.d.ts +68 -0
  44. package/types/client/ui/utils/ansi/regx.d.ts +6 -0
  45. package/types/client/ui/utils/ansi/utils.d.ts +6 -0
  46. package/types/client/ui/utils/index.d.ts +9 -0
  47. package/types/server/dev.d.ts +17 -0
  48. package/types/server/hot.d.ts +16 -0
  49. package/types/server/index.d.ts +42 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const index = require('./utils/index.cjs');
13
+
14
+ /**
15
+ * @module progress
16
+ * @see https://github.com/shellscape/webpack-plugin-serve
17
+ * @see https://www.zhangxinxu.com/wordpress/2015/07/svg-circle-loading
18
+ */
19
+ const PROGRESS = 'wds-progress';
20
+ const PERIMETER = 2 * Math.PI * 44;
21
+ const CSS = `
22
+ .${PROGRESS} {
23
+ width: 48px;
24
+ right: 16px;
25
+ height: 48px;
26
+ bottom: 16px;
27
+ display: block;
28
+ font-size: 16px;
29
+ position: fixed;
30
+ cursor: default;
31
+ user-select: none;
32
+ font-style: normal;
33
+ font-weight: normal;
34
+ z-index: 2147483647;
35
+ transform-origin: center;
36
+ transform: scale(0) translateZ(0);
37
+ transition: transform .25s ease-out;
38
+ }
39
+ .${PROGRESS}-show {
40
+ transform: scale(1) translateZ(0);
41
+ }
42
+ .${PROGRESS}-track {
43
+ stroke: #badfac;
44
+ stroke-width: 8;
45
+ stroke-linecap: round;
46
+ fill: rgba(0, 0, 0, 0);
47
+ stroke-dasharray: ${PERIMETER};
48
+ stroke-dashoffset: ${PERIMETER};
49
+ transition: stroke-dashoffset .25s linear;
50
+ transform: matrix(0, -1, 1, 0, 0, 96) translateZ(0);
51
+ }
52
+ `;
53
+ const HTML = `
54
+ <svg class="${PROGRESS}" x="0" y="0" viewBox="0 0 96 96">
55
+ <circle fill="#282d35" cx="50%" cy="50%" r="44" />
56
+ <circle class="${PROGRESS}-track" cx="50%" cy="50%" r="44" />
57
+ <path fill="#fff" d="m48,83.213561l-31.122918,-17.60678l0,-35.21356l31.122918,-17.60678l31.122918,17.60678l0,35.21356l-31.122918,17.60678z" />
58
+ <path fill="#8ed6fb" d="m22.434956,31.608089l24.537982,-13.880011l0,10.810563l-15.288554,8.410172l-9.249428,-5.340723zm-1.678513,1.520052l0,29.027711l8.979458,-5.182262l0,-18.657318l-8.979458,-5.188131zm52.908373,-1.520052l-24.537982,-13.880011l0,10.810563l15.288554,8.410172l9.249428,-5.340723zm1.678513,1.520052l0,29.027711l-8.979458,-5.182262l0,-18.657318l8.979458,-5.188131zm-1.050538,30.905767l-25.165957,14.238016l0,-10.452558l16.121941,-8.867948l0.123247,-0.070427l8.920768,5.152918zm-52.485811,0l25.165957,14.238016l0,-10.452558l-16.121941,-8.867948l-0.123247,-0.070427l-8.920768,5.152918z" />
59
+ <path fill="#1c78c0" d="m49.126834,30.997721l15.083141,8.292793l0,16.432994l-15.083141,-8.709487l0,-16.016301zm-2.153896,0l-15.083141,8.292793l0,16.432994l15.083141,-8.709487l0,-16.016301zm16.215844,26.62732l-15.141831,8.328007l-15.141831,-8.328007l15.141831,-8.744701l15.141831,8.744701z" />
60
+ </svg>
61
+ `;
62
+ class Progress {
63
+ timer;
64
+ hidden = true;
65
+ svg;
66
+ track;
67
+ constructor() {
68
+ index.injectCSS(CSS);
69
+ [this.svg] = index.appendHTML(HTML);
70
+ this.track = this.svg.querySelector(`.${PROGRESS}-track`);
71
+ }
72
+ update(value) {
73
+ value = Math.max(0, Math.min(100, value));
74
+ this.track.style.strokeDashoffset = (((100 - value) / 100) * PERIMETER).toString();
75
+ }
76
+ show() {
77
+ if (this.hidden) {
78
+ this.hidden = false;
79
+ clearTimeout(this.timer);
80
+ this.svg.classList.add(`${PROGRESS}-show`);
81
+ }
82
+ }
83
+ hide() {
84
+ if (!this.hidden) {
85
+ this.hidden = true;
86
+ this.timer = self.setTimeout(() => {
87
+ this.update(0);
88
+ this.svg.classList.remove(`${PROGRESS}-show`);
89
+ }, 300);
90
+ }
91
+ }
92
+ }
93
+
94
+ module.exports = Progress;
@@ -0,0 +1,443 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const utils = require('./utils.cjs');
13
+ const regx = require('./regx.cjs');
14
+
15
+ /**
16
+ * @module index
17
+ */
18
+ class Ansi {
19
+ buffer = '';
20
+ style = {
21
+ dim: false,
22
+ bold: false,
23
+ color: null,
24
+ blink: false,
25
+ hidden: false,
26
+ italic: false,
27
+ inverse: false,
28
+ overline: false,
29
+ background: null,
30
+ underline: false,
31
+ strikethrough: false
32
+ };
33
+ colors256;
34
+ colors16;
35
+ constructor(theme = {}) {
36
+ const colors16 = [
37
+ // Colors 16 bit
38
+ [
39
+ // Black
40
+ utils.getThemeColor([0, 0, 0], theme.black),
41
+ // Red
42
+ utils.getThemeColor([187, 0, 0], theme.red),
43
+ // Green
44
+ utils.getThemeColor([0, 187, 0], theme.green),
45
+ // Yellow
46
+ utils.getThemeColor([187, 187, 0], theme.yellow),
47
+ // Blue
48
+ utils.getThemeColor([0, 0, 187], theme.blue),
49
+ // Magenta
50
+ utils.getThemeColor([187, 0, 187], theme.magenta),
51
+ // Cyan
52
+ utils.getThemeColor([0, 187, 187], theme.cyan),
53
+ // White
54
+ utils.getThemeColor([255, 255, 255], theme.white)
55
+ ],
56
+ // Bright colors
57
+ [
58
+ // Bright Black
59
+ utils.getThemeColor([85, 85, 85], theme.brightBlack),
60
+ // Bright Red
61
+ utils.getThemeColor([255, 85, 85], theme.brightRed),
62
+ // Bright Green
63
+ utils.getThemeColor([0, 255, 0], theme.brightGreen),
64
+ // Bright Yellow
65
+ utils.getThemeColor([255, 255, 85], theme.brightYellow),
66
+ // Bright Blue
67
+ utils.getThemeColor([85, 85, 255], theme.brightBlue),
68
+ // Bright Magenta
69
+ utils.getThemeColor([255, 85, 255], theme.brightMagenta),
70
+ // Bright Cyan
71
+ utils.getThemeColor([85, 255, 255], theme.brightCyan),
72
+ // Bright White
73
+ utils.getThemeColor([255, 255, 255], theme.brightWhite)
74
+ ]
75
+ ];
76
+ // Colors 256 bit
77
+ const colors256 = [];
78
+ // Index 0..15 : Ansi-Colors
79
+ for (const palette of colors16) {
80
+ for (const color of palette) {
81
+ colors256.push(color);
82
+ }
83
+ }
84
+ // Index 16..231 : RGB 6x6x6
85
+ // https://gist.github.com/jasonm23/2868981#file-xterm-256color-yaml
86
+ const levels = [0, 95, 135, 175, 215, 255];
87
+ for (let r = 0; r < 6; ++r) {
88
+ for (let g = 0; g < 6; ++g) {
89
+ for (let b = 0; b < 6; ++b) {
90
+ colors256.push([levels[r], levels[g], levels[b]]);
91
+ }
92
+ }
93
+ }
94
+ // Index 232..255 : Grayscale
95
+ let grayscale = 8;
96
+ for (let i = 0; i < 24; ++i, grayscale += 10) {
97
+ colors256.push([grayscale, grayscale, grayscale]);
98
+ }
99
+ // Init ANSI colors
100
+ this.colors16 = colors16;
101
+ this.colors256 = colors256;
102
+ }
103
+ read() {
104
+ const { buffer } = this;
105
+ const { length } = buffer;
106
+ const pos = buffer.indexOf('\x1B');
107
+ // The most common case, no ESC codes
108
+ if (pos < 0) {
109
+ this.buffer = '';
110
+ return {
111
+ value: buffer,
112
+ type: 4 /* TokenType.TEXT */
113
+ };
114
+ }
115
+ if (pos > 0) {
116
+ this.buffer = buffer.slice(pos);
117
+ return {
118
+ type: 4 /* TokenType.TEXT */,
119
+ value: buffer.slice(0, pos)
120
+ };
121
+ }
122
+ if (length === 1) {
123
+ // Lone ESC in Buffer, We don't know yet
124
+ return {
125
+ type: 5 /* TokenType.INCESC */
126
+ };
127
+ }
128
+ const peek = buffer.charAt(1);
129
+ // We treat this as a single ESC
130
+ // Which effecitvely shows
131
+ if (peek !== '[' && peek !== ']') {
132
+ this.buffer = buffer.slice(1);
133
+ // DeMorgan
134
+ return {
135
+ type: 1 /* TokenType.ESC */
136
+ };
137
+ }
138
+ // OK is this an SGR or OSC that we handle
139
+ // SGR CHECK
140
+ if (peek === '[') {
141
+ // We do this regex initialization here so
142
+ // we can keep the regex close to its use (Readability)
143
+ // All ansi codes are typically in the following format.
144
+ // We parse it and focus specifically on the
145
+ // graphics commands (SGR)
146
+ //
147
+ // CONTROL-SEQUENCE-INTRODUCER CSI (ESC, '[')
148
+ // PRIVATE-MODE-CHAR (!, <, >, ?)
149
+ // Numeric parameters separated by semicolons ('0' - '9', ';')
150
+ // Intermediate-modifiers (0x20 - 0x2f)
151
+ // COMMAND-CHAR (0x40 - 0x7e)
152
+ const match = buffer.match(regx.CSI_RE);
153
+ // This match is guaranteed to terminate (even on
154
+ // invalid input). The key is to match on legal and
155
+ // illegal sequences.
156
+ // The first alternate matches everything legal and
157
+ // the second matches everything illegal.
158
+ //
159
+ // If it doesn't match, then we have not received
160
+ // either the full sequence or an illegal sequence.
161
+ // If it does match, the presence of field 4 tells
162
+ // us whether it was legal or illegal.
163
+ if (match === null) {
164
+ return {
165
+ type: 5 /* TokenType.INCESC */
166
+ };
167
+ }
168
+ // match is an array
169
+ // 0 - total match
170
+ // 1 - private mode chars group
171
+ // 2 - digits and semicolons group
172
+ // 3 - command
173
+ // 4 - illegal char
174
+ if (match[4]) {
175
+ this.buffer = buffer.slice(1);
176
+ // Illegal sequence, just remove the ESC
177
+ return {
178
+ type: 1 /* TokenType.ESC */
179
+ };
180
+ }
181
+ this.buffer = buffer.slice(match[0].length);
182
+ // If not a valid SGR, we don't handle
183
+ if (match[1] !== '' || match[3] !== 'm') {
184
+ return {
185
+ type: 6 /* TokenType.UNKNOWN */
186
+ };
187
+ } else {
188
+ return {
189
+ signal: match[2],
190
+ type: 3 /* TokenType.SGR */
191
+ };
192
+ }
193
+ }
194
+ // OSC CHECK
195
+ if (peek === ']') {
196
+ if (length < 4) {
197
+ return {
198
+ type: 5 /* TokenType.INCESC */
199
+ };
200
+ }
201
+ if (buffer.charAt(2) !== '8' || buffer.charAt(3) !== ';') {
202
+ this.buffer = buffer.slice(1);
203
+ // This is not a match, so we'll just treat it as ESC
204
+ return {
205
+ type: 1 /* TokenType.ESC */
206
+ };
207
+ }
208
+ // We do this regex initialization here so
209
+ // we can keep the regex close to its use (Readability)
210
+ // Matching a Hyperlink OSC with a regex is difficult
211
+ // because Javascript's regex engine doesn't support
212
+ // 'partial match' support.
213
+ //
214
+ // Therefore, we require the system to match the
215
+ // string-terminator(ST) before attempting a match.
216
+ // Once we find it, we attempt the Hyperlink-Begin
217
+ // match.
218
+ // If that goes ok, we scan forward for the next
219
+ // ST.
220
+ // Finally, we try to match it all and return
221
+ // the sequence.
222
+ // Also, it is important to note that we consider
223
+ // certain control characters as an invalidation of
224
+ // the entire sequence.
225
+ // We do regex initializations here so
226
+ // we can keep the regex close to its use (Readability)
227
+ // STRING-TERMINATOR
228
+ // This is likely to terminate in most scenarios
229
+ // because it will terminate on a newline
230
+ // VERY IMPORTANT
231
+ // We do a stateful regex match with exec.
232
+ // If the regex is global, and it used with 'exec',
233
+ // then it will search starting at the 'lastIndex'
234
+ // If it matches, the regex can be used again to
235
+ // find the next match.
236
+ regx.OSC_ST_RE.lastIndex = 0;
237
+ // We might have the prefix and URI
238
+ // Lets start our search for the ST twice
239
+ for (let count = 0; count < 2; count++) {
240
+ const match = regx.OSC_ST_RE.exec(buffer);
241
+ if (match === null) {
242
+ return {
243
+ type: 5 /* TokenType.INCESC */
244
+ };
245
+ }
246
+ // If an illegal character was found, bail on the match
247
+ if (match[3]) {
248
+ this.buffer = buffer.slice(1);
249
+ // Illegal sequence, just remove the ESC
250
+ return {
251
+ type: 1 /* TokenType.ESC */
252
+ };
253
+ }
254
+ }
255
+ // OK, at this point we should have a FULL match!
256
+ // Lets try to match that now
257
+ const match = buffer.match(regx.OSC_RE);
258
+ if (match === null) {
259
+ this.buffer = buffer.slice(1);
260
+ // Illegal sequence, just remove the ESC
261
+ return {
262
+ type: 1 /* TokenType.ESC */
263
+ };
264
+ }
265
+ this.buffer = buffer.slice(match[0].length);
266
+ // If a valid SGR
267
+ // match is an array
268
+ // 0 - total match
269
+ // 1 - URL
270
+ // 2 - Text
271
+ return {
272
+ url: match[1],
273
+ value: match[2],
274
+ type: 2 /* TokenType.OSC */
275
+ };
276
+ }
277
+ return {
278
+ type: 0 /* TokenType.EOS */
279
+ };
280
+ }
281
+ reset() {
282
+ const { style } = this;
283
+ style.dim = false;
284
+ style.bold = false;
285
+ style.color = null;
286
+ style.blink = false;
287
+ style.hidden = false;
288
+ style.italic = false;
289
+ style.inverse = false;
290
+ style.background = null;
291
+ style.underline = false;
292
+ style.strikethrough = false;
293
+ }
294
+ process(signal) {
295
+ let index = 0;
296
+ // Ok - we have a valid "SGR" (Select Graphic Rendition)
297
+ const sequences = signal.split(';');
298
+ const maxIndex = sequences.length - 1;
299
+ // ANSI style and colors
300
+ const { style, colors16, colors256 } = this;
301
+ // Read cmd by index
302
+ const read = () => parseInt(sequences[index++], 10);
303
+ // Each of these params affects the SGR state
304
+ // Why do we shift through the array instead of a forEach??
305
+ // ... because some commands consume the params that follow !
306
+ for (; index <= maxIndex; index++) {
307
+ const code = read();
308
+ if (code === 1) {
309
+ style.bold = true;
310
+ } else if (code === 2) {
311
+ style.dim = true;
312
+ } else if (code === 3) {
313
+ style.italic = true;
314
+ } else if (code === 4) {
315
+ style.underline = true;
316
+ } else if (code === 5) {
317
+ style.blink = true;
318
+ } else if (code === 7) {
319
+ style.inverse = true;
320
+ } else if (code === 8) {
321
+ style.hidden = true;
322
+ } else if (code === 9) {
323
+ style.strikethrough = true;
324
+ } else if (code === 53) {
325
+ style.overline = true;
326
+ } else if (code === 21) {
327
+ style.bold = false;
328
+ } else if (code === 22) {
329
+ style.dim = false;
330
+ style.bold = false;
331
+ } else if (code === 23) {
332
+ style.italic = false;
333
+ } else if (code === 24) {
334
+ style.underline = false;
335
+ } else if (code === 25) {
336
+ style.blink = false;
337
+ } else if (code === 27) {
338
+ style.inverse = false;
339
+ } else if (code === 28) {
340
+ style.hidden = false;
341
+ } else if (code === 29) {
342
+ style.strikethrough = false;
343
+ } else if (code === 29) {
344
+ style.strikethrough = false;
345
+ } else if (code === 55) {
346
+ style.overline = false;
347
+ } else if (code === 49) {
348
+ style.background = null;
349
+ } else if (code >= 30 && code < 38) {
350
+ style.color = colors16[0][code - 30];
351
+ } else if (code >= 40 && code < 48) {
352
+ style.background = colors16[0][code - 40];
353
+ } else if (code >= 90 && code < 98) {
354
+ style.color = colors16[1][code - 90];
355
+ } else if (code >= 100 && code < 108) {
356
+ style.background = colors16[1][code - 100];
357
+ } else if (code === 38 || code === 48) {
358
+ // Extended set foreground/background color
359
+ // validate that param exists
360
+ if (index < maxIndex) {
361
+ const mode = read();
362
+ // Extend color (38=fg, 48=bg)
363
+ const isForeground = code === 38;
364
+ // MODE 5 - 256 color palette
365
+ if (mode === 5 && index <= maxIndex) {
366
+ const index = utils.toUint8(read());
367
+ if (isForeground) {
368
+ style.color = colors256[index];
369
+ } else {
370
+ style.background = colors256[index];
371
+ }
372
+ }
373
+ // MODE 2 - True Color
374
+ if (mode === 2 && index + 2 <= maxIndex) {
375
+ const r = utils.toUint8(read());
376
+ const g = utils.toUint8(read());
377
+ const b = utils.toUint8(read());
378
+ // True Color
379
+ const color = [r, g, b];
380
+ if (isForeground) {
381
+ style.color = color;
382
+ } else {
383
+ style.background = color;
384
+ }
385
+ }
386
+ }
387
+ } else {
388
+ this.reset();
389
+ }
390
+ }
391
+ }
392
+ block(token) {
393
+ const block = {
394
+ value: token.value,
395
+ style: { ...this.style }
396
+ };
397
+ if ('url' in token) {
398
+ block.url = token.url;
399
+ }
400
+ return block;
401
+ }
402
+ write(text, callback) {
403
+ this.buffer += text;
404
+ while (this.buffer) {
405
+ const token = this.read();
406
+ switch (token.type) {
407
+ case 0 /* TokenType.EOS */:
408
+ case 5 /* TokenType.INCESC */:
409
+ break;
410
+ case 1 /* TokenType.ESC */:
411
+ case 6 /* TokenType.UNKNOWN */:
412
+ continue;
413
+ case 3 /* TokenType.SGR */:
414
+ this.process(token.signal);
415
+ continue;
416
+ case 2 /* TokenType.OSC */:
417
+ case 4 /* TokenType.TEXT */:
418
+ callback(this.block(token));
419
+ continue;
420
+ default:
421
+ continue;
422
+ }
423
+ }
424
+ }
425
+ flush(callback) {
426
+ const { buffer } = this;
427
+ // Get flush block
428
+ if (buffer !== '') {
429
+ callback(
430
+ this.block({
431
+ value: buffer,
432
+ type: 4 /* TokenType.TEXT */
433
+ })
434
+ );
435
+ }
436
+ // Reset
437
+ this.reset();
438
+ // Flush buffer
439
+ this.buffer = '';
440
+ }
441
+ }
442
+
443
+ module.exports = Ansi;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ /**
13
+ * @module regx
14
+ */
15
+ // prettier-ignore
16
+ // (?: # legal sequence
17
+ // (\x1b\\) # ESC \
18
+ // | # alternate
19
+ // (\x07) # BEL (what xterm did)
20
+ // ) # legal sequence end
21
+ // | # alternate (second attempt)
22
+ // ( # illegal sequence
23
+ // [\x00-\x06] # anything illegal
24
+ // | # alternate
25
+ // [\x08-\x1a] # anything illegal
26
+ // | # alternate
27
+ // [\x1c-\x1f] # anything illegal
28
+ // ) # illegal sequence end
29
+ const OSC_ST_RE = /(?:(\x1b\\)|(\x07))|([\x00-\x06]|[\x08-\x1a]|[\x1c-\x1f])/g;
30
+ // prettier-ignore
31
+ // ^ # beginning of line
32
+ // (?: # legal sequence
33
+ // \x1b\[ # CSI
34
+ // ([\x3c-\x3f]?) # private-mode char
35
+ // ([\d;]*) # any digits or semicolons
36
+ // ( # modifier command sequence
37
+ // [\x20-\x2f]? # an intermediate modifier
38
+ // [\x40-\x7e] # the command
39
+ // ) # modifier command sequence end
40
+ // ) # legal sequence end
41
+ // | # alternate (second attempt)
42
+ // (?: # illegal sequence
43
+ // \x1b\[ # CSI
44
+ // [\x20-\x7e]* # anything legal
45
+ // ([\x00-\x1f:]) # anything illegal
46
+ // ) # illegal sequence end
47
+ const CSI_RE = /^(?:\x1b\[([\x3c-\x3f]?)([\d;]*)([\x20-\x2f]?[\x40-\x7e]))|(?:\x1b\[[\x20-\x7e]*([\x00-\x1f:]))/;
48
+ // prettier-ignore
49
+ // ^ # beginning of line
50
+ // \x1b\]8; # OSC Hyperlink
51
+ // [\x20-\x3a\x3c-\x7e]* # params (excluding ;)
52
+ // ; # end of params
53
+ // ([\x21-\x7e]{0,512}) # URL capture
54
+ // (?: # ST sequence
55
+ // (?:\x1b\\) # ESC \
56
+ // | # alternate
57
+ // (?:\x07) # BEL (what xterm did)
58
+ // ) # ST sequence end
59
+ // ([\x20-\x7e]+) # TEXT capture
60
+ // \x1b\]8;; # OSC Hyperlink End
61
+ // (?: # ST sequence
62
+ // (?:\x1b\\) # ESC \
63
+ // | # alternate
64
+ // (?:\x07) # BEL (what xterm did)
65
+ // ) # ST sequence end
66
+ const OSC_RE = /^\x1b\]8;[\x20-\x3a\x3c-\x7e]*;([\x21-\x7e]{0,512})(?:(?:\x1b\\)|(?:\x07))([\x20-\x7e]+)\x1b\]8;;(?:(?:\x1b\\)|(?:\x07))/;
67
+
68
+ exports.CSI_RE = CSI_RE;
69
+ exports.OSC_RE = OSC_RE;
70
+ exports.OSC_ST_RE = OSC_ST_RE;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.1.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ /**
13
+ * @module utils
14
+ */
15
+ function toUint8(uint8) {
16
+ return uint8 & 0xff;
17
+ }
18
+ function getThemeColor(defaultColor, color) {
19
+ if (color) {
20
+ const [r, g, b] = color;
21
+ return [toUint8(r), toUint8(g), toUint8(b)];
22
+ }
23
+ return defaultColor;
24
+ }
25
+
26
+ exports.getThemeColor = getThemeColor;
27
+ exports.toUint8 = toUint8;