dn-react-router-toolkit 0.1.8 → 0.1.10
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/client_env.d.mts +7 -0
- package/dist/components/client_env.d.ts +7 -0
- package/dist/components/client_env.js +50 -0
- package/dist/components/client_env.mjs +19 -0
- package/dist/file-kit/client/drop_file_input.d.mts +9 -9
- package/dist/file-kit/client/drop_file_input.d.ts +9 -9
- package/dist/file-kit/client/file_upload_button.d.mts +10 -0
- package/dist/file-kit/client/file_upload_button.d.ts +10 -0
- package/dist/file-kit/client/file_upload_button.js +89 -0
- package/dist/file-kit/client/file_upload_button.mjs +58 -0
- package/dist/file-kit/client/file_uploader.d.mts +3 -4
- package/dist/file-kit/client/file_uploader.d.ts +3 -4
- package/dist/file-kit/client/file_uploader.js +20 -9
- package/dist/file-kit/client/file_uploader.mjs +20 -9
- package/dist/file-kit/client/format_size.d.mts +3 -0
- package/dist/file-kit/client/format_size.d.ts +3 -0
- package/dist/file-kit/client/format_size.js +38 -0
- package/dist/file-kit/client/format_size.mjs +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/components/client_env.tsx
|
|
31
|
+
var client_env_exports = {};
|
|
32
|
+
__export(client_env_exports, {
|
|
33
|
+
default: () => ClientEnv
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(client_env_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_react_router = require("react-router");
|
|
38
|
+
function ClientEnv({ dataKey = "ENV" }) {
|
|
39
|
+
const data = (0, import_react_router.useRouteLoaderData)("root");
|
|
40
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, data && /* @__PURE__ */ import_react.default.createElement(
|
|
41
|
+
"script",
|
|
42
|
+
{
|
|
43
|
+
dangerouslySetInnerHTML: {
|
|
44
|
+
__html: `window.process = ${JSON.stringify({
|
|
45
|
+
env: data?.[dataKey]
|
|
46
|
+
})}`
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
));
|
|
50
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/components/client_env.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useRouteLoaderData } from "react-router";
|
|
4
|
+
function ClientEnv({ dataKey = "ENV" }) {
|
|
5
|
+
const data = useRouteLoaderData("root");
|
|
6
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, data && /* @__PURE__ */ React.createElement(
|
|
7
|
+
"script",
|
|
8
|
+
{
|
|
9
|
+
dangerouslySetInnerHTML: {
|
|
10
|
+
__html: `window.process = ${JSON.stringify({
|
|
11
|
+
env: data?.[dataKey]
|
|
12
|
+
})}`
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
));
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
ClientEnv as default
|
|
19
|
+
};
|
|
@@ -15,20 +15,20 @@ type FileItem<T> = {
|
|
|
15
15
|
height?: number;
|
|
16
16
|
item?: T;
|
|
17
17
|
};
|
|
18
|
-
type Props<
|
|
19
|
-
defaultValue?:
|
|
18
|
+
type Props<TFile> = {
|
|
19
|
+
defaultValue?: TFile | TFile[];
|
|
20
20
|
options?: FileUploaderOptions;
|
|
21
21
|
onFileInput?: (files: File[]) => void;
|
|
22
|
-
onFileUploaded?: (file:
|
|
23
|
-
onChange?: (files:
|
|
22
|
+
onFileUploaded?: (file: TFile) => Promise<void>;
|
|
23
|
+
onChange?: (files: TFile[]) => void;
|
|
24
24
|
limit?: number;
|
|
25
25
|
};
|
|
26
|
-
declare function createUseDropFileInput<
|
|
27
|
-
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<
|
|
28
|
-
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<
|
|
26
|
+
declare function createUseDropFileInput<TFile>({ uploadFile, }: {
|
|
27
|
+
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<TFile>;
|
|
28
|
+
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<TFile>) => {
|
|
29
29
|
fileIds: string[];
|
|
30
|
-
files: FileItem<
|
|
31
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem<
|
|
30
|
+
files: FileItem<TFile>[];
|
|
31
|
+
setFiles: React.Dispatch<React.SetStateAction<FileItem<TFile>[]>>;
|
|
32
32
|
Component: ({ className, container, draggingClassName, name, hideMessage, children, ...props }: FileInputProps) => React.JSX.Element;
|
|
33
33
|
};
|
|
34
34
|
declare function DropFileMessageBox(): React.JSX.Element;
|
|
@@ -15,20 +15,20 @@ type FileItem<T> = {
|
|
|
15
15
|
height?: number;
|
|
16
16
|
item?: T;
|
|
17
17
|
};
|
|
18
|
-
type Props<
|
|
19
|
-
defaultValue?:
|
|
18
|
+
type Props<TFile> = {
|
|
19
|
+
defaultValue?: TFile | TFile[];
|
|
20
20
|
options?: FileUploaderOptions;
|
|
21
21
|
onFileInput?: (files: File[]) => void;
|
|
22
|
-
onFileUploaded?: (file:
|
|
23
|
-
onChange?: (files:
|
|
22
|
+
onFileUploaded?: (file: TFile) => Promise<void>;
|
|
23
|
+
onChange?: (files: TFile[]) => void;
|
|
24
24
|
limit?: number;
|
|
25
25
|
};
|
|
26
|
-
declare function createUseDropFileInput<
|
|
27
|
-
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<
|
|
28
|
-
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<
|
|
26
|
+
declare function createUseDropFileInput<TFile>({ uploadFile, }: {
|
|
27
|
+
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<TFile>;
|
|
28
|
+
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<TFile>) => {
|
|
29
29
|
fileIds: string[];
|
|
30
|
-
files: FileItem<
|
|
31
|
-
setFiles: React.Dispatch<React.SetStateAction<FileItem<
|
|
30
|
+
files: FileItem<TFile>[];
|
|
31
|
+
setFiles: React.Dispatch<React.SetStateAction<FileItem<TFile>[]>>;
|
|
32
32
|
Component: ({ className, container, draggingClassName, name, hideMessage, children, ...props }: FileInputProps) => React.JSX.Element;
|
|
33
33
|
};
|
|
34
34
|
declare function DropFileMessageBox(): React.JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type Props<TFile> = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
|
|
4
|
+
onUpload?: (files: TFile[]) => Promise<void> | void;
|
|
5
|
+
};
|
|
6
|
+
declare function createFileUploadButton<TFile>({ uploadFile, }: {
|
|
7
|
+
uploadFile: (file: File) => Promise<TFile>;
|
|
8
|
+
}): ({ onUpload, children, className, style, ...props }: Props<TFile>) => React.JSX.Element;
|
|
9
|
+
|
|
10
|
+
export { createFileUploadButton as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type Props<TFile> = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
|
|
4
|
+
onUpload?: (files: TFile[]) => Promise<void> | void;
|
|
5
|
+
};
|
|
6
|
+
declare function createFileUploadButton<TFile>({ uploadFile, }: {
|
|
7
|
+
uploadFile: (file: File) => Promise<TFile>;
|
|
8
|
+
}): ({ onUpload, children, className, style, ...props }: Props<TFile>) => React.JSX.Element;
|
|
9
|
+
|
|
10
|
+
export { createFileUploadButton as default };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/file-kit/client/file_upload_button.tsx
|
|
31
|
+
var file_upload_button_exports = {};
|
|
32
|
+
__export(file_upload_button_exports, {
|
|
33
|
+
default: () => createFileUploadButton
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(file_upload_button_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_react2 = require("react");
|
|
38
|
+
function createFileUploadButton({
|
|
39
|
+
uploadFile
|
|
40
|
+
}) {
|
|
41
|
+
return function FileUploadButton({
|
|
42
|
+
onUpload,
|
|
43
|
+
children,
|
|
44
|
+
className,
|
|
45
|
+
style,
|
|
46
|
+
...props
|
|
47
|
+
}) {
|
|
48
|
+
const inputRef = (0, import_react2.useRef)(null);
|
|
49
|
+
const onClick = () => {
|
|
50
|
+
inputRef.current?.click();
|
|
51
|
+
};
|
|
52
|
+
const onChange = async (e) => {
|
|
53
|
+
const files = e.target.files;
|
|
54
|
+
if (files && files.length > 0) {
|
|
55
|
+
if (onUpload) {
|
|
56
|
+
try {
|
|
57
|
+
const entities = await Promise.all(
|
|
58
|
+
Array.from(files).map((file) => uploadFile(file))
|
|
59
|
+
);
|
|
60
|
+
await onUpload(entities);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error(err);
|
|
63
|
+
alert("\uD30C\uC77C \uC5C5\uB85C\uB4DC \uC911 \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
e.target.value = "";
|
|
68
|
+
};
|
|
69
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
|
70
|
+
"input",
|
|
71
|
+
{
|
|
72
|
+
...props,
|
|
73
|
+
type: "file",
|
|
74
|
+
ref: inputRef,
|
|
75
|
+
className: "hidden",
|
|
76
|
+
onChange
|
|
77
|
+
}
|
|
78
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
79
|
+
"button",
|
|
80
|
+
{
|
|
81
|
+
className,
|
|
82
|
+
style,
|
|
83
|
+
type: "button",
|
|
84
|
+
onClick
|
|
85
|
+
},
|
|
86
|
+
children
|
|
87
|
+
));
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/file-kit/client/file_upload_button.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
function createFileUploadButton({
|
|
5
|
+
uploadFile
|
|
6
|
+
}) {
|
|
7
|
+
return function FileUploadButton({
|
|
8
|
+
onUpload,
|
|
9
|
+
children,
|
|
10
|
+
className,
|
|
11
|
+
style,
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
const inputRef = useRef(null);
|
|
15
|
+
const onClick = () => {
|
|
16
|
+
inputRef.current?.click();
|
|
17
|
+
};
|
|
18
|
+
const onChange = async (e) => {
|
|
19
|
+
const files = e.target.files;
|
|
20
|
+
if (files && files.length > 0) {
|
|
21
|
+
if (onUpload) {
|
|
22
|
+
try {
|
|
23
|
+
const entities = await Promise.all(
|
|
24
|
+
Array.from(files).map((file) => uploadFile(file))
|
|
25
|
+
);
|
|
26
|
+
await onUpload(entities);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(err);
|
|
29
|
+
alert("\uD30C\uC77C \uC5C5\uB85C\uB4DC \uC911 \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
e.target.value = "";
|
|
34
|
+
};
|
|
35
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
36
|
+
"input",
|
|
37
|
+
{
|
|
38
|
+
...props,
|
|
39
|
+
type: "file",
|
|
40
|
+
ref: inputRef,
|
|
41
|
+
className: "hidden",
|
|
42
|
+
onChange
|
|
43
|
+
}
|
|
44
|
+
), /* @__PURE__ */ React.createElement(
|
|
45
|
+
"button",
|
|
46
|
+
{
|
|
47
|
+
className,
|
|
48
|
+
style,
|
|
49
|
+
type: "button",
|
|
50
|
+
onClick
|
|
51
|
+
},
|
|
52
|
+
children
|
|
53
|
+
));
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
createFileUploadButton as default
|
|
58
|
+
};
|
|
@@ -2,12 +2,11 @@ type FileUploaderOptions = {
|
|
|
2
2
|
metadata?: Record<string, unknown>;
|
|
3
3
|
convertToWebp?: boolean;
|
|
4
4
|
};
|
|
5
|
-
declare class FileUploader {
|
|
5
|
+
declare class FileUploader<TFile> {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
constructor(endpoint?: string);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<any>;
|
|
8
|
+
uploadFile(file: File, options?: FileUploaderOptions): Promise<TFile>;
|
|
9
|
+
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<TFile>;
|
|
11
10
|
deleteFile(fileId: string): Promise<boolean>;
|
|
12
11
|
}
|
|
13
12
|
|
|
@@ -2,12 +2,11 @@ type FileUploaderOptions = {
|
|
|
2
2
|
metadata?: Record<string, unknown>;
|
|
3
3
|
convertToWebp?: boolean;
|
|
4
4
|
};
|
|
5
|
-
declare class FileUploader {
|
|
5
|
+
declare class FileUploader<TFile> {
|
|
6
6
|
endpoint: string;
|
|
7
7
|
constructor(endpoint?: string);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<any>;
|
|
8
|
+
uploadFile(file: File, options?: FileUploaderOptions): Promise<TFile>;
|
|
9
|
+
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<TFile>;
|
|
11
10
|
deleteFile(fileId: string): Promise<boolean>;
|
|
12
11
|
}
|
|
13
12
|
|
|
@@ -62,19 +62,30 @@ var FileUploader = class {
|
|
|
62
62
|
constructor(endpoint = "/api/files") {
|
|
63
63
|
this.endpoint = endpoint;
|
|
64
64
|
}
|
|
65
|
-
formatSize = (size) => {
|
|
66
|
-
if (size < 1024) {
|
|
67
|
-
return `${size} B`;
|
|
68
|
-
}
|
|
69
|
-
if (size < 1024 * 1024) {
|
|
70
|
-
return `${(size / 1024).toFixed(2)} KB`;
|
|
71
|
-
}
|
|
72
|
-
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
73
|
-
};
|
|
74
65
|
uploadFile(file, options = {}) {
|
|
75
66
|
return this.uploadBlob(file, file.name, options);
|
|
76
67
|
}
|
|
77
68
|
async uploadBlob(blob, name = "blob", options = {}) {
|
|
69
|
+
if (options.convertToWebp && blob.type.startsWith("image/") && blob.type !== "image/webp") {
|
|
70
|
+
const img = document.createElement("img");
|
|
71
|
+
img.src = URL.createObjectURL(blob);
|
|
72
|
+
await img.decode();
|
|
73
|
+
const canvas = document.createElement("canvas");
|
|
74
|
+
canvas.width = img.width;
|
|
75
|
+
canvas.height = img.height;
|
|
76
|
+
const ctx = canvas.getContext("2d");
|
|
77
|
+
if (ctx) {
|
|
78
|
+
ctx.drawImage(img, 0, 0);
|
|
79
|
+
}
|
|
80
|
+
const webpBlob = await new Promise((resolve) => {
|
|
81
|
+
canvas.toBlob((b) => {
|
|
82
|
+
resolve(b);
|
|
83
|
+
}, "image/webp");
|
|
84
|
+
});
|
|
85
|
+
if (webpBlob) {
|
|
86
|
+
blob = webpBlob;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
78
89
|
const { type, size } = blob;
|
|
79
90
|
const metadataForMedia = await generateMetadata(blob);
|
|
80
91
|
const metadata = {
|
|
@@ -36,19 +36,30 @@ var FileUploader = class {
|
|
|
36
36
|
constructor(endpoint = "/api/files") {
|
|
37
37
|
this.endpoint = endpoint;
|
|
38
38
|
}
|
|
39
|
-
formatSize = (size) => {
|
|
40
|
-
if (size < 1024) {
|
|
41
|
-
return `${size} B`;
|
|
42
|
-
}
|
|
43
|
-
if (size < 1024 * 1024) {
|
|
44
|
-
return `${(size / 1024).toFixed(2)} KB`;
|
|
45
|
-
}
|
|
46
|
-
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
47
|
-
};
|
|
48
39
|
uploadFile(file, options = {}) {
|
|
49
40
|
return this.uploadBlob(file, file.name, options);
|
|
50
41
|
}
|
|
51
42
|
async uploadBlob(blob, name = "blob", options = {}) {
|
|
43
|
+
if (options.convertToWebp && blob.type.startsWith("image/") && blob.type !== "image/webp") {
|
|
44
|
+
const img = document.createElement("img");
|
|
45
|
+
img.src = URL.createObjectURL(blob);
|
|
46
|
+
await img.decode();
|
|
47
|
+
const canvas = document.createElement("canvas");
|
|
48
|
+
canvas.width = img.width;
|
|
49
|
+
canvas.height = img.height;
|
|
50
|
+
const ctx = canvas.getContext("2d");
|
|
51
|
+
if (ctx) {
|
|
52
|
+
ctx.drawImage(img, 0, 0);
|
|
53
|
+
}
|
|
54
|
+
const webpBlob = await new Promise((resolve) => {
|
|
55
|
+
canvas.toBlob((b) => {
|
|
56
|
+
resolve(b);
|
|
57
|
+
}, "image/webp");
|
|
58
|
+
});
|
|
59
|
+
if (webpBlob) {
|
|
60
|
+
blob = webpBlob;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
const { type, size } = blob;
|
|
53
64
|
const metadataForMedia = await generateMetadata(blob);
|
|
54
65
|
const metadata = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/file-kit/client/format_size.ts
|
|
21
|
+
var format_size_exports = {};
|
|
22
|
+
__export(format_size_exports, {
|
|
23
|
+
formatSize: () => formatSize
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(format_size_exports);
|
|
26
|
+
function formatSize(size) {
|
|
27
|
+
if (size < 1024) {
|
|
28
|
+
return `${size} B`;
|
|
29
|
+
}
|
|
30
|
+
if (size < 1024 * 1024) {
|
|
31
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
32
|
+
}
|
|
33
|
+
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
formatSize
|
|
38
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/file-kit/client/format_size.ts
|
|
2
|
+
function formatSize(size) {
|
|
3
|
+
if (size < 1024) {
|
|
4
|
+
return `${size} B`;
|
|
5
|
+
}
|
|
6
|
+
if (size < 1024 * 1024) {
|
|
7
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
8
|
+
}
|
|
9
|
+
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
formatSize
|
|
13
|
+
};
|