@mts-pjsc/image-optimize 1.1.1 → 1.1.4
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/components/Image.d.ts +19 -7
- package/dist/components/Image.js +25 -9
- package/package.json +1 -1
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
19
|
-
*
|
|
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
|
|
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;
|
package/dist/components/Image.js
CHANGED
|
@@ -46,6 +46,10 @@ export class Image extends React.Component {
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
this.checks += 1;
|
|
49
|
+
if (Image.isUseSourceUrl && this.thisComponent) {
|
|
50
|
+
this.thisComponent.src = this.sourceUrl;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
49
53
|
if (Image.isAvif === null || Image.isWebP === null) {
|
|
50
54
|
await this.initImageFormats();
|
|
51
55
|
}
|
|
@@ -98,7 +102,8 @@ export class Image extends React.Component {
|
|
|
98
102
|
return Image.controlPoints[index];
|
|
99
103
|
}
|
|
100
104
|
makeResultUrl(optimalSize) {
|
|
101
|
-
|
|
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
|
-
*
|
|
177
|
+
* Image optimizer will take source url for show image.
|
|
175
178
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
179
|
+
* This is required when working on localhost.
|
|
180
|
+
* Because a remote microservice cannot make requests to your localhost.
|
|
178
181
|
*
|
|
179
182
|
* Example:
|
|
180
|
-
*
|
|
183
|
+
* Image.isUseSourceUrl = process.env.NODE_ENV !== "production";
|
|
184
|
+
*/
|
|
185
|
+
Image.isUseSourceUrl = false;
|
|
186
|
+
/**
|
|
187
|
+
* Image optimizer will change origin to other domain.
|
|
188
|
+
*
|
|
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.
|
|
193
|
+
*
|
|
194
|
+
* Example:
|
|
195
|
+
* Image.imgOrigin = https://tb.mts.ru
|
|
181
196
|
*
|
|
182
197
|
*/
|
|
183
|
-
|
|
184
|
-
Image.
|
|
198
|
+
Image.imgOrigin = void 0;
|
|
199
|
+
Image.isAvif = null;
|
|
200
|
+
Image.isWebP = null;
|