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.
Files changed (56) 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/puck-core/core/with-editable.js +4 -5
  9. package/dist/components/shadcn/slider.js +1 -1
  10. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/flipImageAlgorithm.js +44 -0
  11. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/moveCoordinatesAlgorithm.js +8 -0
  12. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/resizeCoordinatesAlgorithm.js +291 -0
  13. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/rotateImageAlgorithm.js +38 -0
  14. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/algorithms/transformImageAlgorithm.js +84 -0
  15. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/animation/index.js +78 -0
  16. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/boundary/index.js +31 -0
  17. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/canvas/index.js +94 -0
  18. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/constants/index.js +8 -0
  19. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaPositionRestrictions.js +51 -0
  20. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultAreaSizeRestrictions.js +30 -0
  21. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultBoundary.js +10 -0
  22. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPosition.js +12 -0
  23. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultPositionRestrictions.js +17 -0
  24. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSize.js +31 -0
  25. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultSizeRestrictions.js +16 -0
  26. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultStencilConstraints.js +13 -0
  27. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/defaultVisibleArea.js +49 -0
  28. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/defaults/index.js +84 -0
  29. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/extensions/stencil-size/index.js +107 -0
  30. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/image/index.js +350 -0
  31. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/instance/AbstractCropperInstance.js +494 -0
  32. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/approximateSize.js +30 -0
  33. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitCoordinates.js +30 -0
  34. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/fitVisibleArea.js +26 -0
  35. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/helpers.js +125 -0
  36. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/imageTransforms.js +83 -0
  37. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/interactions.js +19 -0
  38. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/normalize.js +83 -0
  39. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/sizeRestrictions.js +58 -0
  40. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/service/utils.js +313 -0
  41. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/copyState.js +7 -0
  42. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/createState.js +41 -0
  43. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/moveCoordinates.js +15 -0
  44. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/reconcileState.js +44 -0
  45. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/resizeCoordinates.js +22 -0
  46. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setBoundary.js +31 -0
  47. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setCoordinates.js +83 -0
  48. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/setVisibleArea.js +18 -0
  49. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/state/transformImage.js +18 -0
  50. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/types/index.js +16 -0
  51. package/dist/node_modules/.pnpm/advanced-cropper@0.17.1/node_modules/advanced-cropper/utils/index.js +268 -0
  52. package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +63 -0
  53. 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
  54. package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +181 -0
  55. package/dist/style.css +406 -0
  56. package/package.json +21 -20
@@ -2,6 +2,7 @@ import { buttonsField, badgeField } from "./interactive.js";
2
2
  import { actionDefaults, actionField, buttonDefaults, buttonField, iconField, resolveActionUrl } from "./interactive.js";
3
3
  import { descriptionField, headingField, featuresField } from "./content.js";
4
4
  import { cardField, cardsField } from "./content.js";
5
+ import { getPlaceholderMediaUrl, media16x9Placeholder, media1x1Placeholder, media9x16Placeholder, mediaField, mediasField } from "./media.js";
5
6
  const contentFields = {
6
7
  heading: headingField,
7
8
  description: descriptionField,
@@ -28,7 +29,13 @@ export {
28
29
  contentFieldsWithFeatures,
29
30
  descriptionField,
30
31
  featuresField,
32
+ getPlaceholderMediaUrl,
31
33
  headingField,
32
34
  iconField,
35
+ media16x9Placeholder,
36
+ media1x1Placeholder,
37
+ media9x16Placeholder,
38
+ mediaField,
39
+ mediasField,
33
40
  resolveActionUrl
34
41
  };
@@ -3,7 +3,6 @@ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { useRef, useEffect, useCallback } from "react";
4
4
  import { registerOverlayPortal } from "@puckeditor/core";
5
5
  import { usePuckDispatch, usePuckAppState } from "./hooks.js";
6
- import { Pencil } from "lucide-react";
7
6
  import { useEditorContext } from "./context/editor-context.js";
8
7
  import set from "../../../node_modules/.pnpm/lodash-es@4.17.23/node_modules/lodash-es/set.js";
9
8
  const BLOCK_LEVEL_TYPES = /* @__PURE__ */ new Set(["image", "media"]);
@@ -94,8 +93,8 @@ function withEditable(Component, config) {
94
93
  transform: `scale(${inverseScale})`,
95
94
  transformOrigin: "center center"
96
95
  },
97
- className: "flex h-8 w-8 items-center justify-center rounded-full bg-black/50 shadow-md backdrop-blur-sm",
98
- children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-white" })
96
+ className: "flex items-center justify-center rounded-full bg-black/50 px-2 py-1 shadow-md backdrop-blur-sm",
97
+ children: /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-white", children: "Edit" })
99
98
  }
