forked from staltz/hyperpunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
155 lines (141 loc) · 4.4 KB
/
index.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const noise1Png = require('./noise1');
const noise2Png = require('./noise2');
const noise3Png = require('./noise3');
const HUE_SHIFT_INTENSITY = 4;
const BRIGHT_GREEN = '#28FC91';
const DARK_GREEN = '#0F2218';
const TEXT_GREEN = '51, 255, 0';
exports.decorateConfig = (config) => {
return Object.assign({}, config, {
foregroundColor: BRIGHT_GREEN,
backgroundColor: DARK_GREEN,
borderColor: BRIGHT_GREEN,
cursorColor: '#40FFFF',
});
}
exports.decorateHyper = (HyperTerm, { React, notify }) => {
return class extends React.Component {
constructor(props, context) {
super(props, context);
this.state = { noise: 0 };
this._flip = this._flip.bind(this);
this._intervalID = null;
}
_flip () {
this.setState({ noise: (this.state.noise + 1) % 3 });
}
componentWillMount() {
this._intervalID = setInterval(this._flip, 120);
}
render() {
const noisePng = [noise1Png, noise2Png, noise3Png][this.state.noise];
const noiseCss = `
background-image: ${noisePng};
background-size: 100px 100px;
`;
const textShadow = generateTextShadow();
const overridenProps = {
backgroundColor: 'black',
customCSS: `
${this.props.customCSS || ''}
body {
${noiseCss}
}
.tabs_nav {
${noiseCss}
}
.tabs_nav .tabs_title {
color: rgb(${TEXT_GREEN}) !important;
font-weight: bold !important;
${textShadow}
}
.tabs_list {
background-color: ${DARK_GREEN} !important;
background-image: none !important;
}
.tab_tab {
border-width: 0px !important;
border-right: 0px solid transparent !important;
border-left: 1px solid ${BRIGHT_GREEN} !important;
}
.tab_tab:not(.tab_active) {
color: rgba(${TEXT_GREEN}, 0.7);
}
.tab_tab.tab_active {
height: calc(100% + 1px);
${noiseCss}
border-left: 0px solid ${BRIGHT_GREEN} !important;
${textShadow}
font-weight: bold;
color: rgb(${TEXT_GREEN});
}
/* Hide hardcoded black bottom border */
.tab_active:before {
border-bottom: none !important;
border-left: 1px solid transparent !important;
}
`,
};
return React.createElement(HyperTerm, Object.assign({}, this.props, overridenProps));
}
componentWillUnmount() {
clearInterval(this._intervalID);
}
}
}
exports.decorateTerm = (Term, { React, notify }) => {
return class extends React.Component {
constructor (props, context) {
super(props, context);
this._drawFrame = this._drawFrame.bind(this);
this._onTerminal = this._onTerminal.bind(this);
this._injectStyles = this._injectStyles.bind(this);
this._div = null;
this._body = null;
this._globalStyle = null;
this._term = null;
this._intervalID = null;
}
_onTerminal (term) {
if (this.props.onTerminal) this.props.onTerminal(term);
this._div = term.div_;
this._term = term;
this._body = term.cursorNode_.parentElement;
this._window = term.document_.defaultView;
this._injectStyles();
this._intervalID = setInterval(() => {
this._window.requestAnimationFrame(this._drawFrame);
}, 80);
}
_injectStyles() {
if (this._term) {
this._term.prefs_.set('background-color', 'transparent');
this._term.prefs_.set('background-image', 'none');
}
this._globalStyle = document.createElement('style');
this._globalStyle.setAttribute('type', 'text/css');
this._term.scrollPort_.document_.body.appendChild(this._globalStyle);
}
_drawFrame () {
this._globalStyle.innerHTML = `
x-screen {
${generateTextShadow()}
}
`;
}
render () {
return React.createElement(Term, Object.assign({}, this.props, {
onTerminal: this._onTerminal
}));
}
componentWillUnmount () {
clearInterval(this._intervalID);
}
}
};
function generateTextShadow() {
let x = -1 + 2 * Math.random();
x = x * x;
const intensity = HUE_SHIFT_INTENSITY * x;
return `text-shadow: ${intensity}px 0 1px rgba(0,30,255,0.5), ${-intensity}px 0 1px rgba(255,0,80,0.3), 0 0 3px !important;`
}