var _excluded = ["mode", "minFontSizePx", "maxFontSizePx", "fontSizePrecisionPx", "scrollToEnd", "as", "children"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useCallback, useEffect, useRef } from 'react';
import { autoTextSize } from "./auto-text-size-standalone";
export default function AutoResizeText(_ref) {
  var mode = _ref.mode,
    minFontSizePx = _ref.minFontSizePx,
    maxFontSizePx = _ref.maxFontSizePx,
    fontSizePrecisionPx = _ref.fontSizePrecisionPx,
    scrollToEnd = _ref.scrollToEnd,
    _ref$as = _ref.as,
    Comp = _ref$as === void 0 ? 'div' : _ref$as,
    children = _ref.children,
    rest = _objectWithoutProperties(_ref, _excluded);
  var updateTextSizeRef = useRef();
  useEffect(function () {
    var _updateTextSizeRef$cu;
    (_updateTextSizeRef$cu = updateTextSizeRef.current) === null || _updateTextSizeRef$cu === void 0 || _updateTextSizeRef$cu.call(updateTextSizeRef);
  }, [children]);
  var refCallback = useCallback(function (innerEl) {
    var _updateTextSizeRef$cu2;
    (_updateTextSizeRef$cu2 = updateTextSizeRef.current) === null || _updateTextSizeRef$cu2 === void 0 || _updateTextSizeRef$cu2.disconnect();
    var containerEl = innerEl === null || innerEl === void 0 ? void 0 : innerEl.parentElement;
    if (!innerEl || !containerEl) return;
    updateTextSizeRef.current = autoTextSize({
      innerEl: innerEl,
      containerEl: containerEl,
      mode: mode,
      minFontSizePx: minFontSizePx,
      maxFontSizePx: maxFontSizePx,
      fontSizePrecisionPx: fontSizePrecisionPx,
      scrollToEnd: scrollToEnd
    });
  }, [mode, minFontSizePx, maxFontSizePx, fontSizePrecisionPx, scrollToEnd]);
  return /*#__PURE__*/React.createElement(Comp, _extends({
    ref: refCallback
  }, rest), children);
}