@bbki.ng/components 1.5.19 → 1.5.20

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.
package/dist/index.d.ts CHANGED
@@ -225,4 +225,27 @@ interface NoiseCoverProps {
225
225
  }
226
226
  declare const NoiseCover: (props: NoiseCoverProps) => JSX.Element;
227
227
 
228
- export { Article, ArticleProps, ArticleSkeleton, ArticleSkeletonProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, Error, ErrorBoundary, ImageDropProps, ImagePreviewerProps, Link, LinkColor, LinkList, LinkListProps, LinkListSkeleton, LinkListSkeletonProps, LinkProps, List, Logo, LogoProps, Nav, NavProps, NoiseCover, NoiseCoverProps, NotFound, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags, ThreeColLayout, TitledList, TitledListProps, listProps, threeColLayoutProps };
228
+ declare enum ossProcessType {
229
+ THUMBNAIL = "thumbnail",
230
+ WEBP = "webp",
231
+ NULL = "null",
232
+ oWEBP = "owebp",
233
+ PROG = "prog"
234
+ }
235
+ interface Photo {
236
+ src: string;
237
+ width: number;
238
+ height: number;
239
+ processType?: ossProcessType;
240
+ avgColor?: string;
241
+ thumbnailSrc?: string;
242
+ renderedWidth?: number;
243
+ }
244
+
245
+ interface ImgProps extends Photo {
246
+ className?: string;
247
+ size?: "large" | "normal";
248
+ }
249
+ declare const Img: (props: ImgProps) => JSX.Element;
250
+
251
+ export { Article, ArticleProps, ArticleSkeleton, ArticleSkeletonProps, BLinkDotProps, BlinkDot, Breadcrumb, BreadcrumbProps, Button, ButtonProps, ButtonType, DropImage, Error, ErrorBoundary, ImageDropProps, ImagePreviewerProps, Img, ImgProps, Link, LinkColor, LinkList, LinkListProps, LinkListSkeleton, LinkListSkeletonProps, LinkProps, List, Logo, LogoProps, Nav, NavProps, NoiseCover, NoiseCoverProps, NotFound, Page, Panel, PanelProps, PathObj, PopConfirm, PopConfirmProps, Skeleton, SkeletonColor, SkeletonProps, Table, TableProps, Tag, TagProps, Tags, ThreeColLayout, TitledList, TitledListProps, listProps, threeColLayoutProps };
package/dist/index.js CHANGED
@@ -67,6 +67,7 @@ __export(src_exports, {
67
67
  DropImage: () => DropImage,
68
68
  Error: () => Error2,
69
69
  ErrorBoundary: () => ErrorBoundary,
70
+ Img: () => Img,
70
71
  Link: () => Link,
71
72
  LinkColor: () => LinkColor,
72
73
  LinkList: () => LinkList,
@@ -576,7 +577,7 @@ var useDropImage = (params) => {
576
577
  setIsDragOver(false);
577
578
  imageFile.current = null;
578
579
  };
579
- const calcDefaultImgSize = (img, defaultWidth) => {
580
+ const calcDefaultImgSize2 = (img, defaultWidth) => {
580
581
  const { width, height } = img;
581
582
  const whRatio = width / height;
582
583
  const isHorizontal = width > height;
@@ -619,7 +620,7 @@ var useDropImage = (params) => {
619
620
  await p();
620
621
  } catch (e) {
621
622
  }
622
- setImageSize(calcDefaultImgSize({
623
+ setImageSize(calcDefaultImgSize2({
623
624
  width: img.naturalWidth,
624
625
  height: img.naturalHeight
625
626
  }));
@@ -832,6 +833,108 @@ var ThreeColLayout = (props) => {
832
833
  className: (0, import_classnames9.default)("hidden", colCls)
833
834
  }, rightRenderer && rightRenderer()));
834
835
  };
836
+
837
+ // src/img/Img.tsx
838
+ var import_classnames10 = __toESM(require("classnames"));
839
+ var import_react19 = __toESM(require("react"));
840
+
841
+ // src/img/utils.ts
842
+ var addOssWebpProcessStyle = (originUrl, style) => {
843
+ const OSS_ADDRESS = "https://zjh-im-res.oss-cn-shenzhen.aliyuncs.com";
844
+ const isInvalidOSSImgUrl = !originUrl.startsWith(OSS_ADDRESS);
845
+ const isProcessedOssImg = /x-oss-process=style\/\w+/.test(originUrl);
846
+ const isWebpImg = /webp$/.test(originUrl);
847
+ if (isInvalidOSSImgUrl || isProcessedOssImg || isWebpImg && style === "webp" /* WEBP */ || style === "null" /* NULL */) {
848
+ return originUrl;
849
+ }
850
+ return `${originUrl}?x-oss-process=style/${style}`;
851
+ };
852
+ var calcDefaultImgSize = (img, defaultWidth, scale) => {
853
+ const { width, height } = img;
854
+ const whRatio = width / height;
855
+ const isHorizontal = width > height;
856
+ const finalWidth = (defaultWidth || (isHorizontal ? 576 : 384)) * (scale || 1);
857
+ return {
858
+ width: finalWidth,
859
+ height: finalWidth / whRatio
860
+ };
861
+ };
862
+ var delay = (time) => {
863
+ return new Promise((resolve) => {
864
+ setTimeout(resolve, time);
865
+ });
866
+ };
867
+
868
+ // src/img/Img.tsx
869
+ var emptyDataURL = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
870
+ var Img = (props) => {
871
+ const {
872
+ src,
873
+ className,
874
+ renderedWidth,
875
+ avgColor,
876
+ thumbnailSrc,
877
+ processType,
878
+ size
879
+ } = props;
880
+ const { width, height } = calcDefaultImgSize(props, renderedWidth, size === "normal" ? 0.6 : 1);
881
+ const [loaded, setLoaded] = (0, import_react19.useState)(false);
882
+ const [decoded, setDecoded] = (0, import_react19.useState)(false);
883
+ const baseWrapperStyle = {
884
+ width: "initial",
885
+ height: "initial",
886
+ backgroundColor: avgColor || "unset"
887
+ };
888
+ const dynamicWrapperStyle = loaded ? {
889
+ backgroundImage: "none"
890
+ } : {
891
+ backgroundSize: "cover",
892
+ backgroundPosition: "0% 0%",
893
+ backgroundImage: `url(${thumbnailSrc ? thumbnailSrc : addOssWebpProcessStyle(src, "thumbnail" /* THUMBNAIL */)})`
894
+ };
895
+ const handleImgLoad = (img) => {
896
+ const updateFunc = async () => {
897
+ const p = "decode" in img ? img.decode : Promise.resolve;
898
+ try {
899
+ await p();
900
+ } catch (e) {
901
+ }
902
+ await delay(500);
903
+ setDecoded(true);
904
+ await delay(500);
905
+ setLoaded(true);
906
+ };
907
+ img.onload = updateFunc;
908
+ };
909
+ return /* @__PURE__ */ import_react19.default.createElement("span", {
910
+ className: (0, import_classnames10.default)(className, "inline-block", "relative", "overflow-hidden", "leading-none", "align-bottom", "border-0"),
911
+ style: Object.assign({}, baseWrapperStyle, dynamicWrapperStyle)
912
+ }, /* @__PURE__ */ import_react19.default.createElement("img", {
913
+ ref: (input) => {
914
+ if (!input) {
915
+ return;
916
+ }
917
+ handleImgLoad(input);
918
+ },
919
+ width,
920
+ height,
921
+ src: addOssWebpProcessStyle(src, processType || "webp" /* WEBP */),
922
+ decoding: "async",
923
+ loading: "lazy",
924
+ style: {
925
+ contentVisibility: "auto"
926
+ },
927
+ className: (0, import_classnames10.default)("transition-opacity", "opacity-100", {
928
+ "opacity-0": !decoded
929
+ })
930
+ }), /* @__PURE__ */ import_react19.default.createElement("img", {
931
+ src: emptyDataURL,
932
+ className: (0, import_classnames10.default)("lqip-blur", "absolute", "h-full", "w-full", "transition-opacity", "opacity-100", {
933
+ "opacity-0": decoded
934
+ }),
935
+ style: { top: 0, left: 0 }
936
+ }));
937
+ };
835
938
  module.exports = __toCommonJS(src_exports);
836
939
  // Annotate the CommonJS export names for ESM import in node:
837
940
  0 && (module.exports = {
@@ -844,6 +947,7 @@ module.exports = __toCommonJS(src_exports);
844
947
  DropImage,
845
948
  Error,
846
949
  ErrorBoundary,
950
+ Img,
847
951
  Link,
848
952
  LinkColor,
849
953
  LinkList,
package/dist/index.mjs CHANGED
@@ -521,7 +521,7 @@ var useDropImage = (params) => {
521
521
  setIsDragOver(false);
522
522
  imageFile.current = null;
523
523
  };
524
- const calcDefaultImgSize = (img, defaultWidth) => {
524
+ const calcDefaultImgSize2 = (img, defaultWidth) => {
525
525
  const { width, height } = img;
526
526
  const whRatio = width / height;
527
527
  const isHorizontal = width > height;
@@ -564,7 +564,7 @@ var useDropImage = (params) => {
564
564
  await p();
565
565
  } catch (e) {
566
566
  }
567
- setImageSize(calcDefaultImgSize({
567
+ setImageSize(calcDefaultImgSize2({
568
568
  width: img.naturalWidth,
569
569
  height: img.naturalHeight
570
570
  }));
@@ -777,6 +777,108 @@ var ThreeColLayout = (props) => {
777
777
  className: cls3("hidden", colCls)
778
778
  }, rightRenderer && rightRenderer()));
779
779
  };
780
+
781
+ // src/img/Img.tsx
782
+ import classnames from "classnames";
783
+ import React18, { useState as useState5 } from "react";
784
+
785
+ // src/img/utils.ts
786
+ var addOssWebpProcessStyle = (originUrl, style) => {
787
+ const OSS_ADDRESS = "https://zjh-im-res.oss-cn-shenzhen.aliyuncs.com";
788
+ const isInvalidOSSImgUrl = !originUrl.startsWith(OSS_ADDRESS);
789
+ const isProcessedOssImg = /x-oss-process=style\/\w+/.test(originUrl);
790
+ const isWebpImg = /webp$/.test(originUrl);
791
+ if (isInvalidOSSImgUrl || isProcessedOssImg || isWebpImg && style === "webp" /* WEBP */ || style === "null" /* NULL */) {
792
+ return originUrl;
793
+ }
794
+ return `${originUrl}?x-oss-process=style/${style}`;
795
+ };
796
+ var calcDefaultImgSize = (img, defaultWidth, scale) => {
797
+ const { width, height } = img;
798
+ const whRatio = width / height;
799
+ const isHorizontal = width > height;
800
+ const finalWidth = (defaultWidth || (isHorizontal ? 576 : 384)) * (scale || 1);
801
+ return {
802
+ width: finalWidth,
803
+ height: finalWidth / whRatio
804
+ };
805
+ };
806
+ var delay = (time) => {
807
+ return new Promise((resolve) => {
808
+ setTimeout(resolve, time);
809
+ });
810
+ };
811
+
812
+ // src/img/Img.tsx
813
+ var emptyDataURL = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
814
+ var Img = (props) => {
815
+ const {
816
+ src,
817
+ className,
818
+ renderedWidth,
819
+ avgColor,
820
+ thumbnailSrc,
821
+ processType,
822
+ size
823
+ } = props;
824
+ const { width, height } = calcDefaultImgSize(props, renderedWidth, size === "normal" ? 0.6 : 1);
825
+ const [loaded, setLoaded] = useState5(false);
826
+ const [decoded, setDecoded] = useState5(false);
827
+ const baseWrapperStyle = {
828
+ width: "initial",
829
+ height: "initial",
830
+ backgroundColor: avgColor || "unset"
831
+ };
832
+ const dynamicWrapperStyle = loaded ? {
833
+ backgroundImage: "none"
834
+ } : {
835
+ backgroundSize: "cover",
836
+ backgroundPosition: "0% 0%",
837
+ backgroundImage: `url(${thumbnailSrc ? thumbnailSrc : addOssWebpProcessStyle(src, "thumbnail" /* THUMBNAIL */)})`
838
+ };
839
+ const handleImgLoad = (img) => {
840
+ const updateFunc = async () => {
841
+ const p = "decode" in img ? img.decode : Promise.resolve;
842
+ try {
843
+ await p();
844
+ } catch (e) {
845
+ }
846
+ await delay(500);
847
+ setDecoded(true);
848
+ await delay(500);
849
+ setLoaded(true);
850
+ };
851
+ img.onload = updateFunc;
852
+ };
853
+ return /* @__PURE__ */ React18.createElement("span", {
854
+ className: classnames(className, "inline-block", "relative", "overflow-hidden", "leading-none", "align-bottom", "border-0"),
855
+ style: Object.assign({}, baseWrapperStyle, dynamicWrapperStyle)
856
+ }, /* @__PURE__ */ React18.createElement("img", {
857
+ ref: (input) => {
858
+ if (!input) {
859
+ return;
860
+ }
861
+ handleImgLoad(input);
862
+ },
863
+ width,
864
+ height,
865
+ src: addOssWebpProcessStyle(src, processType || "webp" /* WEBP */),
866
+ decoding: "async",
867
+ loading: "lazy",
868
+ style: {
869
+ contentVisibility: "auto"
870
+ },
871
+ className: classnames("transition-opacity", "opacity-100", {
872
+ "opacity-0": !decoded
873
+ })
874
+ }), /* @__PURE__ */ React18.createElement("img", {
875
+ src: emptyDataURL,
876
+ className: classnames("lqip-blur", "absolute", "h-full", "w-full", "transition-opacity", "opacity-100", {
877
+ "opacity-0": decoded
878
+ }),
879
+ style: { top: 0, left: 0 }
880
+ }));
881
+ };
780
882
  export {
781
883
  Article,
782
884
  ArticleSkeleton,
@@ -787,6 +889,7 @@ export {
787
889
  DropImage,
788
890
  Error2 as Error,
789
891
  ErrorBoundary,
892
+ Img,
790
893
  Link,
791
894
  LinkColor,
792
895
  LinkList,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/components",
3
- "version": "1.5.19",
3
+ "version": "1.5.20",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",