analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
78 lines (72 loc) • 3.73 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/Quiz/Quiz.utils.ts
var formatExamInfo = (examBoard, examYear) => {
if (examBoard && examYear) {
return `(${examBoard} - ${examYear})`;
}
if (examBoard) {
return `(${examBoard})`;
}
if (examYear) {
return `(${examYear})`;
}
return "";
};
var shuffleWithSeed = (array, seed) => {
const shuffled = [...array];
let hash = 0;
for (let i = 0; i < seed.length; i++) {
const char = _nullishCoalesce(seed.codePointAt(i), () => ( 0));
hash = (hash << 5) - hash + char;
hash = hash & hash;
}
const seededRandom = (max) => {
hash = hash * 1103515245 + 12345 & 2147483647;
return hash % max;
};
for (let i = shuffled.length - 1; i > 0; i--) {
const j = seededRandom(i + 1);
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
};
var prependLetterToHtml = (letter, html) => {
if (html.trim().startsWith("<p>")) {
return html.replace(/^(\s*<p>)/, `$1${letter}) `);
}
return `${letter}) ${html}`;
};
var getTrueOrFalseOptionState = (optionId, variant, currentQuestionResult, localAnswers) => {
const correctAnswerOption = _optionalChain([currentQuestionResult, 'optionalAccess', _ => _.options, 'optionalAccess', _2 => _2.find, 'call', _3 => _3(
(op) => op.id === optionId
)]);
const isStatementTrue = variant === "result" /* RESULT */ ? _nullishCoalesce(_optionalChain([correctAnswerOption, 'optionalAccess', _4 => _4.isCorrect]), () => ( false)) : false;
const studentSelection = variant === "result" /* RESULT */ ? _optionalChain([currentQuestionResult, 'optionalAccess', _5 => _5.selectedOptions, 'optionalAccess', _6 => _6.find, 'call', _7 => _7(
(op) => op.optionId === optionId
)]) : void 0;
const hasAnswered = variant === "result" /* RESULT */ ? studentSelection !== void 0 : !!localAnswers[optionId];
const studentMarkedTrue = variant === "result" /* RESULT */ ? _nullishCoalesce(_optionalChain([studentSelection, 'optionalAccess', _8 => _8.isCorrect]), () => ( false)) : localAnswers[optionId] === "V" /* VERDADEIRO */;
const getStudentAnswerDisplay = () => {
if (variant !== "result" /* RESULT */) {
return localAnswers[optionId] || "-";
}
if (!hasAnswered) {
return "-";
}
return studentMarkedTrue ? "V" /* VERDADEIRO */ : "F" /* FALSO */;
};
const studentAnswer = getStudentAnswerDisplay();
const correctAnswer = isStatementTrue ? "V" /* VERDADEIRO */ : "F" /* FALSO */;
const isStudentCorrect = hasAnswered && studentMarkedTrue === isStatementTrue;
const variantCorrect = isStudentCorrect ? "correct" /* CORRECT */ : "incorrect" /* INCORRECT */;
return {
isStatementTrue,
hasAnswered,
studentMarkedTrue,
studentAnswer,
correctAnswer,
isStudentCorrect,
variantCorrect
};
};
exports.formatExamInfo = formatExamInfo; exports.shuffleWithSeed = shuffleWithSeed; exports.prependLetterToHtml = prependLetterToHtml; exports.getTrueOrFalseOptionState = getTrueOrFalseOptionState;
//# sourceMappingURL=chunk-GYQUB3VW.js.map