@xcpcio/core 0.35.0 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +9 -3
- package/package.json +2 -2
- package/src/utils/color.ts +11 -2
package/dist/index.cjs
CHANGED
|
@@ -15,8 +15,8 @@ const relativeTime = require('dayjs/plugin/relativeTime');
|
|
|
15
15
|
const _ = require('lodash');
|
|
16
16
|
const XLSX = require('xlsx-js-style');
|
|
17
17
|
const stringWidth = require('string-width');
|
|
18
|
-
const colorDiff = require('color-diff');
|
|
19
18
|
const chroma = require('chroma-js');
|
|
19
|
+
const colorDiff = require('color-diff');
|
|
20
20
|
|
|
21
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
22
22
|
|
|
@@ -469,7 +469,7 @@ function calcDirt(attemptedNum, solvedNum) {
|
|
|
469
469
|
return Math.floor((attemptedNum - solvedNum) * 100 / attemptedNum);
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
-
function
|
|
472
|
+
function getWhiteOrBlackColorV1(background) {
|
|
473
473
|
const [R, G, B] = chroma__default(background).rgb();
|
|
474
474
|
const color = { R, G, B };
|
|
475
475
|
const palette = [
|
|
@@ -483,6 +483,12 @@ function getWhiteOrBlackColor(background) {
|
|
|
483
483
|
return "#fff";
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
|
+
function getWhiteOrBlackColor(background) {
|
|
487
|
+
const [R, G, B] = chroma__default(background).rgb();
|
|
488
|
+
const brightness = (R * 299 + G * 587 + B * 114) / 1e3;
|
|
489
|
+
const threshold = 148;
|
|
490
|
+
return brightness <= threshold ? "#fff" : "#000";
|
|
491
|
+
}
|
|
486
492
|
|
|
487
493
|
class ProblemStatistics {
|
|
488
494
|
constructor() {
|
|
@@ -1717,6 +1723,7 @@ exports.getImageSource = getImageSource;
|
|
|
1717
1723
|
exports.getTimeDiff = getTimeDiff;
|
|
1718
1724
|
exports.getTimestamp = getTimestamp;
|
|
1719
1725
|
exports.getWhiteOrBlackColor = getWhiteOrBlackColor;
|
|
1726
|
+
exports.getWhiteOrBlackColorV1 = getWhiteOrBlackColorV1;
|
|
1720
1727
|
exports.isAccepted = isAccepted;
|
|
1721
1728
|
exports.isNotCalculatedPenaltyStatus = isNotCalculatedPenaltyStatus;
|
|
1722
1729
|
exports.isPending = isPending;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ declare class TeamProblemStatistics {
|
|
|
83
83
|
|
|
84
84
|
declare function calcDirt(attemptedNum: number, solvedNum: number): number;
|
|
85
85
|
|
|
86
|
+
declare function getWhiteOrBlackColorV1(background: string): "#000" | "#fff";
|
|
86
87
|
declare function getWhiteOrBlackColor(background: string): "#000" | "#fff";
|
|
87
88
|
|
|
88
89
|
declare function createDayJS(time?: Date | string | number | undefined): dayjs.Dayjs;
|
|
@@ -327,4 +328,4 @@ declare function isRejected(status: SubmissionStatus): boolean;
|
|
|
327
328
|
declare function isPending(status: SubmissionStatus): boolean;
|
|
328
329
|
declare function isNotCalculatedPenaltyStatus(status: SubmissionStatus): boolean;
|
|
329
330
|
|
|
330
|
-
export { Award, Awards, Balloon, Balloons, CodeforcesGymGhostDATConverter, Contest, ContestIndex, ContestIndexConfig, ContestIndexList, ContestOptions, GeneralExcelConverter, MedalType, PlaceChartPointData, Problem, ProblemStatistics, Problems, Rank, RankOptions, RankStatistics, Resolver, SelectOptionItem, Submission, Submissions, Team, TeamProblemStatistics, Teams, calcDirt, createContest, createContestIndex, createContestIndexList, createDayJS, createProblem, createProblems, createProblemsByProblemIds, createSubmission, createSubmissions, createTeam, createTeams, getImageSource, getTimeDiff, getTimestamp, getWhiteOrBlackColor, isAccepted, isNotCalculatedPenaltyStatus, isPending, isRejected, isValidMedalType, stringToSubmissionStatus };
|
|
331
|
+
export { Award, Awards, Balloon, Balloons, CodeforcesGymGhostDATConverter, Contest, ContestIndex, ContestIndexConfig, ContestIndexList, ContestOptions, GeneralExcelConverter, MedalType, PlaceChartPointData, Problem, ProblemStatistics, Problems, Rank, RankOptions, RankStatistics, Resolver, SelectOptionItem, Submission, Submissions, Team, TeamProblemStatistics, Teams, calcDirt, createContest, createContestIndex, createContestIndexList, createDayJS, createProblem, createProblems, createProblemsByProblemIds, createSubmission, createSubmissions, createTeam, createTeams, getImageSource, getTimeDiff, getTimestamp, getWhiteOrBlackColor, getWhiteOrBlackColorV1, isAccepted, isNotCalculatedPenaltyStatus, isPending, isRejected, isValidMedalType, stringToSubmissionStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -12,8 +12,8 @@ import relativeTime from 'dayjs/plugin/relativeTime';
|
|
|
12
12
|
import _ from 'lodash';
|
|
13
13
|
import * as XLSX from 'xlsx-js-style';
|
|
14
14
|
import stringWidth from 'string-width';
|
|
15
|
-
import { furthest } from 'color-diff';
|
|
16
15
|
import chroma from 'chroma-js';
|
|
16
|
+
import { furthest } from 'color-diff';
|
|
17
17
|
|
|
18
18
|
function stringToSubmissionStatus(status) {
|
|
19
19
|
status = status.toUpperCase().replace(" ", "_");
|
|
@@ -438,7 +438,7 @@ function calcDirt(attemptedNum, solvedNum) {
|
|
|
438
438
|
return Math.floor((attemptedNum - solvedNum) * 100 / attemptedNum);
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
function
|
|
441
|
+
function getWhiteOrBlackColorV1(background) {
|
|
442
442
|
const [R, G, B] = chroma(background).rgb();
|
|
443
443
|
const color = { R, G, B };
|
|
444
444
|
const palette = [
|
|
@@ -452,6 +452,12 @@ function getWhiteOrBlackColor(background) {
|
|
|
452
452
|
return "#fff";
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
|
+
function getWhiteOrBlackColor(background) {
|
|
456
|
+
const [R, G, B] = chroma(background).rgb();
|
|
457
|
+
const brightness = (R * 299 + G * 587 + B * 114) / 1e3;
|
|
458
|
+
const threshold = 148;
|
|
459
|
+
return brightness <= threshold ? "#fff" : "#000";
|
|
460
|
+
}
|
|
455
461
|
|
|
456
462
|
class ProblemStatistics {
|
|
457
463
|
constructor() {
|
|
@@ -1650,4 +1656,4 @@ class Resolver extends Rank {
|
|
|
1650
1656
|
}
|
|
1651
1657
|
}
|
|
1652
1658
|
|
|
1653
|
-
export { Award, Balloon, CodeforcesGymGhostDATConverter, Contest, ContestIndex, ContestIndexConfig, ContestOptions, GeneralExcelConverter, MedalType, PlaceChartPointData, Problem, ProblemStatistics, Rank, RankOptions, RankStatistics, Resolver, Submission, Team, TeamProblemStatistics, calcDirt, createContest, createContestIndex, createContestIndexList, createDayJS, createProblem, createProblems, createProblemsByProblemIds, createSubmission, createSubmissions, createTeam, createTeams, getImageSource, getTimeDiff, getTimestamp, getWhiteOrBlackColor, isAccepted, isNotCalculatedPenaltyStatus, isPending, isRejected, isValidMedalType, stringToSubmissionStatus };
|
|
1659
|
+
export { Award, Balloon, CodeforcesGymGhostDATConverter, Contest, ContestIndex, ContestIndexConfig, ContestOptions, GeneralExcelConverter, MedalType, PlaceChartPointData, Problem, ProblemStatistics, Rank, RankOptions, RankStatistics, Resolver, Submission, Team, TeamProblemStatistics, calcDirt, createContest, createContestIndex, createContestIndexList, createDayJS, createProblem, createProblems, createProblemsByProblemIds, createSubmission, createSubmissions, createTeam, createTeams, getImageSource, getTimeDiff, getTimestamp, getWhiteOrBlackColor, getWhiteOrBlackColorV1, isAccepted, isNotCalculatedPenaltyStatus, isPending, isRejected, isValidMedalType, stringToSubmissionStatus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xcpcio/core",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"description": "XCPCIO Core",
|
|
5
5
|
"author": "Dup4 <lyuzhi.pan@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"lodash": "^4.17.21",
|
|
47
47
|
"string-width": "^6.1.0",
|
|
48
48
|
"xlsx-js-style": "^1.2.0",
|
|
49
|
-
"@xcpcio/types": "0.35.
|
|
49
|
+
"@xcpcio/types": "0.35.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@babel/types": "^7.22.4",
|
package/src/utils/color.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { furthest } from "color-diff";
|
|
2
1
|
import chroma from "chroma-js";
|
|
2
|
+
import { furthest } from "color-diff";
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function getWhiteOrBlackColorV1(background: string) {
|
|
5
5
|
const [R, G, B] = chroma(background).rgb();
|
|
6
6
|
const color = { R, G, B };
|
|
7
7
|
const palette = [
|
|
@@ -17,3 +17,12 @@ export function getWhiteOrBlackColor(background: string) {
|
|
|
17
17
|
return "#fff";
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export function getWhiteOrBlackColor(background: string) {
|
|
22
|
+
const [R, G, B] = chroma(background).rgb();
|
|
23
|
+
|
|
24
|
+
const brightness = (R * 299 + G * 587 + B * 114) / 1000;
|
|
25
|
+
const threshold = 148;
|
|
26
|
+
|
|
27
|
+
return brightness <= threshold ? "#fff" : "#000";
|
|
28
|
+
}
|