forked from Tadrisino/MathApp_frontend
lighter first load, math reads left-to-right in quizzes, tickets from the server, readable separators
- Every screen but home is its own chunk and preloads when the browser is
idle; React and motion get their own long-cached chunks. The app entry
goes from 505 kB (160 kB gzip) to 85 kB (27 kB gzip).
- Quiz prompts, options and lesson examples go through MathText, so
'10 + 3 - 7 - 2' reads from the left; an unpaired bracket at the edge of
a math run stays with the Persian sentence.
- Support lists tickets from GET /support/tickets instead of this
browser's localStorage; a ticket's messages load when it is opened.
- '·' next to a Persian zero read as another digit ('فصلِ ۱ · ۰' looked
like ۱۰۰); a thin bar separates them now. Notification bodies show
Persian digits.
- A root or vertex the model already marked with coordinates is no longer
labelled a second time on top of it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -32,12 +32,36 @@ export function MathText({ text }: { text: string }) {
|
||||
run = run.slice(lead.length);
|
||||
const tail = EDGE_END.exec(run)?.[0] ?? '';
|
||||
run = run.slice(0, run.length - tail.length);
|
||||
// «(۱، −۴)» باید کامل قفل شود، ولی پرانتزِ بازِ بیجفت در سرِ تکه مالِ جمله است.
|
||||
// «(۱، −۴)» باید کامل قفل شود، ولی پرانتزِ بیجفت در لبهی تکه مالِ جمله است:
|
||||
// در «۱۰ − ۲ (با محاسبه…)» پرانتزِ باز جزوِ جملهی فارسیِ بعدی است و اگر قفل شود
|
||||
// به سمتِ غلط میرود.
|
||||
const edge = trimUnpaired(run);
|
||||
const head = lead + edge.head;
|
||||
run = edge.run;
|
||||
if (!run || !/[0-9۰-۹]/.test(run)) continue;
|
||||
out.push(text.slice(last, start + lead.length));
|
||||
out.push(text.slice(last, start + head.length));
|
||||
out.push(<span key={i++} style={LTR}>{run}</span>);
|
||||
last = start + lead.length + run.length;
|
||||
last = start + head.length + run.length;
|
||||
}
|
||||
out.push(text.slice(last));
|
||||
return <>{out.map((n, j) => (typeof n === 'string' ? <Fragment key={`t${j}`}>{n}</Fragment> : n))}</>;
|
||||
}
|
||||
|
||||
const count = (s: string, ch: string) => s.split(ch).length - 1;
|
||||
|
||||
/**
|
||||
* پرانتزِ بازِ بیجفت در تهِ تکه و بستهی بیجفت در سرش را (با فاصلهی کنارش) کنار
|
||||
* میگذارد؛ `head` یعنی چه مقدار از سرِ تکه به جملهی فارسی برگشت.
|
||||
*/
|
||||
function trimUnpaired(run: string): { head: string; run: string } {
|
||||
let head = '';
|
||||
while (/[(\[]\s*$/.test(run) && count(run, '(') + count(run, '[') > count(run, ')') + count(run, ']')) {
|
||||
run = run.slice(0, run.length - /\s*[(\[]\s*$/.exec(run)![0].length);
|
||||
}
|
||||
while (/^\s*[)\]]/.test(run) && count(run, ')') + count(run, ']') > count(run, '(') + count(run, '[')) {
|
||||
const m = /^\s*[)\]]\s*/.exec(run)![0];
|
||||
head += m;
|
||||
run = run.slice(m.length);
|
||||
}
|
||||
return { head, run };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user