emdash-plugin-retouche 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,14 +1,39 @@
1
- # Journal des versions
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2026-12-03)
4
+
5
+ ### Added
6
+
7
+ - The admin page is available in English and French and follows the EmDash admin language, read from
8
+ `<html lang>`. Any language other than French falls back to English.
9
+ - Route errors carry a code (`IMAGE_NOT_FOUND`, `UNSUPPORTED_FORMAT`, `UNDECODABLE_IMAGE`,
10
+ `MEDIA_UNAVAILABLE`) in `error.code`, which the admin translates.
11
+
12
+ ### Changed
13
+
14
+ - The image is chosen in the EmDash media picker, opened from a single line that shows the selected
15
+ image, instead of a thumbnail gallery. The picker searches the library and accepts uploads.
16
+ - New peer dependency `@emdash-cms/admin`, with the same range as `emdash`.
17
+
18
+ ### Breaking changes
19
+
20
+ - The `images` route is removed: the media picker lists the images itself.
21
+ - Documentation, code, logs and API error messages are now in English. Only the plugin name,
22
+ **Retouche**, stays in French.
23
+ - Preset identifiers renamed: `crayon` becomes `pencil` and `couleur` becomes `color`, in the
24
+ `preview` and `save` routes and in the `Preset` type.
25
+ - The `retoucher()` export becomes `retouch()`, and `RetoucheOptions` and `RetoucheResult` become
26
+ `RetouchOptions` and `RetouchResult`.
27
+ - Retouched images are saved as `<name>-retouched.jpg` instead of `<name>-retouche.jpg`.
2
28
 
3
29
  ## 0.1.0 (2026-12-03)
4
30
 
5
- Première version.
31
+ First release.
6
32
 
7
- - Page d'admin **Retouche** : choix d'une image de la médiathèque, préréglage « Dessin au crayon » ou
8
- « Dessin en couleur », curseur d'intensité et aperçu avant/après calculé par le serveur.
9
- - Enregistrement d'une nouvelle image `<nom>-retouche.jpg` en 2000 px de large au plus, sans modifier
10
- l'original.
11
- - Retouche avec sharp : correction de l'éclairage par division du fond flouté, contraste automatique, JPEG
12
- mozjpeg qualité 86, métadonnées de la photo retirées.
13
- - Capacités `media:read`, `media:bytes:read` et `media:write` ; routes privées protégées par `media:read` ou
14
- `media:upload`.
33
+ - **Retouche** admin page: pick an image from the media library, a "Pencil drawing" or "Color
34
+ drawing" preset, an intensity slider and a before/after preview computed by the server.
35
+ - Saves a new `<name>-retouche.jpg` image at most 2000 px wide, without modifying the original.
36
+ - Retouch with sharp: lighting correction by division by the blurred background, autocontrast,
37
+ mozjpeg JPEG at quality 86, photo metadata removed.
38
+ - Capabilities `media:read`, `media:bytes:read` and `media:write`; private routes guarded by
39
+ `media:read` or `media:upload`.
package/README.md CHANGED
@@ -1,63 +1,65 @@
1
1
  # emdash-plugin-retouche
2
2
 
