Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

advanced-cropper

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

advanced-cropper - npm Package Compare versions

Comparing version 0.14.0 to 0.15.0

2

algorithms/index.js
export { moveCoordinatesAlgorithm } from './moveCoordinatesAlgorithm.js';
export { fitDirections, resizeCoordinatesAlgorithm } from './resizeCoordinatesAlgorithm.js';
export { anchoredResizeCoordinatesAlgorithm, fitDirections, resizeCoordinatesAlgorithm } from './resizeCoordinatesAlgorithm.js';
export { rotateImageAlgorithm } from './rotateImageAlgorithm.js';
export { flipImageAlgorithm } from './flipImageAlgorithm.js';
export { transformImageAlgorithm } from './transformImageAlgorithm.js';

@@ -1,2 +0,2 @@

import { AspectRatio, Coordinates, PositionRestrictions, ResizeDirections, SizeRestrictions } from "../types/index";
import { AspectRatio, Coordinates, MoveDirections, PositionRestrictions, ResizeDirections, SizeRestrictions, ResizeAnchor } from "../types/index";
import { ResizeOptions } from "../state/index";

@@ -8,6 +8,12 @@ interface FitDirectionsParams {

sizeRestrictions: SizeRestrictions;
allowedDirections: {
left?: boolean;
right?: boolean;
top?: boolean;
bottom?: boolean;
};
preserveRatio?: boolean;
compensate?: boolean;
}
declare function fitDirections({ coordinates, directions, positionRestrictions, sizeRestrictions, preserveRatio, compensate, }: FitDirectionsParams): ResizeDirections;
declare function fitDirections({ coordinates, directions, positionRestrictions, sizeRestrictions, preserveRatio, allowedDirections, compensate, }: FitDirectionsParams): ResizeDirections;
interface ResizeLimitations {

@@ -18,3 +24,14 @@ aspectRatio: AspectRatio;

}
declare function resizeCoordinatesAlgorithm(coordinates: Coordinates, directions: ResizeDirections, options: ResizeOptions, limitations: ResizeLimitations): Coordinates;
export { fitDirections, ResizeLimitations, resizeCoordinatesAlgorithm };
declare function resizeCoordinatesAlgorithm(coordinates: Coordinates, directions: ResizeDirections, options: {
compensate?: boolean;
preserveAspectRatio?: boolean;
allowedDirections?: {
left?: boolean;
right?: boolean;
top?: boolean;
bottom?: boolean;
};
respectDirection?: 'width' | 'height';
}, limitations: ResizeLimitations): Coordinates;
declare function anchoredResizeCoordinatesAlgorithm(coordinates: Coordinates, anchor: ResizeAnchor, directions: MoveDirections, options: ResizeOptions, limitations: ResizeLimitations): Coordinates;
export { fitDirections, ResizeLimitations, resizeCoordinatesAlgorithm, anchoredResizeCoordinatesAlgorithm };
import { __assign } from 'tslib';
import { ALL_DIRECTIONS, HORIZONTAL_DIRECTIONS, VERTICAL_DIRECTIONS } from '../constants/index.js';
import { isRoughlyEqual } from '../utils/index.js';
import { applyDirections, getIntersections, ratio, getBrokenRatio } from '../service/utils.js';
import { isGreater, isRoughlyEqual } from '../utils/index.js';
import { moveToPositionRestrictions, applyDirections, getIntersections, getOppositeSide, ratio, getBrokenRatio, applyMove, diff } from '../service/utils.js';
import '../types/index.js';

@@ -10,3 +10,3 @@ import '../state/setCoordinates.js';

