@uxf/core 11.19.0 → 11.21.0

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 (54) hide show
  1. package/README.md +1 -1
  2. package/components/hide.d.ts +3 -0
  3. package/components/hide.js +3 -0
  4. package/components/show.d.ts +3 -0
  5. package/components/show.js +3 -0
  6. package/hooks/_useSimulatedButton.d.ts +3 -0
  7. package/hooks/_useSimulatedButton.js +3 -0
  8. package/hooks/useAnchorProps.d.ts +6 -0
  9. package/hooks/useAnchorProps.js +3 -0
  10. package/hooks/useBodyScrollLock.d.ts +6 -0
  11. package/hooks/useBodyScrollLock.js +3 -0
  12. package/hooks/useButtonProps.d.ts +6 -0
  13. package/hooks/useButtonProps.js +3 -0
  14. package/hooks/useClickableProps.d.ts +6 -0
  15. package/hooks/useClickableProps.js +3 -0
  16. package/hooks/useFocusReturn.d.ts +3 -0
  17. package/hooks/useFocusReturn.js +3 -0
  18. package/hooks/useFocusTrap.d.ts +3 -0
  19. package/hooks/useFocusTrap.js +3 -0
  20. package/hooks/useInputFocus.d.ts +3 -0
  21. package/hooks/useInputFocus.js +3 -0
  22. package/hooks/useIsMounted.d.ts +3 -0
  23. package/hooks/useIsMounted.js +3 -0
  24. package/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
  25. package/hooks/useIsomorphicLayoutEffect.js +3 -0
  26. package/hooks/useKey.d.ts +9 -0
  27. package/hooks/useKey.js +3 -0
  28. package/hooks/useLatest.d.ts +3 -0
  29. package/hooks/useLatest.js +3 -0
  30. package/hooks/useMinWindowWidth.d.ts +3 -0
  31. package/hooks/useMinWindowWidth.js +3 -0
  32. package/hooks/useMouseDragToScroll.d.ts +3 -0
  33. package/hooks/useMouseDragToScroll.js +3 -0
  34. package/hooks/useOnMount.d.ts +3 -0
  35. package/hooks/useOnMount.js +3 -0
  36. package/hooks/useOnUnmount.d.ts +3 -0
  37. package/hooks/useOnUnmount.js +3 -0
  38. package/hooks/useOnUpdate.d.ts +3 -0
  39. package/hooks/useOnUpdate.js +3 -0
  40. package/hooks/usePagination.d.ts +3 -0
  41. package/hooks/usePagination.js +3 -0
  42. package/hooks/usePrevious.d.ts +3 -0
  43. package/hooks/usePrevious.js +3 -0
  44. package/hooks/useRafState.d.ts +3 -0
  45. package/hooks/useRafState.js +3 -0
  46. package/hooks/useWindowScroll.d.ts +3 -0
  47. package/hooks/useWindowScroll.js +3 -0
  48. package/hooks/useWindowSize.d.ts +3 -0
  49. package/hooks/useWindowSize.js +3 -0
  50. package/package.json +1 -1
  51. package/utils/composeRefs.d.ts +3 -0
  52. package/utils/composeRefs.js +3 -0
  53. package/utils/image.d.ts +14 -4
  54. package/utils/image.js +77 -51
package/README.md CHANGED
@@ -74,7 +74,7 @@ cookie.set("cookie-name", "value", /* ttl in seconds (optional) */, /* options (
74
74
  cookie.delete("cookie-name", /* options (optional) */);
75
75
  ```
76
76
 
77
- ## Hooks
77
+ ## Hooks - @deprecated - will be moved to @uxf/core-react
78
78
 
79
79
  ```tsx
80
80
  import { useBodyScrollLock } from "@uxf/core/hooks/useBodyScrollLock";
