@mts-pjsc/image-optimize 1.0.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/LICENSE +201 -0
- package/README.md +49 -0
- package/dist/es5/components/Image.js +166 -0
- package/dist/es5/components/Image.js.map +1 -0
- package/dist/es5/helpers/check-avif-feature.js +17 -0
- package/dist/es5/helpers/check-avif-feature.js.map +1 -0
- package/dist/es5/helpers/check-webp-feature.js +23 -0
- package/dist/es5/helpers/check-webp-feature.js.map +1 -0
- package/dist/es5/index.js +9 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/esnext/components/Image.js +143 -0
- package/dist/esnext/components/Image.js.map +1 -0
- package/dist/esnext/helpers/check-avif-feature.js +13 -0
- package/dist/esnext/helpers/check-avif-feature.js.map +1 -0
- package/dist/esnext/helpers/check-webp-feature.js +19 -0
- package/dist/esnext/helpers/check-webp-feature.js.map +1 -0
- package/dist/esnext/index.js +6 -0
- package/dist/esnext/index.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Microservice for responsive resize, compression and optimization of images on the fly for web pages.
|
|
2
|
+
|
|
3
|
+
Optimizing images helps reduce image weight and increases website loading speed, which is very important for both users and search engines. For these purposes, we have created a microservice that perfectly copes with this task.
|
|
4
|
+
|
|
5
|
+
Features:
|
|
6
|
+
- Resize images for the user's screen size,
|
|
7
|
+
- Image compressions to reduce traffic,
|
|
8
|
+
- Converting images to modern formats such as webp and avif,
|
|
9
|
+
- Works with dynamically content, compression occurs on the fly,
|
|
10
|
+
- High compression speed, an average picture is processed in just 200 ms,
|
|
11
|
+
- Includes exporter of metrics for Prometheus,
|
|
12
|
+
- Supports basic authorization for multiple domains and endpoints,
|
|
13
|
+
- Supports security restrictions for allowed addresses.
|
|
14
|
+
|
|
15
|
+
### Try
|
|
16
|
+
To try the microservice features, run the container with the command:
|
|
17
|
+
```sh
|
|
18
|
+
docker run -it --rm -p 3000:3000 mts-optimize
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Now you can open the browser and check the work with the command:
|
|
22
|
+
```sh
|
|
23
|
+
http://localhost:3000/optimize?size=1060&format=webp&src=https://tb.mts.ru/static/landing/images-index2/banner/slider/partners.png
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
By changing the src, size, format parameters, you can choose the path to the image, the final size and the image format.
|
|
27
|
+
|
|
28
|
+
### Use
|
|
29
|
+
To start the microservice in production, use the command:
|
|
30
|
+
```sh
|
|
31
|
+
docker run -d --restart always -p 3000:3000 mts-optimize
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Container parameters
|
|
35
|
+
- `-e PORT=3000` - the port on which the microservice will be launched, default 3000.
|
|
36
|
+
- `-e ALLOW_SIZES="100,200,1024-1920"` - an array of allowed sizes for the resulting images, default 100-1920. Use specific values to prevent heavy loads on the server.
|
|
37
|
+
- `-e ALLOW_SOURCES="https%3A%2F%2Ftb.mts.ru%2F"` - url array of allowed addresses for image sources, default * (any). Use comma as separator. It is recommended to apply encodeURIComponent to url.
|
|
38
|
+
- `-e BASIC_AUTHS="https%3A%2F%2Ftb.mts.ru%2F"` - an array of endpoints with basic authorization parameters, default empty. Has format encodeURIComponent("url"):login:password. Use comma as separator.
|
|
39
|
+
|
|
40
|
+
### Components for web
|
|
41
|
+
Right now you can use sample from the ./components-samples/ReactLazyImg.ts(add link after publishing) file. Just copy the file to your project and use it. The component inherits interface of the html img element. The component automatically check the most suitable picture in size and formats supported by the browser and selects the most optimal picture for display.
|
|
42
|
+
|
|
43
|
+
Sample for use in React:
|
|
44
|
+
```typescript
|
|
45
|
+
<LazyImg
|
|
46
|
+
alt="Sample of work mts-optimize"
|
|
47
|
+
src="/static/landing/images-getmeback/phone-fon.png"
|
|
48
|
+
/>
|
|
49
|
+
```
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Image = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var check_avif_feature_1 = require("../helpers/check-avif-feature");
|
|
8
|
+
var check_webp_feature_1 = require("../helpers/check-webp-feature");
|
|
9
|
+
var Image = /** @class */ (function (_super) {
|
|
10
|
+
(0, tslib_1.__extends)(Image, _super);
|
|
11
|
+
function Image(props) {
|
|
12
|
+
var _this = _super.call(this, props) || this;
|
|
13
|
+
_this.resultUrl = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
14
|
+
_this.resizeCheckTimeout = 0;
|
|
15
|
+
_this.sourceUrl = "";
|
|
16
|
+
_this.extensionsRegexp = /\.\w+$/u;
|
|
17
|
+
_this.controlPoints = [160, 320, 640, 1280, 1920];
|
|
18
|
+
_this.lastOptimalSize = -1;
|
|
19
|
+
_this.checks = 0;
|
|
20
|
+
_this.windowResizeHandler = function () { return _this.onWindowResize(); };
|
|
21
|
+
return _this;
|
|
22
|
+
}
|
|
23
|
+
Image.prototype.componentDidMount = function () {
|
|
24
|
+
this.shouldComponentUpdate(this.props);
|
|
25
|
+
window.addEventListener("resize", this.windowResizeHandler);
|
|
26
|
+
};
|
|
27
|
+
Image.prototype.shouldComponentUpdate = function (props) {
|
|
28
|
+
var _this = this;
|
|
29
|
+
if (this.sourceUrl !== props.src) {
|
|
30
|
+
this.sourceUrl = props.src;
|
|
31
|
+
this.checks = 0;
|
|
32
|
+
requestAnimationFrame(function () { return _this.checkImage(); });
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
Image.prototype.componentWillUnmount = function () {
|
|
38
|
+
window.removeEventListener("resize", this.windowResizeHandler);
|
|
39
|
+
};
|
|
40
|
+
Image.prototype.render = function () {
|
|
41
|
+
var _this = this;
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)("img", { alt: this.props.alt, className: this.props.className, onLoad: function () { return requestAnimationFrame(function () { return _this.checkImage(); }); }, ref: function (elem) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
_this.thisComponent = elem;
|
|
45
|
+
(_b = (_a = _this.props).setRef) === null || _b === void 0 ? void 0 : _b.call(_a, elem);
|
|
46
|
+
}, src: this.resultUrl }, void 0));
|
|
47
|
+
};
|
|
48
|
+
// eslint-disable-next-line max-statements, complexity, max-lines-per-function
|
|
49
|
+
Image.prototype.checkImage = function (isResize) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (isResize === void 0) { isResize = false; }
|
|
52
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
53
|
+
var result, result, containerSize, element, indexOptimalSize, sourceUrl, url, match, format, resultUrl;
|
|
54
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
55
|
+
switch (_b.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
if (!this.thisComponent) {
|
|
58
|
+
return [2 /*return*/];
|
|
59
|
+
}
|
|
60
|
+
if (this.checks > 1) {
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
if (!(Image.isAvif === null)) return [3 /*break*/, 2];
|
|
64
|
+
return [4 /*yield*/, (0, check_avif_feature_1.checkAvifFeature)()];
|
|
65
|
+
case 1:
|
|
66
|
+
result = _b.sent();
|
|
67
|
+
// !!! Eslint alert it's true, upgrade algorithm later
|
|
68
|
+
// eslint-disable-next-line require-atomic-updates
|
|
69
|
+
Image.isAvif = result;
|
|
70
|
+
this.checkImage();
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
case 2:
|
|
73
|
+
if (!(!Image.isAvif && Image.isWebP === null)) return [3 /*break*/, 4];
|
|
74
|
+
return [4 /*yield*/, (0, check_webp_feature_1.checkWebpFeature)()];
|
|
75
|
+
case 3:
|
|
76
|
+
result = _b.sent();
|
|
77
|
+
// eslint-disable-next-line require-atomic-updates
|
|
78
|
+
Image.isWebP = result;
|
|
79
|
+
this.checkImage();
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
case 4:
|
|
82
|
+
// Checks +1 after check webp support
|
|
83
|
+
this.checks += 1;
|
|
84
|
+
containerSize = 0;
|
|
85
|
+
element = this.thisComponent;
|
|
86
|
+
while (containerSize < 2 && Boolean(element)) {
|
|
87
|
+
containerSize = element.getBoundingClientRect().width ||
|
|
88
|
+
Number.parseFloat(getComputedStyle(element).width) || 0;
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
|
|
90
|
+
element = element.parentElement;
|
|
91
|
+
}
|
|
92
|
+
containerSize *= window.devicePixelRatio;
|
|
93
|
+
indexOptimalSize = this.controlPoints
|
|
94
|
+
.findIndex(function (width) { return containerSize <= width; });
|
|
95
|
+
if (indexOptimalSize < 0) { // If bigger then maximum size or NaN
|
|
96
|
+
indexOptimalSize = this.controlPoints.length - 1;
|
|
97
|
+
}
|
|
98
|
+
indexOptimalSize += (_a = this.props.offset) !== null && _a !== void 0 ? _a : 0;
|
|
99
|
+
if (indexOptimalSize < 0) {
|
|
100
|
+
indexOptimalSize = 0;
|
|
101
|
+
}
|
|
102
|
+
else if (indexOptimalSize >= this.controlPoints.length) {
|
|
103
|
+
indexOptimalSize = this.controlPoints.length - 1;
|
|
104
|
+
}
|
|
105
|
+
if (!isResize && this.lastOptimalSize >= 0 && this.lastOptimalSize !== indexOptimalSize) {
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.warn("New image size", this.controlPoints[this.lastOptimalSize], this.controlPoints[indexOptimalSize], this.sourceUrl);
|
|
108
|
+
}
|
|
109
|
+
this.lastOptimalSize = indexOptimalSize;
|
|
110
|
+
sourceUrl = new URL(this.sourceUrl, location.origin);
|
|
111
|
+
url = new URL("/optimizer/optimize", location.origin);
|
|
112
|
+
url.searchParams.set("src", sourceUrl.toString());
|
|
113
|
+
url.searchParams.set("size", String(this.controlPoints[indexOptimalSize]));
|
|
114
|
+
if (typeof this.props.quality === "number") {
|
|
115
|
+
url.searchParams.set("quality", String(this.props.quality));
|
|
116
|
+
}
|
|
117
|
+
match = this.extensionsRegexp.exec(sourceUrl.pathname);
|
|
118
|
+
format = "";
|
|
119
|
+
if (Image.isAvif) {
|
|
120
|
+
format = "avif";
|
|
121
|
+
}
|
|
122
|
+
else if (Image.isWebP === true) {
|
|
123
|
+
format = "webp";
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
format = String(match === null || match === void 0 ? void 0 : match[0])
|
|
127
|
+
.replace(".", "")
|
|
128
|
+
.replace("jpg", "jpeg");
|
|
129
|
+
}
|
|
130
|
+
url.searchParams.set("format", format);
|
|
131
|
+
resultUrl = url.toString();
|
|
132
|
+
if (this.resultUrl !== resultUrl) {
|
|
133
|
+
this.resultUrl = resultUrl;
|
|
134
|
+
this.thisComponent.src = this.resultUrl;
|
|
135
|
+
if (process.env.NODE_ENV !== "production" && Image.isShowDiagnostic) {
|
|
136
|
+
// eslint-disable-next-line no-console
|
|
137
|
+
console.log([
|
|
138
|
+
"🏄 Image optimization:",
|
|
139
|
+
"Container size ".concat(containerSize, "px,"),
|
|
140
|
+
"optimal size ".concat(this.controlPoints[indexOptimalSize], ","),
|
|
141
|
+
"image ".concat(this.sourceUrl)
|
|
142
|
+
].join(" "));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
Image.prototype.onWindowResize = function () {
|
|
151
|
+
var _this = this;
|
|
152
|
+
if (this.resizeCheckTimeout) {
|
|
153
|
+
clearTimeout(this.resizeCheckTimeout);
|
|
154
|
+
}
|
|
155
|
+
this.resizeCheckTimeout = window.setTimeout(function () {
|
|
156
|
+
_this.checks = 0;
|
|
157
|
+
_this.checkImage(true);
|
|
158
|
+
}, 500);
|
|
159
|
+
};
|
|
160
|
+
Image.isShowDiagnostic = false;
|
|
161
|
+
Image.isAvif = null;
|
|
162
|
+
Image.isWebP = null;
|
|
163
|
+
return Image;
|
|
164
|
+
}(react_1.default.Component));
|
|
165
|
+
exports.Image = Image;
|
|
166
|
+
//# sourceMappingURL=Image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../src/components/Image.tsx"],"names":[],"mappings":";;;;;AAAA,+BAA0B;AAC1B,oEAA+D;AAC/D,oEAA+D;AAW/D;IAAoD,sCAAkB;IA0BlE,eAAoB,KAAQ;QAA5B,YACI,kBAAM,KAAK,CAAC,SAGf;QAtBM,eAAS,GAAW,gFAAgF,CAAC;QAErG,wBAAkB,GAAW,CAAC,CAAC;QAI9B,eAAS,GAAW,EAAE,CAAC;QAEd,sBAAgB,GAAW,SAAS,CAAC;QAErC,mBAAa,GAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAI/D,qBAAe,GAAW,CAAC,CAAC,CAAC;QAE7B,YAAM,GAAW,CAAC,CAAC;QAKvB,KAAI,CAAC,mBAAmB,GAAG,cAAY,OAAA,KAAI,CAAC,cAAc,EAAE,EAArB,CAAqB,CAAC;;IACjE,CAAC;IAEM,iCAAiB,GAAxB;QACI,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CA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CAAC,kBAAkB,CAAC,CAAC;SACzC;QAED,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,UAAU,CAAC;YACxC,KAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAChB,KAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,EAAE,GAAG,CAAC,CAAC;IACZ,CAAC;IAhLa,sBAAgB,GAAY,KAAK,CAAC;IAElC,YAAM,GAAmB,IAAI,CAAC;IAE9B,YAAM,GAAmB,IAAI,CAAC;IA8KhD,YAAC;CAAA,AApLD,CAAoD,eAAK,CAAC,SAAS,GAoLlE;AApLY,sBAAK"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkAvifFeature = void 0;
|
|
4
|
+
var checkAvifFeature = function () { return new Promise(function (resolve) {
|
|
5
|
+
var img = new Image();
|
|
6
|
+
img.onload = function () {
|
|
7
|
+
var result = (img.width > 0) && (img.height > 0);
|
|
8
|
+
resolve(result);
|
|
9
|
+
};
|
|
10
|
+
img.onerror = function () {
|
|
11
|
+
resolve(false);
|
|
12
|
+
};
|
|
13
|
+
// eslint-disable-next-line max-len
|
|
14
|
+
img.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=";
|
|
15
|
+
}); };
|
|
16
|
+
exports.checkAvifFeature = checkAvifFeature;
|
|
17
|
+
//# sourceMappingURL=check-avif-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-avif-feature.js","sourceRoot":"","sources":["../../../src/helpers/check-avif-feature.ts"],"names":[],"mappings":";;;AACO,IAAM,gBAAgB,GAAG,cAAwB,OAAA,IAAI,OAAO,CAAU,UAAC,OAAkC;IAC5G,IAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IACxB,GAAG,CAAC,MAAM,GAAG;QACT,IAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,GAAG,CAAC,OAAO,GAAG;QACV,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IACF,mCAAmC;IACnC,GAAG,CAAC,GAAG,GAAG,ybAAyb,CAAC;AACxc,CAAC,CAAC,EAXsD,CAWtD,CAAC;AAXU,QAAA,gBAAgB,oBAW1B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkWebpFeature = void 0;
|
|
4
|
+
var checkWebpFeature = function () { return new Promise(function (resolve) {
|
|
5
|
+
var kTestImages = {
|
|
6
|
+
lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
|
|
7
|
+
lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
|
|
8
|
+
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
|
|
9
|
+
animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////" +
|
|
10
|
+
"AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
|
|
11
|
+
};
|
|
12
|
+
var img = new Image();
|
|
13
|
+
img.onload = function () {
|
|
14
|
+
var result = (img.width > 0) && (img.height > 0);
|
|
15
|
+
resolve(result);
|
|
16
|
+
};
|
|
17
|
+
img.onerror = function () {
|
|
18
|
+
resolve(false);
|
|
19
|
+
};
|
|
20
|
+
img.src = "data:image/webp;base64,".concat(kTestImages.lossless);
|
|
21
|
+
}); };
|
|
22
|
+
exports.checkWebpFeature = checkWebpFeature;
|
|
23
|
+
//# sourceMappingURL=check-webp-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-webp-feature.js","sourceRoot":"","sources":["../../../src/helpers/check-webp-feature.ts"],"names":[],"mappings":";;;AACO,IAAM,gBAAgB,GAAG,cAAwB,OAAA,IAAI,OAAO,CAAU,UAAC,OAAkC;IAC5G,IAAM,WAAW,GAAG;QAChB,KAAK,EAAE,0DAA0D;QACjE,QAAQ,EAAE,kDAAkD;QAC5D,KAAK,EAAE,kHAAkH;QACzH,SAAS,EAAE,0DAA0D;YACjE,kEAAkE;KACzE,CAAC;IACF,IAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IACxB,GAAG,CAAC,MAAM,GAAG;QACT,IAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,GAAG,CAAC,OAAO,GAAG;QACV,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IACF,GAAG,CAAC,GAAG,GAAG,iCAA0B,WAAW,CAAC,QAAQ,CAAE,CAAC;AAC/D,CAAC,CAAC,EAjBsD,CAiBtD,CAAC;AAjBU,QAAA,gBAAgB,oBAiB1B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
// Components
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./components/Image"), exports);
|
|
6
|
+
// Helpers
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./helpers/check-avif-feature"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./helpers/check-webp-feature"), exports);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,aAAa;AACb,kEAAmC;AAEnC,UAAU;AACV,4EAA6C;AAC7C,4EAA6C"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { checkAvifFeature } from "../helpers/check-avif-feature";
|
|
4
|
+
import { checkWebpFeature } from "../helpers/check-webp-feature";
|
|
5
|
+
export class Image extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.resultUrl = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
9
|
+
this.resizeCheckTimeout = 0;
|
|
10
|
+
this.sourceUrl = "";
|
|
11
|
+
this.extensionsRegexp = /\.\w+$/u;
|
|
12
|
+
this.controlPoints = [160, 320, 640, 1280, 1920];
|
|
13
|
+
this.lastOptimalSize = -1;
|
|
14
|
+
this.checks = 0;
|
|
15
|
+
this.windowResizeHandler = () => this.onWindowResize();
|
|
16
|
+
}
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
this.shouldComponentUpdate(this.props);
|
|
19
|
+
window.addEventListener("resize", this.windowResizeHandler);
|
|
20
|
+
}
|
|
21
|
+
shouldComponentUpdate(props) {
|
|
22
|
+
if (this.sourceUrl !== props.src) {
|
|
23
|
+
this.sourceUrl = props.src;
|
|
24
|
+
this.checks = 0;
|
|
25
|
+
requestAnimationFrame(() => this.checkImage());
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
componentWillUnmount() {
|
|
31
|
+
window.removeEventListener("resize", this.windowResizeHandler);
|
|
32
|
+
}
|
|
33
|
+
render() {
|
|
34
|
+
return (_jsx("img", { alt: this.props.alt, className: this.props.className, onLoad: () => requestAnimationFrame(() => this.checkImage()), ref: (elem) => {
|
|
35
|
+
this.thisComponent = elem;
|
|
36
|
+
this.props.setRef?.(elem);
|
|
37
|
+
}, src: this.resultUrl }, void 0));
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line max-statements, complexity, max-lines-per-function
|
|
40
|
+
async checkImage(isResize = false) {
|
|
41
|
+
if (!this.thisComponent) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (this.checks > 1) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Image.isAvif === null) {
|
|
48
|
+
const result = await checkAvifFeature();
|
|
49
|
+
// !!! Eslint alert it's true, upgrade algorithm later
|
|
50
|
+
// eslint-disable-next-line require-atomic-updates
|
|
51
|
+
Image.isAvif = result;
|
|
52
|
+
this.checkImage();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!Image.isAvif && Image.isWebP === null) {
|
|
56
|
+
const result = await checkWebpFeature();
|
|
57
|
+
// eslint-disable-next-line require-atomic-updates
|
|
58
|
+
Image.isWebP = result;
|
|
59
|
+
this.checkImage();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// Checks +1 after check webp support
|
|
63
|
+
this.checks += 1;
|
|
64
|
+
// Find optimal size
|
|
65
|
+
let containerSize = 0;
|
|
66
|
+
let element = this.thisComponent;
|
|
67
|
+
while (containerSize < 2 && Boolean(element)) {
|
|
68
|
+
containerSize = element.getBoundingClientRect().width ||
|
|
69
|
+
Number.parseFloat(getComputedStyle(element).width) || 0;
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
|
|
71
|
+
element = element.parentElement;
|
|
72
|
+
}
|
|
73
|
+
containerSize *= window.devicePixelRatio;
|
|
74
|
+
let indexOptimalSize = this.controlPoints
|
|
75
|
+
.findIndex((width) => containerSize <= width);
|
|
76
|
+
if (indexOptimalSize < 0) { // If bigger then maximum size or NaN
|
|
77
|
+
indexOptimalSize = this.controlPoints.length - 1;
|
|
78
|
+
}
|
|
79
|
+
indexOptimalSize += this.props.offset ?? 0;
|
|
80
|
+
if (indexOptimalSize < 0) {
|
|
81
|
+
indexOptimalSize = 0;
|
|
82
|
+
}
|
|
83
|
+
else if (indexOptimalSize >= this.controlPoints.length) {
|
|
84
|
+
indexOptimalSize = this.controlPoints.length - 1;
|
|
85
|
+
}
|
|
86
|
+
if (!isResize && this.lastOptimalSize >= 0 && this.lastOptimalSize !== indexOptimalSize) {
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.warn("New image size", this.controlPoints[this.lastOptimalSize], this.controlPoints[indexOptimalSize], this.sourceUrl);
|
|
89
|
+
}
|
|
90
|
+
this.lastOptimalSize = indexOptimalSize;
|
|
91
|
+
// Make correct source url
|
|
92
|
+
const sourceUrl = new URL(this.sourceUrl, location.origin);
|
|
93
|
+
// Make result url
|
|
94
|
+
const url = new URL("/optimizer/optimize", location.origin);
|
|
95
|
+
url.searchParams.set("src", sourceUrl.toString());
|
|
96
|
+
url.searchParams.set("size", String(this.controlPoints[indexOptimalSize]));
|
|
97
|
+
if (typeof this.props.quality === "number") {
|
|
98
|
+
url.searchParams.set("quality", String(this.props.quality));
|
|
99
|
+
}
|
|
100
|
+
const match = this.extensionsRegexp.exec(sourceUrl.pathname);
|
|
101
|
+
let format = "";
|
|
102
|
+
if (Image.isAvif) {
|
|
103
|
+
format = "avif";
|
|
104
|
+
}
|
|
105
|
+
else if (Image.isWebP === true) {
|
|
106
|
+
format = "webp";
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
format = String(match?.[0])
|
|
110
|
+
.replace(".", "")
|
|
111
|
+
.replace("jpg", "jpeg");
|
|
112
|
+
}
|
|
113
|
+
url.searchParams.set("format", format);
|
|
114
|
+
// Apply result url
|
|
115
|
+
const resultUrl = url.toString();
|
|
116
|
+
if (this.resultUrl !== resultUrl) {
|
|
117
|
+
this.resultUrl = resultUrl;
|
|
118
|
+
this.thisComponent.src = this.resultUrl;
|
|
119
|
+
if (process.env.NODE_ENV !== "production" && Image.isShowDiagnostic) {
|
|
120
|
+
// eslint-disable-next-line no-console
|
|
121
|
+
console.log([
|
|
122
|
+
"🏄 Image optimization:",
|
|
123
|
+
`Container size ${containerSize}px,`,
|
|
124
|
+
`optimal size ${this.controlPoints[indexOptimalSize]},`,
|
|
125
|
+
`image ${this.sourceUrl}`
|
|
126
|
+
].join(" "));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
onWindowResize() {
|
|
131
|
+
if (this.resizeCheckTimeout) {
|
|
132
|
+
clearTimeout(this.resizeCheckTimeout);
|
|
133
|
+
}
|
|
134
|
+
this.resizeCheckTimeout = window.setTimeout(() => {
|
|
135
|
+
this.checks = 0;
|
|
136
|
+
this.checkImage(true);
|
|
137
|
+
}, 500);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
Image.isShowDiagnostic = false;
|
|
141
|
+
Image.isAvif = null;
|
|
142
|
+
Image.isWebP = null;
|
|
143
|
+
//# sourceMappingURL=Image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../src/components/Image.tsx"],"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QACjC,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE;YAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;YACxC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,KAAK,CAAC,gBAAgB,EAAE;gBACjE,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC;oBACR,wBAAwB;oBACxB,kBAAkB,aAAa,KAAK;oBACpC,gBAAgB,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG;oBACvD,SAAS,IAAI,CAAC,SAAS,EAAE;iBAC5B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;aAChB;SACJ;IACL,CAAC;IAEO,cAAc;QAClB,IAAI,IAAI,CAAC,kBAAkB,EAAE;YACzB,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACzC;QAED,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;YAC7C,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,EAAE,GAAG,CAAC,CAAC;IACZ,CAAC;;AAhLa,sBAAgB,GAAY,KAAK,CAAC;AAElC,YAAM,GAAmB,IAAI,CAAC;AAE9B,YAAM,GAAmB,IAAI,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const checkAvifFeature = () => new Promise((resolve) => {
|
|
2
|
+
const img = new Image();
|
|
3
|
+
img.onload = () => {
|
|
4
|
+
const result = (img.width > 0) && (img.height > 0);
|
|
5
|
+
resolve(result);
|
|
6
|
+
};
|
|
7
|
+
img.onerror = () => {
|
|
8
|
+
resolve(false);
|
|
9
|
+
};
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
11
|
+
img.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=";
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=check-avif-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-avif-feature.js","sourceRoot":"","sources":["../../../src/helpers/check-avif-feature.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAqB,EAAE,CAAC,IAAI,OAAO,CAAU,CAAC,OAAkC,EAAE,EAAE;IAChH,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IACxB,GAAG,CAAC,MAAM,GAAG,GAAS,EAAE;QACpB,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,GAAG,CAAC,OAAO,GAAG,GAAS,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IACF,mCAAmC;IACnC,GAAG,CAAC,GAAG,GAAG,ybAAyb,CAAC;AACxc,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const checkWebpFeature = () => new Promise((resolve) => {
|
|
2
|
+
const kTestImages = {
|
|
3
|
+
lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
|
|
4
|
+
lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
|
|
5
|
+
alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
|
|
6
|
+
animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////" +
|
|
7
|
+
"AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
|
|
8
|
+
};
|
|
9
|
+
const img = new Image();
|
|
10
|
+
img.onload = () => {
|
|
11
|
+
const result = (img.width > 0) && (img.height > 0);
|
|
12
|
+
resolve(result);
|
|
13
|
+
};
|
|
14
|
+
img.onerror = () => {
|
|
15
|
+
resolve(false);
|
|
16
|
+
};
|
|
17
|
+
img.src = `data:image/webp;base64,${kTestImages.lossless}`;
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=check-webp-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-webp-feature.js","sourceRoot":"","sources":["../../../src/helpers/check-webp-feature.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAqB,EAAE,CAAC,IAAI,OAAO,CAAU,CAAC,OAAkC,EAAE,EAAE;IAChH,MAAM,WAAW,GAAG;QAChB,KAAK,EAAE,0DAA0D;QACjE,QAAQ,EAAE,kDAAkD;QAC5D,KAAK,EAAE,kHAAkH;QACzH,SAAS,EAAE,0DAA0D;YACjE,kEAAkE;KACzE,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;IACxB,GAAG,CAAC,MAAM,GAAG,GAAS,EAAE;QACpB,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,GAAG,CAAC,OAAO,GAAG,GAAS,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC;IACF,GAAG,CAAC,GAAG,GAAG,0BAA0B,WAAW,CAAC,QAAQ,EAAE,CAAC;AAC/D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,oBAAoB,CAAC;AAEnC,UAAU;AACV,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mts-pjsc/image-optimize",
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"eslint": "eslint --fix -c .eslintrc.js --ext .tsx,.ts,.jsx,.js ./src/",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"build:esnext": "tsc --project tsconfig.json",
|
|
12
|
+
"build:commonjs": "tsc --project tsconfig.es5.json",
|
|
13
|
+
"build": "rm -rf dist/ && npm run build:esnext && npm run build:commonjs"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/MobileTeleSystems/image-optimize-react.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"image",
|
|
21
|
+
"optimization"
|
|
22
|
+
],
|
|
23
|
+
"lint-staged": {
|
|
24
|
+
"./src/**/*.(ts|tsx|js|jsx)": [
|
|
25
|
+
"eslint --fix -c .eslintrc.js --ext .tsx,.ts,.jsx,.js"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"author": "MobileTeleSystems",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/MobileTeleSystems/image-optimize-react/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/MobileTeleSystems/image-optimize-react#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"react": "^17.0.2",
|
|
36
|
+
"renamer": "^4.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@labeg/code-style": "^2.0.27",
|
|
40
|
+
"@types/node": "^16.11.12",
|
|
41
|
+
"@types/react": "^17.0.37",
|
|
42
|
+
"husky": "^7.0.4",
|
|
43
|
+
"lint-staged": "^12.1.2",
|
|
44
|
+
"typescript": "^4.5.4"
|
|
45
|
+
}
|
|
46
|
+
}
|