@r2digisolutions/components 0.23.1 → 0.24.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/dist/components/atoms/BrandMark/BrandMark.svelte +47 -7
- package/dist/components/atoms/BrandMark/BrandMark.svelte.d.ts +4 -0
- package/dist/components/atoms/Slider/Slider.svelte +19 -15
- package/dist/components/atoms/Slider/Slider.svelte.d.ts +2 -0
- package/dist/components/molecules/AuthCard/AuthCard.svelte +19 -4
- package/dist/components/molecules/AuthCard/AuthCard.svelte.d.ts +4 -0
- package/dist/components/molecules/CanvasElementsPanel/CanvasElementsPanel.svelte +90 -26
- package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +176 -5
- package/dist/components/molecules/Combobox/Combobox.svelte +2 -2
- package/dist/components/molecules/DateTimePicker/DateTimePicker.svelte +121 -33
- package/dist/components/molecules/FormSection/FormSection.svelte +25 -28
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte +183 -0
- package/dist/components/molecules/ImageEditor/ImageEditor.svelte.d.ts +19 -0
- package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +58 -35
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +293 -39
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +6 -1
- package/dist/components/molecules/MediaStage/MediaStage.svelte +302 -245
- package/dist/components/molecules/MentionInput/MentionInput.svelte +332 -120
- package/dist/components/molecules/MentionInput/MentionInput.svelte.d.ts +13 -2
- package/dist/components/molecules/Select/Select.svelte +14 -1
- package/dist/components/molecules/Select/Select.svelte.d.ts +3 -0
- package/dist/components/molecules/UserMenu/UserMenu.svelte +30 -27
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +200 -17
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +14 -0
- package/dist/components/organisms/AppShell/AppShell.svelte +7 -1
- package/dist/components/organisms/AppShell/AppShell.svelte.d.ts +2 -0
- package/dist/components/organisms/AuthShell/AuthShell.svelte +61 -29
- package/dist/components/organisms/AuthShell/AuthShell.svelte.d.ts +4 -0
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +156 -7
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +5 -0
- package/dist/components/organisms/Navbar/Navbar.svelte +2 -2
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte +314 -141
- package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte.d.ts +20 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/styles.css +17 -0
- package/dist/utils/canvasDocument.d.ts +56 -4
- package/dist/utils/canvasDocument.js +91 -2
- package/dist/utils/canvasExport.d.ts +1 -1
- package/dist/utils/canvasExport.js +15 -25
- package/package.json +1 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import WidgetFrame from '../WidgetFrame/WidgetFrame.svelte';
|
|
3
3
|
import MediaKindIcon from '../../atoms/MediaKindIcon/MediaKindIcon.svelte';
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
canvasLayerFilter,
|
|
6
|
+
mediaContentBox,
|
|
7
|
+
type CanvasLayer,
|
|
8
|
+
type CanvasLayerRect
|
|
9
|
+
} from '../../../utils/canvasDocument.js';
|
|
5
10
|
import type { WidgetRect } from '../WidgetCanvas/widgetCanvasContext.js';
|
|
6
11
|
import { isContainerKind } from '../../../utils/canvasHierarchy.js';
|
|
7
12
|
import { CANVAS_SVG_SHAPES } from '../../../utils/canvasShapes.js';
|
|
@@ -37,6 +42,18 @@
|
|
|
37
42
|
onclick?: (e: MouseEvent) => void;
|
|
38
43
|
ondblclick?: (e: MouseEvent) => void;
|
|
39
44
|
onchange?: (rect: WidgetRect) => void;
|
|
45
|
+
/** Zoom and pan inside an image, or grow a text box so the type stays inside. */
|
|
46
|
+
onpatch?: (
|
|
47
|
+
partial: Partial<
|
|
48
|
+
Pick<
|
|
49
|
+
CanvasLayer,
|
|
50
|
+
'mediaScale' | 'mediaX' | 'mediaY' | 'rect' | 'fontSize' | 'rotation' | 'textMaxWidth'
|
|
51
|
+
>
|
|
52
|
+
>
|
|
53
|
+
) => void;
|
|
54
|
+
/** Double-click turned this text or note into an editor. */
|
|
55
|
+
editing?: boolean;
|
|
56
|
+
ontextcommit?: (text: string) => void;
|
|
40
57
|
/** True while this frame is being dragged/resized. */
|
|
41
58
|
oninteract?: (active: boolean) => void;
|
|
42
59
|
/**
|
|
@@ -63,6 +80,9 @@
|
|
|
63
80
|
onclick,
|
|
64
81
|
ondblclick,
|
|
65
82
|
onchange,
|
|
83
|
+
onpatch,
|
|
84
|
+
editing = false,
|
|
85
|
+
ontextcommit,
|
|
66
86
|
oninteract,
|
|
67
87
|
followStageRect = false
|
|
68
88
|
}: MediaLayerItemProps = $props();
|
|
@@ -72,6 +92,179 @@
|
|
|
72
92
|
const noResize = $derived(layoutSizeLocked || layoutLocked);
|
|
73
93
|
let rect = $state<WidgetRect>({ x: 0, y: 0, w: 100, h: 100 });
|
|
74
94
|
let interacting = $state(false);
|
|
95
|
+
let mediaBox = $state<HTMLDivElement | null>(null);
|
|
96
|
+
let textEl = $state<HTMLDivElement | null>(null);
|
|
97
|
+
let naturalW = $state(0);
|
|
98
|
+
let naturalH = $state(0);
|
|
99
|
+
let mediaGesture = $state(false);
|
|
100
|
+
let mediaLive = $state<{ x: number; y: number; scale: number } | null>(null);
|
|
101
|
+
let textFocused = false;
|
|
102
|
+
let resizeEdge: string | null = null;
|
|
103
|
+
let panOrigin = { x: 0, y: 0, mediaX: 0.5, mediaY: 0.5 };
|
|
104
|
+
|
|
105
|
+
const mediaScale = $derived(mediaLive?.scale ?? layer.mediaScale ?? 1);
|
|
106
|
+
const mediaX = $derived(mediaLive?.x ?? layer.mediaX ?? 0.5);
|
|
107
|
+
const mediaY = $derived(mediaLive?.y ?? layer.mediaY ?? 0.5);
|
|
108
|
+
const placed = $derived(
|
|
109
|
+
mediaContentBox(
|
|
110
|
+
{ w: Math.max(pos.w, 1), h: Math.max(pos.h, 1) },
|
|
111
|
+
{ w: naturalW, h: naturalH },
|
|
112
|
+
layer.objectFit,
|
|
113
|
+
mediaScale,
|
|
114
|
+
mediaX,
|
|
115
|
+
mediaY
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
function clamp01(n: number) {
|
|
120
|
+
return Math.min(1, Math.max(0, n));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function onMediaLoad(e: Event) {
|
|
124
|
+
const img = e.currentTarget as HTMLImageElement;
|
|
125
|
+
if (!img.naturalWidth) return;
|
|
126
|
+
naturalW = img.naturalWidth;
|
|
127
|
+
naturalH = img.naturalHeight;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function currentMedia() {
|
|
131
|
+
return {
|
|
132
|
+
x: mediaLive?.x ?? layer.mediaX ?? 0.5,
|
|
133
|
+
y: mediaLive?.y ?? layer.mediaY ?? 0.5,
|
|
134
|
+
scale: mediaLive?.scale ?? layer.mediaScale ?? 1
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function beginMediaPan(e: PointerEvent) {
|
|
139
|
+
if (e.button !== 0) return;
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
|
143
|
+
mediaGesture = true;
|
|
144
|
+
const cur = currentMedia();
|
|
145
|
+
panOrigin = { x: e.clientX, y: e.clientY, mediaX: cur.x, mediaY: cur.y };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function moveMediaPan(e: PointerEvent) {
|
|
149
|
+
if (!mediaGesture || !mediaBox) return;
|
|
150
|
+
const box = mediaBox.getBoundingClientRect();
|
|
151
|
+
if (box.width < 1 || box.height < 1) return;
|
|
152
|
+
const docDx = ((e.clientX - panOrigin.x) / box.width) * Math.max(pos.w, 1);
|
|
153
|
+
const docDy = ((e.clientY - panOrigin.y) / box.height) * Math.max(pos.h, 1);
|
|
154
|
+
const base = mediaContentBox(
|
|
155
|
+
{ w: Math.max(pos.w, 1), h: Math.max(pos.h, 1) },
|
|
156
|
+
{ w: naturalW, h: naturalH },
|
|
157
|
+
layer.objectFit,
|
|
158
|
+
currentMedia().scale,
|
|
159
|
+
0,
|
|
160
|
+
0
|
|
161
|
+
);
|
|
162
|
+
const spanX = pos.w - base.w;
|
|
163
|
+
const spanY = pos.h - base.h;
|
|
164
|
+
mediaLive = {
|
|
165
|
+
x: Math.abs(spanX) > 0.5 ? clamp01(panOrigin.mediaX + docDx / spanX) : panOrigin.mediaX,
|
|
166
|
+
y: Math.abs(spanY) > 0.5 ? clamp01(panOrigin.mediaY + docDy / spanY) : panOrigin.mediaY,
|
|
167
|
+
scale: currentMedia().scale
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function endMediaPan() {
|
|
172
|
+
if (!mediaGesture) return;
|
|
173
|
+
mediaGesture = false;
|
|
174
|
+
const cur = currentMedia();
|
|
175
|
+
onpatch?.({ mediaX: cur.x, mediaY: cur.y, mediaScale: cur.scale });
|
|
176
|
+
mediaLive = null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function readEditableText(el: HTMLElement) {
|
|
180
|
+
return (el.innerText ?? '').replace(/\n$/, '');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function zoomMedia(e: WheelEvent) {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
e.stopPropagation();
|
|
186
|
+
const fit = layer.objectFit ?? 'cover';
|
|
187
|
+
const min = fit === 'cover' ? 1 : 0.25;
|
|
188
|
+
const cur = currentMedia();
|
|
189
|
+
const factor = e.deltaY < 0 ? 1.08 : 1 / 1.08;
|
|
190
|
+
const scale = Math.min(6, Math.max(min, cur.scale * factor));
|
|
191
|
+
mediaLive = { x: cur.x, y: cur.y, scale };
|
|
192
|
+
onpatch?.({ mediaX: cur.x, mediaY: cur.y, mediaScale: scale });
|
|
193
|
+
if (!mediaGesture) mediaLive = null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const textAuto = $derived(
|
|
197
|
+
(layer.kind === 'text' || layer.kind === 'sticky') && (layer.autoSize ?? layer.kind === 'text')
|
|
198
|
+
);
|
|
199
|
+
/** Canva: los laterales cambian el ancho; las esquinas escalan la letra. Arriba/abajo no existe. */
|
|
200
|
+
const TEXT_RESIZE_EDGES = ['e', 'w', 'ne', 'nw', 'se', 'sw'] as const;
|
|
201
|
+
const isCornerEdge = (edge: string | null) =>
|
|
202
|
+
edge === 'ne' || edge === 'nw' || edge === 'se' || edge === 'sw';
|
|
203
|
+
let textResizeStart: { fontSize: number; w: number } | null = null;
|
|
204
|
+
|
|
205
|
+
function onFrameInteract(active: boolean) {
|
|
206
|
+
if (active) {
|
|
207
|
+
interacting = true;
|
|
208
|
+
if (resizeEdge && textAuto) {
|
|
209
|
+
textResizeStart = {
|
|
210
|
+
fontSize: layer.fontSize ?? (layer.kind === 'sticky' ? 20 : 32),
|
|
211
|
+
w: Math.max(1, pos.w)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
oninteract?.(true);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const edge = resizeEdge;
|
|
218
|
+
resizeEdge = null;
|
|
219
|
+
textResizeStart = null;
|
|
220
|
+
if (edge && textAuto) {
|
|
221
|
+
const scaleX = pos.w > 0 ? layer.rect.w / pos.w : 1;
|
|
222
|
+
onpatch?.({ textMaxWidth: Math.max(8, rect.w * scaleX) });
|
|
223
|
+
}
|
|
224
|
+
interacting = false;
|
|
225
|
+
oninteract?.(false);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Esquina en texto: la letra sigue al ancho, igual que Canva. Los laterales no tocan la letra. */
|
|
229
|
+
function onFrameRect(r: WidgetRect) {
|
|
230
|
+
if (!followStageRect) rect = r;
|
|
231
|
+
onchange?.(r);
|
|
232
|
+
if (!textAuto || !textResizeStart || !isCornerEdge(resizeEdge)) return;
|
|
233
|
+
const ratio = r.w / textResizeStart.w;
|
|
234
|
+
if (!Number.isFinite(ratio) || ratio <= 0) return;
|
|
235
|
+
const fontSize = Math.max(8, Math.min(400, Math.round(textResizeStart.fontSize * ratio)));
|
|
236
|
+
if (fontSize !== (layer.fontSize ?? (layer.kind === 'sticky' ? 20 : 32))) {
|
|
237
|
+
onpatch?.({ fontSize });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function onTextBoxResize(next: { x: number; y: number; w: number; h: number }) {
|
|
242
|
+
if (!textAuto || readOnly) return;
|
|
243
|
+
const scaleX = pos.w > 0 ? layer.rect.w / pos.w : 1;
|
|
244
|
+
const scaleY = pos.h > 0 ? layer.rect.h / pos.h : 1;
|
|
245
|
+
const w = next.w * scaleX;
|
|
246
|
+
const h = next.h * scaleY;
|
|
247
|
+
if (Math.abs(w - layer.rect.w) <= 1 && Math.abs(h - layer.rect.h) <= 1) return;
|
|
248
|
+
onpatch?.({ rect: { ...layer.rect, w, h } });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
$effect(() => {
|
|
252
|
+
if (!editing) {
|
|
253
|
+
textFocused = false;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!textEl || textFocused) return;
|
|
257
|
+
textFocused = true;
|
|
258
|
+
const el = textEl;
|
|
259
|
+
el.focus();
|
|
260
|
+
const raw = (el.innerText ?? '').replace(/\n$/, '').trim();
|
|
261
|
+
if (!raw) return;
|
|
262
|
+
const range = document.createRange();
|
|
263
|
+
range.selectNodeContents(el);
|
|
264
|
+
const sel = window.getSelection();
|
|
265
|
+
sel?.removeAllRanges();
|
|
266
|
+
sel?.addRange(range);
|
|
267
|
+
});
|
|
75
268
|
|
|
76
269
|
$effect(() => {
|
|
77
270
|
// Single-item drag/resize: WidgetFrame owns the live rect.
|
|
@@ -80,13 +273,9 @@
|
|
|
80
273
|
rect = { x: pos.x, y: pos.y, w: pos.w, h: pos.h };
|
|
81
274
|
});
|
|
82
275
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
: layer.objectFit === 'fill'
|
|
87
|
-
? 'object-fill'
|
|
88
|
-
: 'object-cover'
|
|
89
|
-
);
|
|
276
|
+
const cssFit = $derived(layer.objectFit ?? 'cover');
|
|
277
|
+
/** Zoomed bitmaps use the measured box. Scale 1 is plain object-fit, same as before. */
|
|
278
|
+
const zoomedMedia = $derived(Math.abs(mediaScale - 1) > 0.001);
|
|
90
279
|
|
|
91
280
|
const contentTransform = $derived.by(() => {
|
|
92
281
|
const parts: string[] = [];
|
|
@@ -95,11 +284,7 @@
|
|
|
95
284
|
return parts.length ? parts.join(' ') : undefined;
|
|
96
285
|
});
|
|
97
286
|
|
|
98
|
-
const filter = $derived
|
|
99
|
-
const parts: string[] = [];
|
|
100
|
-
if (layer.blur) parts.push(`blur(${layer.blur}px)`);
|
|
101
|
-
return parts.length ? parts.join(' ') : undefined;
|
|
102
|
-
});
|
|
287
|
+
const filter = $derived(canvasLayerFilter(layer));
|
|
103
288
|
|
|
104
289
|
const boxShadow = $derived(
|
|
105
290
|
layer.shadowBlur
|
|
@@ -114,7 +299,7 @@
|
|
|
114
299
|
!!layer.clipChildren ||
|
|
115
300
|
layer.kind === 'image' ||
|
|
116
301
|
layer.kind === 'video' ||
|
|
117
|
-
layer.kind === 'sticky' ||
|
|
302
|
+
((layer.kind === 'text' || layer.kind === 'sticky') && !textAuto) ||
|
|
118
303
|
layer.kind === 'border' ||
|
|
119
304
|
layer.kind === 'canvasPanel' ||
|
|
120
305
|
layer.kind === 'overlay' ||
|
|
@@ -128,6 +313,7 @@
|
|
|
128
313
|
|
|
129
314
|
{#if layer.visible}
|
|
130
315
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
316
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
131
317
|
<div
|
|
132
318
|
class={['contents', className]}
|
|
133
319
|
data-layer-item
|
|
@@ -147,28 +333,42 @@
|
|
|
147
333
|
freeform
|
|
148
334
|
showChrome={false}
|
|
149
335
|
flush
|
|
336
|
+
clipContent={layer.kind === 'text' || layer.kind === 'sticky' ? !textAuto : true}
|
|
150
337
|
handleStyle="canva"
|
|
338
|
+
hugContent={textAuto}
|
|
339
|
+
hugMaxWidth={layer.textMaxWidth ?? 0}
|
|
340
|
+
resizeEdges={textAuto ? [...TEXT_RESIZE_EDGES] : undefined}
|
|
341
|
+
oncontentresize={onTextBoxResize}
|
|
151
342
|
handlesVisible={handlesOn}
|
|
152
343
|
raiseOnSelect={false}
|
|
153
344
|
stackIndex={stackIndex ?? layer.zIndex}
|
|
154
345
|
transform={paintTransform}
|
|
346
|
+
rotation={layer.rotation ?? 0}
|
|
347
|
+
onrotation={(deg) => onpatch?.({ rotation: deg })}
|
|
155
348
|
draggable={!layer.locked && !readOnly && !noDrag}
|
|
156
349
|
resizable={!layer.locked && !readOnly && !noResize && handlesOn}
|
|
157
350
|
bind:rect
|
|
158
351
|
applyRect={!followStageRect}
|
|
159
|
-
minW={layer.kind === 'line' || layer.kind === 'arrow' || layer.kind === 'path'
|
|
160
|
-
|
|
352
|
+
minW={layer.kind === 'line' || layer.kind === 'arrow' || layer.kind === 'path'
|
|
353
|
+
? 16
|
|
354
|
+
: layer.kind === 'text' || layer.kind === 'sticky'
|
|
355
|
+
? 8
|
|
356
|
+
: 40}
|
|
357
|
+
minH={layer.kind === 'line'
|
|
358
|
+
? 4
|
|
359
|
+
: layer.kind === 'text' || layer.kind === 'sticky'
|
|
360
|
+
? 8
|
|
361
|
+
: layer.kind === 'arrow' || layer.kind === 'path'
|
|
362
|
+
? 16
|
|
363
|
+
: 24}
|
|
364
|
+
onresizestart={(_e, edge) => {
|
|
365
|
+
resizeEdge = edge;
|
|
366
|
+
}}
|
|
161
367
|
class={['bg-transparent', passthrough || readOnly ? 'pointer-events-none' : '']
|
|
162
368
|
.filter(Boolean)
|
|
163
369
|
.join(' ')}
|
|
164
|
-
onchange={
|
|
165
|
-
|
|
166
|
-
onchange?.(r);
|
|
167
|
-
}}
|
|
168
|
-
oninteract={(active) => {
|
|
169
|
-
interacting = active;
|
|
170
|
-
oninteract?.(active);
|
|
171
|
-
}}
|
|
370
|
+
onchange={onFrameRect}
|
|
371
|
+
oninteract={onFrameInteract}
|
|
172
372
|
>
|
|
173
373
|
<div
|
|
174
374
|
class="h-full w-full"
|
|
@@ -181,17 +381,59 @@
|
|
|
181
381
|
style:clip-path={clipPath}
|
|
182
382
|
>
|
|
183
383
|
{#if layer.kind === 'image' && layer.src}
|
|
184
|
-
<
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
384
|
+
<div class="relative h-full w-full" bind:this={mediaBox}>
|
|
385
|
+
{#if zoomedMedia && naturalW > 0}
|
|
386
|
+
<img
|
|
387
|
+
src={layer.src}
|
|
388
|
+
alt={layer.name}
|
|
389
|
+
class="absolute max-w-none"
|
|
390
|
+
draggable="false"
|
|
391
|
+
style:width="{(placed.w / Math.max(pos.w, 1)) * 100}%"
|
|
392
|
+
style:height="{(placed.h / Math.max(pos.h, 1)) * 100}%"
|
|
393
|
+
style:left="{(placed.x / Math.max(pos.w, 1)) * 100}%"
|
|
394
|
+
style:top="{(placed.y / Math.max(pos.h, 1)) * 100}%"
|
|
395
|
+
onload={onMediaLoad}
|
|
396
|
+
/>
|
|
397
|
+
{:else}
|
|
398
|
+
<img
|
|
399
|
+
src={layer.src}
|
|
400
|
+
alt={layer.name}
|
|
401
|
+
class="h-full w-full"
|
|
402
|
+
draggable="false"
|
|
403
|
+
style:object-fit={cssFit}
|
|
404
|
+
style:object-position="{mediaX * 100}% {mediaY * 100}%"
|
|
405
|
+
onload={onMediaLoad}
|
|
406
|
+
/>
|
|
407
|
+
{/if}
|
|
408
|
+
{#if selected && !readOnly && !passthrough}
|
|
409
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
410
|
+
<div
|
|
411
|
+
class="absolute cursor-grab active:cursor-grabbing"
|
|
412
|
+
style="inset: 12px"
|
|
413
|
+
onpointerdown={beginMediaPan}
|
|
414
|
+
onpointermove={moveMediaPan}
|
|
415
|
+
onpointerup={endMediaPan}
|
|
416
|
+
onpointercancel={endMediaPan}
|
|
417
|
+
onwheel={zoomMedia}
|
|
418
|
+
></div>
|
|
419
|
+
{/if}
|
|
420
|
+
</div>
|
|
190
421
|
{:else if layer.kind === 'video' && layer.src}
|
|
191
|
-
<video
|
|
422
|
+
<video
|
|
423
|
+
src={layer.src}
|
|
424
|
+
class="h-full w-full"
|
|
425
|
+
style:object-fit={cssFit}
|
|
426
|
+
style:object-position="{mediaX * 100}% {mediaY * 100}%"
|
|
427
|
+
style:transform={zoomedMedia ? `scale(${mediaScale})` : undefined}
|
|
428
|
+
muted
|
|
429
|
+
playsinline
|
|
430
|
+
></video>
|
|
192
431
|
{:else if layer.kind === 'text' || layer.kind === 'sticky'}
|
|
193
432
|
<div
|
|
194
|
-
class=
|
|
433
|
+
class={[
|
|
434
|
+
'px-1.5 py-1 break-words whitespace-pre-wrap',
|
|
435
|
+
!textAuto && 'h-full w-full overflow-hidden'
|
|
436
|
+
]}
|
|
195
437
|
style:background={layer.kind === 'sticky'
|
|
196
438
|
? (layer.fill ?? '#fef08a')
|
|
197
439
|
: layer.textBackground}
|
|
@@ -205,16 +447,28 @@
|
|
|
205
447
|
? `${layer.letterSpacing}px`
|
|
206
448
|
: undefined}
|
|
207
449
|
style:line-height={layer.lineHeight ?? 1.25}
|
|
208
|
-
style:justify-content={layer.textAlign === 'center'
|
|
209
|
-
? 'center'
|
|
210
|
-
: layer.textAlign === 'right'
|
|
211
|
-
? 'flex-end'
|
|
212
|
-
: 'flex-start'}
|
|
213
450
|
style:text-align={layer.textAlign ?? 'left'}
|
|
214
|
-
style:align-items={layer.kind === 'sticky' ? 'flex-start' : 'center'}
|
|
215
451
|
style:border-radius="{layer.borderRadius ?? (layer.kind === 'sticky' ? 4 : 0)}px"
|
|
216
452
|
>
|
|
217
|
-
{
|
|
453
|
+
{#if editing}
|
|
454
|
+
<div
|
|
455
|
+
bind:this={textEl}
|
|
456
|
+
class="wrap-anywhere whitespace-pre-wrap outline-none"
|
|
457
|
+
contenteditable="true"
|
|
458
|
+
role="textbox"
|
|
459
|
+
tabindex="0"
|
|
460
|
+
onpointerdown={(e) => e.stopPropagation()}
|
|
461
|
+
onblur={() => {
|
|
462
|
+
if (textEl) ontextcommit?.(readEditableText(textEl));
|
|
463
|
+
}}
|
|
464
|
+
>
|
|
465
|
+
{layer.text ?? (layer.kind === 'sticky' ? 'Note' : 'Text')}
|
|
466
|
+
</div>
|
|
467
|
+
{:else}
|
|
468
|
+
<span class="wrap-anywhere whitespace-pre-wrap"
|
|
469
|
+
>{layer.text ?? (layer.kind === 'sticky' ? 'Note' : 'Text')}</span
|
|
470
|
+
>
|
|
471
|
+
{/if}
|
|
218
472
|
</div>
|
|
219
473
|
{:else if layer.kind === 'rect' || layer.kind === 'roundRect' || layer.kind === 'border'}
|
|
220
474
|
<div
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CanvasLayer, type CanvasLayerRect } from '../../../utils/canvasDocument.js';
|
|
2
2
|
import type { WidgetRect } from '../WidgetCanvas/widgetCanvasContext.js';
|
|
3
3
|
interface MediaLayerItemProps {
|
|
4
4
|
layer: CanvasLayer;
|
|
@@ -31,6 +31,11 @@ interface MediaLayerItemProps {
|
|
|
31
31
|
onclick?: (e: MouseEvent) => void;
|
|
32
32
|
ondblclick?: (e: MouseEvent) => void;
|
|
33
33
|
onchange?: (rect: WidgetRect) => void;
|
|
34
|
+
/** Zoom and pan inside an image, or grow a text box so the type stays inside. */
|
|
35
|
+
onpatch?: (partial: Partial<Pick<CanvasLayer, 'mediaScale' | 'mediaX' | 'mediaY' | 'rect' | 'fontSize' | 'rotation' | 'textMaxWidth'>>) => void;
|
|
36
|
+
/** Double-click turned this text or note into an editor. */
|
|
37
|
+
editing?: boolean;
|
|
38
|
+
ontextcommit?: (text: string) => void;
|
|
34
39
|
/** True while this frame is being dragged/resized. */
|
|
35
40
|
oninteract?: (active: boolean) => void;
|
|
36
41
|
/**
|