@qxs-bns/utils 0.0.4 → 0.0.6

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"),t=require("./src/file-operations.cjs"),o=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),a=require("vue");exports.isMobile=r.isMobile;exports.createVideoUploader=t.createVideoUploader;exports.isImageByMimeType=o.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:()=>a.isVNode});
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { isMobile as r } from "./src/device.js";
2
- import { VideoUploader as m } from "./src/file-operations.js";
2
+ import { createVideoUploader as t } from "./src/file-operations.js";
3
3
  import { isImageByMimeType as p } from "./src/media.js";
4
- import { initStorage as f, useStorage as a } from "./src/storage.js";
4
+ import { initStorage as a, useStorage as f } 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,
10
- f as initStorage,
9
+ t as createVideoUploader,
10
+ a as initStorage,
11
11
  d as isBoolean,
12
12
  n as isElement,
13
13
  p as isImageByMimeType,
@@ -16,6 +16,6 @@ export {
16
16
  g as isUndefined,
17
17
  B as isVNode,
18
18
  b as isWindow,
19
- a as useStorage,
19
+ f as useStorage,
20
20
  w as watermark
21
21
  };
package/package.json CHANGED
@@ -1,16 +1,56 @@
1
1
  {
2
2
  "name": "@qxs-bns/utils",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.js",
6
6
  "types": "./types/index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "index.cjs",
10
+ "src",
11
+ "types",
12
+ "lib"
13
+ ],
7
14
  "exports": {
8
15
  ".": {
9
16
  "types": "./types/index.d.ts",
10
17
  "import": "./index.js",
11
18
  "require": "./index.cjs"
19
+ },
20
+ "./src/file-operations": {
21
+ "types": "./types/index.d.ts",
22
+ "import": "./src/file-operations.js",
23
+ "require": "./src/file-operations.cjs"
24
+ },
25
+ "./src/media": {
26
+ "types": "./types/index.d.ts",
27
+ "import": "./src/media.js",
28
+ "require": "./src/media.cjs"
29
+ },
30
+ "./src/device": {
31
+ "types": "./types/index.d.ts",
32
+ "import": "./src/device.js",
33
+ "require": "./src/device.cjs"
34
+ },
35
+ "./src/storage": {
36
+ "types": "./types/index.d.ts",
37
+ "import": "./src/storage.js",
38
+ "require": "./src/storage.cjs"
39
+ },
40
+ "./src/type": {
41
+ "types": "./types/index.d.ts",
42
+ "import": "./src/type.js",
43
+ "require": "./src/type.cjs"
44
+ },
45
+ "./src/watermark": {
46
+ "types": "./types/index.d.ts",
47
+ "import": "./src/watermark.js",
48
+ "require": "./src/watermark.cjs"
12
49
  }
13
50
  },