function fitDirections(_a) {
var coordinates = _a.coordinates, directions = _a.directions, positionRestrictions = _a.positionRestrictions, sizeRestrictions = _a.sizeRestrictions, preserveRatio = _a.preserveRatio, compensate = _a.compensate;
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;
var fittedDirections = __assign({}, directions);

@@ -46,3 +46,6 @@ var currentWidth = applyDirections(coordinates, fittedDirections).width;

var breaks = getIntersections(applyDirections(coordinates, fittedDirections), positionRestrictions);
if (compensate) {
var canBeCompensated = ALL_DIRECTIONS.every(function (direction) {
return !isGreater(breaks[getOppositeSide(direction)], 0) || allowedDirections[direction];
});
if (compensate && canBeCompensated) {
if (breaks.left && breaks.left > 0 && breaks.right === 0) {

@@ -155,3 +158,3 @@ fittedDirections.right += breaks.left;

var aspectRatio = limitations.aspectRatio, positionRestrictions = limitations.positionRestrictions, sizeRestrictions = limitations.sizeRestrictions;
var actualCoordinates = __assign(__assign({}, coordinates), { right: coordinates.left + coordinates.width, bottom: coordinates.top + coordinates.height });
var actualCoordinates = __assign({}, coordinates);
directions = __assign({}, directions);

@@ -185,2 +188,3 @@ var allowedDirections = options.allowedDirections || {

positionRestrictions: positionRestrictions,
allowedDirections: allowedDirections,
});

@@ -252,2 +256,3 @@ // 2. Second step: fix desired box to correspondent to aspect ratio

compensate: options.compensate,
allowedDirections: allowedDirections,
});

@@ -261,7 +266,5 @@ }

: getBrokenRatio(currentWidth / currentHeight, aspectRatio);
if (ratioBroken && Math.abs(ratioBroken - currentWidth / currentHeight) > 1e-3) {
if (ratioBroken && isGreater(Math.abs(ratioBroken - currentWidth / currentHeight), 0)) {
ALL_DIRECTIONS.forEach(function (direction) {
if (!allowedDirections[direction]) {
directions[direction] = 0;
}
directions[direction] = 0;
});

@@ -279,3 +282,48 @@ }

}
function anchorToMassPoint(coordinates, anchor) {
var plainAnchor = anchor.toLowerCase();
return {
left: coordinates.left +
coordinates.width * (plainAnchor.indexOf('west') !== -1 ? 1 : plainAnchor.indexOf('east') !== -1 ? 0 : 0.5),
top: coordinates.top +
coordinates.height *
(plainAnchor.indexOf('north') !== -1 ? 1 : plainAnchor.indexOf('south') !== -1 ? 0 : 0.5),
};
}
function anchoredResizeCoordinatesAlgorithm(coordinates, anchor, directions, options, limitations) {
var reference = options.reference;
var plainAnchor = anchor.toLowerCase();
var normalizedDirections = {
left: plainAnchor.indexOf('west') === -1 ? directions.left : -directions.left,
top: -directions.top,
right: directions.left,
bottom: directions.top,
};
if (['north', 'south', 'center'].every(function (el) { return plainAnchor.indexOf(el) === -1; })) {
normalizedDirections.top = 0;
normalizedDirections.bottom = 0;
}
if (['west', 'east', 'center'].every(function (el) { return plainAnchor.indexOf(el) === -1; })) {
normalizedDirections.left = 0;
normalizedDirections.right = 0;
}
var allowedDirections = {
left: plainAnchor.indexOf('east') === -1,
top: plainAnchor.indexOf('south') === -1,
right: plainAnchor.indexOf('west') === -1,
bottom: plainAnchor.indexOf('north') === -1,
};
ALL_DIRECTIONS.forEach(function (direction) {
if (!allowedDirections[direction]) {
normalizedDirections[direction] = 0;
}
});
var result = resizeCoordinatesAlgorithm(coordinates, normalizedDirections, __assign(__assign({}, options), { allowedDirections: allowedDirections }), limitations);
if (reference) {
// Move the result to anchor
result = applyMove(result, diff(anchorToMassPoint(reference, anchor), anchorToMassPoint(result, anchor)));
}
return moveToPositionRestrictions(result, limitations.positionRestrictions);
}
export { fitDirections, resizeCoordinatesAlgorithm };
export { anchoredResizeCoordinatesAlgorithm, fitDirections, resizeCoordinatesAlgorithm };
export { debounce, deepClone, deepCompare, distance, emptyCoordinates, getCloserAngle, getDirectionNames, getOptions, isArray, isArrayBufferLike, isBlob, isCardinalDirection, isCrossOriginURL, isDataUrl, isFunction, isGreater, isLocal, isLower, isMouseEvent, isNaN, isNumber, isNumeric, isObject, isOrdinalDirection, isRoughlyEqual, isString, isTouchEvent, isUndefined, isWheelEvent, parseNumber, promiseTimeout, sign } from './utils/index.js';
export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance } from './service/utils.js';
export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getOppositeSide, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance } from './service/utils.js';
export { calculateAreaSizeRestrictions, calculateSizeRestrictions, mergeSizeRestrictions, reconcileSizeRestrictions } from './service/sizeRestrictions.js';

