@escapenavigator/utils 2.0.8 → 2.0.10

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.
@@ -0,0 +1,33 @@
1
+ export declare const IMAGE_CDN_HOST_COM = "d2z3luly8bezbw.cloudfront.net";
2
+ export declare const IMAGE_CDN_HOST_RU = "picture.escapenavigator.ru";
3
+ /** @see en-ui/src/image/utils.ts — keep in sync */
4
+ export declare const imageSizes: {
5
+ readonly xs: "300x300";
6
+ readonly s: "300x300";
7
+ readonly m: "300x300";
8
+ readonly l: "300x300";
9
+ readonly xl: "300x300";
10
+ readonly xxl: "640x640";
11
+ readonly auto: "640x640";
12
+ };
13
+ export type ImageResizeSize = keyof typeof imageSizes | (string & {});
14
+ export declare const GALLERY_IMAGE_SIZE = "1280x1280";
15
+ /** Default CDN resize box when size is omitted. */
16
+ export declare const DEFAULT_IMAGE_DIMENSIONS = "300x300";
17
+ export declare const isRuImageRegion: () => boolean;
18
+ export declare const getImageCdnHost: () => string;
19
+ export declare const extractStoragePath: (src: string) => string | null;
20
+ export declare const isEscapenavigatorImage: (src: string) => boolean;
21
+ export declare const resolveImageDimensions: (size?: ImageResizeSize) => string;
22
+ /** @see en-ui getImageSrc — same logic, for raw `<img>` outside @alphakits/ui Image */
23
+ export declare const getImageUrl: (src?: string, size?: ImageResizeSize) => string | undefined;
24
+ /** @deprecated use imageSizes */
25
+ export declare const imageResizeSizes: {
26
+ readonly xs: "300x300";
27
+ readonly s: "300x300";
28
+ readonly m: "300x300";
29
+ readonly l: "300x300";
30
+ readonly xl: "300x300";
31
+ readonly xxl: "640x640";
32
+ readonly auto: "640x640";
33
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageResizeSizes = exports.getImageUrl = exports.resolveImageDimensions = exports.isEscapenavigatorImage = exports.extractStoragePath = exports.getImageCdnHost = exports.isRuImageRegion = exports.DEFAULT_IMAGE_DIMENSIONS = exports.GALLERY_IMAGE_SIZE = exports.imageSizes = exports.IMAGE_CDN_HOST_RU = exports.IMAGE_CDN_HOST_COM = void 0;
4
+ exports.IMAGE_CDN_HOST_COM = 'd2z3luly8bezbw.cloudfront.net';
5
+ exports.IMAGE_CDN_HOST_RU = 'picture.escapenavigator.ru';
6
+ const S3_BUCKET_MARKER = 'escapenavigator-images.s3';
7
+ const CDN_HOSTS = [exports.IMAGE_CDN_HOST_COM, exports.IMAGE_CDN_HOST_RU];
8
+ /** @see en-ui/src/image/utils.ts — keep in sync */
9
+ exports.imageSizes = {
10
+ xs: '300x300',
11
+ s: '300x300',
12
+ m: '300x300',
13
+ l: '300x300',
14
+ xl: '300x300',
15
+ xxl: '640x640',
16
+ auto: '640x640',
17
+ };
18
+ exports.GALLERY_IMAGE_SIZE = '1280x1280';
19
+ /** Default CDN resize box when size is omitted. */
20
+ exports.DEFAULT_IMAGE_DIMENSIONS = '300x300';
21
+ const isRuImageRegion = () => process.env.REACT_APP_REGION === 'ru';
22
+ exports.isRuImageRegion = isRuImageRegion;
23
+ const getImageCdnHost = () => (0, exports.isRuImageRegion)() ? exports.IMAGE_CDN_HOST_RU : exports.IMAGE_CDN_HOST_COM;
24
+ exports.getImageCdnHost = getImageCdnHost;
25
+ const extractStoragePath = (src) => {
26
+ if (src.includes('amazonaws.com/')) {
27
+ return src.split('amazonaws.com/')[1]?.split('?')[0] ?? null;
28
+ }
29
+ const match = src.match(/fit-in\/[^/]+\/(.+?)(?:\?|$)/);
30
+ return match?.[1] ?? null;
31
+ };
32
+ exports.extractStoragePath = extractStoragePath;
33
+ const isEscapenavigatorImage = (src) => src.includes(S3_BUCKET_MARKER) || CDN_HOSTS.some((host) => src.includes(host));
34
+ exports.isEscapenavigatorImage = isEscapenavigatorImage;
35
+ const resolveImageDimensions = (size) => {
36
+ if (!size)
37
+ return exports.DEFAULT_IMAGE_DIMENSIONS;
38
+ if (size in exports.imageSizes) {
39
+ return exports.imageSizes[size];
40
+ }
41
+ return size;
42
+ };
43
+ exports.resolveImageDimensions = resolveImageDimensions;
44
+ /** @see en-ui getImageSrc — same logic, for raw `<img>` outside @alphakits/ui Image */
45
+ const getImageUrl = (src, size) => {
46
+ if (!src || src.startsWith('data:'))
47
+ return src;
48
+ const dimensions = (0, exports.resolveImageDimensions)(size);
49
+ if (!(0, exports.isEscapenavigatorImage)(src))
50
+ return src;
51
+ const path = (0, exports.extractStoragePath)(src);
52
+ if (!path)
53
+ return src;
54
+ return `https://${(0, exports.getImageCdnHost)()}/fit-in/${dimensions}/${path}`;
55
+ };
56
+ exports.getImageUrl = getImageUrl;
57
+ /** @deprecated use imageSizes */
58
+ exports.imageResizeSizes = exports.imageSizes;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from './get-full-name';
14
14
  export * from './get-handled-error-message';
15
15
  export * from './get-order-cancelation-state';
16
16
  export * from './get-service-error';
17
+ export * from './image-url';
17
18
  export * from './is-axios-error';
18
19
  export * from './is-network-error';
19
20
  export * from './is-stale-chunk-error';
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __exportStar(require("./get-full-name"), exports);
30
30
  __exportStar(require("./get-handled-error-message"), exports);
31
31
  __exportStar(require("./get-order-cancelation-state"), exports);
32
32
  __exportStar(require("./get-service-error"), exports);
33
+ __exportStar(require("./image-url"), exports);
33
34
  __exportStar(require("./is-axios-error"), exports);
34
35
  __exportStar(require("./is-network-error"), exports);
35
36
  __exportStar(require("./is-stale-chunk-error"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
17
- "@escapenavigator/types": "^2.0.8",
17
+ "@escapenavigator/types": "^2.0.9",
18
18
  "axios": "^0.21.4",
19
19
  "class-transformer": "^0.5.1",
20
20
  "class-validator": "^0.13.2",
@@ -29,5 +29,5 @@
29
29
  "ts-jest": "^29.1.1",
30
30
  "typescript": "^5.6"
31
31
  },
32
- "gitHead": "f88105efecc1893d1eb103e8b2069161b0e6dd0a"
32
+ "gitHead": "f6880726301abd10e18e00f30e11e96c0eff3d12"
33
33
  }