51
+ "dependencies": {
52
+ "ali-oss": "^6.22.0"
53
+ },
14
54
  "publishConfig": {
15
55
  "access": "public",
16
56
  "registry": "https://registry.npmjs.org/"
@@ -1 +1 @@
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
+ "use strict";var s=(e,d,l)=>new Promise((o,t)=>{var i=a=>{try{n(l.next(a))}catch(c){t(c)}},u=a=>{try{n(l.throw(a))}catch(c){t(c)}},n=a=>a.done?o(a.value):Promise.resolve(a.value).then(i,u);n((l=l.apply(e,d)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../public/aliyun-upload-sdk-1.5.6/aliyun-upload-sdk-1.5.6.min.cjs"),f=require("../public/aliyun-upload-sdk-1.5.6/lib/aliyun-oss-sdk-6.17.1.min.cjs");function y(e){return s(this,null,function*(){return new Promise((d,l)=>{try{const o=document.createElement("script");o.text=e,document.head.appendChild(o),d()}catch(o){l(o)}})})}function h(){return s(this,null,function*(){try{if(yield y(f),yield y(S),!window.AliyunUpload)throw new Error("SDK 加载成功但未找到 AliyunUpload 对象")}catch(e){throw e}})}function A(e){return s(this,null,function*(){if(typeof window=="undefined")throw new TypeError("VideoUploader 只能在浏览器环境中使用");window.AliyunUpload||(yield h());const d=new window.AliyunUpload.Vod({onUploadFailed:e.onUploadFailed,onUploadSucceed:e.onUploadSucceed,onUploadProgress:e.onUploadProgress,onUploadTokenExpired:e.onUploadTokenExpired||(()=>{}),onUploadstarted:o=>s(this,null,function*(){var n;const{uploadAuth:t,uploadAddress:i,videoId:u}=(yield(n=e.onUploadstarted)==null?void 0:n.call(e,o))||{};t&&i&&u&&d.setUploadAuthAndAddress(o,t,i,u)})});return{uploader:d,upload:o=>s(this,null,function*(){return new Promise((t,i)=>{const u=JSON.stringify({Vod:{UserData:{IsShowWaterMark:"false",Priority:"7"}}});d.addFile(o,null,null,null,u),d.startUpload();const n=r=>{t({videoId:r.videoId})},a=(r,w,p)=>{i(new Error(p||"上传失败"))},c=d.onUploadSucceed,U=d.onUploadFailed;d.onUploadSucceed=r=>{n(r),c==null||c(r)},d.onUploadFailed=(r,w,p)=>{a(r,w,p),U==null||U(r,w,p)}})})}})}exports.createVideoUploader=A;
@@ -1,80 +1,88 @@
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) => {
1
+ var s = (d, o, l) => new Promise((e, t) => {
2
+ var i = (a) => {
6
3
  try {
7
- n(o.next(e));
8
- } catch (a) {
9
- i(a);
4
+ r(l.next(a));
5
+ } catch (c) {
6
+ t(c);
10
7
  }
11
- }, s = (e) => {
8
+ }, p = (a) => {
12
9
  try {
13
- n(o.throw(e));
14
- } catch (a) {
15
- i(a);
10
+ r(l.throw(a));
11
+ } catch (c) {
12
+ t(c);
16
13
  }
17
- }, n = (e) => e.done ? r(e.value) : Promise.resolve(e.value).then(t, s);
18
- n((o = o.apply(l, d)).next());
14
+ }, r = (a) => a.done ? e(a.value) : Promise.resolve(a.value).then(i, p);
15
+ r((l = l.apply(d, o)).next());
19
16
  });
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;
17
+ import f from "../public/aliyun-upload-sdk-1.5.6/aliyun-upload-sdk-1.5.6.min.js";
18
+ import h from "../public/aliyun-upload-sdk-1.5.6/lib/aliyun-oss-sdk-6.17.1.min.js";
19
+ function y(d) {
20
+ return s(this, null, function* () {
21
+ return new Promise((o, l) => {
22
+ try {
23
+ const e = document.createElement("script");
24
+ e.text = d, document.head.appendChild(e), o();
25
+ } catch (e) {
26
+ l(e);
27
+ }
28
+ });
25
29
  });
26
30
  }
27
- class E {
28
- constructor(d) {
29
- w(this, "uploader");
30
- this.initialize(d);
31
- }
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
- });
49
- }
50
- upload(d) {
51
- return new Promise((o, r) => {
52
- if (!this.uploader) {
53
- r(new Error("请先调用 init 方法初始化上传器"));
54
- return;
55
- }
56
- const i = JSON.stringify({
57
- Vod: {
58
- UserData: {
59
- IsShowWaterMark: "false",
60
- Priority: "7"
61
- }
62
- }
63
- });
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);
74
- };
31
+ function A() {
32
+ return s(this, null, function* () {
33
+ try {
34
+ if (yield y(h), yield y(f), !window.AliyunUpload)
35
+ throw new Error("SDK 加载成功但未找到 AliyunUpload 对象");
36
+ } catch (d) {
37
+ throw d;
38
+ }
39
+ });
40
+ }
41
+ function P(d) {
42
+ return s(this, null, function* () {
43
+ if (typeof window == "undefined")
44
+ throw new TypeError("VideoUploader 只能在浏览器环境中使用");
45
+ window.AliyunUpload || (yield A());
46
+ const o = new window.AliyunUpload.Vod({
47
+ onUploadFailed: d.onUploadFailed,
48
+ onUploadSucceed: d.onUploadSucceed,
49
+ onUploadProgress: d.onUploadProgress,
50
+ onUploadTokenExpired: d.onUploadTokenExpired || (() => {
51
+ }),
52
+ onUploadstarted: (e) => s(this, null, function* () {
53
+ var r;
54
+ const { uploadAuth: t, uploadAddress: i, videoId: p } = (yield (r = d.onUploadstarted) == null ? void 0 : r.call(d, e)) || {};
55
+ t && i && p && o.setUploadAuthAndAddress(e, t, i, p);
56
+ })
75
57
  });
76
- }
58
+ return {
59
+ uploader: o,
60
+ upload: (e) => s(this, null, function* () {
61
+ return new Promise((t, i) => {
62
+ const p = JSON.stringify({
63
+ Vod: {
64
+ UserData: {
65
+ IsShowWaterMark: "false",
66
+ Priority: "7"
67
+ }
68
+ }
69
+ });
70
+ o.addFile(e, null, null, null, p), o.startUpload();
71
+ const r = (n) => {
72
+ t({ videoId: n.videoId });
73
+ }, a = (n, w, u) => {
74
+ i(new Error(u || "上传失败"));
75
+ }, c = o.onUploadSucceed, U = o.onUploadFailed;
76
+ o.onUploadSucceed = (n) => {
77
+ r(n), c == null || c(n);
78
+ }, o.onUploadFailed = (n, w, u) => {
79
+ a(n, w, u), U == null || U(n, w, u);
80
+ };
81
+ });
82
+ })
83
+ };
84
+ });
77
85
  }
78
86
  export {
79
- E as VideoUploader
87
+ P as createVideoUploader
80
88
  };
package/types/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { isVNode } from 'vue';
2
2
 
3
+ export declare function createVideoUploader(options: VideoUploadOptions): Promise<IVideoUploader>;
4
+
3
5
  export declare const initStorage: typeof Storage_2.init;
4
6
 
5
7
  export declare const isBoolean: (val: any) => val is boolean;
@@ -105,13 +107,6 @@ export declare interface UploadInfo {
105
107
 
106
108
  export declare const useStorage: typeof Storage_2.getInstance;
107
109
 
108
- export declare class VideoUploader implements IVideoUploader {
109
- uploader: any;
110
- constructor(options: VideoUploadOptions);
111
- private initialize;
112
- upload(file: File): Promise<VideoUploadResult>;
113
- }
114
-
115
110
  declare interface VideoUploadOptions {
116
111
  onUploadFailed?: (uploadInfo: any, code: string, message: string) => void;
117
112
  onUploadSucceed?: (uploadInfo: any) => void;
@@ -136,6 +131,11 @@ export declare function watermark(): {
136
131
  export { }
137
132
 
138
133
 
134
+ declare module '*.js?raw' {
135
+ const content: string;
136
+ }
137
+
138
+
139
139
  declare global {
140
140
  interface Window {
141
141
  AliyunUpload: any;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}exports.commonjsRequire=o;
@@ -1,6 +0,0 @@
1
- function r(o) {
2
- throw new Error('Could not dynamically require "' + o + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3
- }
4
- export {
5
- r as commonjsRequire
6
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}exports.getDefaultExportFromCjs=e;
@@ -1,6 +0,0 @@
1
- function e(t) {
2
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
3
- }
4
- export {
5
- e as getDefaultExportFromCjs
6
- };