Vorlesen und Leichte Sprache mit KI-Vorschlag (0.34.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m24s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m15s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m10s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m8s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 13:24:56 +00:00
parent fc2505297b
commit 856a5c30af
210 changed files with 1447 additions and 521 deletions

View file

@ -0,0 +1,116 @@
<script setup>
import { ref, watch } from 'vue';
import { router } from '@inertiajs/vue3';
import { BookOpenText, LoaderCircle, PencilLine, Sparkles, TriangleAlert } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle } from '@/components/ui/sheet';
import RichTextEditor from '@/components/RichTextEditor.vue';
import ReadAloud from '@/components/ReadAloud.vue';
import { http } from '@/lib/http';
/**
* Leiste über einem Inhalt: Vorlesen, Umschalten auf Leichte Sprache und – für die
* Redaktion – Bearbeiten der Leichten Sprache mit optionalem KI-Vorschlag.
*/
const props = defineProps({
/** { type, id, html, can_edit, ai } oder null */
easy: { type: Object, default: null },
/** Element, dessen Text vorgelesen wird */
readSource: { type: [Object, Function], default: null },
});
const showEasy = defineModel({ type: Boolean, default: false });
const reader = ref(null);
watch(showEasy, () => reader.value?.stop());
// Bearbeiten
const editing = ref(false);
const draft = ref('');
const aiAssisted = ref(false);
const suggesting = ref(false);
const saving = ref(false);
function openEditor() {
draft.value = props.easy?.html ?? '';
aiAssisted.value = false;
editing.value = true;
}
async function suggest() {
if (draft.value.trim() && !window.confirm('Den bisherigen Text durch einen neuen Vorschlag ersetzen?')) return;
suggesting.value = true;
try {
const { html } = await http.post(`/leichte-sprache/${props.easy.type}/${props.easy.id}/vorschlag`);
draft.value = html;
aiAssisted.value = true;
toast.success('Vorschlag erstellt – bitte prüfen und anpassen.');
} catch (error) {
toast.error(error.message);
} finally {
suggesting.value = false;
}
}
function save(html = draft.value) {
saving.value = true;
router.put(`/leichte-sprache/${props.easy.type}/${props.easy.id}`, { html, ai_assisted: aiAssisted.value }, {
preserveScroll: true,
onSuccess: () => {
editing.value = false;
showEasy.value = !!html;
},
onFinish: () => (saving.value = false),
});
}
function remove() {
if (window.confirm('Leichte Sprache für diesen Inhalt entfernen?')) save('');
}
</script>
<template>
<div class="flex flex-wrap items-center gap-2">
<ReadAloud ref="reader" :source="readSource" />
<div v-if="easy?.html" class="inline-flex rounded-md border bg-muted/50 p-0.5" role="group" aria-label="Sprachfassung">
<button type="button" class="rounded px-2.5 py-1 text-[13px] font-medium" :class="!showEasy ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'" :aria-pressed="!showEasy" @click="showEasy = false">Standard</button>
<button type="button" class="inline-flex items-center gap-1.5 rounded px-2.5 py-1 text-[13px] font-medium" :class="showEasy ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'" :aria-pressed="showEasy" @click="showEasy = true">
<BookOpenText class="size-3.5" /> Leichte Sprache
</button>
</div>
<Button v-if="easy?.can_edit" type="button" variant="ghost" size="sm" class="text-muted-foreground" @click="openEditor">
<PencilLine /> {{ easy.html ? 'Leichte Sprache bearbeiten' : 'Leichte Sprache ergänzen' }}
</Button>
<Sheet v-if="easy?.can_edit" v-model:open="editing">
<SheetContent class="flex w-full flex-col gap-0 sm:max-w-2xl">
<SheetHeader>
<SheetTitle>Leichte Sprache</SheetTitle>
<SheetDescription>Eine zweite, leicht verständliche Fassung. Lesende schalten oben am Inhalt zwischen „Standard“ und „Leichte Sprache“ um.</SheetDescription>
</SheetHeader>
<div class="grid flex-1 content-start gap-4 overflow-y-auto px-4 pb-4">
<div v-if="easy.ai" class="grid gap-2 rounded-md border bg-muted/40 p-3">
<Button type="button" variant="outline" size="sm" class="justify-self-start" :disabled="suggesting" @click="suggest">
<LoaderCircle v-if="suggesting" class="animate-spin" /><Sparkles v-else /> {{ suggesting ? 'Vorschlag wird erstellt …' : 'KI-Vorschlag erstellen' }}
</Button>
<p class="flex items-start gap-1.5 text-xs text-muted-foreground">
<TriangleAlert class="mt-0.5 size-3.5 shrink-0" />
Dafür wird der Text an den KI-Dienst übertragen, den die Administration eingerichtet hat. Nur Inhalte ohne Zielgruppen-Einschränkung. Den Vorschlag bitte immer prüfen.
</p>
</div>
<RichTextEditor v-model="draft" bordered min-height="20rem" :headings="[2]" placeholder="Kurze Sätze. Ein Gedanke pro Satz. Einfache Wörter." />
<p class="text-xs text-muted-foreground">Leichte Sprache sehen alle, die den Inhalt sehen dürfen. Nur Allgemeines aufnehmen, nichts aus Abschnitten für bestimmte Zielgruppen.</p>
</div>
<SheetFooter class="flex-row justify-between border-t">
<Button v-if="easy.html" type="button" variant="ghost" class="text-destructive hover:text-destructive" :disabled="saving" @click="remove">Entfernen</Button>
<span v-else />
<Button type="button" :disabled="saving || suggesting" @click="save()"><LoaderCircle v-if="saving" class="animate-spin" /> Speichern</Button>
</SheetFooter>
</SheetContent>
</Sheet>
</div>
</template>

