dune-react 0.0.43 → 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.
Files changed (55) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +6 -0
  2. package/dist/_virtual/index.js +4 -0
  3. package/dist/components/puck-base/media.d.ts +1 -0
  4. package/dist/components/puck-base/media.js +272 -129
  5. package/dist/components/puck-block/gallery-sections/static-grid/static-grid.js +14 -10
  6. package/dist/components/puck-block/testimonial-sections/bento-testimonial/component.js +7 -6
  7. package/dist/components/puck-core/core/props/index.js +7 -0
  8. package/dist/components/shadcn/slider.js +1 -1
  9. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/flipImageAlgorithm.js +44 -0
  10. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/moveCoordinatesAlgorithm.js +8 -0
  11. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/resizeCoordinatesAlgorithm.js +291 -0
  12. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/rotateImageAlgorithm.js +38 -0
  13. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/transformImageAlgorithm.js +84 -0
  14. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/animation/index.js +78 -0
  15. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/boundary/index.js +31 -0
  16. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/canvas/index.js +94 -0
  17. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/constants/index.js +8 -0
  18. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaPositionRestrictions.js +51 -0
  19. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaSizeRestrictions.js +30 -0
  20. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultBoundary.js +10 -0
  21. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPosition.js +12 -0
  22. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPositionRestrictions.js +17 -0
  23. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSize.js +31 -0
  24. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSizeRestrictions.js +16 -0
  25. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultStencilConstraints.js +13 -0
  26. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultVisibleArea.js +49 -0
  27. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/index.js +84 -0
  28. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/extensions/stencil-size/index.js +107 -0
  29. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/image/index.js +350 -0
  30. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/instance/AbstractCropperInstance.js +494 -0
  31. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/approximateSize.js +30 -0
  32. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitCoordinates.js +30 -0
  33. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitVisibleArea.js +26 -0
  34. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/helpers.js +125 -0
  35. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/imageTransforms.js +83 -0
  36. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/interactions.js +19 -0
  37. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/normalize.js +83 -0
  38. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/sizeRestrictions.js +58 -0
  39. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/utils.js +313 -0
  40. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/copyState.js +7 -0
  41. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/createState.js +41 -0
  42. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/moveCoordinates.js +15 -0
  43. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/reconcileState.js +44 -0
  44. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/resizeCoordinates.js +22 -0
  45. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setBoundary.js +31 -0
  46. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setCoordinates.js +83 -0
  47. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setVisibleArea.js +18 -0
  48. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/transformImage.js +18 -0
  49. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/types/index.js +16 -0
  50. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/utils/index.js +268 -0
  51. package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +63 -0
  52. 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
  53. package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +181 -0
  54. package/dist/style.css +406 -0
  55. package/package.json +21 -20
