This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
umd.ts
69 lines (58 loc) 路 1.93 KB
/
umd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gardens from '../lib/gardens';
const env = {
browser: typeof window !== 'undefined'
&& typeof navigator !== 'undefined',
node: typeof process !== 'undefined'
&& process.versions && process.versions.node
};
const hex = /^#[0-9a-f]{6}$/i;
if ( env.browser ) {
const edge = parseFloat(
( navigator.userAgent.match( /Edge?\/([\d.]+)/ )
|| [ '', '0' ] )[ 1 ] );
const supportsColor = !edge || edge >= 19;
const hrt = typeof performance !== 'undefined';
gardens.configureEnvironment({
performance: hrt ? performance : null,
supportsColor,
timingPrecision: hrt ? 6 : 0
});
}
else if ( env.node ) {
const chalk = require( 'chalk' );
const { performance } = require( 'perf_hooks' );
const readline = require( 'readline' );
const color = require( 'supports-color' );
const { inspect } = require( 'util' );
const supportsColor = color.stdout.hasBasic;
gardens.configureEnvironment({
defaultOutputType: 'ansi',
defaultStream: process.stdout,
inspect( item, options ) {
return inspect( item, { colors: supportsColor && options.outputType === 'ansi' });
},
moveCursorBy( x, y ) {
readline.moveCursor( process.stdout, x, y );
},
performance,
style( text, style ) {
if ( !style ) return { text };
let wrap = chalk;
if ( hex.test( style.backgroundColor ) ) wrap = wrap.bgHex( style.backgroundColor );
if ( style.color ) wrap = wrap.hex( style.color );
if ( style.fontStyle === 'italic' ) wrap = wrap.italic;
if ( style.fontWeight > 400 ) wrap = wrap.bold;
if ( style.textDecoration ) {
wrap = wrap.underline;
if ( style.textDecoration.includes( 'underline' ) ) wrap = wrap.underline;
if ( style.textDecoration.includes( 'line-through' ) ) wrap = wrap.strikethrough;
}
return {
text: wrap( text )
};
},
supportsColor,
timingPrecision: 6
});
}
export default new gardens();