@@ -22,3 +22,3 @@ export { getAreaPositionRestrictions, getAreaSizeRestrictions, getAspectRatio, getCoefficient, getDefaultCoordinates, getDefaultVisibleArea, getMinimumSize, getPositionRestrictions, getRoundedCoordinates, getSizeRestrictions, getStencilCoordinates, getTransformedImageSize, isConsistentState, isInitializedState } from './service/helpers.js';

export { moveCoordinatesAlgorithm } from './algorithms/moveCoordinatesAlgorithm.js';
export { fitDirections, resizeCoordinatesAlgorithm } from './algorithms/resizeCoordinatesAlgorithm.js';
export { anchoredResizeCoordinatesAlgorithm, fitDirections, resizeCoordinatesAlgorithm } from './algorithms/resizeCoordinatesAlgorithm.js';
export { rotateImageAlgorithm } from './algorithms/rotateImageAlgorithm.js';

@@ -25,0 +25,0 @@ export { flipImageAlgorithm } from './algorithms/flipImageAlgorithm.js';

@@ -1,2 +0,2 @@

import { Boundary, CoordinatesTransform, CoreSettings, CropperImage, CropperInteractions, CropperState, CropperTransitionsSettings, DefaultTransforms, ImageTransform, ModifierSettings, MoveDirections, Nullable, PostprocessAction, PostprocessFunction, Priority, ResizeDirections, Rotate, Scale, VisibleArea } from "../types/index";
import { Boundary, CoordinatesTransform, CoreSettings, CropperImage, CropperInteractions, CropperState, CropperTransitionsSettings, DefaultTransforms, ImageTransform, ModifierSettings, MoveDirections, Nullable, PostprocessAction, PostprocessFunction, Priority, ResizeAnchor, Rotate, Scale, VisibleArea } from "../types/index";
import { CreateStateAlgorithm, MoveAlgorithm, ReconcileStateAlgorithm, ResizeAlgorithm, SetBoundaryAlgorithm, SetCoordinatesAlgorithm, SetVisibleAreaAlgorithm, TransformImageAlgorithm } from "../state/index";

