@sealpixel/ui 1.0.0-rc.20 → 1.0.0-rc.22
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/dist/components/editor/empty-state.d.ts +14 -0
- package/dist/components/editor/empty-state.js +38 -0
- package/dist/components/editor/empty-state.js.map +1 -0
- package/dist/components/editor/json-attribute.d.ts +5 -0
- package/dist/components/editor/json-attribute.js +18 -0
- package/dist/components/editor/json-attribute.js.map +1 -0
- package/dist/components/editor/panel-fit.d.ts +20 -0
- package/dist/components/editor/panel-fit.js +60 -0
- package/dist/components/editor/panel-fit.js.map +1 -0
- package/dist/components/editor/styles.d.ts +2 -0
- package/dist/components/editor/styles.js +697 -0
- package/dist/components/editor/styles.js.map +1 -0
- package/dist/components/editor/toast.d.ts +8 -0
- package/dist/components/editor/toast.js +21 -0
- package/dist/components/editor/toast.js.map +1 -0
- package/dist/components/sealpixel-editor.d.ts +9 -44
- package/dist/components/sealpixel-editor.js +45 -888
- package/dist/components/sealpixel-editor.js.map +1 -1
- package/dist/components/sealpixel-stage.js +11 -2
- package/dist/components/sealpixel-stage.js.map +1 -1
- package/dist/controllers/history-shortcuts-controller.d.ts +18 -0
- package/dist/controllers/history-shortcuts-controller.js +68 -0
- package/dist/controllers/history-shortcuts-controller.js.map +1 -0
- package/dist/locales/de.js +16 -0
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +16 -0
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +16 -0
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fr.js +16 -0
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/ja.js +16 -0
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/pt.js +16 -0
- package/dist/locales/pt.js.map +1 -1
- package/dist/tools/annotate.d.ts +58 -0
- package/dist/tools/annotate.js +136 -12
- package/dist/tools/annotate.js.map +1 -1
- package/dist/tools/assist.d.ts +3 -0
- package/dist/tools/assist.js +44 -9
- package/dist/tools/assist.js.map +1 -1
- package/dist/tools/crop-mask.d.ts +2 -0
- package/dist/tools/crop-mask.js +11 -0
- package/dist/tools/crop-mask.js.map +1 -1
- package/dist/tools/crop.d.ts +9 -0
- package/dist/tools/crop.js +117 -48
- package/dist/tools/crop.js.map +1 -1
- package/dist/tools/filter.js +41 -19
- package/dist/tools/filter.js.map +1 -1
- package/dist/tools/finetune.js +10 -7
- package/dist/tools/finetune.js.map +1 -1
- package/dist/tools/frame.js +10 -10
- package/dist/tools/frame.js.map +1 -1
- package/dist/tools/instance-state.d.ts +8 -0
- package/dist/tools/instance-state.js +32 -0
- package/dist/tools/instance-state.js.map +1 -0
- package/dist/tools/keys.d.ts +95 -3
- package/dist/tools/keys.js +135 -2
- package/dist/tools/keys.js.map +1 -1
- package/dist/tools/redact.d.ts +18 -10
- package/dist/tools/redact.js +233 -35
- package/dist/tools/redact.js.map +1 -1
- package/dist/tools/region-transform.d.ts +23 -14
- package/dist/tools/region-transform.js +45 -32
- package/dist/tools/region-transform.js.map +1 -1
- package/dist/tools/resize.js +11 -9
- package/dist/tools/resize.js.map +1 -1
- package/dist/tools/sticker.js +7 -3
- package/dist/tools/sticker.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { canonicalJson, configurePlugins, createAssetResolver, createEditorSession, SealpixelError, } from '@sealpixel/core';
|
|
2
2
|
import { defaultPlugins } from '@sealpixel/plugins';
|
|
3
|
-
import {
|
|
3
|
+
import { html, LitElement, nothing } from 'lit';
|
|
4
|
+
import { HistoryShortcutsController } from '../controllers/history-shortcuts-controller.js';
|
|
4
5
|
import { SessionController } from '../controllers/session-controller.js';
|
|
5
6
|
import { createI18n } from '../i18n.js';
|
|
6
7
|
import { resolveLocale } from '../locales/index.js';
|
|
7
8
|
import { base, tokens } from '../theme.js';
|
|
8
9
|
import { toolsFor } from '../tools/index.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(value);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
console.warn(`[sealpixel] ${name} is not valid JSON`);
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
toAttribute: (value) => (value ? JSON.stringify(value) : null),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
10
|
+
import { bindToolContext } from '../tools/instance-state.js';
|
|
11
|
+
import { renderEmpty } from './editor/empty-state.js';
|
|
12
|
+
import { jsonAttribute } from './editor/json-attribute.js';
|
|
13
|
+
import { syncPanelFill } from './editor/panel-fit.js';
|
|
14
|
+
import { editorStyles } from './editor/styles.js';
|
|
15
|
+
import { formatBytes, renderToast } from './editor/toast.js';
|
|
26
16
|
/**
|
|
27
17
|
* The default editor. Headless `EditorSession` underneath; this element adds
|
|
28
18
|
* the responsive shell, tools and events.
|
|
@@ -30,711 +20,8 @@ function jsonAttribute(name) {
|
|
|
30
20
|
* Events: `sealpixel:ready`, `sealpixel:load`, `sealpixel:change` ({ log, index }),
|
|
31
21
|
* `sealpixel:process` (ExportResult), `sealpixel:error` (SealpixelError).
|
|
32
22
|
*/
|
|
33
|
-
/**
|
|
34
|
-
* What makes a settings bar worth its height: a control, or anything that
|
|
35
|
-
* draws. Plain `div`s are the tools' own scaffolding and never count.
|
|
36
|
-
*/
|
|
37
|
-
const PANEL_CONTENT = 'select, input, textarea, button, img, svg, canvas, a, [role]';
|
|
38
23
|
export class SealpixelEditor extends LitElement {
|
|
39
|
-
static { this.styles = [
|
|
40
|
-
tokens,
|
|
41
|
-
base,
|
|
42
|
-
css `
|
|
43
|
-
:host {
|
|
44
|
-
display: block;
|
|
45
|
-
container-type: inline-size;
|
|
46
|
-
background: var(--sealpixel-color-bg);
|
|
47
|
-
color: var(--sealpixel-color-fg);
|
|
48
|
-
height: 100%;
|
|
49
|
-
min-height: 480px;
|
|
50
|
-
min-width: 0;
|
|
51
|
-
overflow: hidden;
|
|
52
|
-
}
|
|
53
|
-
:host(:focus) {
|
|
54
|
-
outline: none;
|
|
55
|
-
}
|
|
56
|
-
.root {
|
|
57
|
-
position: relative;
|
|
58
|
-
display: grid;
|
|
59
|
-
height: 100%;
|
|
60
|
-
min-width: 0;
|
|
61
|
-
grid-template:
|
|
62
|
-
'nav' auto
|
|
63
|
-
'stage' 1fr
|
|
64
|
-
'panel' auto
|
|
65
|
-
'toolbar' auto / 1fr;
|
|
66
|
-
padding-bottom: env(safe-area-inset-bottom);
|
|
67
|
-
}
|
|
68
|
-
.root > * {
|
|
69
|
-
min-width: 0;
|
|
70
|
-
min-height: 0;
|
|
71
|
-
}
|
|
72
|
-
sealpixel-stage {
|
|
73
|
-
grid-area: stage;
|
|
74
|
-
min-height: 160px;
|
|
75
|
-
}
|
|
76
|
-
sealpixel-nav {
|
|
77
|
-
grid-area: nav;
|
|
78
|
-
}
|
|
79
|
-
sealpixel-toolbar {
|
|
80
|
-
grid-area: toolbar;
|
|
81
|
-
}
|
|
82
|
-
.panel {
|
|
83
|
-
grid-area: panel;
|
|
84
|
-
background: var(--sealpixel-color-surface);
|
|
85
|
-
border-top: 1px solid var(--sealpixel-color-border);
|
|
86
|
-
padding: var(--sealpixel-space) calc(var(--sealpixel-space) * 1.5);
|
|
87
|
-
/*
|
|
88
|
-
* The configured height, not a fitted one: a bar that grew and shrank
|
|
89
|
-
* as the user moved between tools would resize the stage under them,
|
|
90
|
-
* and the image would shift every time they changed their mind.
|
|
91
|
-
*
|
|
92
|
-
* The exception is a tool whose settings do not fit at all. Then the
|
|
93
|
-
* bar takes the height they need, measured by syncPanelFit(), because
|
|
94
|
-
* the alternative is worse: a fixed-height wrapping flex container has
|
|
95
|
-
* no scrollable cross-axis overflow, so nothing scrolls and the sticky
|
|
96
|
-
* choice row is pulled up over the settings. 34cqh caps both heights,
|
|
97
|
-
* so a busy tool can never take the stage on a short viewport.
|
|
98
|
-
*/
|
|
99
|
-
height: min(34cqh, max(var(--sealpixel-panel-size), var(--sealpixel-panel-fit, 0px)));
|
|
100
|
-
overflow: auto;
|
|
101
|
-
/*
|
|
102
|
-
* A bottom bar lays its blocks across the width and wraps, where the
|
|
103
|
-
* old right-hand column stacked them. Stacking five blocks in a bar
|
|
104
|
-
* that is one or two rows tall would push the last of them out of
|
|
105
|
-
* sight, so a block takes a full row only when it asks for one.
|
|
106
|
-
*/
|
|
107
|
-
display: flex;
|
|
108
|
-
flex-wrap: wrap;
|
|
109
|
-
/*
|
|
110
|
-
* Safe centring places the blocks in the middle while they fit and
|
|
111
|
-
* at the start once they do not. Plain centring overflows a fixed bar
|
|
112
|
-
* at both ends, and nothing scrolls back to what sits above the top.
|
|
113
|
-
*/
|
|
114
|
-
align-items: center;
|
|
115
|
-
align-content: safe center;
|
|
116
|
-
justify-content: safe center;
|
|
117
|
-
gap: var(--sealpixel-space) calc(var(--sealpixel-space) * 2);
|
|
118
|
-
scrollbar-width: thin;
|
|
119
|
-
scroll-behavior: smooth;
|
|
120
|
-
}
|
|
121
|
-
/*
|
|
122
|
-
* A tool whose panel lays out to nothing gets no bar. Without this the
|
|
123
|
-
* fixed height above reserves an empty surface and takes it off the
|
|
124
|
-
* stage; see syncPanelFill(), which sets the attribute.
|
|
125
|
-
*/
|
|
126
|
-
.panel[data-empty] {
|
|
127
|
-
height: 0;
|
|
128
|
-
padding: 0;
|
|
129
|
-
border-top: 0;
|
|
130
|
-
overflow: hidden;
|
|
131
|
-
}
|
|
132
|
-
/*
|
|
133
|
-
* A dial needs room to be worth dragging, but it must not grow into all
|
|
134
|
-
* of it: a dial that stretches pushes the controls beside it against the
|
|
135
|
-
* two edges of the bar, and they stop reading as one group.
|
|
136
|
-
*/
|
|
137
|
-
.panel > sealpixel-slider {
|
|
138
|
-
flex: 0 1 360px;
|
|
139
|
-
min-width: 240px;
|
|
140
|
-
}
|
|
141
|
-
/* Chips, presets and asset libraries always get their own full row. */
|
|
142
|
-
.panel > .strip,
|
|
143
|
-
.panel > .grid {
|
|
144
|
-
flex: 1 1 100%;
|
|
145
|
-
}
|
|
146
|
-
.panel > .row,
|
|
147
|
-
.panel > .rows,
|
|
148
|
-
.panel > .field,
|
|
149
|
-
.panel > .hint {
|
|
150
|
-
flex: 0 1 auto;
|
|
151
|
-
}
|
|
152
|
-
/*
|
|
153
|
-
* A tool panel has two kinds of control: the choice of what to work with
|
|
154
|
-
* (a shape, a frame style, a preset, a parameter) and the settings for
|
|
155
|
-
* whatever is chosen. The choice belongs at the bottom, next to the tool
|
|
156
|
-
* rail it continues, and its settings appear above it. Side by side they
|
|
157
|
-
* read as one undifferentiated row of buttons and it is not obvious which
|
|
158
|
-
* of them changes what.
|
|
159
|
-
*
|
|
160
|
-
* Ordering here rather than in each tool keeps a panel's source in
|
|
161
|
-
* reading order and lets a third-party tool join in with one class.
|
|
162
|
-
*/
|
|
163
|
-
.panel > * {
|
|
164
|
-
order: 1;
|
|
165
|
-
}
|
|
166
|
-
/*
|
|
167
|
-
* Switching tools rebuilds the panel, so the rows rise on the new
|
|
168
|
-
* children and never on a value change inside the open tool, where Lit
|
|
169
|
-
* patches the same nodes.
|
|
170
|
-
*
|
|
171
|
-
* Transform only, deliberately. A fade would put the labels at partial
|
|
172
|
-
* opacity for a moment, and a contrast audit that samples the panel
|
|
173
|
-
* during that moment reports text it can read on screen as failing.
|
|
174
|
-
* Transform also keeps the panel's own height still, which the layout
|
|
175
|
-
* around it is measured against.
|
|
176
|
-
*/
|
|
177
|
-
.panel > * {
|
|
178
|
-
animation: sealpixel-panel-in var(--sealpixel-duration) var(--sealpixel-ease-out) both;
|
|
179
|
-
}
|
|
180
|
-
.panel > *:nth-child(2) {
|
|
181
|
-
animation-delay: 25ms;
|
|
182
|
-
}
|
|
183
|
-
.panel > *:nth-child(n + 3) {
|
|
184
|
-
animation-delay: 50ms;
|
|
185
|
-
}
|
|
186
|
-
@keyframes sealpixel-panel-in {
|
|
187
|
-
from {
|
|
188
|
-
transform: translateY(8px);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/* Phones: option grids become one horizontal strip so the stage keeps its height. */
|
|
192
|
-
.panel .grid,
|
|
193
|
-
.panel .strip {
|
|
194
|
-
display: flex;
|
|
195
|
-
gap: var(--sealpixel-space);
|
|
196
|
-
overflow-x: auto;
|
|
197
|
-
scrollbar-width: none;
|
|
198
|
-
padding-bottom: 2px;
|
|
199
|
-
scroll-snap-type: x proximity;
|
|
200
|
-
}
|
|
201
|
-
.panel .grid::-webkit-scrollbar,
|
|
202
|
-
.panel .strip::-webkit-scrollbar {
|
|
203
|
-
display: none;
|
|
204
|
-
}
|
|
205
|
-
.panel .grid > *,
|
|
206
|
-
.panel .strip > * {
|
|
207
|
-
flex: 0 0 auto;
|
|
208
|
-
min-width: 96px;
|
|
209
|
-
scroll-snap-align: start;
|
|
210
|
-
}
|
|
211
|
-
.panel .strip > * {
|
|
212
|
-
min-width: 0;
|
|
213
|
-
}
|
|
214
|
-
/*
|
|
215
|
-
* The strip centres while it fits and scrolls from the first item once
|
|
216
|
-
* it does not, so a short row of presets is not stranded at the left
|
|
217
|
-
* edge of a wide bar.
|
|
218
|
-
*/
|
|
219
|
-
.panel .strip {
|
|
220
|
-
justify-content: safe center;
|
|
221
|
-
align-items: end;
|
|
222
|
-
scroll-behavior: smooth;
|
|
223
|
-
}
|
|
224
|
-
.panel .chips {
|
|
225
|
-
gap: 2px;
|
|
226
|
-
}
|
|
227
|
-
/*
|
|
228
|
-
* A segmented control: one pill holds the row, the segments share it. Six
|
|
229
|
-
* separate buttons put six borders in a row and made the choice look like
|
|
230
|
-
* six unrelated actions; one container says they are one decision with
|
|
231
|
-
* one answer at a time.
|
|
232
|
-
*/
|
|
233
|
-
.panel .group {
|
|
234
|
-
display: inline-flex;
|
|
235
|
-
gap: 2px;
|
|
236
|
-
padding: 2px;
|
|
237
|
-
background: var(--sealpixel-color-surface-2);
|
|
238
|
-
border-radius: var(--sealpixel-radius-pill);
|
|
239
|
-
flex: 0 0 auto;
|
|
240
|
-
}
|
|
241
|
-
.panel .group sealpixel-button::part(button) {
|
|
242
|
-
background: transparent;
|
|
243
|
-
border-color: transparent;
|
|
244
|
-
min-height: calc(var(--sealpixel-control-height) - 4px);
|
|
245
|
-
min-width: calc(var(--sealpixel-control-height) - 4px);
|
|
246
|
-
padding: 0 calc(var(--sealpixel-space) * 1.25);
|
|
247
|
-
}
|
|
248
|
-
.panel .group sealpixel-button:hover::part(button) {
|
|
249
|
-
background: color-mix(in srgb, var(--sealpixel-color-fg) 7%, transparent);
|
|
250
|
-
}
|
|
251
|
-
.panel .group sealpixel-button[pressed]::part(button) {
|
|
252
|
-
background: var(--sealpixel-color-surface);
|
|
253
|
-
color: var(--sealpixel-color-accent);
|
|
254
|
-
box-shadow: var(--sealpixel-shadow-sm, none);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/* Filter tiles: the image is the control, the label only names it. */
|
|
258
|
-
.panel .tiles {
|
|
259
|
-
gap: calc(var(--sealpixel-space) * 0.75);
|
|
260
|
-
}
|
|
261
|
-
/*
|
|
262
|
-
* The one control in the bar that gets bigger. Everywhere else the chrome
|
|
263
|
-
* shrank; here the chrome is the point, because a preset is judged by
|
|
264
|
-
* looking at it.
|
|
265
|
-
*/
|
|
266
|
-
.panel .thumb {
|
|
267
|
-
display: block;
|
|
268
|
-
width: 100%;
|
|
269
|
-
height: 64px;
|
|
270
|
-
object-fit: cover;
|
|
271
|
-
border-radius: var(--sealpixel-radius);
|
|
272
|
-
background: var(--sealpixel-color-surface-2);
|
|
273
|
-
box-shadow: 0 0 0 1px var(--sealpixel-color-border);
|
|
274
|
-
transition:
|
|
275
|
-
box-shadow var(--sealpixel-duration) var(--sealpixel-ease),
|
|
276
|
-
transform var(--sealpixel-duration) var(--sealpixel-ease-spring);
|
|
277
|
-
}
|
|
278
|
-
.panel .tiles sealpixel-button {
|
|
279
|
-
min-width: 84px;
|
|
280
|
-
max-width: 84px;
|
|
281
|
-
}
|
|
282
|
-
.panel .tiles sealpixel-button::part(button) {
|
|
283
|
-
flex-direction: column;
|
|
284
|
-
gap: 6px;
|
|
285
|
-
padding: 0;
|
|
286
|
-
min-height: 0;
|
|
287
|
-
height: auto;
|
|
288
|
-
font-size: calc(var(--sealpixel-font-size) * 11 / 14);
|
|
289
|
-
background: transparent;
|
|
290
|
-
color: var(--sealpixel-color-fg-muted);
|
|
291
|
-
}
|
|
292
|
-
.panel .tiles sealpixel-button:hover .thumb {
|
|
293
|
-
transform: translateY(-2px);
|
|
294
|
-
}
|
|
295
|
-
.panel .tiles sealpixel-button[pressed] .thumb {
|
|
296
|
-
box-shadow:
|
|
297
|
-
0 0 0 2px var(--sealpixel-color-surface),
|
|
298
|
-
0 0 0 4px var(--sealpixel-color-accent);
|
|
299
|
-
}
|
|
300
|
-
.panel .tiles sealpixel-button[pressed]::part(button) {
|
|
301
|
-
background: transparent;
|
|
302
|
-
border-color: transparent;
|
|
303
|
-
color: var(--sealpixel-color-fg);
|
|
304
|
-
}
|
|
305
|
-
/* Separates the untouched image from the presets. */
|
|
306
|
-
.panel .divider {
|
|
307
|
-
flex: 0 0 auto;
|
|
308
|
-
align-self: stretch;
|
|
309
|
-
width: 1px;
|
|
310
|
-
min-width: 1px;
|
|
311
|
-
margin: 6px calc(var(--sealpixel-space) * 0.5);
|
|
312
|
-
background: var(--sealpixel-color-border);
|
|
313
|
-
opacity: 0.55;
|
|
314
|
-
}
|
|
315
|
-
.panel .row.compact > sealpixel-button {
|
|
316
|
-
flex: 0 0 auto;
|
|
317
|
-
min-width: 72px;
|
|
318
|
-
}
|
|
319
|
-
/* Phones: sibling groups share one line and hints make room for the stage. */
|
|
320
|
-
.panel .rows {
|
|
321
|
-
display: flex;
|
|
322
|
-
gap: var(--sealpixel-space);
|
|
323
|
-
align-items: end;
|
|
324
|
-
}
|
|
325
|
-
/*
|
|
326
|
-
* Content width, not an equal share. An equal share squeezed a text field
|
|
327
|
-
* and a colour well down to a few pixels each and their labels ran into
|
|
328
|
-
* one another; only a dial has a reason to take the leftover room.
|
|
329
|
-
*/
|
|
330
|
-
.panel .rows > * {
|
|
331
|
-
flex: 0 1 auto;
|
|
332
|
-
min-width: 0;
|
|
333
|
-
}
|
|
334
|
-
/*
|
|
335
|
-
* A dial needs travel to be worth dragging. Inside a settings row it was
|
|
336
|
-
* sharing the width equally with a colour swatch and a checkbox and ended
|
|
337
|
-
* up a few ticks wide, which is not a control any more. The row grows to
|
|
338
|
-
* give it that width instead of shrinking to its contents.
|
|
339
|
-
*/
|
|
340
|
-
/*
|
|
341
|
-
* A settings row scrolls sideways when it is wider than the bar, the way
|
|
342
|
-
* the choice row does. Letting it overflow instead left the last control
|
|
343
|
-
* cut off at the edge with nothing to say it was there.
|
|
344
|
-
*/
|
|
345
|
-
.panel > .rows {
|
|
346
|
-
flex: 0 1 auto;
|
|
347
|
-
max-width: 100%;
|
|
348
|
-
overflow-x: auto;
|
|
349
|
-
overflow-y: hidden;
|
|
350
|
-
scrollbar-width: none;
|
|
351
|
-
scroll-behavior: smooth;
|
|
352
|
-
padding-bottom: 1px;
|
|
353
|
-
}
|
|
354
|
-
.panel > .rows::-webkit-scrollbar {
|
|
355
|
-
display: none;
|
|
356
|
-
}
|
|
357
|
-
.panel > .rows > * {
|
|
358
|
-
flex-shrink: 0;
|
|
359
|
-
}
|
|
360
|
-
.panel .rows > sealpixel-slider {
|
|
361
|
-
flex: 0 1 260px;
|
|
362
|
-
min-width: 220px;
|
|
363
|
-
}
|
|
364
|
-
.panel .rows .row {
|
|
365
|
-
flex-wrap: nowrap;
|
|
366
|
-
}
|
|
367
|
-
.panel .rows .row > sealpixel-button {
|
|
368
|
-
flex: 1 1 0;
|
|
369
|
-
min-width: 0;
|
|
370
|
-
}
|
|
371
|
-
/*
|
|
372
|
-
* A field fills its label, but never shrinks to nothing: a text box a
|
|
373
|
-
* few pixels wide hides what was typed into it, and a select that narrow
|
|
374
|
-
* hides which option is chosen.
|
|
375
|
-
*/
|
|
376
|
-
.panel .rows select,
|
|
377
|
-
.panel .rows input:not([type='checkbox']):not([type='color']) {
|
|
378
|
-
width: 100%;
|
|
379
|
-
min-width: 7em;
|
|
380
|
-
}
|
|
381
|
-
.panel .rows input[type='text'],
|
|
382
|
-
.panel .rows textarea {
|
|
383
|
-
min-width: 11em;
|
|
384
|
-
}
|
|
385
|
-
.panel .rows > .field:has(input[type='color']),
|
|
386
|
-
.panel .rows > .field.check {
|
|
387
|
-
flex: 0 0 auto;
|
|
388
|
-
}
|
|
389
|
-
/* A colour well is square, which makes the disc round. */
|
|
390
|
-
.panel .rows > .field:has(input[type='color']) input {
|
|
391
|
-
width: var(--sealpixel-control-height);
|
|
392
|
-
aspect-ratio: 1;
|
|
393
|
-
}
|
|
394
|
-
.panel .swatches {
|
|
395
|
-
display: flex;
|
|
396
|
-
flex-wrap: wrap;
|
|
397
|
-
gap: 6px;
|
|
398
|
-
margin-bottom: 6px;
|
|
399
|
-
}
|
|
400
|
-
.panel .swatch {
|
|
401
|
-
width: 24px;
|
|
402
|
-
height: 24px;
|
|
403
|
-
border-radius: 50%;
|
|
404
|
-
border: 0;
|
|
405
|
-
box-shadow: 0 0 0 1px var(--sealpixel-color-border);
|
|
406
|
-
cursor: pointer;
|
|
407
|
-
padding: 0;
|
|
408
|
-
transition:
|
|
409
|
-
transform var(--sealpixel-duration) var(--sealpixel-ease-spring),
|
|
410
|
-
border-color var(--sealpixel-transition),
|
|
411
|
-
box-shadow var(--sealpixel-duration) var(--sealpixel-ease);
|
|
412
|
-
}
|
|
413
|
-
.panel .swatch:hover {
|
|
414
|
-
transform: scale(1.12);
|
|
415
|
-
}
|
|
416
|
-
.panel .swatch:active {
|
|
417
|
-
transform: scale(0.94);
|
|
418
|
-
}
|
|
419
|
-
/* The ring sits off the disc, so the colour itself is never covered. */
|
|
420
|
-
.panel .swatch[aria-pressed='true'] {
|
|
421
|
-
box-shadow:
|
|
422
|
-
0 0 0 2px var(--sealpixel-color-surface),
|
|
423
|
-
0 0 0 3.5px var(--sealpixel-color-accent);
|
|
424
|
-
}
|
|
425
|
-
.panel:empty {
|
|
426
|
-
display: none;
|
|
427
|
-
}
|
|
428
|
-
.toast {
|
|
429
|
-
position: absolute;
|
|
430
|
-
left: 50%;
|
|
431
|
-
bottom: calc(var(--sealpixel-toolbar-size) + var(--sealpixel-space) * 2);
|
|
432
|
-
/* Sits above the stage, never over the bar the user is working in. */
|
|
433
|
-
transform: translateX(-50%);
|
|
434
|
-
display: flex;
|
|
435
|
-
align-items: center;
|
|
436
|
-
gap: var(--sealpixel-space);
|
|
437
|
-
max-width: calc(100% - var(--sealpixel-space) * 4);
|
|
438
|
-
padding: calc(var(--sealpixel-space) * 1.25) calc(var(--sealpixel-space) * 2);
|
|
439
|
-
border-radius: 999px;
|
|
440
|
-
background: color-mix(in srgb, var(--sealpixel-color-surface) 92%, transparent);
|
|
441
|
-
border: 1px solid var(--sealpixel-color-border);
|
|
442
|
-
box-shadow: var(--sealpixel-shadow, 0 8px 24px rgba(0, 0, 0, 0.3));
|
|
443
|
-
color: var(--sealpixel-color-fg);
|
|
444
|
-
font-size: calc(var(--sealpixel-font-size) * 13 / 14);
|
|
445
|
-
white-space: nowrap;
|
|
446
|
-
backdrop-filter: blur(8px);
|
|
447
|
-
cursor: pointer;
|
|
448
|
-
z-index: 2;
|
|
449
|
-
animation: sealpixel-toast-in var(--sealpixel-duration) var(--sealpixel-ease-out) both;
|
|
450
|
-
}
|
|
451
|
-
.toast:hover {
|
|
452
|
-
border-color: var(--sealpixel-color-fg-muted);
|
|
453
|
-
}
|
|
454
|
-
.toast code {
|
|
455
|
-
font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
456
|
-
color: var(--sealpixel-color-fg-muted);
|
|
457
|
-
padding: 2px 8px;
|
|
458
|
-
border-radius: 999px;
|
|
459
|
-
background: var(--sealpixel-color-surface-2);
|
|
460
|
-
}
|
|
461
|
-
@keyframes sealpixel-toast-in {
|
|
462
|
-
from {
|
|
463
|
-
opacity: 0;
|
|
464
|
-
transform: translate(-50%, 12px) scale(0.96);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
/*
|
|
468
|
-
* Wide layouts move the tool rail to the left edge and nothing else. The
|
|
469
|
-
* panel stays a bottom bar at every width, so a control sits in the same
|
|
470
|
-
* place on a phone and on a desktop, and the stage keeps the full width
|
|
471
|
-
* it needs for a landscape image.
|
|
472
|
-
*/
|
|
473
|
-
@container (min-width: 48rem) {
|
|
474
|
-
/*
|
|
475
|
-
* The rail runs the full height beside both the stage and the bar.
|
|
476
|
-
* Stopping it above the bar cost it the bar's height, and with ten or
|
|
477
|
-
* more tools the last of them ended up scrolled out of sight behind
|
|
478
|
-
* the settings of the one already open.
|
|
479
|
-
*/
|
|
480
|
-
.root {
|
|
481
|
-
grid-template:
|
|
482
|
-
'nav nav' auto
|
|
483
|
-
'toolbar stage' 1fr
|
|
484
|
-
'toolbar panel' auto / var(--sealpixel-toolbar-size) 1fr;
|
|
485
|
-
}
|
|
486
|
-
.panel {
|
|
487
|
-
height: max(var(--sealpixel-panel-size), var(--sealpixel-panel-fit, 0px));
|
|
488
|
-
padding: var(--sealpixel-space) calc(var(--sealpixel-space) * 2);
|
|
489
|
-
}
|
|
490
|
-
.panel[data-empty] {
|
|
491
|
-
height: 0;
|
|
492
|
-
padding: 0;
|
|
493
|
-
}
|
|
494
|
-
.toast {
|
|
495
|
-
bottom: calc(var(--sealpixel-space) * 2);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
.panel .row {
|
|
499
|
-
display: flex;
|
|
500
|
-
gap: var(--sealpixel-space);
|
|
501
|
-
flex-wrap: wrap;
|
|
502
|
-
}
|
|
503
|
-
.panel > .choice {
|
|
504
|
-
order: 2;
|
|
505
|
-
flex: 1 1 100%;
|
|
506
|
-
justify-content: safe center;
|
|
507
|
-
/*
|
|
508
|
-
* Pinned to the foot of the bar. The choice is what gets the user out
|
|
509
|
-
* of the tool they are in, so it has to stay reachable even when a
|
|
510
|
-
* busy panel scrolls its settings.
|
|
511
|
-
*/
|
|
512
|
-
position: sticky;
|
|
513
|
-
bottom: 0;
|
|
514
|
-
z-index: 1;
|
|
515
|
-
background: var(--sealpixel-color-surface);
|
|
516
|
-
padding-top: 4px;
|
|
517
|
-
/*
|
|
518
|
-
* One line that scrolls, never two that wrap. A wrapped second line
|
|
519
|
-
* falls below the bar and takes whatever was on it out of reach, and
|
|
520
|
-
* on a phone that was the reset button.
|
|
521
|
-
*/
|
|
522
|
-
flex-wrap: nowrap;
|
|
523
|
-
overflow-x: auto;
|
|
524
|
-
overflow-y: hidden;
|
|
525
|
-
scrollbar-width: none;
|
|
526
|
-
scroll-behavior: smooth;
|
|
527
|
-
}
|
|
528
|
-
.panel > .choice::-webkit-scrollbar {
|
|
529
|
-
display: none;
|
|
530
|
-
}
|
|
531
|
-
.panel > .choice > * {
|
|
532
|
-
flex-shrink: 0;
|
|
533
|
-
}
|
|
534
|
-
.panel .field {
|
|
535
|
-
display: grid;
|
|
536
|
-
gap: 3px;
|
|
537
|
-
justify-items: center;
|
|
538
|
-
color: var(--sealpixel-color-fg-muted);
|
|
539
|
-
}
|
|
540
|
-
/* The label names the control; it is not the thing being read. */
|
|
541
|
-
.panel .field > span,
|
|
542
|
-
.panel .field > .lab {
|
|
543
|
-
font-size: calc(var(--sealpixel-font-size) * 11 / 14);
|
|
544
|
-
letter-spacing: 0.012em;
|
|
545
|
-
line-height: 1.2;
|
|
546
|
-
}
|
|
547
|
-
.panel .hint {
|
|
548
|
-
margin: 0;
|
|
549
|
-
color: var(--sealpixel-color-fg-muted);
|
|
550
|
-
font-size: calc(var(--sealpixel-font-size) * 12 / 14);
|
|
551
|
-
}
|
|
552
|
-
/*
|
|
553
|
-
* Width and height are one measurement, so they sit against the link that
|
|
554
|
-
* binds them rather than being two fields that happen to be adjacent.
|
|
555
|
-
*/
|
|
556
|
-
.panel .dims {
|
|
557
|
-
display: inline-flex;
|
|
558
|
-
align-items: center;
|
|
559
|
-
gap: 4px;
|
|
560
|
-
}
|
|
561
|
-
.panel .dims input[type='number'] {
|
|
562
|
-
width: 5.5em;
|
|
563
|
-
min-width: 0;
|
|
564
|
-
text-align: center;
|
|
565
|
-
font-variant-numeric: tabular-nums;
|
|
566
|
-
appearance: textfield;
|
|
567
|
-
}
|
|
568
|
-
.panel .dims input::-webkit-outer-spin-button,
|
|
569
|
-
.panel .dims input::-webkit-inner-spin-button {
|
|
570
|
-
appearance: none;
|
|
571
|
-
margin: 0;
|
|
572
|
-
}
|
|
573
|
-
/* A value the link worked out, not one that was typed. */
|
|
574
|
-
.panel .dims input.derived {
|
|
575
|
-
color: var(--sealpixel-color-fg-muted);
|
|
576
|
-
font-weight: 400;
|
|
577
|
-
}
|
|
578
|
-
.panel .dims sealpixel-button::part(button) {
|
|
579
|
-
min-width: calc(var(--sealpixel-control-height) - 6px);
|
|
580
|
-
min-height: calc(var(--sealpixel-control-height) - 6px);
|
|
581
|
-
padding: 0;
|
|
582
|
-
background: transparent;
|
|
583
|
-
color: var(--sealpixel-color-fg-muted);
|
|
584
|
-
}
|
|
585
|
-
.panel .dims sealpixel-button[pressed]::part(button) {
|
|
586
|
-
background: var(--sealpixel-color-accent-soft);
|
|
587
|
-
color: var(--sealpixel-color-accent);
|
|
588
|
-
}
|
|
589
|
-
.panel .anchors {
|
|
590
|
-
display: grid;
|
|
591
|
-
grid-template-columns: repeat(3, 1fr);
|
|
592
|
-
gap: 4px;
|
|
593
|
-
max-width: 180px;
|
|
594
|
-
}
|
|
595
|
-
.panel .field.check {
|
|
596
|
-
grid-template-columns: auto 1fr;
|
|
597
|
-
align-items: center;
|
|
598
|
-
}
|
|
599
|
-
.panel textarea {
|
|
600
|
-
font: inherit;
|
|
601
|
-
color: var(--sealpixel-color-fg);
|
|
602
|
-
background: var(--sealpixel-color-surface-2);
|
|
603
|
-
border: 1px solid var(--sealpixel-color-border);
|
|
604
|
-
border-radius: var(--sealpixel-radius-sm);
|
|
605
|
-
padding: var(--sealpixel-space);
|
|
606
|
-
resize: vertical;
|
|
607
|
-
}
|
|
608
|
-
/* A colour is a disc, not a box: it shows the colour and nothing else. */
|
|
609
|
-
.panel input[type='color'] {
|
|
610
|
-
/* Without this the engine keeps its own swatch metrics inside the box
|
|
611
|
-
and the disc comes out an ellipse. */
|
|
612
|
-
appearance: none;
|
|
613
|
-
min-height: var(--sealpixel-control-height);
|
|
614
|
-
height: var(--sealpixel-control-height);
|
|
615
|
-
width: var(--sealpixel-control-height);
|
|
616
|
-
padding: 0;
|
|
617
|
-
border: 0;
|
|
618
|
-
border-radius: 50%;
|
|
619
|
-
background: transparent;
|
|
620
|
-
cursor: pointer;
|
|
621
|
-
overflow: hidden;
|
|
622
|
-
}
|
|
623
|
-
/* The swatch has to be told to fill the box; it does not by default. */
|
|
624
|
-
.panel input[type='color']::-webkit-color-swatch-wrapper {
|
|
625
|
-
padding: 0;
|
|
626
|
-
width: 100%;
|
|
627
|
-
height: 100%;
|
|
628
|
-
}
|
|
629
|
-
.panel input[type='color']::-webkit-color-swatch {
|
|
630
|
-
width: 100%;
|
|
631
|
-
height: 100%;
|
|
632
|
-
border: 0;
|
|
633
|
-
border-radius: 50%;
|
|
634
|
-
box-shadow: 0 0 0 1px var(--sealpixel-color-border);
|
|
635
|
-
}
|
|
636
|
-
.panel input[type='color']::-moz-color-swatch {
|
|
637
|
-
width: 100%;
|
|
638
|
-
height: 100%;
|
|
639
|
-
border: 0;
|
|
640
|
-
border-radius: 50%;
|
|
641
|
-
box-shadow: 0 0 0 1px var(--sealpixel-color-border);
|
|
642
|
-
}
|
|
643
|
-
.panel input:not([type='checkbox']):not([type='color']),
|
|
644
|
-
.panel select {
|
|
645
|
-
font: inherit;
|
|
646
|
-
font-size: calc(var(--sealpixel-font-size) * 13 / 14);
|
|
647
|
-
color: var(--sealpixel-color-fg);
|
|
648
|
-
background: var(--sealpixel-color-surface-2);
|
|
649
|
-
border: 1px solid transparent;
|
|
650
|
-
border-radius: var(--sealpixel-radius-pill);
|
|
651
|
-
min-height: var(--sealpixel-control-height);
|
|
652
|
-
padding: 0 calc(var(--sealpixel-space) * 1.5);
|
|
653
|
-
}
|
|
654
|
-
/*
|
|
655
|
-
* The chevron is drawn rather than left to the platform, so a select sits
|
|
656
|
-
* next to a pill button instead of looking like a form field that walked
|
|
657
|
-
* in from another page. The right padding keeps the text off it.
|
|
658
|
-
*/
|
|
659
|
-
.panel select {
|
|
660
|
-
appearance: none;
|
|
661
|
-
padding-right: calc(var(--sealpixel-space) * 3);
|
|
662
|
-
background-image:
|
|
663
|
-
linear-gradient(45deg, transparent 50%, currentColor 50%),
|
|
664
|
-
linear-gradient(135deg, currentColor 50%, transparent 50%);
|
|
665
|
-
background-size: 5px 5px, 5px 5px;
|
|
666
|
-
background-position:
|
|
667
|
-
right 14px top 52%,
|
|
668
|
-
right 10px top 52%;
|
|
669
|
-
background-repeat: no-repeat;
|
|
670
|
-
color: var(--sealpixel-color-fg);
|
|
671
|
-
}
|
|
672
|
-
.empty {
|
|
673
|
-
grid-area: stage;
|
|
674
|
-
display: grid;
|
|
675
|
-
place-content: center;
|
|
676
|
-
gap: var(--sealpixel-space);
|
|
677
|
-
text-align: center;
|
|
678
|
-
color: var(--sealpixel-color-fg-muted);
|
|
679
|
-
padding: var(--sealpixel-space);
|
|
680
|
-
}
|
|
681
|
-
.empty {
|
|
682
|
-
transition:
|
|
683
|
-
background var(--sealpixel-duration) var(--sealpixel-ease),
|
|
684
|
-
color var(--sealpixel-duration) var(--sealpixel-ease);
|
|
685
|
-
}
|
|
686
|
-
.empty.dragover {
|
|
687
|
-
outline: 2px dashed var(--sealpixel-color-accent);
|
|
688
|
-
outline-offset: -8px;
|
|
689
|
-
background: var(--sealpixel-color-accent-soft, transparent);
|
|
690
|
-
color: var(--sealpixel-color-fg);
|
|
691
|
-
}
|
|
692
|
-
/*
|
|
693
|
-
* A source is loading: the mark, its core breathing. The outer square
|
|
694
|
-
* stands still and the inner one swells and fades, in the muted
|
|
695
|
-
* foreground so nothing reads as a warning. It stops under
|
|
696
|
-
* prefers-reduced-motion and still reads as the mark.
|
|
697
|
-
*/
|
|
698
|
-
.empty.loading {
|
|
699
|
-
justify-items: center;
|
|
700
|
-
gap: calc(var(--sealpixel-space) * 2);
|
|
701
|
-
}
|
|
702
|
-
.empty.loading p {
|
|
703
|
-
margin: 0;
|
|
704
|
-
}
|
|
705
|
-
.mark {
|
|
706
|
-
display: block;
|
|
707
|
-
width: 40px;
|
|
708
|
-
height: 40px;
|
|
709
|
-
color: var(--sealpixel-color-fg-muted);
|
|
710
|
-
}
|
|
711
|
-
.mark .core {
|
|
712
|
-
transform-origin: 16px 16px;
|
|
713
|
-
animation: sealpixel-loading-breathe 1.8s var(--sealpixel-ease) infinite;
|
|
714
|
-
}
|
|
715
|
-
@keyframes sealpixel-loading-breathe {
|
|
716
|
-
50% {
|
|
717
|
-
opacity: 0.45;
|
|
718
|
-
transform: scale(0.62);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
.error {
|
|
723
|
-
grid-area: nav;
|
|
724
|
-
align-self: end;
|
|
725
|
-
justify-self: center;
|
|
726
|
-
margin-top: calc(var(--sealpixel-toolbar-size) + 4px);
|
|
727
|
-
z-index: 1;
|
|
728
|
-
padding: 6px 10px;
|
|
729
|
-
border-radius: var(--sealpixel-radius);
|
|
730
|
-
background: var(--sealpixel-color-danger);
|
|
731
|
-
color: white;
|
|
732
|
-
font-size: calc(var(--sealpixel-font-size) * 12 / 14);
|
|
733
|
-
box-shadow: var(--sealpixel-shadow-raised, none);
|
|
734
|
-
animation: sealpixel-panel-in var(--sealpixel-duration) var(--sealpixel-ease-out) both;
|
|
735
|
-
}
|
|
736
|
-
`,
|
|
737
|
-
]; }
|
|
24
|
+
static { this.styles = [tokens, base, editorStyles]; }
|
|
738
25
|
static { this.properties = {
|
|
739
26
|
plugins: { attribute: false },
|
|
740
27
|
pluginOptions: {
|
|
@@ -795,34 +82,12 @@ export class SealpixelEditor extends LitElement {
|
|
|
795
82
|
this.sessionRenderer = null;
|
|
796
83
|
this.sessionAssets = null;
|
|
797
84
|
this.sessionLimits = null;
|
|
798
|
-
this.onPointerDown = () => {
|
|
799
|
-
if (!this.matches(':focus-within'))
|
|
800
|
-
this.focus({ preventScroll: true });
|
|
801
|
-
};
|
|
802
|
-
this.onKeydown = (e) => {
|
|
803
|
-
const session = this.ctl.session;
|
|
804
|
-
if (!session || session.getState().status !== 'ready')
|
|
805
|
-
return;
|
|
806
|
-
// Undo inside a text field belongs to the field: it takes back the typing,
|
|
807
|
-
// not the last edit of the image.
|
|
808
|
-
if (isTextEntry(e.composedPath()[0]))
|
|
809
|
-
return;
|
|
810
|
-
const mod = e.metaKey || e.ctrlKey;
|
|
811
|
-
if (this.showHistory === 'none')
|
|
812
|
-
return;
|
|
813
|
-
if (mod && e.key.toLowerCase() === 'z') {
|
|
814
|
-
e.preventDefault();
|
|
815
|
-
if (e.shiftKey)
|
|
816
|
-
session.redo();
|
|
817
|
-
else
|
|
818
|
-
session.undo();
|
|
819
|
-
}
|
|
820
|
-
else if (mod && e.key.toLowerCase() === 'y') {
|
|
821
|
-
e.preventDefault();
|
|
822
|
-
session.redo();
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
85
|
this.toastTimer = null;
|
|
86
|
+
// The controller registers itself with the element; nothing else needs it.
|
|
87
|
+
new HistoryShortcutsController(this, {
|
|
88
|
+
session: () => this.ctl.session,
|
|
89
|
+
showHistory: () => this.showHistory,
|
|
90
|
+
});
|
|
826
91
|
this.plugins = null;
|
|
827
92
|
this.pluginOptions = null;
|
|
828
93
|
this.session = null;
|
|
@@ -931,7 +196,12 @@ export class SealpixelEditor extends LitElement {
|
|
|
931
196
|
}
|
|
932
197
|
connectedCallback() {
|
|
933
198
|
super.connectedCallback();
|
|
934
|
-
|
|
199
|
+
// React and Svelte set properties after they insert the element, in the
|
|
200
|
+
// same task. The first session therefore waits for the first update, which
|
|
201
|
+
// Lit runs in a microtask after the connection. A session built here would
|
|
202
|
+
// use the default plugins, and a later `plugins` would replace it.
|
|
203
|
+
if (this.hasUpdated)
|
|
204
|
+
this.ensureSession();
|
|
935
205
|
// Out of the document long enough to lose the session: the source comes
|
|
936
206
|
// back with the edit log it had when it left.
|
|
937
207
|
if (this.released) {
|
|
@@ -941,12 +211,6 @@ export class SealpixelEditor extends LitElement {
|
|
|
941
211
|
if (this.loadedSrc)
|
|
942
212
|
void this.loadSource(this.loadedSrc, restore);
|
|
943
213
|
}
|
|
944
|
-
// Keyboard shortcuts need focus inside the editor. WebKit does not focus
|
|
945
|
-
// buttons on click, so pull focus in on any pointer interaction.
|
|
946
|
-
if (!this.hasAttribute('tabindex'))
|
|
947
|
-
this.tabIndex = -1;
|
|
948
|
-
this.addEventListener('keydown', this.onKeydown);
|
|
949
|
-
this.addEventListener('pointerdown', this.onPointerDown);
|
|
950
214
|
this.resizeObserver = new ResizeObserver((entries) => {
|
|
951
215
|
const width = entries[0]?.contentRect.width ?? this.clientWidth;
|
|
952
216
|
this._wide = width >= 768;
|
|
@@ -955,8 +219,6 @@ export class SealpixelEditor extends LitElement {
|
|
|
955
219
|
}
|
|
956
220
|
disconnectedCallback() {
|
|
957
221
|
super.disconnectedCallback();
|
|
958
|
-
this.removeEventListener('keydown', this.onKeydown);
|
|
959
|
-
this.removeEventListener('pointerdown', this.onPointerDown);
|
|
960
222
|
this.resizeObserver?.disconnect();
|
|
961
223
|
// A move in the DOM (an append into another parent, a portal, a keyed
|
|
962
224
|
// reorder) disconnects and connects again in the same task. Disposing here
|
|
@@ -1001,7 +263,12 @@ export class SealpixelEditor extends LitElement {
|
|
|
1001
263
|
}
|
|
1002
264
|
this.ownsSession = false;
|
|
1003
265
|
this.ctl.session = this.session;
|
|
266
|
+
// The active tool activates again on the new session.
|
|
267
|
+
this.previousTool = null;
|
|
1004
268
|
}
|
|
269
|
+
// The first update creates the session with the properties set so far.
|
|
270
|
+
if (!this.hasUpdated && this.isConnected)
|
|
271
|
+
this.ensureSession();
|
|
1005
272
|
// A new plugin list or renderer needs a new session; reload the current source into it.
|
|
1006
273
|
if ((changed.has('plugins') ||
|
|
1007
274
|
changed.has('pluginOptions') ||
|
|
@@ -1018,6 +285,8 @@ export class SealpixelEditor extends LitElement {
|
|
|
1018
285
|
this._pluginTools = {};
|
|
1019
286
|
this.lastEmittedVersion = -1;
|
|
1020
287
|
this.lastSource = null;
|
|
288
|
+
// The active tool activates again on the new session.
|
|
289
|
+
this.previousTool = null;
|
|
1021
290
|
this.ensureSession();
|
|
1022
291
|
if (this.loadedSrc)
|
|
1023
292
|
void this.loadSource(this.loadedSrc);
|
|
@@ -1046,7 +315,9 @@ export class SealpixelEditor extends LitElement {
|
|
|
1046
315
|
}
|
|
1047
316
|
this.syncActiveTool();
|
|
1048
317
|
this.syncSource(state);
|
|
1049
|
-
this.
|
|
318
|
+
const panel = this.renderRoot.querySelector('.panel');
|
|
319
|
+
if (panel)
|
|
320
|
+
syncPanelFill(panel);
|
|
1050
321
|
}
|
|
1051
322
|
/** Tells every tool, active or not, that a new source has loaded. Once per source. */
|
|
1052
323
|
syncSource(state) {
|
|
@@ -1057,63 +328,6 @@ export class SealpixelEditor extends LitElement {
|
|
|
1057
328
|
for (const tool of this.currentTools())
|
|
1058
329
|
tool.onSource?.(ctx);
|
|
1059
330
|
}
|
|
1060
|
-
/**
|
|
1061
|
-
* Collapses the settings bar when the open tool has nothing to put in it.
|
|
1062
|
-
*
|
|
1063
|
-
* A tool renders its own structure, and a structure can hold nothing: crop
|
|
1064
|
-
* with `rotation`, `flip` and `reset` off and a single enforced aspect emits
|
|
1065
|
-
* two empty wrappers. The bar is a fixed height on purpose — see `.panel` —
|
|
1066
|
-
* so that reserved an empty bordered surface and took the same height off
|
|
1067
|
-
* the stage. On the landing page's avatar card that was 240 px of nothing
|
|
1068
|
-
* against a 178 px stage, and the photo rendered at 10 percent.
|
|
1069
|
-
*
|
|
1070
|
-
* Read from the DOM rather than asked of the tool: every tool would
|
|
1071
|
-
* otherwise have to declare it, and a tool whose panel empties out only
|
|
1072
|
-
* under some options would get it wrong.
|
|
1073
|
-
*
|
|
1074
|
-
* Not measured by size either. The empty wrappers still lay out — the row
|
|
1075
|
-
* is 8px from its own gap and the group 4px from its border — so a
|
|
1076
|
-
* bounding box tells content and scaffolding apart not at all. What counts
|
|
1077
|
-
* is a control or a word: a custom element, a form control, or any text.
|
|
1078
|
-
*/
|
|
1079
|
-
syncPanelFill() {
|
|
1080
|
-
const panel = this.renderRoot.querySelector('.panel');
|
|
1081
|
-
if (!panel)
|
|
1082
|
-
return;
|
|
1083
|
-
const filled = (panel.textContent ?? '').trim().length > 0 ||
|
|
1084
|
-
Array.from(panel.querySelectorAll('*')).some((node) => node.tagName.includes('-') || node.matches(PANEL_CONTENT));
|
|
1085
|
-
panel.toggleAttribute('data-empty', !filled);
|
|
1086
|
-
this.syncPanelFit(panel, filled);
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Lets the settings bar grow to the height its content needs.
|
|
1090
|
-
*
|
|
1091
|
-
* The bar is a fixed height so that moving between tools does not resize
|
|
1092
|
-
* the stage under the user. When a tool needs more than that height, the
|
|
1093
|
-
* overflow has nowhere to go: a wrapping flex container of fixed height has
|
|
1094
|
-
* no scrollable cross-axis overflow, so `overflow: auto` never produces a
|
|
1095
|
-
* scrollbar, and the sticky choice row — which pins itself inside the
|
|
1096
|
-
* scrollport — is dragged up over the settings instead. The colour swatch
|
|
1097
|
-
* ends up half covered and the fill toggle disappears behind the shapes.
|
|
1098
|
-
*
|
|
1099
|
-
* WebKit is where this surfaced, on a real iPhone: it lays these controls
|
|
1100
|
-
* taller than Blink does, and at phone width crop, finetune and annotate
|
|
1101
|
-
* needed 138, 140 and 136 pixels against the 112 the bar had. Raising the
|
|
1102
|
-
* default would have taken those pixels off every stage in every engine, so
|
|
1103
|
-
* the height is measured instead and only the bar that needs more gets it.
|
|
1104
|
-
* `34cqh` still caps it, so a busy tool cannot eat the stage.
|
|
1105
|
-
*/
|
|
1106
|
-
syncPanelFit(panel, filled) {
|
|
1107
|
-
panel.style.removeProperty('--sealpixel-panel-fit');
|
|
1108
|
-
if (!filled)
|
|
1109
|
-
return;
|
|
1110
|
-
// Read after the reset, so a bar that has since shrunk measures its own
|
|
1111
|
-
// content and not the height it was given last time.
|
|
1112
|
-
const needed = panel.scrollHeight;
|
|
1113
|
-
if (needed > panel.clientHeight) {
|
|
1114
|
-
panel.style.setProperty('--sealpixel-panel-fit', `${needed}px`);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
331
|
async loadSource(src, restore) {
|
|
1118
332
|
const session = this.getSession();
|
|
1119
333
|
try {
|
|
@@ -1205,7 +419,8 @@ export class SealpixelEditor extends LitElement {
|
|
|
1205
419
|
toolContext(state) {
|
|
1206
420
|
const session = this.getSession();
|
|
1207
421
|
const stage = this.stage;
|
|
1208
|
-
|
|
422
|
+
// The tools are shared objects; their transient state is kept per editor.
|
|
423
|
+
return bindToolContext(this, {
|
|
1209
424
|
session,
|
|
1210
425
|
state,
|
|
1211
426
|
document: state.document,
|
|
@@ -1249,7 +464,7 @@ export class SealpixelEditor extends LitElement {
|
|
|
1249
464
|
},
|
|
1250
465
|
layout: this._wide ? 'wide' : 'narrow',
|
|
1251
466
|
options: (pluginId) => session.registry.byId.get(pluginId)?.options,
|
|
1252
|
-
};
|
|
467
|
+
});
|
|
1253
468
|
}
|
|
1254
469
|
syncActiveTool() {
|
|
1255
470
|
const state = this.ctl.state;
|
|
@@ -1361,7 +576,15 @@ export class SealpixelEditor extends LitElement {
|
|
|
1361
576
|
.overlay=${ctx && tool?.overlay ? tool.overlay(ctx) : null}
|
|
1362
577
|
@stage-view=${() => this.requestUpdate()}
|
|
1363
578
|
></sealpixel-stage>`
|
|
1364
|
-
:
|
|
579
|
+
: renderEmpty({
|
|
580
|
+
state,
|
|
581
|
+
t: this.i18n.t,
|
|
582
|
+
dragover: this._dragover,
|
|
583
|
+
setDragover: (dragover) => {
|
|
584
|
+
this._dragover = dragover;
|
|
585
|
+
},
|
|
586
|
+
onFiles: (files) => this.onFiles(files),
|
|
587
|
+
})}
|
|
1365
588
|
<div class="panel" part="panel">${ctx && tool ? tool.panel(ctx) : nothing}</div>
|
|
1366
589
|
<sealpixel-toolbar
|
|
1367
590
|
part="toolbar"
|
|
@@ -1376,78 +599,12 @@ export class SealpixelEditor extends LitElement {
|
|
|
1376
599
|
}}
|
|
1377
600
|
></sealpixel-toolbar>
|
|
1378
601
|
${state?.error ? html `<div class="error" role="alert">${this.i18n.t('editor.error', { message: state.error.message })}</div>` : nothing}
|
|
1379
|
-
${this._toast
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
}}>
|
|
1383
|
-
<span>${this._toast.text}</span>
|
|
1384
|
-
${this._toast.hash ? html `<code>${this._toast.hash}</code>` : nothing}
|
|
1385
|
-
</div>`
|
|
1386
|
-
: nothing}
|
|
602
|
+
${renderToast(this._toast, () => {
|
|
603
|
+
this._toast = null;
|
|
604
|
+
})}
|
|
1387
605
|
<span id="live" class="visually-hidden" role="status" aria-live="polite"></span>
|
|
1388
606
|
</div>
|
|
1389
607
|
`;
|
|
1390
608
|
}
|
|
1391
|
-
renderEmpty(state) {
|
|
1392
|
-
if (state?.status === 'loading') {
|
|
1393
|
-
return html `<div class="empty loading" part="empty" role="status">
|
|
1394
|
-
<svg class="mark" viewBox="0 0 32 32" aria-hidden="true">
|
|
1395
|
-
<rect x="3" y="3" width="26" height="26" rx="5" fill="none" stroke="currentColor" stroke-width="2" />
|
|
1396
|
-
<rect class="core" x="11" y="11" width="10" height="10" rx="1.5" fill="currentColor" />
|
|
1397
|
-
</svg>
|
|
1398
|
-
<p>${this.i18n.t('editor.loading')}</p>
|
|
1399
|
-
</div>`;
|
|
1400
|
-
}
|
|
1401
|
-
return html `<div
|
|
1402
|
-
class="empty ${this._dragover ? 'dragover' : ''}"
|
|
1403
|
-
part="empty"
|
|
1404
|
-
@dragover=${(e) => {
|
|
1405
|
-
e.preventDefault();
|
|
1406
|
-
this._dragover = true;
|
|
1407
|
-
}}
|
|
1408
|
-
@dragleave=${() => {
|
|
1409
|
-
this._dragover = false;
|
|
1410
|
-
}}
|
|
1411
|
-
@drop=${(e) => {
|
|
1412
|
-
e.preventDefault();
|
|
1413
|
-
this._dragover = false;
|
|
1414
|
-
this.onFiles(e.dataTransfer?.files ?? null);
|
|
1415
|
-
}}
|
|
1416
|
-
>
|
|
1417
|
-
<p>${this.i18n.t('editor.empty')}</p>
|
|
1418
|
-
<label>
|
|
1419
|
-
<input class="visually-hidden" type="file" accept="image/png,image/jpeg,image/webp" @change=${(e) => this.onFiles(e.target.files)} />
|
|
1420
|
-
<sealpixel-button variant="primary" @click=${(e) => e.currentTarget.previousElementSibling.click()}>
|
|
1421
|
-
${this.i18n.t('editor.choose')}
|
|
1422
|
-
</sealpixel-button>
|
|
1423
|
-
</label>
|
|
1424
|
-
</div>`;
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
/** Input types that hold no text, so Cmd/Ctrl+Z on them has nothing of their own to undo. */
|
|
1428
|
-
const NON_TEXT_INPUTS = new Set([
|
|
1429
|
-
'button',
|
|
1430
|
-
'checkbox',
|
|
1431
|
-
'color',
|
|
1432
|
-
'file',
|
|
1433
|
-
'image',
|
|
1434
|
-
'radio',
|
|
1435
|
-
'range',
|
|
1436
|
-
'reset',
|
|
1437
|
-
'submit',
|
|
1438
|
-
]);
|
|
1439
|
-
function isTextEntry(target) {
|
|
1440
|
-
if (!(target instanceof HTMLElement))
|
|
1441
|
-
return false;
|
|
1442
|
-
if (target.isContentEditable || target instanceof HTMLTextAreaElement)
|
|
1443
|
-
return true;
|
|
1444
|
-
return target instanceof HTMLInputElement && !NON_TEXT_INPUTS.has(target.type);
|
|
1445
|
-
}
|
|
1446
|
-
function formatBytes(n) {
|
|
1447
|
-
if (n < 1024)
|
|
1448
|
-
return `${n} B`;
|
|
1449
|
-
if (n < 1024 * 1024)
|
|
1450
|
-
return `${(n / 1024).toFixed(n < 10240 ? 1 : 0)} KB`;
|
|
1451
|
-
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
1452
609
|
}
|
|
1453
610
|
//# sourceMappingURL=sealpixel-editor.js.map
|