@zyzgroup/core-web 0.0.1 → 0.0.3

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,25 +1,156 @@
1
- class BaseError extends Error {
2
- constructor(message, options) {
3
- super(message, options);
4
- this.name = this.constructor.name;
1
+ class a extends Error {
2
+ cause;
3
+ constructor(n, t) {
4
+ super(n, t), this.name = this.constructor.name;
5
5
  }
6
6
  }
7
- class EnvironmentError extends BaseError {
7
+ class l extends a {
8
8
  constructor() {
9
9
  super("This is not a browser environment");
10
10
  }
11
11
  }
12
- class FileSelectCancelError extends BaseError {
12
+ class c extends a {
13
13
  constructor() {
14
14
  super("Cancel select");
15
15
  }
16
16
  }
17
- class IllegalFileError extends BaseError {
18
- constructor(accepts) {
19
- super(`Please select files in ${accepts} format`);
20
- this.accepts = accepts;
17
+ class d extends a {
18
+ accepts;
19
+ constructor(n) {
20
+ super(`Please select files in ${n} format`), this.accepts = n;
21
21
  }
22
22
  }
23
-
24
- export { BaseError, EnvironmentError, FileSelectCancelError, IllegalFileError };
23
+ function f(e, n) {
24
+ e.addEventListener(
25
+ "change",
26
+ function() {
27
+ n(e.files);
28
+ },
29
+ !1
30
+ );
31
+ }
32
+ function g(e, n) {
33
+ e.addEventListener(
34
+ "dragover",
35
+ function(t) {
36
+ t.stopPropagation(), t.preventDefault(), t.dataTransfer && (t.dataTransfer.dropEffect = "copy");
37
+ },
38
+ !1
39
+ ), e.addEventListener(
40
+ "drop",
41
+ function(t) {
42
+ t.stopPropagation(), t.preventDefault(), t.dataTransfer && n(t.dataTransfer.files);
43
+ },
44
+ !1
45
+ );
46
+ }
47
+ const h = (e = ["*"], n) => {
48
+ if (!globalThis.document || !(globalThis.document instanceof Document))
49
+ throw new l();
50
+ const t = globalThis.document.createElement("input");
51
+ return t.setAttribute("type", "file"), t.setAttribute("visibility", "hidden"), Array.isArray(e) && e.length > 0 && t.setAttribute("accept", e.join(",")), n && t.setAttribute("multiple", "true"), t.click(), new Promise((r, s) => {
52
+ globalThis.addEventListener(
53
+ "focus",
54
+ () => {
55
+ setTimeout(() => {
56
+ (!t.files || t.files?.length === 0) && s(new c());
57
+ }, 1e3);
58
+ },
59
+ { once: !0 }
60
+ ), t.addEventListener("change", () => {
61
+ if (!t.files || t.files?.length === 0)
62
+ s(new c());
63
+ else {
64
+ const i = Array.from(t.files);
65
+ o(i) && s(new d(e)), r(i);
66
+ }
67
+ });
68
+ });
69
+ function o(r) {
70
+ return !e.includes("*") && r.some((s) => !e.includes(`.${m(s)}`));
71
+ }
72
+ }, v = (e) => {
73
+ const n = new FileReader();
74
+ return new Promise((t, o) => {
75
+ n.addEventListener(
76
+ "progress",
77
+ (r) => {
78
+ const s = "(" + Math.floor(r.total / 1e3) + " KB)", i = Math.floor(r.loaded / r.total * 100) + "%";
79
+ console.log(`Loading size: ${s} progress: ${i}`);
80
+ }
81
+ ), n.addEventListener("load", (r) => {
82
+ t(r.target?.result);
83
+ }), n.addEventListener("error", (r) => {
84
+ o(r);
85
+ }), e(n);
86
+ });
87
+ }, m = (e) => {
88
+ let n;
89
+ return e instanceof File ? n = e.name : n = e, n.match(/\.([0-9a-z]+)(?:[\\?#]|$)/i)[1] ?? "";
90
+ }, w = (e) => /^image\//.test(e.type), b = (e) => /^video\//.test(e.type), x = (e) => /^audio\//.test(e.type), y = (e) => /^application\/(?:vnd\.openxmlformats-officedocument\.wordprocessingml\.document|msword|vnd\.ms-word\.document\.macroenabled\.12|vnd\.openxmlformats-officedocument\.wordprocessingml\.template|vnd\.ms-word\.template\.macroenabled\.12)$/.test(
91
+ e.type
92
+ ), E = (e) => /^application\/(?:vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|vnd\.ms-excel|vnd\.ms-excel\.sheet\.macroenabled\.12|vnd\.openxmlformats-officedocument\.spreadsheetml\.template|vnd\.ms-excel\.template\.macroenabled\.12)$/.test(
93
+ e.type
94
+ ), L = (e) => /^application\/(?:vnd\.ms-powerpoint|vnd\.openxmlformats-officedocument\.presentationml\.presentation|vnd\.ms-powerpoint\.presentation\.macroenabled\.12|vnd\.openxmlformats-officedocument\.presentationml\.template|vnd\.ms-powerpoint\.template\.macroenabled\.12)$/.test(
95
+ e.type
96
+ ), F = (e) => /^application\/json$/.test(e.type), A = (e) => /^(?:application|text)\/(?:xml|xhtml\+xml)$/.test(e.type);
97
+ function D(e) {
98
+ const n = e.slice(0, 4), t = new FileReader();
99
+ let o;
100
+ return new Promise((r, s) => {
101
+ t.onload = function() {
102
+ const i = t.result;
103
+ switch (new DataView(i).getUint32(0, !1)) {
104
+ case 2303741511:
105
+ o = "image/png";
106
+ break;
107
+ case 1195984440:
108
+ o = "image/gif";
109
+ break;
110
+ case 626017350:
111
+ o = "application/pdf";
112
+ break;
113
+ case 1347093252:
114
+ o = "application/zip";
115
+ break;
116
+ }
117
+ return r(o);
118
+ }, t.readAsArrayBuffer(n);
119
+ });
120
+ }
121
+ function T(e) {
122
+ const n = new Blob(["(" + e.toString() + ")()"], {
123
+ type: "application/javascript"
124
+ });
125
+ return URL.createObjectURL(n);
126
+ }
127
+ function $(e, n) {
128
+ if (!e.type.startsWith("image/"))
129
+ return;
130
+ const t = document.createElement("img");
131
+ return t.src = URL.createObjectURL(e), t.width = n?.width ?? 60, t.height = n?.height ?? 60, t.onload = function() {
132
+ }, t;
133
+ }
134
+ export {
135
+ a as BaseError,
136
+ l as EnvironmentError,
137
+ c as FileSelectCancelError,
138
+ d as IllegalFileError,
139
+ $ as file2Image,
140
+ T as fn2ObjectURL,
141
+ m as getFileExtension,
142
+ D as getFileType,
143
+ g as handleDragAndDropFiles,
144
+ f as handleInputFiles,
145
+ x as isAudio,
146
+ E as isExcelDocument,
147
+ w as isImage,
148
+ F as isJsonDocument,
149
+ L as isPowerPointDocument,
150
+ b as isVideo,
151
+ y as isWordDocument,
152
+ A as isXmlDocument,
153
+ v as readeFile,
154
+ h as selectFile
155
+ };
25
156
  //# sourceMappingURL=zyzgroup-core-web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zyzgroup-core-web.js","sources":["../src/error.ts"],"sourcesContent":["export class BaseError extends Error {\n cause?: Error;\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = this.constructor.name;\n }\n}\n\nexport class EnvironmentError extends BaseError {\n constructor() {\n super(\"This is not a browser environment\");\n }\n}\n\nexport class FileSelectCancelError extends BaseError {\n constructor() {\n super(\"Cancel select\");\n }\n}\n\nexport class IllegalFileError extends BaseError {\n accepts: string[];\n\n constructor(accepts: string[]) {\n super(`Please select files in ${accepts} format`);\n this.accepts = accepts;\n }\n}\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB,KAAM,CAAA;AAAA,EAGnC,WAAA,CAAY,SAAiB,OAAwB,EAAA;AACnD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AACtB,IAAK,IAAA,CAAA,IAAA,GAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC/B;AACF,CAAA;AAEO,MAAM,yBAAyB,SAAU,CAAA;AAAA,EAC9C,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,mCAAmC,CAAA,CAAA;AAAA,GAC3C;AACF,CAAA;AAEO,MAAM,8BAA8B,SAAU,CAAA;AAAA,EACnD,WAAc,GAAA;AACZ,IAAA,KAAA,CAAM,eAAe,CAAA,CAAA;AAAA,GACvB;AACF,CAAA;AAEO,MAAM,yBAAyB,SAAU,CAAA;AAAA,EAG9C,YAAY,OAAmB,EAAA;AAC7B,IAAM,KAAA,CAAA,CAAA,uBAAA,EAA0B,OAAO,CAAS,OAAA,CAAA,CAAA,CAAA;AAChD,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AAAA,GACjB;AACF;;;;"}
1
+ {"version":3,"file":"zyzgroup-core-web.js","sources":["../src/error.ts","../src/file.ts"],"sourcesContent":["export class BaseError extends Error {\n cause?: Error;\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = this.constructor.name;\n }\n}\n\nexport class EnvironmentError extends BaseError {\n constructor() {\n super(\"This is not a browser environment\");\n }\n}\n\nexport class FileSelectCancelError extends BaseError {\n constructor() {\n super(\"Cancel select\");\n }\n}\n\nexport class IllegalFileError extends BaseError {\n accepts: string[];\n\n constructor(accepts: string[]) {\n super(`Please select files in ${accepts} format`);\n this.accepts = accepts;\n }\n}\n","import {\n EnvironmentError,\n FileSelectCancelError,\n IllegalFileError\n} from \"./error\";\n\n// <input type=\"file\" id=\"input\">\n// <input type=\"file\" id=\"input\" multiple accept=\"image/*\" style=\"display:none\" name=\"photos[]\">\n// <label for=\"input\">Select some files</label>\n// input css :focus :focus-within\nexport function handleInputFiles(\n el: HTMLInputElement,\n cb: (files: FileList | null) => any\n) {\n el.addEventListener(\n \"change\",\n function () {\n cb(el.files);\n },\n false\n );\n}\n\nexport function handleDragAndDropFiles(\n dropZoneEl: HTMLElement,\n cb: (files: FileList | null) => any\n) {\n // dragover dragenter dragend drop\n dropZoneEl.addEventListener(\n \"dragover\",\n function (e) {\n e.stopPropagation();\n e.preventDefault();\n if (e.dataTransfer) e.dataTransfer.dropEffect = \"copy\";\n },\n false\n );\n dropZoneEl.addEventListener(\n \"drop\",\n function (e) {\n e.stopPropagation();\n e.preventDefault();\n if (e.dataTransfer) cb(e.dataTransfer.files);\n },\n false\n );\n}\n\n/**\n * 选择系统文件\n *\n * @param accepts 可选文件后缀\n * @param multiple 是否多选\n * @returns\n */\nexport const selectFile = (\n accepts: string[] = [\"*\"],\n multiple?: boolean\n): Promise<File[]> => {\n if (!globalThis.document || !(globalThis.document instanceof Document)) {\n throw new EnvironmentError();\n }\n const inputElement = globalThis.document.createElement(\"input\");\n inputElement.setAttribute(\"type\", \"file\");\n inputElement.setAttribute(\"visibility\", \"hidden\");\n if (Array.isArray(accepts) && accepts.length > 0) {\n inputElement.setAttribute(\"accept\", accepts.join(\",\"));\n }\n if (multiple) {\n inputElement.setAttribute(\"multiple\", \"true\");\n }\n inputElement.click();\n\n return new Promise((resolve, reject) => {\n globalThis.addEventListener(\n \"focus\",\n () => {\n setTimeout(() => {\n if (!inputElement.files || inputElement.files?.length === 0) {\n reject(new FileSelectCancelError());\n }\n }, 1000);\n },\n { once: true }\n );\n inputElement.addEventListener(\"change\", () => {\n if (!inputElement.files || inputElement.files?.length === 0) {\n reject(new FileSelectCancelError());\n } else {\n const files = Array.from(inputElement.files);\n if (illegalFiles(files)) {\n reject(new IllegalFileError(accepts));\n }\n resolve(files);\n }\n });\n });\n\n function illegalFiles(files: File[]): boolean {\n return (\n !accepts.includes(\"*\") &&\n files.some((file) => !accepts.includes(`.${getFileExtension(file)}`))\n );\n }\n};\n\nexport interface FileHandler {\n (fileRender: FileReader): void;\n}\n\nexport const readeFile = <T extends string | ArrayBuffer | null>(\n fileHandler: FileHandler\n): Promise<T> => {\n const reader = new FileReader();\n return new Promise((resolve, reject) => {\n reader.addEventListener(\n \"progress\",\n (event: FileReaderEventMap[\"progress\"]) => {\n const size = \"(\" + Math.floor(event.total / 1000) + \" KB)\";\n const progress = Math.floor((event.loaded / event.total) * 100) + \"%\";\n console.log(`Loading size: ${size} progress: ${progress}`);\n }\n );\n reader.addEventListener(\"load\", (event: FileReaderEventMap[\"load\"]) => {\n resolve(event.target?.result as T);\n });\n reader.addEventListener(\"error\", (event: FileReaderEventMap[\"error\"]) => {\n reject(event);\n });\n fileHandler(reader);\n // reader.readAsDataURL(file);\n // reader.readAsBinaryString(file);\n });\n};\n\n/**\n * 获取文件后缀\n *\n * @param file 文件或文件名\n * @returns\n */\nexport const getFileExtension = (file: File | string): string => {\n let fileName: string;\n if (file instanceof File) {\n fileName = file.name;\n } else {\n fileName = file;\n }\n return fileName.match(/\\.([0-9a-z]+)(?:[\\\\?#]|$)/i)![1] ?? \"\";\n};\n\nexport const isImage = (file: File): boolean => {\n return /^image\\//.test(file.type);\n};\n\nexport const isVideo = (file: File): boolean => {\n return /^video\\//.test(file.type);\n};\n\nexport const isAudio = (file: File): boolean => {\n return /^audio\\//.test(file.type);\n};\n\nexport const isWordDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.openxmlformats-officedocument\\.wordprocessingml\\.document|msword|vnd\\.ms-word\\.document\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.wordprocessingml\\.template|vnd\\.ms-word\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isExcelDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.openxmlformats-officedocument\\.spreadsheetml\\.sheet|vnd\\.ms-excel|vnd\\.ms-excel\\.sheet\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.spreadsheetml\\.template|vnd\\.ms-excel\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isPowerPointDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.ms-powerpoint|vnd\\.openxmlformats-officedocument\\.presentationml\\.presentation|vnd\\.ms-powerpoint\\.presentation\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.presentationml\\.template|vnd\\.ms-powerpoint\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isJsonDocument = (file: File): boolean => {\n return /^application\\/json$/.test(file.type);\n};\n\nexport const isXmlDocument = (file: File): boolean => {\n return /^(?:application|text)\\/(?:xml|xhtml\\+xml)$/.test(file.type);\n};\n\n/**\n * 判断文件类型\n * @example <input type=\"file\" onchange=\"getFileType(this.files[0])\"></input>\n */\nexport function getFileType(file: File) {\n // 文件开头的四个字节,生成一个 Blob 对象\n const slice = file.slice(0, 4);\n const reader = new FileReader();\n let verified_type: string;\n return new Promise((resolve, reject) => {\n reader.onload = function () {\n const buffer = reader.result as ArrayBuffer;\n // 将这四个字节的内容,视作一个32位整数\n const view = new DataView(buffer);\n const magic = view.getUint32(0, false);\n // 根据文件的前四个字节,判断它的类型\n switch (magic) {\n case 0x89504e47:\n verified_type = \"image/png\";\n break;\n case 0x47494638:\n verified_type = \"image/gif\";\n break;\n case 0x25504446:\n verified_type = \"application/pdf\";\n break;\n case 0x504b0304:\n verified_type = \"application/zip\";\n break;\n }\n return resolve(verified_type);\n };\n // 读取这四个字节\n reader.readAsArrayBuffer(slice);\n });\n}\n\n/**\n * 将一个函数转换为 blob,然后为这个 blob 生成 URL 对象\n */\nexport function fn2ObjectURL(fn: (...args: any[]) => any) {\n const blob = new Blob([\"(\" + fn.toString() + \")()\"], {\n type: \"application/javascript\"\n });\n return URL.createObjectURL(blob);\n // URL.revokeObjectURL(URL.createObjectURL(blob))\n}\n\nexport function file2Image(\n file: File,\n options?: {\n width?: number;\n height?: number;\n }\n) {\n if (!file.type.startsWith(\"image/\")) {\n return;\n }\n const img: HTMLImageElement = document.createElement(\"img\");\n img.src = URL.createObjectURL(file);\n img.width = options?.width ?? 60;\n img.height = options?.height ?? 60;\n img.onload = function () {\n // URL.revokeObjectURL(img.src);\n };\n return img;\n}\n"],"names":["BaseError","message","options","EnvironmentError","FileSelectCancelError","IllegalFileError","accepts","handleInputFiles","el","cb","handleDragAndDropFiles","dropZoneEl","e","selectFile","multiple","inputElement","resolve","reject","files","illegalFiles","file","getFileExtension","readeFile","fileHandler","reader","event","size","progress","fileName","isImage","isVideo","isAudio","isWordDocument","isExcelDocument","isPowerPointDocument","isJsonDocument","isXmlDocument","getFileType","slice","verified_type","buffer","fn2ObjectURL","fn","blob","file2Image","img"],"mappings":"AAAO,MAAMA,UAAkB,MAAM;AAAA,EACnC;AAAA,EAEA,YAAYC,GAAiBC,GAAwB;AACnD,UAAMD,GAASC,CAAO,GACjB,KAAA,OAAO,KAAK,YAAY;AAAA,EAC/B;AACF;AAEO,MAAMC,UAAyBH,EAAU;AAAA,EAC9C,cAAc;AACZ,UAAM,mCAAmC;AAAA,EAC3C;AACF;AAEO,MAAMI,UAA8BJ,EAAU;AAAA,EACnD,cAAc;AACZ,UAAM,eAAe;AAAA,EACvB;AACF;AAEO,MAAMK,UAAyBL,EAAU;AAAA,EAC9C;AAAA,EAEA,YAAYM,GAAmB;AACvB,UAAA,0BAA0B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AK,WAAW,QAAQ;AAChC;AAEI,QAAAyB,IAAwB,SAAS,cAAc,KAAK;AACtD,SAAAA,EAAA,MAAM,IAAI,gBAAgBzB,CAAI,GAC9ByB,EAAA,QAAQ3C,GAAS,SAAS,IAC1B2C,EAAA,SAAS3C,GAAS,UAAU,IAChC2C,EAAI,SAAS,WAAY;AAAA,EAAA,GAGlBA;AACT;"}
@@ -1,38 +1,2 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZYZGroupCoreWeb = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- class BaseError extends Error {
8
- constructor(message, options) {
9
- super(message, options);
10
- this.name = this.constructor.name;
11
- }
12
- }
13
- class EnvironmentError extends BaseError {
14
- constructor() {
15
- super("This is not a browser environment");
16
- }
17
- }
18
- class FileSelectCancelError extends BaseError {
19
- constructor() {
20
- super("Cancel select");
21
- }
22
- }
23
- class IllegalFileError extends BaseError {
24
- constructor(accepts) {
25
- super(`Please select files in ${accepts} format`);
26
- this.accepts = accepts;
27
- }
28
- }
29
-
30
- exports.BaseError = BaseError;
31
- exports.EnvironmentError = EnvironmentError;
32
- exports.FileSelectCancelError = FileSelectCancelError;
33
- exports.IllegalFileError = IllegalFileError;
34
-
35
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
36
-
37
- }));
1
+ (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i["zyzgroup-core-web"]={}))})(this,function(i){"use strict";class s extends Error{cause;constructor(n,t){super(n,t),this.name=this.constructor.name}}class d extends s{constructor(){super("This is not a browser environment")}}class c extends s{constructor(){super("Cancel select")}}class m extends s{accepts;constructor(n){super(`Please select files in ${n} format`),this.accepts=n}}function f(e,n){e.addEventListener("change",function(){n(e.files)},!1)}function p(e,n){e.addEventListener("dragover",function(t){t.stopPropagation(),t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy")},!1),e.addEventListener("drop",function(t){t.stopPropagation(),t.preventDefault(),t.dataTransfer&&n(t.dataTransfer.files)},!1)}const g=(e=["*"],n)=>{if(!globalThis.document||!(globalThis.document instanceof Document))throw new d;const t=globalThis.document.createElement("input");return t.setAttribute("type","file"),t.setAttribute("visibility","hidden"),Array.isArray(e)&&e.length>0&&t.setAttribute("accept",e.join(",")),n&&t.setAttribute("multiple","true"),t.click(),new Promise((o,a)=>{globalThis.addEventListener("focus",()=>{setTimeout(()=>{(!t.files||t.files?.length===0)&&a(new c)},1e3)},{once:!0}),t.addEventListener("change",()=>{if(!t.files||t.files?.length===0)a(new c);else{const l=Array.from(t.files);r(l)&&a(new m(e)),o(l)}})});function r(o){return!e.includes("*")&&o.some(a=>!e.includes(`.${u(a)}`))}},h=e=>{const n=new FileReader;return new Promise((t,r)=>{n.addEventListener("progress",o=>{const a="("+Math.floor(o.total/1e3)+" KB)",l=Math.floor(o.loaded/o.total*100)+"%";console.log(`Loading size: ${a} progress: ${l}`)}),n.addEventListener("load",o=>{t(o.target?.result)}),n.addEventListener("error",o=>{r(o)}),e(n)})},u=e=>{let n;return e instanceof File?n=e.name:n=e,n.match(/\.([0-9a-z]+)(?:[\\?#]|$)/i)[1]??""},v=e=>/^image\//.test(e.type),b=e=>/^video\//.test(e.type),w=e=>/^audio\//.test(e.type),E=e=>/^application\/(?:vnd\.openxmlformats-officedocument\.wordprocessingml\.document|msword|vnd\.ms-word\.document\.macroenabled\.12|vnd\.openxmlformats-officedocument\.wordprocessingml\.template|vnd\.ms-word\.template\.macroenabled\.12)$/.test(e.type),y=e=>/^application\/(?:vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|vnd\.ms-excel|vnd\.ms-excel\.sheet\.macroenabled\.12|vnd\.openxmlformats-officedocument\.spreadsheetml\.template|vnd\.ms-excel\.template\.macroenabled\.12)$/.test(e.type),F=e=>/^application\/(?:vnd\.ms-powerpoint|vnd\.openxmlformats-officedocument\.presentationml\.presentation|vnd\.ms-powerpoint\.presentation\.macroenabled\.12|vnd\.openxmlformats-officedocument\.presentationml\.template|vnd\.ms-powerpoint\.template\.macroenabled\.12)$/.test(e.type),D=e=>/^application\/json$/.test(e.type),L=e=>/^(?:application|text)\/(?:xml|xhtml\+xml)$/.test(e.type);function T(e){const n=e.slice(0,4),t=new FileReader;let r;return new Promise((o,a)=>{t.onload=function(){const l=t.result;switch(new DataView(l).getUint32(0,!1)){case 2303741511:r="image/png";break;case 1195984440:r="image/gif";break;case 626017350:r="application/pdf";break;case 1347093252:r="application/zip";break}return o(r)},t.readAsArrayBuffer(n)})}function A(e){const n=new Blob(["("+e.toString()+")()"],{type:"application/javascript"});return URL.createObjectURL(n)}function P(e,n){if(!e.type.startsWith("image/"))return;const t=document.createElement("img");return t.src=URL.createObjectURL(e),t.width=n?.width??60,t.height=n?.height??60,t.onload=function(){},t}i.BaseError=s,i.EnvironmentError=d,i.FileSelectCancelError=c,i.IllegalFileError=m,i.file2Image=P,i.fn2ObjectURL=A,i.getFileExtension=u,i.getFileType=T,i.handleDragAndDropFiles=p,i.handleInputFiles=f,i.isAudio=w,i.isExcelDocument=y,i.isImage=v,i.isJsonDocument=D,i.isPowerPointDocument=F,i.isVideo=b,i.isWordDocument=E,i.isXmlDocument=L,i.readeFile=h,i.selectFile=g,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
38
2
  //# sourceMappingURL=zyzgroup-core-web.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"zyzgroup-core-web.umd.cjs","sources":["../src/error.ts"],"sourcesContent":["export class BaseError extends Error {\n cause?: Error;\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = this.constructor.name;\n }\n}\n\nexport class EnvironmentError extends BaseError {\n constructor() {\n super(\"This is not a browser environment\");\n }\n}\n\nexport class FileSelectCancelError extends BaseError {\n constructor() {\n super(\"Cancel select\");\n }\n}\n\nexport class IllegalFileError extends BaseError {\n accepts: string[];\n\n constructor(accepts: string[]) {\n super(`Please select files in ${accepts} format`);\n this.accepts = accepts;\n }\n}\n"],"names":[],"mappings":";;;;;;EAAO,MAAM,kBAAkB,KAAM,CAAA;EAAA,EAGnC,WAAA,CAAY,SAAiB,OAAwB,EAAA;EACnD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;EACtB,IAAK,IAAA,CAAA,IAAA,GAAO,KAAK,WAAY,CAAA,IAAA,CAAA;EAAA,GAC/B;EACF,CAAA;EAEO,MAAM,yBAAyB,SAAU,CAAA;EAAA,EAC9C,WAAc,GAAA;EACZ,IAAA,KAAA,CAAM,mCAAmC,CAAA,CAAA;EAAA,GAC3C;EACF,CAAA;EAEO,MAAM,8BAA8B,SAAU,CAAA;EAAA,EACnD,WAAc,GAAA;EACZ,IAAA,KAAA,CAAM,eAAe,CAAA,CAAA;EAAA,GACvB;EACF,CAAA;EAEO,MAAM,yBAAyB,SAAU,CAAA;EAAA,EAG9C,YAAY,OAAmB,EAAA;EAC7B,IAAM,KAAA,CAAA,CAAA,uBAAA,EAA0B,OAAO,CAAS,OAAA,CAAA,CAAA,CAAA;EAChD,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;EAAA,GACjB;EACF;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"zyzgroup-core-web.umd.cjs","sources":["../src/error.ts","../src/file.ts"],"sourcesContent":["export class BaseError extends Error {\n cause?: Error;\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = this.constructor.name;\n }\n}\n\nexport class EnvironmentError extends BaseError {\n constructor() {\n super(\"This is not a browser environment\");\n }\n}\n\nexport class FileSelectCancelError extends BaseError {\n constructor() {\n super(\"Cancel select\");\n }\n}\n\nexport class IllegalFileError extends BaseError {\n accepts: string[];\n\n constructor(accepts: string[]) {\n super(`Please select files in ${accepts} format`);\n this.accepts = accepts;\n }\n}\n","import {\n EnvironmentError,\n FileSelectCancelError,\n IllegalFileError\n} from \"./error\";\n\n// <input type=\"file\" id=\"input\">\n// <input type=\"file\" id=\"input\" multiple accept=\"image/*\" style=\"display:none\" name=\"photos[]\">\n// <label for=\"input\">Select some files</label>\n// input css :focus :focus-within\nexport function handleInputFiles(\n el: HTMLInputElement,\n cb: (files: FileList | null) => any\n) {\n el.addEventListener(\n \"change\",\n function () {\n cb(el.files);\n },\n false\n );\n}\n\nexport function handleDragAndDropFiles(\n dropZoneEl: HTMLElement,\n cb: (files: FileList | null) => any\n) {\n // dragover dragenter dragend drop\n dropZoneEl.addEventListener(\n \"dragover\",\n function (e) {\n e.stopPropagation();\n e.preventDefault();\n if (e.dataTransfer) e.dataTransfer.dropEffect = \"copy\";\n },\n false\n );\n dropZoneEl.addEventListener(\n \"drop\",\n function (e) {\n e.stopPropagation();\n e.preventDefault();\n if (e.dataTransfer) cb(e.dataTransfer.files);\n },\n false\n );\n}\n\n/**\n * 选择系统文件\n *\n * @param accepts 可选文件后缀\n * @param multiple 是否多选\n * @returns\n */\nexport const selectFile = (\n accepts: string[] = [\"*\"],\n multiple?: boolean\n): Promise<File[]> => {\n if (!globalThis.document || !(globalThis.document instanceof Document)) {\n throw new EnvironmentError();\n }\n const inputElement = globalThis.document.createElement(\"input\");\n inputElement.setAttribute(\"type\", \"file\");\n inputElement.setAttribute(\"visibility\", \"hidden\");\n if (Array.isArray(accepts) && accepts.length > 0) {\n inputElement.setAttribute(\"accept\", accepts.join(\",\"));\n }\n if (multiple) {\n inputElement.setAttribute(\"multiple\", \"true\");\n }\n inputElement.click();\n\n return new Promise((resolve, reject) => {\n globalThis.addEventListener(\n \"focus\",\n () => {\n setTimeout(() => {\n if (!inputElement.files || inputElement.files?.length === 0) {\n reject(new FileSelectCancelError());\n }\n }, 1000);\n },\n { once: true }\n );\n inputElement.addEventListener(\"change\", () => {\n if (!inputElement.files || inputElement.files?.length === 0) {\n reject(new FileSelectCancelError());\n } else {\n const files = Array.from(inputElement.files);\n if (illegalFiles(files)) {\n reject(new IllegalFileError(accepts));\n }\n resolve(files);\n }\n });\n });\n\n function illegalFiles(files: File[]): boolean {\n return (\n !accepts.includes(\"*\") &&\n files.some((file) => !accepts.includes(`.${getFileExtension(file)}`))\n );\n }\n};\n\nexport interface FileHandler {\n (fileRender: FileReader): void;\n}\n\nexport const readeFile = <T extends string | ArrayBuffer | null>(\n fileHandler: FileHandler\n): Promise<T> => {\n const reader = new FileReader();\n return new Promise((resolve, reject) => {\n reader.addEventListener(\n \"progress\",\n (event: FileReaderEventMap[\"progress\"]) => {\n const size = \"(\" + Math.floor(event.total / 1000) + \" KB)\";\n const progress = Math.floor((event.loaded / event.total) * 100) + \"%\";\n console.log(`Loading size: ${size} progress: ${progress}`);\n }\n );\n reader.addEventListener(\"load\", (event: FileReaderEventMap[\"load\"]) => {\n resolve(event.target?.result as T);\n });\n reader.addEventListener(\"error\", (event: FileReaderEventMap[\"error\"]) => {\n reject(event);\n });\n fileHandler(reader);\n // reader.readAsDataURL(file);\n // reader.readAsBinaryString(file);\n });\n};\n\n/**\n * 获取文件后缀\n *\n * @param file 文件或文件名\n * @returns\n */\nexport const getFileExtension = (file: File | string): string => {\n let fileName: string;\n if (file instanceof File) {\n fileName = file.name;\n } else {\n fileName = file;\n }\n return fileName.match(/\\.([0-9a-z]+)(?:[\\\\?#]|$)/i)![1] ?? \"\";\n};\n\nexport const isImage = (file: File): boolean => {\n return /^image\\//.test(file.type);\n};\n\nexport const isVideo = (file: File): boolean => {\n return /^video\\//.test(file.type);\n};\n\nexport const isAudio = (file: File): boolean => {\n return /^audio\\//.test(file.type);\n};\n\nexport const isWordDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.openxmlformats-officedocument\\.wordprocessingml\\.document|msword|vnd\\.ms-word\\.document\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.wordprocessingml\\.template|vnd\\.ms-word\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isExcelDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.openxmlformats-officedocument\\.spreadsheetml\\.sheet|vnd\\.ms-excel|vnd\\.ms-excel\\.sheet\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.spreadsheetml\\.template|vnd\\.ms-excel\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isPowerPointDocument = (file: File): boolean => {\n return /^application\\/(?:vnd\\.ms-powerpoint|vnd\\.openxmlformats-officedocument\\.presentationml\\.presentation|vnd\\.ms-powerpoint\\.presentation\\.macroenabled\\.12|vnd\\.openxmlformats-officedocument\\.presentationml\\.template|vnd\\.ms-powerpoint\\.template\\.macroenabled\\.12)$/.test(\n file.type\n );\n};\n\nexport const isJsonDocument = (file: File): boolean => {\n return /^application\\/json$/.test(file.type);\n};\n\nexport const isXmlDocument = (file: File): boolean => {\n return /^(?:application|text)\\/(?:xml|xhtml\\+xml)$/.test(file.type);\n};\n\n/**\n * 判断文件类型\n * @example <input type=\"file\" onchange=\"getFileType(this.files[0])\"></input>\n */\nexport function getFileType(file: File) {\n // 文件开头的四个字节,生成一个 Blob 对象\n const slice = file.slice(0, 4);\n const reader = new FileReader();\n let verified_type: string;\n return new Promise((resolve, reject) => {\n reader.onload = function () {\n const buffer = reader.result as ArrayBuffer;\n // 将这四个字节的内容,视作一个32位整数\n const view = new DataView(buffer);\n const magic = view.getUint32(0, false);\n // 根据文件的前四个字节,判断它的类型\n switch (magic) {\n case 0x89504e47:\n verified_type = \"image/png\";\n break;\n case 0x47494638:\n verified_type = \"image/gif\";\n break;\n case 0x25504446:\n verified_type = \"application/pdf\";\n break;\n case 0x504b0304:\n verified_type = \"application/zip\";\n break;\n }\n return resolve(verified_type);\n };\n // 读取这四个字节\n reader.readAsArrayBuffer(slice);\n });\n}\n\n/**\n * 将一个函数转换为 blob,然后为这个 blob 生成 URL 对象\n */\nexport function fn2ObjectURL(fn: (...args: any[]) => any) {\n const blob = new Blob([\"(\" + fn.toString() + \")()\"], {\n type: \"application/javascript\"\n });\n return URL.createObjectURL(blob);\n // URL.revokeObjectURL(URL.createObjectURL(blob))\n}\n\nexport function file2Image(\n file: File,\n options?: {\n width?: number;\n height?: number;\n }\n) {\n if (!file.type.startsWith(\"image/\")) {\n return;\n }\n const img: HTMLImageElement = document.createElement(\"img\");\n img.src = URL.createObjectURL(file);\n img.width = options?.width ?? 60;\n img.height = options?.height ?? 60;\n img.onload = function () {\n // URL.revokeObjectURL(img.src);\n };\n return img;\n}\n"],"names":["BaseError","message","options","EnvironmentError","FileSelectCancelError","IllegalFileError","accepts","handleInputFiles","el","cb","handleDragAndDropFiles","dropZoneEl","e","selectFile","multiple","inputElement","resolve","reject","files","illegalFiles","file","getFileExtension","readeFile","fileHandler","reader","event","size","progress","fileName","isImage","isVideo","isAudio","isWordDocument","isExcelDocument","isPowerPointDocument","isJsonDocument","isXmlDocument","getFileType","slice","verified_type","buffer","fn2ObjectURL","fn","blob","file2Image","img"],"mappings":"4OAAO,MAAMA,UAAkB,KAAM,CACnC,MAEA,YAAYC,EAAiBC,EAAwB,CACnD,MAAMD,EAASC,CAAO,EACjB,KAAA,KAAO,KAAK,YAAY,IAC/B,CACF,CAEO,MAAMC,UAAyBH,CAAU,CAC9C,aAAc,CACZ,MAAM,mCAAmC,CAC3C,CACF,CAEO,MAAMI,UAA8BJ,CAAU,CACnD,aAAc,CACZ,MAAM,eAAe,CACvB,CACF,CAEO,MAAMK,UAAyBL,CAAU,CAC9C,QAEA,YAAYM,EAAmB,CACvB,MAAA,0BAA0BA,CAAO,SAAS,EAChD,KAAK,QAAUA,CACjB,CACF,CClBgB,SAAAC,EACdC,EACAC,EACA,CACGD,EAAA,iBACD,SACA,UAAY,CACVC,EAAGD,EAAG,KAAK,CACb,EACA,EAAA,CAEJ,CAEgB,SAAAE,EACdC,EACAF,EACA,CAEWE,EAAA,iBACT,WACA,SAAUC,EAAG,CACXA,EAAE,gBAAgB,EAClBA,EAAE,eAAe,EACbA,EAAE,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EAAShB,EAAO,OAKtB,OAHa,IAAI,SAASgB,CAAM,EACb,UAAU,EAAG,EAAK,EAEtB,CACb,IAAK,YACaD,EAAA,YAChB,MACF,IAAK,YACaA,EAAA,YAChB,MACF,IAAK,WACaA,EAAA,kBAChB,MACF,IAAK,YACaA,EAAA,kBAChB,KACJ,CACA,OAAOvB,EAAQuB,CAAa,CAAA,EAG9Bf,EAAO,kBAAkBc,CAAK,CAAA,CAC/B,CACH,CAKO,SAASG,EAAaC,EAA6B,CAClD,MAAAC,EAAO,IAAI,KAAK,CAAC,IAAMD,EAAG,SAAA,EAAa,KAAK,EAAG,CACnD,KAAM,wBAAA,CACP,EACM,OAAA,IAAI,gBAAgBC,CAAI,CAEjC,CAEgB,SAAAC,EACdxB,EACAlB,EAIA,CACA,GAAI,CAACkB,EAAK,KAAK,WAAW,QAAQ,EAChC,OAEI,MAAAyB,EAAwB,SAAS,cAAc,KAAK,EACtD,OAAAA,EAAA,IAAM,IAAI,gBAAgBzB,CAAI,EAC9ByB,EAAA,MAAQ3C,GAAS,OAAS,GAC1B2C,EAAA,OAAS3C,GAAS,QAAU,GAChC2C,EAAI,OAAS,UAAY,CAAA,EAGlBA,CACT"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@zyzgroup/core-web",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
+ "type": "module",
5
6
  "main": "dist/zyzgroup-core-web.umd.cjs",
6
7
  "module": "dist/zyzgroup-core-web.js",
7
8
  "types": "types/index.d.ts",
@@ -16,6 +17,8 @@
16
17
  "types/**/*"
17
18
  ],
18
19
  "scripts": {
20
+ "build": "npm run build:type && npm run --prefix ../../../vite/ lib -- ../lib/packages/core-web/vite.config.json",
21
+ "publishToNpm": "update_package_version ./package.json && npm publish --access public",
19
22
  "build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.json",
20
23
  "clear:type": "rimraf ./types"
21
24
  },
@@ -23,4 +26,4 @@
23
26
  "rimraf": "^5.0.5",
24
27
  "typescript": "^5.2.2"
25
28
  }
26
- }
29
+ }
@@ -0,0 +1,22 @@
1
+ export declare function handleInputFiles(el: HTMLInputElement, cb: (files: FileList | null) => any): void;
2
+ export declare function handleDragAndDropFiles(dropZoneEl: HTMLElement, cb: (files: FileList | null) => any): void;
3
+ export declare const selectFile: (accepts?: string[], multiple?: boolean) => Promise<File[]>;
4
+ export interface FileHandler {
5
+ (fileRender: FileReader): void;
6
+ }
7
+ export declare const readeFile: <T extends string | ArrayBuffer | null>(fileHandler: FileHandler) => Promise<T>;
8
+ export declare const getFileExtension: (file: File | string) => string;
9
+ export declare const isImage: (file: File) => boolean;
10
+ export declare const isVideo: (file: File) => boolean;
11
+ export declare const isAudio: (file: File) => boolean;
12
+ export declare const isWordDocument: (file: File) => boolean;
13
+ export declare const isExcelDocument: (file: File) => boolean;
14
+ export declare const isPowerPointDocument: (file: File) => boolean;
15
+ export declare const isJsonDocument: (file: File) => boolean;
16
+ export declare const isXmlDocument: (file: File) => boolean;
17
+ export declare function getFileType(file: File): Promise<unknown>;
18
+ export declare function fn2ObjectURL(fn: (...args: any[]) => any): string;
19
+ export declare function file2Image(file: File, options?: {
20
+ width?: number;
21
+ height?: number;
22
+ }): HTMLImageElement | undefined;
package/types/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export { BaseError, EnvironmentError, FileSelectCancelError, IllegalFileError } from "./error";
1
+ export * from "./error";
2
+ export * from "./file";