Anki/ts/routes/image-occlusion/[...imagePathOrNoteId]/+page.ts
jariji 33d1057a46 Add "hide all but one" occlusion mode.
This PR adds the "hide all but one" occlusion mode. An example use case
is a note containing a collection of pairs of selection, where each
selection is the prompt for the other in its pair.

For example, given a table like

| small | big |
|-------+-----|
|   a   |  A  |
|   b   |  B  |
|   c   |  C  |

in each card, five letters are occluded, and one is shown. The user is
prompted to state the occluded symbol that is adjacent to the shown symbol.
2025-11-04 01:03:09 +00:00

33 lines
992 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { get } from "svelte/store";
import { addOrUpdateNote } from "../add-or-update-note.svelte";
import type { IOMode } from "../lib";
import { occlusionMode } from "../store";
import type { PageLoad } from "./$types";
async function save(): Promise<void> {
addOrUpdateNote(globalThis["anki"].imageOcclusion.mode, get(occlusionMode));
}
export const load = (async ({ params }) => {
let mode: IOMode;
if (/^\d+/.test(params.imagePathOrNoteId)) {
mode = { kind: "edit", noteId: Number(params.imagePathOrNoteId) };
} else {
mode = { kind: "add", imagePath: params.imagePathOrNoteId, notetypeId: 0 };
}
// for adding note from mobile devices
globalThis.anki = globalThis.anki || {};
globalThis.anki.imageOcclusion = {
mode,
save,
};
return {
mode,
};
}) satisfies PageLoad;