feat(bibliotheque): étape D, la page /bibliotheque (VueFiches en Mixte, GrapheConnaissances par un second adaptateur, axes thème, époque, auteur ; disposition radiale amorcée au cache du graphe), le module de build et la route de la fiche au clic ; /rag et le commutateur mènent à /bibliotheque, /media intact
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<!--
|
||||
CommutateurMode — B4a-M4. En tête de la carte unifiée : deux onglets, « Entraide » et
|
||||
« Pratiques inspirantes » (rôle tablist, aria-selected, 44 px, flèches ← → entre les deux),
|
||||
puis « Bibliothèque », un LIEN vers /media (le mode RAG de la taxonomie N est l'onglet XL
|
||||
existant). Il n'écrit pas l'URL : il émet `choisir`, la page s'en charge. Rien n'anime.
|
||||
puis « Bibliothèque », un LIEN vers /bibliotheque (lot B9 ; il menait à /media, qui reste à sa
|
||||
place). Il n'écrit pas l'URL : il émet `choisir`, la page s'en charge. Rien n'anime.
|
||||
-->
|
||||
<template>
|
||||
<div class="modes">
|
||||
@@ -23,7 +23,7 @@
|
||||
@keydown.left.prevent="voisin(i, -1)"
|
||||
>{{ m.court }}<span v-if="m.suite" class="modes__suite">{{ m.suite }}</span></button>
|
||||
</div>
|
||||
<NuxtLink to="/media" class="modes__lien">Bibliothèque</NuxtLink>
|
||||
<NuxtLink to="/bibliotheque" class="modes__lien">Bibliothèque</NuxtLink>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* bibliotheque — lot B9. Jumeau de modules/connaissances.ts pour la bibliothèque navigable : au build,
|
||||
* dans Node, il lit l'export du registre (data/bibliotheque/oeuvres-registre.json) et les socles
|
||||
* (content/bibliotheque/*.md), applique le réglage de service (utils/bibliotheque/service.ts), puis :
|
||||
*
|
||||
* - `#build/bibliotheque/arbre.mjs` : l'export, `fiche` gardée pour les seuls socles servis. C'est
|
||||
* tout ce que la page /bibliotheque reçoit : aucun texte de fiche ;
|
||||
* - `#bibliotheque-fiches` (module virtuel du serveur Nitro) : le HTML des socles SERVIS, et d'eux
|
||||
* seuls, lu par /api/bibliotheque/fiche/<slug> au clic. Un socle non servi n'entre pas dans le build.
|
||||
*
|
||||
* Un socle illisible, un socle dont l'œuvre n'est pas à l'export, une fiche de l'export sans socle :
|
||||
* le build échoue. Module local : Nuxt enregistre seul les fichiers de modules/.
|
||||
*/
|
||||
import { readdirSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { defineNuxtModule, addTemplate, useLogger } from '@nuxt/kit'
|
||||
import { lireSocle, rendreSocle, IGNORES } from '../utils/bibliotheque/socles'
|
||||
import { estServi, reglageEffectif, compterMotifs } from '../utils/bibliotheque/service'
|
||||
import { arbreServi, ligneAuteurs, type ExportRegistre } from '../utils/bibliotheque/arbre'
|
||||
|
||||
export const DOSSIER = 'content/bibliotheque'
|
||||
export const EXPORT = 'data/bibliotheque/oeuvres-registre.json'
|
||||
|
||||
export interface FicheServie {
|
||||
id: string; slug: string; titre: string; auteurs: string; annee: number | null; regime: string
|
||||
relecture_humaine: string | null; date_fiche: string; html: string; sommaire: { id: string; titre: string }[]
|
||||
}
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: { name: 'bibliotheque' },
|
||||
setup(_options, nuxt) {
|
||||
const log = useLogger('bibliotheque')
|
||||
const racine = nuxt.options.rootDir
|
||||
const ex = JSON.parse(readFileSync(join(racine, EXPORT), 'utf8')) as ExportRegistre
|
||||
const parId = new Map(ex.oeuvres.map((o) => [o.id, o]))
|
||||
const lus = readdirSync(join(racine, DOSSIER))
|
||||
.filter((nom) => nom.endsWith('.md') && !IGNORES.includes(nom))
|
||||
.sort()
|
||||
.map((nom) => lireSocle({ nom, contenu: readFileSync(join(racine, DOSSIER, nom), 'utf8') }))
|
||||
|
||||
const defauts: string[] = []
|
||||
for (const s of lus) {
|
||||
for (const e of s.erreurs) defauts.push(`${s.nom} : ${e}`)
|
||||
const o = parId.get(s.fm.id)
|
||||
if (!o) defauts.push(`${s.nom} : l'œuvre ${s.fm.id} n'est pas à l'export`)
|
||||
else if (o.fiche !== s.fm.slug) defauts.push(`${s.nom} : l'export nomme la fiche « ${o.fiche} »`)
|
||||
}
|
||||
for (const o of ex.oeuvres) if (o.fiche && !lus.some((s) => s.fm.slug === o.fiche)) defauts.push(`${o.id} : fiche « ${o.fiche} » sans socle`)
|
||||
if (defauts.length) throw new Error(`${DOSSIER} : ${defauts.length} défaut(s)\n${defauts.map((d) => ` · ${d}`).join('\n')}`)
|
||||
|
||||
const reglage = reglageEffectif(process.env.BIBLIOTHEQUE_SERVICE)
|
||||
const servis = lus.filter((s) => estServi(s, reglage))
|
||||
const arbre = arbreServi(ex, new Set(servis.map((s) => s.fm.slug)))
|
||||
const ids = new Set(ex.oeuvres.map((o) => o.id))
|
||||
const fiches: Record<string, FicheServie> = {}
|
||||
for (const s of servis) {
|
||||
const o = parId.get(s.fm.id)!
|
||||
const r = rendreSocle(s, ids)
|
||||
fiches[s.fm.slug] = {
|
||||
id: o.id, slug: s.fm.slug, titre: o.titre, auteurs: ligneAuteurs(ex, o), annee: o.annee, regime: s.fm.regime,
|
||||
relecture_humaine: s.fm.relecture_humaine ?? null, date_fiche: String(s.fm.date_fiche), html: r.html, sommaire: r.sommaire,
|
||||
}
|
||||
}
|
||||
const c = compterMotifs(lus)
|
||||
log.info(`${ex.oeuvres.length} œuvres ; ${lus.length} socles (${c.servis} conformes, ${c.rejetes} rejetés, ${c.gloses} à gloses, ${c.omises} à citations omises) ; réglage « ${reglage} » : ${servis.length} fiches servies`)
|
||||
|
||||
addTemplate({
|
||||
filename: 'bibliotheque/arbre.mjs',
|
||||
write: true,
|
||||
getContents: () => `// Généré par modules/bibliotheque.ts depuis ${EXPORT} : ne pas éditer.\nexport default ${JSON.stringify(arbre)}\n`,
|
||||
})
|
||||
addTemplate({
|
||||
filename: 'bibliotheque/arbre.d.mts',
|
||||
write: true,
|
||||
getContents: () => `import type { ExportRegistre } from '../../utils/bibliotheque/arbre'\ndeclare const arbre: ExportRegistre\nexport default arbre\n`,
|
||||
})
|
||||
nuxt.hook('nitro:config', (config) => {
|
||||
config.virtual = config.virtual || {}
|
||||
config.virtual['#bibliotheque-fiches'] = () => `export default ${JSON.stringify(fiches)}`
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,317 @@
|
||||
<!--
|
||||
/bibliotheque — lot B9. L'arborescence du registre des œuvres (la couche ancienne d'AEP), projetée
|
||||
par un axe (thème, époque, auteur), et la fiche de lecture des œuvres dont le socle est servi.
|
||||
CONCEPTION - bibliothèque navigable (19-10) §4 ; le brief B9 réécrit (18/11).
|
||||
|
||||
Les mêmes composants que /connaissances, sans y toucher : `VueFiches` en Mixte (le graphe, la liste,
|
||||
la fiche en panneau) et `GrapheConnaissances` nourri par un second adaptateur (utils/bibliotheque/
|
||||
arbre.ts). Le chemin dans l'arborescence est le filtre de l'axe, dans l'URL : ?axe=epoque&epoque=…,
|
||||
?fiche=oeu:… ; « Agrandir » est un état de la page (l'adresse ne change pas).
|
||||
|
||||
Données au build : `#build/bibliotheque/arbre.mjs` (l'export, aucune fiche) ; le HTML d'une fiche
|
||||
arrive au clic, par /api/bibliotheque/fiche/<slug>.
|
||||
-->
|
||||
<template>
|
||||
<main class="bib" :class="{ 'bib--agrandi': agrandiVu }">
|
||||
<header class="bib-tete">
|
||||
<h1 class="bib-tete__titre">Bibliothèque</h1>
|
||||
<p class="bib-bandeau">
|
||||
{{ phrase }}
|
||||
Navigation inspirée de
|
||||
<a href="https://holosapiens.earth" target="_blank" rel="noopener noreferrer">l’explorateur Holosapiens<span class="sr-only"> (nouvel onglet)</span></a>.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div class="bib-vue">
|
||||
<VueFiches
|
||||
:vf="vf"
|
||||
intention="Les livres que lit AEP, rangés par thème, par époque ou par auteur : ouvrez une catégorie, ses œuvres apparaissent."
|
||||
libelle-recherche="Rechercher une œuvre, un auteur…"
|
||||
:libelles-vue="{ carte: 'Graphe' }"
|
||||
:lien-page="lienPage"
|
||||
:navigation-lineaire="false"
|
||||
>
|
||||
<template #carte>
|
||||
<div class="bib-graphe">
|
||||
<GrapheConnaissances
|
||||
:noeuds="graphe.noeuds"
|
||||
:liens="graphe.liens"
|
||||
:selection="selection"
|
||||
:survol="vf.survolId != null ? String(vf.survolId) : null"
|
||||
:retenus="retenus"
|
||||
:kinds-principaux="KINDS_PRINCIPAUX"
|
||||
:libelle-kind="libelleKind"
|
||||
titre="Arborescence de la bibliothèque"
|
||||
@select="choisir"
|
||||
@survol="(id: string | null) => (vf.survolId = id)"
|
||||
/>
|
||||
<ul class="bib-legende" aria-label="Légende de l’arborescence">
|
||||
<li><span class="bib-legende__cat" aria-hidden="true" />{{ LIBELLE_AXE[axe] }}</li>
|
||||
<li><span class="bib-legende__fiche" aria-hidden="true" />Fiche de lecture</li>
|
||||
<li><span class="bib-legende__ref" aria-hidden="true" />Référence seulement</li>
|
||||
</ul>
|
||||
<p v-if="graphe.masquees" class="bib-masquees">
|
||||
{{ graphe.masquees }} {{ graphe.masquees > 1 ? 'autres œuvres' : 'autre œuvre' }} dans la liste seulement
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #detail="{ filtrer }">
|
||||
<article v-if="oeuvre" class="bo">
|
||||
<h2 class="bo__titre">{{ oeuvre.titre }}</h2>
|
||||
<p class="bo__meta">
|
||||
{{ ligneAuteurs(arbre, oeuvre) }} · {{ anneeTexte(oeuvre.annee) }}<template v-if="oeuvre.epoque"> · {{ nomEpoque.get(oeuvre.epoque) }}</template>
|
||||
</p>
|
||||
<ChipGroup v-if="oeuvre.courants.length" :aria-label="`Thèmes de ${oeuvre.titre}`" class="bo__themes">
|
||||
<Chip
|
||||
v-for="c in oeuvre.courants"
|
||||
:key="c"
|
||||
:label="nomCourant.get(c) ?? c"
|
||||
variant="fonction"
|
||||
:active="(vf.etat.filtres.theme ?? []).includes(c)"
|
||||
:aria-label="`Filtrer par thème : ${nomCourant.get(c)}`"
|
||||
@toggle="filtrer('theme', c)"
|
||||
/>
|
||||
</ChipGroup>
|
||||
|
||||
<template v-if="oeuvre.fiche">
|
||||
<p class="bo__statut">Fiche de lecture · {{ oeuvre.regime }}</p>
|
||||
<button
|
||||
v-if="vf.largeur === 'ordinateur' || vf.largeur === 'tablette'"
|
||||
type="button"
|
||||
class="bo__agrandir"
|
||||
:aria-pressed="agrandi ? 'true' : 'false'"
|
||||
@click="agrandi = !agrandi"
|
||||
>{{ agrandi ? 'Réduire' : 'Agrandir, avec le sommaire' }}</button>
|
||||
<p v-if="chargement === 'pending'" class="bo__etat">Chargement de la fiche…</p>
|
||||
<p v-else-if="!ficheLue" class="bo__etat">La fiche n’a pas pu être chargée.</p>
|
||||
<BibliothequeFicheLecture v-else :fiche="ficheLue" :sommaire="agrandiVu" sur-place @oeuvre="(id: string) => vf.ouvrirFiche(id)" />
|
||||
</template>
|
||||
<div v-else class="bo__reference">
|
||||
<p class="bo__statut">Référence seulement</p>
|
||||
<p v-if="oeuvre.regime">Cette œuvre est lue par notre analyse ; sa fiche n’est pas encore ouverte.</p>
|
||||
<p v-else>Cette œuvre est au registre de la bibliothèque, sans fiche de lecture : nous n’en avons rien de plus.</p>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</VueFiches>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import arbreBrut from '#build/bibliotheque/arbre.mjs'
|
||||
import type { ConfigVueFiches } from '~/utils/vueFiches'
|
||||
import type { MiniFiche } from '~/composables/useFicheAdapter'
|
||||
import { amorcer } from '~/utils/connaissances/graphe'
|
||||
import {
|
||||
AXES, KINDS_PRINCIPAUX, DIMENSION_AXE, LIBELLES_STATUT, categories, fichesBibliotheque, grapheAxe, disposerArbre,
|
||||
idCategorie, lireIdCategorie, ligneAuteurs, anneeTexte, type Axe, type ExportRegistre,
|
||||
} from '~/utils/bibliotheque/arbre'
|
||||
|
||||
const arbre = arbreBrut as unknown as ExportRegistre
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const parId = new Map(arbre.oeuvres.map((o) => [o.id, o]))
|
||||
const nomEpoque = new Map(arbre.epoques.map((e) => [e.id, e.nom]))
|
||||
const nomCourant = new Map(arbre.courants.map((c) => [c.id, c.contre_point ? `${c.nom} (contre-point)` : c.nom]))
|
||||
const nbFiches = arbre.oeuvres.filter((o) => o.fiche).length
|
||||
const phrase = nbFiches
|
||||
? `${arbre.oeuvres.length} œuvres au registre, dont ${nbFiches} avec une fiche de lecture composée depuis nos notes, pas encore relue.`
|
||||
: `${arbre.oeuvres.length} œuvres au registre. Aucune fiche de lecture n’est encore ouverte : chaque œuvre est une référence.`
|
||||
|
||||
const fiches = fichesBibliotheque(arbre)
|
||||
const valeursDe = (axe: Axe) => categories(arbre, axe).map((c) => ({ valeur: c.valeur, libelle: c.libelle }))
|
||||
const config: ConfigVueFiches = {
|
||||
dimensions: [
|
||||
{ cle: 'statut', libelle: 'Statut', variante: 'posture', valeurs: (['fiche', 'reference'] as const).filter((s) => s === 'reference' || nbFiches).map((s) => ({ valeur: s, libelle: LIBELLES_STATUT[s] })) },
|
||||
{ cle: 'theme', libelle: 'Thème', variante: 'fonction', valeurs: valeursDe('theme') },
|
||||
{ cle: 'epoque', libelle: 'Époque', variante: 'echelle', valeurs: valeursDe('epoque') },
|
||||
{ cle: 'auteur', libelle: 'Auteur (initiale)', variante: 'echelle', valeurs: valeursDe('auteur') },
|
||||
],
|
||||
tris: ['ordre', 'nom', 'pertinence'],
|
||||
triDefaut: 'ordre',
|
||||
libellesTri: { ordre: 'Année' },
|
||||
groupes: [
|
||||
{ cle: 'epoque', libelle: 'Époque', dimension: 'epoque', sans: 'Sans date au registre' },
|
||||
{ cle: 'theme', libelle: 'Thème', dimension: 'theme', sans: 'Sans thème au registre' },
|
||||
],
|
||||
etats: ['carte', 'mixte', 'fiches'],
|
||||
sousVues: { parametre: 'axe', valeurs: AXES, defaut: 'theme' },
|
||||
}
|
||||
const vf = useVueFiches(fiches, config, { etatDefaut: 'carte' })
|
||||
|
||||
// ── L'arborescence : l'axe choisi, le chemin (filtre de l'axe, sinon les catégories de la fiche ouverte) ──
|
||||
const LIBELLE_AXE: Record<Axe, string> = { theme: 'Thème', epoque: 'Époque', auteur: 'Initiale de l’auteur' }
|
||||
const axe = computed<Axe>(() => (AXES.some((a) => a.valeur === vf.etat.sousVue) ? vf.etat.sousVue : 'theme') as Axe)
|
||||
const oeuvre = computed(() => (vf.ficheId ? parId.get(vf.ficheId) : undefined))
|
||||
const filtreAxe = computed(() => vf.etat.filtres[DIMENSION_AXE[axe.value]] ?? [])
|
||||
const focus = computed(() => {
|
||||
if (filtreAxe.value.length) return filtreAxe.value
|
||||
const f = vf.ficheOuverte as MiniFiche | null
|
||||
return f?.etiquettes?.[DIMENSION_AXE[axe.value]] ?? []
|
||||
})
|
||||
const filtresActifs = computed(() => vf.nbActifs > 0 || !!vf.q.trim())
|
||||
const graphe = computed(() => {
|
||||
// Les œuvres filtrées hors du résultat ne sont pas dans le graphe ; le filtre de l'axe, lui, est le chemin
|
||||
const garder = filtresActifs.value ? new Set([...vf.idsResultat].map(String)) : null
|
||||
const g = grapheAxe(arbre, axe.value, focus.value, garder, vf.ficheId)
|
||||
amorcer(g.noeuds, g.liens, new Set(KINDS_PRINCIPAUX), disposerArbre(g.noeuds, g.liens))
|
||||
return g
|
||||
})
|
||||
const selection = computed(() => vf.ficheId ?? (filtreAxe.value.length === 1 ? idCategorie(axe.value, filtreAxe.value[0]) : null))
|
||||
/** Sans sélection, filtres actifs : les catégories qui gardent au moins une œuvre restent allumées. */
|
||||
const retenus = computed<Set<string> | null>(() => {
|
||||
if (!filtresActifs.value) return null
|
||||
const ids = new Set([...vf.idsResultat].map(String))
|
||||
for (const f of fiches) if (ids.has(String(f.id))) for (const v of f.etiquettes?.[DIMENSION_AXE[axe.value]] ?? []) ids.add(idCategorie(axe.value, v))
|
||||
return ids
|
||||
})
|
||||
const libelleKind = (k: string) => (k === 'axe' ? LIBELLE_AXE[axe.value].toLowerCase() : k === 'fiche' ? 'fiche de lecture' : 'référence seulement')
|
||||
|
||||
/** Clic sur une catégorie : elle devient le chemin (re-clic : on remonte) ; sur une œuvre : sa fiche. */
|
||||
function choisir(id: string) {
|
||||
const c = lireIdCategorie(id)
|
||||
if (!c) { vf.ouvrirFiche(id); return }
|
||||
const dim = DIMENSION_AXE[c.axe]
|
||||
const query: Record<string, any> = { ...route.query }
|
||||
if (filtreAxe.value.length === 1 && filtreAxe.value[0] === c.valeur && !vf.ficheId) delete query[dim]
|
||||
else query[dim] = c.valeur
|
||||
delete query.fiche
|
||||
router.replace({ query })
|
||||
}
|
||||
const lienPage = (f: MiniFiche) => {
|
||||
const o = parId.get(String(f.id))
|
||||
return o?.fiche ? `/bibliotheque/fiche/${o.fiche}` : null
|
||||
}
|
||||
|
||||
// ── La fiche : chargée au clic (ou par l'URL partagée), jamais dans le paquet de la page ──
|
||||
const slug = computed(() => oeuvre.value?.fiche ?? null)
|
||||
const { data: ficheLue, status: chargement } = await useAsyncData(
|
||||
() => `bibliotheque-fiche-${slug.value ?? 'aucune'}`,
|
||||
() => (slug.value ? $fetch<any>(`/api/bibliotheque/fiche/${slug.value}`) : Promise.resolve(null)),
|
||||
{ watch: [slug] },
|
||||
)
|
||||
const agrandi = ref(false)
|
||||
watch(() => vf.ficheId, (id) => { if (!id) agrandi.value = false })
|
||||
const agrandiVu = computed(() => agrandi.value && !!oeuvre.value?.fiche && vf.largeur !== 'telephone')
|
||||
|
||||
useSeoMeta({
|
||||
title: () => (oeuvre.value ? `${oeuvre.value.titre} — Bibliothèque — AEP` : 'Bibliothèque — AEP'),
|
||||
description: 'Les livres que lit AEP, rangés par thème, par époque ou par auteur : le registre des œuvres en arborescence, et les fiches de lecture.',
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.bib { height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; color: var(--text); }
|
||||
.bib-tete {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: var(--space-2xs) var(--space-md);
|
||||
padding: var(--space-xs) var(--space-md);
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
}
|
||||
.bib-tete__titre { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: 1.25; }
|
||||
.bib-bandeau { flex: 1 1 32rem; min-width: 0; margin: 0; font-size: var(--fs-sm); line-height: 1.45; color: color-mix(in srgb, var(--text) 82%, transparent); }
|
||||
.bib-bandeau a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
|
||||
.bib-bandeau a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
|
||||
.bib-vue { flex: 1 1 0; min-height: 0; min-width: 0; }
|
||||
|
||||
/* Le graphe et sa légende : la légende du composant (concepts et sources) ne vaut pas ici */
|
||||
.bib-graphe { position: relative; flex: 1; min-height: 0; min-width: 0; display: flex; }
|
||||
.bib-graphe :deep(.gc__legende) { display: none; }
|
||||
/* Une œuvre à fiche : petit rond plein ; une catégorie : rond creux (défaut du composant) */
|
||||
.bib-graphe :deep(.gc__noeud[data-id^='oeu:'] .gc__rond) { background: var(--text); }
|
||||
.bib-graphe :deep(.gc__noeud[data-id^='oeu:'] .gc__libelle) { font-weight: var(--fw-medium); }
|
||||
.bib-graphe :deep(.gc__noeud--sel[data-id^='oeu:'] .gc__rond) { background: var(--accent); }
|
||||
.bib-legende {
|
||||
position: absolute;
|
||||
left: var(--space-lg);
|
||||
bottom: var(--space-xs);
|
||||
max-width: calc(100% - var(--space-lg) - var(--space-sm));
|
||||
margin: 0;
|
||||
padding: var(--space-2xs) var(--space-xs);
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2xs) var(--space-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
|
||||
font-size: var(--fs-xs);
|
||||
line-height: 1.3;
|
||||
color: color-mix(in srgb, var(--text) 78%, transparent);
|
||||
pointer-events: none;
|
||||
}
|
||||
.bib-legende li { display: inline-flex; align-items: center; gap: var(--space-2xs); }
|
||||
.bib-legende__cat { width: 12px; height: 12px; border-radius: var(--radius-full); border: 2px solid var(--text); background: var(--surface); }
|
||||
.bib-legende__fiche { width: 10px; height: 10px; border-radius: var(--radius-full); border: 2px solid var(--text); background: var(--text); }
|
||||
.bib-legende__ref { width: 9px; height: 9px; border-radius: 2px; background: color-mix(in srgb, var(--text) 52%, var(--bg-alt)); }
|
||||
.bib-masquees {
|
||||
position: absolute;
|
||||
right: var(--space-sm);
|
||||
top: var(--space-xs);
|
||||
margin: 0;
|
||||
padding: var(--space-2xs) var(--space-xs);
|
||||
border-radius: var(--radius-sm);
|
||||
background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
|
||||
font-size: var(--fs-xs);
|
||||
color: color-mix(in srgb, var(--text) 78%, transparent);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Le panneau : une fiche de 2 000 mots demande plus que les 380 px de la vue fiches */
|
||||
@media (min-width: 1024px) {
|
||||
.bib :deep(.vf--detail .vf-corps) { grid-template-columns: var(--vf-liste) minmax(0, 1fr) min(34rem, 42vw); }
|
||||
.bib :deep(.vf--detail.vf--fiches .vf-corps) { grid-template-columns: minmax(0, 1fr) 0 min(34rem, 42vw); }
|
||||
.bib :deep(.vf--detail.vf--carte .vf-corps) { grid-template-columns: 0 minmax(0, 1fr) min(34rem, 42vw); }
|
||||
}
|
||||
/* « Agrandir » : le graphe et la liste s'effacent, la fiche prend la largeur ; l'adresse ne change pas */
|
||||
@media (min-width: 768px) {
|
||||
.bib--agrandi :deep(.vf-corps),
|
||||
.bib--agrandi :deep(.vf--detail .vf-corps),
|
||||
.bib--agrandi :deep(.vf--detail.vf--fiches .vf-corps),
|
||||
.bib--agrandi :deep(.vf--detail.vf--carte .vf-corps) { grid-template-columns: 0 0 minmax(0, 1fr); }
|
||||
.bib--agrandi :deep(.vf-liste),
|
||||
.bib--agrandi :deep(.vf-carte) { visibility: hidden; }
|
||||
.bib--agrandi :deep(.vf-detail) { grid-column: 3; border-left: none; }
|
||||
.bib--agrandi :deep(.vf-detail__corps) { padding-inline: max(var(--space-md), calc((100% - 68ch) / 2)); }
|
||||
}
|
||||
@media (min-width: 768px) and (max-width: 1023.98px) {
|
||||
.bib--agrandi :deep(.vf-corps) { grid-template-columns: 0 minmax(0, 1fr); }
|
||||
.bib--agrandi :deep(.vf-detail) { grid-column: 2; }
|
||||
}
|
||||
|
||||
/* La fiche d'une œuvre dans le panneau */
|
||||
.bo { min-width: 0; overflow-wrap: anywhere; }
|
||||
.bo p { margin: 0; }
|
||||
.bo__titre { margin: 0 0 var(--space-2xs); font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
|
||||
.bo__meta { font-size: var(--fs-sm); color: color-mix(in srgb, var(--text) 78%, transparent); }
|
||||
.bo__themes { margin-top: var(--space-xs); }
|
||||
.bo__statut { margin-top: var(--space-sm) !important; font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: 0.04em; color: color-mix(in srgb, var(--text) 78%, transparent); }
|
||||
.bo__agrandir {
|
||||
min-height: 44px;
|
||||
margin: var(--space-xs) 0 var(--space-sm);
|
||||
padding: 0 var(--space-sm);
|
||||
border: 1px solid var(--border-strong, var(--border));
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
font-size: var(--fs-sm);
|
||||
font-weight: var(--fw-medium);
|
||||
cursor: pointer;
|
||||
}
|
||||
.bo__agrandir[aria-pressed='true'] { background: var(--text); color: var(--surface); }
|
||||
.bo__agrandir:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
|
||||
.bo__etat { margin-top: var(--space-sm) !important; font-size: var(--fs-sm); }
|
||||
.bo__reference { margin-top: var(--space-xs); display: flex; flex-direction: column; gap: var(--space-2xs); font-size: var(--fs-sm); line-height: 1.5; }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.bib-tete { padding: var(--space-2xs) var(--space-sm); }
|
||||
.bib-bandeau { font-size: var(--fs-xs); }
|
||||
}
|
||||
</style>
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
<script setup lang="ts">
|
||||
navigateTo('/media', { redirectCode: 301 })
|
||||
navigateTo('/bibliotheque', { redirectCode: 301 })
|
||||
</script>
|
||||
|
||||
@@ -127,6 +127,13 @@ const A = await charger('utils', 'bibliotheque', 'arbre.ts')
|
||||
const G = await jiti.import(join(racine, 'utils', 'connaissances', 'graphe.ts'))
|
||||
ok(!!A, 'utils/bibliotheque/arbre.ts existe')
|
||||
ok(typeof G.amorcer === 'function', 'graphe.ts : amorcer (une disposition calculée entre au cache)')
|
||||
if (typeof G.amorcer === 'function') {
|
||||
const nd = [{ id: 'a', libelle: 'A', kind: 'axe' }, { id: 'b', libelle: 'B', kind: 'reference' }]
|
||||
const ln = [{ de: 'b', vers: 'a', type: 't', provenance: 'source' }]
|
||||
const p = new Map([['a', { x: 0.3, y: 0.1 }], ['b', { x: -0.2, y: 0.4 }]])
|
||||
G.amorcer(nd, ln, new Set(['axe', 'fiche']), p)
|
||||
ok(G.disposerEnCache(nd, ln, new Set(['axe', 'fiche'])) === p && G.disposerEnCache(nd, ln, new Set(['concept'])) !== p, 'graphe.ts : la disposition amorcée est rendue telle quelle, pour la même signature seulement')
|
||||
}
|
||||
if (A && ex) {
|
||||
const arbre = A.arbreServi(ex, new Set(ex.oeuvres.filter((o) => o.fiche).slice(0, 3).map((o) => o.fiche)))
|
||||
ok(arbre.oeuvres.filter((o) => o.fiche).length === 3, 'arbre servi : une fiche seulement si son socle est servi')
|
||||
@@ -135,10 +142,17 @@ if (A && ex) {
|
||||
for (const axe of ['theme', 'epoque', 'auteur']) {
|
||||
const g = A.grapheAxe(arbre, axe, [])
|
||||
ok(g.noeuds.every((x) => x.kind === 'axe') && g.noeuds.length >= 12, `graphe ${axe} : sans focus, les catégories seules (${g.noeuds.length})`)
|
||||
const cat = g.noeuds[0].id
|
||||
const g2 = A.grapheAxe(arbre, axe, [cat])
|
||||
const cat = A.lireIdCategorie(g.noeuds[0].id)
|
||||
const g2 = A.grapheAxe(arbre, axe, [cat.valeur])
|
||||
const oe = g2.noeuds.filter((x) => x.kind !== 'axe')
|
||||
ok(oe.length > 0 && g2.liens.every((l) => l.vers.startsWith('axe:')), `graphe ${axe} : une catégorie ouverte montre ses œuvres (${oe.length})`)
|
||||
ok(oe.length > 0 && oe.length <= A.MAX_OEUVRES && g2.liens.every((l) => l.vers.startsWith('axe:')), `graphe ${axe} : une catégorie ouverte montre ses œuvres (${oe.length}, ${g2.masquees} dans la liste seulement)`)
|
||||
const derniere = A.categories(arbre, axe).find((c) => c.valeur === cat.valeur).oeuvres.at(-1)
|
||||
const g3 = A.grapheAxe(arbre, axe, [cat.valeur], null, derniere.id)
|
||||
ok(g3.noeuds.some((x) => x.id === derniere.id), `graphe ${axe} : l'œuvre ouverte est toujours dans le graphe, même au-delà de ${A.MAX_OEUVRES}`)
|
||||
const pos = A.disposerArbre(g2.noeuds, g2.liens)
|
||||
const c0 = pos.get(g.noeuds[0].id)
|
||||
const dist = oe.map((x) => Math.hypot(pos.get(x.id).x - c0.x, pos.get(x.id).y - c0.y))
|
||||
ok(g2.noeuds.every((x) => Number.isFinite(pos.get(x.id)?.x)) && dist.every((d) => d > 0.1 && d < 0.25), `graphe ${axe} : les œuvres en anneaux autour de la catégorie ouverte (distance ${Math.min(...dist).toFixed(2)} à ${Math.max(...dist).toFixed(2)})`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* GET /api/bibliotheque/fiche/<slug> (lot B9) — le HTML d'une fiche de lecture SERVIE, au clic.
|
||||
* Lit le module virtuel posé par modules/bibliotheque.ts au build : un socle non servi n'y est pas,
|
||||
* la route répond 404. `noindex` en en-tête par le middleware (tout /api/*).
|
||||
*/
|
||||
// @ts-expect-error module virtuel posé par modules/bibliotheque.ts
|
||||
import fiches from '#bibliotheque-fiches'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const slug = getRouterParam(event, 'slug') ?? ''
|
||||
const f = /^[a-z0-9-]+$/.test(slug) && Object.prototype.hasOwnProperty.call(fiches, slug) ? fiches[slug] : null
|
||||
if (!f) throw createError({ statusCode: 404, statusMessage: 'Fiche non servie' })
|
||||
setHeader(event, 'Cache-Control', 'public, max-age=3600')
|
||||
return f
|
||||
})
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* arbre — lot B9. Le second adaptateur de `GrapheConnaissances` et de `VueFiches` : l'export du
|
||||
* registre (data/bibliotheque/oeuvres-registre.json, filtré par le réglage au build) devient les
|
||||
* fiches de la vue et une ARBORESCENCE, projection du registre par un axe (thème, époque, auteur).
|
||||
* Fonctions pures ; aucune connaissance du DOM ; testées par scripts/test-bibliotheque.mjs.
|
||||
*
|
||||
* - nœuds principaux (ronds, boutons, au clavier) : les catégories de l'axe (`axe`) et les œuvres
|
||||
* qui ont une fiche servie (`fiche`) ; nœuds secondaires (carrés gris) : les œuvres « référence
|
||||
* seulement » (au registre, rien de plus), que la liste rend au clavier ;
|
||||
* - sans catégorie ouverte : les catégories seules ; une catégorie ouverte (le filtre de l'axe,
|
||||
* dans l'URL) montre ses œuvres, ses fiches d'abord, MAX_OEUVRES au plus (la liste les a toutes) ;
|
||||
* - disposition radiale, calculée en O(n) (aucune force sur 650 nœuds au téléphone) et posée au
|
||||
* cache de `utils/connaissances/graphe.ts` (`amorcer`) avant que le composant la demande.
|
||||
*/
|
||||
import type { MiniFiche } from '../../composables/useFicheAdapter'
|
||||
import type { LienGraphe, NoeudGraphe, Pt } from '../connaissances/graphe'
|
||||
|
||||
export interface OeuvreExport {
|
||||
id: string; titre: string; auteurs: string[]; annee: number | null; epoque: string | null
|
||||
courants: string[]; regime: string | null; dans_corpus: boolean; fiche: string | null; couche: string
|
||||
}
|
||||
export interface ExportRegistre {
|
||||
version: number
|
||||
source: { registre_maj: string; exporte_le: string }
|
||||
champs: string[]
|
||||
personnes: Record<string, string>
|
||||
epoques: { id: string; nom: string; debut: number; fin: number }[]
|
||||
courants: { id: string; nom: string; contre_point: boolean }[]
|
||||
oeuvres: OeuvreExport[]
|
||||
}
|
||||
|
||||
export type Axe = 'theme' | 'epoque' | 'auteur'
|
||||
export const AXES: { valeur: Axe; libelle: string }[] = [
|
||||
{ valeur: 'theme', libelle: 'Par thème' },
|
||||
{ valeur: 'epoque', libelle: 'Par époque' },
|
||||
{ valeur: 'auteur', libelle: 'Par auteur' },
|
||||
]
|
||||
export const KINDS_PRINCIPAUX = ['axe', 'fiche']
|
||||
export const SANS = 'sans'
|
||||
export const MAX_OEUVRES = 40
|
||||
export const LIBELLES_STATUT: Record<string, string> = { fiche: 'Fiche de lecture', reference: 'Référence seulement' }
|
||||
|
||||
/** L'export tel que la page le reçoit : `fiche` gardée pour les seuls socles servis. */
|
||||
export function arbreServi(ex: ExportRegistre, servis: Set<string>): ExportRegistre {
|
||||
return { ...ex, oeuvres: ex.oeuvres.map((o) => ({ ...o, fiche: o.fiche && servis.has(o.fiche) ? o.fiche : null })) }
|
||||
}
|
||||
|
||||
export const nomsAuteurs = (ex: ExportRegistre, o: OeuvreExport) => o.auteurs.map((a) => ex.personnes[a]).filter(Boolean)
|
||||
export const ligneAuteurs = (ex: ExportRegistre, o: OeuvreExport) => nomsAuteurs(ex, o).join(', ') || 'auteur inconnu au registre'
|
||||
export const anneeTexte = (a: number | null) => (a == null ? 's. d.' : a < 0 ? `${-a} av. J.-C.` : String(a))
|
||||
|
||||
const PARTICULES = new Set(['de', 'du', 'des', 'd', 'la', 'le', 'l', 'von', 'van', 'der', 'jr', 'sr', 'fils'])
|
||||
const sansAccent = (s: string) => s.normalize('NFD').replace(/[̀-ͯ]/g, '')
|
||||
/** Nom de classement d'une personne : le dernier mot qui n'est pas une particule (« de Sade » → Sade). */
|
||||
export function nomDeClassement(nom: string): string {
|
||||
const mots = nom.replace(/[()]/g, ' ').split(/[\s’']+/).filter(Boolean)
|
||||
for (let i = mots.length - 1; i >= 0; i--) if (!PARTICULES.has(sansAccent(mots[i]).toLowerCase().replace(/\.$/, ''))) return mots[i]
|
||||
return mots[mots.length - 1] ?? nom
|
||||
}
|
||||
/** Lettre de l'axe auteur : initiale du nom de classement du premier auteur, ou `sans`. */
|
||||
export function lettre(ex: ExportRegistre, o: OeuvreExport): string {
|
||||
const n = o.auteurs[0] && ex.personnes[o.auteurs[0]]
|
||||
const l = n ? sansAccent(nomDeClassement(n)).charAt(0).toUpperCase() : ''
|
||||
return /^[A-Z]$/.test(l) ? l : SANS
|
||||
}
|
||||
|
||||
/** Les catégories d'un axe, dans l'ordre de l'axe, avec leurs œuvres. */
|
||||
export function categories(ex: ExportRegistre, axe: Axe): { valeur: string; libelle: string; oeuvres: OeuvreExport[] }[] {
|
||||
const de = (o: OeuvreExport): string[] =>
|
||||
axe === 'theme' ? (o.courants.length ? o.courants : [SANS]) : axe === 'epoque' ? [o.epoque ?? SANS] : [lettre(ex, o)]
|
||||
const base = axe === 'theme'
|
||||
? ex.courants.map((c) => ({ valeur: c.id, libelle: c.contre_point ? `${c.nom} (contre-point)` : c.nom }))
|
||||
: axe === 'epoque'
|
||||
? ex.epoques.map((e) => ({ valeur: e.id, libelle: e.nom }))
|
||||
: [...new Set(ex.oeuvres.map((o) => lettre(ex, o)).filter((l) => l !== SANS))].sort().map((l) => ({ valeur: l, libelle: l }))
|
||||
const sans = { valeur: SANS, libelle: axe === 'theme' ? 'Sans thème au registre' : axe === 'epoque' ? 'Sans date au registre' : 'Auteur inconnu au registre' }
|
||||
return [...base, sans]
|
||||
.map((c) => ({ ...c, oeuvres: ex.oeuvres.filter((o) => de(o).includes(c.valeur)) }))
|
||||
.filter((c) => c.oeuvres.length)
|
||||
}
|
||||
|
||||
export const idCategorie = (axe: Axe, valeur: string) => `axe:${axe}:${valeur}`
|
||||
export const lireIdCategorie = (id: string): { axe: Axe; valeur: string } | null => {
|
||||
const m = /^axe:(theme|epoque|auteur):(.+)$/.exec(id)
|
||||
return m ? { axe: m[1] as Axe, valeur: m[2] } : null
|
||||
}
|
||||
/** Dimension de filtre (paramètre d'URL) qui porte le chemin de chaque axe. */
|
||||
export const DIMENSION_AXE: Record<Axe, string> = { theme: 'theme', epoque: 'epoque', auteur: 'auteur' }
|
||||
|
||||
/** Les fiches de la vue : une par œuvre du registre, ordonnées par année (l'ordre d'origine de la liste). */
|
||||
export function fichesBibliotheque(ex: ExportRegistre): MiniFiche[] {
|
||||
const lettres = new Map(ex.oeuvres.map((o) => [o.id, lettre(ex, o)]))
|
||||
const nomEpoque = new Map(ex.epoques.map((e) => [e.id, e.nom]))
|
||||
const nomCourant = new Map(ex.courants.map((c) => [c.id, c.nom]))
|
||||
return [...ex.oeuvres]
|
||||
.sort((a, b) => (a.annee ?? 99999) - (b.annee ?? 99999) || (a.titre < b.titre ? -1 : 1))
|
||||
.map((o) => {
|
||||
const statut = o.fiche ? 'fiche' : 'reference'
|
||||
return {
|
||||
id: o.id,
|
||||
nom: o.titre,
|
||||
resume: `${ligneAuteurs(ex, o)} · ${anneeTexte(o.annee)}`,
|
||||
chips: [LIBELLES_STATUT[statut]],
|
||||
chipsDimension: 'statut',
|
||||
// Pas de géographie : `geoloc: true`, comme les fiches de /connaissances (sinon « 631 sans adresse »)
|
||||
geoloc: true,
|
||||
kind: 'oeuvre' as MiniFiche['kind'],
|
||||
etiquettes: {
|
||||
theme: o.courants.length ? o.courants : [SANS],
|
||||
epoque: [o.epoque ?? SANS],
|
||||
auteur: [lettres.get(o.id)!],
|
||||
statut: [statut],
|
||||
},
|
||||
texte: [nomsAuteurs(ex, o).join(' '), o.epoque ? nomEpoque.get(o.epoque) : '', ...o.courants.map((c) => nomCourant.get(c))].join(' '),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Le graphe d'un axe. `focus` : les catégories ouvertes (valeurs de l'axe). Sans focus, les catégories
|
||||
* seules ; avec, leurs œuvres (fiches d'abord, MAX_OEUVRES par catégorie), reliées à chacune de leurs
|
||||
* catégories. `garder` (les fiches du résultat de la vue, null = toutes) écarte les œuvres filtrées.
|
||||
* `ouverte` : l'œuvre dont la fiche est ouverte, toujours dans le graphe (au-delà de MAX_OEUVRES).
|
||||
* `masquees` : combien d'œuvres retenues des catégories ouvertes ne sont pas dans le graphe.
|
||||
*/
|
||||
export function grapheAxe(ex: ExportRegistre, axe: Axe, focus: string[], garder: Set<string> | null = null, ouverte: string | null = null): { noeuds: NoeudGraphe[]; liens: LienGraphe[]; masquees: number } {
|
||||
const cats = categories(ex, axe)
|
||||
const noeuds: NoeudGraphe[] = cats.map((c) => ({
|
||||
id: idCategorie(axe, c.valeur),
|
||||
libelle: `${c.libelle} · ${c.oeuvres.length}`,
|
||||
kind: 'axe',
|
||||
poids: Math.min(6, Math.round(Math.log2(c.oeuvres.length + 1))),
|
||||
}))
|
||||
const liens: LienGraphe[] = []
|
||||
const vus = new Set<string>()
|
||||
/** La catégorie ouverte où l'œuvre est montrée : son lien vient en premier, la disposition l'y range. */
|
||||
const parent = new Map<string, string>()
|
||||
let masquees = 0
|
||||
const auteur = (o: OeuvreExport) => (o.auteurs[0] && ex.personnes[o.auteurs[0]] ? nomDeClassement(ex.personnes[o.auteurs[0]]) : '')
|
||||
for (const c of cats.filter((x) => focus.includes(x.valeur))) {
|
||||
const tri = c.oeuvres.filter((o) => o.id === ouverte || !garder || garder.has(o.id)).sort((a, b) => Number(b.id === ouverte) - Number(a.id === ouverte) || Number(!a.fiche) - Number(!b.fiche) || Number(!a.dans_corpus) - Number(!b.dans_corpus) || (a.annee ?? 99999) - (b.annee ?? 99999))
|
||||
masquees += Math.max(0, tri.length - MAX_OEUVRES)
|
||||
for (const o of tri.slice(0, MAX_OEUVRES)) {
|
||||
if (vus.has(o.id)) continue
|
||||
vus.add(o.id)
|
||||
parent.set(o.id, c.valeur)
|
||||
noeuds.push({ id: o.id, libelle: axe === 'auteur' && auteur(o) ? `${auteur(o)}, ${o.titre}` : o.titre, kind: o.fiche ? 'fiche' : 'reference', poids: 0 })
|
||||
}
|
||||
}
|
||||
const presentes = new Set(cats.map((c) => c.valeur))
|
||||
for (const o of ex.oeuvres) {
|
||||
if (!vus.has(o.id)) continue
|
||||
const de = axe === 'theme' ? (o.courants.length ? o.courants : [SANS]) : axe === 'epoque' ? [o.epoque ?? SANS] : [lettre(ex, o)]
|
||||
const p = parent.get(o.id)!
|
||||
for (const v of [p, ...de.filter((x) => x !== p)]) if (presentes.has(v)) liens.push({ de: o.id, vers: idCategorie(axe, v), type: 'appartient_a', provenance: 'source' })
|
||||
}
|
||||
return { noeuds, liens, masquees }
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposition radiale : les catégories sur une ellipse (0,5 × 0,34) ; les œuvres d'une catégorie ouverte
|
||||
* en anneaux autour d'elle (16 sur le premier, 24 sur le second ; son lien est le premier de chaque
|
||||
* œuvre, `grapheAxe` l'y met), rayon 0,2 : à un pas, la caméra du
|
||||
* composant (zoom borné à 2,4 fois le graphe entier) remplit la zone. Repère sans unité, centré.
|
||||
*/
|
||||
export function disposerArbre(noeuds: NoeudGraphe[], liens: LienGraphe[]): Map<string, Pt> {
|
||||
const pos = new Map<string, Pt>()
|
||||
const cats = noeuds.filter((x) => x.kind === 'axe')
|
||||
cats.forEach((c, i) => {
|
||||
const t = -Math.PI / 2 + (2 * Math.PI * i) / Math.max(cats.length, 1)
|
||||
pos.set(c.id, { x: 0.5 * Math.cos(t), y: 0.34 * Math.sin(t) }) // ellipse : couchée sur un écran large, debout au téléphone (le composant tourne le dessin)
|
||||
})
|
||||
const premiere = new Map<string, string>()
|
||||
for (const l of liens) if (!premiere.has(l.de)) premiere.set(l.de, l.vers)
|
||||
const parCat = new Map<string, string[]>()
|
||||
for (const x of noeuds) {
|
||||
if (x.kind === 'axe') continue
|
||||
const c = premiere.get(x.id)
|
||||
if (!c) continue
|
||||
parCat.set(c, [...(parCat.get(c) ?? []), x.id])
|
||||
}
|
||||
for (const [c, ids] of parCat) {
|
||||
const centre = pos.get(c)!
|
||||
const t0 = Math.atan2(centre.y, centre.x)
|
||||
const anneaux = ids.length <= 16 ? [ids] : [ids.slice(0, 16), ids.slice(16)]
|
||||
anneaux.forEach((anneau, k) => {
|
||||
const r = anneaux.length === 1 ? 0.2 : k === 0 ? 0.13 : 0.22
|
||||
anneau.forEach((id, j) => {
|
||||
const t = t0 + (2 * Math.PI * j) / anneau.length + (k ? Math.PI / anneau.length : 0)
|
||||
pos.set(id, { x: centre.x + r * Math.cos(t), y: centre.y + r * Math.sin(t) })
|
||||
})
|
||||
})
|
||||
}
|
||||
for (const x of noeuds) if (!pos.has(x.id)) pos.set(x.id, { x: 0, y: 0 })
|
||||
return pos
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
* d'étendue 1 (aucune position en données) ;
|
||||
* - `disposerEnCache` : la même, mémorisée par signature du graphe (une fois par processus) ;
|
||||
* - `voisinage` : identifiants à `pas` liens au plus d'un nœud (graphe local d'Obsidian) ;
|
||||
* - `boite` : boîte englobante d'un ensemble de points, une seule écriture pour le dessin et la caméra.
|
||||
* - `boite` : boîte englobante d'un ensemble de points, une seule écriture pour le dessin et la caméra ;
|
||||
* - `amorcer` (B9) : pose au cache une disposition calculée ailleurs, sous la même signature.
|
||||
*/
|
||||
|
||||
/** Un nœud : `kind` dit sa forme (principal si dans `kindsPrincipaux`, sinon secondaire). */
|
||||
@@ -122,17 +123,31 @@ export function disposer(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux:
|
||||
|
||||
/** Cache par signature du graphe : au serveur, une fois par processus, pas une fois par requête. */
|
||||
const CACHE = new Map<string, Map<string, Pt>>()
|
||||
const signature = (noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>) =>
|
||||
JSON.stringify([noeuds.map((x) => [x.id, x.kind]), liens.map((l) => [l.de, l.vers]), [...principaux]])
|
||||
function garder(sig: string, p: Map<string, Pt>) {
|
||||
if (CACHE.size > 24) CACHE.delete(CACHE.keys().next().value as string)
|
||||
CACHE.set(sig, p)
|
||||
}
|
||||
export function disposerEnCache(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>): Map<string, Pt> {
|
||||
const sig = JSON.stringify([noeuds.map((x) => [x.id, x.kind]), liens.map((l) => [l.de, l.vers]), [...principaux]])
|
||||
const sig = signature(noeuds, liens, principaux)
|
||||
let p = CACHE.get(sig)
|
||||
if (!p) {
|
||||
p = disposer(noeuds, liens, principaux)
|
||||
if (CACHE.size > 24) CACHE.delete(CACHE.keys().next().value as string)
|
||||
CACHE.set(sig, p)
|
||||
garder(sig, p)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
/**
|
||||
* Lot B9 : une disposition déjà calculée (l'arborescence de la bibliothèque, radiale, en O(n)) entre
|
||||
* au cache sous la signature du graphe ; `disposerEnCache` la rend sans calculer de force. Mêmes
|
||||
* nœuds, liens et kinds principaux que ceux que recevra le composant, dans le même ordre.
|
||||
*/
|
||||
export function amorcer(noeuds: NoeudGraphe[], liens: LienGraphe[], principaux: Set<string>, p: Map<string, Pt>): void {
|
||||
garder(signature(noeuds, liens, principaux), p)
|
||||
}
|
||||
|
||||
/** Identifiants à `pas` liens au plus de `id` (le nœud compris) ; `tout` = tous. */
|
||||
export function voisinage(liens: LienGraphe[], id: string, pas: Pas): Set<string> | null {
|
||||
if (pas === 'tout') return null
|
||||
|
||||
Reference in New Issue
Block a user