danielgm-ui 0.1.1 → 0.3.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 +60 -3
- package/TABLER-LICENSE.txt +21 -21
- package/dist/animated-grid.d.ts +32 -0
- package/dist/animated-grid.js +346 -0
- package/dist/header.d.ts +24 -0
- package/dist/header.js +18 -0
- package/dist/image-cropper.d.ts +24 -0
- package/dist/image-cropper.js +180 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/internal/animated-grid-layout.d.ts +24 -0
- package/dist/internal/animated-grid-layout.js +55 -0
- package/dist/internal/image-crop.d.ts +25 -0
- package/dist/internal/image-crop.js +22 -0
- package/dist/styles.css +3594 -3367
- package/package.json +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/** Recorte local: el navegador decodifica la imagen y exporta el área visible a un Blob. */
|
|
4
|
+
import { useEffect, useId, useRef, useState, } from 'react';
|
|
5
|
+
import { Button } from './button.js';
|
|
6
|
+
import { Slider } from './slider.js';
|
|
7
|
+
import { clampCropOffset, getCropGeometry } from './internal/image-crop.js';
|
|
8
|
+
import { cx } from './utils.js';
|
|
9
|
+
/** Visor con arrastre, zoom, desplazamiento por teclado y exportación al confirmar. */
|
|
10
|
+
export function ImageCropper({ src, onCrop, aspectRatio = 1, outputWidth = 512, outputType = 'image/png', quality = 0.92, maxZoom = 4, locale = 'en', disabled = false, className, style, ...props }) {
|
|
11
|
+
const [imageUrl, setImageUrl] = useState();
|
|
12
|
+
const [imageSize, setImageSize] = useState();
|
|
13
|
+
const [viewport, setViewport] = useState({ width: 0, height: 0 });
|
|
14
|
+
const [zoom, setZoom] = useState(1);
|
|
15
|
+
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
|
16
|
+
const [dragging, setDragging] = useState(false);
|
|
17
|
+
const [saving, setSaving] = useState(false);
|
|
18
|
+
const [message, setMessage] = useState();
|
|
19
|
+
const stage = useRef(null);
|
|
20
|
+
const image = useRef(null);
|
|
21
|
+
const drag = useRef(undefined);
|
|
22
|
+
const id = useId();
|
|
23
|
+
const es = locale === 'es';
|
|
24
|
+
const ratio = Number.isFinite(aspectRatio) && aspectRatio > 0 ? aspectRatio : 1;
|
|
25
|
+
const zoomLimit = Number.isFinite(maxZoom) ? Math.max(1, maxZoom) : 4;
|
|
26
|
+
const width = Number.isFinite(outputWidth) ? Math.max(1, Math.round(outputWidth)) : 512;
|
|
27
|
+
const geometry = imageSize && viewport.width > 0 && viewport.height > 0
|
|
28
|
+
? getCropGeometry(imageSize.width, imageSize.height, viewport.width, viewport.height, zoom, offset)
|
|
29
|
+
: undefined;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!geometry)
|
|
32
|
+
return;
|
|
33
|
+
setOffset((current) => {
|
|
34
|
+
const next = clampCropOffset(current, geometry);
|
|
35
|
+
return next.x === current.x && next.y === current.y ? current : next;
|
|
36
|
+
});
|
|
37
|
+
// La posición se ajusta solo cuando cambian las medidas o el zoom.
|
|
38
|
+
}, [imageSize?.width, imageSize?.height, viewport.width, viewport.height, zoom]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
drag.current = undefined;
|
|
41
|
+
setDragging(false);
|
|
42
|
+
setImageSize(undefined);
|
|
43
|
+
setOffset({ x: 0, y: 0 });
|
|
44
|
+
setZoom(1);
|
|
45
|
+
setMessage(undefined);
|
|
46
|
+
if (!src) {
|
|
47
|
+
setImageUrl(undefined);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const url = typeof src === 'string' ? src : URL.createObjectURL(src);
|
|
51
|
+
setImageUrl(url);
|
|
52
|
+
return () => {
|
|
53
|
+
if (typeof src !== 'string')
|
|
54
|
+
URL.revokeObjectURL(url);
|
|
55
|
+
};
|
|
56
|
+
}, [src]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!disabled)
|
|
59
|
+
return;
|
|
60
|
+
drag.current = undefined;
|
|
61
|
+
setDragging(false);
|
|
62
|
+
}, [disabled]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!stage.current)
|
|
65
|
+
return;
|
|
66
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
67
|
+
setViewport({ width: entry.contentRect.width, height: entry.contentRect.height });
|
|
68
|
+
});
|
|
69
|
+
observer.observe(stage.current);
|
|
70
|
+
return () => observer.disconnect();
|
|
71
|
+
}, []);
|
|
72
|
+
function move(next) {
|
|
73
|
+
if (!geometry)
|
|
74
|
+
return;
|
|
75
|
+
setOffset(clampCropOffset(next, geometry));
|
|
76
|
+
}
|
|
77
|
+
async function crop() {
|
|
78
|
+
if (!geometry || !image.current || saving || disabled)
|
|
79
|
+
return;
|
|
80
|
+
setSaving(true);
|
|
81
|
+
setMessage(undefined);
|
|
82
|
+
try {
|
|
83
|
+
const canvas = document.createElement('canvas');
|
|
84
|
+
canvas.width = width;
|
|
85
|
+
canvas.height = Math.max(1, Math.round(width / ratio));
|
|
86
|
+
const context = canvas.getContext('2d');
|
|
87
|
+
if (!context)
|
|
88
|
+
throw new Error('Canvas unavailable');
|
|
89
|
+
context.drawImage(image.current, geometry.x, geometry.y, geometry.width, geometry.height, 0, 0, canvas.width, canvas.height);
|
|
90
|
+
const blob = await new Promise((resolve, reject) => {
|
|
91
|
+
canvas.toBlob((result) => (result ? resolve(result) : reject(new Error('Image export failed'))), outputType, Math.max(0, Math.min(1, quality)));
|
|
92
|
+
});
|
|
93
|
+
await onCrop(blob);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
setMessage(es
|
|
97
|
+
? 'No se pudo recortar la imagen. Comprueba que la URL permita CORS.'
|
|
98
|
+
: 'Could not crop the image. Check that the URL allows CORS.');
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
setSaving(false);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const labels = es
|
|
105
|
+
? {
|
|
106
|
+
region: 'Área de recorte',
|
|
107
|
+
hint: 'Arrastra la imagen o usa las flechas para encuadrarla.',
|
|
108
|
+
zoom: 'Zoom',
|
|
109
|
+
crop: 'Recortar imagen',
|
|
110
|
+
empty: 'Selecciona una imagen para recortar.',
|
|
111
|
+
invalid: 'No se pudo abrir la imagen.',
|
|
112
|
+
}
|
|
113
|
+
: {
|
|
114
|
+
region: 'Crop area',
|
|
115
|
+
hint: 'Drag the image or use the arrow keys to position it.',
|
|
116
|
+
zoom: 'Zoom',
|
|
117
|
+
crop: 'Crop image',
|
|
118
|
+
empty: 'Choose an image to crop.',
|
|
119
|
+
invalid: 'Could not open the image.',
|
|
120
|
+
};
|
|
121
|
+
return (_jsxs("div", { ...props, className: cx('dgm-image-cropper', className), style: style, "data-disabled": disabled || undefined, children: [_jsxs("div", { ref: stage, className: "dgm-image-cropper-stage", style: { '--dgm-crop-ratio': ratio }, role: "group", "aria-label": labels.region, "aria-describedby": `${id}-hint`, tabIndex: imageSize && !disabled ? 0 : -1, "data-dragging": dragging || undefined, onPointerDown: (event) => {
|
|
122
|
+
if (!geometry || disabled || event.button !== 0)
|
|
123
|
+
return;
|
|
124
|
+
event.currentTarget.focus();
|
|
125
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
126
|
+
drag.current = {
|
|
127
|
+
pointerId: event.pointerId,
|
|
128
|
+
x: event.clientX,
|
|
129
|
+
y: event.clientY,
|
|
130
|
+
offsetX: offset.x,
|
|
131
|
+
offsetY: offset.y,
|
|
132
|
+
};
|
|
133
|
+
setDragging(true);
|
|
134
|
+
}, onPointerMove: (event) => {
|
|
135
|
+
if (disabled || !drag.current || drag.current.pointerId !== event.pointerId)
|
|
136
|
+
return;
|
|
137
|
+
move({
|
|
138
|
+
x: drag.current.offsetX + event.clientX - drag.current.x,
|
|
139
|
+
y: drag.current.offsetY + event.clientY - drag.current.y,
|
|
140
|
+
});
|
|
141
|
+
}, onPointerUp: (event) => {
|
|
142
|
+
if (drag.current?.pointerId !== event.pointerId)
|
|
143
|
+
return;
|
|
144
|
+
drag.current = undefined;
|
|
145
|
+
setDragging(false);
|
|
146
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
147
|
+
}, onPointerCancel: () => {
|
|
148
|
+
drag.current = undefined;
|
|
149
|
+
setDragging(false);
|
|
150
|
+
}, onKeyDown: (event) => {
|
|
151
|
+
if (!geometry || disabled)
|
|
152
|
+
return;
|
|
153
|
+
const step = event.shiftKey ? 1 : 10;
|
|
154
|
+
const delta = {
|
|
155
|
+
ArrowLeft: { x: -step, y: 0 },
|
|
156
|
+
ArrowRight: { x: step, y: 0 },
|
|
157
|
+
ArrowUp: { x: 0, y: -step },
|
|
158
|
+
ArrowDown: { x: 0, y: step },
|
|
159
|
+
}[event.key];
|
|
160
|
+
if (!delta)
|
|
161
|
+
return;
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
move({ x: offset.x + delta.x, y: offset.y + delta.y });
|
|
164
|
+
}, children: [imageUrl ? (_jsx("img", { ref: image, alt: "", crossOrigin: typeof src === 'string' && !src.startsWith('data:') && !src.startsWith('blob:')
|
|
165
|
+
? 'anonymous'
|
|
166
|
+
: undefined, src: imageUrl, draggable: false, onLoad: (event) => {
|
|
167
|
+
const current = event.currentTarget;
|
|
168
|
+
setImageSize({ width: current.naturalWidth, height: current.naturalHeight });
|
|
169
|
+
setMessage(undefined);
|
|
170
|
+
}, onError: () => {
|
|
171
|
+
setImageSize(undefined);
|
|
172
|
+
setMessage(labels.invalid);
|
|
173
|
+
}, style: geometry
|
|
174
|
+
? {
|
|
175
|
+
width: imageSize?.width,
|
|
176
|
+
height: imageSize?.height,
|
|
177
|
+
transform: `translate(-50%, -50%) translate(${Math.max(-geometry.maxOffsetX, Math.min(geometry.maxOffsetX, offset.x))}px, ${Math.max(-geometry.maxOffsetY, Math.min(geometry.maxOffsetY, offset.y))}px) scale(${geometry.scale})`,
|
|
178
|
+
}
|
|
179
|
+
: { visibility: 'hidden' } })) : (_jsx("span", { className: "dgm-image-cropper-empty", children: labels.empty })), imageSize && _jsx("span", { className: "dgm-image-cropper-guides", "aria-hidden": "true" })] }), _jsx("p", { id: `${id}-hint`, className: "dgm-description", children: labels.hint }), _jsxs("div", { className: "dgm-image-cropper-controls", children: [_jsx(Slider, { label: labels.zoom, min: 1, max: Math.max(1.01, zoomLimit), step: 0.01, value: zoom, onValueChange: setZoom, formatValue: (value) => `${Math.round(value * 100)}%`, disabled: disabled || !imageSize || zoomLimit === 1 }), _jsx(Button, { onClick: crop, disabled: disabled || !geometry, loading: saving, children: labels.crop })] }), message && (_jsx("p", { className: "dgm-error", role: "alert", children: message }))] }));
|
|
180
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* El CSS se importa por separado desde `danielgm-ui/styles.css`.
|
|
7
7
|
*/
|
|
8
8
|
export { Button, type ButtonProps } from './button.js';
|
|
9
|
+
export { Header, HeaderBrand, HeaderNav, HeaderActions, type HeaderProps, type HeaderBrandProps, type HeaderNavProps, type HeaderActionsProps, } from './header.js';
|
|
9
10
|
export { Typography, type TypographyProps, type TypographyVariant, type TypographyElement, type TypographyTone, } from './typography.js';
|
|
10
11
|
export { Slider, RangeSlider, type SliderProps, type RangeSliderProps, type SliderBaseProps, } from './slider.js';
|
|
11
12
|
export { MultiSelect, type MultiSelectProps } from './multi-select.js';
|
|
@@ -29,6 +30,7 @@ export { CheckboxGroup, SwitchGroup, type CheckboxGroupProps, type SwitchGroupPr
|
|
|
29
30
|
export { DatePicker, DateRangePicker, type DatePickerProps, type DateRangePickerProps, type DateRangeValue, type DatePickerBaseProps, } from './date-picker.js';
|
|
30
31
|
export { DataTable, type DataTableProps, type DataColumn, type DataTableSort, } from './data-table.js';
|
|
31
32
|
export { FileUpload, type FileUploadProps, type FileRejection } from './file-upload.js';
|
|
33
|
+
export { ImageCropper, type ImageCropperProps } from './image-cropper.js';
|
|
32
34
|
export { CommandPalette, type CommandPaletteProps, type CommandAction } from './command-palette.js';
|
|
33
35
|
export { Stepper, type StepperProps, type StepItem } from './stepper.js';
|
|
34
36
|
export { DropdownMenu, type DropdownMenuProps, type DropdownMenuItem } from './dropdown-menu.js';
|
|
@@ -41,6 +43,7 @@ export { CustomSelect, type CustomSelectProps, type SelectOption } from './custo
|
|
|
41
43
|
export { Modal, type ModalProps } from './modal.js';
|
|
42
44
|
export { Tooltip, type TooltipProps } from './tooltip.js';
|
|
43
45
|
export { Transition, type TransitionProps } from './transition.js';
|
|
46
|
+
export { AnimatedGrid, type AnimatedGridProps, type AnimatedGridColumns } from './animated-grid.js';
|
|
44
47
|
export { Tabs, type TabsProps, type TabItem } from './tabs.js';
|
|
45
48
|
export { Accordion, type AccordionProps, type AccordionItem, type AccordionSingleProps, type AccordionMultipleProps, } from './accordion.js';
|
|
46
49
|
export { Input, Textarea, Select, type InputProps, type TextareaProps, type SelectProps, } from './fields.js';
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* El CSS se importa por separado desde `danielgm-ui/styles.css`.
|
|
7
7
|
*/
|
|
8
8
|
export { Button } from './button.js';
|
|
9
|
+
export { Header, HeaderBrand, HeaderNav, HeaderActions, } from './header.js';
|
|
9
10
|
export { Typography, } from './typography.js';
|
|
10
11
|
export { Slider, RangeSlider, } from './slider.js';
|
|
11
12
|
export { MultiSelect } from './multi-select.js';
|
|
@@ -29,6 +30,7 @@ export { CheckboxGroup, SwitchGroup, } from './choice-group.js';
|
|
|
29
30
|
export { DatePicker, DateRangePicker, } from './date-picker.js';
|
|
30
31
|
export { DataTable, } from './data-table.js';
|
|
31
32
|
export { FileUpload } from './file-upload.js';
|
|
33
|
+
export { ImageCropper } from './image-cropper.js';
|
|
32
34
|
export { CommandPalette } from './command-palette.js';
|
|
33
35
|
export { Stepper } from './stepper.js';
|
|
34
36
|
export { DropdownMenu } from './dropdown-menu.js';
|
|
@@ -41,6 +43,7 @@ export { CustomSelect } from './custom-select.js';
|
|
|
41
43
|
export { Modal } from './modal.js';
|
|
42
44
|
export { Tooltip } from './tooltip.js';
|
|
43
45
|
export { Transition } from './transition.js';
|
|
46
|
+
export { AnimatedGrid } from './animated-grid.js';
|
|
44
47
|
export { Tabs } from './tabs.js';
|
|
45
48
|
export { Accordion, } from './accordion.js';
|
|
46
49
|
export { Input, Textarea, Select, } from './fields.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Datos de presencia independientes de React: una salida conserva su celda hasta completarse. */
|
|
2
|
+
export interface GridSlot<T> {
|
|
3
|
+
key: string;
|
|
4
|
+
item: T;
|
|
5
|
+
exiting: boolean;
|
|
6
|
+
exited: boolean;
|
|
7
|
+
appear: boolean;
|
|
8
|
+
exitHeight: number;
|
|
9
|
+
}
|
|
10
|
+
/** Reconciliación de claves: las altas y el nuevo orden esperan mientras exista una salida. */
|
|
11
|
+
export declare function reconcileGridSlots<T>(previous: readonly GridSlot<T>[], desiredKeys: readonly string[], desiredItems: ReadonlyMap<string, T>, lastItems: ReadonlyMap<string, T>, heights: ReadonlyMap<string, number>): GridSlot<T>[];
|
|
12
|
+
/** Coordenadas de layout, ajenas a transformaciones visuales que aún estén animándose. */
|
|
13
|
+
export interface GridPosition {
|
|
14
|
+
left: number;
|
|
15
|
+
top: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
row: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Las celdas de una fila comparten offsetTop aunque su contenido tenga alturas distintas.
|
|
22
|
+
* Agrupar esos valores evita confundir el cambio de altura de una fila con un salto de fila.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readGridPositions(nodes: ReadonlyMap<string, HTMLDivElement>): Map<string, GridPosition>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Reconciliación de claves: las altas y el nuevo orden esperan mientras exista una salida. */
|
|
2
|
+
export function reconcileGridSlots(previous, desiredKeys, desiredItems, lastItems, heights) {
|
|
3
|
+
const desired = new Set(desiredKeys);
|
|
4
|
+
const retained = previous.map((slot) => {
|
|
5
|
+
if (desired.has(slot.key)) {
|
|
6
|
+
return slot.exiting ? { ...slot, exiting: false, exited: false } : slot;
|
|
7
|
+
}
|
|
8
|
+
if (slot.exiting)
|
|
9
|
+
return slot;
|
|
10
|
+
return {
|
|
11
|
+
...slot,
|
|
12
|
+
item: lastItems.has(slot.key) ? lastItems.get(slot.key) : slot.item,
|
|
13
|
+
exiting: true,
|
|
14
|
+
exited: false,
|
|
15
|
+
exitHeight: heights.get(slot.key) ?? 0,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
if (retained.some((slot) => slot.exiting))
|
|
19
|
+
return retained;
|
|
20
|
+
const existing = new Map(retained.map((slot) => [slot.key, slot]));
|
|
21
|
+
return desiredKeys.map((key) => existing.get(key) ?? {
|
|
22
|
+
key,
|
|
23
|
+
item: desiredItems.get(key),
|
|
24
|
+
exiting: false,
|
|
25
|
+
exited: false,
|
|
26
|
+
appear: true,
|
|
27
|
+
exitHeight: 0,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Las celdas de una fila comparten offsetTop aunque su contenido tenga alturas distintas.
|
|
32
|
+
* Agrupar esos valores evita confundir el cambio de altura de una fila con un salto de fila.
|
|
33
|
+
*/
|
|
34
|
+
export function readGridPositions(nodes) {
|
|
35
|
+
const measured = [...nodes]
|
|
36
|
+
.filter(([, node]) => node.isConnected)
|
|
37
|
+
.map(([key, node]) => ({
|
|
38
|
+
key,
|
|
39
|
+
left: node.offsetLeft,
|
|
40
|
+
top: node.offsetTop,
|
|
41
|
+
width: node.offsetWidth,
|
|
42
|
+
height: node.offsetHeight,
|
|
43
|
+
}));
|
|
44
|
+
const rows = new Map();
|
|
45
|
+
let row = -1;
|
|
46
|
+
let rowTop = Number.NEGATIVE_INFINITY;
|
|
47
|
+
for (const { key, top } of [...measured].sort((a, b) => a.top - b.top)) {
|
|
48
|
+
if (row < 0 || Math.abs(rowTop - top) > 2) {
|
|
49
|
+
row++;
|
|
50
|
+
rowTop = top;
|
|
51
|
+
}
|
|
52
|
+
rows.set(key, row);
|
|
53
|
+
}
|
|
54
|
+
return new Map(measured.map(({ key, ...position }) => [key, { ...position, row: rows.get(key) }]));
|
|
55
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Geometría compartida entre el visor y la exportación al canvas. */
|
|
2
|
+
export interface CropGeometry {
|
|
3
|
+
scale: number;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
maxOffsetX: number;
|
|
9
|
+
maxOffsetY: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function clampCropOffset(offset: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}, bounds: {
|
|
15
|
+
maxOffsetX: number;
|
|
16
|
+
maxOffsetY: number;
|
|
17
|
+
}): {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
/** El mismo rectángulo gobierna la posición visible y los píxeles exportados. */
|
|
22
|
+
export declare function getCropGeometry(imageWidth: number, imageHeight: number, viewportWidth: number, viewportHeight: number, zoom: number, offset: {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}): CropGeometry;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function clampCropOffset(offset, bounds) {
|
|
2
|
+
return {
|
|
3
|
+
x: Math.max(-bounds.maxOffsetX, Math.min(bounds.maxOffsetX, offset.x)),
|
|
4
|
+
y: Math.max(-bounds.maxOffsetY, Math.min(bounds.maxOffsetY, offset.y)),
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
/** El mismo rectángulo gobierna la posición visible y los píxeles exportados. */
|
|
8
|
+
export function getCropGeometry(imageWidth, imageHeight, viewportWidth, viewportHeight, zoom, offset) {
|
|
9
|
+
const scale = Math.max(viewportWidth / imageWidth, viewportHeight / imageHeight) * zoom;
|
|
10
|
+
const maxOffsetX = Math.max(0, (imageWidth * scale - viewportWidth) / 2);
|
|
11
|
+
const maxOffsetY = Math.max(0, (imageHeight * scale - viewportHeight) / 2);
|
|
12
|
+
const limited = clampCropOffset(offset, { maxOffsetX, maxOffsetY });
|
|
13
|
+
return {
|
|
14
|
+
scale,
|
|
15
|
+
x: (imageWidth * scale - viewportWidth) / (2 * scale) - limited.x / scale,
|
|
16
|
+
y: (imageHeight * scale - viewportHeight) / (2 * scale) - limited.y / scale,
|
|
17
|
+
width: viewportWidth / scale,
|
|
18
|
+
height: viewportHeight / scale,
|
|
19
|
+
maxOffsetX,
|
|
20
|
+
maxOffsetY,
|
|
21
|
+
};
|
|
22
|
+
}
|