@mts-pjsc/image-optimize 1.1.5 → 1.2.1
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.
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
export interface IImageOptions {
|
|
1
|
+
import { Component } from "react";
|
|
2
|
+
export interface IImageOptions extends React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement> {
|
|
3
3
|
src: string;
|
|
4
4
|
alt: string;
|
|
5
5
|
offset?: number;
|
|
6
6
|
quality?: number;
|
|
7
|
-
className?: string;
|
|
8
7
|
setRef?: (elem: HTMLImageElement | null) => void;
|
|
9
8
|
}
|
|
10
|
-
export declare class Image<P extends IImageOptions> extends
|
|
9
|
+
export declare class Image<P extends IImageOptions> extends Component<P> {
|
|
11
10
|
static isShowDiagnostic: boolean;
|
|
12
11
|
static controlPoints: number[];
|
|
13
12
|
/**
|
package/dist/components/Image.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
// For Next.js 13 and react 18. Switch component for support server components later.
|
|
2
|
+
"use client";
|
|
3
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
8
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
9
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
10
|
+
t[p[i]] = s[p[i]];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
1
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
15
|
+
import { Component } from "react";
|
|
3
16
|
import { getFormatFeatures } from "../helpers/get-format-features.js";
|
|
4
|
-
export class Image extends
|
|
17
|
+
export class Image extends Component {
|
|
5
18
|
constructor(props) {
|
|
6
19
|
super(props);
|
|
7
20
|
this.resultUrl = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
@@ -27,19 +40,20 @@ export class Image extends React.Component {
|
|
|
27
40
|
this.checks = 0;
|
|
28
41
|
// Raf for correct image position after redraw outer components
|
|
29
42
|
requestAnimationFrame(() => this.checkImage());
|
|
30
|
-
return true;
|
|
31
43
|
}
|
|
32
|
-
return
|
|
44
|
+
return true;
|
|
33
45
|
}
|
|
34
46
|
componentWillUnmount() {
|
|
35
47
|
window.removeEventListener("resize", this.windowResizeHandler);
|
|
36
48
|
}
|
|
37
49
|
render() {
|
|
38
|
-
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
const _a = this.props, { offset, quality, setRef, src, alt } = _a, props = __rest(_a, ["offset", "quality", "setRef", "src", "alt"]);
|
|
52
|
+
return (_jsx("img", Object.assign({}, props, { alt: alt, onLoad: () => requestAnimationFrame(() => this.checkImage()), ref: (elem) => {
|
|
39
53
|
var _a, _b;
|
|
40
54
|
this.thisComponent = elem;
|
|
41
55
|
(_b = (_a = this.props).setRef) === null || _b === void 0 ? void 0 : _b.call(_a, elem);
|
|
42
|
-
}, src: this.resultUrl }));
|
|
56
|
+
}, src: this.resultUrl })));
|
|
43
57
|
}
|
|
44
58
|
async checkImage(isResize = false) {
|
|
45
59
|
if (this.checks > 1) {
|