@@ -3,5 +3,8 @@ interface HideProps {
3
3
  when: boolean;
4
4
  children?: ReactNode;
5
5
  }
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  export declare function Hide(props: HideProps): React.JSX.Element | null;
7
10
  export {};
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Hide = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * @deprecated Use import from @uxf/core-react instead.
10
+ */
8
11
  function Hide(props) {
9
12
  if (props.when) {
10
13
  return null;
@@ -3,5 +3,8 @@ interface ShowProps {
3
3
  when: boolean;
4
4
  children?: ReactNode;
5
5
  }
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  export declare function Show(props: ShowProps): React.JSX.Element | null;
7
10
  export {};
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Show = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * @deprecated Use import from @uxf/core-react instead.
10
+ */
8
11
  function Show(props) {
9
12
  if (!props.when) {
10
13
  return null;
@@ -8,6 +8,9 @@ interface Props<T extends HTMLElement> {
8
8
  onKeyUp?: KeyboardEventHandler<T>;
9
9
  submit?: boolean;
10
10
  }
11
+ /**
12
+ * @deprecated Use import from @uxf/core-react instead.
13
+ */
11
14
  export declare function _useSimulatedButton<T extends HTMLElement>({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, submit, }: Props<T>): {
12
15
  onClick: MouseEventHandler<T>;
13
16
  onKeyDown: KeyboardEventHandler<T>;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._useSimulatedButton = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, submit, }) {
6
9
  const _onClick = (0, react_1.useCallback)((e) => {
7
10
  var _a;
@@ -1,8 +1,14 @@
1
1
  import { AnchorHTMLAttributes } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export interface UseAnchorProps {
3
6
  analyticsCallback?: () => void;
4
7
  disabled?: boolean;
5
8
  loading?: boolean;
6
9
  type?: "submit";
7
10
  }
11
+ /**
12
+ * @deprecated Use import from @uxf/core-react instead.
13
+ */
8
14
  export declare function useAnchorProps<T extends AnchorHTMLAttributes<HTMLAnchorElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, download, href, hrefLang, loading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }: UseAnchorProps & T): T;
@@ -4,6 +4,9 @@ exports.useAnchorProps = void 0;
4
4
  const classes_1 = require("../constants/classes");
5
5
  const cx_1 = require("../utils/cx");
6
6
  const _useSimulatedButton_1 = require("./_useSimulatedButton");
7
+ /**
8
+ * @deprecated Use import from @uxf/core-react instead.
9
+ */
7
10
  function useAnchorProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, download, href, hrefLang, loading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }) {
8
11
  const isBusy = loading ? loading : Boolean(ariaBusy);
9
12
  const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
@@ -1,6 +1,12 @@
1
1
  import { RefObject } from "react";
2
2
  import { BodyScrollOptions } from "../utils/bodyScrollLock";
3
+ /**
4
+ * @deprecated Use import from @uxf/core-react instead.
5
+ */
3
6
  export interface UseBodyScrollLockOptions extends BodyScrollOptions {
4
7
  clearAllOnClose?: boolean;
5
8
  }
9
+ /**
10
+ * @deprecated Use import from @uxf/core-react instead.
11
+ */
6
12
  export declare function useBodyScrollLock<T extends HTMLElement>(containerRef: RefObject<T>, isOpen: boolean, { allowTouchMove, clearAllOnClose, reserveScrollBarGap }?: Partial<UseBodyScrollLockOptions>): void;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBodyScrollLock = void 0;
4
4
  const react_1 = require("react");
5
5
  const bodyScrollLock_1 = require("../utils/bodyScrollLock");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useBodyScrollLock(containerRef, isOpen, { allowTouchMove, clearAllOnClose, reserveScrollBarGap } = {}) {
7
10
  (0, react_1.useEffect)(() => {
8
11
  const node = containerRef.current;
@@ -1,6 +1,12 @@
1
1
  import { ButtonHTMLAttributes } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export interface UseButtonProps {
3
6
  analyticsCallback?: () => void;
4
7
  loading?: boolean;
5
8
  }
9
+ /**
10
+ * @deprecated Use import from @uxf/core-react instead.
11
+ */
6
12
  export declare function useButtonProps<T extends ButtonHTMLAttributes<HTMLButtonElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }: UseButtonProps & T): T;
@@ -4,6 +4,9 @@ exports.useButtonProps = void 0;
4
4
  const react_1 = require("react");
5
5
  const classes_1 = require("../constants/classes");
6
6
  const cx_1 = require("../utils/cx");
7
+ /**
8
+ * @deprecated Use import from @uxf/core-react instead.
9
+ */
7
10
  function useButtonProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }) {
8
11
  const isBusy = loading ? loading : Boolean(ariaBusy);
9
12
  const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
@@ -1,8 +1,14 @@
1
1
  import { HTMLAttributes } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export interface UseClickableProps {
3
6
  analyticsCallback?: () => void;
4
7
  disabled?: boolean;
5
8
  loading?: boolean;
6
9
  type?: "submit";
7
10
  }
11
+ /**
12
+ * @deprecated Use import from @uxf/core-react instead.
13
+ */
8
14
  export declare function useClickableProps<T extends HTMLAttributes<HTMLElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, loading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }: UseClickableProps & T): T;
@@ -4,6 +4,9 @@ exports.useClickableProps = void 0;
4
4
  const classes_1 = require("../constants/classes");
5
5
  const cx_1 = require("../utils/cx");
6
6
  const _useSimulatedButton_1 = require("./_useSimulatedButton");
7
+ /**
8
+ * @deprecated Use import from @uxf/core-react instead.
9
+ */
7
10
  function useClickableProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, disabled, loading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }) {
8
11
  const isBusy = loading ? loading : Boolean(ariaBusy);
9
12
  const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
@@ -1 +1,4 @@
1
+ /**
2
+ * @deprecated Use import from @uxf/core-react instead.
3
+ */
1
4
  export declare function useFocusReturn(opened: boolean, transitionDuration?: number, shouldReturnFocus?: boolean): () => void;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFocusReturn = void 0;
4
4
  const react_1 = require("react");
5
5
  const useOnUpdate_1 = require("./useOnUpdate");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useFocusReturn(opened, transitionDuration = 0, shouldReturnFocus = true) {
7
10
  const lastActiveElement = (0, react_1.useRef)();
8
11
  const returnFocus = () => {
@@ -1,2 +1,5 @@
1
1
  import { RefCallback } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useFocusTrap<T extends HTMLElement>(active?: boolean): RefCallback<T>;
@@ -85,6 +85,9 @@ function createAriaHider(containerNode, selector = "body > :not(script)") {
85
85
  });
86
86
  };
87
87
  }
