@mts-pjsc/image-optimize 1.1.0 → 1.1.3

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.
@@ -10,19 +10,31 @@ export interface IImageOptions {
10
10
  export declare class Image<P extends IImageOptions> extends React.Component<P> {
11
11
  static isShowDiagnostic: boolean;
12
12
  static controlPoints: number[];
13
- private static isAvif;
14
- private static isWebP;
15
13
  /**
16
- * Change for local development.
14
+ * Image optimizer will take source url for show image.
15
+ *
16
+ * This is required when working on localhost.
17
+ * Because a remote microservice cannot make requests to your localhost.
18
+ *
19
+ * Example:
20
+ * Image.isUseSourceUrl = process.env.NODE_ENV !== "production";
21
+ */
22
+ static isUseSourceUrl: boolean;
23
+ /**
24
+ * Image optimizer will change origin to other domain.
25
+ *
26
+ * This is necessary when you developing locally, this will take pictures from the DEV server by CORS.
17
27
  *
18
- * The server microservice will not be able to make a request to your localhost.
19
- * Therefore, when developing locally, you must specify a production or development server origin.
28
+ * Also, this parameter must be specified if the component works in the microfront.
29
+ * Then you need to specify the address to the server with pictures.
20
30
  *
21
31
  * Example:
22
- * https://tb.mts.ru
32
+ * Image.imgOrigin = https://tb.mts.ru
23
33
  *
24
34
  */
25
- static imgOrigin: string;
35
+ static imgOrigin?: string;
36
+ private static isAvif;
37
+ private static isWebP;
26
38
  resultUrl: string;
27
39
  resizeCheckTimeout: number;
28
40
  thisComponent: HTMLImageElement | null;
@@ -42,6 +42,10 @@ export class Image extends React.Component {
42
42
  }, src: this.resultUrl }));
43
43
  }
44
44
  async checkImage(isResize = false) {
45
+ if (Image.isUseSourceUrl && this.thisComponent) {
46
+ this.thisComponent.src = this.resultUrl;
47
+ return;
48
+ }
45
49
  if (this.checks > 1) {
46
50
  return;
47
51
  }
@@ -98,7 +102,8 @@ export class Image extends React.Component {
98
102
  return Image.controlPoints[index];
99
103
  }
100
104
  makeResultUrl(optimalSize) {
101
- const sourceUrl = new URL(this.sourceUrl, Image.imgOrigin);
105
+ var _a;
106
+ const sourceUrl = new URL(this.sourceUrl, (_a = Image.imgOrigin) !== null && _a !== void 0 ? _a : location.origin);
102
107
  const url = new URL("/optimizer/optimize", location.origin);
103
108
  url.searchParams.set("src", sourceUrl.toString());
104
109
  url.searchParams.set("size", String(optimalSize));
@@ -168,17 +173,28 @@ export class Image extends React.Component {
168
173
  }
169
174
  Image.isShowDiagnostic = false;
170
175
  Image.controlPoints = [160, 320, 640, 1280, 1920];
171
- Image.isAvif = null;
172
- Image.isWebP = null;
173
176
  /**
174
- * Change for local development.
177
+ * Image optimizer will take source url for show image.
178
+ *
179
+ * This is required when working on localhost.
180
+ * Because a remote microservice cannot make requests to your localhost.
181
+ *
182
+ * Example:
183
+ * Image.isUseSourceUrl = process.env.NODE_ENV !== "production";
184
+ */
185
+ Image.isUseSourceUrl = false;
186
+ /**
187
+ * Image optimizer will change origin to other domain.
175
188
  *
176
- * The server microservice will not be able to make a request to your localhost.
177
- * Therefore, when developing locally, you must specify a production or development server origin.
189
+ * This is necessary when you developing locally, this will take pictures from the DEV server by CORS.
190
+ *
191
+ * Also, this parameter must be specified if the component works in the microfront.
192
+ * Then you need to specify the address to the server with pictures.
178
193
  *
179
194
  * Example:
180
- * https://tb.mts.ru
195
+ * Image.imgOrigin = https://tb.mts.ru
181
196
  *
182
197
  */
183
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-binary-expression
184
- Image.imgOrigin = typeof process === void 0 ? location.origin : "";
198
+ Image.imgOrigin = void 0;
199
+ Image.isAvif = null;
200
+ Image.isWebP = null;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mts-pjsc/image-optimize",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "React component for image optimizer",
5
- "main": "dist/es5/index.js",
6
- "module": "dist/esnext/index.js",
7
- "esnext": "dist/esnext/index.js",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "esnext": "dist/index.js",
8
8
  "type": "module",
9
9
  "scripts": {
10
10
  "eslint": "eslint --fix -c .eslintrc.cjs --ext .tsx,.ts,.jsx,.js ./src/",