@open-slide/core 2.0.0-beta.3 → 2.0.0-beta.6
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 +1 -1
- package/dist/{build-Bzy-qlGc.js → build-Cu5_qRyE.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-nbSvY7z_.js → config-BQ6rD2iE.js} +226 -27
- package/dist/{config-DjWifhaA.d.ts → config-GMR1QUlM.d.ts} +1 -1
- package/dist/{dev-MXa5Tod4.js → dev-BK641O5e.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-DEpQcKz3.js → preview-BuCI-RMW.js} +1 -1
- package/dist/{types-BWg-Dtbg.d.ts → types-BcbaKTNY.d.ts} +60 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DlKyeNX7.js → zh-tw-DlZoAc2-.js} +271 -35
- package/package.json +6 -6
- package/src/app/components/asset-view.tsx +448 -0
- package/src/app/components/history-provider.tsx +68 -44
- package/src/app/components/icon-switcher-indicator.tsx +10 -0
- package/src/app/components/inspector/arrange-panel.tsx +449 -0
- package/src/app/components/inspector/inline-text-editor.tsx +170 -284
- package/src/app/components/inspector/inspect-overlay.tsx +642 -295
- package/src/app/components/inspector/inspector-panel.tsx +434 -427
- package/src/app/components/inspector/inspector-provider.tsx +564 -293
- package/src/app/components/inspector/save-bar.tsx +36 -0
- package/src/app/components/note-markdown.test.tsx +42 -0
- package/src/app/components/note-markdown.tsx +85 -0
- package/src/app/components/panel/editor-sidebar.tsx +50 -0
- package/src/app/components/panel/panel-fields.tsx +204 -16
- package/src/app/components/panel/panel-shell.tsx +3 -18
- package/src/app/components/style-panel/style-panel.tsx +4 -69
- package/src/app/lib/assets.ts +33 -0
- package/src/app/lib/export-html.ts +48 -5
- package/src/app/lib/inspector/geometry.test.ts +324 -0
- package/src/app/lib/inspector/geometry.ts +207 -0
- package/src/app/lib/inspector/text-edit-timeline.test.ts +121 -0
- package/src/app/lib/inspector/text-edit-timeline.ts +12 -0
- package/src/app/lib/inspector/text-selection.ts +117 -0
- package/src/app/lib/inspector/use-editor.ts +1 -1
- package/src/app/lib/inspector/use-visual-editor.ts +429 -0
- package/src/app/lib/inspector/visual-dom.ts +255 -0
- package/src/app/lib/keys.ts +9 -0
- package/src/app/lib/note-markdown.test.ts +147 -0
- package/src/app/lib/note-markdown.ts +116 -0
- package/src/app/routes/presenter.tsx +3 -2
- package/src/app/routes/slide.tsx +34 -9
- package/src/locale/en.ts +71 -9
- package/src/locale/ja.ts +73 -8
- package/src/locale/types.ts +60 -0
- package/src/locale/zh-cn.ts +69 -9
- package/src/locale/zh-tw.ts +69 -9
|
@@ -1,337 +1,684 @@
|
|
|
1
1
|
import { Crop, ImageIcon } from 'lucide-react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { findSlideSource } from '@/lib/inspector/fiber';
|
|
4
|
+
import {
|
|
5
|
+
type Guide,
|
|
6
|
+
type Point,
|
|
7
|
+
type Rect,
|
|
8
|
+
type ResizeHandle,
|
|
9
|
+
resizeRect,
|
|
10
|
+
snapMove,
|
|
11
|
+
unionRects,
|
|
12
|
+
} from '@/lib/inspector/geometry';
|
|
6
13
|
import {
|
|
7
14
|
isInspectableEventTarget,
|
|
8
15
|
pickElement,
|
|
9
16
|
pickInspectorTarget,
|
|
10
17
|
} from '@/lib/inspector/pick-target';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
import type { VisualEdit } from '@/lib/inspector/use-visual-editor';
|
|
19
|
+
import {
|
|
20
|
+
type Canvas,
|
|
21
|
+
canTransform,
|
|
22
|
+
captureTransform,
|
|
23
|
+
editableTargets,
|
|
24
|
+
independentTargets,
|
|
25
|
+
marqueeTargets,
|
|
26
|
+
moveOps,
|
|
27
|
+
previewOps,
|
|
28
|
+
readCanvas,
|
|
29
|
+
readFrame,
|
|
30
|
+
restoreTransform,
|
|
31
|
+
round,
|
|
32
|
+
sizeOps,
|
|
33
|
+
styleOp,
|
|
34
|
+
type TransformSnapshot,
|
|
35
|
+
} from '@/lib/inspector/visual-dom';
|
|
36
|
+
import { isTypingTarget } from '@/lib/keys';
|
|
37
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
38
|
+
import { type SelectedTarget, useInspector } from './inspector-provider';
|
|
39
|
+
|
|
40
|
+
type Gesture = {
|
|
41
|
+
pointerId: number;
|
|
42
|
+
start: Point;
|
|
43
|
+
targets: SelectedTarget[];
|
|
44
|
+
mode: 'move' | 'marquee' | 'rotate' | ResizeHandle;
|
|
45
|
+
snapshots: TransformSnapshot[];
|
|
46
|
+
canvas: Canvas;
|
|
47
|
+
bounds: Rect | null;
|
|
48
|
+
candidates: Rect[];
|
|
49
|
+
moved: boolean;
|
|
50
|
+
edits: VisualEdit[];
|
|
51
|
+
previousSelection: SelectedTarget[];
|
|
52
|
+
clickSelection: SelectedTarget[];
|
|
53
|
+
additive: boolean;
|
|
54
|
+
};
|
|
18
55
|
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
56
|
+
type ScreenRect = { left: number; top: number; width: number; height: number };
|
|
57
|
+
const HANDLES: { handle: ResizeHandle; x: number; y: number; cursor: string }[] = [
|
|
58
|
+
{ handle: 'nw', x: 0, y: 0, cursor: 'nwse-resize' },
|
|
59
|
+
{ handle: 'n', x: 0.5, y: 0, cursor: 'ns-resize' },
|
|
60
|
+
{ handle: 'ne', x: 1, y: 0, cursor: 'nesw-resize' },
|
|
61
|
+
{ handle: 'e', x: 1, y: 0.5, cursor: 'ew-resize' },
|
|
62
|
+
{ handle: 'se', x: 1, y: 1, cursor: 'nwse-resize' },
|
|
63
|
+
{ handle: 's', x: 0.5, y: 1, cursor: 'ns-resize' },
|
|
64
|
+
{ handle: 'sw', x: 0, y: 1, cursor: 'nesw-resize' },
|
|
65
|
+
{ handle: 'w', x: 0, y: 0.5, cursor: 'ew-resize' },
|
|
66
|
+
];
|
|
22
67
|
|
|
23
68
|
export function InspectOverlay() {
|
|
24
|
-
const {
|
|
69
|
+
const {
|
|
70
|
+
active,
|
|
71
|
+
slideId,
|
|
72
|
+
selection,
|
|
73
|
+
selected,
|
|
74
|
+
setSelection,
|
|
75
|
+
cancel,
|
|
76
|
+
openCrop,
|
|
77
|
+
openReplace,
|
|
78
|
+
inlineEdit,
|
|
79
|
+
committing,
|
|
80
|
+
bufferBatch,
|
|
81
|
+
visual,
|
|
82
|
+
opsVersion,
|
|
83
|
+
} = useInspector();
|
|
84
|
+
const t = useLocale();
|
|
25
85
|
const overlayRef = useRef<HTMLDivElement>(null);
|
|
26
|
-
const
|
|
86
|
+
const measureRef = useRef<(() => void) | null>(null);
|
|
87
|
+
const gestureRef = useRef<Gesture | null>(null);
|
|
88
|
+
const suppressClick = useRef(false);
|
|
89
|
+
const [hover, setHover] = useState<HTMLElement | null>(null);
|
|
90
|
+
const [localTargets, setLocalTargets] = useState<SelectedTarget[] | null>(null);
|
|
91
|
+
const [guides, setGuides] = useState<Guide[]>([]);
|
|
92
|
+
const [marquee, setMarquee] = useState<Rect | null>(null);
|
|
93
|
+
const frameIds = useRef(new WeakMap<HTMLElement, number>());
|
|
94
|
+
const nextFrameId = useRef(0);
|
|
95
|
+
const [frames, setFrames] = useState<(ScreenRect & { id: number })[]>([]);
|
|
96
|
+
const [hoverFrame, setHoverFrame] = useState<ScreenRect | null>(null);
|
|
97
|
+
const [canvasFrame, setCanvasFrame] = useState<ScreenRect | null>(null);
|
|
98
|
+
const [scale, setScale] = useState(1);
|
|
99
|
+
const displayed = localTargets ?? selection;
|
|
27
100
|
|
|
28
101
|
useEffect(() => {
|
|
29
|
-
if (!active)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
e.stopPropagation();
|
|
40
|
-
cancel();
|
|
41
|
-
}
|
|
102
|
+
if (!active) return;
|
|
103
|
+
const root = document.querySelector<HTMLElement>('[data-inspector-root]');
|
|
104
|
+
if (!root) return;
|
|
105
|
+
const style = document.createElement('style');
|
|
106
|
+
style.textContent = EDITING_FREEZE_CSS;
|
|
107
|
+
document.head.appendChild(style);
|
|
108
|
+
root.dataset.inspectorEditing = 'true';
|
|
109
|
+
return () => {
|
|
110
|
+
style.remove();
|
|
111
|
+
delete root.dataset.inspectorEditing;
|
|
42
112
|
};
|
|
113
|
+
}, [active]);
|
|
43
114
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
115
|
+
useLayoutEffect(() => {
|
|
116
|
+
if (!active) return;
|
|
117
|
+
void opsVersion;
|
|
118
|
+
let raf = 0;
|
|
119
|
+
const stopAt = performance.now() + 420;
|
|
120
|
+
const measure = () => {
|
|
121
|
+
const overlay = overlayRef.current;
|
|
122
|
+
const canvas = readCanvas();
|
|
123
|
+
if (!overlay || !canvas) return;
|
|
124
|
+
const origin = overlay.getBoundingClientRect();
|
|
125
|
+
const rect = (anchor: HTMLElement): ScreenRect => {
|
|
126
|
+
const box = anchor.getBoundingClientRect();
|
|
127
|
+
return {
|
|
128
|
+
left: box.left - origin.left,
|
|
129
|
+
top: box.top - origin.top,
|
|
130
|
+
width: box.width,
|
|
131
|
+
height: box.height,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const next = displayed
|
|
135
|
+
.filter((target) => target.anchor.isConnected)
|
|
136
|
+
.map((target) => {
|
|
137
|
+
let id = frameIds.current.get(target.anchor);
|
|
138
|
+
if (id === undefined) {
|
|
139
|
+
id = ++nextFrameId.current;
|
|
140
|
+
frameIds.current.set(target.anchor, id);
|
|
141
|
+
}
|
|
142
|
+
return { ...rect(target.anchor), id };
|
|
143
|
+
});
|
|
144
|
+
setFrames((previous) =>
|
|
145
|
+
JSON.stringify(previous) === JSON.stringify(next) ? previous : next,
|
|
146
|
+
);
|
|
147
|
+
const nextHover =
|
|
148
|
+
hover?.isConnected && !displayed.some((target) => target.anchor === hover)
|
|
149
|
+
? rect(hover)
|
|
150
|
+
: null;
|
|
151
|
+
setHoverFrame((previous) =>
|
|
152
|
+
JSON.stringify(previous) === JSON.stringify(nextHover) ? previous : nextHover,
|
|
153
|
+
);
|
|
154
|
+
const nextCanvas = rect(canvas.root);
|
|
155
|
+
setCanvasFrame((previous) =>
|
|
156
|
+
JSON.stringify(previous) === JSON.stringify(nextCanvas) ? previous : nextCanvas,
|
|
157
|
+
);
|
|
158
|
+
setScale(canvas.scale);
|
|
52
159
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
160
|
+
const track = () => {
|
|
161
|
+
measure();
|
|
162
|
+
if (performance.now() < stopAt) raf = requestAnimationFrame(track);
|
|
163
|
+
};
|
|
164
|
+
measureRef.current = measure;
|
|
165
|
+
track();
|
|
166
|
+
const observer = new ResizeObserver(measure);
|
|
167
|
+
if (overlayRef.current) observer.observe(overlayRef.current);
|
|
168
|
+
for (const target of displayed) if (target.anchor.isConnected) observer.observe(target.anchor);
|
|
169
|
+
window.addEventListener('resize', measure);
|
|
170
|
+
window.addEventListener('scroll', measure, true);
|
|
171
|
+
return () => {
|
|
172
|
+
measureRef.current = null;
|
|
173
|
+
cancelAnimationFrame(raf);
|
|
174
|
+
observer.disconnect();
|
|
175
|
+
window.removeEventListener('resize', measure);
|
|
176
|
+
window.removeEventListener('scroll', measure, true);
|
|
66
177
|
};
|
|
178
|
+
}, [active, displayed, hover, opsVersion]);
|
|
67
179
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!active) return;
|
|
182
|
+
let raf = 0;
|
|
183
|
+
let pendingMove: PointerEvent | null = null;
|
|
184
|
+
const clearGesture = (restore: boolean) => {
|
|
185
|
+
const gesture = gestureRef.current;
|
|
186
|
+
if (restore) for (const snapshot of gesture?.snapshots ?? []) restoreTransform(snapshot);
|
|
187
|
+
if (gesture) delete gesture.canvas.root.dataset.visualGesture;
|
|
188
|
+
gestureRef.current = null;
|
|
189
|
+
setLocalTargets(null);
|
|
190
|
+
setGuides([]);
|
|
191
|
+
setMarquee(null);
|
|
192
|
+
measureRef.current?.();
|
|
193
|
+
document.documentElement.style.removeProperty('cursor');
|
|
194
|
+
document.documentElement.style.removeProperty('--osd-gesture-cursor');
|
|
195
|
+
};
|
|
196
|
+
const targetAt = (event: PointerEvent): SelectedTarget | null => {
|
|
197
|
+
const element = pickInspectorTarget(pickElement(event.clientX, event.clientY));
|
|
198
|
+
return element ? findSlideSource(element, slideId, { hostOnly: true }) : null;
|
|
199
|
+
};
|
|
200
|
+
const point = (event: PointerEvent, canvas: Canvas): Point => ({
|
|
201
|
+
x: (event.clientX - canvas.rect.left) / canvas.scale,
|
|
202
|
+
y: (event.clientY - canvas.rect.top) / canvas.scale,
|
|
203
|
+
});
|
|
204
|
+
const onDown = (event: PointerEvent) => {
|
|
205
|
+
if (event.button !== 0 || !event.isPrimary || committing || gestureRef.current) return;
|
|
206
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
207
|
+
const handle = element?.closest<HTMLElement>('[data-resize-handle], [data-rotate-handle]');
|
|
208
|
+
if (!handle && !isInspectableEventTarget(event.target)) return;
|
|
209
|
+
if (!handle && inlineEdit?.anchor.contains(event.target as Node)) return;
|
|
210
|
+
const canvas = readCanvas();
|
|
211
|
+
if (!canvas) return;
|
|
212
|
+
if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
|
|
213
|
+
let hit = handle ? selected : targetAt(event);
|
|
214
|
+
if (hit && !handle && !event.metaKey && !event.ctrlKey) {
|
|
215
|
+
const hitAnchor = hit.anchor;
|
|
216
|
+
const ancestor = selection.find((target) => target.anchor.contains(hitAnchor));
|
|
217
|
+
if (ancestor && !event.shiftKey) hit = ancestor;
|
|
218
|
+
const frame = readFrame(hit.anchor, canvas);
|
|
219
|
+
const background =
|
|
220
|
+
Math.abs(frame.x) < 1 &&
|
|
221
|
+
Math.abs(frame.y) < 1 &&
|
|
222
|
+
frame.width >= canvas.width - 1 &&
|
|
223
|
+
frame.height >= canvas.height - 1;
|
|
224
|
+
if (background && !selection.some((target) => target.anchor === hit?.anchor)) hit = null;
|
|
225
|
+
}
|
|
226
|
+
let targets = selection;
|
|
227
|
+
let clickSelection = selection;
|
|
228
|
+
if (hit && !handle) {
|
|
229
|
+
if (event.shiftKey) {
|
|
230
|
+
const alreadySelected = selection.some((target) => target.anchor === hit.anchor);
|
|
231
|
+
clickSelection = alreadySelected
|
|
232
|
+
? selection.filter((target) => target.anchor !== hit.anchor)
|
|
233
|
+
: [
|
|
234
|
+
...selection.filter(
|
|
235
|
+
(target) =>
|
|
236
|
+
!target.anchor.contains(hit.anchor) && !hit.anchor.contains(target.anchor),
|
|
237
|
+
),
|
|
238
|
+
hit,
|
|
239
|
+
];
|
|
240
|
+
targets = alreadySelected ? selection : clickSelection;
|
|
241
|
+
} else if (!selection.some((target) => target.anchor === hit.anchor)) targets = [hit];
|
|
242
|
+
} else if (!hit) targets = event.shiftKey ? selection : [];
|
|
243
|
+
if (!event.shiftKey || !hit || handle) clickSelection = targets;
|
|
244
|
+
const mode = handle?.hasAttribute('data-rotate-handle')
|
|
245
|
+
? 'rotate'
|
|
246
|
+
: (handle?.dataset.resizeHandle as ResizeHandle | undefined);
|
|
247
|
+
const chosen = independentTargets(targets);
|
|
248
|
+
const transformable =
|
|
249
|
+
chosen.length > 0 && chosen.every((target) => canTransform(target, canvas));
|
|
250
|
+
const snapshots = transformable
|
|
251
|
+
? chosen.map((target) => captureTransform(target, canvas))
|
|
252
|
+
: [];
|
|
253
|
+
const bounds = unionRects(snapshots.map((snapshot) => snapshot.frame));
|
|
254
|
+
const candidates = editableTargets(canvas, slideId)
|
|
255
|
+
.filter(
|
|
256
|
+
(target) =>
|
|
257
|
+
!chosen.some(
|
|
258
|
+
(selectedTarget) =>
|
|
259
|
+
selectedTarget.anchor.contains(target.anchor) ||
|
|
260
|
+
target.anchor.contains(selectedTarget.anchor),
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
.map((target) => readFrame(target.anchor, canvas));
|
|
264
|
+
candidates.push({ x: 0, y: 0, width: canvas.width, height: canvas.height });
|
|
265
|
+
gestureRef.current = {
|
|
266
|
+
pointerId: event.pointerId,
|
|
267
|
+
start: point(event, canvas),
|
|
268
|
+
targets: chosen,
|
|
269
|
+
mode: hit ? (mode ?? 'move') : 'marquee',
|
|
270
|
+
snapshots,
|
|
271
|
+
canvas,
|
|
272
|
+
bounds,
|
|
273
|
+
candidates,
|
|
274
|
+
moved: false,
|
|
275
|
+
edits: [],
|
|
276
|
+
previousSelection: selection,
|
|
277
|
+
clickSelection,
|
|
278
|
+
additive: event.shiftKey,
|
|
279
|
+
};
|
|
280
|
+
canvas.root.dataset.visualGesture = 'true';
|
|
281
|
+
setLocalTargets(chosen);
|
|
282
|
+
suppressClick.current = true;
|
|
283
|
+
event.preventDefault();
|
|
284
|
+
event.stopPropagation();
|
|
285
|
+
};
|
|
286
|
+
const update = (event: PointerEvent) => {
|
|
287
|
+
const gesture = gestureRef.current;
|
|
288
|
+
if (!gesture || gesture.pointerId !== event.pointerId) return;
|
|
289
|
+
const current = point(event, gesture.canvas);
|
|
290
|
+
let delta = { x: current.x - gesture.start.x, y: current.y - gesture.start.y };
|
|
291
|
+
if (!gesture.moved && Math.hypot(delta.x, delta.y) * gesture.canvas.scale < 3) return;
|
|
292
|
+
gesture.moved = true;
|
|
293
|
+
if (gesture.mode === 'marquee') {
|
|
294
|
+
const rect = {
|
|
295
|
+
x: Math.min(gesture.start.x, current.x),
|
|
296
|
+
y: Math.min(gesture.start.y, current.y),
|
|
297
|
+
width: Math.abs(delta.x),
|
|
298
|
+
height: Math.abs(delta.y),
|
|
299
|
+
};
|
|
300
|
+
setMarquee(rect);
|
|
301
|
+
const candidates = editableTargets(gesture.canvas, slideId).flatMap((target) => {
|
|
302
|
+
if (!canTransform(target, gesture.canvas)) return [];
|
|
303
|
+
const frame = readFrame(target.anchor, gesture.canvas);
|
|
304
|
+
const fullCanvas =
|
|
305
|
+
Math.abs(frame.x) < 1 &&
|
|
306
|
+
Math.abs(frame.y) < 1 &&
|
|
307
|
+
frame.width >= gesture.canvas.width - 1 &&
|
|
308
|
+
frame.height >= gesture.canvas.height - 1;
|
|
309
|
+
return fullCanvas ? [] : [{ target, frame }];
|
|
310
|
+
});
|
|
311
|
+
const targets = marqueeTargets(rect, candidates);
|
|
312
|
+
gesture.targets = independentTargets(
|
|
313
|
+
[...(gesture.additive ? gesture.previousSelection : []), ...targets].filter(
|
|
314
|
+
(target, index, all) =>
|
|
315
|
+
all.findIndex((other) => other.anchor === target.anchor) === index,
|
|
316
|
+
),
|
|
317
|
+
);
|
|
318
|
+
setLocalTargets(gesture.targets);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!gesture.bounds || !gesture.snapshots.length) return;
|
|
322
|
+
const cursor =
|
|
323
|
+
gesture.mode === 'move'
|
|
324
|
+
? 'grabbing'
|
|
325
|
+
: gesture.mode === 'rotate'
|
|
326
|
+
? 'crosshair'
|
|
327
|
+
: `${gesture.mode}-resize`;
|
|
328
|
+
document.documentElement.style.cursor = cursor;
|
|
329
|
+
document.documentElement.style.setProperty('--osd-gesture-cursor', cursor);
|
|
330
|
+
let nextGuides: Guide[] = [];
|
|
331
|
+
if (gesture.mode === 'move') {
|
|
332
|
+
const horizontal = event.shiftKey && Math.abs(delta.x) >= Math.abs(delta.y);
|
|
333
|
+
const vertical = event.shiftKey && !horizontal;
|
|
334
|
+
if (horizontal) delta.y = 0;
|
|
335
|
+
if (vertical) delta.x = 0;
|
|
336
|
+
if (visual.snapping && !event.altKey) {
|
|
337
|
+
const snapped = snapMove(
|
|
338
|
+
gesture.bounds,
|
|
339
|
+
delta,
|
|
340
|
+
gesture.candidates,
|
|
341
|
+
6 / gesture.canvas.scale,
|
|
342
|
+
);
|
|
343
|
+
delta = { x: vertical ? 0 : snapped.delta.x, y: horizontal ? 0 : snapped.delta.y };
|
|
344
|
+
nextGuides = snapped.guides.filter(
|
|
345
|
+
(guide) => !(horizontal && guide.axis === 'y') && !(vertical && guide.axis === 'x'),
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
gesture.edits = gesture.snapshots.map((snapshot) => ({
|
|
349
|
+
...snapshot.target,
|
|
350
|
+
ops: moveOps(snapshot, delta, gesture.canvas),
|
|
351
|
+
}));
|
|
352
|
+
} else if (gesture.mode === 'rotate') {
|
|
353
|
+
const center = {
|
|
354
|
+
x: gesture.bounds.x + gesture.bounds.width / 2,
|
|
355
|
+
y: gesture.bounds.y + gesture.bounds.height / 2,
|
|
356
|
+
};
|
|
357
|
+
const startAngle = Math.atan2(gesture.start.y - center.y, gesture.start.x - center.x);
|
|
358
|
+
const angle = Math.atan2(current.y - center.y, current.x - center.x);
|
|
359
|
+
const snapshot = gesture.snapshots[0];
|
|
360
|
+
let rotation = snapshot.rotation + ((angle - startAngle) * 180) / Math.PI;
|
|
361
|
+
if (event.shiftKey) rotation = Math.round(rotation / 15) * 15;
|
|
362
|
+
gesture.edits = [{ ...snapshot.target, ops: [styleOp('rotate', `${round(rotation)}deg`)] }];
|
|
363
|
+
} else {
|
|
364
|
+
const snapshot = gesture.snapshots[0];
|
|
365
|
+
const frame = resizeRect(snapshot.frame, gesture.mode, delta, event.shiftKey);
|
|
366
|
+
gesture.edits = [
|
|
367
|
+
{
|
|
368
|
+
...snapshot.target,
|
|
369
|
+
ops: sizeOps(snapshot, frame, gesture.canvas, {
|
|
370
|
+
x: gesture.mode.includes('w') ? 1 : gesture.mode.includes('e') ? 0 : 0.5,
|
|
371
|
+
y: gesture.mode.includes('n') ? 1 : gesture.mode.includes('s') ? 0 : 0.5,
|
|
372
|
+
}),
|
|
373
|
+
},
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
for (const edit of gesture.edits) previewOps(edit.anchor, edit.ops);
|
|
377
|
+
setGuides(nextGuides);
|
|
378
|
+
measureRef.current?.();
|
|
379
|
+
};
|
|
380
|
+
const onMove = (event: PointerEvent) => {
|
|
381
|
+
if (gestureRef.current) {
|
|
382
|
+
pendingMove = event;
|
|
383
|
+
if (!raf)
|
|
384
|
+
raf = requestAnimationFrame(() => {
|
|
385
|
+
raf = 0;
|
|
386
|
+
if (pendingMove) update(pendingMove);
|
|
387
|
+
pendingMove = null;
|
|
388
|
+
});
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (
|
|
392
|
+
!isInspectableEventTarget(event.target) ||
|
|
393
|
+
inlineEdit?.anchor.contains(event.target as Node)
|
|
394
|
+
) {
|
|
395
|
+
setHover(null);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
setHover(targetAt(event)?.anchor ?? null);
|
|
399
|
+
};
|
|
400
|
+
const onUp = (event: PointerEvent) => {
|
|
401
|
+
const gesture = gestureRef.current;
|
|
402
|
+
if (!gesture || gesture.pointerId !== event.pointerId) return;
|
|
403
|
+
cancelAnimationFrame(raf);
|
|
404
|
+
raf = 0;
|
|
405
|
+
pendingMove = null;
|
|
406
|
+
if (gesture.snapshots.some((snapshot) => !snapshot.target.anchor.isConnected)) {
|
|
407
|
+
clearGesture(true);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
update(event);
|
|
411
|
+
for (const snapshot of gesture.snapshots) restoreTransform(snapshot);
|
|
412
|
+
if (gesture.moved && gesture.edits.length) bufferBatch(gesture.edits);
|
|
413
|
+
setSelection(gesture.moved ? gesture.targets : gesture.clickSelection);
|
|
414
|
+
clearGesture(false);
|
|
415
|
+
};
|
|
416
|
+
const onCancel = (event: Event) => {
|
|
417
|
+
if (event instanceof PointerEvent && event.pointerId !== gestureRef.current?.pointerId)
|
|
418
|
+
return;
|
|
419
|
+
cancelAnimationFrame(raf);
|
|
420
|
+
raf = 0;
|
|
421
|
+
pendingMove = null;
|
|
422
|
+
clearGesture(true);
|
|
423
|
+
};
|
|
424
|
+
const onClick = (event: MouseEvent) => {
|
|
425
|
+
if (suppressClick.current) {
|
|
426
|
+
suppressClick.current = false;
|
|
427
|
+
if (
|
|
428
|
+
isInspectableEventTarget(event.target) ||
|
|
429
|
+
(event.target instanceof Element &&
|
|
430
|
+
event.target.closest('[data-resize-handle], [data-rotate-handle]'))
|
|
431
|
+
) {
|
|
432
|
+
event.preventDefault();
|
|
433
|
+
event.stopImmediatePropagation();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (
|
|
438
|
+
!isInspectableEventTarget(event.target) ||
|
|
439
|
+
inlineEdit?.anchor.contains(event.target as Node)
|
|
440
|
+
)
|
|
441
|
+
return;
|
|
442
|
+
event.preventDefault();
|
|
443
|
+
event.stopPropagation();
|
|
444
|
+
};
|
|
445
|
+
const onDoubleClick = (event: MouseEvent) => {
|
|
446
|
+
if (!isInspectableEventTarget(event.target)) return;
|
|
447
|
+
const element = pickInspectorTarget(pickElement(event.clientX, event.clientY));
|
|
448
|
+
const hit = element ? findSlideSource(element, slideId, { hostOnly: true }) : null;
|
|
449
|
+
if (!(hit?.anchor instanceof HTMLImageElement)) return;
|
|
450
|
+
event.preventDefault();
|
|
451
|
+
event.stopPropagation();
|
|
452
|
+
setSelection([hit]);
|
|
79
453
|
openCrop(hit.anchor);
|
|
80
454
|
};
|
|
81
|
-
|
|
455
|
+
const onKey = (event: KeyboardEvent) => {
|
|
456
|
+
if (
|
|
457
|
+
event.key !== 'Escape' ||
|
|
458
|
+
event.isComposing ||
|
|
459
|
+
event.keyCode === 229 ||
|
|
460
|
+
inlineEdit ||
|
|
461
|
+
isTypingTarget(event.target)
|
|
462
|
+
)
|
|
463
|
+
return;
|
|
464
|
+
if (
|
|
465
|
+
event.target instanceof Element &&
|
|
466
|
+
event.target.closest('[role="dialog"], [role="menu"], [role="listbox"]')
|
|
467
|
+
)
|
|
468
|
+
return;
|
|
469
|
+
event.preventDefault();
|
|
470
|
+
event.stopImmediatePropagation();
|
|
471
|
+
if (gestureRef.current) {
|
|
472
|
+
cancelAnimationFrame(raf);
|
|
473
|
+
raf = 0;
|
|
474
|
+
pendingMove = null;
|
|
475
|
+
clearGesture(true);
|
|
476
|
+
} else if (selection.length) setSelection([]);
|
|
477
|
+
else cancel();
|
|
478
|
+
};
|
|
479
|
+
window.addEventListener('pointerdown', onDown, true);
|
|
82
480
|
window.addEventListener('pointermove', onMove, true);
|
|
481
|
+
window.addEventListener('pointerup', onUp, true);
|
|
482
|
+
window.addEventListener('pointercancel', onCancel, true);
|
|
483
|
+
window.addEventListener('blur', onCancel);
|
|
83
484
|
window.addEventListener('click', onClick, true);
|
|
84
|
-
window.addEventListener('dblclick',
|
|
485
|
+
window.addEventListener('dblclick', onDoubleClick, true);
|
|
85
486
|
window.addEventListener('keydown', onKey, true);
|
|
487
|
+
const overlay = overlayRef.current;
|
|
488
|
+
overlay?.setAttribute('data-inspector-ready', 'true');
|
|
86
489
|
return () => {
|
|
490
|
+
overlay?.removeAttribute('data-inspector-ready');
|
|
491
|
+
cancelAnimationFrame(raf);
|
|
492
|
+
window.removeEventListener('pointerdown', onDown, true);
|
|
87
493
|
window.removeEventListener('pointermove', onMove, true);
|
|
494
|
+
window.removeEventListener('pointerup', onUp, true);
|
|
495
|
+
window.removeEventListener('pointercancel', onCancel, true);
|
|
496
|
+
window.removeEventListener('blur', onCancel);
|
|
88
497
|
window.removeEventListener('click', onClick, true);
|
|
89
|
-
window.removeEventListener('dblclick',
|
|
498
|
+
window.removeEventListener('dblclick', onDoubleClick, true);
|
|
90
499
|
window.removeEventListener('keydown', onKey, true);
|
|
91
500
|
};
|
|
92
|
-
}, [
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
showImageActions
|
|
106
|
-
editing={!!inlineEdit && inlineEdit.anchor === selectedAnchor}
|
|
107
|
-
/>
|
|
108
|
-
<Frame anchor={dedupedHover} overlayRef={overlayRef} variant="hover" />
|
|
109
|
-
</div>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
type FrameVariant = 'selected' | 'hover';
|
|
114
|
-
|
|
115
|
-
const FRAME_STYLES: Record<FrameVariant, React.CSSProperties> = {
|
|
116
|
-
selected: { outline: '2px solid #3b82f6', background: 'rgba(59,130,246,0.1)' },
|
|
117
|
-
hover: { outline: '1.5px dashed #3b82f6', background: 'rgba(59,130,246,0.05)' },
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
function Frame({
|
|
121
|
-
anchor,
|
|
122
|
-
overlayRef,
|
|
123
|
-
variant,
|
|
124
|
-
showImageActions = false,
|
|
125
|
-
editing = false,
|
|
126
|
-
}: {
|
|
127
|
-
anchor: HTMLElement | null;
|
|
128
|
-
overlayRef: React.RefObject<HTMLDivElement | null>;
|
|
129
|
-
variant: FrameVariant;
|
|
130
|
-
showImageActions?: boolean;
|
|
131
|
-
editing?: boolean;
|
|
132
|
-
}) {
|
|
133
|
-
const [rect, setRect] = useState<RelRect | null>(null);
|
|
134
|
-
const [hasTarget, setHasTarget] = useState(false);
|
|
135
|
-
|
|
136
|
-
const measure = useCallback(() => {
|
|
137
|
-
const overlay = overlayRef.current;
|
|
138
|
-
if (!anchor?.isConnected || !overlay) {
|
|
139
|
-
setHasTarget(false);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const targetRect = anchor.getBoundingClientRect();
|
|
144
|
-
const overlayRect = overlay.getBoundingClientRect();
|
|
145
|
-
const next = {
|
|
146
|
-
left: targetRect.left - overlayRect.left,
|
|
147
|
-
top: targetRect.top - overlayRect.top,
|
|
148
|
-
width: targetRect.width,
|
|
149
|
-
height: targetRect.height,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
setHasTarget(true);
|
|
153
|
-
setRect((prev) => (sameRect(prev, next) ? prev : next));
|
|
154
|
-
}, [overlayRef, anchor]);
|
|
155
|
-
|
|
156
|
-
useLayoutEffect(() => {
|
|
157
|
-
measure();
|
|
158
|
-
}, [measure]);
|
|
501
|
+
}, [
|
|
502
|
+
active,
|
|
503
|
+
selection,
|
|
504
|
+
selected,
|
|
505
|
+
slideId,
|
|
506
|
+
setSelection,
|
|
507
|
+
inlineEdit,
|
|
508
|
+
committing,
|
|
509
|
+
bufferBatch,
|
|
510
|
+
visual.snapping,
|
|
511
|
+
cancel,
|
|
512
|
+
openCrop,
|
|
513
|
+
]);
|
|
159
514
|
|
|
160
515
|
useEffect(() => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
let tracking = 0;
|
|
168
|
-
const scheduleMeasure = () => {
|
|
169
|
-
cancelAnimationFrame(scheduled);
|
|
170
|
-
scheduled = requestAnimationFrame(measure);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const resizeObserver = new ResizeObserver(scheduleMeasure);
|
|
174
|
-
const root = document.querySelector<HTMLElement>('[data-inspector-root]');
|
|
175
|
-
if (root) resizeObserver.observe(root);
|
|
176
|
-
if (overlayRef.current) resizeObserver.observe(overlayRef.current);
|
|
177
|
-
resizeObserver.observe(anchor);
|
|
178
|
-
|
|
179
|
-
const stopAt = performance.now() + LAYOUT_TRACK_MS;
|
|
180
|
-
const trackPanelTransition = () => {
|
|
181
|
-
measure();
|
|
182
|
-
if (performance.now() < stopAt) tracking = requestAnimationFrame(trackPanelTransition);
|
|
183
|
-
};
|
|
184
|
-
tracking = requestAnimationFrame(trackPanelTransition);
|
|
185
|
-
|
|
186
|
-
window.addEventListener('resize', scheduleMeasure, true);
|
|
187
|
-
window.addEventListener('scroll', scheduleMeasure, true);
|
|
188
|
-
return () => {
|
|
189
|
-
resizeObserver.disconnect();
|
|
190
|
-
cancelAnimationFrame(scheduled);
|
|
191
|
-
cancelAnimationFrame(tracking);
|
|
192
|
-
window.removeEventListener('resize', scheduleMeasure, true);
|
|
193
|
-
window.removeEventListener('scroll', scheduleMeasure, true);
|
|
516
|
+
const reset = () => {
|
|
517
|
+
for (const snapshot of gestureRef.current?.snapshots ?? []) restoreTransform(snapshot);
|
|
518
|
+
if (gestureRef.current) delete gestureRef.current.canvas.root.dataset.visualGesture;
|
|
519
|
+
gestureRef.current = null;
|
|
520
|
+
document.documentElement.style.removeProperty('cursor');
|
|
521
|
+
document.documentElement.style.removeProperty('--osd-gesture-cursor');
|
|
194
522
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const [morph, setMorph] = useState(false);
|
|
202
|
-
useLayoutEffect(() => {
|
|
203
|
-
if (visible) {
|
|
204
|
-
setMorph(true);
|
|
205
|
-
return;
|
|
523
|
+
if (!active) {
|
|
524
|
+
reset();
|
|
525
|
+
setLocalTargets(null);
|
|
526
|
+
setGuides([]);
|
|
527
|
+
setMarquee(null);
|
|
528
|
+
setHover(null);
|
|
206
529
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}, [visible]);
|
|
530
|
+
return reset;
|
|
531
|
+
}, [active]);
|
|
210
532
|
|
|
211
|
-
if (!
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const imageAnchor = anchor instanceof HTMLImageElement ? anchor : null;
|
|
220
|
-
const actionsVisible = showImageActions && visible && !!imageAnchor;
|
|
221
|
-
|
|
222
|
-
// While a text run is being edited inline, drop the tint so the text
|
|
223
|
-
// underneath stays fully readable.
|
|
224
|
-
const frameStyle = editing
|
|
225
|
-
? { ...FRAME_STYLES[variant], background: 'transparent' }
|
|
226
|
-
: FRAME_STYLES[variant];
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<>
|
|
230
|
-
<div
|
|
231
|
-
className="absolute"
|
|
232
|
-
style={{
|
|
233
|
-
left: rect.left,
|
|
234
|
-
top: rect.top,
|
|
235
|
-
width: rect.width,
|
|
236
|
-
height: rect.height,
|
|
237
|
-
opacity: visible ? 1 : 0,
|
|
238
|
-
transition,
|
|
239
|
-
...frameStyle,
|
|
240
|
-
}}
|
|
241
|
-
/>
|
|
242
|
-
{showImageActions && imageAnchor && (
|
|
243
|
-
<ImageActionPanel
|
|
244
|
-
anchor={imageAnchor}
|
|
245
|
-
rect={rect}
|
|
246
|
-
visible={actionsVisible}
|
|
247
|
-
transition={transition}
|
|
248
|
-
/>
|
|
249
|
-
)}
|
|
250
|
-
</>
|
|
533
|
+
if (!active) return null;
|
|
534
|
+
const bounds = unionRects(
|
|
535
|
+
frames.map((frame) => ({
|
|
536
|
+
x: frame.left,
|
|
537
|
+
y: frame.top,
|
|
538
|
+
width: frame.width,
|
|
539
|
+
height: frame.height,
|
|
540
|
+
})),
|
|
251
541
|
);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
anchor
|
|
258
|
-
rect
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
visible: boolean;
|
|
265
|
-
transition: string;
|
|
266
|
-
}) {
|
|
267
|
-
const { openCrop, openReplace } = useInspector();
|
|
268
|
-
const t = useLocale();
|
|
542
|
+
const canvas = readCanvas();
|
|
543
|
+
const transformable =
|
|
544
|
+
!!canvas && displayed.length > 0 && displayed.every((target) => canTransform(target, canvas));
|
|
545
|
+
const editing = !!inlineEdit;
|
|
546
|
+
const single = displayed.length === 1;
|
|
547
|
+
const imageAnchor = selected?.anchor instanceof HTMLImageElement ? selected.anchor : null;
|
|
548
|
+
const toScreen = (rect: Rect) => ({
|
|
549
|
+
left: (canvasFrame?.left ?? 0) + rect.x * scale,
|
|
550
|
+
top: (canvasFrame?.top ?? 0) + rect.y * scale,
|
|
551
|
+
width: rect.width * scale,
|
|
552
|
+
height: rect.height * scale,
|
|
553
|
+
});
|
|
269
554
|
return (
|
|
270
|
-
<
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
style={
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
e.stopPropagation();
|
|
292
|
-
openReplace(anchor);
|
|
293
|
-
}}
|
|
294
|
-
className="inline-flex size-7 items-center justify-center rounded-[5px] text-foreground/85 transition-[background-color,color,scale] duration-150 hover:bg-muted hover:text-foreground active:scale-[0.94] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
295
|
-
>
|
|
296
|
-
<ImageIcon className="size-3.5" />
|
|
297
|
-
</button>
|
|
298
|
-
}
|
|
299
|
-
/>
|
|
300
|
-
<TooltipContent side="bottom" data-inspector-ui>
|
|
301
|
-
{t.inspector.replace}
|
|
302
|
-
</TooltipContent>
|
|
303
|
-
</Tooltip>
|
|
304
|
-
<Tooltip>
|
|
305
|
-
<TooltipTrigger
|
|
306
|
-
render={
|
|
555
|
+
<div
|
|
556
|
+
ref={overlayRef}
|
|
557
|
+
data-inspector-ui
|
|
558
|
+
className="pointer-events-none absolute inset-0 z-30 select-none"
|
|
559
|
+
>
|
|
560
|
+
{hoverFrame && !gestureRef.current && (
|
|
561
|
+
<div className="absolute border border-dashed border-blue-500/70" style={hoverFrame} />
|
|
562
|
+
)}
|
|
563
|
+
{frames.length > 1 &&
|
|
564
|
+
frames.map(({ id, ...frame }) => (
|
|
565
|
+
<div key={id} className="absolute border border-blue-500/60" style={frame} />
|
|
566
|
+
))}
|
|
567
|
+
{bounds && (
|
|
568
|
+
<div
|
|
569
|
+
data-selection-frame="true"
|
|
570
|
+
className="absolute border border-blue-500"
|
|
571
|
+
style={{ left: bounds.x, top: bounds.y, width: bounds.width, height: bounds.height }}
|
|
572
|
+
>
|
|
573
|
+
{!editing && transformable && single && !committing && (
|
|
574
|
+
<>
|
|
575
|
+
<div className="absolute -top-6 left-1/2 h-6 w-px bg-blue-500" />
|
|
307
576
|
<button
|
|
308
577
|
type="button"
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
578
|
+
data-rotate-handle
|
|
579
|
+
aria-label={t.inspector.rotateHandle}
|
|
580
|
+
className="pointer-events-auto absolute -top-7 left-1/2 size-3 -translate-x-1/2 cursor-crosshair rounded-full border border-blue-500 bg-background shadow-sm focus-visible:outline-2 focus-visible:outline-blue-600"
|
|
581
|
+
/>
|
|
582
|
+
{HANDLES.map(({ handle, x, y, cursor }) => (
|
|
583
|
+
<button
|
|
584
|
+
key={handle}
|
|
585
|
+
type="button"
|
|
586
|
+
data-resize-handle={handle}
|
|
587
|
+
aria-label={format(t.inspector.resizeHandle, { handle })}
|
|
588
|
+
className="pointer-events-auto absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-[2px] border border-blue-500 bg-background shadow-sm focus-visible:outline-2 focus-visible:outline-blue-600"
|
|
589
|
+
style={{ left: `${x * 100}%`, top: `${y * 100}%`, cursor, touchAction: 'none' }}
|
|
590
|
+
/>
|
|
591
|
+
))}
|
|
592
|
+
</>
|
|
593
|
+
)}
|
|
594
|
+
{gestureRef.current?.moved && (
|
|
595
|
+
<span className="absolute -bottom-7 left-1/2 -translate-x-1/2 whitespace-nowrap rounded bg-foreground px-2 py-1 font-mono text-[10px] text-background">
|
|
596
|
+
{round(bounds.width / scale)} × {round(bounds.height / scale)}
|
|
597
|
+
</span>
|
|
598
|
+
)}
|
|
599
|
+
</div>
|
|
600
|
+
)}
|
|
601
|
+
{canvasFrame &&
|
|
602
|
+
guides.map((guide) => (
|
|
603
|
+
<div
|
|
604
|
+
key={`${guide.axis}:${guide.position}`}
|
|
605
|
+
data-alignment-guide={guide.axis}
|
|
606
|
+
className="absolute bg-cyan-500"
|
|
607
|
+
style={
|
|
608
|
+
guide.axis === 'x'
|
|
609
|
+
? {
|
|
610
|
+
left: canvasFrame.left + guide.position * scale,
|
|
611
|
+
top: canvasFrame.top + guide.start * scale,
|
|
612
|
+
width: 1,
|
|
613
|
+
height: (guide.end - guide.start) * scale,
|
|
614
|
+
}
|
|
615
|
+
: {
|
|
616
|
+
left: canvasFrame.left + guide.start * scale,
|
|
617
|
+
top: canvasFrame.top + guide.position * scale,
|
|
618
|
+
width: (guide.end - guide.start) * scale,
|
|
619
|
+
height: 1,
|
|
620
|
+
}
|
|
318
621
|
}
|
|
319
622
|
/>
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
623
|
+
))}
|
|
624
|
+
{marquee && (
|
|
625
|
+
<div className="absolute border border-blue-500 bg-blue-500/10" style={toScreen(marquee)} />
|
|
626
|
+
)}
|
|
627
|
+
{imageAnchor && single && bounds && !gestureRef.current && (
|
|
628
|
+
<div
|
|
629
|
+
className="pointer-events-auto absolute flex gap-1 rounded-md border bg-popover p-1 shadow-floating"
|
|
630
|
+
style={{
|
|
631
|
+
left: bounds.x + bounds.width / 2,
|
|
632
|
+
top: bounds.y + bounds.height + 10,
|
|
633
|
+
transform: 'translateX(-50%)',
|
|
634
|
+
}}
|
|
635
|
+
>
|
|
636
|
+
<button
|
|
637
|
+
type="button"
|
|
638
|
+
aria-label={t.inspector.replace}
|
|
639
|
+
title={t.inspector.replace}
|
|
640
|
+
onClick={() => openReplace(imageAnchor)}
|
|
641
|
+
className="flex size-7 items-center justify-center rounded hover:bg-muted focus-visible:outline-2"
|
|
642
|
+
>
|
|
643
|
+
<ImageIcon className="size-3.5" />
|
|
644
|
+
</button>
|
|
645
|
+
<button
|
|
646
|
+
type="button"
|
|
647
|
+
aria-label={t.inspector.crop}
|
|
648
|
+
title={t.inspector.crop}
|
|
649
|
+
onClick={() => openCrop(imageAnchor)}
|
|
650
|
+
className="flex size-7 items-center justify-center rounded hover:bg-muted focus-visible:outline-2"
|
|
651
|
+
>
|
|
652
|
+
<Crop className="size-3.5" />
|
|
653
|
+
</button>
|
|
654
|
+
</div>
|
|
655
|
+
)}
|
|
656
|
+
</div>
|
|
326
657
|
);
|
|
327
658
|
}
|
|
328
659
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
660
|
+
const EDITING_FREEZE_CSS = `
|
|
661
|
+
[data-inspector-editing] { touch-action: none; }
|
|
662
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *),
|
|
663
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::before,
|
|
664
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::after {
|
|
665
|
+
animation-duration: 1ms !important;
|
|
666
|
+
animation-delay: 0s !important;
|
|
667
|
+
animation-iteration-count: 1 !important;
|
|
668
|
+
animation-fill-mode: forwards !important;
|
|
669
|
+
transition: none !important;
|
|
670
|
+
view-transition-name: none !important;
|
|
671
|
+
user-select: none;
|
|
672
|
+
}
|
|
673
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *),
|
|
674
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::before,
|
|
675
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::after {
|
|
676
|
+
cursor: default !important;
|
|
677
|
+
}
|
|
678
|
+
[data-inspector-editing] [data-visual-gesture],
|
|
679
|
+
[data-inspector-editing] [data-visual-gesture] *,
|
|
680
|
+
[data-inspector-editing] [data-visual-gesture] *::before,
|
|
681
|
+
[data-inspector-editing] [data-visual-gesture] *::after {
|
|
682
|
+
cursor: var(--osd-gesture-cursor, default) !important;
|
|
337
683
|
}
|
|
684
|
+
`;
|