88
+ /**
89
+ * @deprecated Use import from @uxf/core-react instead.
90
+ */
88
91
  function useFocusTrap(active = true) {
89
92
  const ref = (0, react_1.useRef)();
90
93
  const restoreAria = (0, react_1.useRef)();
@@ -1,4 +1,7 @@
1
1
  import { FocusEventHandler, MouseEventHandler, RefObject } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useInputFocus<T extends HTMLInputElement | HTMLTextAreaElement | HTMLElement>(focusRef: RefObject<T>, onBlur?: FocusEventHandler<T>, onFocus?: FocusEventHandler<T>): {
3
6
  focused: boolean;
4
7
  focus: MouseEventHandler<HTMLElement>;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useInputFocus = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useInputFocus(focusRef, onBlur, onFocus) {
6
9
  const [focused, setFocused] = (0, react_1.useState)(false);
7
10
  const focus = (0, react_1.useCallback)(() => {
@@ -1 +1,4 @@
1
+ /**
2
+ * @deprecated Use import from @uxf/core-react instead.
3
+ */
1
4
  export declare function useIsMounted(): boolean;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useIsMounted = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useIsMounted() {
6
9
  const [isMounted, setIsMounted] = (0, react_1.useState)(false);
7
10
  (0, react_1.useEffect)(() => setIsMounted(true), []);
@@ -1,2 +1,5 @@
1
1
  import { useEffect } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare const useIsomorphicLayoutEffect: typeof useEffect;
@@ -3,4 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useIsomorphicLayoutEffect = void 0;
4
4
  const react_1 = require("react");
5
5
  const isBrowser_1 = require("../utils/isBrowser");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  exports.useIsomorphicLayoutEffect = isBrowser_1.isBrowser ? react_1.useLayoutEffect : react_1.useEffect;
package/hooks/useKey.d.ts CHANGED
@@ -1,10 +1,19 @@
1
1
  import { RefObject } from "react";
2
2
  type KeyPredicate = (e: KeyboardEvent) => boolean;
3
+ /**
4
+ * @deprecated Use import from @uxf/core-react instead.
5
+ */
3
6
  export type KeyFilter = null | undefined | string | KeyPredicate;
7
+ /**
8
+ * @deprecated Use import from @uxf/core-react instead.
9
+ */
4
10
  export interface UseKeyOptions<T extends HTMLElement> {
5
11
  disabled?: boolean;
6
12
  targetRef?: RefObject<T>;
7
13
  type: "keydown" | "keyup" | "keypress";
8
14
  }
15
+ /**
16
+ * @deprecated Use import from @uxf/core-react instead.
17
+ */
9
18
  export declare function useKey<T extends HTMLElement>(keyFilter: KeyFilter, callback: (e: KeyboardEvent) => void, { disabled, targetRef, type }?: Partial<UseKeyOptions<T>>): void;
10
19
  export {};
package/hooks/useKey.js CHANGED
@@ -7,6 +7,9 @@ const createKeyPredicate = (keyFilter) => typeof keyFilter === "function"
7
7
  : typeof keyFilter === "string"
8
8
  ? (e) => e.key === keyFilter
9
9
  : () => false;
10
+ /**
11
+ * @deprecated Use import from @uxf/core-react instead.
12
+ */
10
13
  function useKey(keyFilter, callback, { disabled, targetRef, type = "keydown" } = {}) {
11
14
  (0, react_1.useEffect)(() => {
12
15
  if (disabled) {
@@ -1,2 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useLatest<T>(current: T): import("react").MutableRefObject<T>;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useLatest = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useLatest(current) {
6
9
  const storedValue = (0, react_1.useRef)(current);
7
10
  storedValue.current = current;
@@ -1 +1,4 @@
1
+ /**
2
+ * @deprecated Use import from @uxf/core-react instead.
3
+ */
1
4
  export declare function useMinWindowWidth(minWidth: number, debounce?: number): boolean | undefined;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMinWindowWidth = void 0;
4
4
  const react_1 = require("react");
5
5
  const useRafState_1 = require("./useRafState");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useMinWindowWidth(minWidth, debounce = 0) {
7
10
  const [state, setState] = (0, useRafState_1.useRafState)();
8
11
  (0, react_1.useEffect)(() => {
@@ -1,2 +1,5 @@
1
1
  import { CSSProperties, RefObject } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useMouseDragToScroll<T extends HTMLElement>(containerRef: RefObject<T>): CSSProperties | undefined;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMouseDragToScroll = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useMouseDragToScroll(containerRef) {
6
9
  const position = (0, react_1.useRef)({ left: 0, top: 0, x: 0, y: 0 });
7
10
  const [style, setStyle] = (0, react_1.useState)();
@@ -1,2 +1,5 @@
1
1
  import { EffectCallback } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useOnMount(effect: EffectCallback): void;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOnMount = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useOnMount(effect) {
6
9
  (0, react_1.useEffect)(() => {
7
10
  return effect();
@@ -1,2 +1,5 @@
1
1
  import { EffectCallback } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useOnUnmount(effect: EffectCallback): void;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOnUnmount = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useOnUnmount(effect) {
6
9
  const effectRef = (0, react_1.useRef)(effect);
7
10
  // update the ref each render so if it changed the newest callback will be invoked
@@ -1,2 +1,5 @@
1
1
  import { DependencyList, EffectCallback } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useOnUpdate(effect: EffectCallback, deps: DependencyList): void;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOnUpdate = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function useOnUpdate(effect, deps) {
6
9
  const firstRun = (0, react_1.useRef)(true);
7
10
  (0, react_1.useEffect)(() => {
@@ -1,2 +1,5 @@
1
1
  import { PaginationConfig, PaginationItem } from "../utils/pagination";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare const usePagination: (config: PaginationConfig) => PaginationItem[];
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePagination = void 0;
4
4
  const react_1 = require("react");
5
5
  const pagination_1 = require("../utils/pagination");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  const usePagination = (config) => {
7
10
  return (0, react_1.useMemo)(() => (0, pagination_1.paginationGenerate)(config),
8
11
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,2 +1,5 @@
1
1
  /// <reference types="react" />
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function usePrevious<T>(current: T): import("react").MutableRefObject<T>;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePrevious = void 0;
4
4
  const react_1 = require("react");
5
+ /**
6
+ * @deprecated Use import from @uxf/core-react instead.
7
+ */
5
8
  function usePrevious(current) {
6
9
  const storedValue = (0, react_1.useRef)(current);
7
10
  (0, react_1.useEffect)(() => {
@@ -1,2 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function useRafState<S = undefined>(initialState?: S | (() => S)): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useRafState = void 0;
4
4
  const react_1 = require("react");
5
5
  const useOnUnmount_1 = require("./useOnUnmount");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useRafState(initialState) {
7
10
  const frame = (0, react_1.useRef)(0);
8
11
  const [state, setState] = (0, react_1.useState)(initialState);
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated Use import from @uxf/core-react instead.
3
+ */
1
4
  export declare function useWindowScroll(): {
2
5
  x: number;
3
6
  y: number;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useWindowScroll = void 0;
4
4
  const react_1 = require("react");
5
5
  const useRafState_1 = require("./useRafState");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useWindowScroll() {
7
10
  const [state, setState] = (0, useRafState_1.useRafState)();
8
11
  (0, react_1.useEffect)(() => {
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated Use import from @uxf/core-react instead.
3
+ */
1
4
  export declare function useWindowSize(): {
2
5
  width: number;
3
6
  height: number;
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useWindowSize = void 0;
4
4
  const react_1 = require("react");
5
5
  const useRafState_1 = require("./useRafState");
6
+ /**
7
+ * @deprecated Use import from @uxf/core-react instead.
8
+ */
6
9
  function useWindowSize() {
7
10
  const [state, setState] = (0, useRafState_1.useRafState)();
8
11
  (0, react_1.useEffect)(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.19.0",
3
+ "version": "11.21.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
@@ -1,2 +1,5 @@
1
1
  import { Ref, RefCallback } from "react";
2
+ /**
3
+ * @deprecated Use import from @uxf/core-react instead.
4
+ */
2
5
  export declare function composeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T>;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.composeRefs = void 0;
4
+ /**
5
+ * @deprecated Use import from @uxf/core-react instead.
6
+ */
4
7
  function composeRefs(...refs) {
5
8
  return (value) => refs.forEach((ref) => {
6
9
  if (!ref) {
package/utils/image.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { FC } from "react";
2
- import { ImageSource, ResizerImageProps } from "./resizer";
1
+ import React from "react";
2
+ import { ImageResponse, ImageSource, ResizerImageProps, StaticImageData } from "./resizer";
3
3
  export type Dimension = number | "auto";
4
4
  export type Format = "avif" | "webp" | "original";
5
5
  export type Quality = number | Record<Format, number>;
6
+ export declare function isSrcString(src: ImageSource): src is string;
7
+ export declare function isSrcImageResponse(src: ImageSource): src is ImageResponse;
8
+ export declare function isSrcStaticImageData(src: ImageSource): src is StaticImageData;
9
+ export declare function parseImgExtension(src: string): string | undefined;
6
10
  export declare function getSvgImgUrl(src: ImageSource): string | undefined;
7
11
  export declare function getImgQuality(quality: Quality | undefined, format: Format): number | undefined;
8
12
  export declare function getImgUniqueIdentifier(src: ImageSource): string | undefined;
@@ -11,7 +15,10 @@ export declare function getImgElementWidth(src: ImageSource, width: number | und
11
15
  export type GetImgSrcSetOptions = ResizerImageProps & {
12
16
  maxHiDpi?: 3 | 2 | 1;
13
17
  };
14
- export declare function getImgSrcSet(src?: ImageSource, width?: Dimension, height?: Dimension, options?: GetImgSrcSetOptions): string | undefined;
18
+ export declare function getImgSrcSet(src: ImageSource, width?: Dimension, height?: Dimension, options?: GetImgSrcSetOptions): string | undefined;
19
+ /**
20
+ * @deprecated Use import from @uxf/ui instead.
21
+ */
15
22
  export type ImageSourcesOptions = Omit<GetImgSrcSetOptions, "quality" | "toFormat"> & {
16
23
  isAvifDisabled?: boolean;
17
24
  isWebPDisabled?: boolean;
@@ -25,5 +32,8 @@ interface ImageSourcesProps {
25
32
  src: ImageSource;
26
33
  width: Dimension;
27
34
  }
28
- export declare const ImgSources: FC<ImageSourcesProps>;
35
+ /**
36
+ * @deprecated Use import from @uxf/ui instead.
37
+ */
38
+ export declare function ImgSources(props: ImageSourcesProps): React.JSX.Element | null;
29
39
  export {};
package/utils/image.js CHANGED
@@ -3,93 +3,119 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ImgSources = exports.getImgSrcSet = exports.getImgElementWidth = exports.getImgElementHeight = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = void 0;
6
+ exports.ImgSources = exports.getImgSrcSet = exports.getImgElementWidth = exports.getImgElementHeight = exports.getImgUniqueIdentifier = exports.getImgQuality = exports.getSvgImgUrl = exports.parseImgExtension = exports.isSrcStaticImageData = exports.isSrcImageResponse = exports.isSrcString = void 0;
7
+ const hide_1 = require("@uxf/core-react/components/hide");
7
8
  const react_1 = __importDefault(require("react"));
8
- const hide_1 = require("../components/hide");
9
9
  const file_1 = require("./file");
10
+ const is_empty_1 = require("./is-empty");
11
+ const is_not_nil_1 = require("./is-not-nil");
10
12
  const resizer_1 = require("./resizer");
11
- function toImageResponse(src) {
12
- return typeof src !== "string" && "uuid" in src ? src : undefined;
13
+ function isSrcString(src) {
14
+ return typeof src === "string";
13
15
  }
14
- function toStaticImageData(src) {
15
- return typeof src !== "string" && "src" in src ? src : undefined;
16
+ exports.isSrcString = isSrcString;
17
+ function isSrcImageResponse(src) {
18
+ return !isSrcString(src) && "uuid" in src;
16
19
  }
20
+ exports.isSrcImageResponse = isSrcImageResponse;
21
+ function isSrcStaticImageData(src) {
22
+ return !isSrcString(src) && "src" in src;
23
+ }
24
+ exports.isSrcStaticImageData = isSrcStaticImageData;
17
25
  function parseImgExtension(src) {
18
26
  const ext = src.slice(src.lastIndexOf(".") + 1);
19
27
  return ext.length > 1 ? ext : undefined;
20
28
  }
29
+ exports.parseImgExtension = parseImgExtension;
30
+ function isSvgExtension(src) {
31
+ return parseImgExtension(src) === "svg";
32
+ }
21
33
  function getSvgImgUrl(src) {
22
- if (typeof src === "string" && parseImgExtension(src) === "svg") {
34
+ if (isSrcString(src) && isSvgExtension(src)) {
23
35
  return src;
24
36
  }
25
- const imageResponse = toImageResponse(src);
26
- if (imageResponse && parseImgExtension(imageResponse.extension) === "svg") {
27
- return (0, file_1.getFileUrl)(imageResponse);
37
+ if (isSrcImageResponse(src) && isSvgExtension(src.extension)) {
38
+ return (0, file_1.getFileUrl)(src);
28
39
  }
29
- const staticImageData = toStaticImageData(src);
30
- if (staticImageData && parseImgExtension(staticImageData.src) === "svg") {
31
- return staticImageData.src;
40
+ if (isSrcStaticImageData(src) && isSvgExtension(src.src)) {
41
+ return src.src;
32
42
  }
33
43
  return undefined;
34
44
  }
35
45
  exports.getSvgImgUrl = getSvgImgUrl;
36
46
  function getImgQuality(quality, format) {
37
- return typeof quality === "number" ? quality : quality ? quality[format] : undefined;
47
+ if (typeof quality === "number") {
48
+ return quality;
49
+ }
50
+ return quality ? quality[format] : undefined;
38
51
  }
39
52
  exports.getImgQuality = getImgQuality;
40
53
  function getImgUniqueIdentifier(src) {
41
- var _a, _b, _c;
42
- return typeof src === "string" ? src : (_b = (_a = toImageResponse(src)) === null || _a === void 0 ? void 0 : _a.uuid) !== null && _b !== void 0 ? _b : (_c = toStaticImageData(src)) === null || _c === void 0 ? void 0 : _c.src;
54
+ return isSrcString(src)
55
+ ? src
56
+ : isSrcImageResponse(src)
57
+ ? src.uuid
58
+ : isSrcStaticImageData(src)
59
+ ? src.src
60
+ : undefined;
43
61
  }
44
62
  exports.getImgUniqueIdentifier = getImgUniqueIdentifier;
45
63
  function getImgElementHeight(src, width, height) {
46
64
  var _a, _b;
47
- return typeof src === "string"
48
- ? height
49
- : height !== null && height !== void 0 ? height : (Math.floor((((_a = src.height) !== null && _a !== void 0 ? _a : 0) / ((_b = src.width) !== null && _b !== void 0 ? _b : 0)) * (width || 0)) || undefined);
65
+ if (isSrcString(src) || (0, is_not_nil_1.isNotNil)(height)) {
66
+ return height;
67
+ }
68
+ const calculatedHeight = Math.floor((((_a = src.height) !== null && _a !== void 0 ? _a : 0) / ((_b = src.width) !== null && _b !== void 0 ? _b : 0)) * (width !== null && width !== void 0 ? width : 0));
69
+ return calculatedHeight === 0 ? undefined : calculatedHeight;
50
70
  }
51
71
  exports.getImgElementHeight = getImgElementHeight;
52
72
  function getImgElementWidth(src, width, height) {
53
73
  var _a, _b;
54
- return typeof src === "string"
55
- ? width
56
- : width !== null && width !== void 0 ? width : (Math.floor(((_a = src.width) !== null && _a !== void 0 ? _a : 0) / ((_b = src.height) !== null && _b !== void 0 ? _b : 0)) * (height || 0) || undefined);
74
+ if (isSrcString(src) || (0, is_not_nil_1.isNotNil)(width)) {
75
+ return width;
76
+ }
77
+ const calculatedWidth = Math.floor(((_a = src.width) !== null && _a !== void 0 ? _a : 0) / ((_b = src.height) !== null && _b !== void 0 ? _b : 0)) * (height !== null && height !== void 0 ? height : 0);
78
+ return calculatedWidth === 0 ? undefined : calculatedWidth;
57
79
  }
58
80
  exports.getImgElementWidth = getImgElementWidth;
81
+ function isDimensionNumber(value) {
82
+ return typeof value === "number";
83
+ }
84
+ function getDimension(dimension, size) {
85
+ return isDimensionNumber(dimension) ? dimension * size : "auto";
86
+ }
59
87
  const HIDPI_SIZES = [3, 2, 1];
60
88
  function getImgSrcSet(src, width, height, options = {}) {
61
89
  var _a, _b;
62
- if (!src) {
63
- return undefined;
64
- }
65
90
  let toFormat;
66
91
  let h = height !== null && height !== void 0 ? height : "auto";
67
92
  let w = width !== null && width !== void 0 ? width : "auto";
68
- if (typeof src === "string") {
93
+ if (isSrcString(src)) {
94
+ if ((0, is_empty_1.isEmpty)(src)) {
95
+ return undefined;
96
+ }
69
97
  toFormat = parseImgExtension(src);
70
98
  }
71
- const imageResponse = toImageResponse(src);
72
- if (imageResponse) {
73
- if (!imageResponse.uuid) {
99
+ if (isSrcImageResponse(src)) {
100
+ if ((0, is_empty_1.isEmpty)(src.uuid)) {
74
101
  return undefined;
75
102
  }
76
- toFormat = parseImgExtension(imageResponse.extension);
77
- h = (_a = (h || imageResponse.height)) !== null && _a !== void 0 ? _a : "auto";
78
- w = (_b = (w || imageResponse.width)) !== null && _b !== void 0 ? _b : "auto";
103
+ toFormat = parseImgExtension(src.extension);
104
+ h = (_a = (h || src.height)) !== null && _a !== void 0 ? _a : "auto";
105
+ w = (_b = (w || src.width)) !== null && _b !== void 0 ? _b : "auto";
79
106
  }
80
- const staticImageData = toStaticImageData(src);
81
- if (staticImageData) {
82
- if (!staticImageData.src) {
107
+ if (isSrcStaticImageData(src)) {
108
+ if ((0, is_empty_1.isEmpty)(src.src)) {
83
109
  return undefined;
84
110
  }
85
- toFormat = parseImgExtension(staticImageData.src);
86
- h = h || staticImageData.height;
87
- w = w || staticImageData.width;
111
+ toFormat = parseImgExtension(src.src);
112
+ h = h || src.height;
113
+ w = w || src.width;
88
114
  }
89
115
  const { maxHiDpi, ...restOptions } = options;
90
- if (typeof h === "number" || typeof w === "number") {
116
+ if (isDimensionNumber(h) || isDimensionNumber(w)) {
91
117
  return (maxHiDpi ? HIDPI_SIZES.slice(-maxHiDpi) : HIDPI_SIZES)
92
- .map((size) => (0, resizer_1.resizerImageUrl)(src, typeof w === "number" ? w * size : "auto", typeof h === "number" ? h * size : "auto", {
118
+ .map((size) => (0, resizer_1.resizerImageUrl)(src, getDimension(w, size), getDimension(h, size), {
93
119
  toFormat,
94
120
  ...restOptions,
95
121
  }) + (size > 1 ? ` ${size}x` : ""))
@@ -98,23 +124,23 @@ function getImgSrcSet(src, width, height, options = {}) {
98
124
  return (0, resizer_1.resizerImageUrl)(src, w, h, { toFormat, ...restOptions });
99
125
  }
100
126
  exports.getImgSrcSet = getImgSrcSet;
101
- const ImgSources = (props) => {
127
+ /**
128
+ * @deprecated Use import from @uxf/ui instead.
129
+ */
130
+ function ImgSources(props) {
102
131
  var _a, _b, _c, _d, _e;
103
- if (!props.src) {
132
+ if (isSrcString(props.src) && (0, is_empty_1.isEmpty)(props.src)) {
104
133
  return null;
105
134
  }
106
- const imageResponse = toImageResponse(props.src);
107
- if (imageResponse && !imageResponse.uuid) {
135
+ if (isSrcImageResponse(props.src) && (0, is_empty_1.isEmpty)(props.src.uuid)) {
108
136
  return null;
109
137
  }
110
- const staticImageData = toStaticImageData(props.src);
111
- if (staticImageData && !staticImageData.src) {
138
+ if (isSrcStaticImageData(props.src) && (0, is_empty_1.isEmpty)(props.src.src)) {
112
139
  return null;
113
140
  }
114
- let media;
115
- if (props.breakpoints && props.breakpointIndex) {
116
- media = `(min-width: ${props.breakpoints[props.breakpointIndex]})`;
117
- }
141
+ const media = (0, is_not_nil_1.isNotNil)(props.breakpoints) && (0, is_not_nil_1.isNotNil)(props.breakpointIndex)
142
+ ? `(min-width: ${props.breakpoints[props.breakpointIndex]})`
143
+ : undefined;
118
144
  return (react_1.default.createElement(react_1.default.Fragment, null,
119
145
  react_1.default.createElement(hide_1.Hide, { when: Boolean((_a = props.options) === null || _a === void 0 ? void 0 : _a.isAvifDisabled) },
120
146
  react_1.default.createElement("source", { media: media, srcSet: getImgSrcSet(props.src, props.width, props.height, {
@@ -132,5 +158,5 @@ const ImgSources = (props) => {
132
158
  ...((_e = props.options) !== null && _e !== void 0 ? _e : {}),
133
159
  quality: getImgQuality(props.quality, "original"),
134
160
  }) })));
135
- };
161
+ }
136
162
  exports.ImgSources = ImgSources;