Audit complet de mise en forme — Image (2e élément du tableau)

Implémente toutes les options manquantes identifiées pour l'élément
Image : dimensionnement/ratio/object-fit, filtres CSS, upload de
fichier (en plus de l'URL), lien/plein écran au clic, chargement
différé, légende, et tous les attributs de boîte partagés déjà créés
pour Titre/Paragraphe (padding/margin/fond/bordure/ombre/opacité/
position du bloc).

Système de pages : un support peut désormais avoir 0 page (un nouveau
support démarre vide), suppression de toutes les pages en un clic, et
la pagination automatique insère intelligemment la nouvelle page juste
après celle qui déborde plutôt qu'en toute fin de liste.

Bugs réels trouvés et corrigés en cours de route : le style de bloc
(dont align-self) ciblait l'élément interne au lieu de son enveloppe
(légende/lien) ; une image à sa taille native pouvait déclencher une
pagination infinie ; upload/mise à jour d'attribut ne déclenchaient
jamais le contrôle de débordement.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-09-26 12:06:44 +02:00
co-authored by Claude Sonnet 5
parent 6c7675fad0
commit 9ad50c58b8
27 changed files with 1299 additions and 174 deletions
+45 -48
View File
@@ -27,6 +27,8 @@ BOX_DEFAULTS = {
"background_color": "",
"border_radius": "",
"align_self": "stretch",
"width": "",
"max_width": "",
"height": "",
"min_height": "",
"max_height": "",
@@ -36,58 +38,39 @@ BOX_DEFAULTS = {
}
def render_box_style(a: dict[str, Any]) -> str:
"""Construit les déclarations CSS inline communes à plusieurs kinds à
partir des attributs `padding`/`margin`/`background_color`/
`border_radius`/`height`/`min_height`/`max_height`/`min_width`/
`box_shadow`/`opacity`/`border`/`align_self` de `a` — chaîne vide pour
tout attribut absent ou à sa valeur par défaut (aucun style ajouté,
comportement historique inchangé). `border` est un dict à 4 clés
(`BORDER_SIDES`), chacune `{"style", "width", "color"}` — un côté à
`style="none"` (ou absent) ne produit aucune déclaration pour ce
côté, jamais un `border-top:none` explicite.
- **Retour** : les déclarations CSS (`"propriete:valeur; ..."`),
jamais vide ni `None`.
- **Exceptions** : aucune."""
parts: list[str] = []
# (clé d'attribut, propriété CSS) — chaque paire suit exactement le même
# patron (lire/nettoyer/ajouter si non vide) ; une simple table de
# correspondance ici évite un enchaînement de blocs `if` identiques
# (complexité cognitive réduite, voir _render_simple_properties).
_SIMPLE_PROPERTIES = (
("padding", "padding"),
("margin", "margin"),
("background_color", "background-color"),
("border_radius", "border-radius"),
("width", "width"),
("max_width", "max-width"),
("height", "height"),
("min_height", "min-height"),
("max_height", "max-height"),
("min_width", "min-width"),
("box_shadow", "box-shadow"),
("opacity", "opacity"),
)
padding = str(a.get("padding", "")).strip()
if padding:
parts.append(f"padding:{html_lib.escape(padding)};")
margin = str(a.get("margin", "")).strip()
if margin:
parts.append(f"margin:{html_lib.escape(margin)};")
def _render_simple_properties(a: dict[str, Any]) -> list[str]:
parts = []
for attr_key, css_prop in _SIMPLE_PROPERTIES:
value = str(a.get(attr_key, "")).strip()
if value:
parts.append(f"{css_prop}:{html_lib.escape(value)};")
return parts
background_color = str(a.get("background_color", "")).strip()
if background_color:
parts.append(f"background-color:{html_lib.escape(background_color)};")
border_radius = str(a.get("border_radius", "")).strip()
if border_radius:
parts.append(f"border-radius:{html_lib.escape(border_radius)};")
height = str(a.get("height", "")).strip()
if height:
parts.append(f"height:{html_lib.escape(height)};")
min_height = str(a.get("min_height", "")).strip()
if min_height:
parts.append(f"min-height:{html_lib.escape(min_height)};")
max_height = str(a.get("max_height", "")).strip()
if max_height:
parts.append(f"max-height:{html_lib.escape(max_height)};")
min_width = str(a.get("min_width", "")).strip()
if min_width:
parts.append(f"min-width:{html_lib.escape(min_width)};")
box_shadow = str(a.get("box_shadow", "")).strip()
if box_shadow:
parts.append(f"box-shadow:{html_lib.escape(box_shadow)};")
opacity = str(a.get("opacity", "")).strip()
if opacity:
parts.append(f"opacity:{html_lib.escape(opacity)};")
def _render_border(a: dict[str, Any]) -> list[str]:
"""Un côté à `style="none"` (ou absent) ne produit aucune déclaration
pour ce côté, jamais un `border-top:none` explicite."""
parts = []
border = a.get("border") or {}
for side in BORDER_SIDES:
side_border = border.get(side) or {}
@@ -96,6 +79,20 @@ def render_box_style(a: dict[str, Any]) -> str:
width = html_lib.escape(str(side_border.get("width", "1px")))
color = html_lib.escape(str(side_border.get("color", "var(--doc-border)")))
parts.append(f"border-{side}:{width} {html_lib.escape(style)} {color};")
return parts
def render_box_style(a: dict[str, Any]) -> str:
"""Construit les déclarations CSS inline communes à plusieurs kinds à
partir des attributs listés dans `_SIMPLE_PROPERTIES` + `border`/
`align_self` de `a` — chaîne vide pour tout attribut absent ou à sa
valeur par défaut (aucun style ajouté, comportement historique
inchangé). `border` est un dict à 4 clés (`BORDER_SIDES`), chacune
`{"style", "width", "color"}`.
- **Retour** : les déclarations CSS (`"propriete:valeur; ..."`),
jamais vide ni `None`.
- **Exceptions** : aucune."""
parts = _render_simple_properties(a) + _render_border(a)
# align-self ne fait quoi que ce soit d'utile QUE si l'élément a par
# ailleurs une taille bornée (max_width/width) — voir la note dans