czapp-shared 1.0.39 → 1.1.0
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.d.mts +132 -6
- package/dist/index.d.ts +132 -6
- package/dist/index.js +318 -15
- package/dist/index.mjs +305 -14
- package/package.json +1 -1
- package/src/concrete/color.ts +41 -0
- package/src/concrete/level.ts +42 -17
- package/src/concrete/levelDefaults.ts +118 -0
- package/src/concrete/levelValidation.ts +101 -0
- package/src/design/api.ts +2 -0
- package/src/design/levels.ts +103 -0
- package/src/index.ts +4 -0
- package/test/levelConfig.test.ts +106 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
5
22
|
var __export = (target, all) => {
|
|
6
23
|
for (var name in all)
|
|
7
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,7 +39,11 @@ __export(index_exports, {
|
|
|
22
39
|
ApiMethod: () => ApiMethod,
|
|
23
40
|
ApiPath: () => ApiPath,
|
|
24
41
|
AppError: () => AppError,
|
|
42
|
+
AvatarPresetId: () => AvatarPresetId,
|
|
25
43
|
ClientPlatform: () => ClientPlatform,
|
|
44
|
+
DEFAULT_LEVELS_CONFIG: () => DEFAULT_LEVELS_CONFIG,
|
|
45
|
+
DEFAULT_LEVEL_DEFINITIONS: () => DEFAULT_LEVEL_DEFINITIONS,
|
|
46
|
+
DEFAULT_XP_AWARDS: () => DEFAULT_XP_AWARDS,
|
|
26
47
|
Familiarity: () => Familiarity,
|
|
27
48
|
HttpStatusCode: () => HttpStatusCode,
|
|
28
49
|
LEARNING_STAGES_IN_GROUP: () => LEARNING_STAGES_IN_GROUP,
|
|
@@ -32,6 +53,9 @@ __export(index_exports, {
|
|
|
32
53
|
LearningStageGroup: () => LearningStageGroup,
|
|
33
54
|
Lexeme: () => Lexeme,
|
|
34
55
|
LexemePair: () => LexemePair,
|
|
56
|
+
MAX_LEVEL_NAME_LENGTH: () => MAX_LEVEL_NAME_LENGTH,
|
|
57
|
+
MAX_LOTTIE_BYTES: () => MAX_LOTTIE_BYTES,
|
|
58
|
+
MAX_SVG_BYTES: () => MAX_SVG_BYTES,
|
|
35
59
|
Progress: () => Progress,
|
|
36
60
|
ReminderFrequency: () => ReminderFrequency,
|
|
37
61
|
Scenario: () => Scenario,
|
|
@@ -44,6 +68,7 @@ __export(index_exports, {
|
|
|
44
68
|
convertJSDateStringToMySQLDate: () => convertJSDateStringToMySQLDate,
|
|
45
69
|
dateDifferenceInDays: () => dateDifferenceInDays,
|
|
46
70
|
deriveStreakFromVocabCheckActivity: () => deriveStreakFromVocabCheckActivity,
|
|
71
|
+
generatePalette: () => generatePalette,
|
|
47
72
|
getBestStreak: () => getBestStreak,
|
|
48
73
|
getFlashcardReviewXp: () => getFlashcardReviewXp,
|
|
49
74
|
getFormattedDate: () => getFormattedDate,
|
|
@@ -52,9 +77,12 @@ __export(index_exports, {
|
|
|
52
77
|
getMysqlDateIgnoreTZ: () => getMysqlDateIgnoreTZ,
|
|
53
78
|
getTestXp: () => getTestXp,
|
|
54
79
|
getUserLevelProgress: () => getUserLevelProgress,
|
|
80
|
+
hexToHsl: () => hexToHsl,
|
|
81
|
+
hslToHex: () => hslToHex,
|
|
55
82
|
isClientDateTooFarFromServerDate: () => isClientDateTooFarFromServerDate,
|
|
56
83
|
isExpired: () => isExpired,
|
|
57
84
|
isFinalTest: () => isFinalTest,
|
|
85
|
+
isHexColor: () => isHexColor,
|
|
58
86
|
isLearningStageGroup: () => isLearningStageGroup,
|
|
59
87
|
isStringContainingInteger: () => isStringContainingInteger,
|
|
60
88
|
isThePreviousDay: () => isThePreviousDay,
|
|
@@ -62,10 +90,46 @@ __export(index_exports, {
|
|
|
62
90
|
isValidJsDateString: () => isValidJsDateString,
|
|
63
91
|
isValidMysqlDateString: () => isValidMysqlDateString,
|
|
64
92
|
maxLevel: () => maxLevel,
|
|
65
|
-
parameterReplace: () => parameterReplace
|
|
93
|
+
parameterReplace: () => parameterReplace,
|
|
94
|
+
shiftHue: () => shiftHue,
|
|
95
|
+
validateLevelDefinition: () => validateLevelDefinition,
|
|
96
|
+
validateLevelsConfig: () => validateLevelsConfig,
|
|
97
|
+
validateXpAwards: () => validateXpAwards
|
|
66
98
|
});
|
|
67
99
|
module.exports = __toCommonJS(index_exports);
|
|
68
100
|
|
|
101
|
+
// src/concrete/color.ts
|
|
102
|
+
var hexToHsl = (hex) => {
|
|
103
|
+
let value = hex.replace("#", "");
|
|
104
|
+
if (value.length === 3) value = value.split("").map((c) => c + c).join("");
|
|
105
|
+
const r = parseInt(value.slice(0, 2), 16) / 255;
|
|
106
|
+
const g = parseInt(value.slice(2, 4), 16) / 255;
|
|
107
|
+
const b = parseInt(value.slice(4, 6), 16) / 255;
|
|
108
|
+
const max = Math.max(r, g, b);
|
|
109
|
+
const min = Math.min(r, g, b);
|
|
110
|
+
const l = (max + min) / 2;
|
|
111
|
+
if (max === min) return { h: 0, s: 0, l };
|
|
112
|
+
const d = max - min;
|
|
113
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
114
|
+
const h = max === r ? (g - b) / d + (g < b ? 6 : 0) : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
|
|
115
|
+
return { h: h * 60, s, l };
|
|
116
|
+
};
|
|
117
|
+
var hslToHex = ({ h, s, l }) => {
|
|
118
|
+
const hue = (h % 360 + 360) % 360;
|
|
119
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
120
|
+
const x = c * (1 - Math.abs(hue / 60 % 2 - 1));
|
|
121
|
+
const m = l - c / 2;
|
|
122
|
+
const [r, g, b] = hue < 60 ? [c, x, 0] : hue < 120 ? [x, c, 0] : hue < 180 ? [0, c, x] : hue < 240 ? [0, x, c] : hue < 300 ? [x, 0, c] : [c, 0, x];
|
|
123
|
+
const toHex = (v) => Math.round((v + m) * 255).toString(16).padStart(2, "0");
|
|
124
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
125
|
+
};
|
|
126
|
+
var shiftHue = (hex, degrees) => {
|
|
127
|
+
if (!degrees) return hex;
|
|
128
|
+
const hsl = hexToHsl(hex);
|
|
129
|
+
return hslToHex(__spreadProps(__spreadValues({}, hsl), { h: hsl.h + degrees }));
|
|
130
|
+
};
|
|
131
|
+
var isHexColor = (value) => typeof value === "string" && /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value);
|
|
132
|
+
|
|
69
133
|
// src/concrete/date.ts
|
|
70
134
|
var getMysqlDateIgnoreTZ = (date) => {
|
|
71
135
|
let dateStr;
|
|
@@ -149,9 +213,12 @@ var LEVELS = [
|
|
|
149
213
|
];
|
|
150
214
|
var maxLevel = LEVELS[LEVELS.length - 1].level;
|
|
151
215
|
var meetsRequirements = (level, xp, bestStreak) => xp >= level.xpThreshold && bestStreak >= level.minBestStreak;
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
216
|
+
var sorted = (levels) => levels.length < 2 || levels.every((l, i) => i === 0 || levels[i - 1].level < l.level) ? levels : [...levels].sort((a, b) => a.level - b.level);
|
|
217
|
+
var getLevel = (xp, bestStreak, levels = LEVELS) => {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
const ordered = sorted(levels);
|
|
220
|
+
let reached = (_b = (_a = ordered[0]) == null ? void 0 : _a.level) != null ? _b : 1;
|
|
221
|
+
for (const level of ordered) {
|
|
155
222
|
if (!meetsRequirements(level, xp, bestStreak)) {
|
|
156
223
|
break;
|
|
157
224
|
}
|
|
@@ -159,14 +226,16 @@ var getLevel = (xp, bestStreak) => {
|
|
|
159
226
|
}
|
|
160
227
|
return reached;
|
|
161
228
|
};
|
|
162
|
-
var getLevelProgress = (xp, bestStreak) => {
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
|
|
229
|
+
var getLevelProgress = (xp, bestStreak, levels = LEVELS) => {
|
|
230
|
+
const ordered = sorted(levels);
|
|
231
|
+
const level = getLevel(xp, bestStreak, ordered);
|
|
232
|
+
const index = ordered.findIndex((l) => l.level === level);
|
|
233
|
+
const current = ordered[index];
|
|
234
|
+
const next = ordered[index + 1];
|
|
235
|
+
if (!current || !next) {
|
|
167
236
|
return { level, xpToNextLevel: 0, xpProgress: 1, streakDaysToNextLevel: 0 };
|
|
168
237
|
}
|
|
169
|
-
const span = next.xpThreshold - current.xpThreshold;
|
|
238
|
+
const span = Math.max(1, next.xpThreshold - current.xpThreshold);
|
|
170
239
|
return {
|
|
171
240
|
level,
|
|
172
241
|
nextLevel: next.level,
|
|
@@ -175,15 +244,233 @@ var getLevelProgress = (xp, bestStreak) => {
|
|
|
175
244
|
streakDaysToNextLevel: Math.max(0, next.minBestStreak - bestStreak)
|
|
176
245
|
};
|
|
177
246
|
};
|
|
178
|
-
var
|
|
179
|
-
|
|
247
|
+
var DEFAULT_XP_AWARDS = {
|
|
248
|
+
flashcardReview: XP_FLASHCARD_REVIEW,
|
|
249
|
+
test: XP_TEST,
|
|
250
|
+
perTestKnownAnswer: XP_PER_TEST_KNOWN_ANSWER,
|
|
251
|
+
perWordRetired: XP_PER_WORD_RETIRED,
|
|
252
|
+
dailyStreakBonusCap: XP_DAILY_STREAK_BONUS_CAP
|
|
253
|
+
};
|
|
254
|
+
var getFlashcardReviewXp = (retiredCount, newStreakDayLength, awards = DEFAULT_XP_AWARDS) => awards.flashcardReview + retiredCount * awards.perWordRetired + Math.min(Math.max(0, newStreakDayLength), awards.dailyStreakBonusCap);
|
|
255
|
+
var getTestXp = (knownCount, awards = DEFAULT_XP_AWARDS) => awards.test + knownCount * awards.perTestKnownAnswer;
|
|
180
256
|
var getBestStreak = (user) => {
|
|
181
257
|
var _a, _b;
|
|
182
258
|
return Math.max((_a = user.highStreakLength) != null ? _a : 0, (_b = user.currentStreakLength) != null ? _b : 0);
|
|
183
259
|
};
|
|
184
|
-
var getUserLevelProgress = (user) => {
|
|
260
|
+
var getUserLevelProgress = (user, levels = LEVELS) => {
|
|
185
261
|
var _a;
|
|
186
|
-
return getLevelProgress((_a = user.xp) != null ? _a : 0, getBestStreak(user));
|
|
262
|
+
return getLevelProgress((_a = user.xp) != null ? _a : 0, getBestStreak(user), levels);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/design/levels.ts
|
|
266
|
+
var AvatarPresetId = /* @__PURE__ */ ((AvatarPresetId2) => {
|
|
267
|
+
AvatarPresetId2["COOL_CATALYST"] = "coolCatalyst";
|
|
268
|
+
AvatarPresetId2["SWIFT_STARTER"] = "swiftStarter";
|
|
269
|
+
AvatarPresetId2["BOLD_BUILDER"] = "boldBuilder";
|
|
270
|
+
AvatarPresetId2["WORD_WRANGLER"] = "wordWrangler";
|
|
271
|
+
AvatarPresetId2["FLUENT_FLAME"] = "fluentFlame";
|
|
272
|
+
AvatarPresetId2["MIGHTY_MASTER"] = "mightyMaster";
|
|
273
|
+
AvatarPresetId2["RADIANT_ROCKSTAR"] = "radiantRockstar";
|
|
274
|
+
AvatarPresetId2["WISE_WIZARD"] = "wiseWizard";
|
|
275
|
+
AvatarPresetId2["LEGENDARY_LINGUIST"] = "legendaryLinguist";
|
|
276
|
+
AvatarPresetId2["ABSOLUTE_ALPHA"] = "absoluteAlpha";
|
|
277
|
+
return AvatarPresetId2;
|
|
278
|
+
})(AvatarPresetId || {});
|
|
279
|
+
|
|
280
|
+
// src/concrete/levelDefaults.ts
|
|
281
|
+
var DESIGN = {
|
|
282
|
+
background: "#ece7e1",
|
|
283
|
+
card: "#f9f8f6",
|
|
284
|
+
brand: "#317a97",
|
|
285
|
+
brandMid: "#76b2cb",
|
|
286
|
+
brandLight: "#a7d2e4",
|
|
287
|
+
brandPale: "#cedfe8",
|
|
288
|
+
points: "#fcb64a",
|
|
289
|
+
streak: "#f0643f",
|
|
290
|
+
test: "#80bda6",
|
|
291
|
+
testDark: "#326451",
|
|
292
|
+
testText: "#4c836e",
|
|
293
|
+
leaderboardHighlight: "#fbe6c4",
|
|
294
|
+
divider: "#d9d3c9",
|
|
295
|
+
heatScale: ["#dddddd", "#f8d9ab", "#f49911", "#e37639", "#df6c4a", "#cf4132"]
|
|
296
|
+
};
|
|
297
|
+
var BASE_HUE = 28;
|
|
298
|
+
var LEVEL_HUES = [BASE_HUE, 50, 125, 175, 210, 240, 275, 320, 355, 45];
|
|
299
|
+
var NAMES = [
|
|
300
|
+
{ en: "Cool Catalyst", cz: "Klidn\xFD katalyz\xE1tor" },
|
|
301
|
+
{ en: "Swift Starter", cz: "Svi\u017En\xFD start\xE9r" },
|
|
302
|
+
{ en: "Bold Builder", cz: "Bystr\xFD budovatel" },
|
|
303
|
+
{ en: "Word Wrangler", cz: "Slovn\xED sb\u011Bratel" },
|
|
304
|
+
{ en: "Fluent Flame", cz: "Plynul\xFD plamen" },
|
|
305
|
+
{ en: "Mighty Master", cz: "Mocn\xFD mistr" },
|
|
306
|
+
{ en: "Radiant Rockstar", cz: "Z\xE1\u0159iv\xFD znalec" },
|
|
307
|
+
{ en: "Wise Wizard", cz: "Moudr\xFD m\xE1g" },
|
|
308
|
+
{ en: "Legendary Linguist", cz: "Legend\xE1rn\xED lingvista" },
|
|
309
|
+
{ en: "Absolute Alpha", cz: "Absolutn\xED alfa" }
|
|
310
|
+
];
|
|
311
|
+
var PRESETS = [
|
|
312
|
+
"coolCatalyst" /* COOL_CATALYST */,
|
|
313
|
+
"swiftStarter" /* SWIFT_STARTER */,
|
|
314
|
+
"boldBuilder" /* BOLD_BUILDER */,
|
|
315
|
+
"wordWrangler" /* WORD_WRANGLER */,
|
|
316
|
+
"fluentFlame" /* FLUENT_FLAME */,
|
|
317
|
+
"mightyMaster" /* MIGHTY_MASTER */,
|
|
318
|
+
"radiantRockstar" /* RADIANT_ROCKSTAR */,
|
|
319
|
+
"wiseWizard" /* WISE_WIZARD */,
|
|
320
|
+
"legendaryLinguist" /* LEGENDARY_LINGUIST */,
|
|
321
|
+
"absoluteAlpha" /* ABSOLUTE_ALPHA */
|
|
322
|
+
];
|
|
323
|
+
var generatePalette = (hue) => {
|
|
324
|
+
const shift = hue - BASE_HUE;
|
|
325
|
+
const rotate = (hex) => shiftHue(hex, shift);
|
|
326
|
+
const lightnessFix = hue >= 40 && hue <= 70 ? -0.08 : 0;
|
|
327
|
+
const accent = (s, l) => hslToHex({ h: hue, s, l: l + lightnessFix });
|
|
328
|
+
const isOriginal = shift === 0;
|
|
329
|
+
return {
|
|
330
|
+
background: rotate(DESIGN.background),
|
|
331
|
+
card: rotate(DESIGN.card),
|
|
332
|
+
brand: rotate(DESIGN.brand),
|
|
333
|
+
brandMid: rotate(DESIGN.brandMid),
|
|
334
|
+
brandLight: rotate(DESIGN.brandLight),
|
|
335
|
+
brandPale: rotate(DESIGN.brandPale),
|
|
336
|
+
points: rotate(DESIGN.points),
|
|
337
|
+
streak: rotate(DESIGN.streak),
|
|
338
|
+
test: rotate(DESIGN.test),
|
|
339
|
+
testDark: rotate(DESIGN.testDark),
|
|
340
|
+
testText: rotate(DESIGN.testText),
|
|
341
|
+
// level 1 keeps the original design's exact accent orange and progress track
|
|
342
|
+
accent: isOriginal ? "#e37639" : accent(0.75, 0.5),
|
|
343
|
+
accentDark: accent(0.7, 0.33),
|
|
344
|
+
accentLight: accent(0.9, 0.72),
|
|
345
|
+
accentPale: isOriginal ? "#f2e1d4" : accent(0.85, 0.93),
|
|
346
|
+
chartRetired: accent(0.7, 0.33),
|
|
347
|
+
chartLearning: isOriginal ? "#e37639" : accent(0.75, 0.5),
|
|
348
|
+
chartQueued: accent(0.9, 0.72),
|
|
349
|
+
leaderboardHighlight: rotate(DESIGN.leaderboardHighlight),
|
|
350
|
+
divider: rotate(DESIGN.divider),
|
|
351
|
+
heatScale: DESIGN.heatScale.map(rotate),
|
|
352
|
+
celebrationGradient: [accent(0.9, 0.96), accent(0.85, 0.84), accent(0.8, 0.68)],
|
|
353
|
+
iconHueShift: shift
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
var DEFAULT_LEVEL_DEFINITIONS = LEVELS.map((rules, i) => ({
|
|
357
|
+
level: rules.level,
|
|
358
|
+
xpThreshold: rules.xpThreshold,
|
|
359
|
+
minBestStreak: rules.minBestStreak,
|
|
360
|
+
names: NAMES[i],
|
|
361
|
+
palette: generatePalette(LEVEL_HUES[i]),
|
|
362
|
+
avatar: {
|
|
363
|
+
alphaHueShift: LEVEL_HUES[i] - BASE_HUE,
|
|
364
|
+
preset: { id: PRESETS[i], params: { speed: 1 } }
|
|
365
|
+
}
|
|
366
|
+
}));
|
|
367
|
+
var DEFAULT_LEVELS_CONFIG = {
|
|
368
|
+
version: 0,
|
|
369
|
+
levels: DEFAULT_LEVEL_DEFINITIONS,
|
|
370
|
+
awards: DEFAULT_XP_AWARDS
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// src/concrete/levelValidation.ts
|
|
374
|
+
var MAX_LOTTIE_BYTES = 512 * 1024;
|
|
375
|
+
var MAX_SVG_BYTES = 128 * 1024;
|
|
376
|
+
var MAX_LEVEL_NAME_LENGTH = 40;
|
|
377
|
+
var PALETTE_COLOUR_KEYS = [
|
|
378
|
+
"background",
|
|
379
|
+
"card",
|
|
380
|
+
"brand",
|
|
381
|
+
"brandMid",
|
|
382
|
+
"brandLight",
|
|
383
|
+
"brandPale",
|
|
384
|
+
"points",
|
|
385
|
+
"streak",
|
|
386
|
+
"test",
|
|
387
|
+
"testDark",
|
|
388
|
+
"testText",
|
|
389
|
+
"accent",
|
|
390
|
+
"accentDark",
|
|
391
|
+
"accentLight",
|
|
392
|
+
"accentPale",
|
|
393
|
+
"chartRetired",
|
|
394
|
+
"chartLearning",
|
|
395
|
+
"chartQueued",
|
|
396
|
+
"leaderboardHighlight",
|
|
397
|
+
"divider"
|
|
398
|
+
];
|
|
399
|
+
var isNonNegativeInt = (value) => Number.isInteger(value) && value >= 0;
|
|
400
|
+
var validateLevelDefinition = (level) => {
|
|
401
|
+
var _a, _b;
|
|
402
|
+
const errors = [];
|
|
403
|
+
const where = `level ${level == null ? void 0 : level.level}`;
|
|
404
|
+
if (!Number.isInteger(level == null ? void 0 : level.level) || level.level < 1) errors.push(`${where}: level must be a whole number from 1`);
|
|
405
|
+
if (!isNonNegativeInt(level == null ? void 0 : level.xpThreshold)) errors.push(`${where}: XP threshold must be a whole number from 0`);
|
|
406
|
+
if (!isNonNegativeInt(level == null ? void 0 : level.minBestStreak)) errors.push(`${where}: best streak must be a whole number from 0`);
|
|
407
|
+
for (const lang of ["en", "cz"]) {
|
|
408
|
+
const name = (_a = level == null ? void 0 : level.names) == null ? void 0 : _a[lang];
|
|
409
|
+
if (typeof name !== "string" || !name.trim() || name.length > MAX_LEVEL_NAME_LENGTH) {
|
|
410
|
+
errors.push(`${where}: ${lang} name must be 1-${MAX_LEVEL_NAME_LENGTH} characters`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const palette = level == null ? void 0 : level.palette;
|
|
414
|
+
if (!palette) {
|
|
415
|
+
errors.push(`${where}: palette missing`);
|
|
416
|
+
} else {
|
|
417
|
+
for (const key of PALETTE_COLOUR_KEYS) {
|
|
418
|
+
if (!isHexColor(palette[key])) errors.push(`${where}: palette ${key} must be a hex colour`);
|
|
419
|
+
}
|
|
420
|
+
if (!Array.isArray(palette.heatScale) || palette.heatScale.length !== 6 || !palette.heatScale.every(isHexColor)) {
|
|
421
|
+
errors.push(`${where}: palette heatScale must be 6 hex colours`);
|
|
422
|
+
}
|
|
423
|
+
if (!Array.isArray(palette.celebrationGradient) || palette.celebrationGradient.length !== 3 || !palette.celebrationGradient.every(isHexColor)) {
|
|
424
|
+
errors.push(`${where}: palette celebrationGradient must be 3 hex colours`);
|
|
425
|
+
}
|
|
426
|
+
if (typeof palette.iconHueShift !== "number" || !isFinite(palette.iconHueShift)) {
|
|
427
|
+
errors.push(`${where}: palette iconHueShift must be a number`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const avatar = level == null ? void 0 : level.avatar;
|
|
431
|
+
if (!avatar || typeof avatar.alphaHueShift !== "number" || !isFinite(avatar.alphaHueShift)) {
|
|
432
|
+
errors.push(`${where}: avatar alphaHueShift must be a number`);
|
|
433
|
+
} else {
|
|
434
|
+
if (avatar.preset && !Object.values(AvatarPresetId).includes(avatar.preset.id)) {
|
|
435
|
+
errors.push(`${where}: unknown avatar preset '${avatar.preset.id}'`);
|
|
436
|
+
}
|
|
437
|
+
if (avatar.lottie !== void 0) {
|
|
438
|
+
if (typeof avatar.lottie !== "string" || avatar.lottie.length > MAX_LOTTIE_BYTES) {
|
|
439
|
+
errors.push(`${where}: Lottie animation must be at most ${MAX_LOTTIE_BYTES / 1024}KB`);
|
|
440
|
+
} else {
|
|
441
|
+
try {
|
|
442
|
+
JSON.parse(avatar.lottie);
|
|
443
|
+
} catch (e) {
|
|
444
|
+
errors.push(`${where}: Lottie animation is not valid JSON`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
for (const image of (_b = avatar.images) != null ? _b : []) {
|
|
449
|
+
if (typeof (image == null ? void 0 : image.svg) !== "string" || !image.svg.includes("<svg") || image.svg.length > MAX_SVG_BYTES) {
|
|
450
|
+
errors.push(`${where}: image '${image == null ? void 0 : image.id}' must be SVG markup of at most ${MAX_SVG_BYTES / 1024}KB`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return errors;
|
|
455
|
+
};
|
|
456
|
+
var validateXpAwards = (awards) => ["flashcardReview", "test", "perTestKnownAnswer", "perWordRetired", "dailyStreakBonusCap"].filter((key) => !isNonNegativeInt(awards == null ? void 0 : awards[key])).map((key) => `XP award ${key} must be a whole number from 0`);
|
|
457
|
+
var validateLevelsConfig = (config) => {
|
|
458
|
+
var _a;
|
|
459
|
+
const errors = validateXpAwards(config.awards);
|
|
460
|
+
const levels = [...(_a = config.levels) != null ? _a : []].sort((a, b) => a.level - b.level);
|
|
461
|
+
if (levels.length === 0) return [...errors, "there must be at least one level"];
|
|
462
|
+
levels.forEach((level, i) => {
|
|
463
|
+
errors.push(...validateLevelDefinition(level));
|
|
464
|
+
if (level.level !== i + 1) errors.push(`levels must be numbered 1 to ${levels.length} with no gaps`);
|
|
465
|
+
if (i === 0 && level.xpThreshold !== 0) errors.push("level 1 must need 0 XP");
|
|
466
|
+
if (i > 0 && level.xpThreshold <= levels[i - 1].xpThreshold) {
|
|
467
|
+
errors.push(`level ${level.level} must need more XP than level ${levels[i - 1].level}`);
|
|
468
|
+
}
|
|
469
|
+
if (i > 0 && level.minBestStreak < levels[i - 1].minBestStreak) {
|
|
470
|
+
errors.push(`level ${level.level} can't need a shorter best streak than level ${levels[i - 1].level}`);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
return [...new Set(errors)];
|
|
187
474
|
};
|
|
188
475
|
|
|
189
476
|
// src/design/types.ts
|
|
@@ -382,6 +669,7 @@ var ApiPath = /* @__PURE__ */ ((ApiPath2) => {
|
|
|
382
669
|
ApiPath2["HEALTH"] = "/health";
|
|
383
670
|
ApiPath2["LAST_WORDS_ADDED"] = "/lastWordsAdded";
|
|
384
671
|
ApiPath2["LEADERBOARD"] = "/leaderboard";
|
|
672
|
+
ApiPath2["LEVELS"] = "/levels";
|
|
385
673
|
ApiPath2["LEXEMES"] = "/lexemes";
|
|
386
674
|
ApiPath2["LEXEMES_ALL"] = "/lexemes/all";
|
|
387
675
|
ApiPath2["LEXEMES_COUNT"] = "/lexemes/count/:language";
|
|
@@ -420,7 +708,11 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
420
708
|
ApiMethod,
|
|
421
709
|
ApiPath,
|
|
422
710
|
AppError,
|
|
711
|
+
AvatarPresetId,
|
|
423
712
|
ClientPlatform,
|
|
713
|
+
DEFAULT_LEVELS_CONFIG,
|
|
714
|
+
DEFAULT_LEVEL_DEFINITIONS,
|
|
715
|
+
DEFAULT_XP_AWARDS,
|
|
424
716
|
Familiarity,
|
|
425
717
|
HttpStatusCode,
|
|
426
718
|
LEARNING_STAGES_IN_GROUP,
|
|
@@ -430,6 +722,9 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
430
722
|
LearningStageGroup,
|
|
431
723
|
Lexeme,
|
|
432
724
|
LexemePair,
|
|
725
|
+
MAX_LEVEL_NAME_LENGTH,
|
|
726
|
+
MAX_LOTTIE_BYTES,
|
|
727
|
+
MAX_SVG_BYTES,
|
|
433
728
|
Progress,
|
|
434
729
|
ReminderFrequency,
|
|
435
730
|
Scenario,
|
|
@@ -442,6 +737,7 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
442
737
|
convertJSDateStringToMySQLDate,
|
|
443
738
|
dateDifferenceInDays,
|
|
444
739
|
deriveStreakFromVocabCheckActivity,
|
|
740
|
+
generatePalette,
|
|
445
741
|
getBestStreak,
|
|
446
742
|
getFlashcardReviewXp,
|
|
447
743
|
getFormattedDate,
|
|
@@ -450,9 +746,12 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
450
746
|
getMysqlDateIgnoreTZ,
|
|
451
747
|
getTestXp,
|
|
452
748
|
getUserLevelProgress,
|
|
749
|
+
hexToHsl,
|
|
750
|
+
hslToHex,
|
|
453
751
|
isClientDateTooFarFromServerDate,
|
|
454
752
|
isExpired,
|
|
455
753
|
isFinalTest,
|
|
754
|
+
isHexColor,
|
|
456
755
|
isLearningStageGroup,
|
|
457
756
|
isStringContainingInteger,
|
|
458
757
|
isThePreviousDay,
|
|
@@ -460,5 +759,9 @@ var ClientPlatform = /* @__PURE__ */ ((ClientPlatform2) => {
|
|
|
460
759
|
isValidJsDateString,
|
|
461
760
|
isValidMysqlDateString,
|
|
462
761
|
maxLevel,
|
|
463
|
-
parameterReplace
|
|
762
|
+
parameterReplace,
|
|
763
|
+
shiftHue,
|
|
764
|
+
validateLevelDefinition,
|
|
765
|
+
validateLevelsConfig,
|
|
766
|
+
validateXpAwards
|
|
464
767
|
});
|