@qxs-bns/utils 0.0.2 → 0.0.4

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),o=require("./src/file-operations.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),n=require("vue");exports.isMobile=r.isMobile;exports.videoUploader=o.videoUploader;exports.isImageByMimeType=t.isImageByMimeType;exports.initStorage=i.initStorage;exports.useStorage=i.useStorage;exports.isBoolean=e.isBoolean;exports.isElement=e.isElement;exports.isNumber=e.isNumber;exports.isUndefined=e.isUndefined;exports.isWindow=e.isWindow;exports.watermark=s.watermark;Object.defineProperty(exports,"isVNode",{enumerable:!0,get:()=>n.isVNode});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),o=require("./src/file-operations.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),n=require("vue");exports.isMobile=r.isMobile;exports.VideoUploader=o.VideoUploader;exports.isImageByMimeType=t.isImageByMimeType;exports.initStorage=i.initStorage;exports.useStorage=i.useStorage;exports.isBoolean=e.isBoolean;exports.isElement=e.isElement;exports.isNumber=e.isNumber;exports.isUndefined=e.isUndefined;exports.isWindow=e.isWindow;exports.watermark=s.watermark;Object.defineProperty(exports,"isVNode",{enumerable:!0,get:()=>n.isVNode});
package/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { isMobile as r } from "./src/device.js";
2
- import { videoUploader as m } from "./src/file-operations.js";
2
+ import { VideoUploader as m } from "./src/file-operations.js";
3
3
  import { isImageByMimeType as p } from "./src/media.js";
4
4
  import { initStorage as f, useStorage as a } from "./src/storage.js";
5
5
  import { isBoolean as d, isElement as n, isNumber as l, isUndefined as g, isWindow as b } from "./src/types.js";
6
6
  import { watermark as w } from "./src/watermark.js";
7
7
  import { isVNode as B } from "vue";
8
8
  export {
9
+ m as VideoUploader,
9
10
  f as initStorage,
10
11
  d as isBoolean,
11
12
  n as isElement,
@@ -16,6 +17,5 @@ export {
16
17
  B as isVNode,
17
18
  b as isWindow,
18
19
  a as useStorage,
19
- m as videoUploader,
20
20
  w as watermark
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qxs-bns/utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.js",
6
6
  "types": "./types/index.d.ts",
@@ -11,9 +11,6 @@
11
11
  "require": "./index.cjs"
12
12
  }
13
13
  },
