Use simple prng instead of a dependency

closes #2999
This commit is contained in:
Aleksey Kladov 2020-02-03 16:37:12 +01:00
parent 056a01502b
commit ad57726f91
4 changed files with 23 additions and 18 deletions

View file

@ -98,12 +98,6 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/seedrandom": {
"version": "2.4.28",
"resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.28.tgz",
"integrity": "sha512-SMA+fUwULwK7sd/ZJicUztiPs8F1yCPwF3O23Z9uQ32ME5Ha0NmDK9+QTsYE4O2tHXChzXomSWWeIhCnoN1LqA==",
"dev": true
},
"@types/vscode": { "@types/vscode": {
"version": "1.41.0", "version": "1.41.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.41.0.tgz", "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.41.0.tgz",
@ -691,11 +685,6 @@
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==", "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==",
"dev": true "dev": true
}, },
"seedrandom": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
},
"semver": { "semver": {
"version": "6.3.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",

View file

@ -25,7 +25,6 @@
}, },
"dependencies": { "dependencies": {
"jsonc-parser": "^2.1.0", "jsonc-parser": "^2.1.0",
"seedrandom": "^3.0.5",
"vscode-languageclient": "^6.1.0" "vscode-languageclient": "^6.1.0"
}, },
"devDependencies": { "devDependencies": {
@ -33,7 +32,6 @@
"@rollup/plugin-node-resolve": "^6.1.0", "@rollup/plugin-node-resolve": "^6.1.0",
"@rollup/plugin-typescript": "^2.0.0", "@rollup/plugin-typescript": "^2.0.0",
"@types/node": "^12.12.25", "@types/node": "^12.12.25",
"@types/seedrandom": "^2.4.28",
"@types/vscode": "^1.41.0", "@types/vscode": "^1.41.0",
"rollup": "^1.30.1", "rollup": "^1.30.1",
"tslib": "^1.10.0", "tslib": "^1.10.0",

View file

@ -1,6 +1,5 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient'; import * as lc from 'vscode-languageclient';
import seedrandom from 'seedrandom';
import { ColorTheme, TextMateRuleSettings } from './color_theme'; import { ColorTheme, TextMateRuleSettings } from './color_theme';
@ -70,9 +69,9 @@ interface Decoration {
// Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76 // Based on this HSL-based color generator: https://gist.github.com/bendc/76c48ce53299e6078a76
function fancify(seed: string, shade: 'light' | 'dark') { function fancify(seed: string, shade: 'light' | 'dark') {
const random = seedrandom(seed); const random = randomU32Numbers(hashString(seed))
const randomInt = (min: number, max: number) => { const randomInt = (min: number, max: number) => {
return Math.floor(random() * (max - min + 1)) + min; return Math.abs(random()) % (max - min + 1) + min;
}; };
const h = randomInt(0, 360); const h = randomInt(0, 360);
@ -246,3 +245,23 @@ const TAG_TO_SCOPES = new Map<string, string[]>([
["keyword.unsafe", ["keyword.other.unsafe"]], ["keyword.unsafe", ["keyword.other.unsafe"]],
["keyword.control", ["keyword.control"]], ["keyword.control", ["keyword.control"]],
]); ]);
function randomU32Numbers(seed: number) {
let random = seed | 0;
return () => {
random ^= random << 13;
random ^= random >> 17;
random ^= random << 5;
random |= 0;
return random
}
}
function hashString(str: string): number {
let res = 0;
for (let i = 0; i < str.length; ++i) {
const c = str.codePointAt(i)!!;
res = (res * 31 + c) & ~0;
}
return res;
}

View file

@ -13,8 +13,7 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"newLine": "LF", "newLine": "LF"
"esModuleInterop": true
}, },
"exclude": [ "exclude": [
"node_modules" "node_modules"