dune-react 0.0.43 → 0.0.45
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/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/puck-core/core/props/index.js +7 -0
- package/dist/components/puck-core/core/with-editable.js +4 -5
- 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 +21 -20
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ratio } from "../service/utils.js";
|
|
2
|
+
import { getTransformedImageSize } from "../service/helpers.js";
|
|
3
|
+
import { ImageRestriction } from "../types/index.js";
|
|
4
|
+
function defaultAreaSizeRestrictions(state, settings) {
|
|
5
|
+
var boundary = state.boundary;
|
|
6
|
+
var imageRestriction = settings.imageRestriction;
|
|
7
|
+
var imageSize = getTransformedImageSize(state);
|
|
8
|
+
var restrictions = {
|
|
9
|
+
minWidth: 0,
|
|
10
|
+
minHeight: 0,
|
|
11
|
+
maxWidth: Infinity,
|
|
12
|
+
maxHeight: Infinity
|
|
13
|
+
};
|
|
14
|
+
if (imageRestriction === ImageRestriction.fillArea) {
|
|
15
|
+
restrictions.maxWidth = imageSize.width;
|
|
16
|
+
restrictions.maxHeight = imageSize.height;
|
|
17
|
+
} else if (imageRestriction === ImageRestriction.fitArea) {
|
|
18
|
+
if (ratio(boundary) > ratio(imageSize)) {
|
|
19
|
+
restrictions.maxHeight = imageSize.height;
|
|
20
|
+
restrictions.maxWidth = imageSize.height * ratio(boundary);
|
|
21
|
+
} else {
|
|
22
|
+
restrictions.maxWidth = imageSize.width;
|
|
23
|
+
restrictions.maxHeight = imageSize.width / ratio(boundary);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return restrictions;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
defaultAreaSizeRestrictions
|
|
30
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getTransformedImageSize } from "../service/helpers.js";
|
|
2
|
+
function defaultPosition(state) {
|
|
3
|
+
var visibleArea = state.visibleArea, coordinates = state.coordinates;
|
|
4
|
+
var area = visibleArea || getTransformedImageSize(state);
|
|
5
|
+
return {
|
|
6
|
+
left: (visibleArea ? visibleArea.left : 0) + area.width / 2 - (coordinates ? coordinates.width / 2 : 0),
|
|
7
|
+
top: (visibleArea ? visibleArea.top : 0) + area.height / 2 - (coordinates ? coordinates.height / 2 : 0)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
defaultPosition
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getTransformedImageSize } from "../service/helpers.js";
|
|
2
|
+
function defaultPositionRestrictions(state, settings) {
|
|
3
|
+
var imageSize = getTransformedImageSize(state);
|
|
4
|
+
var limits = {};
|
|
5
|
+
if (settings.imageRestriction && settings.imageRestriction !== "none") {
|
|
6
|
+
limits = {
|
|
7
|
+
left: 0,
|
|
8
|
+
top: 0,
|
|
9
|
+
right: imageSize.width,
|
|
10
|
+
bottom: imageSize.height
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return limits;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
defaultPositionRestrictions
|
|
17
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { positionToSizeRestrictions, ratio } from "../service/utils.js";
|
|
3
|
+
import { getSizeRestrictions, getAspectRatio, getPositionRestrictions } from "../service/helpers.js";
|
|
4
|
+
import { approximateSize } from "../service/approximateSize.js";
|
|
5
|
+
function defaultSize(state, settings) {
|
|
6
|
+
var imageSize = state.imageSize, visibleArea = state.visibleArea;
|
|
7
|
+
var sizeRestrictions = getSizeRestrictions(state, settings);
|
|
8
|
+
var aspectRatio = getAspectRatio(state, settings);
|
|
9
|
+
var area;
|
|
10
|
+
if (visibleArea) {
|
|
11
|
+
area = visibleArea;
|
|
12
|
+
} else {
|
|
13
|
+
var sizeRestrictions_1 = positionToSizeRestrictions(getPositionRestrictions(state, settings));
|
|
14
|
+
area = {
|
|
15
|
+
width: Math.max(sizeRestrictions_1.minWidth, Math.min(sizeRestrictions_1.maxWidth, imageSize.width)),
|
|
16
|
+
height: Math.max(sizeRestrictions_1.minHeight, Math.min(sizeRestrictions_1.maxHeight, imageSize.height))
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var optimalRatio = Math.min(aspectRatio.maximum || Infinity, Math.max(aspectRatio.minimum || 0, ratio(area)));
|
|
20
|
+
var size = area.width < area.height ? {
|
|
21
|
+
width: area.width * 0.8,
|
|
22
|
+
height: area.width * 0.8 / optimalRatio
|
|
23
|
+
} : {
|
|
24
|
+
height: area.height * 0.8,
|
|
25
|
+
width: area.height * 0.8 * optimalRatio
|
|
26
|
+
};
|
|
27
|
+
return approximateSize(__assign(__assign({}, size), { aspectRatio, sizeRestrictions }));
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
defaultSize
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isNumeric, parseNumber } from "../utils/index.js";
|
|
2
|
+
function retrieveSizeRestrictions(settings) {
|
|
3
|
+
return {
|
|
4
|
+
minWidth: isNumeric(settings.minWidth) ? parseNumber(settings.minWidth) : 0,
|
|
5
|
+
minHeight: isNumeric(settings.minHeight) ? parseNumber(settings.minHeight) : 0,
|
|
6
|
+
maxWidth: isNumeric(settings.maxWidth) ? parseNumber(settings.maxWidth) : Infinity,
|
|
7
|
+
maxHeight: isNumeric(settings.maxHeight) ? parseNumber(settings.maxHeight) : Infinity
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function pixelsRestrictions(state, settings) {
|
|
11
|
+
return retrieveSizeRestrictions(settings);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
pixelsRestrictions,
|
|
15
|
+
retrieveSizeRestrictions
|
|
16
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isFunction } from "../utils/index.js";
|
|
2
|
+
import { createAspectRatio } from "../service/utils.js";
|
|
3
|
+
function defaultStencilConstraints(rawSettings, stencilProps) {
|
|
4
|
+
if (!rawSettings.aspectRatio) {
|
|
5
|
+
return {
|
|
6
|
+
aspectRatio: createAspectRatio(isFunction(stencilProps.aspectRatio) ? stencilProps.aspectRatio() : stencilProps.aspectRatio)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
defaultStencilConstraints
|
|
13
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { ratio, resizeToSizeRestrictions, getIntersections, coordinatesToPositionRestrictions, moveToPositionRestrictions } from "../service/utils.js";
|
|
3
|
+
import { getTransformedImageSize, getAreaSizeRestrictions } from "../service/helpers.js";
|
|
4
|
+
function defaultVisibleArea(state, settings) {
|
|
5
|
+
var coordinates = state.coordinates, boundary = state.boundary;
|
|
6
|
+
var imageSize = getTransformedImageSize(state);
|
|
7
|
+
var boundaryRatio = ratio(boundary);
|
|
8
|
+
if (coordinates) {
|
|
9
|
+
var reference = {
|
|
10
|
+
height: Math.max(coordinates.height, imageSize.height),
|
|
11
|
+
width: Math.max(coordinates.width, imageSize.width)
|
|
12
|
+
};
|
|
13
|
+
var visibleArea = {
|
|
14
|
+
left: 0,
|
|
15
|
+
top: 0,
|
|
16
|
+
width: ratio(reference) > boundaryRatio ? reference.width : reference.height * boundaryRatio,
|
|
17
|
+
height: ratio(reference) > boundaryRatio ? reference.width / boundaryRatio : reference.height
|
|
18
|
+
};
|
|
19
|
+
visibleArea = resizeToSizeRestrictions(visibleArea, getAreaSizeRestrictions(state, settings));
|
|
20
|
+
visibleArea.left = coordinates.left + coordinates.width / 2 - visibleArea.width / 2;
|
|
21
|
+
visibleArea.top = coordinates.top + coordinates.height / 2 - visibleArea.height / 2;
|
|
22
|
+
var coordinatesIntersection = getIntersections(coordinates, coordinatesToPositionRestrictions(__assign({ left: 0, top: 0 }, imageSize)));
|
|
23
|
+
var restrictions = {};
|
|
24
|
+
if (!coordinatesIntersection.left && !coordinatesIntersection.right && visibleArea.width <= imageSize.width) {
|
|
25
|
+
restrictions.left = 0;
|
|
26
|
+
restrictions.right = imageSize.width;
|
|
27
|
+
}
|
|
28
|
+
if (!coordinatesIntersection.top && !coordinatesIntersection.bottom && visibleArea.height <= imageSize.height) {
|
|
29
|
+
restrictions.top = 0;
|
|
30
|
+
restrictions.bottom = imageSize.height;
|
|
31
|
+
}
|
|
32
|
+
return moveToPositionRestrictions(visibleArea, restrictions);
|
|
33
|
+
} else {
|
|
34
|
+
var imageRatio = ratio(imageSize);
|
|
35
|
+
var areaProperties = {
|
|
36
|
+
height: imageRatio < boundaryRatio ? imageSize.height : imageSize.width / boundaryRatio,
|
|
37
|
+
width: imageRatio < boundaryRatio ? imageSize.height * boundaryRatio : imageSize.width
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
left: imageSize.width / 2 - areaProperties.width / 2,
|
|
41
|
+
top: imageSize.height / 2 - areaProperties.height / 2,
|
|
42
|
+
width: areaProperties.width,
|
|
43
|
+
height: areaProperties.height
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
defaultVisibleArea
|
|
49
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { isFunction } from "../utils/index.js";
|
|
3
|
+
import { createAspectRatio } from "../service/utils.js";
|
|
4
|
+
import { mergeSizeRestrictions } from "../service/sizeRestrictions.js";
|
|
5
|
+
import { defaultPositionRestrictions } from "./defaultPositionRestrictions.js";
|
|
6
|
+
import { defaultVisibleArea } from "./defaultVisibleArea.js";
|
|
7
|
+
import { defaultSize } from "./defaultSize.js";
|
|
8
|
+
import { pixelsRestrictions } from "./defaultSizeRestrictions.js";
|
|
9
|
+
import { retrieveSizeRestrictions } from "./defaultSizeRestrictions.js";
|
|
10
|
+
import { defaultPosition } from "./defaultPosition.js";
|
|
11
|
+
import { defaultAreaPositionRestrictions } from "./defaultAreaPositionRestrictions.js";
|
|
12
|
+
import { defaultAreaSizeRestrictions } from "./defaultAreaSizeRestrictions.js";
|
|
13
|
+
function withDefaultSizeRestrictions(sizeRestrictions) {
|
|
14
|
+
return function(state, basicSettings) {
|
|
15
|
+
var value = isFunction(sizeRestrictions) ? sizeRestrictions(state, basicSettings) : sizeRestrictions;
|
|
16
|
+
return mergeSizeRestrictions(pixelsRestrictions(state, basicSettings), value);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createDefaultSettings(params) {
|
|
20
|
+
return __assign(__assign({}, params), { sizeRestrictions: function(state, basicSettings) {
|
|
21
|
+
var restrictions;
|
|
22
|
+
if (params.sizeRestrictions) {
|
|
23
|
+
restrictions = isFunction(params.sizeRestrictions) ? params.sizeRestrictions(state, basicSettings) : params.sizeRestrictions;
|
|
24
|
+
} else {
|
|
25
|
+
restrictions = pixelsRestrictions(state, basicSettings);
|
|
26
|
+
}
|
|
27
|
+
return restrictions;
|
|
28
|
+
}, areaPositionRestrictions: function(state, basicSettings) {
|
|
29
|
+
if (params.areaPositionRestrictions) {
|
|
30
|
+
return isFunction(params.areaPositionRestrictions) ? params.areaPositionRestrictions(state, basicSettings) : params.areaPositionRestrictions;
|
|
31
|
+
} else {
|
|
32
|
+
return defaultAreaPositionRestrictions(state, basicSettings);
|
|
33
|
+
}
|
|
34
|
+
}, areaSizeRestrictions: function(state, basicSettings) {
|
|
35
|
+
if (params.areaSizeRestrictions) {
|
|
36
|
+
return isFunction(params.areaSizeRestrictions) ? params.areaSizeRestrictions(state, basicSettings) : params.areaSizeRestrictions;
|
|
37
|
+
} else {
|
|
38
|
+
return defaultAreaSizeRestrictions(state, basicSettings);
|
|
39
|
+
}
|
|
40
|
+
}, positionRestrictions: function(state, basicSettings) {
|
|
41
|
+
if (params.positionRestrictions) {
|
|
42
|
+
return isFunction(params.positionRestrictions) ? params.positionRestrictions(state, basicSettings) : params.positionRestrictions;
|
|
43
|
+
} else {
|
|
44
|
+
return defaultPositionRestrictions(state, basicSettings);
|
|
45
|
+
}
|
|
46
|
+
}, defaultCoordinates: function(state, basicSettings) {
|
|
47
|
+
if (params.defaultCoordinates) {
|
|
48
|
+
return isFunction(params.defaultCoordinates) ? params.defaultCoordinates(state, basicSettings) : params.defaultCoordinates;
|
|
49
|
+
} else {
|
|
50
|
+
var defaultSizeAlgorithm = params.defaultSize;
|
|
51
|
+
if (!defaultSizeAlgorithm) {
|
|
52
|
+
defaultSizeAlgorithm = defaultSize;
|
|
53
|
+
}
|
|
54
|
+
var size = isFunction(defaultSizeAlgorithm) ? defaultSizeAlgorithm(state, basicSettings) : defaultSizeAlgorithm;
|
|
55
|
+
var defaultPositionAlgorithm_1 = params.defaultPosition || defaultPosition;
|
|
56
|
+
return [
|
|
57
|
+
size,
|
|
58
|
+
function(state2) {
|
|
59
|
+
return __assign({}, isFunction(defaultPositionAlgorithm_1) ? defaultPositionAlgorithm_1(state2, basicSettings) : defaultPositionAlgorithm_1);
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}, defaultVisibleArea: function(state, basicSettings) {
|
|
64
|
+
if (params.defaultVisibleArea) {
|
|
65
|
+
return isFunction(params.defaultVisibleArea) ? params.defaultVisibleArea(state, basicSettings) : params.defaultVisibleArea;
|
|
66
|
+
} else {
|
|
67
|
+
return defaultVisibleArea(state, basicSettings);
|
|
68
|
+
}
|
|
69
|
+
}, aspectRatio: function(state, basicSettings) {
|
|
70
|
+
return createAspectRatio(isFunction(params.aspectRatio) ? params.aspectRatio(state, basicSettings) : params.aspectRatio);
|
|
71
|
+
} });
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
createDefaultSettings,
|
|
75
|
+
defaultAreaPositionRestrictions,
|
|
76
|
+
defaultAreaSizeRestrictions,
|
|
77
|
+
defaultPosition,
|
|
78
|
+
defaultPositionRestrictions,
|
|
79
|
+
defaultSize,
|
|
80
|
+
defaultVisibleArea,
|
|
81
|
+
pixelsRestrictions,
|
|
82
|
+
retrieveSizeRestrictions,
|
|
83
|
+
withDefaultSizeRestrictions
|
|
84
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { __assign } from "../../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
|
|
2
|
+
import { isFunction } from "../../utils/index.js";
|
|
3
|
+
import { ratio, aspectRatioIntersection, createAspectRatio, applyScale, fitToSizeRestrictions, applyMove, diff, getCenter, moveToPositionRestrictions, mergePositionRestrictions, coordinatesToPositionRestrictions } from "../../service/utils.js";
|
|
4
|
+
import { getSizeRestrictions, getAspectRatio, getAreaSizeRestrictions, isInitializedState, getAreaPositionRestrictions } from "../../service/helpers.js";
|
|
5
|
+
import { copyState } from "../../state/copyState.js";
|
|
6
|
+
import { approximateSize } from "../../service/approximateSize.js";
|
|
7
|
+
import { defaultStencilConstraints } from "../../defaults/defaultStencilConstraints.js";
|
|
8
|
+
function fixedStencilConstraints(rawSettings, stencilOptions) {
|
|
9
|
+
var defaultConstraints = defaultStencilConstraints({}, stencilOptions);
|
|
10
|
+
return {
|
|
11
|
+
stencilSize: function(state, settings) {
|
|
12
|
+
var previousSize = isFunction(rawSettings.stencilSize) ? rawSettings.stencilSize(state, settings) : rawSettings.stencilSize;
|
|
13
|
+
return approximateSize(__assign(__assign({}, previousSize), { aspectRatio: aspectRatioIntersection(defaultConstraints.aspectRatio, createAspectRatio(ratio(previousSize))) }));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getStencilSize(state, settings) {
|
|
18
|
+
var boundary = state.boundary;
|
|
19
|
+
var size = isFunction(settings.stencilSize) ? settings.stencilSize(state, settings) : settings.stencilSize;
|
|
20
|
+
if (size.width > boundary.width || size.height > boundary.height) {
|
|
21
|
+
size = approximateSize({
|
|
22
|
+
sizeRestrictions: {
|
|
23
|
+
maxWidth: boundary.width,
|
|
24
|
+
maxHeight: boundary.height,
|
|
25
|
+
minWidth: 0,
|
|
26
|
+
minHeight: 0
|
|
27
|
+
},
|
|
28
|
+
width: size.width,
|
|
29
|
+
height: size.height,
|
|
30
|
+
aspectRatio: {
|
|
31
|
+
minimum: ratio(size),
|
|
32
|
+
maximum: ratio(size)
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return size;
|
|
37
|
+
}
|
|
38
|
+
function sizeRestrictions(state, settings) {
|
|
39
|
+
var stencilSize = getStencilSize(state, __assign(__assign({}, settings), { stencilSize: settings.stencilSize }));
|
|
40
|
+
var areaRestrictions = getAreaSizeRestrictions(state, settings);
|
|
41
|
+
return {
|
|
42
|
+
maxWidth: areaRestrictions.maxWidth * stencilSize.width / state.boundary.width,
|
|
43
|
+
maxHeight: areaRestrictions.maxHeight * stencilSize.height / state.boundary.height,
|
|
44
|
+
minWidth: 0,
|
|
45
|
+
minHeight: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function defaultSize(state, settings) {
|
|
49
|
+
var imageSize = state.imageSize, visibleArea = state.visibleArea, boundary = state.boundary;
|
|
50
|
+
var sizeRestrictions2 = getSizeRestrictions(state, settings);
|
|
51
|
+
var aspectRatio2 = getAspectRatio(state, settings);
|
|
52
|
+
var stencilSize = isFunction(settings.stencilSize) ? settings.stencilSize(state, settings) : settings.stencilSize;
|
|
53
|
+
var area = visibleArea || imageSize;
|
|
54
|
+
var height, width;
|
|
55
|
+
if (ratio(area) > ratio(boundary)) {
|
|
56
|
+
height = stencilSize.height * area.height / boundary.height;
|
|
57
|
+
width = height * ratio(stencilSize);
|
|
58
|
+
} else {
|
|
59
|
+
width = stencilSize.width * area.width / boundary.width;
|
|
60
|
+
height = width / ratio(stencilSize);
|
|
61
|
+
}
|
|
62
|
+
return approximateSize({
|
|
63
|
+
width,
|
|
64
|
+
height,
|
|
65
|
+
aspectRatio: aspectRatio2,
|
|
66
|
+
sizeRestrictions: sizeRestrictions2
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function aspectRatio(state, settings) {
|
|
70
|
+
var value = ratio(getStencilSize(state, settings));
|
|
71
|
+
return {
|
|
72
|
+
minimum: value,
|
|
73
|
+
maximum: value
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function fixedStencilAlgorithm(state, settings) {
|
|
77
|
+
if (isInitializedState(state)) {
|
|
78
|
+
var result = copyState(state);
|
|
79
|
+
var stencil = getStencilSize(state, settings);
|
|
80
|
+
result.visibleArea = applyScale(result.visibleArea, result.coordinates.width * result.boundary.width / (result.visibleArea.width * stencil.width));
|
|
81
|
+
var scale = fitToSizeRestrictions(result.visibleArea, getAreaSizeRestrictions(result, settings));
|
|
82
|
+
if (scale !== 1) {
|
|
83
|
+
result.visibleArea = applyScale(result.visibleArea, scale);
|
|
84
|
+
result.coordinates = applyScale(result.coordinates, scale);
|
|
85
|
+
}
|
|
86
|
+
result.visibleArea = applyMove(result.visibleArea, diff(getCenter(result.coordinates), getCenter(result.visibleArea)));
|
|
87
|
+
result.visibleArea = moveToPositionRestrictions(result.visibleArea, getAreaPositionRestrictions(result, settings));
|
|
88
|
+
result.coordinates = moveToPositionRestrictions(result.coordinates, mergePositionRestrictions(coordinatesToPositionRestrictions(result.visibleArea), getAreaPositionRestrictions(result, settings)));
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
return state;
|
|
92
|
+
}
|
|
93
|
+
function fixedStencil(state, settings, action) {
|
|
94
|
+
if (action && action.immediately) {
|
|
95
|
+
return fixedStencilAlgorithm(state, settings);
|
|
96
|
+
}
|
|
97
|
+
return state;
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
aspectRatio,
|
|
101
|
+
defaultSize,
|
|
102
|
+
fixedStencil,
|
|
103
|
+
fixedStencilAlgorithm,
|
|
104
|
+
fixedStencilConstraints,
|
|
105
|
+
getStencilSize,
|
|
106
|
+
sizeRestrictions
|
|
107
|
+
};
|