14
- "dependencies": {
15
- "axios": "^1.7.9"
16
- },
17
14
  "publishConfig": {
18
15
  "access": "public",
19
16
  "registry": "https://registry.npmjs.org/"
package/src/device.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){const i=navigator.userAgent,n=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let t=!1;for(let e=0;e<n.length;e++)if(i.indexOf(n[e])>0){t=!0;break}return t}exports.isMobile=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){if(typeof navigator!="undefined"){const i=navigator.userAgent,n=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let t=!1;for(let e=0;e<n.length;e++)if(i.indexOf(n[e])>0){t=!0;break}return t}return"确保在浏览器环境中"}exports.isMobile=o;
package/src/device.js CHANGED
@@ -1,20 +1,23 @@
1
- function i() {
2
- const t = navigator.userAgent, n = [
3
- "Android",
4
- "iPhone",
5
- "SymbianOS",
6
- "Windows Phone",
7
- "iPad",
8
- "iPod"
9
- ];
10
- let o = !1;
11
- for (let e = 0; e < n.length; e++)
12
- if (t.indexOf(n[e]) > 0) {
13
- o = !0;
14
- break;
15
- }
16
- return o;
1
+ function o() {
2
+ if (typeof navigator != "undefined") {
3
+ const i = navigator.userAgent, n = [
4
+ "Android",
5
+ "iPhone",
6
+ "SymbianOS",
7
+ "Windows Phone",
8
+ "iPad",
9
+ "iPod"
10
+ ];
11
+ let t = !1;
12
+ for (let e = 0; e < n.length; e++)
13
+ if (i.indexOf(n[e]) > 0) {
14
+ t = !0;
15
+ break;
16
+ }
17
+ return t;
18
+ }
19
+ return "确保在浏览器环境中";
17
20
  }
18
21
  export {
19
- i as isMobile
22
+ o as isMobile
20
23
  };
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var S=(a,d,e)=>d in a?w(a,d,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[d]=e;var c=(a,d,e)=>S(a,typeof d!="symbol"?d+"":d,e);var U=(a,d,e)=>new Promise((l,n)=>{var s=r=>{try{t(e.next(r))}catch(o){n(o)}},u=r=>{try{t(e.throw(r))}catch(o){n(o)}},t=r=>r.done?l(r.value):Promise.resolve(r.value).then(s,u);t((e=e.apply(a,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.cjs");require("../lib/aliyun-upload-sdk-1.5.6.min.cjs");window.OSS=y;const h=window.AliyunUpload;class A{constructor(){c(this,"uploader");if(!h)throw new Error("请先引入阿里云上传SDK")}init(d){return this.uploader=new h.Vod({onUploadFailed:d.onUploadFailed,onUploadSucceed:d.onUploadSucceed,onUploadProgress:d.onUploadProgress,onUploadTokenExpired:d.onUploadTokenExpired||(()=>{}),onUploadstarted:e=>U(this,null,function*(){var u;const{uploadAuth:l,uploadAddress:n,videoId:s}=(yield(u=d.onUploadstarted)==null?void 0:u.call(d,e))||{};l&&n&&s&&this.uploader.setUploadAuthAndAddress(e,l,n,s)})}),this.uploader}upload(d){return new Promise((e,l)=>{if(!this.uploader){l(new Error("请先调用 init 方法初始化上传器"));return}const n=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});this.uploader.addFile(d,null,null,null,n),this.uploader.startUpload();const s=o=>{e({videoId:o.videoId})},u=(o,p,i)=>{l(new Error(i||"上传失败"))},t=this.uploader.onUploadSucceed,r=this.uploader.onUploadFailed;this.uploader.onUploadSucceed=o=>{s(o),t==null||t(o)},this.uploader.onUploadFailed=(o,p,i)=>{u(o,p,i),r==null||r(o,p,i)}})}}const v=new A;exports.videoUploader=v;
1
+ "use strict";var h=Object.defineProperty;var y=(l,d,o)=>d in l?h(l,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[d]=o;var w=(l,d,o)=>y(l,typeof d!="symbol"?d+"":d,o);var p=(l,d,o)=>new Promise((r,i)=>{var t=a=>{try{n(o.next(a))}catch(e){i(e)}},s=a=>{try{n(o.throw(a))}catch(e){i(e)}},n=a=>a.done?r(a.value):Promise.resolve(a.value).then(t,s);n((o=o.apply(l,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../vendor/ali-oss/dist/aliyun-oss-sdk.js.cjs");let U;function f(){return p(this,null,function*(){window.OSS=S,yield import("../lib/aliyun-upload-sdk-1.5.6.min.js"),U=window.AliyunUpload})}class A{constructor(d){w(this,"uploader");this.initialize(d)}initialize(d){return p(this,null,function*(){if(typeof window=="undefined")throw new TypeError("VideoUploader 只能在浏览器环境中使用");U||(yield f()),this.uploader=new U.Vod({onUploadFailed:d.onUploadFailed,onUploadSucceed:d.onUploadSucceed,onUploadProgress:d.onUploadProgress,onUploadTokenExpired:d.onUploadTokenExpired||(()=>{}),onUploadstarted:o=>p(this,null,function*(){var s;const{uploadAuth:r,uploadAddress:i,videoId:t}=(yield(s=d.onUploadstarted)==null?void 0:s.call(d,o))||{};r&&i&&t&&this.uploader.setUploadAuthAndAddress(o,r,i,t)})})})}upload(d){return new Promise((o,r)=>{if(!this.uploader){r(new Error("请先调用 init 方法初始化上传器"));return}const i=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});this.uploader.addFile(d,null,null,null,i),this.uploader.startUpload();const t=e=>{o({videoId:e.videoId})},s=(e,c,u)=>{r(new Error(u||"上传失败"))},n=this.uploader.onUploadSucceed,a=this.uploader.onUploadFailed;this.uploader.onUploadSucceed=e=>{t(e),n==null||n(e)},this.uploader.onUploadFailed=(e,c,u)=>{s(e,c,u),a==null||a(e,c,u)}})}}exports.VideoUploader=A;
@@ -1,53 +1,59 @@
1
- var w = Object.defineProperty;
2
- var S = (a, d, o) => d in a ? w(a, d, { enumerable: !0, configurable: !0, writable: !0, value: o }) : a[d] = o;
3
- var U = (a, d, o) => S(a, typeof d != "symbol" ? d + "" : d, o);
4
- var c = (a, d, o) => new Promise((l, n) => {
5
- var s = (r) => {
1
+ var h = Object.defineProperty;
2
+ var y = (l, d, o) => d in l ? h(l, d, { enumerable: !0, configurable: !0, writable: !0, value: o }) : l[d] = o;
3
+ var w = (l, d, o) => y(l, typeof d != "symbol" ? d + "" : d, o);
4
+ var u = (l, d, o) => new Promise((r, i) => {
5
+ var t = (e) => {
6
6
  try {
7
- t(o.next(r));
8
- } catch (e) {
9
- n(e);
7
+ n(o.next(e));
8
+ } catch (a) {
9
+ i(a);
10
10
  }
11
- }, p = (r) => {
11
+ }, s = (e) => {
12
12
  try {
13
- t(o.throw(r));
14
- } catch (e) {
15
- n(e);
13
+ n(o.throw(e));
14
+ } catch (a) {
15
+ i(a);
16
16
  }
17
- }, t = (r) => r.done ? l(r.value) : Promise.resolve(r.value).then(s, p);
18
- t((o = o.apply(a, d)).next());
17
+ }, n = (e) => e.done ? r(e.value) : Promise.resolve(e.value).then(t, s);
18
+ n((o = o.apply(l, d)).next());
19
19
  });
20
- import A from "../node_modules/.pnpm/ali-oss@6.22.0/node_modules/ali-oss/dist/aliyun-oss-sdk.js";
21
- import "../lib/aliyun-upload-sdk-1.5.6.min.js";
22
- window.OSS = A;
23
- const h = window.AliyunUpload;
24
- class f {
25
- constructor() {
26
- U(this, "uploader");
27
- if (!h)
28
- throw new Error("请先引入阿里云上传SDK");
20
+ import S from "../vendor/ali-oss/dist/aliyun-oss-sdk.js.js";
21
+ let c;
22
+ function f() {
23
+ return u(this, null, function* () {
24
+ window.OSS = S, yield import("../lib/aliyun-upload-sdk-1.5.6.min.js"), c = window.AliyunUpload;
25
+ });
26
+ }
27
+ class E {
28
+ constructor(d) {
29
+ w(this, "uploader");
30
+ this.initialize(d);
29
31
  }
30
- init(d) {
31
- return this.uploader = new h.Vod({
32
- onUploadFailed: d.onUploadFailed,
33
- onUploadSucceed: d.onUploadSucceed,
34
- onUploadProgress: d.onUploadProgress,
35
- onUploadTokenExpired: d.onUploadTokenExpired || (() => {
36
- }),
37
- onUploadstarted: (o) => c(this, null, function* () {
38
- var p;
39
- const { uploadAuth: l, uploadAddress: n, videoId: s } = (yield (p = d.onUploadstarted) == null ? void 0 : p.call(d, o)) || {};
40
- l && n && s && this.uploader.setUploadAuthAndAddress(o, l, n, s);
41
- })
42
- }), this.uploader;
32
+ initialize(d) {
33
+ return u(this, null, function* () {
34
+ if (typeof window == "undefined")
35
+ throw new TypeError("VideoUploader 只能在浏览器环境中使用");
36
+ c || (yield f()), this.uploader = new c.Vod({
37
+ onUploadFailed: d.onUploadFailed,
38
+ onUploadSucceed: d.onUploadSucceed,
39
+ onUploadProgress: d.onUploadProgress,
40
+ onUploadTokenExpired: d.onUploadTokenExpired || (() => {
41
+ }),
42
+ onUploadstarted: (o) => u(this, null, function* () {
43
+ var s;
44
+ const { uploadAuth: r, uploadAddress: i, videoId: t } = (yield (s = d.onUploadstarted) == null ? void 0 : s.call(d, o)) || {};
45
+ r && i && t && this.uploader.setUploadAuthAndAddress(o, r, i, t);
46
+ })
47
+ });
48
+ });
43
49
  }
44
50
  upload(d) {
45
- return new Promise((o, l) => {
51
+ return new Promise((o, r) => {
46
52
  if (!this.uploader) {
47
- l(new Error("请先调用 init 方法初始化上传器"));
53
+ r(new Error("请先调用 init 方法初始化上传器"));
48
54
  return;
49
55
  }
50
- const n = JSON.stringify({
56
+ const i = JSON.stringify({
51
57
  Vod: {
52
58
  UserData: {
53
59
  IsShowWaterMark: "false",
@@ -55,21 +61,20 @@ class f {
55
61
  }
56
62
  }
57
63
  });
58
- this.uploader.addFile(d, null, null, null, n), this.uploader.startUpload();
59
- const s = (e) => {
60
- o({ videoId: e.videoId });
61
- }, p = (e, i, u) => {
62
- l(new Error(u || "上传失败"));
63
- }, t = this.uploader.onUploadSucceed, r = this.uploader.onUploadFailed;
64
- this.uploader.onUploadSucceed = (e) => {
65
- s(e), t == null || t(e);
66
- }, this.uploader.onUploadFailed = (e, i, u) => {
67
- p(e, i, u), r == null || r(e, i, u);
64
+ this.uploader.addFile(d, null, null, null, i), this.uploader.startUpload();
65
+ const t = (a) => {
66
+ o({ videoId: a.videoId });
67
+ }, s = (a, U, p) => {
68
+ r(new Error(p || "上传失败"));
69
+ }, n = this.uploader.onUploadSucceed, e = this.uploader.onUploadFailed;
70
+ this.uploader.onUploadSucceed = (a) => {
71
+ t(a), n == null || n(a);
72
+ }, this.uploader.onUploadFailed = (a, U, p) => {
73
+ s(a, U, p), e == null || e(a, U, p);
68
74
  };
69
75
  });
70
76
  }
71
77
  }
72
- const F = new f();
73
78
  export {
74
- F as videoUploader
79
+ E as VideoUploader
75
80
  };
package/types/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare function isImageByMimeType(file: File): boolean;
11
11
  /**
12
12
  * 判断是移动端还是pc端
13
13
  */
14
- export declare function isMobile(): boolean;
14
+ export declare function isMobile(): boolean | "确保在浏览器环境中";
15
15
 
16
16
  export declare const isNumber: (val: any) => val is number;
17
17
 
@@ -21,6 +21,11 @@ export { isVNode }
21
21
 
22
22
  export declare function isWindow(val: unknown): val is Window;
23
23
 
24
+ export declare interface IVideoUploader {
25
+ uploader: any;
26
+ upload: (file: File) => Promise<VideoUploadResult>;
27
+ }
28
+
24
29
  declare interface SettingsType {
25
30
  /** 水印总体的id */
26
31
  id?: string;
@@ -100,15 +105,13 @@ export declare interface UploadInfo {
100
105
 
101
106
  export declare const useStorage: typeof Storage_2.getInstance;
102
107
 
103
- declare class VideoUploader {
104
- private uploader;
105
- constructor();
106
- init(options: VideoUploadOptions): any;
108
+ export declare class VideoUploader implements IVideoUploader {
109
+ uploader: any;
110
+ constructor(options: VideoUploadOptions);
111
+ private initialize;
107
112
  upload(file: File): Promise<VideoUploadResult>;
108
113
  }
109
114
 
110
- export declare const videoUploader: VideoUploader;
111
-
112
115
  declare interface VideoUploadOptions {
113
116
  onUploadFailed?: (uploadInfo: any, code: string, message: string) => void;
114
117
  onUploadSucceed?: (uploadInfo: any) => void;