@paperpic/react 0.0.0-stage → 0.1.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.
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: Viewer
3
+ description: How people zoom, pan and fit a document image in PaperPic, what the toolbar offers, and how to show an image read-only, with a live demo.
4
+ ---
5
+
6
+ # Viewer
7
+
8
+ Small print and long receipts are hard to read at a glance on a screen. The viewer fits the image when it loads and lets people zoom into any part of it.
9
+
10
+ <Demo src="/samples/receipt.jpg" alt="A receipt" :editable="false" />
11
+
12
+ ## Zoom and pan
13
+
14
+ | Action | Mouse and trackpad | Touch | Keyboard |
15
+ | ------------------------------- | ----------------------------- | ---------- | ----------- |
16
+ | Zoom | Wheel, or pinch on a trackpad | Pinch | `+` and `-` |
17
+ | Pan | Drag | Drag | Arrow keys |
18
+ | Switch between the fit and 100% | Double click | Double tap | |
19
+ | Fit the whole image | | | `0` |
20
+
21
+ The keyboard works with the focus on the viewer. A pinch zooms around the point between the fingers. On a touch screen, one finger scrolls the page while the image is fitted, and pans the image once it is zoomed in.
22
+
23
+ The zoom goes from the fit of the whole image, or 100% for a small image, up to 800%. An image that fits stays centered, and one that overflows pans up to its edges.
24
+
25
+ When the image loads, it fits the viewer whole, and it keeps its fit when the viewer changes size, until the user zooms by hand.
26
+
27
+ In a long page, the wheel would zoom the image instead of scrolling the page. Set `wheelZoom: false` there: the buttons, the keyboard and a pinch on a touch screen still zoom.
28
+
29
+ ## The toolbar
30
+
31
+ The toolbar sits at the right of the viewer, and scrolls when the viewer is too short for its buttons. It hides while editing, so it never covers a corner of Crop or Straighten.
32
+
33
+ | Button | What it does |
34
+ | --------------------------- | ---------------------------------------------------------------- |
35
+ | Edit | Starts the [edit mode](./editing). Hidden with `editable: false` |
36
+ | Zoom in, Zoom out | Zoom one step, around the center |
37
+ | Fit to width, Fit to height | Fit the width, which suits long documents, or the height |
38
+ | Rotate left, Rotate right | Only in a read-only viewer: turn the image on display |
39
+ | Download | Only with `download: true`: save the image on display |
40
+
41
+ With `toolbar: false`, the toolbar and the edit bar are hidden, and you can build your own controls with the [methods](../reference/methods).
42
+
43
+ ## Read-only viewer {#read-only}
44
+
45
+ With `editable: false`, the Edit button goes away, and the toolbar gets two buttons that rotate the image. That rotation only changes the display, and nothing is saved. Use it for documents that people should read but not change, such as the attachments of a record.
46
+
47
+ :::tabs key:framework
48
+ == JavaScript
49
+
50
+ ```ts
51
+ const pic = new PaperPic(container, {
52
+ src: '/receipt.jpg',
53
+ alt: 'A receipt',
54
+ editable: false,
55
+ })
56
+ ```
57
+
58
+ == Vue
59
+
60
+ ```vue
61
+ <PaperPic src="/receipt.jpg" alt="A receipt" :editable="false" />
62
+ ```
63
+
64
+ == React
65
+
66
+ ```tsx
67
+ <PaperPic src="/receipt.jpg" alt="A receipt" editable={false} />
68
+ ```
69
+
70
+ :::
71
+
72
+ ## Control the view from code
73
+
74
+ The methods [`zoomIn()`](../reference/methods#zoomin), [`zoomOut()`](../reference/methods#zoomout), [`zoomTo()`](../reference/methods#zoomto) and [`fit()`](../reference/methods#fit) do what the buttons do, and [`getState()`](../reference/methods#getstate) tells you the zoom and the fit in effect:
75
+
76
+ ```ts
77
+ pic.fit('width')
78
+ pic.zoomTo(2)
79
+
80
+ const { zoom, fit } = pic.getState()
81
+ ```
@@ -0,0 +1,113 @@
1
+ ---
2
+ title: CSS tokens
3
+ description: The CSS custom properties that theme PaperPic, with their light and dark values, plus its stylesheet, its cascade layer, its public classes and the names of its controls.
4
+ ---
5
+
6
+ # CSS tokens
7
+
8
+ The tokens are CSS custom properties that change the look of the component without overriding its rules. Set them on `:root`, on an ancestor of the viewer or on `.paperpic`:
9
+
10
+ ```css
11
+ :root {
12
+ --paperpic-color-accent: #c2410c;
13
+ --paperpic-radius: 0;
14
+ }
15
+ ```
16
+
17
+ | Token | Light | Dark | Description |
18
+ | -------------------------------- | --------- | --------- | ------------------------------------- |
19
+ | `--paperpic-color-accent` | `#0a84ff` | `#5cb5ff` | Accent of the interface |
20
+ | `--paperpic-color-surface` | `#fff` | `#151e2e` | Background of the interface |
21
+ | `--paperpic-color-text` | `#1a263c` | `#f2f5f9` | Text of the interface |
22
+ | `--paperpic-radius` | `6px` | `6px` | Corner radius of the interface |
23
+ | `--paperpic-transition-duration` | `0.2s` | `0.2s` | Duration of the interface transitions |
24
+
25
+ ## Dark mode
26
+
27
+ The color tokens take their light or dark value with `light-dark()`, from the `color-scheme` of the page. Without `color-scheme` they are light. With `color-scheme: dark` they are dark, and with `color-scheme: light dark` they are dark when the system prefers a dark color scheme. [Styling](../guide/styling#dark-mode) shows how to set it.
28
+
29
+ To choose both values of a token, use `light-dark()` too:
30
+
31
+ ```css
32
+ :root {
33
+ --paperpic-color-accent: light-dark(#c2410c, #fb923c);
34
+ }
35
+ ```
36
+
37
+ ## Stylesheet
38
+
39
+ Each package ships one stylesheet. Import it once in your app:
40
+
41
+ :::tabs key:framework
42
+ == JavaScript
43
+
44
+ ```ts
45
+ import '@paperpic/core/style.css'
46
+ ```
47
+
48
+ == Vue
49
+
50
+ ```ts
51
+ import '@paperpic/vue/style.css'
52
+ ```
53
+
54
+ == React
55
+
56
+ ```ts
57
+ import '@paperpic/react/style.css'
58
+ ```
59
+
60
+ :::
61
+
62
+ Its rules live in the `paperpic` cascade layer, so any CSS of yours outside a layer overrides them, whatever its specificity. This includes global resets, such as a rule on `button`. With Tailwind CSS, name the order of the layers, as [Styling](../guide/styling#tailwind) shows.
63
+
64
+ ## Classes {#classes}
65
+
66
+ These classes are public: their names, and the elements they mark, stay stable between releases. The other classes of the component hold its layout together and can change in any release.
67
+
68
+ | Class | Element |
69
+ | ------------------------- | ----------------------------------------------------------------------------------------------------------- |
70
+ | `paperpic` | The root of the viewer |
71
+ | `paperpic-button` | Every button of the toolbar and the edit bar |
72
+ | `paperpic-button-danger` | Discard, in the question before discarding the changes |
73
+ | `paperpic-button-primary` | Apply, and Done in every tool |
74
+ | `paperpic-button-text` | The buttons of the question before discarding the changes |
75
+ | `paperpic-edit-bar` | The edit bar, a card at the bottom while editing |
76
+ | `paperpic-editing` | The root, while editing |
77
+ | `paperpic-handle` | A corner handle of Crop and Straighten |
78
+ | `paperpic-host` | The element that the Vue and React components render around the viewer |
79
+ | `paperpic-icon` | The icon of a button |
80
+ | `paperpic-status` | The message for screen readers, which also shows while the image loads or the changes apply, and on failure |
81
+ | `paperpic-status-visible` | The message, while it shows in the middle of the viewer |
82
+ | `paperpic-toolbar` | The toolbar at the right, hidden while editing |
83
+ | `paperpic-viewport` | The area that shows the image and takes the keyboard focus |
84
+
85
+ Buttons show their state with ARIA attributes, which you can select too:
86
+
87
+ | Attribute | State |
88
+ | ------------------------ | ------------------------------------------------------------------------------------------------ |
89
+ | `[aria-disabled='true']` | The button cannot act now. It keeps the keyboard focus, so it is not `disabled` |
90
+ | `[aria-pressed='true']` | The fit in effect, Fit to width or Fit to height, or the choice of Adjust that the ruler changes |
91
+
92
+ The hover and these states paint with `box-shadow`, which global resets of buttons leave alone. To restyle them, override `box-shadow` too.
93
+
94
+ ## Controls {#controls}
95
+
96
+ Every button, ruler and corner handle carries `data-paperpic-control`, with the key of its [label](./labels). Select it to style one control:
97
+
98
+ ```css
99
+ .paperpic-button[data-paperpic-control='edit'] {
100
+ color: var(--paperpic-color-accent);
101
+ }
102
+ ```
103
+
104
+ | Place | Values |
105
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
106
+ | Toolbar | `edit`, `zoomIn`, `zoomOut`, `fitWidth`, `fitHeight`, `rotateLeft`, `rotateRight`, `download` |
107
+ | Edit bar | `cancel`, `crop`, `perspective`, `rotateLeft`, `flip`, `adjust`, `threshold`, `undo`, `redo`, `apply` |
108
+ | Adjust and Clean up | `brightness` and `contrast`, the choices and their rulers, `threshold`, the switch, and `thresholdSensitivity`, its ruler |
109
+ | Every tool | `cancelTool`, `confirm` |
110
+ | Crop and Straighten | `zoomIn`, `zoomOut`, `cornerTopLeft`, `cornerTopRight`, `cornerBottomRight`, `cornerBottomLeft` |
111
+ | Question before discarding | `keepEditing`, `discard` |
112
+
113
+ `rotateLeft` names two buttons that never show at the same time: the one of a read-only viewer, which turns the display, and the one of the edit bar, which turns the image. So do `zoomIn` and `zoomOut`, in the toolbar and in a panel, and `threshold`, the button of Clean up and its switch. `brightness` and `contrast` name a choice and its ruler, which show together: add `button` or `input` to the selector to tell them apart.
@@ -0,0 +1,68 @@
1
+ ---
2
+ title: Events
3
+ description: The events of PaperPic and what each one carries, load, error, change, apply and download, with how to listen to them in JavaScript, Vue and React.
4
+ ---
5
+
6
+ # Events
7
+
8
+ Events tell your code what happens in the viewer. Listen to them with [`on()`](./methods#on). In Vue they are component events, such as `@apply`, and in React they are props, such as `onApply`.
9
+
10
+ :::tabs key:framework
11
+ == JavaScript
12
+
13
+ ```ts
14
+ pic.on('apply', ({ blob }) => upload(blob))
15
+ ```
16
+
17
+ == Vue
18
+
19
+ ```vue
20
+ <PaperPic :src @apply="({ blob }) => upload(blob)" />
21
+ ```
22
+
23
+ == React
24
+
25
+ ```tsx
26
+ <PaperPic src={src} onApply={({ blob }) => upload(blob)} />
27
+ ```
28
+
29
+ :::
30
+
31
+ ## `load`
32
+
33
+ - **Payload:** `{ width: number, height: number }`
34
+
35
+ The image is loaded and on display. `width` and `height` are its size in pixels.
36
+
37
+ ## `error`
38
+
39
+ - **Payload:** `{ error: Error }`
40
+
41
+ The image could not be loaded, or the edits could not be applied. After a failed Apply, the edit stays open.
42
+
43
+ ## `change`
44
+
45
+ - **Payload:** [`PaperPicState`](./state)
46
+
47
+ The user changed the view or the edit, such as by zooming, opening a tool or undoing. It also reports the start of Apply, with `busy: true`. `setOptions()` and the props of the components never emit it.
48
+
49
+ ## `apply`
50
+
51
+ - **Payload:** `{ blob: Blob, width: number, height: number, type: string }`
52
+
53
+ The user applied the edits, and the result is already on display. `blob` holds the image in the format `type`, which [`output`](./options#output) chooses.
54
+
55
+ ## `download`
56
+
57
+ - **Payload:** `{ source: string | Blob, filename: string, preventDefault: () => void }`
58
+
59
+ The image is about to be saved, from the download button or from [`download()`](./methods#download). `source` is the image on display: the result of the last Apply, or else the `src`. `filename` is the name of the file.
60
+
61
+ Call `preventDefault()` to stop the browser from saving the file, such as to save it another way:
62
+
63
+ ```ts
64
+ pic.on('download', ({ source, filename, preventDefault }) => {
65
+ preventDefault()
66
+ saveToCloud(source, filename)
67
+ })
68
+ ```
@@ -0,0 +1,70 @@
1
+ ---
2
+ title: Labels
3
+ description: Every text of the PaperPic interface, with its key and its English default, to translate the component or change its wording.
4
+ ---
5
+
6
+ # Labels
7
+
8
+ Labels are the texts that the component shows, and the ones it announces to screen readers. They are in English by default. Pass the ones you want to change to the [`labels`](./options#labels) option, and the others keep their English text.
9
+
10
+ ```ts
11
+ const pic = new PaperPic(container, {
12
+ src: '/receipt.jpg',
13
+ labels: {
14
+ apply: 'Aplicar',
15
+ cancel: 'Cancelar',
16
+ zoomLevel: percent => `Zoom ${percent} %`,
17
+ },
18
+ })
19
+ ```
20
+
21
+ Five labels are functions, because their text includes a value. Create the object once, and not on every render, so the viewer does not receive it again each time.
22
+
23
+ | Key | English | Use |
24
+ | ---------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
25
+ | `adjust` | Adjust | The button that opens the ruler of brightness and contrast |
26
+ | `adjustmentLevel` | Brightness +30 | Function of the name and the value from -100 to 100, announced after moving the ruler of Adjust |
27
+ | `applied` | Changes applied | Announced when the changes are applied |
28
+ | `apply` | Apply | The button that applies the changes |
29
+ | `applyError` | The changes could not be applied | Shown when Apply fails |
30
+ | `brightness` | Brightness | The choice of brightness in Adjust, and the name of its ruler |
31
+ | `cancel` | Cancel | The button that leaves the edit mode |
32
+ | `cancelTool` | Cancel this tool | The button that closes a tool and discards its changes |
33
+ | `confirm` | Done | The button that closes a tool and keeps its changes |
34
+ | `contrast` | Contrast | The choice of contrast in Adjust, and the name of its ruler |
35
+ | `cornerBottomLeft` | Bottom left corner | The name of a corner handle |
36
+ | `cornerBottomRight` | Bottom right corner | The name of a corner handle |
37
+ | `cornerMoved` | Top left corner: 120, 80 | Function of the corner and its position in pixels of the image, announced after moving a corner |
38
+ | `cornerSelected` | Top left corner: tap where it goes | Function of the corner, shown and announced after pressing a corner handle, until a tap on the image moves it |
39
+ | `cornerTopLeft` | Top left corner | The name of a corner handle |
40
+ | `cornerTopRight` | Top right corner | The name of a corner handle |
41
+ | `crop` | Crop | The Crop button |
42
+ | `cropHint` | Drag the corners | What to do in Crop |
43
+ | `discard` | Discard | The button that confirms losing the changes |
44
+ | `discardQuestion` | Discard your changes? | The question before losing the changes |
45
+ | `download` | Download | The download button |
46
+ | `edit` | Edit | The button that starts editing |
47
+ | `editBar` | Editing controls | The name of the edit bar, for screen readers |
48
+ | `editing` | Editing | Announced when the edit mode starts |
49
+ | `fitHeight` | Fit to height | The button that fits the height of the image |
50
+ | `fitWidth` | Fit to width | The button that fits the width of the image |
51
+ | `flip` | Flip | The Flip button |
52
+ | `inUse` | In use | The description of Adjust or Clean up while its setting is in effect, which a dot shows |
53
+ | `keepEditing` | Keep editing | The button that goes back to editing instead of losing the changes |
54
+ | `loadError` | The image could not be loaded | Shown when the image fails to load |
55
+ | `loading` | Loading image | Shown while the image loads |
56
+ | `perspective` | Straighten | The Straighten button |
57
+ | `perspectiveHint` | Drag each corner to a corner of the document | What to do in Straighten |
58
+ | `processing` | Applying changes | Shown while Apply runs |
59
+ | `redo` | Redo | The Redo button |
60
+ | `rotateLeft` | Rotate left | The rotate button of the edit bar, and one of the two of a read-only viewer |
61
+ | `rotateRight` | Rotate right | The other rotate button of a read-only viewer |
62
+ | `threshold` | Clean up | The Clean up button, and the switch that turns it on and off |
63
+ | `thresholdLevel` | Sensitivity 50% | Function of the percent, announced after moving the ruler of Clean up |
64
+ | `thresholdSensitivity` | Sensitivity | The name of the ruler of Clean up |
65
+ | `toolbar` | Image controls | The name of the toolbar, for screen readers |
66
+ | `undo` | Undo | The Undo button |
67
+ | `viewer` | Image viewer | The name of the area that shows the image, for screen readers |
68
+ | `zoomIn` | Zoom in | The zoom in button, in the toolbar and in the panels of Crop and Straighten |
69
+ | `zoomLevel` | Zoom 150% | Function of the percent, announced after zooming from the toolbar or the keyboard |
70
+ | `zoomOut` | Zoom out | The zoom out button, in the toolbar and in the panels of Crop and Straighten |
@@ -0,0 +1,228 @@
1
+ ---
2
+ title: Methods
3
+ description: Every method of the PaperPic class, to control the viewer from your own code, such as zoom, fit, rotate, edit, apply, download and reload.
4
+ ---
5
+
6
+ # Methods
7
+
8
+ The methods control the viewer from your own code, such as from buttons of your own with [`toolbar: false`](./options#toolbar). In Vue and React, the component ref gives you the viewer: see [Vue](./vue) and [React](./react).
9
+
10
+ ```ts
11
+ import { PaperPic } from '@paperpic/core'
12
+
13
+ const pic = new PaperPic(container, { src: '/receipt.jpg' })
14
+
15
+ pic.zoomIn()
16
+ ```
17
+
18
+ ## Create and destroy
19
+
20
+ ### `new PaperPic()`
21
+
22
+ ```ts
23
+ class PaperPic {
24
+ constructor(container: HTMLElement, options?: PaperPicOptions)
25
+ }
26
+ ```
27
+
28
+ Creates the viewer inside `container`, which it fills. Give the container a height, or the viewer stays at its minimum height. [Options](./options) lists what `options` takes.
29
+
30
+ It throws a `TypeError` if `container` is not an element. Create the viewer once the element exists, such as on mount.
31
+
32
+ ### `destroy()`
33
+
34
+ ```ts
35
+ function destroy(): void
36
+ ```
37
+
38
+ Removes the viewer and releases everything it holds, such as its worker and the memory of its images. Calling it twice is safe.
39
+
40
+ ## Options and state
41
+
42
+ ### `setOptions()`
43
+
44
+ ```ts
45
+ function setOptions(options: PaperPicOptions): void
46
+ ```
47
+
48
+ Changes the options you pass and keeps the others. `undefined` brings an option back to its default. It never emits `change`, so two-way bindings do not loop.
49
+
50
+ ### `getState()`
51
+
52
+ ```ts
53
+ function getState(): PaperPicState
54
+ ```
55
+
56
+ Returns what the viewer is showing, such as the zoom, the mode and whether there are changes to apply. [State](./state) describes every field.
57
+
58
+ ### `on()`
59
+
60
+ ```ts
61
+ function on(name: keyof PaperPicEvents, listener: (payload) => void): () => void
62
+ ```
63
+
64
+ Listens to an event, and returns a function that stops listening. [Events](./events) describes each event.
65
+
66
+ ```ts
67
+ const off = pic.on('apply', ({ blob }) => upload(blob))
68
+
69
+ off()
70
+ ```
71
+
72
+ ## View
73
+
74
+ ### `zoomIn()`
75
+
76
+ ```ts
77
+ function zoomIn(): void
78
+ ```
79
+
80
+ Zooms in one step, around the center of the viewer.
81
+
82
+ ### `zoomOut()`
83
+
84
+ ```ts
85
+ function zoomOut(): void
86
+ ```
87
+
88
+ Zooms out one step, around the center of the viewer.
89
+
90
+ ### `zoomTo()`
91
+
92
+ ```ts
93
+ function zoomTo(zoom: number, point?: { x: number, y: number }): void
94
+ ```
95
+
96
+ Sets the zoom, where `1` shows one pixel of the image per screen pixel. `point` stays in place: it is in CSS pixels from the top left corner of the viewer, and its center by default.
97
+
98
+ The zoom goes from the fit of the whole image, or `1` if that is smaller, up to `8`. A value out of range is clamped.
99
+
100
+ ### `fit()`
101
+
102
+ ```ts
103
+ function fit(fit: 'image' | 'width' | 'height'): void
104
+ ```
105
+
106
+ Fits the whole image, its width or its height to the viewer.
107
+
108
+ ## Editing
109
+
110
+ ### `edit()`
111
+
112
+ ```ts
113
+ function edit(): void
114
+ ```
115
+
116
+ Starts editing. It does nothing if the image is not ready or [`editable`](./options#editable) is `false`.
117
+
118
+ ### `rotate()`
119
+
120
+ ```ts
121
+ function rotate(direction?: 1 | -1): void
122
+ ```
123
+
124
+ Turns the image a quarter turn: clockwise with `1`, the default, and counterclockwise with `-1`. While editing, it is an edit that [`apply()`](#apply) makes permanent. In a read-only viewer, it only changes the display. Otherwise, it does nothing.
125
+
126
+ ### `flip()`
127
+
128
+ ```ts
129
+ function flip(): void
130
+ ```
131
+
132
+ Mirrors the image left to right as it is on display, so after a quarter turn it still mirrors left to right. To turn the image upside down, flip it and rotate it twice. It is an edit, and it does nothing outside the edit mode or while a tool is open.
133
+
134
+ ### `openTool()`
135
+
136
+ ```ts
137
+ function openTool(id: ToolId): void
138
+ ```
139
+
140
+ Opens a tool with a panel: Crop, with `'crop'`, Straighten, with `'perspective'`, Adjust, with `'adjust'`, or Clean up, with `'threshold'`, which turns on as it opens. The tool stays open until [`confirmTool()`](#confirmtool) or [`cancelTool()`](#canceltool), and meanwhile the other edits, Undo, Redo and Apply do nothing. It does nothing outside the edit mode, while another tool is open, for Adjust while Clean up is on, and for Crop and Straighten while a preview is on its way.
141
+
142
+ ### `confirmTool()`
143
+
144
+ ```ts
145
+ function confirmTool(): void
146
+ ```
147
+
148
+ Closes the open tool and adds what it chose to the edits, as `Enter` does: the selection of Crop or Straighten, or the settings of Adjust or Clean up, as one edit.
149
+
150
+ ### `cancelTool()`
151
+
152
+ ```ts
153
+ function cancelTool(): void
154
+ ```
155
+
156
+ Closes the open tool and discards its changes, as `Esc` does.
157
+
158
+ ### `setThreshold()`
159
+
160
+ ```ts
161
+ function setThreshold(setting: { enabled?: boolean, sensitivity?: number }): void
162
+ ```
163
+
164
+ Turns Clean up on or off, or changes its sensitivity, from 0 to 1. Clean up always runs after the other edits. While Clean up is open, it changes what Clean up shows, and [`confirmTool()`](#confirmtool) keeps it as one edit. It does nothing outside the edit mode or while another tool is open.
165
+
166
+ It throws a `RangeError` if `sensitivity` is not between 0 and 1.
167
+
168
+ ### `setAdjustments()`
169
+
170
+ ```ts
171
+ function setAdjustments(setting: { brightness?: number, contrast?: number }): void
172
+ ```
173
+
174
+ Changes the brightness or the contrast, each from -1 to 1, where 0 leaves the image as it is. They run after the other edits. While Adjust is open, it changes what Adjust shows, and [`confirmTool()`](#confirmtool) keeps it as one edit. It does nothing outside the edit mode, while another tool is open or while Clean up is on, because a cleaned up document has tones of its own.
175
+
176
+ It throws a `RangeError` if a value is not between -1 and 1.
177
+
178
+ ### `undo()`
179
+
180
+ ```ts
181
+ function undo(): void
182
+ ```
183
+
184
+ Undoes the last edit.
185
+
186
+ ### `redo()`
187
+
188
+ ```ts
189
+ function redo(): void
190
+ ```
191
+
192
+ Brings back the last edit undone.
193
+
194
+ ### `apply()`
195
+
196
+ ```ts
197
+ function apply(): Promise<void>
198
+ ```
199
+
200
+ Applies the edits at full resolution, or at [`maxOutputSize`](./options#maxoutputsize). The result becomes the image on display, the history empties, the viewer goes back to the view mode, and the [`apply`](./events#apply) event carries the result. Apply cannot be interrupted, and it blocks the controls while it runs.
201
+
202
+ If it fails, the [`error`](./events#error) event reports it and the edit stays open.
203
+
204
+ ### `cancel()`
205
+
206
+ ```ts
207
+ function cancel(): void
208
+ ```
209
+
210
+ Discards the edits and goes back to the view mode. It does not ask first: the built-in Cancel button and `Esc` do.
211
+
212
+ ## Image
213
+
214
+ ### `download()`
215
+
216
+ ```ts
217
+ function download(): void
218
+ ```
219
+
220
+ Saves the image on display as a file: the result of the last Apply, or else the source. It works without the [`download`](./options#download) option, which only shows a button. The [`download`](./events#download) event comes first and can stop it. It does nothing while editing, because the edits are not applied yet.
221
+
222
+ ### `reload()`
223
+
224
+ ```ts
225
+ function reload(): void
226
+ ```
227
+
228
+ Loads the current [`src`](./options#src) again, which brings back the original after an Apply.