1. Bugs fixed:
- Backup schema now accepts theme: "aero" so backups exported under
Frutiger Aero pass parseBackup on import, and applyImport in "replace"
mode replaces SRS schedules, answer history, and chats instead of
merging into existing SRS or skipping empty arrays.
- Typed FillBlank cards bind the input value to chosen ?? value instead
of chosen ?? "", and normalise() preserves Unicode letters (\p{L}\p{N})
when grading non-ASCII answers.
- OpenAI-compatible vision calls (contentFor in lib/openai-compat.ts)
prefix data:image/jpeg;base64, when routes pass stripped base64.
- Streaming calls (ollamaChatStream, providerChatStream) keep their
AbortController active across the entire body stream and API routes
forward request.signal so stopping a chat or cancelling a run aborts
the upstream request immediately.
- HomeworkCard uses homeworkModeLabelKey so "check" records display the
Checked label instead of Step-by-step guide.
- Desktop dropzones on /create and /homework accept dropped documents as
well as images.
- LibraryScreen filters reported questions out of its due and mistake
counts to match ReviewClient.
- Clearing a provider key resets generation if it pointed at that
provider; chat conversations persist and restore provider; ModelPicker
keys items by provider:name.
- RouteTransition no longer mutates module-level lastPath during render.
- Service worker asset handler falls back to Response.error() when an
uncached asset fetch fails offline.
- Confetti and .ice-orb / .ice-bubble respect the in-app reduce-motion
toggle.
2. Performance & cleanup:
- Deduplicate window storage listeners across all six localStorage
stores (one listener while subscribed instead of N^2 notifications).
- Use todayAnswerCount in LibraryScreen and pass sorted folders to
DeckCard.
- Memoize MessageRow with stable callbacks in ChatScreen and compute
last message IDs in a single pass.
- Close ImageBitmap after drawing in lib/image.ts and destroy pdf.js
documents in finally in lib/documents.ts.
- Avoid re-parsing serialized sync payloads in POST /api/sync.
- Deduplicate copyText (lib/share.ts -> lib/clipboard.ts), chatMessageId,
describeExtraction, ALL_FOLDERS, useIsPhone, and remove unused helpers
and boilerplate public/*.svg files.
Version 0.5.8, SW -> freezmo-v80.
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
export function cn(...parts: Array<string | false | null | undefined>): string {
|
|
return parts.filter(Boolean).join(" ");
|
|
}
|
|
|
|
export function uid(prefix = "id"): string {
|
|
const rand =
|
|
typeof crypto !== "undefined" && "randomUUID" in crypto
|
|
? crypto.randomUUID().slice(0, 8)
|
|
: Math.random().toString(36).slice(2, 10);
|
|
return `${prefix}_${Date.now().toString(36)}_${rand}`;
|
|
}
|
|
|
|
/** Deterministic-ish shuffle (Fisher-Yates). Returns a new array. */
|
|
export function shuffle<T>(input: readonly T[]): T[] {
|
|
const out = [...input];
|
|
for (let i = out.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[out[i], out[j]] = [out[j], out[i]];
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function formatDate(timestamp: number): string {
|
|
try {
|
|
return new Intl.DateTimeFormat(undefined, {
|
|
day: "numeric",
|
|
month: "short",
|
|
year: "numeric",
|
|
}).format(new Date(timestamp));
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/** Remove ```json fences and stray prose around a JSON object. */
|
|
export function stripFences(text: string): string {
|
|
let value = text.trim();
|
|
const fence = value.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
if (fence) value = fence[1].trim();
|
|
if ((value.startsWith("{") && value.endsWith("}")) || (value.startsWith("[") && value.endsWith("]"))) {
|
|
return value;
|
|
}
|
|
const start = value.indexOf("{");
|
|
const end = value.lastIndexOf("}");
|
|
if (start !== -1 && end > start) return value.slice(start, end + 1);
|
|
return value;
|
|
}
|
|
|
|
export function parseJsonLoose(text: string): unknown {
|
|
const cleaned = stripFences(text);
|
|
try {
|
|
return JSON.parse(cleaned);
|
|
} catch {
|
|
// Last resort: tolerate trailing commas from chatty models.
|
|
return JSON.parse(cleaned.replace(/,\s*([}\]])/g, "$1"));
|
|
}
|
|
}
|
|
|
|
export function truncate(value: string, max: number): string {
|
|
return value.length > max ? `${value.slice(0, max - 1)}…` : value;
|
|
}
|
|
|
|
/**
|
|
* A friendlier label for a model name: "gemma4:31b-cloud" → "Gemma 4 31B",
|
|
* "gpt-oss:120b" → "GPT OSS 120B". Chips show this; the raw name lives in a
|
|
* tooltip (and the picker keeps the technical names).
|
|
*/
|
|
export function prettyModelName(name: string): string {
|
|
const base = name.replace(/:cloud$/i, "").replace(/-cloud$/i, "");
|
|
const [family, ...tagParts] = base.split(":");
|
|
const words = family
|
|
.replace(/[-_.]+/g, " ")
|
|
.replace(/([a-z])(\d)/gi, "$1 $2")
|
|
.trim()
|
|
.split(/\s+/)
|
|
.filter(Boolean);
|
|
const prettyFamily = words
|
|
.map((word) =>
|
|
/^[a-z]{1,3}$/i.test(word) && word === word.toLowerCase()
|
|
? word.toUpperCase()
|
|
: word.charAt(0).toUpperCase() + word.slice(1),
|
|
)
|
|
.join(" ");
|
|
const tag = tagParts
|
|
.join(" ")
|
|
.replace(/^(\d+)([a-z])$/i, (_match, size: string, unit: string) => `${size}${unit.toUpperCase()}`);
|
|
return [prettyFamily, tag].filter(Boolean).join(" ");
|
|
}
|