doom-design-system 0.4.6 → 0.4.7

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.
@@ -11,32 +11,31 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import React, { useState, useEffect, useCallback, useRef } from "react";
14
+ import { useState, useEffect, useCallback, useRef, useMemo, } from "react";
15
15
  import clsx from "clsx";
16
16
  import styles from "./Image.module.css";
17
17
  import { Skeleton } from "../Skeleton/Skeleton.js";
18
+ const toCssValue = (val) => {
19
+ if (val === undefined || val === null)
20
+ return undefined;
21
+ if (typeof val === "number")
22
+ return `${val}px`;
23
+ return val;
24
+ };
25
+ const getIntrinsicSize = (val) => {
26
+ if (typeof val === "number")
27
+ return val;
28
+ if (typeof val === "string" && !val.endsWith("%")) {
29
+ const parsed = parseFloat(val);
30
+ return isNaN(parsed) ? undefined : parsed;
31
+ }
32
+ return undefined;
33
+ };
18
34
  export function Image(_a) {
19
35
  var { src, alt, className, fit, style, onLoad, onError, fallbackSrc, aspectRatio, rounded = true, width, height } = _a, props = __rest(_a, ["src", "alt", "className", "fit", "style", "onLoad", "onError", "fallbackSrc", "aspectRatio", "rounded", "width", "height"]);
20
36
  const [status, setStatus] = useState("loading");
21
37
  const [showSkeleton, setShowSkeleton] = useState(true);
22
- // Helper to extract intrinsic numeric value and convert to CSS
23
- const toCssValue = (val) => {
24
- if (val === undefined || val === null)
25
- return undefined;
26
- if (typeof val === "number")
27
- return `${val}px`;
28
- return val;
29
- };
30
- const getIntrinsicSize = (val) => {
31
- if (typeof val === "number")
32
- return val;
33
- if (typeof val === "string" && !val.endsWith("%")) {
34
- const parsed = parseFloat(val);
35
- return isNaN(parsed) ? undefined : parsed;
36
- }
37
- return undefined;
38
- };
39
- const computedAspectRatio = React.useMemo(() => {
38
+ const computedAspectRatio = useMemo(() => {
40
39
  if (aspectRatio)
41
40
  return aspectRatio;
42
41
  const w = getIntrinsicSize(width);
@@ -44,6 +43,13 @@ export function Image(_a) {
44
43
  return w && h ? `${w} / ${h}` : undefined;
45
44
  }, [aspectRatio, width, height]);
46
45
  const prevSrcRef = useRef(src);
46
+ const imgRef = useRef(null);
47
+ useEffect(() => {
48
+ var _a;
49
+ if ((_a = imgRef.current) === null || _a === void 0 ? void 0 : _a.complete) {
50
+ setStatus("loaded");
51
+ }
52
+ }, []);
47
53
  // Reset state when source changes
48
54
  useEffect(() => {
49
55
  if (prevSrcRef.current !== src) {
@@ -91,5 +97,5 @@ export function Image(_a) {
91
97
  return (_jsxs("div", { className: clsx(styles.wrapper, rounded && styles.rounded, className), style: Object.assign({ aspectRatio: computedAspectRatio, width: toCssValue(width), height: toCssValue(height) }, style), children: [_jsx("div", { className: clsx(styles.skeletonLayer, status === "loaded" && styles.fadeOut), "aria-hidden": "true", children: showSkeleton && (_jsx(Skeleton, { style: {
92
98
  width: "100%",
93
99
  height: "100%",
94
- } })) }), _jsx("img", Object.assign({ src: src, alt: alt, className: clsx(styles.image, fit && styles[`fit-${fit}`], status === "loaded" ? styles.visible : styles.hidden), onLoad: handleLoad, onError: handleError, width: width, height: height }, props))] }));
100
+ } })) }), _jsx("img", Object.assign({ ref: imgRef, src: src, alt: alt, className: clsx(styles.image, fit && styles[`fit-${fit}`], status === "loaded" ? styles.visible : styles.hidden), onLoad: handleLoad, onError: handleError, width: width, height: height }, props))] }));
95
101
  }