View file

@ -0,0 +1,111 @@
<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { Pause, Play, Square, Volume2 } from '@lucide/vue';
import { Button } from '@/components/ui/button';
/**
* „Vorlesen“ mit der Sprachausgabe des Browsers bzw. Geräts – ohne Übertragung an Dritte.
* Liest den Text des übergebenen Elements (oder eine Funktion, die Text liefert).
*/
const props = defineProps({
/** Element oder () => string */
source: { type: [Object, Function], default: null },
label: { type: String, default: 'Vorlesen' },
});
const supported = ref(false);
const state = ref('idle'); // idle | playing | paused
let queue = [];
onMounted(() => {
supported.value = typeof window !== 'undefined' && 'speechSynthesis' in window && 'SpeechSynthesisUtterance' in window;
});
onBeforeUnmount(() => stop());
function text() {
const source = typeof props.source === 'function' ? props.source() : props.source;
if (typeof source === 'string') return source;
if (!source) return '';
// Nur sichtbarer Text, Absätze als Pausen
return (source.$el ?? source).innerText ?? '';
}
function voice() {
const voices = window.speechSynthesis.getVoices();
return voices.find((v) => v.lang === 'de-DE' && v.localService) ?? voices.find((v) => v.lang?.startsWith('de')) ?? null;
}
// Manche Browser brechen lange Texte ab – daher in Sätze bzw. kurze Abschnitte teilen
function chunks(value) {
return value
.split(/\n+/)
.flatMap((paragraph) => paragraph.match(/[^.!?…:]+[.!?…:]*\s*/g) ?? [paragraph])
.map((part) => part.trim())
.filter(Boolean)
.reduce((list, part) => {
const last = list[list.length - 1];
last && last.length + part.length < 220 ? (list[list.length - 1] = `${last} ${part}`) : list.push(part);
return list;
}, []);
}
function speakNext() {
const next = queue.shift();
if (!next) {
state.value = 'idle';
return;
}
const utterance = new SpeechSynthesisUtterance(next);
utterance.lang = 'de-DE';
utterance.voice = voice();
utterance.rate = 0.95;
utterance.onend = () => state.value === 'playing' && speakNext();
utterance.onerror = () => (state.value = 'idle');
window.speechSynthesis.speak(utterance);
}
function play() {
if (state.value === 'paused') {
window.speechSynthesis.resume();
state.value = 'playing';
return;
}
window.speechSynthesis.cancel();
queue = chunks(text());
state.value = 'playing';
speakNext();
}
function pause() {
window.speechSynthesis.pause();
state.value = 'paused';
}
function stop() {
queue = [];
state.value = 'idle';
if (supported.value) window.speechSynthesis.cancel();
}
defineExpose({ stop });
</script>
<template>
<div v-if="supported" class="inline-flex items-center gap-1" role="group" aria-label="Vorlesen">
<Button v-if="state !== 'playing'" type="button" variant="outline" size="sm" @click="play">
<component :is="state === 'paused' ? Play : Volume2" /> {{ state === 'paused' ? 'Weiter' : label }}
</Button>
<Button v-else type="button" variant="outline" size="sm" @click="pause"><Pause /> Pause</Button>
<Button v-if="state !== 'idle'" type="button" variant="ghost" size="icon" class="size-8" aria-label="Vorlesen beenden" @click="stop"><Square class="size-3.5" /></Button>
</div>
</template>

View file

@ -21,6 +21,8 @@ export { default as PersonAvatar } from '@/components/PersonAvatar.vue';
export { default as AppIcon } from '@/components/AppIcon.vue';
export { default as FileIcon } from '@/components/FileIcon.vue';
export { default as RichTextEditor } from '@/components/RichTextEditor.vue';
export { default as ReadAloud } from '@/components/ReadAloud.vue';
export { default as EasyLanguageBar } from '@/components/EasyLanguageBar.vue';
export { default as TreeSelect } from '@/components/TreeSelect.vue';
export { default as PersonPicker } from '@/components/PersonPicker.vue';
export { default as AudienceEditor } from '@/components/AudienceEditor.vue';