forked from razh/js13k-2015
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreplaceAll.js
167 lines (157 loc) · 3.71 KB
/
replaceAll.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
156
157
158
159
160
161
162
163
164
165
166
167
'use strict';
const through = require('through2');
// Map to avoid duplicate keys.
const substitutions = {
'.aPM': '.applyProjectionMatrix',
'.aP': '.applyProjection',
'.uPM': '.updateProjectionMatrix',
'.m4': '.applyMatrix4',
'.m3': '.applyMatrix3',
'.ps': '.positionScreen',
'.pw': '.positionWorld',
'.ra': '.rotateOnAxis',
'.rx': '.rotateX',
'.ry': '.rotateY',
'.rz': '.rotateZ',
'.ta': '.translateOnAxis',
'.tx': '.translateX',
'.ty': '.translateY',
'.tz': '.translateZ',
'.lA': '.lookAt',
'.dTS': '.distanceToSquared',
'.dT': '.distanceTo',
'.nM': '.getNormalMatrix',
'.mM': '.multiplyMatrices',
'.nz': '.normalize',
'.aa': '.setFromAxisAngle',
'.gI': '.getInverse',
'.tr': '.transpose',
'.cV': '.crossVectors',
'.mWI': '.matrixWorldInverse',
'.mW': '.matrixWorld',
'.mP': '.setFromMatrixPosition',
'.mRQ': '.makeRotationFromQuaternion',
'.mQ': '.multiplyQuaternions',
'.qu': /\.quaternion(?!\w+)/g,
'.sR': '.setFromRotationMatrix',
'.sQ': '.setFromQuaternion',
'.sE': '.setFromEuler',
'.aQ': '.applyQuaternion',
'.uQ': '.updateQuaternion',
'.uR': '.updateRotation',
'.nm': '.normalModel',
'.nr': '.normal',
'.id': '.identity',
'.mt': '.material',
'.po': '.position',
'.ro': '.rotation',
'.aS': '.addScalar',
'.mS': '.multiplyScalar',
'.uM': '.updateMatrix',
'.rgb': '.setRGB',
'.fA': '.fromArray',
'.sV': '.subVectors',
'.pM': '.projectionMatrix',
'.mx': /\.matrix(?!\w+)/g,
'.cFN': '.computeFaceNormals',
'.ds': /\.distance(?!\w+)/g,
// Camera.
'.ca': '.camera',
'.as': '.aspect',
// Render data.
'ls': /lights(?!\w+)/g,
'os': /objects(?!\w+)/g,
// Render list.
'sO': 'setObject',
'cTV': 'checkTriangleVisibility',
'cBC': 'checkBackfaceCulling',
'pV': 'pushVertex',
// Bounding box.
'.sFP': '.setFromPoints',
'.sFO': '.setFromObject',
'.eP': '.expandByPoint',
'.iB': '.isIntersectionBox',
'.eS': '.expandByScalar',
'.mE': '.makeEmpty',
'.vi': '.visible',
'.ge': '.geometry',
'.ve': '.vertices',
'.fa': '.faces',
'.qd': '.quads',
'el': 'elements',
'.se': '.scene',
'.ch': '.children',
'.rr': '.renderer',
'.rg': '.running',
'.ud': /\.update(?!\w+)/g,
'.cp': '.copy',
'.mul': /\.multiply(?!\w+)/g,
'.sP': /\.setPosition(?!\w+)/g,
'.pS': '.projectScene',
// Filter properties.
'.fi': '.filter',
'.cB': '.categoryBits',
'.mB': '.maskBits',
'.grI': '.groupIndex',
// Material properties.
'wf': 'wireframe',
'op': 'opacity',
'bl': 'blending',
'ov': 'overdraw',
// Material sides.
'.DS': '.DoubleSide',
'.FS': '.FrontSide',
'.BS': '.BackSide',
// Color properties.
'am': 'ambient',
'em': 'emissive',
'tC': 'strokeColor',
'cr': 'color',
// Utils.
'.i': '.inherits',
// Browserify.
'NF': 'MODULE_NOT_FOUND',
'N': 'Cannot find module '
};
// Only for reference rigt now.
const exclude = [
'fillStyle',
'strokeStyle',
'lineWidth',
'shadowColor',
'shadowBlur',
'beginPath',
'moveTo',
'lineTo',
'setTransform',
'translate',
'scale',
'fill',
'stroke',
'innerWidth',
'innerHeight',
'remove'
];
module.exports = function() {
function replaceAll(file, encoding, callback) {
if (file.isNull()) {
this.push(file);
return callback();
}
try {
let contents = String(file.contents);
Object.keys(substitutions).forEach(function(key) {
const value = substitutions[key];
const regex = value instanceof RegExp ? value
: new RegExp(value.replace('.', '\\.'), 'g');
contents = contents.replace(regex, key);
});
file.contents = new Buffer(contents);
} catch (e) {
throw new Error();
}
this.push(file);
callback();
}
return through.obj(replaceAll);
};