Skip to content

Commit ad57726

Browse files
committed
Use simple prng instead of a dependency
closes #2999
1 parent 056a015 commit ad57726

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

editors/code/package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editors/code/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
},
2626
"dependencies": {
2727
"jsonc-parser": "^2.1.0",
28-
"seedrandom": "^3.0.5",
2928
"vscode-languageclient": "^6.1.0"
3029
},
3130
"devDependencies": {
3231
"@rollup/plugin-commonjs": "^11.0.1",
3332
"@rollup/plugin-node-resolve": "^6.1.0",
3433
"@rollup/plugin-typescript": "^2.0.0",
3534
"@types/node": "^12.12.25",
36-
"@types/seedrandom": "^2.4.28",
3735
"@types/vscode": "^1.41.0",
3836
"rollup": "^1.30.1",
3937
"tslib": "^1.10.0",

editors/code/src/highlighting.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode';
22
import * as lc from 'vscode-languageclient';
3-
import seedrandom from 'seedrandom';
43

54
import { ColorTheme, TextMateRuleSettings } from './color_theme';
65

@@ -70,9 +69,9 @@ interface Decoration {
7069

7170
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
7271
function fancify(seed: string, shade: 'light' | 'dark') {
73-
const random = seedrandom(seed);
72+
const random = randomU32Numbers(hashString(seed))
7473
const randomInt = (min: number, max: number) => {
75-
return Math.floor(random() * (max - min + 1)) + min;
74+
return Math.abs(random()) % (max - min + 1) + min;
7675
};
7776

7877
const h = randomInt(0, 360);
@@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map<string, string[]>([
246245
["keyword.unsafe", ["keyword.other.unsafe"]],
247246
["keyword.control", ["keyword.control"]],
248247
]);
248+
249+
function randomU32Numbers(seed: number) {
250+
let random = seed | 0;
251+
return () => {
252+
random ^= random << 13;
253+
random ^= random >> 17;
254+
random ^= random << 5;
255+
random |= 0;
256+
return random
257+
}
258+
}
259+
260+
function hashString(str: string): number {
261+
let res = 0;
262+
for (let i = 0; i < str.length; ++i) {
263+
const c = str.codePointAt(i)!!;
264+
res = (res * 31 + c) & ~0;
265+
}
266+
return res;
267+
}

editors/code/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"noUnusedParameters": true,
1414
"noImplicitReturns": true,
1515
"noFallthroughCasesInSwitch": true,
16-
"newLine": "LF",
17-
"esModuleInterop": true
16+
"newLine": "LF"
1817
},
1918
"exclude": [
2019
"node_modules"

0 commit comments

Comments
 (0)