@@ -0,0 +1,125 @@
1
+ import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
2
+ import { emptyCoordinates, isFunction, isNumber, isBoolean } from "../utils/index.js";
3
+ import { createAspectRatio, getBrokenRatio, ratio, isConsistentSize, isConsistentPosition, moveToPositionRestrictions, rotateSize } from "./utils.js";
4
+ import { calculateAreaSizeRestrictions, calculateSizeRestrictions } from "./sizeRestrictions.js";
5
+ function isInitializedState(state) {
6
+ return Boolean(state && state.visibleArea && state.coordinates);
7
+ }
8
+ function getAreaSizeRestrictions(state, settings) {
9
+ return calculateAreaSizeRestrictions(state, settings);
10
+ }
11
+ function getAreaPositionRestrictions(state, settings) {
12
+ return isFunction(settings.areaPositionRestrictions) ? settings.areaPositionRestrictions(state, settings) : settings.areaPositionRestrictions;
13
+ }
14
+ function getSizeRestrictions(state, settings) {
15
+ return calculateSizeRestrictions(state, settings);
16
+ }
17
+ function getPositionRestrictions(state, settings) {
18
+ return isFunction(settings.positionRestrictions) ? settings.positionRestrictions(state, settings) : settings.positionRestrictions;
19
+ }
20
+ function getCoefficient(state) {
21
+ return state.visibleArea ? state.visibleArea.width / state.boundary.width : 0;
22
+ }
23
+ function getStencilCoordinates(state) {
24
+ if (isInitializedState(state)) {
25
+ var _a = state.coordinates, width = _a.width, height = _a.height, left = _a.left, top_1 = _a.top;
26
+ var coefficient = getCoefficient(state);
27
+ return {
28
+ width: width / coefficient,
29
+ height: height / coefficient,
30
+ left: (left - state.visibleArea.left) / coefficient,
31
+ top: (top_1 - state.visibleArea.top) / coefficient
32
+ };
33
+ } else {
34
+ return emptyCoordinates();
35
+ }
36
+ }
37
+ function getAspectRatio(state, settings) {
38
+ return createAspectRatio(isFunction(settings.aspectRatio) ? settings.aspectRatio(state, settings) : settings.aspectRatio);
39
+ }
40
+ function getDefaultCoordinates(state, settings) {
41
+ return isFunction(settings.defaultCoordinates) ? settings.defaultCoordinates(state, settings) : settings.defaultCoordinates;
42
+ }
43
+ function getDefaultVisibleArea(state, settings) {
44
+ return isFunction(settings.defaultVisibleArea) ? settings.defaultVisibleArea(state, settings) : settings.defaultVisibleArea;
45
+ }
46
+ function getDefaultTransforms(state, settings) {
47
+ var transforms = __assign(__assign({}, state.transforms), { flip: __assign({}, state.transforms.flip) });
48
+ if (settings.defaultTransforms) {
49
+ var defaultTransforms = isFunction(settings.defaultTransforms) ? settings.defaultTransforms(state, settings) : settings.defaultTransforms;
50
+ if (isNumber(defaultTransforms.rotate)) {
51
+ transforms.rotate = defaultTransforms.rotate;
52
+ }
53
+ if (defaultTransforms.flip) {
54
+ if (isBoolean(defaultTransforms.flip.horizontal)) {
55
+ transforms.flip.horizontal = defaultTransforms.flip.horizontal;
56
+ }
57
+ if (isBoolean(defaultTransforms.flip.vertical)) {
58
+ transforms.flip.vertical = defaultTransforms.flip.vertical;
59
+ }
60
+ }
61
+ }
62
+ return transforms;
63
+ }
64
+ function getTransformedImageSize(state) {
65
+ if (state.imageSize && state.imageSize.width && state.imageSize.height) {
66
+ return rotateSize(state.imageSize, state.transforms.rotate);
67
+ } else {
68
+ return {
69
+ width: 0,
70
+ height: 0
71
+ };
72
+ }
73
+ }
74
+ function getMinimumSize(state) {
75
+ return state.coordinates ? Math.min(state.coordinates.width, state.coordinates.height, 20 * getCoefficient(state)) : 1;
76
+ }
77
+ function getRoundedCoordinates(state, settings) {
78
+ if (isInitializedState(state)) {
79
+ var sizeRestrictions = getSizeRestrictions(state, settings);
80
+ var positionRestrictions = getPositionRestrictions(state, settings);
81
+ var roundCoordinates = {
82
+ width: Math.round(state.coordinates.width),
83
+ height: Math.round(state.coordinates.height),
84
+ left: Math.round(state.coordinates.left),
85
+ top: Math.round(state.coordinates.top)
86
+ };
87
+ if (roundCoordinates.width > sizeRestrictions.maxWidth) {
88
+ roundCoordinates.width = Math.floor(state.coordinates.width);
89
+ } else if (roundCoordinates.width < sizeRestrictions.minWidth) {
90
+ roundCoordinates.width = Math.ceil(state.coordinates.width);
91
+ }
92
+ if (roundCoordinates.height > sizeRestrictions.maxHeight) {
93
+ roundCoordinates.height = Math.floor(state.coordinates.height);
94
+ } else if (roundCoordinates.height < sizeRestrictions.minHeight) {
95
+ roundCoordinates.height = Math.ceil(state.coordinates.height);
96
+ }
97
+ return moveToPositionRestrictions(roundCoordinates, positionRestrictions);
98
+ } else {
99
+ return null;
100
+ }
101
+ }
102
+ function isConsistentState(state, settings) {
103
+ if (isInitializedState(state)) {
104
+ return !getBrokenRatio(ratio(state.coordinates), getAspectRatio(state, settings)) && isConsistentSize(state.visibleArea, getAreaSizeRestrictions(state, settings)) && isConsistentSize(state.coordinates, getSizeRestrictions(state, settings)) && isConsistentPosition(state.visibleArea, getAreaPositionRestrictions(state, settings)) && isConsistentPosition(state.coordinates, getPositionRestrictions(state, settings));
105
+ } else {
106
+ return true;
107
+ }
108
+ }
109
+ export {
110
+ getAreaPositionRestrictions,
111
+ getAreaSizeRestrictions,
112
+ getAspectRatio,
113
+ getCoefficient,
114
+ getDefaultCoordinates,
115
+ getDefaultTransforms,
116
+ getDefaultVisibleArea,
117
+ getMinimumSize,
118
+ getPositionRestrictions,
119
+ getRoundedCoordinates,
120
+ getSizeRestrictions,
121
+ getStencilCoordinates,
122
+ getTransformedImageSize,
123
+ isConsistentState,
124
+ isInitializedState
125
+ };
@@ -0,0 +1,83 @@
1
+ import { isRoughlyEqual, sign, distance } from "../utils/index.js";
2
+ function calculateGeometricProperties(touches, container) {
3
+ var _a = container.getBoundingClientRect(), left = _a.left, top = _a.top;
4
+ var centerMass = { left: 0, top: 0 };
5
+ var spread = 0;
6
+ touches.forEach(function(touch) {
7
+ centerMass.left += (touch.clientX - left) / touches.length;
8
+ centerMass.top += (touch.clientY - top) / touches.length;
9
+ });
10
+ touches.forEach(function(touch) {
11
+ spread += distance({ left: centerMass.left, top: centerMass.top }, { left: touch.clientX - left, top: touch.clientY - top });
12
+ });
13
+ return { centerMass, spread, count: touches.length };
14
+ }
15
+ function touchesToImageTransform(touches, previousTouches, container, options) {
16
+ if (options === void 0) {
17
+ options = {};
18
+ }
19
+ var move, scale, rotate;
20
+ if (previousTouches.length === 1 && touches.length === 1) {
21
+ if (options.move) {
22
+ move = {
23
+ left: previousTouches[0].clientX - touches[0].clientX,
24
+ top: previousTouches[0].clientY - touches[0].clientY
25
+ };
26
+ }
27
+ } else if (touches.length > 1) {
28
+ var previousProperties = calculateGeometricProperties(previousTouches, container);
29
+ var properties = calculateGeometricProperties(touches, container);
30
+ if (options.rotate && previousTouches.length === 2 && touches.length === 2) {
31
+ var diffs = {
32
+ left: [
33
+ touches[0].clientX - touches[1].clientX,
34
+ previousTouches[0].clientX - previousTouches[1].clientX
35
+ ],
36
+ top: [touches[0].clientY - touches[1].clientY, previousTouches[0].clientY - previousTouches[1].clientY]
37
+ };
38
+ var y = diffs.left[0] * diffs.top[1] - diffs.left[1] * diffs.top[0];
39
+ var x = diffs.left[0] * diffs.left[1] + diffs.top[0] * diffs.top[1];
40
+ if (!isRoughlyEqual(x, 0) && !isRoughlyEqual(y, 0)) {
41
+ var radians = Math.atan2(y, x);
42
+ var angle = -(radians * 180) / Math.PI;
43
+ rotate = {
44
+ center: properties.centerMass,
45
+ angle
46
+ };
47
+ }
48
+ }
49
+ if (options.move) {
50
+ move = {
51
+ left: previousProperties.centerMass.left - properties.centerMass.left,
52
+ top: previousProperties.centerMass.top - properties.centerMass.top
53
+ };
54
+ }
55
+ if (options.scale) {
56
+ scale = {
57
+ factor: properties.spread / previousProperties.spread,
58
+ center: properties.centerMass
59
+ };
60
+ }
61
+ }
62
+ return {
63
+ move,
64
+ scale,
65
+ rotate
66
+ };
67
+ }
68
+ function wheelEventToImageTransform(event, container, ratio) {
69
+ if (ratio === void 0) {
70
+ ratio = 0.1;
71
+ }
72
+ var _a = container.getBoundingClientRect(), left = _a.left, top = _a.top;
73
+ var factor = 1 - ratio * sign(event.deltaY || event.detail || event.wheelDelta);
74
+ var center = {
75
+ left: event.clientX - left,
76
+ top: event.clientY - top
77
+ };
78
+ return { scale: { factor, center } };
79
+ }
80
+ export {
81
+ touchesToImageTransform,
82
+ wheelEventToImageTransform
83
+ };
@@ -0,0 +1,19 @@
1
+ function hasInteractions(interactions) {
2
+ return interactions.moveCoordinates || interactions.resizeCoordinates || interactions.transformImage.move || interactions.transformImage.rotate || interactions.transformImage.flip || interactions.transformImage.scale;
3
+ }
4
+ function getEmptyInteractions() {
5
+ return {
6
+ moveCoordinates: false,
7
+ resizeCoordinates: false,
8
+ transformImage: {
9
+ rotate: false,
10
+ move: false,
11
+ scale: false,
12
+ flip: false
13
+ }
14
+ };
15
+ }
16
+ export {
17
+ getEmptyInteractions,
18
+ hasInteractions
19
+ };
@@ -0,0 +1,83 @@
1
+ import { isNumber } from "../utils/index.js";
2
+ import { getCoefficient } from "./helpers.js";
3
+ function normalizeResizeDirections(state, directions) {
4
+ var coefficient = getCoefficient(state);
5
+ return {
6
+ left: isNumber(directions.left) ? directions.left * coefficient : 0,
7
+ top: isNumber(directions.top) ? directions.top * coefficient : 0,
8
+ right: isNumber(directions.right) ? directions.right * coefficient : 0,
9
+ bottom: isNumber(directions.bottom) ? directions.bottom * coefficient : 0
10
+ };
11
+ }
12
+ function normalizeCenter(state, center) {
13
+ var coefficient = getCoefficient(state);
14
+ if (state.visibleArea) {
15
+ return {
16
+ left: center.left * coefficient + state.visibleArea.left,
17
+ top: center.top * coefficient + state.visibleArea.top
18
+ };
19
+ }
20
+ return center;
21
+ }
22
+ function normalizeFlip(state, flip) {
23
+ if (state) {
24
+ var normalizedAngle = Math.abs(state.transforms.rotate % 180);
25
+ if (normalizedAngle <= 45 || normalizedAngle >= 135) {
26
+ return flip;
27
+ } else {
28
+ return {
29
+ horizontal: flip.vertical,
30
+ vertical: flip.horizontal
31
+ };
32
+ }
33
+ }
34
+ return flip;
35
+ }
36
+ function fillMoveDirections(directions) {
37
+ return {
38
+ left: isNumber(directions.left) ? directions.left : 0,
39
+ top: isNumber(directions.top) ? directions.top : 0
40
+ };
41
+ }
42
+ function fillResizeDirections(directions) {
43
+ return {
44
+ left: isNumber(directions.left) ? directions.left : 0,
45
+ top: isNumber(directions.top) ? directions.top : 0,
46
+ right: isNumber(directions.right) ? directions.right : 0,
47
+ bottom: isNumber(directions.bottom) ? directions.bottom : 0
48
+ };
49
+ }
50
+ function normalizeMoveDirections(state, directions) {
51
+ var coefficient = getCoefficient(state);
52
+ return {
53
+ left: isNumber(directions.left) ? directions.left * coefficient : 0,
54
+ top: isNumber(directions.top) ? directions.top * coefficient : 0
55
+ };
56
+ }
57
+ function normalizeImageTransform(state, transform) {
58
+ if (transform.scale) {
59
+ transform.scale = {
60
+ factor: isNumber(transform.scale) ? transform.scale : transform.scale.factor,
61
+ center: !isNumber(transform.scale) && transform.scale.center ? normalizeCenter(state, transform.scale.center) : void 0
62
+ };
63
+ }
64
+ if (transform.rotate) {
65
+ transform.rotate = {
66
+ angle: isNumber(transform.rotate) ? transform.rotate : transform.rotate.angle,
67
+ center: !isNumber(transform.rotate) && transform.rotate.center ? normalizeCenter(state, transform.rotate.center) : void 0
68
+ };
69
+ }
70
+ if (transform.move) {
71
+ transform.move = normalizeMoveDirections(state, transform.move);
72
+ }
73
+ return transform;
74
+ }
75
+ export {
76
+ fillMoveDirections,
77
+ fillResizeDirections,
78
+ normalizeCenter,
79
+ normalizeFlip,
80
+ normalizeImageTransform,
81
+ normalizeMoveDirections,
82
+ normalizeResizeDirections
83
+ };
@@ -0,0 +1,58 @@
1
+ import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
2
+ import { isFunction, isNumeric, parseNumber } from "../utils/index.js";
3
+ import { ratio } from "./utils.js";
4
+ import { getPositionRestrictions } from "./helpers.js";
5
+ function reconcileSizeRestrictions(sizeRestrictions) {
6
+ var restrictions = __assign({}, sizeRestrictions);
7
+ if (restrictions.minWidth > restrictions.maxWidth) {
8
+ restrictions.minWidth = restrictions.maxWidth;
9
+ }
10
+ if (restrictions.minHeight > restrictions.maxHeight) {
11
+ restrictions.minHeight = restrictions.maxHeight;
12
+ }
13
+ return restrictions;
14
+ }
15
+ function mergeSizeRestrictions(a, b) {
16
+ var first = a;
17
+ var second = __assign({ minWidth: 0, minHeight: 0, maxWidth: Infinity, maxHeight: Infinity }, b);
18
+ return reconcileSizeRestrictions({
19
+ maxHeight: Math.min(first.maxHeight, second.maxHeight),
20
+ minHeight: Math.max(first.minHeight, second.minHeight),
21
+ maxWidth: Math.min(first.maxWidth, second.maxWidth),
22
+ minWidth: Math.max(first.minWidth, second.minWidth)
23
+ });
24
+ }
25
+ function calculateSizeRestrictions(state, settings) {
26
+ var sizeRestrictions = isFunction(settings.sizeRestrictions) ? settings.sizeRestrictions(state, settings) : settings.sizeRestrictions;
27
+ var positionRestrictions = getPositionRestrictions(state, settings);
28
+ var restrictions = {
29
+ minWidth: isNumeric(sizeRestrictions.minWidth) ? parseNumber(sizeRestrictions.minWidth) : 0,
30
+ minHeight: isNumeric(sizeRestrictions.minHeight) ? parseNumber(sizeRestrictions.minHeight) : 0,
31
+ maxWidth: isNumeric(sizeRestrictions.maxWidth) ? parseNumber(sizeRestrictions.maxWidth) : Infinity,
32
+ maxHeight: isNumeric(sizeRestrictions.maxHeight) ? parseNumber(sizeRestrictions.maxHeight) : Infinity
33
+ };
34
+ if (positionRestrictions.left !== void 0 && positionRestrictions.right !== void 0) {
35
+ restrictions.maxWidth = Math.min(restrictions.maxWidth, positionRestrictions.right - positionRestrictions.left);
36
+ }
37
+ if (positionRestrictions.bottom !== void 0 && positionRestrictions.top !== void 0) {
38
+ restrictions.maxHeight = Math.min(restrictions.maxHeight, positionRestrictions.bottom - positionRestrictions.top);
39
+ }
40
+ return reconcileSizeRestrictions(restrictions);
41
+ }
42
+ function calculateAreaSizeRestrictions(state, settings) {
43
+ var sizeRestrictions = isFunction(settings.areaSizeRestrictions) ? settings.areaSizeRestrictions(state, settings) : settings.areaSizeRestrictions;
44
+ if (sizeRestrictions.maxWidth < Infinity && sizeRestrictions.maxHeight < Infinity) {
45
+ if (ratio(state.boundary) > sizeRestrictions.maxWidth / sizeRestrictions.maxHeight) {
46
+ sizeRestrictions.maxHeight = sizeRestrictions.maxWidth / ratio(state.boundary);
47
+ } else {
48
+ sizeRestrictions.maxWidth = sizeRestrictions.maxHeight * ratio(state.boundary);
49
+ }
50
+ }
51
+ return reconcileSizeRestrictions(sizeRestrictions);
52
+ }
53
+ export {
54
+ calculateAreaSizeRestrictions,
55
+ calculateSizeRestrictions,
56
+ mergeSizeRestrictions,
57
+ reconcileSizeRestrictions
58
+ };
@@ -0,0 +1,313 @@
1
+ import { __assign } from "../../../../tslib@2.8.1/node_modules/tslib/tslib.es6.js";
2
+ import { ALL_DIRECTIONS } from "../constants/index.js";
3
+ import { isNumber, isNumeric, isFunction, isLower, isUndefined, isGreater } from "../utils/index.js";
4
+ function diff(firstObject, secondObject) {
5
+ return {
6
+ left: firstObject.left - secondObject.left,
7
+ top: firstObject.top - secondObject.top
8
+ };
9
+ }
10
+ function getCenter(object) {
11
+ return {
12
+ left: object.left + object.width / 2,
13
+ top: object.top + object.height / 2
14
+ };
15
+ }
16
+ function getOppositeSide(side) {
17
+ return {
18
+ left: "right",
19
+ top: "bottom",
20
+ right: "left",
21
+ bottom: "top"
22
+ }[side];
23
+ }
24
+ function sizeDistance(a, b) {
25
+ return Math.pow(a.width - b.width, 2) + Math.pow(a.height - b.height, 2);
26
+ }
27
+ function applyDirections(coordinates, directions) {
28
+ return {
29
+ left: coordinates.left - directions.left,
30
+ top: coordinates.top - directions.top,
31
+ width: coordinates.width + directions.left + directions.right,
32
+ height: coordinates.height + directions.top + directions.bottom
33
+ };
34
+ }
35
+ function inverseMove(directions) {
36
+ return {
37
+ left: -directions.left,
38
+ top: -directions.top
39
+ };
40
+ }
41
+ function applyMove(object, move) {
42
+ return __assign(__assign({}, object), { left: object.left + move.left, top: object.top + move.top });
43
+ }
44
+ function coordinatesToPositionRestrictions(coordinates) {
45
+ return {
46
+ left: coordinates.left,
47
+ top: coordinates.top,
48
+ right: coordinates.left + coordinates.width,
49
+ bottom: coordinates.top + coordinates.height
50
+ };
51
+ }
52
+ function applyScale(object, factor, center, progress) {
53
+ if (factor !== 1) {
54
+ if ("left" in object || "top" in object) {
55
+ if (center) {
56
+ var currentCenter = getCenter(object);
57
+ return {
58
+ width: object.width * factor,
59
+ height: object.height * factor,
60
+ left: object.left + object.width * (1 - factor) / 2 + (center.left - currentCenter.left) * (1 - factor),
61
+ top: object.top + object.height * (1 - factor) / 2 + (center.top - currentCenter.top) * (1 - factor)
62
+ };
63
+ } else {
64
+ return {
65
+ width: object.width * factor,
66
+ height: object.height * factor,
67
+ left: object.left + object.width * (1 - factor) / 2,
68
+ top: object.top + object.height * (1 - factor) / 2
69
+ };
70
+ }
71
+ } else {
72
+ return {
73
+ width: object.width * factor,
74
+ height: object.height * factor
75
+ };
76
+ }
77
+ } else {
78
+ return object;
79
+ }
80
+ }
81
+ function ratio(object) {
82
+ return object.width / object.height;
83
+ }
84
+ function maxScale(size, restrictions) {
85
+ return Math.min(restrictions.maxWidth ? restrictions.maxWidth / size.width : Infinity, restrictions.maxHeight ? restrictions.maxHeight / size.height : Infinity);
86
+ }
87
+ function minScale(size, restrictions) {
88
+ return Math.max(restrictions.minWidth ? restrictions.minWidth / size.width : 0, restrictions.minHeight ? restrictions.minHeight / size.height : 0);
89
+ }
90
+ function getBrokenRatio(currentAspectRatio, aspectRatio) {
91
+ var ratioBroken;
92
+ if (aspectRatio.minimum && isLower(currentAspectRatio, aspectRatio.minimum)) {
93
+ ratioBroken = aspectRatio.minimum;
94
+ } else if (aspectRatio.maximum && isGreater(currentAspectRatio, aspectRatio.maximum)) {
95
+ ratioBroken = aspectRatio.maximum;
96
+ }
97
+ return ratioBroken;
98
+ }
99
+ function fitToSizeRestrictions(coordinates, sizeRestrictions) {
100
+ var aspectRatio = ratio(coordinates);
101
+ var scale = 1;
102
+ if (sizeRestrictions.minWidth > 0 && sizeRestrictions.minHeight > 0) {
103
+ if (aspectRatio > sizeRestrictions.minWidth / sizeRestrictions.minHeight) {
104
+ if (coordinates.height < sizeRestrictions.minHeight) {
105
+ scale = sizeRestrictions.minHeight / coordinates.height;
106
+ }
107
+ } else {
108
+ if (coordinates.width < sizeRestrictions.minWidth) {
109
+ scale = sizeRestrictions.minWidth / coordinates.width;
110
+ }
111
+ }
112
+ } else if (sizeRestrictions.minWidth > 0) {
113
+ if (coordinates.width < sizeRestrictions.minWidth) {
114
+ scale = sizeRestrictions.minWidth / coordinates.width;
115
+ }
116
+ } else if (sizeRestrictions.minHeight > 0) {
117
+ if (coordinates.height < sizeRestrictions.minHeight) {
118
+ scale = sizeRestrictions.minHeight / coordinates.height;
119
+ }
120
+ }
121
+ if (sizeRestrictions.maxWidth < Infinity && sizeRestrictions.maxHeight < Infinity) {
122
+ if (aspectRatio > sizeRestrictions.maxWidth / sizeRestrictions.maxHeight) {
123
+ if (coordinates.width > sizeRestrictions.maxWidth) {
124
+ scale = sizeRestrictions.maxWidth / coordinates.width;
125
+ }
126
+ } else {
127
+ if (coordinates.height > sizeRestrictions.maxHeight) {
128
+ scale = sizeRestrictions.maxHeight / coordinates.height;
129
+ }
130
+ }
131
+ } else if (sizeRestrictions.maxWidth < Infinity) {
132
+ if (coordinates.width > sizeRestrictions.maxWidth) {
133
+ scale = sizeRestrictions.maxWidth / coordinates.width;
134
+ }
135
+ } else if (sizeRestrictions.maxHeight < Infinity) {
136
+ if (coordinates.height > sizeRestrictions.maxHeight) {
137
+ scale = sizeRestrictions.maxHeight / coordinates.height;
138
+ }
139
+ }
140
+ return scale;
141
+ }
142
+ function getIntersections(object, positionRestrictions) {
143
+ var intersections = {
144
+ left: 0,
145
+ top: 0,
146
+ right: 0,
147
+ bottom: 0
148
+ };
149
+ ALL_DIRECTIONS.forEach(function(direction) {
150
+ var areaLimit = positionRestrictions[direction];
151
+ var objectLimit = coordinatesToPositionRestrictions(object)[direction];
152
+ if (areaLimit !== void 0 && objectLimit !== void 0) {
153
+ if (direction === "left" || direction === "top") {
154
+ intersections[direction] = Math.max(0, areaLimit - objectLimit);
155
+ } else {
156
+ intersections[direction] = Math.max(0, objectLimit - areaLimit);
157
+ }
158
+ } else {
159
+ intersections[direction] = 0;
160
+ }
161
+ });
162
+ return intersections;
163
+ }
164
+ function resizeToSizeRestrictions(coordinates, sizeRestrictions) {
165
+ return applyScale(coordinates, fitToSizeRestrictions(coordinates, sizeRestrictions));
166
+ }
167
+ function rotateSize(size, angle) {
168
+ var radians = angle * Math.PI / 180;
169
+ return {
170
+ width: Math.abs(size.width * Math.cos(radians)) + Math.abs(size.height * Math.sin(radians)),
171
+ height: Math.abs(size.width * Math.sin(radians)) + Math.abs(size.height * Math.cos(radians))
172
+ };
173
+ }
174
+ function rotatePoint(point, angle, anchor) {
175
+ var radians = angle * Math.PI / 180;
176
+ if (anchor) {
177
+ return {
178
+ left: (point.left - anchor.left) * Math.cos(radians) - (point.top - anchor.top) * Math.sin(radians) + anchor.left,
179
+ top: (point.left - anchor.left) * Math.sin(radians) + (point.top - anchor.top) * Math.cos(radians) + anchor.top
180
+ };
181
+ } else {
182
+ return {
183
+ left: point.left * Math.cos(radians) - point.top * Math.sin(radians),
184
+ top: point.left * Math.sin(radians) + point.top * Math.cos(radians)
185
+ };
186
+ }
187
+ }
188
+ function positionToSizeRestrictions(positionRestrictions) {
189
+ return {
190
+ minWidth: 0,
191
+ minHeight: 0,
192
+ maxWidth: positionRestrictions.right !== void 0 && positionRestrictions.left !== void 0 ? positionRestrictions.right - positionRestrictions.left : Infinity,
193
+ maxHeight: positionRestrictions.bottom !== void 0 && positionRestrictions.top !== void 0 ? positionRestrictions.bottom - positionRestrictions.top : Infinity
194
+ };
195
+ }
196
+ function mergePositionRestrictions(a, b) {
197
+ var restrictions = {};
198
+ ALL_DIRECTIONS.forEach(function(direction) {
199
+ var firstDirection = a[direction];
200
+ var secondDirection = b[direction];
201
+ if (firstDirection !== void 0 && secondDirection !== void 0) {
202
+ if (direction === "left" || direction === "top") {
203
+ restrictions[direction] = Math.max(firstDirection, secondDirection);
204
+ } else {
205
+ restrictions[direction] = Math.min(firstDirection, secondDirection);
206
+ }
207
+ } else if (secondDirection !== void 0) {
208
+ restrictions[direction] = secondDirection;
209
+ } else if (firstDirection !== void 0) {
210
+ restrictions[direction] = firstDirection;
211
+ }
212
+ });
213
+ return restrictions;
214
+ }
215
+ function fitToPositionRestrictions(coordinates, positionRestrictions) {
216
+ var directions = {
217
+ left: 0,
218
+ top: 0
219
+ };
220
+ var intersection = getIntersections(coordinates, positionRestrictions);
221
+ if (intersection.left && intersection.left > 0) {
222
+ directions.left = intersection.left;
223
+ } else if (intersection.right && intersection.right > 0) {
224
+ directions.left = -intersection.right;
225
+ }
226
+ if (intersection.top && intersection.top > 0) {
227
+ directions.top = intersection.top;
228
+ } else if (intersection.bottom && intersection.bottom > 0) {
229
+ directions.top = -intersection.bottom;
230
+ }
231
+ return directions;
232
+ }
233
+ function moveToPositionRestrictions(coordinates, positionRestrictions) {
234
+ return applyMove(coordinates, fitToPositionRestrictions(coordinates, positionRestrictions));
235
+ }
236
+ function aspectRatioIntersection(main, subset) {
237
+ if (!subset) {
238
+ return main;
239
+ } else if (!main) {
240
+ return subset;
241
+ } else {
242
+ return {
243
+ minimum: Math.min(main.maximum, Math.max(main.minimum, subset.minimum)),
244
+ maximum: Math.max(main.minimum, Math.min(main.maximum, subset.maximum))
245
+ };
246
+ }
247
+ }
248
+ function createAspectRatio(aspectRatio) {
249
+ if (aspectRatio === void 0) {
250
+ aspectRatio = {};
251
+ }
252
+ if (isNumber(aspectRatio)) {
253
+ return {
254
+ minimum: aspectRatio,
255
+ maximum: aspectRatio
256
+ };
257
+ } else {
258
+ return {
259
+ minimum: isNumeric(aspectRatio.minimum) ? aspectRatio.minimum : 0,
260
+ maximum: isNumeric(aspectRatio.maximum) ? aspectRatio.maximum : Infinity
261
+ };
262
+ }
263
+ }
264
+ function isConsistentSize(size, restrictions) {
265
+ return (isUndefined(restrictions.maxWidth) || !isGreater(size.width, restrictions.maxWidth)) && (isUndefined(restrictions.maxHeight) || !isGreater(size.height, restrictions.maxHeight)) && (isUndefined(restrictions.minHeight) || !isLower(size.height, restrictions.minHeight)) && (isUndefined(restrictions.minWidth) || !isLower(size.width, restrictions.minWidth));
266
+ }
267
+ function isConsistentPosition(coordinates, restrictions) {
268
+ return (isUndefined(restrictions.left) || !isLower(coordinates.left, restrictions.left)) && (isUndefined(restrictions.top) || !isLower(coordinates.top, restrictions.top)) && (isUndefined(restrictions.right) || !isGreater(coordinates.left + coordinates.width, restrictions.right)) && (isUndefined(restrictions.bottom) || !isGreater(coordinates.top + coordinates.height, restrictions.bottom));
269
+ }
270
+ function getCloserSize(candidates, reference, sizeRestrictions, aspectRatio) {
271
+ var traverse = function(ignoreMinimum) {
272
+ return candidates.reduce(function(minimum, size) {
273
+ var _a = isFunction(sizeRestrictions) ? sizeRestrictions(size) : sizeRestrictions, maxHeight = _a.maxHeight, maxWidth = _a.maxWidth, minWidth = _a.minWidth, minHeight = _a.minHeight;
274
+ var preparedAspectRatio = createAspectRatio(isFunction(aspectRatio) ? aspectRatio(size) : aspectRatio);
275
+ var preparedSizeRestrictions = ignoreMinimum ? { maxWidth, maxHeight } : { maxWidth, maxHeight, minWidth, minHeight };
276
+ if (isConsistentSize(size, preparedSizeRestrictions) && !getBrokenRatio(ratio(size), preparedAspectRatio) && size.width && size.height) {
277
+ return !minimum || isLower(sizeDistance(size, reference), sizeDistance(minimum, reference)) ? size : minimum;
278
+ } else {
279
+ return minimum;
280
+ }
281
+ }, null);
282
+ };
283
+ return traverse() || traverse(true);
284
+ }
285
+ export {
286
+ applyDirections,
287
+ applyMove,
288
+ applyScale,
289
+ aspectRatioIntersection,
290
+ coordinatesToPositionRestrictions,
291
+ createAspectRatio,
292
+ diff,
293
+ fitToPositionRestrictions,
294
+ fitToSizeRestrictions,
295
+ getBrokenRatio,
296
+ getCenter,
297
+ getCloserSize,
298
+ getIntersections,
299
+ getOppositeSide,
300
+ inverseMove,
301
+ isConsistentPosition,
302
+ isConsistentSize,
303
+ maxScale,
304
+ mergePositionRestrictions,
305
+ minScale,
306
+ moveToPositionRestrictions,
307
+ positionToSizeRestrictions,
308
+ ratio,
309
+ resizeToSizeRestrictions,
310
+ rotatePoint,
311
+ rotateSize,
312
+ sizeDistance
313
+ };
@@ -0,0 +1,7 @@
1
+ import { deepClone } from "../utils/index.js";
2
+ function copyState(state) {
3
+ return deepClone(state);
4
+ }
5
+ export {
6
+ copyState
7
+ };