3
- Plugin [EmDash](https://emdashcms.com) natif qui retouche les photos de dessins prises au téléphone :
4
- papier uniformément blanc, contraste renforcé, image ramenée à 2000 px de large. La retouche
5
- s'applique depuis l'admin, image par image, et crée toujours une nouvelle image dans la
6
- médiathèque : l'original reste intact.
3
+ Native [EmDash](https://emdashcms.com) plugin that retouches phone photos of drawings: evenly white
4
+ paper, stronger contrast, image scaled down to 2000 px wide. The retouch runs from the admin, one
5
+ image at a time, and always creates a new image in the media library: the original stays untouched.
7
6
 
8
- Version d'EmDash prise en charge : 1.6 et suivantes de la branche 1.x.
7
+ Supported EmDash versions: 1.6 and later on the 1.x line.
9
8
 
10
- ## Fonctionnement
9
+ ## How it works
11
10
 
12
- Une page **Retouche** s'ajoute à l'admin (`/_emdash/admin/plugins/retouche`). On y choisit :
11
+ A **Retouche** page is added to the admin (`/_emdash/admin/plugins/retouche`). There you pick:
13
12
 
14
- 1. une image de la médiathèque ;
15
- 2. un préréglage :
16
- - **Dessin au crayon** : niveaux de gris, papier blanchi, contraste renforcé ;
17
- - **Dessin en couleur** : même correction d'éclairage, couleurs conservées, papier neutre ;
18
- 3. une intensité, de 0 % (image d'origine) à 100 % (retouche complète).
13
+ 1. an image, through the EmDash media picker, where you can also search or upload a new photo;
14
+ 2. a preset:
15
+ - **Pencil drawing**: grayscale, whitened paper, stronger contrast;
16
+ - **Color drawing**: same lighting correction, colors kept, neutral paper;
17
+ 3. an intensity, from 0 % (original image) to 100 % (full retouch).
19
18
 
20
- L'aperçu avant/après est calculé par le serveur à chaque réglage, sur une copie de 900 px de large.
21
- Le bouton **Enregistrer une copie retouchée** applique la même retouche en 2000 px et ajoute le
22
- résultat à la médiathèque sous le nom `<nom d'origine>-retouche.jpg`.
19
+ The page follows the language of the EmDash admin: French when the admin is in French, English for
20
+ every other language. The admin exposes no translation API to plugins, so the page reads the locale
21
+ the admin writes to `<html lang>` and switches as soon as it changes.
23
22
 
24
- ### Algorithme
23
+ The server computes the before/after preview on every settings change, on a copy 900 px wide. The
24
+ **Save a retouched copy** button applies the same retouch at 2000 px and adds the result to the media
25
+ library as `<original name>-retouched.jpg`.
25
26
 
26
- Le traitement reprend la retouche faite à la main sous Python/PIL sur les premières photos :
27
+ ### Algorithm
27
28
 
28
- 1. Orientation EXIF appliquée, transparence posée sur du blanc, réduction à 2000 px de large au
29
- plus.
30
- 2. Préréglage crayon : passage en niveaux de gris.
31
- 3. Correction de l'éclairage : chaque pixel est divisé par une copie très floutée de l'image, avec
32
- un gain de 235. Le flou vaut 1/15 de la largeur, soit 40 px pour 600 px de large. Il est calculé
33
- sur une copie de 240 px puis agrandi, ce qui donne le même fond qu'un flou en pleine taille pour
34
- une fraction du temps. En couleur, la division se fait canal par canal : un papier jauni par une
35
- lumière chaude redevient neutre.
36
- 4. Contraste automatique, sur le modèle de `ImageOps.autocontrast` : 2 % des pixels les plus sombres
37
- et 13 % des plus clairs sont écrêtés, puis l'histogramme est étiré. En couleur, la même table
38
- s'applique aux trois canaux, calculée sur la luminance, pour ne pas décaler les teintes.
39
- 5. Mélange avec l'image de l'étape 2 selon l'intensité choisie.
40
- 6. JPEG qualité 86 avec mozjpeg. Les métadonnées de la photo, dont la position GPS, ne sont pas
41
- reprises.
29
+ The processing reproduces the retouch first done by hand with Python/PIL:
42
30
 
43
- Le `composite` de sharp en mode `colour-dodge` a été essayé pour l'étape 3 : sur une feuille de test,
44
- il s'écartait de la division de 6 niveaux en moyenne et de 59 au pire, pour un temps de calcul
45
- identique. Le plugin calcule donc la division directement sur les pixels.
31
+ 1. EXIF orientation applied, transparency flattened onto white, image scaled down to 2000 px wide
32
+ at most.
33
+ 2. Pencil preset: conversion to grayscale.
34
+ 3. Lighting correction: each pixel is divided by a heavily blurred copy of the image, with a gain of
35
+ 235. The blur is 1/15 of the width, which is 40 px for a 600 px wide image. It is computed on a
36
+ 240 px copy and then enlarged, which gives the same background as a full-size blur in a fraction
37
+ of the time. In color, the division runs per channel, so paper yellowed by warm light turns
38
+ neutral again.
39
+ 4. Autocontrast, modelled on `ImageOps.autocontrast`: the darkest 2 % and the lightest 13 % of the
40
+ pixels are clipped, then the histogram is stretched. In color, the same table applies to all three
41
+ channels, computed on the luma, so hues do not shift.
42
+ 5. Blend with the image from step 2 according to the chosen intensity.
43
+ 6. JPEG at quality 86 with mozjpeg. The photo metadata, GPS position included, is not carried over.
46
44
 
47
- Sur une photo de 4032 × 3024 px (Apple M4, Node 24), l'aperçu prend 50 à 90 ms et
48
- l'enregistrement 170 à 330 ms selon le préréglage.
45
+ The sharp `composite` operation in `colour-dodge` mode was tried for step 3: on a test sheet it
46
+ differed from the division by 6 levels on average and 59 at worst, for the same computing time. The
47
+ plugin therefore computes the division directly on the pixels.
48
+
49
+ On a 4032 × 3024 px photo (Apple M4, Node 24), the preview takes 50 to 90 ms and saving takes 170 to
50
+ 330 ms depending on the preset.
49
51
 
50
52
  ## Installation
51
53
 
52
- Le site doit déjà utiliser `@astrojs/react` (requis par l'admin d'EmDash) et avoir `sharp` en
53
- dépendance directe : le plugin l'utilise sans l'embarquer, pour éviter une seconde copie de ce
54
- module natif.
54
+ The site must already use `@astrojs/react` (required by the EmDash admin) and have `sharp` as a
55
+ direct dependency: the plugin uses it without bundling it, to avoid a second copy of this native
56
+ module.
55
57
 
56
58
  ```bash
57
59
  pnpm add emdash-plugin-retouche sharp
58
60
  ```
59
61
 
60
- Ajoutez ensuite le plugin dans `plugins` de l'intégration EmDash, dans `astro.config.mjs` :
62
+ Then add the plugin to `plugins` of the EmDash integration in `astro.config.mjs`:
61
63
 
62
64
  ```js
63
65
  import react from "@astrojs/react";
@@ -75,52 +77,57 @@ export default defineConfig({
75
77
  });
76
78
  ```
77
79
 
78
- Redéployez le site : un plugin natif n'est actif qu'après un nouveau build.
80
+ Redeploy the site: a native plugin is only active after a new build.
81
+
82
+ The package declares `@cloudflare/kumo` at the exact version `2.19.0`, the one used by the EmDash
83
+ 1.6 admin. If an EmDash release moves to another Kumo version, the plugin has to be updated with it.
79
84
 
80
- Le paquet déclare `@cloudflare/kumo` en version exacte `2.19.0`, celle de l'admin d'EmDash 1.6.
81
- Si une version d'EmDash change de version de Kumo, il faudra mettre à jour le plugin en même temps.
85
+ The image is chosen with `MediaPickerModal`, exported by `@emdash-cms/admin`, the package of the
86
+ EmDash admin. The plugin declares it as a peer dependency with the same range as `emdash`. The site
87
+ must resolve a single copy of it, the one `emdash` uses: the picker relies on the admin's query
88
+ client and translations, and a second copy would not find them. pnpm installs the peer on its own and
89
+ shares the copy when the versions match. This component is exported but not described in the plugin
90
+ documentation, so an EmDash release can change it without notice.
82
91
 
83
- ## Accès et permissions
92
+ ## Access and permissions
84
93
 
85
- Le plugin est natif parce que sa page d'admin est en React et qu'il exécute `sharp` dans le
86
- processus du site. Il n'est donc pas isolé : il a les mêmes droits que le site. Les capacités
87
- ci-dessous limitent ce que lui expose `ctx`, mais ne l'isolent pas du reste du processus.
94
+ The plugin is native because its admin page is written in React and it runs `sharp` inside the site
95
+ process. It is therefore not sandboxed: it has the same rights as the site. The capabilities below
96
+ limit what `ctx` exposes to it, but do not isolate it from the rest of the process.
88
97
 
89
- | Capacité | Usage |
98
+ | Capability | Use |
90
99
  | --- | --- |
91
- | `media:read` | lister les images et lire leurs métadonnées |
92
- | `media:bytes:read` | lire le fichier de l'image à retoucher (16 Mio au plus) |
93
- | `media:write` | ajouter l'image retouchée à la médiathèque |
100
+ | `media:read` | read the metadata of the image to retouch |
101
+ | `media:bytes:read` | read the file of the image to retouch (16 MiB at most) |
102
+ | `media:write` | add the retouched image to the media library |
94
103
 
95
- Le plugin n'appelle jamais `ctx.media.delete()` et ne modifie aucun média existant.
104
+ The plugin never calls `ctx.media.delete()` and never modifies an existing media item.
96
105
 
97
- Routes, toutes privées, sous `/_emdash/api/plugins/retouche/` :
106
+ Routes, all private, under `/_emdash/api/plugins/retouche/`:
98
107
 
99
- | Route | Méthode | Permission | Rôle |
108
+ | Route | Method | Permission | Role |
100
109
  | --- | --- | --- | --- |
101
- | `images` | GET | `media:read` | liste paginée des images JPEG, PNG, WebP, AVIF et GIF |
102
- | `preview` | POST | `media:read` | aperçu JPEG en 900 px, renvoyé en data URL |
103
- | `save` | POST | `media:upload` | retouche en 2000 px et ajout à la médiathèque |
104
-
105
- Le plugin n'a ni réglage, ni stockage, ni accès réseau.
106
-
107
- ## Limites connues
108
-
109
- - La photo d'origine ne doit pas dépasser 16 Mio, plafond de `ctx.media.readBytes()` dans EmDash.
110
- - EmDash 1.6 ne transmet pas les octets d'un fichier au hook `media:beforeUpload` : la retouche ne
111
- peut pas s'appliquer à l'envoi et reste une action manuelle.
112
- - Pas de bouton « Retoucher » sur les champs image des contenus. Un widget de champ remplace tout
113
- l'éditeur du champ, et un panneau d'éditeur qui remplacerait l'image demanderait les capacités
114
- `admin.editor-draft:read` et `admin.editor-draft:patch`, hors du périmètre de cette version.
115
- - Le texte alternatif et la légende de l'original ne sont pas recopiés sur l'image retouchée : cela
116
- demanderait la capacité `media:metadata:write`.
117
- - Retoucher deux fois la même image crée deux médias distincts portant le même nom
118
- `<nom>-retouche.jpg`.
119
- - L'interface est en français uniquement.
120
- - Le flou prolonge les bords de l'image : dans l'angle le plus sombre d'une photo très inégalement
121
- éclairée, le papier peut rester légèrement gris, comme avec la retouche d'origine sous PIL.
122
-
123
- ## Développement
110
+ | `preview` | POST | `media:read` | 900 px JPEG preview, returned as a data URL |
111
+ | `save` | POST | `media:upload` | 2000 px retouch added to the media library |
112
+
113
+ The plugin has no settings, no storage and no network access.
114
+
115
+ ## Known limitations
116
+
117
+ - The original photo must not exceed 16 MiB, the cap of `ctx.media.readBytes()` in EmDash.
118
+ - EmDash 1.6 does not pass the file bytes to the `media:beforeUpload` hook: the retouch cannot run on
119
+ upload and stays a manual action.
120
+ - No "Retouch" button on the image fields of content entries. A field widget replaces the whole field
121
+ editor, and an editor panel that replaced the image would need the `admin.editor-draft:read` and
122
+ `admin.editor-draft:patch` capabilities, outside the scope of this version.
123
+ - The alt text and caption of the original are not copied to the retouched image: that would need
124
+ the `media:metadata:write` capability.
125
+ - Retouching the same image twice creates two separate media items with the same
126
+ `<name>-retouched.jpg` name.
127
+ - The blur extends the image edges: in the darkest corner of a very unevenly lit photo, the paper can
128
+ stay slightly grey, as with the original PIL retouch.
129
+
130
+ ## Development
124
131
 
125
132
  ```bash
126
133
  pnpm install
@@ -130,20 +137,24 @@ pnpm install
130
137
  pnpm check
131
138
  ```
132
139
 
133
- `pnpm check` enchaîne ESLint, `tsc --noEmit`, Vitest et le build tsdown ; la CI GitHub Actions lance les
134
- mêmes étapes. La publication sur npm passe par un tag, comme le décrit [RELEASING.md](RELEASING.md). Les tests génèrent leurs
135
- propres images : une feuille synthétique avec un dégradé d'éclairage, un papier teinté, une grille
136
- de traits et une pastille rouge. Le dépôt ne contient aucune photo de dessin réel.
140
+ `pnpm check` runs ESLint, `tsc --noEmit`, Vitest and the tsdown build; the GitHub Actions CI runs the
141
+ same steps. Publishing to npm goes through a tag, as described in [RELEASING.md](RELEASING.md). The
142
+ tests generate their own images: a synthetic sheet with a lighting gradient, tinted paper, a stroke
143
+ grid and a red disc. The repository contains no photo of a real drawing.
137
144
 
138
- Pour essayer le plugin dans un site local sans le publier :
145
+ To try the plugin in a local site without publishing it:
139
146
 
140
147
  ```bash
141
148
  pnpm add ../emdash-plugin-retouche
142
149
  ```
143
150
 
144
- La page d'admin (`src/admin/`) est livrée en source TypeScript : c'est le build Vite du site qui la
145
- compile, avec ses propres React et Kumo.
151
+ Translations live in `src/admin/i18n/`, one catalogue per language typed by the `Messages` interface.
152
+ Adding a language means adding a catalogue and a case in `messagesFor()`. The routes return an
153
+ English message for logs and API clients, plus an `error.code` that the admin translates.
154
+
155
+ The admin page (`src/admin/`) ships as TypeScript source: the site's Vite build compiles it, with
156
+ the site's own React and Kumo.
146
157
 
147
- ## Licence
158
+ ## License
148
159
 
149
160
  [MIT](LICENSE)
package/dist/index.d.mts CHANGED
@@ -1,20 +1,20 @@
1
1
  import { PluginDescriptor, ResolvedPlugin } from "emdash";
2
- declare const PRESETS: readonly ["crayon", "couleur"];
2
+ declare const PRESETS: readonly ["pencil", "color"];
3
3
  type Preset = (typeof PRESETS)[number];
4
- interface RetoucheOptions {
4
+ interface RetouchOptions {
5
5
  readonly preset: Preset;
6
- /** De 0 (image d'origine redimensionnée) à 1 (retouche complète). */
6
+ /** From 0 (resized original image) to 1 (full retouch). */
7
7
  readonly intensity: number;
8
8
  readonly maxWidth: number;
9
9
  }
10
- interface RetoucheResult {
11
- /** Copie indépendante : `jpeg.buffer` contient exactement le fichier. */
10
+ interface RetouchResult {
11
+ /** Independent copy: `jpeg.buffer` holds exactly the file. */
12
12
  readonly jpeg: Uint8Array<ArrayBuffer>;
13
13
  readonly width: number;
14
14
  readonly height: number;
15
15
  }
16
- export declare function retoucher(input: Uint8Array, options: RetoucheOptions): Promise<RetoucheResult>;
17
- /** À placer dans `plugins: []` de l'intégration `emdash()`, dans `astro.config.mjs`. */
16
+ export declare function retouch(input: Uint8Array, options: RetouchOptions): Promise<RetouchResult>;
17
+ /** Add to `plugins: []` of the `emdash()` integration in `astro.config.mjs`. */
18
18
  export declare function retouchePlugin(): PluginDescriptor;
19
19
  export declare function createPlugin(): ResolvedPlugin;
20
- export type { Preset, RetoucheOptions, RetoucheResult };
20
+ export type { Preset, RetouchOptions, RetouchResult };