szld-libs 0.2.25 → 0.2.26
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/szld-components.es.js +16320 -13638
- package/dist/szld-components.umd.js +55 -55
- package/es/components/Upload/index.js +5 -6
- package/es/index.js +6 -3
- package/es/main.d.ts +2 -1
- package/es/main.js +16 -14
- package/es/utils/image-compression/UPNG.d.ts +142 -0
- package/es/utils/image-compression/UPNG.js +1665 -0
- package/es/utils/image-compression/image.d.ts +8 -0
- package/es/utils/{compression-file.js → image-compression/image.js} +17 -24
- package/es/utils/image-compression/index.d.ts +9 -0
- package/es/utils/image-compression/index.js +39 -0
- package/es/utils/image-compression/vite.svg +1 -0
- package/lib/components/Upload/index.js +5 -6
- package/lib/index.js +4 -1
- package/lib/main.d.ts +2 -1
- package/lib/main.js +2 -0
- package/lib/utils/image-compression/UPNG.d.ts +142 -0
- package/lib/utils/image-compression/UPNG.js +1664 -0
- package/lib/utils/image-compression/image.d.ts +8 -0
- package/lib/utils/{compression-file.js → image-compression/image.js} +16 -23
- package/lib/utils/image-compression/index.d.ts +9 -0
- package/lib/utils/image-compression/index.js +38 -0
- package/lib/utils/image-compression/vite.svg +1 -0
- package/package.json +2 -1
- package/es/utils/compression-file.d.ts +0 -11
- package/lib/utils/compression-file.d.ts +0 -11
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const fileToDataURL: (file: Blob | File) => Promise<any>;
|
|
2
|
+
export declare const dataURLToImage: (dataURL: string) => Promise<HTMLImageElement>;
|
|
3
|
+
export declare const canvastoFile: (canvas: HTMLCanvasElement, type: string, quality: number) => Promise<Blob | null>;
|
|
4
|
+
export declare const scaleWidthHeight: (img: HTMLImageElement) => {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const convertQualityToBit: (quality: number) => number;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const fileToDataURL = (file) => {
|
|
2
|
-
return new Promise((resolve) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
3
|
const reader = new FileReader();
|
|
4
4
|
reader.onloadend = (e) => resolve(e.target.result);
|
|
5
|
+
reader.onerror = (e) => reject(e);
|
|
5
6
|
reader.readAsDataURL(file);
|
|
6
7
|
});
|
|
7
8
|
};
|
|
8
9
|
const dataURLToImage = (dataURL) => {
|
|
9
|
-
return new Promise((resolve) => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
10
11
|
const img = new Image();
|
|
11
12
|
img.onload = () => resolve(img);
|
|
13
|
+
img.onerror = (e) => reject(e);
|
|
12
14
|
img.src = dataURL;
|
|
13
15
|
});
|
|
14
16
|
};
|
|
@@ -18,8 +20,8 @@ const canvastoFile = (canvas, type, quality) => {
|
|
|
18
20
|
);
|
|
19
21
|
};
|
|
20
22
|
const scaleWidthHeight = (img) => {
|
|
21
|
-
const maxWidth =
|
|
22
|
-
const maxHeight =
|
|
23
|
+
const maxWidth = 2e3;
|
|
24
|
+
const maxHeight = 2e3;
|
|
23
25
|
const originWidth = img.width;
|
|
24
26
|
const originHeight = img.height;
|
|
25
27
|
let targetWidth = img.width;
|
|
@@ -38,28 +40,19 @@ const scaleWidthHeight = (img) => {
|
|
|
38
40
|
height: targetHeight
|
|
39
41
|
};
|
|
40
42
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
43
|
+
const convertQualityToBit = (quality) => {
|
|
44
|
+
let bit = 0;
|
|
45
|
+
if (quality > 1 || quality < 0) {
|
|
46
|
+
bit = 0;
|
|
47
|
+
} else {
|
|
48
|
+
bit = !quality ? 0 : quality * 256;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
const context = canvas.getContext("2d");
|
|
48
|
-
const base64 = await fileToDataURL(file);
|
|
49
|
-
const img = await dataURLToImage(base64);
|
|
50
|
-
const target = scaleWidthHeight(img);
|
|
51
|
-
canvas.width = target.width;
|
|
52
|
-
canvas.height = target.height;
|
|
53
|
-
context.clearRect(0, 0, target.width, target.height);
|
|
54
|
-
context.drawImage(img, 0, 0, target.width, target.height);
|
|
55
|
-
const blob = await canvastoFile(canvas, type, quality);
|
|
56
|
-
const newFile = new File([blob], fileName, {
|
|
57
|
-
type
|
|
58
|
-
});
|
|
59
|
-
return newFile;
|
|
50
|
+
return bit;
|
|
60
51
|
};
|
|
61
52
|
export {
|
|
62
|
-
|
|
53
|
+
canvastoFile,
|
|
54
|
+
convertQualityToBit,
|
|
63
55
|
dataURLToImage,
|
|
64
|
-
fileToDataURL
|
|
56
|
+
fileToDataURL,
|
|
57
|
+
scaleWidthHeight
|
|
65
58
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片压缩方法
|
|
3
|
+
* @param {Object} file 图片文件
|
|
4
|
+
* @param {Nubmber} quality 压缩质量参数 0-1
|
|
5
|
+
* @param {limit} limit 最小限制大小,小于该值时不进行压缩
|
|
6
|
+
* @returns 压缩后的新图片
|
|
7
|
+
*/
|
|
8
|
+
declare const compressionImage: (file: File, quality?: number, limit?: number) => Promise<File>;
|
|
9
|
+
export default compressionImage;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import UPNG from "./UPNG";
|
|
2
|
+
import { fileToDataURL, dataURLToImage, scaleWidthHeight, canvastoFile, convertQualityToBit } from "./image";
|
|
3
|
+
const compressionImage = async (file, quality = 0.5, limit = 300) => {
|
|
4
|
+
const fileName = file.name;
|
|
5
|
+
if (file.size / 1024 < limit) {
|
|
6
|
+
return file;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const canvas = document.createElement("canvas");
|
|
10
|
+
const context = canvas.getContext("2d");
|
|
11
|
+
const base64 = await fileToDataURL(file);
|
|
12
|
+
const img = await dataURLToImage(base64);
|
|
13
|
+
const target = scaleWidthHeight(img);
|
|
14
|
+
canvas.width = target.width;
|
|
15
|
+
canvas.height = target.height;
|
|
16
|
+
context.clearRect(0, 0, target.width, target.height);
|
|
17
|
+
context.drawImage(img, 0, 0, target.width, target.height);
|
|
18
|
+
if (["image/jpeg", "image/jpg"].includes(file.type)) {
|
|
19
|
+
const blob = await canvastoFile(canvas, file.type, quality);
|
|
20
|
+
const newFile = new File([blob], fileName, {
|
|
21
|
+
type: file.type
|
|
22
|
+
});
|
|
23
|
+
return newFile;
|
|
24
|
+
} else {
|
|
25
|
+
const imageData = context.getImageData(0, 0, target.width, target.height).data;
|
|
26
|
+
const bit = convertQualityToBit(quality);
|
|
27
|
+
const png = UPNG.encode([imageData.buffer], target.width, target.height, bit);
|
|
28
|
+
const newFile = new File([png], file.name, {
|
|
29
|
+
type: file.type
|
|
30
|
+
});
|
|
31
|
+
return newFile;
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return file;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
compressionImage as default
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const antd = require("antd");
|
|
4
3
|
const icons = require("@ant-design/icons");
|
|
5
|
-
const
|
|
4
|
+
const antd = require("antd");
|
|
6
5
|
const react = require("react");
|
|
7
|
-
const utils = require("../../utils");
|
|
8
6
|
require("react-dom");
|
|
9
|
-
const
|
|
7
|
+
const utils = require("../../utils");
|
|
8
|
+
const filetype = require("../../utils/filetype");
|
|
9
|
+
const compressionImage = require("../../utils/image-compression");
|
|
10
10
|
const defaultFileType = [filetype.FileSuffix.jpeg, filetype.FileSuffix.jpg, filetype.FileSuffix.png];
|
|
11
11
|
const UploadFile = (props) => {
|
|
12
12
|
const {
|
|
@@ -51,9 +51,8 @@ const UploadFile = (props) => {
|
|
|
51
51
|
}
|
|
52
52
|
if (compression) {
|
|
53
53
|
resolve(
|
|
54
|
-
|
|
54
|
+
compressionImage(
|
|
55
55
|
file,
|
|
56
|
-
compression.type,
|
|
57
56
|
compression.quality,
|
|
58
57
|
compression.limit
|
|
59
58
|
)
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,10 @@ const Demo = () => {
|
|
|
22
22
|
Salt: "HnSzldjt#2557013#"
|
|
23
23
|
}));
|
|
24
24
|
};
|
|
25
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
25
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh" }, children: [
|
|
26
|
+
"测试页面",
|
|
27
|
+
/* @__PURE__ */ jsxRuntime.jsx(main.UploadFile, { compression: { quality: 0.8, limit: 5 * 1024 }, accept: ".heic,.jpg,.png,.jpeg", maxSize: 100 })
|
|
28
|
+
] });
|
|
26
29
|
};
|
|
27
30
|
ReactDOM.createRoot(document.getElementById("root")).render(
|
|
28
31
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.BrowserRouter, { children: /* @__PURE__ */ jsxRuntime.jsx(Demo, {}) })
|
package/lib/main.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import showWorkFlow, { WorkFlowNode } from "./components/WorkFlowNode";
|
|
|
9
9
|
import * as download from "./utils/download";
|
|
10
10
|
import * as fileType from "./utils/filetype";
|
|
11
11
|
import * as FormRules from './utils/formRules';
|
|
12
|
+
import compressionImage from './utils/image-compression';
|
|
12
13
|
import * as utils from "./utils/index";
|
|
13
14
|
import * as verfyCode from "./utils/verify-code";
|
|
14
15
|
import useCaptcha from "./hooks/useCaptcha";
|
|
@@ -18,4 +19,4 @@ import useRemember from "./hooks/useRemember";
|
|
|
18
19
|
import useRowSelection from "./hooks/useRowSelection";
|
|
19
20
|
import AES from "./utils/aes";
|
|
20
21
|
import HmacSHA512 from './utils/hmacSHA512';
|
|
21
|
-
export { AES, AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, WorkFlowNode, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode };
|
|
22
|
+
export { AES, AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, WorkFlowNode, compressionImage, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode };
|
package/lib/main.js
CHANGED
|
@@ -11,6 +11,7 @@ const WorkFlowNode = require("./components/WorkFlowNode");
|
|
|
11
11
|
const download = require("./utils/download");
|
|
12
12
|
const filetype = require("./utils/filetype");
|
|
13
13
|
const formRules = require("./utils/formRules");
|
|
14
|
+
const imageCompression = require("./utils/image-compression");
|
|
14
15
|
const index = require("./utils/index");
|
|
15
16
|
const verifyCode = require("./utils/verify-code");
|
|
16
17
|
const useCaptcha = require("./hooks/useCaptcha");
|
|
@@ -56,6 +57,7 @@ exports.showWorkFlow = WorkFlowNode;
|
|
|
56
57
|
exports.download = download__namespace;
|
|
57
58
|
exports.fileType = filetype__namespace;
|
|
58
59
|
exports.FormRules = formRules__namespace;
|
|
60
|
+
exports.compressionImage = imageCompression;
|
|
59
61
|
exports.utils = index__namespace;
|
|
60
62
|
exports.verfyCode = verifyCode__namespace;
|
|
61
63
|
exports.useCaptcha = useCaptcha;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export default UPNG;
|
|
2
|
+
declare namespace UPNG {
|
|
3
|
+
function toRGBA8(out: any): ArrayBufferLike[];
|
|
4
|
+
namespace toRGBA8 {
|
|
5
|
+
function decodeImage(data: any, w: any, h: any, out: any): Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
function decode(buff: any): {
|
|
8
|
+
tabs: {};
|
|
9
|
+
frames: never[];
|
|
10
|
+
};
|
|
11
|
+
namespace decode {
|
|
12
|
+
function _decompress(out: any, dd: any, w: any, h: any): any;
|
|
13
|
+
function _inflate(data: any, buff: any): any;
|
|
14
|
+
function _readInterlace(data: any, out: any): Uint8Array;
|
|
15
|
+
function _getBPP(out: any): number;
|
|
16
|
+
function _filterZero(data: any, out: any, off: any, w: any, h: any): any;
|
|
17
|
+
function _paeth(a: any, b: any, c: any): any;
|
|
18
|
+
function _IHDR(data: any, offset: any, out: any): void;
|
|
19
|
+
}
|
|
20
|
+
function inflateRaw(N: any, W: any): any;
|
|
21
|
+
namespace _bin {
|
|
22
|
+
function nextZero(data: any, p: any): any;
|
|
23
|
+
function readUshort(buff: any, p: any): number;
|
|
24
|
+
function writeUshort(buff: any, p: any, n: any): void;
|
|
25
|
+
function readUint(buff: any, p: any): number;
|
|
26
|
+
function writeUint(buff: any, p: any, n: any): void;
|
|
27
|
+
function readASCII(buff: any, p: any, l: any): string;
|
|
28
|
+
function writeASCII(data: any, p: any, s: any): void;
|
|
29
|
+
function readBytes(buff: any, p: any, l: any): any[];
|
|
30
|
+
function pad(n: any): any;
|
|
31
|
+
function readUTF8(buff: any, p: any, l: any): string;
|
|
32
|
+
}
|
|
33
|
+
function _copyTile(sb: any, sw: any, sh: any, tb: any, tw: any, th: any, xoff: any, yoff: any, mode: any): boolean;
|
|
34
|
+
function encode(bufs: any, w: any, h: any, ps: any, dels: any, tabs: any, forbidPlte: any): ArrayBufferLike;
|
|
35
|
+
namespace encode {
|
|
36
|
+
function _main(nimg: any, w: any, h: any, dels: any, tabs: any): ArrayBufferLike;
|
|
37
|
+
function compressPNG(out: any, filter: any, levelZero: any): void;
|
|
38
|
+
function compress(bufs: any, w: any, h: any, ps: any, prms: any): {
|
|
39
|
+
ctype: number;
|
|
40
|
+
depth: number;
|
|
41
|
+
plte: any[];
|
|
42
|
+
frames: {
|
|
43
|
+
rect: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
width: any;
|
|
47
|
+
height: any;
|
|
48
|
+
};
|
|
49
|
+
img: Uint8Array;
|
|
50
|
+
blend: number;
|
|
51
|
+
dispose: number;
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
54
|
+
function framize(bufs: any, w: any, h: any, alwaysBlend: any, evenCrd: any, forbidPrev: any): {
|
|
55
|
+
rect: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
width: any;
|
|
59
|
+
height: any;
|
|
60
|
+
};
|
|
61
|
+
img: Uint8Array;
|
|
62
|
+
blend: number;
|
|
63
|
+
dispose: number;
|
|
64
|
+
}[];
|
|
65
|
+
function _updateFrame(bufs: any, w: any, h: any, frms: any, i: any, r: any, evenCrd: any): void;
|
|
66
|
+
function _prepareDiff(cimg: any, w: any, h: any, nimg: any, rec: any): void;
|
|
67
|
+
function _filterZero(img: any, h: any, bpp: any, bpl: any, data: any, filter: any, levelZero: any): any;
|
|
68
|
+
function _filterLine(data: any, img: any, y: any, bpl: any, bpp: any, type: any): void;
|
|
69
|
+
function concatRGBA(bufs: any): ArrayBufferLike;
|
|
70
|
+
}
|
|
71
|
+
function encodeLL(bufs: any, w: any, h: any, cc: any, ac: any, depth: any, dels: any, tabs: any): ArrayBufferLike;
|
|
72
|
+
namespace crc {
|
|
73
|
+
export const table: Uint32Array;
|
|
74
|
+
export function update(c: any, buf: any, off: any, len: any): any;
|
|
75
|
+
export function crc_1(b: any, o: any, l: any): number;
|
|
76
|
+
export { crc_1 as crc };
|
|
77
|
+
}
|
|
78
|
+
function quantize(abuf: any, ps: any): {
|
|
79
|
+
abuf: ArrayBufferLike;
|
|
80
|
+
inds: Uint8Array;
|
|
81
|
+
plte: {
|
|
82
|
+
i0: number;
|
|
83
|
+
i1: any;
|
|
84
|
+
bst: null;
|
|
85
|
+
est: null;
|
|
86
|
+
tdst: number;
|
|
87
|
+
left: null;
|
|
88
|
+
right: null;
|
|
89
|
+
} | {
|
|
90
|
+
i0: number;
|
|
91
|
+
i1: any;
|
|
92
|
+
bst: null;
|
|
93
|
+
est: null;
|
|
94
|
+
tdst: number;
|
|
95
|
+
left: null;
|
|
96
|
+
right: null;
|
|
97
|
+
}[];
|
|
98
|
+
};
|
|
99
|
+
namespace quantize {
|
|
100
|
+
function getKDtree(nimg: any, ps: any, err: any): ({
|
|
101
|
+
i0: number;
|
|
102
|
+
i1: any;
|
|
103
|
+
bst: null;
|
|
104
|
+
est: null;
|
|
105
|
+
tdst: number;
|
|
106
|
+
left: null;
|
|
107
|
+
right: null;
|
|
108
|
+
} | {
|
|
109
|
+
i0: number;
|
|
110
|
+
i1: any;
|
|
111
|
+
bst: null;
|
|
112
|
+
est: null;
|
|
113
|
+
tdst: number;
|
|
114
|
+
left: null;
|
|
115
|
+
right: null;
|
|
116
|
+
}[])[];
|
|
117
|
+
function getNearest(nd: any, r: any, g: any, b: any, a: any): any;
|
|
118
|
+
function planeDst(est: any, r: any, g: any, b: any, a: any): number;
|
|
119
|
+
function dist(q: any, r: any, g: any, b: any, a: any): number;
|
|
120
|
+
function splitPixels(nimg: any, nimg32: any, i0: any, i1: any, e: any, eMq: any): any;
|
|
121
|
+
function vecDot(nimg: any, i: any, e: any): number;
|
|
122
|
+
function stats(nimg: any, i0: any, i1: any): {
|
|
123
|
+
R: number[];
|
|
124
|
+
m: number[];
|
|
125
|
+
N: number;
|
|
126
|
+
};
|
|
127
|
+
function estats(stats: any): {
|
|
128
|
+
Cov: number[];
|
|
129
|
+
q: number[];
|
|
130
|
+
e: number[];
|
|
131
|
+
L: number;
|
|
132
|
+
eMq255: number;
|
|
133
|
+
eMq: number;
|
|
134
|
+
rgba: number;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
namespace M4 {
|
|
138
|
+
function multVec(m: any, v: any): number[];
|
|
139
|
+
function dot(x: any, y: any): number;
|
|
140
|
+
function sml(a: any, y: any): number[];
|
|
141
|
+
}
|
|
142
|
+
}
|