@cleartrip/ct-design-image 4.0.0-SNAPSHOT-test.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.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Image
2
+
3
+ An enhanced image component with loading states and optimization.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @cleartrip/ct-design-image
11
+ # or
12
+ pnpm add @cleartrip/ct-design-image
13
+ ```
14
+
15
+ ### Peer dependencies
16
+
17
+ ```bash
18
+ # Required for all targets
19
+ npm install react
20
+
21
+ # Web only
22
+ npm install react-dom
23
+
24
+ # React Native only
25
+ npm install react-native
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Usage
31
+
32
+ ### Basic
33
+
34
+ ```tsx
35
+ import { Image } from '@cleartrip/ct-design-image';
36
+
37
+ function Example() {
38
+ return (
39
+ <Image>
40
+ {/* Basic usage */}
41
+ </Image>
42
+ );
43
+ }
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Props
49
+
50
+ | Prop | Type | Default | Required | Description |
51
+ |------|------|---------|----------|-------------|
52
+ | `fallbackUrl` | `string` | — | No | URL to swap in when `src` fails to load. Also used as the initial |
53
+ | `onError` | `(e: SyntheticEvent<HTMLImageElement, Event>) => void` | — | No | Fired when the image fails to load. The fallback swap happens |
54
+ | `Component` | `ComponentType<IImageWebRendererProps>` | — | No | Optional custom renderer used in place of the default `<img>`. |
55
+ | `resizeMode` | `'contain' | 'cover' | 'stretch' | 'center'` | — | No | `react-native-fast-image` resize mode. Ignored on web. |
56
+
57
+ ---
58
+
59
+ ## Accessibility
60
+
61
+ - The component follows accessibility best practices
62
+ - Ensure proper ARIA attributes are provided where needed
63
+ - Test with screen readers to ensure usability
64
+
65
+ ---
66
+
67
+ ## Migration
68
+
69
+ If migrating from a previous version:
70
+
71
+ ```diff
72
+ - import { Image } from 'yagami/core/components';
73
+ + import { Image } from '@cleartrip/ct-design-image';
74
+ ```
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { IImageProps } from './type';
3
+ declare const Image: React.ForwardRefExoticComponent<IImageProps & React.RefAttributes<HTMLImageElement>>;
4
+ export default Image;
5
+ //# sourceMappingURL=Image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0D,MAAM,OAAO,CAAC;AAO/E,OAAO,EAAE,WAAW,EAA0B,MAAM,QAAQ,CAAC;AAmF7D,QAAA,MAAM,KAAK,sFAgDV,CAAC;AAIF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { IImageProps } from './type';
2
+ declare const Image: {
3
+ ({ src, alt, width, height, fallbackUrl, styleConfig, onClick, onLoad, onError, resizeMode, }: IImageProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default Image;
7
+ //# sourceMappingURL=Image.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.native.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/Image.native.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAmBrC,QAAA,MAAM,KAAK;mGAWR,WAAW;;CA0Eb,CAAC;AAIF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";var r=require("react/jsx-runtime"),e=require("react"),t=require("@cleartrip/ct-design-style-manager");function o(r){return r&&r.__esModule?r:{default:r}}var a=o(require("next/image"));const i=t.makeStyles(()=>({root:{}}));e.forwardRef(({src:e,alt:t,width:o,height:a,className:i,onClick:n,onLoad:s,onError:l},c)=>r.jsx("img",{ref:c,src:e,alt:t,width:o,height:a,className:i,onClick:n,onLoad:s,onError:l})).displayName="ImageDefaultRenderer";const n=e.forwardRef(({src:e,alt:t,width:o,height:i,className:n,onClick:s,onLoad:l,onError:c,priority:d,loading:u,blurDataURL:f,unoptimized:g,fetchPriority:h},m)=>r.jsx(a.default,{ref:m,src:e,alt:t,width:o,height:i,className:n,onClick:s,onLoad:l,onError:c,priority:d,loading:u,blurDataURL:f,unoptimized:g,fetchPriority:h}));n.displayName="NextImageComponent";const s=e.forwardRef(({src:o,alt:a,width:s,height:l,fallbackUrl:c,styleConfig:d,onClick:u,onLoad:f,onError:g,Component:h},m)=>{const[p,y]=e.useState(o||c||""),{root:w=[]}=d||{},C=t.useWebMergeStyles([i.root,...w],[i.root,w]);e.useEffect(()=>{y(o||c||"")},[c,o]);const N=h||n;return r.jsx(N,{ref:m,src:p,alt:a,width:s,height:l,className:C,onClick:u,onLoad:f,onError:r=>{c&&p!==c&&y(c),g&&g(r)}})});s.displayName="Image",exports.Image=s,exports.isSvg=function(r){return"string"==typeof r&&r.endsWith(".svg")};
2
+ //# sourceMappingURL=ct-design-image.browser.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-image.browser.cjs.js","sources":["../packages/components/Image/src/style.ts","../packages/components/Image/src/Image.tsx"],"sourcesContent":[null,null],"names":["staticImageStyles","makeStyles","root","forwardRef","src","alt","width","height","className","onClick","onLoad","onError","ref","_jsx","jsx","displayName","NextImageComponent","priority","loading","blurDataURL","unoptimized","fetchPriority","NextImage","default","Image","fallbackUrl","styleConfig","Component","imageSource","setImageSource","useState","customRootStyles","mergedRootClassName","useWebMergeStyles","useEffect","Renderer","e","url","endsWith"],"mappings":"qMAYA,MAAMA,EAAoBC,EAAUA,WAAC,KAAO,CAC1CC,KAAM,CAAE,KCIkBC,EAAUA,WACpC,EAAGC,MAAKC,MAAKC,QAAOC,SAAQC,YAAWC,UAASC,SAAQC,WAAWC,IACjEC,EACEC,IAAA,MAAA,CAAAF,IAAKA,EACLR,IAAKA,EACLC,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWA,EACXC,QAASA,EACTC,OAAQA,EACRC,QAASA,KAKKI,YAAc,uBAElC,MAAMC,EAAqBb,EAAUA,WACnC,EAEIC,MACAC,MACAC,QACAC,SACAC,YACAC,UACAC,SACAC,UACAM,WACAC,UACAC,cACAC,cACAC,iBAEFT,IAEAC,EAAAA,IAACS,EAASC,QACR,CAAAX,IAAKA,EACLR,IAAKA,EACLC,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWA,EACXC,QAASA,EACTC,OAAQA,EACRC,QAASA,EACTM,SAAUA,EACVC,QAASA,EACTC,YAAaA,EACbC,YAAaA,EACbC,cAAeA,KAKrBL,EAAmBD,YAAc,qBAiBjC,MAAMS,EAAQrB,EAAUA,WACtB,EAAGC,MAAKC,MAAKC,QAAOC,SAAQkB,cAAaC,cAAajB,UAASC,SAAQC,UAASgB,aAAaf,KAC3F,MAAOgB,EAAaC,GAAkBC,EAAQA,SAAS1B,GAAOqB,GAAe,KAErEvB,KAAM6B,EAAmB,IAAOL,GAAe,CAAA,EAIjDM,EAAsBC,EAAAA,kBAC1B,CAACjC,EAAkBE,QAAoB6B,GACvC,CAAC/B,EAAkBE,KAAM6B,IAG3BG,EAAAA,UAAU,KACRL,EAAezB,GAAOqB,GAAe,KACpC,CAACA,EAAarB,IAEjB,MAaM+B,EAAYR,GAAaX,EAI/B,OACEH,EAACC,IAAAqB,GACCvB,IAAKA,EACLR,IAAKwB,EACLvB,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWwB,EACXvB,QAASA,EACTC,OAAQA,EACRC,QA3BkByB,IAChBX,GAAeG,IAAgBH,GACjCI,EAAeJ,GAEbd,GACFA,EAAQyB,QA4BhBZ,EAAMT,YAAc,sCDlHd,SAAgBsB,GACpB,MAAsB,iBAARA,GAAoBA,EAAIC,SAAS,OACjD"}
@@ -0,0 +1,2 @@
1
+ import{jsx as o}from"react/jsx-runtime";import{forwardRef as r,useState as t,useEffect as i}from"react";import{makeStyles as a,useWebMergeStyles as e}from"@cleartrip/ct-design-style-manager";import n from"next/image";const l=a(()=>({root:{}}));function s(o){return"string"==typeof o&&o.endsWith(".svg")}r(({src:r,alt:t,width:i,height:a,className:e,onClick:n,onLoad:l,onError:s},c)=>o("img",{ref:c,src:r,alt:t,width:i,height:a,className:e,onClick:n,onLoad:l,onError:s})).displayName="ImageDefaultRenderer";const c=r(({src:r,alt:t,width:i,height:a,className:e,onClick:l,onLoad:s,onError:c,priority:m,loading:d,blurDataURL:h,unoptimized:g,fetchPriority:p},f)=>o(n,{ref:f,src:r,alt:t,width:i,height:a,className:e,onClick:l,onLoad:s,onError:c,priority:m,loading:d,blurDataURL:h,unoptimized:g,fetchPriority:p}));c.displayName="NextImageComponent";const m=r(({src:r,alt:a,width:n,height:s,fallbackUrl:m,styleConfig:d,onClick:h,onLoad:g,onError:p,Component:f},y)=>{const[u,C]=t(r||m||""),{root:N=[]}=d||{},L=e([l.root,...N],[l.root,N]);i(()=>{C(r||m||"")},[m,r]);return o(f||c,{ref:y,src:u,alt:a,width:n,height:s,className:L,onClick:h,onLoad:g,onError:o=>{m&&u!==m&&C(m),p&&p(o)}})});m.displayName="Image";export{m as Image,s as isSvg};
2
+ //# sourceMappingURL=ct-design-image.browser.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-image.browser.esm.js","sources":["../packages/components/Image/src/style.ts","../packages/components/Image/src/Image.tsx"],"sourcesContent":[null,null],"names":["staticImageStyles","makeStyles","root","isSvg","url","endsWith","forwardRef","src","alt","width","height","className","onClick","onLoad","onError","ref","_jsx","displayName","NextImageComponent","priority","loading","blurDataURL","unoptimized","fetchPriority","NextImage","Image","fallbackUrl","styleConfig","Component","imageSource","setImageSource","useState","customRootStyles","mergedRootClassName","useWebMergeStyles","useEffect","e"],"mappings":"yNAYA,MAAMA,EAAoBC,EAAW,KAAO,CAC1CC,KAAM,CAAE,KAaJ,SAAUC,EAAMC,GACpB,MAAsB,iBAARA,GAAoBA,EAAIC,SAAS,OACjD,CCX4BC,EAC1B,EAAGC,MAAKC,MAAKC,QAAOC,SAAQC,YAAWC,UAASC,SAAQC,WAAWC,IACjEC,EACE,MAAA,CAAAD,IAAKA,EACLR,IAAKA,EACLC,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWA,EACXC,QAASA,EACTC,OAAQA,EACRC,QAASA,KAKKG,YAAc,uBAElC,MAAMC,EAAqBZ,EACzB,EAEIC,MACAC,MACAC,QACAC,SACAC,YACAC,UACAC,SACAC,UACAK,WACAC,UACAC,cACAC,cACAC,iBAEFR,IAEAC,EAACQ,EACC,CAAAT,IAAKA,EACLR,IAAKA,EACLC,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWA,EACXC,QAASA,EACTC,OAAQA,EACRC,QAASA,EACTK,SAAUA,EACVC,QAASA,EACTC,YAAaA,EACbC,YAAaA,EACbC,cAAeA,KAKrBL,EAAmBD,YAAc,qBAiBjC,MAAMQ,EAAQnB,EACZ,EAAGC,MAAKC,MAAKC,QAAOC,SAAQgB,cAAaC,cAAaf,UAASC,SAAQC,UAASc,aAAab,KAC3F,MAAOc,EAAaC,GAAkBC,EAAiBxB,GAAOmB,GAAe,KAErExB,KAAM8B,EAAmB,IAAOL,GAAe,CAAA,EAIjDM,EAAsBC,EAC1B,CAAClC,EAAkBE,QAAoB8B,GACvC,CAAChC,EAAkBE,KAAM8B,IAG3BG,EAAU,KACRL,EAAevB,GAAOmB,GAAe,KACpC,CAACA,EAAanB,IAmBjB,OACES,EALgBY,GAAaV,GAM3BH,IAAKA,EACLR,IAAKsB,EACLrB,IAAKA,EACLC,MAAOA,EACPC,OAAQA,EACRC,UAAWsB,EACXrB,QAASA,EACTC,OAAQA,EACRC,QA3BkBsB,IAChBV,GAAeG,IAAgBH,GACjCI,EAAeJ,GAEbZ,GACFA,EAAQsB,QA4BhBX,EAAMR,YAAc"}
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var ctDesignStyleManager = require('@cleartrip/ct-design-style-manager');
6
+ var NextImage = require('next/image');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
11
+
12
+ const staticImageStyles = ctDesignStyleManager.makeStyles(() => ({
13
+ root: {},
14
+ }));
15
+ function isSvg(url) {
16
+ return typeof url === 'string' && url.endsWith('.svg');
17
+ }
18
+
19
+ const DefaultImgComponent = react.forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError }, ref) => (jsxRuntime.jsx("img", { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError })));
20
+ DefaultImgComponent.displayName = 'ImageDefaultRenderer';
21
+ const NextImageComponent = react.forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError, priority, loading, blurDataURL, unoptimized, fetchPriority, }, ref) => (jsxRuntime.jsx(NextImage__default.default, { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError, priority: priority, loading: loading, blurDataURL: blurDataURL, unoptimized: unoptimized, fetchPriority: fetchPriority })));
22
+ NextImageComponent.displayName = 'NextImageComponent';
23
+ const Image = react.forwardRef(({ src, alt, width, height, fallbackUrl, styleConfig, onClick, onLoad, onError, Component }, ref) => {
24
+ const [imageSource, setImageSource] = react.useState(src || fallbackUrl || '');
25
+ const { root: customRootStyles = [] } = styleConfig || {};
26
+ const mergedRootClassName = ctDesignStyleManager.useWebMergeStyles([staticImageStyles.root, ...customRootStyles], [staticImageStyles.root, customRootStyles]);
27
+ react.useEffect(() => {
28
+ setImageSource(src || fallbackUrl || '');
29
+ }, [fallbackUrl, src]);
30
+ const onImageError = (e) => {
31
+ if (fallbackUrl && imageSource !== fallbackUrl) {
32
+ setImageSource(fallbackUrl);
33
+ }
34
+ if (onError) {
35
+ onError(e);
36
+ }
37
+ };
38
+ const Renderer = (Component || NextImageComponent);
39
+ return (jsxRuntime.jsx(Renderer, { ref: ref, src: imageSource, alt: alt, width: width, height: height, className: mergedRootClassName, onClick: onClick, onLoad: onLoad, onError: onImageError }));
40
+ });
41
+ Image.displayName = 'Image';
42
+
43
+ exports.Image = Image;
44
+ exports.isSvg = isSvg;
45
+ //# sourceMappingURL=ct-design-image.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-image.cjs.js","sources":["../packages/components/Image/src/style.ts","../packages/components/Image/src/Image.tsx"],"sourcesContent":[null,null],"names":["makeStyles","forwardRef","_jsx","NextImage","useState","useWebMergeStyles","useEffect"],"mappings":";;;;;;;;;;;AAYA,MAAM,iBAAiB,GAAGA,+BAAU,CAAC,OAAO;AAC1C,IAAA,IAAI,EAAE,EAAE;AACT,CAAA,CAAC,CAAC,CAAC;AAYE,SAAU,KAAK,CAAC,GAA8B,EAAA;IAClD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzD;;ACXA,MAAM,mBAAmB,GAAGC,gBAAU,CACpC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,MACpEC,cACE,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,CAAA,CACH,CACF,CAAC;AAEF,mBAAmB,CAAC,WAAW,GAAG,sBAAsB,CAAC;AAEzD,MAAM,kBAAkB,GAAGD,gBAAU,CACnC,CACE,EACE,GAAG,EACH,GAAG,EACH,KAAK,EACL,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,GAC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,IAAI,WAAW,KAAK,WAAW,EAAE;YAC9C,cAAc,CAAC,WAAW,CAAC,CAAC;SAC7B;QACD,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,CAAC,CAAC,CAAC;SACZ;AACH,KAAC,CAAC;AAMF,IAAA,MAAM,QAAQ,IAAI,SAAS,IAAI,kBAAkB,CAEhD,CAAC;AAEF,IAAA,QACEJ,cAAC,CAAA,QAAQ,IACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAA,CACrB,EACF;AACJ,CAAC,EACD;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO;;;;;"}
@@ -0,0 +1,38 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState, useEffect } from 'react';
3
+ import { makeStyles, useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
4
+ import NextImage from 'next/image';
5
+
6
+ const staticImageStyles = makeStyles(() => ({
7
+ root: {},
8
+ }));
9
+ function isSvg(url) {
10
+ return typeof url === 'string' && url.endsWith('.svg');
11
+ }
12
+
13
+ const DefaultImgComponent = forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError }, ref) => (jsx("img", { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError })));
14
+ DefaultImgComponent.displayName = 'ImageDefaultRenderer';
15
+ const NextImageComponent = forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError, priority, loading, blurDataURL, unoptimized, fetchPriority, }, ref) => (jsx(NextImage, { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError, priority: priority, loading: loading, blurDataURL: blurDataURL, unoptimized: unoptimized, fetchPriority: fetchPriority })));
16
+ NextImageComponent.displayName = 'NextImageComponent';
17
+ const Image = forwardRef(({ src, alt, width, height, fallbackUrl, styleConfig, onClick, onLoad, onError, Component }, ref) => {
18
+ const [imageSource, setImageSource] = useState(src || fallbackUrl || '');
19
+ const { root: customRootStyles = [] } = styleConfig || {};
20
+ const mergedRootClassName = useWebMergeStyles([staticImageStyles.root, ...customRootStyles], [staticImageStyles.root, customRootStyles]);
21
+ useEffect(() => {
22
+ setImageSource(src || fallbackUrl || '');
23
+ }, [fallbackUrl, src]);
24
+ const onImageError = (e) => {
25
+ if (fallbackUrl && imageSource !== fallbackUrl) {
26
+ setImageSource(fallbackUrl);
27
+ }
28
+ if (onError) {
29
+ onError(e);
30
+ }
31
+ };
32
+ const Renderer = (Component || NextImageComponent);
33
+ return (jsx(Renderer, { ref: ref, src: imageSource, alt: alt, width: width, height: height, className: mergedRootClassName, onClick: onClick, onLoad: onLoad, onError: onImageError }));
34
+ });
35
+ Image.displayName = 'Image';
36
+
37
+ export { Image, isSvg };
38
+ //# sourceMappingURL=ct-design-image.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-image.esm.js","sources":["../packages/components/Image/src/style.ts","../packages/components/Image/src/Image.tsx"],"sourcesContent":[null,null],"names":["_jsx"],"mappings":";;;;;AAYA,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO;AAC1C,IAAA,IAAI,EAAE,EAAE;AACT,CAAA,CAAC,CAAC,CAAC;AAYE,SAAU,KAAK,CAAC,GAA8B,EAAA;IAClD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzD;;ACXA,MAAM,mBAAmB,GAAG,UAAU,CACpC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,MACpEA,GACE,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,GA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AE,gBAAgB,GAAG,EAAE,EAAE,GAAG,WAAW,IAAI,EAAE,CAAC;IAI1D,MAAM,mBAAmB,GAAG,iBAAiB,CAC3C,CAAC,iBAAiB,CAAC,IAAc,EAAE,GAAI,gBAAwC,CAAC,EAChF,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAC3C,CAAC;IAEF,SAAS,CAAC,MAAK;AACb,QAAA,cAAc,CAAC,GAAG,IAAI,WAAW,IAAI,EAAE,CAAC,CAAC;AAC3C,KAAC,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;AAEvB,IAAA,MAAM,YAAY,GAAG,CAAC,CAA0C,KAAI;AAClE,QAAA,IAAI,WAAW,IAAI,WAAW,KAAK,WAAW,EAAE;YAC9C,cAAc,CAAC,WAAW,CAAC,CAAC;SAC7B;QACD,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,CAAC,CAAC,CAAC;SACZ;AACH,KAAC,CAAC;AAMF,IAAA,MAAM,QAAQ,IAAI,SAAS,IAAI,kBAAkB,CAEhD,CAAC;AAEF,IAAA,QACEA,GAAC,CAAA,QAAQ,IACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAA,CACrB,EACF;AACJ,CAAC,EACD;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO;;;;"}
@@ -0,0 +1,46 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('@cleartrip/ct-design-style-manager'), require('next/image')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', '@cleartrip/ct-design-style-manager', 'next/image'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemImage = {}, global.jsxRuntime, global.React, global.ctDesignStyleManager, global.NextImage));
5
+ })(this, (function (exports, jsxRuntime, react, ctDesignStyleManager, NextImage) { 'use strict';
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var NextImage__default = /*#__PURE__*/_interopDefault(NextImage);
10
+
11
+ const staticImageStyles = ctDesignStyleManager.makeStyles(() => ({
12
+ root: {},
13
+ }));
14
+ function isSvg(url) {
15
+ return typeof url === 'string' && url.endsWith('.svg');
16
+ }
17
+
18
+ const DefaultImgComponent = react.forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError }, ref) => (jsxRuntime.jsx("img", { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError })));
19
+ DefaultImgComponent.displayName = 'ImageDefaultRenderer';
20
+ const NextImageComponent = react.forwardRef(({ src, alt, width, height, className, onClick, onLoad, onError, priority, loading, blurDataURL, unoptimized, fetchPriority, }, ref) => (jsxRuntime.jsx(NextImage__default.default, { ref: ref, src: src, alt: alt, width: width, height: height, className: className, onClick: onClick, onLoad: onLoad, onError: onError, priority: priority, loading: loading, blurDataURL: blurDataURL, unoptimized: unoptimized, fetchPriority: fetchPriority })));
21
+ NextImageComponent.displayName = 'NextImageComponent';
22
+ const Image = react.forwardRef(({ src, alt, width, height, fallbackUrl, styleConfig, onClick, onLoad, onError, Component }, ref) => {
23
+ const [imageSource, setImageSource] = react.useState(src || fallbackUrl || '');
24
+ const { root: customRootStyles = [] } = styleConfig || {};
25
+ const mergedRootClassName = ctDesignStyleManager.useWebMergeStyles([staticImageStyles.root, ...customRootStyles], [staticImageStyles.root, customRootStyles]);
26
+ react.useEffect(() => {
27
+ setImageSource(src || fallbackUrl || '');
28
+ }, [fallbackUrl, src]);
29
+ const onImageError = (e) => {
30
+ if (fallbackUrl && imageSource !== fallbackUrl) {
31
+ setImageSource(fallbackUrl);
32
+ }
33
+ if (onError) {
34
+ onError(e);
35
+ }
36
+ };
37
+ const Renderer = (Component || NextImageComponent);
38
+ return (jsxRuntime.jsx(Renderer, { ref: ref, src: imageSource, alt: alt, width: width, height: height, className: mergedRootClassName, onClick: onClick, onLoad: onLoad, onError: onImageError }));
39
+ });
40
+ Image.displayName = 'Image';
41
+
42
+ exports.Image = Image;
43
+ exports.isSvg = isSvg;
44
+
45
+ }));
46
+ //# sourceMappingURL=ct-design-image.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-image.umd.js","sources":["../packages/components/Image/src/style.ts","../packages/components/Image/src/Image.tsx"],"sourcesContent":[null,null],"names":["makeStyles","forwardRef","_jsx","NextImage","useState","useWebMergeStyles","useEffect"],"mappings":";;;;;;;;;;IAYA,MAAM,iBAAiB,GAAGA,+BAAU,CAAC,OAAO;IAC1C,IAAA,IAAI,EAAE,EAAE;IACT,CAAA,CAAC,CAAC,CAAC;IAYE,SAAU,KAAK,CAAC,GAA8B,EAAA;QAClD,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzD;;ICXA,MAAM,mBAAmB,GAAGC,gBAAU,CACpC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,MACpEC,cACE,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,CAAA,CACH,CACF,CAAC;IAEF,mBAAmB,CAAC,WAAW,GAAG,sBAAsB,CAAC;IAEzD,MAAM,kBAAkB,GAAGD,gBAAU,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I,EAAE,CAAC,CAAC;IAC3C,KAAC,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;IAEvB,IAAA,MAAM,YAAY,GAAG,CAAC,CAA0C,KAAI;IAClE,QAAA,IAAI,WAAW,IAAI,WAAW,KAAK,WAAW,EAAE;gBAC9C,cAAc,CAAC,WAAW,CAAC,CAAC;aAC7B;YACD,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,CAAC,CAAC,CAAC;aACZ;IACH,KAAC,CAAC;IAMF,IAAA,MAAM,QAAQ,IAAI,SAAS,IAAI,kBAAkB,CAEhD,CAAC;IAEF,IAAA,QACEJ,cAAC,CAAA,QAAQ,IACP,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EAAA,CACrB,EACF;IACJ,CAAC,EACD;IAEF,KAAK,CAAC,WAAW,GAAG,OAAO;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ export { default as Image } from './Image';
2
+ export { isSvg } from './style';
3
+ export * from './type';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as Image } from './Image.native';
2
+ export { isSvg } from './style';
3
+ export * from './type';
4
+ //# sourceMappingURL=index.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const staticImageStyles: {
2
+ root: {};
3
+ };
4
+ export default staticImageStyles;
5
+ export declare function isSvg(url: string | undefined | null): boolean;
6
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/style.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,iBAAiB;;CAEpB,CAAC;AAEJ,eAAe,iBAAiB,CAAC;AAUjC,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAE7D"}
package/dist/type.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { ComponentType, SyntheticEvent } from 'react';
2
+ import type { ImageStyle } from '@cleartrip/ct-design-types';
3
+ export interface IImageStyleConfig {
4
+ root?: Omit<ImageStyle, 'backgroundColor' | 'overlayColor' | 'borderColor'>[];
5
+ }
6
+ export interface IImageWebRendererProps {
7
+ src: string;
8
+ alt: string;
9
+ width?: number;
10
+ height?: number;
11
+ className?: string;
12
+ onClick?: () => void;
13
+ onLoad?: () => void;
14
+ onError?: (e: SyntheticEvent<HTMLImageElement, Event>) => void;
15
+ priority?: boolean;
16
+ loading?: 'eager' | 'lazy';
17
+ blurDataURL?: string;
18
+ unoptimized?: boolean;
19
+ fetchPriority?: 'high' | 'low' | 'auto';
20
+ }
21
+ export interface IImageProps {
22
+ src: string;
23
+ alt: string;
24
+ width?: number;
25
+ height?: number;
26
+ fallbackUrl?: string;
27
+ styleConfig?: IImageStyleConfig;
28
+ onClick?: () => void;
29
+ onLoad?: () => void;
30
+ onError?: (e: SyntheticEvent<HTMLImageElement, Event>) => void;
31
+ Component?: ComponentType<IImageWebRendererProps>;
32
+ resizeMode?: 'contain' | 'cover' | 'stretch' | 'center';
33
+ }
34
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/Image/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAW7D,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,GAAG,cAAc,GAAG,aAAa,CAAC,EAAE,CAAC;CAC/E;AAOD,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;CACzC;AAgBD,MAAM,WAAW,WAAW;IAE1B,GAAG,EAAE,MAAM,CAAC;IAEZ,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;IAKhB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEhC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAKpB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC;IAQ/D,SAAS,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAKlD,UAAU,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;CACzD"}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@cleartrip/ct-design-image",
3
+ "version": "4.0.0-SNAPSHOT-test.0",
4
+ "description": "Image component — web <img>/custom component, native FastImage + SvgUri.",
5
+ "types": "dist/index.d.ts",
6
+ "main": "./dist/ct-design-image.cjs.js",
7
+ "react-native": "src/index.native.ts",
8
+ "jsnext:main": "dist/ct-design-image.esm.js",
9
+ "module": "dist/ct-design-image.esm.js",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/ct-design-image.d.ts",
14
+ "import": "./dist/ct-design-image.esm.js",
15
+ "default": "./dist/ct-design-image.cjs.js"
16
+ }
17
+ },
18
+ "browser": {
19
+ "./dist/ct-design-image.esm.js": "./dist/ct-design-image.browser.esm.js",
20
+ "./dist/ct-design-image.cjs.js": "./dist/ct-design-image.browser.cjs.js"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src"
25
+ ],
26
+ "dependencies": {
27
+ "@cleartrip/ct-design-conditional-wrap": "4.0.0-SNAPSHOT-test.0",
28
+ "@cleartrip/ct-design-event-propagation": "4.0.0-SNAPSHOT-test.0",
29
+ "@cleartrip/ct-design-style-manager": "4.0.0-SNAPSHOT-test.0",
30
+ "@cleartrip/ct-design-theme": "4.0.0-SNAPSHOT-test.0"
31
+ },
32
+ "devDependencies": {
33
+ "next": "^14.2.35",
34
+ "@cleartrip/ct-design-types": "4.0.0-SNAPSHOT-test.0"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=16.8.0",
38
+ "react-dom": ">=16.8.0",
39
+ "react-native": ">=0.78.0",
40
+ "react-native-fast-image": ">=8.6.0",
41
+ "react-native-svg": ">=13.0.0",
42
+ "next": ">=14.0.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "react-native": {
46
+ "optional": true
47
+ },
48
+ "react-native-fast-image": {
49
+ "optional": true
50
+ },
51
+ "react-native-svg": {
52
+ "optional": true
53
+ },
54
+ "next": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "author": "Cleartrip",
62
+ "license": "ISC",
63
+ "scripts": {
64
+ "test": "echo \"Error: no test specified\" && exit 1",
65
+ "watch-package": "rollup -c -w",
66
+ "build-package": "rollup -c",
67
+ "build-package:clean": "rm -rf dist && rollup -c",
68
+ "publish-package:local": "yalc publish"
69
+ }
70
+ }
@@ -0,0 +1,118 @@
1
+ import { SyntheticEvent, useEffect, useState } from 'react';
2
+
3
+ import { Pressable } from 'react-native';
4
+ import FastImage, { ImageStyle as FastImageStyle } from 'react-native-fast-image';
5
+ import { SvgUri } from 'react-native-svg';
6
+
7
+ import { useNativeMergeStyles, useStyles } from '@cleartrip/ct-design-style-manager';
8
+ import EventCollectorProvider, { useMergeEvents, useTriggerEvents } from '@cleartrip/ct-design-event-propagation';
9
+
10
+ import { IImageProps } from './type';
11
+ import { isSvg } from './style';
12
+
13
+ /**
14
+ * Native implementation of `Image`.
15
+ *
16
+ * Migrated from yagami (aldenui) per `Migration.MD`:
17
+ * - `FastImage` is the raster renderer (RN's built-in `Image`
18
+ * doesn't cache or decode as well across large lists).
19
+ * - `.svg` URLs are detected via `isSvg` and delegated to
20
+ * `react-native-svg`'s `SvgUri`, which `FastImage` can't handle.
21
+ * - When `onClick` is supplied the tree is wrapped in a
22
+ * `Pressable` (to get press feedback + hit-slop) inside an
23
+ * `EventCollectorProvider` so upstream collectors see the tap
24
+ * through the event-propagation hook chain.
25
+ *
26
+ * No built-in fallback URL is shipped — callers provide their own
27
+ * via the `fallbackUrl` prop when a product default exists.
28
+ */
29
+ const Image = ({
30
+ src,
31
+ alt,
32
+ width,
33
+ height,
34
+ fallbackUrl,
35
+ styleConfig,
36
+ onClick,
37
+ onLoad,
38
+ onError,
39
+ resizeMode,
40
+ }: IImageProps) => {
41
+ const [imageSource, setImageSource] = useState<{ uri: string }>({
42
+ uri: src || fallbackUrl || '',
43
+ });
44
+
45
+ const imageStyles = useStyles(
46
+ () => ({
47
+ image: {
48
+ height,
49
+ width,
50
+ },
51
+ }),
52
+ [height, width],
53
+ );
54
+
55
+ const { root: customRootStyles = [] } = styleConfig || {};
56
+
57
+ const mergedImageStyles = useNativeMergeStyles(
58
+ [imageStyles.image, ...customRootStyles],
59
+ [imageStyles, customRootStyles],
60
+ );
61
+
62
+ const mergedEvents = useMergeEvents({ onClick: onClick ? [onClick] : [] });
63
+ const { onClick: onClickEvent } = useTriggerEvents(mergedEvents);
64
+
65
+ useEffect(() => {
66
+ setImageSource({ uri: src || fallbackUrl || '' });
67
+ }, [fallbackUrl, src]);
68
+
69
+ // `.svg` URLs go through react-native-svg — FastImage can't decode them.
70
+ if (isSvg(src)) {
71
+ return <SvgUri width={width} height={height} uri={src} style={mergedImageStyles} />;
72
+ }
73
+
74
+ const onImageError = () => {
75
+ if (fallbackUrl) {
76
+ setImageSource({ uri: fallbackUrl });
77
+ }
78
+ if (onError) {
79
+ // FastImage's error callback doesn't produce a DOM SyntheticEvent.
80
+ // Synthesize the minimum shape the public API promises so
81
+ // cross-platform consumers don't have to branch.
82
+ const syntheticEvent = {
83
+ currentTarget: {
84
+ src: imageSource.uri,
85
+ onerror: null,
86
+ },
87
+ } as unknown as SyntheticEvent;
88
+ onError(syntheticEvent as never);
89
+ }
90
+ };
91
+
92
+ const imageElement = (
93
+ <FastImage
94
+ source={imageSource}
95
+ style={mergedImageStyles as FastImageStyle}
96
+ accessibilityLabel={alt}
97
+ onLoad={onLoad}
98
+ onError={onImageError}
99
+ resizeMode={resizeMode}
100
+ />
101
+ );
102
+
103
+ if (!onClick) {
104
+ return imageElement;
105
+ }
106
+
107
+ return (
108
+ <EventCollectorProvider value={mergedEvents}>
109
+ <Pressable style={mergedImageStyles} onPress={onClickEvent}>
110
+ {imageElement}
111
+ </Pressable>
112
+ </EventCollectorProvider>
113
+ );
114
+ };
115
+
116
+ Image.displayName = 'Image';
117
+
118
+ export default Image;
package/src/Image.tsx ADDED
@@ -0,0 +1,143 @@
1
+ import React, { forwardRef, SyntheticEvent, useEffect, useState } from 'react';
2
+
3
+ import { useWebMergeStyles } from '@cleartrip/ct-design-style-manager';
4
+ import type { Styles } from '@cleartrip/ct-design-types';
5
+
6
+ import NextImage from 'next/image';
7
+
8
+ import { IImageProps, IImageWebRendererProps } from './type';
9
+ import staticImageStyles from './style';
10
+
11
+ /**
12
+ * Default web renderer. Emits a plain `<img>` so the design-system
13
+ * package stays framework-agnostic. Consumers that want `next/image`
14
+ * (or any other image optimizer) can inject it via the `Component`
15
+ * prop — the injected component is handed the same minimal surface
16
+ * described by `IImageWebRendererProps`.
17
+ */
18
+ const DefaultImgComponent = forwardRef<HTMLImageElement, IImageWebRendererProps>(
19
+ ({ src, alt, width, height, className, onClick, onLoad, onError }, ref) => (
20
+ <img
21
+ ref={ref}
22
+ src={src}
23
+ alt={alt}
24
+ width={width}
25
+ height={height}
26
+ className={className}
27
+ onClick={onClick}
28
+ onLoad={onLoad}
29
+ onError={onError}
30
+ />
31
+ ),
32
+ );
33
+
34
+ DefaultImgComponent.displayName = 'ImageDefaultRenderer';
35
+
36
+ const NextImageComponent = forwardRef<HTMLImageElement, IImageWebRendererProps>(
37
+ (
38
+ {
39
+ src,
40
+ alt,
41
+ width,
42
+ height,
43
+ className,
44
+ onClick,
45
+ onLoad,
46
+ onError,
47
+ priority,
48
+ loading,
49
+ blurDataURL,
50
+ unoptimized,
51
+ fetchPriority,
52
+ },
53
+ ref,
54
+ ) => (
55
+ <NextImage
56
+ ref={ref}
57
+ src={src}
58
+ alt={alt}
59
+ width={width}
60
+ height={height}
61
+ className={className}
62
+ onClick={onClick}
63
+ onLoad={onLoad}
64
+ onError={onError}
65
+ priority={priority}
66
+ loading={loading}
67
+ blurDataURL={blurDataURL}
68
+ unoptimized={unoptimized}
69
+ fetchPriority={fetchPriority}
70
+ />
71
+ ),
72
+ );
73
+
74
+ NextImageComponent.displayName = 'NextImageComponent';
75
+ /**
76
+ * Web implementation of `Image`.
77
+ *
78
+ * Migrated from yagami (aldenui) per `Migration.MD`:
79
+ * - `next/image` coupling dropped; the renderer is injectable via
80
+ * the `Component` prop (defaults to a semantic `<img>`).
81
+ * - `useWebMergeStyles` composes caller-provided `styleConfig.root`
82
+ * slots into a single className string handed to the renderer.
83
+ * - Fallback-URL handling mirrors the yagami behavior bit-for-bit:
84
+ * initial `src || fallbackUrl`, and onError swaps in `fallbackUrl`
85
+ * once (guarded by `imageSource !== fallbackUrl` to prevent an
86
+ * infinite error loop when the fallback itself 404s).
87
+ *
88
+ * The ref is forwarded to the underlying `HTMLImageElement` so
89
+ * consumers can still measure or imperatively trigger loads.
90
+ */
91
+ const Image = forwardRef<HTMLImageElement, IImageProps>(
92
+ ({ src, alt, width, height, fallbackUrl, styleConfig, onClick, onLoad, onError, Component }, ref) => {
93
+ const [imageSource, setImageSource] = useState<string>(src || fallbackUrl || '');
94
+
95
+ const { root: customRootStyles = [] } = styleConfig || {};
96
+
97
+ // Note: customRootStyles is a `ViewStyle`-shaped array; the
98
+ // style-manager flattens it into real CSS at resolution time.
99
+ const mergedRootClassName = useWebMergeStyles(
100
+ [staticImageStyles.root as Styles, ...(customRootStyles as unknown as Styles[])],
101
+ [staticImageStyles.root, customRootStyles],
102
+ );
103
+
104
+ useEffect(() => {
105
+ setImageSource(src || fallbackUrl || '');
106
+ }, [fallbackUrl, src]);
107
+
108
+ const onImageError = (e: SyntheticEvent<HTMLImageElement, Event>) => {
109
+ if (fallbackUrl && imageSource !== fallbackUrl) {
110
+ setImageSource(fallbackUrl);
111
+ }
112
+ if (onError) {
113
+ onError(e);
114
+ }
115
+ };
116
+
117
+ // The default renderer is a `forwardRef`-ed `<img>` so the ref
118
+ // passes straight through. User-injected renderers SHOULD also be
119
+ // forwardRef-wrapped (next/image is); we widen the type here so
120
+ // the `ref` attribute is accepted unconditionally.
121
+ const Renderer = (Component || NextImageComponent) as React.ComponentType<
122
+ IImageWebRendererProps & { ref?: React.Ref<HTMLImageElement> }
123
+ >;
124
+
125
+ return (
126
+ <Renderer
127
+ ref={ref}
128
+ src={imageSource}
129
+ alt={alt}
130
+ width={width}
131
+ height={height}
132
+ className={mergedRootClassName}
133
+ onClick={onClick}
134
+ onLoad={onLoad}
135
+ onError={onImageError}
136
+ />
137
+ );
138
+ },
139
+ );
140
+
141
+ Image.displayName = 'Image';
142
+
143
+ export default Image;
@@ -0,0 +1,3 @@
1
+ export { default as Image } from './Image.native';
2
+ export { isSvg } from './style';
3
+ export * from './type';
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Image } from './Image';
2
+ export { isSvg } from './style';
3
+ export * from './type';
package/src/style.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { makeStyles } from '@cleartrip/ct-design-style-manager';
2
+
3
+ /**
4
+ * Static style slots for the Image component.
5
+ *
6
+ * Image has no built-in chrome (no border/spacing/background) so the
7
+ * shared slot is an empty `root` — present so both the web and native
8
+ * entry points have a consistent `useWebMergeStyles` / `useNativeMergeStyles`
9
+ * seed to layer caller-provided styles on top of.
10
+ *
11
+ * @see Migration.MD — "Step 5 — Apply static styles with makeStyles"
12
+ */
13
+ const staticImageStyles = makeStyles(() => ({
14
+ root: {},
15
+ }));
16
+
17
+ export default staticImageStyles;
18
+
19
+ /**
20
+ * Utility: is this URL a static `.svg` asset?
21
+ *
22
+ * Native `FastImage` cannot decode SVGs, so the native entry point
23
+ * detects them and delegates to `react-native-svg`'s `SvgUri` instead.
24
+ * Web lets the browser handle SVG natively, so this helper is
25
+ * native-only in practice.
26
+ */
27
+ export function isSvg(url: string | undefined | null): boolean {
28
+ return typeof url === 'string' && url.endsWith('.svg');
29
+ }
package/src/type.ts ADDED
@@ -0,0 +1,91 @@
1
+ import type { ComponentType, SyntheticEvent } from 'react';
2
+
3
+ import type { ImageStyle } from '@cleartrip/ct-design-types';
4
+
5
+ /**
6
+ * Style-config slot shape shared by web + native. On web each entry is
7
+ * surfaced as a CSSProperties object via the style-manager; on native
8
+ * the same array flows into `react-native-fast-image`'s `style` prop.
9
+ *
10
+ * We drop a handful of RN-only keys that aren't meaningful for an
11
+ * `<img>` element — matching the yagami contract so consumer call sites
12
+ * don't have to branch per platform.
13
+ */
14
+ export interface IImageStyleConfig {
15
+ root?: Omit<ImageStyle, 'backgroundColor' | 'overlayColor' | 'borderColor'>[];
16
+ }
17
+
18
+ /**
19
+ * Minimal subset of props forwarded to the underlying web renderer
20
+ * (`<img>` by default, or a caller-injected `Component`). Kept narrow
21
+ * so callers don't accidentally rely on next/image-specific props.
22
+ */
23
+ export interface IImageWebRendererProps {
24
+ src: string;
25
+ alt: string;
26
+ width?: number;
27
+ height?: number;
28
+ className?: string;
29
+ onClick?: () => void;
30
+ onLoad?: () => void;
31
+ onError?: (e: SyntheticEvent<HTMLImageElement, Event>) => void;
32
+ priority?: boolean;
33
+ loading?: 'eager' | 'lazy';
34
+ blurDataURL?: string;
35
+ unoptimized?: boolean;
36
+ fetchPriority?: 'high' | 'low' | 'auto';
37
+ }
38
+
39
+ /**
40
+ * Public props for `Image`.
41
+ *
42
+ * This is the single shared contract between web (`Image.tsx`) and
43
+ * native (`Image.native.tsx`). Fields tagged `@web` are ignored on
44
+ * native and vice versa — the platform files destructure what they
45
+ * need and leave the rest untouched.
46
+ *
47
+ * Migration note: yagami's web Image extended `ImageProps` from
48
+ * `next/image`. The design system can't depend on Next, so this
49
+ * contract instead exposes a `Component` injection point — callers
50
+ * who want next/image optimization pass `NextImage` through; everyone
51
+ * else gets a plain `<img>`.
52
+ */
53
+ export interface IImageProps {
54
+ /** Source URL for the image. Falls back to `fallbackUrl` if empty. */
55
+ src: string;
56
+ /** Accessible name. Required on both platforms. */
57
+ alt: string;
58
+ /** Intrinsic width in px. */
59
+ width?: number;
60
+ /** Intrinsic height in px. */
61
+ height?: number;
62
+ /**
63
+ * URL to swap in when `src` fails to load. Also used as the initial
64
+ * source when `src` is empty/unset.
65
+ */
66
+ fallbackUrl?: string;
67
+ /** Fine-grained style overrides for the image element. */
68
+ styleConfig?: IImageStyleConfig;
69
+ /** Fired when the user activates the image (click / press). */
70
+ onClick?: () => void;
71
+ /** Fired once the image finishes loading. */
72
+ onLoad?: () => void;
73
+ /**
74
+ * Fired when the image fails to load. The fallback swap happens
75
+ * automatically; this callback is informational.
76
+ */
77
+ onError?: (e: SyntheticEvent<HTMLImageElement, Event>) => void;
78
+ /**
79
+ * Optional custom renderer used in place of the default `<img>`.
80
+ * Lets integrators plug in `next/image`, `gatsby-image`, or any
81
+ * other image component without the DS package taking a dependency
82
+ * on it.
83
+ * @web
84
+ */
85
+ Component?: ComponentType<IImageWebRendererProps>;
86
+ /**
87
+ * `react-native-fast-image` resize mode. Ignored on web.
88
+ * @native
89
+ */
90
+ resizeMode?: 'contain' | 'cover' | 'stretch' | 'center';
91
+ }