Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/explorer / lib / components / CropPanel / CropOptions.js
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useMemo, useState, useEffect } from 'react';
import { useExplorer } from '../../hooks';
import { DEFAULT_CROP_TYPE } from './CropPanel.constants';
import { convertObjToArray, roundNum } from './CropPanel.utils';
import ImageResize from './ImageResize';
import Option from './Option';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var CropOptions = function CropOptions(_ref) {
  var _selectedCropTypePres;
  var _ref$imageParams = _ref.imageParams,
    imageParams = _ref$imageParams === void 0 ? {} : _ref$imageParams,
    _ref$cropDimensions = _ref.cropDimensions,
    cropDimensions = _ref$cropDimensions === void 0 ? {} : _ref$cropDimensions,
    updateTransformations = _ref.updateTransformations,
    handleCropChange = _ref.handleCropChange,
    setImageParams = _ref.setImageParams,
    selections = _ref.selections;
  var _useExplorer = useExplorer(),
    i18n = _useExplorer.i18n,
    _useExplorer$opts = _useExplorer.opts,
    _useExplorer$opts2 = _useExplorer$opts === void 0 ? {} : _useExplorer$opts,
    _useExplorer$opts2$cr = _useExplorer$opts2.cropPresets,
    cropPresets = _useExplorer$opts2$cr === void 0 ? {} : _useExplorer$opts2$cr;
  var file = selections[0];
  var _useState = useState(DEFAULT_CROP_TYPE),
    _useState2 = _slicedToArray(_useState, 2),
    cropType = _useState2[0],
    setCropType = _useState2[1];
  var _useState3 = useState(null),
    _useState4 = _slicedToArray(_useState3, 2),
    cropPreset = _useState4[0],
    setCropPreset = _useState4[1];
  var _useState5 = useState(true),
    _useState6 = _slicedToArray(_useState5, 2),
    isRatioLocked = _useState6[0],
    setIsRatioLocked = _useState6[1];
  useEffect(function () {
    var newParams = _objectSpread(_objectSpread({}, imageParams), {}, {
      func: ''
    });
    setImageParams(newParams);
    updateTransformations(newParams);
  }, []);
  var availableCropTypes = useMemo(function () {
    return [DEFAULT_CROP_TYPE].concat(_toConsumableArray(convertObjToArray(cropPresets)));
  }, [cropPresets]);
  var selectedCropTypePresets = cropPresets[cropType];
  var changeCropPreset = function changeCropPreset(value) {
    var _value$split = value.split(':'),
      _value$split2 = _slicedToArray(_value$split, 3),
      widthOrRatio = _value$split2[0],
      height = _value$split2[1],
      autoResize = _value$split2[2];
    setCropPreset(value);
    if (!widthOrRatio && !height) {
      return;
    }
    if (widthOrRatio && !height) {
      handleCropChange(_objectSpread(_objectSpread({}, imageParams), {}, {
        crop: _objectSpread(_objectSpread({}, cropDimensions), {}, {
          autoResize: false,
          ratio: widthOrRatio
        })
      }));
      return;
    }
    var isAutoResizeEnabled = autoResize === 'true';
    var newWidth = roundNum(parseInt(widthOrRatio));
    var newHeight = roundNum(parseInt(height));
    handleCropChange(_objectSpread(_objectSpread(_objectSpread({}, imageParams), isAutoResizeEnabled ? {
      width: newWidth,
      height: newHeight
    } : {}), {}, {
      crop: _objectSpread(_objectSpread({}, cropDimensions), {}, {
        width: newWidth,
        height: newHeight,
        autoResize: isAutoResizeEnabled,
        ratio: newWidth / newHeight
      })
    }));
  };
  var updateCropType = function updateCropType(newCropType) {
    setCropType(newCropType);
    var newSelectedCropTypePresets = cropPresets[newCropType];
    if (newSelectedCropTypePresets) {
      var _newSelectedCropTypeP;
      changeCropPreset(Array.isArray(newSelectedCropTypePresets) ? (_newSelectedCropTypeP = newSelectedCropTypePresets[0]) === null || _newSelectedCropTypeP === void 0 ? void 0 : _newSelectedCropTypeP.value : newSelectedCropTypePresets === null || newSelectedCropTypePresets === void 0 ? void 0 : newSelectedCropTypePresets.value);
    } else {
      handleCropChange(_objectSpread(_objectSpread({}, imageParams), {}, {
        crop: _objectSpread(_objectSpread({}, cropDimensions), {}, {
          autoResize: false,
          ratio: DEFAULT_CROP_TYPE === newCropType ? 'custom' : newCropType
        })
      }));
    }
  };
  var updateImageParams = function updateImageParams(newCropDimens) {
    // TODO(Amr): this function overwrites the image resize params used in imageOptions
    // we should split the state
    handleCropChange(_objectSpread(_objectSpread({}, imageParams), {}, {
      crop: _objectSpread(_objectSpread({}, cropDimensions), {}, {
        width: roundNum(parseInt(newCropDimens.width)),
        height: roundNum(parseInt(newCropDimens.height))
      })
    }));
  };
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsx(Option, {
      label: i18n('exportOptionsPresetLabel'),
      value: cropType,
      options: availableCropTypes,
      onChange: updateCropType,
      block: true,
      i18nKeyPrefix: "exportOptionsCropType"
    }), selectedCropTypePresets && Array.isArray(selectedCropTypePresets) && selectedCropTypePresets.length > 0 && /*#__PURE__*/_jsx(Option, {
      label: i18n("".concat(cropType)) || i18n(cropType) || cropType,
      value: cropPreset || ((_selectedCropTypePres = selectedCropTypePresets[0]) === null || _selectedCropTypePres === void 0 ? void 0 : _selectedCropTypePres.value),
      options: selectedCropTypePresets,
      onChange: changeCropPreset,
      block: true,
      i18nKeyPrefix: "exportOptionsCropType".concat(cropType, "Presets")
    }), /*#__PURE__*/_jsx(ImageResize, {
      imageParams: cropDimensions,
      setImageParams: updateImageParams,
      isRatioLocked: isRatioLocked,
      setIsRatioLocked: setIsRatioLocked,
      ratio: cropDimensions.width / cropDimensions.height,
      hideOptions: true,
      file: file
    })]
  });
};
export default CropOptions;