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