@hussmartinez/image-sdk 0.4.0 → 0.6.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/README.md +4 -3
- package/dist/assets/image/render.worker.js +2 -2
- package/dist/element.d.ts +163 -7
- package/dist/element.js +2 -2
- package/dist/index.d.ts +234 -18
- package/dist/index.js +11 -9
- package/dist/index.js.map +1 -1
- package/dist/lazy/inline-worker-COOlwTsC.js +30 -0
- package/dist/lazy/{inline-worker-DsBNkr8Q.js.map → inline-worker-COOlwTsC.js.map} +1 -1
- package/dist/react.d.ts +218 -18
- package/dist/react.js +1 -1
- package/dist/shared/{core-BlFeJWak.js → core-VHeENp7j.js} +429 -32
- package/dist/shared/core-VHeENp7j.js.map +1 -0
- package/dist/shared/{editor-Bjv32UmV.js → editor-Bj9Xo5nf.js} +2059 -1481
- package/dist/shared/editor-Bj9Xo5nf.js.map +1 -0
- package/dist/styles.css +41 -6
- package/formats/hm-image-command/v3.schema.json +311 -0
- package/formats/hm-image-plan/v3.schema.json +1032 -0
- package/package.json +2 -2
- package/dist/lazy/inline-worker-DsBNkr8Q.js +0 -30
- package/dist/shared/core-BlFeJWak.js.map +0 -1
- package/dist/shared/editor-Bjv32UmV.js.map +0 -1
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as fitAspect, At as placement, Bt as asImageError, D as compositionDeltaToSource, E as aspectRatio, Et as createImageRenderer, F as compositionSize, Ht as isImageError, I as compositionToSource, K as createImageReducer, L as cropRect, M as moveCrop, Mt as createImageEngine, N as nudgeCropOnScreen, Nt as engineInternals, O as cropInComposition, P as wholeCrop, S as drawingBounds, T as ASPECT_PRESETS, a as fitRedactionRegion, at as longerThan, b as arrowBounds, d as applyMatrix, g as layerToScene, gt as MAX_LAYER_TEXT_LENGTH, h as layerToOutput, i as compositionRectToScene, j as handleInSource, jt as createImageProcessor, k as dragHandle, lt as LAYER_ALIGNMENTS, n as createImageSession, ot as DEVELOP_ADJUSTMENTS, p as invertMatrix, q as FORBIDDEN_IN_TEXT, r as newLayerBox, rt as MAX_METADATA_LENGTH, st as FILTER_PRESETS, t as imageMessages, u as sceneRectToComposition, ut as LAYER_FONTS, v as sceneToOutput, w as simplifyStroke, xt as MAX_STROKE_WIDTH, y as createImageKey, yt as MAX_SCENE_COORDINATE, z as outputSize } from "./core-VHeENp7j.js";
|
|
2
2
|
import { applyCommands, createMessages, createShortcutRegistry, createStore, createToolRegistry, defineMessages, defineTool, plural } from "@hussmartinez/sdk-core";
|
|
3
|
-
import { AddIcon, AnnouncerProvider, Button, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, IconButton, LayersIcon, MoveDownIcon, MoveUpIcon, NumberField, OpenIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, Slider, Spinner, TextArea, TextField, TextIcon, ToggleButton, Toolbar, ToolbarGroup, UiMessagesProvider, UndoIcon, VisibleIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform } from "@hussmartinez/ui/react";
|
|
3
|
+
import { AddIcon, AnnouncerProvider, ArrowIcon, Button, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, IconButton, LayersIcon, MoveDownIcon, MoveUpIcon, NumberField, OpenIcon, PenIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, Slider, Spinner, TextArea, TextField, TextIcon, ToggleButton, Toolbar, ToolbarGroup, Tooltip, UiMessagesProvider, UndoIcon, VisibleIcon, ZoomInIcon, ZoomOutIcon, useAnnounce, usePlatform } from "@hussmartinez/ui/react";
|
|
4
4
|
import { createContext, forwardRef, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { uiMessages } from "@hussmartinez/ui";
|
|
7
|
+
// src/features/editor-state.ts
|
|
8
|
+
var NO_TOOL = Object.freeze({
|
|
9
|
+
tool: null,
|
|
10
|
+
crop: null,
|
|
11
|
+
redact: null,
|
|
12
|
+
layers: null,
|
|
13
|
+
draw: null
|
|
14
|
+
});
|
|
15
|
+
var IDLE = Object.freeze({
|
|
16
|
+
...NO_TOOL,
|
|
17
|
+
error: null,
|
|
18
|
+
preview: null,
|
|
19
|
+
dialog: null
|
|
20
|
+
});
|
|
21
|
+
function createEditorStore() {
|
|
22
|
+
return createStore(IDLE);
|
|
23
|
+
}
|
|
7
24
|
// src/features/tool-types.ts
|
|
8
25
|
var hasDocument = ({ snapshot }) => snapshot.plan !== null;
|
|
9
26
|
// src/features/crop/crop-tools.ts
|
|
@@ -12,13 +29,12 @@ function startCrop({ session, editor }) {
|
|
|
12
29
|
if (!plan || !source) return;
|
|
13
30
|
editor.set((state) => ({
|
|
14
31
|
...state,
|
|
32
|
+
...NO_TOOL,
|
|
15
33
|
tool: "crop",
|
|
16
34
|
crop: {
|
|
17
35
|
pending: plan.base.crop ?? wholeCrop(source),
|
|
18
36
|
aspect: "free"
|
|
19
37
|
},
|
|
20
|
-
redact: null,
|
|
21
|
-
layers: null,
|
|
22
38
|
preview: null
|
|
23
39
|
}));
|
|
24
40
|
}
|
|
@@ -63,45 +79,10 @@ var flipVerticalTool = /* @__PURE__ */ defineTool({
|
|
|
63
79
|
isEnabled: hasDocument,
|
|
64
80
|
run: (context) => flip(context, "flipY")
|
|
65
81
|
});
|
|
66
|
-
// src/features/export/export-tool.ts
|
|
67
|
-
var exportTool = /* @__PURE__ */ defineTool({
|
|
68
|
-
id: "image.export",
|
|
69
|
-
label: "tools.export",
|
|
70
|
-
icon: "export",
|
|
71
|
-
group: "export",
|
|
72
|
-
isEnabled: ({ snapshot, editor }) => snapshot.plan !== null && editor.tool === null,
|
|
73
|
-
run: ({ editor }) => editor.set((state) => ({
|
|
74
|
-
...state,
|
|
75
|
-
dialog: "export"
|
|
76
|
-
}))
|
|
77
|
-
});
|
|
78
|
-
// src/features/history/history-tools.ts
|
|
79
|
-
var undoTool = /* @__PURE__ */ defineTool({
|
|
80
|
-
id: "image.undo",
|
|
81
|
-
label: "tools.undo",
|
|
82
|
-
icon: "undo",
|
|
83
|
-
group: "history",
|
|
84
|
-
isEnabled: ({ snapshot }) => snapshot.canUndo,
|
|
85
|
-
run: ({ session }) => {
|
|
86
|
-
session.undo();
|
|
87
|
-
},
|
|
88
|
-
shortcuts: "undo"
|
|
89
|
-
});
|
|
90
|
-
var redoTool = /* @__PURE__ */ defineTool({
|
|
91
|
-
id: "image.redo",
|
|
92
|
-
label: "tools.redo",
|
|
93
|
-
icon: "redo",
|
|
94
|
-
group: "history",
|
|
95
|
-
isEnabled: ({ snapshot }) => snapshot.canRedo,
|
|
96
|
-
run: ({ session }) => {
|
|
97
|
-
session.redo();
|
|
98
|
-
},
|
|
99
|
-
shortcuts: "redo"
|
|
100
|
-
});
|
|
101
82
|
// src/features/layers/new-layer.ts
|
|
102
83
|
var DEFAULT_TEXT_COLOUR = "#000000";
|
|
103
84
|
var DEFAULT_SHAPE_COLOUR = "#e02020";
|
|
104
|
-
var clamp$
|
|
85
|
+
var clamp$3 = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
105
86
|
function newLayerKey(plan) {
|
|
106
87
|
return createImageKey(new Set([...plan.layers, ...plan.redactions].map((item) => item.key)));
|
|
107
88
|
}
|
|
@@ -129,7 +110,7 @@ function newTextLayer(plan, source) {
|
|
|
129
110
|
}
|
|
130
111
|
function defaultStrokeWidth(plan, source) {
|
|
131
112
|
const { width, height } = compositionSize(plan, source);
|
|
132
|
-
return clamp$
|
|
113
|
+
return clamp$3(Math.round(Math.min(width, height) / 100), 2, MAX_STROKE_WIDTH);
|
|
133
114
|
}
|
|
134
115
|
function newShapeLayer(plan, source, shape) {
|
|
135
116
|
const { width, height } = compositionSize(plan, source);
|
|
@@ -149,11 +130,129 @@ function newShapeLayer(plan, source, shape) {
|
|
|
149
130
|
...box
|
|
150
131
|
};
|
|
151
132
|
}
|
|
133
|
+
function newArrowLayer(plan, source) {
|
|
134
|
+
const composition = compositionSize(plan, source);
|
|
135
|
+
const crop = cropRect(plan.base.crop, source);
|
|
136
|
+
const { orientation } = plan.base;
|
|
137
|
+
const scene = (x, y) => {
|
|
138
|
+
const point = compositionToSource({
|
|
139
|
+
x,
|
|
140
|
+
y
|
|
141
|
+
}, crop, orientation);
|
|
142
|
+
return {
|
|
143
|
+
x: Math.round(point.x) || 0,
|
|
144
|
+
y: Math.round(point.y) || 0
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const middle = composition.height / 2;
|
|
148
|
+
const from = scene(composition.width * 3 / 8, middle);
|
|
149
|
+
let to = scene(composition.width * 5 / 8, middle);
|
|
150
|
+
if (to.x === from.x && to.y === from.y) {
|
|
151
|
+
const beside = scene(composition.width * 3 / 8 + 1, middle);
|
|
152
|
+
to = beside.x === from.x && beside.y === from.y ? {
|
|
153
|
+
x: from.x + 1,
|
|
154
|
+
y: from.y
|
|
155
|
+
} : beside;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...common(plan),
|
|
159
|
+
kind: "arrow",
|
|
160
|
+
from,
|
|
161
|
+
to,
|
|
162
|
+
colour: DEFAULT_SHAPE_COLOUR,
|
|
163
|
+
width: defaultStrokeWidth(plan, source)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
152
166
|
var insertOnTop = (plan, layer) => ({
|
|
153
167
|
type: "image.insertLayers",
|
|
154
168
|
at: plan.layers.length,
|
|
155
169
|
layers: [layer]
|
|
156
170
|
});
|
|
171
|
+
// src/features/draw/draw-tool.ts
|
|
172
|
+
var DRAW_OPACITY = {
|
|
173
|
+
pen: 100,
|
|
174
|
+
highlighter: 40
|
|
175
|
+
};
|
|
176
|
+
var DRAW_COLOUR = {
|
|
177
|
+
pen: DEFAULT_SHAPE_COLOUR,
|
|
178
|
+
highlighter: "#f0c020"
|
|
179
|
+
};
|
|
180
|
+
var HIGHLIGHTER_WIDTH = 6;
|
|
181
|
+
function drawWidth({ session }, mode) {
|
|
182
|
+
const { plan, source } = session.getSnapshot();
|
|
183
|
+
const pen = plan && source ? defaultStrokeWidth(plan, source) : 2;
|
|
184
|
+
return mode === "pen" ? pen : Math.min(pen * HIGHLIGHTER_WIDTH, MAX_STROKE_WIDTH);
|
|
185
|
+
}
|
|
186
|
+
var drawTool = /* @__PURE__ */ defineTool({
|
|
187
|
+
id: "image.draw",
|
|
188
|
+
label: "tools.draw",
|
|
189
|
+
icon: "pen",
|
|
190
|
+
group: "draw",
|
|
191
|
+
isEnabled: hasDocument,
|
|
192
|
+
isActive: ({ editor }) => editor.tool === "draw",
|
|
193
|
+
run: (context) => {
|
|
194
|
+
const { editor, session } = context;
|
|
195
|
+
const selected = editor.getSnapshot().layers?.selected ?? null;
|
|
196
|
+
const layer = session.getSnapshot().plan?.layers.find((item) => item.key === selected);
|
|
197
|
+
const target = layer?.kind === "drawing" && layer.opacity === DRAW_OPACITY.pen ? layer.key : null;
|
|
198
|
+
editor.set((state) => state.tool === "draw" ? {
|
|
199
|
+
...state,
|
|
200
|
+
...NO_TOOL,
|
|
201
|
+
preview: null
|
|
202
|
+
} : {
|
|
203
|
+
...state,
|
|
204
|
+
...NO_TOOL,
|
|
205
|
+
tool: "draw",
|
|
206
|
+
preview: null,
|
|
207
|
+
draw: {
|
|
208
|
+
mode: "pen",
|
|
209
|
+
colour: DRAW_COLOUR.pen,
|
|
210
|
+
width: drawWidth(context, "pen"),
|
|
211
|
+
target
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
shortcuts: ["D"]
|
|
216
|
+
});
|
|
217
|
+
// src/features/export/export-tool.ts
|
|
218
|
+
var exportTool = {
|
|
219
|
+
.../* @__PURE__ */ defineTool({
|
|
220
|
+
id: "image.export",
|
|
221
|
+
label: "tools.export",
|
|
222
|
+
icon: "export",
|
|
223
|
+
group: "export",
|
|
224
|
+
isEnabled: ({ snapshot, editor }) => snapshot.plan !== null && editor.tool !== "crop",
|
|
225
|
+
run: ({ editor }) => editor.set((state) => state.tool === "crop" ? state : {
|
|
226
|
+
...state,
|
|
227
|
+
...NO_TOOL,
|
|
228
|
+
dialog: "export"
|
|
229
|
+
})
|
|
230
|
+
}),
|
|
231
|
+
unavailable: ({ snapshot, editor }) => snapshot.plan !== null && editor.tool === "crop" ? "tools.exportWhileCropping" : void 0
|
|
232
|
+
};
|
|
233
|
+
// src/features/history/history-tools.ts
|
|
234
|
+
var undoTool = /* @__PURE__ */ defineTool({
|
|
235
|
+
id: "image.undo",
|
|
236
|
+
label: "tools.undo",
|
|
237
|
+
icon: "undo",
|
|
238
|
+
group: "history",
|
|
239
|
+
isEnabled: ({ snapshot }) => snapshot.canUndo,
|
|
240
|
+
run: ({ session }) => {
|
|
241
|
+
session.undo();
|
|
242
|
+
},
|
|
243
|
+
shortcuts: "undo"
|
|
244
|
+
});
|
|
245
|
+
var redoTool = /* @__PURE__ */ defineTool({
|
|
246
|
+
id: "image.redo",
|
|
247
|
+
label: "tools.redo",
|
|
248
|
+
icon: "redo",
|
|
249
|
+
group: "history",
|
|
250
|
+
isEnabled: ({ snapshot }) => snapshot.canRedo,
|
|
251
|
+
run: ({ session }) => {
|
|
252
|
+
session.redo();
|
|
253
|
+
},
|
|
254
|
+
shortcuts: "redo"
|
|
255
|
+
});
|
|
157
256
|
// src/features/layers/add-layer-tools.ts
|
|
158
257
|
function add({ session, editor }, create, edit = false) {
|
|
159
258
|
const { plan, source } = session.getSnapshot();
|
|
@@ -171,9 +270,8 @@ function add({ session, editor }, create, edit = false) {
|
|
|
171
270
|
}
|
|
172
271
|
editor.set((state) => ({
|
|
173
272
|
...state,
|
|
273
|
+
...NO_TOOL,
|
|
174
274
|
tool: "layers",
|
|
175
|
-
crop: null,
|
|
176
|
-
redact: null,
|
|
177
275
|
preview: null,
|
|
178
276
|
error: null,
|
|
179
277
|
layers: edit ? {
|
|
@@ -207,6 +305,14 @@ var addEllipseTool = /* @__PURE__ */ defineTool({
|
|
|
207
305
|
isEnabled: hasDocument,
|
|
208
306
|
run: (context) => add(context, (plan, source) => newShapeLayer(plan, source, "ellipse"))
|
|
209
307
|
});
|
|
308
|
+
var addArrowTool = /* @__PURE__ */ defineTool({
|
|
309
|
+
id: "image.add-arrow",
|
|
310
|
+
label: "tools.add-arrow",
|
|
311
|
+
icon: "arrow",
|
|
312
|
+
group: "add",
|
|
313
|
+
isEnabled: hasDocument,
|
|
314
|
+
run: (context) => add(context, newArrowLayer)
|
|
315
|
+
});
|
|
210
316
|
var addImageTool = /* @__PURE__ */ defineTool({
|
|
211
317
|
id: "image.add-image",
|
|
212
318
|
label: "tools.add-image",
|
|
@@ -227,14 +333,12 @@ var layersTool = /* @__PURE__ */ defineTool({
|
|
|
227
333
|
const top = session.getSnapshot().plan?.layers.at(-1)?.key ?? null;
|
|
228
334
|
editor.set((state) => state.tool === "layers" ? {
|
|
229
335
|
...state,
|
|
230
|
-
|
|
231
|
-
layers: null,
|
|
336
|
+
...NO_TOOL,
|
|
232
337
|
preview: null
|
|
233
338
|
} : {
|
|
234
339
|
...state,
|
|
340
|
+
...NO_TOOL,
|
|
235
341
|
tool: "layers",
|
|
236
|
-
crop: null,
|
|
237
|
-
redact: null,
|
|
238
342
|
preview: null,
|
|
239
343
|
layers: {
|
|
240
344
|
selected: top,
|
|
@@ -300,14 +404,12 @@ var redactTool = /* @__PURE__ */ defineTool({
|
|
|
300
404
|
run: ({ editor }) => {
|
|
301
405
|
editor.set((state) => state.tool === "redact" ? {
|
|
302
406
|
...state,
|
|
303
|
-
|
|
304
|
-
redact: null,
|
|
407
|
+
...NO_TOOL,
|
|
305
408
|
preview: null
|
|
306
409
|
} : {
|
|
307
410
|
...state,
|
|
411
|
+
...NO_TOOL,
|
|
308
412
|
tool: "redact",
|
|
309
|
-
crop: null,
|
|
310
|
-
layers: null,
|
|
311
413
|
preview: null,
|
|
312
414
|
redact: {
|
|
313
415
|
selected: null,
|
|
@@ -320,7 +422,7 @@ var redactTool = /* @__PURE__ */ defineTool({
|
|
|
320
422
|
});
|
|
321
423
|
// src/features/zoom/zoom-tools.ts
|
|
322
424
|
var STEP = 1.25;
|
|
323
|
-
var clamp$
|
|
425
|
+
var clamp$2 = (zoom) => Math.min(16, Math.max(.1, zoom));
|
|
324
426
|
// src/features/tools.ts
|
|
325
427
|
var imageTools = [
|
|
326
428
|
openTool,
|
|
@@ -335,7 +437,9 @@ var imageTools = [
|
|
|
335
437
|
addTextTool,
|
|
336
438
|
addRectangleTool,
|
|
337
439
|
addEllipseTool,
|
|
440
|
+
addArrowTool,
|
|
338
441
|
addImageTool,
|
|
442
|
+
drawTool,
|
|
339
443
|
layersTool,
|
|
340
444
|
/* @__PURE__ */ defineTool({
|
|
341
445
|
id: "image.zoom-in",
|
|
@@ -345,7 +449,7 @@ var imageTools = [
|
|
|
345
449
|
isEnabled: hasDocument,
|
|
346
450
|
run: ({ view }) => view.set((v) => ({
|
|
347
451
|
...v,
|
|
348
|
-
zoom: clamp$
|
|
452
|
+
zoom: clamp$2(v.zoom * STEP)
|
|
349
453
|
})),
|
|
350
454
|
shortcuts: "zoom-in"
|
|
351
455
|
}),
|
|
@@ -357,7 +461,7 @@ var imageTools = [
|
|
|
357
461
|
isEnabled: hasDocument,
|
|
358
462
|
run: ({ view }) => view.set((v) => ({
|
|
359
463
|
...v,
|
|
360
|
-
zoom: clamp$
|
|
464
|
+
zoom: clamp$2(v.zoom / STEP)
|
|
361
465
|
})),
|
|
362
466
|
shortcuts: "zoom-out"
|
|
363
467
|
}),
|
|
@@ -393,8 +497,10 @@ var DEFAULT_TOOLBAR = [
|
|
|
393
497
|
"image.add-text",
|
|
394
498
|
"image.add-rectangle",
|
|
395
499
|
"image.add-ellipse",
|
|
500
|
+
"image.add-arrow",
|
|
396
501
|
"image.add-image"
|
|
397
502
|
],
|
|
503
|
+
["image.draw"],
|
|
398
504
|
["image.layers"],
|
|
399
505
|
[
|
|
400
506
|
"image.zoom-in",
|
|
@@ -416,9 +522,8 @@ function createInserter(session, editor) {
|
|
|
416
522
|
const selected = [...session.getSnapshot().plan?.layers ?? []].reverse().find((layer) => layer.kind === "image" && layer.source === image.id)?.key ?? null;
|
|
417
523
|
editor.set((state) => ({
|
|
418
524
|
...state,
|
|
525
|
+
...NO_TOOL,
|
|
419
526
|
tool: "layers",
|
|
420
|
-
crop: null,
|
|
421
|
-
redact: null,
|
|
422
527
|
preview: null,
|
|
423
528
|
error: null,
|
|
424
529
|
layers: { selected }
|
|
@@ -635,959 +740,369 @@ function ImageCropPanel(props) {
|
|
|
635
740
|
]
|
|
636
741
|
});
|
|
637
742
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const notice = useRef(null);
|
|
646
|
-
const ownedFocus = useRef(null);
|
|
647
|
-
const subscribe = useMemo(() => lifecycle ? (changed) => lifecycle.subscribe(() => {
|
|
648
|
-
const active = document.activeElement;
|
|
649
|
-
ownedFocus.current = active && surface.current?.contains(active) ? active : null;
|
|
650
|
-
changed();
|
|
651
|
-
}) : unchanged, [lifecycle]);
|
|
652
|
-
const terminal = useSyncExternalStore(subscribe, lifecycle?.getSnapshot ?? usable, usable);
|
|
653
|
-
useEffect(() => {
|
|
654
|
-
if (!terminal || !ownedFocus.current) return;
|
|
655
|
-
const active = document.activeElement;
|
|
656
|
-
if (active === document.body || active === ownedFocus.current) notice.current?.focus();
|
|
657
|
-
ownedFocus.current = null;
|
|
658
|
-
}, [terminal]);
|
|
659
|
-
return /* @__PURE__ */ jsx("div", {
|
|
660
|
-
ref: surface,
|
|
661
|
-
className: "hm-image-engine-boundary",
|
|
662
|
-
children: terminal ? /* @__PURE__ */ jsx("p", {
|
|
663
|
-
ref: notice,
|
|
664
|
-
role: "alert",
|
|
665
|
-
tabIndex: -1,
|
|
666
|
-
className: "hm-image-engine-unavailable",
|
|
667
|
-
children: messages.t("editor.engineUnavailable")
|
|
668
|
-
}) : children
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
// src/react/export/export-listener.ts
|
|
672
|
-
var ExportListenerContext = createContext(null);
|
|
673
|
-
// src/react/export/ExportDialog.tsx
|
|
674
|
-
var FORMATS = [
|
|
675
|
-
"png",
|
|
676
|
-
"jpeg",
|
|
677
|
-
"webp"
|
|
678
|
-
];
|
|
679
|
-
var EXTENSIONS = {
|
|
680
|
-
png: "png",
|
|
681
|
-
jpeg: "jpg",
|
|
682
|
-
webp: "webp"
|
|
683
|
-
};
|
|
684
|
-
var FIELDS$1 = [
|
|
685
|
-
"title",
|
|
686
|
-
"description",
|
|
687
|
-
"artist",
|
|
688
|
-
"copyright"
|
|
689
|
-
];
|
|
690
|
-
var KINDS$1 = [
|
|
691
|
-
"location",
|
|
692
|
-
"camera",
|
|
693
|
-
"timestamps",
|
|
694
|
-
"thumbnail",
|
|
695
|
-
"colourProfile",
|
|
696
|
-
"other"
|
|
697
|
-
];
|
|
698
|
-
var DEFAULT_QUALITY = 92;
|
|
699
|
-
var keepable = (text) => longerThan(text, 2e3) ? [...text].slice(0, MAX_METADATA_LENGTH).join("") : text;
|
|
700
|
-
function initialDraft(plan, source) {
|
|
701
|
-
return {
|
|
702
|
-
format: FORMATS.includes(source.format) ? source.format : "png",
|
|
703
|
-
quality: DEFAULT_QUALITY,
|
|
704
|
-
output: plan.output,
|
|
705
|
-
metadata: plan.metadata
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
var sameOutput = (a, b) => a.kind === "scale" && b.kind === "scale" ? a.scale === b.scale : a.kind === "fit" && b.kind === "fit" && a.width === b.width && a.height === b.height;
|
|
709
|
-
function changes(plan, draft) {
|
|
710
|
-
const commands = [];
|
|
711
|
-
if (!sameOutput(plan.output, draft.output)) commands.push({
|
|
712
|
-
type: "image.setOutput",
|
|
713
|
-
output: draft.output
|
|
714
|
-
});
|
|
715
|
-
for (const field of FIELDS$1) if (plan.metadata[field] !== draft.metadata[field]) commands.push({
|
|
716
|
-
type: "image.setMetadata",
|
|
717
|
-
field,
|
|
718
|
-
value: draft.metadata[field]
|
|
719
|
-
});
|
|
720
|
-
return commands;
|
|
721
|
-
}
|
|
722
|
-
var formatOf = (draft) => draft.format === "png" ? { type: "png" } : {
|
|
723
|
-
type: draft.format,
|
|
724
|
-
quality: draft.quality / 100
|
|
725
|
-
};
|
|
726
|
-
function ImageExportDialog(props) {
|
|
727
|
-
const { onExport, fileName = "image" } = props;
|
|
728
|
-
const lifecycle = engineInternals(useImageInternals().engine);
|
|
729
|
-
const session = useImageSession();
|
|
730
|
-
const { plan, source } = useImageDocument();
|
|
731
|
-
const [editor, editorStore] = useImageEditorState();
|
|
732
|
-
const messages = useImageMessages();
|
|
733
|
-
const announce = useAnnounce();
|
|
734
|
-
const listener = useContext(ExportListenerContext);
|
|
735
|
-
const [draft, setDraft] = useState(null);
|
|
736
|
-
const [phase, setPhase] = useState({ kind: "choose" });
|
|
737
|
-
const [error, setError] = useState(null);
|
|
738
|
-
const controller = useRef(null);
|
|
739
|
-
const objectUrl = useRef(null);
|
|
740
|
-
const downloadButton = useRef(null);
|
|
741
|
-
const open = editor.dialog === "export" && plan !== null && source !== null;
|
|
742
|
-
const current = draft ?? (plan && source ? initialDraft(plan, source) : null);
|
|
743
|
-
const revoke = () => {
|
|
744
|
-
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
745
|
-
objectUrl.current = null;
|
|
743
|
+
function createGesture(session, editor) {
|
|
744
|
+
let pending;
|
|
745
|
+
let timer;
|
|
746
|
+
const reducer = createImageReducer((id) => session.getSnapshot().sources.find((source) => source.id === id));
|
|
747
|
+
const clearTimer = () => {
|
|
748
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
749
|
+
timer = void 0;
|
|
746
750
|
};
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
running?.abort();
|
|
752
|
-
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
753
|
-
objectUrl.current = null;
|
|
754
|
-
setDraft(null);
|
|
755
|
-
setPhase((now) => now.kind === "choose" ? now : { kind: "choose" });
|
|
756
|
-
setError(null);
|
|
757
|
-
}, [open]);
|
|
758
|
-
useEffect(() => () => {
|
|
759
|
-
controller.current?.abort();
|
|
760
|
-
controller.current = null;
|
|
761
|
-
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
762
|
-
}, []);
|
|
763
|
-
const done = phase.kind === "done";
|
|
764
|
-
useEffect(() => {
|
|
765
|
-
if (done) downloadButton.current?.focus();
|
|
766
|
-
}, [done]);
|
|
767
|
-
const close = () => {
|
|
768
|
-
editorStore.set((state) => state.dialog === null ? state : {
|
|
751
|
+
const end = () => {
|
|
752
|
+
clearTimer();
|
|
753
|
+
pending = void 0;
|
|
754
|
+
editor.set((state) => state.preview === null ? state : {
|
|
769
755
|
...state,
|
|
770
|
-
|
|
756
|
+
preview: null
|
|
771
757
|
});
|
|
772
758
|
};
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
const commands = changes(plan, current);
|
|
783
|
-
if (commands.length > 0) session.execute(commands);
|
|
784
|
-
} catch (reason) {
|
|
785
|
-
setError(reason);
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
const running = new AbortController();
|
|
789
|
-
controller.current = running;
|
|
790
|
-
setPhase({
|
|
791
|
-
kind: "exporting",
|
|
792
|
-
progress: 0
|
|
793
|
-
});
|
|
794
|
-
try {
|
|
795
|
-
const result = await session.export(formatOf(current), {
|
|
796
|
-
signal: running.signal,
|
|
797
|
-
onProgress: (progress) => setPhase((now) => now.kind === "exporting" ? {
|
|
798
|
-
kind: "exporting",
|
|
799
|
-
progress
|
|
800
|
-
} : now)
|
|
801
|
-
});
|
|
802
|
-
if (controller.current !== running || lifecycle?.getSnapshot()) return;
|
|
803
|
-
controller.current = null;
|
|
804
|
-
announce(messages.t("export.done", {
|
|
805
|
-
format: formatName(current.format),
|
|
806
|
-
size: result.blob.size
|
|
759
|
+
const value = {
|
|
760
|
+
preview(commands) {
|
|
761
|
+
const plan = session.getSnapshot().plan;
|
|
762
|
+
if (!plan) return;
|
|
763
|
+
const preview = applyCommands(reducer, plan, commands).state;
|
|
764
|
+
pending = commands;
|
|
765
|
+
editor.set((state) => ({
|
|
766
|
+
...state,
|
|
767
|
+
preview
|
|
807
768
|
}));
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
769
|
+
},
|
|
770
|
+
commit() {
|
|
771
|
+
const commands = pending;
|
|
772
|
+
end();
|
|
773
|
+
if (commands && commands.length > 0) session.execute(commands);
|
|
774
|
+
},
|
|
775
|
+
commitSoon() {
|
|
776
|
+
clearTimer();
|
|
777
|
+
timer = setTimeout(() => value.commit(), 500);
|
|
778
|
+
},
|
|
779
|
+
cancel: end,
|
|
780
|
+
active: () => pending !== void 0
|
|
781
|
+
};
|
|
782
|
+
return value;
|
|
783
|
+
}
|
|
784
|
+
function useGesture() {
|
|
785
|
+
const { session, editor } = useImageInternals();
|
|
786
|
+
const gesture = useMemo(() => createGesture(session, editor), [editor, session]);
|
|
787
|
+
useEffect(() => () => gesture.commit(), [gesture]);
|
|
788
|
+
return gesture;
|
|
789
|
+
}
|
|
790
|
+
var shared = /* @__PURE__ */ new WeakMap();
|
|
791
|
+
function useSharedGesture() {
|
|
792
|
+
const { session, editor } = useImageInternals();
|
|
793
|
+
const gesture = useMemo(() => {
|
|
794
|
+
const existing = shared.get(editor);
|
|
795
|
+
if (existing) return existing;
|
|
796
|
+
const created = createGesture(session, editor);
|
|
797
|
+
shared.set(editor, created);
|
|
798
|
+
return created;
|
|
799
|
+
}, [editor, session]);
|
|
800
|
+
useEffect(() => () => gesture.commit(), [gesture]);
|
|
801
|
+
return gesture;
|
|
802
|
+
}
|
|
803
|
+
// src/react/redact/use-redact.ts
|
|
804
|
+
var keysOf = (plan) => new Set([...plan.layers, ...plan.redactions].map((item) => item.key));
|
|
805
|
+
function newRedactionKey(plan) {
|
|
806
|
+
return createImageKey(keysOf(plan));
|
|
807
|
+
}
|
|
808
|
+
function useRedactActions() {
|
|
809
|
+
const { session, editor, messages } = useImageInternals();
|
|
810
|
+
const announce = useAnnounce();
|
|
811
|
+
const gesture = useSharedGesture();
|
|
812
|
+
return useMemo(() => {
|
|
813
|
+
const settings = () => editor.getSnapshot().redact ?? {
|
|
814
|
+
selected: null,
|
|
815
|
+
mode: "solid",
|
|
816
|
+
colour: "#000000"
|
|
817
|
+
};
|
|
818
|
+
const set = (changes) => editor.set((state) => state.tool === "redact" ? {
|
|
819
|
+
...state,
|
|
820
|
+
redact: {
|
|
821
|
+
...settings(),
|
|
822
|
+
...changes
|
|
820
823
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
824
|
+
} : state);
|
|
825
|
+
const redaction = (key, region) => {
|
|
826
|
+
const { mode, colour } = settings();
|
|
827
|
+
const fitted = fitRedactionRegion(region);
|
|
828
|
+
return mode === "solid" ? {
|
|
829
|
+
key,
|
|
830
|
+
mode,
|
|
831
|
+
...fitted,
|
|
832
|
+
colour
|
|
833
|
+
} : {
|
|
834
|
+
key,
|
|
835
|
+
mode,
|
|
836
|
+
...fitted
|
|
837
|
+
};
|
|
838
|
+
};
|
|
839
|
+
const insert = (item, plan) => ({
|
|
840
|
+
type: "image.insertRedactions",
|
|
841
|
+
at: plan.redactions.length,
|
|
842
|
+
redactions: [item]
|
|
843
|
+
});
|
|
844
|
+
const count = () => session.getSnapshot().plan?.redactions.length ?? 0;
|
|
845
|
+
return {
|
|
846
|
+
gesture,
|
|
847
|
+
add() {
|
|
848
|
+
const { plan, source } = session.getSnapshot();
|
|
849
|
+
if (!plan || !source) return;
|
|
850
|
+
gesture.commit();
|
|
851
|
+
const { width, height } = compositionSize(plan, source);
|
|
852
|
+
const shown = {
|
|
853
|
+
x: Math.round(width * .375),
|
|
854
|
+
y: Math.round(height * .375),
|
|
855
|
+
width: Math.max(1, Math.round(width / 4)),
|
|
856
|
+
height: Math.max(1, Math.round(height / 4))
|
|
857
|
+
};
|
|
858
|
+
const key = newRedactionKey(plan);
|
|
859
|
+
const region = compositionRectToScene(shown, cropRect(plan.base.crop, source), plan.base.orientation);
|
|
860
|
+
session.execute(insert(redaction(key, region), plan));
|
|
861
|
+
set({ selected: key });
|
|
862
|
+
announce(messages.t("redact.added", { count: count() }));
|
|
863
|
+
},
|
|
864
|
+
select(key) {
|
|
865
|
+
if (settings().selected === key) return;
|
|
866
|
+
gesture.commit();
|
|
867
|
+
const item = session.getSnapshot().plan?.redactions.find((r) => r.key === key);
|
|
868
|
+
set({
|
|
869
|
+
selected: item ? key : null,
|
|
870
|
+
...item ? { mode: item.mode } : {},
|
|
871
|
+
...item?.mode === "solid" ? { colour: item.colour } : {}
|
|
872
|
+
});
|
|
873
|
+
},
|
|
874
|
+
remove(key) {
|
|
875
|
+
gesture.cancel();
|
|
876
|
+
if (!session.getSnapshot().plan?.redactions.some((r) => r.key === key)) return;
|
|
877
|
+
session.execute({
|
|
878
|
+
type: "image.removeRedactions",
|
|
879
|
+
keys: [key]
|
|
880
|
+
});
|
|
881
|
+
if (settings().selected === key) set({ selected: null });
|
|
882
|
+
announce(count() === 0 ? messages.t("redact.removedLast") : messages.t("redact.removed", { count: count() }));
|
|
883
|
+
},
|
|
884
|
+
drawing(key, rect) {
|
|
885
|
+
const { plan, source } = session.getSnapshot();
|
|
886
|
+
if (!plan || !source) return;
|
|
887
|
+
const region = compositionRectToScene(rect, cropRect(plan.base.crop, source), plan.base.orientation);
|
|
888
|
+
gesture.preview([insert(redaction(key, region), plan)]);
|
|
889
|
+
},
|
|
890
|
+
moving(key, region) {
|
|
891
|
+
gesture.preview([{
|
|
892
|
+
type: "image.updateRedactions",
|
|
893
|
+
updates: [{
|
|
894
|
+
key,
|
|
895
|
+
props: fitRedactionRegion(region)
|
|
896
|
+
}]
|
|
897
|
+
}]);
|
|
898
|
+
},
|
|
899
|
+
commit(soon = false) {
|
|
900
|
+
if (soon) {
|
|
901
|
+
gesture.commitSoon();
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
const drew = gesture.active() && count();
|
|
905
|
+
gesture.commit();
|
|
906
|
+
if (drew !== false && count() > drew) announce(messages.t("redact.added", { count: count() }));
|
|
907
|
+
},
|
|
908
|
+
cancel() {
|
|
909
|
+
gesture.cancel();
|
|
910
|
+
},
|
|
911
|
+
setRegion(key, region) {
|
|
912
|
+
gesture.commit();
|
|
913
|
+
session.execute({
|
|
914
|
+
type: "image.updateRedactions",
|
|
915
|
+
updates: [{
|
|
916
|
+
key,
|
|
917
|
+
props: fitRedactionRegion(region)
|
|
918
|
+
}]
|
|
919
|
+
});
|
|
920
|
+
},
|
|
921
|
+
setMode(mode) {
|
|
922
|
+
gesture.commit();
|
|
923
|
+
const { selected, colour } = settings();
|
|
924
|
+
const item = session.getSnapshot().plan?.redactions.find((r) => r.key === selected);
|
|
925
|
+
if (item && item.mode !== mode) session.execute({
|
|
926
|
+
type: "image.updateRedactions",
|
|
927
|
+
updates: [{
|
|
928
|
+
key: item.key,
|
|
929
|
+
props: mode === "solid" ? {
|
|
930
|
+
mode,
|
|
931
|
+
colour
|
|
932
|
+
} : { mode }
|
|
933
|
+
}]
|
|
934
|
+
});
|
|
935
|
+
set({ mode });
|
|
936
|
+
},
|
|
937
|
+
setColour(colour) {
|
|
938
|
+
gesture.commit();
|
|
939
|
+
const item = session.getSnapshot().plan?.redactions.find((r) => r.key === settings().selected);
|
|
940
|
+
if (item?.mode === "solid" && item.colour !== colour) session.execute({
|
|
941
|
+
type: "image.updateRedactions",
|
|
942
|
+
updates: [{
|
|
943
|
+
key: item.key,
|
|
944
|
+
props: { colour }
|
|
945
|
+
}]
|
|
946
|
+
});
|
|
947
|
+
set({ colour });
|
|
948
|
+
},
|
|
949
|
+
done() {
|
|
950
|
+
gesture.commit();
|
|
951
|
+
editor.set((state) => state.tool === "redact" ? {
|
|
952
|
+
...state,
|
|
953
|
+
...NO_TOOL,
|
|
954
|
+
preview: null
|
|
955
|
+
} : state);
|
|
833
956
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const link = document.createElement("a");
|
|
843
|
-
link.href = objectUrl.current;
|
|
844
|
-
link.download = `${fileName}.${EXTENSIONS[phase.format]}`;
|
|
845
|
-
link.click();
|
|
846
|
-
};
|
|
847
|
-
const composition = compositionSize(plan, source);
|
|
848
|
-
const size = outputSize(current.output, composition);
|
|
849
|
-
const removed = KINDS$1.filter((kind) => source.metadata[kind]);
|
|
850
|
-
const kept = FIELDS$1.filter((field) => current.metadata[field] !== "");
|
|
851
|
-
const exporting = phase.kind === "exporting";
|
|
852
|
-
const footer = phase.kind === "done" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
853
|
-
variant: "secondary",
|
|
854
|
-
onClick: close,
|
|
855
|
-
children: messages.t("export.close")
|
|
856
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
857
|
-
ref: downloadButton,
|
|
858
|
-
variant: "primary",
|
|
859
|
-
onClick: download,
|
|
860
|
-
children: messages.t("export.download")
|
|
861
|
-
})] }) : exporting ? /* @__PURE__ */ jsx(Button, {
|
|
862
|
-
variant: "secondary",
|
|
863
|
-
onClick: stop,
|
|
864
|
-
children: messages.t("export.stop")
|
|
865
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
866
|
-
variant: "secondary",
|
|
867
|
-
onClick: close,
|
|
868
|
-
children: messages.t("export.cancel")
|
|
869
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
870
|
-
variant: "primary",
|
|
871
|
-
onClick: () => void run(),
|
|
872
|
-
children: messages.t("export.confirm")
|
|
873
|
-
})] });
|
|
874
|
-
return /* @__PURE__ */ jsx(Dialog, {
|
|
875
|
-
open,
|
|
876
|
-
onOpenChange: (next) => {
|
|
877
|
-
if (!next) close();
|
|
878
|
-
},
|
|
879
|
-
title: messages.t("export.title"),
|
|
880
|
-
description: messages.t("export.description"),
|
|
881
|
-
footer,
|
|
882
|
-
className: ["hm-image-export", props.className].filter(Boolean).join(" "),
|
|
883
|
-
children: phase.kind === "done" ? /* @__PURE__ */ jsx("p", {
|
|
884
|
-
className: "hm-image-export-result",
|
|
885
|
-
children: messages.t("export.ready", {
|
|
886
|
-
width: phase.result.width,
|
|
887
|
-
height: phase.result.height,
|
|
888
|
-
format: formatName(phase.format),
|
|
889
|
-
size: phase.result.blob.size
|
|
890
|
-
})
|
|
891
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
892
|
-
/* @__PURE__ */ jsxs("fieldset", {
|
|
893
|
-
className: "hm-image-export-choices",
|
|
894
|
-
disabled: exporting,
|
|
895
|
-
children: [
|
|
896
|
-
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
897
|
-
label: messages.t("export.format"),
|
|
898
|
-
value: current.format,
|
|
899
|
-
size: "small",
|
|
900
|
-
options: FORMATS.map((format) => ({
|
|
901
|
-
value: format,
|
|
902
|
-
label: formatName(format)
|
|
903
|
-
})),
|
|
904
|
-
onValueChange: (format) => update({ format })
|
|
905
|
-
}),
|
|
906
|
-
current.format === "png" ? null : /* @__PURE__ */ jsx(Field, {
|
|
907
|
-
label: messages.t("export.quality"),
|
|
908
|
-
className: "hm-image-slider-field",
|
|
909
|
-
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
910
|
-
className: "hm-image-adjust-row",
|
|
911
|
-
children: [/* @__PURE__ */ jsx(Slider, {
|
|
912
|
-
...control,
|
|
913
|
-
min: 1,
|
|
914
|
-
max: 100,
|
|
915
|
-
step: 1,
|
|
916
|
-
largeStep: 10,
|
|
917
|
-
value: current.quality,
|
|
918
|
-
formatValue: (quality) => messages.t("export.qualityValue", { quality }),
|
|
919
|
-
onValueChange: (quality) => update({ quality: Math.round(quality) })
|
|
920
|
-
}), /* @__PURE__ */ jsx("output", {
|
|
921
|
-
className: "hm-image-adjust-value",
|
|
922
|
-
"aria-hidden": "true",
|
|
923
|
-
children: messages.t("export.qualityValue", { quality: current.quality })
|
|
924
|
-
})]
|
|
925
|
-
})
|
|
926
|
-
}),
|
|
927
|
-
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
928
|
-
label: messages.t("export.size"),
|
|
929
|
-
value: current.output.kind,
|
|
930
|
-
size: "small",
|
|
931
|
-
options: [{
|
|
932
|
-
value: "scale",
|
|
933
|
-
label: messages.t("export.sizes.scale")
|
|
934
|
-
}, {
|
|
935
|
-
value: "fit",
|
|
936
|
-
label: messages.t("export.sizes.fit")
|
|
937
|
-
}],
|
|
938
|
-
onValueChange: (kind) => update({ output: kind === "fit" ? {
|
|
939
|
-
kind: "fit",
|
|
940
|
-
width: composition.width,
|
|
941
|
-
height: composition.height
|
|
942
|
-
} : {
|
|
943
|
-
kind: "scale",
|
|
944
|
-
scale: 1
|
|
945
|
-
} })
|
|
946
|
-
}),
|
|
947
|
-
/* @__PURE__ */ jsx("div", {
|
|
948
|
-
className: "hm-image-export-fields",
|
|
949
|
-
children: current.output.kind === "scale" ? /* @__PURE__ */ jsx(Field, {
|
|
950
|
-
label: messages.t("export.scale"),
|
|
951
|
-
children: /* @__PURE__ */ jsx(NumberField, {
|
|
952
|
-
value: Math.round(current.output.scale * 100),
|
|
953
|
-
min: 1,
|
|
954
|
-
max: 100,
|
|
955
|
-
step: 1,
|
|
956
|
-
largeStep: 10,
|
|
957
|
-
onValueChange: (percent) => update({ output: {
|
|
958
|
-
kind: "scale",
|
|
959
|
-
scale: Math.round(percent) / 100
|
|
960
|
-
} })
|
|
961
|
-
})
|
|
962
|
-
}) : ["width", "height"].map((side) => {
|
|
963
|
-
const output = current.output;
|
|
964
|
-
return /* @__PURE__ */ jsx(Field, {
|
|
965
|
-
label: messages.t(side === "width" ? "export.fitWidth" : "export.fitHeight"),
|
|
966
|
-
children: /* @__PURE__ */ jsx(NumberField, {
|
|
967
|
-
value: output[side],
|
|
968
|
-
min: 1,
|
|
969
|
-
step: 1,
|
|
970
|
-
largeStep: 100,
|
|
971
|
-
onValueChange: (value) => update({ output: {
|
|
972
|
-
...output,
|
|
973
|
-
[side]: Math.max(1, Math.round(value))
|
|
974
|
-
} })
|
|
975
|
-
})
|
|
976
|
-
}, side);
|
|
977
|
-
})
|
|
978
|
-
}),
|
|
979
|
-
/* @__PURE__ */ jsxs("fieldset", {
|
|
980
|
-
className: "hm-image-export-metadata",
|
|
981
|
-
children: [
|
|
982
|
-
/* @__PURE__ */ jsx("legend", { children: messages.t("export.fields") }),
|
|
983
|
-
/* @__PURE__ */ jsx("p", {
|
|
984
|
-
className: "hm-image-export-hint",
|
|
985
|
-
children: messages.t("export.fieldsHint")
|
|
986
|
-
}),
|
|
987
|
-
/* @__PURE__ */ jsx("div", {
|
|
988
|
-
className: "hm-image-export-fields",
|
|
989
|
-
children: FIELDS$1.map((field) => /* @__PURE__ */ jsx(Field, {
|
|
990
|
-
label: messages.t(`export.field.${field}`),
|
|
991
|
-
children: /* @__PURE__ */ jsx(TextField, {
|
|
992
|
-
autoComplete: "off",
|
|
993
|
-
value: current.metadata[field],
|
|
994
|
-
onValueChange: (value) => update({ metadata: {
|
|
995
|
-
...current.metadata,
|
|
996
|
-
[field]: keepable(value)
|
|
997
|
-
} })
|
|
998
|
-
})
|
|
999
|
-
}, field))
|
|
1000
|
-
})
|
|
1001
|
-
]
|
|
1002
|
-
})
|
|
1003
|
-
]
|
|
1004
|
-
}),
|
|
1005
|
-
/* @__PURE__ */ jsxs("section", {
|
|
1006
|
-
className: "hm-image-export-summary",
|
|
1007
|
-
"aria-label": messages.t("export.summary"),
|
|
1008
|
-
children: [
|
|
1009
|
-
/* @__PURE__ */ jsx("p", { children: messages.t("export.output", {
|
|
1010
|
-
width: size.width,
|
|
1011
|
-
height: size.height,
|
|
1012
|
-
format: formatName(current.format)
|
|
1013
|
-
}) }),
|
|
1014
|
-
plan.redactions.length > 0 ? /* @__PURE__ */ jsxs("p", { children: [messages.t("export.redacted", { count: plan.redactions.length }), plan.redactions.some((redaction) => redaction.mode === "pixelate") ? ` ${messages.t("export.redactedPixelated")}` : null] }) : null,
|
|
1015
|
-
removed.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: messages.t("export.removed") }), /* @__PURE__ */ jsx("ul", { children: removed.map((kind) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.kind.${kind}`) }, kind)) })] }) : /* @__PURE__ */ jsx("p", { children: messages.t("export.removedNone") }),
|
|
1016
|
-
kept.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: messages.t("export.kept") }), /* @__PURE__ */ jsx("ul", { children: kept.map((field) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.field.${field}`) }, field)) })] }) : null
|
|
1017
|
-
]
|
|
1018
|
-
}),
|
|
1019
|
-
exporting ? /* @__PURE__ */ jsx(ProgressBar, {
|
|
1020
|
-
label: messages.t("export.progress"),
|
|
1021
|
-
value: Math.round(phase.progress * 100),
|
|
1022
|
-
max: 100
|
|
1023
|
-
}) : null,
|
|
1024
|
-
error ? /* @__PURE__ */ jsx("p", {
|
|
1025
|
-
className: "hm-image-export-error",
|
|
1026
|
-
role: "alert",
|
|
1027
|
-
children: messages.error(error)
|
|
1028
|
-
}) : null
|
|
1029
|
-
] })
|
|
1030
|
-
});
|
|
957
|
+
};
|
|
958
|
+
}, [
|
|
959
|
+
announce,
|
|
960
|
+
editor,
|
|
961
|
+
gesture,
|
|
962
|
+
messages,
|
|
963
|
+
session
|
|
964
|
+
]);
|
|
1031
965
|
}
|
|
1032
|
-
// src/
|
|
1033
|
-
var
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
return createStore(IDLE);
|
|
966
|
+
// src/react/layers/use-layers.ts
|
|
967
|
+
var DUPLICATE_OFFSET = 8;
|
|
968
|
+
var LABEL_LENGTH = 40;
|
|
969
|
+
var EVERY_FORBIDDEN = new RegExp(FORBIDDEN_IN_TEXT.source, "gu");
|
|
970
|
+
function layerLabel(layer, messages) {
|
|
971
|
+
if (layer.name !== "") return layer.name;
|
|
972
|
+
if (layer.kind === "text") {
|
|
973
|
+
const line = layer.text.split("\n").find((text) => text.trim() !== "");
|
|
974
|
+
if (line) return [...line.trim()].slice(0, LABEL_LENGTH).join("");
|
|
975
|
+
}
|
|
976
|
+
return messages.t(`layers.kinds.${layer.kind === "shape" ? layer.shape : layer.kind}`);
|
|
1044
977
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
"editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.",
|
|
1048
|
-
"editor.label": "Image editor",
|
|
1049
|
-
"editor.preview": "Edited image preview, {width, number} × {height, number}",
|
|
1050
|
-
"editor.empty": "Open an image to start editing. It stays on this device.",
|
|
1051
|
-
"editor.choose": "Choose an image",
|
|
1052
|
-
"editor.dropHint": "or drop it here",
|
|
1053
|
-
"editor.opening": "Opening the image…",
|
|
1054
|
-
"editor.cancel": "Cancel",
|
|
1055
|
-
"editor.opened": "Image opened, {width, number} × {height, number}.",
|
|
1056
|
-
"editor.undid": "Undid {action}.",
|
|
1057
|
-
"editor.redid": "Redid {action}.",
|
|
1058
|
-
"actions.image.setCrop": "crop",
|
|
1059
|
-
"actions.image.setOrientation": "rotate or flip",
|
|
1060
|
-
"actions.image.setOutput": "size",
|
|
1061
|
-
"actions.image.setMetadata": "metadata",
|
|
1062
|
-
"actions.image.setDevelop": "adjustment",
|
|
1063
|
-
"actions.image.setFilter": "filter",
|
|
1064
|
-
"actions.image.insertLayers": "layer",
|
|
1065
|
-
"actions.image.removeLayers": "layer",
|
|
1066
|
-
"actions.image.restoreLayers": "layer",
|
|
1067
|
-
"actions.image.moveLayers": "layer order",
|
|
1068
|
-
"actions.image.setLayerOrder": "layer order",
|
|
1069
|
-
"actions.image.updateLayers": "layer change",
|
|
1070
|
-
"actions.image.insertRedactions": "redaction",
|
|
1071
|
-
"actions.image.removeRedactions": "redaction",
|
|
1072
|
-
"actions.image.restoreRedactions": "redaction",
|
|
1073
|
-
"actions.image.moveRedactions": "redaction order",
|
|
1074
|
-
"actions.image.setRedactionOrder": "redaction order",
|
|
1075
|
-
"actions.image.updateRedactions": "redaction change",
|
|
1076
|
-
"toolbar.label": "Image tools",
|
|
1077
|
-
"toolbar.groups.file": "File",
|
|
1078
|
-
"toolbar.groups.history": "History",
|
|
1079
|
-
"toolbar.groups.orientation": "Rotate",
|
|
1080
|
-
"toolbar.groups.zoom": "Zoom",
|
|
1081
|
-
"toolbar.groups.other": "More tools",
|
|
1082
|
-
"tools.open": "Open image",
|
|
1083
|
-
"tools.undo": "Undo",
|
|
1084
|
-
"tools.redo": "Redo",
|
|
1085
|
-
"tools.rotate-left": "Rotate left",
|
|
1086
|
-
"tools.rotate-right": "Rotate right",
|
|
1087
|
-
"tools.zoom-in": "Zoom in",
|
|
1088
|
-
"tools.zoom-out": "Zoom out",
|
|
1089
|
-
"tools.zoom-fit": "Fit to the stage",
|
|
1090
|
-
"tools.crop": "Crop",
|
|
1091
|
-
"tools.flip-horizontal": "Flip horizontally",
|
|
1092
|
-
"tools.flip-vertical": "Flip vertically",
|
|
1093
|
-
"toolbar.groups.crop": "Crop",
|
|
1094
|
-
"crop.frame": "Crop area",
|
|
1095
|
-
"crop.frameDescription": "{width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; with Shift, they resize it; Enter applies and Escape cancels.",
|
|
1096
|
-
"crop.size": "{width, number} × {height, number}, from {x, number}, {y, number}",
|
|
1097
|
-
"crop.panel": "Crop",
|
|
1098
|
-
"crop.x": "Left",
|
|
1099
|
-
"crop.y": "Top",
|
|
1100
|
-
"crop.width": "Width",
|
|
1101
|
-
"crop.height": "Height",
|
|
1102
|
-
"crop.aspect": "Aspect ratio",
|
|
1103
|
-
"crop.aspects.free": "Free",
|
|
1104
|
-
"crop.aspects.original": "Original",
|
|
1105
|
-
"crop.aspects.ratio": "{width}:{height}",
|
|
1106
|
-
"crop.apply": "Apply crop",
|
|
1107
|
-
"crop.cancel": "Cancel",
|
|
1108
|
-
"crop.reset": "Whole image",
|
|
1109
|
-
"crop.applied": "Cropped to {width, number} × {height, number}.",
|
|
1110
|
-
"tools.redact": "Redact",
|
|
1111
|
-
"toolbar.groups.redact": "Redact",
|
|
1112
|
-
"redact.panel": "Redact",
|
|
1113
|
-
"redact.intro": "Cover parts of the image. Only the exported image is redacted: the original stays in the editor.",
|
|
1114
|
-
"redact.add": "Add area",
|
|
1115
|
-
"redact.done": "Done",
|
|
1116
|
-
"redact.mode": "Cover with",
|
|
1117
|
-
"redact.modes.solid": "Solid colour",
|
|
1118
|
-
"redact.modes.pixelate": "Pixelation",
|
|
1119
|
-
"redact.pixelateHint": "Pixelation may not hide text. For text and numbers, use a solid colour.",
|
|
1120
|
-
"redact.colour": "Colour",
|
|
1121
|
-
"redact.colours.black": "Black",
|
|
1122
|
-
"redact.colours.white": "White",
|
|
1123
|
-
"redact.x": "Left",
|
|
1124
|
-
"redact.y": "Top",
|
|
1125
|
-
"redact.width": "Width",
|
|
1126
|
-
"redact.height": "Height",
|
|
1127
|
-
"redact.areas": "Redacted areas",
|
|
1128
|
-
"redact.none": "No areas yet. Drag across the image, or add one.",
|
|
1129
|
-
"redact.area": "Area {index, number}: {mode}, {width, number} × {height, number}",
|
|
1130
|
-
"redact.modeNames.solid": "solid colour",
|
|
1131
|
-
"redact.modeNames.pixelate": "pixelated",
|
|
1132
|
-
"redact.remove": "Remove area {index, number}",
|
|
1133
|
-
"redact.frame": "Redacted area {index, number} of {count, number}",
|
|
1134
|
-
"redact.frameDescription": "{mode}, {width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; with Shift, they resize it; Delete removes it and Escape ends redacting.",
|
|
1135
|
-
"redact.added": /* @__PURE__ */ plural("count", {
|
|
1136
|
-
one: "Area added. {count} area is redacted.",
|
|
1137
|
-
other: "Area added. {count, number} areas are redacted."
|
|
1138
|
-
}),
|
|
1139
|
-
"redact.removedLast": "Area removed. Nothing is redacted.",
|
|
1140
|
-
"redact.removed": /* @__PURE__ */ plural("count", {
|
|
1141
|
-
one: "Area removed. {count} area is redacted.",
|
|
1142
|
-
other: "Area removed. {count, number} areas are redacted."
|
|
1143
|
-
}),
|
|
1144
|
-
"tools.add-text": "Add text",
|
|
1145
|
-
"tools.add-rectangle": "Add a rectangle",
|
|
1146
|
-
"tools.add-ellipse": "Add an ellipse",
|
|
1147
|
-
"tools.add-image": "Add an image",
|
|
1148
|
-
"toolbar.groups.add": "Add",
|
|
1149
|
-
"editor.inserting": "Adding the image…",
|
|
1150
|
-
"layers.text": "Text",
|
|
1151
|
-
"layers.font": "Font",
|
|
1152
|
-
"layers.fonts.sans-serif": "Sans",
|
|
1153
|
-
"layers.fonts.serif": "Serif",
|
|
1154
|
-
"layers.fonts.monospace": "Mono",
|
|
1155
|
-
"layers.align": "Alignment",
|
|
1156
|
-
"layers.alignments.start": "Start",
|
|
1157
|
-
"layers.alignments.center": "Centre",
|
|
1158
|
-
"layers.alignments.end": "End",
|
|
1159
|
-
"layers.bold": "Bold",
|
|
1160
|
-
"layers.colour": "Colour",
|
|
1161
|
-
"layers.fill": "Fill",
|
|
1162
|
-
"layers.outline": "Outline",
|
|
1163
|
-
"layers.fillColour": "Fill colour",
|
|
1164
|
-
"layers.outlineColour": "Outline colour",
|
|
1165
|
-
"layers.outlineWidth": "Outline width",
|
|
1166
|
-
"layers.colours.black": "Black",
|
|
1167
|
-
"layers.colours.white": "White",
|
|
1168
|
-
"layers.colours.red": "Red",
|
|
1169
|
-
"layers.colours.yellow": "Yellow",
|
|
1170
|
-
"layers.colours.green": "Green",
|
|
1171
|
-
"layers.colours.blue": "Blue",
|
|
1172
|
-
"tools.layers": "Layers",
|
|
1173
|
-
"toolbar.groups.layers": "Layers",
|
|
1174
|
-
"layers.panel": "Layers",
|
|
1175
|
-
"layers.list": "Layers, the top one first",
|
|
1176
|
-
"layers.none": "No layers yet. Add text, a shape or an image from the toolbar.",
|
|
1177
|
-
"layers.kinds.text": "Text",
|
|
1178
|
-
"layers.kinds.rectangle": "Rectangle",
|
|
1179
|
-
"layers.kinds.ellipse": "Ellipse",
|
|
1180
|
-
"layers.kinds.image": "Image",
|
|
1181
|
-
"layers.visible": "Show {name}",
|
|
1182
|
-
"layers.selected": "Selected layer",
|
|
1183
|
-
"layers.moveUp": "Move up",
|
|
1184
|
-
"layers.moveDown": "Move down",
|
|
1185
|
-
"layers.mirror": "Mirror",
|
|
1186
|
-
"layers.duplicate": "Duplicate",
|
|
1187
|
-
"layers.remove": "Delete",
|
|
1188
|
-
"layers.name": "Name",
|
|
1189
|
-
"layers.x": "Left",
|
|
1190
|
-
"layers.y": "Top",
|
|
1191
|
-
"layers.width": "Width",
|
|
1192
|
-
"layers.height": "Height",
|
|
1193
|
-
"layers.rotation": "Turn, in degrees",
|
|
1194
|
-
"layers.opacity": "Opacity, in percent",
|
|
1195
|
-
"layers.done": "Done",
|
|
1196
|
-
"layers.frame": "Layer {index, number} of {count, number}: {name}",
|
|
1197
|
-
"layers.frameDescription": "{width, number} × {height, number} pixels, from {x, number}, {y, number}, turned {degrees, number}°. Arrow keys move it; with Shift, they resize it; Delete removes it and Escape closes the layers.",
|
|
1198
|
-
"layers.movedUp": "Moved {name} up. It's layer {index, number} of {count, number}.",
|
|
1199
|
-
"layers.movedDown": "Moved {name} down. It's layer {index, number} of {count, number}.",
|
|
1200
|
-
"layers.duplicated": "Duplicated {name}.",
|
|
1201
|
-
"layers.removed": "Deleted {name}.",
|
|
1202
|
-
"inspector.label": "Panels",
|
|
1203
|
-
"inspector.adjust": "Adjust",
|
|
1204
|
-
"inspector.filters": "Filters",
|
|
1205
|
-
"inspector.info": "Info",
|
|
1206
|
-
"notices.label": "Notices",
|
|
1207
|
-
"notices.dismiss": "Dismiss",
|
|
1208
|
-
"notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.",
|
|
1209
|
-
"info.panel": "Image info",
|
|
1210
|
-
"info.size": "Size",
|
|
1211
|
-
"info.sizeValue": "{width, number} × {height, number} pixels",
|
|
1212
|
-
"info.format": "Format",
|
|
1213
|
-
"info.formats.png": "PNG",
|
|
1214
|
-
"info.formats.jpeg": "JPEG",
|
|
1215
|
-
"info.formats.webp": "WebP",
|
|
1216
|
-
"info.formats.gif": "GIF",
|
|
1217
|
-
"info.formats.avif": "AVIF",
|
|
1218
|
-
"info.formats.heif": "HEIF",
|
|
1219
|
-
"info.formats.bmp": "BMP",
|
|
1220
|
-
"info.frames": "Frames",
|
|
1221
|
-
"info.fileSize": "File size",
|
|
1222
|
-
"info.fileSizeValue": "{size, fileSize}",
|
|
1223
|
-
"info.metadata": "Metadata in the file",
|
|
1224
|
-
"info.metadataNone": "None",
|
|
1225
|
-
"info.kept": "Kept on export",
|
|
1226
|
-
"info.keptNone": "Nothing",
|
|
1227
|
-
"develop.panel": "Adjust",
|
|
1228
|
-
"develop.temperature": "Temperature",
|
|
1229
|
-
"develop.tint": "Tint",
|
|
1230
|
-
"develop.exposure": "Exposure",
|
|
1231
|
-
"develop.highlights": "Highlights",
|
|
1232
|
-
"develop.shadows": "Shadows",
|
|
1233
|
-
"develop.contrast": "Contrast",
|
|
1234
|
-
"develop.saturation": "Saturation",
|
|
1235
|
-
"develop.vibrance": "Vibrance",
|
|
1236
|
-
"develop.reset": "Reset {name}",
|
|
1237
|
-
"develop.resetAll": "Reset all",
|
|
1238
|
-
"develop.wasReset": "All adjustments reset.",
|
|
1239
|
-
"filters.panel": "Filters",
|
|
1240
|
-
"filters.label": "Filter",
|
|
1241
|
-
"filters.none": "None",
|
|
1242
|
-
"filters.vivid": "Vivid",
|
|
1243
|
-
"filters.warm": "Warm",
|
|
1244
|
-
"filters.cool": "Cool",
|
|
1245
|
-
"filters.fade": "Fade",
|
|
1246
|
-
"filters.mono": "Mono",
|
|
1247
|
-
"filters.noir": "Noir",
|
|
1248
|
-
"filters.sepia": "Sepia",
|
|
1249
|
-
"filters.strength": "Strength",
|
|
1250
|
-
"toolbar.groups.export": "Export",
|
|
1251
|
-
"tools.export": "Export",
|
|
1252
|
-
"export.title": "Export image",
|
|
1253
|
-
"export.description": "The file is made on this device, and nothing is uploaded.",
|
|
1254
|
-
"export.format": "Format",
|
|
1255
|
-
"export.formats.png": "PNG",
|
|
1256
|
-
"export.formats.jpeg": "JPEG",
|
|
1257
|
-
"export.formats.webp": "WebP",
|
|
1258
|
-
"export.quality": "Quality",
|
|
1259
|
-
"export.qualityValue": "{quality, number}%",
|
|
1260
|
-
"export.size": "Size",
|
|
1261
|
-
"export.sizes.scale": "Scale",
|
|
1262
|
-
"export.sizes.fit": "Fit in a box",
|
|
1263
|
-
"export.scale": "Scale, in percent",
|
|
1264
|
-
"export.fitWidth": "Largest width",
|
|
1265
|
-
"export.fitHeight": "Largest height",
|
|
1266
|
-
"export.fields": "Details to include",
|
|
1267
|
-
"export.fieldsHint": "Only what you fill in is written to the file.",
|
|
1268
|
-
"export.field.title": "Title",
|
|
1269
|
-
"export.field.description": "Description",
|
|
1270
|
-
"export.field.artist": "Artist",
|
|
1271
|
-
"export.field.copyright": "Copyright",
|
|
1272
|
-
"export.summary": "Summary",
|
|
1273
|
-
"export.output": "{width, number} × {height, number} pixels, {format}",
|
|
1274
|
-
"export.removed": "Removed from the file",
|
|
1275
|
-
"export.removedNone": "The image had no other details to remove.",
|
|
1276
|
-
"export.redacted": /* @__PURE__ */ plural("count", {
|
|
1277
|
-
one: "{count} area is redacted.",
|
|
1278
|
-
other: "{count, number} areas are redacted."
|
|
1279
|
-
}),
|
|
1280
|
-
"export.redactedPixelated": "Pixelated areas may not hide text.",
|
|
1281
|
-
"export.kind.location": "Location",
|
|
1282
|
-
"export.kind.camera": "Camera details",
|
|
1283
|
-
"export.kind.timestamps": "Dates and times",
|
|
1284
|
-
"export.kind.thumbnail": "Embedded thumbnail",
|
|
1285
|
-
"export.kind.colourProfile": "Colour profile: colours outside sRGB are clipped",
|
|
1286
|
-
"export.kind.other": "Other metadata",
|
|
1287
|
-
"export.kept": "Kept in the file",
|
|
1288
|
-
"export.confirm": "Export",
|
|
1289
|
-
"export.cancel": "Cancel",
|
|
1290
|
-
"export.progress": "Exporting the image",
|
|
1291
|
-
"export.stop": "Stop exporting",
|
|
1292
|
-
"export.cancelled": "Export stopped.",
|
|
1293
|
-
"export.done": "Exported a {format} of {size, fileSize}.",
|
|
1294
|
-
"export.ready": "{width, number} × {height, number} pixels, {format}, {size, fileSize}",
|
|
1295
|
-
"export.download": "Download",
|
|
1296
|
-
"export.close": "Done"
|
|
1297
|
-
});
|
|
1298
|
-
// src/react/editor-messages.ts
|
|
1299
|
-
var imageEditorMessages = /* @__PURE__ */ defineMessages({
|
|
1300
|
-
...imageMessages,
|
|
1301
|
-
...uiMessages,
|
|
1302
|
-
...imageEditorText
|
|
1303
|
-
});
|
|
1304
|
-
// src/react/view-store.ts
|
|
1305
|
-
var FITTED = Object.freeze({
|
|
1306
|
-
zoom: 1,
|
|
1307
|
-
pan: Object.freeze({
|
|
1308
|
-
x: 0,
|
|
1309
|
-
y: 0
|
|
1310
|
-
})
|
|
1311
|
-
});
|
|
1312
|
-
function createViewStore() {
|
|
1313
|
-
return createStore(FITTED);
|
|
1314
|
-
}
|
|
1315
|
-
// src/react/ImageEditorProvider.tsx
|
|
1316
|
-
function own(props) {
|
|
1317
|
-
const engine = props.engine ?? createImageEngine(props.assetsUrl === void 0 ? {} : { assetsUrl: props.assetsUrl });
|
|
1318
|
-
const processor = props.processor ?? createImageProcessor(engine);
|
|
1319
|
-
const session = props.session ?? createImageSession({
|
|
1320
|
-
engine,
|
|
1321
|
-
processor,
|
|
1322
|
-
...props.filePolicy ? { filePolicy: props.filePolicy } : {},
|
|
1323
|
-
...props.onEvent ? { onEvent: props.onEvent } : {}
|
|
1324
|
-
});
|
|
1325
|
-
return {
|
|
1326
|
-
engine,
|
|
1327
|
-
session,
|
|
1328
|
-
dispose() {
|
|
1329
|
-
if (!props.session) session.destroy();
|
|
1330
|
-
if (!props.processor) processor.destroy();
|
|
1331
|
-
if (!props.engine) engine.destroy();
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
978
|
+
function fitLayerName(name) {
|
|
979
|
+
return [...name.replace(EVERY_FORBIDDEN, "").trim()].slice(0, 100).join("");
|
|
1334
980
|
}
|
|
1335
|
-
function
|
|
1336
|
-
return
|
|
981
|
+
function fitLayerText(text) {
|
|
982
|
+
return [...text.replace(/\r\n?/g, "\n").replace(/\t/g, " ").replace(EVERY_FORBIDDEN, "")].slice(0, MAX_LAYER_TEXT_LENGTH).join("");
|
|
1337
983
|
}
|
|
1338
|
-
function
|
|
1339
|
-
const { messages: overrides, locale = "en", children } = props;
|
|
1340
|
-
const [owned] = useState(() => own(props));
|
|
1341
|
-
const [view] = useState(createViewStore);
|
|
1342
|
-
const [editor] = useState(createEditorStore);
|
|
1343
|
-
const [opener] = useState(() => createOpener(owned.session));
|
|
1344
|
-
const [inserter] = useState(() => createInserter(owned.session, editor));
|
|
1345
|
-
useEffect(() => {
|
|
1346
|
-
if (owned.pending !== void 0) clearTimeout(owned.pending);
|
|
1347
|
-
return () => {
|
|
1348
|
-
owned.pending = setTimeout(() => owned.dispose(), 0);
|
|
1349
|
-
};
|
|
1350
|
-
}, [owned]);
|
|
1351
|
-
const messages = useMemo(() => createMessages(imageEditorMessages, {
|
|
1352
|
-
locale,
|
|
1353
|
-
...overrides ? { overrides } : {}
|
|
1354
|
-
}), [locale, overrides]);
|
|
1355
|
-
const value = useMemo(() => ({
|
|
1356
|
-
session: owned.session,
|
|
1357
|
-
engine: owned.engine,
|
|
1358
|
-
messages,
|
|
1359
|
-
view,
|
|
1360
|
-
editor,
|
|
1361
|
-
opener,
|
|
1362
|
-
inserter
|
|
1363
|
-
}), [
|
|
1364
|
-
owned,
|
|
1365
|
-
messages,
|
|
1366
|
-
view,
|
|
1367
|
-
editor,
|
|
1368
|
-
opener,
|
|
1369
|
-
inserter
|
|
1370
|
-
]);
|
|
1371
|
-
return /* @__PURE__ */ jsx(ImageContext.Provider, {
|
|
1372
|
-
value,
|
|
1373
|
-
children: /* @__PURE__ */ jsx(UiMessagesProvider, {
|
|
1374
|
-
messages,
|
|
1375
|
-
children: props.boundary === false ? children : /* @__PURE__ */ jsx(EngineBoundary, { children })
|
|
1376
|
-
})
|
|
1377
|
-
});
|
|
1378
|
-
}
|
|
1379
|
-
function createGesture(session, editor) {
|
|
1380
|
-
let pending;
|
|
1381
|
-
let timer;
|
|
1382
|
-
const reducer = createImageReducer((id) => session.getSnapshot().sources.find((source) => source.id === id));
|
|
1383
|
-
const clearTimer = () => {
|
|
1384
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
1385
|
-
timer = void 0;
|
|
1386
|
-
};
|
|
1387
|
-
const end = () => {
|
|
1388
|
-
clearTimer();
|
|
1389
|
-
pending = void 0;
|
|
1390
|
-
editor.set((state) => state.preview === null ? state : {
|
|
1391
|
-
...state,
|
|
1392
|
-
preview: null
|
|
1393
|
-
});
|
|
1394
|
-
};
|
|
1395
|
-
const value = {
|
|
1396
|
-
preview(commands) {
|
|
1397
|
-
const plan = session.getSnapshot().plan;
|
|
1398
|
-
if (!plan) return;
|
|
1399
|
-
const preview = applyCommands(reducer, plan, commands).state;
|
|
1400
|
-
pending = commands;
|
|
1401
|
-
editor.set((state) => ({
|
|
1402
|
-
...state,
|
|
1403
|
-
preview
|
|
1404
|
-
}));
|
|
1405
|
-
},
|
|
1406
|
-
commit() {
|
|
1407
|
-
const commands = pending;
|
|
1408
|
-
end();
|
|
1409
|
-
if (commands && commands.length > 0) session.execute(commands);
|
|
1410
|
-
},
|
|
1411
|
-
commitSoon() {
|
|
1412
|
-
clearTimer();
|
|
1413
|
-
timer = setTimeout(() => value.commit(), 500);
|
|
1414
|
-
},
|
|
1415
|
-
cancel: end,
|
|
1416
|
-
active: () => pending !== void 0
|
|
1417
|
-
};
|
|
1418
|
-
return value;
|
|
1419
|
-
}
|
|
1420
|
-
function useGesture() {
|
|
1421
|
-
const { session, editor } = useImageInternals();
|
|
1422
|
-
const gesture = useMemo(() => createGesture(session, editor), [editor, session]);
|
|
1423
|
-
useEffect(() => () => gesture.commit(), [gesture]);
|
|
1424
|
-
return gesture;
|
|
1425
|
-
}
|
|
1426
|
-
var shared = /* @__PURE__ */ new WeakMap();
|
|
1427
|
-
function useSharedGesture() {
|
|
1428
|
-
const { session, editor } = useImageInternals();
|
|
1429
|
-
const gesture = useMemo(() => {
|
|
1430
|
-
const existing = shared.get(editor);
|
|
1431
|
-
if (existing) return existing;
|
|
1432
|
-
const created = createGesture(session, editor);
|
|
1433
|
-
shared.set(editor, created);
|
|
1434
|
-
return created;
|
|
1435
|
-
}, [editor, session]);
|
|
1436
|
-
useEffect(() => () => gesture.commit(), [gesture]);
|
|
1437
|
-
return gesture;
|
|
1438
|
-
}
|
|
1439
|
-
// src/react/redact/use-redact.ts
|
|
1440
|
-
var keysOf = (plan) => new Set([...plan.layers, ...plan.redactions].map((item) => item.key));
|
|
1441
|
-
function newRedactionKey(plan) {
|
|
1442
|
-
return createImageKey(keysOf(plan));
|
|
1443
|
-
}
|
|
1444
|
-
function useRedactActions() {
|
|
984
|
+
function useLayerActions() {
|
|
1445
985
|
const { session, editor, messages } = useImageInternals();
|
|
1446
986
|
const announce = useAnnounce();
|
|
1447
987
|
const gesture = useSharedGesture();
|
|
1448
988
|
return useMemo(() => {
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
mode: "solid",
|
|
1452
|
-
colour: "#000000"
|
|
1453
|
-
};
|
|
1454
|
-
const set = (changes) => editor.set((state) => state.tool === "redact" ? {
|
|
989
|
+
const layers = () => session.getSnapshot().plan?.layers ?? [];
|
|
990
|
+
const select = (key) => editor.set((state) => state.tool === "layers" && state.layers?.selected !== key ? {
|
|
1455
991
|
...state,
|
|
1456
|
-
|
|
1457
|
-
...settings(),
|
|
1458
|
-
...changes
|
|
1459
|
-
}
|
|
992
|
+
layers: { selected: key }
|
|
1460
993
|
} : state);
|
|
1461
|
-
const redaction = (key, region) => {
|
|
1462
|
-
const { mode, colour } = settings();
|
|
1463
|
-
const fitted = fitRedactionRegion(region);
|
|
1464
|
-
return mode === "solid" ? {
|
|
1465
|
-
key,
|
|
1466
|
-
mode,
|
|
1467
|
-
...fitted,
|
|
1468
|
-
colour
|
|
1469
|
-
} : {
|
|
1470
|
-
key,
|
|
1471
|
-
mode,
|
|
1472
|
-
...fitted
|
|
1473
|
-
};
|
|
1474
|
-
};
|
|
1475
|
-
const insert = (item, plan) => ({
|
|
1476
|
-
type: "image.insertRedactions",
|
|
1477
|
-
at: plan.redactions.length,
|
|
1478
|
-
redactions: [item]
|
|
1479
|
-
});
|
|
1480
|
-
const count = () => session.getSnapshot().plan?.redactions.length ?? 0;
|
|
1481
994
|
return {
|
|
1482
995
|
gesture,
|
|
1483
|
-
add() {
|
|
1484
|
-
const { plan, source } = session.getSnapshot();
|
|
1485
|
-
if (!plan || !source) return;
|
|
1486
|
-
gesture.commit();
|
|
1487
|
-
const { width, height } = compositionSize(plan, source);
|
|
1488
|
-
const shown = {
|
|
1489
|
-
x: Math.round(width * .375),
|
|
1490
|
-
y: Math.round(height * .375),
|
|
1491
|
-
width: Math.max(1, Math.round(width / 4)),
|
|
1492
|
-
height: Math.max(1, Math.round(height / 4))
|
|
1493
|
-
};
|
|
1494
|
-
const key = newRedactionKey(plan);
|
|
1495
|
-
const region = compositionRectToScene(shown, cropRect(plan.base.crop, source), plan.base.orientation);
|
|
1496
|
-
session.execute(insert(redaction(key, region), plan));
|
|
1497
|
-
set({ selected: key });
|
|
1498
|
-
announce(messages.t("redact.added", { count: count() }));
|
|
1499
|
-
},
|
|
1500
996
|
select(key) {
|
|
1501
|
-
if (
|
|
997
|
+
if (editor.getSnapshot().layers?.selected === key) return;
|
|
1502
998
|
gesture.commit();
|
|
1503
|
-
|
|
1504
|
-
set({
|
|
1505
|
-
selected: item ? key : null,
|
|
1506
|
-
...item ? { mode: item.mode } : {},
|
|
1507
|
-
...item?.mode === "solid" ? { colour: item.colour } : {}
|
|
1508
|
-
});
|
|
999
|
+
select(key !== null && layers().some((layer) => layer.key === key) ? key : null);
|
|
1509
1000
|
},
|
|
1510
1001
|
remove(key) {
|
|
1511
1002
|
gesture.cancel();
|
|
1512
|
-
|
|
1003
|
+
const index = layers().findIndex((layer) => layer.key === key);
|
|
1004
|
+
const layer = layers()[index];
|
|
1005
|
+
if (!layer) return null;
|
|
1513
1006
|
session.execute({
|
|
1514
|
-
type: "image.
|
|
1007
|
+
type: "image.removeLayers",
|
|
1515
1008
|
keys: [key]
|
|
1516
1009
|
});
|
|
1517
|
-
|
|
1518
|
-
|
|
1010
|
+
const next = (layers()[index - 1] ?? layers()[0])?.key ?? null;
|
|
1011
|
+
select(next);
|
|
1012
|
+
announce(messages.t("layers.removed", { name: layerLabel(layer, messages) }));
|
|
1013
|
+
return next;
|
|
1519
1014
|
},
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1015
|
+
duplicate(key) {
|
|
1016
|
+
gesture.commit();
|
|
1017
|
+
const plan = session.getSnapshot().plan;
|
|
1018
|
+
const index = layers().findIndex((layer) => layer.key === key);
|
|
1019
|
+
const layer = layers()[index];
|
|
1020
|
+
if (!plan || !layer) return;
|
|
1021
|
+
const moved = (value) => Math.min(value + DUPLICATE_OFFSET, MAX_SCENE_COORDINATE);
|
|
1022
|
+
const copyKey = newRedactionKey(plan);
|
|
1023
|
+
const copy = layer.kind === "arrow" ? {
|
|
1024
|
+
...layer,
|
|
1025
|
+
key: copyKey,
|
|
1026
|
+
from: {
|
|
1027
|
+
x: moved(layer.from.x),
|
|
1028
|
+
y: moved(layer.from.y)
|
|
1029
|
+
},
|
|
1030
|
+
to: {
|
|
1031
|
+
x: moved(layer.to.x),
|
|
1032
|
+
y: moved(layer.to.y)
|
|
1033
|
+
}
|
|
1034
|
+
} : {
|
|
1035
|
+
...layer,
|
|
1036
|
+
key: copyKey,
|
|
1037
|
+
x: moved(layer.x),
|
|
1038
|
+
y: moved(layer.y)
|
|
1039
|
+
};
|
|
1040
|
+
session.execute({
|
|
1041
|
+
type: "image.insertLayers",
|
|
1042
|
+
at: index + 1,
|
|
1043
|
+
layers: [copy]
|
|
1044
|
+
});
|
|
1045
|
+
select(copy.key);
|
|
1046
|
+
announce(messages.t("layers.duplicated", { name: layerLabel(layer, messages) }));
|
|
1525
1047
|
},
|
|
1526
|
-
|
|
1048
|
+
shift(key, by) {
|
|
1049
|
+
gesture.commit();
|
|
1050
|
+
const index = layers().findIndex((layer) => layer.key === key);
|
|
1051
|
+
const layer = layers()[index];
|
|
1052
|
+
const to = index + by;
|
|
1053
|
+
if (!layer || to < 0 || to >= layers().length) return;
|
|
1054
|
+
session.execute({
|
|
1055
|
+
type: "image.moveLayers",
|
|
1056
|
+
keys: [key],
|
|
1057
|
+
to
|
|
1058
|
+
});
|
|
1059
|
+
announce(messages.t(by > 0 ? "layers.movedUp" : "layers.movedDown", {
|
|
1060
|
+
name: layerLabel(layer, messages),
|
|
1061
|
+
index: layers().length - to,
|
|
1062
|
+
count: layers().length
|
|
1063
|
+
}));
|
|
1064
|
+
},
|
|
1065
|
+
moving(key, props) {
|
|
1527
1066
|
gesture.preview([{
|
|
1528
|
-
type: "image.
|
|
1067
|
+
type: "image.updateLayers",
|
|
1529
1068
|
updates: [{
|
|
1530
1069
|
key,
|
|
1531
|
-
props
|
|
1070
|
+
props
|
|
1532
1071
|
}]
|
|
1533
1072
|
}]);
|
|
1534
1073
|
},
|
|
1535
1074
|
commit(soon = false) {
|
|
1536
|
-
if (soon)
|
|
1537
|
-
|
|
1538
|
-
return;
|
|
1539
|
-
}
|
|
1540
|
-
const drew = gesture.active() && count();
|
|
1541
|
-
gesture.commit();
|
|
1542
|
-
if (drew !== false && count() > drew) announce(messages.t("redact.added", { count: count() }));
|
|
1075
|
+
if (soon) gesture.commitSoon();
|
|
1076
|
+
else gesture.commit();
|
|
1543
1077
|
},
|
|
1544
1078
|
cancel() {
|
|
1545
1079
|
gesture.cancel();
|
|
1546
1080
|
},
|
|
1547
|
-
|
|
1081
|
+
set(key, props) {
|
|
1548
1082
|
gesture.commit();
|
|
1549
1083
|
session.execute({
|
|
1550
|
-
type: "image.
|
|
1084
|
+
type: "image.updateLayers",
|
|
1551
1085
|
updates: [{
|
|
1552
1086
|
key,
|
|
1553
|
-
props
|
|
1087
|
+
props
|
|
1554
1088
|
}]
|
|
1555
1089
|
});
|
|
1556
1090
|
},
|
|
1557
|
-
|
|
1558
|
-
gesture.
|
|
1559
|
-
|
|
1560
|
-
const item = session.getSnapshot().plan?.redactions.find((r) => r.key === selected);
|
|
1561
|
-
if (item && item.mode !== mode) session.execute({
|
|
1562
|
-
type: "image.updateRedactions",
|
|
1091
|
+
typing(key, props) {
|
|
1092
|
+
gesture.preview([{
|
|
1093
|
+
type: "image.updateLayers",
|
|
1563
1094
|
updates: [{
|
|
1564
|
-
key
|
|
1565
|
-
props
|
|
1566
|
-
mode,
|
|
1567
|
-
colour
|
|
1568
|
-
} : { mode }
|
|
1095
|
+
key,
|
|
1096
|
+
props
|
|
1569
1097
|
}]
|
|
1570
|
-
});
|
|
1571
|
-
|
|
1098
|
+
}]);
|
|
1099
|
+
gesture.commitSoon();
|
|
1572
1100
|
},
|
|
1573
|
-
|
|
1101
|
+
done() {
|
|
1574
1102
|
gesture.commit();
|
|
1575
|
-
|
|
1576
|
-
if (item?.mode === "solid" && item.colour !== colour) session.execute({
|
|
1577
|
-
type: "image.updateRedactions",
|
|
1578
|
-
updates: [{
|
|
1579
|
-
key: item.key,
|
|
1580
|
-
props: { colour }
|
|
1581
|
-
}]
|
|
1582
|
-
});
|
|
1583
|
-
set({ colour });
|
|
1584
|
-
},
|
|
1585
|
-
done() {
|
|
1586
|
-
gesture.commit();
|
|
1587
|
-
editor.set((state) => state.tool === "redact" ? {
|
|
1103
|
+
editor.set((state) => state.tool === "layers" ? {
|
|
1588
1104
|
...state,
|
|
1589
|
-
|
|
1590
|
-
redact: null,
|
|
1105
|
+
...NO_TOOL,
|
|
1591
1106
|
preview: null
|
|
1592
1107
|
} : state);
|
|
1593
1108
|
}
|
|
@@ -1600,356 +1115,1349 @@ function useRedactActions() {
|
|
|
1600
1115
|
session
|
|
1601
1116
|
]);
|
|
1602
1117
|
}
|
|
1603
|
-
// src/react/layers/
|
|
1604
|
-
var
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1118
|
+
// src/react/layers/LayerFields.tsx
|
|
1119
|
+
var SWATCHES = [
|
|
1120
|
+
{
|
|
1121
|
+
value: "#000000",
|
|
1122
|
+
name: "black"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
value: "#ffffff",
|
|
1126
|
+
name: "white"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
value: "#e02020",
|
|
1130
|
+
name: "red"
|
|
1131
|
+
},
|
|
1132
|
+
{
|
|
1133
|
+
value: "#f0c020",
|
|
1134
|
+
name: "yellow"
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
value: "#20a040",
|
|
1138
|
+
name: "green"
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
value: "#2060e0",
|
|
1142
|
+
name: "blue"
|
|
1612
1143
|
}
|
|
1613
|
-
|
|
1144
|
+
];
|
|
1145
|
+
function useSwatches() {
|
|
1146
|
+
const messages = useImageMessages();
|
|
1147
|
+
return SWATCHES.map(({ value, name }) => ({
|
|
1148
|
+
value,
|
|
1149
|
+
label: messages.t(`layers.colours.${name}`)
|
|
1150
|
+
}));
|
|
1151
|
+
}
|
|
1152
|
+
function TextLayerFields(props) {
|
|
1153
|
+
const { layer, actions, run } = props;
|
|
1154
|
+
const messages = useImageMessages();
|
|
1155
|
+
const swatches = useSwatches();
|
|
1156
|
+
const key = layer?.key ?? null;
|
|
1157
|
+
const text = layer?.text ?? "";
|
|
1158
|
+
const [value, setValue] = useState(text);
|
|
1159
|
+
useEffect(() => setValue(text), [key, text]);
|
|
1160
|
+
const off = layer === null;
|
|
1161
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1162
|
+
className: "hm-image-layer-kind",
|
|
1163
|
+
"data-hm-inactive": off ? "" : void 0,
|
|
1164
|
+
children: [
|
|
1165
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1166
|
+
label: messages.t("layers.text"),
|
|
1167
|
+
className: "hm-image-layers-text",
|
|
1168
|
+
children: /* @__PURE__ */ jsx(TextArea, {
|
|
1169
|
+
rows: 3,
|
|
1170
|
+
value,
|
|
1171
|
+
disabled: off,
|
|
1172
|
+
onValueChange: (typed) => {
|
|
1173
|
+
const fitted = fitLayerText(typed);
|
|
1174
|
+
setValue(fitted);
|
|
1175
|
+
if (layer) run(() => actions.typing(layer.key, { text: fitted }));
|
|
1176
|
+
},
|
|
1177
|
+
onBlur: () => actions.commit()
|
|
1178
|
+
})
|
|
1179
|
+
}),
|
|
1180
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1181
|
+
label: messages.t("layers.font"),
|
|
1182
|
+
size: "small",
|
|
1183
|
+
value: layer?.font ?? "sans-serif",
|
|
1184
|
+
options: LAYER_FONTS.map((font) => ({
|
|
1185
|
+
value: font,
|
|
1186
|
+
label: messages.t(`layers.fonts.${font}`),
|
|
1187
|
+
disabled: off
|
|
1188
|
+
})),
|
|
1189
|
+
onValueChange: (font) => layer && run(() => actions.set(layer.key, { font }))
|
|
1190
|
+
}),
|
|
1191
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1192
|
+
className: "hm-image-layer-row",
|
|
1193
|
+
children: [/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1194
|
+
label: messages.t("layers.align"),
|
|
1195
|
+
size: "small",
|
|
1196
|
+
value: layer?.align ?? "center",
|
|
1197
|
+
options: LAYER_ALIGNMENTS.map((align) => ({
|
|
1198
|
+
value: align,
|
|
1199
|
+
label: messages.t(`layers.alignments.${align}`),
|
|
1200
|
+
disabled: off
|
|
1201
|
+
})),
|
|
1202
|
+
onValueChange: (align) => layer && run(() => actions.set(layer.key, { align }))
|
|
1203
|
+
}), /* @__PURE__ */ jsx(ToggleButton, {
|
|
1204
|
+
size: "small",
|
|
1205
|
+
pressed: layer?.bold ?? false,
|
|
1206
|
+
disabled: off,
|
|
1207
|
+
onPressedChange: (bold) => layer && run(() => actions.set(layer.key, { bold })),
|
|
1208
|
+
children: messages.t("layers.bold")
|
|
1209
|
+
})]
|
|
1210
|
+
}),
|
|
1211
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1212
|
+
label: messages.t("layers.colour"),
|
|
1213
|
+
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1214
|
+
value: layer?.colour ?? "#000000",
|
|
1215
|
+
swatches,
|
|
1216
|
+
disabled: off,
|
|
1217
|
+
onValueChange: (colour) => {
|
|
1218
|
+
if (layer && colour !== layer.colour) run(() => actions.set(layer.key, { colour }));
|
|
1219
|
+
}
|
|
1220
|
+
})
|
|
1221
|
+
})
|
|
1222
|
+
]
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
function ShapeLayerFields(props) {
|
|
1226
|
+
const { layer, actions, run } = props;
|
|
1227
|
+
const messages = useImageMessages();
|
|
1228
|
+
const session = useImageSession();
|
|
1229
|
+
const swatches = useSwatches();
|
|
1230
|
+
const off = layer === null;
|
|
1231
|
+
const fill = layer?.fill ?? null;
|
|
1232
|
+
const stroke = layer?.stroke ?? null;
|
|
1233
|
+
const outline = (colour) => {
|
|
1234
|
+
const { plan, source } = session.getSnapshot();
|
|
1235
|
+
const widest = layer ? Math.max(1, Math.floor(Math.min(layer.width, layer.height) / 2)) : 1;
|
|
1236
|
+
return {
|
|
1237
|
+
colour,
|
|
1238
|
+
width: plan && source ? Math.min(defaultStrokeWidth(plan, source), widest) : 1
|
|
1239
|
+
};
|
|
1240
|
+
};
|
|
1241
|
+
const set = (props) => {
|
|
1242
|
+
if (layer) run(() => actions.set(layer.key, props));
|
|
1243
|
+
};
|
|
1244
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1245
|
+
className: "hm-image-layer-kind",
|
|
1246
|
+
"data-hm-inactive": off ? "" : void 0,
|
|
1247
|
+
children: [
|
|
1248
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1249
|
+
className: "hm-image-layer-row",
|
|
1250
|
+
children: [/* @__PURE__ */ jsx(ToggleButton, {
|
|
1251
|
+
size: "small",
|
|
1252
|
+
pressed: fill !== null,
|
|
1253
|
+
disabled: off,
|
|
1254
|
+
onPressedChange: (on) => {
|
|
1255
|
+
if (on) set({ fill: stroke?.colour ?? "#e02020" });
|
|
1256
|
+
else if (stroke) set({ fill: null });
|
|
1257
|
+
else set({
|
|
1258
|
+
fill: null,
|
|
1259
|
+
stroke: outline(fill ?? "#e02020")
|
|
1260
|
+
});
|
|
1261
|
+
},
|
|
1262
|
+
children: messages.t("layers.fill")
|
|
1263
|
+
}), /* @__PURE__ */ jsx(ToggleButton, {
|
|
1264
|
+
size: "small",
|
|
1265
|
+
pressed: stroke !== null,
|
|
1266
|
+
disabled: off,
|
|
1267
|
+
onPressedChange: (on) => {
|
|
1268
|
+
if (on) set({ stroke: outline(fill ?? "#e02020") });
|
|
1269
|
+
else if (fill !== null) set({ stroke: null });
|
|
1270
|
+
else set({
|
|
1271
|
+
stroke: null,
|
|
1272
|
+
fill: stroke?.colour ?? "#e02020"
|
|
1273
|
+
});
|
|
1274
|
+
},
|
|
1275
|
+
children: messages.t("layers.outline")
|
|
1276
|
+
})]
|
|
1277
|
+
}),
|
|
1278
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1279
|
+
label: messages.t("layers.fillColour"),
|
|
1280
|
+
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1281
|
+
value: fill ?? "#e02020",
|
|
1282
|
+
swatches,
|
|
1283
|
+
disabled: off || fill === null,
|
|
1284
|
+
onValueChange: (colour) => {
|
|
1285
|
+
if (fill !== null && colour !== fill) set({ fill: colour });
|
|
1286
|
+
}
|
|
1287
|
+
})
|
|
1288
|
+
}),
|
|
1289
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1290
|
+
label: messages.t("layers.outlineColour"),
|
|
1291
|
+
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1292
|
+
value: stroke?.colour ?? "#e02020",
|
|
1293
|
+
swatches,
|
|
1294
|
+
disabled: off || stroke === null,
|
|
1295
|
+
onValueChange: (colour) => {
|
|
1296
|
+
if (stroke && colour !== stroke.colour) set({ stroke: {
|
|
1297
|
+
...stroke,
|
|
1298
|
+
colour
|
|
1299
|
+
} });
|
|
1300
|
+
}
|
|
1301
|
+
})
|
|
1302
|
+
}),
|
|
1303
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1304
|
+
label: messages.t("layers.outlineWidth"),
|
|
1305
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1306
|
+
value: stroke?.width ?? 1,
|
|
1307
|
+
min: 1,
|
|
1308
|
+
max: MAX_STROKE_WIDTH,
|
|
1309
|
+
step: 1,
|
|
1310
|
+
largeStep: 5,
|
|
1311
|
+
disabled: off || stroke === null,
|
|
1312
|
+
onValueChange: (width) => {
|
|
1313
|
+
if (stroke) set({ stroke: {
|
|
1314
|
+
...stroke,
|
|
1315
|
+
width: Math.round(width)
|
|
1316
|
+
} });
|
|
1317
|
+
}
|
|
1318
|
+
})
|
|
1319
|
+
})
|
|
1320
|
+
]
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
function ArrowLayerFields(props) {
|
|
1324
|
+
const { layer, actions, run } = props;
|
|
1325
|
+
const messages = useImageMessages();
|
|
1326
|
+
const swatches = useSwatches();
|
|
1327
|
+
const off = layer === null;
|
|
1328
|
+
const end = (which, axis) => /* @__PURE__ */ jsx(Field, {
|
|
1329
|
+
label: messages.t(`layers.arrow.${which}.${axis}`),
|
|
1330
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1331
|
+
value: layer ? layer[which][axis] : 0,
|
|
1332
|
+
min: -MAX_SCENE_COORDINATE,
|
|
1333
|
+
max: MAX_SCENE_COORDINATE,
|
|
1334
|
+
step: 1,
|
|
1335
|
+
largeStep: 10,
|
|
1336
|
+
disabled: off,
|
|
1337
|
+
onValueChange: (value) => {
|
|
1338
|
+
if (!layer) return;
|
|
1339
|
+
const moved = {
|
|
1340
|
+
...layer[which],
|
|
1341
|
+
[axis]: Math.round(value)
|
|
1342
|
+
};
|
|
1343
|
+
const other = layer[which === "from" ? "to" : "from"];
|
|
1344
|
+
if (moved.x === other.x && moved.y === other.y) return;
|
|
1345
|
+
run(() => actions.set(layer.key, { [which]: moved }));
|
|
1346
|
+
}
|
|
1347
|
+
})
|
|
1348
|
+
}, `${which}.${axis}`);
|
|
1349
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1350
|
+
className: "hm-image-layer-kind",
|
|
1351
|
+
"data-hm-inactive": off ? "" : void 0,
|
|
1352
|
+
children: [
|
|
1353
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1354
|
+
className: "hm-image-layer-ends",
|
|
1355
|
+
children: [
|
|
1356
|
+
end("from", "x"),
|
|
1357
|
+
end("from", "y"),
|
|
1358
|
+
end("to", "x"),
|
|
1359
|
+
end("to", "y")
|
|
1360
|
+
]
|
|
1361
|
+
}),
|
|
1362
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1363
|
+
label: messages.t("layers.colour"),
|
|
1364
|
+
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1365
|
+
value: layer?.colour ?? "#e02020",
|
|
1366
|
+
swatches,
|
|
1367
|
+
disabled: off,
|
|
1368
|
+
onValueChange: (colour) => {
|
|
1369
|
+
if (layer && colour !== layer.colour) run(() => actions.set(layer.key, { colour }));
|
|
1370
|
+
}
|
|
1371
|
+
})
|
|
1372
|
+
}),
|
|
1373
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1374
|
+
label: messages.t("layers.arrow.width"),
|
|
1375
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1376
|
+
value: layer?.width ?? 1,
|
|
1377
|
+
min: 1,
|
|
1378
|
+
max: MAX_STROKE_WIDTH,
|
|
1379
|
+
step: 1,
|
|
1380
|
+
largeStep: 5,
|
|
1381
|
+
disabled: off,
|
|
1382
|
+
onValueChange: (width) => {
|
|
1383
|
+
if (layer) run(() => actions.set(layer.key, { width: Math.round(width) }));
|
|
1384
|
+
}
|
|
1385
|
+
})
|
|
1386
|
+
})
|
|
1387
|
+
]
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
// src/react/draw/use-draw.ts
|
|
1391
|
+
var clamp$1 = (value) => Math.min(MAX_SCENE_COORDINATE, Math.max(-MAX_SCENE_COORDINATE, Math.round(value) || 0));
|
|
1392
|
+
function relative(samples, origin) {
|
|
1393
|
+
return samples.flatMap((point) => [clamp$1(point.x) - origin.x, clamp$1(point.y) - origin.y]);
|
|
1394
|
+
}
|
|
1395
|
+
function useDrawActions() {
|
|
1396
|
+
const context = useImageInternals();
|
|
1397
|
+
const { session, editor, messages } = context;
|
|
1398
|
+
const announce = useAnnounce();
|
|
1399
|
+
const gesture = useSharedGesture();
|
|
1400
|
+
return useMemo(() => {
|
|
1401
|
+
const settings = () => editor.getSnapshot().draw;
|
|
1402
|
+
const patch = (changes) => editor.set((state) => state.tool === "draw" && state.draw ? {
|
|
1403
|
+
...state,
|
|
1404
|
+
draw: {
|
|
1405
|
+
...state.draw,
|
|
1406
|
+
...changes
|
|
1407
|
+
}
|
|
1408
|
+
} : state);
|
|
1409
|
+
const targetIn = (plan) => {
|
|
1410
|
+
const current = settings();
|
|
1411
|
+
const layer = plan?.layers.find((item) => item.key === current?.target);
|
|
1412
|
+
return current && layer?.kind === "drawing" && layer.opacity === DRAW_OPACITY[current.mode] ? layer : void 0;
|
|
1413
|
+
};
|
|
1414
|
+
return {
|
|
1415
|
+
gesture,
|
|
1416
|
+
newKey: () => {
|
|
1417
|
+
const plan = session.getSnapshot().plan;
|
|
1418
|
+
return plan ? newLayerKey(plan) : "";
|
|
1419
|
+
},
|
|
1420
|
+
target: () => targetIn(session.getSnapshot().plan),
|
|
1421
|
+
drawing(key, samples, tolerance) {
|
|
1422
|
+
const current = settings();
|
|
1423
|
+
const plan = session.getSnapshot().plan;
|
|
1424
|
+
const first = samples[0];
|
|
1425
|
+
if (!current || !plan || !first) return;
|
|
1426
|
+
const joined = targetIn(plan);
|
|
1427
|
+
const origin = joined ?? {
|
|
1428
|
+
x: clamp$1(first.x),
|
|
1429
|
+
y: clamp$1(first.y)
|
|
1430
|
+
};
|
|
1431
|
+
const stroke = {
|
|
1432
|
+
colour: current.colour,
|
|
1433
|
+
width: current.width,
|
|
1434
|
+
runs: simplifyStroke(relative(samples, origin), tolerance)
|
|
1435
|
+
};
|
|
1436
|
+
const command = joined ? {
|
|
1437
|
+
type: "image.addStrokes",
|
|
1438
|
+
key: joined.key,
|
|
1439
|
+
strokes: [stroke]
|
|
1440
|
+
} : {
|
|
1441
|
+
type: "image.insertLayers",
|
|
1442
|
+
at: plan.layers.length,
|
|
1443
|
+
layers: [{
|
|
1444
|
+
key,
|
|
1445
|
+
kind: "drawing",
|
|
1446
|
+
name: "",
|
|
1447
|
+
visible: true,
|
|
1448
|
+
opacity: DRAW_OPACITY[current.mode],
|
|
1449
|
+
x: origin.x,
|
|
1450
|
+
y: origin.y,
|
|
1451
|
+
strokes: [stroke]
|
|
1452
|
+
}]
|
|
1453
|
+
};
|
|
1454
|
+
gesture.preview([command]);
|
|
1455
|
+
},
|
|
1456
|
+
commit(key) {
|
|
1457
|
+
const started = targetIn(session.getSnapshot().plan) === void 0;
|
|
1458
|
+
try {
|
|
1459
|
+
gesture.commit();
|
|
1460
|
+
editor.set((state) => state.error === null ? state : {
|
|
1461
|
+
...state,
|
|
1462
|
+
error: null
|
|
1463
|
+
});
|
|
1464
|
+
} catch (reason) {
|
|
1465
|
+
const error = isImageError(reason) ? reason : asImageError(reason);
|
|
1466
|
+
editor.set((state) => ({
|
|
1467
|
+
...state,
|
|
1468
|
+
error,
|
|
1469
|
+
preview: null
|
|
1470
|
+
}));
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (started && session.getSnapshot().plan?.layers.some((layer) => layer.key === key)) patch({ target: key });
|
|
1474
|
+
},
|
|
1475
|
+
cancel() {
|
|
1476
|
+
gesture.cancel();
|
|
1477
|
+
},
|
|
1478
|
+
set(changes) {
|
|
1479
|
+
gesture.commit();
|
|
1480
|
+
const current = settings();
|
|
1481
|
+
if (!current) return;
|
|
1482
|
+
if (changes.mode !== void 0 && changes.mode !== current.mode) {
|
|
1483
|
+
patch({
|
|
1484
|
+
mode: changes.mode,
|
|
1485
|
+
colour: DRAW_COLOUR[changes.mode],
|
|
1486
|
+
width: drawWidth(context, changes.mode),
|
|
1487
|
+
target: null
|
|
1488
|
+
});
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
patch({
|
|
1492
|
+
...changes.colour === void 0 ? {} : { colour: changes.colour },
|
|
1493
|
+
...changes.width === void 0 ? {} : { width: Math.min(MAX_STROKE_WIDTH, Math.max(1, Math.round(changes.width))) }
|
|
1494
|
+
});
|
|
1495
|
+
},
|
|
1496
|
+
removeLast() {
|
|
1497
|
+
gesture.cancel();
|
|
1498
|
+
const drawing = targetIn(session.getSnapshot().plan);
|
|
1499
|
+
if (!drawing) return;
|
|
1500
|
+
if (drawing.strokes.length > 1) session.execute({
|
|
1501
|
+
type: "image.removeStrokes",
|
|
1502
|
+
key: drawing.key,
|
|
1503
|
+
indexes: [drawing.strokes.length - 1]
|
|
1504
|
+
});
|
|
1505
|
+
else {
|
|
1506
|
+
session.execute({
|
|
1507
|
+
type: "image.removeLayers",
|
|
1508
|
+
keys: [drawing.key]
|
|
1509
|
+
});
|
|
1510
|
+
patch({ target: null });
|
|
1511
|
+
}
|
|
1512
|
+
announce(messages.t("draw.removed"));
|
|
1513
|
+
},
|
|
1514
|
+
done() {
|
|
1515
|
+
gesture.commit();
|
|
1516
|
+
editor.set((state) => state.tool === "draw" ? {
|
|
1517
|
+
...state,
|
|
1518
|
+
...NO_TOOL,
|
|
1519
|
+
preview: null
|
|
1520
|
+
} : state);
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
}, [
|
|
1524
|
+
announce,
|
|
1525
|
+
context,
|
|
1526
|
+
editor,
|
|
1527
|
+
gesture,
|
|
1528
|
+
messages,
|
|
1529
|
+
session
|
|
1530
|
+
]);
|
|
1531
|
+
}
|
|
1532
|
+
// src/react/draw/DrawPanel.tsx
|
|
1533
|
+
function ImageDrawPanel(props) {
|
|
1534
|
+
const [state] = useImageEditorState();
|
|
1535
|
+
useImageDocument();
|
|
1536
|
+
const messages = useImageMessages();
|
|
1537
|
+
const actions = useDrawActions();
|
|
1538
|
+
const swatches = useSwatches();
|
|
1539
|
+
const settings = state.draw;
|
|
1540
|
+
if (state.tool !== "draw" || !settings) return null;
|
|
1541
|
+
const drawing = actions.target();
|
|
1542
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1543
|
+
className: ["hm-image-draw-panel", props.className].filter(Boolean).join(" "),
|
|
1544
|
+
"aria-label": messages.t("draw.panel"),
|
|
1545
|
+
children: [
|
|
1546
|
+
/* @__PURE__ */ jsx("p", {
|
|
1547
|
+
className: "hm-image-draw-intro",
|
|
1548
|
+
children: messages.t("draw.intro")
|
|
1549
|
+
}),
|
|
1550
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1551
|
+
label: messages.t("draw.mode"),
|
|
1552
|
+
value: settings.mode,
|
|
1553
|
+
size: "small",
|
|
1554
|
+
options: [{
|
|
1555
|
+
value: "pen",
|
|
1556
|
+
label: messages.t("draw.modes.pen")
|
|
1557
|
+
}, {
|
|
1558
|
+
value: "highlighter",
|
|
1559
|
+
label: messages.t("draw.modes.highlighter")
|
|
1560
|
+
}],
|
|
1561
|
+
onValueChange: (mode) => actions.set({ mode })
|
|
1562
|
+
}),
|
|
1563
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1564
|
+
label: messages.t("draw.colour"),
|
|
1565
|
+
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1566
|
+
value: settings.colour,
|
|
1567
|
+
swatches,
|
|
1568
|
+
onValueChange: (colour) => {
|
|
1569
|
+
if (colour !== settings.colour) actions.set({ colour });
|
|
1570
|
+
}
|
|
1571
|
+
})
|
|
1572
|
+
}),
|
|
1573
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1574
|
+
label: messages.t("draw.width"),
|
|
1575
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1576
|
+
value: settings.width,
|
|
1577
|
+
min: 1,
|
|
1578
|
+
max: MAX_STROKE_WIDTH,
|
|
1579
|
+
step: 1,
|
|
1580
|
+
largeStep: 5,
|
|
1581
|
+
onValueChange: (width) => actions.set({ width })
|
|
1582
|
+
})
|
|
1583
|
+
}),
|
|
1584
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1585
|
+
className: "hm-image-draw-actions",
|
|
1586
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1587
|
+
variant: "secondary",
|
|
1588
|
+
className: "hm-image-draw-remove",
|
|
1589
|
+
disabled: !drawing,
|
|
1590
|
+
focusableWhenDisabled: true,
|
|
1591
|
+
onClick: () => actions.removeLast(),
|
|
1592
|
+
children: messages.t("draw.removeLast")
|
|
1593
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1594
|
+
variant: "primary",
|
|
1595
|
+
className: "hm-image-draw-done",
|
|
1596
|
+
onClick: () => actions.done(),
|
|
1597
|
+
children: messages.t("draw.done")
|
|
1598
|
+
})]
|
|
1599
|
+
})
|
|
1600
|
+
]
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
// src/react/EngineBoundary.tsx
|
|
1604
|
+
var usable = () => false;
|
|
1605
|
+
var unchanged = () => () => {};
|
|
1606
|
+
function EngineBoundary({ children }) {
|
|
1607
|
+
const { engine, messages } = useImageInternals();
|
|
1608
|
+
const lifecycle = engineInternals(engine);
|
|
1609
|
+
const surface = useRef(null);
|
|
1610
|
+
const notice = useRef(null);
|
|
1611
|
+
const ownedFocus = useRef(null);
|
|
1612
|
+
const subscribe = useMemo(() => lifecycle ? (changed) => lifecycle.subscribe(() => {
|
|
1613
|
+
const active = document.activeElement;
|
|
1614
|
+
ownedFocus.current = active && surface.current?.contains(active) ? active : null;
|
|
1615
|
+
changed();
|
|
1616
|
+
}) : unchanged, [lifecycle]);
|
|
1617
|
+
const terminal = useSyncExternalStore(subscribe, lifecycle?.getSnapshot ?? usable, usable);
|
|
1618
|
+
useEffect(() => {
|
|
1619
|
+
if (!terminal || !ownedFocus.current) return;
|
|
1620
|
+
const active = document.activeElement;
|
|
1621
|
+
if (active === document.body || active === ownedFocus.current) notice.current?.focus();
|
|
1622
|
+
ownedFocus.current = null;
|
|
1623
|
+
}, [terminal]);
|
|
1624
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1625
|
+
ref: surface,
|
|
1626
|
+
className: "hm-image-engine-boundary",
|
|
1627
|
+
children: terminal ? /* @__PURE__ */ jsx("p", {
|
|
1628
|
+
ref: notice,
|
|
1629
|
+
role: "alert",
|
|
1630
|
+
tabIndex: -1,
|
|
1631
|
+
className: "hm-image-engine-unavailable",
|
|
1632
|
+
children: messages.t("editor.engineUnavailable")
|
|
1633
|
+
}) : children
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
// src/react/export/export-listener.ts
|
|
1637
|
+
var ExportListenerContext = createContext(null);
|
|
1638
|
+
// src/react/export/ExportDialog.tsx
|
|
1639
|
+
var FORMATS = [
|
|
1640
|
+
"png",
|
|
1641
|
+
"jpeg",
|
|
1642
|
+
"webp"
|
|
1643
|
+
];
|
|
1644
|
+
var EXTENSIONS = {
|
|
1645
|
+
png: "png",
|
|
1646
|
+
jpeg: "jpg",
|
|
1647
|
+
webp: "webp"
|
|
1648
|
+
};
|
|
1649
|
+
var FIELDS$1 = [
|
|
1650
|
+
"title",
|
|
1651
|
+
"description",
|
|
1652
|
+
"artist",
|
|
1653
|
+
"copyright"
|
|
1654
|
+
];
|
|
1655
|
+
var KINDS$1 = [
|
|
1656
|
+
"location",
|
|
1657
|
+
"camera",
|
|
1658
|
+
"timestamps",
|
|
1659
|
+
"thumbnail",
|
|
1660
|
+
"colourProfile",
|
|
1661
|
+
"other"
|
|
1662
|
+
];
|
|
1663
|
+
var DEFAULT_QUALITY = 92;
|
|
1664
|
+
var keepable = (text) => longerThan(text, 2e3) ? [...text].slice(0, MAX_METADATA_LENGTH).join("") : text;
|
|
1665
|
+
function initialDraft(plan, source) {
|
|
1666
|
+
return {
|
|
1667
|
+
format: FORMATS.includes(source.format) ? source.format : "png",
|
|
1668
|
+
quality: DEFAULT_QUALITY,
|
|
1669
|
+
output: plan.output,
|
|
1670
|
+
metadata: plan.metadata
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
var sameOutput = (a, b) => a.kind === "scale" && b.kind === "scale" ? a.scale === b.scale : a.kind === "fit" && b.kind === "fit" && a.width === b.width && a.height === b.height;
|
|
1674
|
+
function changes(plan, draft) {
|
|
1675
|
+
const commands = [];
|
|
1676
|
+
if (!sameOutput(plan.output, draft.output)) commands.push({
|
|
1677
|
+
type: "image.setOutput",
|
|
1678
|
+
output: draft.output
|
|
1679
|
+
});
|
|
1680
|
+
for (const field of FIELDS$1) if (plan.metadata[field] !== draft.metadata[field]) commands.push({
|
|
1681
|
+
type: "image.setMetadata",
|
|
1682
|
+
field,
|
|
1683
|
+
value: draft.metadata[field]
|
|
1684
|
+
});
|
|
1685
|
+
return commands;
|
|
1686
|
+
}
|
|
1687
|
+
var formatOf = (draft) => draft.format === "png" ? { type: "png" } : {
|
|
1688
|
+
type: draft.format,
|
|
1689
|
+
quality: draft.quality / 100
|
|
1690
|
+
};
|
|
1691
|
+
function ImageExportDialog(props) {
|
|
1692
|
+
const { onExport, fileName = "image" } = props;
|
|
1693
|
+
const lifecycle = engineInternals(useImageInternals().engine);
|
|
1694
|
+
const session = useImageSession();
|
|
1695
|
+
const { plan, source } = useImageDocument();
|
|
1696
|
+
const [editor, editorStore] = useImageEditorState();
|
|
1697
|
+
const messages = useImageMessages();
|
|
1698
|
+
const announce = useAnnounce();
|
|
1699
|
+
const listener = useContext(ExportListenerContext);
|
|
1700
|
+
const [draft, setDraft] = useState(null);
|
|
1701
|
+
const [phase, setPhase] = useState({ kind: "choose" });
|
|
1702
|
+
const [error, setError] = useState(null);
|
|
1703
|
+
const controller = useRef(null);
|
|
1704
|
+
const objectUrl = useRef(null);
|
|
1705
|
+
const downloadButton = useRef(null);
|
|
1706
|
+
const open = editor.dialog === "export" && plan !== null && source !== null;
|
|
1707
|
+
const current = draft ?? (plan && source ? initialDraft(plan, source) : null);
|
|
1708
|
+
const revoke = () => {
|
|
1709
|
+
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
1710
|
+
objectUrl.current = null;
|
|
1711
|
+
};
|
|
1712
|
+
useEffect(() => {
|
|
1713
|
+
if (open) return;
|
|
1714
|
+
const running = controller.current;
|
|
1715
|
+
controller.current = null;
|
|
1716
|
+
running?.abort();
|
|
1717
|
+
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
1718
|
+
objectUrl.current = null;
|
|
1719
|
+
setDraft(null);
|
|
1720
|
+
setPhase((now) => now.kind === "choose" ? now : { kind: "choose" });
|
|
1721
|
+
setError(null);
|
|
1722
|
+
}, [open]);
|
|
1723
|
+
useEffect(() => () => {
|
|
1724
|
+
controller.current?.abort();
|
|
1725
|
+
controller.current = null;
|
|
1726
|
+
if (objectUrl.current) URL.revokeObjectURL(objectUrl.current);
|
|
1727
|
+
}, []);
|
|
1728
|
+
const done = phase.kind === "done";
|
|
1729
|
+
useEffect(() => {
|
|
1730
|
+
if (done) downloadButton.current?.focus();
|
|
1731
|
+
}, [done]);
|
|
1732
|
+
const close = () => {
|
|
1733
|
+
editorStore.set((state) => state.dialog === null ? state : {
|
|
1734
|
+
...state,
|
|
1735
|
+
dialog: null
|
|
1736
|
+
});
|
|
1737
|
+
};
|
|
1738
|
+
if (!plan || !source || !current) return null;
|
|
1739
|
+
const update = (patch) => setDraft({
|
|
1740
|
+
...current,
|
|
1741
|
+
...patch
|
|
1742
|
+
});
|
|
1743
|
+
const formatName = (format) => messages.t(`export.formats.${format}`);
|
|
1744
|
+
const run = async () => {
|
|
1745
|
+
setError(null);
|
|
1746
|
+
try {
|
|
1747
|
+
const commands = changes(plan, current);
|
|
1748
|
+
if (commands.length > 0) session.execute(commands);
|
|
1749
|
+
} catch (reason) {
|
|
1750
|
+
setError(reason);
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
const running = new AbortController();
|
|
1754
|
+
controller.current = running;
|
|
1755
|
+
setPhase({
|
|
1756
|
+
kind: "exporting",
|
|
1757
|
+
progress: 0
|
|
1758
|
+
});
|
|
1759
|
+
try {
|
|
1760
|
+
const result = await session.export(formatOf(current), {
|
|
1761
|
+
signal: running.signal,
|
|
1762
|
+
onProgress: (progress) => setPhase((now) => now.kind === "exporting" ? {
|
|
1763
|
+
kind: "exporting",
|
|
1764
|
+
progress
|
|
1765
|
+
} : now)
|
|
1766
|
+
});
|
|
1767
|
+
if (controller.current !== running || lifecycle?.getSnapshot()) return;
|
|
1768
|
+
controller.current = null;
|
|
1769
|
+
announce(messages.t("export.done", {
|
|
1770
|
+
format: formatName(current.format),
|
|
1771
|
+
size: result.blob.size
|
|
1772
|
+
}));
|
|
1773
|
+
listener?.({
|
|
1774
|
+
format: current.format,
|
|
1775
|
+
width: result.width,
|
|
1776
|
+
height: result.height,
|
|
1777
|
+
size: result.blob.size,
|
|
1778
|
+
removed: result.removed,
|
|
1779
|
+
kept: result.kept
|
|
1780
|
+
});
|
|
1781
|
+
if (onExport) {
|
|
1782
|
+
onExport(result.blob, result);
|
|
1783
|
+
close();
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
setPhase({
|
|
1787
|
+
kind: "done",
|
|
1788
|
+
result,
|
|
1789
|
+
format: current.format
|
|
1790
|
+
});
|
|
1791
|
+
} catch (reason) {
|
|
1792
|
+
if (controller.current !== running || lifecycle?.getSnapshot()) return;
|
|
1793
|
+
controller.current = null;
|
|
1794
|
+
setPhase({ kind: "choose" });
|
|
1795
|
+
if (isImageError(reason) && reason.code === "ABORTED") {
|
|
1796
|
+
announce(messages.t("export.cancelled"));
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
setError(reason);
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
const stop = () => controller.current?.abort();
|
|
1803
|
+
const download = () => {
|
|
1804
|
+
if (phase.kind !== "done" || lifecycle?.getSnapshot()) return;
|
|
1805
|
+
revoke();
|
|
1806
|
+
objectUrl.current = URL.createObjectURL(phase.result.blob);
|
|
1807
|
+
const link = document.createElement("a");
|
|
1808
|
+
link.href = objectUrl.current;
|
|
1809
|
+
link.download = `${fileName}.${EXTENSIONS[phase.format]}`;
|
|
1810
|
+
link.click();
|
|
1811
|
+
};
|
|
1812
|
+
const composition = compositionSize(plan, source);
|
|
1813
|
+
const size = outputSize(current.output, composition);
|
|
1814
|
+
const removed = KINDS$1.filter((kind) => source.metadata[kind]);
|
|
1815
|
+
const kept = FIELDS$1.filter((field) => current.metadata[field] !== "");
|
|
1816
|
+
const exporting = phase.kind === "exporting";
|
|
1817
|
+
const footer = phase.kind === "done" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1818
|
+
variant: "secondary",
|
|
1819
|
+
onClick: close,
|
|
1820
|
+
children: messages.t("export.close")
|
|
1821
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1822
|
+
ref: downloadButton,
|
|
1823
|
+
variant: "primary",
|
|
1824
|
+
onClick: download,
|
|
1825
|
+
children: messages.t("export.download")
|
|
1826
|
+
})] }) : exporting ? /* @__PURE__ */ jsx(Button, {
|
|
1827
|
+
variant: "secondary",
|
|
1828
|
+
onClick: stop,
|
|
1829
|
+
children: messages.t("export.stop")
|
|
1830
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1831
|
+
variant: "secondary",
|
|
1832
|
+
onClick: close,
|
|
1833
|
+
children: messages.t("export.cancel")
|
|
1834
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1835
|
+
variant: "primary",
|
|
1836
|
+
onClick: () => void run(),
|
|
1837
|
+
children: messages.t("export.confirm")
|
|
1838
|
+
})] });
|
|
1839
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
1840
|
+
open,
|
|
1841
|
+
onOpenChange: (next) => {
|
|
1842
|
+
if (!next) close();
|
|
1843
|
+
},
|
|
1844
|
+
title: messages.t("export.title"),
|
|
1845
|
+
description: messages.t("export.description"),
|
|
1846
|
+
footer,
|
|
1847
|
+
className: ["hm-image-export", props.className].filter(Boolean).join(" "),
|
|
1848
|
+
children: phase.kind === "done" ? /* @__PURE__ */ jsx("p", {
|
|
1849
|
+
className: "hm-image-export-result",
|
|
1850
|
+
children: messages.t("export.ready", {
|
|
1851
|
+
width: phase.result.width,
|
|
1852
|
+
height: phase.result.height,
|
|
1853
|
+
format: formatName(phase.format),
|
|
1854
|
+
size: phase.result.blob.size
|
|
1855
|
+
})
|
|
1856
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1857
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
1858
|
+
className: "hm-image-export-choices",
|
|
1859
|
+
disabled: exporting,
|
|
1860
|
+
children: [
|
|
1861
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1862
|
+
label: messages.t("export.format"),
|
|
1863
|
+
value: current.format,
|
|
1864
|
+
size: "small",
|
|
1865
|
+
options: FORMATS.map((format) => ({
|
|
1866
|
+
value: format,
|
|
1867
|
+
label: formatName(format)
|
|
1868
|
+
})),
|
|
1869
|
+
onValueChange: (format) => update({ format })
|
|
1870
|
+
}),
|
|
1871
|
+
current.format === "png" ? null : /* @__PURE__ */ jsx(Field, {
|
|
1872
|
+
label: messages.t("export.quality"),
|
|
1873
|
+
className: "hm-image-slider-field",
|
|
1874
|
+
children: (control) => /* @__PURE__ */ jsxs("div", {
|
|
1875
|
+
className: "hm-image-adjust-row",
|
|
1876
|
+
children: [/* @__PURE__ */ jsx(Slider, {
|
|
1877
|
+
...control,
|
|
1878
|
+
min: 1,
|
|
1879
|
+
max: 100,
|
|
1880
|
+
step: 1,
|
|
1881
|
+
largeStep: 10,
|
|
1882
|
+
value: current.quality,
|
|
1883
|
+
formatValue: (quality) => messages.t("export.qualityValue", { quality }),
|
|
1884
|
+
onValueChange: (quality) => update({ quality: Math.round(quality) })
|
|
1885
|
+
}), /* @__PURE__ */ jsx("output", {
|
|
1886
|
+
className: "hm-image-adjust-value",
|
|
1887
|
+
"aria-hidden": "true",
|
|
1888
|
+
children: messages.t("export.qualityValue", { quality: current.quality })
|
|
1889
|
+
})]
|
|
1890
|
+
})
|
|
1891
|
+
}),
|
|
1892
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1893
|
+
label: messages.t("export.size"),
|
|
1894
|
+
value: current.output.kind,
|
|
1895
|
+
size: "small",
|
|
1896
|
+
options: [{
|
|
1897
|
+
value: "scale",
|
|
1898
|
+
label: messages.t("export.sizes.scale")
|
|
1899
|
+
}, {
|
|
1900
|
+
value: "fit",
|
|
1901
|
+
label: messages.t("export.sizes.fit")
|
|
1902
|
+
}],
|
|
1903
|
+
onValueChange: (kind) => update({ output: kind === "fit" ? {
|
|
1904
|
+
kind: "fit",
|
|
1905
|
+
width: composition.width,
|
|
1906
|
+
height: composition.height
|
|
1907
|
+
} : {
|
|
1908
|
+
kind: "scale",
|
|
1909
|
+
scale: 1
|
|
1910
|
+
} })
|
|
1911
|
+
}),
|
|
1912
|
+
/* @__PURE__ */ jsx("div", {
|
|
1913
|
+
className: "hm-image-export-fields",
|
|
1914
|
+
children: current.output.kind === "scale" ? /* @__PURE__ */ jsx(Field, {
|
|
1915
|
+
label: messages.t("export.scale"),
|
|
1916
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1917
|
+
value: Math.round(current.output.scale * 100),
|
|
1918
|
+
min: 1,
|
|
1919
|
+
max: 100,
|
|
1920
|
+
step: 1,
|
|
1921
|
+
largeStep: 10,
|
|
1922
|
+
onValueChange: (percent) => update({ output: {
|
|
1923
|
+
kind: "scale",
|
|
1924
|
+
scale: Math.round(percent) / 100
|
|
1925
|
+
} })
|
|
1926
|
+
})
|
|
1927
|
+
}) : ["width", "height"].map((side) => {
|
|
1928
|
+
const output = current.output;
|
|
1929
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
1930
|
+
label: messages.t(side === "width" ? "export.fitWidth" : "export.fitHeight"),
|
|
1931
|
+
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1932
|
+
value: output[side],
|
|
1933
|
+
min: 1,
|
|
1934
|
+
step: 1,
|
|
1935
|
+
largeStep: 100,
|
|
1936
|
+
onValueChange: (value) => update({ output: {
|
|
1937
|
+
...output,
|
|
1938
|
+
[side]: Math.max(1, Math.round(value))
|
|
1939
|
+
} })
|
|
1940
|
+
})
|
|
1941
|
+
}, side);
|
|
1942
|
+
})
|
|
1943
|
+
}),
|
|
1944
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
1945
|
+
className: "hm-image-export-metadata",
|
|
1946
|
+
children: [
|
|
1947
|
+
/* @__PURE__ */ jsx("legend", { children: messages.t("export.fields") }),
|
|
1948
|
+
/* @__PURE__ */ jsx("p", {
|
|
1949
|
+
className: "hm-image-export-hint",
|
|
1950
|
+
children: messages.t("export.fieldsHint")
|
|
1951
|
+
}),
|
|
1952
|
+
/* @__PURE__ */ jsx("div", {
|
|
1953
|
+
className: "hm-image-export-fields",
|
|
1954
|
+
children: FIELDS$1.map((field) => /* @__PURE__ */ jsx(Field, {
|
|
1955
|
+
label: messages.t(`export.field.${field}`),
|
|
1956
|
+
children: /* @__PURE__ */ jsx(TextField, {
|
|
1957
|
+
autoComplete: "off",
|
|
1958
|
+
value: current.metadata[field],
|
|
1959
|
+
onValueChange: (value) => update({ metadata: {
|
|
1960
|
+
...current.metadata,
|
|
1961
|
+
[field]: keepable(value)
|
|
1962
|
+
} })
|
|
1963
|
+
})
|
|
1964
|
+
}, field))
|
|
1965
|
+
})
|
|
1966
|
+
]
|
|
1967
|
+
})
|
|
1968
|
+
]
|
|
1969
|
+
}),
|
|
1970
|
+
/* @__PURE__ */ jsxs("section", {
|
|
1971
|
+
className: "hm-image-export-summary",
|
|
1972
|
+
"aria-label": messages.t("export.summary"),
|
|
1973
|
+
children: [
|
|
1974
|
+
/* @__PURE__ */ jsx("p", { children: messages.t("export.output", {
|
|
1975
|
+
width: size.width,
|
|
1976
|
+
height: size.height,
|
|
1977
|
+
format: formatName(current.format)
|
|
1978
|
+
}) }),
|
|
1979
|
+
plan.redactions.length > 0 ? /* @__PURE__ */ jsxs("p", { children: [messages.t("export.redacted", { count: plan.redactions.length }), plan.redactions.some((redaction) => redaction.mode === "pixelate") ? ` ${messages.t("export.redactedPixelated")}` : null] }) : null,
|
|
1980
|
+
removed.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: messages.t("export.removed") }), /* @__PURE__ */ jsx("ul", { children: removed.map((kind) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.kind.${kind}`) }, kind)) })] }) : /* @__PURE__ */ jsx("p", { children: messages.t("export.removedNone") }),
|
|
1981
|
+
kept.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: messages.t("export.kept") }), /* @__PURE__ */ jsx("ul", { children: kept.map((field) => /* @__PURE__ */ jsx("li", { children: messages.t(`export.field.${field}`) }, field)) })] }) : null
|
|
1982
|
+
]
|
|
1983
|
+
}),
|
|
1984
|
+
exporting ? /* @__PURE__ */ jsx(ProgressBar, {
|
|
1985
|
+
label: messages.t("export.progress"),
|
|
1986
|
+
value: Math.round(phase.progress * 100),
|
|
1987
|
+
max: 100
|
|
1988
|
+
}) : null,
|
|
1989
|
+
error ? /* @__PURE__ */ jsx("p", {
|
|
1990
|
+
className: "hm-image-export-error",
|
|
1991
|
+
role: "alert",
|
|
1992
|
+
children: messages.error(error)
|
|
1993
|
+
}) : null
|
|
1994
|
+
] })
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
// src/messages/editor-en.ts
|
|
1998
|
+
var imageEditorText = /* @__PURE__ */ defineMessages({
|
|
1999
|
+
"editor.engineUnavailable": "Image processing stopped. Reload this page or reopen the editor, then choose the image again. Unsaved edits will be lost unless your application has saved them.",
|
|
2000
|
+
"editor.label": "Image editor",
|
|
2001
|
+
"editor.preview": "Edited image preview, {width, number} × {height, number}",
|
|
2002
|
+
"editor.empty": "Open an image to start editing. It stays on this device.",
|
|
2003
|
+
"editor.choose": "Choose an image",
|
|
2004
|
+
"editor.dropHint": "or drop it here",
|
|
2005
|
+
"editor.opening": "Opening the image…",
|
|
2006
|
+
"editor.cancel": "Cancel",
|
|
2007
|
+
"editor.opened": "Image opened, {width, number} × {height, number}.",
|
|
2008
|
+
"editor.undid": "Undid {action}.",
|
|
2009
|
+
"editor.redid": "Redid {action}.",
|
|
2010
|
+
"actions.image.setCrop": "crop",
|
|
2011
|
+
"actions.image.setOrientation": "rotate or flip",
|
|
2012
|
+
"actions.image.setOutput": "size",
|
|
2013
|
+
"actions.image.setMetadata": "metadata",
|
|
2014
|
+
"actions.image.setDevelop": "adjustment",
|
|
2015
|
+
"actions.image.setFilter": "filter",
|
|
2016
|
+
"actions.image.insertLayers": "layer",
|
|
2017
|
+
"actions.image.removeLayers": "layer",
|
|
2018
|
+
"actions.image.restoreLayers": "layer",
|
|
2019
|
+
"actions.image.moveLayers": "layer order",
|
|
2020
|
+
"actions.image.setLayerOrder": "layer order",
|
|
2021
|
+
"actions.image.updateLayers": "layer change",
|
|
2022
|
+
"actions.image.addStrokes": "stroke",
|
|
2023
|
+
"actions.image.removeStrokes": "stroke",
|
|
2024
|
+
"actions.image.restoreStrokes": "stroke",
|
|
2025
|
+
"actions.image.insertRedactions": "redaction",
|
|
2026
|
+
"actions.image.removeRedactions": "redaction",
|
|
2027
|
+
"actions.image.restoreRedactions": "redaction",
|
|
2028
|
+
"actions.image.moveRedactions": "redaction order",
|
|
2029
|
+
"actions.image.setRedactionOrder": "redaction order",
|
|
2030
|
+
"actions.image.updateRedactions": "redaction change",
|
|
2031
|
+
"toolbar.label": "Image tools",
|
|
2032
|
+
"toolbar.groups.file": "File",
|
|
2033
|
+
"toolbar.groups.history": "History",
|
|
2034
|
+
"toolbar.groups.orientation": "Rotate",
|
|
2035
|
+
"toolbar.groups.zoom": "Zoom",
|
|
2036
|
+
"toolbar.groups.other": "More tools",
|
|
2037
|
+
"tools.open": "Open image",
|
|
2038
|
+
"tools.undo": "Undo",
|
|
2039
|
+
"tools.redo": "Redo",
|
|
2040
|
+
"tools.rotate-left": "Rotate left",
|
|
2041
|
+
"tools.rotate-right": "Rotate right",
|
|
2042
|
+
"tools.zoom-in": "Zoom in",
|
|
2043
|
+
"tools.zoom-out": "Zoom out",
|
|
2044
|
+
"tools.zoom-fit": "Fit to the stage",
|
|
2045
|
+
"tools.crop": "Crop",
|
|
2046
|
+
"tools.flip-horizontal": "Flip horizontally",
|
|
2047
|
+
"tools.flip-vertical": "Flip vertically",
|
|
2048
|
+
"toolbar.groups.crop": "Crop",
|
|
2049
|
+
"crop.frame": "Crop area",
|
|
2050
|
+
"crop.frameDescription": "{width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; with Shift, they resize it; Enter applies and Escape cancels.",
|
|
2051
|
+
"crop.size": "{width, number} × {height, number}, from {x, number}, {y, number}",
|
|
2052
|
+
"crop.panel": "Crop",
|
|
2053
|
+
"crop.x": "Left",
|
|
2054
|
+
"crop.y": "Top",
|
|
2055
|
+
"crop.width": "Width",
|
|
2056
|
+
"crop.height": "Height",
|
|
2057
|
+
"crop.aspect": "Aspect ratio",
|
|
2058
|
+
"crop.aspects.free": "Free",
|
|
2059
|
+
"crop.aspects.original": "Original",
|
|
2060
|
+
"crop.aspects.ratio": "{width}:{height}",
|
|
2061
|
+
"crop.apply": "Apply crop",
|
|
2062
|
+
"crop.cancel": "Cancel",
|
|
2063
|
+
"crop.reset": "Whole image",
|
|
2064
|
+
"crop.applied": "Cropped to {width, number} × {height, number}.",
|
|
2065
|
+
"tools.redact": "Redact",
|
|
2066
|
+
"toolbar.groups.redact": "Redact",
|
|
2067
|
+
"redact.panel": "Redact",
|
|
2068
|
+
"redact.intro": "Cover parts of the image. Only the exported image is redacted: the original stays in the editor.",
|
|
2069
|
+
"redact.add": "Add area",
|
|
2070
|
+
"redact.done": "Done",
|
|
2071
|
+
"redact.mode": "Cover with",
|
|
2072
|
+
"redact.modes.solid": "Solid colour",
|
|
2073
|
+
"redact.modes.pixelate": "Pixelation",
|
|
2074
|
+
"redact.pixelateHint": "Pixelation may not hide text. For text and numbers, use a solid colour.",
|
|
2075
|
+
"redact.colour": "Colour",
|
|
2076
|
+
"redact.colours.black": "Black",
|
|
2077
|
+
"redact.colours.white": "White",
|
|
2078
|
+
"redact.x": "Left",
|
|
2079
|
+
"redact.y": "Top",
|
|
2080
|
+
"redact.width": "Width",
|
|
2081
|
+
"redact.height": "Height",
|
|
2082
|
+
"redact.areas": "Redacted areas",
|
|
2083
|
+
"redact.none": "No areas yet. Drag across the image, or add one.",
|
|
2084
|
+
"redact.area": "Area {index, number}: {mode}, {width, number} × {height, number}",
|
|
2085
|
+
"redact.modeNames.solid": "solid colour",
|
|
2086
|
+
"redact.modeNames.pixelate": "pixelated",
|
|
2087
|
+
"redact.remove": "Remove area {index, number}",
|
|
2088
|
+
"redact.frame": "Redacted area {index, number} of {count, number}",
|
|
2089
|
+
"redact.frameDescription": "{mode}, {width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; with Shift, they resize it; Delete removes it and Escape ends redacting.",
|
|
2090
|
+
"redact.added": /* @__PURE__ */ plural("count", {
|
|
2091
|
+
one: "Area added. {count} area is redacted.",
|
|
2092
|
+
other: "Area added. {count, number} areas are redacted."
|
|
2093
|
+
}),
|
|
2094
|
+
"redact.removedLast": "Area removed. Nothing is redacted.",
|
|
2095
|
+
"redact.removed": /* @__PURE__ */ plural("count", {
|
|
2096
|
+
one: "Area removed. {count} area is redacted.",
|
|
2097
|
+
other: "Area removed. {count, number} areas are redacted."
|
|
2098
|
+
}),
|
|
2099
|
+
"tools.add-text": "Add text",
|
|
2100
|
+
"tools.add-rectangle": "Add a rectangle",
|
|
2101
|
+
"tools.add-ellipse": "Add an ellipse",
|
|
2102
|
+
"tools.add-arrow": "Add an arrow",
|
|
2103
|
+
"tools.add-image": "Add an image",
|
|
2104
|
+
"tools.draw": "Draw",
|
|
2105
|
+
"toolbar.groups.draw": "Draw",
|
|
2106
|
+
"toolbar.groups.add": "Add",
|
|
2107
|
+
"editor.inserting": "Adding the image…",
|
|
2108
|
+
"layers.text": "Text",
|
|
2109
|
+
"layers.font": "Font",
|
|
2110
|
+
"layers.fonts.sans-serif": "Sans",
|
|
2111
|
+
"layers.fonts.serif": "Serif",
|
|
2112
|
+
"layers.fonts.monospace": "Mono",
|
|
2113
|
+
"layers.align": "Alignment",
|
|
2114
|
+
"layers.alignments.start": "Start",
|
|
2115
|
+
"layers.alignments.center": "Centre",
|
|
2116
|
+
"layers.alignments.end": "End",
|
|
2117
|
+
"layers.bold": "Bold",
|
|
2118
|
+
"layers.colour": "Colour",
|
|
2119
|
+
"layers.arrow.from.x": "Tail, left",
|
|
2120
|
+
"layers.arrow.from.y": "Tail, top",
|
|
2121
|
+
"layers.arrow.to.x": "Tip, left",
|
|
2122
|
+
"layers.arrow.to.y": "Tip, top",
|
|
2123
|
+
"layers.arrow.width": "Width",
|
|
2124
|
+
"layers.fill": "Fill",
|
|
2125
|
+
"layers.outline": "Outline",
|
|
2126
|
+
"layers.fillColour": "Fill colour",
|
|
2127
|
+
"layers.outlineColour": "Outline colour",
|
|
2128
|
+
"layers.outlineWidth": "Outline width",
|
|
2129
|
+
"layers.colours.black": "Black",
|
|
2130
|
+
"layers.colours.white": "White",
|
|
2131
|
+
"layers.colours.red": "Red",
|
|
2132
|
+
"layers.colours.yellow": "Yellow",
|
|
2133
|
+
"layers.colours.green": "Green",
|
|
2134
|
+
"layers.colours.blue": "Blue",
|
|
2135
|
+
"draw.panel": "Draw",
|
|
2136
|
+
"draw.intro": "Drag across the image to draw. Drawing needs a mouse, a pen or a finger; to point at something with the keyboard, add an arrow.",
|
|
2137
|
+
"draw.mode": "Draw with",
|
|
2138
|
+
"draw.modes.pen": "Pen",
|
|
2139
|
+
"draw.modes.highlighter": "Highlighter",
|
|
2140
|
+
"draw.colour": "Colour",
|
|
2141
|
+
"draw.width": "Width",
|
|
2142
|
+
"draw.removeLast": "Remove last stroke",
|
|
2143
|
+
"draw.removed": "Removed the last stroke.",
|
|
2144
|
+
"draw.done": "Done",
|
|
2145
|
+
"tools.layers": "Layers",
|
|
2146
|
+
"toolbar.groups.layers": "Layers",
|
|
2147
|
+
"layers.panel": "Layers",
|
|
2148
|
+
"layers.list": "Layers, the top one first",
|
|
2149
|
+
"layers.none": "No layers yet. Add text, a shape or an image from the toolbar.",
|
|
2150
|
+
"layers.kinds.text": "Text",
|
|
2151
|
+
"layers.kinds.rectangle": "Rectangle",
|
|
2152
|
+
"layers.kinds.ellipse": "Ellipse",
|
|
2153
|
+
"layers.kinds.image": "Image",
|
|
2154
|
+
"layers.kinds.drawing": "Drawing",
|
|
2155
|
+
"layers.kinds.arrow": "Arrow",
|
|
2156
|
+
"layers.visible": "Show {name}",
|
|
2157
|
+
"layers.selected": "Selected layer",
|
|
2158
|
+
"layers.moveUp": "Move up",
|
|
2159
|
+
"layers.moveDown": "Move down",
|
|
2160
|
+
"layers.mirror": "Mirror",
|
|
2161
|
+
"layers.duplicate": "Duplicate",
|
|
2162
|
+
"layers.remove": "Delete",
|
|
2163
|
+
"layers.name": "Name",
|
|
2164
|
+
"layers.x": "Left",
|
|
2165
|
+
"layers.y": "Top",
|
|
2166
|
+
"layers.width": "Width",
|
|
2167
|
+
"layers.height": "Height",
|
|
2168
|
+
"layers.rotation": "Turn, in degrees",
|
|
2169
|
+
"layers.opacity": "Opacity, in percent",
|
|
2170
|
+
"layers.done": "Done",
|
|
2171
|
+
"layers.frame": "Layer {index, number} of {count, number}: {name}",
|
|
2172
|
+
"layers.frameDescription": "{width, number} × {height, number} pixels, from {x, number}, {y, number}, turned {degrees, number}°. Arrow keys move it; with Shift, they resize it; Delete removes it and Escape closes the layers.",
|
|
2173
|
+
"layers.drawingDescription": /* @__PURE__ */ plural("count", {
|
|
2174
|
+
one: "{count} stroke, {width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; Delete removes it and Escape closes the layers.",
|
|
2175
|
+
other: "{count, number} strokes, {width, number} × {height, number} pixels, from {x, number}, {y, number}. Arrow keys move it; Delete removes it and Escape closes the layers."
|
|
2176
|
+
}),
|
|
2177
|
+
"layers.arrowDescription": "From {fromX, number}, {fromY, number} to {toX, number}, {toY, number}. Arrow keys move it; with Shift, they move its tip; Delete removes it and Escape closes the layers.",
|
|
2178
|
+
"layers.movedUp": "Moved {name} up. It's layer {index, number} of {count, number}.",
|
|
2179
|
+
"layers.movedDown": "Moved {name} down. It's layer {index, number} of {count, number}.",
|
|
2180
|
+
"layers.duplicated": "Duplicated {name}.",
|
|
2181
|
+
"layers.removed": "Deleted {name}.",
|
|
2182
|
+
"inspector.label": "Panels",
|
|
2183
|
+
"inspector.adjust": "Adjust",
|
|
2184
|
+
"inspector.filters": "Filters",
|
|
2185
|
+
"inspector.info": "Info",
|
|
2186
|
+
"notices.label": "Notices",
|
|
2187
|
+
"notices.dismiss": "Dismiss",
|
|
2188
|
+
"notices.colourProfile": "This image has a colour profile. Colours outside sRGB will be clipped in the exported file.",
|
|
2189
|
+
"info.panel": "Image info",
|
|
2190
|
+
"info.size": "Size",
|
|
2191
|
+
"info.sizeValue": "{width, number} × {height, number} pixels",
|
|
2192
|
+
"info.format": "Format",
|
|
2193
|
+
"info.formats.png": "PNG",
|
|
2194
|
+
"info.formats.jpeg": "JPEG",
|
|
2195
|
+
"info.formats.webp": "WebP",
|
|
2196
|
+
"info.formats.gif": "GIF",
|
|
2197
|
+
"info.formats.avif": "AVIF",
|
|
2198
|
+
"info.formats.heif": "HEIF",
|
|
2199
|
+
"info.formats.bmp": "BMP",
|
|
2200
|
+
"info.frames": "Frames",
|
|
2201
|
+
"info.fileSize": "File size",
|
|
2202
|
+
"info.fileSizeValue": "{size, fileSize}",
|
|
2203
|
+
"info.metadata": "Metadata in the file",
|
|
2204
|
+
"info.metadataNone": "None",
|
|
2205
|
+
"info.kept": "Kept on export",
|
|
2206
|
+
"info.keptNone": "Nothing",
|
|
2207
|
+
"develop.panel": "Adjust",
|
|
2208
|
+
"develop.temperature": "Temperature",
|
|
2209
|
+
"develop.tint": "Tint",
|
|
2210
|
+
"develop.exposure": "Exposure",
|
|
2211
|
+
"develop.highlights": "Highlights",
|
|
2212
|
+
"develop.shadows": "Shadows",
|
|
2213
|
+
"develop.contrast": "Contrast",
|
|
2214
|
+
"develop.saturation": "Saturation",
|
|
2215
|
+
"develop.vibrance": "Vibrance",
|
|
2216
|
+
"develop.reset": "Reset {name}",
|
|
2217
|
+
"develop.resetAll": "Reset all",
|
|
2218
|
+
"develop.wasReset": "All adjustments reset.",
|
|
2219
|
+
"filters.panel": "Filters",
|
|
2220
|
+
"filters.label": "Filter",
|
|
2221
|
+
"filters.none": "None",
|
|
2222
|
+
"filters.vivid": "Vivid",
|
|
2223
|
+
"filters.warm": "Warm",
|
|
2224
|
+
"filters.cool": "Cool",
|
|
2225
|
+
"filters.fade": "Fade",
|
|
2226
|
+
"filters.mono": "Mono",
|
|
2227
|
+
"filters.noir": "Noir",
|
|
2228
|
+
"filters.sepia": "Sepia",
|
|
2229
|
+
"filters.strength": "Strength",
|
|
2230
|
+
"toolbar.groups.export": "Export",
|
|
2231
|
+
"tools.export": "Export",
|
|
2232
|
+
"tools.exportWhileCropping": "Apply or cancel the crop before exporting.",
|
|
2233
|
+
"export.title": "Export image",
|
|
2234
|
+
"export.description": "The file is made on this device, and nothing is uploaded.",
|
|
2235
|
+
"export.format": "Format",
|
|
2236
|
+
"export.formats.png": "PNG",
|
|
2237
|
+
"export.formats.jpeg": "JPEG",
|
|
2238
|
+
"export.formats.webp": "WebP",
|
|
2239
|
+
"export.quality": "Quality",
|
|
2240
|
+
"export.qualityValue": "{quality, number}%",
|
|
2241
|
+
"export.size": "Size",
|
|
2242
|
+
"export.sizes.scale": "Scale",
|
|
2243
|
+
"export.sizes.fit": "Fit in a box",
|
|
2244
|
+
"export.scale": "Scale, in percent",
|
|
2245
|
+
"export.fitWidth": "Largest width",
|
|
2246
|
+
"export.fitHeight": "Largest height",
|
|
2247
|
+
"export.fields": "Details to include",
|
|
2248
|
+
"export.fieldsHint": "Only what you fill in is written to the file.",
|
|
2249
|
+
"export.field.title": "Title",
|
|
2250
|
+
"export.field.description": "Description",
|
|
2251
|
+
"export.field.artist": "Artist",
|
|
2252
|
+
"export.field.copyright": "Copyright",
|
|
2253
|
+
"export.summary": "Summary",
|
|
2254
|
+
"export.output": "{width, number} × {height, number} pixels, {format}",
|
|
2255
|
+
"export.removed": "Removed from the file",
|
|
2256
|
+
"export.removedNone": "The image had no other details to remove.",
|
|
2257
|
+
"export.redacted": /* @__PURE__ */ plural("count", {
|
|
2258
|
+
one: "{count} area is redacted.",
|
|
2259
|
+
other: "{count, number} areas are redacted."
|
|
2260
|
+
}),
|
|
2261
|
+
"export.redactedPixelated": "Pixelated areas may not hide text.",
|
|
2262
|
+
"export.kind.location": "Location",
|
|
2263
|
+
"export.kind.camera": "Camera details",
|
|
2264
|
+
"export.kind.timestamps": "Dates and times",
|
|
2265
|
+
"export.kind.thumbnail": "Embedded thumbnail",
|
|
2266
|
+
"export.kind.colourProfile": "Colour profile: colours outside sRGB are clipped",
|
|
2267
|
+
"export.kind.other": "Other metadata",
|
|
2268
|
+
"export.kept": "Kept in the file",
|
|
2269
|
+
"export.confirm": "Export",
|
|
2270
|
+
"export.cancel": "Cancel",
|
|
2271
|
+
"export.progress": "Exporting the image",
|
|
2272
|
+
"export.stop": "Stop exporting",
|
|
2273
|
+
"export.cancelled": "Export stopped.",
|
|
2274
|
+
"export.done": "Exported a {format} of {size, fileSize}.",
|
|
2275
|
+
"export.ready": "{width, number} × {height, number} pixels, {format}, {size, fileSize}",
|
|
2276
|
+
"export.download": "Download",
|
|
2277
|
+
"export.close": "Done"
|
|
2278
|
+
});
|
|
2279
|
+
// src/react/editor-messages.ts
|
|
2280
|
+
var imageEditorMessages = /* @__PURE__ */ defineMessages({
|
|
2281
|
+
...imageMessages,
|
|
2282
|
+
...uiMessages,
|
|
2283
|
+
...imageEditorText
|
|
2284
|
+
});
|
|
2285
|
+
// src/react/view-store.ts
|
|
2286
|
+
var FITTED = Object.freeze({
|
|
2287
|
+
zoom: 1,
|
|
2288
|
+
pan: Object.freeze({
|
|
2289
|
+
x: 0,
|
|
2290
|
+
y: 0
|
|
2291
|
+
})
|
|
2292
|
+
});
|
|
2293
|
+
function createViewStore() {
|
|
2294
|
+
return createStore(FITTED);
|
|
1614
2295
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
2296
|
+
// src/react/ImageEditorProvider.tsx
|
|
2297
|
+
function own(props) {
|
|
2298
|
+
const engine = props.engine ?? createImageEngine(props.assetsUrl === void 0 ? {} : { assetsUrl: props.assetsUrl });
|
|
2299
|
+
const processor = props.processor ?? createImageProcessor(engine);
|
|
2300
|
+
const session = props.session ?? createImageSession({
|
|
2301
|
+
engine,
|
|
2302
|
+
processor,
|
|
2303
|
+
...props.filePolicy ? { filePolicy: props.filePolicy } : {},
|
|
2304
|
+
...props.onEvent ? { onEvent: props.onEvent } : {}
|
|
2305
|
+
});
|
|
2306
|
+
return {
|
|
2307
|
+
engine,
|
|
2308
|
+
session,
|
|
2309
|
+
dispose() {
|
|
2310
|
+
if (!props.session) session.destroy();
|
|
2311
|
+
if (!props.processor) processor.destroy();
|
|
2312
|
+
if (!props.engine) engine.destroy();
|
|
2313
|
+
}
|
|
2314
|
+
};
|
|
1617
2315
|
}
|
|
1618
|
-
function
|
|
1619
|
-
return
|
|
2316
|
+
function ImageEditorProvider(props) {
|
|
2317
|
+
return /* @__PURE__ */ jsx(ImageProvider, { ...props });
|
|
1620
2318
|
}
|
|
1621
|
-
function
|
|
1622
|
-
const {
|
|
1623
|
-
const
|
|
1624
|
-
const
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
gesture,
|
|
1633
|
-
select(key) {
|
|
1634
|
-
if (editor.getSnapshot().layers?.selected === key) return;
|
|
1635
|
-
gesture.commit();
|
|
1636
|
-
select(key !== null && layers().some((layer) => layer.key === key) ? key : null);
|
|
1637
|
-
},
|
|
1638
|
-
remove(key) {
|
|
1639
|
-
gesture.cancel();
|
|
1640
|
-
const index = layers().findIndex((layer) => layer.key === key);
|
|
1641
|
-
const layer = layers()[index];
|
|
1642
|
-
if (!layer) return null;
|
|
1643
|
-
session.execute({
|
|
1644
|
-
type: "image.removeLayers",
|
|
1645
|
-
keys: [key]
|
|
1646
|
-
});
|
|
1647
|
-
const next = (layers()[index] ?? layers().at(-1))?.key ?? null;
|
|
1648
|
-
select(next);
|
|
1649
|
-
announce(messages.t("layers.removed", { name: layerLabel(layer, messages) }));
|
|
1650
|
-
return next;
|
|
1651
|
-
},
|
|
1652
|
-
duplicate(key) {
|
|
1653
|
-
gesture.commit();
|
|
1654
|
-
const plan = session.getSnapshot().plan;
|
|
1655
|
-
const index = layers().findIndex((layer) => layer.key === key);
|
|
1656
|
-
const layer = layers()[index];
|
|
1657
|
-
if (!plan || !layer) return;
|
|
1658
|
-
const copy = {
|
|
1659
|
-
...layer,
|
|
1660
|
-
key: newRedactionKey(plan),
|
|
1661
|
-
x: Math.min(layer.x + DUPLICATE_OFFSET, MAX_SCENE_COORDINATE),
|
|
1662
|
-
y: Math.min(layer.y + DUPLICATE_OFFSET, MAX_SCENE_COORDINATE)
|
|
1663
|
-
};
|
|
1664
|
-
session.execute({
|
|
1665
|
-
type: "image.insertLayers",
|
|
1666
|
-
at: index + 1,
|
|
1667
|
-
layers: [copy]
|
|
1668
|
-
});
|
|
1669
|
-
select(copy.key);
|
|
1670
|
-
announce(messages.t("layers.duplicated", { name: layerLabel(layer, messages) }));
|
|
1671
|
-
},
|
|
1672
|
-
shift(key, by) {
|
|
1673
|
-
gesture.commit();
|
|
1674
|
-
const index = layers().findIndex((layer) => layer.key === key);
|
|
1675
|
-
const layer = layers()[index];
|
|
1676
|
-
const to = index + by;
|
|
1677
|
-
if (!layer || to < 0 || to >= layers().length) return;
|
|
1678
|
-
session.execute({
|
|
1679
|
-
type: "image.moveLayers",
|
|
1680
|
-
keys: [key],
|
|
1681
|
-
to
|
|
1682
|
-
});
|
|
1683
|
-
announce(messages.t(by > 0 ? "layers.movedUp" : "layers.movedDown", {
|
|
1684
|
-
name: layerLabel(layer, messages),
|
|
1685
|
-
index: layers().length - to,
|
|
1686
|
-
count: layers().length
|
|
1687
|
-
}));
|
|
1688
|
-
},
|
|
1689
|
-
moving(key, box) {
|
|
1690
|
-
const { x, y, width, height } = box;
|
|
1691
|
-
gesture.preview([{
|
|
1692
|
-
type: "image.updateLayers",
|
|
1693
|
-
updates: [{
|
|
1694
|
-
key,
|
|
1695
|
-
props: {
|
|
1696
|
-
x,
|
|
1697
|
-
y,
|
|
1698
|
-
width,
|
|
1699
|
-
height
|
|
1700
|
-
}
|
|
1701
|
-
}]
|
|
1702
|
-
}]);
|
|
1703
|
-
},
|
|
1704
|
-
commit(soon = false) {
|
|
1705
|
-
if (soon) gesture.commitSoon();
|
|
1706
|
-
else gesture.commit();
|
|
1707
|
-
},
|
|
1708
|
-
cancel() {
|
|
1709
|
-
gesture.cancel();
|
|
1710
|
-
},
|
|
1711
|
-
set(key, props) {
|
|
1712
|
-
gesture.commit();
|
|
1713
|
-
session.execute({
|
|
1714
|
-
type: "image.updateLayers",
|
|
1715
|
-
updates: [{
|
|
1716
|
-
key,
|
|
1717
|
-
props
|
|
1718
|
-
}]
|
|
1719
|
-
});
|
|
1720
|
-
},
|
|
1721
|
-
typing(key, props) {
|
|
1722
|
-
gesture.preview([{
|
|
1723
|
-
type: "image.updateLayers",
|
|
1724
|
-
updates: [{
|
|
1725
|
-
key,
|
|
1726
|
-
props
|
|
1727
|
-
}]
|
|
1728
|
-
}]);
|
|
1729
|
-
gesture.commitSoon();
|
|
1730
|
-
},
|
|
1731
|
-
done() {
|
|
1732
|
-
gesture.commit();
|
|
1733
|
-
editor.set((state) => state.tool === "layers" ? {
|
|
1734
|
-
...state,
|
|
1735
|
-
tool: null,
|
|
1736
|
-
layers: null,
|
|
1737
|
-
preview: null
|
|
1738
|
-
} : state);
|
|
1739
|
-
}
|
|
2319
|
+
function ImageProvider(props) {
|
|
2320
|
+
const { messages: overrides, locale = "en", children } = props;
|
|
2321
|
+
const [owned] = useState(() => own(props));
|
|
2322
|
+
const [view] = useState(createViewStore);
|
|
2323
|
+
const [editor] = useState(createEditorStore);
|
|
2324
|
+
const [opener] = useState(() => createOpener(owned.session));
|
|
2325
|
+
const [inserter] = useState(() => createInserter(owned.session, editor));
|
|
2326
|
+
useEffect(() => {
|
|
2327
|
+
if (owned.pending !== void 0) clearTimeout(owned.pending);
|
|
2328
|
+
return () => {
|
|
2329
|
+
owned.pending = setTimeout(() => owned.dispose(), 0);
|
|
1740
2330
|
};
|
|
1741
|
-
}, [
|
|
1742
|
-
|
|
2331
|
+
}, [owned]);
|
|
2332
|
+
const messages = useMemo(() => createMessages(imageEditorMessages, {
|
|
2333
|
+
locale,
|
|
2334
|
+
...overrides ? { overrides } : {}
|
|
2335
|
+
}), [locale, overrides]);
|
|
2336
|
+
const value = useMemo(() => ({
|
|
2337
|
+
session: owned.session,
|
|
2338
|
+
engine: owned.engine,
|
|
2339
|
+
messages,
|
|
2340
|
+
view,
|
|
1743
2341
|
editor,
|
|
1744
|
-
|
|
2342
|
+
opener,
|
|
2343
|
+
inserter
|
|
2344
|
+
}), [
|
|
2345
|
+
owned,
|
|
1745
2346
|
messages,
|
|
1746
|
-
|
|
2347
|
+
view,
|
|
2348
|
+
editor,
|
|
2349
|
+
opener,
|
|
2350
|
+
inserter
|
|
1747
2351
|
]);
|
|
1748
|
-
|
|
1749
|
-
// src/react/layers/LayerFields.tsx
|
|
1750
|
-
var SWATCHES = [
|
|
1751
|
-
{
|
|
1752
|
-
value: "#000000",
|
|
1753
|
-
name: "black"
|
|
1754
|
-
},
|
|
1755
|
-
{
|
|
1756
|
-
value: "#ffffff",
|
|
1757
|
-
name: "white"
|
|
1758
|
-
},
|
|
1759
|
-
{
|
|
1760
|
-
value: "#e02020",
|
|
1761
|
-
name: "red"
|
|
1762
|
-
},
|
|
1763
|
-
{
|
|
1764
|
-
value: "#f0c020",
|
|
1765
|
-
name: "yellow"
|
|
1766
|
-
},
|
|
1767
|
-
{
|
|
1768
|
-
value: "#20a040",
|
|
1769
|
-
name: "green"
|
|
1770
|
-
},
|
|
1771
|
-
{
|
|
1772
|
-
value: "#2060e0",
|
|
1773
|
-
name: "blue"
|
|
1774
|
-
}
|
|
1775
|
-
];
|
|
1776
|
-
function useSwatches() {
|
|
1777
|
-
const messages = useImageMessages();
|
|
1778
|
-
return SWATCHES.map(({ value, name }) => ({
|
|
2352
|
+
return /* @__PURE__ */ jsx(ImageContext.Provider, {
|
|
1779
2353
|
value,
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
}
|
|
1783
|
-
|
|
1784
|
-
const { layer, actions, run } = props;
|
|
1785
|
-
const messages = useImageMessages();
|
|
1786
|
-
const swatches = useSwatches();
|
|
1787
|
-
const key = layer?.key ?? null;
|
|
1788
|
-
const text = layer?.text ?? "";
|
|
1789
|
-
const [value, setValue] = useState(text);
|
|
1790
|
-
useEffect(() => setValue(text), [key, text]);
|
|
1791
|
-
const off = layer === null;
|
|
1792
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1793
|
-
className: "hm-image-layer-kind",
|
|
1794
|
-
"data-hm-inactive": off ? "" : void 0,
|
|
1795
|
-
children: [
|
|
1796
|
-
/* @__PURE__ */ jsx(Field, {
|
|
1797
|
-
label: messages.t("layers.text"),
|
|
1798
|
-
className: "hm-image-layers-text",
|
|
1799
|
-
children: /* @__PURE__ */ jsx(TextArea, {
|
|
1800
|
-
rows: 3,
|
|
1801
|
-
value,
|
|
1802
|
-
disabled: off,
|
|
1803
|
-
onValueChange: (typed) => {
|
|
1804
|
-
const fitted = fitLayerText(typed);
|
|
1805
|
-
setValue(fitted);
|
|
1806
|
-
if (layer) run(() => actions.typing(layer.key, { text: fitted }));
|
|
1807
|
-
},
|
|
1808
|
-
onBlur: () => actions.commit()
|
|
1809
|
-
})
|
|
1810
|
-
}),
|
|
1811
|
-
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1812
|
-
label: messages.t("layers.font"),
|
|
1813
|
-
size: "small",
|
|
1814
|
-
value: layer?.font ?? "sans-serif",
|
|
1815
|
-
options: LAYER_FONTS.map((font) => ({
|
|
1816
|
-
value: font,
|
|
1817
|
-
label: messages.t(`layers.fonts.${font}`),
|
|
1818
|
-
disabled: off
|
|
1819
|
-
})),
|
|
1820
|
-
onValueChange: (font) => layer && run(() => actions.set(layer.key, { font }))
|
|
1821
|
-
}),
|
|
1822
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1823
|
-
className: "hm-image-layer-row",
|
|
1824
|
-
children: [/* @__PURE__ */ jsx(SegmentedControl, {
|
|
1825
|
-
label: messages.t("layers.align"),
|
|
1826
|
-
size: "small",
|
|
1827
|
-
value: layer?.align ?? "center",
|
|
1828
|
-
options: LAYER_ALIGNMENTS.map((align) => ({
|
|
1829
|
-
value: align,
|
|
1830
|
-
label: messages.t(`layers.alignments.${align}`),
|
|
1831
|
-
disabled: off
|
|
1832
|
-
})),
|
|
1833
|
-
onValueChange: (align) => layer && run(() => actions.set(layer.key, { align }))
|
|
1834
|
-
}), /* @__PURE__ */ jsx(ToggleButton, {
|
|
1835
|
-
size: "small",
|
|
1836
|
-
pressed: layer?.bold ?? false,
|
|
1837
|
-
disabled: off,
|
|
1838
|
-
onPressedChange: (bold) => layer && run(() => actions.set(layer.key, { bold })),
|
|
1839
|
-
children: messages.t("layers.bold")
|
|
1840
|
-
})]
|
|
1841
|
-
}),
|
|
1842
|
-
/* @__PURE__ */ jsx(Field, {
|
|
1843
|
-
label: messages.t("layers.colour"),
|
|
1844
|
-
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1845
|
-
value: layer?.colour ?? "#000000",
|
|
1846
|
-
swatches,
|
|
1847
|
-
disabled: off,
|
|
1848
|
-
onValueChange: (colour) => {
|
|
1849
|
-
if (layer && colour !== layer.colour) run(() => actions.set(layer.key, { colour }));
|
|
1850
|
-
}
|
|
1851
|
-
})
|
|
1852
|
-
})
|
|
1853
|
-
]
|
|
2354
|
+
children: /* @__PURE__ */ jsx(UiMessagesProvider, {
|
|
2355
|
+
messages,
|
|
2356
|
+
children: props.boundary === false ? children : /* @__PURE__ */ jsx(EngineBoundary, { children })
|
|
2357
|
+
})
|
|
1854
2358
|
});
|
|
1855
2359
|
}
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
const set = (props) => {
|
|
1873
|
-
if (layer) run(() => actions.set(layer.key, props));
|
|
2360
|
+
// src/react/layers/frame-geometry.ts
|
|
2361
|
+
var isBoxedLayer = (layer) => layer.kind === "text" || layer.kind === "shape" || layer.kind === "image";
|
|
2362
|
+
var LAYER_HANDLES = [
|
|
2363
|
+
"nw",
|
|
2364
|
+
"n",
|
|
2365
|
+
"ne",
|
|
2366
|
+
"e",
|
|
2367
|
+
"se",
|
|
2368
|
+
"s",
|
|
2369
|
+
"sw",
|
|
2370
|
+
"w"
|
|
2371
|
+
];
|
|
2372
|
+
function turned([a, b, c, d], x, y) {
|
|
2373
|
+
return {
|
|
2374
|
+
x: a * x + c * y,
|
|
2375
|
+
y: b * x + d * y
|
|
1874
2376
|
};
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
},
|
|
1906
|
-
children: messages.t("layers.outline")
|
|
1907
|
-
})]
|
|
1908
|
-
}),
|
|
1909
|
-
/* @__PURE__ */ jsx(Field, {
|
|
1910
|
-
label: messages.t("layers.fillColour"),
|
|
1911
|
-
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1912
|
-
value: fill ?? "#e02020",
|
|
1913
|
-
swatches,
|
|
1914
|
-
disabled: off || fill === null,
|
|
1915
|
-
onValueChange: (colour) => {
|
|
1916
|
-
if (fill !== null && colour !== fill) set({ fill: colour });
|
|
1917
|
-
}
|
|
1918
|
-
})
|
|
1919
|
-
}),
|
|
1920
|
-
/* @__PURE__ */ jsx(Field, {
|
|
1921
|
-
label: messages.t("layers.outlineColour"),
|
|
1922
|
-
children: /* @__PURE__ */ jsx(ColorField, {
|
|
1923
|
-
value: stroke?.colour ?? "#e02020",
|
|
1924
|
-
swatches,
|
|
1925
|
-
disabled: off || stroke === null,
|
|
1926
|
-
onValueChange: (colour) => {
|
|
1927
|
-
if (stroke && colour !== stroke.colour) set({ stroke: {
|
|
1928
|
-
...stroke,
|
|
1929
|
-
colour
|
|
1930
|
-
} });
|
|
1931
|
-
}
|
|
1932
|
-
})
|
|
1933
|
-
}),
|
|
1934
|
-
/* @__PURE__ */ jsx(Field, {
|
|
1935
|
-
label: messages.t("layers.outlineWidth"),
|
|
1936
|
-
children: /* @__PURE__ */ jsx(NumberField, {
|
|
1937
|
-
value: stroke?.width ?? 1,
|
|
1938
|
-
min: 1,
|
|
1939
|
-
max: MAX_STROKE_WIDTH,
|
|
1940
|
-
step: 1,
|
|
1941
|
-
largeStep: 5,
|
|
1942
|
-
disabled: off || stroke === null,
|
|
1943
|
-
onValueChange: (width) => {
|
|
1944
|
-
if (stroke) set({ stroke: {
|
|
1945
|
-
...stroke,
|
|
1946
|
-
width: Math.round(width)
|
|
1947
|
-
} });
|
|
1948
|
-
}
|
|
1949
|
-
})
|
|
1950
|
-
})
|
|
1951
|
-
]
|
|
2377
|
+
}
|
|
2378
|
+
var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
2379
|
+
var whole = (value) => Math.round(value) || 0;
|
|
2380
|
+
var boxOf = ({ x, y, width, height, rotation, flipX }) => ({
|
|
2381
|
+
x,
|
|
2382
|
+
y,
|
|
2383
|
+
width,
|
|
2384
|
+
height,
|
|
2385
|
+
rotation,
|
|
2386
|
+
flipX
|
|
2387
|
+
});
|
|
2388
|
+
function moveLayerBox(box, sceneToComposition, dx, dy) {
|
|
2389
|
+
const by = turned(invertMatrix(sceneToComposition), dx, dy);
|
|
2390
|
+
const limit = MAX_SCENE_COORDINATE;
|
|
2391
|
+
return {
|
|
2392
|
+
...box,
|
|
2393
|
+
x: clamp(box.x + whole(by.x), -limit, limit),
|
|
2394
|
+
y: clamp(box.y + whole(by.y), -limit, limit)
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
function resizeLayerBox(box, handle, dx, dy) {
|
|
2398
|
+
const west = handle.includes("w");
|
|
2399
|
+
const north = handle.includes("n");
|
|
2400
|
+
const size = (length, by) => clamp(whole(length + by), 1, MAX_SCENE_COORDINATE);
|
|
2401
|
+
const width = handle.includes("e") ? size(box.width, dx) : west ? size(box.width, -dx) : box.width;
|
|
2402
|
+
const height = handle.includes("s") ? size(box.height, dy) : north ? size(box.height, -dy) : box.height;
|
|
2403
|
+
const matrix = layerToScene(box);
|
|
2404
|
+
const anchor = applyMatrix(matrix, {
|
|
2405
|
+
x: west ? box.width : 0,
|
|
2406
|
+
y: north ? box.height : 0
|
|
1952
2407
|
});
|
|
2408
|
+
const fromCentre = turned(matrix, (west ? width : 0) - width / 2, (north ? height : 0) - height / 2);
|
|
2409
|
+
const limit = MAX_SCENE_COORDINATE;
|
|
2410
|
+
return {
|
|
2411
|
+
x: clamp(whole(anchor.x - fromCentre.x - width / 2), -limit, limit),
|
|
2412
|
+
y: clamp(whole(anchor.y - fromCentre.y - height / 2), -limit, limit),
|
|
2413
|
+
width,
|
|
2414
|
+
height,
|
|
2415
|
+
rotation: box.rotation,
|
|
2416
|
+
flipX: box.flipX
|
|
2417
|
+
};
|
|
2418
|
+
}
|
|
2419
|
+
function edgeFacing(layerToComposition, direction) {
|
|
2420
|
+
const east = turned(layerToComposition, 1, 0);
|
|
2421
|
+
const south = turned(layerToComposition, 0, 1);
|
|
2422
|
+
const along = (vector) => direction === "right" ? vector.x : vector.y;
|
|
2423
|
+
const facing = [
|
|
2424
|
+
["e", along(east)],
|
|
2425
|
+
["s", along(south)],
|
|
2426
|
+
["w", -along(east)],
|
|
2427
|
+
["n", -along(south)]
|
|
2428
|
+
];
|
|
2429
|
+
let best = facing[0];
|
|
2430
|
+
for (const edge of facing) if (edge[1] > best[1] + 1e-9) best = edge;
|
|
2431
|
+
return best[0];
|
|
2432
|
+
}
|
|
2433
|
+
function resizeLayerBoxOnScreen(box, layerToComposition, direction, by) {
|
|
2434
|
+
const edge = edgeFacing(layerToComposition, direction);
|
|
2435
|
+
const outward = edge === "e" || edge === "s" ? by : -by;
|
|
2436
|
+
return resizeLayerBox(box, edge, outward, outward);
|
|
2437
|
+
}
|
|
2438
|
+
var CURSORS = [
|
|
2439
|
+
"ew-resize",
|
|
2440
|
+
"nwse-resize",
|
|
2441
|
+
"ns-resize",
|
|
2442
|
+
"nesw-resize"
|
|
2443
|
+
];
|
|
2444
|
+
function handleCursor(layerToComposition, handle) {
|
|
2445
|
+
const seen = turned(layerToComposition, handle.includes("e") ? 1 : handle.includes("w") ? -1 : 0, handle.includes("s") ? 1 : handle.includes("n") ? -1 : 0);
|
|
2446
|
+
return CURSORS[(Math.round(Math.atan2(seen.y, seen.x) / (Math.PI / 4)) % 4 + 4) % 4];
|
|
2447
|
+
}
|
|
2448
|
+
var placeOf = ({ x, y, width, height }) => ({
|
|
2449
|
+
x,
|
|
2450
|
+
y,
|
|
2451
|
+
width,
|
|
2452
|
+
height
|
|
2453
|
+
});
|
|
2454
|
+
function moveScenePoint(point, sceneToComposition, dx, dy) {
|
|
2455
|
+
const by = turned(invertMatrix(sceneToComposition), dx, dy);
|
|
2456
|
+
const limit = MAX_SCENE_COORDINATE;
|
|
2457
|
+
return {
|
|
2458
|
+
x: clamp(point.x + whole(by.x), -limit, limit),
|
|
2459
|
+
y: clamp(point.y + whole(by.y), -limit, limit)
|
|
2460
|
+
};
|
|
1953
2461
|
}
|
|
1954
2462
|
// src/react/layers/LayersPanel.tsx
|
|
1955
2463
|
function NameField(props) {
|
|
@@ -1977,22 +2485,12 @@ function ImageLayersPanel(props) {
|
|
|
1977
2485
|
const messages = useImageMessages();
|
|
1978
2486
|
const actions = useLayerActions();
|
|
1979
2487
|
const session = useImageSession();
|
|
1980
|
-
const list = useRef(null);
|
|
1981
2488
|
const panel = useRef(null);
|
|
1982
2489
|
const [problem, setProblem] = useState(null);
|
|
1983
|
-
const focusNext = useRef(null);
|
|
1984
|
-
useEffect(() => {
|
|
1985
|
-
const next = focusNext.current;
|
|
1986
|
-
if (!next) return;
|
|
1987
|
-
focusNext.current = null;
|
|
1988
|
-
const active = document.activeElement;
|
|
1989
|
-
if (active && active !== document.body && !list.current?.contains(active)) return;
|
|
1990
|
-
list.current?.querySelector(`[data-hm-layer="${CSS.escape(next.key)}"] ${next.visibility ? ".hm-image-layer-visibility" : ".hm-image-layer-select"}`)?.focus();
|
|
1991
|
-
});
|
|
1992
2490
|
const focus = state.tool === "layers" ? state.layers?.focus : void 0;
|
|
1993
2491
|
useEffect(() => {
|
|
1994
2492
|
if (!focus) return;
|
|
1995
|
-
panel.current?.querySelector(focus === "text" ? ".hm-image-layers-text textarea" : ".hm-image-layers-list [
|
|
2493
|
+
panel.current?.querySelector(focus === "text" ? ".hm-image-layers-text textarea" : ".hm-image-layers-list [data-hm-tab-stop]")?.focus();
|
|
1996
2494
|
editor.set((current) => current.layers?.focus ? {
|
|
1997
2495
|
...current,
|
|
1998
2496
|
layers: { selected: current.layers.selected }
|
|
@@ -2002,6 +2500,7 @@ function ImageLayersPanel(props) {
|
|
|
2002
2500
|
const { layers } = plan;
|
|
2003
2501
|
const selectedIndex = layers.findIndex((layer) => layer.key === state.layers?.selected);
|
|
2004
2502
|
const selected = layers[selectedIndex];
|
|
2503
|
+
const boxed = selected && isBoxedLayer(selected) ? selected : void 0;
|
|
2005
2504
|
const count = layers.length;
|
|
2006
2505
|
const run = (action) => {
|
|
2007
2506
|
try {
|
|
@@ -2011,51 +2510,30 @@ function ImageLayersPanel(props) {
|
|
|
2011
2510
|
setProblem(error);
|
|
2012
2511
|
}
|
|
2013
2512
|
};
|
|
2014
|
-
const
|
|
2015
|
-
const
|
|
2016
|
-
const
|
|
2017
|
-
if (
|
|
2018
|
-
|
|
2019
|
-
if (
|
|
2020
|
-
event.preventDefault();
|
|
2021
|
-
event.stopPropagation();
|
|
2022
|
-
actions.select(key);
|
|
2023
|
-
const by = event.key === "ArrowUp" ? 1 : -1;
|
|
2024
|
-
const to = layers.findIndex((layer) => layer.key === key) + by;
|
|
2025
|
-
if (to < 0 || to >= count) return;
|
|
2026
|
-
focusNext.current = {
|
|
2027
|
-
key,
|
|
2028
|
-
visibility
|
|
2029
|
-
};
|
|
2030
|
-
run(() => actions.shift(key, by));
|
|
2031
|
-
return;
|
|
2032
|
-
}
|
|
2033
|
-
if (!event.altKey && (event.key === "Delete" || event.key === "Backspace")) {
|
|
2034
|
-
event.preventDefault();
|
|
2035
|
-
event.stopPropagation();
|
|
2036
|
-
run(() => {
|
|
2037
|
-
const next = actions.remove(key);
|
|
2038
|
-
if (next !== null) focusNext.current = {
|
|
2039
|
-
key: next,
|
|
2040
|
-
visibility: false
|
|
2041
|
-
};
|
|
2042
|
-
else list.current?.closest(".hm-image-layers-panel")?.querySelector(".hm-image-layers-done")?.focus();
|
|
2043
|
-
});
|
|
2044
|
-
}
|
|
2513
|
+
const moveTo = (key, toIndex) => {
|
|
2514
|
+
const from = layers.findIndex((layer) => layer.key === key);
|
|
2515
|
+
const to = count - 1 - toIndex;
|
|
2516
|
+
if (from < 0) return;
|
|
2517
|
+
actions.select(key);
|
|
2518
|
+
if (Math.abs(to - from) === 1) run(() => actions.shift(key, to > from ? 1 : -1));
|
|
2045
2519
|
};
|
|
2520
|
+
const removeFromList = (key) => run(() => {
|
|
2521
|
+
if (actions.remove(key) === null) panel.current?.querySelector(".hm-image-layers-done")?.focus();
|
|
2522
|
+
});
|
|
2046
2523
|
const boxField = (name) => {
|
|
2047
2524
|
const length = name === "width" || name === "height";
|
|
2525
|
+
const placedLayer = boxed ?? (!length && selected?.kind === "drawing" ? selected : void 0);
|
|
2048
2526
|
return /* @__PURE__ */ jsx(Field, {
|
|
2049
2527
|
label: messages.t(`layers.${name}`),
|
|
2050
2528
|
children: /* @__PURE__ */ jsx(NumberField, {
|
|
2051
|
-
value:
|
|
2529
|
+
value: boxed ? boxed[name] : placedLayer?.kind === "drawing" && !length ? placedLayer[name] : length ? 1 : 0,
|
|
2052
2530
|
min: length ? 1 : -MAX_SCENE_COORDINATE,
|
|
2053
2531
|
max: MAX_SCENE_COORDINATE,
|
|
2054
2532
|
step: 1,
|
|
2055
2533
|
largeStep: 10,
|
|
2056
|
-
disabled: !
|
|
2534
|
+
disabled: !placedLayer,
|
|
2057
2535
|
onValueChange: (value) => {
|
|
2058
|
-
if (
|
|
2536
|
+
if (placedLayer) run(() => actions.set(placedLayer.key, { [name]: Math.round(value) }));
|
|
2059
2537
|
}
|
|
2060
2538
|
})
|
|
2061
2539
|
}, name);
|
|
@@ -2076,27 +2554,28 @@ function ImageLayersPanel(props) {
|
|
|
2076
2554
|
children: count === 0 ? /* @__PURE__ */ jsx("p", {
|
|
2077
2555
|
className: "hm-image-layers-none",
|
|
2078
2556
|
children: messages.t("layers.none")
|
|
2079
|
-
}) : /* @__PURE__ */ jsx(
|
|
2080
|
-
|
|
2081
|
-
|
|
2557
|
+
}) : /* @__PURE__ */ jsx(ReorderableList, {
|
|
2558
|
+
label: messages.t("layers.list"),
|
|
2559
|
+
selectedId: selected?.key ?? null,
|
|
2560
|
+
onSelectedChange: (key) => actions.select(key),
|
|
2561
|
+
onMove: moveTo,
|
|
2562
|
+
onRemove: removeFromList,
|
|
2563
|
+
announceMoves: false,
|
|
2082
2564
|
children: [...layers].reverse().map((layer) => {
|
|
2083
2565
|
const name = layerLabel(layer, messages);
|
|
2084
|
-
return /* @__PURE__ */
|
|
2566
|
+
return /* @__PURE__ */ jsx(ReorderableListItem, {
|
|
2567
|
+
id: layer.key,
|
|
2568
|
+
label: name,
|
|
2085
2569
|
"data-hm-layer": layer.key,
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
className: "hm-image-layer-select",
|
|
2089
|
-
pressed: layer.key === selected?.key,
|
|
2090
|
-
"aria-keyshortcuts": "Alt+ArrowUp Alt+ArrowDown Delete",
|
|
2091
|
-
onClick: () => actions.select(layer.key),
|
|
2092
|
-
children: name
|
|
2093
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
2570
|
+
classNames: { item: "hm-image-layer-select" },
|
|
2571
|
+
controls: [/* @__PURE__ */ jsx(IconButton, {
|
|
2094
2572
|
className: "hm-image-layer-visibility",
|
|
2095
2573
|
label: messages.t("layers.visible", { name }),
|
|
2096
2574
|
icon: layer.visible ? /* @__PURE__ */ jsx(VisibleIcon, {}) : /* @__PURE__ */ jsx(HiddenIcon, {}),
|
|
2097
2575
|
pressed: layer.visible,
|
|
2098
2576
|
onClick: () => run(() => actions.set(layer.key, { visible: !layer.visible }))
|
|
2099
|
-
})]
|
|
2577
|
+
}, "visibility")],
|
|
2578
|
+
children: name
|
|
2100
2579
|
}, layer.key);
|
|
2101
2580
|
})
|
|
2102
2581
|
})
|
|
@@ -2111,6 +2590,7 @@ function ImageLayersPanel(props) {
|
|
|
2111
2590
|
icon: /* @__PURE__ */ jsx(MoveUpIcon, {}),
|
|
2112
2591
|
disabled: !selected || selectedIndex === count - 1,
|
|
2113
2592
|
focusableWhenDisabled: true,
|
|
2593
|
+
"aria-keyshortcuts": "Alt+ArrowUp",
|
|
2114
2594
|
onClick: () => selected && run(() => actions.shift(selected.key, 1))
|
|
2115
2595
|
}),
|
|
2116
2596
|
/* @__PURE__ */ jsx(IconButton, {
|
|
@@ -2118,15 +2598,16 @@ function ImageLayersPanel(props) {
|
|
|
2118
2598
|
icon: /* @__PURE__ */ jsx(MoveDownIcon, {}),
|
|
2119
2599
|
disabled: !selected || selectedIndex === 0,
|
|
2120
2600
|
focusableWhenDisabled: true,
|
|
2601
|
+
"aria-keyshortcuts": "Alt+ArrowDown",
|
|
2121
2602
|
onClick: () => selected && run(() => actions.shift(selected.key, -1))
|
|
2122
2603
|
}),
|
|
2123
2604
|
/* @__PURE__ */ jsx(IconButton, {
|
|
2124
2605
|
label: messages.t("layers.mirror"),
|
|
2125
2606
|
icon: /* @__PURE__ */ jsx(FlipHorizontalIcon, {}),
|
|
2126
|
-
pressed:
|
|
2127
|
-
disabled: !
|
|
2607
|
+
pressed: boxed?.flipX ?? false,
|
|
2608
|
+
disabled: !boxed,
|
|
2128
2609
|
focusableWhenDisabled: true,
|
|
2129
|
-
onClick: () =>
|
|
2610
|
+
onClick: () => boxed && run(() => actions.set(boxed.key, { flipX: !boxed.flipX }))
|
|
2130
2611
|
}),
|
|
2131
2612
|
/* @__PURE__ */ jsx(IconButton, {
|
|
2132
2613
|
label: messages.t("layers.duplicate"),
|
|
@@ -2175,16 +2656,16 @@ function ImageLayersPanel(props) {
|
|
|
2175
2656
|
/* @__PURE__ */ jsx(Field, {
|
|
2176
2657
|
label: messages.t("layers.rotation"),
|
|
2177
2658
|
children: /* @__PURE__ */ jsx(NumberField, {
|
|
2178
|
-
value:
|
|
2659
|
+
value: boxed ? boxed.rotation / 10 : 0,
|
|
2179
2660
|
min: 0,
|
|
2180
2661
|
max: 359.9,
|
|
2181
2662
|
step: 1,
|
|
2182
2663
|
largeStep: 15,
|
|
2183
|
-
disabled: !
|
|
2664
|
+
disabled: !boxed,
|
|
2184
2665
|
onValueChange: (value) => {
|
|
2185
|
-
if (!
|
|
2666
|
+
if (!boxed) return;
|
|
2186
2667
|
const rotation = (Math.round(value * 10) % 3600 + 3600) % 3600;
|
|
2187
|
-
run(() => actions.set(
|
|
2668
|
+
run(() => actions.set(boxed.key, { rotation }));
|
|
2188
2669
|
}
|
|
2189
2670
|
})
|
|
2190
2671
|
}),
|
|
@@ -2206,15 +2687,23 @@ function ImageLayersPanel(props) {
|
|
|
2206
2687
|
}),
|
|
2207
2688
|
/* @__PURE__ */ jsxs("div", {
|
|
2208
2689
|
className: "hm-image-layer-kinds",
|
|
2209
|
-
children: [
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2690
|
+
children: [
|
|
2691
|
+
/* @__PURE__ */ jsx(TextLayerFields, {
|
|
2692
|
+
layer: selected?.kind === "text" ? selected : null,
|
|
2693
|
+
actions,
|
|
2694
|
+
run
|
|
2695
|
+
}),
|
|
2696
|
+
/* @__PURE__ */ jsx(ShapeLayerFields, {
|
|
2697
|
+
layer: selected?.kind === "shape" ? selected : null,
|
|
2698
|
+
actions,
|
|
2699
|
+
run
|
|
2700
|
+
}),
|
|
2701
|
+
/* @__PURE__ */ jsx(ArrowLayerFields, {
|
|
2702
|
+
layer: selected?.kind === "arrow" ? selected : null,
|
|
2703
|
+
actions,
|
|
2704
|
+
run
|
|
2705
|
+
})
|
|
2706
|
+
]
|
|
2218
2707
|
}),
|
|
2219
2708
|
/* @__PURE__ */ jsx("div", {
|
|
2220
2709
|
className: "hm-image-layers-actions",
|
|
@@ -2568,6 +3057,7 @@ function ImageInspector(props) {
|
|
|
2568
3057
|
if (editor.tool === "crop") return /* @__PURE__ */ jsx(ImageCropPanel, {});
|
|
2569
3058
|
if (editor.tool === "redact") return /* @__PURE__ */ jsx(ImageRedactPanel, {});
|
|
2570
3059
|
if (editor.tool === "layers") return /* @__PURE__ */ jsx(ImageLayersPanel, {});
|
|
3060
|
+
if (editor.tool === "draw") return /* @__PURE__ */ jsx(ImageDrawPanel, {});
|
|
2571
3061
|
if (!plan) return null;
|
|
2572
3062
|
const panels = PANELS.filter((name) => props.features?.[name] !== false);
|
|
2573
3063
|
const first = panels[0];
|
|
@@ -2718,92 +3208,82 @@ function CropFrame(props) {
|
|
|
2718
3208
|
}, handle))]
|
|
2719
3209
|
});
|
|
2720
3210
|
}
|
|
2721
|
-
// src/react/
|
|
2722
|
-
var
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
3211
|
+
// src/react/draw/DrawOverlay.tsx
|
|
3212
|
+
var MAX_SAMPLES = 127937;
|
|
3213
|
+
function DrawOverlay(props) {
|
|
3214
|
+
const { plan, source, view } = props;
|
|
3215
|
+
const actions = useDrawActions();
|
|
3216
|
+
const overlay = useRef(null);
|
|
3217
|
+
const stroke = useRef(void 0);
|
|
3218
|
+
useEffect(() => {
|
|
3219
|
+
const onKeyDown = (event) => {
|
|
3220
|
+
if (event.key !== "Escape" || !stroke.current) return;
|
|
3221
|
+
event.preventDefault();
|
|
3222
|
+
event.stopPropagation();
|
|
3223
|
+
stroke.current = void 0;
|
|
3224
|
+
actions.cancel();
|
|
3225
|
+
};
|
|
3226
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
3227
|
+
return () => document.removeEventListener("keydown", onKeyDown, true);
|
|
3228
|
+
}, [actions]);
|
|
3229
|
+
const composition = compositionSize(plan, source);
|
|
3230
|
+
const placed = placement(composition, view);
|
|
3231
|
+
if (!(placed.scale > 0)) return null;
|
|
3232
|
+
const crop = cropRect(plan.base.crop, source);
|
|
3233
|
+
const { orientation } = plan.base;
|
|
3234
|
+
const sceneOf = (clientX, clientY) => {
|
|
3235
|
+
const box = overlay.current?.getBoundingClientRect();
|
|
3236
|
+
return compositionToSource({
|
|
3237
|
+
x: (clientX - (box?.left ?? 0) - placed.x) / placed.scale,
|
|
3238
|
+
y: (clientY - (box?.top ?? 0) - placed.y) / placed.scale
|
|
3239
|
+
}, crop, orientation);
|
|
2736
3240
|
};
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
return {
|
|
2752
|
-
...box,
|
|
2753
|
-
x: clamp(box.x + whole(by.x), -limit, limit),
|
|
2754
|
-
y: clamp(box.y + whole(by.y), -limit, limit)
|
|
3241
|
+
const onPointerDown = (event) => {
|
|
3242
|
+
if (event.button !== 0 || stroke.current) return;
|
|
3243
|
+
event.preventDefault();
|
|
3244
|
+
try {
|
|
3245
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3246
|
+
} catch {}
|
|
3247
|
+
const current = {
|
|
3248
|
+
pointer: event.pointerId,
|
|
3249
|
+
key: actions.newKey(),
|
|
3250
|
+
samples: [sceneOf(event.clientX, event.clientY)],
|
|
3251
|
+
tolerance: Math.max(1, Math.round(1 / placed.scale))
|
|
3252
|
+
};
|
|
3253
|
+
stroke.current = current;
|
|
3254
|
+
actions.drawing(current.key, current.samples, current.tolerance);
|
|
2755
3255
|
};
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
x: clamp(whole(anchor.x - fromCentre.x - width / 2), -limit, limit),
|
|
2772
|
-
y: clamp(whole(anchor.y - fromCentre.y - height / 2), -limit, limit),
|
|
2773
|
-
width,
|
|
2774
|
-
height,
|
|
2775
|
-
rotation: box.rotation,
|
|
2776
|
-
flipX: box.flipX
|
|
3256
|
+
const onPointerMove = (event) => {
|
|
3257
|
+
const current = stroke.current;
|
|
3258
|
+
if (!current || current.pointer !== event.pointerId) return;
|
|
3259
|
+
const native = event.nativeEvent;
|
|
3260
|
+
const events = native.getCoalescedEvents?.() ?? [];
|
|
3261
|
+
for (const sample of events.length > 0 ? events : [native]) current.samples.push(sceneOf(sample.clientX, sample.clientY));
|
|
3262
|
+
if (current.samples.length >= MAX_SAMPLES) {
|
|
3263
|
+
const last = current.samples[127936];
|
|
3264
|
+
const rest = current.samples.slice(127936);
|
|
3265
|
+
actions.drawing(current.key, current.samples.slice(0, MAX_SAMPLES), current.tolerance);
|
|
3266
|
+
actions.commit(current.key);
|
|
3267
|
+
current.key = actions.newKey();
|
|
3268
|
+
current.samples = rest.length > 0 ? rest : [last];
|
|
3269
|
+
}
|
|
3270
|
+
actions.drawing(current.key, current.samples, current.tolerance);
|
|
2777
3271
|
};
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
}
|
|
2793
|
-
function resizeLayerBoxOnScreen(box, layerToComposition, direction, by) {
|
|
2794
|
-
const edge = edgeFacing(layerToComposition, direction);
|
|
2795
|
-
const outward = edge === "e" || edge === "s" ? by : -by;
|
|
2796
|
-
return resizeLayerBox(box, edge, outward, outward);
|
|
2797
|
-
}
|
|
2798
|
-
var CURSORS = [
|
|
2799
|
-
"ew-resize",
|
|
2800
|
-
"nwse-resize",
|
|
2801
|
-
"ns-resize",
|
|
2802
|
-
"nesw-resize"
|
|
2803
|
-
];
|
|
2804
|
-
function handleCursor(layerToComposition, handle) {
|
|
2805
|
-
const seen = turned(layerToComposition, handle.includes("e") ? 1 : handle.includes("w") ? -1 : 0, handle.includes("s") ? 1 : handle.includes("n") ? -1 : 0);
|
|
2806
|
-
return CURSORS[(Math.round(Math.atan2(seen.y, seen.x) / (Math.PI / 4)) % 4 + 4) % 4];
|
|
3272
|
+
const onPointerEnd = (event) => {
|
|
3273
|
+
const current = stroke.current;
|
|
3274
|
+
if (!current || current.pointer !== event.pointerId) return;
|
|
3275
|
+
stroke.current = void 0;
|
|
3276
|
+
if (event.type === "pointercancel") actions.cancel();
|
|
3277
|
+
else actions.commit(current.key);
|
|
3278
|
+
};
|
|
3279
|
+
return /* @__PURE__ */ jsx("div", {
|
|
3280
|
+
ref: overlay,
|
|
3281
|
+
className: "hm-image-draw-overlay",
|
|
3282
|
+
onPointerDown,
|
|
3283
|
+
onPointerMove,
|
|
3284
|
+
onPointerUp: onPointerEnd,
|
|
3285
|
+
onPointerCancel: onPointerEnd
|
|
3286
|
+
});
|
|
2807
3287
|
}
|
|
2808
3288
|
// src/react/layers/LayersOverlay.tsx
|
|
2809
3289
|
var ARROWS$1 = {
|
|
@@ -2838,12 +3318,45 @@ function LayersOverlay(props) {
|
|
|
2838
3318
|
const { orientation } = plan.base;
|
|
2839
3319
|
const sceneToComposition = sceneToOutput(crop, orientation, composition);
|
|
2840
3320
|
const seen = (box) => layerToOutput(box, crop, orientation, composition);
|
|
3321
|
+
const onStage = (rect) => {
|
|
3322
|
+
const shown = sceneRectToComposition(rect, crop, orientation);
|
|
3323
|
+
return {
|
|
3324
|
+
left: placed.x + shown.x * placed.scale,
|
|
3325
|
+
top: placed.y + shown.y * placed.scale,
|
|
3326
|
+
width: shown.width * placed.scale,
|
|
3327
|
+
height: shown.height * placed.scale
|
|
3328
|
+
};
|
|
3329
|
+
};
|
|
3330
|
+
const aimed = (from, to, fields) => from.x === to.x && from.y === to.y ? null : fields;
|
|
3331
|
+
const dragOf = (layer, part) => {
|
|
3332
|
+
if (layer.kind === "drawing") return (dx, dy) => ({ ...moveScenePoint(layer, sceneToComposition, dx, dy) });
|
|
3333
|
+
if (layer.kind === "arrow") return (dx, dy) => {
|
|
3334
|
+
const from = part === "to" ? layer.from : moveScenePoint(layer.from, sceneToComposition, dx, dy);
|
|
3335
|
+
const to = part === "from" ? layer.to : moveScenePoint(layer.to, sceneToComposition, dx, dy);
|
|
3336
|
+
return aimed(from, to, {
|
|
3337
|
+
from,
|
|
3338
|
+
to
|
|
3339
|
+
});
|
|
3340
|
+
};
|
|
3341
|
+
const start = boxOf(layer);
|
|
3342
|
+
return (dx, dy) => {
|
|
3343
|
+
if (part === "move") return placeOf(moveLayerBox(start, sceneToComposition, dx, dy));
|
|
3344
|
+
const own = turned(invertMatrix(seen(start)), dx, dy);
|
|
3345
|
+
return placeOf(resizeLayerBox(start, part, own.x, own.y));
|
|
3346
|
+
};
|
|
3347
|
+
};
|
|
3348
|
+
const nudgeOf = (layer, dx, dy, shift) => {
|
|
3349
|
+
if (layer.kind === "drawing") return shift ? null : { ...moveScenePoint(layer, sceneToComposition, dx, dy) };
|
|
3350
|
+
if (layer.kind === "arrow") return dragOf(layer, shift ? "to" : "move")(dx, dy);
|
|
3351
|
+
const box = boxOf(layer);
|
|
3352
|
+
return placeOf(shift ? resizeLayerBoxOnScreen(box, seen(box), dx !== 0 ? "right" : "down", dx + dy) : moveLayerBox(box, sceneToComposition, dx, dy));
|
|
3353
|
+
};
|
|
2841
3354
|
const capture = (event) => {
|
|
2842
3355
|
try {
|
|
2843
3356
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
2844
3357
|
} catch {}
|
|
2845
3358
|
};
|
|
2846
|
-
const onFramePointerDown = (layer,
|
|
3359
|
+
const onFramePointerDown = (layer, part) => (event) => {
|
|
2847
3360
|
if (event.button !== 0) return;
|
|
2848
3361
|
event.preventDefault();
|
|
2849
3362
|
event.stopPropagation();
|
|
@@ -2855,23 +3368,17 @@ function LayersOverlay(props) {
|
|
|
2855
3368
|
x: event.clientX,
|
|
2856
3369
|
y: event.clientY,
|
|
2857
3370
|
key: layer.key,
|
|
2858
|
-
|
|
2859
|
-
start: boxOf(layer),
|
|
3371
|
+
at: dragOf(layer, part),
|
|
2860
3372
|
moved: false
|
|
2861
3373
|
};
|
|
2862
3374
|
};
|
|
2863
3375
|
const onPointerMove = (event) => {
|
|
2864
3376
|
const current = drag.current;
|
|
2865
3377
|
if (!current || current.pointer !== event.pointerId) return;
|
|
2866
|
-
const
|
|
2867
|
-
|
|
3378
|
+
const fields = current.at((event.clientX - current.x) / placed.scale, (event.clientY - current.y) / placed.scale);
|
|
3379
|
+
if (!fields) return;
|
|
2868
3380
|
current.moved = true;
|
|
2869
|
-
|
|
2870
|
-
actions.moving(current.key, moveLayerBox(current.start, sceneToComposition, dx, dy));
|
|
2871
|
-
return;
|
|
2872
|
-
}
|
|
2873
|
-
const own = turned(invertMatrix(seen(current.start)), dx, dy);
|
|
2874
|
-
actions.moving(current.key, resizeLayerBox(current.start, current.handle, own.x, own.y));
|
|
3381
|
+
actions.moving(current.key, fields);
|
|
2875
3382
|
};
|
|
2876
3383
|
const onPointerEnd = (event) => {
|
|
2877
3384
|
const current = drag.current;
|
|
@@ -2908,10 +3415,9 @@ function LayersOverlay(props) {
|
|
|
2908
3415
|
if (!arrow) return;
|
|
2909
3416
|
event.preventDefault();
|
|
2910
3417
|
event.stopPropagation();
|
|
2911
|
-
const [
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
actions.moving(layer.key, moved);
|
|
3418
|
+
const fields = nudgeOf(layer, arrow[0], arrow[1], event.shiftKey);
|
|
3419
|
+
if (!fields) return;
|
|
3420
|
+
actions.moving(layer.key, fields);
|
|
2915
3421
|
actions.commit(true);
|
|
2916
3422
|
};
|
|
2917
3423
|
const count = plan.layers.length;
|
|
@@ -2926,10 +3432,10 @@ function LayersOverlay(props) {
|
|
|
2926
3432
|
children: shown.map((layer) => {
|
|
2927
3433
|
const index = plan.layers.indexOf(layer);
|
|
2928
3434
|
const isSelected = layer.key === selected;
|
|
2929
|
-
const
|
|
2930
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
3435
|
+
const frame = {
|
|
2931
3436
|
className: "hm-image-layer-frame",
|
|
2932
3437
|
"data-hm-layer": layer.key,
|
|
3438
|
+
"data-hm-kind": layer.kind,
|
|
2933
3439
|
"data-hm-selected": isSelected ? "" : void 0,
|
|
2934
3440
|
"data-hm-hidden": layer.visible ? void 0 : "",
|
|
2935
3441
|
role: "group",
|
|
@@ -2940,15 +3446,65 @@ function LayersOverlay(props) {
|
|
|
2940
3446
|
}),
|
|
2941
3447
|
"aria-describedby": `${describedBy}-${index}`,
|
|
2942
3448
|
tabIndex: layer.key === tabStop ? 0 : -1,
|
|
3449
|
+
onFocus: () => actions.select(layer.key),
|
|
3450
|
+
onKeyDown: onKeyDown(layer),
|
|
3451
|
+
onPointerDown: onFramePointerDown(layer, "move"),
|
|
3452
|
+
...pointer
|
|
3453
|
+
};
|
|
3454
|
+
if (layer.kind === "drawing" || layer.kind === "arrow") {
|
|
3455
|
+
const bounds = layer.kind === "drawing" ? drawingBounds(layer) : arrowBounds(layer);
|
|
3456
|
+
const box = onStage(bounds);
|
|
3457
|
+
const inFrame = (point) => {
|
|
3458
|
+
const at = onStage({
|
|
3459
|
+
...point,
|
|
3460
|
+
width: 0,
|
|
3461
|
+
height: 0
|
|
3462
|
+
});
|
|
3463
|
+
return {
|
|
3464
|
+
left: `${at.left - box.left}px`,
|
|
3465
|
+
top: `${at.top - box.top}px`
|
|
3466
|
+
};
|
|
3467
|
+
};
|
|
3468
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3469
|
+
...frame,
|
|
3470
|
+
style: {
|
|
3471
|
+
width: `${box.width}px`,
|
|
3472
|
+
height: `${box.height}px`,
|
|
3473
|
+
transform: `translate(${box.left}px, ${box.top}px)`
|
|
3474
|
+
},
|
|
3475
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
3476
|
+
id: `${describedBy}-${index}`,
|
|
3477
|
+
hidden: true,
|
|
3478
|
+
children: layer.kind === "drawing" ? messages.t("layers.drawingDescription", {
|
|
3479
|
+
count: layer.strokes.length,
|
|
3480
|
+
width: bounds.width,
|
|
3481
|
+
height: bounds.height,
|
|
3482
|
+
x: bounds.x,
|
|
3483
|
+
y: bounds.y
|
|
3484
|
+
}) : messages.t("layers.arrowDescription", {
|
|
3485
|
+
fromX: layer.from.x,
|
|
3486
|
+
fromY: layer.from.y,
|
|
3487
|
+
toX: layer.to.x,
|
|
3488
|
+
toY: layer.to.y
|
|
3489
|
+
})
|
|
3490
|
+
}), isSelected && layer.kind === "arrow" ? ["from", "to"].map((end) => /* @__PURE__ */ jsx("span", {
|
|
3491
|
+
className: "hm-image-layer-handle",
|
|
3492
|
+
"data-hm-end": end,
|
|
3493
|
+
"aria-hidden": "true",
|
|
3494
|
+
style: inFrame(layer[end]),
|
|
3495
|
+
onPointerDown: onFramePointerDown(layer, end),
|
|
3496
|
+
...pointer
|
|
3497
|
+
}, end)) : null]
|
|
3498
|
+
}, layer.key);
|
|
3499
|
+
}
|
|
3500
|
+
const [a, b, c, d, e, f] = seen(layer);
|
|
3501
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3502
|
+
...frame,
|
|
2943
3503
|
style: {
|
|
2944
3504
|
width: `${layer.width * placed.scale}px`,
|
|
2945
3505
|
height: `${layer.height * placed.scale}px`,
|
|
2946
3506
|
transform: `matrix(${a}, ${b}, ${c}, ${d}, ${placed.x + e * placed.scale}, ${placed.y + f * placed.scale})`
|
|
2947
3507
|
},
|
|
2948
|
-
onFocus: () => actions.select(layer.key),
|
|
2949
|
-
onKeyDown: onKeyDown(layer),
|
|
2950
|
-
onPointerDown: onFramePointerDown(layer, "move"),
|
|
2951
|
-
...pointer,
|
|
2952
3508
|
children: [/* @__PURE__ */ jsx("span", {
|
|
2953
3509
|
id: `${describedBy}-${index}`,
|
|
2954
3510
|
hidden: true,
|
|
@@ -3324,7 +3880,8 @@ function ImageStage(props) {
|
|
|
3324
3880
|
const cropping = editorState.tool === "crop";
|
|
3325
3881
|
const redacting = editorState.tool === "redact";
|
|
3326
3882
|
const layering = editorState.tool === "layers";
|
|
3327
|
-
const
|
|
3883
|
+
const drawing = editorState.tool === "draw";
|
|
3884
|
+
const inset = cropping || redacting || layering || drawing ? CROP_INSET : 0;
|
|
3328
3885
|
const plan = useMemo(() => {
|
|
3329
3886
|
const committed = snapshot.plan;
|
|
3330
3887
|
if (!committed) return null;
|
|
@@ -3469,6 +4026,21 @@ function ImageStage(props) {
|
|
|
3469
4026
|
}
|
|
3470
4027
|
})
|
|
3471
4028
|
}) : null,
|
|
4029
|
+
drawing && plan && source && size ? /* @__PURE__ */ jsx("div", {
|
|
4030
|
+
className: "hm-image-stage-overlay",
|
|
4031
|
+
children: /* @__PURE__ */ jsx(DrawOverlay, {
|
|
4032
|
+
plan,
|
|
4033
|
+
source,
|
|
4034
|
+
view: {
|
|
4035
|
+
width: size.width,
|
|
4036
|
+
height: size.height,
|
|
4037
|
+
pixelRatio: 1,
|
|
4038
|
+
zoom: view.zoom,
|
|
4039
|
+
pan: view.pan,
|
|
4040
|
+
inset
|
|
4041
|
+
}
|
|
4042
|
+
})
|
|
4043
|
+
}) : null,
|
|
3472
4044
|
empty ? /* @__PURE__ */ jsxs(FileDropZone, {
|
|
3473
4045
|
className: "hm-image-stage-drop",
|
|
3474
4046
|
accept: "image/*",
|
|
@@ -3517,15 +4089,22 @@ function ImageToolbar(props) {
|
|
|
3517
4089
|
children: group.filter((tool) => tool.isAvailable?.(state) ?? true).map((tool) => {
|
|
3518
4090
|
const Icon = icons[tool.icon];
|
|
3519
4091
|
const keys = shortcuts?.ariaKeyShortcuts(tool.id);
|
|
3520
|
-
|
|
4092
|
+
const disabled = !(tool.isEnabled?.(state) ?? true);
|
|
4093
|
+
const reason = disabled ? tool.unavailable?.(state) : void 0;
|
|
4094
|
+
const button = /* @__PURE__ */ jsx(IconButton, {
|
|
3521
4095
|
"data-tool": tool.id,
|
|
3522
4096
|
label: t(tool.label),
|
|
3523
4097
|
icon: Icon ? /* @__PURE__ */ jsx(Icon, {}) : null,
|
|
3524
|
-
disabled
|
|
4098
|
+
disabled,
|
|
4099
|
+
...reason ? { focusableWhenDisabled: true } : {},
|
|
3525
4100
|
...tool.isActive ? { pressed: tool.isActive(state) } : {},
|
|
3526
4101
|
...keys ? { "aria-keyshortcuts": keys } : {},
|
|
3527
4102
|
onClick: () => void tool.run(context)
|
|
3528
4103
|
}, tool.id);
|
|
4104
|
+
return reason ? /* @__PURE__ */ jsx(Tooltip, {
|
|
4105
|
+
content: t(reason),
|
|
4106
|
+
children: button
|
|
4107
|
+
}, tool.id) : button;
|
|
3529
4108
|
})
|
|
3530
4109
|
}, group.map((tool) => tool.id).join(" ")))
|
|
3531
4110
|
});
|
|
@@ -3547,6 +4126,8 @@ var imageIcons = {
|
|
|
3547
4126
|
rectangle: RectangleIcon,
|
|
3548
4127
|
ellipse: EllipseIcon,
|
|
3549
4128
|
"add-image": AddIcon,
|
|
4129
|
+
arrow: ArrowIcon,
|
|
4130
|
+
pen: PenIcon,
|
|
3550
4131
|
export: DownloadIcon,
|
|
3551
4132
|
"flip-horizontal": FlipHorizontalIcon,
|
|
3552
4133
|
"flip-vertical": FlipVerticalIcon,
|
|
@@ -3685,10 +4266,7 @@ function ImageEditorBody(props) {
|
|
|
3685
4266
|
if (sourceId === void 0) return;
|
|
3686
4267
|
editor.set((state) => state.tool === null && state.dialog === null && state.error === null ? state : {
|
|
3687
4268
|
...state,
|
|
3688
|
-
|
|
3689
|
-
crop: null,
|
|
3690
|
-
redact: null,
|
|
3691
|
-
layers: null,
|
|
4269
|
+
...NO_TOOL,
|
|
3692
4270
|
preview: null,
|
|
3693
4271
|
dialog: null,
|
|
3694
4272
|
error: null
|
|
@@ -3812,6 +4390,6 @@ var ImageEditor = forwardRef(function ImageEditor(props, ref) {
|
|
|
3812
4390
|
}) })
|
|
3813
4391
|
});
|
|
3814
4392
|
});
|
|
3815
|
-
export {
|
|
4393
|
+
export { useImageEditorState as _, ImageInfoPanel as a, useImageView as b, ImageRedactPanel as c, imageEditorMessages as d, ImageExportDialog as f, useImageDocument as g, ImageCropPanel as h, ImageStage as i, ImageLayersPanel as l, ImageDrawPanel as m, imageIcons as n, ImageFilterPanel as o, ExportListenerContext as p, ImageToolbar as r, ImageAdjustPanel as s, ImageEditor as t, ImageEditorProvider as u, useImageMessages as v, imageTools as x, useImageSession as y };
|
|
3816
4394
|
|
|
3817
|
-
//# sourceMappingURL=editor-
|
|
4395
|
+
//# sourceMappingURL=editor-Bj9Xo5nf.js.map
|