@@ -92,3 +92,3 @@ interface TransitionOptions {

moveCoordinatesEnd: (options?: ImmediatelyOptions & TransitionOptions) => void;
resizeCoordinates: (directions: Partial<ResizeDirections>, parameters: unknown, options?: InteractionOptions & ImmediatelyOptions & NormalizeOptions & TransitionOptions) => void;
resizeCoordinates: (anchor: ResizeAnchor, directions: Partial<MoveDirections>, parameters?: unknown, options?: InteractionOptions & ImmediatelyOptions & NormalizeOptions & TransitionOptions) => void;
resizeCoordinatesEnd: (options?: ImmediatelyOptions & TransitionOptions) => void;

@@ -95,0 +95,0 @@ getStencilCoordinates: () => {

@@ -363,3 +363,3 @@ import { __assign, __rest } from 'tslib';

};
this.resizeCoordinates = function (directions, parameters, options) {
this.resizeCoordinates = function (anchor, directions, parameters, options) {
if (options === void 0) { options = {}; }

@@ -375,3 +375,3 @@ var state = _this.getData().state;

: fillResizeDirections(directions);
var result = _this.applyPostProcess({ name: 'resizeCoordinates', interaction: interaction, immediately: immediately, transitions: transitions }, (resizeCoordinatesAlgorithm || resizeCoordinates)(state, settings, normalizedDirections, isObject(parameters) ? parameters : {}));
var result = _this.applyPostProcess({ name: 'resizeCoordinates', interaction: interaction, immediately: immediately, transitions: transitions }, (resizeCoordinatesAlgorithm || resizeCoordinates)(state, settings, anchor, normalizedDirections, isObject(parameters) ? parameters : {}));
callbacks.push(onResize);

@@ -378,0 +378,0 @@ if (interaction) {

@@ -14,2 +14,3 @@ 'use strict';

exports.moveCoordinatesAlgorithm = moveCoordinatesAlgorithm.moveCoordinatesAlgorithm;
exports.anchoredResizeCoordinatesAlgorithm = resizeCoordinatesAlgorithm.anchoredResizeCoordinatesAlgorithm;
exports.fitDirections = resizeCoordinatesAlgorithm.fitDirections;

@@ -16,0 +17,0 @@ exports.resizeCoordinatesAlgorithm = resizeCoordinatesAlgorithm.resizeCoordinatesAlgorithm;

@@ -14,3 +14,3 @@ 'use strict';

function fitDirections(_a) {
var coordinates = _a.coordinates, directions = _a.directions, positionRestrictions = _a.positionRestrictions, sizeRestrictions = _a.sizeRestrictions, preserveRatio = _a.preserveRatio, compensate = _a.compensate;
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;
var fittedDirections = tslib.__assign({}, directions);

@@ -50,3 +50,6 @@ var currentWidth = utils.applyDirections(coordinates, fittedDirections).width;

var breaks = utils.getIntersections(utils.applyDirections(coordinates, fittedDirections), positionRestrictions);
if (compensate) {
var canBeCompensated = index.ALL_DIRECTIONS.every(function (direction) {
return !index$1.isGreater(breaks[utils.getOppositeSide(direction)], 0) || allowedDirections[direction];
});
if (compensate && canBeCompensated) {
if (breaks.left && breaks.left > 0 && breaks.right === 0) {

@@ -159,3 +162,3 @@ fittedDirections.right += breaks.left;

var aspectRatio = limitations.aspectRatio, positionRestrictions = limitations.positionRestrictions, sizeRestrictions = limitations.sizeRestrictions;
var actualCoordinates = tslib.__assign(tslib.__assign({}, coordinates), { right: coordinates.left + coordinates.width, bottom: coordinates.top + coordinates.height });
var actualCoordinates = tslib.__assign({}, coordinates);
directions = tslib.__assign({}, directions);

@@ -189,2 +192,3 @@ var allowedDirections = options.allowedDirections || {

positionRestrictions: positionRestrictions,
allowedDirections: allowedDirections,
});

@@ -256,2 +260,3 @@ // 2. Second step: fix desired box to correspondent to aspect ratio

compensate: options.compensate,
allowedDirections: allowedDirections,
});

@@ -265,7 +270,5 @@ }

: utils.getBrokenRatio(currentWidth / currentHeight, aspectRatio);
if (ratioBroken && Math.abs(ratioBroken - currentWidth / currentHeight) > 1e-3) {
if (ratioBroken && index$1.isGreater(Math.abs(ratioBroken - currentWidth / currentHeight), 0)) {
index.ALL_DIRECTIONS.forEach(function (direction) {
if (!allowedDirections[direction]) {
directions[direction] = 0;
}
directions[direction] = 0;
});

@@ -283,4 +286,50 @@ }

}
function anchorToMassPoint(coordinates, anchor) {
var plainAnchor = anchor.toLowerCase();
return {
left: coordinates.left +
coordinates.width * (plainAnchor.indexOf('west') !== -1 ? 1 : plainAnchor.indexOf('east') !== -1 ? 0 : 0.5),
top: coordinates.top +
coordinates.height *
(plainAnchor.indexOf('north') !== -1 ? 1 : plainAnchor.indexOf('south') !== -1 ? 0 : 0.5),
};
}
function anchoredResizeCoordinatesAlgorithm(coordinates, anchor, directions, options, limitations) {
var reference = options.reference;
var plainAnchor = anchor.toLowerCase();
var normalizedDirections = {
left: plainAnchor.indexOf('west') === -1 ? directions.left : -directions.left,
top: -directions.top,
right: directions.left,
bottom: directions.top,
};
if (['north', 'south', 'center'].every(function (el) { return plainAnchor.indexOf(el) === -1; })) {
normalizedDirections.top = 0;
normalizedDirections.bottom = 0;
}
if (['west', 'east', 'center'].every(function (el) { return plainAnchor.indexOf(el) === -1; })) {
normalizedDirections.left = 0;
normalizedDirections.right = 0;
}
var allowedDirections = {
left: plainAnchor.indexOf('east') === -1,
top: plainAnchor.indexOf('south') === -1,
right: plainAnchor.indexOf('west') === -1,
bottom: plainAnchor.indexOf('north') === -1,
};
index.ALL_DIRECTIONS.forEach(function (direction) {
if (!allowedDirections[direction]) {
normalizedDirections[direction] = 0;
}
});
var result = resizeCoordinatesAlgorithm(coordinates, normalizedDirections, tslib.__assign(tslib.__assign({}, options), { allowedDirections: allowedDirections }), limitations);
if (reference) {
// Move the result to anchor
result = utils.applyMove(result, utils.diff(anchorToMassPoint(reference, anchor), anchorToMassPoint(result, anchor)));
}
return utils.moveToPositionRestrictions(result, limitations.positionRestrictions);
}
exports.anchoredResizeCoordinatesAlgorithm = anchoredResizeCoordinatesAlgorithm;
exports.fitDirections = fitDirections;
exports.resizeCoordinatesAlgorithm = resizeCoordinatesAlgorithm;

@@ -94,2 +94,3 @@ 'use strict';

exports.getIntersections = utils.getIntersections;
exports.getOppositeSide = utils.getOppositeSide;
exports.getTransitionStyle = utils.getTransitionStyle;

@@ -168,2 +169,3 @@ exports.inverseMove = utils.inverseMove;

exports.moveCoordinatesAlgorithm = moveCoordinatesAlgorithm.moveCoordinatesAlgorithm;
exports.anchoredResizeCoordinatesAlgorithm = resizeCoordinatesAlgorithm.anchoredResizeCoordinatesAlgorithm;
exports.fitDirections = resizeCoordinatesAlgorithm.fitDirections;

@@ -170,0 +172,0 @@ exports.resizeCoordinatesAlgorithm = resizeCoordinatesAlgorithm.resizeCoordinatesAlgorithm;

@@ -367,3 +367,3 @@ 'use strict';

};
this.resizeCoordinates = function (directions, parameters, options) {
this.resizeCoordinates = function (anchor, directions, parameters, options) {
if (options === void 0) { options = {}; }

@@ -379,3 +379,3 @@ var state = _this.getData().state;

: normalize.fillResizeDirections(directions);
var result = _this.applyPostProcess({ name: 'resizeCoordinates', interaction: interaction, immediately: immediately, transitions: transitions }, (resizeCoordinatesAlgorithm || resizeCoordinates.resizeCoordinates)(state, settings, normalizedDirections, index.isObject(parameters) ? parameters : {}));
var result = _this.applyPostProcess({ name: 'resizeCoordinates', interaction: interaction, immediately: immediately, transitions: transitions }, (resizeCoordinatesAlgorithm || resizeCoordinates.resizeCoordinates)(state, settings, anchor, normalizedDirections, index.isObject(parameters) ? parameters : {}));
callbacks.push(onResize);

@@ -382,0 +382,0 @@ if (interaction) {

@@ -30,2 +30,3 @@ 'use strict';

exports.getIntersections = utils.getIntersections;
exports.getOppositeSide = utils.getOppositeSide;
exports.getTransitionStyle = utils.getTransitionStyle;

@@ -32,0 +33,0 @@ exports.inverseMove = utils.inverseMove;

@@ -21,2 +21,10 @@ 'use strict';

}
function getOppositeSide(side) {
return {
left: 'right',
top: 'bottom',
right: 'left',
bottom: 'top',
}[side];
}
function sizeDistance(a, b) {

@@ -347,2 +355,3 @@ return Math.pow(a.width - b.width, 2) + Math.pow(a.height - b.height, 2);

exports.getIntersections = getIntersections;
exports.getOppositeSide = getOppositeSide;
exports.getTransitionStyle = getTransitionStyle;

@@ -349,0 +358,0 @@ exports.inverseMove = inverseMove;

@@ -42,3 +42,3 @@ 'use strict';

}
function resizeCoordinates(state, settings, directions, options) {
function resizeCoordinates(state, settings, anchor, directions, options) {
if (helpers.isInitializedState(state)) {

@@ -49,3 +49,3 @@ var result = copyState.copyState(state);

var sizeRestrictions = helpers.getSizeRestrictions(result, settings);
result.coordinates = resizeCoordinatesAlgorithm.resizeCoordinatesAlgorithm(result.coordinates, directions, options, {
result.coordinates = resizeCoordinatesAlgorithm.anchoredResizeCoordinatesAlgorithm(result.coordinates, anchor, directions, tslib.__assign(tslib.__assign({}, options), { compensate: false }), {
positionRestrictions: utils.mergePositionRestrictions(helpers.getPositionRestrictions(result, settings), utils.coordinatesToPositionRestrictions(result.visibleArea)),

@@ -52,0 +52,0 @@ sizeRestrictions: {

@@ -13,7 +13,7 @@ 'use strict';

function resizeCoordinates(state, settings, directions, options) {
function resizeCoordinates(state, settings, anchor, directions, options) {
var minimumSize = helpers.getMinimumSize(state);
var sizeRestrictions = helpers.getSizeRestrictions(state, settings);
return helpers.isInitializedState(state)
? tslib.__assign(tslib.__assign({}, copyState.copyState(state)), { coordinates: resizeCoordinatesAlgorithm.resizeCoordinatesAlgorithm(state.coordinates, directions, options, {
? tslib.__assign(tslib.__assign({}, copyState.copyState(state)), { coordinates: resizeCoordinatesAlgorithm.anchoredResizeCoordinatesAlgorithm(state.coordinates, anchor, directions, options, {
positionRestrictions: utils.mergePositionRestrictions(helpers.getPositionRestrictions(state, settings), utils.coordinatesToPositionRestrictions(state.visibleArea)),

@@ -20,0 +20,0 @@ sizeRestrictions: {

{
"name": "advanced-cropper",
"version": "0.14.0",
"version": "0.15.0",
"description": "The core of the advanced cropper libraries family",

@@ -5,0 +5,0 @@ "author": "Norserium",

@@ -1,2 +0,2 @@

export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance } from './utils.js';
export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getOppositeSide, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance } from './utils.js';
export { calculateAreaSizeRestrictions, calculateSizeRestrictions, mergeSizeRestrictions, reconcileSizeRestrictions } from './sizeRestrictions.js';

@@ -3,0 +3,0 @@ export { getAreaPositionRestrictions, getAreaSizeRestrictions, getAspectRatio, getCoefficient, getDefaultCoordinates, getDefaultVisibleArea, getMinimumSize, getPositionRestrictions, getRoundedCoordinates, getSizeRestrictions, getStencilCoordinates, getTransformedImageSize, isConsistentState, isInitializedState } from './helpers.js';

@@ -1,4 +0,5 @@

import { AspectRatio, Coordinates, CropperTransitions, Diff, Intersections, MoveDirections, Point, PositionRestrictions, RawAspectRatio, ResizeDirections, Size, SizeRestrictions } from "../types/index";
import { AspectRatio, Coordinates, CropperTransitions, Diff, Intersections, MoveDirections, Point, PositionDirection, PositionRestrictions, RawAspectRatio, ResizeDirections, Size, SizeRestrictions } from "../types/index";
declare function diff(firstObject: Point, secondObject: Point): Diff;
declare function getCenter(object: Coordinates): Point;
declare function getOppositeSide(side: PositionDirection): PositionDirection;
declare function sizeDistance(a: Size, b: Size): number;

@@ -45,2 +46,2 @@ declare function applyDirections(coordinates: Coordinates, directions: ResizeDirections): Coordinates;

declare function getCloserSize(candidates: Size[], reference: Size, sizeRestrictions: Partial<SizeRestrictions> | ((size: Size) => Partial<SizeRestrictions>), aspectRatio: RawAspectRatio | ((size: Size) => RawAspectRatio)): Size | null;
export { diff, getCenter, sizeDistance, applyDirections, inverseMove, applyMove, coordinatesToPositionRestrictions, applyScale, ratio, maxScale, minScale, getBrokenRatio, fitToSizeRestrictions, getIntersections, resizeToSizeRestrictions, rotateSize, rotatePoint, positionToSizeRestrictions, mergePositionRestrictions, fitToPositionRestrictions, moveToPositionRestrictions, aspectRatioIntersection, createAspectRatio, getTransitionStyle, isConsistentSize, isConsistentPosition, getCloserSize };
export { diff, getCenter, getOppositeSide, sizeDistance, applyDirections, inverseMove, applyMove, coordinatesToPositionRestrictions, applyScale, ratio, maxScale, minScale, getBrokenRatio, fitToSizeRestrictions, getIntersections, resizeToSizeRestrictions, rotateSize, rotatePoint, positionToSizeRestrictions, mergePositionRestrictions, fitToPositionRestrictions, moveToPositionRestrictions, aspectRatioIntersection, createAspectRatio, getTransitionStyle, isConsistentSize, isConsistentPosition, getCloserSize };

@@ -17,2 +17,10 @@ import { __assign } from 'tslib';

}
function getOppositeSide(side) {
return {
left: 'right',
top: 'bottom',
right: 'left',
bottom: 'top',
}[side];
}
function sizeDistance(a, b) {

@@ -330,2 +338,2 @@ return Math.pow(a.width - b.width, 2) + Math.pow(a.height - b.height, 2);

export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance };
export { applyDirections, applyMove, applyScale, aspectRatioIntersection, coordinatesToPositionRestrictions, createAspectRatio, diff, fitToPositionRestrictions, fitToSizeRestrictions, getBrokenRatio, getCenter, getCloserSize, getIntersections, getOppositeSide, getTransitionStyle, inverseMove, isConsistentPosition, isConsistentSize, maxScale, mergePositionRestrictions, minScale, moveToPositionRestrictions, positionToSizeRestrictions, ratio, resizeToSizeRestrictions, rotatePoint, rotateSize, sizeDistance };

@@ -1,2 +0,2 @@

import { Coordinates, CoreSettings, CropperState, ImageTransform, InitializedCropperState, PostprocessAction, RawAspectRatio, ResizeDirections } from "../../types/index";
import { Coordinates, CoreSettings, CropperState, ImageTransform, InitializedCropperState, PostprocessAction, RawAspectRatio, ResizeAnchor, ResizeDirections } from "../../types/index";
import { ResizeOptions } from "../../state/index";

@@ -22,3 +22,3 @@ import { BoundingBoxType, FitToImageSettings } from "../../extensions/fit-to-image/index";

declare function transformImage(state: ExtendedState, settings: CoreSettings, transform: ImageTransform): CropperState;
declare function resizeCoordinates(state: CropperState, settings: CoreSettings & FitToImageSettings, directions: ResizeDirections, options: ResizeOptions): CropperState;
declare function resizeCoordinates(state: CropperState, settings: CoreSettings & FitToImageSettings, anchor: ResizeAnchor, directions: ResizeDirections, options: ResizeOptions): CropperState;
declare function defaultSize(state: CropperState, settings: CoreSettings): {

@@ -25,0 +25,0 @@ width: number;

@@ -9,3 +9,3 @@ import { __assign } from 'tslib';

import { transformImage as transformImage$1 } from '../../state/transformImage.js';
import { resizeCoordinatesAlgorithm } from '../../algorithms/resizeCoordinatesAlgorithm.js';
import { anchoredResizeCoordinatesAlgorithm } from '../../algorithms/resizeCoordinatesAlgorithm.js';
import { defaultStencilConstraints } from '../../defaults/defaultStencilConstraints.js';

@@ -39,3 +39,3 @@ import { BoundingBoxType } from '../../extensions/fit-to-image/types.js';

}
function resizeCoordinates(state, settings, directions, options) {
function resizeCoordinates(state, settings, anchor, directions, options) {
if (isInitializedState(state)) {

@@ -46,3 +46,3 @@ var result = copyState(state);

var sizeRestrictions = getSizeRestrictions(result, settings);
result.coordinates = resizeCoordinatesAlgorithm(result.coordinates, directions, options, {
result.coordinates = anchoredResizeCoordinatesAlgorithm(result.coordinates, anchor, directions, __assign(__assign({}, options), { compensate: false }), {
positionRestrictions: mergePositionRestrictions(getPositionRestrictions(result, settings), coordinatesToPositionRestrictions(result.visibleArea)),

@@ -49,0 +49,0 @@ sizeRestrictions: {

@@ -1,15 +0,10 @@

import { CoreSettings, CropperState, ResizeDirections } from "../types/index";
import { Coordinates, CoreSettings, CropperState, MoveDirections, ResizeAnchor } from "../types/index";
interface ResizeOptions {
compensate?: boolean;
preserveAspectRatio?: boolean;
allowedDirections?: {
left?: boolean;
right?: boolean;
top?: boolean;
bottom?: boolean;
};
respectDirection?: 'width' | 'height';
reference?: Coordinates | null;
}
type ResizeAlgorithm<Settings extends CoreSettings = CoreSettings> = (state: CropperState, settings: Settings, directions: ResizeDirections, options: ResizeOptions) => CropperState;
declare function resizeCoordinates(state: CropperState, settings: CoreSettings, directions: ResizeDirections, options: ResizeOptions): CropperState;
type ResizeAlgorithm<Settings extends CoreSettings = CoreSettings> = (state: CropperState, settings: Settings, anchor: ResizeAnchor, directions: MoveDirections, options: ResizeOptions) => CropperState;
declare function resizeCoordinates(state: CropperState, settings: CoreSettings, anchor: ResizeAnchor, directions: MoveDirections, options: ResizeOptions): CropperState;
export { ResizeOptions, ResizeAlgorithm, resizeCoordinates };

@@ -7,9 +7,9 @@ import { __assign } from 'tslib';

import './setCoordinates.js';
import { resizeCoordinatesAlgorithm } from '../algorithms/resizeCoordinatesAlgorithm.js';
import { anchoredResizeCoordinatesAlgorithm } from '../algorithms/resizeCoordinatesAlgorithm.js';
function resizeCoordinates(state, settings, directions, options) {
function resizeCoordinates(state, settings, anchor, directions, options) {
var minimumSize = getMinimumSize(state);
var sizeRestrictions = getSizeRestrictions(state, settings);
return isInitializedState(state)
? __assign(__assign({}, copyState(state)), { coordinates: resizeCoordinatesAlgorithm(state.coordinates, directions, options, {
? __assign(__assign({}, copyState(state)), { coordinates: anchoredResizeCoordinatesAlgorithm(state.coordinates, anchor, directions, options, {
positionRestrictions: mergePositionRestrictions(getPositionRestrictions(state, settings), coordinatesToPositionRestrictions(state.visibleArea)),

@@ -16,0 +16,0 @@ sizeRestrictions: {

@@ -54,2 +54,3 @@ type TimingFunction = string;

}
type ResizeAnchor = OrdinalDirection | 'center';
type RawAspectRatio = Partial<AspectRatio> | number;

@@ -199,2 +200,2 @@ interface Diff {

};
export { TimingFunction, Coordinates, VisibleArea, Limits, SizeRestrictions, AreaSizeRestrictions, PositionRestrictions, AreaPositionRestrictions, ResizeDirections, MoveDirections, Point, Size, ImageSize, Boundary, Intersections, AspectRatio, RawAspectRatio, Diff, Position, ImageRestriction, Priority, PositionDirection, HorizontalDirection, VerticalDirection, MainDirections, HorizontalCardinalDirection, VerticalCardinalDirection, CardinalDirection, OrdinalDirection, Scale, Rotate, Flip, Transforms, PartialTransforms, ImageTransform, CoordinatesTransform, CropperState, InitializedCropperState, BoundarySizeAlgorithm, DefaultSize, DefaultPosition, DefaultVisibleArea, DefaultCoordinates, CoreSettings, BivarianceConstraint, ModifierSettings, CropperImage, CropperTransitions, CropperInteractions, CropperTransitionsSettings, SimpleTouch, PostprocessAction, PostprocessFunction, Nullable, DefaultTransforms, DebouncedFunction };
export { TimingFunction, Coordinates, VisibleArea, Limits, SizeRestrictions, AreaSizeRestrictions, PositionRestrictions, AreaPositionRestrictions, ResizeDirections, MoveDirections, Point, Size, ImageSize, Boundary, Intersections, AspectRatio, ResizeAnchor, RawAspectRatio, Diff, Position, ImageRestriction, Priority, PositionDirection, HorizontalDirection, VerticalDirection, MainDirections, HorizontalCardinalDirection, VerticalCardinalDirection, CardinalDirection, OrdinalDirection, Scale, Rotate, Flip, Transforms, PartialTransforms, ImageTransform, CoordinatesTransform, CropperState, InitializedCropperState, BoundarySizeAlgorithm, DefaultSize, DefaultPosition, DefaultVisibleArea, DefaultCoordinates, CoreSettings, BivarianceConstraint, ModifierSettings, CropperImage, CropperTransitions, CropperInteractions, CropperTransitionsSettings, SimpleTouch, PostprocessAction, PostprocessFunction, Nullable, DefaultTransforms, DebouncedFunction };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc