dune-react 0.0.42 → 0.0.44
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/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/components/puck-base/media.d.ts +1 -0
- package/dist/components/puck-base/media.js +272 -129
- package/dist/components/puck-block/contact-sections/centered-form/centered-form.js +1 -1
- package/dist/components/puck-block/contact-sections/contact-modal/contact-modal.js +1 -1
- package/dist/components/puck-block/contact-sections/form-with-media/form-with-media.js +1 -1
- package/dist/components/puck-block/contact-sections/header-form-cards/header-form-cards.js +1 -1
- package/dist/components/puck-block/contact-sections/split-info-form/split-info-form.js +135 -50
- package/dist/components/puck-block/gallery-sections/static-grid/static-grid.js +14 -10
- package/dist/components/puck-block/testimonial-sections/bento-testimonial/component.js +7 -6
- package/dist/components/shadcn/slider.js +1 -1
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/flipImageAlgorithm.js +44 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/moveCoordinatesAlgorithm.js +8 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/resizeCoordinatesAlgorithm.js +291 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/rotateImageAlgorithm.js +38 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/transformImageAlgorithm.js +84 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/animation/index.js +78 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/boundary/index.js +31 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/canvas/index.js +94 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/constants/index.js +8 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaPositionRestrictions.js +51 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaSizeRestrictions.js +30 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultBoundary.js +10 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPosition.js +12 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPositionRestrictions.js +17 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSize.js +31 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSizeRestrictions.js +16 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultStencilConstraints.js +13 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultVisibleArea.js +49 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/index.js +84 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/extensions/stencil-size/index.js +107 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/image/index.js +350 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/instance/AbstractCropperInstance.js +494 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/approximateSize.js +30 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitCoordinates.js +30 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitVisibleArea.js +26 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/helpers.js +125 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/imageTransforms.js +83 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/interactions.js +19 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/normalize.js +83 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/sizeRestrictions.js +58 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/utils.js +313 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/copyState.js +7 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/createState.js +41 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/moveCoordinates.js +15 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/reconcileState.js +44 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/resizeCoordinates.js +22 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setBoundary.js +31 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setCoordinates.js +83 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setVisibleArea.js +18 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/transformImage.js +18 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/types/index.js +16 -0
- package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/utils/index.js +268 -0
- package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +63 -0
- package/dist/node_modules/.pnpm/react-advanced-cropper@0.20.1_react@19.2.4/node_modules/react-advanced-cropper/dist/index.esm-bundler.js +1715 -0
- package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +181 -0
- package/dist/style.css +406 -0
- package/package.json +2 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { ALL_DIRECTIONS, HORIZONTAL_DIRECTIONS, VERTICAL_DIRECTIONS } from "../constants/index.js";
|
|
3
|
+
import { isGreater, isRoughlyEqual } from "../utils/index.js";
|
|
4
|
+
import { applyMove, diff, moveToPositionRestrictions, applyDirections, ratio, getBrokenRatio, getIntersections, getOppositeSide } from "../service/utils.js";
|
|
5
|
+
import { moveCoordinatesAlgorithm } from "./moveCoordinatesAlgorithm.js";
|
|
6
|
+
function fitDirections(_a) {
|
|
7
|
+
var coordinates = _a.coordinates, directions = _a.directions, positionRestrictions = _a.positionRestrictions, sizeRestrictions = _a.sizeRestrictions, preserveRatio = _a.preserveRatio, allowedDirections = _a.allowedDirections, _b = _a.compensate, compensate = _b === void 0 ? true : _b;
|
|
8
|
+
var fittedDirections = __assign({}, directions);
|
|
9
|
+
var currentWidth = applyDirections(coordinates, fittedDirections).width;
|
|
10
|
+
var currentHeight = applyDirections(coordinates, fittedDirections).height;
|
|
11
|
+
if (currentWidth < 0) {
|
|
12
|
+
if (fittedDirections.left < 0 && fittedDirections.right < 0) {
|
|
13
|
+
fittedDirections.left = -(coordinates.width - sizeRestrictions.minWidth) / (fittedDirections.left / fittedDirections.right);
|
|
14
|
+
fittedDirections.right = -(coordinates.width - sizeRestrictions.minWidth) / (fittedDirections.right / fittedDirections.left);
|
|
15
|
+
} else if (fittedDirections.left < 0) {
|
|
16
|
+
fittedDirections.left = -(coordinates.width - sizeRestrictions.minWidth);
|
|
17
|
+
} else if (fittedDirections.right < 0) {
|
|
18
|
+
fittedDirections.right = -(coordinates.width - sizeRestrictions.minWidth);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (currentHeight < 0) {
|
|
22
|
+
if (fittedDirections.top < 0 && fittedDirections.bottom < 0) {
|
|
23
|
+
fittedDirections.top = -(coordinates.height - sizeRestrictions.minHeight) / (fittedDirections.top / fittedDirections.bottom);
|
|
24
|
+
fittedDirections.bottom = -(coordinates.height - sizeRestrictions.minHeight) / (fittedDirections.bottom / fittedDirections.top);
|
|
25
|
+
} else if (fittedDirections.top < 0) {
|
|
26
|
+
fittedDirections.top = -(coordinates.height - sizeRestrictions.minHeight);
|
|
27
|
+
} else if (fittedDirections.bottom < 0) {
|
|
28
|
+
fittedDirections.bottom = -(coordinates.height - sizeRestrictions.minHeight);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var breaks = getIntersections(applyDirections(coordinates, fittedDirections), positionRestrictions);
|
|
32
|
+
var canBeCompensated = ALL_DIRECTIONS.every(function(direction) {
|
|
33
|
+
return !isGreater(breaks[getOppositeSide(direction)], 0) || allowedDirections[direction];
|
|
34
|
+
});
|
|
35
|
+
if (compensate && canBeCompensated) {
|
|
36
|
+
if (breaks.left && breaks.left > 0 && breaks.right === 0) {
|
|
37
|
+
fittedDirections.right += breaks.left;
|
|
38
|
+
fittedDirections.left -= breaks.left;
|
|
39
|
+
} else if (breaks.right && breaks.right > 0 && breaks.left === 0) {
|
|
40
|
+
fittedDirections.left += breaks.right;
|
|
41
|
+
fittedDirections.right -= breaks.right;
|
|
42
|
+
}
|
|
43
|
+
if (breaks.top && breaks.top > 0 && breaks.bottom === 0) {
|
|
44
|
+
fittedDirections.bottom += breaks.top;
|
|
45
|
+
fittedDirections.top -= breaks.top;
|
|
46
|
+
} else if (breaks.bottom && breaks.bottom > 0 && breaks.top === 0) {
|
|
47
|
+
fittedDirections.top += breaks.bottom;
|
|
48
|
+
fittedDirections.bottom -= breaks.bottom;
|
|
49
|
+
}
|
|
50
|
+
breaks = getIntersections(applyDirections(coordinates, fittedDirections), positionRestrictions);
|
|
51
|
+
}
|
|
52
|
+
var maxResize = {
|
|
53
|
+
width: Infinity,
|
|
54
|
+
height: Infinity,
|
|
55
|
+
left: Infinity,
|
|
56
|
+
right: Infinity,
|
|
57
|
+
top: Infinity,
|
|
58
|
+
bottom: Infinity
|
|
59
|
+
};
|
|
60
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
61
|
+
var intersection = breaks[direction];
|
|
62
|
+
if (intersection && fittedDirections[direction]) {
|
|
63
|
+
maxResize[direction] = Math.max(0, 1 - intersection / fittedDirections[direction]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (preserveRatio) {
|
|
67
|
+
var multiplier_1 = Math.min.apply(Math, ALL_DIRECTIONS.map(function(direction) {
|
|
68
|
+
return maxResize[direction];
|
|
69
|
+
}));
|
|
70
|
+
if (multiplier_1 !== Infinity) {
|
|
71
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
72
|
+
fittedDirections[direction] *= multiplier_1;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
77
|
+
if (maxResize[direction] !== Infinity) {
|
|
78
|
+
fittedDirections[direction] *= maxResize[direction];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
currentWidth = applyDirections(coordinates, fittedDirections).width;
|
|
83
|
+
currentHeight = applyDirections(coordinates, fittedDirections).height;
|
|
84
|
+
if (fittedDirections.right + fittedDirections.left) {
|
|
85
|
+
if (currentWidth > sizeRestrictions.maxWidth) {
|
|
86
|
+
maxResize.width = (sizeRestrictions.maxWidth - coordinates.width) / (fittedDirections.right + fittedDirections.left);
|
|
87
|
+
} else if (currentWidth < sizeRestrictions.minWidth) {
|
|
88
|
+
maxResize.width = (sizeRestrictions.minWidth - coordinates.width) / (fittedDirections.right + fittedDirections.left);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (fittedDirections.bottom + fittedDirections.top) {
|
|
92
|
+
if (currentHeight > sizeRestrictions.maxHeight) {
|
|
93
|
+
maxResize.height = (sizeRestrictions.maxHeight - coordinates.height) / (fittedDirections.bottom + fittedDirections.top);
|
|
94
|
+
} else if (currentHeight < sizeRestrictions.minHeight) {
|
|
95
|
+
maxResize.height = (sizeRestrictions.minHeight - coordinates.height) / (fittedDirections.bottom + fittedDirections.top);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (preserveRatio) {
|
|
99
|
+
var multiplier_2 = Math.min(maxResize.width, maxResize.height);
|
|
100
|
+
if (multiplier_2 !== Infinity) {
|
|
101
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
102
|
+
fittedDirections[direction] *= multiplier_2;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
if (maxResize.width !== Infinity) {
|
|
107
|
+
HORIZONTAL_DIRECTIONS.forEach(function(direction) {
|
|
108
|
+
fittedDirections[direction] *= maxResize.width;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (maxResize.height !== Infinity) {
|
|
112
|
+
VERTICAL_DIRECTIONS.forEach(function(direction) {
|
|
113
|
+
fittedDirections[direction] *= maxResize.height;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return fittedDirections;
|
|
118
|
+
}
|
|
119
|
+
function distributeOverlap(overlap, first, second) {
|
|
120
|
+
if (isRoughlyEqual(first + second, 0)) {
|
|
121
|
+
return overlap / 2;
|
|
122
|
+
} else if (isRoughlyEqual(first, 0)) {
|
|
123
|
+
return 0;
|
|
124
|
+
} else if (isRoughlyEqual(second, 0)) {
|
|
125
|
+
return overlap;
|
|
126
|
+
} else {
|
|
127
|
+
return overlap * Math.abs(first / (first + second));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function resizeCoordinatesAlgorithm(coordinates, directions, options, limitations) {
|
|
131
|
+
var aspectRatio = limitations.aspectRatio, positionRestrictions = limitations.positionRestrictions, sizeRestrictions = limitations.sizeRestrictions;
|
|
132
|
+
var actualCoordinates = __assign({}, coordinates);
|
|
133
|
+
directions = __assign({}, directions);
|
|
134
|
+
var allowedDirections = options.allowedDirections || {
|
|
135
|
+
left: true,
|
|
136
|
+
right: true,
|
|
137
|
+
bottom: true,
|
|
138
|
+
top: true
|
|
139
|
+
};
|
|
140
|
+
if (coordinates.width < sizeRestrictions.minWidth) {
|
|
141
|
+
directions.left = 0;
|
|
142
|
+
directions.right = 0;
|
|
143
|
+
}
|
|
144
|
+
if (coordinates.height < sizeRestrictions.minHeight) {
|
|
145
|
+
directions.top = 0;
|
|
146
|
+
directions.bottom = 0;
|
|
147
|
+
}
|
|
148
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
149
|
+
if (!allowedDirections[direction]) {
|
|
150
|
+
directions[direction] = 0;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
directions = fitDirections({
|
|
154
|
+
coordinates: actualCoordinates,
|
|
155
|
+
directions,
|
|
156
|
+
sizeRestrictions,
|
|
157
|
+
positionRestrictions,
|
|
158
|
+
allowedDirections
|
|
159
|
+
});
|
|
160
|
+
var currentWidth = applyDirections(actualCoordinates, directions).width;
|
|
161
|
+
var currentHeight = applyDirections(actualCoordinates, directions).height;
|
|
162
|
+
var ratioBroken = options.preserveAspectRatio ? ratio(actualCoordinates) : getBrokenRatio(currentWidth / currentHeight, aspectRatio);
|
|
163
|
+
if (ratioBroken) {
|
|
164
|
+
var respectDirection = options.respectDirection;
|
|
165
|
+
if (respectDirection !== "width" && respectDirection !== "height") {
|
|
166
|
+
if (actualCoordinates.width >= actualCoordinates.height || ratioBroken === 1) {
|
|
167
|
+
respectDirection = "width";
|
|
168
|
+
} else {
|
|
169
|
+
respectDirection = "height";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (respectDirection === "width") {
|
|
173
|
+
var overlapHeight = currentWidth / ratioBroken - actualCoordinates.height;
|
|
174
|
+
if (allowedDirections.top && allowedDirections.bottom) {
|
|
175
|
+
var top_1 = directions.top, bottom = directions.bottom;
|
|
176
|
+
directions.bottom = distributeOverlap(overlapHeight, bottom, top_1);
|
|
177
|
+
directions.top = distributeOverlap(overlapHeight, top_1, bottom);
|
|
178
|
+
} else if (allowedDirections.bottom) {
|
|
179
|
+
directions.bottom = overlapHeight;
|
|
180
|
+
} else if (allowedDirections.top) {
|
|
181
|
+
directions.top = overlapHeight;
|
|
182
|
+
} else if (allowedDirections.right) {
|
|
183
|
+
directions.right = 0;
|
|
184
|
+
} else if (allowedDirections.left) {
|
|
185
|
+
directions.left = 0;
|
|
186
|
+
}
|
|
187
|
+
} else if (respectDirection === "height") {
|
|
188
|
+
var overlapWidth = actualCoordinates.width - currentHeight * ratioBroken;
|
|
189
|
+
if (allowedDirections.left && allowedDirections.right) {
|
|
190
|
+
var left = directions.left, right = directions.right;
|
|
191
|
+
directions.left = -distributeOverlap(overlapWidth, left, right);
|
|
192
|
+
directions.right = -distributeOverlap(overlapWidth, right, left);
|
|
193
|
+
} else if (allowedDirections.left) {
|
|
194
|
+
directions.left = -overlapWidth;
|
|
195
|
+
} else if (allowedDirections.right) {
|
|
196
|
+
directions.right = -overlapWidth;
|
|
197
|
+
} else if (allowedDirections.top) {
|
|
198
|
+
directions.top = 0;
|
|
199
|
+
} else if (allowedDirections.bottom) {
|
|
200
|
+
directions.bottom = 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
directions = fitDirections({
|
|
204
|
+
directions,
|
|
205
|
+
coordinates: actualCoordinates,
|
|
206
|
+
sizeRestrictions,
|
|
207
|
+
positionRestrictions,
|
|
208
|
+
preserveRatio: true,
|
|
209
|
+
compensate: options.compensate,
|
|
210
|
+
allowedDirections
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
currentWidth = applyDirections(actualCoordinates, directions).width;
|
|
214
|
+
currentHeight = applyDirections(actualCoordinates, directions).height;
|
|
215
|
+
ratioBroken = options.preserveAspectRatio ? ratio(actualCoordinates) : getBrokenRatio(currentWidth / currentHeight, aspectRatio);
|
|
216
|
+
if (ratioBroken && isGreater(Math.abs(ratioBroken - currentWidth / currentHeight), 0)) {
|
|
217
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
218
|
+
directions[direction] = 0;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return moveCoordinatesAlgorithm({
|
|
222
|
+
width: coordinates.width + directions.right + directions.left,
|
|
223
|
+
height: coordinates.height + directions.top + directions.bottom,
|
|
224
|
+
left: coordinates.left,
|
|
225
|
+
top: coordinates.top
|
|
226
|
+
}, {
|
|
227
|
+
left: -directions.left,
|
|
228
|
+
top: -directions.top
|
|
229
|
+
}, positionRestrictions);
|
|
230
|
+
}
|
|
231
|
+
function anchorToMassPoint(coordinates, anchor) {
|
|
232
|
+
var plainAnchor = anchor.toLowerCase();
|
|
233
|
+
return {
|
|
234
|
+
left: coordinates.left + coordinates.width * (plainAnchor.indexOf("west") !== -1 ? 1 : plainAnchor.indexOf("east") !== -1 ? 0 : 0.5),
|
|
235
|
+
top: coordinates.top + coordinates.height * (plainAnchor.indexOf("north") !== -1 ? 1 : plainAnchor.indexOf("south") !== -1 ? 0 : 0.5)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function anchorToAllowedDirections(anchor) {
|
|
239
|
+
var plainAnchor = anchor.toLowerCase();
|
|
240
|
+
return {
|
|
241
|
+
left: plainAnchor.indexOf("east") === -1,
|
|
242
|
+
top: plainAnchor.indexOf("south") === -1,
|
|
243
|
+
right: plainAnchor.indexOf("west") === -1,
|
|
244
|
+
bottom: plainAnchor.indexOf("north") === -1
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function anchorMoveToResizeDirections(anchor, directions) {
|
|
248
|
+
var plainAnchor = anchor.toLowerCase();
|
|
249
|
+
var normalizedDirections = {
|
|
250
|
+
left: plainAnchor.indexOf("west") === -1 ? directions.left : -directions.left,
|
|
251
|
+
top: -directions.top,
|
|
252
|
+
right: directions.left,
|
|
253
|
+
bottom: directions.top
|
|
254
|
+
};
|
|
255
|
+
if (["north", "south", "center"].every(function(el) {
|
|
256
|
+
return plainAnchor.indexOf(el) === -1;
|
|
257
|
+
})) {
|
|
258
|
+
normalizedDirections.top = 0;
|
|
259
|
+
normalizedDirections.bottom = 0;
|
|
260
|
+
}
|
|
261
|
+
if (["west", "east", "center"].every(function(el) {
|
|
262
|
+
return plainAnchor.indexOf(el) === -1;
|
|
263
|
+
})) {
|
|
264
|
+
normalizedDirections.left = 0;
|
|
265
|
+
normalizedDirections.right = 0;
|
|
266
|
+
}
|
|
267
|
+
var allowedDirections = anchorToAllowedDirections(anchor);
|
|
268
|
+
ALL_DIRECTIONS.forEach(function(direction) {
|
|
269
|
+
if (!allowedDirections[direction]) {
|
|
270
|
+
normalizedDirections[direction] = 0;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return normalizedDirections;
|
|
274
|
+
}
|
|
275
|
+
function anchoredResizeCoordinatesAlgorithm(coordinates, anchor, directions, options, limitations) {
|
|
276
|
+
var reference = options.reference;
|
|
277
|
+
var resizeDirections = anchorMoveToResizeDirections(anchor, directions);
|
|
278
|
+
var allowedDirections = anchorToAllowedDirections(anchor);
|
|
279
|
+
var result = resizeCoordinatesAlgorithm(coordinates, resizeDirections, __assign(__assign({}, options), { allowedDirections }), limitations);
|
|
280
|
+
if (reference) {
|
|
281
|
+
result = applyMove(result, diff(anchorToMassPoint(reference, anchor), anchorToMassPoint(result, anchor)));
|
|
282
|
+
}
|
|
283
|
+
return moveToPositionRestrictions(result, limitations.positionRestrictions);
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
anchorMoveToResizeDirections,
|
|
287
|
+
anchorToAllowedDirections,
|
|
288
|
+
anchoredResizeCoordinatesAlgorithm,
|
|
289
|
+
fitDirections,
|
|
290
|
+
resizeCoordinatesAlgorithm
|
|
291
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { isNumber } from "../utils/index.js";
|
|
3
|
+
import { rotatePoint, getCenter, diff, resizeToSizeRestrictions, moveToPositionRestrictions, applyMove } from "../service/utils.js";
|
|
4
|
+
import { mergeSizeRestrictions } from "../service/sizeRestrictions.js";
|
|
5
|
+
import { isInitializedState, getTransformedImageSize, getAspectRatio, getSizeRestrictions, getAreaSizeRestrictions, getPositionRestrictions, getAreaPositionRestrictions } from "../service/helpers.js";
|
|
6
|
+
import { copyState } from "../state/copyState.js";
|
|
7
|
+
import { approximateSize } from "../service/approximateSize.js";
|
|
8
|
+
function rotateImageAlgorithm(state, settings, rotate) {
|
|
9
|
+
if (isInitializedState(state)) {
|
|
10
|
+
var result = copyState(state);
|
|
11
|
+
var angle = isNumber(rotate) ? rotate : rotate.angle;
|
|
12
|
+
var imageCenter = rotatePoint(getCenter(__assign({ left: 0, top: 0 }, getTransformedImageSize(state))), angle);
|
|
13
|
+
result.transforms.rotate += angle;
|
|
14
|
+
result.coordinates = __assign(__assign({}, approximateSize({
|
|
15
|
+
sizeRestrictions: getSizeRestrictions(result, settings),
|
|
16
|
+
aspectRatio: getAspectRatio(result, settings),
|
|
17
|
+
width: result.coordinates.width,
|
|
18
|
+
height: result.coordinates.height
|
|
19
|
+
})), rotatePoint(getCenter(result.coordinates), angle));
|
|
20
|
+
var center = !isNumber(rotate) && rotate.center ? rotate.center : getCenter(state.coordinates);
|
|
21
|
+
var shift = diff(getCenter(state.coordinates), rotatePoint(getCenter(state.coordinates), angle, center));
|
|
22
|
+
var imageSize = getTransformedImageSize(result);
|
|
23
|
+
result.coordinates.left -= imageCenter.left - imageSize.width / 2 + result.coordinates.width / 2 - shift.left;
|
|
24
|
+
result.coordinates.top -= imageCenter.top - imageSize.height / 2 + result.coordinates.height / 2 - shift.top;
|
|
25
|
+
result.visibleArea = resizeToSizeRestrictions(result.visibleArea, mergeSizeRestrictions(getAreaSizeRestrictions(result, settings), {
|
|
26
|
+
minWidth: result.coordinates.width,
|
|
27
|
+
minHeight: result.coordinates.height
|
|
28
|
+
}));
|
|
29
|
+
result.coordinates = moveToPositionRestrictions(result.coordinates, getPositionRestrictions(result, settings));
|
|
30
|
+
result.visibleArea = applyMove(result.visibleArea, diff(getCenter(result.coordinates), getCenter(state.coordinates)));
|
|
31
|
+
result.visibleArea = moveToPositionRestrictions(result.visibleArea, getAreaPositionRestrictions(result, settings));
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
rotateImageAlgorithm
|
|
38
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { isNumber, isRoughlyEqual } from "../utils/index.js";
|
|
2
|
+
import { applyMove, minScale, maxScale, positionToSizeRestrictions, applyScale, moveToPositionRestrictions, mergePositionRestrictions, coordinatesToPositionRestrictions, getCenter, inverseMove, fitToPositionRestrictions } from "../service/utils.js";
|
|
3
|
+
import { isInitializedState, getSizeRestrictions, getPositionRestrictions, getAreaSizeRestrictions, getAreaPositionRestrictions } from "../service/helpers.js";
|
|
4
|
+
import { copyState } from "../state/copyState.js";
|
|
5
|
+
function transformImageAlgorithm(state, settings, transform) {
|
|
6
|
+
var _a;
|
|
7
|
+
var _b = transform.scale, scale = _b === void 0 ? 1 : _b, _c = transform.move, move = _c === void 0 ? {} : _c;
|
|
8
|
+
if (isInitializedState(state)) {
|
|
9
|
+
var result = copyState(state);
|
|
10
|
+
var scaleFactor = 1 / (isNumber(scale) ? scale : scale.factor);
|
|
11
|
+
var scaleCenter = !isNumber(scale) ? scale.center : void 0;
|
|
12
|
+
var isAllowedScale = !isRoughlyEqual(scaleFactor, 1);
|
|
13
|
+
var areaScale = 1;
|
|
14
|
+
var stencilScale = 1;
|
|
15
|
+
result.visibleArea = applyMove(result.visibleArea, {
|
|
16
|
+
left: move.left || 0,
|
|
17
|
+
top: move.top || 0
|
|
18
|
+
});
|
|
19
|
+
var sizeRestrictions = getSizeRestrictions(result, settings);
|
|
20
|
+
var positionRestrictions = getPositionRestrictions(result, settings);
|
|
21
|
+
var areaSizeRestrictions = getAreaSizeRestrictions(result, settings);
|
|
22
|
+
var scaleRestrictions = {
|
|
23
|
+
stencil: {
|
|
24
|
+
minimum: Math.max(sizeRestrictions.minWidth ? sizeRestrictions.minWidth / result.coordinates.width : 0, sizeRestrictions.minHeight ? sizeRestrictions.minHeight / result.coordinates.height : 0),
|
|
25
|
+
maximum: Math.min(sizeRestrictions.maxWidth ? sizeRestrictions.maxWidth / result.coordinates.width : Infinity, sizeRestrictions.maxHeight ? sizeRestrictions.maxHeight / result.coordinates.height : Infinity, maxScale(result.coordinates, positionToSizeRestrictions(positionRestrictions)))
|
|
26
|
+
},
|
|
27
|
+
area: {
|
|
28
|
+
maximum: maxScale(result.visibleArea, areaSizeRestrictions),
|
|
29
|
+
minimum: minScale(result.visibleArea, areaSizeRestrictions)
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (scaleFactor && isAllowedScale) {
|
|
33
|
+
if (scaleFactor < 1) {
|
|
34
|
+
stencilScale = Math.max(scaleFactor, Math.max(scaleRestrictions.area.minimum, scaleRestrictions.stencil.minimum));
|
|
35
|
+
if (stencilScale > 1) {
|
|
36
|
+
stencilScale = 1;
|
|
37
|
+
}
|
|
38
|
+
} else if (scaleFactor > 1) {
|
|
39
|
+
stencilScale = Math.min(scaleFactor, Math.min(scaleRestrictions.area.maximum, scaleRestrictions.stencil.maximum));
|
|
40
|
+
if (stencilScale < 1) {
|
|
41
|
+
stencilScale = 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (stencilScale) {
|
|
46
|
+
result.visibleArea = applyScale(result.visibleArea, stencilScale, scaleCenter);
|
|
47
|
+
}
|
|
48
|
+
var relativeCoordinates = {
|
|
49
|
+
left: state.coordinates.left - state.visibleArea.left,
|
|
50
|
+
right: state.visibleArea.width + state.visibleArea.left - (state.coordinates.width + state.coordinates.left),
|
|
51
|
+
top: state.coordinates.top - state.visibleArea.top,
|
|
52
|
+
bottom: state.visibleArea.height + state.visibleArea.top - (state.coordinates.height + state.coordinates.top)
|
|
53
|
+
};
|
|
54
|
+
result.visibleArea = moveToPositionRestrictions(result.visibleArea, {
|
|
55
|
+
left: positionRestrictions.left !== void 0 ? positionRestrictions.left - relativeCoordinates.left * stencilScale : void 0,
|
|
56
|
+
top: positionRestrictions.top !== void 0 ? positionRestrictions.top - relativeCoordinates.top * stencilScale : void 0,
|
|
57
|
+
bottom: positionRestrictions.bottom !== void 0 ? positionRestrictions.bottom + relativeCoordinates.bottom * stencilScale : void 0,
|
|
58
|
+
right: positionRestrictions.right !== void 0 ? positionRestrictions.right + relativeCoordinates.right * stencilScale : void 0
|
|
59
|
+
});
|
|
60
|
+
result.visibleArea = moveToPositionRestrictions(result.visibleArea, getAreaPositionRestrictions(result, settings));
|
|
61
|
+
result.coordinates.width = result.coordinates.width * stencilScale;
|
|
62
|
+
result.coordinates.height = result.coordinates.height * stencilScale;
|
|
63
|
+
result.coordinates.left = result.visibleArea.left + relativeCoordinates.left * stencilScale;
|
|
64
|
+
result.coordinates.top = result.visibleArea.top + relativeCoordinates.top * stencilScale;
|
|
65
|
+
result.coordinates = moveToPositionRestrictions(result.coordinates, mergePositionRestrictions(coordinatesToPositionRestrictions(result.visibleArea), positionRestrictions));
|
|
66
|
+
if (isAllowedScale && scaleFactor && ((_a = settings.transformImage) === null || _a === void 0 ? void 0 : _a.adjustStencil)) {
|
|
67
|
+
if (scaleFactor > 1) {
|
|
68
|
+
areaScale = Math.min(scaleRestrictions.area.maximum, scaleFactor) / stencilScale;
|
|
69
|
+
} else if (scaleFactor < 1) {
|
|
70
|
+
areaScale = Math.max(result.coordinates.height / result.visibleArea.height, result.coordinates.width / result.visibleArea.width, scaleFactor / stencilScale);
|
|
71
|
+
}
|
|
72
|
+
if (areaScale !== 1) {
|
|
73
|
+
result.visibleArea = applyScale(result.visibleArea, areaScale, scaleFactor > 1 ? scaleCenter : getCenter(result.coordinates));
|
|
74
|
+
result.visibleArea = moveToPositionRestrictions(result.visibleArea, getAreaPositionRestrictions(result, settings));
|
|
75
|
+
result.visibleArea = applyMove(result.visibleArea, inverseMove(fitToPositionRestrictions(result.coordinates, coordinatesToPositionRestrictions(result.visibleArea))));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
transformImageAlgorithm
|
|
84
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var timingFunctions = {
|
|
2
|
+
linear: function(t) {
|
|
3
|
+
return t;
|
|
4
|
+
},
|
|
5
|
+
"ease-in": function(t) {
|
|
6
|
+
return Math.pow(t, 1.675);
|
|
7
|
+
},
|
|
8
|
+
"ease-out": function(t) {
|
|
9
|
+
return 1 - Math.pow(1 - t, 1.675);
|
|
10
|
+
},
|
|
11
|
+
"ease-in-out": function(t) {
|
|
12
|
+
return 0.5 * (Math.sin((t - 0.5) * Math.PI) + 1);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var Animation = (
|
|
16
|
+
/** @class */
|
|
17
|
+
function() {
|
|
18
|
+
function Animation2() {
|
|
19
|
+
this.active = false;
|
|
20
|
+
}
|
|
21
|
+
Animation2.prototype.start = function(animation) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.onStart = animation.onStart;
|
|
24
|
+
this.onProgress = animation.onProgress;
|
|
25
|
+
this.onStop = animation.onStop;
|
|
26
|
+
if (!this.active) {
|
|
27
|
+
(_a = this.onStart) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
28
|
+
}
|
|
29
|
+
if (this.id) {
|
|
30
|
+
window.cancelAnimationFrame(this.id);
|
|
31
|
+
}
|
|
32
|
+
this.startTime = performance.now();
|
|
33
|
+
this.timingFunction = animation.timingFunction;
|
|
34
|
+
this.endTime = this.startTime + animation.duration;
|
|
35
|
+
this.active = true;
|
|
36
|
+
this.animate();
|
|
37
|
+
};
|
|
38
|
+
Animation2.prototype.animate = function() {
|
|
39
|
+
var _this = this;
|
|
40
|
+
if (this.startTime && this.endTime) {
|
|
41
|
+
var timingFunction = timingFunctions[this.timingFunction];
|
|
42
|
+
if (!timingFunction) {
|
|
43
|
+
if (process.env.NODE_ENV !== "production") {
|
|
44
|
+
console.warn("[Animation] The timing function '" + timingFunction + "' is not supported. Available timing function: 'linear', 'ease-in', 'ease-in-out', 'ease-out'. Reset to 'ease-out'.");
|
|
45
|
+
}
|
|
46
|
+
timingFunction = timingFunctions["ease-out"];
|
|
47
|
+
}
|
|
48
|
+
var percent = 1 - (this.endTime - performance.now()) / (this.endTime - this.startTime);
|
|
49
|
+
var progress = Math.min(1, timingFunction(percent));
|
|
50
|
+
if (this.onProgress) {
|
|
51
|
+
this.onProgress(progress);
|
|
52
|
+
}
|
|
53
|
+
if (percent < 1) {
|
|
54
|
+
this.id = window.requestAnimationFrame(function() {
|
|
55
|
+
return _this.animate();
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
this.stop();
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
this.stop();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Animation2.prototype.stop = function() {
|
|
65
|
+
this.active = false;
|
|
66
|
+
if (this.id) {
|
|
67
|
+
window.cancelAnimationFrame(this.id);
|
|
68
|
+
}
|
|
69
|
+
if (this.onStop) {
|
|
70
|
+
this.onStop();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return Animation2;
|
|
74
|
+
}()
|
|
75
|
+
);
|
|
76
|
+
export {
|
|
77
|
+
Animation
|
|
78
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function stretchCropperBoundary(boundary, stretcher, size) {
|
|
2
|
+
stretcher.style.width = "0px";
|
|
3
|
+
stretcher.style.height = "0px";
|
|
4
|
+
stretcher.style.width = Math.max(boundary.clientWidth, size.width) + "px";
|
|
5
|
+
var ratio = size.width / size.height;
|
|
6
|
+
stretcher.style.height = Math.max(boundary.clientHeight, stretcher.clientWidth / ratio) + "px";
|
|
7
|
+
stretcher.style.width = stretcher.clientHeight * ratio + "px";
|
|
8
|
+
}
|
|
9
|
+
function stretchPreviewBoundary(boundary, stretcher, size) {
|
|
10
|
+
stretcher.style.width = "0px";
|
|
11
|
+
stretcher.style.height = "0px";
|
|
12
|
+
stretcher.style.width = Math.max(boundary.getBoundingClientRect().width, size.width) + "px";
|
|
13
|
+
var ratio = size.width / size.height;
|
|
14
|
+
stretcher.style.height = Math.max(boundary.getBoundingClientRect().height, stretcher.getBoundingClientRect().width / ratio) + "px";
|
|
15
|
+
stretcher.style.width = stretcher.getBoundingClientRect().height * ratio + "px";
|
|
16
|
+
if (stretcher.clientWidth / stretcher.clientHeight > boundary.clientWidth / boundary.clientHeight) {
|
|
17
|
+
if (stretcher.clientWidth > boundary.clientWidth) {
|
|
18
|
+
stretcher.style.width = boundary.clientWidth + "px";
|
|
19
|
+
stretcher.style.height = boundary.clientWidth / ratio + "px";
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
if (stretcher.clientHeight > boundary.clientHeight) {
|
|
23
|
+
stretcher.style.height = boundary.clientHeight + "px";
|
|
24
|
+
stretcher.style.width = boundary.clientHeight * ratio + "px";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
stretchCropperBoundary,
|
|
30
|
+
stretchPreviewBoundary
|
|
31
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { isNumeric } from "../utils/index.js";
|
|
3
|
+
import { rotatePoint, getCenter, rotateSize } from "../service/utils.js";
|
|
4
|
+
import { isInitializedState } from "../service/helpers.js";
|
|
5
|
+
import { approximateSize } from "../service/approximateSize.js";
|
|
6
|
+
function prepareSource(canvas, image, _a) {
|
|
7
|
+
var rotate = _a.rotate, flip = _a.flip;
|
|
8
|
+
var originalSize = {
|
|
9
|
+
width: "naturalWidth" in image ? image.naturalWidth : image.width,
|
|
10
|
+
height: "naturalHeight" in image ? image.naturalHeight : image.height
|
|
11
|
+
};
|
|
12
|
+
var transformedSize = rotateSize(originalSize, rotate);
|
|
13
|
+
var ctx = canvas.getContext("2d");
|
|
14
|
+
canvas.height = transformedSize.height;
|
|
15
|
+
canvas.width = transformedSize.width;
|
|
16
|
+
if (ctx) {
|
|
17
|
+
ctx.save();
|
|
18
|
+
var canvasCenter = rotatePoint(getCenter(__assign({ left: 0, top: 0 }, originalSize)), rotate);
|
|
19
|
+
ctx.translate(-(canvasCenter.left - transformedSize.width / 2), -(canvasCenter.top - transformedSize.height / 2));
|
|
20
|
+
ctx.rotate(rotate * Math.PI / 180);
|
|
21
|
+
ctx.translate(flip.horizontal ? originalSize.width : 0, flip.vertical ? originalSize.height : 0);
|
|
22
|
+
ctx.scale(flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1);
|
|
23
|
+
ctx.drawImage(image, 0, 0, originalSize.width, originalSize.height);
|
|
24
|
+
ctx.restore();
|
|
25
|
+
}
|
|
26
|
+
return canvas;
|
|
27
|
+
}
|
|
28
|
+
function updateCanvas(canvas, source, coordinates, resultSize, options) {
|
|
29
|
+
canvas.width = resultSize ? resultSize.width : coordinates.width;
|
|
30
|
+
canvas.height = resultSize ? resultSize.height : coordinates.height;
|
|
31
|
+
var ctx = canvas.getContext("2d");
|
|
32
|
+
if (ctx) {
|
|
33
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
34
|
+
if (options) {
|
|
35
|
+
if (options.imageSmoothingEnabled) {
|
|
36
|
+
ctx.imageSmoothingEnabled = options.imageSmoothingEnabled;
|
|
37
|
+
}
|
|
38
|
+
if (options.imageSmoothingQuality) {
|
|
39
|
+
ctx.imageSmoothingQuality = options.imageSmoothingQuality;
|
|
40
|
+
}
|
|
41
|
+
if (options.fillColor) {
|
|
42
|
+
ctx.fillStyle = options.fillColor;
|
|
43
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
44
|
+
ctx.save();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var offsetX = coordinates.left < 0 ? -coordinates.left : 0;
|
|
48
|
+
var offsetY = coordinates.top < 0 ? -coordinates.top : 0;
|
|
49
|
+
ctx.drawImage(source, coordinates.left + offsetX, coordinates.top + offsetY, coordinates.width, coordinates.height, offsetX * (canvas.width / coordinates.width), offsetY * (canvas.height / coordinates.height), canvas.width, canvas.height);
|
|
50
|
+
}
|
|
51
|
+
return canvas;
|
|
52
|
+
}
|
|
53
|
+
function drawCroppedArea(state, image, resultCanvas, spareCanvas, options) {
|
|
54
|
+
if (isInitializedState(state)) {
|
|
55
|
+
var transforms = state.transforms, coordinates = state.coordinates;
|
|
56
|
+
var imageTransformed = transforms.rotate !== 0 || transforms.flip.horizontal || transforms.flip.vertical;
|
|
57
|
+
var source = imageTransformed ? prepareSource(spareCanvas, image, transforms) : image;
|
|
58
|
+
var params = __assign({ minWidth: 0, minHeight: 0, maxWidth: Infinity, maxHeight: Infinity, maxArea: Infinity, imageSmoothingEnabled: true, imageSmoothingQuality: "high", fillColor: "transparent" }, options);
|
|
59
|
+
var firstNumeric = function(array) {
|
|
60
|
+
return array.find(function(el) {
|
|
61
|
+
return isNumeric(el);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
var size = approximateSize({
|
|
65
|
+
sizeRestrictions: {
|
|
66
|
+
minWidth: firstNumeric([params.width, params.minWidth]) || 0,
|
|
67
|
+
minHeight: firstNumeric([params.height, params.minHeight]) || 0,
|
|
68
|
+
maxWidth: firstNumeric([params.width, params.maxWidth]) || Infinity,
|
|
69
|
+
maxHeight: firstNumeric([params.height, params.maxHeight]) || Infinity
|
|
70
|
+
},
|
|
71
|
+
width: coordinates.width,
|
|
72
|
+
height: coordinates.height,
|
|
73
|
+
aspectRatio: {
|
|
74
|
+
minimum: coordinates.width / coordinates.height,
|
|
75
|
+
maximum: coordinates.width / coordinates.height
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (params.maxArea && size.width * size.height > params.maxArea) {
|
|
79
|
+
var scale = Math.sqrt(params.maxArea / (size.width * size.height));
|
|
80
|
+
size = {
|
|
81
|
+
width: Math.round(scale * size.width),
|
|
82
|
+
height: Math.round(scale * size.height)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return updateCanvas(resultCanvas, source, coordinates, size, params);
|
|
86
|
+
} else {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
drawCroppedArea,
|
|
92
|
+
prepareSource,
|
|
93
|
+
updateCanvas
|
|
94
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ratio } from "../service/utils.js";
|
|
2
|
+
import { getTransformedImageSize } from "../service/helpers.js";
|
|
3
|
+
import { ImageRestriction } from "../types/index.js";
|
|
4
|
+
function defaultAreaPositionRestrictions(state, settings) {
|
|
5
|
+
var visibleArea = state.visibleArea, boundary = state.boundary;
|
|
6
|
+
var imageRestriction = settings.imageRestriction;
|
|
7
|
+
var imageSize = getTransformedImageSize(state);
|
|
8
|
+
var restrictions = {};
|
|
9
|
+
if (imageRestriction === ImageRestriction.fillArea) {
|
|
10
|
+
restrictions = {
|
|
11
|
+
left: 0,
|
|
12
|
+
top: 0,
|
|
13
|
+
right: imageSize.width,
|
|
14
|
+
bottom: imageSize.height
|
|
15
|
+
};
|
|
16
|
+
} else if (imageRestriction === ImageRestriction.fitArea) {
|
|
17
|
+
if (ratio(boundary) > ratio(imageSize)) {
|
|
18
|
+
restrictions = {
|
|
19
|
+
top: 0,
|
|
20
|
+
bottom: imageSize.height
|
|
21
|
+
};
|
|
22
|
+
if (visibleArea) {
|
|
23
|
+
if (visibleArea.width > imageSize.width) {
|
|
24
|
+
restrictions.left = -(visibleArea.width - imageSize.width) / 2;
|
|
25
|
+
restrictions.right = imageSize.width - restrictions.left;
|
|
26
|
+
} else {
|
|
27
|
+
restrictions.left = 0;
|
|
28
|
+
restrictions.right = imageSize.width;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
restrictions = {
|
|
33
|
+
left: 0,
|
|
34
|
+
right: imageSize.width
|
|
35
|
+
};
|
|
36
|
+
if (visibleArea) {
|
|
37
|
+
if (visibleArea.height > imageSize.height) {
|
|
38
|
+
restrictions.top = -(visibleArea.height - imageSize.height) / 2;
|
|
39
|
+
restrictions.bottom = imageSize.height - restrictions.top;
|
|
40
|
+
} else {
|
|
41
|
+
restrictions.top = 0;
|
|
42
|
+
restrictions.bottom = imageSize.height;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return restrictions;
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
defaultAreaPositionRestrictions
|
|
51
|
+
};
|