100
99
  ) })
101
100
  ] });
@@ -106,8 +105,8 @@ function withEditable(Component, config) {
106
105
  "span",
107
106
  {
108
107
  onClick: handleEdit,
109
- className: "flex h-8 w-8 items-center justify-center rounded-full bg-black/50 shadow-md backdrop-blur-sm",
110
- children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4 text-white" })
108
+ className: "flex items-center justify-center rounded-full bg-black/50 px-2 py-1 shadow-md backdrop-blur-sm",
109
+ children: /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-white", children: "Edit" })
111
110
  }
112
111
  ) })
113
112
  ] });
@@ -34,7 +34,7 @@ function Slider({
34
34
  Slider$1.Track,
35
35
  {
36
36
  "data-slot": "slider-track",
37
- className: "relative grow overflow-hidden rounded-full bg-muted select-none data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1",
37
+ className: "relative grow overflow-hidden rounded-full bg-muted-foreground/20 select-none data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1",
38
38
  children: /* @__PURE__ */ jsx(
39
39
  Slider$1.Indicator,
40
40
  {
@@ -0,0 +1,44 @@
1
+ import { rotatePoint, getCenter, applyMove, diff, moveToPositionRestrictions } from "../service/utils.js";
2
+ import { isInitializedState, getTransformedImageSize, getAreaPositionRestrictions } from "../service/helpers.js";
3
+ import { copyState } from "../state/copyState.js";
4
+ function flipImageAlgorithm(state, settings, horizontal, vertical) {
5
+ if (isInitializedState(state)) {
6
+ var result = copyState(state);
7
+ var rotate = state.transforms.rotate;
8
+ var imageSize = getTransformedImageSize(state);
9
+ var changed = {
10
+ horizontal,
11
+ vertical
12
+ };
13
+ if (changed.horizontal || changed.vertical) {
14
+ var imageCenter = rotatePoint({
15
+ left: imageSize.width / 2,
16
+ top: imageSize.height / 2
17
+ }, -rotate);
18
+ var oldCenter = rotatePoint(getCenter(result.coordinates), -rotate);
19
+ var newCenter = rotatePoint({
20
+ left: changed.horizontal ? imageCenter.left - (oldCenter.left - imageCenter.left) : oldCenter.left,
21
+ top: changed.vertical ? imageCenter.top - (oldCenter.top - imageCenter.top) : oldCenter.top
22
+ }, rotate);
23
+ result.coordinates = applyMove(result.coordinates, diff(newCenter, getCenter(result.coordinates)));
24
+ oldCenter = rotatePoint(getCenter(result.visibleArea), -rotate);
25
+ newCenter = rotatePoint({
26
+ left: changed.horizontal ? imageCenter.left - (oldCenter.left - imageCenter.left) : oldCenter.left,
27
+ top: changed.vertical ? imageCenter.top - (oldCenter.top - imageCenter.top) : oldCenter.top
28
+ }, rotate);
29
+ result.visibleArea = applyMove(result.visibleArea, diff(newCenter, getCenter(result.visibleArea)));
30
+ result.visibleArea = moveToPositionRestrictions(result.visibleArea, getAreaPositionRestrictions(result, settings));
31
+ }
32
+ if (changed.horizontal) {
33
+ result.transforms.flip.horizontal = !state.transforms.flip.horizontal;
34
+ }
35
+ if (changed.vertical) {
36
+ result.transforms.flip.vertical = !state.transforms.flip.vertical;
37
+ }
38
+ return result;
39
+ }
40
+ return state;
41
+ }
42
+ export {
43
+ flipImageAlgorithm
44
+ };
@@ -0,0 +1,8 @@
1
+ import { applyMove, moveToPositionRestrictions } from "../service/utils.js";
2
+ function moveCoordinatesAlgorithm(coordinates, directions, positionRestrictions) {
3
+ var movedCoordinates = applyMove(coordinates, directions);
4
+ return positionRestrictions ? moveToPositionRestrictions(movedCoordinates, positionRestrictions) : movedCoordinates;
5
+ }
6
+ export {
7
+ moveCoordinatesAlgorithm
8
+ };
@@ -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
+ };